Bug 861905 - Contacts API: Shortcut permission check in the child. r=mounir, a=leo+
authorGregor Wagner <anygregor@gmail.com>
Wed, 17 Apr 2013 07:51:51 -0400
changeset 119140 5fe874b8efbdc8e67d53af43113aef9f9429d5fc
parent 119139 19b5590e161c98c650061285fb5534313d567f2e
child 119141 e7951efbe48990ab4b1daca92fc354fd94857ef8
push id693
push userryanvm@gmail.com
push dateFri, 19 Apr 2013 12:25:43 +0000
reviewersmounir, leo
bugs861905
milestone18.0
Bug 861905 - Contacts API: Shortcut permission check in the child. r=mounir, a=leo+
dom/contacts/ContactManager.js
--- a/dom/contacts/ContactManager.js
+++ b/dom/contacts/ContactManager.js
@@ -14,16 +14,20 @@ const Cu = Components.utils;
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/DOMRequestHelper.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");
 
 const CONTACTS_SENDMORE_MINIMUM = 5;
 
 const nsIClassInfo            = Ci.nsIClassInfo;
 const CONTACTPROPERTIES_CID   = Components.ID("{f5181640-89e8-11e1-b0c4-0800200c9a66}");
@@ -516,16 +520,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()