Bug 588305 - Convert offline storage notifications to a doorhanger panel. r=MattN
authorMark Hammond <mhammond@skippinet.com.au>
Mon, 29 Apr 2013 17:38:53 +1000
changeset 141144 ea5490a3bca7f8119595e045aec896b8168def53
parent 141143 3b3d66182d26817017b922bb9d22a40f0cf04af2
child 141145 082445b83eba1134f01a1e6d1110c68b41987a5b
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN
bugs588305
milestone23.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 588305 - Convert offline storage notifications to a doorhanger panel. r=MattN
browser/base/content/browser.js
browser/base/content/test/test_offlineNotification.html
browser/base/content/test/test_offline_gzip.html
browser/themes/linux/browser.css
browser/themes/osx/browser.css
browser/themes/windows/browser.css
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -5625,73 +5625,69 @@ var OfflineApps = {
     return false;
   },
 
   offlineAppRequested: function(aContentWindow) {
     if (!gPrefService.getBoolPref("browser.offline-apps.notify")) {
       return;
     }
 
-    var browserWindow = this._getBrowserWindowForContentWindow(aContentWindow);
-    var browser = this._getBrowserForContentWindow(browserWindow,
+    let browserWindow = this._getBrowserWindowForContentWindow(aContentWindow);
+    let browser = this._getBrowserForContentWindow(browserWindow,
                                                    aContentWindow);
 
-    var currentURI = aContentWindow.document.documentURIObject;
+    let currentURI = aContentWindow.document.documentURIObject;
 
     // don't bother showing UI if the user has already made a decision
     if (Services.perms.testExactPermission(currentURI, "offline-app") != Services.perms.UNKNOWN_ACTION)
       return;
 
     try {
       if (gPrefService.getBoolPref("offline-apps.allow_by_default")) {
         // all pages can use offline capabilities, no need to ask the user
         return;
       }
     } catch(e) {
       // this pref isn't set by default, ignore failures
     }
 
-    var host = currentURI.asciiHost;
-    var notificationBox = gBrowser.getNotificationBox(browser);
-    var notificationID = "offline-app-requested-" + host;
-    var notification = notificationBox.getNotificationWithValue(notificationID);
+    let host = currentURI.asciiHost;
+    let notificationID = "offline-app-requested-" + host;
+    let notification = PopupNotifications.getNotification(notificationID, browser);
 
     if (notification) {
-      notification.documents.push(aContentWindow.document);
+      notification.options.documents.push(aContentWindow.document);
     } else {
-      var buttons = [{
+      let mainAction = {
         label: gNavigatorBundle.getString("offlineApps.allow"),
         accessKey: gNavigatorBundle.getString("offlineApps.allowAccessKey"),
         callback: function() {
-          for (let document of notification.documents) {
+          for (let document of notification.options.documents) {
             OfflineApps.allowSite(document);
           }
         }
-      },{
+      };
+      let secondaryActions = [{
         label: gNavigatorBundle.getString("offlineApps.never"),
         accessKey: gNavigatorBundle.getString("offlineApps.neverAccessKey"),
         callback: function() {
-          for (let document of notification.documents) {
+          for (let document of notification.options.documents) {
             OfflineApps.disallowSite(document);
           }
         }
-      },{
-        label: gNavigatorBundle.getString("offlineApps.notNow"),
-        accessKey: gNavigatorBundle.getString("offlineApps.notNowAccessKey"),
-        callback: function() { /* noop */ }
       }];
-
-      const priority = notificationBox.PRIORITY_INFO_LOW;
-      var message = gNavigatorBundle.getFormattedString("offlineApps.available",
+      let message = gNavigatorBundle.getFormattedString("offlineApps.available",
                                                         [ host ]);
-      notification =
-        notificationBox.appendNotification(message, notificationID,
-                                           "chrome://browser/skin/Info.png",
-                                           priority, buttons);
-      notification.documents = [ aContentWindow.document ];
+      let anchorID = "indexedDB-notification-icon";
+      let options= {
+        documents : [ aContentWindow.document ]
+      };
+      notification = PopupNotifications.show(browser, notificationID, message,
+                                             anchorID, mainAction,
+                                             secondaryActions, options);
     }
   },
 
   allowSite: function(aDocument) {
     Services.perms.add(aDocument.documentURIObject, "offline-app", Services.perms.ALLOW_ACTION);
 
     // When a site is enabled while loading, manifest resources will
     // start fetching immediately.  This one time we need to do it
--- a/browser/base/content/test/test_offlineNotification.html
+++ b/browser/base/content/test/test_offlineNotification.html
@@ -100,28 +100,27 @@ function testEventHandling() {
   w.applicationCache.removeEventListener(expectedEvent, eventHandler, true);
   w.applicationCache.dispatchEvent(e);
   is(count, 1, "Wrong number events!");
 }
 
 function loaded() {
   testEventHandling();
 
-  // Click the notification bar's "Allow" button.  This should kick
+  // Click the notification panel's "Allow" button.  This should kick
   // off updates, which will eventually lead to getting messages from
   // the children.
   var wm = SpecialPowers.Cc["@mozilla.org/appshell/window-mediator;1"].
            getService(SpecialPowers.Ci.nsIWindowMediator);
   var win = wm.getMostRecentWindow("navigator:browser");
-  var notificationBox = win.gBrowser.getNotificationBox();
+  var panel = win.PopupNotifications.panel;
+  is(panel.childElementCount, 2, "2 notifications being displayed");
+  panel.firstElementChild.button.click();
 
-  var notification = notificationBox.getNotificationWithValue("offline-app-requested-mochi.test");
-  notification.childNodes[0].click();
-
-  notification = SpecialPowers.wrap(notificationBox).getNotificationWithValue("offline-app-requested-example.com");
-  notification.childNodes[0].click();
+  // should have dismissed one of the notifications.
+  is(panel.childElementCount, 1, "1 notification now being displayed");
+  panel.firstElementChild.button.click();
 }
 
 </script>
 </pre>
 </body>
 </html>
-
--- a/browser/base/content/test/test_offline_gzip.html
+++ b/browser/base/content/test/test_offline_gzip.html
@@ -91,26 +91,22 @@ function handleMessageEvents(event) {
       break;
     default:
       // how'd we get here?
       ok(false, "cacheCount not 1 or 2");
   }
 }
 
 function loaded() {
-  // Click the notification bar's "Allow" button.  This should kick
+  // Click the notification panel's "Allow" button.  This should kick
   // off updates, which will eventually lead to getting messages from
   // the iframe.
   var wm = SpecialPowers.Cc["@mozilla.org/appshell/window-mediator;1"].
            getService(SpecialPowers.Ci.nsIWindowMediator);
   var win = wm.getMostRecentWindow("navigator:browser");
-  var notificationBox = win.gBrowser.getNotificationBox();
-
-  var notification = notificationBox
-    .getNotificationWithValue("offline-app-requested-mochi.test");
-  notification.childNodes[0].click();
+  var panel = win.PopupNotifications.panel;
+  panel.firstElementChild.button.click();
 }
 
 </script>
 </pre>
 </body>
 </html>
-
--- a/browser/themes/linux/browser.css
+++ b/browser/themes/linux/browser.css
@@ -1184,17 +1184,18 @@ toolbar[iconsize="small"] #webrtc-status
   margin: 0;
   -moz-margin-start: 5px;
   min-height: 0;
   min-width: 0;
   list-style-image: url("moz-icon://stock/gtk-cancel?size=menu");
 }
 
 .popup-notification-icon[popupid="indexedDB-permissions-prompt"],
-.popup-notification-icon[popupid="indexedDB-quota-prompt"] {
+.popup-notification-icon[popupid="indexedDB-quota-prompt"],
+.popup-notification-icon[popupid*="offline-app-requested"] {
   list-style-image: url(chrome://global/skin/icons/question-64.png);
 }
 
 .popup-notification-icon[popupid="password-save"],
 .popup-notification-icon[popupid="password-change"] {
   list-style-image: url(chrome://mozapps/skin/passwordmgr/key-64.png);
 }
 
@@ -2340,9 +2341,8 @@ chatbox {
 }
 
 #main-window[privatebrowsingmode=temporary] #TabsToolbar::before {
   display: -moz-box;
   content: "";
   background: url("chrome://browser/skin/privatebrowsing-mask.png") center no-repeat;
   width: 40px;
 }
-
--- a/browser/themes/osx/browser.css
+++ b/browser/themes/osx/browser.css
@@ -3245,17 +3245,18 @@ toolbarbutton.chevron > .toolbarbutton-m
   -moz-image-region: rect(0px, 32px, 16px, 16px);
 }
 
 .popup-progress-cancel:active {
   -moz-image-region: rect(0px, 48px, 16px, 32px);
 }
 
 .popup-notification-icon[popupid="indexedDB-permissions-prompt"],
-.popup-notification-icon[popupid="indexedDB-quota-prompt"] {
+.popup-notification-icon[popupid="indexedDB-quota-prompt"],
+.popup-notification-icon[popupid*="offline-app-requested"] {
   list-style-image: url(chrome://global/skin/icons/question-64.png);
 }
 
 .popup-notification-icon[popupid="password-save"],
 .popup-notification-icon[popupid="password-change"] {
   list-style-image: url(chrome://mozapps/skin/passwordmgr/key-64.png);
 }
 
@@ -3969,10 +3970,8 @@ panel[type="arrow"][popupid="click-to-pl
   #main-window[privatebrowsingmode=temporary] {
     background-position: top right 10px;
   }
 
   #main-window[privatebrowsingmode=temporary][inFullscreen][tabsontop=true] #window-controls {
     -moz-padding-end: 50px;
   }
 }
-
-
--- a/browser/themes/windows/browser.css
+++ b/browser/themes/windows/browser.css
@@ -2358,17 +2358,18 @@ toolbarbutton.bookmark-item[dragover="tr
   -moz-image-region: rect(16px, 32px, 32px, 16px);
 }
 
 .popup-progress-cancel:active {
   -moz-image-region: rect(32px, 32px, 48px, 16px);
 }
 
 .popup-notification-icon[popupid="indexedDB-permissions-prompt"],
-.popup-notification-icon[popupid="indexedDB-quota-prompt"] {
+.popup-notification-icon[popupid="indexedDB-quota-prompt"],
+.popup-notification-icon[popupid*="offline-app-requested"] {
   list-style-image: url(chrome://global/skin/icons/question-64.png);
 }
 
 .popup-notification-icon[popupid="password-save"],
 .popup-notification-icon[popupid="password-change"] {
   list-style-image: url(chrome://mozapps/skin/passwordmgr/key-64.png);
 }
 
@@ -3067,9 +3068,8 @@ chatbox {
   background-position: top left;
 }
 
 #main-window[privatebrowsingmode=temporary] #appmenu-button > .button-box > .box-inherit > .button-icon {
   list-style-image: url("chrome://browser/skin/privatebrowsing-light.png");
   width: 20px;
   height: 16px;
 }
-