Bug 792604 - Permission Settings followup fixes. r=sicking
authorGregor Wagner <gwagner@mozilla.com>
Thu, 20 Sep 2012 08:56:55 -0700
changeset 107742 7c33cfd00ffc97d672647662b218be0443bc5f5d
parent 107741 a5eaeae976505efada8159358871d9e7fc089770
child 107743 b805572c0c40b45b1198299bfae5560c2b41f698
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewerssicking
bugs792604
milestone18.0a1
Bug 792604 - Permission Settings followup fixes. r=sicking
dom/interfaces/permission/nsIDOMPermissionSettings.idl
dom/permission/PermissionSettings.js
dom/permission/PermissionSettings.manifest
dom/permission/tests/test_permission_basics.html
--- a/dom/interfaces/permission/nsIDOMPermissionSettings.idl
+++ b/dom/interfaces/permission/nsIDOMPermissionSettings.idl
@@ -1,15 +1,15 @@
 /* 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/. */
 
 #include "domstubs.idl"
 
 interface nsIDOMDOMRequest;
 
-[scriptable, uuid(36e73ef0-c6f4-11e1-9b21-0800200c9a66)]
+[scriptable, uuid(18390770-02ab-11e2-a21f-0800200c9a66)]
 interface nsIDOMPermissionSettings : nsISupports
 {
-  DOMString get(in DOMString permission, in DOMString access, in DOMString manifestURI, in DOMString origin, in bool browserFlag);
+  DOMString get(in DOMString permission, in DOMString manifestURI, in DOMString origin, in bool browserFlag);
 
-  void set(in DOMString permission, in DOMString access, in DOMString manifestURI, in DOMString origin, in DOMString value, in bool browserFlag);
+  void set(in DOMString permission, in DOMString value, in DOMString manifestURI, in DOMString origin, in bool browserFlag);
 };
