Bug 1259148 - Allow the user to restore the doorhanger using the icon.
MozReview-Commit-ID: B6fcURu8oiM
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -2581,17 +2581,35 @@ ContentPermissionPrompt.prototype = {
"geo-notification-icon", options);
},
_promptWebNotifications : function(aRequest) {
var message = gBrowserBundle.GetStringFromName("webNotifications.receiveFromSite");
var actions;
- var browser = this._getBrowserForRequest(aRequest);
+ // Bug 1259148: Wrap the request in a proxy that ignores multiple `allow`
+ // and `cancel` calls. If the permission doorhanger is dismissed, we notify
+ // the site immediately, but keep the icon in the location bar. If the user
+ // restores the doorhanger and makes a final decision, we store the new
+ // permission, but don't notify the site.
+ var isHandled = false;
+ var requestProxy = new Proxy(aRequest, {
+ get(target, property) {
+ if (property == "allow" || property == "cancel") {
+ if (isHandled) {
+ return function() {};
+ }
+ isHandled = true;
+ }
+ return Reflect.get(target, property);
+ },
+ });
+
+ var browser = this._getBrowserForRequest(requestProxy);
// Only show "allow for session" in PB mode, we don't
// support "allow for session" in non-PB mode.
if (PrivateBrowsingUtils.isBrowserPrivate(browser)) {
actions = [
{
stringId: "webNotifications.receiveForSession",
action: Ci.nsIPermissionManager.ALLOW_ACTION,
expireType: Ci.nsIPermissionManager.EXPIRE_SESSION,
@@ -2615,27 +2633,23 @@ ContentPermissionPrompt.prototype = {
];
}
var options = {
learnMoreURL:
Services.urlFormatter.formatURLPref("app.support.baseURL") + "push",
eventCallback(type) {
if (type == "dismissed") {
- // Bug 1259148: Hide the doorhanger icon. Unlike other permission
- // doorhangers, the user can't restore the doorhanger using the icon
- // in the location bar. Instead, the site will be notified that the
- // doorhanger was dismissed.
- this.remove();
- aRequest.cancel();
+ // Bug 1259148: Notify the site that the doorhanger was dismissed.
+ requestProxy.cancel();
}
},
};
- this._showPrompt(aRequest, message, "desktop-notification", actions,
+ this._showPrompt(requestProxy, message, "desktop-notification", actions,
"web-notifications",
"web-notifications-notification-icon", options);
},
_promptPointerLock: function CPP_promtPointerLock(aRequest, autoAllow) {
let message = gBrowserBundle.GetStringFromName(autoAllow ?
"pointerLock.autoLock.title3" : "pointerLock.title3");