Bug 861905 - Contacts API: Shortcut permission check in the child. r=mounir
authorGregor Wagner <anygregor@gmail.com>
Wed, 17 Apr 2013 07:51:51 -0400
changeset 128982 4f58c0e74b97
parent 128981 ef0432d35332
child 128983 14db91e6346f
push id24552
push userryanvm@gmail.com
push date2013-04-17 16:08 +0000
treeherdermozilla-central@22b8581c2dd7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmounir
bugs861905
milestone23.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 861905 - Contacts API: Shortcut permission check in the child. r=mounir
dom/contacts/ContactManager.js
--- a/dom/contacts/ContactManager.js
+++ b/dom/contacts/ContactManager.js
@@ -15,16 +15,20 @@ Cu.import("resource://gre/modules/XPCOMU
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/DOMRequestHelper.jsm");
 Cu.import("resource://gre/modules/ObjectWrapper.jsm");
 
 XPCOMUtils.defineLazyGetter(Services, "DOMRequest", function() {
   return Cc["@mozilla.org/dom/dom-request-service;1"].getService(Ci.nsIDOMRequestService);
 });
 
+XPCOMUtils.defineLazyServiceGetter(this, "pm",
+                                   "@mozilla.org/permissionmanager;1",
+                                   "nsIPermissionManager");
+
 XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
                                    "@mozilla.org/childprocessmessagemanager;1",
                                    "nsIMessageSender");
 
 function stringOrBust(aObj) {
   if (typeof aObj != "string") {
     if (DEBUG) debug("Field is not a string and was ignored.");
     return undefined;
@@ -554,16 +558,25 @@ ContactManager.prototype = {
       case "getSimContacts":
       case "listen":
         access = "read";
         break;
       default:
         access = "unknown";
       }
 
+    // Shortcut for ALLOW_ACTION so we avoid a parent roundtrip
+    let type = "contacts-" + access;
+    let permValue =
+      pm.testExactPermissionFromPrincipal(this._window.document.nodePrincipal, type);
+    if (permValue == Ci.nsIPermissionManager.ALLOW_ACTION) {
+      aAllowCallback();
+      return;
+    }
+
     let requestID = this.getRequestId({
       request: aRequest,
       allow: function() {
         aAllowCallback();
       }.bind(this),
       cancel : function() {
         if (aCancelCallback) {
           aCancelCallback()