Bug 570156 - Convert download dialog to a nsIPromptService prompt [r=mbrubeck]
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -2713,55 +2713,16 @@ var AlertsHelper = {
if (this._timeoutID != -1) {
clearTimeout(this._timeoutID);
this._timeoutAlert();
}
}
};
-var HelperAppDialog = {
- _launcher: null,
- _container: null,
-
- show: function had_show(aLauncher) {
- this._launcher = aLauncher;
- document.getElementById("helperapp-target").value = this._launcher.suggestedFileName;
-
- if (!this._launcher.MIMEInfo.hasDefaultHandler)
- document.getElementById("helperapp-open").disabled = true;
-
- this._container = document.getElementById("helperapp-container");
- this._container.hidden = false;
-
- let rect = this._container.getBoundingClientRect();
- this._container.top = (window.innerHeight - rect.height) / 2;
- this._container.left = (window.innerWidth - rect.width) / 2;
-
- BrowserUI.pushPopup(this, this._container);
- },
-
- save: function had_save() {
- this._launcher.saveToDisk(null, false);
- this.hide();
- },
-
- open: function had_open() {
- this._launcher.launchWithApplication(null, false);
- this.hide();
- },
-
- hide: function had_hide() {
- document.getElementById("helperapp-target").value = "";
- this._container.hidden = true;
-
- BrowserUI.popPopup();
- }
-};
-
function ProgressController(tab) {
this._tab = tab;
// Properties used to cache security state used to update the UI
this.state = null;
this._hostChanged = false; // onLocationChange will flip this bit
}
--- a/mobile/chrome/content/browser.xul
+++ b/mobile/chrome/content/browser.xul
@@ -492,28 +492,16 @@
<description flex="1">&bookmarksHeader.label;</description>
<toolbarbutton id="tool-bookmarks-manage" class="urlbar-button show-text button-dark" type="checkbox" autocheck="true"
label="&bookmarksManage.label;" oncommand="BookmarkList.toggleManage();"/>
<toolbarbutton id="tool-bookmarks-close" class="urlbar-button button-image" command="cmd_close"/>
</hbox>
<placelist id="bookmark-items" type="bookmarks" flex="1" onopen="BookmarkList.openBookmark();" autoedit="true"/>
</vbox>
- <!-- save/open dialog -->
- <vbox id="helperapp-container" class="dialog-dark" hidden="true" align="center" top="0" left="0">
- <label id="helperapp-prompt" value="&helperApp.prompt;"/>
- <label id="helperapp-target" value="" crop="center"/>
- <separator/>
- <hbox pack="center">
- <button id="helperapp-open" class="button-dark" label="&helperApp.open;" oncommand="HelperAppDialog.open();"/>
- <button id="helperapp-save" class="button-dark" label="&helperApp.save;" oncommand="HelperAppDialog.save();"/>
- <button id="helperapp-nothing" class="button-dark" label="&helperApp.nothing;" oncommand="HelperAppDialog.hide();"/>
- </hbox>
- </vbox>
-
<vbox id="context-popup" hidden="true" class="dialog-dark" top="0" left="0">
<hbox id="context-header">
<label id="context-hint" crop="center" flex="1"/>
</hbox>
<richlistbox id="context-commands" onclick="ContextHelper.hide();">
<richlistitem id="context-openinnewtab" type="link" onclick="ContextCommands.openInNewTab(event);">
<label value="&contextOpenInNewTab.label;"/>
</richlistitem>
--- a/mobile/components/HelperAppDialog.js
+++ b/mobile/components/HelperAppDialog.js
@@ -49,22 +49,67 @@ function HelperAppLauncherDialog() { }
HelperAppLauncherDialog.prototype = {
classDescription: "HelperApp Launcher Dialog",
contractID: "@mozilla.org/helperapplauncherdialog;1",
classID: Components.ID("{e9d277a0-268a-4ec2-bb8c-10fdf3e44611}"),
QueryInterface: XPCOMUtils.generateQI([Ci.nsIHelperAppLauncherDialog]),
show: function hald_show(aLauncher, aContext, aReason) {
- this._launcher = aLauncher;
- this._context = aContext;
+ let window = aContext.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIDOMWindowInternal);
+
+ let sbs = Cc["@mozilla.org/intl/stringbundle;1"].getService(Ci.nsIStringBundleService);
+ let bundle = sbs.createBundle("chrome://browser/locale/browser.properties");
+
+ let prompter = Cc["@mozilla.org/embedcomp/prompt-service;1"].getService(Ci.nsIPromptService);
+ let flags = Ci.nsIPrompt.BUTTON_POS_1_DEFAULT +
+ (Ci.nsIPrompt.BUTTON_TITLE_IS_STRING * Ci.nsIPrompt.BUTTON_POS_0) +
+ (Ci.nsIPrompt.BUTTON_TITLE_IS_STRING * Ci.nsIPrompt.BUTTON_POS_1);
+
+ let title = bundle.GetStringFromName("helperApp.title");
+ let message = bundle.GetStringFromName("helperApp.prompt");
+ message += "\n " + aLauncher.suggestedFileName;
+
+ let type = aLauncher.MIMEInfo.description;
+ if (type == "") {
+ try {
+ type = aLauncher.MIMEInfo.primaryExtension.toUpperCase();
+ } catch (e) {
+ type = aLauncher.MIMEInfo.MIMEType;
+ }
+ }
+ message += "\n " + type;
- let wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
- let browser = wm.getMostRecentWindow("navigator:browser");
- browser.HelperAppDialog.show(aLauncher);
+ let open = bundle.GetStringFromName("helperApp.open");
+ let save = bundle.GetStringFromName("helperApp.save");
+ let nothing = bundle.GetStringFromName("helperApp.nothing");
+
+ // Check to see if we can open this file or not
+ if (aLauncher.MIMEInfo.hasDefaultHandler) {
+ flags += (Ci.nsIPrompt.BUTTON_TITLE_IS_STRING * Ci.nsIPrompt.BUTTON_POS_2);
+
+ let choice = prompter.confirmEx(window,
+ title, message,
+ flags, save, open, nothing,
+ null, {});
+
+ if (choice == 0)
+ aLauncher.saveToDisk(null, false);
+ else if (choice == 1)
+ aLauncher.launchWithApplication(null, false);
+ } else {
+ let choice = prompter.confirmEx(window,
+ title, message,
+ flags, save, nothing, null,
+ null, {});
+
+ if (choice == 0)
+ aLauncher.saveToDisk(null, false);
+ }
},
promptForSaveToFile: function hald_promptForSaveToFile(aLauncher, aContext, aDefaultFile, aSuggestedFileExt, aForcePrompt) {
let file = null;
let prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
if (!aForcePrompt) {
--- a/mobile/locales/en-US/chrome/browser.dtd
+++ b/mobile/locales/en-US/chrome/browser.dtd
@@ -22,21 +22,16 @@
<!ENTITY bookmarksHeader.label "Bookmarks">
<!ENTITY bookmarksManage.label "Manage">
<!ENTITY editBookmarkRemove.label "Remove">
<!ENTITY editBookmarkDone.label "Done">
<!ENTITY editBookmarkTags.label "Add tags here">
-<!ENTITY helperApp.prompt "What would you like to do with">
-<!ENTITY helperApp.open "Open">
-<!ENTITY helperApp.save "Save">
-<!ENTITY helperApp.nothing "Nothing">
-
<!ENTITY formHelper.previous "Previous">
<!ENTITY formHelper.next "Next">
<!ENTITY formHelper.done "Done">
<!ENTITY addonsHeader.label "Add-ons">
<!ENTITY addonsLocal.label "Your Add-ons">
<!ENTITY addonsUpdate.label "Update">
<!ENTITY addonsRepo.label "Get Add-ons">
--- a/mobile/locales/en-US/chrome/browser.properties
+++ b/mobile/locales/en-US/chrome/browser.properties
@@ -144,8 +144,16 @@ homepage.custom2=Custom Page
pageactions.saveas.pdf=Save As PDF
pageactions.search.addNew=Add Search Engine
pageactions.password.forget=Forget Password
pageactions.reset=Clear Site Preferences
pageactions.geo=Location
pageactions.popup=Popups
pageactions.offline-app=Offline Storage
pageactions.password=Password
+
+# Helper App Dialog (Save/Open)
+helperApp.title=Opening File
+helperApp.prompt=What would you like to do with:
+helperApp.open=Open
+helperApp.save=Save
+helperApp.nothing=Nothing
+
--- a/mobile/themes/hildon/platform.css
+++ b/mobile/themes/hildon/platform.css
@@ -155,16 +155,17 @@ dialog .prompt-title {
dialog .prompt-title {
font-size: 18px !important;
}
}
dialog .prompt-message {
margin-top: 8px;
+ white-space: pre-wrap;
}
dialog .button-checkbox {
margin-left: 24px;
}
/* buttons ----------------------------------------------------------------- */
.button-text,