From 3f6c1dab903fe95f4f3be0c253f8be83be7db48a Mon Sep 17 00:00:00 2001 From: Mark Banner Date: Tue, 27 Aug 2019 08:03:12 +0000 Subject: [PATCH] Bug 324361 - Remove openApplication/openApplicationWithURI from the shell service as they aren't used. r=mossop Keeps a function for opening the Mac desktop preferences. Differential Revision: https://phabricator.services.mozilla.com/D43269 --HG-- extra : moz-landing-system : lando --- .../shell/content/setDesktopBackground.js | 2 +- .../components/shell/nsGNOMEShellService.cpp | 37 ------ .../components/shell/nsIMacShellService.idl | 8 +- browser/components/shell/nsIShellService.idl | 23 ---- .../components/shell/nsMacShellService.cpp | 96 ++------------- .../shell/nsWindowsShellService.cpp | 110 ------------------ .../test/browser_UITour_defaultBrowser.js | 4 - 7 files changed, 15 insertions(+), 265 deletions(-) diff --git a/browser/components/shell/content/setDesktopBackground.js b/browser/components/shell/content/setDesktopBackground.js index 94c495dda531..9fce23fa0c9b 100644 --- a/browser/components/shell/content/setDesktopBackground.js +++ b/browser/components/shell/content/setDesktopBackground.js @@ -245,6 +245,6 @@ if (AppConstants.platform != "macosx") { }; gSetBackground.showDesktopPrefs = function() { - this._shell.openApplication(Ci.nsIMacShellService.APPLICATION_DESKTOP); + this._shell.QueryInterface(Ci.nsIMacShellService).showDesktopPreferences(); }; } diff --git a/browser/components/shell/nsGNOMEShellService.cpp b/browser/components/shell/nsGNOMEShellService.cpp index 7d21a3fc848d..ecbfd9c557f5 100644 --- a/browser/components/shell/nsGNOMEShellService.cpp +++ b/browser/components/shell/nsGNOMEShellService.cpp @@ -19,7 +19,6 @@ #include "nsIGSettingsService.h" #include "nsIStringBundle.h" #include "nsIOutputStream.h" -#include "nsIProcess.h" #include "nsServiceManagerUtils.h" #include "nsComponentManagerUtils.h" #include "nsIImageLoadingContent.h" @@ -501,39 +500,3 @@ nsGNOMEShellService::SetDesktopBackgroundColor(uint32_t aColor) { return NS_ERROR_FAILURE; } - -NS_IMETHODIMP -nsGNOMEShellService::OpenApplication(int32_t aApplication) { - nsAutoCString scheme; - if (aApplication == APPLICATION_MAIL) - scheme.AssignLiteral("mailto"); - else if (aApplication == APPLICATION_NEWS) - scheme.AssignLiteral("news"); - else - return NS_ERROR_NOT_AVAILABLE; - - nsCOMPtr giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID); - if (giovfs) { - nsCOMPtr handlerApp; - giovfs->GetAppForURIScheme(scheme, getter_AddRefs(handlerApp)); - if (handlerApp) return handlerApp->LaunchWithURI(nullptr, nullptr); - } - - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -nsGNOMEShellService::OpenApplicationWithURI(nsIFile* 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 nsCString spec(aURI); - const char* specStr = spec.get(); - return process->Run(false, &specStr, 1); -} diff --git a/browser/components/shell/nsIMacShellService.idl b/browser/components/shell/nsIMacShellService.idl index 6a532bbd0b2a..e320a814abc4 100644 --- a/browser/components/shell/nsIMacShellService.idl +++ b/browser/components/shell/nsIMacShellService.idl @@ -8,8 +8,8 @@ [scriptable, uuid(387fdc80-0077-4b60-a0d9-d9e80a83ba64)] interface nsIMacShellService : nsIShellService { - const long APPLICATION_KEYCHAIN_ACCESS = 2; - const long APPLICATION_NETWORK = 3; - const long APPLICATION_DESKTOP = 4; + /** + * Opens the desktop preferences, e.g. for after setting the background. + */ + void showDesktopPreferences(); }; - diff --git a/browser/components/shell/nsIShellService.idl b/browser/components/shell/nsIShellService.idl index a194ead0e87a..a3fa43412327 100644 --- a/browser/components/shell/nsIShellService.idl +++ b/browser/components/shell/nsIShellService.idl @@ -60,33 +60,10 @@ interface nsIShellService : nsISupports in long aPosition, in ACString aImageName); - /** - * Constants identifying applications that can be opened with - * openApplication. - */ - const long APPLICATION_MAIL = 0; - const long APPLICATION_NEWS = 1; - - /** - * Opens the application specified. If more than one application of the - * given type is available on the system, the default or "preferred" - * application is used. - */ - void openApplication(in long aApplication); - /** * The desktop background color, visible when no background image is * used, or if the background image is centered and does not fill the * entire screen. A rgb value, where (r << 16 | g << 8 | b) */ attribute unsigned long desktopBackgroundColor; - - /** - * 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 nsIFile aApplication, in ACString aURI); }; diff --git a/browser/components/shell/nsMacShellService.cpp b/browser/components/shell/nsMacShellService.cpp index aa4c286d5ce2..f968614f74b2 100644 --- a/browser/components/shell/nsMacShellService.cpp +++ b/browser/components/shell/nsMacShellService.cpp @@ -7,7 +7,6 @@ #include "nsIImageLoadingContent.h" #include "mozilla/dom/Document.h" #include "nsIContent.h" -#include "nsILocalFileMac.h" #include "nsIObserverService.h" #include "nsIPrefService.h" #include "nsIServiceManager.h" @@ -23,6 +22,7 @@ #include "nsILoadContext.h" #include "mozilla/dom/Element.h" +#include #include #include @@ -265,56 +265,15 @@ nsMacShellService::OnStateChange(nsIWebProgress* aWebProgress, } NS_IMETHODIMP -nsMacShellService::OpenApplication(int32_t aApplication) { - nsresult rv = NS_OK; - CFURLRef appURL = nil; - OSStatus err = noErr; - - switch (aApplication) { - case nsIShellService::APPLICATION_MAIL: { - CFURLRef tempURL = ::CFURLCreateWithString(kCFAllocatorDefault, - CFSTR("mailto:"), nullptr); - err = ::LSGetApplicationForURL(tempURL, kLSRolesAll, nullptr, &appURL); - ::CFRelease(tempURL); - } break; - case nsIShellService::APPLICATION_NEWS: { - CFURLRef tempURL = - ::CFURLCreateWithString(kCFAllocatorDefault, CFSTR("news:"), nullptr); - err = ::LSGetApplicationForURL(tempURL, kLSRolesAll, nullptr, &appURL); - ::CFRelease(tempURL); - } break; - case nsIMacShellService::APPLICATION_KEYCHAIN_ACCESS: - err = ::LSGetApplicationForInfo('APPL', 'kcmr', nullptr, kLSRolesAll, - nullptr, &appURL); - break; - case nsIMacShellService::APPLICATION_NETWORK: { - nsCOMPtr lf; - rv = NS_NewNativeLocalFile(NETWORK_PREFPANE, true, getter_AddRefs(lf)); - NS_ENSURE_SUCCESS(rv, rv); - bool exists; - lf->Exists(&exists); - if (!exists) return NS_ERROR_FILE_NOT_FOUND; - return lf->Launch(); - } - case nsIMacShellService::APPLICATION_DESKTOP: { - nsCOMPtr lf; - rv = NS_NewNativeLocalFile(DESKTOP_PREFPANE, true, getter_AddRefs(lf)); - NS_ENSURE_SUCCESS(rv, rv); - bool exists; - lf->Exists(&exists); - if (!exists) return NS_ERROR_FILE_NOT_FOUND; - return lf->Launch(); - } - } - - if (appURL && err == noErr) { - err = ::LSOpenCFURLRef(appURL, nullptr); - rv = err != noErr ? NS_ERROR_FAILURE : NS_OK; - - ::CFRelease(appURL); - } - - return rv; +nsMacShellService::ShowDesktopPreferences() { + nsCOMPtr lf; + nsresult rv = + NS_NewNativeLocalFile(DESKTOP_PREFPANE, true, getter_AddRefs(lf)); + NS_ENSURE_SUCCESS(rv, rv); + bool exists; + lf->Exists(&exists); + if (!exists) return NS_ERROR_FILE_NOT_FOUND; + return lf->Launch(); } NS_IMETHODIMP @@ -332,38 +291,3 @@ nsMacShellService::SetDesktopBackgroundColor(uint32_t aColor) { // supports. return NS_ERROR_NOT_IMPLEMENTED; } - -NS_IMETHODIMP -nsMacShellService::OpenApplicationWithURI(nsIFile* aApplication, - const nsACString& aURI) { - nsCOMPtr lfm(do_QueryInterface(aApplication)); - CFURLRef appURL; - nsresult rv = lfm->GetCFURL(&appURL); - if (NS_FAILED(rv)) return rv; - - const nsCString spec(aURI); - const UInt8* uriString = (const UInt8*)spec.get(); - CFURLRef uri = ::CFURLCreateWithBytes(nullptr, uriString, aURI.Length(), - kCFStringEncodingUTF8, nullptr); - if (!uri) return NS_ERROR_OUT_OF_MEMORY; - - CFArrayRef uris = ::CFArrayCreate(nullptr, (const void**)&uri, 1, nullptr); - if (!uris) { - ::CFRelease(uri); - return NS_ERROR_OUT_OF_MEMORY; - } - - LSLaunchURLSpec launchSpec; - launchSpec.appURL = appURL; - launchSpec.itemURLs = uris; - launchSpec.passThruParams = nullptr; - launchSpec.launchFlags = kLSLaunchDefaults; - launchSpec.asyncRefCon = nullptr; - - OSErr err = ::LSOpenFromURLSpec(&launchSpec, nullptr); - - ::CFRelease(uris); - ::CFRelease(uri); - - return err != noErr ? NS_ERROR_FAILURE : NS_OK; -} diff --git a/browser/components/shell/nsWindowsShellService.cpp b/browser/components/shell/nsWindowsShellService.cpp index 78ca34535f2c..5154858163b8 100644 --- a/browser/components/shell/nsWindowsShellService.cpp +++ b/browser/components/shell/nsWindowsShellService.cpp @@ -20,7 +20,6 @@ #include "nsNetUtil.h" #include "nsServiceManagerUtils.h" #include "nsShellService.h" -#include "nsIProcess.h" #include "nsICategoryManager.h" #include "nsDirectoryServiceUtils.h" #include "nsAppDirectoryServiceDefs.h" @@ -646,99 +645,6 @@ nsWindowsShellService::SetDesktopBackground(dom::Element* aElement, return rv; } -NS_IMETHODIMP -nsWindowsShellService::OpenApplication(int32_t aApplication) { - nsAutoString application; - switch (aApplication) { - case nsIShellService::APPLICATION_MAIL: - application.AssignLiteral("Mail"); - break; - case nsIShellService::APPLICATION_NEWS: - application.AssignLiteral("News"); - break; - } - - // The Default Client section of the Windows Registry looks like this: - // - // Clients\aClient\ - // e.g. aClient = "Mail"... - // \Mail\(default) = Client Subkey Name - // \Client Subkey Name - // \Client Subkey Name\shell\open\command\ - // \Client Subkey Name\shell\open\command\(default) = path to exe - // - - // Find the default application for this class. - HKEY theKey; - nsresult rv = OpenKeyForReading(HKEY_CLASSES_ROOT, application, &theKey); - if (NS_FAILED(rv)) return rv; - - wchar_t buf[MAX_BUF]; - DWORD type, len = sizeof buf; - DWORD res = ::RegQueryValueExW(theKey, EmptyString().get(), 0, &type, - (LPBYTE)&buf, &len); - - if (REG_FAILED(res) || !*buf) return NS_OK; - - // Close the key we opened. - ::RegCloseKey(theKey); - - // Find the "open" command - application.Append('\\'); - application.Append(buf); - application.AppendLiteral("\\shell\\open\\command"); - - rv = OpenKeyForReading(HKEY_CLASSES_ROOT, application, &theKey); - if (NS_FAILED(rv)) return rv; - - ::ZeroMemory(buf, sizeof(buf)); - len = sizeof buf; - res = ::RegQueryValueExW(theKey, EmptyString().get(), 0, &type, (LPBYTE)&buf, - &len); - if (REG_FAILED(res) || !*buf) return NS_ERROR_FAILURE; - - // Close the key we opened. - ::RegCloseKey(theKey); - - // Look for any embedded environment variables and substitute their - // values, as |::CreateProcessW| is unable to do this. - nsAutoString path(buf); - int32_t end = path.Length(); - int32_t cursor = 0, temp = 0; - ::ZeroMemory(buf, sizeof(buf)); - do { - cursor = path.FindChar('%', cursor); - if (cursor < 0) break; - - temp = path.FindChar('%', cursor + 1); - ++cursor; - - ::ZeroMemory(&buf, sizeof(buf)); - - ::GetEnvironmentVariableW( - nsAutoString(Substring(path, cursor, temp - cursor)).get(), buf, - sizeof(buf)); - - // "+ 2" is to subtract the extra characters used to delimit the environment - // variable ('%'). - path.Replace((cursor - 1), temp - cursor + 2, nsDependentString(buf)); - - ++cursor; - } while (cursor < end); - - STARTUPINFOW si; - PROCESS_INFORMATION pi; - - ::ZeroMemory(&si, sizeof(STARTUPINFOW)); - ::ZeroMemory(&pi, sizeof(PROCESS_INFORMATION)); - - BOOL success = ::CreateProcessW(nullptr, (LPWSTR)path.get(), nullptr, nullptr, - FALSE, 0, nullptr, nullptr, &si, &pi); - if (!success) return NS_ERROR_FAILURE; - - return NS_OK; -} - NS_IMETHODIMP nsWindowsShellService::GetDesktopBackgroundColor(uint32_t* aColor) { uint32_t color = ::GetSysColor(COLOR_DESKTOP); @@ -780,19 +686,3 @@ nsWindowsShellService::SetDesktopBackgroundColor(uint32_t aColor) { nsWindowsShellService::nsWindowsShellService() {} nsWindowsShellService::~nsWindowsShellService() {} - -NS_IMETHODIMP -nsWindowsShellService::OpenApplicationWithURI(nsIFile* 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 nsCString spec(aURI); - const char* specStr = spec.get(); - return process->Run(false, &specStr, 1); -} diff --git a/browser/components/uitour/test/browser_UITour_defaultBrowser.js b/browser/components/uitour/test/browser_UITour_defaultBrowser.js index 7839dfc2588e..a0c1d8b24f33 100644 --- a/browser/components/uitour/test/browser_UITour_defaultBrowser.js +++ b/browser/components/uitour/test/browser_UITour_defaultBrowser.js @@ -28,11 +28,7 @@ MockShellService.prototype = { BACKGROUND_FIT: 5, BACKGROUND_SPAN: 6, setDesktopBackground(aElement, aPosition) {}, - APPLICATION_MAIL: 0, - APPLICATION_NEWS: 1, - openApplication(aApplication) {}, desktopBackgroundColor: 0, - openApplicationWithURI(aApplication, aURI) {}, }; var mockShellService = new MockObjectRegisterer(