Bug 779378: B2G Voicemail: Hook up to permissions manager; r=gwagner

This commit is contained in:
Kyle Machulis 2012-08-23 16:31:02 -07:00
Родитель f4c2eb9bc2
Коммит 1004044a0d
3 изменённых файлов: 15 добавлений и 19 удалений

Просмотреть файл

@ -1138,20 +1138,20 @@ Navigator::GetMozVoicemail(nsIDOMMozVoicemail** aVoicemail)
if (!mVoicemail) { if (!mVoicemail) {
nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mWindow); 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 nsCOMPtr<nsIDocument> document = do_QueryInterface(window->GetExtantDocument());
// for non-chrome pages. NS_ENSURE_TRUE(document, NS_OK);
if (!nsContentUtils::IsCallerChrome()) { nsCOMPtr<nsIPrincipal> principal = document->NodePrincipal();
nsCOMPtr<nsIDocument> doc = do_QueryInterface(window->GetExtantDocument()); nsCOMPtr<nsIPermissionManager> permMgr =
NS_ENSURE_TRUE(doc, NS_OK); do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
NS_ENSURE_TRUE(permMgr, NS_OK);
nsCOMPtr<nsIURI> uri; PRUint32 permission = nsIPermissionManager::DENY_ACTION;
doc->NodePrincipal()->GetURI(getter_AddRefs(uri)); permMgr->TestPermissionFromPrincipal(principal, "voicemail", &permission);
if (!nsContentUtils::URIIsChromeOrInPref(uri, "dom.voicemail.whitelist")) { if (permission != nsIPermissionManager::ALLOW_ACTION) {
return NS_OK; return NS_OK;
}
} }
nsresult rv = NS_NewVoicemail(window, getter_AddRefs(mVoicemail)); nsresult rv = NS_NewVoicemail(window, getter_AddRefs(mVoicemail));

Просмотреть файл

@ -3,9 +3,7 @@
MARIONETTE_TIMEOUT = 10000; MARIONETTE_TIMEOUT = 10000;
const WHITELIST_PREF = "dom.voicemail.whitelist"; SpecialPowers.addPermission("voicemail", true, document);
let uriPrePath = window.location.protocol + "//" + window.location.host;
SpecialPowers.setCharPref(WHITELIST_PREF, uriPrePath);
let voicemail = window.navigator.mozVoicemail; let voicemail = window.navigator.mozVoicemail;
ok(voicemail instanceof MozVoicemail); ok(voicemail instanceof MozVoicemail);
@ -14,5 +12,5 @@ ok(voicemail instanceof MozVoicemail);
is(voicemail.number, "+15552175049"); is(voicemail.number, "+15552175049");
is(voicemail.displayName, "Voicemail"); is(voicemail.displayName, "Voicemail");
SpecialPowers.clearUserPref(WHITELIST_PREF); SpecialPowers.removePermission("voicemail", document);
finish(); finish();

Просмотреть файл

@ -1,9 +1,7 @@
/* Any copyright is dedicated to the Public Domain. /* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */ * http://creativecommons.org/publicdomain/zero/1.0/ */
const WHITELIST_PREF = "dom.voicemail.whitelist"; SpecialPowers.addPermission("voicemail", true, document);
let uriPrePath = window.location.protocol + "//" + window.location.host;
SpecialPowers.setCharPref(WHITELIST_PREF, uriPrePath);
let voicemail = window.navigator.mozVoicemail; let voicemail = window.navigator.mozVoicemail;
ok(voicemail instanceof MozVoicemail); ok(voicemail instanceof MozVoicemail);
@ -222,7 +220,7 @@ function testLevel3DiscardInactive() {
} }
function cleanUp() { function cleanUp() {
SpecialPowers.clearUserPref(WHITELIST_PREF); SpecialPowers.removePermission("voicemail", document);
finish(); finish();
} }