📄 nsprogressdialog.js
字号:
// 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 ) { }, onSecurityChange: function( aWebProgress, aRequest, state ) { }, // ---------- 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.nsIObserver) || iid.equals(Components.interfaces.nsIInterfaceRequestor) || iid.equals(Components.interfaces.nsISupports)) return this; Components.returnCode = Components.results.NS_ERROR_NO_INTERFACE; return null; }, // ---------- 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; } Components.returnCode = Components.results.NS_ERROR_NO_INTERFACE; return null; }, // ---------- 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 ) { var appName = this.MIMEInfo.preferredApplicationHandler.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(); // Intialize 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; } },
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -