Bug 779378: B2G Voicemail: Hook up to permissions manager; r=gwagner
authorKyle Machulis <kyle@nonpolynomial.com>
Thu, 23 Aug 2012 16:31:02 -0700
changeset 105274 8eb991da28afe836f0d718411b6ca10cb8f74267
parent 105273 6e67b20609d24dc062fc89a6eb6ffd8682cdf6fe
child 105275 dbd014cfb8488efe09a57e7f9bac5a0c93819384
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
reviewersgwagner
bugs779378
milestone17.0a1
Bug 779378: B2G Voicemail: Hook up to permissions manager; r=gwagner
dom/base/Navigator.cpp
dom/telephony/test/marionette/test_voicemail_number.js
dom/telephony/test/marionette/test_voicemail_statuschanged.js
--- a/dom/base/Navigator.cpp
+++ b/dom/base/Navigator.cpp
@@ -1133,30 +1133,30 @@ Navigator::GetMozTelephony(nsIDOMTelepho
 
 NS_IMETHODIMP
 Navigator::GetMozVoicemail(nsIDOMMozVoicemail** aVoicemail)
 {
   *aVoicemail = nullptr;
 
   if (!mVoicemail) {
     nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mWindow);
-    NS_ENSURE_TRUE(window && window->GetDocShell(), NS_OK);
+    NS_ENSURE_TRUE(window, NS_OK);
 
-    // Chrome is always allowed access, so do the permission check only
-    // for non-chrome pages.
-    if (!nsContentUtils::IsCallerChrome()) {
-      nsCOMPtr<nsIDocument> doc = do_QueryInterface(window->GetExtantDocument());
-      NS_ENSURE_TRUE(doc, NS_OK);
+    nsCOMPtr<nsIDocument> document = do_QueryInterface(window->GetExtantDocument());
+    NS_ENSURE_TRUE(document, NS_OK);
+    nsCOMPtr<nsIPrincipal> principal = document->NodePrincipal();
+    nsCOMPtr<nsIPermissionManager> permMgr =
+      do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
+    NS_ENSURE_TRUE(permMgr, NS_OK);
 
-      nsCOMPtr<nsIURI> uri;
-      doc->NodePrincipal()->GetURI(getter_AddRefs(uri));
+    PRUint32 permission = nsIPermissionManager::DENY_ACTION;
+    permMgr->TestPermissionFromPrincipal(principal, "voicemail", &permission);
 
-      if (!nsContentUtils::URIIsChromeOrInPref(uri, "dom.voicemail.whitelist")) {
-        return NS_OK;
-      }
+    if (permission != nsIPermissionManager::ALLOW_ACTION) {
+      return NS_OK;
     }
 
     nsresult rv = NS_NewVoicemail(window, getter_AddRefs(mVoicemail));
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   NS_ADDREF(*aVoicemail = mVoicemail);
   return NS_OK;
--- a/dom/telephony/test/marionette/test_voicemail_number.js
+++ b/dom/telephony/test/marionette/test_voicemail_number.js
@@ -1,18 +1,16 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 10000;
 
-const WHITELIST_PREF = "dom.voicemail.whitelist";
-let uriPrePath = window.location.protocol + "//" + window.location.host;
-SpecialPowers.setCharPref(WHITELIST_PREF, uriPrePath);
+SpecialPowers.addPermission("voicemail", true, document);
 
 let voicemail = window.navigator.mozVoicemail;
 ok(voicemail instanceof MozVoicemail);
 
 // These are the emulator's hard coded voicemail number and alphaId
 is(voicemail.number, "+15552175049");
 is(voicemail.displayName, "Voicemail");
 
-SpecialPowers.clearUserPref(WHITELIST_PREF);
+SpecialPowers.removePermission("voicemail", document);
 finish();
--- a/dom/telephony/test/marionette/test_voicemail_statuschanged.js
+++ b/dom/telephony/test/marionette/test_voicemail_statuschanged.js
@@ -1,14 +1,12 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
-const WHITELIST_PREF = "dom.voicemail.whitelist";
-let uriPrePath = window.location.protocol + "//" + window.location.host;
-SpecialPowers.setCharPref(WHITELIST_PREF, uriPrePath);
+SpecialPowers.addPermission("voicemail", true, document);
 
 let voicemail = window.navigator.mozVoicemail;
 ok(voicemail instanceof MozVoicemail);
 is(voicemail.status, null);
 
 function sendIndicatorPDU(pdu, listener, nextTest) {
   let smsCommand = "sms pdu " + pdu;
   let commandCompleted = false;
@@ -217,13 +215,13 @@ function testLevel3DiscardInactive() {
     is(status.returnMessage, MWI_LEVEL3_INACTIVE_BODY);
     isVoicemailStatus(status);
   }
 
   sendIndicatorPDU(MWI_LEVEL3_DISCARD_INACTIVE_PDU, onLevel3Inactive, cleanUp);
 }
 
 function cleanUp() {
-  SpecialPowers.clearUserPref(WHITELIST_PREF);
+  SpecialPowers.removePermission("voicemail", document);
   finish();
 }
 
 testLevel1Indicator();