зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1203233 implement geolocation permission, r=aswan,florian
MozReview-Commit-ID: 8V7bNyeGZNh --HG-- extra : rebase_source : 9b67f0b004ae64444fc73019e971aa8b068a0dc2
This commit is contained in:
Родитель
467786d86a
Коммит
eef34ca89d
|
@ -83,6 +83,7 @@ webextPerms.updateAccept.accessKey=U
|
||||||
|
|
||||||
webextPerms.description.bookmarks=Read and modify bookmarks
|
webextPerms.description.bookmarks=Read and modify bookmarks
|
||||||
webextPerms.description.downloads=Download files and read and modify the browser’s download history
|
webextPerms.description.downloads=Download files and read and modify the browser’s download history
|
||||||
|
webextPerms.description.geolocation=Access your location
|
||||||
webextPerms.description.history=Access browsing history
|
webextPerms.description.history=Access browsing history
|
||||||
# LOCALIZATION NOTE (webextPerms.description.nativeMessaging)
|
# LOCALIZATION NOTE (webextPerms.description.nativeMessaging)
|
||||||
# %S will be replaced with the name of the application
|
# %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
|
* allow or cancel itself based on the user's current
|
||||||
* permission settings without displaying the prompt.
|
* permission settings without displaying the prompt.
|
||||||
*
|
*
|
||||||
* If the <xul:browser> that the request is associated with
|
* If the permission is not already set and the <xul:browser> that the request
|
||||||
* does not belong to a browser window with the PopupNotifications
|
* is associated with does not belong to a browser window with the
|
||||||
* global set, the prompt request is ignored.
|
* PopupNotifications global set, the prompt request is ignored.
|
||||||
*/
|
*/
|
||||||
prompt() {
|
prompt() {
|
||||||
let chromeWin = this.browser.ownerGlobal;
|
|
||||||
if (!chromeWin.PopupNotifications) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We ignore requests from non-nsIStandardURLs
|
// We ignore requests from non-nsIStandardURLs
|
||||||
let requestingURI = this.principal.URI;
|
let requestingURI = this.principal.URI;
|
||||||
if (!(requestingURI instanceof Ci.nsIStandardURL)) {
|
if (!(requestingURI instanceof Ci.nsIStandardURL)) {
|
||||||
|
@ -286,6 +281,12 @@ this.PermissionPromptPrototype = {
|
||||||
.CustomEvent("PermissionStateChange"));
|
.CustomEvent("PermissionStateChange"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let chromeWin = this.browser.ownerGlobal;
|
||||||
|
if (!chromeWin.PopupNotifications) {
|
||||||
|
this.cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Transform the PermissionPrompt actions into PopupNotification actions.
|
// Transform the PermissionPrompt actions into PopupNotification actions.
|
||||||
let popupNotificationActions = [];
|
let popupNotificationActions = [];
|
||||||
for (let promptAction of this.promptActions) {
|
for (let promptAction of this.promptActions) {
|
||||||
|
|
|
@ -252,7 +252,7 @@ this.SitePermissions = {
|
||||||
* @return {boolean} if the URI is supported.
|
* @return {boolean} if the URI is supported.
|
||||||
*/
|
*/
|
||||||
isSupportedURI(uri) {
|
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 contextualIdentities chrome://extensions/content/ext-contextualIdentities.js
|
||||||
category webextension-scripts cookies chrome://extensions/content/ext-cookies.js
|
category webextension-scripts cookies chrome://extensions/content/ext-cookies.js
|
||||||
category webextension-scripts downloads chrome://extensions/content/ext-downloads.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 management chrome://extensions/content/ext-management.js
|
||||||
category webextension-scripts notifications chrome://extensions/content/ext-notifications.js
|
category webextension-scripts notifications chrome://extensions/content/ext-notifications.js
|
||||||
category webextension-scripts i18n chrome://extensions/content/ext-i18n.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-contextualIdentities.js
|
||||||
content/extensions/ext-cookies.js
|
content/extensions/ext-cookies.js
|
||||||
content/extensions/ext-downloads.js
|
content/extensions/ext-downloads.js
|
||||||
|
content/extensions/ext-geolocation.js
|
||||||
content/extensions/ext-management.js
|
content/extensions/ext-management.js
|
||||||
content/extensions/ext-notifications.js
|
content/extensions/ext-notifications.js
|
||||||
content/extensions/ext-i18n.js
|
content/extensions/ext-i18n.js
|
||||||
|
|
|
@ -212,6 +212,7 @@
|
||||||
"enum": [
|
"enum": [
|
||||||
"alarms",
|
"alarms",
|
||||||
"clipboardWrite",
|
"clipboardWrite",
|
||||||
|
"geolocation",
|
||||||
"idle",
|
"idle",
|
||||||
"notifications",
|
"notifications",
|
||||||
"storage"
|
"storage"
|
||||||
|
|
|
@ -40,6 +40,7 @@ support-files =
|
||||||
return_headers.sjs
|
return_headers.sjs
|
||||||
webrequest_worker.js
|
webrequest_worker.js
|
||||||
!/toolkit/components/passwordmgr/test/authenticate.sjs
|
!/toolkit/components/passwordmgr/test/authenticate.sjs
|
||||||
|
!/dom/tests/mochitest/geolocation/network_geolocation.sjs
|
||||||
|
|
||||||
[test_clipboard.html]
|
[test_clipboard.html]
|
||||||
# skip-if = # disabled test case with_permission_allow_copy, see inline comment.
|
# 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_exclude_include_globs.html]
|
||||||
[test_ext_i18n_css.html]
|
[test_ext_i18n_css.html]
|
||||||
[test_ext_generate.html]
|
[test_ext_generate.html]
|
||||||
|
[test_ext_geolocation.html]
|
||||||
|
skip-if = os == 'android' # Android support Bug 1336194
|
||||||
[test_ext_notifications.html]
|
[test_ext_notifications.html]
|
||||||
[test_ext_permission_xhr.html]
|
[test_ext_permission_xhr.html]
|
||||||
[test_ext_runtime_connect.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>
|
Загрузка…
Ссылка в новой задаче