diff --git a/mozilla/browser/components/shell/public/nsIShellService.idl b/mozilla/browser/components/shell/public/nsIShellService.idl index f3d15f22a0d..12ed5442cbd 100644 --- a/mozilla/browser/components/shell/public/nsIShellService.idl +++ b/mozilla/browser/components/shell/public/nsIShellService.idl @@ -38,8 +38,9 @@ #include "nsISupports.idl" interface nsIDOMElement; +interface nsILocalFile; -[scriptable, uuid(d6f62053-3769-46f6-bd2b-0a1440d6c394)] +[scriptable, uuid(a4c253ab-09b9-4fb0-a61d-600621e690e4)] interface nsIShellService : nsISupports { /** @@ -114,3 +115,18 @@ interface nsIShellService : nsISupports attribute unsigned long desktopBackgroundColor; }; +// this interface stability for non-frozen interfaces esp. outside of gecko +// is retarded. +[scriptable, uuid(d48f8ea2-c912-48fa-9714-10d8098f05ea)] +interface nsIShellService_MOZILLA_1_8_BRANCH : nsISupports +{ + /** + * Opens an application with a specific URI to load. + * @param application + * The application file (or bundle directory, on OS X) + * @param uri + * The uri to be loaded by the application + */ + void openApplicationWithURI(in nsILocalFile aApplication, in ACString aURI); +}; + diff --git a/mozilla/browser/components/shell/src/nsGNOMEShellService.cpp b/mozilla/browser/components/shell/src/nsGNOMEShellService.cpp index a66fd3b2126..9634349717a 100644 --- a/mozilla/browser/components/shell/src/nsGNOMEShellService.cpp +++ b/mozilla/browser/components/shell/src/nsGNOMEShellService.cpp @@ -49,6 +49,7 @@ #include "nsIStringBundle.h" #include "gfxIImageFrame.h" #include "nsIOutputStream.h" +#include "nsIProcess.h" #include "nsNetUtil.h" #include "nsIDOMHTMLImageElement.h" #include "nsIImageLoadingContent.h" @@ -135,7 +136,7 @@ nsGNOMEShellService::Init() return appPath->GetNativePath(mAppPath); } -NS_IMPL_ISUPPORTS1(nsGNOMEShellService, nsIShellService) +NS_IMPL_ISUPPORTS2(nsGNOMEShellService, nsIShellService, nsIShellService_MOZILLA_1_8_BRANCH) PRBool nsGNOMEShellService::KeyMatchesAppName(const char *aKeyValue) const @@ -540,3 +541,22 @@ nsGNOMEShellService::OpenApplication(PRInt32 aApplication) return err ? NS_OK : NS_ERROR_FAILURE; } + +NS_IMETHODIMP +nsGNOMEShellService::OpenApplicationWithURI(nsILocalFile* aApplication, const nsACString& aURI) +{ + nsresult rv; + nsCOMPtr process = + do_CreateInstance("@mozilla.org/process/util;1", &rv); + if (NS_FAILED(rv)) + return rv; + + rv = process->Init(aApplication); + if (NS_FAILED(rv)) + return rv; + + const nsPromiseFlatCString& spec = PromiseFlatCString(aURI); + const char* specStr = spec.get(); + PRUint32 pid; + return process->Run(PR_FALSE, &specStr, 1, &pid); +} diff --git a/mozilla/browser/components/shell/src/nsGNOMEShellService.h b/mozilla/browser/components/shell/src/nsGNOMEShellService.h index 7b98433c80f..6046891c0cf 100644 --- a/mozilla/browser/components/shell/src/nsGNOMEShellService.h +++ b/mozilla/browser/components/shell/src/nsGNOMEShellService.h @@ -40,13 +40,15 @@ #include "nsIShellService.h" #include "nsString.h" -class nsGNOMEShellService : public nsIShellService +class nsGNOMEShellService : public nsIShellService, + public nsIShellService_MOZILLA_1_8_BRANCH { public: nsGNOMEShellService() : mCheckedThisSession(PR_FALSE) { } NS_DECL_ISUPPORTS NS_DECL_NSISHELLSERVICE + NS_DECL_NSISHELLSERVICE_MOZILLA_1_8_BRANCH nsresult Init() NS_HIDDEN; diff --git a/mozilla/browser/components/shell/src/nsMacShellService.cpp b/mozilla/browser/components/shell/src/nsMacShellService.cpp index 5803992d638..08194d08103 100644 --- a/mozilla/browser/components/shell/src/nsMacShellService.cpp +++ b/mozilla/browser/components/shell/src/nsMacShellService.cpp @@ -42,6 +42,7 @@ #include "nsIImageLoadingContent.h" #include "nsIDocument.h" #include "nsIContent.h" +#include "nsILocalFileMac.h" #include "nsIObserverService.h" #include "nsIPrefService.h" #include "nsIServiceManager.h" @@ -76,7 +77,7 @@ extern "C" { const FSRef* inBindingRef); } -NS_IMPL_ISUPPORTS3(nsMacShellService, nsIMacShellService, nsIShellService, nsIWebProgressListener) +NS_IMPL_ISUPPORTS4(nsMacShellService, nsIMacShellService, nsIShellService, nsIWebProgressListener, nsIShellService_MOZILLA_1_8_BRANCH) NS_IMETHODIMP nsMacShellService::IsDefaultBrowser(PRBool aStartupCheck, PRBool* aIsDefaultBrowser) @@ -457,3 +458,41 @@ nsMacShellService::SetDesktopBackgroundColor(PRUint32 aColor) // supports. return NS_ERROR_NOT_IMPLEMENTED; } + +NS_IMETHODIMP +nsMacShellService::OpenApplicationWithURI(nsILocalFile* aApplication, const nsACString& aURI) +{ + nsCOMPtr lfm(do_QueryInterface(aApplication)); + CFURLRef appURL; + nsresult rv = lfm->GetCFURL(&appURL); + if (NS_FAILED(rv)) + return rv; + + const nsPromiseFlatCString& spec = PromiseFlatCString(aURI); + const UInt8* uriString = (const UInt8*)spec.get(); + CFURLRef uri = ::CFURLCreateWithBytes(NULL, uriString, aURI.Length(), + kCFStringEncodingUTF8, NULL); + if (!uri) + return NS_ERROR_OUT_OF_MEMORY; + + CFArrayRef uris = ::CFArrayCreate(NULL, (const void**)&uri, 1, NULL); + if (!uris) { + ::CFRelease(uri); + return NS_ERROR_OUT_OF_MEMORY; + } + + LSLaunchURLSpec launchSpec; + launchSpec.appURL = appURL; + launchSpec.itemURLs = uris; + launchSpec.passThruParams = NULL; + launchSpec.launchFlags = kLSLaunchDefaults; + launchSpec.asyncRefCon = NULL; + + OSErr err = ::LSOpenFromURLSpec(&launchSpec, NULL); + + ::CFRelease(uris); + ::CFRelease(uri); + + return err != noErr ? NS_ERROR_FAILURE : NS_OK; +} + diff --git a/mozilla/browser/components/shell/src/nsMacShellService.h b/mozilla/browser/components/shell/src/nsMacShellService.h index 3d0a9d3d029..cf550108ab6 100644 --- a/mozilla/browser/components/shell/src/nsMacShellService.h +++ b/mozilla/browser/components/shell/src/nsMacShellService.h @@ -43,7 +43,8 @@ #include "nsILocalFile.h" class nsMacShellService : public nsIMacShellService, - public nsIWebProgressListener + public nsIWebProgressListener, + public nsIShellService_MOZILLA_1_8_BRANCH { public: nsMacShellService() : mCheckedThisSession(PR_FALSE) {}; @@ -53,6 +54,7 @@ public: NS_DECL_NSISHELLSERVICE NS_DECL_NSIMACSHELLSERVICE NS_DECL_NSIWEBPROGRESSLISTENER + NS_DECL_NSISHELLSERVICE_MOZILLA_1_8_BRANCH protected: diff --git a/mozilla/browser/components/shell/src/nsWindowsShellService.cpp b/mozilla/browser/components/shell/src/nsWindowsShellService.cpp index 2f02d7e8e7d..223d2f1bda8 100644 --- a/mozilla/browser/components/shell/src/nsWindowsShellService.cpp +++ b/mozilla/browser/components/shell/src/nsWindowsShellService.cpp @@ -54,6 +54,7 @@ #include "nsShellService.h" #include "nsWindowsShellService.h" #include "nsIObserverService.h" +#include "nsIProcess.h" #include "nsICategoryManager.h" #include "nsBrowserCompsCID.h" #include "nsNativeCharsetUtils.h" @@ -75,7 +76,7 @@ #define REG_FAILED(val) \ (val != ERROR_SUCCESS) -NS_IMPL_ISUPPORTS3(nsWindowsShellService, nsIWindowsShellService, nsIShellService, nsIObserver) +NS_IMPL_ISUPPORTS4(nsWindowsShellService, nsIWindowsShellService, nsIShellService, nsIObserver, nsIShellService_MOZILLA_1_8_BRANCH) static nsresult OpenUserKeyForReading(HKEY aStartKey, const char* aKeyName, HKEY* aKey) @@ -1057,3 +1058,22 @@ nsWindowsShellService::Observe(nsISupports* aObject, const char* aTopic, const P return NS_OK; } +NS_IMETHODIMP +nsWindowsShellService::OpenApplicationWithURI(nsILocalFile* aApplication, const nsACString& aURI) +{ + nsresult rv; + nsCOMPtr process = + do_CreateInstance("@mozilla.org/process/util;1", &rv); + if (NS_FAILED(rv)) + return rv; + + rv = process->Init(aApplication); + if (NS_FAILED(rv)) + return rv; + + const nsPromiseFlatCString& spec = PromiseFlatCString(aURI); + const char* specStr = spec.get(); + PRUint32 pid; + return process->Run(PR_FALSE, &specStr, 1, &pid); +} + diff --git a/mozilla/browser/components/shell/src/nsWindowsShellService.h b/mozilla/browser/components/shell/src/nsWindowsShellService.h index e8905d53613..6b2eb6fd8c8 100644 --- a/mozilla/browser/components/shell/src/nsWindowsShellService.h +++ b/mozilla/browser/components/shell/src/nsWindowsShellService.h @@ -47,7 +47,8 @@ #include class nsWindowsShellService : public nsIWindowsShellService, - public nsIObserver + public nsIObserver, + public nsIShellService_MOZILLA_1_8_BRANCH { public: nsWindowsShellService(); @@ -57,6 +58,7 @@ public: NS_DECL_NSISHELLSERVICE NS_DECL_NSIWINDOWSSHELLSERVICE NS_DECL_NSIOBSERVER + NS_DECL_NSISHELLSERVICE_MOZILLA_1_8_BRANCH static NS_METHOD Register(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *registryLocation, const char *componentType, const nsModuleComponentInfo *info);