⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nshelperappdlg.js

📁 从国外的站点上淘的个人财务管理系统.开源.
💻 JS
📖 第 1 页 / 共 3 页
字号:
/*//@line 42 "/c/builds/1813/mozilla/toolkit/mozapps/downloads/src/nsHelperAppDlg.js.in"*//* This file implements the nsIHelperAppLauncherDialog interface. * * The implementation consists of a JavaScript "class" named nsUnknownContentTypeDialog, * 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 * nsUnknownContentTypeDialog component. *//* ctor */function nsUnknownContentTypeDialog() {    // Initialize data properties.    this.mLauncher = null;    this.mContext  = null;    this.mSourcePath = null;    this.chosenApp = null;    this.givenDefaultApp = false;    this.updateSelf = true;    this.mTitle    = "";}nsUnknownContentTypeDialog.prototype = {    nsIMIMEInfo  : Components.interfaces.nsIMIMEInfo,    // This "class" supports nsIHelperAppLauncherDialog, and nsISupports.    QueryInterface: function (iid) {        if (!iid.equals(Components.interfaces.nsIHelperAppLauncherDialog) &&            !iid.equals(Components.interfaces.nsISupports)) {            throw Components.results.NS_ERROR_NO_INTERFACE;        }        return this;    },    // ---------- 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;      // Display the dialog using the Window Watcher interface.            var ir = aContext.QueryInterface(Components.interfaces.nsIInterfaceRequestor);      var dwi = ir.getInterface(Components.interfaces.nsIDOMWindowInternal);      var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]                .getService(Components.interfaces.nsIWindowWatcher);      this.mDialog = ww.openWindow(dwi,                                   "chrome://mozapps/content/downloads/unknownContentType.xul",                                   null,                                   "chrome,centerscreen,titlebar,dialog=yes,dependent",                                   null);      // Hook this object to the dialog.      this.mDialog.dialog = this;            // Hook up utility functions.       this.getSpecialFolderKey = this.mDialog.getSpecialFolderKey;            // Watch for error notifications.      this.progressListener.helperAppDlg = this;      this.mLauncher.setWebProgressListener(this.progressListener);    },    // promptForSaveToFile:  Display file picker dialog and return selected file.    //                       This is called by the External Helper App Service    //                       after the ucth dialog calls |saveToDisk| with a null    //                       target filename (no target, therefore user must pick).    //    //                       Alternatively, if the user has selected to have all    //                       files download to a specific location, return that    //                       location and don't ask via the dialog.     //    // Note - this function is called without a dialog, so it cannot access any part    // of the dialog XUL as other functions on this object do.     promptForSaveToFile: function(aLauncher, aContext, aDefaultFile, aSuggestedFileExtension) {      var result = "";            this.mLauncher = aLauncher;      // If the user is always downloading to the same location, the default download      // folder is stored in preferences. If a value is found stored, use that       // automatically and don't ask via a dialog.       var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);      var autodownload = prefs.getBoolPref("browser.download.useDownloadDir");      if (autodownload) {        function getSpecialFolderKey(aFolderType)         {          if (aFolderType == "Desktop")            return "Desk";                  if (aFolderType != "Downloads")            throw "ASSERTION FAILED: folder type should be 'Desktop' or 'Downloads'";        //@line 142 "/c/builds/1813/mozilla/toolkit/mozapps/downloads/src/nsHelperAppDlg.js.in"          return "Pers";//@line 150 "/c/builds/1813/mozilla/toolkit/mozapps/downloads/src/nsHelperAppDlg.js.in"        }                function getDownloadsFolder(aFolder)        {          var fileLocator = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties);          var dir = fileLocator.get(getSpecialFolderKey(aFolder), Components.interfaces.nsILocalFile);                    var bundle = Components.classes["@mozilla.org/intl/stringbundle;1"].getService(Components.interfaces.nsIStringBundleService);          bundle = bundle.createBundle("chrome://mozapps/locale/downloads/unknownContentType.properties");          var description = bundle.GetStringFromName("myDownloads");          if (aFolder != "Desktop")            dir.append(description);                      return dir;        }        var defaultFolder = null;        switch (prefs.getIntPref("browser.download.folderList")) {        case 0:          defaultFolder = getDownloadsFolder("Desktop");          break;        case 1:          defaultFolder = getDownloadsFolder("Downloads");          break;        case 2:          defaultFolder = prefs.getComplexValue("browser.download.dir", Components.interfaces.nsILocalFile);          break;        }                result = this.validateLeafName(defaultFolder, aDefaultFile, aSuggestedFileExtension);      }            if (!result) {        // Use file picker to show dialog.        var nsIFilePicker = Components.interfaces.nsIFilePicker;        var picker = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);        var bundle = Components.classes["@mozilla.org/intl/stringbundle;1"].getService(Components.interfaces.nsIStringBundleService);        bundle = bundle.createBundle("chrome://mozapps/locale/downloads/unknownContentType.properties");        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(this.mLauncher.MIMEInfo.description, wildCardExtension);        }        picker.appendFilters( nsIFilePicker.filterAll );        // Pull in the user's preferences and get the default download directory.        var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);        try {          var startDir = prefs.getComplexValue("browser.download.dir", Components.interfaces.nsILocalFile);          if (startDir.exists()) {            picker.displayDirectory = startDir;          }        }         catch(exception) { }        var dlgResult = picker.show();        if (dlgResult == nsIFilePicker.returnCancel) {          // null result means user cancelled.          return null;        }        // Be sure to save the directory the user chose through the Save As...         // dialog  as the new browser.download.dir        result = picker.file;        if (result) {          try {            // Remove the file so that it's not there when we ensure non-existence later;            // this is safe because for the file to exist, the user would have had to            // confirm that he wanted the file overwritten.            if (result.exists())              result.remove(false);          }          catch (e) { }          var newDir = result.parent;          prefs.setComplexValue("browser.download.dir", Components.interfaces.nsILocalFile, newDir);          result = this.validateLeafName(newDir, result.leafName, null);        }      }      return result;    },    /**     * Ensures that a local folder/file combination does not already exist in     * the file system (or finds such a combination with a reasonably similar     * leaf name), creates the corresponding file, and returns it.     *     * @param   aLocalFile     *          the folder where the file resides     * @param   aLeafName     *          the string name of the file (may be empty if no name is known,     *          in which case a name will be chosen)     * @param   aFileExt     *          the extension of the file, if one is known; this will be ignored     *          if aLeafName is non-empty     * @returns nsILocalFile     *          the created file     */    validateLeafName: function (aLocalFile, aLeafName, aFileExt)    {      if (!aLocalFile || !aLocalFile.exists())        return null;      if (aLeafName == "")        aLeafName = "unnamed" + (aFileExt ? "." + aFileExt : "");      aLocalFile.append(aLeafName);      this.makeFileUnique(aLocalFile);      if (aLocalFile.isExecutable() && !this.mLauncher.targetFile.isExecutable()) {        var f = aLocalFile.clone();        aLocalFile.leafName = aLocalFile.leafName + "." + this.mLauncher.MIMEInfo.primaryExtension;         f.remove(false);        this.makeFileUnique(aLocalFile);      }      return aLocalFile;    },    /**     * Generates and returns a uniquely-named file from aLocalFile.  If     * aLocalFile does not exist, it will be the file returned; otherwise, a     * file whose name is similar to that of aLocalFile will be returned.     */    makeFileUnique: function (aLocalFile)    {      try {        // Note - this code is identical to that in         //   toolkit/content/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.         var collisionCount = 0;        while (aLocalFile.exists()) {          collisionCount++;          if (collisionCount == 1) {            // Append "(2)" before the last dot in (or at the end of) the filename            // special case .ext.gz etc files so we don't wind up with .tar(2).gz            if (aLocalFile.leafName.match(/\.[^\.]{1,3}\.(gz|bz2|Z)$/i)) {              aLocalFile.leafName = aLocalFile.leafName.replace(/\.[^\.]{1,3}\.(gz|bz2|Z)$/i, "(2)$&");            }            else {              aLocalFile.leafName = aLocalFile.leafName.replace(/(\.[^\.]*)?$/, "(2)$&");            }          }          else {            // replace the last (n) in the filename with (n+1)            aLocalFile.leafName = aLocalFile.leafName.replace(/^(.*\()\d+\)/, "$1" + (collisionCount+1) + ")");          }        }        aLocalFile.create(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0600);      }      catch (e) {        dump("*** exception in validateLeafName: " + e + "\n");        if (aLocalFile.leafName == "" || aLocalFile.isDirectory()) {          aLocalFile.append("unnamed");          if (aLocalFile.exists())            aLocalFile.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0600);        }      }    },        // ---------- 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, onStateChange, onLocationChange, and onSecurityChange notifications.        onProgressChange: function( aWebProgress,                                    aRequest,                                    aCurSelfProgress,                                    aMaxSelfProgress,                                    aCurTotalProgress,                                    aMaxTotalProgress ) {        },        onProgressChange64: function( aWebProgress,                                      aRequest,                                      aCurSelfProgress,                                      aMaxSelfProgress,                                      aCurTotalProgress,                                      aMaxTotalProgress ) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -