Bug 1234148 - Replaced toasts in JS modules with snackbars. r?sebastian draft
authorAlex Johnson <me@alex-johnson.net>
Mon, 21 Dec 2015 11:52:12 -0500
changeset 316738 360fedcd8833d004ed3cbea53e358ebca982307c
parent 316718 6f0ea23659a48af551357799e36859212a8ce3e4
child 316812 0edfe8cd43f75f843ec452d6b28090b3c92a68a5
child 316813 51861ea640508ba8fcc72ac6fb30b636f4acdf1a
push id8597
push usermrjohnsonalex@gmail.com
push dateMon, 21 Dec 2015 20:57:54 +0000
reviewerssebastian
bugs1234148
milestone46.0a1
Bug 1234148 - Replaced toasts in JS modules with snackbars. r?sebastian
mobile/android/chrome/content/ActionBarHandler.js
mobile/android/chrome/content/MasterPassword.js
mobile/android/chrome/content/PrintHelper.js
mobile/android/chrome/content/Reader.js
mobile/android/chrome/content/SelectionHandler.js
mobile/android/chrome/content/WebcompatReporter.js
mobile/android/chrome/content/aboutLogins.js
mobile/android/modules/DownloadNotifications.jsm
--- a/mobile/android/chrome/content/ActionBarHandler.js
+++ b/mobile/android/chrome/content/ActionBarHandler.js
@@ -1,14 +1,16 @@
 // -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 "use strict";
 
