Bug 1615134 - Shell service API to open macOS Security & Privacy preferences panes. r=spohl

Example: Cc["@mozilla.org/browser/shell-service;1"].getService(Ci.nsIMacShellService).showSecurityPreferences("Privacy_AllFiles")

Differential Revision: https://phabricator.services.mozilla.com/D62690
This commit is contained in:
Matthew Noorenberghe
2020-02-14 04:06:09 +00:00
parent 6c4a4714e3
commit dd27be4a2e
5 changed files with 83 additions and 0 deletions

View File

@@ -3,6 +3,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "CocoaFileUtils.h"
#include "nsDirectoryServiceDefs.h"
#include "nsIImageLoadingContent.h"
#include "mozilla/dom/Document.h"
@@ -288,3 +289,32 @@ nsMacShellService::SetDesktopBackgroundColor(uint32_t aColor) {
// supports.
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsMacShellService::ShowSecurityPreferences(const nsACString& aPaneID) {
nsresult rv = NS_ERROR_NOT_AVAILABLE;
CFStringRef paneID = ::CFStringCreateWithBytes(
kCFAllocatorDefault, (const UInt8*)PromiseFlatCString(aPaneID).get(),
aPaneID.Length(), kCFStringEncodingUTF8, false);
if (paneID) {
CFStringRef format =
CFSTR("x-apple.systempreferences:com.apple.preference.security?%@");
if (format) {
CFStringRef urlStr =
CFStringCreateWithFormat(kCFAllocatorDefault, NULL, format, paneID);
if (urlStr) {
CFURLRef url = ::CFURLCreateWithString(NULL, urlStr, NULL);
rv = CocoaFileUtils::OpenURL(url);
::CFRelease(urlStr);
}
::CFRelease(format);
}
::CFRelease(paneID);
}
return rv;
}