Bug 1350053 - Part 1 - Change install flow of Light-weight Themes (LWT) to use PopupNotifications, instead of notification boxes. r?Mossop draft
authorMike de Boer <mdeboer@mozilla.com>
Mon, 10 Apr 2017 16:16:50 +0200
changeset 559828 8410268415950306be9ac5a046b84bfff46e4ad6
parent 559608 731639fccc709a4dd95fed7e9dda88efb2227906
child 559829 a447797110ad53f3c51522321d1454d29189ca15
push id53232
push usermdeboer@mozilla.com
push dateMon, 10 Apr 2017 17:42:36 +0000
reviewersMossop
bugs1350053
milestone55.0a1
Bug 1350053 - Part 1 - Change install flow of Light-weight Themes (LWT) to use PopupNotifications, instead of notification boxes. r?Mossop The newer Theming API follows the WebExtension install flow, which uses PopupNotifications to request permission before installation, show progress and notify upon install completion. This patch makes sure that older LWTs follow that same flow. MozReview-Commit-ID: C7X2si0a47J
browser/base/content/browser-addons.js
browser/locales/en-US/chrome/browser/browser.properties
--- a/browser/base/content/browser-addons.js
+++ b/browser/base/content/browser-addons.js
@@ -637,44 +637,35 @@ var LightWeightThemeWebInstaller = {
       }
     }
 
     if (this._isAllowed(baseURI)) {
       this._install(data, notify);
       return;
     }
 
