Bug 1203233 implement geolocation permission, r=aswan,florian

MozReview-Commit-ID: 8V7bNyeGZNh

--HG--
extra : rebase_source : 9b67f0b004ae64444fc73019e971aa8b068a0dc2
This commit is contained in:
Shane Caraveo 2017-02-04 16:10:50 -08:00
Родитель 467786d86a
Коммит eef34ca89d
9 изменённых файлов: 132 добавлений и 9 удалений

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

@ -83,6 +83,7 @@ webextPerms.updateAccept.accessKey=U
webextPerms.description.bookmarks=Read and modify bookmarks
webextPerms.description.downloads=Download files and read and modify the browsers download history
webextPerms.description.geolocation=Access your location
webextPerms.description.history=Access browsing history
# LOCALIZATION NOTE (webextPerms.description.nativeMessaging)
# %S will be replaced with the name of the application

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

@ -246,16 +246,11 @@ this.PermissionPromptPrototype = {
* allow or cancel itself based on the user's current
* permission settings without displaying the prompt.
*
* If the <xul:browser> that the request is associated with
* does not belong to a browser window with the PopupNotifications
* global set, the prompt request is ignored.
* If the permission is not already set and the <xul:browser> that the request
* is associated with does not belong to a browser window with the
* PopupNotifications global set, the prompt request is ignored.
*/
prompt() {
let chromeWin = this.browser.ownerGlobal;
if (!chromeWin.PopupNotifications) {
return;
}
// We ignore requests from non-nsIStandardURLs
let requestingURI = this.principal.URI;
if (!(requestingURI instanceof Ci.nsIStandardURL)) {
@ -286,6 +281,12 @@ this.PermissionPromptPrototype = {
.CustomEvent("PermissionStateChange"));
}
let chromeWin = this.browser.ownerGlobal;
if (!chromeWin.PopupNotifications) {
this.cancel();
return;
}
// Transform the PermissionPrompt actions into PopupNotification actions.
let popupNotificationActions = [];
for (let promptAction of this.promptActions) {

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

@ -252,7 +252,7 @@ this.SitePermissions = {
* @return {boolean} if the URI is supported.
*/
isSupportedURI(uri) {
return uri && (uri.schemeIs("http") || uri.schemeIs("https"));
return uri && ["http", "https", "moz-extension"].includes(uri.scheme);
},
/**

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

@ -0,0 +1,28 @@
"use strict";
const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
XPCOMUtils.defineLazyModuleGetter(this, "Services",
"resource://gre/modules/Services.jsm");
// If the user has changed the permission on the addon to something other than
// always allow, then we want to preserve that choice. We only set the
// permission if it is not set (unknown_action), and we only remove the
// permission on shutdown if it is always allow.
/* eslint-disable mozilla/balanced-listeners */
extensions.on("startup", (type, extension) => {
if (extension.hasPermission("geolocation") &&
Services.perms.testPermission(extension.principal.URI, "geo") == Services.perms.UNKNOWN_ACTION) {
Services.perms.add(extension.principal.URI, "geo",
Services.perms.ALLOW_ACTION,
Services.perms.EXPIRE_SESSION);
}
});
extensions.on("shutdown", (type, extension) => {
if (extension.hasPermission("geolocation") &&
Services.perms.testPermission(extension.principal.URI, "geo") == Services.perms.ALLOW_ACTION) {
Services.perms.remove(extension.principal.URI, "geo");
}
});

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

@ -4,6 +4,7 @@ category webextension-scripts backgroundPage chrome://extensions/content/ext-bac
category webextension-scripts contextualIdentities chrome://extensions/content/ext-contextualIdentities.js
category webextension-scripts cookies chrome://extensions/content/ext-cookies.js
category webextension-scripts downloads chrome://extensions/content/ext-downloads.js
category webextension-scripts geolocation chrome://extensions/content/ext-geolocation.js
category webextension-scripts management chrome://extensions/content/ext-management.js
category webextension-scripts notifications chrome://extensions/content/ext-notifications.js
category webextension-scripts i18n chrome://extensions/content/ext-i18n.js

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

@ -10,6 +10,7 @@ toolkit.jar:
content/extensions/ext-contextualIdentities.js
content/extensions/ext-cookies.js
content/extensions/ext-downloads.js
content/extensions/ext-geolocation.js
content/extensions/ext-management.js
content/extensions/ext-notifications.js
content/extensions/ext-i18n.js

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

@ -212,6 +212,7 @@
"enum": [
"alarms",
"clipboardWrite",
"geolocation",
"idle",
"notifications",
"storage"

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

@ -40,6 +40,7 @@ support-files =
return_headers.sjs
webrequest_worker.js
!/toolkit/components/passwordmgr/test/authenticate.sjs
!/dom/tests/mochitest/geolocation/network_geolocation.sjs
[test_clipboard.html]
# skip-if = # disabled test case with_permission_allow_copy, see inline comment.
@ -64,6 +65,8 @@ skip-if = os == 'android' # Android does not support multiple windows.
[test_ext_exclude_include_globs.html]
[test_ext_i18n_css.html]
[test_ext_generate.html]
[test_ext_geolocation.html]
skip-if = os == 'android' # Android support Bug 1336194
[test_ext_notifications.html]
[test_ext_permission_xhr.html]
[test_ext_runtime_connect.html]

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

@ -0,0 +1,87 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/ExtensionTestUtils.js"></script>
<script type="text/javascript" src="head.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script>
"use strict";
add_task(function* test_geolocation_nopermission() {
let GEO_URL = "http://mochi.test:8888/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs";
yield SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", GEO_URL]]});
});
add_task(function* test_geolocation() {
let extension = ExtensionTestUtils.loadExtension({
manifest: {
permissions: [
"geolocation",
],
},
background() {
navigator.geolocation.getCurrentPosition(() => {
browser.test.notifyPass("success geolocation call");
}, (error) => {
browser.test.notifyFail(`geolocation call ${error}`);
});
},
});
yield extension.startup();
yield extension.awaitFinish();
yield extension.unload();
});
add_task(function* test_geolocation_nopermission() {
let extension = ExtensionTestUtils.loadExtension({
background() {
navigator.geolocation.getCurrentPosition(() => {
browser.test.notifyFail("success geolocation call");
}, (error) => {
browser.test.notifyPass(`geolocation call ${error}`);
});
},
});
yield extension.startup();
yield extension.awaitFinish();
yield extension.unload();
});
add_task(function* test_geolocation_prompt() {
let extension = ExtensionTestUtils.loadExtension({
background() {
browser.tabs.create({url: "tab.html"});
},
files: {
"tab.html": `<html><head>
<meta charset="utf-8">
<script src="tab.js"><\/script>
</head></html>`,
"tab.js": () => {
navigator.geolocation.getCurrentPosition(() => {
browser.test.notifyPass("success geolocation call");
}, (error) => {
browser.test.notifyFail(`geolocation call ${error}`);
});
},
},
});
// Bypass the actual prompt, but the prompt result is to allow access.
yield SpecialPowers.pushPrefEnv({"set": [["geo.prompt.testing", true], ["geo.prompt.testing.allow", true]]});
yield extension.startup();
yield extension.awaitFinish();
yield extension.unload();
});
</script>
</head>
<body>
</body>
</html>