Bug 1900225: Part 2 - Inform user of system UX issues initiated by geolocation request r=gstoll,emilio,bolsson,pbz

This patch installs the framework for various platforms to inform the user of
one of two things: 1) a coming system dialog asking for system geolocation
permission that will be presented after the Firefox doorhanger asking for
permission for the page, and 2) that we will open a system preferences window,
where the user can enable geolocation for Firefox because it is currently not
enabled.  The code that handles this has been remoted to the parent process
since implementations will not be able to operate in the content process
sandbox.

Here, it stubs the behavior so this does nothing on every platform.
In this patch series, the behavior will be implemented for Windows.

Note: The code will run the geolocation for the page if the user granted it in
Firefox, regardless of whether the user granted or canceled the system
permission.  This respects the user's instruction and provides a work-around in
the event of a bug, although it would usually either fail to get a location or
it will get a very poor one (e.g. via IP lookup).

Differential Revision: https://phabricator.services.mozilla.com/D216473
This commit is contained in:
David P
2024-08-27 22:47:32 +00:00
parent 11d22fb06c
commit cbefd73d45
12 changed files with 476 additions and 14 deletions

View File

@@ -86,6 +86,13 @@ XPCOMUtils.defineLazyServiceGetter(
"@mozilla.org/content-pref/service;1",
"nsIContentPrefService2"
);
ChromeUtils.defineLazyGetter(lazy, "gBrandBundle", function () {
return Services.strings.createBundle(
"chrome://branding/locale/brand.properties"
);
});
ChromeUtils.defineLazyGetter(lazy, "gBrowserBundle", function () {
return Services.strings.createBundle(
"chrome://browser/locale/browser.properties"
@@ -251,6 +258,17 @@ class PermissionPrompt {
throw new Error("Not implemented.");
}
/**
* The hint text to show to the user in the PopupNotification, see
* `PopupNotifications_show` in PopupNotifications.sys.mjs.
* By default, no hint is shown.
*
* @return {string}
*/
get hintText() {
return undefined;
}
/**
* Provides the preferred name to use in the permission popups,
* based on the principal URI (the URI.hostPort for any URI scheme
@@ -607,6 +625,7 @@ class PermissionPrompt {
return false;
};
options.hintText = this.hintText;
// Post-prompts show up as dismissed.
options.dismissed = postPrompt;
@@ -731,6 +750,14 @@ class GeolocationPermissionPrompt extends PermissionPromptForRequest {
constructor(request) {
super();
this.request = request;
let types = request.types.QueryInterface(Ci.nsIArray);
let perm = types.queryElementAt(0, Ci.nsIContentPermissionType);
if (perm.options.length) {
this.systemPermissionMsg = perm.options.queryElementAt(
0,
Ci.nsISupportsString
);
}
}
get type() {
@@ -799,6 +826,26 @@ class GeolocationPermissionPrompt extends PermissionPromptForRequest {
);
}
get hintText() {
let productName = lazy.gBrandBundle.GetStringFromName("brandShortName");
if (this.systemPermissionMsg == "sysdlg") {
return lazy.gBrowserBundle.formatStringFromName(
"geolocation.systemWillRequestPermission",
[productName]
);
}
if (this.systemPermissionMsg == "syssetting") {
return lazy.gBrowserBundle.formatStringFromName(
"geolocation.needsSystemSetting",
[productName]
);
}
return undefined;
}
get promptActions() {
return [
{