2012-09-19 11:19:00 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* 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/. */
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2012-09-28 15:16:29 -07:00
|
|
|
function debug(aMsg) {
|
2012-10-23 13:11:02 -07:00
|
|
|
//dump("-*- PermissionSettings.js: " + aMsg + "\n");
|
2012-09-28 15:16:29 -07:00
|
|
|
}
|
2012-09-19 11:19:00 -07:00
|
|
|
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cu = Components.utils;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2012-12-14 17:32:30 -08:00
|
|
|
Cu.import("resource://gre/modules/PermissionsTable.jsm");
|
2012-09-19 11:19:00 -07:00
|
|
|
|
2012-09-21 11:30:09 -07:00
|
|
|
var cpm = Cc["@mozilla.org/childprocessmessagemanager;1"].getService(Ci.nsISyncMessageSender);
|
2012-09-19 11:19:00 -07:00
|
|
|
|
|
|
|
// PermissionSettings
|
|
|
|
|
|
|
|
const PERMISSIONSETTINGS_CONTRACTID = "@mozilla.org/permissionSettings;1";
|
2013-01-23 10:17:33 -08:00
|
|
|
const PERMISSIONSETTINGS_CID = Components.ID("{18390770-02ab-11e2-a21f-0800200c9a66}");
|
2012-09-21 11:30:09 -07:00
|
|
|
const nsIDOMPermissionSettings = Ci.nsIDOMPermissionSettings;
|
2012-09-19 11:19:00 -07:00
|
|
|
|
|
|
|
function PermissionSettings()
|
|
|
|
{
|
|
|
|
debug("Constructor");
|
|
|
|
}
|
|
|
|
|
2012-10-23 13:11:02 -07:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this,
|
|
|
|
"permissionManager",
|
|
|
|
"@mozilla.org/permissionmanager;1",
|
|
|
|
"nsIPermissionManager");
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this,
|
|
|
|
"secMan",
|
|
|
|
"@mozilla.org/scriptsecuritymanager;1",
|
|
|
|
"nsIScriptSecurityManager");
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this,
|
|
|
|
"appsService",
|
|
|
|
"@mozilla.org/AppsService;1",
|
|
|
|
"nsIAppsService");
|
2012-09-19 11:19:00 -07:00
|
|
|
|
|
|
|
PermissionSettings.prototype = {
|
2012-11-28 02:57:16 -08:00
|
|
|
get: function get(aPermName, aManifestURL, aOrigin, aBrowserFlag) {
|
|
|
|
debug("Get called with: " + aPermName + ", " + aManifestURL + ", " + aOrigin + ", " + aBrowserFlag);
|
2012-09-19 11:19:00 -07:00
|
|
|
let uri = Services.io.newURI(aOrigin, null, null);
|
|
|
|
let appID = appsService.getAppLocalIdByManifestURL(aManifestURL);
|
|
|
|
let principal = secMan.getAppCodebasePrincipal(uri, appID, aBrowserFlag);
|
2013-01-10 12:23:39 -08:00
|
|
|
let result = permissionManager.testExactPermanentPermission(principal, aPermName);
|
2012-09-19 11:19:00 -07:00
|
|
|
|
|
|
|
switch (result)
|
|
|
|
{
|
|
|
|
case Ci.nsIPermissionManager.UNKNOWN_ACTION:
|
2012-09-28 15:16:29 -07:00
|
|
|
return "unknown";
|
2012-09-19 11:19:00 -07:00
|
|
|
case Ci.nsIPermissionManager.ALLOW_ACTION:
|
|
|
|
return "allow";
|
|
|
|
case Ci.nsIPermissionManager.DENY_ACTION:
|
|
|
|
return "deny";
|
|
|
|
case Ci.nsIPermissionManager.PROMPT_ACTION:
|
|
|
|
return "prompt";
|
|
|
|
default:
|
|
|
|
dump("Unsupported PermissionSettings Action!\n");
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-12-14 17:32:30 -08:00
|
|
|
isExplicit: function isExplicit(aPermName, aManifestURL, aOrigin,
|
|
|
|
aBrowserFlag) {
|
|
|
|
debug("isExplicit: " + aPermName + ", " + aManifestURL + ", " + aOrigin);
|
|
|
|
let uri = Services.io.newURI(aOrigin, null, null);
|
|
|
|
let appID = appsService.getAppLocalIdByManifestURL(aManifestURL);
|
|
|
|
let principal = secMan.getAppCodebasePrincipal(uri, appID, aBrowserFlag);
|
|
|
|
|
|
|
|
return isExplicitInPermissionsTable(aPermName, principal.appStatus);
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function set(aPermName, aPermValue, aManifestURL, aOrigin,
|
|
|
|
aBrowserFlag) {
|
|
|
|
debug("Set called with: " + aPermName + ", " + aManifestURL + ", " +
|
2013-01-23 10:17:33 -08:00
|
|
|
aOrigin + ", " + aPermValue + ", " + aBrowserFlag);
|
|
|
|
let currentPermValue = this.get(aPermName, aManifestURL, aOrigin,
|
2013-01-17 13:50:59 -08:00
|
|
|
aBrowserFlag);
|
2012-09-19 11:19:00 -07:00
|
|
|
let action;
|
2012-12-14 17:32:30 -08:00
|
|
|
// Check for invalid calls so that we throw an exception rather than get
|
|
|
|
// killed by parent process
|
2013-01-23 10:17:33 -08:00
|
|
|
if (currentPermValue === "unknown" ||
|
2013-01-17 13:50:59 -08:00
|
|
|
aPermValue === "unknown" ||
|
2012-12-14 17:32:30 -08:00
|
|
|
!this.isExplicit(aPermName, aManifestURL, aOrigin, aBrowserFlag)) {
|
|
|
|
let errorMsg = "PermissionSettings.js: '" + aPermName + "'" +
|
2013-01-17 13:50:59 -08:00
|
|
|
" is an implicit permission for '" + aManifestURL +
|
|
|
|
"' or the permission isn't set";
|
2012-12-14 17:32:30 -08:00
|
|
|
Cu.reportError(errorMsg);
|
|
|
|
throw new Components.Exception(errorMsg);
|
|
|
|
}
|
|
|
|
|
2012-09-19 11:19:00 -07:00
|
|
|
cpm.sendSyncMessage("PermissionSettings:AddPermission", {
|
2012-11-28 02:57:16 -08:00
|
|
|
type: aPermName,
|
2012-09-19 11:19:00 -07:00
|
|
|
origin: aOrigin,
|
|
|
|
manifestURL: aManifestURL,
|
2012-11-28 02:57:16 -08:00
|
|
|
value: aPermValue,
|
2012-09-19 11:19:00 -07:00
|
|
|
browserFlag: aBrowserFlag
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-11-28 02:57:16 -08:00
|
|
|
init: function init(aWindow) {
|
2012-09-19 11:19:00 -07:00
|
|
|
debug("init");
|
2012-09-20 08:56:55 -07:00
|
|
|
|
2012-09-19 11:19:00 -07:00
|
|
|
// Set navigator.mozPermissionSettings to null.
|
2012-09-20 08:56:55 -07:00
|
|
|
let perm = Services.perms.testExactPermissionFromPrincipal(aWindow.document.nodePrincipal, "permissions");
|
2012-09-19 11:19:00 -07:00
|
|
|
if (!Services.prefs.getBoolPref("dom.mozPermissionSettings.enabled")
|
2012-09-20 08:56:55 -07:00
|
|
|
|| perm != Ci.nsIPermissionManager.ALLOW_ACTION) {
|
2012-09-19 11:19:00 -07:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
debug("Permission to get/set permissions granted!");
|
|
|
|
},
|
|
|
|
|
|
|
|
classID : PERMISSIONSETTINGS_CID,
|
|
|
|
QueryInterface : XPCOMUtils.generateQI([nsIDOMPermissionSettings, Ci.nsIDOMGlobalPropertyInitializer]),
|
|
|
|
|
|
|
|
classInfo : XPCOMUtils.generateCI({classID: PERMISSIONSETTINGS_CID,
|
|
|
|
contractID: PERMISSIONSETTINGS_CONTRACTID,
|
|
|
|
classDescription: "PermissionSettings",
|
|
|
|
interfaces: [nsIDOMPermissionSettings],
|
|
|
|
flags: Ci.nsIClassInfo.DOM_OBJECT})
|
|
|
|
}
|
|
|
|
|
2012-10-31 09:13:28 -07:00
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([PermissionSettings])
|