mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-20 08:45:46 +00:00
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
This commit is contained in:
parent
c5413ef080
commit
3f6c1dab90
@ -245,6 +245,6 @@ if (AppConstants.platform != "macosx") {
|
||||
};
|
||||
|
||||
gSetBackground.showDesktopPrefs = function() {
|
||||
this._shell.openApplication(Ci.nsIMacShellService.APPLICATION_DESKTOP);
|
||||
this._shell.QueryInterface(Ci.nsIMacShellService).showDesktopPreferences();
|
||||
};
|
||||
}
|
||||
|
@ -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<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
|
||||
if (giovfs) {
|
||||
nsCOMPtr<nsIHandlerApp> 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<nsIProcess> 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);
|
||||
}
|
||||
|
@ -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();
|
||||
};
|
||||
|
||||
|
@ -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);
|
||||
};
|
||||
|
@ -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 <Carbon/Carbon.h>
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
|
||||
@ -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<nsIFile> 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<nsIFile> 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<nsIFile> 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<nsILocalFileMac> 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;
|
||||
}
|
||||
|
@ -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<nsIProcess> 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);
|
||||
}
|
||||
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user