📄 nsextensionmanager.js
字号:
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- *//* ***** 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 Extension Manager. * * The Initial Developer of the Original Code is Ben Goodger. * Portions created by the Initial Developer are Copyright (C) 2004 * the Initial Developer. All Rights Reserved. * * Contributor(s): * Ben Goodger <ben@mozilla.org> (Google Inc.) * Benjamin Smedberg <benjamin@smedbergs.us> * Jens Bannmann <jens.b@web.de> * Robert Strong <robert.bugzilla@gmail.com> * Dave Townsend <dave.townsend@blueprintit.co.uk> * Daniel Veditz <dveditz@mozilla.com> * * 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 ***** *///// TODO:// - better logging//const nsIExtensionManager = Components.interfaces.nsIExtensionManager;const nsIAddonUpdateCheckListener = Components.interfaces.nsIAddonUpdateCheckListener;const nsIUpdateItem = Components.interfaces.nsIUpdateItem;const nsILocalFile = Components.interfaces.nsILocalFile;const nsILineInputStream = Components.interfaces.nsILineInputStream;const nsIInstallLocation = Components.interfaces.nsIInstallLocation;const nsIURL = Components.interfaces.nsIURL// XXXrstrong calling hasMoreElements on a nsIDirectoryEnumerator after// it has been removed will cause a crash on Mac OS X - bug 292823const nsIDirectoryEnumerator = Components.interfaces.nsIDirectoryEnumerator;const PREF_EM_CHECK_COMPATIBILITY = "extensions.checkCompatibility";const PREF_EM_LAST_APP_VERSION = "extensions.lastAppVersion";const PREF_UPDATE_COUNT = "extensions.update.count";const PREF_UPDATE_DEFAULT_URL = "extensions.update.url";const PREF_EM_IGNOREMTIMECHANGES = "extensions.ignoreMTimeChanges";const PREF_EM_DISABLEDOBSOLETE = "extensions.disabledObsolete";const PREF_EM_LAST_SELECTED_SKIN = "extensions.lastSelectedSkin";const PREF_EM_EXTENSION_FORMAT = "extensions.%UUID%.";const PREF_EM_ITEM_UPDATE_ENABLED = "extensions.%UUID%.update.enabled";const PREF_EM_UPDATE_ENABLED = "extensions.update.enabled";const PREF_EM_ITEM_UPDATE_URL = "extensions.%UUID%.update.url";const PREF_EM_DSS_ENABLED = "extensions.dss.enabled";const PREF_DSS_SWITCHPENDING = "extensions.dss.switchPending";const PREF_DSS_SKIN_TO_SELECT = "extensions.lastSelectedSkin";const PREF_GENERAL_SKINS_SELECTEDSKIN = "general.skins.selectedSkin";const PREF_EM_LOGGING_ENABLED = "extensions.logging.enabled";const PREF_EM_UPDATE_INTERVAL = "extensions.update.interval";const PREF_BLOCKLIST_URL = "extensions.blocklist.url";const PREF_BLOCKLIST_DETAILS_URL = "extensions.blocklist.detailsURL";const PREF_BLOCKLIST_ENABLED = "extensions.blocklist.enabled";const PREF_BLOCKLIST_INTERVAL = "extensions.blocklist.interval";const PREF_UPDATE_NOTIFYUSER = "extensions.update.notifyUser";const DIR_EXTENSIONS = "extensions";const DIR_CHROME = "chrome";const DIR_STAGE = "staged-xpis";const FILE_EXTENSIONS = "extensions.rdf";const FILE_EXTENSION_MANIFEST = "extensions.ini";const FILE_EXTENSIONS_STARTUP_CACHE = "extensions.cache";const FILE_AUTOREG = ".autoreg";const FILE_INSTALL_MANIFEST = "install.rdf";const FILE_CONTENTS_MANIFEST = "contents.rdf";const FILE_CHROME_MANIFEST = "chrome.manifest";const FILE_BLOCKLIST = "blocklist.xml";const UNKNOWN_XPCOM_ABI = "unknownABI";const FILE_LOGFILE = "extensionmanager.log";const FILE_DEFAULT_THEME_JAR = "classic.jar";const TOOLKIT_ID = "toolkit@mozilla.org"const KEY_PROFILEDIR = "ProfD";const KEY_PROFILEDS = "ProfDS";const KEY_APPDIR = "XCurProcD";const KEY_TEMPDIR = "TmpD";const EM_ACTION_REQUESTED_TOPIC = "em-action-requested";const EM_ITEM_INSTALLED = "item-installed";const EM_ITEM_UPGRADED = "item-upgraded";const EM_ITEM_UNINSTALLED = "item-uninstalled";const EM_ITEM_ENABLED = "item-enabled";const EM_ITEM_DISABLED = "item-disabled";const EM_ITEM_CANCEL = "item-cancel-action";const OP_NONE = "";const OP_NEEDS_INSTALL = "needs-install";const OP_NEEDS_UPGRADE = "needs-upgrade";const OP_NEEDS_UNINSTALL = "needs-uninstall";const OP_NEEDS_ENABLE = "needs-enable";const OP_NEEDS_DISABLE = "needs-disable";const KEY_APP_PROFILE = "app-profile";const KEY_APP_GLOBAL = "app-global";const CATEGORY_INSTALL_LOCATIONS = "extension-install-locations";const PREFIX_NS_EM = "http://www.mozilla.org/2004/em-rdf#";const PREFIX_NS_CHROME = "http://www.mozilla.org/rdf/chrome#";const PREFIX_ITEM_URI = "urn:mozilla:item:";const PREFIX_EXTENSION = "urn:mozilla:extension:";const PREFIX_THEME = "urn:mozilla:theme:";const RDFURI_INSTALL_MANIFEST_ROOT = "urn:mozilla:install-manifest";const RDFURI_ITEM_ROOT = "urn:mozilla:item:root"const RDFURI_DEFAULT_THEME = "urn:mozilla:item:{972ce4c6-7e08-4474-a285-3208198ce6fd}";const XMLURI_PARSE_ERROR = "http://www.mozilla.org/newlayout/xml/parsererror.xml"const XMLURI_BLOCKLIST = "http://www.mozilla.org/2006/addons-blocklist";const URI_GENERIC_ICON_XPINSTALL = "chrome://mozapps/skin/xpinstall/xpinstallItemGeneric.png";const URI_GENERIC_ICON_THEME = "chrome://mozapps/skin/extensions/themeGeneric.png";const URI_XPINSTALL_CONFIRM_DIALOG = "chrome://mozapps/content/xpinstall/xpinstallConfirm.xul";const URI_FINALIZE_DIALOG = "chrome://mozapps/content/extensions/finalize.xul";const URI_EXTENSIONS_PROPERTIES = "chrome://mozapps/locale/extensions/extensions.properties";const URI_BRAND_PROPERTIES = "chrome://branding/locale/brand.properties";const URI_DOWNLOADS_PROPERTIES = "chrome://mozapps/locale/downloads/downloads.properties";const URI_EXTENSION_UPDATE_DIALOG = "chrome://mozapps/content/extensions/update.xul";const URI_EXTENSION_LIST_DIALOG = "chrome://mozapps/content/extensions/list.xul";const INSTALLERROR_SUCCESS = 0;const INSTALLERROR_INVALID_VERSION = -1;const INSTALLERROR_INVALID_GUID = -2;const INSTALLERROR_INCOMPATIBLE_VERSION = -3;const INSTALLERROR_PHONED_HOME = -4;const INSTALLERROR_INCOMPATIBLE_PLATFORM = -5;const INSTALLERROR_BLOCKLISTED = -6;const MODE_RDONLY = 0x01;const MODE_WRONLY = 0x02;const MODE_CREATE = 0x08;const MODE_APPEND = 0x10;const MODE_TRUNCATE = 0x20;const PERMS_FILE = 0644;const PERMS_DIRECTORY = 0755;var gApp = null;var gPref = null;var gRDF = null;var gOS = null;var gXPCOMABI = null;var gOSTarget = null;var gConsole = null;var gInstallManifestRoot = null;var gVersionChecker = null;var gLoggingEnabled = null;var gCheckCompatibility = true;/** * Valid GUIDs fit this pattern. */var gIDTest = /^(\{[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\}|[a-z0-9-\._]*\@[a-z0-9-\._]+)$/i;// shared code for suppressing bad cert dialogs//@line 40 "/c/builds/1813/mozilla/toolkit/mozapps/extensions/src/../../shared/src/badCertHandler.js"/** * Only allow built-in certs for HTTPS connections. See bug 340198. */function checkCert(channel) { if (!channel.originalURI.schemeIs("https")) // bypass return; const Ci = Components.interfaces; var cert = channel.securityInfo.QueryInterface(Ci.nsISSLStatusProvider). SSLStatus.QueryInterface(Ci.nsISSLStatus).serverCert; var issuer = cert.issuer; while (issuer && !cert.equals(issuer)) { cert = issuer; issuer = cert.issuer; } if (!issuer || issuer.tokenName != "Builtin Object Token") throw "cert issuer is not built-in";}/** * This class implements nsIBadCertListener. It's job is to prevent "bad cert" * security dialogs from being shown to the user. It is better to simply fail * if the certificate is bad. See bug 304286. */function BadCertHandler() {}BadCertHandler.prototype = { // nsIBadCertListener confirmUnknownIssuer: function(socketInfo, cert, certAddType) { LOG("EM BadCertHandler: Unknown issuer"); return false; }, confirmMismatchDomain: function(socketInfo, targetURL, cert) { LOG("EM BadCertHandler: Mismatched domain"); return false; }, confirmCertExpired: function(socketInfo, cert) { LOG("EM BadCertHandler: Expired certificate"); return false; }, notifyCrlNextupdate: function(socketInfo, targetURL, cert) { }, // nsIChannelEventSink onChannelRedirect: function(oldChannel, newChannel, flags) { // make sure the certificate of the old channel checks out before we follow // a redirect from it. See bug 340198. checkCert(oldChannel); }, // nsIInterfaceRequestor getInterface: function(iid) { if (iid.equals(Components.interfaces.nsIBadCertListener) || iid.equals(Components.interfaces.nsIChannelEventSink)) return this; Components.returnCode = Components.results.NS_ERROR_NO_INTERFACE; return null; }, // nsISupports QueryInterface: function(iid) { if (!iid.equals(Components.interfaces.nsIBadCertListener) && !iid.equals(Components.interfaces.nsIChannelEventSink) && !iid.equals(Components.interfaces.nsIInterfaceRequestor) && !iid.equals(Components.interfaces.nsISupports)) throw Components.results.NS_ERROR_NO_INTERFACE; return this; }};//@line 183 "/c/builds/1813/mozilla/toolkit/mozapps/extensions/src/nsExtensionManager.js.in"/** * Creates a Version Checker object. * @returns A handle to the global Version Checker service. */function getVersionChecker() { if (!gVersionChecker) { gVersionChecker = Components.classes["@mozilla.org/xpcom/version-comparator;1"] .getService(Components.interfaces.nsIVersionComparator); } return gVersionChecker;}var BundleManager = { /** * Creates and returns a String Bundle at the specified URI * @param bundleURI * The URI of the bundle to load * @returns A nsIStringBundle which was retrieved. */ getBundle: function(bundleURI) { var sbs = Components.classes["@mozilla.org/intl/stringbundle;1"] .getService(Components.interfaces.nsIStringBundleService); return sbs.createBundle(bundleURI); }, _appName: "", /** * The Application's display name. */ get appName() { if (!this._appName) { var brandBundle = this.getBundle(URI_BRAND_PROPERTIES) this._appName = brandBundle.GetStringFromName("brandShortName"); } return this._appName; }};/////////////////////////////////////////////////////////////////////////////////// Utility Functions//function EM_NS(property) { return PREFIX_NS_EM + property;}function CHROME_NS(property) { return PREFIX_NS_CHROME + property;}function EM_R(property) { return gRDF.GetResource(EM_NS(property));}function EM_L(literal) { return gRDF.GetLiteral(literal);}function EM_I(integer) { return gRDF.GetIntLiteral(integer);}function EM_D(integer) { return gRDF.GetDateLiteral(integer);}/** * Gets a preference value, handling the case where there is no default. * @param func * The name of the preference function to call, on nsIPrefBranch * @param preference * The name of the preference * @param defaultValue * The default value to return in the event the preference has * no setting * @returns The value of the preference, or undefined if there was no * user or default value. */function getPref(func, preference, defaultValue) { try { return gPref[func](preference); } catch (e) { } return defaultValue;}/** * Initializes a RDF Container at a URI in a datasource. * @param datasource * The datasource the container is in * @param root * The RDF Resource which is the root of the container. * @returns The nsIRDFContainer, initialized at the root. */function getContainer(datasource, root) { var ctr = Components.classes["@mozilla.org/rdf/container;1"] .createInstance(Components.interfaces.nsIRDFContainer); ctr.Init(datasource, root); return ctr;}/** * Gets a RDF Resource for item with the given ID * @param id * The GUID of the item to construct a RDF resource to the * active item for * @returns The RDF Resource to the Active item. */function getResourceForID(id) { return gRDF.GetResource(PREFIX_ITEM_URI + id);}/**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -