Bug 594504 - Show a message to explain why downloads with no helper apps were cancelled [r=mfinkle]
authorWesley Johnston <wjohnston@mozilla.com>
Fri, 10 Sep 2010 15:25:09 -0400
changeset 66560 6b9420db098c03f2a7f870a33b0943079466ac77
parent 66559 11d099ed1e4c37efe583dbf4ead647d6626aa732
child 66561 a9d023f0f8c823c2cf402d86259bfe302621fb4c
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs594504
Bug 594504 - Show a message to explain why downloads with no helper apps were cancelled [r=mfinkle]
mobile/components/HelperAppDialog.js
mobile/components/Makefile.in
mobile/locales/en-US/chrome/browser.properties
--- a/mobile/components/HelperAppDialog.js
+++ b/mobile/components/HelperAppDialog.js
@@ -35,16 +35,21 @@
  * ***** END LICENSE BLOCK ***** */
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cu = Components.utils;
 const Cr = Components.results;
 
 const PREF_BD_USEDOWNLOADDIR = "browser.download.useDownloadDir";
+#ifdef ANDROID
+const URI_GENERIC_ICON_DOWNLOAD = "drawable://alertdownloads";
+#else
+const URI_GENERIC_ICON_DOWNLOAD = "chrome://browser/skin/images/alert-downloads-30.png";
+#endif
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 
 // -----------------------------------------------------------------------
 // HelperApp Launcher Dialog
 // -----------------------------------------------------------------------
 
@@ -55,23 +60,38 @@ HelperAppLauncherDialog.prototype = {
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIHelperAppLauncherDialog]),
 
   show: function hald_show(aLauncher, aContext, aReason) {
     // Check to see if we can open this file or not
     if (aLauncher.MIMEInfo.hasDefaultHandler) {
       aLauncher.MIMEInfo.preferredAction = Ci.nsIMIMEInfo.useSystemDefault;
       aLauncher.launchWithApplication(null, false);
     } else {
-      aLauncher.cancel(Cr.NS_BINDING_ABORTED);
+      let wasClicked = false;
+      let listener = {
+        observe: function(aSubject, aTopic, aData) {
+          if (aTopic == "alertclickcallback") {
+            wasClicked = true;
+            let win = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator).getMostRecentWindow("navigator:browser");
+            if (win)
+              win.BrowserUI.showPanel("downloads-container");
+  
+            aLauncher.saveToDisk(null, false);
+          } else {
+            if (!wasClicked)
+              aLauncher.cancel(Cr.NS_BINDING_ABORTED);
+          }
+        }
+      };
+      this._notify(aLauncher, listener);
     }
   },
 
   promptForSaveToFile: function hald_promptForSaveToFile(aLauncher, aContext, aDefaultFile, aSuggestedFileExt, aForcePrompt) {
     let file = null;
-
     let prefs = Services.prefs;
 
     if (!aForcePrompt) {
       // Check to see if the user wishes to auto save to the default download
       // folder without prompting. Note that preference might not be set.
       let autodownload = true;
       try {
         autodownload = prefs.getBoolPref(PREF_BD_USEDOWNLOADDIR);
@@ -211,12 +231,22 @@ HelperAppLauncherDialog.prototype = {
         if (aLocalFile.exists())
           aLocalFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0600);
       }
     }
   },
 
   isUsableDirectory: function hald_isUsableDirectory(aDirectory) {
     return aDirectory.exists() && aDirectory.isDirectory() && aDirectory.isWritable();
+  },
+
+  _notify: function hald_notify(aLauncher, aCallback) {
+    let bundle = Services.strings.createBundle("chrome://browser/locale/browser.properties");
+
+    let notifier = Cc["@mozilla.org/alerts-service;1"].getService(Ci.nsIAlertsService);
+    notifier.showAlertNotification(URI_GENERIC_ICON_DOWNLOAD,
+                                   bundle.GetStringFromName("alertDownloads"),
+                                   bundle.GetStringFromName("alertCantOpenDownload"),
+                                   true, "", aCallback, "downloadopen-fail");
   }
 };
 
 const NSGetFactory = XPCOMUtils.generateNSGetFactory([HelperAppLauncherDialog]);
--- a/mobile/components/Makefile.in
+++ b/mobile/components/Makefile.in
@@ -49,27 +49,27 @@ XPIDL_MODULE = MobileComponents
 XPIDLSRCS = \
         SessionStore.idl \
         $(NULL)
 
 EXTRA_PP_COMPONENTS = \
         AboutRedirector.js \
         BrowserCLH.js \
         DirectoryProvider.js\
+        HelperAppDialog.js \
         Sidebar.js \
         SessionStore.js \
         $(NULL)
 
 EXTRA_COMPONENTS = \
         MobileComponents.manifest \
         BrowserStartup.js \
         ContentPermissionPrompt.js \
         XPIDialogService.js \
         DownloadManagerUI.js \
-        HelperAppDialog.js \
         PromptService.js \
         ContentDispatchChooser.js \
         AutoCompleteCache.js \
         AddonUpdateService.js \
         FormAutoComplete.js \
         LoginManager.js \
         BlocklistPrompt.js \
 	$(NULL)
--- a/mobile/locales/en-US/chrome/browser.properties
+++ b/mobile/locales/en-US/chrome/browser.properties
@@ -84,16 +84,17 @@ alertLockScreen.unlocked=Unlocked
 # LOCALIZATION NOTE (alertAddonsDisabled): Semi-colon list of plural forms.
 # See: http://developer.mozilla.org/en/docs/Localization_and_Plurals
 # #1 number of add-ons
 alertAddonsDisabled=#1 incompatible add-on was disabled;#1 incompatible add-ons were disabled
 
 alertDownloads=Downloads
 alertDownloadsStart=Downloading: %S
 alertDownloadsDone=%S has finished downloading
+alertCantOpenDownload=Can't open file. Tap to save it.
 
 # Notifications
 notificationRestart.normal=Restart to complete changes.
 notificationRestart.update=Add-ons updated. Restart to complete changes.
 notificationRestart.blocked=Unsafe add-ons installed. Restart to disable.
 notificationRestart.button=Restart
 
 # Popup Blocker