Bug 775815 - Use new Permission Manager API in SpecialPowers. r=sicking
authorMounir Lamouri <mounir.lamouri@gmail.com>
Thu, 23 Aug 2012 11:23:48 -0700
changeset 103224 93a43b48cb6690c16fad7cb866502af09adc97d2
parent 103183 ad7963c93bd8e334e06433b6357fe0a432f107df
child 103225 ebe6e3330f6384dec428eecc7950ea72e0790d2f
push id13890
push userryanvm@gmail.com
push dateThu, 23 Aug 2012 23:50:55 +0000
treeherdermozilla-inbound@e137f28dfe70 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssicking
bugs775815
milestone17.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 775815 - Use new Permission Manager API in SpecialPowers. r=sicking
testing/mochitest/tests/SimpleTest/SpecialPowersObserverAPI.js
testing/mochitest/tests/SimpleTest/specialpowersAPI.js
--- a/testing/mochitest/tests/SimpleTest/SpecialPowersObserverAPI.js
+++ b/testing/mochitest/tests/SimpleTest/SpecialPowersObserverAPI.js
@@ -170,24 +170,27 @@ SpecialPowersObserverAPI.prototype = {
             throw new SpecialPowersException("Invalid operation for SPProcessCrashService");
         }
         break;
 
       case "SPPermissionManager":
         let perms =
           Components.classes["@mozilla.org/permissionmanager;1"]
                     .getService(Components.interfaces.nsIPermissionManager);
-        let uri = this._getURI(aMessage.json.url);
+        let msg = aMessage.json;
 
-        switch (aMessage.json.op) {
+        let secMan = Cc["@mozilla.org/scriptsecuritymanager;1"].getService(Ci.nsIScriptSecurityManager);
+        let principal = secMan.getAppCodebasePrincipal(this._getURI(msg.url), msg.appId, msg.isInBrowserElement);
+
+        switch (msg.op) {
           case "add":
-            perms.add(uri, aMessage.json.type, aMessage.json.permission);
+            perms.addFromPrincipal(principal, msg.type, msg.permission);
             break;
           case "remove":
-            perms.remove(uri.host, aMessage.json.type);
+            perms.removeFromPrincipal(principal, msg.type);
             break;
           default:
             throw new SpecialPowersException("Invalid operation for " +
                                              "SPPermissionManager");
         }
         break;
 
       default:
--- a/testing/mochitest/tests/SimpleTest/specialpowersAPI.js
+++ b/testing/mochitest/tests/SimpleTest/specialpowersAPI.js
@@ -1126,50 +1126,68 @@ SpecialPowersAPI.prototype = {
     obsvc.notifyObservers(document, "fullscreen-approved", null);
   },
   
   removeFullscreenAllowed: function(document) {
     var pm = Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager);
     pm.removeFromPrincipal(document.nodePrincipal, "fullscreen");
   },
 
-  _getURI: function(urlOrDocument) {
-    if (typeof(urlOrDocument) == "string") {
-      return Cc["@mozilla.org/network/io-service;1"].
-               getService(Ci.nsIIOService).
-               newURI(urlOrDocument, null, null);
+  _getInfoFromPermissionArg: function(arg) {
+    let url = "";
+    let appId = Ci.nsIScriptSecurityManager.NO_APP_ID;
+    let isInBrowserElement = false;
+
+    if (typeof(arg) == "string") {
+      // It's an URL.
+      url = Cc["@mozilla.org/network/io-service;1"]
+              .getService(Ci.nsIIOService)
+              .newURI(arg, null, null)
+              .spec;
+    } else if (arg.nodePrincipal) {
+      // It's a document.
+      url = arg.nodePrincipal.URI.spec;
+      appId = arg.nodePrincipal.appId;
+      isInBrowserElement = arg.nodePrincipal.isInBrowserElement;
+    } else {
+      url = arg.url;
+      appId = arg.appId;
+      isInBrowserElement = arg.isInBrowserElement;
     }
-    // Assume document.
-    return this.getDocumentURIObject(urlOrDocument);
+
+    return [ url, appId, isInBrowserElement ];
   },
 
-  addPermission: function(type, allow, urlOrDocument) {
-    let uri = this._getURI(urlOrDocument);
+  addPermission: function(type, allow, arg) {
+    let [url, appId, isInBrowserElement] = this._getInfoFromPermissionArg(arg);
 
-    let permission = allow ?
-                     Ci.nsIPermissionManager.ALLOW_ACTION :
-                     Ci.nsIPermissionManager.DENY_ACTION;
+    let permission = allow ? Ci.nsIPermissionManager.ALLOW_ACTION
+                           : Ci.nsIPermissionManager.DENY_ACTION;
 
     var msg = {
       'op': "add",
       'type': type,
-      'url': uri.spec,
-      'permission': permission
+      'permission': permission,
+      'url': url,
+      'appId': appId,
+      'isInBrowserElement': isInBrowserElement
     };
 
     this._sendSyncMessage('SPPermissionManager', msg);
   },
 
-  removePermission: function(type, urlOrDocument) {
-    let uri = this._getURI(urlOrDocument);
+  removePermission: function(type, arg) {
+    let [url, appId, isInBrowserElement] = this._getInfoFromPermissionArg(arg);
 
     var msg = {
       'op': "remove",
       'type': type,
-      'url': uri.spec
+      'url': url,
+      'appId': appId,
+      'isInBrowserElement': isInBrowserElement
     };
 
     this._sendSyncMessage('SPPermissionManager', msg);
   },
 
   getMozFullPath: function(file) {
     return file.mozFullPath;
   }