Bug 1259148 - Allow the user to restore the doorhanger using the icon. draft
authorKit Cambridge <kcambridge@mozilla.com>
Thu, 21 Apr 2016 17:05:14 -0700
changeset 355175 2302af099ff3073f01939a52d8614acfd57bfb17
parent 355174 7b8a8b25711d7a4669115b00a2f23cb87b584ddf
child 519131 cc4e4ea454e4171e94226fb9c47a05b57a9673ff
push id16215
push userkcambridge@mozilla.com
push dateFri, 22 Apr 2016 00:22:17 +0000
bugs1259148
milestone48.0a1
Bug 1259148 - Allow the user to restore the doorhanger using the icon. MozReview-Commit-ID: B6fcURu8oiM
browser/components/nsBrowserGlue.js
--- 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");