Bug 1238139 - Show snackbar for completed downloads. r=ahunt,mcomella
authorSebastian Kaspari <s.kaspari@gmail.com>
Thu, 14 Jan 2016 19:48:29 +0100
changeset 280720 16fd23fa010398406745efee2fced49ed2df6ce8
parent 280719 62fc74be5c7580e753a7c437bb562620ba0fa5ba
child 280721 4c88876f1d655fdb53889f174e4566e310ab5e55
push id29921
push usercbook@mozilla.com
push dateThu, 21 Jan 2016 10:48:07 +0000
treeherdermozilla-central@aa416d2a76fa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersahunt, mcomella
bugs1238139
milestone46.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 1238139 - Show snackbar for completed downloads. r=ahunt,mcomella
mobile/android/locales/en-US/chrome/browser.properties
mobile/android/modules/DownloadNotifications.jsm
--- a/mobile/android/locales/en-US/chrome/browser.properties
+++ b/mobile/android/locales/en-US/chrome/browser.properties
@@ -20,16 +20,19 @@ alertDownloadsStart2=Download starting
 alertDownloadsDone2=Download complete
 alertCantOpenDownload=Can't open file. Tap to save it.
 alertDownloadsSize=Download too big
 alertDownloadsNoSpace=Not enough storage space
 alertDownloadsToast=Download started…
 alertDownloadsPause=Pause
 alertDownloadsResume=Resume
 alertDownloadsCancel=Cancel
+# LOCALIZATION NOTE (alertDownloadSucceeded): This text is shown as a snackbar inside the app after a
+# successful download. %S will be replaced by the file name of the download.
+alertDownloadSucceeded=%S downloaded
 # LOCALIZATION NOTE (undoCloseToast.message): This message appears in a toast
 # when the user tries to download something in Guest mode.
 downloads.disabledInGuest=Downloads are disabled in guest sessions
 
 alertFullScreenToast=Press BACK to leave full-screen mode
 
 # LOCALIZATION NOTE (alertSearchEngineAddedToast, alertSearchEngineErrorToast, alertSearchEngineDuplicateToast)
 # %S will be replaced by the name of the search engine (exposed by the current page)
--- a/mobile/android/modules/DownloadNotifications.jsm
+++ b/mobile/android/modules/DownloadNotifications.jsm
@@ -11,16 +11,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.defineLazyModuleGetter(this, "UITelemetry", "resource://gre/modules/UITelemetry.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"));
@@ -76,22 +77,40 @@ var DownloadNotifications = {
     // If this is a new download, show a snackbar as well.
     if (this._viewAdded) {
       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;
+
+    if (download.succeeded) {
+      let file = new FileUtils.File(download.target.path);
+
+      Snackbars.show(strings.formatStringFromName("alertDownloadSucceeded", [file.leafName], 1), Snackbars.LENGTH_LONG, {
+        action: {
+          label: strings.GetStringFromName("helperapps.open"),
+          callback: () => {
+            UITelemetry.addEvent("launch.1", "toast", null, "downloads");
+            try {
+              file.launch();
+            } catch (ex) {
+              this.showInAboutDownloads(download);
+            }
+            if (notification) {
+              notification.hide();
+            }
+          }
+        }});
     }
 
-    notification.showOrUpdate();
+    if (notification) {
+      notification.showOrUpdate();
+    }
   },
 
   onDownloadRemoved: function (download) {
     let notification = notifications.get(download);
     if (!notification) {
       Cu.reportError("Download doesn't have a notification.");
       return;
     }