+XPCOMUtils.defineLazyModuleGetter(this, "Snackbars", "resource://gre/modules/Snackbars.jsm");
+
 const PHONE_REGEX = /^\+?[0-9\s,-.\(\)*#pw]{1,30}$/; // Are we a phone #?
 
 
 /**
  * ActionBarHandler Object and methods. Interface between Gecko Text Selection code
  * (TouchCaret, SelectionCarets, etc) and the Mobile ActionBar UI.
  */
 var ActionBarHandler = {
@@ -321,17 +323,17 @@ var ActionBarHandler = {
       action: function(element, win) {
         // First copy the selection text to the clipboard.
         let selectedText = ActionBarHandler._getSelectedText();
         let clipboard = Cc["@mozilla.org/widget/clipboardhelper;1"].
           getService(Ci.nsIClipboardHelper);
         clipboard.copyString(selectedText);
 
         let msg = Strings.browser.GetStringFromName("selectionHelper.textCopied");
-        NativeWindow.toast.show(msg, "short");
+        Snackbars.show(msg, Snackbars.LENGTH_SHORT);
 
         // Then cut the selection text.
         ActionBarHandler._getSelection(element, win).deleteFromDocument();
 
         ActionBarHandler._uninit();
         UITelemetry.addEvent("action.1", "actionbar", null, "cut");
       },
     },
@@ -356,17 +358,17 @@ var ActionBarHandler = {
 
       action: function(element, win) {
         let selectedText = ActionBarHandler._getSelectedText();
         let clipboard = Cc["@mozilla.org/widget/clipboardhelper;1"].
           getService(Ci.nsIClipboardHelper);
         clipboard.copyString(selectedText);
 
         let msg = Strings.browser.GetStringFromName("selectionHelper.textCopied");
-        NativeWindow.toast.show(msg, "short");
+        Snackbars.show(msg, Snackbars.LENGTH_SHORT);
 
         ActionBarHandler._uninit();
         UITelemetry.addEvent("action.1", "actionbar", null, "copy");
       },
     },
 
     PASTE: {
       id: "paste_action",
--- a/mobile/android/chrome/content/MasterPassword.js
+++ b/mobile/android/chrome/content/MasterPassword.js
@@ -1,13 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 "use strict";
 
+XPCOMUtils.defineLazyModuleGetter(this, "Snackbars", "resource://gre/modules/Snackbars.jsm");
+
 var MasterPassword = {
   pref: "privacy.masterpassword.enabled",
   _tokenName: "",
 
   get _secModuleDB() {
     delete this._secModuleDB;
     return this._secModuleDB = Cc["@mozilla.org/security/pkcs11moduledb;1"].getService(Ci.nsIPKCS11ModuleDB);
   },
@@ -56,12 +58,12 @@ var MasterPassword = {
       if (token.checkPassword(aOldPassword)) {
         token.changePassword(aOldPassword, "");
         BrowserApp.notifyPrefObservers(this.pref);
         return true;
       }
     } catch(e) {
       dump("MasterPassword.removePassword: " + e + "\n");
     }
-    NativeWindow.toast.show(Strings.browser.GetStringFromName("masterPassword.incorrect"), "short");
+    Snackbars.show(Strings.browser.GetStringFromName("masterPassword.incorrect"), Snackbars.LENGTH_SHORT);
     return false;
   }
 };
--- a/mobile/android/chrome/content/PrintHelper.js
+++ b/mobile/android/chrome/content/PrintHelper.js
@@ -1,14 +1,16 @@
 // -*- Mode: js; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 "use strict";
 
+XPCOMUtils.defineLazyModuleGetter(this, "Snackbars", "resource://gre/modules/Snackbars.jsm");
+
 var PrintHelper = {
   init: function() {
     Services.obs.addObserver(this, "Print:PDF", false);
   },
 
   observe: function (aSubject, aTopic, aData) {
     let browser = BrowserApp.selectedBrowser;
 
@@ -43,17 +45,17 @@ var PrintHelper = {
     let webBrowserPrint = aBrowser.contentWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebBrowserPrint);
 
     return new Promise((resolve, reject) => {
       webBrowserPrint.print(printSettings, {
         onStateChange: function(webProgress, request, stateFlags, status) {
           // We get two STATE_START calls, one for STATE_IS_DOCUMENT and one for STATE_IS_NETWORK
           if (stateFlags & Ci.nsIWebProgressListener.STATE_START && stateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK) {
             // Let the user know something is happening. Generating the PDF can take some time.
-            NativeWindow.toast.show(Strings.browser.GetStringFromName("alertPrintjobToast"), "long");
+            Snackbars.show(Strings.browser.GetStringFromName("alertPrintjobToast"), Snackbars.LENGTH_LONG);
           }
 
           // We get two STATE_STOP calls, one for STATE_IS_DOCUMENT and one for STATE_IS_NETWORK
           if (stateFlags & Ci.nsIWebProgressListener.STATE_STOP && stateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK) {
             if (Components.isSuccessCode(status)) {
               // Send the details to Java
               resolve({ file: file.path, title: fileName });
             } else {
--- a/mobile/android/chrome/content/Reader.js
+++ b/mobile/android/chrome/content/Reader.js
@@ -1,15 +1,17 @@
 // -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
+XPCOMUtils.defineLazyModuleGetter(this, "Snackbars", "resource://gre/modules/Snackbars.jsm");
+
 /*globals MAX_URI_LENGTH, MAX_TITLE_LENGTH */
 
 var Reader = {
   // These values should match those defined in BrowserContract.java.
   STATUS_UNFETCHED: 0,
   STATUS_FETCH_FAILED_TEMPORARY: 1,
   STATUS_FETCH_FAILED_PERMANENT: 2,
   STATUS_FETCH_FAILED_UNSUPPORTED_FORMAT: 3,
@@ -174,17 +176,17 @@ var Reader = {
         Messaging.sendRequest({
           type: "SystemUI:Visibility",
           visible: message.data.visible
         });
         break;
 
       case "Reader:ToolbarHidden":
         if (!this._hasUsedToolbar) {
-          NativeWindow.toast.show(Strings.browser.GetStringFromName("readerMode.toolbarTip"), "short");
+          Snackbars.show(Strings.browser.GetStringFromName("readerMode.toolbarTip"), Snackbars.LENGTH_SHORT);
           Services.prefs.setBoolPref("reader.has_used_toolbar", true);
           this._hasUsedToolbar = true;
         }
         break;
 
       case "Reader:UpdateReaderButton": {
         let tab = BrowserApp.getTabForBrowser(message.target);
         tab.browser.isArticle = message.data.isArticle;
--- a/mobile/android/chrome/content/SelectionHandler.js
+++ b/mobile/android/chrome/content/SelectionHandler.js
@@ -1,14 +1,16 @@
 // -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 "use strict";
 
+XPCOMUtils.defineLazyModuleGetter(this, "Snackbars", "resource://gre/modules/Snackbars.jsm");
+
 // Define elements that bound phone number containers.
 const PHONE_NUMBER_CONTAINERS = "td,div";
 const DEFER_CLOSE_TRIGGER_MS = 125; // Grace period delay before deferred _closeSelection()
 
 // Gecko AccessibleCaret pref names.
 const PREF_GECKO_ACCESSIBLECARET_ENABLED = "layout.accessiblecaret.enabled";
 
 var SelectionHandler = {
@@ -1083,17 +1085,17 @@ var SelectionHandler = {
     this._domWinUtils.sendMouseEventToWindow("mouseup", aX, aY, 0, 0, 0, true);
   },
 
   copySelection: function sh_copySelection() {
     let selectedText = this._getSelectedText();
     if (selectedText.length) {
       let clipboard = Cc["@mozilla.org/widget/clipboardhelper;1"].getService(Ci.nsIClipboardHelper);
       clipboard.copyString(selectedText);
-      NativeWindow.toast.show(Strings.browser.GetStringFromName("selectionHelper.textCopied"), "short");
+      Snackbars.show(Strings.browser.GetStringFromName("selectionHelper.textCopied"), Snackbars.LENGTH_SHORT);
     }
     this._closeSelection();
   },
 
   shareSelection: function sh_shareSelection() {
     let selectedText = this._getSelectedText();
     if (selectedText.length) {
       Messaging.sendRequest({
--- a/mobile/android/chrome/content/WebcompatReporter.js
+++ b/mobile/android/chrome/content/WebcompatReporter.js
@@ -4,16 +4,17 @@
 
 var { classes: Cc, interfaces: Ci, utils: Cu } = Components;
 
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
                                   "resource://gre/modules/PrivateBrowsingUtils.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "Snackbars", "resource://gre/modules/Snackbars.jsm");
 
 var WebcompatReporter = {
   menuItem: null,
   menuItemEnabled: null,
   init: function() {
     Services.obs.addObserver(this, "DesktopMode:Change", false);
     Services.obs.addObserver(this, "chrome-document-global-created", false);
     Services.obs.addObserver(this, "content-document-global-created", false);
@@ -72,22 +73,22 @@ var WebcompatReporter = {
                     url.startsWith("file") ||
                     url.startsWith("resource"));
   },
 
   reportDesktopModePrompt: function() {
     let currentURI = BrowserApp.selectedTab.browser.currentURI.spec;
     let message = this.strings.GetStringFromName("webcompat.reportDesktopMode.message");
     let options = {
-      button: {
+      action: {
         label: this.strings.GetStringFromName("webcompat.reportDesktopModeYes.label"),
         callback: () => this.reportIssue(currentURI)
       }
     };
-    NativeWindow.toast.show(message, "long", options);
+    Snackbars.show(message, Snackbars.LENGTH_LONG, options);
   },
 
   reportIssue: function(url) {
     let webcompatURL = new URL("https://webcompat.com/");
     webcompatURL.searchParams.append("open", "1");
     webcompatURL.searchParams.append("url", url);
     if (PrivateBrowsingUtils.isBrowserPrivate(BrowserApp.selectedTab.browser)) {
       BrowserApp.addTab(webcompatURL.href, {parentId: BrowserApp.selectedTab.id, isPrivate: true});
--- a/mobile/android/chrome/content/aboutLogins.js
+++ b/mobile/android/chrome/content/aboutLogins.js
@@ -14,31 +14,32 @@ XPCOMUtils.defineLazyGetter(window, "gCh
   window.QueryInterface(Ci.nsIInterfaceRequestor)
     .getInterface(Ci.nsIWebNavigation)
     .QueryInterface(Ci.nsIDocShellTreeItem)
     .rootTreeItem
     .QueryInterface(Ci.nsIInterfaceRequestor)
     .getInterface(Ci.nsIDOMWindow)
     .QueryInterface(Ci.nsIDOMChromeWindow));
 
+XPCOMUtils.defineLazyModuleGetter(this, "Snackbars", "resource://gre/modules/Snackbars.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Prompt",
                                   "resource://gre/modules/Prompt.jsm");
 
 var debug = Cu.import("resource://gre/modules/AndroidLog.jsm", {}).AndroidLog.d.bind(null, "AboutLogins");
 
 var gStringBundle = Services.strings.createBundle("chrome://browser/locale/aboutLogins.properties");
 
-function copyStringAndToast(string, notifyString) {
+function copyStringShowSnackbar(string, notifyString) {
   try {
     let clipboard = Cc["@mozilla.org/widget/clipboardhelper;1"].getService(Ci.nsIClipboardHelper);
     clipboard.copyString(string);
-    gChromeWin.NativeWindow.toast.show(notifyString, "short");
+    Snackbars.show(notifyString, Snackbars.LENGTH_SHORT);
   } catch (e) {
     debug("Error copying from about:logins");
-    gChromeWin.NativeWindow.toast.show(gStringBundle.GetStringFromName("loginsDetails.copyFailed"), "short");
+    Snackbars.show(gStringBundle.GetStringFromName("loginsDetails.copyFailed"), Snackbars.LENGTH_SHORT);
   }
 }
 
 // Delay filtering while typing in MS
 const FILTER_DELAY = 500;
 /* Constants for usage telemetry */
 const LOGINS_LIST_VIEWED = 0;
 const LOGIN_VIEWED = 1;
@@ -295,17 +296,17 @@ var Logins = {
     let origUsername = this._selectedLogin.username;
     let origPassword = this._selectedLogin.password;
     let origDomain = this._selectedLogin.hostname;
 
     try {
       if ((newUsername === origUsername) &&
           (newPassword === origPassword) &&
           (newDomain === origDomain) ) {
-        gChromeWin.NativeWindow.toast.show(gStringBundle.GetStringFromName("editLogin.saved1"), "short");
+        Snackbars.show(gStringBundle.GetStringFromName("editLogin.saved1"), Snackbars.LENGTH_SHORT);
         this._showList();
         return;
       }
 
       let logins = Services.logins.findLogins({}, origDomain, origDomain, null);
 
       for (let i = 0; i < logins.length; i++) {
         if (logins[i].username == origUsername) {
@@ -314,20 +315,20 @@ var Logins = {
           clone.password = newPassword;
           clone.hostname = newDomain;
           Services.logins.removeLogin(logins[i]);
           Services.logins.addLogin(clone);
           break;
         }
       }
     } catch (e) {
-      gChromeWin.NativeWindow.toast.show(gStringBundle.GetStringFromName("editLogin.couldNotSave"), "short");
+      Snackbars.show(gStringBundle.GetStringFromName("editLogin.couldNotSave"), Snackbars.LENGTH_SHORT);
       return;
     }
-    gChromeWin.NativeWindow.toast.show(gStringBundle.GetStringFromName("editLogin.saved1"), "short");
+    Snackbars.show(gStringBundle.GetStringFromName("editLogin.saved1"), Snackbars.LENGTH_SHORT);
     this._showList();
   },
 
   _onPasswordBtn: function () {
     Services.telemetry.getHistogramById("PWMGR_ABOUT_LOGINS_USAGE").add(LOGIN_PW_TOGGLED);
     this._updatePasswordBtn(this._isPasswordBtnInHideMode());
   },
 
@@ -358,17 +359,17 @@ var Logins = {
       message: password,
       buttons: [
         gStringBundle.GetStringFromName("loginsDialog.copy"),
         gStringBundle.GetStringFromName("loginsDialog.cancel") ]
       }).show((data) => {
         switch (data.button) {
           case 0:
           // Corresponds to "Copy password" button.
-          copyStringAndToast(password, gStringBundle.GetStringFromName("loginsDetails.passwordCopied"));
+          copyStringShowSnackbar(password, gStringBundle.GetStringFromName("loginsDetails.passwordCopied"));
         }
      });
   },
 
   _onLoginClick: function (event) {
     let loginItem = event.currentTarget;
     let login = loginItem.login;
     if (!login) {
@@ -390,20 +391,20 @@ var Logins = {
     prompt.setSingleChoiceItems(menuItems);
     prompt.show((data) => {
       // Switch on indices of buttons, as they were added when creating login item.
       switch (data.button) {
         case 0:
           this._showPassword(login.password);
           break;
         case 1:
-          copyStringAndToast(login.password, gStringBundle.GetStringFromName("loginsDetails.passwordCopied"));
+          copyStringShowSnackbar(login.password, gStringBundle.GetStringFromName("loginsDetails.passwordCopied"));
           break;
         case 2:
-          copyStringAndToast(login.username, gStringBundle.GetStringFromName("loginsDetails.usernameCopied"));
+          copyStringShowSnackbar(login.username, gStringBundle.GetStringFromName("loginsDetails.usernameCopied"));
           break;
         case 3:
           this._selectedLogin = login;
           this._showEditLoginDialog(login);
           history.pushState({ id: login.guid }, document.title);
           break;
         case 4:
           let confirmPrompt = new Prompt({
--- a/mobile/android/modules/DownloadNotifications.jsm
+++ b/mobile/android/modules/DownloadNotifications.jsm
@@ -10,16 +10,17 @@ const { classes: Cc, interfaces: Ci, uti
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "Downloads", "resource://gre/modules/Downloads.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "FileUtils", "resource://gre/modules/FileUtils.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Notifications", "resource://gre/modules/Notifications.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "OS", "resource://gre/modules/osfile.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Services", "resource://gre/modules/Services.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "Snackbars", "resource://gre/modules/Snackbars.jsm");
 
 XPCOMUtils.defineLazyServiceGetter(this, "ParentalControls",
   "@mozilla.org/parental-controls-service;1", "nsIParentalControlsService");
 
 var Log = Cu.import("resource://gre/modules/AndroidLog.jsm", {}).AndroidLog.i.bind(null, "DownloadNotifications");
 
 XPCOMUtils.defineLazyGetter(this, "strings",
                             () => Services.strings.createBundle("chrome://browser/locale/browser.properties"));
@@ -59,27 +60,27 @@ var DownloadNotifications = {
     // user decides to retry the download.
     if (download.succeeded && !this._viewAdded) {
       return;
     }
 
     if (!ParentalControls.isAllowed(ParentalControls.DOWNLOAD)) {
       download.cancel().catch(Cu.reportError);
       download.removePartialData().catch(Cu.reportError);
-      window.NativeWindow.toast.show(strings.GetStringFromName("downloads.disabledInGuest"), "long");
+      Snackbars.show(strings.GetStringFromName("downloads.disabledInGuest"), Snackbars.LENGTH_LONG);
       return;
     }
 
     let notification = new DownloadNotification(download);
     notifications.set(download, notification);
     notification.showOrUpdate();
 
-    // If this is a new download, show a toast as well.
+    // If this is a new download, show a snackbar as well.
     if (this._viewAdded) {
-      window.NativeWindow.toast.show(strings.GetStringFromName("alertDownloadsToast"), "long");
+      Snackbars.show(strings.GetStringFromName("alertDownloadsToast"), Snackbars.LENGTH_LONG);
     }
   },
 
   onDownloadChanged: function (download) {
     let notification = notifications.get(download);
     if (!notification) {
       Cu.reportError("Download doesn't have a notification.");
       return;