diff --git a/embedding/components/Makefile.in b/embedding/components/Makefile.in index 52d093f65ab..ffee211616a 100644 --- a/embedding/components/Makefile.in +++ b/embedding/components/Makefile.in @@ -45,7 +45,7 @@ include $(DEPTH)/config/autoconf.mk # You'd think we could skip building ui if XUL is disabled, # but we need to export interface headers from those directories. -DIRS = windowwatcher appstartup find webbrowserpersist commandhandler ui +DIRS = windowwatcher appstartup find webbrowserpersist commandhandler ifdef MOZ_XUL ifdef NS_PRINTING diff --git a/embedding/components/ui/Makefile.in b/embedding/components/ui/Makefile.in deleted file mode 100644 index 0c507bf22fb..00000000000 --- a/embedding/components/ui/Makefile.in +++ /dev/null @@ -1,47 +0,0 @@ -# -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is mozilla.org code. -# -# The Initial Developer of the Original Code is -# Netscape Communications, Inc. -# Portions created by the Initial Developer are Copyright (C) 2001 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# -# Alternatively, the contents of this file may be used under the terms of -# either the GNU General Public License Version 2 or later (the "GPL"), or -# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -DEPTH = ../../.. -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ - -include $(DEPTH)/config/autoconf.mk - -DIRS = helperAppDlg progressDlg - -include $(topsrcdir)/config/rules.mk diff --git a/embedding/components/ui/helperAppDlg/Makefile.in b/embedding/components/ui/helperAppDlg/Makefile.in deleted file mode 100644 index 1115798bde5..00000000000 --- a/embedding/components/ui/helperAppDlg/Makefile.in +++ /dev/null @@ -1,52 +0,0 @@ -# -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is mozilla.org code. -# -# The Initial Developer of the Original Code is -# Netscape Communications, Inc. -# Portions created by the Initial Developer are Copyright (C) 2001 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# -# Alternatively, the contents of this file may be used under the terms of -# either the GNU General Public License Version 2 or later (the "GPL"), or -# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -DEPTH = ../../../.. -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ - -MODULE=helperAppDlg - -include $(DEPTH)/config/autoconf.mk - -EXTRA_COMPONENTS = \ - nsHelperAppDlg.js \ - $(NULL) - -include $(topsrcdir)/config/rules.mk - diff --git a/embedding/components/ui/helperAppDlg/nsHelperAppDlg.js b/embedding/components/ui/helperAppDlg/nsHelperAppDlg.js deleted file mode 100644 index 01c01b97a15..00000000000 --- a/embedding/components/ui/helperAppDlg/nsHelperAppDlg.js +++ /dev/null @@ -1,894 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is the Mozilla browser. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Bill Law - * Scott MacGregor - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/* This file implements the nsIHelperAppLauncherDialog interface. - * - * The implementation consists of a JavaScript "class" named nsHelperAppDialog, - * comprised of: - * - a JS constructor function - * - a prototype providing all the interface methods and implementation stuff - * - * In addition, this file implements an nsIModule object that registers the - * nsHelperAppDialog component. - */ - -const nsIHelperAppLauncherDialog = Components.interfaces.nsIHelperAppLauncherDialog; -const REASON_CANTHANDLE = nsIHelperAppLauncherDialog.REASON_CANTHANDLE; -const REASON_SERVERREQUEST = nsIHelperAppLauncherDialog.REASON_SERVERREQUEST; -const REASON_TYPESNIFFED = nsIHelperAppLauncherDialog.REASON_TYPESNIFFED; - - -/* ctor - */ -function nsHelperAppDialog() { - // Initialize data properties. - this.mLauncher = null; - this.mContext = null; - this.mSourcePath = null; - this.chosenApp = null; - this.givenDefaultApp = false; - this.strings = new Array; - this.elements = new Array; - this.updateSelf = true; - this.mTitle = ""; - this.mIsMac = false; -} - -nsHelperAppDialog.prototype = { - // Turn this on to get debugging messages. - debug: false, - - nsIMIMEInfo : Components.interfaces.nsIMIMEInfo, - - // Dump text (if debug is on). - dump: function( text ) { - if ( this.debug ) { - dump( text ); - } - }, - - // This "class" supports nsIHelperAppLauncherDialog, and nsISupports. - QueryInterface: function (iid) { - if (iid.equals(Components.interfaces.nsIHelperAppLauncherDialog) || - iid.equals(Components.interfaces.nsISupports)) - return this; - - throw Components.results.NS_ERROR_NO_INTERFACE; - }, - - // ---------- nsIHelperAppLauncherDialog methods ---------- - - // show: Open XUL dialog using window watcher. Since the dialog is not - // modal, it needs to be a top level window and the way to open - // one of those is via that route). - show: function(aLauncher, aContext, aReason) { - this.mLauncher = aLauncher; - this.mContext = aContext; - this.mReason = aReason; - // Display the dialog using the Window Watcher interface. - var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"] - .getService( Components.interfaces.nsIWindowWatcher ); - this.mDialog = ww.openWindow( null, // no parent - "chrome://global/content/nsHelperAppDlg.xul", - null, - "chrome,titlebar,dialog=yes", - null ); - // Hook this object to the dialog. - this.mDialog.dialog = this; - // Watch for error notifications. - this.mIsMac = (this.mDialog.navigator.platform.indexOf( "Mac" ) != -1); - this.progressListener.helperAppDlg = this; - this.mLauncher.setWebProgressListener( this.progressListener ); - }, - - // promptForSaveToFile: Display file picker dialog and return selected file. - promptForSaveToFile: function(aLauncher, aContext, aDefaultFile, aSuggestedFileExtension, aForcePrompt) { - var result = ""; - - const prefSvcContractID = "@mozilla.org/preferences-service;1"; - const prefSvcIID = Components.interfaces.nsIPrefService; - var branch = Components.classes[prefSvcContractID].getService(prefSvcIID) - .getBranch("browser.download."); - var dir = null; - - const nsILocalFile = Components.interfaces.nsILocalFile; - const kDownloadDirPref = "dir"; - - // Try and pull in download directory pref - try { - dir = branch.getComplexValue(kDownloadDirPref, nsILocalFile); - } catch (e) { } - - var bundle = Components.classes["@mozilla.org/intl/stringbundle;1"] - .getService(Components.interfaces.nsIStringBundleService) - .createBundle("chrome://global/locale/nsHelperAppDlg.properties"); - - var autoDownload = branch.getBoolPref("autoDownload"); - // If the autoDownload pref is set then just download to default download directory - if (!aForcePrompt && autoDownload && dir && dir.exists()) { - if (aDefaultFile == "") - aDefaultFile = bundle.GetStringFromName("noDefaultFile") + (aSuggestedFileExtension || ""); - dir.append(aDefaultFile); - return uniqueFile(dir); - } - - // Use file picker to show dialog. - var nsIFilePicker = Components.interfaces.nsIFilePicker; - var picker = Components.classes[ "@mozilla.org/filepicker;1" ] - .createInstance( nsIFilePicker ); - - var windowTitle = bundle.GetStringFromName( "saveDialogTitle" ); - - var parent = aContext - .QueryInterface( Components.interfaces.nsIInterfaceRequestor ) - .getInterface( Components.interfaces.nsIDOMWindowInternal ); - picker.init( parent, windowTitle, nsIFilePicker.modeSave ); - picker.defaultString = aDefaultFile; - if (aSuggestedFileExtension) { - // aSuggestedFileExtension includes the period, so strip it - picker.defaultExtension = aSuggestedFileExtension.substring(1); - } else { - try { - picker.defaultExtension = this.mLauncher.MIMEInfo.primaryExtension; - } catch (ex) { - } - } - - var wildCardExtension = "*"; - if ( aSuggestedFileExtension ) { - wildCardExtension += aSuggestedFileExtension; - picker.appendFilter( wildCardExtension, wildCardExtension ); - } - - picker.appendFilters( nsIFilePicker.filterAll ); - - try { - if (dir.exists()) - picker.displayDirectory = dir; - } catch (e) { } - - if (picker.show() == nsIFilePicker.returnCancel || !picker.file) { - // Null result means user cancelled. - return null; - } - - // If not using specified location save the user's choice of directory - if (branch.getBoolPref("lastLocation") || autoDownload) { - var directory = picker.file.parent.QueryInterface(nsILocalFile); - branch.setComplexValue(kDownloadDirPref, nsILocalFile, directory); - } - - return picker.file; - }, - - // ---------- implementation methods ---------- - - // Web progress listener so we can detect errors while mLauncher is - // streaming the data to a temporary file. - progressListener: { - // Implementation properties. - helperAppDlg: null, - - // nsIWebProgressListener methods. - // Look for error notifications and display alert to user. - onStatusChange: function( aWebProgress, aRequest, aStatus, aMessage ) { - if ( aStatus != Components.results.NS_OK ) { - // Get prompt service. - var prompter = Components.classes[ "@mozilla.org/embedcomp/prompt-service;1" ] - .getService( Components.interfaces.nsIPromptService ); - // Display error alert (using text supplied by back-end). - prompter.alert( this.dialog, this.helperAppDlg.mTitle, aMessage ); - - // Close the dialog. - this.helperAppDlg.onCancel(); - if ( this.helperAppDlg.mDialog ) { - this.helperAppDlg.mDialog.close(); - } - } - }, - - // Ignore onProgressChange, onProgressChange64, onStateChange, onLocationChange, onSecurityChange, and onRefreshAttempted notifications. - onProgressChange: function( aWebProgress, - aRequest, - aCurSelfProgress, - aMaxSelfProgress, - aCurTotalProgress, - aMaxTotalProgress ) { - }, - - onProgressChange64: function( aWebProgress, - aRequest, - aCurSelfProgress, - aMaxSelfProgress, - aCurTotalProgress, - aMaxTotalProgress ) { - }, - - onStateChange: function( aWebProgress, aRequest, aStateFlags, aStatus ) { - }, - - onLocationChange: function( aWebProgress, aRequest, aLocation ) { - }, - - onSecurityChange: function( aWebProgress, aRequest, state ) { - }, - - onRefreshAttempted: function( aWebProgress, aURI, aDelay, aSameURI ) { - return true; - } - }, - - // initDialog: Fill various dialog fields with initial content. - initDialog : function() { - // Put product brand short name in prompt. - var prompt = this.dialogElement( "prompt" ); - var modified = this.replaceInsert( prompt.firstChild.nodeValue, 1, this.getString( "brandShortName" ) ); - prompt.firstChild.nodeValue = modified; - - // Put file name in window title. - var suggestedFileName = this.mLauncher.suggestedFileName; - - // Some URIs do not implement nsIURL, so we can't just QI. - var url = this.mLauncher.source.clone(); - try { - url.userPass = ""; - } catch (ex) {} - var fname = ""; - this.mSourcePath = url.prePath; - try { - url = url.QueryInterface( Components.interfaces.nsIURL ); - // A url, use file name from it. - fname = url.fileName; - this.mSourcePath += url.directory; - } catch (ex) { - // A generic uri, use path. - fname = url.path; - this.mSourcePath += url.path; - } - - if (suggestedFileName) - fname = suggestedFileName; - - this.mTitle = this.replaceInsert( this.mDialog.document.title, 1, fname); - this.mDialog.document.title = this.mTitle; - - // Put content type, filename and location into intro. - this.initIntro(url, fname); - - var iconString = "moz-icon://" + fname + "?size=32&contentType=" + this.mLauncher.MIMEInfo.MIMEType; - - this.dialogElement("contentTypeImage").setAttribute("src", iconString); - - this.initAppAndSaveToDiskValues(); - - // Initialize "always ask me" box. This should always be disabled - // and set to true for the ambiguous type application/octet-stream. - // Same if this dialog was forced due to a server request or type - // sniffing - var alwaysHandleCheckbox = this.dialogElement( "alwaysHandle" ); - if (this.mReason != REASON_CANTHANDLE || - this.mLauncher.MIMEInfo.MIMEType == "application/octet-stream"){ - alwaysHandleCheckbox.checked = false; - alwaysHandleCheckbox.disabled = true; - } - else { - alwaysHandleCheckbox.checked = !this.mLauncher.MIMEInfo.alwaysAskBeforeHandling; - } - - // Position it. - if ( this.mDialog.opener ) { - this.mDialog.moveToAlertPosition(); - } else { - this.mDialog.sizeToContent(); - this.mDialog.centerWindowOnScreen(); - } - - // Set initial focus - this.dialogElement( "mode" ).focus(); - - this.mDialog.document.documentElement.getButton("accept").disabled = true; - const nsITimer = Components.interfaces.nsITimer; - this._timer = Components.classes["@mozilla.org/timer;1"] - .createInstance(nsITimer); - this._timer.initWithCallback(this, 250, nsITimer.TYPE_ONE_SHOT); - }, - - // initIntro: - initIntro: function(url, filename) { - var intro = this.dialogElement( "intro" ); - var desc = this.mLauncher.MIMEInfo.description; - - var text; - if ( this.mReason == REASON_CANTHANDLE ) - text = "intro."; - else if (this.mReason == REASON_SERVERREQUEST ) - text = "intro.attachment."; - else if (this.mReason == REASON_TYPESNIFFED ) - text = "intro.sniffed."; - - var modified; - if (desc) - modified = this.replaceInsert( this.getString( text + "label" ), 1, desc ); - else - modified = this.getString( text + "noDesc.label" ); - - modified = this.replaceInsert( modified, 2, this.mLauncher.MIMEInfo.MIMEType ); - modified = this.replaceInsert( modified, 3, filename); - modified = this.replaceInsert( modified, 4, this.getString( "brandShortName" )); - - // if mSourcePath is a local file, then let's use the pretty path name instead of an ugly - // url... - var pathString = url.prePath; - try - { - var fileURL = url.QueryInterface(Components.interfaces.nsIFileURL); - if (fileURL) - { - var fileObject = fileURL.file; - if (fileObject) - { - var parentObject = fileObject.parent; - if (parentObject) - { - pathString = parentObject.path; - } - } - } - } catch(ex) {} - - - intro.firstChild.nodeValue = ""; - intro.firstChild.nodeValue = modified; - - // Set the location text, which is separate from the intro text so it can be cropped - var location = this.dialogElement( "location" ); - location.value = pathString; - location.setAttribute( "tooltiptext", this.mSourcePath ); - }, - - _timer: null, - notify: function (aTimer) { - try { // The user may have already canceled the dialog. - if (!this._blurred) - this.mDialog.document.documentElement.getButton('accept').disabled = false; - } catch (ex) {} - this._timer = null; - }, - - _blurred: false, - onBlur: function(aEvent) { - if (aEvent.target != this.mDialog.document) - return; - - this._blurred = true; - this.mDialog.document.documentElement.getButton("accept").disabled = true; - }, - - onFocus: function(aEvent) { - if (aEvent.target != this.mDialog.document) - return; - - this._blurred = false; - if (!this._timer) { - // Don't enable the button if the initial timer is running - var script = "document.documentElement.getButton('accept').disabled = false"; - this.mDialog.setTimeout(script, 250); - } - }, - - // Returns true iff opening the default application makes sense. - openWithDefaultOK: function() { - var result; - - // The checking is different on Windows... - if ( this.mDialog.navigator.platform.indexOf( "Win" ) != -1 ) { - // Windows presents some special cases. - // We need to prevent use of "system default" when the file is - // executable (so the user doesn't launch nasty programs downloaded - // from the web), and, enable use of "system default" if it isn't - // executable (because we will prompt the user for the default app - // in that case). - - // Need to get temporary file and check for executable-ness. - var tmpFile = this.mLauncher.targetFile; - - // Default is Ok if the file isn't executable (and vice-versa). - result = !tmpFile.isExecutable(); - } else { - // On other platforms, default is Ok if there is a default app. - // Note that nsIMIMEInfo providers need to ensure that this holds true - // on each platform. - result = this.mLauncher.MIMEInfo.hasDefaultHandler; - } - return result; - }, - - // Set "default" application description field. - initDefaultApp: function() { - // Use description, if we can get one. - var desc = this.mLauncher.MIMEInfo.defaultDescription; - if ( desc ) { - this.dialogElement( "useSystemDefault" ).label = this.replaceInsert( this.getString( "defaultApp" ), 1, desc ); - } - }, - - // getPath: - getPath: function(file) { - if (this.mIsMac) { - return file.leafName || file.path; - } - - return file.path; - }, - - // initAppAndSaveToDiskValues: - initAppAndSaveToDiskValues: function() { - // Fill in helper app info, if there is any. - try { - this.chosenApp = - this.mLauncher.MIMEInfo.preferredApplicationHandler - .QueryInterface(Components.interfaces.nsILocalHandlerApp); - } catch (e) { - this.chosenApp = null; - } - // Initialize "default application" field. - this.initDefaultApp(); - - // Fill application name textbox. - if (this.chosenApp && this.chosenApp.executable && - this.chosenApp.executable.path) { - this.dialogElement( "appPath" ).value = - this.getPath(this.chosenApp.executable); - } - - var useDefault = this.dialogElement( "useSystemDefault" ); - if (this.mLauncher.MIMEInfo.preferredAction == this.nsIMIMEInfo.useSystemDefault && - this.mReason != REASON_SERVERREQUEST) { - // Open (using system default). - useDefault.radioGroup.selectedItem = useDefault; - } else if (this.mLauncher.MIMEInfo.preferredAction == this.nsIMIMEInfo.useHelperApp && - this.mReason != REASON_SERVERREQUEST) { - // Open with given helper app. - var openUsing = this.dialogElement( "openUsing" ); - openUsing.radioGroup.selectedItem = openUsing; - } else { - // Save to disk. - var saveToDisk = this.dialogElement( "saveToDisk" ); - saveToDisk.radioGroup.selectedItem = saveToDisk; - } - // If we don't have a "default app" then disable that choice. - if ( !this.openWithDefaultOK() ) { - // Disable that choice. - useDefault.hidden = true; - // If that's the default, then switch to "save to disk." - if ( useDefault.selected ) { - useDefault.radioGroup.selectedItem = this.dialogElement( "saveToDisk" ); - } - } - - // Enable/Disable choose application button and textfield - this.toggleChoice(); - }, - - // Enable pick app button if the user chooses that option. - toggleChoice : function () { - // See what option is selected. - var openUsing = this.dialogElement( "openUsing" ).selected; - this.dialogElement( "chooseApp" ).disabled = !openUsing; - // appPath is always disabled on Mac - this.dialogElement( "appPath" ).disabled = !openUsing || this.mIsMac; - this.updateOKButton(); - }, - - // Returns the user-selected application - helperAppChoice: function() { - var result = this.chosenApp; - if (!this.mIsMac) { - var typed = this.dialogElement( "appPath" ).value; - // First, see if one was chosen via the Choose... button. - if ( result ) { - // Verify that the user didn't type in something different later. - if ( typed != result.executable.path ) { - // Use what was typed in. - try { - result.executable.QueryInterface( Components.interfaces.nsILocalFile ).initWithPath( typed ); - } catch( e ) { - // Invalid path was typed. - result = null; - } - } - } else { - // The user didn't use the Choose... button, try using what they typed in. - var localFile = Components.classes[ "@mozilla.org/file/local;1" ] - .createInstance( Components.interfaces.nsILocalFile ); - try { - localFile.initWithPath( typed ); - result = Components.classes[ - "@mozilla.org/uriloader/local-handler-app;1"]. - createInstance(Components.interfaces.nsILocalHandlerApp); - result.executable = localFile; - - } catch( e ) { - result = null; - } - } - // Remember what was chosen. - this.chosenApp = result; - } - return result; - }, - - updateOKButton: function() { - var ok = false; - if ( this.dialogElement( "saveToDisk" ).selected ) - { - // This is always OK. - ok = true; - } - else if ( this.dialogElement( "useSystemDefault" ).selected ) - { - // No app need be specified in this case. - ok = true; - } - else - { - // only enable the OK button if we have a default app to use or if - // the user chose an app.... - ok = this.chosenApp || /\S/.test( this.dialogElement( "appPath" ).value ); - } - - // Enable Ok button if ok to press. - this.mDialog.document.documentElement.getButton( "accept" ).disabled = !ok; - }, - - // Returns true iff the user-specified helper app has been modified. - appChanged: function() { - return this.helperAppChoice() != this.mLauncher.MIMEInfo.preferredApplicationHandler; - }, - - updateMIMEInfo: function() { - var needUpdate = false; - // If current selection differs from what's in the mime info object, - // then we need to update. - // However, we don't want to change the action all nsIMIMEInfo objects to - // saveToDisk if mReason is REASON_SERVERREQUEST. - if ( this.dialogElement( "saveToDisk" ).selected && - this.mReason != REASON_SERVERREQUEST ) { - needUpdate = this.mLauncher.MIMEInfo.preferredAction != this.nsIMIMEInfo.saveToDisk; - if ( needUpdate ) - this.mLauncher.MIMEInfo.preferredAction = this.nsIMIMEInfo.saveToDisk; - } else if ( this.dialogElement( "useSystemDefault" ).selected ) { - needUpdate = this.mLauncher.MIMEInfo.preferredAction != this.nsIMIMEInfo.useSystemDefault; - if ( needUpdate ) - this.mLauncher.MIMEInfo.preferredAction = this.nsIMIMEInfo.useSystemDefault; - } else if ( this.dialogElement( "openUsing" ).selected ) { - // For "open with", we need to check both preferred action and whether the user chose - // a new app. - needUpdate = this.mLauncher.MIMEInfo.preferredAction != this.nsIMIMEInfo.useHelperApp || this.appChanged(); - if ( needUpdate ) { - this.mLauncher.MIMEInfo.preferredAction = this.nsIMIMEInfo.useHelperApp; - // App may have changed - Update application - var app = this.helperAppChoice(); - this.mLauncher.MIMEInfo.preferredApplicationHandler = app; - } - } - // Only care about the state of "always ask" if this dialog wasn't forced - if ( this.mReason == REASON_CANTHANDLE ) - { - // We will also need to update if the "always ask" flag has changed. - needUpdate = needUpdate || this.mLauncher.MIMEInfo.alwaysAskBeforeHandling == this.dialogElement( "alwaysHandle" ).checked; - - // One last special case: If the input "always ask" flag was false, then we always - // update. In that case we are displaying the helper app dialog for the first - // time for this mime type and we need to store the user's action in the mimeTypes.rdf - // data source (whether that action has changed or not; if it didn't change, then we need - // to store the "always ask" flag so the helper app dialog will or won't display - // next time, per the user's selection). - needUpdate = needUpdate || !this.mLauncher.MIMEInfo.alwaysAskBeforeHandling; - - // Make sure mime info has updated setting for the "always ask" flag. - this.mLauncher.MIMEInfo.alwaysAskBeforeHandling = !this.dialogElement( "alwaysHandle" ).checked; - } - - return needUpdate; - }, - - // See if the user changed things, and if so, update the - // mimeTypes.rdf entry for this mime type. - updateHelperAppPref: function() { - // We update by passing this mime info into the "Edit Type" helper app - // pref dialog. It will update the data source and close the dialog - // automatically. - this.mDialog.openDialog( "chrome://communicator/content/pref/pref-applications-edit.xul", - "_blank", - "chrome,modal=yes,resizable=no", - this ); - }, - - // onOK: - onOK: function() { - // Verify typed app path, if necessary. - if ( this.dialogElement( "openUsing" ).selected ) { - var helperApp = this.helperAppChoice(); - if ( !helperApp || !helperApp.executable || - !helperApp.executable.exists() ) { - // Show alert and try again. - var msg = this.replaceInsert( this.getString( "badApp" ), 1, this.dialogElement( "appPath" ).value ); - var svc = Components.classes[ "@mozilla.org/embedcomp/prompt-service;1" ] - .getService( Components.interfaces.nsIPromptService ); - svc.alert( this.mDialog, this.getString( "badApp.title" ), msg ); - // Disable the OK button. - this.mDialog.document.documentElement.getButton( "accept" ).disabled = true; - // Select and focus the input field if input field is not disabled - var path = this.dialogElement( "appPath" ); - if ( !path.disabled ) { - path.select(); - path.focus(); - } - // Clear chosen application. - this.chosenApp = null; - // Leave dialog up. - return false; - } - } - - // Remove our web progress listener (a progress dialog will be - // taking over). - this.mLauncher.setWebProgressListener( null ); - - // saveToDisk and launchWithApplication can return errors in - // certain circumstances (e.g. The user clicks cancel in the - // "Save to Disk" dialog. In those cases, we don't want to - // update the helper application preferences in the RDF file. - try { - var needUpdate = this.updateMIMEInfo(); - if ( this.dialogElement( "saveToDisk" ).selected ) - this.mLauncher.saveToDisk( null, false ); - else - this.mLauncher.launchWithApplication( null, false ); - - // Update user pref for this mime type (if necessary). We do not - // store anything in the mime type preferences for the ambiguous - // type application/octet-stream. - if ( needUpdate && - this.mLauncher.MIMEInfo.MIMEType != "application/octet-stream" ) - { - this.updateHelperAppPref(); - } - - } catch(e) { } - - // Unhook dialog from this object. - this.mDialog.dialog = null; - - // Close up dialog by returning true. - return true; - }, - - // onCancel: - onCancel: function() { - // Remove our web progress listener. - this.mLauncher.setWebProgressListener( null ); - - // Cancel app launcher. - try { - const NS_BINDING_ABORTED = 0x804b0002; - this.mLauncher.cancel(NS_BINDING_ABORTED); - } catch( exception ) { - } - - // Unhook dialog from this object. - this.mDialog.dialog = null; - - // Close up dialog by returning true. - return true; - }, - - // dialogElement: Try cache; obtain from document if not there. - dialogElement: function( id ) { - // Check if we've already fetched it. - if ( !( id in this.elements ) ) { - // No, then get it from dialog. - this.elements[ id ] = this.mDialog.document.getElementById( id ); - } - return this.elements[ id ]; - }, - - // chooseApp: Open file picker and prompt user for application. - chooseApp: function() { - var nsIFilePicker = Components.interfaces.nsIFilePicker; - var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance( nsIFilePicker ); - fp.init( this.mDialog, - this.getString( "chooseAppFilePickerTitle" ), - nsIFilePicker.modeOpen ); - - // XXX - We want to say nsIFilePicker.filterExecutable or something - fp.appendFilters( nsIFilePicker.filterAll ); - - if ( fp.show() == nsIFilePicker.returnOK && fp.file ) { - // Remember the file they chose to run. - - var localHandler = Components.classes[ - "@mozilla.org/uriloader/local-handler-app;1"]. - createInstance(Components.interfaces.nsILocalHandlerApp); - localHandler.executable = fp.file; - this.chosenApp = localHandler; - // Update dialog. - this.dialogElement( "appPath" ).value = - this.getPath(this.chosenApp.executable); - } - }, - - // dumpInfo: - doDebug: function() { - const nsIProgressDialog = Components.interfaces.nsIProgressDialog; - // Open new progress dialog. - var progress = Components.classes[ "@mozilla.org/progressdialog;1" ] - .createInstance( nsIProgressDialog ); - // Show it. - progress.open( this.mDialog ); - }, - - // dumpObj: - dumpObj: function( spec ) { - var val = ""; - try { - val = eval( "this."+spec ).toString(); - } catch( exception ) { - } - this.dump( spec + "=" + val + "\n" ); - }, - - // dumpObjectProperties - dumpObjectProperties: function( desc, obj ) { - for( prop in obj ) { - this.dump( desc + "." + prop + "=" ); - var val = ""; - try { - val = obj[ prop ]; - } catch ( exception ) { - } - this.dump( val + "\n" ); - } - }, - - // getString: Fetch data string from dialog content (and cache it). - getString: function( id ) { - // Check if we've fetched this string already. - if ( !( id in this.strings ) ) { - // Try to get it. - var elem = this.mDialog.document.getElementById( id ); - if ( elem - && - elem.firstChild - && - elem.firstChild.nodeValue ) { - this.strings[ id ] = elem.firstChild.nodeValue; - } else { - // If unable to fetch string, use an empty string. - this.strings[ id ] = ""; - } - } - return this.strings[ id ]; - }, - - // replaceInsert: Replace given insert with replacement text and return the result. - replaceInsert: function( text, insertNo, replacementText ) { - var result = text; - var regExp = new RegExp("#"+insertNo); - result = result.replace( regExp, replacementText ); - return result; - } -} - -// This Component's module implementation. All the code below is used to get this -// component registered and accessible via XPCOM. -var module = { - firstTime: true, - - // registerSelf: Register this component. - registerSelf: function (compMgr, fileSpec, location, type) { - if (this.firstTime) { - this.firstTime = false; - throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN; - } - compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar); - - compMgr.registerFactoryLocation( this.cid, - "Mozilla Helper App Launcher Dialog", - this.contractId, - fileSpec, - location, - type ); - }, - - // getClassObject: Return this component's factory object. - getClassObject: function (compMgr, cid, iid) { - if (!cid.equals(this.cid)) { - throw Components.results.NS_ERROR_NO_INTERFACE; - } - - if (!iid.equals(Components.interfaces.nsIFactory)) { - throw Components.results.NS_ERROR_NOT_IMPLEMENTED; - } - - return this.factory; - }, - - /* CID for this class */ - cid: Components.ID("{F68578EB-6EC2-4169-AE19-8C6243F0ABE1}"), - - /* Contract ID for this class */ - contractId: "@mozilla.org/helperapplauncherdialog;1", - - /* factory object */ - factory: { - // createInstance: Return a new nsProgressDialog object. - createInstance: function (outer, iid) { - if (outer != null) - throw Components.results.NS_ERROR_NO_AGGREGATION; - - return (new nsHelperAppDialog()).QueryInterface(iid); - } - }, - - // canUnload: n/a (returns true) - canUnload: function(compMgr) { - return true; - } -}; - -// NSGetModule: Return the nsIModule object. -function NSGetModule(compMgr, fileSpec) { - return module; -} - -// Since we're automatically downloading, we don't get the file picker's -// logic to check for existing files, so we need to do that here. -// -// Note - this code is identical to that in contentAreaUtils.js. -// If you are updating this code, update that code too! We can't share code -// here since this is called in a js component. -function uniqueFile(aLocalFile) { - while (aLocalFile.exists()) { - parts = /(-\d+)?(\.[^.]+)?$/.test(aLocalFile.leafName); - aLocalFile.leafName = RegExp.leftContext + (RegExp.$1 - 1) + RegExp.$2; - } - return aLocalFile; -} diff --git a/embedding/components/ui/helperAppDlg/nsHelperAppDlg.xul b/embedding/components/ui/helperAppDlg/nsHelperAppDlg.xul deleted file mode 100644 index 6e098d0d65f..00000000000 --- a/embedding/components/ui/helperAppDlg/nsHelperAppDlg.xul +++ /dev/null @@ -1,123 +0,0 @@ - - - - - - - - %brandDTD; - - %nsHelperAppDlgDTD; -]> - - - - - - - &intro.label; - - - &prompt.label; - - - - - - - - - - - - - - - - diff --git a/embedding/components/ui/jar.mn b/embedding/components/ui/jar.mn deleted file mode 100644 index 8e80b4c66bd..00000000000 --- a/embedding/components/ui/jar.mn +++ /dev/null @@ -1,3 +0,0 @@ -toolkit.jar: - content/global/nsHelperAppDlg.xul (helperAppDlg/nsHelperAppDlg.xul) - content/global/nsProgressDialog.xul (progressDlg/nsProgressDialog.xul) diff --git a/embedding/components/ui/progressDlg/Makefile.in b/embedding/components/ui/progressDlg/Makefile.in deleted file mode 100644 index d6dc2bfc29a..00000000000 --- a/embedding/components/ui/progressDlg/Makefile.in +++ /dev/null @@ -1,51 +0,0 @@ -# -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is mozilla.org code. -# -# The Initial Developer of the Original Code is -# Netscape Communications, Inc. -# Portions created by the Initial Developer are Copyright (C) 2001 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# -# Alternatively, the contents of this file may be used under the terms of -# either the GNU General Public License Version 2 or later (the "GPL"), or -# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -DEPTH = ../../../.. -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ - -include $(DEPTH)/config/autoconf.mk - -MODULE = progressDlg -XPIDL_MODULE = progressDlg - -EXTRA_COMPONENTS = nsProgressDialog.js - -include $(topsrcdir)/config/rules.mk - diff --git a/embedding/components/ui/progressDlg/nsProgressDialog.js b/embedding/components/ui/progressDlg/nsProgressDialog.js deleted file mode 100644 index 579d42104d3..00000000000 --- a/embedding/components/ui/progressDlg/nsProgressDialog.js +++ /dev/null @@ -1,944 +0,0 @@ -/* vim:set ts=4 sts=4 sw=4 et cin: */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Mozilla Progress Dialog. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corp. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Bill Law - * Aaron Kaluszka - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/* This file implements the nsIProgressDialog interface. See nsIProgressDialog.idl - * - * The implementation consists of a JavaScript "class" named nsProgressDialog, - * comprised of: - * - a JS constructor function - * - a prototype providing all the interface methods and implementation stuff - * - * In addition, this file implements an nsIModule object that registers the - * nsProgressDialog component. - */ - -/* ctor - */ -function nsProgressDialog() { - // Initialize data properties. - this.mParent = null; - this.mOperation = null; - this.mStartTime = ( new Date() ).getTime(); - this.observer = null; - this.mLastUpdate = Number.MIN_VALUE; // To ensure first onProgress causes update. - this.mInterval = 750; // Default to .75 seconds. - this.mElapsed = 0; - this.mLoaded = false; - this.fields = new Array; - this.strings = new Array; - this.mSource = null; - this.mTarget = null; - this.mTargetFile = null; - this.mMIMEInfo = null; - this.mDialog = null; - this.mDisplayName = null; - this.mPaused = false; - this.mRequest = null; - this.mCompleted = false; - this.mMode = "normal"; - this.mPercent = -1; - this.mRate = 0; - this.mBundle = null; - this.mCancelDownloadOnClose = true; -} - -const nsIProgressDialog = Components.interfaces.nsIProgressDialog; -const nsIWindowWatcher = Components.interfaces.nsIWindowWatcher; -const nsIWebProgressListener = Components.interfaces.nsIWebProgressListener; -const nsITextToSubURI = Components.interfaces.nsITextToSubURI; -const nsIChannel = Components.interfaces.nsIChannel; -const nsIFileURL = Components.interfaces.nsIFileURL; -const nsIURL = Components.interfaces.nsIURL; -const nsILocalFile = Components.interfaces.nsILocalFile; - -nsProgressDialog.prototype = { - // Turn this on to get debugging messages. - debug: false, - - // Chrome-related constants. - dialogChrome: "chrome://global/content/nsProgressDialog.xul", - dialogFeatures: "chrome,titlebar,minimizable=yes,dialog=no", - - // getters/setters - get saving() { return this.MIMEInfo == null || - this.MIMEInfo.preferredAction == Components.interfaces.nsIMIMEInfo.saveToDisk; }, - get parent() { return this.mParent; }, - set parent(newval) { return this.mParent = newval; }, - get operation() { return this.mOperation; }, - set operation(newval) { return this.mOperation = newval; }, - get observer() { return this.mObserver; }, - set observer(newval) { return this.mObserver = newval; }, - get startTime() { return this.mStartTime; }, - set startTime(newval) { return this.mStartTime = newval/1000; }, // PR_Now() is in microseconds, so we convert. - get lastUpdate() { return this.mLastUpdate; }, - set lastUpdate(newval) { return this.mLastUpdate = newval; }, - get interval() { return this.mInterval; }, - set interval(newval) { return this.mInterval = newval; }, - get elapsed() { return this.mElapsed; }, - set elapsed(newval) { return this.mElapsed = newval; }, - get loaded() { return this.mLoaded; }, - set loaded(newval) { return this.mLoaded = newval; }, - get source() { return this.mSource; }, - set source(newval) { return this.mSource = newval; }, - get target() { return this.mTarget; }, - get targetFile() { return this.mTargetFile; }, - get MIMEInfo() { return this.mMIMEInfo; }, - set MIMEInfo(newval) { return this.mMIMEInfo = newval; }, - get dialog() { return this.mDialog; }, - set dialog(newval) { return this.mDialog = newval; }, - get displayName() { return this.mDisplayName; }, - set displayName(newval) { return this.mDisplayName = newval; }, - get paused() { return this.mPaused; }, - get completed() { return this.mCompleted; }, - get mode() { return this.mMode; }, - get percent() { return this.mPercent; }, - get rate() { return this.mRate; }, - get kRate() { return this.mRate / 1024; }, - get cancelDownloadOnClose() { return this.mCancelDownloadOnClose; }, - set cancelDownloadOnClose(newval) { return this.mCancelDownloadOnClose = newval; }, - - set target(newval) { - // If newval references a file on the local filesystem, then grab a - // reference to its corresponding nsIFile. - if (newval instanceof nsIFileURL && newval.file instanceof nsILocalFile) { - this.mTargetFile = newval.file.QueryInterface(nsILocalFile); - } else { - this.mTargetFile = null; - } - - return this.mTarget = newval; - }, - - // These setters use functions that update the dialog. - set paused(newval) { return this.setPaused(newval); }, - set completed(newval) { return this.setCompleted(newval); }, - set mode(newval) { return this.setMode(newval); }, - set percent(newval) { return this.setPercent(newval); }, - set rate(newval) { return this.setRate(newval); }, - - // ---------- nsIProgressDialog methods ---------- - - // open: Store aParentWindow and open the dialog. - open: function( aParentWindow ) { - // Save parent and "persist" operation. - this.parent = aParentWindow; - - // Open dialog using the WindowWatcher service. - var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"] - .getService( nsIWindowWatcher ); - this.dialog = ww.openWindow( this.parent, - this.dialogChrome, - null, - this.dialogFeatures, - this ); - }, - - init: function( aSource, aTarget, aDisplayName, aMIMEInfo, aStartTime, - aTempFile, aOperation ) { - this.source = aSource; - this.target = aTarget; - this.displayName = aDisplayName; - this.MIMEInfo = aMIMEInfo; - if ( aStartTime ) { - this.startTime = aStartTime; - } - this.operation = aOperation; - }, - - // ----- nsIDownloadProgressListener/nsIWebProgressListener methods ----- - // Take advantage of javascript's function overloading feature to combine - // similiar nsIDownloadProgressListener and nsIWebProgressListener methods - // in one. For nsIWebProgressListener calls, the aDownload paramater will - // always be undefined. - - // Look for STATE_STOP and update dialog to indicate completion when it happens. - onStateChange: function( aWebProgress, aRequest, aStateFlags, aStatus, aDownload ) { - if ( aStateFlags & nsIWebProgressListener.STATE_STOP ) { - // if we are downloading, then just wait for the first STATE_STOP - if ( this.targetFile != null ) { - // we are done transferring... - this.completed = true; - return; - } - - // otherwise, wait for STATE_STOP with aRequest corresponding to - // our target. XXX redirects might screw up this logic. - try { - var chan = aRequest.QueryInterface(nsIChannel); - if (chan.URI.equals(this.target)) { - // we are done transferring... - this.completed = true; - } - } - catch (e) { - } - } - }, - - // Handle progress notifications. - onProgressChange: function( aWebProgress, - aRequest, - aCurSelfProgress, - aMaxSelfProgress, - aCurTotalProgress, - aMaxTotalProgress, - aDownload ) { - return this.onProgressChange64(aWebProgress, aRequest, aCurSelfProgress, - aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress, aDownload); - }, - - onProgressChange64: function( aWebProgress, - aRequest, - aCurSelfProgress, - aMaxSelfProgress, - aCurTotalProgress, - aMaxTotalProgress, - aDownload ) { - // Get current time. - var now = ( new Date() ).getTime(); - - // If interval hasn't elapsed, ignore it. - if ( now - this.lastUpdate < this.interval ) { - return; - } - - // Update this time. - this.lastUpdate = now; - - // Update elapsed time. - this.elapsed = now - this.startTime; - - // Calculate percentage. - if ( aMaxTotalProgress > 0) { - this.percent = Math.floor( ( aCurTotalProgress * 100.0 ) / aMaxTotalProgress ); - } else { - this.percent = -1; - } - - // If dialog not loaded, then don't bother trying to update display. - if ( !this.loaded ) { - return; - } - - // Update dialog's display of elapsed time. - this.setValue( "timeElapsed", this.formatSeconds( this.elapsed / 1000 ) ); - - // Now that we've set the progress and the time, update # bytes downloaded... - // Update status (nn KB of mm KB at xx.x KB/sec) - var status = this.getString( "progressMsg" ); - - // Insert 1 is the number of kilobytes downloaded so far. - status = this.replaceInsert( status, 1, parseInt( aCurTotalProgress/1024 + .5 ) ); - - // Insert 2 is the total number of kilobytes to be downloaded (if known). - if ( aMaxTotalProgress != "-1" ) { - status = this.replaceInsert( status, 2, parseInt( aMaxTotalProgress/1024 + .5 ) ); - } else { - status = this.replaceInsert( status, 2, "??" ); - } - - // Insert 3 is the download rate. - if ( this.elapsed ) { - // Use the download speed where available, otherwise calculate - // rate using current progress and elapsed time. - if ( aDownload ) { - this.rate = aDownload.speed; - } else { - this.rate = ( aCurTotalProgress * 1000 ) / this.elapsed; - } - status = this.replaceInsert( status, 3, this.kRate.toFixed(1) ); - } else { - // Rate not established, yet. - status = this.replaceInsert( status, 3, "??.?" ); - } - - // All 3 inserts are taken care of, now update status msg. - this.setValue( "status", status ); - - // Update time remaining. - if ( this.rate && ( aMaxTotalProgress > 0 ) ) { - // Calculate how much time to download remaining at this rate. - var rem = Math.round( ( aMaxTotalProgress - aCurTotalProgress ) / this.rate ); - this.setValue( "timeLeft", this.formatSeconds( rem ) ); - } else { - // We don't know how much time remains. - this.setValue( "timeLeft", this.getString( "unknownTime" ) ); - } - }, - - // Look for error notifications and display alert to user. - onStatusChange: function( aWebProgress, aRequest, aStatus, aMessage, aDownload ) { - // Check for error condition (only if dialog is still open). - if ( aStatus != Components.results.NS_OK ) { - if ( this.loaded ) { - // Get prompt service. - var prompter = Components.classes[ "@mozilla.org/embedcomp/prompt-service;1" ] - .getService( Components.interfaces.nsIPromptService ); - // Display error alert (using text supplied by back-end). - var title = this.getProperty( this.saving ? "savingAlertTitle" : "openingAlertTitle", - [ this.fileName() ], - 1 ); - prompter.alert( this.dialog, title, aMessage ); - - // Close the dialog. - if ( !this.completed ) { - this.onCancel(); - } - } else { - // Error occurred prior to onload even firing. - // We can't handle this error until we're done loading, so - // defer the handling of this call. - this.dialog.setTimeout( function(obj,wp,req,stat,msg){obj.onStatusChange(wp,req,stat,msg)}, - 100, this, aWebProgress, aRequest, aStatus, aMessage ); - } - } - }, - - // Ignore onLocationChange and onSecurityChange notifications. - onLocationChange: function( aWebProgress, aRequest, aLocation, aDownload ) { - }, - - onSecurityChange: function( aWebProgress, aRequest, aState, aDownload ) { - }, - - // ---------- nsIObserver methods ---------- - observe: function( anObject, aTopic, aData ) { - // Something of interest occured on the dialog. - // Dispatch to corresponding implementation method. - switch ( aTopic ) { - case "onload": - this.onLoad(); - break; - case "oncancel": - this.onCancel(); - break; - case "onpause": - this.onPause(); - break; - case "onlaunch": - this.onLaunch(); - break; - case "onreveal": - this.onReveal(); - break; - case "onunload": - this.onUnload(); - break; - case "oncompleted": - // This event comes in when setCompleted needs to be deferred because - // the dialog isn't loaded yet. - this.completed = true; - break; - default: - break; - } - }, - - // ---------- nsISupports methods ---------- - - // This "class" supports nsIProgressDialog, nsIWebProgressListener (by virtue - // of interface inheritance), nsIObserver, and nsISupports. - QueryInterface: function (iid) { - if (iid.equals(Components.interfaces.nsIProgressDialog) || - iid.equals(Components.interfaces.nsIDownload) || - iid.equals(Components.interfaces.nsITransfer) || - iid.equals(Components.interfaces.nsIWebProgressListener) || - iid.equals(Components.interfaces.nsIWebProgressListener2) || - iid.equals(Components.interfaces.nsIDownloadProgressListener) || - iid.equals(Components.interfaces.nsIObserver) || - iid.equals(Components.interfaces.nsIInterfaceRequestor) || - iid.equals(Components.interfaces.nsISupports)) - return this; - - throw Components.results.NS_ERROR_NO_INTERFACE; - }, - - // ---------- nsIInterfaceRequestor methods ---------- - - getInterface: function(iid) { - if (iid.equals(Components.interfaces.nsIPrompt) || - iid.equals(Components.interfaces.nsIAuthPrompt)) { - // use the window watcher service to get a nsIPrompt/nsIAuthPrompt impl - var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"] - .getService(Components.interfaces.nsIWindowWatcher); - var prompt; - if (iid.equals(Components.interfaces.nsIPrompt)) - prompt = ww.getNewPrompter(this.parent); - else - prompt = ww.getNewAuthPrompter(this.parent); - return prompt; - } - throw Components.results.NS_ERROR_NO_INTERFACE; - }, - - // ---------- implementation methods ---------- - - // Initialize the dialog. - onLoad: function() { - // Note that onLoad has finished. - this.loaded = true; - - // Fill dialog. - this.loadDialog(); - - // Position dialog. - if ( this.dialog.opener ) { - this.dialog.moveToAlertPosition(); - } else { - this.dialog.centerWindowOnScreen(); - } - - // Set initial focus on "keep open" box. If that box is hidden, or, if - // the download is already complete, then focus is on the cancel/close - // button. The download may be complete if it was really short and the - // dialog took longer to open than to download the data. - if ( !this.completed && !this.saving ) { - this.dialogElement( "keep" ).focus(); - } else { - this.dialogElement( "cancel" ).focus(); - } - }, - - // load dialog with initial contents - loadDialog: function() { - // Check whether we're saving versus opening with a helper app. - if ( !this.saving ) { - // Put proper label on source field. - this.setValue( "sourceLabel", this.getString( "openingSource" ) ); - - // Target is the "preferred" application. Hide if empty. - if ( this.MIMEInfo && - this.MIMEInfo.preferredApplicationHandler && - this.MIMEInfo.preferredApplicationHandler.executable ) { - var appName = - this.MIMEInfo.preferredApplicationHandler.executable.leafName; - if ( appName == null || appName.length == 0 ) { - this.hide( "targetRow" ); - } else { - // Use the "with:" label. - this.setValue( "targetLabel", this.getString( "openingTarget" ) ); - // Name of application. - this.setValue( "target", appName ); - } - } else { - this.hide( "targetRow" ); - } - } else { - // If target is not a local file, then hide extra dialog controls. - if (this.targetFile != null) { - this.setValue( "target", this.targetFile.path ); - } else { - this.setValue( "target", this.target.spec ); - this.hide( "pauseResume" ); - this.hide( "launch" ); - this.hide( "reveal" ); - } - } - - // Set source field. - this.setValue( "source", this.source.spec ); - - var now = ( new Date() ).getTime(); - - // Initialize the elapsed time. - if ( !this.elapsed ) { - this.elapsed = now - this.startTime; - } - - // Update elapsed time display. - this.setValue( "timeElapsed", this.formatSeconds( this.elapsed / 1000 ) ); - this.setValue( "timeLeft", this.getString( "unknownTime" ) ); - - // Initialize the "keep open" box. Hide this if we're opening a helper app - // or if we are uploading. - if ( !this.saving || !this.targetFile ) { - // Hide this in this case. - this.hide( "keep" ); - } else { - // Initialize using last-set value from prefs. - var prefs = Components.classes[ "@mozilla.org/preferences-service;1" ] - .getService( Components.interfaces.nsIPrefBranch ); - if ( prefs ) { - this.dialogElement( "keep" ).checked = prefs.getBoolPref( "browser.download.progressDnldDialog.keepAlive" ); - } - } - - // Initialize title. - this.setTitle(); - }, - - // Cancel button stops the download (if not completed), - // and closes the dialog. - onCancel: function() { - // Cancel the download, if not completed. - if ( !this.completed ) { - if ( this.operation ) { - const NS_BINDING_ABORTED = 0x804b0002; - this.operation.cancel(NS_BINDING_ABORTED); - // XXX We're supposed to clean up files/directories. - } - if ( this.observer ) { - this.observer.observe( this, "oncancel", "" ); - } - this.paused = false; - } - // Test whether the dialog is already closed. - // This will be the case if we've come through onUnload. - if ( this.dialog ) { - // Close the dialog. - this.dialog.close(); - } - }, - - // onunload event means the dialog has closed. - // We go through our onCancel logic to stop the download if still in progress. - onUnload: function() { - // Remember "keep dialog open" setting, if visible. - if ( this.saving ) { - var prefs = Components.classes["@mozilla.org/preferences-service;1"] - .getService( Components.interfaces.nsIPrefBranch ); - if ( prefs ) { - prefs.setBoolPref( "browser.download.progressDnldDialog.keepAlive", this.dialogElement( "keep" ).checked ); - } - } - this.dialog = null; // The dialog is history. - if ( this.mCancelDownloadOnClose ) { - this.onCancel(); - } - }, - - // onpause event means the user pressed the pause/resume button - // Toggle the pause/resume state (see the function setPause(), below).i - onPause: function() { - this.paused = !this.paused; - }, - - // onlaunch event means the user pressed the launch button - // Invoke the launch method of the target file. - onLaunch: function() { - try { - const kDontAskAgainPref = "browser.download.progressDnlgDialog.dontAskForLaunch"; - try { - var pref = Components.classes["@mozilla.org/preferences-service;1"] - .getService(Components.interfaces.nsIPrefBranch); - var dontAskAgain = pref.getBoolPref(kDontAskAgainPref); - } catch (e) { - // we need to ask if we're unsure - dontAskAgain = false; - } - if ( !dontAskAgain && this.targetFile.isExecutable() ) { - try { - var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] - .getService( Components.interfaces.nsIPromptService ); - } catch (ex) { - // getService doesn't return null, it throws - return; - } - var title = this.getProperty( "openingAlertTitle", - [ this.fileName() ], - 1 ); - var msg = this.getProperty( "securityAlertMsg", - [ this.fileName() ], - 1 ); - var dontaskmsg = this.getProperty( "dontAskAgain", - [ ], 0 ); - var checkbox = {value:0}; - var okToProceed = promptService.confirmCheck(this.dialog, title, msg, dontaskmsg, checkbox); - try { - if (checkbox.value != dontAskAgain) - pref.setBoolPref(kDontAskAgainPref, checkbox.value); - } catch (ex) {} - - if ( !okToProceed ) - return; - } - this.targetFile.launch(); - this.dialog.close(); - } catch ( exception ) { - // XXX Need code here to tell user the launch failed! - dump( "nsProgressDialog::onLaunch failed: " + exception + "\n" ); - } - }, - - // onreveal event means the user pressed the "reveal location" button - // Invoke the reveal method of the target file. - onReveal: function() { - try { - this.targetFile.reveal(); - this.dialog.close(); - } catch ( exception ) { - } - }, - - // Get filename from the target. - fileName: function() { - if ( this.targetFile != null ) - return this.targetFile.leafName; - try { - var escapedFileName = this.target.QueryInterface(nsIURL).fileName; - var textToSubURI = Components.classes["@mozilla.org/intl/texttosuburi;1"] - .getService(nsITextToSubURI); - return textToSubURI.unEscapeURIForUI(this.target.originCharset, escapedFileName); - } catch (e) {} - return ""; - }, - - // Set the dialog title. - setTitle: function() { - // Start with saving/opening template. - // If percentage is not known (-1), use alternate template - var title = this.saving - ? ( this.percent != -1 ? this.getString( "savingTitle" ) : this.getString( "unknownSavingTitle" ) ) - : ( this.percent != -1 ? this.getString( "openingTitle" ) : this.getString( "unknownOpeningTitle" ) ); - - - // Use file name as insert 1. - title = this.replaceInsert( title, 1, this.fileName() ); - - // Use percentage as insert 2 (if known). - if ( this.percent != -1 ) { - title = this.replaceInsert( title, 2, this.percent ); - } - - // Set dialog's title property. - if ( this.dialog ) { - this.dialog.document.title = title; - } - }, - - // Update the dialog to indicate specified percent complete. - setPercent: function( percent ) { - // Maximum percentage is 100. - if ( percent > 100 ) { - percent = 100; - } - // Test if percentage is changing. - if ( this.percent != percent ) { - this.mPercent = percent; - - // If dialog not opened yet, bail early. - if ( !this.loaded ) { - return this.mPercent; - } - - if ( percent == -1 ) { - // Progress meter needs to be in "undetermined" mode. - this.mode = "undetermined"; - - // Update progress meter percentage text. - this.setValue( "progressText", "" ); - } else { - // Progress meter needs to be in normal mode. - this.mode = "normal"; - - // Set progress meter thermometer. - this.setValue( "progress", percent ); - - // Update progress meter percentage text. - this.setValue( "progressText", this.replaceInsert( this.getString( "percentMsg" ), 1, percent ) ); - } - - // Update title. - this.setTitle(); - } - return this.mPercent; - }, - - // Update download rate and dialog display. - setRate: function( rate ) { - this.mRate = rate; - return this.mRate; - }, - - // Handle download completion. - setCompleted: function() { - // If dialog hasn't loaded yet, defer this. - if ( !this.loaded ) { - this.dialog.setTimeout( function(obj){obj.setCompleted()}, 100, this ); - return false; - } - if ( !this.mCompleted ) { - this.mCompleted = true; - - // If the "keep dialog open" box is checked, then update dialog. - if ( this.dialog && this.dialogElement( "keep" ).checked ) { - // Indicate completion in status area. - var string = this.getString( "completeMsg" ); - string = this.replaceInsert( string, - 1, - this.formatSeconds( this.elapsed/1000 ) ); - string = this.replaceInsert( string, - 2, - this.targetFile.fileSize >> 10 ); - - this.setValue( "status", string); - // Put progress meter at 100%. - this.percent = 100; - - // Set time remaining to 00:00. - this.setValue( "timeLeft", this.formatSeconds( 0 ) ); - - // Change Cancel button to Close, and give it focus. - var cancelButton = this.dialogElement( "cancel" ); - cancelButton.label = this.getString( "close" ); - cancelButton.focus(); - - // Activate reveal/launch buttons if we enable them. - var enableButtons = true; - try { - var prefs = Components.classes[ "@mozilla.org/preferences-service;1" ] - .getService( Components.interfaces.nsIPrefBranch ); - enableButtons = prefs.getBoolPref( "browser.download.progressDnldDialog.enable_launch_reveal_buttons" ); - } catch ( e ) { - } - - if ( enableButtons ) { - this.enable( "reveal" ); - try { - if ( this.targetFile != null ) { - this.enable( "launch" ); - } - } catch(e) { - } - } - - // Disable the Pause/Resume buttons. - this.dialogElement( "pauseResume" ).disabled = true; - - // Fix up dialog layout (which gets messed up sometimes). - this.dialog.sizeToContent(); - - // GetAttention to show the user that we're done - this.dialog.getAttention(); - } else if ( this.dialog ) { - this.dialog.close(); - } - } - return this.mCompleted; - }, - - // Set progress meter to given mode ("normal" or "undetermined"). - setMode: function( newMode ) { - if ( this.mode != newMode ) { - // Need to update progress meter. - this.dialogElement( "progress" ).setAttribute( "mode", newMode ); - } - return this.mMode = newMode; - }, - - // Set pause/resume state. - setPaused: function( pausing ) { - // If state changing, then update stuff. - if ( this.paused != pausing ) { - var string = pausing ? "resume" : "pause"; - this.dialogElement( "pauseResume" ).label = this.getString(string); - - // If we have an observer, tell it to suspend/resume - if ( this.observer ) { - this.observer.observe( this, pausing ? "onpause" : "onresume" , "" ); - } - } - return this.mPaused = pausing; - }, - - // Format number of seconds in hh:mm:ss form. - formatSeconds: function( secs ) { - // Round the number of seconds to remove fractions. - secs = parseInt( secs + .5 ); - var hours = parseInt( secs/3600 ); - secs -= hours*3600; - var mins = parseInt( secs/60 ); - secs -= mins*60; - var result; - if ( hours ) - result = this.getString( "longTimeFormat" ); - else - result = this.getString( "shortTimeFormat" ); - - if ( hours < 10 ) - hours = "0" + hours; - if ( mins < 10 ) - mins = "0" + mins; - if ( secs < 10 ) - secs = "0" + secs; - - // Insert hours, minutes, and seconds into result string. - result = this.replaceInsert( result, 1, hours ); - result = this.replaceInsert( result, 2, mins ); - result = this.replaceInsert( result, 3, secs ); - - return result; - }, - - // Get dialog element using argument as id. - dialogElement: function( id ) { - // Check if we've already fetched it. - if ( !( id in this.fields ) ) { - // No, then get it from dialog. - try { - this.fields[ id ] = this.dialog.document.getElementById( id ); - } catch(e) { - this.fields[ id ] = { - value: "", - setAttribute: function(id,val) {}, - removeAttribute: function(id) {} - } - } - } - return this.fields[ id ]; - }, - - // Set dialog element value for given dialog element. - setValue: function( id, val ) { - this.dialogElement( id ).value = val; - }, - - // Enable dialog element. - enable: function( field ) { - this.dialogElement( field ).removeAttribute( "disabled" ); - }, - - // Get localizable string from properties file. - getProperty: function( propertyId, strings, len ) { - if ( !this.mBundle ) { - this.mBundle = Components.classes[ "@mozilla.org/intl/stringbundle;1" ] - .getService( Components.interfaces.nsIStringBundleService ) - .createBundle( "chrome://global/locale/nsProgressDialog.properties"); - } - return len ? this.mBundle.formatStringFromName( propertyId, strings, len ) - : this.mBundle.getStringFromName( propertyId ); - }, - - // Get localizable string (from dialog elements). - getString: function ( stringId ) { - // Check if we've fetched this string already. - if ( !( this.strings && stringId in this.strings ) ) { - // Presume the string is empty if we can't get it. - this.strings[ stringId ] = ""; - // Try to get it. - try { - this.strings[ stringId ] = this.dialog.document.getElementById( "string."+stringId ).childNodes[0].nodeValue; - } catch (e) {} - } - return this.strings[ stringId ]; - }, - - // Replaces insert ("#n") with input text. - replaceInsert: function( text, index, value ) { - var result = text; - var regExp = new RegExp( "#"+index ); - result = result.replace( regExp, value ); - return result; - }, - - // Hide a given dialog field. - hide: function( field ) { - this.dialogElement( field ).hidden = true; - - // Also hide any related separator element... - var sep = this.dialogElement( field+"Separator" ); - if (sep) - sep.hidden = true; - }, - - // Return input in hex, prepended with "0x" and leading zeros (to 8 digits). - hex: function( x ) { - return "0x" + ("0000000" + Number(x).toString(16)).slice(-8); - }, - - // Dump text (if debug is on). - dump: function( text ) { - if ( this.debug ) { - dump( text ); - } - } -} - -// This Component's module implementation. All the code below is used to get this -// component registered and accessible via XPCOM. -var module = { - // registerSelf: Register this component. - registerSelf: function (compMgr, fileSpec, location, type) { - var compReg = compMgr.QueryInterface( Components.interfaces.nsIComponentRegistrar ); - compReg.registerFactoryLocation( this.cid, - "Mozilla Download Progress Dialog", - this.contractId, - fileSpec, - location, - type ); - }, - - // getClassObject: Return this component's factory object. - getClassObject: function (compMgr, cid, iid) { - if (!cid.equals(this.cid)) - throw Components.results.NS_ERROR_NO_INTERFACE; - - if (!iid.equals(Components.interfaces.nsIFactory)) - throw Components.results.NS_ERROR_NOT_IMPLEMENTED; - - return this.factory; - }, - - /* CID for this class */ - cid: Components.ID("{F5D248FD-024C-4f30-B208-F3003B85BC92}"), - - /* Contract ID for this class */ - contractId: "@mozilla.org/progressdialog;1", - - /* factory object */ - factory: { - // createInstance: Return a new nsProgressDialog object. - createInstance: function (outer, iid) { - if (outer != null) - throw Components.results.NS_ERROR_NO_AGGREGATION; - - return (new nsProgressDialog()).QueryInterface(iid); - } - }, - - // canUnload: n/a (returns true) - canUnload: function(compMgr) { - return true; - } -}; - -// NSGetModule: Return the nsIModule object. -function NSGetModule(compMgr, fileSpec) { - return module; -} diff --git a/embedding/components/ui/progressDlg/nsProgressDialog.xul b/embedding/components/ui/progressDlg/nsProgressDialog.xul deleted file mode 100644 index fc164a858c9..00000000000 --- a/embedding/components/ui/progressDlg/nsProgressDialog.xul +++ /dev/null @@ -1,169 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - &close; - &progressMsg; - &completeMsg; - &percentMsg; - &shortTimeFormat; - &longTimeFormat; - &unknownTime; - &pausedMsg; - &savingTitle; - &openingTitle; - &openingSource; - &openingTarget; - &unknownSavingTitle; - &unknownOpeningTitle; - &pause; - &resume; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -