From c94f5db02e2aa5fdf76ca935df2363dae7e3c9b6 Mon Sep 17 00:00:00 2001 From: Gregor Wagner Date: Wed, 17 Apr 2013 07:51:51 -0400 Subject: [PATCH] Bug 861905 - Contacts API: Shortcut permission check in the child. r=mounir --- dom/contacts/ContactManager.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/dom/contacts/ContactManager.js b/dom/contacts/ContactManager.js index 830e7afd79ab..0ea900b82ae1 100644 --- a/dom/contacts/ContactManager.js +++ b/dom/contacts/ContactManager.js @@ -20,6 +20,10 @@ 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"); @@ -559,6 +563,15 @@ ContactManager.prototype = { 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() {