--- a/dom/permission/PermissionSettings.js
+++ b/dom/permission/PermissionSettings.js
@@ -18,31 +18,31 @@ Cu.import("resource://gre/modules/XPCOMU
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/PermissionSettings.jsm");
 
 var cpm = Components.classes["@mozilla.org/childprocessmessagemanager;1"].getService(Components.interfaces.nsISyncMessageSender);
 
 // PermissionSettings
 
 const PERMISSIONSETTINGS_CONTRACTID = "@mozilla.org/permissionSettings;1";
-const PERMISSIONSETTINGS_CID        = Components.ID("{36e73ef0-c6f4-11e1-9b21-0800200c9a66}");
+const PERMISSIONSETTINGS_CID        = Components.ID("{18390770-02ab-11e2-a21f-0800200c9a66}");
 const nsIDOMPermissionSettings      = Components.interfaces.nsIDOMPermissionSettings;
 
 function PermissionSettings()
 {
   debug("Constructor");
 }
 
 var permissionManager = Components.classes["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager);
 var secMan = Components.classes["@mozilla.org/scriptsecuritymanager;1"].getService(Components.interfaces.nsIScriptSecurityManager);
 var appsService = Components.classes["@mozilla.org/AppsService;1"].getService(Components.interfaces.nsIAppsService);
 
 PermissionSettings.prototype = {
-  get: function get(aPermission, aAccess, aManifestURL, aOrigin, aBrowserFlag) {
-    debug("Get called with: " + aPermission + ", " + aAccess + ", " + aManifestURL + ", " + aOrigin + ", " + aBrowserFlag);
+  get: function get(aPermission, aManifestURL, aOrigin, aBrowserFlag) {
+    debug("Get called with: " + aPermission + ", " + aManifestURL + ", " + aOrigin + ", " + aBrowserFlag);
     let uri = Services.io.newURI(aOrigin, null, null);
     let appID = appsService.getAppLocalIdByManifestURL(aManifestURL);
     let principal = secMan.getAppCodebasePrincipal(uri, appID, aBrowserFlag);
     let result = permissionManager.testExactPermissionFromPrincipal(principal, aPermission);
 
     switch (result)
     {
       case Ci.nsIPermissionManager.UNKNOWN_ACTION:
@@ -54,35 +54,35 @@ PermissionSettings.prototype = {
       case Ci.nsIPermissionManager.PROMPT_ACTION:
         return "prompt";
       default:
         dump("Unsupported PermissionSettings Action!\n");
         return "unknown";
     }
   },
 
-  set: function set(aPermission, aAccess, aManifestURL, aOrigin, aValue, aBrowserFlag) {
-    debug("Set called with: " + aPermission + ", " + aAccess + ", " + aManifestURL + ", " + aOrigin + ",  " + aValue + ", " + aBrowserFlag);
+  set: function set(aPermission, aValue, aManifestURL, aOrigin, aBrowserFlag) {
+    debug("Set called with: " + aPermission + ", " + aManifestURL + ", " + aOrigin + ",  " + aValue + ", " + aBrowserFlag);
     let action;
     cpm.sendSyncMessage("PermissionSettings:AddPermission", {
       type: aPermission,
-      access: aAccess,
       origin: aOrigin,
       manifestURL: aManifestURL,
       value: aValue,
       browserFlag: aBrowserFlag
     });
   },
 
   init: function(aWindow) {
     debug("init");
+
     // Set navigator.mozPermissionSettings to null.
+    let perm = Services.perms.testExactPermissionFromPrincipal(aWindow.document.nodePrincipal, "permissions");
     if (!Services.prefs.getBoolPref("dom.mozPermissionSettings.enabled")
-        || Services.perms.testExactPermissionFromPrincipal(aWindow.document.nodePrincipal, "permissions")) {
-      debug("Permission to get/set permissions not granted!");
+        || perm != Ci.nsIPermissionManager.ALLOW_ACTION) {
       return null;
     }
 
     debug("Permission to get/set permissions granted!");
   },
 
   classID : PERMISSIONSETTINGS_CID,
   QueryInterface : XPCOMUtils.generateQI([nsIDOMPermissionSettings, Ci.nsIDOMGlobalPropertyInitializer]),
--- a/dom/permission/PermissionSettings.manifest
+++ b/dom/permission/PermissionSettings.manifest
@@ -1,3 +1,3 @@
-component {36e73ef0-c6f4-11e1-9b21-0800200c9a66} PermissionSettings.js
-contract @mozilla.org/permissionSettings;1 {36e73ef0-c6f4-11e1-9b21-0800200c9a66}
+component {18390770-02ab-11e2-a21f-0800200c9a66} PermissionSettings.js
+contract @mozilla.org/permissionSettings;1 {18390770-02ab-11e2-a21f-0800200c9a66}
 category JavaScript-navigator-property mozPermissionSettings @mozilla.org/permissionSettings;1
--- a/dom/permission/tests/test_permission_basics.html
+++ b/dom/permission/tests/test_permission_basics.html
@@ -16,38 +16,39 @@ https://bugzilla.mozilla.org/show_bug.cg
 <div id="content" style="display: none">
 
 </div>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 "use strict";
 
+SpecialPowers.addPermission("permissions", true, document);
 var comp = SpecialPowers.wrap(Components);
 SpecialPowers.pushPrefEnv({ "set": [["dom.mozPermissionSettings.enabled", true]] }, 
                           function() {
-                            SpecialPowers.addPermission("permissions", true, document);
+                            SpecialPowers.removePermission("permissions", document);
                           });
 
 comp.utils.import("resource://gre/modules/PermissionSettings.jsm");
 var mozPermissions = window.navigator.mozPermissionSettings;
 
 function permissionTest() {
   if (gPermissionssEnabled) {
-    mozPermissions.set("a", "read", "http://examplemanifestURI.com", "http://origin.com", "unknown", true);
-    var result = mozPermissions.get("a","read", "http://examplemanifestURI.com", "http://origin.com", true);
+    mozPermissions.set("a", "unknown", "http://examplemanifestURI.com", "http://origin.com", true);
+    var result = mozPermissions.get("a", "http://examplemanifestURI.com", "http://origin.com", true);
     is(result, "unknown", "same result");
-    mozPermissions.set("a", "read", "http://examplemanifestURI.com", "http://origin.com", "allow", true);
-    result = mozPermissions.get("a","read", "http://examplemanifestURI.com", "http://origin.com", true);
+    mozPermissions.set("a", "allow", "http://examplemanifestURI.com", "http://origin.com", true);
+    result = mozPermissions.get("a", "http://examplemanifestURI.com", "http://origin.com", true);
     is(result, "allow", "same result");
-    mozPermissions.set("a", "read", "http://examplemanifestURI.com", "http://origin.com", "deny", true);
-    result = mozPermissions.get("a","read", "http://examplemanifestURI.com", "http://origin.com", true);
+    mozPermissions.set("a", "deny", "http://examplemanifestURI.com", "http://origin.com", true);
+    result = mozPermissions.get("a", "http://examplemanifestURI.com", "http://origin.com", true);
     is(result, "deny", "same result");
-    mozPermissions.set("a", "read", "http://examplemanifestURI.com", "http://origin.com", "prompt", true);
-    result = mozPermissions.get("a","read", "http://examplemanifestURI.com", "http://origin.com", true);
+    mozPermissions.set("a", "prompt", "http://examplemanifestURI.com", "http://origin.com", true);
+    result = mozPermissions.get("a", "http://examplemanifestURI.com", "http://origin.com", true);
     is(result, "prompt", "same result");
     SimpleTest.finish();
   } else {
     is(mozPermissions, null, "mozPermissionSettings is null when not enabled.");
     SimpleTest.finish();
   }
 }