Bug 779379 - B2G MobileConnection: Hook up to permissions manager. r=jlebar

This commit is contained in:
Gregor Wagner 2012-08-16 17:42:26 -07:00
parent 7db646ce0a
commit 0684d004cb
3 changed files with 16 additions and 19 deletions

View File

@ -38,6 +38,7 @@
#include "Connection.h"
#include "MobileConnection.h"
#include "nsIIdleObserver.h"
#include "nsIPermissionManager.h"
#ifdef MOZ_MEDIA_NAVIGATOR
#include "MediaManager.h"
@ -1243,20 +1244,20 @@ Navigator::GetMozMobileConnection(nsIDOMMozMobileConnection** aMobileConnection)
if (!mMobileConnection) {
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, "mobileconnection", &permission);
if (!nsContentUtils::URIIsChromeOrInPref(uri, "dom.mobileconnection.whitelist")) {
return NS_OK;
}
if (permission != nsIPermissionManager::ALLOW_ACTION) {
return NS_OK;
}
mMobileConnection = new network::MobileConnection();

View File

@ -4,9 +4,7 @@
// getNetworks() can take some time..
MARIONETTE_TIMEOUT = 60000;
const WHITELIST_PREF = "dom.mobileconnection.whitelist";
let uriPrePath = window.location.protocol + "//" + window.location.host;
SpecialPowers.setCharPref(WHITELIST_PREF, uriPrePath);
SpecialPowers.addPermission("mobileconnection", true, document);
let connection = navigator.mozMobileConnection;
ok(connection instanceof MozMobileConnection,
@ -233,7 +231,7 @@ function testSelectExistingNetworkAuto() {
}
function cleanUp() {
SpecialPowers.clearUserPref(WHITELIST_PREF);
SpecialPowers.removePermission("mobileconnection", document);
finish();
}

View File

@ -3,9 +3,7 @@
MARIONETTE_TIMEOUT = 30000;
const WHITELIST_PREF = "dom.mobileconnection.whitelist";
let uriPrePath = window.location.protocol + "//" + window.location.host;
SpecialPowers.setCharPref(WHITELIST_PREF, uriPrePath);
SpecialPowers.addPermission("mobileconnection", true, document);
let connection = navigator.mozMobileConnection;
ok(connection instanceof MozMobileConnection,
@ -138,7 +136,7 @@ function testHome() {
}
function cleanUp() {
SpecialPowers.clearUserPref(WHITELIST_PREF);
SpecialPowers.removePermission("mobileconnection", document);
finish();
}