-    let allowButtonText =
-      gNavigatorBundle.getString("lwthemeInstallRequest.allowButton");
-    let allowButtonAccesskey =
-      gNavigatorBundle.getString("lwthemeInstallRequest.allowButton.accesskey");
-    let message =
-      gNavigatorBundle.getFormattedString("lwthemeInstallRequest.message",
-                                          [uri.host]);
-    let buttons = [{
-      label: allowButtonText,
-      accessKey: allowButtonAccesskey,
-      callback() {
+    let strings = {
+      header: gNavigatorBundle.getFormattedString("webextPerms.header", [data.name]),
+      text: gNavigatorBundle.getFormattedString("lwthemeInstallRequest.message2",
+                                                [uri.host]),
+      acceptText: gNavigatorBundle.getString("lwthemeInstallRequest.allowButton2"),
+      acceptKey: gNavigatorBundle.getString("lwthemeInstallRequest.allowButton.accesskey2"),
+      cancelText: gNavigatorBundle.getString("webextPerms.cancel.label"),
+      cancelKey: gNavigatorBundle.getString("webextPerms.cancel.accessKey"),
+      msgs: []
+    };
+    ExtensionsUI.showPermissionsPrompt(gBrowser.selectedBrowser, strings, null,
+      "installWeb").then(answer => {
+      if (answer) {
         LightWeightThemeWebInstaller._install(data, notify);
       }
-    }];
-
-    this._removePreviousNotifications();
-
-    let notificationBox = gBrowser.getNotificationBox();
-    let notificationBar =
-      notificationBox.appendNotification(message, "lwtheme-install-request", "",
-                                         notificationBox.PRIORITY_INFO_MEDIUM,
-                                         buttons);
-    notificationBar.persistence = 1;
+    });
   },
 
   _install(newLWTheme, notify) {
-    let previousLWTheme = this._manager.currentTheme;
-
     let listener = {
       onEnabling(aAddon, aRequiresRestart) {
         if (!aRequiresRestart) {
           return;
         }
 
         let messageString = gNavigatorBundle.getFormattedString("lwthemeNeedsRestart.message",
           [aAddon.name], 1);
@@ -693,69 +684,26 @@ var LightWeightThemeWebInstaller = {
 
         PopupNotifications.show(gBrowser.selectedBrowser, "addon-theme-change",
                                 messageString, "addons-notification-icon",
                                 action, null, options);
       },
 
       onEnabled(aAddon) {
         if (notify) {
-          LightWeightThemeWebInstaller._postInstallNotification(newLWTheme, previousLWTheme);
+          ExtensionsUI.showInstallNotification(gBrowser.selectedBrowser, newLWTheme);
         }
       }
     };
 
     AddonManager.addAddonListener(listener);
     this._manager.currentTheme = newLWTheme;
     AddonManager.removeAddonListener(listener);
   },
 
-  _postInstallNotification(newTheme, previousTheme) {
-    function text(id) {
-      return gNavigatorBundle.getString("lwthemePostInstallNotification." + id);
-    }
-
-    let buttons = [{
-      label: text("undoButton"),
-      accessKey: text("undoButton.accesskey"),
-      callback() {
-        LightWeightThemeWebInstaller._manager.forgetUsedTheme(newTheme.id);
-        LightWeightThemeWebInstaller._manager.currentTheme = previousTheme;
-      }
-    }, {
-      label: text("manageButton"),
-      accessKey: text("manageButton.accesskey"),
-      callback() {
-        BrowserOpenAddonsMgr("addons://list/theme");
-      }
-    }];
-
-    this._removePreviousNotifications();
-
-    let notificationBox = gBrowser.getNotificationBox();
-    let notificationBar =
-      notificationBox.appendNotification(text("message"),
-                                         "lwtheme-install-notification", "",
-                                         notificationBox.PRIORITY_INFO_MEDIUM,
-                                         buttons);
-    notificationBar.persistence = 1;
-    notificationBar.timeout = Date.now() + 20000; // 20 seconds
-  },
-
-  _removePreviousNotifications() {
-    let box = gBrowser.getNotificationBox();
-
-    ["lwtheme-install-request",
-     "lwtheme-install-notification"].forEach(function(value) {
-        let notification = box.getNotificationWithValue(value);
-        if (notification)
-          box.removeNotification(notification);
-      });
-  },
-
   _preview(dataString, baseURI) {
     if (!this._isAllowed(baseURI))
       return;
 
     let data = this._manager.parseTheme(dataString, baseURI);
     if (!data)
       return;
 
--- a/browser/locales/en-US/chrome/browser/browser.properties
+++ b/browser/locales/en-US/chrome/browser/browser.properties
@@ -217,27 +217,21 @@ unsignedAddonsDisabled.learnMore.accessk
 # LOCALIZATION NOTE (compactLightTheme.name): This is displayed in about:addons -> Appearance
 compactLightTheme.name=Compact Light
 compactLightTheme.description=A compact theme with a light color scheme.
 
 # LOCALIZATION NOTE (compactDarkTheme.name): This is displayed in about:addons -> Appearance
 compactDarkTheme.name=Compact Dark
 compactDarkTheme.description=A compact theme with a dark color scheme.
 
-# LOCALIZATION NOTE (lwthemeInstallRequest.message): %S will be replaced with
+# LOCALIZATION NOTE (lwthemeInstallRequest.message2): %S will be replaced with
 # the host name of the site.
-lwthemeInstallRequest.message=This site (%S) attempted to install a theme.
-lwthemeInstallRequest.allowButton=Allow
-lwthemeInstallRequest.allowButton.accesskey=a
-
-lwthemePostInstallNotification.message=A new theme has been installed.
-lwthemePostInstallNotification.undoButton=Undo
-lwthemePostInstallNotification.undoButton.accesskey=U
-lwthemePostInstallNotification.manageButton=Manage Themes…
-lwthemePostInstallNotification.manageButton.accesskey=M
+lwthemeInstallRequest.message2=This site (%S) attempted to install a theme.
+lwthemeInstallRequest.allowButton2=Allow
+lwthemeInstallRequest.allowButton.accesskey2=a
 
 # LOCALIZATION NOTE (lwthemeNeedsRestart.message):
 # %S will be replaced with the new theme name.
 lwthemeNeedsRestart.message=%S will be installed after you restart.
 lwthemeNeedsRestart.button=Restart Now
 lwthemeNeedsRestart.accesskey=R
 
 # LOCALIZATION NOTE (popupWarning.message): Semicolon-separated list of plural forms.