mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 11:25:00 +00:00
Backed out changeset 3bfa589adaae (bug 892837) for landing with the wrong bug #.
This commit is contained in:
parent
c51d813f63
commit
3966083bc4
@ -6,8 +6,6 @@ const Cc = Components.classes;
|
|||||||
const Ci = Components.interfaces;
|
const Ci = Components.interfaces;
|
||||||
const Cu = Components.utils;
|
const Cu = Components.utils;
|
||||||
|
|
||||||
const UNKNOWN_FAIL = ["geolocation", "desktop-notification"];
|
|
||||||
|
|
||||||
Cu.import("resource://gre/modules/Services.jsm");
|
Cu.import("resource://gre/modules/Services.jsm");
|
||||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||||
Cu.import("resource://webapprt/modules/WebappRT.jsm");
|
Cu.import("resource://webapprt/modules/WebappRT.jsm");
|
||||||
@ -18,8 +16,25 @@ ContentPermission.prototype = {
|
|||||||
classID: Components.ID("{07ef5b2e-88fb-47bd-8cec-d3b0bef11ac4}"),
|
classID: Components.ID("{07ef5b2e-88fb-47bd-8cec-d3b0bef11ac4}"),
|
||||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPermissionPrompt]),
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPermissionPrompt]),
|
||||||
|
|
||||||
_getChromeWindow: function(aWindow) {
|
prompt: function(request) {
|
||||||
return aWindow
|
// Only handle geolocation requests for now
|
||||||
|
if (request.type != "geolocation") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reuse any remembered permission preferences
|
||||||
|
let result = Services.perms.testExactPermissionFromPrincipal(request.principal, "geo");
|
||||||
|
if (result == Ci.nsIPermissionManager.ALLOW_ACTION) {
|
||||||
|
request.allow();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (result == Ci.nsIPermissionManager.DENY_ACTION) {
|
||||||
|
request.cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getChromeWindow(aWindow) {
|
||||||
|
var chromeWin = aWindow
|
||||||
.QueryInterface(Ci.nsIInterfaceRequestor)
|
.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||||
.getInterface(Ci.nsIWebNavigation)
|
.getInterface(Ci.nsIWebNavigation)
|
||||||
.QueryInterface(Ci.nsIDocShellTreeItem)
|
.QueryInterface(Ci.nsIDocShellTreeItem)
|
||||||
@ -27,74 +42,38 @@ ContentPermission.prototype = {
|
|||||||
.QueryInterface(Ci.nsIInterfaceRequestor)
|
.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||||
.getInterface(Ci.nsIDOMWindow)
|
.getInterface(Ci.nsIDOMWindow)
|
||||||
.QueryInterface(Ci.nsIDOMChromeWindow);
|
.QueryInterface(Ci.nsIDOMChromeWindow);
|
||||||
},
|
return chromeWin;
|
||||||
|
|
||||||
prompt: function(request) {
|
|
||||||
// Reuse any remembered permission preferences
|
|
||||||
let result =
|
|
||||||
Services.perms.testExactPermissionFromPrincipal(request.principal,
|
|
||||||
request.type);
|
|
||||||
|
|
||||||
// We used to use the name "geo" for the geolocation permission, now we're
|
|
||||||
// using "geolocation". We need to check both to support existing
|
|
||||||
// installations.
|
|
||||||
if ((result == Ci.nsIPermissionManager.UNKNOWN_ACTION ||
|
|
||||||
result == Ci.nsIPermissionManager.PROMPT_ACTION) &&
|
|
||||||
request.type == "geolocation") {
|
|
||||||
let geoResult = Services.perms.testExactPermission(request.principal.URI,
|
|
||||||
"geo");
|
|
||||||
// We override the result only if the "geo" permission was allowed or
|
|
||||||
// denied.
|
|
||||||
if (geoResult == Ci.nsIPermissionManager.ALLOW_ACTION ||
|
|
||||||
geoResult == Ci.nsIPermissionManager.DENY_ACTION) {
|
|
||||||
result = geoResult;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result == Ci.nsIPermissionManager.ALLOW_ACTION) {
|
|
||||||
request.allow();
|
|
||||||
return;
|
|
||||||
} else if (result == Ci.nsIPermissionManager.DENY_ACTION ||
|
|
||||||
(result == Ci.nsIPermissionManager.UNKNOWN_ACTION &&
|
|
||||||
UNKNOWN_FAIL.indexOf(request.type) >= 0)) {
|
|
||||||
request.cancel();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display a prompt at the top level
|
// Display a prompt at the top level
|
||||||
let {name} = WebappRT.config.app.manifest;
|
let {name} = WebappRT.config.app.manifest;
|
||||||
let requestingWindow = request.window.top;
|
let requestingWindow = request.window.top;
|
||||||
let chromeWin = this._getChromeWindow(requestingWindow);
|
let chromeWin = getChromeWindow(requestingWindow);
|
||||||
let bundle = Services.strings.createBundle("chrome://webapprt/locale/webapp.properties");
|
let bundle = Services.strings.createBundle("chrome://webapprt/locale/webapp.properties");
|
||||||
|
|
||||||
// Construct a prompt with share/don't and remember checkbox
|
// Construct a prompt with share/don't and remember checkbox
|
||||||
let remember = {value: false};
|
let remember = {value: false};
|
||||||
let choice = Services.prompt.confirmEx(
|
let choice = Services.prompt.confirmEx(
|
||||||
chromeWin,
|
chromeWin,
|
||||||
bundle.formatStringFromName(request.type + ".title", [name], 1),
|
bundle.formatStringFromName("geolocation.title", [name], 1),
|
||||||
bundle.GetStringFromName(request.type + ".description"),
|
bundle.GetStringFromName("geolocation.description"),
|
||||||
// Set both buttons to strings with the cancel button being default
|
// Set both buttons to strings with the cancel button being default
|
||||||
Ci.nsIPromptService.BUTTON_POS_1_DEFAULT |
|
Ci.nsIPromptService.BUTTON_POS_1_DEFAULT |
|
||||||
Ci.nsIPromptService.BUTTON_TITLE_IS_STRING * Ci.nsIPromptService.BUTTON_POS_0 |
|
Ci.nsIPromptService.BUTTON_TITLE_IS_STRING * Ci.nsIPromptService.BUTTON_POS_0 |
|
||||||
Ci.nsIPromptService.BUTTON_TITLE_IS_STRING * Ci.nsIPromptService.BUTTON_POS_1,
|
Ci.nsIPromptService.BUTTON_TITLE_IS_STRING * Ci.nsIPromptService.BUTTON_POS_1,
|
||||||
bundle.GetStringFromName(request.type + ".allow"),
|
bundle.GetStringFromName("geolocation.sharelocation"),
|
||||||
bundle.GetStringFromName(request.type + ".deny"),
|
bundle.GetStringFromName("geolocation.dontshare"),
|
||||||
null,
|
null,
|
||||||
bundle.GetStringFromName(request.type + ".remember"),
|
bundle.GetStringFromName("geolocation.remember"),
|
||||||
remember);
|
remember);
|
||||||
|
|
||||||
|
// Persist the choice if the user wants to remember
|
||||||
|
if (remember.value) {
|
||||||
let action = Ci.nsIPermissionManager.ALLOW_ACTION;
|
let action = Ci.nsIPermissionManager.ALLOW_ACTION;
|
||||||
if (choice != 0) {
|
if (choice != 0) {
|
||||||
action = Ci.nsIPermissionManager.DENY_ACTION;
|
action = Ci.nsIPermissionManager.DENY_ACTION;
|
||||||
}
|
}
|
||||||
|
Services.perms.addFromPrincipal(request.principal, "geo", action);
|
||||||
if (remember.value) {
|
|
||||||
// Persist the choice if the user wants to remember
|
|
||||||
Services.perms.addFromPrincipal(request.principal, request.type, action);
|
|
||||||
} else {
|
|
||||||
// Otherwise allow the permission for the current session
|
|
||||||
Services.perms.addFromPrincipal(request.principal, request.type, action,
|
|
||||||
Ci.nsIPermissionManager.EXPIRE_SESSION);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trigger the selected choice
|
// Trigger the selected choice
|
||||||
|
@ -20,18 +20,10 @@ hideApplicationCmdMac.label=Hide %S
|
|||||||
# the webapp.
|
# the webapp.
|
||||||
geolocation.title=%S - Share Location
|
geolocation.title=%S - Share Location
|
||||||
geolocation.description=Do you want to share your location?
|
geolocation.description=Do you want to share your location?
|
||||||
geolocation.allow=Share Location
|
geolocation.sharelocation=Share Location
|
||||||
geolocation.deny=Don't Share
|
geolocation.dontshare=Don't Share
|
||||||
geolocation.remember=Remember my choice
|
geolocation.remember=Remember my choice
|
||||||
|
|
||||||
# LOCALIZATION NOTE (desktop-notification.title): %S will be replaced with the
|
|
||||||
# name of the webapp.
|
|
||||||
desktop-notification.title=%S - Show notifications
|
|
||||||
desktop-notification.description=Do you want to allow notifications?
|
|
||||||
desktop-notification.allow=Show
|
|
||||||
desktop-notification.deny=Don't show
|
|
||||||
desktop-notification.remember=Remember my choice
|
|
||||||
|
|
||||||
# LOCALIZATION NOTE (webapps.install.title): %S will be replaced with the name
|
# LOCALIZATION NOTE (webapps.install.title): %S will be replaced with the name
|
||||||
# of the webapp being installed.
|
# of the webapp being installed.
|
||||||
webapps.install.title=Install %S
|
webapps.install.title=Install %S
|
||||||
|
Loading…
Reference in New Issue
Block a user