2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2007-08-16 14:17:45 -07:00
|
|
|
/*
|
|
|
|
# ***** 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>
|
2008-03-14 16:34:32 -07:00
|
|
|
# Dave Townsend <dtownsend@oxymoronical.com>
|
2007-08-16 14:17:45 -07:00
|
|
|
# Daniel Veditz <dveditz@mozilla.com>
|
2007-08-29 01:16:15 -07:00
|
|
|
# Alexander J. Vincent <ajvincent@gmail.com>
|
2007-08-16 14:17:45 -07:00
|
|
|
#
|
|
|
|
# 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 *****
|
|
|
|
*/
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//
|
|
|
|
// TODO:
|
|
|
|
// - better logging
|
|
|
|
//
|
|
|
|
|
2007-09-03 20:07:11 -07:00
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cr = Components.results;
|
|
|
|
|
|
|
|
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
2009-09-17 02:03:33 -07:00
|
|
|
Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm");
|
2009-10-23 12:42:48 -07:00
|
|
|
Components.utils.import("resource://gre/modules/FileUtils.jsm");
|
2007-09-03 20:07:11 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
const PREF_EM_CHECK_COMPATIBILITY = "extensions.checkCompatibility";
|
2007-09-03 14:44:12 -07:00
|
|
|
const PREF_EM_CHECK_UPDATE_SECURITY = "extensions.checkUpdateSecurity";
|
2007-03-22 10:30:00 -07:00
|
|
|
const PREF_EM_LAST_APP_VERSION = "extensions.lastAppVersion";
|
2008-01-25 01:30:41 -08:00
|
|
|
const PREF_EM_ENABLED_ITEMS = "extensions.enabledItems";
|
2007-03-22 10:30:00 -07:00
|
|
|
const PREF_UPDATE_COUNT = "extensions.update.count";
|
|
|
|
const PREF_UPDATE_DEFAULT_URL = "extensions.update.url";
|
2008-03-07 16:16:38 -08:00
|
|
|
const PREF_EM_NEW_ADDONS_LIST = "extensions.newAddons";
|
2009-09-15 05:40:49 -07:00
|
|
|
const PREF_EM_DISABLED_ADDONS_LIST = "extensions.disabledAddons";
|
|
|
|
const PREF_EM_SHOW_MISMATCH_UI = "extensions.showMismatchUI";
|
2007-03-22 10:30:00 -07:00
|
|
|
const PREF_EM_IGNOREMTIMECHANGES = "extensions.ignoreMTimeChanges";
|
|
|
|
const PREF_EM_DISABLEDOBSOLETE = "extensions.disabledObsolete";
|
|
|
|
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";
|
2009-09-17 02:03:33 -07:00
|
|
|
const PREF_LWTHEME_TO_SELECT = "extensions.lwThemeToSelect";
|
2007-03-22 10:30:00 -07:00
|
|
|
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_UPDATE_NOTIFYUSER = "extensions.update.notifyUser";
|
2007-06-25 14:02:46 -07:00
|
|
|
const PREF_MATCH_OS_LOCALE = "intl.locale.matchOS";
|
|
|
|
const PREF_SELECTED_LOCALE = "general.useragent.locale";
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
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";
|
2007-12-11 16:56:09 -08:00
|
|
|
const FILE_EXTENSIONS_LOG = "extensions.log";
|
2007-03-22 10:30:00 -07:00
|
|
|
const FILE_INSTALL_MANIFEST = "install.rdf";
|
|
|
|
const FILE_CHROME_MANIFEST = "chrome.manifest";
|
|
|
|
|
|
|
|
const UNKNOWN_XPCOM_ABI = "unknownABI";
|
|
|
|
|
|
|
|
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";
|
2008-01-15 07:13:59 -08:00
|
|
|
const KEY_APP_SYSTEM_LOCAL = "app-system-local";
|
|
|
|
const KEY_APP_SYSTEM_SHARE = "app-system-share";
|
|
|
|
const KEY_APP_SYSTEM_USER = "app-system-user";
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
const CATEGORY_INSTALL_LOCATIONS = "extension-install-locations";
|
2007-08-15 00:49:12 -07:00
|
|
|
const CATEGORY_UPDATE_PARAMS = "extension-update-params";
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
const PREFIX_NS_EM = "http://www.mozilla.org/2004/em-rdf#";
|
|
|
|
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 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_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";
|
|
|
|
|
2009-09-17 02:03:33 -07:00
|
|
|
const URI_EXTENSION_MANAGER = "chrome://mozapps/content/extensions/extensions.xul";
|
|
|
|
const FEATURES_EXTENSION_MANAGER = "chrome,menubar,extra-chrome,toolbar,dialog=no,resizable";
|
|
|
|
const FEATURES_EXTENSION_UPDATES = "chrome,centerscreen,extra-chrome,dialog,resizable,modal";
|
|
|
|
|
2009-09-10 11:50:41 -07:00
|
|
|
/**
|
|
|
|
* Constants that internal code can use to indicate the reason for an add-on
|
|
|
|
* update check. external code uses other constants in nsIExtensionManager.idl.
|
|
|
|
*/
|
|
|
|
const MAX_PUBLIC_UPDATE_WHEN = 15;
|
|
|
|
const UPDATE_WHEN_PERIODIC_UPDATE = 16;
|
|
|
|
const UPDATE_WHEN_ADDON_INSTALLED = 17;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bitmask of the different types of update check.
|
|
|
|
*/
|
|
|
|
const UPDATE_TYPE_COMPATIBILITY = 32;
|
|
|
|
const UPDATE_TYPE_NEWVERSION = 64;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
const INSTALLERROR_SUCCESS = 0;
|
|
|
|
const INSTALLERROR_INVALID_VERSION = -1;
|
|
|
|
const INSTALLERROR_INVALID_GUID = -2;
|
|
|
|
const INSTALLERROR_INCOMPATIBLE_VERSION = -3;
|
2008-11-26 07:04:13 -08:00
|
|
|
const INSTALLERROR_PHONING_HOME = -4;
|
2007-03-22 10:30:00 -07:00
|
|
|
const INSTALLERROR_INCOMPATIBLE_PLATFORM = -5;
|
|
|
|
const INSTALLERROR_BLOCKLISTED = -6;
|
2007-09-03 14:44:12 -07:00
|
|
|
const INSTALLERROR_INSECURE_UPDATE = -7;
|
2008-03-14 16:34:32 -07:00
|
|
|
const INSTALLERROR_INVALID_MANIFEST = -8;
|
|
|
|
const INSTALLERROR_RESTRICTED = -9;
|
2008-11-02 04:13:48 -08:00
|
|
|
const INSTALLERROR_SOFTBLOCKED = -10;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-11-04 21:50:52 -08:00
|
|
|
const REQ_VERSION = 2;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var gApp = null;
|
|
|
|
var gPref = null;
|
|
|
|
var gRDF = null;
|
|
|
|
var gOS = null;
|
2009-11-09 10:14:13 -08:00
|
|
|
var gCheckCompatibilityPref;
|
2008-08-14 02:43:43 -07:00
|
|
|
var gEmSingleton = null;
|
2007-08-15 17:43:12 -07:00
|
|
|
var gBlocklist = null;
|
2007-03-22 10:30:00 -07:00
|
|
|
var gXPCOMABI = null;
|
|
|
|
var gOSTarget = null;
|
|
|
|
var gConsole = null;
|
|
|
|
var gInstallManifestRoot = null;
|
|
|
|
var gVersionChecker = null;
|
|
|
|
var gLoggingEnabled = null;
|
|
|
|
var gCheckCompatibility = true;
|
2007-09-03 14:44:12 -07:00
|
|
|
var gCheckUpdateSecurity = true;
|
2007-06-25 14:02:46 -07:00
|
|
|
var gLocale = "en-US";
|
2008-03-07 16:16:38 -08:00
|
|
|
var gFirstRun = false;
|
2008-07-25 09:23:25 -07:00
|
|
|
var gAllowFlush = true;
|
|
|
|
var gDSNeedsFlush = false;
|
|
|
|
var gManifestNeedsFlush = false;
|
2009-09-17 02:03:33 -07:00
|
|
|
var gDefaultTheme = "classic/1.0";
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-08-29 01:16:15 -07:00
|
|
|
/**
|
2007-03-22 10:30:00 -07:00
|
|
|
* 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;
|
|
|
|
|
2010-01-07 08:44:22 -08:00
|
|
|
var gBranchVersion = /^([^\.]+\.[0-9]+[a-z]*).*/gi;
|
2009-11-09 10:14:13 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// shared code for suppressing bad cert dialogs
|
2009-10-13 12:45:20 -07:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "gCertUtils", function() {
|
|
|
|
let temp = { };
|
|
|
|
Components.utils.import("resource://gre/modules/CertUtils.jsm", temp);
|
|
|
|
return temp;
|
|
|
|
});
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a Version Checker object.
|
|
|
|
* @returns A handle to the global Version Checker service.
|
|
|
|
*/
|
|
|
|
function getVersionChecker() {
|
|
|
|
if (!gVersionChecker) {
|
2007-09-03 20:07:11 -07:00
|
|
|
gVersionChecker = Cc["@mozilla.org/xpcom/version-comparator;1"].
|
|
|
|
getService(Ci.nsIVersionComparator);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return gVersionChecker;
|
|
|
|
}
|
|
|
|
|
2007-08-29 01:16:15 -07:00
|
|
|
var BundleManager = {
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
getBundle: function BundleManager_getBundle(bundleURI) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var sbs = Cc["@mozilla.org/intl/stringbundle;1"].
|
|
|
|
getService(Ci.nsIStringBundleService);
|
2007-03-22 10:30:00 -07:00
|
|
|
return sbs.createBundle(bundleURI);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
_appName: "",
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* 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 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
|
2007-08-29 01:16:15 -07:00
|
|
|
* The default value to return in the event the preference has
|
2007-03-22 10:30:00 -07:00
|
|
|
* 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) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var ctr = Cc["@mozilla.org/rdf/container;1"].
|
|
|
|
createInstance(Ci.nsIRDFContainer);
|
2007-03-22 10:30:00 -07:00
|
|
|
ctr.Init(datasource, root);
|
|
|
|
return ctr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a RDF Resource for item with the given ID
|
|
|
|
* @param id
|
2007-08-29 01:16:15 -07:00
|
|
|
* The GUID of the item to construct a RDF resource to the
|
2007-03-22 10:30:00 -07:00
|
|
|
* active item for
|
2007-08-29 01:16:15 -07:00
|
|
|
* @returns The RDF Resource to the Active item.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
function getResourceForID(id) {
|
|
|
|
return gRDF.GetResource(PREFIX_ITEM_URI + id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct a nsIUpdateItem with the supplied metadata
|
|
|
|
* ...
|
|
|
|
*/
|
2007-08-29 01:16:15 -07:00
|
|
|
function makeItem(id, version, locationKey, minVersion, maxVersion, name,
|
2007-09-03 14:44:12 -07:00
|
|
|
updateURL, updateHash, iconURL, updateRDF, updateKey, type,
|
|
|
|
targetAppID) {
|
2007-08-29 01:16:15 -07:00
|
|
|
var item = new UpdateItem();
|
2007-03-22 10:30:00 -07:00
|
|
|
item.init(id, version, locationKey, minVersion, maxVersion, name,
|
2007-09-03 14:44:12 -07:00
|
|
|
updateURL, updateHash, iconURL, updateRDF, updateKey, type,
|
|
|
|
targetAppID);
|
2007-03-22 10:30:00 -07:00
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the descriptor of a directory as a relative path to common base
|
|
|
|
* directories (profile, user home, app install dir, etc).
|
|
|
|
*
|
|
|
|
* @param itemLocation
|
|
|
|
* The nsILocalFile representing the item's directory.
|
|
|
|
* @param installLocation the nsIInstallLocation for this item
|
|
|
|
*/
|
|
|
|
function getDescriptorFromFile(itemLocation, installLocation) {
|
|
|
|
var baseDir = installLocation.location;
|
|
|
|
|
|
|
|
if (baseDir && baseDir.contains(itemLocation, true)) {
|
|
|
|
return "rel%" + itemLocation.getRelativeDescriptor(baseDir);
|
|
|
|
}
|
|
|
|
|
|
|
|
return "abs%" + itemLocation.persistentDescriptor;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAbsoluteDescriptor(itemLocation) {
|
|
|
|
return itemLocation.persistentDescriptor;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes a Local File object based on a descriptor
|
|
|
|
* provided by "getDescriptorFromFile".
|
|
|
|
*
|
|
|
|
* @param descriptor
|
|
|
|
* The descriptor that locates the directory
|
|
|
|
* @param installLocation
|
|
|
|
* The nsIInstallLocation object for this item.
|
|
|
|
* @returns The nsILocalFile object representing the location of the item
|
|
|
|
*/
|
|
|
|
function getFileFromDescriptor(descriptor, installLocation) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var location = Cc["@mozilla.org/file/local;1"].
|
2007-09-17 11:05:04 -07:00
|
|
|
createInstance(Ci.nsILocalFile);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
var m = descriptor.match(/^(abs|rel)\%(.*)$/);
|
|
|
|
if (!m)
|
2007-09-03 20:07:11 -07:00
|
|
|
throw Cr.NS_ERROR_INVALID_ARG;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (m[1] == "rel") {
|
|
|
|
location.setRelativeDescriptor(installLocation.location, m[2]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
location.persistentDescriptor = m[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
return location;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines if a file is an item package - either a XPI or a JAR file.
|
|
|
|
* @param file
|
|
|
|
* The file to check
|
|
|
|
* @returns true if the file is an item package, false otherwise.
|
|
|
|
*/
|
|
|
|
function fileIsItemPackage(file) {
|
|
|
|
var fileURL = getURIFromFile(file);
|
2007-09-17 11:05:04 -07:00
|
|
|
if (fileURL instanceof Ci.nsIURL)
|
2007-03-22 10:30:00 -07:00
|
|
|
var extension = fileURL.fileExtension.toLowerCase();
|
|
|
|
return extension == "xpi" || extension == "jar";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes a directory and its children. First it tries nsIFile::Remove(true).
|
|
|
|
* If that fails it will fall back to recursing, setting the appropriate
|
|
|
|
* permissions, and deleting the current entry. This is needed for when we have
|
|
|
|
* rights to delete a directory but there are entries that have a read-only
|
|
|
|
* attribute (e.g. a copy restore from a read-only CD, etc.)
|
|
|
|
* @param dir
|
|
|
|
* A nsIFile for the directory to be deleted
|
|
|
|
*/
|
|
|
|
function removeDirRecursive(dir) {
|
|
|
|
try {
|
|
|
|
dir.remove(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
var dirEntries = dir.directoryEntries;
|
|
|
|
while (dirEntries.hasMoreElements()) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var entry = dirEntries.getNext().QueryInterface(Ci.nsIFile);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (entry.isDirectory()) {
|
|
|
|
removeDirRecursive(entry);
|
|
|
|
}
|
|
|
|
else {
|
2009-10-23 12:42:48 -07:00
|
|
|
entry.permissions = FileUtils.PERMS_FILE;
|
2007-03-22 10:30:00 -07:00
|
|
|
entry.remove(false);
|
|
|
|
}
|
|
|
|
}
|
2009-10-23 12:42:48 -07:00
|
|
|
dir.permissions = FileUtils.PERMS_DIRECTORY;
|
2007-03-22 10:30:00 -07:00
|
|
|
dir.remove(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-08-19 03:32:15 -07:00
|
|
|
* Logs a string to the error console and the text console if logging is
|
|
|
|
* enabled.
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param string
|
2009-08-19 03:32:15 -07:00
|
|
|
* The log message.
|
2007-08-29 01:16:15 -07:00
|
|
|
*/
|
2007-03-22 10:30:00 -07:00
|
|
|
function LOG(string) {
|
|
|
|
if (gLoggingEnabled) {
|
2009-08-19 03:32:15 -07:00
|
|
|
dump("*** EM_LOG *** " + string + "\n");
|
2007-08-30 17:43:24 -07:00
|
|
|
if (gConsole)
|
|
|
|
gConsole.logStringMessage(string);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-11 16:56:09 -08:00
|
|
|
/**
|
2009-08-19 03:32:15 -07:00
|
|
|
* Logs a warning to the error console and if logging is enabled to the text
|
|
|
|
* console.
|
2007-12-11 16:56:09 -08:00
|
|
|
* @param string
|
2009-08-19 03:32:15 -07:00
|
|
|
* The warning message.
|
|
|
|
*/
|
|
|
|
function WARN(string) {
|
|
|
|
if (gLoggingEnabled)
|
|
|
|
dump("*** EM_WARN *** " + string + "\n");
|
|
|
|
if (gConsole) {
|
|
|
|
var message = Cc["@mozilla.org/scripterror;1"].
|
|
|
|
createInstance(Ci.nsIScriptError);
|
|
|
|
message.init(string, null, null, 0, 0, Ci.nsIScriptError.warningFlag,
|
|
|
|
"component javascript");
|
|
|
|
gConsole.logMessage(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Logs an error to the error console and to a permanent log file.
|
|
|
|
* @param string
|
|
|
|
* The error message.
|
2007-12-11 16:56:09 -08:00
|
|
|
*/
|
|
|
|
function ERROR(string) {
|
2009-08-19 03:32:15 -07:00
|
|
|
if (gLoggingEnabled)
|
|
|
|
dump("*** EM_ERROR *** " + string + "\n");
|
|
|
|
if (gConsole) {
|
|
|
|
var message = Cc["@mozilla.org/scripterror;1"].
|
|
|
|
createInstance(Ci.nsIScriptError);
|
|
|
|
message.init(string, null, null, 0, 0, Ci.nsIScriptError.errorFlag,
|
|
|
|
"component javascript");
|
|
|
|
gConsole.logMessage(message);
|
|
|
|
}
|
2007-12-11 16:56:09 -08:00
|
|
|
try {
|
|
|
|
var tstamp = new Date();
|
2009-10-23 12:42:48 -07:00
|
|
|
var logfile = FileUtils.getFile(KEY_PROFILEDIR, [FILE_EXTENSIONS_LOG]);
|
2007-12-11 16:56:09 -08:00
|
|
|
var stream = Cc["@mozilla.org/network/file-output-stream;1"].
|
|
|
|
createInstance(Ci.nsIFileOutputStream);
|
|
|
|
stream.init(logfile, 0x02 | 0x08 | 0x10, 0666, 0); // write, create, append
|
|
|
|
var writer = Cc["@mozilla.org/intl/converter-output-stream;1"].
|
|
|
|
createInstance(Ci.nsIConverterOutputStream);
|
|
|
|
writer.init(stream, "UTF-8", 0, 0x0000);
|
|
|
|
string = tstamp.toLocaleFormat("%Y-%m-%d %H:%M:%S - ") + string;
|
|
|
|
writer.writeString(string + "\n");
|
|
|
|
writer.close();
|
|
|
|
}
|
|
|
|
catch (e) { }
|
|
|
|
}
|
|
|
|
|
2007-08-29 01:16:15 -07:00
|
|
|
/**
|
2007-03-22 10:30:00 -07:00
|
|
|
* Randomize the specified file name. Used to force RDF to bypass the cache
|
|
|
|
* when loading certain types of files.
|
2007-08-29 01:16:15 -07:00
|
|
|
* @param fileName
|
2007-03-22 10:30:00 -07:00
|
|
|
* A file name to randomize, e.g. install.rdf
|
|
|
|
* @returns A randomized file name, e.g. install-xyz.rdf
|
|
|
|
*/
|
|
|
|
function getRandomFileName(fileName) {
|
|
|
|
var extensionDelimiter = fileName.lastIndexOf(".");
|
|
|
|
var prefix = fileName.substr(0, extensionDelimiter);
|
|
|
|
var suffix = fileName.substr(extensionDelimiter);
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var characters = "abcdefghijklmnopqrstuvwxyz0123456789";
|
|
|
|
var nameString = prefix + "-";
|
|
|
|
for (var i = 0; i < 3; ++i) {
|
|
|
|
var index = Math.round((Math.random()) * characters.length);
|
|
|
|
nameString += characters.charAt(index);
|
|
|
|
}
|
|
|
|
return nameString + "." + suffix;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the RDF URI prefix of a nsIUpdateItem type. This function should be used
|
2007-08-29 01:16:15 -07:00
|
|
|
* ONLY to support Firefox 1.0 Update RDF files! Item URIs in the datasource
|
2007-03-22 10:30:00 -07:00
|
|
|
* are NOT prefixed.
|
|
|
|
* @param type
|
|
|
|
* The nsIUpdateItem type to find a RDF URI prefix for
|
|
|
|
* @returns The RDF URI prefix.
|
|
|
|
*/
|
|
|
|
function getItemPrefix(type) {
|
2007-09-17 11:05:04 -07:00
|
|
|
if (type & Ci.nsIUpdateItem.TYPE_EXTENSION)
|
2007-03-22 10:30:00 -07:00
|
|
|
return PREFIX_EXTENSION;
|
2007-09-17 11:05:04 -07:00
|
|
|
else if (type & Ci.nsIUpdateItem.TYPE_THEME)
|
2007-03-22 10:30:00 -07:00
|
|
|
return PREFIX_THEME;
|
|
|
|
return PREFIX_ITEM_URI;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Trims a prefix from a string.
|
|
|
|
* @param string
|
|
|
|
* The source string
|
|
|
|
* @param prefix
|
|
|
|
* The prefix to remove.
|
|
|
|
* @returns The suffix (string - prefix)
|
|
|
|
*/
|
|
|
|
function stripPrefix(string, prefix) {
|
|
|
|
return string.substr(prefix.length);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a File URL spec for a nsIFile
|
|
|
|
* @param file
|
|
|
|
* The file to get a file URL spec to
|
|
|
|
* @returns The file URL spec to the file
|
|
|
|
*/
|
|
|
|
function getURLSpecFromFile(file) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var ioServ = Cc["@mozilla.org/network/io-service;1"].
|
|
|
|
getService(Ci.nsIIOService);
|
2007-03-22 10:30:00 -07:00
|
|
|
var fph = ioServ.getProtocolHandler("file")
|
2007-09-03 20:07:11 -07:00
|
|
|
.QueryInterface(Ci.nsIFileProtocolHandler);
|
2007-03-22 10:30:00 -07:00
|
|
|
return fph.getURLSpecFromFile(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs a URI to a spec.
|
|
|
|
* @param spec
|
|
|
|
* The spec to construct a URI to
|
|
|
|
* @returns The nsIURI constructed.
|
|
|
|
*/
|
|
|
|
function newURI(spec) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var ioServ = Cc["@mozilla.org/network/io-service;1"].
|
|
|
|
getService(Ci.nsIIOService);
|
2007-03-22 10:30:00 -07:00
|
|
|
return ioServ.newURI(spec, null, null);
|
|
|
|
}
|
|
|
|
|
2007-08-29 01:16:15 -07:00
|
|
|
/**
|
2007-03-22 10:30:00 -07:00
|
|
|
* Constructs a File URI to a nsIFile
|
|
|
|
* @param file
|
|
|
|
* The file to construct a File URI to
|
|
|
|
* @returns The file URI to the file
|
|
|
|
*/
|
|
|
|
function getURIFromFile(file) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var ioServ = Cc["@mozilla.org/network/io-service;1"].
|
|
|
|
getService(Ci.nsIIOService);
|
2007-03-22 10:30:00 -07:00
|
|
|
return ioServ.newFileURI(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns Whether or not we are currently running in safe mode.
|
|
|
|
*/
|
|
|
|
function inSafeMode() {
|
|
|
|
return gApp.inSafeMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extract the string value from a RDF Literal or Resource
|
|
|
|
* @param literalOrResource
|
|
|
|
* RDF String Literal or Resource
|
|
|
|
* @returns String value of the literal or resource, or undefined if the object
|
|
|
|
* supplied is not a RDF string literal or resource.
|
|
|
|
*/
|
|
|
|
function stringData(literalOrResource) {
|
2007-09-03 20:07:11 -07:00
|
|
|
if (literalOrResource instanceof Ci.nsIRDFLiteral)
|
2007-03-22 10:30:00 -07:00
|
|
|
return literalOrResource.Value;
|
2007-09-03 20:07:11 -07:00
|
|
|
if (literalOrResource instanceof Ci.nsIRDFResource)
|
2007-03-22 10:30:00 -07:00
|
|
|
return literalOrResource.Value;
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extract the integer value of a RDF Literal
|
|
|
|
* @param literal
|
|
|
|
* nsIRDFInt literal
|
|
|
|
* @return integer value of the literal
|
|
|
|
*/
|
|
|
|
function intData(literal) {
|
2007-09-03 20:07:11 -07:00
|
|
|
if (literal instanceof Ci.nsIRDFInt)
|
2007-03-22 10:30:00 -07:00
|
|
|
return literal.Value;
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a property from an install manifest.
|
|
|
|
* @param installManifest
|
|
|
|
* An Install Manifest datasource to read from
|
|
|
|
* @param property
|
|
|
|
* The name of a proprety to read (sans EM_NS)
|
|
|
|
* @returns The literal value of the property, or undefined if the property has
|
|
|
|
* no value.
|
|
|
|
*/
|
|
|
|
function getManifestProperty(installManifest, property) {
|
2007-08-29 01:16:15 -07:00
|
|
|
var target = installManifest.GetTarget(gInstallManifestRoot,
|
2007-03-22 10:30:00 -07:00
|
|
|
gRDF.GetResource(EM_NS(property)), true);
|
|
|
|
var val = stringData(target);
|
|
|
|
return val === undefined ? intData(target) : val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given an Install Manifest Datasource, retrieves the type of item the manifest
|
|
|
|
* describes.
|
2007-08-29 01:16:15 -07:00
|
|
|
* @param installManifest
|
2007-03-22 10:30:00 -07:00
|
|
|
* The Install Manifest Datasource.
|
|
|
|
* @return The nsIUpdateItem type of the item described by the manifest
|
|
|
|
* returns TYPE_EXTENSION if attempts to determine the type fail.
|
|
|
|
*/
|
|
|
|
function getAddonTypeFromInstallManifest(installManifest) {
|
2007-08-29 01:16:15 -07:00
|
|
|
var target = installManifest.GetTarget(gInstallManifestRoot,
|
2007-03-22 10:30:00 -07:00
|
|
|
gRDF.GetResource(EM_NS("type")), true);
|
|
|
|
if (target) {
|
|
|
|
var type = stringData(target);
|
|
|
|
return type === undefined ? intData(target) : parseInt(type);
|
|
|
|
}
|
|
|
|
|
2007-08-29 01:16:15 -07:00
|
|
|
// Firefox 1.0 and earlier did not support addon-type annotation on the
|
|
|
|
// Install Manifest, so we fall back to a theme-only property to
|
2007-03-22 10:30:00 -07:00
|
|
|
// differentiate.
|
|
|
|
if (getManifestProperty(installManifest, "internalName") !== undefined)
|
2007-09-17 11:05:04 -07:00
|
|
|
return Ci.nsIUpdateItem.TYPE_THEME;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// If no type is provided, default to "Extension"
|
2007-09-17 11:05:04 -07:00
|
|
|
return Ci.nsIUpdateItem.TYPE_EXTENSION;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-08-29 01:16:15 -07:00
|
|
|
* Shows a message about an incompatible Extension/Theme.
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param installData
|
|
|
|
* An Install Data object from |getInstallData|
|
|
|
|
*/
|
|
|
|
function showIncompatibleError(installData) {
|
|
|
|
var extensionStrings = BundleManager.getBundle(URI_EXTENSIONS_PROPERTIES);
|
|
|
|
var params = [extensionStrings.GetStringFromName("type-" + installData.type)];
|
2007-08-29 01:16:15 -07:00
|
|
|
var title = extensionStrings.formatStringFromName("incompatibleTitle",
|
2007-03-22 10:30:00 -07:00
|
|
|
params, params.length);
|
2007-09-04 13:59:05 -07:00
|
|
|
params = [installData.name, installData.version, BundleManager.appName,
|
|
|
|
gApp.version];
|
|
|
|
var message = extensionStrings.formatStringFromName("incompatibleMessage",
|
|
|
|
params, params.length);
|
2007-09-03 20:07:11 -07:00
|
|
|
var ps = Cc["@mozilla.org/embedcomp/prompt-service;1"].
|
|
|
|
getService(Ci.nsIPromptService);
|
2007-03-22 10:30:00 -07:00
|
|
|
ps.alert(null, title, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows a message.
|
|
|
|
* @param titleKey
|
|
|
|
* String key of the title string in the Extensions localization file.
|
|
|
|
* @param messageKey
|
|
|
|
* String key of the message string in the Extensions localization file.
|
|
|
|
* @param messageParams
|
|
|
|
* Array of strings to be substituted into |messageKey|. Can be null.
|
|
|
|
*/
|
|
|
|
function showMessage(titleKey, titleParams, messageKey, messageParams) {
|
|
|
|
var extensionStrings = BundleManager.getBundle(URI_EXTENSIONS_PROPERTIES);
|
|
|
|
if (titleParams && titleParams.length > 0) {
|
|
|
|
var title = extensionStrings.formatStringFromName(titleKey, titleParams,
|
|
|
|
titleParams.length);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
title = extensionStrings.GetStringFromName(titleKey);
|
|
|
|
|
|
|
|
if (messageParams && messageParams.length > 0) {
|
|
|
|
var message = extensionStrings.formatStringFromName(messageKey, messageParams,
|
|
|
|
messageParams.length);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
message = extensionStrings.GetStringFromName(messageKey);
|
2007-09-03 20:07:11 -07:00
|
|
|
var ps = Cc["@mozilla.org/embedcomp/prompt-service;1"].
|
|
|
|
getService(Ci.nsIPromptService);
|
2007-03-22 10:30:00 -07:00
|
|
|
ps.alert(null, title, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-11-02 04:13:48 -08:00
|
|
|
* Shows a dialog for a blocklisted item. For soft blocked items this will
|
|
|
|
* return true if the item should still be installed
|
|
|
|
* @param item
|
|
|
|
* The nsIUpdateItem that is blocklisted
|
|
|
|
* @param softblocked
|
|
|
|
* True if this item is only soft blocked and may still be installed.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2008-11-02 04:13:48 -08:00
|
|
|
function showBlocklistMessage(item, softblocked) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var params = Cc["@mozilla.org/embedcomp/dialogparam;1"].
|
|
|
|
createInstance(Ci.nsIDialogParamBlock);
|
2008-11-02 04:13:48 -08:00
|
|
|
params.SetInt(0, softblocked ? 1 : 0);
|
|
|
|
params.SetInt(1, 0);
|
|
|
|
params.SetNumberStrings(1);
|
|
|
|
params.SetString(0, item.name + " " + item.version);
|
|
|
|
|
|
|
|
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
|
|
|
|
getService(Ci.nsIWindowMediator);
|
|
|
|
var win = wm.getMostRecentWindow("Extension:Manager");
|
2007-09-03 20:07:11 -07:00
|
|
|
var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
|
|
|
|
getService(Ci.nsIWindowWatcher);
|
2007-03-22 10:30:00 -07:00
|
|
|
ww.openWindow(win, URI_EXTENSION_LIST_DIALOG, "",
|
|
|
|
"chrome,centerscreen,modal,dialog,titlebar", params);
|
2008-11-02 04:13:48 -08:00
|
|
|
|
|
|
|
return params.GetInt(1) == 0 ? false : true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-08-29 01:16:15 -07:00
|
|
|
/**
|
2007-03-22 10:30:00 -07:00
|
|
|
* Gets a zip reader for the file specified.
|
|
|
|
* @param zipFile
|
|
|
|
* A ZIP archive to open with a nsIZipReader.
|
|
|
|
* @return A nsIZipReader for the file specified.
|
|
|
|
*/
|
|
|
|
function getZipReaderForFile(zipFile) {
|
|
|
|
try {
|
2007-09-03 20:07:11 -07:00
|
|
|
var zipReader = Cc["@mozilla.org/libjar/zip-reader;1"].
|
|
|
|
createInstance(Ci.nsIZipReader);
|
2007-03-22 10:30:00 -07:00
|
|
|
zipReader.open(zipFile);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
zipReader.close();
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
return zipReader;
|
|
|
|
}
|
|
|
|
|
2009-05-19 01:28:04 -07:00
|
|
|
/**
|
|
|
|
* Verifies that a zip file's contents are all signed by the same principal.
|
|
|
|
* Directory entries and anything in the META-INF directory are not checked.
|
|
|
|
* @param zip
|
|
|
|
* A nsIZipReader to check
|
|
|
|
* @param principal
|
|
|
|
* The nsIPrincipal to compare against
|
|
|
|
* @return true if all the contents were signed by the principal, false
|
|
|
|
* otherwise.
|
|
|
|
*/
|
|
|
|
function verifyZipSigning(zip, principal) {
|
|
|
|
var count = 0;
|
|
|
|
var entries = zip.findEntries(null);
|
|
|
|
while (entries.hasMore()) {
|
|
|
|
var entry = entries.getNext();
|
|
|
|
// Nothing in META-INF is in the manifest.
|
|
|
|
if (entry.substr(0, 9) == "META-INF/")
|
|
|
|
continue;
|
|
|
|
// Directory entries aren't in the manifest.
|
|
|
|
if (entry.substr(-1) == "/")
|
|
|
|
continue;
|
|
|
|
count++;
|
|
|
|
var entryPrincipal = zip.getCertificatePrincipal(entry);
|
|
|
|
if (!entryPrincipal || !principal.equals(entryPrincipal))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return zip.manifestEntriesCount == count;
|
|
|
|
}
|
|
|
|
|
2007-08-29 01:16:15 -07:00
|
|
|
/**
|
2007-03-22 10:30:00 -07:00
|
|
|
* Extract a RDF file from a ZIP archive to a random location in the system
|
|
|
|
* temp directory.
|
|
|
|
* @param zipFile
|
|
|
|
* A ZIP archive to read from
|
2007-08-29 01:16:15 -07:00
|
|
|
* @param fileName
|
|
|
|
* The name of the file to read from the zip.
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param suppressErrors
|
2007-08-29 01:16:15 -07:00
|
|
|
* Whether or not to report errors.
|
2007-03-22 10:30:00 -07:00
|
|
|
* @return The file created in the temp directory.
|
|
|
|
*/
|
|
|
|
function extractRDFFileToTempDir(zipFile, fileName, suppressErrors) {
|
2009-10-23 12:42:48 -07:00
|
|
|
var file = FileUtils.getFile(KEY_TEMPDIR, [getRandomFileName(fileName)]);
|
2007-03-22 10:30:00 -07:00
|
|
|
try {
|
|
|
|
var zipReader = getZipReaderForFile(zipFile);
|
|
|
|
zipReader.extract(fileName, file);
|
|
|
|
zipReader.close();
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
if (!suppressErrors) {
|
2007-08-29 01:16:15 -07:00
|
|
|
showMessage("missingFileTitle", [], "missingFileMessage",
|
2007-03-22 10:30:00 -07:00
|
|
|
[BundleManager.appName, fileName]);
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets an Install Manifest datasource from a file.
|
|
|
|
* @param file
|
|
|
|
* The nsIFile that contains the Install Manifest RDF
|
|
|
|
* @returns The Install Manifest datasource
|
|
|
|
*/
|
|
|
|
function getInstallManifest(file) {
|
2008-04-01 02:21:30 -07:00
|
|
|
var uri = getURIFromFile(file);
|
|
|
|
try {
|
|
|
|
var fis = Cc["@mozilla.org/network/file-input-stream;1"].
|
|
|
|
createInstance(Ci.nsIFileInputStream);
|
|
|
|
fis.init(file, -1, -1, false);
|
|
|
|
var bis = Cc["@mozilla.org/network/buffered-input-stream;1"].
|
|
|
|
createInstance(Ci.nsIBufferedInputStream);
|
|
|
|
bis.init(fis, 4096);
|
|
|
|
|
|
|
|
var rdfParser = Cc["@mozilla.org/rdf/xml-parser;1"].
|
|
|
|
createInstance(Ci.nsIRDFXMLParser)
|
|
|
|
var ds = Cc["@mozilla.org/rdf/datasource;1?name=in-memory-datasource"].
|
|
|
|
createInstance(Ci.nsIRDFDataSource);
|
|
|
|
var listener = rdfParser.parseAsync(ds, uri);
|
|
|
|
var channel = Cc["@mozilla.org/network/input-stream-channel;1"].
|
|
|
|
createInstance(Ci.nsIInputStreamChannel);
|
|
|
|
channel.setURI(uri);
|
|
|
|
channel.contentStream = bis;
|
|
|
|
channel.QueryInterface(Ci.nsIChannel);
|
|
|
|
channel.contentType = "text/xml";
|
2008-03-27 02:37:45 -07:00
|
|
|
|
2008-04-01 02:21:30 -07:00
|
|
|
listener.onStartRequest(channel, null);
|
|
|
|
try {
|
|
|
|
var pos = 0;
|
|
|
|
var count = bis.available();
|
|
|
|
while (count > 0) {
|
|
|
|
listener.onDataAvailable(channel, null, bis, pos, count);
|
|
|
|
pos += count;
|
|
|
|
count = bis.available();
|
|
|
|
}
|
|
|
|
listener.onStopRequest(channel, null, Components.results.NS_OK);
|
|
|
|
bis.close();
|
|
|
|
fis.close();
|
|
|
|
|
|
|
|
var arcs = ds.ArcLabelsOut(gInstallManifestRoot);
|
|
|
|
if (arcs.hasMoreElements())
|
|
|
|
return ds;
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
listener.onStopRequest(channel, null, e.result);
|
|
|
|
bis.close();
|
|
|
|
fis.close();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-04-01 02:21:30 -07:00
|
|
|
catch (e) { }
|
|
|
|
|
|
|
|
var url = uri.QueryInterface(Ci.nsIURL);
|
|
|
|
showMessage("malformedTitle", [], "malformedMessage",
|
|
|
|
[BundleManager.appName, url.fileName]);
|
|
|
|
return null;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-10-12 15:45:16 -07:00
|
|
|
/**
|
|
|
|
* Selects the closest matching localized resource in the given RDF resource
|
|
|
|
* @param aDataSource The datasource to look in
|
|
|
|
* @param aResource The root resource containing the localized sections
|
|
|
|
* @returns The nsIRDFResource of the best em:localized section or null
|
|
|
|
* if no valid match was found
|
|
|
|
*/
|
|
|
|
function findClosestLocalizedResource(aDataSource, aResource) {
|
|
|
|
var localizedProp = EM_R("localized");
|
|
|
|
var localeProp = EM_R("locale");
|
|
|
|
|
|
|
|
// Holds the best matching localized resource
|
|
|
|
var bestmatch = null;
|
|
|
|
// The number of locale parts it matched with
|
|
|
|
var bestmatchcount = 0;
|
|
|
|
// The number of locale parts in the match
|
|
|
|
var bestpartcount = 0;
|
|
|
|
|
|
|
|
var locales = [gLocale.toLowerCase()];
|
|
|
|
/* If the current locale is English then it will find a match if there is
|
|
|
|
a valid match for en-US so no point searching that locale too. */
|
|
|
|
if (locales[0].substring(0, 3) != "en-")
|
|
|
|
locales.push("en-us");
|
|
|
|
|
|
|
|
for each (var locale in locales) {
|
|
|
|
var lparts = locale.split("-");
|
|
|
|
var localizations = aDataSource.GetTargets(aResource, localizedProp, true);
|
|
|
|
while (localizations.hasMoreElements()) {
|
|
|
|
var localized = localizations.getNext().QueryInterface(Ci.nsIRDFNode);
|
|
|
|
var list = aDataSource.GetTargets(localized, localeProp, true);
|
|
|
|
while (list.hasMoreElements()) {
|
|
|
|
var found = stringData(list.getNext().QueryInterface(Ci.nsIRDFNode));
|
|
|
|
if (!found)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
found = found.toLowerCase();
|
|
|
|
|
|
|
|
// Exact match is returned immediately
|
|
|
|
if (locale == found)
|
|
|
|
return localized;
|
|
|
|
|
|
|
|
var fparts = found.split("-");
|
|
|
|
/* If we have found a possible match and this one isn't any longer
|
|
|
|
then we dont need to check further. */
|
|
|
|
if (bestmatch && fparts.length < bestmatchcount)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Count the number of parts that match
|
|
|
|
var maxmatchcount = Math.min(fparts.length, lparts.length);
|
|
|
|
var matchcount = 0;
|
|
|
|
while (matchcount < maxmatchcount &&
|
|
|
|
fparts[matchcount] == lparts[matchcount])
|
|
|
|
matchcount++;
|
|
|
|
|
|
|
|
/* If we matched more than the last best match or matched the same and
|
|
|
|
this locale is less specific than the last best match. */
|
|
|
|
if (matchcount > bestmatchcount ||
|
|
|
|
(matchcount == bestmatchcount && fparts.length < bestpartcount)) {
|
|
|
|
bestmatch = localized;
|
|
|
|
bestmatchcount = matchcount;
|
|
|
|
bestpartcount = fparts.length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If we found a valid match for this locale return it
|
|
|
|
if (bestmatch)
|
|
|
|
return bestmatch;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* An enumeration of items in a JS array.
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
function ArrayEnumerator(aItems) {
|
|
|
|
if (aItems) {
|
|
|
|
for (var i = 0; i < aItems.length; ++i) {
|
|
|
|
if (!aItems[i])
|
2007-11-21 13:15:39 -08:00
|
|
|
aItems.splice(i--, 1);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-11-21 13:15:39 -08:00
|
|
|
this._contents = aItems;
|
|
|
|
} else {
|
|
|
|
this._contents = [];
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ArrayEnumerator.prototype = {
|
|
|
|
_index: 0,
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
hasMoreElements: function ArrayEnumerator_hasMoreElements() {
|
2007-03-22 10:30:00 -07:00
|
|
|
return this._index < this._contents.length;
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
getNext: function ArrayEnumerator_getNext() {
|
2007-08-29 01:16:15 -07:00
|
|
|
return this._contents[this._index++];
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An enumeration of files in a JS array.
|
|
|
|
* @param files
|
|
|
|
* The files to enumerate
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
function FileEnumerator(files) {
|
|
|
|
if (files) {
|
|
|
|
for (var i = 0; i < files.length; ++i) {
|
|
|
|
if (!files[i])
|
2007-11-21 13:15:39 -08:00
|
|
|
files.splice(i--, 1);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-11-21 13:15:39 -08:00
|
|
|
this._contents = files;
|
|
|
|
} else {
|
|
|
|
this._contents = [];
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FileEnumerator.prototype = {
|
|
|
|
_index: 0,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the next file in the sequence.
|
2007-08-29 01:16:15 -07:00
|
|
|
*/
|
2007-03-22 10:30:00 -07:00
|
|
|
get nextFile() {
|
|
|
|
if (this._index < this._contents.length)
|
|
|
|
return this._contents[this._index++];
|
|
|
|
return null;
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Stop enumerating. Nothing to do here.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
close: function FileEnumerator_close() {
|
2007-11-21 13:15:39 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An object which identifies an Install Location for items, where the location
|
2007-08-29 01:16:15 -07:00
|
|
|
* relationship is each item living in a directory named with its GUID under
|
2007-03-22 10:30:00 -07:00
|
|
|
* the directory used when constructing this object.
|
|
|
|
*
|
|
|
|
* e.g. <location>\{GUID1}
|
|
|
|
* <location>\{GUID2}
|
|
|
|
* <location>\{GUID3}
|
|
|
|
* ...
|
|
|
|
*
|
|
|
|
* @param name
|
|
|
|
* The string identifier of this Install Location.
|
|
|
|
* @param location
|
2007-08-29 01:16:15 -07:00
|
|
|
* The directory that contains the items.
|
2007-03-22 10:30:00 -07:00
|
|
|
* @constructor
|
|
|
|
*/
|
2008-01-15 07:13:59 -08:00
|
|
|
function DirectoryInstallLocation(name, location, restricted, priority, independent) {
|
2007-03-22 10:30:00 -07:00
|
|
|
this._name = name;
|
|
|
|
if (location.exists()) {
|
|
|
|
if (!location.isDirectory())
|
|
|
|
throw new Error("location must be a directoy!");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
try {
|
2007-09-17 11:05:04 -07:00
|
|
|
location.create(Ci.nsILocalFile.DIRECTORY_TYPE, 0775);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
2009-05-05 04:45:26 -07:00
|
|
|
LOG("DirectoryInstallLocation: failed to create location " +
|
|
|
|
" directory = " + location.path + ", exception = " + e + "\n");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this._location = location;
|
|
|
|
this._locationToIDMap = {};
|
|
|
|
this._restricted = restricted;
|
|
|
|
this._priority = priority;
|
2008-01-15 07:13:59 -08:00
|
|
|
this._independent = independent;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
DirectoryInstallLocation.prototype = {
|
|
|
|
_name : "",
|
|
|
|
_location : null,
|
|
|
|
_locationToIDMap: null,
|
|
|
|
_restricted : false,
|
|
|
|
_priority : 0,
|
2008-01-15 07:13:59 -08:00
|
|
|
_independent : false,
|
2007-03-22 10:30:00 -07:00
|
|
|
_canAccess : null,
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* See nsIExtensionManager.idl
|
|
|
|
*/
|
|
|
|
get name() {
|
|
|
|
return this._name;
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Reads a directory linked to in a file.
|
|
|
|
* @param file
|
|
|
|
* The file containing the directory path
|
|
|
|
* @returns A nsILocalFile object representing the linked directory.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_readDirectoryFromFile: function DirInstallLocation__readDirectoryFromFile(file) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var fis = Cc["@mozilla.org/network/file-input-stream;1"].
|
|
|
|
createInstance(Ci.nsIFileInputStream);
|
2007-03-22 10:30:00 -07:00
|
|
|
fis.init(file, -1, -1, false);
|
|
|
|
var line = { value: "" };
|
2007-09-17 11:05:04 -07:00
|
|
|
if (fis instanceof Ci.nsILineInputStream)
|
2007-03-22 10:30:00 -07:00
|
|
|
fis.readLine(line);
|
|
|
|
fis.close();
|
|
|
|
if (line.value) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var linkedDirectory = Cc["@mozilla.org/file/local;1"].
|
2007-09-17 11:05:04 -07:00
|
|
|
createInstance(Ci.nsILocalFile);
|
2007-03-22 10:30:00 -07:00
|
|
|
try {
|
|
|
|
linkedDirectory.initWithPath(line.value);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
linkedDirectory.setRelativeDescriptor(file.parent, line.value);
|
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return linkedDirectory;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* See nsIExtensionManager.idl
|
|
|
|
*/
|
|
|
|
get itemLocations() {
|
|
|
|
var locations = [];
|
|
|
|
if (!this._location.exists())
|
|
|
|
return new FileEnumerator(locations);
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
try {
|
2007-09-17 11:05:04 -07:00
|
|
|
var entries = this._location.directoryEntries.QueryInterface(Ci.nsIDirectoryEnumerator);
|
2007-03-22 10:30:00 -07:00
|
|
|
while (true) {
|
|
|
|
var entry = entries.nextFile;
|
|
|
|
if (!entry)
|
|
|
|
break;
|
2007-09-17 11:05:04 -07:00
|
|
|
entry instanceof Ci.nsILocalFile;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!entry.isDirectory() && gIDTest.test(entry.leafName)) {
|
|
|
|
var linkedDirectory = this._readDirectoryFromFile(entry);
|
2007-08-29 01:16:15 -07:00
|
|
|
if (linkedDirectory && linkedDirectory.exists() &&
|
2007-03-22 10:30:00 -07:00
|
|
|
linkedDirectory.isDirectory()) {
|
|
|
|
locations.push(linkedDirectory);
|
|
|
|
this._locationToIDMap[linkedDirectory.persistentDescriptor] = entry.leafName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
locations.push(entry);
|
|
|
|
}
|
|
|
|
entries.close();
|
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
catch (e) {
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return new FileEnumerator(locations);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Retrieves the GUID for an item at the specified location.
|
|
|
|
* @param file
|
|
|
|
* The location where an item might live.
|
|
|
|
* @returns The ID for an item that might live at the location specified.
|
2007-08-29 01:16:15 -07:00
|
|
|
*
|
|
|
|
* N.B. This function makes no promises about whether or not this path is
|
2007-03-22 10:30:00 -07:00
|
|
|
* actually maintained by this Install Location.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
getIDForLocation: function DirInstallLocation_getIDForLocation(file) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var section = file.leafName;
|
|
|
|
var filePD = file.persistentDescriptor;
|
2007-08-29 01:16:15 -07:00
|
|
|
if (filePD in this._locationToIDMap)
|
2007-03-22 10:30:00 -07:00
|
|
|
section = this._locationToIDMap[filePD];
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (gIDTest.test(section))
|
|
|
|
return RegExp.$1;
|
|
|
|
return undefined;
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* See nsIExtensionManager.idl
|
|
|
|
*/
|
|
|
|
get location() {
|
|
|
|
return this._location.clone();
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* See nsIExtensionManager.idl
|
|
|
|
*/
|
|
|
|
get restricted() {
|
|
|
|
return this._restricted;
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* See nsIExtensionManager.idl
|
|
|
|
*/
|
|
|
|
get canAccess() {
|
|
|
|
if (this._canAccess != null)
|
|
|
|
return this._canAccess;
|
|
|
|
|
2009-05-05 04:45:26 -07:00
|
|
|
if (!this.location.exists()) {
|
|
|
|
this._canAccess = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var testFile = this.location;
|
|
|
|
testFile.append("Access Privileges Test");
|
|
|
|
try {
|
2009-10-23 12:42:48 -07:00
|
|
|
testFile.createUnique(Ci.nsILocalFile.DIRECTORY_TYPE,
|
|
|
|
FileUtils.PERMS_DIRECTORY);
|
2007-03-22 10:30:00 -07:00
|
|
|
testFile.remove(false);
|
|
|
|
this._canAccess = true;
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
this._canAccess = false;
|
|
|
|
}
|
|
|
|
return this._canAccess;
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* See nsIExtensionManager.idl
|
|
|
|
*/
|
|
|
|
get priority() {
|
|
|
|
return this._priority;
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* See nsIExtensionManager.idl
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
getItemLocation: function DirInstallLocation_getItemLocation(id) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var itemLocation = this.location;
|
|
|
|
itemLocation.append(id);
|
|
|
|
if (itemLocation.exists() && !itemLocation.isDirectory())
|
|
|
|
return this._readDirectoryFromFile(itemLocation);
|
|
|
|
if (!itemLocation.exists() && this.canAccess)
|
2009-10-23 12:42:48 -07:00
|
|
|
itemLocation.create(Ci.nsILocalFile.DIRECTORY_TYPE,
|
|
|
|
FileUtils.PERMS_DIRECTORY);
|
2007-03-22 10:30:00 -07:00
|
|
|
return itemLocation;
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* See nsIExtensionManager.idl
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
itemIsManagedIndependently: function DirInstallLocation_itemIsManagedIndependently(id) {
|
2008-01-15 07:13:59 -08:00
|
|
|
if (this._independent)
|
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
var itemLocation = this.location;
|
|
|
|
itemLocation.append(id);
|
2007-08-29 01:16:15 -07:00
|
|
|
return itemLocation.exists() && !itemLocation.isDirectory();
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* See nsIExtensionManager.idl
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
getItemFile: function DirInstallLocation_getItemFile(id, filePath) {
|
2009-03-31 14:21:07 -07:00
|
|
|
var itemLocation = this.getItemLocation(id);
|
2007-03-22 10:30:00 -07:00
|
|
|
var parts = filePath.split("/");
|
|
|
|
for (var i = 0; i < parts.length; ++i)
|
|
|
|
itemLocation.append(parts[i]);
|
|
|
|
return itemLocation;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stages the specified file for later.
|
|
|
|
* @param file
|
|
|
|
* The file to stage
|
|
|
|
* @param id
|
|
|
|
* The GUID of the item the file represents
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
stageFile: function DirInstallLocation_stageFile(file, id) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var stagedFile = this.location;
|
|
|
|
stagedFile.append(DIR_STAGE);
|
|
|
|
stagedFile.append(id);
|
|
|
|
stagedFile.append(file.leafName);
|
|
|
|
|
|
|
|
// When an incompatible update is successful the file is already staged
|
|
|
|
if (stagedFile.equals(file))
|
|
|
|
return stagedFile;
|
|
|
|
|
2007-08-29 01:16:15 -07:00
|
|
|
if (stagedFile.exists())
|
2007-03-22 10:30:00 -07:00
|
|
|
stagedFile.remove(false);
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
file.copyTo(stagedFile.parent, stagedFile.leafName);
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// If the file has incorrect permissions set, correct them now.
|
|
|
|
if (!stagedFile.isWritable())
|
2009-10-23 12:42:48 -07:00
|
|
|
stagedFile.permissions = FileUtils.PERMS_FILE;
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return stagedFile;
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Returns the most recently staged package (e.g. the last XPI or JAR in a
|
|
|
|
* directory) for an item and removes items that do not qualify.
|
|
|
|
* @param id
|
|
|
|
* The ID of the staged package
|
|
|
|
* @returns an nsIFile if the package exists otherwise null.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
getStageFile: function DirInstallLocation_getStageFile(id) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var stageFile = null;
|
|
|
|
var stageDir = this.location;
|
|
|
|
stageDir.append(DIR_STAGE);
|
|
|
|
stageDir.append(id);
|
|
|
|
if (!stageDir.exists() || !stageDir.isDirectory())
|
|
|
|
return null;
|
|
|
|
try {
|
2007-09-17 11:05:04 -07:00
|
|
|
var entries = stageDir.directoryEntries.QueryInterface(Ci.nsIDirectoryEnumerator);
|
2007-03-22 10:30:00 -07:00
|
|
|
while (entries.hasMoreElements()) {
|
|
|
|
var file = entries.nextFile;
|
2007-09-17 11:05:04 -07:00
|
|
|
if (!(file instanceof Ci.nsILocalFile))
|
2007-03-22 10:30:00 -07:00
|
|
|
continue;
|
|
|
|
if (file.isDirectory())
|
|
|
|
removeDirRecursive(file);
|
|
|
|
else if (fileIsItemPackage(file)) {
|
|
|
|
if (stageFile)
|
|
|
|
stageFile.remove(false);
|
|
|
|
stageFile = file;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
file.remove(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
}
|
2007-09-17 11:05:04 -07:00
|
|
|
if (entries instanceof Ci.nsIDirectoryEnumerator)
|
2007-03-22 10:30:00 -07:00
|
|
|
entries.close();
|
|
|
|
return stageFile;
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Removes a file from the stage. This cleans up the stage if there is nothing
|
|
|
|
* else left after the remove operation.
|
|
|
|
* @param file
|
|
|
|
* The file to remove.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
removeFile: function DirInstallLocation_removeFile(file) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (file.exists())
|
|
|
|
file.remove(false);
|
|
|
|
var parent = file.parent;
|
2007-08-29 01:16:15 -07:00
|
|
|
var entries = parent.directoryEntries;
|
2007-03-22 10:30:00 -07:00
|
|
|
try {
|
|
|
|
// XXXrstrong calling hasMoreElements on a nsIDirectoryEnumerator after
|
|
|
|
// it has been removed will cause a crash on Mac OS X - bug 292823
|
|
|
|
while (parent && !parent.equals(this.location) &&
|
|
|
|
!entries.hasMoreElements()) {
|
|
|
|
parent.remove(false);
|
|
|
|
parent = parent.parent;
|
|
|
|
entries = parent.directoryEntries;
|
|
|
|
}
|
2007-09-17 11:05:04 -07:00
|
|
|
if (entries instanceof Ci.nsIDirectoryEnumerator)
|
2007-03-22 10:30:00 -07:00
|
|
|
entries.close();
|
|
|
|
}
|
|
|
|
catch (e) {
|
2007-12-11 16:56:09 -08:00
|
|
|
ERROR("DirectoryInstallLocation::removeFile: failed to remove staged " +
|
|
|
|
" directory = " + parent.path + ", exception = " + e + "\n");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-09-03 20:07:11 -07:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIInstallLocation])
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
|
2007-09-03 20:07:11 -07:00
|
|
|
const nsIWindowsRegKey = Ci.nsIWindowsRegKey;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* An object that identifies the location of installed items based on entries
|
|
|
|
* in the Windows registry. For each application a subkey is defined that
|
|
|
|
* contains a set of values, where the name of each value is a GUID and the
|
|
|
|
* contents of the value is a filesystem path identifying a directory
|
|
|
|
* containing an installed item.
|
|
|
|
*
|
|
|
|
* @param name
|
|
|
|
* The string identifier of this Install Location.
|
|
|
|
* @param rootKey
|
|
|
|
* The root key (one of the ROOT_KEY_ values from nsIWindowsRegKey).
|
|
|
|
* @param restricted
|
|
|
|
* Indicates that the location may be restricted (e.g., this is
|
|
|
|
* usually true of a system level install location).
|
|
|
|
* @param priority
|
|
|
|
* The priority of this install location.
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
function WinRegInstallLocation(name, rootKey, restricted, priority) {
|
|
|
|
this._name = name;
|
|
|
|
this._rootKey = rootKey;
|
|
|
|
this._restricted = restricted;
|
|
|
|
this._priority = priority;
|
|
|
|
this._IDToDirMap = {};
|
|
|
|
this._DirToIDMap = {};
|
|
|
|
|
|
|
|
// Reading the registry may throw an exception, and that's ok. In error
|
|
|
|
// cases, we just leave ourselves in the empty state.
|
|
|
|
try {
|
|
|
|
var path = this._appKeyPath + "\\Extensions";
|
2007-09-03 20:07:11 -07:00
|
|
|
var key = Cc["@mozilla.org/windows-registry-key;1"].
|
|
|
|
createInstance(nsIWindowsRegKey);
|
2007-03-22 10:30:00 -07:00
|
|
|
key.open(this._rootKey, path, nsIWindowsRegKey.ACCESS_READ);
|
|
|
|
this._readAddons(key);
|
|
|
|
} catch (e) {
|
|
|
|
if (key)
|
|
|
|
key.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
WinRegInstallLocation.prototype = {
|
|
|
|
_name : "",
|
|
|
|
_rootKey : null,
|
|
|
|
_restricted : false,
|
|
|
|
_priority : 0,
|
|
|
|
_IDToDirMap : null, // mapping from ID to directory object
|
|
|
|
_DirToIDMap : null, // mapping from directory path to ID
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Retrieves the path of this Application's data key in the registry.
|
|
|
|
*/
|
|
|
|
get _appKeyPath() {
|
|
|
|
var appVendor = gApp.vendor;
|
|
|
|
var appName = gApp.name;
|
|
|
|
|
|
|
|
#ifdef MOZ_THUNDERBIRD
|
|
|
|
// XXX Thunderbird doesn't specify a vendor string!!
|
|
|
|
if (appVendor == "")
|
|
|
|
appVendor = "Mozilla";
|
|
|
|
#endif
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// XULRunner-based apps may intentionally not specify a vendor:
|
|
|
|
if (appVendor != "")
|
|
|
|
appVendor += "\\";
|
|
|
|
|
|
|
|
return "SOFTWARE\\" + appVendor + appName;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read the registry and build a mapping between GUID and directory for each
|
|
|
|
* installed item.
|
|
|
|
* @param key
|
|
|
|
* The key that contains the GUID->path pairs
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_readAddons: function RegInstallLocation__readAddons(key) {
|
2007-08-29 01:16:15 -07:00
|
|
|
var count = key.valueCount;
|
2007-03-22 10:30:00 -07:00
|
|
|
for (var i = 0; i < count; ++i) {
|
|
|
|
var id = key.getValueName(i);
|
|
|
|
|
2007-09-03 20:07:11 -07:00
|
|
|
var dir = Cc["@mozilla.org/file/local;1"].
|
2007-09-17 11:05:04 -07:00
|
|
|
createInstance(Ci.nsILocalFile);
|
2007-03-22 10:30:00 -07:00
|
|
|
dir.initWithPath(key.readStringValue(id));
|
|
|
|
|
|
|
|
if (dir.exists() && dir.isDirectory()) {
|
|
|
|
this._IDToDirMap[id] = dir;
|
|
|
|
this._DirToIDMap[dir.path] = id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
get name() {
|
|
|
|
return this._name;
|
|
|
|
},
|
|
|
|
|
|
|
|
get itemLocations() {
|
|
|
|
var locations = [];
|
|
|
|
for (var id in this._IDToDirMap) {
|
|
|
|
locations.push(this._IDToDirMap[id]);
|
|
|
|
}
|
|
|
|
return new FileEnumerator(locations);
|
|
|
|
},
|
|
|
|
|
|
|
|
get location() {
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
get restricted() {
|
|
|
|
return this._restricted;
|
|
|
|
},
|
|
|
|
|
|
|
|
// you should never be able to write to this location
|
|
|
|
get canAccess() {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
get priority() {
|
|
|
|
return this._priority;
|
|
|
|
},
|
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
getItemLocation: function RegInstallLocation_getItemLocation(id) {
|
2009-05-05 04:45:53 -07:00
|
|
|
if (!(id in this._IDToDirMap))
|
|
|
|
return null;
|
2009-03-31 14:21:07 -07:00
|
|
|
return this._IDToDirMap[id].clone();
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
getIDForLocation: function RegInstallLocation_getIDForLocation(dir) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return this._DirToIDMap[dir.path];
|
|
|
|
},
|
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
getItemFile: function RegInstallLocation_getItemFile(id, filePath) {
|
2009-03-31 14:21:07 -07:00
|
|
|
var itemLocation = this.getItemLocation(id);
|
2009-12-17 13:12:00 -08:00
|
|
|
if (!itemLocation)
|
|
|
|
return null;
|
2007-03-22 10:30:00 -07:00
|
|
|
var parts = filePath.split("/");
|
|
|
|
for (var i = 0; i < parts.length; ++i)
|
|
|
|
itemLocation.append(parts[i]);
|
|
|
|
return itemLocation;
|
|
|
|
},
|
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
itemIsManagedIndependently: function RegInstallLocation_itemIsManagedIndependently(id) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2007-09-03 20:07:11 -07:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIInstallLocation])
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
2009-06-11 02:54:26 -07:00
|
|
|
* Safely attempt to install or uninstall a given item ID in an install
|
|
|
|
* location. Using aggressive success-safety checks, this function will attempt
|
2007-03-22 10:30:00 -07:00
|
|
|
* to move an existing location for an item aside and then allow installation
|
2007-08-29 01:16:15 -07:00
|
|
|
* into the appropriate folder. If any operation fails the installation will
|
2007-03-22 10:30:00 -07:00
|
|
|
* abort and roll back from the moved-aside old version.
|
|
|
|
* @param itemID
|
|
|
|
* The GUID of the item to perform the operation on.
|
|
|
|
* @param installLocation
|
|
|
|
* The Install Location where the item is installed.
|
2009-06-11 02:54:26 -07:00
|
|
|
* @param file
|
|
|
|
* An xpi file to install to the location or null to just uninstall
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2009-06-11 02:54:26 -07:00
|
|
|
function safeInstallOperation(itemID, installLocation, file) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var movedFiles = [];
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Reverts a deep move by moving backed up files back to their original
|
|
|
|
* location.
|
|
|
|
*/
|
|
|
|
function rollbackMove()
|
|
|
|
{
|
|
|
|
for (var i = 0; i < movedFiles.length; ++i) {
|
|
|
|
var oldFile = movedFiles[i].oldFile;
|
|
|
|
var newFile = movedFiles[i].newFile;
|
|
|
|
try {
|
|
|
|
newFile.moveTo(oldFile.parent, newFile.leafName);
|
|
|
|
}
|
|
|
|
catch (e) {
|
2007-12-11 16:56:09 -08:00
|
|
|
ERROR("safeInstallOperation: failed to roll back files after an install " +
|
|
|
|
"operation failed. Failed to roll back: " + newFile.path + " to: " +
|
|
|
|
oldFile.path + " ... aborting installation.");
|
2007-03-22 10:30:00 -07:00
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Moves a file to a new folder.
|
|
|
|
* @param file
|
|
|
|
* The file to move
|
|
|
|
* @param destination
|
|
|
|
* The target folder
|
|
|
|
*/
|
|
|
|
function moveFile(file, destination) {
|
|
|
|
try {
|
|
|
|
var oldFile = file.clone();
|
|
|
|
file.moveTo(destination, file.leafName);
|
|
|
|
movedFiles.push({ oldFile: oldFile, newFile: file });
|
|
|
|
}
|
|
|
|
catch (e) {
|
2007-12-11 16:56:09 -08:00
|
|
|
ERROR("safeInstallOperation: failed to back up file: " + file.path + " to: " +
|
|
|
|
destination.path + " ... rolling back file moves and aborting " +
|
|
|
|
"installation.");
|
2007-03-22 10:30:00 -07:00
|
|
|
rollbackMove();
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Moves a directory to a new location. If any part of the move fails,
|
|
|
|
* files already moved will be rolled back.
|
|
|
|
* @param sourceDir
|
|
|
|
* The directory to move
|
|
|
|
* @param targetDir
|
|
|
|
* The destination directory
|
|
|
|
* @param currentDir
|
2007-08-29 01:16:15 -07:00
|
|
|
* The current directory (a subdirectory of |sourceDir| or
|
2007-03-22 10:30:00 -07:00
|
|
|
* |sourceDir| itself) we are moving files from.
|
|
|
|
*/
|
|
|
|
function moveDirectory(sourceDir, targetDir, currentDir) {
|
2007-09-17 11:05:04 -07:00
|
|
|
var entries = currentDir.directoryEntries.QueryInterface(Ci.nsIDirectoryEnumerator);
|
2007-03-22 10:30:00 -07:00
|
|
|
while (true) {
|
|
|
|
var entry = entries.nextFile;
|
|
|
|
if (!entry)
|
|
|
|
break;
|
|
|
|
if (entry.isDirectory())
|
|
|
|
moveDirectory(sourceDir, targetDir, entry);
|
2007-09-17 11:05:04 -07:00
|
|
|
else if (entry instanceof Ci.nsILocalFile) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var rd = entry.getRelativeDescriptor(sourceDir);
|
2007-09-17 11:05:04 -07:00
|
|
|
var destination = targetDir.clone().QueryInterface(Ci.nsILocalFile);
|
2007-03-22 10:30:00 -07:00
|
|
|
destination.setRelativeDescriptor(targetDir, rd);
|
|
|
|
moveFile(entry, destination.parent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
entries.close();
|
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
2007-08-29 01:16:15 -07:00
|
|
|
* Removes the temporary backup directory where we stored files.
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param directory
|
|
|
|
* The backup directory to remove
|
|
|
|
*/
|
|
|
|
function cleanUpTrash(directory) {
|
|
|
|
try {
|
|
|
|
// Us-generated. Safe.
|
|
|
|
if (directory && directory.exists())
|
|
|
|
removeDirRecursive(directory);
|
|
|
|
}
|
|
|
|
catch (e) {
|
2007-12-11 16:56:09 -08:00
|
|
|
ERROR("safeInstallOperation: failed to clean up the temporary backup of the " +
|
|
|
|
"older version: " + itemLocationTrash.path);
|
2007-08-29 01:16:15 -07:00
|
|
|
// This is a non-fatal error. Annoying, but non-fatal.
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!installLocation.itemIsManagedIndependently(itemID)) {
|
|
|
|
var itemLocation = installLocation.getItemLocation(itemID);
|
|
|
|
if (itemLocation.exists()) {
|
|
|
|
var trashDirName = itemID + "-trash";
|
|
|
|
var itemLocationTrash = itemLocation.parent.clone();
|
|
|
|
itemLocationTrash.append(trashDirName);
|
|
|
|
if (itemLocationTrash.exists()) {
|
|
|
|
// We can remove recursively here since this is a folder we created, not
|
2007-08-29 01:16:15 -07:00
|
|
|
// one the user specified. If this fails, it'll throw, and the caller
|
2007-03-22 10:30:00 -07:00
|
|
|
// should stop installation.
|
|
|
|
try {
|
|
|
|
removeDirRecursive(itemLocationTrash);
|
|
|
|
}
|
|
|
|
catch (e) {
|
2007-12-11 16:56:09 -08:00
|
|
|
ERROR("safeFileOperation: failed to remove existing trash directory " +
|
|
|
|
itemLocationTrash.path + " ... aborting installation.");
|
2007-03-22 10:30:00 -07:00
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
|
|
|
|
// Move the directory that contains the existing version of the item aside,
|
2007-03-22 10:30:00 -07:00
|
|
|
// into {GUID}-trash. This will throw if there's a failure and the install
|
|
|
|
// will abort.
|
|
|
|
moveDirectory(itemLocation, itemLocationTrash, itemLocation);
|
2007-08-29 01:16:15 -07:00
|
|
|
|
|
|
|
// Clean up the original location, if necessary. Again, this is a path we
|
2007-03-22 10:30:00 -07:00
|
|
|
// generated, so it is safe to recursively delete.
|
|
|
|
try {
|
|
|
|
removeDirRecursive(itemLocation);
|
|
|
|
}
|
|
|
|
catch (e) {
|
2007-12-11 16:56:09 -08:00
|
|
|
ERROR("safeInstallOperation: failed to clean up item location after its contents " +
|
|
|
|
"were properly backed up. Failed to clean up: " + itemLocation.path +
|
|
|
|
" ... rolling back file moves and aborting installation.");
|
2007-03-22 10:30:00 -07:00
|
|
|
rollbackMove();
|
|
|
|
cleanUpTrash(itemLocationTrash);
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (installLocation.name == KEY_APP_PROFILE ||
|
2008-01-15 07:13:59 -08:00
|
|
|
installLocation.name == KEY_APP_GLOBAL ||
|
|
|
|
installLocation.name == KEY_APP_SYSTEM_USER) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Check for a pointer file and move it aside if it exists
|
|
|
|
var pointerFile = installLocation.location.clone();
|
|
|
|
pointerFile.append(itemID);
|
|
|
|
if (pointerFile.exists() && !pointerFile.isDirectory()) {
|
|
|
|
var trashFileName = itemID + "-trash";
|
|
|
|
var itemLocationTrash = installLocation.location.clone();
|
|
|
|
itemLocationTrash.append(trashFileName);
|
|
|
|
if (itemLocationTrash.exists()) {
|
|
|
|
// We can remove recursively here since this is a folder we created, not
|
2007-08-29 01:16:15 -07:00
|
|
|
// one the user specified. If this fails, it'll throw, and the caller
|
2007-03-22 10:30:00 -07:00
|
|
|
// should stop installation.
|
|
|
|
try {
|
|
|
|
removeDirRecursive(itemLocationTrash);
|
|
|
|
}
|
|
|
|
catch (e) {
|
2007-12-11 16:56:09 -08:00
|
|
|
ERROR("safeFileOperation: failed to remove existing trash directory " +
|
|
|
|
itemLocationTrash.path + " ... aborting installation.");
|
2007-03-22 10:30:00 -07:00
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
2009-10-23 12:42:48 -07:00
|
|
|
itemLocationTrash.create(Ci.nsILocalFile.DIRECTORY_TYPE,
|
|
|
|
FileUtils.PERMS_DIRECTORY);
|
2007-03-22 10:30:00 -07:00
|
|
|
// Move the pointer file to the trash.
|
|
|
|
moveFile(pointerFile, itemLocationTrash);
|
|
|
|
}
|
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2009-06-11 02:54:26 -07:00
|
|
|
if (file) {
|
|
|
|
// Extract the xpi's files into the new directory
|
2007-03-22 10:30:00 -07:00
|
|
|
try {
|
2009-12-03 19:29:50 -08:00
|
|
|
var zipReader = getZipReaderForFile(file);
|
|
|
|
|
|
|
|
// create directories first
|
|
|
|
var entries = zipReader.findEntries("*/");
|
|
|
|
while (entries.hasMore()) {
|
|
|
|
var entryName = entries.getNext();
|
|
|
|
var target = installLocation.getItemFile(itemID, entryName);
|
|
|
|
if (!target.exists()) {
|
|
|
|
try {
|
|
|
|
target.create(Ci.nsILocalFile.DIRECTORY_TYPE,
|
|
|
|
FileUtils.PERMS_DIRECTORY);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
ERROR("extractFiles: failed to create target directory for extraction " +
|
|
|
|
"file = " + target.path + ", exception = " + e + "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
entries = zipReader.findEntries(null);
|
|
|
|
while (entries.hasMore()) {
|
|
|
|
var entryName = entries.getNext();
|
|
|
|
target = installLocation.getItemFile(itemID, entryName);
|
|
|
|
if (target.exists())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
zipReader.extract(entryName, target);
|
2010-01-29 15:04:40 -08:00
|
|
|
LOG("Extracted file " + entryName + " with permissions " + target.permissions.toString(8));
|
|
|
|
target.permissions |= FileUtils.PERMS_FILE;
|
2009-12-03 19:29:50 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
2009-06-11 02:54:26 -07:00
|
|
|
// This means the install operation failed. Remove everything and roll back.
|
|
|
|
ERROR("safeInstallOperation: file extraction failed, " +
|
|
|
|
"rolling back file moves and aborting installation.");
|
|
|
|
try {
|
|
|
|
// Us-generated. Safe.
|
|
|
|
removeDirRecursive(itemLocation);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
ERROR("safeInstallOperation: failed to remove the folder we failed to install " +
|
|
|
|
"an item into: " + itemLocation.path + " -- There is not much to suggest " +
|
|
|
|
"here... maybe restart and try again?");
|
|
|
|
cleanUpTrash(itemLocationTrash);
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
rollbackMove();
|
2007-03-22 10:30:00 -07:00
|
|
|
cleanUpTrash(itemLocationTrash);
|
|
|
|
throw e;
|
|
|
|
}
|
2009-12-03 19:29:50 -08:00
|
|
|
finally {
|
|
|
|
if (zipReader)
|
|
|
|
zipReader.close();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
|
|
|
|
// Now, and only now - after everything else has succeeded (against all odds!)
|
|
|
|
// remove the {GUID}-trash directory where we stashed the old version of the
|
2007-03-22 10:30:00 -07:00
|
|
|
// item.
|
|
|
|
cleanUpTrash(itemLocationTrash);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Manages the list of pending operations.
|
|
|
|
*/
|
|
|
|
var PendingOperations = {
|
|
|
|
_ops: { },
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds an entry to the Pending Operations List
|
|
|
|
* @param opType
|
|
|
|
* The type of Operation to be performed
|
|
|
|
* @param entry
|
|
|
|
* A JS Object representing the item to be operated on:
|
|
|
|
* "locationKey" The name of the Install Location where the item
|
|
|
|
* is installed.
|
|
|
|
* "id" The GUID of the item.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
addItem: function PendingOperations_addItem(opType, entry) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (opType == OP_NONE)
|
|
|
|
this.clearOpsForItem(entry.id);
|
|
|
|
else {
|
|
|
|
if (!(opType in this._ops))
|
|
|
|
this._ops[opType] = { };
|
|
|
|
this._ops[opType][entry.id] = entry.locationKey;
|
|
|
|
}
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Removes a Pending Operation from the list
|
|
|
|
* @param opType
|
|
|
|
* The type of Operation being removed
|
|
|
|
* @param id
|
|
|
|
* The GUID of the item to remove the entry for
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
clearItem: function PendingOperations_clearItem(opType, id) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (opType in this._ops && id in this._ops[opType])
|
|
|
|
delete this._ops[opType][id];
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Removes all Pending Operation for an item
|
|
|
|
* @param id
|
|
|
|
* The ID of the item to remove the entries for
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
clearOpsForItem: function PendingOperations_clearOpsForItem(id) {
|
2007-03-22 10:30:00 -07:00
|
|
|
for (var opType in this._ops) {
|
|
|
|
if (id in this._ops[opType])
|
|
|
|
delete this._ops[opType][id];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove all Pending Operations of a certain type
|
|
|
|
* @param opType
|
|
|
|
* The type of Operation to remove all entries for
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
clearItems: function PendingOperations_clearItems(opType) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (opType in this._ops)
|
|
|
|
delete this._ops[opType];
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Get an array of operations of a certain type
|
|
|
|
* @param opType
|
|
|
|
* The type of Operation to return a list of
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
getOperations: function PendingOperations_getOperations(opType) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!(opType in this._ops))
|
|
|
|
return [];
|
|
|
|
var ops = [];
|
|
|
|
for (var id in this._ops[opType])
|
|
|
|
ops.push( {id: id, locationKey: this._ops[opType][id] } );
|
|
|
|
return ops;
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* The total number of Pending Operations, for all types.
|
|
|
|
*/
|
|
|
|
get size() {
|
|
|
|
var size = 0;
|
|
|
|
for (var opType in this._ops) {
|
|
|
|
for (var id in this._ops[opType])
|
|
|
|
++size;
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Manages registered Install Locations
|
|
|
|
*/
|
2007-08-29 01:16:15 -07:00
|
|
|
var InstallLocations = {
|
2007-03-22 10:30:00 -07:00
|
|
|
_locations: { },
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A nsISimpleEnumerator of all available Install Locations.
|
|
|
|
*/
|
|
|
|
get enumeration() {
|
|
|
|
var installLocations = [];
|
2007-08-29 01:16:15 -07:00
|
|
|
for (var key in this._locations)
|
2007-03-22 10:30:00 -07:00
|
|
|
installLocations.push(InstallLocations.get(key));
|
|
|
|
return new ArrayEnumerator(installLocations);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Gets a named Install Location
|
|
|
|
* @param name
|
|
|
|
* The name of the Install Location to get
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
get: function InstallLocations_get(name) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return name in this._locations ? this._locations[name] : null;
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Registers an Install Location
|
|
|
|
* @param installLocation
|
|
|
|
* The Install Location to register
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
put: function InstallLocations_put(installLocation) {
|
2007-03-22 10:30:00 -07:00
|
|
|
this._locations[installLocation.name] = installLocation;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Manages the Startup Cache. The Startup Cache is a representation
|
|
|
|
* of the contents of extensions.cache, a list of all
|
|
|
|
* items the Extension System knows about, whether or not they
|
|
|
|
* are active or visible.
|
|
|
|
*/
|
|
|
|
var StartupCache = {
|
|
|
|
/**
|
|
|
|
* Location Name -> GUID hash of entries from the Startup Cache file
|
|
|
|
* Each entry has the following properties:
|
|
|
|
* "descriptor" The location on disk of the item
|
|
|
|
* "mtime" The time the location was last modified
|
|
|
|
* "op" Any pending operations on this item.
|
|
|
|
* "location" The Install Location name where the item is installed.
|
|
|
|
*/
|
|
|
|
entries: { },
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Puts an entry into the Startup Cache
|
|
|
|
* @param installLocation
|
|
|
|
* The Install Location where the item is installed
|
|
|
|
* @param id
|
|
|
|
* The GUID of the item
|
|
|
|
* @param op
|
|
|
|
* The name of the operation to be performed
|
|
|
|
* @param shouldCreate
|
|
|
|
* Whether or not we should create a new entry for this item
|
2007-08-29 01:16:15 -07:00
|
|
|
* in the cache if one does not already exist.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
put: function StartupCache_put(installLocation, id, op, shouldCreate) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var itemLocation = installLocation.getItemLocation(id);
|
|
|
|
|
|
|
|
var descriptor = null;
|
|
|
|
var mtime = null;
|
|
|
|
if (itemLocation) {
|
2007-09-17 11:05:04 -07:00
|
|
|
itemLocation.QueryInterface(Ci.nsILocalFile);
|
2007-03-22 10:30:00 -07:00
|
|
|
descriptor = getDescriptorFromFile(itemLocation, installLocation);
|
|
|
|
if (itemLocation.exists() && itemLocation.isDirectory())
|
|
|
|
mtime = Math.floor(itemLocation.lastModifiedTime / 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
this._putRaw(installLocation.name, id, descriptor, mtime, op, shouldCreate);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Private helper function for putting an entry into the Startup Cache
|
|
|
|
* without relying on the presence of its associated nsIInstallLocation
|
|
|
|
* instance.
|
|
|
|
*
|
|
|
|
* @param key
|
|
|
|
* The install location name.
|
|
|
|
* @param id
|
|
|
|
* The ID of the item.
|
|
|
|
* @param descriptor
|
|
|
|
* Value returned from absoluteDescriptor. May be null, in which
|
|
|
|
* case the descriptor field is not updated.
|
|
|
|
* @param mtime
|
|
|
|
* The last modified time of the item. May be null, in which case the
|
|
|
|
* descriptor field is not updated.
|
|
|
|
* @param op
|
|
|
|
* The OP code to store with the entry.
|
|
|
|
* @param shouldCreate
|
|
|
|
* Boolean value indicating whether to create or delete the entry.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_putRaw: function StartupCache__putRaw(key, id, descriptor, mtime, op, shouldCreate) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!(key in this.entries))
|
|
|
|
this.entries[key] = { };
|
|
|
|
if (!(id in this.entries[key]))
|
|
|
|
this.entries[key][id] = { };
|
|
|
|
if (shouldCreate) {
|
2007-08-29 01:16:15 -07:00
|
|
|
if (!this.entries[key][id])
|
2007-03-22 10:30:00 -07:00
|
|
|
this.entries[key][id] = { };
|
|
|
|
|
|
|
|
var entry = this.entries[key][id];
|
|
|
|
|
|
|
|
if (descriptor)
|
|
|
|
entry.descriptor = descriptor;
|
2007-08-29 01:16:15 -07:00
|
|
|
if (mtime)
|
2007-03-22 10:30:00 -07:00
|
|
|
entry.mtime = mtime;
|
|
|
|
entry.op = op;
|
|
|
|
entry.location = key;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
this.entries[key][id] = null;
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Clears an entry from the Startup Cache
|
|
|
|
* @param installLocation
|
|
|
|
* The Install Location where item is installed
|
|
|
|
* @param id
|
|
|
|
* The GUID of the item.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
clearEntry: function StartupCache_clearEntry(installLocation, id) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var key = installLocation.name;
|
|
|
|
if (key in this.entries && id in this.entries[key])
|
|
|
|
this.entries[key][id] = null;
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Get all the startup cache entries for a particular ID.
|
|
|
|
* @param id
|
|
|
|
* The GUID of the item to locate.
|
|
|
|
* @returns An array of Startup Cache entries for the specified ID.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
findEntries: function StartupCache_findEntries(id) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var entries = [];
|
|
|
|
for (var key in this.entries) {
|
2007-08-29 01:16:15 -07:00
|
|
|
if (id in this.entries[key])
|
2007-03-22 10:30:00 -07:00
|
|
|
entries.push(this.entries[key][id]);
|
|
|
|
}
|
|
|
|
return entries;
|
|
|
|
},
|
|
|
|
|
2007-08-29 01:16:15 -07:00
|
|
|
/**
|
2007-03-22 10:30:00 -07:00
|
|
|
* Read the Item-Change manifest file into a hash of properties.
|
|
|
|
* The Item-Change manifest currently holds a list of paths, with the last
|
|
|
|
* mtime for each path, and the GUID of the item at that path.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
read: function StartupCache_read() {
|
2009-10-23 12:42:48 -07:00
|
|
|
var itemChangeManifest = FileUtils.getFile(KEY_PROFILEDIR,
|
|
|
|
[FILE_EXTENSIONS_STARTUP_CACHE]);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!itemChangeManifest.exists()) {
|
|
|
|
// There is no change manifest for some reason, either we're in an initial
|
|
|
|
// state or something went wrong with one of the other files and the
|
|
|
|
// change manifest was removed. Return an empty dataset and rebuild.
|
2008-03-07 16:16:38 -08:00
|
|
|
gFirstRun = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
}
|
2007-09-03 20:07:11 -07:00
|
|
|
var fis = Cc["@mozilla.org/network/file-input-stream;1"].
|
|
|
|
createInstance(Ci.nsIFileInputStream);
|
2007-03-22 10:30:00 -07:00
|
|
|
fis.init(itemChangeManifest, -1, -1, false);
|
2007-09-17 11:05:04 -07:00
|
|
|
if (fis instanceof Ci.nsILineInputStream) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var line = { value: "" };
|
|
|
|
var more = false;
|
|
|
|
do {
|
|
|
|
more = fis.readLine(line);
|
|
|
|
if (line.value) {
|
|
|
|
// The Item-Change manifest is formatted like so:
|
|
|
|
// (pd = descriptor)
|
|
|
|
// location-key\tguid-of-item\tpd-to-extension1\tmtime-of-pd\tpending-op
|
|
|
|
// location-key\tguid-of-item\tpd-to-extension2\tmtime-of-pd\tpending-op
|
|
|
|
// ...
|
2007-08-29 01:16:15 -07:00
|
|
|
// We hash on location-key first, because we don't want to have to
|
2007-03-22 10:30:00 -07:00
|
|
|
// spin up the main extensions datasource on every start to determine
|
|
|
|
// the Install Location for an item.
|
|
|
|
// We hash on guid second, because we want a way to quickly determine
|
|
|
|
// item GUID during a check loop that runs on every startup.
|
|
|
|
var parts = line.value.split("\t");
|
2008-04-01 02:26:47 -07:00
|
|
|
// Silently drop any entries in unknown install locations
|
|
|
|
if (!InstallLocations.get(parts[0]))
|
|
|
|
continue;
|
2007-03-22 10:30:00 -07:00
|
|
|
var op = parts[4];
|
|
|
|
this._putRaw(parts[0], parts[1], parts[2], parts[3], op, true);
|
|
|
|
if (op)
|
|
|
|
PendingOperations.addItem(op, { locationKey: parts[0], id: parts[1] });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (more);
|
|
|
|
}
|
|
|
|
fis.close();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Writes the Startup Cache to disk
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
write: function StartupCache_write() {
|
2009-10-23 12:42:48 -07:00
|
|
|
var extensionsCacheFile = FileUtils.getFile(KEY_PROFILEDIR,
|
|
|
|
[FILE_EXTENSIONS_STARTUP_CACHE]);
|
|
|
|
var fos = FileUtils.openSafeFileOutputStream(extensionsCacheFile);
|
2007-03-22 10:30:00 -07:00
|
|
|
for (var locationKey in this.entries) {
|
|
|
|
for (var id in this.entries[locationKey]) {
|
|
|
|
var entry = this.entries[locationKey][id];
|
|
|
|
if (entry) {
|
|
|
|
try {
|
|
|
|
var itemLocation = getFileFromDescriptor(entry.descriptor, InstallLocations.get(locationKey));
|
|
|
|
|
|
|
|
// Update our knowledge of this item's last-modified-time.
|
|
|
|
// XXXdarin: this may cause us to miss changes in some cases.
|
|
|
|
var itemMTime = 0;
|
|
|
|
if (itemLocation.exists() && itemLocation.isDirectory())
|
|
|
|
itemMTime = Math.floor(itemLocation.lastModifiedTime / 1000);
|
|
|
|
|
|
|
|
// Each line in the startup cache manifest is in this form:
|
|
|
|
// location-key\tid-of-item\tpd-to-extension1\tmtime-of-pd\tpending-op
|
|
|
|
var line = locationKey + "\t" + id + "\t" + entry.descriptor + "\t" +
|
|
|
|
itemMTime + "\t" + entry.op + "\r\n";
|
|
|
|
fos.write(line, line.length);
|
|
|
|
}
|
|
|
|
catch (e) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-10-23 12:42:48 -07:00
|
|
|
FileUtils.closeSafeFileOutputStream(fos);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Installs, manages and tracks compatibility for Extensions and Themes
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
function ExtensionManager() {
|
2007-09-03 20:07:11 -07:00
|
|
|
gApp = Cc["@mozilla.org/xre/app-info;1"].
|
|
|
|
getService(Ci.nsIXULAppInfo).QueryInterface(Ci.nsIXULRuntime);
|
2007-03-22 10:30:00 -07:00
|
|
|
gOSTarget = gApp.OS;
|
|
|
|
try {
|
|
|
|
gXPCOMABI = gApp.XPCOMABI;
|
|
|
|
} catch (ex) {
|
|
|
|
// Provide a default for gXPCOMABI. It won't be compared to an
|
|
|
|
// item's metadata (i.e. install.rdf can't specify e.g. WINNT_unknownABI
|
|
|
|
// as targetPlatform), but it will be displayed in error messages and
|
|
|
|
// transmitted to update URLs.
|
|
|
|
gXPCOMABI = UNKNOWN_XPCOM_ABI;
|
|
|
|
}
|
2007-09-03 20:07:11 -07:00
|
|
|
gPref = Cc["@mozilla.org/preferences-service;1"].
|
2009-09-17 02:03:33 -07:00
|
|
|
getService(Ci.nsIPrefBranch2).
|
|
|
|
QueryInterface(Ci.nsIPrefService);
|
|
|
|
var defaults = gPref.getDefaultBranch("");
|
2009-09-17 11:31:52 -07:00
|
|
|
try {
|
|
|
|
gDefaultTheme = defaults.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN);
|
|
|
|
} catch(e) {}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-09-03 20:07:11 -07:00
|
|
|
gOS = Cc["@mozilla.org/observer-service;1"].
|
|
|
|
getService(Ci.nsIObserverService);
|
2007-03-22 10:30:00 -07:00
|
|
|
gOS.addObserver(this, "xpcom-shutdown", false);
|
2009-09-17 02:03:33 -07:00
|
|
|
gOS.addObserver(this, "lightweight-theme-preview-requested", false);
|
|
|
|
gOS.addObserver(this, "lightweight-theme-change-requested", false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-09-03 20:07:11 -07:00
|
|
|
gConsole = Cc["@mozilla.org/consoleservice;1"].
|
|
|
|
getService(Ci.nsIConsoleService);
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-09-03 20:07:11 -07:00
|
|
|
gRDF = Cc["@mozilla.org/rdf/rdf-service;1"].
|
|
|
|
getService(Ci.nsIRDFService);
|
2007-03-22 10:30:00 -07:00
|
|
|
gInstallManifestRoot = gRDF.GetResource(RDFURI_INSTALL_MANIFEST_ROOT);
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Register Global Install Location
|
2009-10-23 12:42:48 -07:00
|
|
|
var appGlobalExtensions = FileUtils.getDir(KEY_APPDIR, [DIR_EXTENSIONS],
|
|
|
|
false);
|
2007-09-17 11:05:04 -07:00
|
|
|
var priority = Ci.nsIInstallLocation.PRIORITY_APP_SYSTEM_GLOBAL;
|
2007-08-29 01:16:15 -07:00
|
|
|
var globalLocation = new DirectoryInstallLocation(KEY_APP_GLOBAL,
|
2007-03-22 10:30:00 -07:00
|
|
|
appGlobalExtensions, true,
|
2008-01-15 07:13:59 -08:00
|
|
|
priority, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
InstallLocations.put(globalLocation);
|
|
|
|
|
|
|
|
// Register App-Profile Install Location
|
2009-10-23 12:42:48 -07:00
|
|
|
var appProfileExtensions = FileUtils.getDir(KEY_PROFILEDS, [DIR_EXTENSIONS],
|
|
|
|
false);
|
2007-09-17 11:05:04 -07:00
|
|
|
var priority = Ci.nsIInstallLocation.PRIORITY_APP_PROFILE;
|
2007-08-29 01:16:15 -07:00
|
|
|
var profileLocation = new DirectoryInstallLocation(KEY_APP_PROFILE,
|
2007-03-22 10:30:00 -07:00
|
|
|
appProfileExtensions, false,
|
2008-01-15 07:13:59 -08:00
|
|
|
priority, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
InstallLocations.put(profileLocation);
|
|
|
|
|
2008-01-15 07:13:59 -08:00
|
|
|
// Register per-user Install Location
|
2008-01-15 08:28:37 -08:00
|
|
|
try {
|
2009-10-23 12:42:48 -07:00
|
|
|
var appSystemUExtensions = FileUtils.getDir("XREUSysExt", [gApp.ID], false);
|
2008-01-15 08:28:37 -08:00
|
|
|
}
|
|
|
|
catch(e) { }
|
|
|
|
|
|
|
|
if (appSystemUExtensions) {
|
|
|
|
var priority = Ci.nsIInstallLocation.PRIORITY_APP_SYSTEM_USER;
|
|
|
|
var systemLocation = new DirectoryInstallLocation(KEY_APP_SYSTEM_USER,
|
|
|
|
appSystemUExtensions, false,
|
|
|
|
priority, true);
|
|
|
|
|
|
|
|
InstallLocations.put(systemLocation);
|
|
|
|
}
|
2008-01-15 07:13:59 -08:00
|
|
|
|
|
|
|
// Register App-System-Shared Install Location
|
2008-01-15 08:28:37 -08:00
|
|
|
try {
|
2009-10-23 12:42:48 -07:00
|
|
|
var appSystemSExtensions = FileUtils.getDir("XRESysSExtPD", [gApp.ID], false);
|
2008-01-15 08:28:37 -08:00
|
|
|
}
|
|
|
|
catch (e) { }
|
2008-01-15 07:13:59 -08:00
|
|
|
|
2008-01-15 08:28:37 -08:00
|
|
|
if (appSystemSExtensions) {
|
|
|
|
var priority = Ci.nsIInstallLocation.PRIORITY_APP_SYSTEM_GLOBAL + 10;
|
|
|
|
var systemLocation = new DirectoryInstallLocation(KEY_APP_SYSTEM_SHARE,
|
|
|
|
appSystemSExtensions, true,
|
|
|
|
priority, true);
|
|
|
|
InstallLocations.put(systemLocation);
|
|
|
|
}
|
2008-01-15 07:13:59 -08:00
|
|
|
|
|
|
|
// Register App-System-Local Install Location
|
2008-01-15 08:28:37 -08:00
|
|
|
try {
|
2009-10-23 12:42:48 -07:00
|
|
|
var appSystemLExtensions = FileUtils.getDir("XRESysLExtPD", [gApp.ID], false);
|
2008-01-15 08:28:37 -08:00
|
|
|
}
|
|
|
|
catch (e) { }
|
|
|
|
|
|
|
|
if (appSystemLExtensions) {
|
|
|
|
var priority = Ci.nsIInstallLocation.PRIORITY_APP_SYSTEM_GLOBAL + 20;
|
|
|
|
var systemLocation = new DirectoryInstallLocation(KEY_APP_SYSTEM_LOCAL,
|
|
|
|
appSystemLExtensions, true,
|
|
|
|
priority, true);
|
|
|
|
InstallLocations.put(systemLocation);
|
|
|
|
}
|
2008-01-15 07:13:59 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef XP_WIN
|
|
|
|
// Register HKEY_LOCAL_MACHINE Install Location
|
|
|
|
InstallLocations.put(
|
|
|
|
new WinRegInstallLocation("winreg-app-global",
|
|
|
|
nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE,
|
|
|
|
true,
|
2007-09-17 11:05:04 -07:00
|
|
|
Ci.nsIInstallLocation.PRIORITY_APP_SYSTEM_GLOBAL + 10));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Register HKEY_CURRENT_USER Install Location
|
|
|
|
InstallLocations.put(
|
|
|
|
new WinRegInstallLocation("winreg-app-user",
|
|
|
|
nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
|
|
|
|
false,
|
2007-09-17 11:05:04 -07:00
|
|
|
Ci.nsIInstallLocation.PRIORITY_APP_SYSTEM_USER + 10));
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Register Additional Install Locations
|
2007-09-03 20:07:11 -07:00
|
|
|
var categoryManager = Cc["@mozilla.org/categorymanager;1"].
|
|
|
|
getService(Ci.nsICategoryManager);
|
2007-03-22 10:30:00 -07:00
|
|
|
var locations = categoryManager.enumerateCategory(CATEGORY_INSTALL_LOCATIONS);
|
|
|
|
while (locations.hasMoreElements()) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var entry = locations.getNext().QueryInterface(Ci.nsISupportsCString).data;
|
2007-03-22 10:30:00 -07:00
|
|
|
var contractID = categoryManager.getCategoryEntry(CATEGORY_INSTALL_LOCATIONS, entry);
|
2007-09-17 11:05:04 -07:00
|
|
|
var location = Cc[contractID].getService(Ci.nsIInstallLocation);
|
2007-03-22 10:30:00 -07:00
|
|
|
InstallLocations.put(location);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ExtensionManager.prototype = {
|
|
|
|
/**
|
|
|
|
* See nsIObserver.idl
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
observe: function EM_observe(subject, topic, data) {
|
2007-03-22 10:30:00 -07:00
|
|
|
switch (topic) {
|
|
|
|
case "profile-after-change":
|
|
|
|
this._profileSelected();
|
|
|
|
break;
|
|
|
|
case "quit-application-requested":
|
|
|
|
this._confirmCancelDownloadsOnQuit(subject);
|
|
|
|
break;
|
|
|
|
case "offline-requested":
|
|
|
|
this._confirmCancelDownloadsOnOffline(subject);
|
|
|
|
break;
|
2009-09-17 02:03:33 -07:00
|
|
|
case "lightweight-theme-preview-requested":
|
|
|
|
if (gPref.prefHasUserValue(PREF_GENERAL_SKINS_SELECTEDSKIN)) {
|
|
|
|
let cancel = subject.QueryInterface(Ci.nsISupportsPRBool);
|
|
|
|
cancel.data = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "lightweight-theme-change-requested":
|
|
|
|
let theme = JSON.parse(data);
|
|
|
|
if (!theme)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (gPref.prefHasUserValue(PREF_GENERAL_SKINS_SELECTEDSKIN)) {
|
|
|
|
if (getPref("getBoolPref", PREF_EM_DSS_ENABLED, false)) {
|
|
|
|
gPref.clearUserPref(PREF_GENERAL_SKINS_SELECTEDSKIN);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let cancel = subject.QueryInterface(Ci.nsISupportsPRBool);
|
|
|
|
cancel.data = true;
|
|
|
|
gPref.setBoolPref(PREF_DSS_SWITCHPENDING, true);
|
|
|
|
gPref.setCharPref(PREF_DSS_SKIN_TO_SELECT, gDefaultTheme);
|
|
|
|
gPref.setCharPref(PREF_LWTHEME_TO_SELECT, theme.id);
|
|
|
|
|
|
|
|
// Open the UI so the user can see that a restart is necessary
|
|
|
|
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
|
|
|
|
getService(Ci.nsIWindowMediator);
|
|
|
|
var win = wm.getMostRecentWindow("Extension:Manager");
|
|
|
|
|
|
|
|
if (win) {
|
|
|
|
win.showView("themes");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
|
|
|
|
getService(Ci.nsIWindowWatcher);
|
|
|
|
var param = Cc["@mozilla.org/supports-array;1"].
|
|
|
|
createInstance(Ci.nsISupportsArray);
|
|
|
|
var arg = Cc["@mozilla.org/supports-string;1"].
|
|
|
|
createInstance(Ci.nsISupportsString);
|
|
|
|
arg.data = "themes";
|
|
|
|
param.AppendElement(arg);
|
|
|
|
ww.openWindow(null, URI_EXTENSION_MANAGER, null, FEATURES_EXTENSION_MANAGER, param);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Cancel any pending theme change and allow the lightweight theme
|
|
|
|
// change to go ahead
|
2009-10-29 06:44:10 -07:00
|
|
|
if (gPref.prefHasUserValue(PREF_DSS_SWITCHPENDING))
|
|
|
|
gPref.clearUserPref(PREF_DSS_SWITCHPENDING);
|
|
|
|
if (gPref.prefHasUserValue(PREF_DSS_SKIN_TO_SELECT))
|
|
|
|
gPref.clearUserPref(PREF_DSS_SKIN_TO_SELECT);
|
2009-09-17 02:03:33 -07:00
|
|
|
}
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
case "xpcom-shutdown":
|
|
|
|
this._shutdown();
|
|
|
|
break;
|
|
|
|
case "nsPref:changed":
|
|
|
|
if (data == PREF_EM_LOGGING_ENABLED)
|
|
|
|
this._loggingToggled();
|
2009-11-09 10:14:13 -08:00
|
|
|
else if (data == gCheckCompatibilityPref ||
|
2007-09-03 14:44:12 -07:00
|
|
|
data == PREF_EM_CHECK_UPDATE_SECURITY)
|
|
|
|
this._updateAppDisabledState();
|
2007-06-25 14:02:46 -07:00
|
|
|
else if ((data == PREF_MATCH_OS_LOCALE) || (data == PREF_SELECTED_LOCALE))
|
|
|
|
this._updateLocale();
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Refresh the logging enabled global from preferences when the user changes
|
|
|
|
* the preference settting.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_loggingToggled: function EM__loggingToggled() {
|
2007-03-22 10:30:00 -07:00
|
|
|
gLoggingEnabled = getPref("getBoolPref", PREF_EM_LOGGING_ENABLED, false);
|
|
|
|
},
|
|
|
|
|
2007-06-25 14:02:46 -07:00
|
|
|
/**
|
|
|
|
* Retrieves the current locale
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_updateLocale: function EM__updateLocale() {
|
2007-06-25 14:02:46 -07:00
|
|
|
try {
|
|
|
|
if (gPref.getBoolPref(PREF_MATCH_OS_LOCALE)) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var localeSvc = Cc["@mozilla.org/intl/nslocaleservice;1"].
|
|
|
|
getService(Ci.nsILocaleService);
|
2007-06-25 14:02:46 -07:00
|
|
|
gLocale = localeSvc.getLocaleComponentForUserAgent();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (ex) {
|
|
|
|
}
|
|
|
|
gLocale = gPref.getCharPref(PREF_SELECTED_LOCALE);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
2007-09-03 14:44:12 -07:00
|
|
|
* When a preference is toggled that affects whether an item is usable or not
|
|
|
|
* we must app-enable or app-disable the item based on the new settings.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_updateAppDisabledState: function EM__updateAppDisabledState() {
|
2009-11-09 10:14:13 -08:00
|
|
|
gCheckCompatibility = getPref("getBoolPref", gCheckCompatibilityPref, true);
|
2007-09-03 14:44:12 -07:00
|
|
|
gCheckUpdateSecurity = getPref("getBoolPref", PREF_EM_CHECK_UPDATE_SECURITY, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
var ds = this.datasource;
|
|
|
|
|
|
|
|
// Enumerate all items
|
|
|
|
var ctr = getContainer(ds, ds._itemRoot);
|
|
|
|
var elements = ctr.GetElements();
|
|
|
|
while (elements.hasMoreElements()) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var itemResource = elements.getNext().QueryInterface(Ci.nsIRDFResource);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// App disable or enable items as necessary
|
|
|
|
// _appEnableItem and _appDisableItem will do nothing if the item is already
|
|
|
|
// in the right state.
|
2009-11-15 03:20:40 -08:00
|
|
|
var id = stripPrefix(itemResource.Value, PREFIX_ITEM_URI);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (this._isUsableItem(id))
|
|
|
|
this._appEnableItem(id);
|
|
|
|
else
|
|
|
|
this._appDisableItem(id);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the system after a profile has been selected.
|
2007-08-29 01:16:15 -07:00
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_profileSelected: function EM__profileSelected() {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Tell the Chrome Registry which Skin to select
|
|
|
|
try {
|
|
|
|
if (gPref.getBoolPref(PREF_DSS_SWITCHPENDING)) {
|
|
|
|
var toSelect = gPref.getCharPref(PREF_DSS_SKIN_TO_SELECT);
|
|
|
|
gPref.setCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN, toSelect);
|
|
|
|
gPref.clearUserPref(PREF_DSS_SWITCHPENDING);
|
|
|
|
gPref.clearUserPref(PREF_DSS_SKIN_TO_SELECT);
|
2009-09-17 02:03:33 -07:00
|
|
|
|
|
|
|
// If we've changed to a non-default theme make sure there is no
|
|
|
|
// lightweight theme selected
|
|
|
|
if (toSelect != gDefaultTheme) {
|
2009-10-28 14:44:15 -07:00
|
|
|
if (gPref.prefHasUserValue(PREF_LWTHEME_TO_SELECT))
|
|
|
|
gPref.clearUserPref(PREF_LWTHEME_TO_SELECT);
|
2009-09-17 02:03:33 -07:00
|
|
|
LightweightThemeManager.currentTheme = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gPref.prefHasUserValue(PREF_LWTHEME_TO_SELECT)) {
|
|
|
|
var id = gPref.getCharPref(PREF_LWTHEME_TO_SELECT);
|
|
|
|
if (id)
|
|
|
|
LightweightThemeManager.currentTheme = LightweightThemeManager.getUsedTheme(id);
|
|
|
|
else
|
|
|
|
LightweightThemeManager.currentTheme = null;
|
|
|
|
gPref.clearUserPref(PREF_LWTHEME_TO_SELECT);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
}
|
2008-01-25 01:30:41 -08:00
|
|
|
|
2009-11-09 10:14:13 -08:00
|
|
|
var version = gApp.version.replace(gBranchVersion, "$1");
|
|
|
|
gCheckCompatibilityPref = PREF_EM_CHECK_COMPATIBILITY + "." + version;
|
|
|
|
|
2009-11-06 18:40:15 -08:00
|
|
|
gLoggingEnabled = getPref("getBoolPref", PREF_EM_LOGGING_ENABLED, false);
|
2009-11-09 10:14:13 -08:00
|
|
|
gCheckCompatibility = getPref("getBoolPref", gCheckCompatibilityPref, true);
|
2009-11-06 18:40:15 -08:00
|
|
|
gCheckUpdateSecurity = getPref("getBoolPref", PREF_EM_CHECK_UPDATE_SECURITY, true);
|
|
|
|
|
2008-01-25 01:30:41 -08:00
|
|
|
if ("nsICrashReporter" in Ci && gApp instanceof Ci.nsICrashReporter) {
|
2009-11-06 18:40:15 -08:00
|
|
|
// Annotate the crash report with relevant add-on information.
|
|
|
|
try {
|
|
|
|
gApp.annotateCrashReport("Add-ons", gPref.getCharPref(PREF_EM_ENABLED_ITEMS));
|
|
|
|
} catch (e) { }
|
2008-01-25 01:30:41 -08:00
|
|
|
try {
|
|
|
|
gApp.annotateCrashReport("Theme", gPref.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN));
|
2009-11-06 18:40:15 -08:00
|
|
|
} catch (e) { }
|
|
|
|
try {
|
|
|
|
gApp.annotateCrashReport("EMCheckCompatibility", gCheckCompatibility);
|
|
|
|
} catch (e) { }
|
2008-01-25 01:30:41 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
gPref.addObserver("extensions.", this, false);
|
2007-06-25 14:02:46 -07:00
|
|
|
gPref.addObserver(PREF_MATCH_OS_LOCALE, this, false);
|
|
|
|
gPref.addObserver(PREF_SELECTED_LOCALE, this, false);
|
|
|
|
this._updateLocale();
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notify user that there are new addons updates
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_showUpdatesWindow: function EM__showUpdatesWindow() {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!getPref("getBoolPref", PREF_UPDATE_NOTIFYUSER, false))
|
|
|
|
return;
|
|
|
|
|
2007-09-03 20:07:11 -07:00
|
|
|
var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
|
|
|
|
getService(Ci.nsIWindowWatcher);
|
|
|
|
var param = Cc["@mozilla.org/supports-array;1"].
|
|
|
|
createInstance(Ci.nsISupportsArray);
|
|
|
|
var arg = Cc["@mozilla.org/supports-string;1"].
|
|
|
|
createInstance(Ci.nsISupportsString);
|
2007-03-22 10:30:00 -07:00
|
|
|
arg.data = "updates-only";
|
|
|
|
param.AppendElement(arg);
|
2009-09-17 02:03:33 -07:00
|
|
|
ww.openWindow(null, URI_EXTENSION_MANAGER, null, FEATURES_EXTENSION_UPDATES, param);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clean up on application shutdown to avoid leaks.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_shutdown: function EM__shutdown() {
|
2008-07-25 09:23:25 -07:00
|
|
|
if (!gAllowFlush) {
|
|
|
|
// Something went wrong and there are potentially flushes pending.
|
|
|
|
ERROR("Reached _shutdown and without clearing any pending flushes");
|
|
|
|
try {
|
|
|
|
gAllowFlush = true;
|
|
|
|
if (gManifestNeedsFlush) {
|
|
|
|
gManifestNeedsFlush = false;
|
|
|
|
this._updateManifests(false);
|
|
|
|
}
|
|
|
|
if (gDSNeedsFlush) {
|
|
|
|
gDSNeedsFlush = false;
|
|
|
|
this.datasource.Flush();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
ERROR("Error flushing caches: " + e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
gOS.removeObserver(this, "xpcom-shutdown");
|
2009-09-17 02:03:33 -07:00
|
|
|
gOS.removeObserver(this, "lightweight-theme-preview-requested");
|
|
|
|
gOS.removeObserver(this, "lightweight-theme-change-requested");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Release strongly held services.
|
|
|
|
gOS = null;
|
2008-11-28 14:20:10 -08:00
|
|
|
if (this._ds) {
|
2007-07-08 03:15:11 -07:00
|
|
|
gRDF.UnregisterDataSource(this._ptr);
|
|
|
|
this._ptr = null;
|
2008-11-28 14:20:10 -08:00
|
|
|
this._ds.shutdown();
|
|
|
|
this._ds = null;
|
2007-07-08 03:15:11 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
gRDF = null;
|
2007-06-25 14:53:29 -07:00
|
|
|
if (gPref) {
|
2007-03-22 10:30:00 -07:00
|
|
|
gPref.removeObserver("extensions.", this);
|
2007-06-25 14:53:29 -07:00
|
|
|
gPref.removeObserver(PREF_MATCH_OS_LOCALE, this);
|
|
|
|
gPref.removeObserver(PREF_SELECTED_LOCALE, this);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
gPref = null;
|
|
|
|
gConsole = null;
|
|
|
|
gVersionChecker = null;
|
|
|
|
gInstallManifestRoot = null;
|
|
|
|
gApp = null;
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
2007-08-29 01:16:15 -07:00
|
|
|
* Check for presence of critical Extension system files. If any is missing,
|
2007-03-22 10:30:00 -07:00
|
|
|
* delete the others and signal that the system needs to rebuild them all
|
|
|
|
* from scratch.
|
|
|
|
* @returns true if any critical file is missing and the system needs to
|
|
|
|
* be rebuilt, false otherwise.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_ensureDatasetIntegrity: function EM__ensureDatasetIntegrity() {
|
2009-10-23 12:42:48 -07:00
|
|
|
var profD = FileUtils.getDir(KEY_PROFILEDIR, [], false);
|
2009-01-06 03:04:41 -08:00
|
|
|
var extensionsDS = profD.clone();
|
|
|
|
extensionsDS.append(FILE_EXTENSIONS);
|
|
|
|
var extensionsINI = profD.clone();
|
|
|
|
extensionsINI.append(FILE_EXTENSION_MANIFEST);
|
|
|
|
var extensionsCache = profD;
|
|
|
|
extensionsCache.append(FILE_EXTENSIONS_STARTUP_CACHE);
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var dsExists = extensionsDS.exists();
|
|
|
|
var iniExists = extensionsINI.exists();
|
|
|
|
var cacheExists = extensionsCache.exists();
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (dsExists && iniExists && cacheExists)
|
2009-01-06 03:04:41 -08:00
|
|
|
return [false, !iniExists];
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// If any of the files are missing, remove the .ini file
|
|
|
|
if (iniExists)
|
|
|
|
extensionsINI.remove(false);
|
|
|
|
|
|
|
|
// If the extensions datasource is missing remove the .cache file if it exists
|
|
|
|
if (!dsExists && cacheExists)
|
|
|
|
extensionsCache.remove(false);
|
|
|
|
|
2009-01-06 03:04:41 -08:00
|
|
|
return [true, !iniExists];
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* See nsIExtensionManager.idl
|
|
|
|
*/
|
2009-05-12 01:22:39 -07:00
|
|
|
start: function EM_start() {
|
2009-01-06 03:04:41 -08:00
|
|
|
var isDirty, forceAutoReg;
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Check for missing manifests - e.g. missing extensions.ini, missing
|
2007-08-29 01:16:15 -07:00
|
|
|
// extensions.cache, extensions.rdf etc. If any of these files
|
2007-03-22 10:30:00 -07:00
|
|
|
// is missing then we are in some kind of weird or initial state and need
|
|
|
|
// to force a regeneration.
|
2009-01-06 03:04:41 -08:00
|
|
|
[isDirty, forceAutoReg] = this._ensureDatasetIntegrity();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-07-25 09:23:25 -07:00
|
|
|
// Block attempts to flush for the entire startup
|
|
|
|
gAllowFlush = false;
|
|
|
|
|
2007-08-29 01:16:15 -07:00
|
|
|
// Configure any items that are being installed, uninstalled or upgraded
|
2007-03-22 10:30:00 -07:00
|
|
|
// by being added, removed or modified by another process. We must do this
|
|
|
|
// on every startup since there is no way we can tell if this has happened
|
|
|
|
// or not!
|
|
|
|
if (this._checkForFileChanges())
|
|
|
|
isDirty = true;
|
|
|
|
|
2008-03-11 16:35:21 -07:00
|
|
|
this._showUpdatesWindow();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (PendingOperations.size != 0)
|
|
|
|
isDirty = true;
|
|
|
|
|
2008-07-25 09:23:25 -07:00
|
|
|
var needsRestart = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
// Extension Changes
|
|
|
|
if (isDirty) {
|
2008-07-25 09:23:25 -07:00
|
|
|
needsRestart = this._finishOperations();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (forceAutoReg) {
|
|
|
|
this._extensionListChanged = true;
|
|
|
|
needsRestart = true;
|
|
|
|
}
|
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2008-07-25 09:23:25 -07:00
|
|
|
// Resume flushing and perform a flush for anything that was deferred
|
|
|
|
try {
|
|
|
|
gAllowFlush = true;
|
|
|
|
if (gManifestNeedsFlush) {
|
|
|
|
gManifestNeedsFlush = false;
|
|
|
|
this._updateManifests(false);
|
|
|
|
}
|
|
|
|
if (gDSNeedsFlush) {
|
|
|
|
gDSNeedsFlush = false;
|
|
|
|
this.datasource.Flush();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
ERROR("Error flushing caches: " + e);
|
|
|
|
}
|
|
|
|
|
2010-02-05 10:21:37 -08:00
|
|
|
// Reset the first run flag.
|
|
|
|
gFirstRun = false;
|
|
|
|
|
2008-07-25 09:23:25 -07:00
|
|
|
return needsRestart;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Notified when a timer fires
|
|
|
|
* @param timer
|
|
|
|
* The timer that fired
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
notify: function EM_notify(timer) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!getPref("getBoolPref", PREF_EM_UPDATE_ENABLED, true))
|
|
|
|
return;
|
|
|
|
|
2009-11-07 00:21:07 -08:00
|
|
|
var items = this.getItemList(Ci.nsIUpdateItem.TYPE_ANY);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-11-17 04:52:03 -08:00
|
|
|
var updater = new ExtensionItemUpdater(this);
|
2007-06-25 08:51:51 -07:00
|
|
|
updater.checkForUpdates(items, items.length,
|
2007-09-17 11:05:04 -07:00
|
|
|
Ci.nsIExtensionManager.UPDATE_CHECK_NEWVERSION,
|
2008-10-21 17:48:52 -07:00
|
|
|
new BackgroundUpdateCheckListener(this.datasource),
|
2009-09-10 11:50:41 -07:00
|
|
|
UPDATE_WHEN_PERIODIC_UPDATE);
|
2009-11-16 23:55:47 -08:00
|
|
|
|
|
|
|
LightweightThemeManager.updateCurrentTheme();
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Check to see if a file is a XPI/JAR file that the user dropped into this
|
2007-08-29 01:16:15 -07:00
|
|
|
* Install Location. (i.e. a XPI that is not a staged XPI from an install
|
|
|
|
* transaction that is currently in operation).
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param file
|
|
|
|
* The XPI/JAR file to configure
|
|
|
|
* @param location
|
|
|
|
* The Install Location where this file was found.
|
2007-08-29 01:16:15 -07:00
|
|
|
* @returns A nsIUpdateItem representing the dropped XPI if this file was a
|
2007-03-22 10:30:00 -07:00
|
|
|
* XPI/JAR that needs installation, null otherwise.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_getItemForDroppedFile: function EM__getItemForDroppedFile(file, location) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (fileIsItemPackage(file)) {
|
|
|
|
// We know nothing about this item, it is not something we've
|
|
|
|
// staged in preparation for finalization, so assume it's something
|
|
|
|
// the user dropped in.
|
2007-08-29 01:16:15 -07:00
|
|
|
LOG("A Item Package appeared at: " + file.path + " that we know " +
|
|
|
|
"nothing about, assuming it was dropped in by the user and " +
|
2007-03-22 10:30:00 -07:00
|
|
|
"configuring for installation now. Location Key: " + location.name);
|
|
|
|
|
|
|
|
var installManifestFile = extractRDFFileToTempDir(file, FILE_INSTALL_MANIFEST, true);
|
|
|
|
if (!installManifestFile.exists())
|
|
|
|
return null;
|
|
|
|
var installManifest = getInstallManifest(installManifestFile);
|
|
|
|
installManifestFile.remove(false);
|
|
|
|
var ds = this.datasource;
|
|
|
|
var installData = this._getInstallData(installManifest);
|
|
|
|
var targetAppInfo = ds.getTargetApplicationInfo(installData.id, installManifest);
|
|
|
|
return makeItem(installData.id,
|
|
|
|
installData.version,
|
|
|
|
location.name,
|
|
|
|
targetAppInfo ? targetAppInfo.minVersion : "",
|
|
|
|
targetAppInfo ? targetAppInfo.maxVersion : "",
|
|
|
|
getManifestProperty(installManifest, "name"),
|
|
|
|
"", /* XPI Update URL */
|
|
|
|
"", /* XPI Update Hash */
|
|
|
|
getManifestProperty(installManifest, "iconURL"),
|
|
|
|
getManifestProperty(installManifest, "updateURL"),
|
2007-09-03 14:44:12 -07:00
|
|
|
getManifestProperty(installManifest, "updateKey"),
|
2007-08-29 01:16:15 -07:00
|
|
|
installData.type,
|
|
|
|
targetAppInfo ? targetAppInfo.appID : gApp.ID);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2008-04-01 02:26:47 -07:00
|
|
|
/**
|
|
|
|
* Configure an item that was installed or upgraded by another process
|
|
|
|
* so that |_finishOperations| can properly complete processing and
|
|
|
|
* registration.
|
|
|
|
* As this is the only point at which we can reliably know the Install
|
|
|
|
* Location of this item, we use this as an opportunity to:
|
|
|
|
* 1. Check that this item is compatible with this Firefox version.
|
|
|
|
* 2. If it is, configure the item by using the supplied callback.
|
|
|
|
* We do not do any special handling in the case that the item is
|
|
|
|
* not compatible with this version other than to simply not register
|
|
|
|
* it and log that fact - there is no "phone home" check for updates.
|
|
|
|
* It may or may not make sense to do this, but for now we'll just
|
|
|
|
* not register.
|
|
|
|
* @param id
|
|
|
|
* The GUID of the item to validate and configure.
|
|
|
|
* @param location
|
|
|
|
* The Install Location where this item is installed.
|
|
|
|
* @param callback
|
|
|
|
* The callback that configures the item for installation upon
|
|
|
|
* successful validation.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
installItem: function EM_installItem(id, location, callback) {
|
2008-04-01 02:26:47 -07:00
|
|
|
// As this is the only pint at which we reliably know the installation
|
|
|
|
var installRDF = location.getItemFile(id, FILE_INSTALL_MANIFEST);
|
|
|
|
if (installRDF.exists()) {
|
|
|
|
LOG("Item Installed/Upgraded at Install Location: " + location.name +
|
|
|
|
" Item ID: " + id + ", attempting to register...");
|
|
|
|
var installManifest = getInstallManifest(installRDF);
|
|
|
|
var installData = this._getInstallData(installManifest);
|
|
|
|
if (installData.error == INSTALLERROR_SUCCESS) {
|
|
|
|
LOG("... success, item is compatible");
|
|
|
|
callback(installManifest, installData.id, location, installData.type);
|
|
|
|
}
|
|
|
|
else if (installData.error == INSTALLERROR_INCOMPATIBLE_VERSION) {
|
|
|
|
LOG("... success, item installed but is not compatible");
|
|
|
|
callback(installManifest, installData.id, location, installData.type);
|
|
|
|
this._appDisableItem(id);
|
|
|
|
}
|
|
|
|
else if (installData.error == INSTALLERROR_INSECURE_UPDATE) {
|
|
|
|
LOG("... success, item installed but does not provide updates securely");
|
|
|
|
callback(installManifest, installData.id, location, installData.type);
|
|
|
|
this._appDisableItem(id);
|
|
|
|
}
|
|
|
|
else if (installData.error == INSTALLERROR_BLOCKLISTED) {
|
|
|
|
LOG("... success, item installed but is blocklisted");
|
|
|
|
callback(installManifest, installData.id, location, installData.type);
|
|
|
|
this._appDisableItem(id);
|
|
|
|
}
|
2008-11-02 04:13:48 -08:00
|
|
|
else if (installData.error == INSTALLERROR_SOFTBLOCKED) {
|
|
|
|
LOG("... success, item installed but is soft blocked, item will be disabled");
|
|
|
|
callback(installManifest, installData.id, location, installData.type);
|
|
|
|
this.disableItem(id);
|
|
|
|
}
|
2008-04-01 02:26:47 -07:00
|
|
|
else {
|
|
|
|
/**
|
|
|
|
* Turns an error code into a message for logging
|
|
|
|
* @param error
|
|
|
|
* an Install Error code
|
|
|
|
* @returns A string message to be logged.
|
|
|
|
*/
|
|
|
|
function translateErrorMessage(error) {
|
|
|
|
switch (error) {
|
|
|
|
case INSTALLERROR_INVALID_GUID:
|
|
|
|
return "Invalid GUID";
|
|
|
|
case INSTALLERROR_INVALID_VERSION:
|
|
|
|
return "Invalid Version";
|
|
|
|
case INSTALLERROR_INCOMPATIBLE_PLATFORM:
|
|
|
|
return "Incompatible Platform";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LOG("... failure, item is not compatible, error: " +
|
|
|
|
translateErrorMessage(installData.error));
|
|
|
|
|
|
|
|
// Add the item to the Startup Cache anyway, so we don't re-detect it
|
|
|
|
// every time the app starts.
|
|
|
|
StartupCache.put(location, id, OP_NONE, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
2007-08-29 01:16:15 -07:00
|
|
|
* Check for changes to items that were made independently of the Extension
|
2007-03-22 10:30:00 -07:00
|
|
|
* Manager, e.g. items were added or removed from a Install Location or items
|
2007-08-29 01:16:15 -07:00
|
|
|
* in an Install Location changed.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_checkForFileChanges: function EM__checkForFileChanges() {
|
2007-03-22 10:30:00 -07:00
|
|
|
var em = this;
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Determines if an item can be used based on whether or not the install
|
|
|
|
* location of the "item" has an equal or higher priority than the install
|
|
|
|
* location where another version may live.
|
|
|
|
* @param id
|
|
|
|
* The GUID of the item being installed.
|
|
|
|
* @param location
|
|
|
|
* The location where an item is to be installed.
|
2007-08-29 01:16:15 -07:00
|
|
|
* @returns true if the item can be installed at that location, false
|
2007-03-22 10:30:00 -07:00
|
|
|
* otherwise.
|
|
|
|
*/
|
|
|
|
function canUse(id, location) {
|
|
|
|
for (var locationKey in StartupCache.entries) {
|
2007-08-29 01:16:15 -07:00
|
|
|
if (locationKey != location.name &&
|
2007-03-22 10:30:00 -07:00
|
|
|
id in StartupCache.entries[locationKey]) {
|
|
|
|
if (StartupCache.entries[locationKey][id]) {
|
|
|
|
var oldInstallLocation = InstallLocations.get(locationKey);
|
|
|
|
if (oldInstallLocation.priority <= location.priority)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
|
|
|
|
/**
|
2007-03-22 10:30:00 -07:00
|
|
|
* Gets a Dialog Param Block loaded with a set of strings to initialize the
|
|
|
|
* XPInstall Confirmation Dialog.
|
|
|
|
* @param strings
|
|
|
|
* An array of strings
|
|
|
|
* @returns A nsIDialogParamBlock loaded with the strings and dialog state.
|
|
|
|
*/
|
|
|
|
function getParamBlock(strings) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var dpb = Cc["@mozilla.org/embedcomp/dialogparam;1"].
|
|
|
|
createInstance(Ci.nsIDialogParamBlock);
|
2007-03-22 10:30:00 -07:00
|
|
|
// OK and Cancel Buttons
|
|
|
|
dpb.SetInt(0, 2);
|
|
|
|
// Number of Strings
|
|
|
|
dpb.SetInt(1, strings.length);
|
|
|
|
dpb.SetNumberStrings(strings.length);
|
|
|
|
// Add Strings
|
|
|
|
for (var i = 0; i < strings.length; ++i)
|
|
|
|
dpb.SetString(i, strings[i]);
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-09-03 20:07:11 -07:00
|
|
|
var supportsString = Cc["@mozilla.org/supports-string;1"].
|
|
|
|
createInstance(Ci.nsISupportsString);
|
2007-03-22 10:30:00 -07:00
|
|
|
var bundle = BundleManager.getBundle(URI_EXTENSIONS_PROPERTIES);
|
|
|
|
supportsString.data = bundle.GetStringFromName("droppedInWarning");
|
2007-09-03 20:07:11 -07:00
|
|
|
var objs = Cc["@mozilla.org/array;1"].
|
|
|
|
createInstance(Ci.nsIMutableArray);
|
2007-03-22 10:30:00 -07:00
|
|
|
objs.appendElement(supportsString, false);
|
|
|
|
dpb.objects = objs;
|
2007-08-29 01:16:15 -07:00
|
|
|
return dpb;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-08-29 01:16:15 -07:00
|
|
|
* Installs a set of files which were dropped into an install location by
|
2007-03-22 10:30:00 -07:00
|
|
|
* the user, only after user confirmation.
|
|
|
|
* @param droppedInFiles
|
|
|
|
* An array of JS objects with the following properties:
|
|
|
|
* "file" The nsILocalFile where the XPI lives
|
2007-08-29 01:16:15 -07:00
|
|
|
* "location" The Install Location where the XPI was found.
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param xpinstallStrings
|
2007-08-29 01:16:15 -07:00
|
|
|
* An array of strings used to initialize the XPInstall Confirm
|
2007-03-22 10:30:00 -07:00
|
|
|
* dialog.
|
2007-08-29 01:16:15 -07:00
|
|
|
*/
|
2007-03-22 10:30:00 -07:00
|
|
|
function installDroppedInFiles(droppedInFiles, xpinstallStrings) {
|
2007-08-29 01:16:15 -07:00
|
|
|
if (droppedInFiles.length == 0)
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var dpb = getParamBlock(xpinstallStrings);
|
2007-09-03 20:07:11 -07:00
|
|
|
var ifptr = Cc["@mozilla.org/supports-interface-pointer;1"].
|
|
|
|
createInstance(Ci.nsISupportsInterfacePointer);
|
2007-03-22 10:30:00 -07:00
|
|
|
ifptr.data = dpb;
|
2007-09-03 20:07:11 -07:00
|
|
|
ifptr.dataIID = Ci.nsIDialogParamBlock;
|
|
|
|
var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
|
|
|
|
getService(Ci.nsIWindowWatcher);
|
2007-08-29 01:16:15 -07:00
|
|
|
ww.openWindow(null, URI_XPINSTALL_CONFIRM_DIALOG,
|
2007-03-22 10:30:00 -07:00
|
|
|
"", "chrome,centerscreen,modal,dialog,titlebar", ifptr);
|
|
|
|
if (!dpb.GetInt(0)) {
|
|
|
|
// User said OK - install items
|
|
|
|
for (var i = 0; i < droppedInFiles.length; ++i) {
|
2007-08-29 01:16:15 -07:00
|
|
|
em.installItemFromFile(droppedInFiles[i].file,
|
2007-03-22 10:30:00 -07:00
|
|
|
droppedInFiles[i].location.name);
|
|
|
|
// We are responsible for cleaning up this file
|
|
|
|
droppedInFiles[i].file.remove(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (i = 0; i < droppedInFiles.length; ++i) {
|
|
|
|
// We are responsible for cleaning up this file
|
|
|
|
droppedInFiles[i].file.remove(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var isDirty = false;
|
|
|
|
var ignoreMTimeChanges = getPref("getBoolPref", PREF_EM_IGNOREMTIMECHANGES,
|
|
|
|
false);
|
|
|
|
StartupCache.read();
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Array of objects with 'location' and 'id' properties to maybe install.
|
|
|
|
var newItems = [];
|
|
|
|
|
|
|
|
var droppedInFiles = [];
|
|
|
|
var xpinstallStrings = [];
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Enumerate over the install locations from low to high priority. The
|
|
|
|
// enumeration returned is pre-sorted.
|
|
|
|
var installLocations = this.installLocations;
|
|
|
|
while (installLocations.hasMoreElements()) {
|
2007-09-17 11:05:04 -07:00
|
|
|
var location = installLocations.getNext().QueryInterface(Ci.nsIInstallLocation);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-08-29 01:16:15 -07:00
|
|
|
// Hash the set of items actually held by the Install Location.
|
2007-03-22 10:30:00 -07:00
|
|
|
var actualItems = { };
|
|
|
|
var entries = location.itemLocations;
|
|
|
|
while (true) {
|
|
|
|
var entry = entries.nextFile;
|
|
|
|
if (!entry)
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Is this location a valid item? It must be a directory, and contain
|
|
|
|
// an install.rdf manifest:
|
|
|
|
if (entry.isDirectory()) {
|
|
|
|
var installRDF = entry.clone();
|
|
|
|
installRDF.append(FILE_INSTALL_MANIFEST);
|
|
|
|
|
|
|
|
var id = location.getIDForLocation(entry);
|
2007-08-29 01:16:15 -07:00
|
|
|
if (!id || (!installRDF.exists() &&
|
2007-03-22 10:30:00 -07:00
|
|
|
!location.itemIsManagedIndependently(id)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
actualItems[id] = entry;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Check to see if this file is a XPI/JAR dropped into this dir
|
|
|
|
// by the user, installing it if necessary. We do this here rather
|
|
|
|
// than separately in |_finishOperations| because I don't want to
|
|
|
|
// walk these lists multiple times on every startup.
|
|
|
|
var item = this._getItemForDroppedFile(entry, location);
|
|
|
|
if (item) {
|
|
|
|
var prettyName = "";
|
|
|
|
try {
|
|
|
|
var zipReader = getZipReaderForFile(entry);
|
2009-05-19 01:28:04 -07:00
|
|
|
var principal = zipReader.getCertificatePrincipal(null);
|
|
|
|
if (principal && principal.hasCertificate) {
|
2009-09-26 08:50:33 -07:00
|
|
|
if (verifyZipSigning(zipReader, principal)) {
|
2009-11-15 03:20:35 -08:00
|
|
|
var x509 = principal.certificate;
|
2009-09-26 08:50:33 -07:00
|
|
|
if (x509 instanceof Ci.nsIX509Cert && x509.commonName.length > 0)
|
|
|
|
prettyName = x509.commonName;
|
|
|
|
else
|
|
|
|
prettyName = principal.prettyName;
|
2009-05-19 01:28:04 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// The xpi isn't correctly signed, don't offer to install.
|
|
|
|
LOG("Ignoring " + entry.path + " as it is not correctly signed.");
|
2009-05-19 04:20:41 -07:00
|
|
|
zipReader.close();
|
2009-05-19 01:28:04 -07:00
|
|
|
entry.remove(true);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
catch (e) { }
|
|
|
|
if (zipReader)
|
|
|
|
zipReader.close();
|
2009-05-19 01:28:04 -07:00
|
|
|
droppedInFiles.push({ file: entry, location: location });
|
2007-08-29 01:16:15 -07:00
|
|
|
xpinstallStrings = xpinstallStrings.concat([item.name,
|
2007-03-22 10:30:00 -07:00
|
|
|
getURLSpecFromFile(entry),
|
2007-08-29 01:16:15 -07:00
|
|
|
item.iconURL,
|
2007-03-22 10:30:00 -07:00
|
|
|
prettyName]);
|
|
|
|
isDirty = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (location.name in StartupCache.entries) {
|
|
|
|
// Look for items that have been uninstalled by removing their directory.
|
|
|
|
for (var id in StartupCache.entries[location.name]) {
|
|
|
|
if (!StartupCache.entries[location.name] ||
|
2007-08-29 01:16:15 -07:00
|
|
|
!StartupCache.entries[location.name][id])
|
2007-03-22 10:30:00 -07:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Force _finishOperations to run if we have enabled or disabled items.
|
|
|
|
// XXXdarin this should be unnecessary now that we check
|
|
|
|
// PendingOperations.size in start()
|
|
|
|
if (StartupCache.entries[location.name][id].op == OP_NEEDS_ENABLE ||
|
|
|
|
StartupCache.entries[location.name][id].op == OP_NEEDS_DISABLE)
|
|
|
|
isDirty = true;
|
2007-08-29 01:16:15 -07:00
|
|
|
|
|
|
|
if (!(id in actualItems) &&
|
2007-03-22 10:30:00 -07:00
|
|
|
StartupCache.entries[location.name][id].op != OP_NEEDS_UNINSTALL &&
|
|
|
|
StartupCache.entries[location.name][id].op != OP_NEEDS_INSTALL &&
|
|
|
|
StartupCache.entries[location.name][id].op != OP_NEEDS_UPGRADE) {
|
2007-08-29 01:16:15 -07:00
|
|
|
// We have an entry for this id in the Extensions database, for this
|
|
|
|
// install location, but it no longer exists in the Install Location.
|
2007-03-22 10:30:00 -07:00
|
|
|
// We can infer from this that the item has been removed, so uninstall
|
2007-08-29 01:16:15 -07:00
|
|
|
// it properly.
|
2007-03-22 10:30:00 -07:00
|
|
|
if (canUse(id, location)) {
|
2007-08-29 01:16:15 -07:00
|
|
|
LOG("Item Uninstalled via file removal from: " + StartupCache.entries[location.name][id].descriptor +
|
2007-03-22 10:30:00 -07:00
|
|
|
" Item ID: " + id + " Location Key: " + location.name + ", uninstalling item.");
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Load the Extensions Datasource and force this item into the visible
|
2007-08-29 01:16:15 -07:00
|
|
|
// items list if it is not already. This allows us to handle the case
|
2007-03-22 10:30:00 -07:00
|
|
|
// where there is an entry for an item in the Startup Cache but not
|
|
|
|
// in the extensions.rdf file - in that case the item will not be in
|
|
|
|
// the visible list and calls to |getInstallLocation| will mysteriously
|
|
|
|
// fail.
|
|
|
|
this.datasource.updateVisibleList(id, location.name, false);
|
|
|
|
this.uninstallItem(id);
|
|
|
|
isDirty = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!ignoreMTimeChanges) {
|
2007-08-29 01:16:15 -07:00
|
|
|
// Look for items whose mtime has changed, and as such we can assume
|
2007-03-22 10:30:00 -07:00
|
|
|
// they have been "upgraded".
|
|
|
|
var lf = { path: StartupCache.entries[location.name][id].descriptor };
|
|
|
|
try {
|
|
|
|
lf = getFileFromDescriptor(StartupCache.entries[location.name][id].descriptor, location);
|
|
|
|
}
|
|
|
|
catch (e) { }
|
|
|
|
|
|
|
|
if (lf.exists && lf.exists()) {
|
|
|
|
var actualMTime = Math.floor(lf.lastModifiedTime / 1000);
|
|
|
|
if (actualMTime != StartupCache.entries[location.name][id].mtime) {
|
2007-08-29 01:16:15 -07:00
|
|
|
LOG("Item Location path changed: " + lf.path + " Item ID: " +
|
2007-03-22 10:30:00 -07:00
|
|
|
id + " Location Key: " + location.name + ", attempting to upgrade item...");
|
|
|
|
if (canUse(id, location)) {
|
2008-04-01 02:26:47 -07:00
|
|
|
this.installItem(id, location,
|
|
|
|
function(installManifest, id, location, type) {
|
|
|
|
em._upgradeItem(installManifest, id, location,
|
|
|
|
type);
|
|
|
|
});
|
2007-03-22 10:30:00 -07:00
|
|
|
isDirty = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
isDirty = true;
|
2007-08-29 01:16:15 -07:00
|
|
|
LOG("Install Location returned a missing or malformed item path! " +
|
|
|
|
"Item Path: " + lf.path + ", Location Key: " + location.name +
|
2007-03-22 10:30:00 -07:00
|
|
|
" Item ID: " + id);
|
|
|
|
if (canUse(id, location)) {
|
|
|
|
// Load the Extensions Datasource and force this item into the visible
|
2007-08-29 01:16:15 -07:00
|
|
|
// items list if it is not already. This allows us to handle the case
|
2007-03-22 10:30:00 -07:00
|
|
|
// where there is an entry for an item in the Startup Cache but not
|
|
|
|
// in the extensions.rdf file - in that case the item will not be in
|
|
|
|
// the visible list and calls to |getInstallLocation| will mysteriously
|
|
|
|
// fail.
|
|
|
|
this.datasource.updateVisibleList(id, location.name, false);
|
|
|
|
this.uninstallItem(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Look for items that have been installed by appearing in the location.
|
|
|
|
for (var id in actualItems) {
|
2007-08-29 01:16:15 -07:00
|
|
|
if (!(location.name in StartupCache.entries) ||
|
2007-03-22 10:30:00 -07:00
|
|
|
!(id in StartupCache.entries[location.name]) ||
|
|
|
|
!StartupCache.entries[location.name][id]) {
|
|
|
|
// Remember that we've seen this item
|
|
|
|
StartupCache.put(location, id, OP_NONE, true);
|
|
|
|
// Push it on the stack of items to maybe install later
|
|
|
|
newItems.push({location: location, id: id});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process any newly discovered items. We do this here instead of in the
|
|
|
|
// previous loop so that we can be sure that we have a fully populated
|
|
|
|
// StartupCache.
|
|
|
|
for (var i = 0; i < newItems.length; ++i) {
|
|
|
|
var id = newItems[i].id;
|
|
|
|
var location = newItems[i].location;
|
|
|
|
if (canUse(id, location)) {
|
2007-08-29 01:16:15 -07:00
|
|
|
LOG("Item Installed via directory addition to Install Location: " +
|
2007-03-22 10:30:00 -07:00
|
|
|
location.name + " Item ID: " + id + ", attempting to register...");
|
2008-04-01 02:26:47 -07:00
|
|
|
this.installItem(id, location,
|
|
|
|
function(installManifest, id, location, type) {
|
|
|
|
em._configureForthcomingItem(installManifest, id, location,
|
|
|
|
type);
|
|
|
|
});
|
2007-03-22 10:30:00 -07:00
|
|
|
// Disable add-ons on install when the InstallDisabled file exists.
|
|
|
|
// This is so Talkback will be disabled on a subset of installs.
|
|
|
|
var installDisabled = location.getItemFile(id, "InstallDisabled");
|
|
|
|
if (installDisabled.exists())
|
|
|
|
em.disableItem(id);
|
|
|
|
isDirty = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ask the user if they want to install the dropped items, for security
|
|
|
|
// purposes.
|
|
|
|
installDroppedInFiles(droppedInFiles, xpinstallStrings);
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return isDirty;
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
_checkForUncoveredItem: function EM__checkForUncoveredItem(id) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var ds = this.datasource;
|
|
|
|
var oldLocation = this.getInstallLocation(id);
|
|
|
|
var newLocations = [];
|
|
|
|
for (var locationKey in StartupCache.entries) {
|
|
|
|
var location = InstallLocations.get(locationKey);
|
2007-08-29 01:16:15 -07:00
|
|
|
if (id in StartupCache.entries[locationKey] &&
|
2007-03-22 10:30:00 -07:00
|
|
|
location.priority > oldLocation.priority)
|
|
|
|
newLocations.push(location);
|
|
|
|
}
|
|
|
|
newLocations.sort(function(a, b) { return b.priority - a.priority; });
|
|
|
|
if (newLocations.length > 0) {
|
|
|
|
for (var i = 0; i < newLocations.length; ++i) {
|
|
|
|
// Check to see that the item at the location exists
|
|
|
|
var installRDF = newLocations[i].getItemFile(id, FILE_INSTALL_MANIFEST);
|
|
|
|
if (installRDF.exists()) {
|
2007-08-29 01:16:15 -07:00
|
|
|
// Update the visible item cache so that |_finalizeUpgrade| is properly
|
2007-03-22 10:30:00 -07:00
|
|
|
// called from |_finishOperations|
|
|
|
|
var name = newLocations[i].name;
|
|
|
|
ds.updateVisibleList(id, name, true);
|
2007-08-29 01:16:15 -07:00
|
|
|
PendingOperations.addItem(OP_NEEDS_UPGRADE,
|
2007-03-22 10:30:00 -07:00
|
|
|
{ locationKey: name, id: id });
|
2007-08-29 01:16:15 -07:00
|
|
|
PendingOperations.addItem(OP_NEEDS_INSTALL,
|
2007-03-22 10:30:00 -07:00
|
|
|
{ locationKey: name, id: id });
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// If no item exists at the location specified, remove this item
|
2007-08-29 01:16:15 -07:00
|
|
|
// from the visible items list and check again.
|
2007-03-22 10:30:00 -07:00
|
|
|
StartupCache.clearEntry(newLocations[i], id);
|
|
|
|
ds.updateVisibleList(id, null, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ds.updateVisibleList(id, null, true);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
2007-08-29 01:16:15 -07:00
|
|
|
* Finish up pending operations - perform upgrades, installs, enables/disables,
|
2007-03-22 10:30:00 -07:00
|
|
|
* uninstalls etc.
|
2007-08-29 01:16:15 -07:00
|
|
|
* @returns true if actions were performed that require a restart, false
|
2007-03-22 10:30:00 -07:00
|
|
|
* otherwise.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_finishOperations: function EM__finishOperations() {
|
2007-03-22 10:30:00 -07:00
|
|
|
try {
|
|
|
|
// Stuff has changed, load the Extensions datasource in all its RDFey
|
2007-08-29 01:16:15 -07:00
|
|
|
// glory.
|
2007-03-22 10:30:00 -07:00
|
|
|
var ds = this.datasource;
|
|
|
|
var updatedTargetAppInfos = [];
|
|
|
|
|
2007-08-29 01:16:15 -07:00
|
|
|
var needsRestart = false;
|
2008-03-07 16:16:38 -08:00
|
|
|
var upgrades = [];
|
|
|
|
var newAddons = [];
|
|
|
|
var addons = getPref("getCharPref", PREF_EM_NEW_ADDONS_LIST, "");
|
|
|
|
if (addons != "")
|
|
|
|
newAddons = addons.split(",");
|
2007-03-22 10:30:00 -07:00
|
|
|
do {
|
|
|
|
// Enable and disable during startup so items that are changed in the
|
|
|
|
// ui can be reset to a no-op.
|
|
|
|
// Look for extensions that need to be enabled.
|
|
|
|
var items = PendingOperations.getOperations(OP_NEEDS_ENABLE);
|
|
|
|
for (var i = items.length - 1; i >= 0; --i) {
|
|
|
|
var id = items[i].id;
|
|
|
|
var installLocation = this.getInstallLocation(id);
|
|
|
|
StartupCache.put(installLocation, id, OP_NONE, true);
|
|
|
|
PendingOperations.clearItem(OP_NEEDS_ENABLE, id);
|
|
|
|
needsRestart = true;
|
|
|
|
}
|
|
|
|
PendingOperations.clearItems(OP_NEEDS_ENABLE);
|
|
|
|
|
|
|
|
// Look for extensions that need to be disabled.
|
|
|
|
items = PendingOperations.getOperations(OP_NEEDS_DISABLE);
|
|
|
|
for (i = items.length - 1; i >= 0; --i) {
|
|
|
|
id = items[i].id;
|
|
|
|
installLocation = this.getInstallLocation(id);
|
|
|
|
StartupCache.put(installLocation, id, OP_NONE, true);
|
|
|
|
PendingOperations.clearItem(OP_NEEDS_DISABLE, id);
|
|
|
|
needsRestart = true;
|
|
|
|
}
|
|
|
|
PendingOperations.clearItems(OP_NEEDS_DISABLE);
|
|
|
|
|
|
|
|
// Look for extensions that need to be upgraded. The process here is to
|
|
|
|
// uninstall the old version of the extension first, then install the
|
2007-08-29 01:16:15 -07:00
|
|
|
// new version in its place.
|
2007-03-22 10:30:00 -07:00
|
|
|
items = PendingOperations.getOperations(OP_NEEDS_UPGRADE);
|
|
|
|
for (i = items.length - 1; i >= 0; --i) {
|
|
|
|
id = items[i].id;
|
|
|
|
var newLocation = InstallLocations.get(items[i].locationKey);
|
2007-12-03 04:20:57 -08:00
|
|
|
// check if there is updated app compatibility info
|
|
|
|
var newTargetAppInfo = ds.getUpdatedTargetAppInfo(id);
|
|
|
|
if (newTargetAppInfo)
|
|
|
|
updatedTargetAppInfos.push(newTargetAppInfo);
|
|
|
|
this._finalizeUpgrade(id, newLocation);
|
2008-03-07 16:16:38 -08:00
|
|
|
upgrades.push(id);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
PendingOperations.clearItems(OP_NEEDS_UPGRADE);
|
|
|
|
|
|
|
|
// Install items
|
|
|
|
items = PendingOperations.getOperations(OP_NEEDS_INSTALL);
|
|
|
|
for (i = items.length - 1; i >= 0; --i) {
|
|
|
|
needsRestart = true;
|
|
|
|
id = items[i].id;
|
|
|
|
// check if there is updated app compatibility info
|
|
|
|
newTargetAppInfo = ds.getUpdatedTargetAppInfo(id);
|
|
|
|
if (newTargetAppInfo)
|
|
|
|
updatedTargetAppInfos.push(newTargetAppInfo);
|
|
|
|
this._finalizeInstall(id, null);
|
2008-03-07 16:16:38 -08:00
|
|
|
if (upgrades.indexOf(id) < 0 && newAddons.indexOf(id) < 0)
|
|
|
|
newAddons.push(id);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
PendingOperations.clearItems(OP_NEEDS_INSTALL);
|
|
|
|
|
|
|
|
// Look for extensions that need to be removed. This MUST be done after
|
|
|
|
// the install operations since extensions to be installed may have to be
|
|
|
|
// uninstalled if there are errors during the installation process!
|
|
|
|
items = PendingOperations.getOperations(OP_NEEDS_UNINSTALL);
|
|
|
|
for (i = items.length - 1; i >= 0; --i) {
|
|
|
|
id = items[i].id;
|
|
|
|
this._finalizeUninstall(id);
|
|
|
|
this._checkForUncoveredItem(id);
|
|
|
|
needsRestart = true;
|
2008-03-07 16:16:38 -08:00
|
|
|
var pos = newAddons.indexOf(id);
|
|
|
|
if (pos >= 0)
|
|
|
|
newAddons.splice(pos, 1);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
PendingOperations.clearItems(OP_NEEDS_UNINSTALL);
|
|
|
|
|
|
|
|
// When there have been operations and all operations have completed.
|
|
|
|
if (PendingOperations.size == 0) {
|
2007-12-11 16:56:09 -08:00
|
|
|
// If there is updated app compatibility info update the datasource.
|
2007-03-22 10:30:00 -07:00
|
|
|
for (i = 0; i < updatedTargetAppInfos.length; ++i)
|
2007-12-11 16:56:09 -08:00
|
|
|
ds.setTargetApplicationInfo(updatedTargetAppInfos[i].id,
|
|
|
|
updatedTargetAppInfos[i].targetAppID,
|
|
|
|
updatedTargetAppInfos[i].minVersion,
|
|
|
|
updatedTargetAppInfos[i].maxVersion,
|
|
|
|
null);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Enumerate all items
|
|
|
|
var ctr = getContainer(ds, ds._itemRoot);
|
|
|
|
var elements = ctr.GetElements();
|
|
|
|
while (elements.hasMoreElements()) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var itemResource = elements.getNext().QueryInterface(Ci.nsIRDFResource);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Ensure appDisabled is in the correct state.
|
|
|
|
id = stripPrefix(itemResource.Value, PREFIX_ITEM_URI);
|
|
|
|
if (this._isUsableItem(id))
|
|
|
|
ds.setItemProperty(id, EM_R("appDisabled"), null);
|
|
|
|
else
|
|
|
|
ds.setItemProperty(id, EM_R("appDisabled"), EM_L("true"));
|
|
|
|
|
|
|
|
// userDisabled is set based on its value being OP_NEEDS_ENABLE or
|
|
|
|
// OP_NEEDS_DISABLE. This allows us to have an item to be enabled
|
|
|
|
// by the app and disabled by the user during a single restart.
|
|
|
|
var value = stringData(ds.GetTarget(itemResource, EM_R("userDisabled"), true));
|
|
|
|
if (value == OP_NEEDS_ENABLE)
|
|
|
|
ds.setItemProperty(id, EM_R("userDisabled"), null);
|
|
|
|
else if (value == OP_NEEDS_DISABLE)
|
|
|
|
ds.setItemProperty(id, EM_R("userDisabled"), EM_L("true"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (PendingOperations.size > 0);
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// If no additional restart is required, it implies that there are
|
|
|
|
// no new components that need registering so we can inform the app
|
2007-08-29 01:16:15 -07:00
|
|
|
// not to do any extra startup checking next time round.
|
2007-03-22 10:30:00 -07:00
|
|
|
this._updateManifests(needsRestart);
|
|
|
|
|
2008-03-07 16:16:38 -08:00
|
|
|
// Remember the list of add-ons that were installed this time around
|
|
|
|
// unless this was a new profile.
|
|
|
|
if (!gFirstRun && newAddons.length > 0)
|
|
|
|
gPref.setCharPref(PREF_EM_NEW_ADDONS_LIST, newAddons.join(","));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
2007-12-11 16:56:09 -08:00
|
|
|
ERROR("ExtensionManager:_finishOperations - failure, catching exception - lineno: " +
|
|
|
|
e.lineNumber + " - file: " + e.fileName + " - " + e);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return needsRestart;
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Checks to see if there are items that are incompatible with this version
|
2007-08-29 01:16:15 -07:00
|
|
|
* of the application, disables them to prevent incompatibility problems and
|
2007-03-22 10:30:00 -07:00
|
|
|
* invokes the Update Wizard to look for newer versions.
|
|
|
|
* @returns true if there were incompatible items installed and disabled, and
|
|
|
|
* the application must now be restarted to reinitialize XPCOM,
|
|
|
|
* false otherwise.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
checkForMismatches: function EM_checkForMismatches() {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Check to see if the version of the application that is being started
|
2007-08-29 01:16:15 -07:00
|
|
|
// now is the same one that was started last time.
|
2007-03-22 10:30:00 -07:00
|
|
|
var currAppVersion = gApp.version;
|
|
|
|
var lastAppVersion = getPref("getCharPref", PREF_EM_LAST_APP_VERSION, "");
|
|
|
|
if (currAppVersion == lastAppVersion)
|
|
|
|
return false;
|
|
|
|
// With a new profile lastAppVersion doesn't exist yet.
|
|
|
|
if (!lastAppVersion) {
|
|
|
|
gPref.setCharPref(PREF_EM_LAST_APP_VERSION, currAppVersion);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-07-25 09:23:25 -07:00
|
|
|
// Block attempts to flush for the entire startup
|
|
|
|
gAllowFlush = false;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Make the extensions datasource consistent if it isn't already.
|
2009-01-06 03:04:41 -08:00
|
|
|
var isDirty;
|
|
|
|
[isDirty,] = this._ensureDatasetIntegrity();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (this._checkForFileChanges())
|
|
|
|
isDirty = true;
|
|
|
|
|
|
|
|
if (PendingOperations.size != 0)
|
|
|
|
isDirty = true;
|
|
|
|
|
2009-06-06 10:09:58 -07:00
|
|
|
var ds = this.datasource;
|
|
|
|
var inactiveItemIDs = [];
|
2010-02-05 10:21:37 -08:00
|
|
|
var appEnabledItemIDs = [];
|
2009-06-06 10:09:58 -07:00
|
|
|
var ctr = getContainer(ds, ds._itemRoot);
|
|
|
|
var elements = ctr.GetElements();
|
|
|
|
while (elements.hasMoreElements()) {
|
|
|
|
var itemResource = elements.getNext().QueryInterface(Ci.nsIRDFResource);
|
|
|
|
var id = stripPrefix(itemResource.Value, PREFIX_ITEM_URI);
|
|
|
|
var appDisabled = ds.getItemProperty(id, "appDisabled");
|
|
|
|
var userDisabled = ds.getItemProperty(id, "userDisabled")
|
|
|
|
if (appDisabled == "true" || appDisabled == OP_NEEDS_DISABLE ||
|
|
|
|
userDisabled == "true" || userDisabled == OP_NEEDS_DISABLE)
|
|
|
|
inactiveItemIDs.push(id);
|
2010-02-05 10:21:37 -08:00
|
|
|
if (appDisabled != "true" && appDisabled != OP_NEEDS_DISABLE)
|
|
|
|
appEnabledItemIDs.push(id);
|
2009-06-06 10:09:58 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (isDirty)
|
|
|
|
this._finishOperations();
|
|
|
|
|
|
|
|
// During app upgrade cleanup invalid entries in the extensions datasource.
|
|
|
|
ds.beginUpdateBatch();
|
|
|
|
var allResources = ds.GetAllResources();
|
|
|
|
while (allResources.hasMoreElements()) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var res = allResources.getNext().QueryInterface(Ci.nsIRDFResource);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (ds.GetTarget(res, EM_R("downloadURL"), true) ||
|
|
|
|
(!ds.GetTarget(res, EM_R("installLocation"), true) &&
|
|
|
|
stringData(ds.GetTarget(res, EM_R("appDisabled"), true)) == "true"))
|
|
|
|
ds.removeDownload(res.Value);
|
|
|
|
}
|
|
|
|
ds.endUpdateBatch();
|
|
|
|
|
2008-04-01 02:26:47 -07:00
|
|
|
var badItems = [];
|
2009-09-15 05:40:49 -07:00
|
|
|
var disabledAddons = [];
|
2007-03-22 10:30:00 -07:00
|
|
|
var allAppManaged = true;
|
2009-06-06 10:09:58 -07:00
|
|
|
elements = ctr.GetElements();
|
2007-03-22 10:30:00 -07:00
|
|
|
while (elements.hasMoreElements()) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var itemResource = elements.getNext().QueryInterface(Ci.nsIRDFResource);
|
2007-03-22 10:30:00 -07:00
|
|
|
var id = stripPrefix(itemResource.Value, PREFIX_ITEM_URI);
|
2008-04-01 02:26:47 -07:00
|
|
|
var location = this.getInstallLocation(id);
|
|
|
|
if (!location) {
|
|
|
|
// Item was in an unknown install location
|
|
|
|
badItems.push(id);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (ds.getItemProperty(id, "appManaged") == "true") {
|
|
|
|
// Force an update of the metadata for appManaged extensions since the
|
|
|
|
// last modified time is not updated for directories on FAT / FAT32
|
|
|
|
// filesystems when software update applies a new version of the app.
|
|
|
|
if (location.name == KEY_APP_GLOBAL) {
|
|
|
|
var installRDF = location.getItemFile(id, FILE_INSTALL_MANIFEST);
|
|
|
|
if (installRDF.exists()) {
|
|
|
|
var metadataDS = getInstallManifest(installRDF);
|
|
|
|
ds.addItemMetadata(id, metadataDS, location);
|
|
|
|
ds.updateProperty(id, "compatible");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (allAppManaged)
|
|
|
|
allAppManaged = false;
|
2007-09-03 14:44:12 -07:00
|
|
|
|
2008-07-25 09:23:25 -07:00
|
|
|
var properties = {
|
|
|
|
availableUpdateURL: null,
|
|
|
|
availableUpdateVersion: null
|
|
|
|
};
|
|
|
|
|
2007-09-03 14:44:12 -07:00
|
|
|
if (ds.getItemProperty(id, "providesUpdatesSecurely") == "false") {
|
|
|
|
/* It's possible the previous version did not understand updateKeys so
|
2008-10-01 23:49:45 -07:00
|
|
|
* check if we can import one for this addon from its manifest. */
|
2008-03-27 02:37:45 -07:00
|
|
|
installRDF = location.getItemFile(id, FILE_INSTALL_MANIFEST);
|
2007-09-03 14:44:12 -07:00
|
|
|
if (installRDF.exists()) {
|
2008-03-27 02:37:45 -07:00
|
|
|
metadataDS = getInstallManifest(installRDF);
|
2007-09-03 14:44:12 -07:00
|
|
|
var literal = metadataDS.GetTarget(gInstallManifestRoot, EM_R("updateKey"), true);
|
2007-09-03 20:07:11 -07:00
|
|
|
if (literal && literal instanceof Ci.nsIRDFLiteral)
|
2007-09-03 14:44:12 -07:00
|
|
|
ds.setItemProperty(id, EM_R("updateKey"), literal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// appDisabled is determined by an item being compatible, using secure
|
|
|
|
// updates, satisfying its dependencies, and not being blocklisted
|
2007-03-22 10:30:00 -07:00
|
|
|
if (this._isUsableItem(id)) {
|
|
|
|
if (ds.getItemProperty(id, "appDisabled"))
|
2008-07-25 09:23:25 -07:00
|
|
|
properties.appDisabled = null;
|
|
|
|
}
|
2010-02-05 10:21:37 -08:00
|
|
|
else {
|
|
|
|
if (!ds.getItemProperty(id, "appDisabled"))
|
|
|
|
properties.appDisabled = EM_L("true");
|
|
|
|
// If this item used to be app enabled then the upgrade has made it incompatible
|
|
|
|
if (appEnabledItemIDs.indexOf(id) >= 0)
|
|
|
|
disabledAddons.push(id);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-07-25 09:23:25 -07:00
|
|
|
ds.setItemProperties(id, properties);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-04-01 02:26:47 -07:00
|
|
|
|
|
|
|
// Must clean up outside of the loop. Modifying the container while
|
|
|
|
// iterating its contents is bad.
|
|
|
|
for (var i = 0; i < badItems.length; i++) {
|
|
|
|
id = badItems[i];
|
|
|
|
LOG("Item " + id + " was installed in an unknown location, removing.");
|
|
|
|
var disabled = ds.getItemProperty(id, "userDisabled") == "true";
|
|
|
|
// Clean up the datasource
|
|
|
|
ds.removeCorruptItem(id);
|
|
|
|
// Check for any unhidden items.
|
|
|
|
var entries = StartupCache.findEntries(id);
|
|
|
|
if (entries.length > 0) {
|
|
|
|
var newLocation = InstallLocations.get(entries[0].location);
|
|
|
|
for (var j = 1; j < entries.length; j++) {
|
|
|
|
location = InstallLocations.get(entries[j].location);
|
|
|
|
if (newLocation.priority < location.priority)
|
|
|
|
newLocation = location;
|
|
|
|
}
|
|
|
|
LOG("Activating item " + id + " in " + newLocation.name);
|
|
|
|
var em = this;
|
|
|
|
this.installItem(id, newLocation,
|
|
|
|
function(installManifest, id, location, type) {
|
|
|
|
em._configureForthcomingItem(installManifest, id, location,
|
|
|
|
type);
|
|
|
|
});
|
|
|
|
if (disabled)
|
|
|
|
em.disableItem(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Update the manifests to reflect the items that were disabled / enabled.
|
|
|
|
this._updateManifests(true);
|
|
|
|
|
2009-09-15 05:40:49 -07:00
|
|
|
// Determine if we should check for compatibility updates when upgrading if
|
|
|
|
// we have add-ons that aren't managed by the application.
|
2010-02-05 10:21:37 -08:00
|
|
|
if (!allAppManaged && !gFirstRun) {
|
2009-09-15 05:40:49 -07:00
|
|
|
// Should we show a UI or just pass the list via a pref?
|
|
|
|
if (getPref("getBoolPref", PREF_EM_SHOW_MISMATCH_UI, true)) {
|
|
|
|
this._showMismatchWindow(inactiveItemIDs);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Remember the list of add-ons that were disabled this time around
|
|
|
|
gPref.setCharPref(PREF_EM_DISABLED_ADDONS_LIST, disabledAddons.join(","));
|
|
|
|
}
|
2009-10-28 14:44:15 -07:00
|
|
|
} else if (gPref.prefHasUserValue(PREF_EM_DISABLED_ADDONS_LIST)) {
|
|
|
|
// Clear the disabled addons list if necessary
|
2009-09-15 05:40:49 -07:00
|
|
|
gPref.clearUserPref(PREF_EM_DISABLED_ADDONS_LIST);
|
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Finish any pending upgrades from the compatibility update to avoid an
|
|
|
|
// additional restart.
|
|
|
|
if (PendingOperations.size != 0)
|
|
|
|
this._finishOperations();
|
|
|
|
|
|
|
|
// Update the last app version so we don't do this again with this version.
|
|
|
|
gPref.setCharPref(PREF_EM_LAST_APP_VERSION, currAppVersion);
|
|
|
|
|
|
|
|
// Prevent extension update dialog from showing
|
|
|
|
gPref.setBoolPref(PREF_UPDATE_NOTIFYUSER, false);
|
2008-07-25 09:23:25 -07:00
|
|
|
|
|
|
|
// Re-enable flushing and flush anything that was deferred
|
|
|
|
try {
|
|
|
|
gAllowFlush = true;
|
|
|
|
if (gManifestNeedsFlush) {
|
|
|
|
gManifestNeedsFlush = false;
|
|
|
|
this._updateManifests(false);
|
|
|
|
}
|
|
|
|
if (gDSNeedsFlush) {
|
|
|
|
gDSNeedsFlush = false;
|
|
|
|
this.datasource.Flush();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
ERROR("Error flushing caches: " + e);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows the "Compatibility Updates" UI
|
2009-06-06 10:09:58 -07:00
|
|
|
* @param items
|
|
|
|
* an array of item IDs that were not enabled in the previous version
|
|
|
|
* of the application.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_showMismatchWindow: function EM__showMismatchWindow(items) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
|
|
|
|
getService(Ci.nsIWindowMediator);
|
2007-03-22 10:30:00 -07:00
|
|
|
var wizard = wm.getMostRecentWindow("Update:Wizard");
|
|
|
|
if (wizard)
|
|
|
|
wizard.focus();
|
|
|
|
else {
|
2009-06-06 10:09:58 -07:00
|
|
|
var variant = Cc["@mozilla.org/variant;1"].
|
|
|
|
createInstance(Ci.nsIWritableVariant);
|
|
|
|
variant.setFromVariant(items);
|
2007-03-22 10:30:00 -07:00
|
|
|
var features = "chrome,centerscreen,dialog,titlebar,modal";
|
|
|
|
// This *must* be modal so as not to break startup! This code is invoked before
|
|
|
|
// the main event loop is initiated (via checkForMismatches).
|
2007-09-03 20:07:11 -07:00
|
|
|
var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
|
|
|
|
getService(Ci.nsIWindowWatcher);
|
2009-06-06 10:09:58 -07:00
|
|
|
ww.openWindow(null, URI_EXTENSION_UPDATE_DIALOG, "", features, variant);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write the Extensions List and the Startup Cache
|
|
|
|
* @param needsRestart
|
|
|
|
* true if the application needs to restart again, false otherwise.
|
2007-08-29 01:16:15 -07:00
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_updateManifests: function EM__updateManifests(needsRestart) {
|
2008-07-25 09:23:25 -07:00
|
|
|
// During startup we block flushing until the startup operations are all
|
|
|
|
// complete to reduce file accesses that can trigger bug 431065
|
|
|
|
if (gAllowFlush) {
|
|
|
|
// Write the Startup Cache (All Items, visible or not)
|
|
|
|
StartupCache.write();
|
|
|
|
// Write the Extensions Locations Manifest (Visible, enabled items)
|
|
|
|
this._updateExtensionsManifest();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
gManifestNeedsFlush = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Notify nsAppRunner to update the compatibility manifest on next startup
|
|
|
|
this._extensionListChanged = needsRestart;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of items that are currently "active" (turned on) of a specific
|
|
|
|
* type
|
|
|
|
* @param type
|
|
|
|
* The nsIUpdateItem type to return a list of items of
|
|
|
|
* @returns An array of active items of the specified type.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_getActiveItems: function EM__getActiveItems(type) {
|
2009-11-07 00:21:07 -08:00
|
|
|
var allItems = this.getItemList(type);
|
2007-03-22 10:30:00 -07:00
|
|
|
var activeItems = [];
|
|
|
|
var ds = this.datasource;
|
|
|
|
for (var i = 0; i < allItems.length; ++i) {
|
|
|
|
var item = allItems[i];
|
|
|
|
|
2008-04-01 02:26:47 -07:00
|
|
|
var installLocation = this.getInstallLocation(item.id);
|
|
|
|
// An entry with an invalid install location is not active.
|
|
|
|
if (!installLocation)
|
|
|
|
continue;
|
2007-08-29 01:16:15 -07:00
|
|
|
// An item entry is valid only if it is not disabled, not about to
|
2007-03-22 10:30:00 -07:00
|
|
|
// be disabled, and not about to be uninstalled.
|
|
|
|
if (installLocation.name in StartupCache.entries &&
|
|
|
|
item.id in StartupCache.entries[installLocation.name] &&
|
|
|
|
StartupCache.entries[installLocation.name][item.id]) {
|
|
|
|
var op = StartupCache.entries[installLocation.name][item.id].op;
|
2007-08-29 01:16:15 -07:00
|
|
|
if (op == OP_NEEDS_INSTALL || op == OP_NEEDS_UPGRADE ||
|
2007-03-22 10:30:00 -07:00
|
|
|
op == OP_NEEDS_UNINSTALL || op == OP_NEEDS_DISABLE)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Suppress items that have been disabled by the user or the app.
|
|
|
|
if (ds.getItemProperty(item.id, "isDisabled") != "true")
|
2008-01-25 01:30:41 -08:00
|
|
|
activeItems.push({ id: item.id, version: item.version,
|
|
|
|
location: installLocation });
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return activeItems;
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Write the Extensions List
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_updateExtensionsManifest: function EM__updateExtensionsManifest() {
|
2007-03-22 10:30:00 -07:00
|
|
|
// When an operation is performed that requires a component re-registration
|
|
|
|
// (extension enabled/disabled, installed, uninstalled), we must write the
|
|
|
|
// set of paths where extensions live so that the startup system can determine
|
|
|
|
// where additional components, preferences, chrome manifests etc live.
|
|
|
|
//
|
2007-08-29 01:16:15 -07:00
|
|
|
// To do this we obtain a list of active extensions and themes and write
|
2007-03-22 10:30:00 -07:00
|
|
|
// these to the extensions.ini file in the profile directory.
|
2008-03-06 18:02:49 -08:00
|
|
|
var validExtensions = this._getActiveItems(Ci.nsIUpdateItem.TYPE_ANY -
|
|
|
|
Ci.nsIUpdateItem.TYPE_THEME);
|
2007-09-17 11:05:04 -07:00
|
|
|
var validThemes = this._getActiveItems(Ci.nsIUpdateItem.TYPE_THEME);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-10-23 12:42:48 -07:00
|
|
|
var extensionsLocationsFile = FileUtils.getFile(KEY_PROFILEDIR,
|
|
|
|
[FILE_EXTENSION_MANIFEST]);
|
|
|
|
var fos = FileUtils.openSafeFileOutputStream(extensionsLocationsFile);
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2008-01-25 01:30:41 -08:00
|
|
|
var enabledItems = [];
|
2007-03-22 10:30:00 -07:00
|
|
|
var extensionSectionHeader = "[ExtensionDirs]\r\n";
|
|
|
|
fos.write(extensionSectionHeader, extensionSectionHeader.length);
|
|
|
|
for (var i = 0; i < validExtensions.length; ++i) {
|
|
|
|
var e = validExtensions[i];
|
2007-09-17 11:05:04 -07:00
|
|
|
var itemLocation = e.location.getItemLocation(e.id).QueryInterface(Ci.nsILocalFile);
|
2007-03-22 10:30:00 -07:00
|
|
|
var descriptor = getAbsoluteDescriptor(itemLocation);
|
|
|
|
var line = "Extension" + i + "=" + descriptor + "\r\n";
|
|
|
|
fos.write(line, line.length);
|
2008-01-25 01:30:41 -08:00
|
|
|
enabledItems.push(e.id + ":" + e.version);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
var themeSectionHeader = "[ThemeDirs]\r\n";
|
|
|
|
fos.write(themeSectionHeader, themeSectionHeader.length);
|
|
|
|
for (i = 0; i < validThemes.length; ++i) {
|
|
|
|
var e = validThemes[i];
|
2007-09-17 11:05:04 -07:00
|
|
|
var itemLocation = e.location.getItemLocation(e.id).QueryInterface(Ci.nsILocalFile);
|
2007-03-22 10:30:00 -07:00
|
|
|
var descriptor = getAbsoluteDescriptor(itemLocation);
|
|
|
|
var line = "Extension" + i + "=" + descriptor + "\r\n";
|
|
|
|
fos.write(line, line.length);
|
2008-01-25 01:30:41 -08:00
|
|
|
enabledItems.push(e.id + ":" + e.version);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-10-23 12:42:48 -07:00
|
|
|
FileUtils.closeSafeFileOutputStream(fos);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-01-25 01:30:41 -08:00
|
|
|
// Cache the enabled list for annotating the crash report subsequently
|
|
|
|
gPref.setCharPref(PREF_EM_ENABLED_ITEMS, enabledItems.join(","));
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Say whether or not the Extension List has changed (and thus whether or not
|
|
|
|
* the system will have to restart the next time it is started).
|
|
|
|
* @param val
|
|
|
|
* true if the Extension List has changed, false otherwise.
|
|
|
|
* @returns |val|
|
|
|
|
*/
|
|
|
|
set _extensionListChanged(val) {
|
|
|
|
// When an extension has an operation perform on it (e.g. install, upgrade,
|
2009-10-15 23:32:29 -07:00
|
|
|
// disable, etc.) we are responsible for writing this information to
|
|
|
|
// compatibility.ini, and nsAppRunner is responsible for checking this on
|
|
|
|
// restart. At some point it may make sense to be able to cancel a
|
|
|
|
// registration but for now we only create the file.
|
|
|
|
if (val) {
|
|
|
|
let XRE = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime);
|
|
|
|
XRE.invalidateCachesOnRestart();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return val;
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Gathers data about an item specified by the supplied Install Manifest
|
2007-08-29 01:16:15 -07:00
|
|
|
* and determines whether or not it can be installed as-is. It makes this
|
|
|
|
* determination by validating the item's GUID, Version, and determining
|
2007-03-22 10:30:00 -07:00
|
|
|
* if it is compatible with this application.
|
2007-08-29 01:16:15 -07:00
|
|
|
* @param installManifest
|
|
|
|
* A nsIRDFDataSource representing the Install Manifest of the
|
2007-03-22 10:30:00 -07:00
|
|
|
* item to be installed.
|
|
|
|
* @return A JS Object with the following properties:
|
|
|
|
* "id" The GUID of the Item being installed.
|
|
|
|
* "version" The Version string of the Item being installed.
|
|
|
|
* "name" The Name of the Item being installed.
|
|
|
|
* "type" The nsIUpdateItem type of the Item being installed.
|
|
|
|
* "targetApps" An array of TargetApplication Info Objects
|
|
|
|
* with "id", "minVersion" and "maxVersion" properties,
|
|
|
|
* representing applications targeted by this item.
|
|
|
|
* "error" The result code:
|
2007-08-29 01:16:15 -07:00
|
|
|
* INSTALLERROR_SUCCESS
|
2007-03-22 10:30:00 -07:00
|
|
|
* no error, item can be installed
|
2007-08-29 01:16:15 -07:00
|
|
|
* INSTALLERROR_INVALID_GUID
|
2007-03-22 10:30:00 -07:00
|
|
|
* error, GUID is not well-formed
|
|
|
|
* INSTALLERROR_INVALID_VERSION
|
|
|
|
* error, Version is not well-formed
|
|
|
|
* INSTALLERROR_INCOMPATIBLE_VERSION
|
|
|
|
* error, item is not compatible with this version
|
|
|
|
* of the application.
|
|
|
|
* INSTALLERROR_INCOMPATIBLE_PLATFORM
|
|
|
|
* error, item is not compatible with the operating
|
|
|
|
* system or ABI the application was built for.
|
2007-09-03 14:44:12 -07:00
|
|
|
* INSTALLERROR_INSECURE_UPDATE
|
|
|
|
* error, item has no secure method of providing updates
|
2007-03-22 10:30:00 -07:00
|
|
|
* INSTALLERROR_BLOCKLISTED
|
|
|
|
* error, item is blocklisted
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_getInstallData: function EM__getInstallData(installManifest) {
|
2007-08-29 01:16:15 -07:00
|
|
|
var installData = { id : "",
|
|
|
|
version : "",
|
|
|
|
name : "",
|
|
|
|
type : 0,
|
|
|
|
error : INSTALLERROR_SUCCESS,
|
2007-03-22 10:30:00 -07:00
|
|
|
targetApps : [],
|
2007-09-03 14:44:12 -07:00
|
|
|
updateURL : "",
|
|
|
|
updateKey : "",
|
2007-03-22 10:30:00 -07:00
|
|
|
currentApp : null };
|
|
|
|
|
|
|
|
// Fetch properties from the Install Manifest
|
|
|
|
installData.id = getManifestProperty(installManifest, "id");
|
|
|
|
installData.version = getManifestProperty(installManifest, "version");
|
|
|
|
installData.name = getManifestProperty(installManifest, "name");
|
|
|
|
installData.type = getAddonTypeFromInstallManifest(installManifest);
|
|
|
|
installData.updateURL= getManifestProperty(installManifest, "updateURL");
|
2007-09-03 14:44:12 -07:00
|
|
|
installData.updateKey= getManifestProperty(installManifest, "updateKey");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads a property off a Target Application resource
|
|
|
|
* @param resource
|
|
|
|
* The RDF Resource for a Target Application
|
|
|
|
* @param property
|
|
|
|
* The property (less EM_NS) to read
|
|
|
|
* @returns The string literal value of the property.
|
|
|
|
*/
|
|
|
|
function readTAProperty(resource, property) {
|
|
|
|
return stringData(installManifest.GetTarget(resource, EM_R(property), true));
|
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
|
|
|
|
var targetApps = installManifest.GetTargets(gInstallManifestRoot,
|
|
|
|
EM_R("targetApplication"),
|
2007-03-22 10:30:00 -07:00
|
|
|
true);
|
|
|
|
while (targetApps.hasMoreElements()) {
|
|
|
|
var targetApp = targetApps.getNext();
|
2007-09-03 20:07:11 -07:00
|
|
|
if (targetApp instanceof Ci.nsIRDFResource) {
|
2007-03-22 10:30:00 -07:00
|
|
|
try {
|
|
|
|
var data = { id : readTAProperty(targetApp, "id"),
|
|
|
|
minVersion: readTAProperty(targetApp, "minVersion"),
|
|
|
|
maxVersion: readTAProperty(targetApp, "maxVersion") };
|
|
|
|
installData.targetApps.push(data);
|
2007-08-29 01:16:15 -07:00
|
|
|
if ((data.id == gApp.ID) ||
|
|
|
|
(data.id == TOOLKIT_ID) && !installData.currentApp)
|
2007-03-22 10:30:00 -07:00
|
|
|
installData.currentApp = data;
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the item specifies one or more target platforms, make sure our OS/ABI
|
|
|
|
// combination is in the list - otherwise, refuse to install the item.
|
|
|
|
var targetPlatforms = null;
|
|
|
|
try {
|
2007-08-29 01:16:15 -07:00
|
|
|
targetPlatforms = installManifest.GetTargets(gInstallManifestRoot,
|
|
|
|
EM_R("targetPlatform"),
|
2007-03-22 10:30:00 -07:00
|
|
|
true);
|
|
|
|
} catch(e) {
|
|
|
|
// No targetPlatform nodes, continue.
|
|
|
|
}
|
|
|
|
if (targetPlatforms != null && targetPlatforms.hasMoreElements()) {
|
|
|
|
var foundMatchingOS = false;
|
|
|
|
var foundMatchingOSAndABI = false;
|
|
|
|
var requireABICompatibility = false;
|
|
|
|
while (targetPlatforms.hasMoreElements()) {
|
|
|
|
var targetPlatform = stringData(targetPlatforms.getNext());
|
|
|
|
var os = targetPlatform.split("_")[0];
|
|
|
|
var index = targetPlatform.indexOf("_");
|
|
|
|
var abi = index != -1 ? targetPlatform.substr(index + 1) : null;
|
|
|
|
if (os == gOSTarget) {
|
|
|
|
foundMatchingOS = true;
|
|
|
|
// The presence of any ABI part after our OS means ABI is important.
|
|
|
|
if (abi != null) {
|
|
|
|
requireABICompatibility = true;
|
|
|
|
// If we don't know our ABI, we can't be compatible
|
|
|
|
if (abi == gXPCOMABI && abi != UNKNOWN_XPCOM_ABI) {
|
|
|
|
foundMatchingOSAndABI = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!foundMatchingOS || (requireABICompatibility && !foundMatchingOSAndABI)) {
|
|
|
|
installData.error = INSTALLERROR_INCOMPATIBLE_PLATFORM;
|
|
|
|
return installData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate the Item ID
|
|
|
|
if (!gIDTest.test(installData.id)) {
|
|
|
|
installData.error = INSTALLERROR_INVALID_GUID;
|
|
|
|
return installData;
|
|
|
|
}
|
2007-09-03 14:44:12 -07:00
|
|
|
|
|
|
|
// Check that the add-on provides a secure update method.
|
|
|
|
if (gCheckUpdateSecurity &&
|
|
|
|
installData.updateURL &&
|
|
|
|
installData.updateURL.substring(0, 6) != "https:" &&
|
|
|
|
!installData.updateKey) {
|
|
|
|
installData.error = INSTALLERROR_INSECURE_UPDATE;
|
|
|
|
return installData;
|
|
|
|
}
|
2009-08-06 07:24:52 -07:00
|
|
|
|
|
|
|
// Check that the item is compatible with the application.
|
|
|
|
if (!this.datasource.isCompatible(installManifest, gInstallManifestRoot, false)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
installData.error = INSTALLERROR_INCOMPATIBLE_VERSION;
|
2007-09-03 14:44:12 -07:00
|
|
|
return installData;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Check if the item is blocklisted.
|
2007-08-15 17:43:12 -07:00
|
|
|
if (!gBlocklist)
|
2007-09-03 20:07:11 -07:00
|
|
|
gBlocklist = Cc["@mozilla.org/extensions/blocklist;1"].
|
|
|
|
getService(Ci.nsIBlocklistService);
|
2008-11-02 04:13:48 -08:00
|
|
|
var state = gBlocklist.getAddonBlocklistState(installData.id, installData.version);
|
|
|
|
if (state == Ci.nsIBlocklistService.STATE_BLOCKED)
|
2007-03-22 10:30:00 -07:00
|
|
|
installData.error = INSTALLERROR_BLOCKLISTED;
|
2008-11-02 04:13:48 -08:00
|
|
|
else if (state == Ci.nsIBlocklistService.STATE_SOFTBLOCKED)
|
|
|
|
installData.error = INSTALLERROR_SOFTBLOCKED;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return installData;
|
2007-08-29 01:16:15 -07:00
|
|
|
},
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
2007-08-29 01:16:15 -07:00
|
|
|
* Installs an item from a XPI/JAR file.
|
2007-03-22 10:30:00 -07:00
|
|
|
* This is the main entry point into the Install system from outside code
|
|
|
|
* (e.g. XPInstall).
|
|
|
|
* @param aXPIFile
|
|
|
|
* The file to install from.
|
|
|
|
* @param aInstallLocationKey
|
2007-08-29 01:16:15 -07:00
|
|
|
* The name of the Install Location where this item should be
|
2007-03-22 10:30:00 -07:00
|
|
|
* installed.
|
2007-08-29 01:16:15 -07:00
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
installItemFromFile: function EM_installItemFromFile(xpiFile, installLocationKey) {
|
2007-03-22 10:30:00 -07:00
|
|
|
this.installItemFromFileInternal(xpiFile, installLocationKey, null);
|
2008-03-14 16:34:32 -07:00
|
|
|
|
|
|
|
// If there are no compatibility checks running and no downloads in
|
|
|
|
// progress then the install operations are complete.
|
2009-01-30 02:07:28 -08:00
|
|
|
if (this._compatibilityCheckCount == 0 && this._transactions.length == 0)
|
|
|
|
this._callInstallListeners("onInstallsCompleted");
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Installs an item from a XPI/JAR file.
|
|
|
|
* @param aXPIFile
|
|
|
|
* The file to install from.
|
|
|
|
* @param aInstallLocationKey
|
2007-08-29 01:16:15 -07:00
|
|
|
* The name of the Install Location where this item should be
|
2007-03-22 10:30:00 -07:00
|
|
|
* installed.
|
|
|
|
* @param aInstallManifest
|
|
|
|
* An updated Install Manifest from the Version Update check.
|
|
|
|
* Can be null when invoked from callers other than the Version
|
|
|
|
* Update check.
|
2008-11-26 07:04:13 -08:00
|
|
|
* @returns The install result code. If this is INSTALLERROR_PHONING_HOME
|
|
|
|
* then a remote update check has been started to attempt to resolve
|
|
|
|
* compatibility problems.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
installItemFromFileInternal: function EM_installItemFromFileInternal(aXPIFile,
|
|
|
|
aInstallLocationKey,
|
|
|
|
aInstallManifest) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var em = this;
|
|
|
|
/**
|
|
|
|
* Gets the Install Location for an Item.
|
2007-08-29 01:16:15 -07:00
|
|
|
* @param itemID
|
2007-03-22 10:30:00 -07:00
|
|
|
* The GUID of the item to find an Install Location for.
|
2007-08-29 01:16:15 -07:00
|
|
|
* @return An object implementing nsIInstallLocation which represents the
|
|
|
|
* location where the specified item should be installed.
|
2007-03-22 10:30:00 -07:00
|
|
|
* This can be:
|
|
|
|
* 1. an object that corresponds to the location key supplied to
|
|
|
|
* |installItemFromFileInternal|,
|
|
|
|
* 2. the default install location (the App Profile Extensions Folder)
|
|
|
|
* if no location key was supplied, or the location key supplied
|
|
|
|
* was not in the set of registered locations
|
|
|
|
* 3. null, if the location selected by 1 or 2 above does not support
|
2007-08-29 01:16:15 -07:00
|
|
|
* installs from XPI/JAR files, or that location is not writable
|
2007-03-22 10:30:00 -07:00
|
|
|
* with the current access privileges.
|
|
|
|
*/
|
|
|
|
function getInstallLocation(itemID) {
|
|
|
|
// Here I use "upgrade" to mean "install a different version of an item".
|
|
|
|
var installLocation = em.getInstallLocation(itemID);
|
|
|
|
if (!installLocation) {
|
|
|
|
// This is not an "upgrade", since we don't have any location data for the
|
|
|
|
// extension ID specified - that is, it's not in our database.
|
|
|
|
|
|
|
|
// Caller supplied a key to a registered location, use that location
|
|
|
|
// for the installation
|
|
|
|
installLocation = InstallLocations.get(aInstallLocationKey);
|
|
|
|
if (installLocation) {
|
|
|
|
// If the specified location does not have a common metadata location
|
|
|
|
// (e.g. extensions have no common root, or other location specified
|
|
|
|
// by the location implementation) - e.g. for a Registry Key enumeration
|
|
|
|
// location - we cannot install or upgrade using a XPI file, probably
|
|
|
|
// because these application types will be handling upgrading themselves.
|
|
|
|
// Just bail.
|
|
|
|
if (!installLocation.location) {
|
2007-08-29 01:16:15 -07:00
|
|
|
LOG("Install Location \"" + installLocation.name + "\" does not support " +
|
|
|
|
"installation of items from XPI/JAR files. You must manage " +
|
2007-03-22 10:30:00 -07:00
|
|
|
"installation and update of these items yourself.");
|
|
|
|
installLocation = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// In the absence of a preferred install location, just default to
|
2007-08-29 01:16:15 -07:00
|
|
|
// the App-Profile
|
2007-03-22 10:30:00 -07:00
|
|
|
installLocation = InstallLocations.get(KEY_APP_PROFILE);
|
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
else {
|
|
|
|
// This is an "upgrade", but not through the Update System, because the
|
|
|
|
// Update code will not let an extension with an incompatible target
|
|
|
|
// app version range through to this point. This is an "upgrade" in the
|
|
|
|
// sense that the user found a different version of an installed extension
|
|
|
|
// and installed it through the web interface, so we have metadata.
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// If the location is different, return the preferred location rather than
|
|
|
|
// the location of the currently installed version, because we may be in
|
2007-08-29 01:16:15 -07:00
|
|
|
// the situation where an item is being installed into the global app
|
2007-03-22 10:30:00 -07:00
|
|
|
// dir when there's a version in the profile dir.
|
2007-08-29 01:16:15 -07:00
|
|
|
if (installLocation.name != aInstallLocationKey)
|
2007-03-22 10:30:00 -07:00
|
|
|
installLocation = InstallLocations.get(aInstallLocationKey);
|
|
|
|
}
|
|
|
|
if (!installLocation.canAccess) {
|
|
|
|
LOG("Install Location\"" + installLocation.name + "\" cannot be written " +
|
|
|
|
"to with your access privileges. Installation will not proceed.");
|
|
|
|
installLocation = null;
|
|
|
|
}
|
|
|
|
return installLocation;
|
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
2007-08-29 01:16:15 -07:00
|
|
|
* Stages a XPI file in the default item location specified by other
|
2007-03-22 10:30:00 -07:00
|
|
|
* applications when they registered with XulRunner if the item's
|
|
|
|
* install manifest specified compatibility with them.
|
|
|
|
*/
|
|
|
|
function stageXPIForOtherApps(xpiFile, installData) {
|
|
|
|
for (var i = 0; i < installData.targetApps.length; ++i) {
|
|
|
|
var targetApp = installData.targetApps[i];
|
2007-08-29 01:16:15 -07:00
|
|
|
if (targetApp.id != gApp.ID && targetApp.id != TOOLKIT_ID) {
|
2007-03-22 10:30:00 -07:00
|
|
|
/* XXXben uncomment when this works!
|
2007-09-03 20:07:11 -07:00
|
|
|
var settingsThingy = Cc[].
|
|
|
|
getService(Ci.nsIXULRunnerSettingsThingy);
|
2007-03-22 10:30:00 -07:00
|
|
|
try {
|
|
|
|
var appPrefix = "SOFTWARE\\Mozilla\\XULRunner\\Applications\\";
|
|
|
|
var branch = settingsThingy.getBranch(appPrefix + targetApp.id);
|
|
|
|
var path = branch.getProperty("ExtensionsLocation");
|
2007-09-03 20:07:11 -07:00
|
|
|
var destination = Cc["@mozilla.org/file/local;1"].
|
2007-09-17 11:05:04 -07:00
|
|
|
createInstance(Ci.nsILocalFile);
|
2007-03-22 10:30:00 -07:00
|
|
|
destination.initWithPath(path);
|
|
|
|
xpiFile.copyTo(file, xpiFile.leafName);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
}
|
|
|
|
*/
|
2007-08-29 01:16:15 -07:00
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Extracts and then starts the install for extensions / themes contained
|
|
|
|
* within a xpi.
|
|
|
|
*/
|
|
|
|
function installMultiXPI(xpiFile, installData) {
|
2007-09-17 11:05:04 -07:00
|
|
|
var fileURL = getURIFromFile(xpiFile).QueryInterface(Ci.nsIURL);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (fileURL.fileExtension.toLowerCase() != "xpi") {
|
2007-08-29 01:16:15 -07:00
|
|
|
LOG("Invalid File Extension: Item: \"" + fileURL.fileName + "\" has an " +
|
2007-03-22 10:30:00 -07:00
|
|
|
"invalid file extension. Only xpi file extensions are allowed for " +
|
|
|
|
"multiple item packages.");
|
|
|
|
var bundle = BundleManager.getBundle(URI_EXTENSIONS_PROPERTIES);
|
2007-08-29 01:16:15 -07:00
|
|
|
showMessage("invalidFileExtTitle", [],
|
2007-03-22 10:30:00 -07:00
|
|
|
"invalidFileExtMessage", [installData.name,
|
|
|
|
fileURL.fileExtension,
|
|
|
|
bundle.GetStringFromName("type-" + installData.type)]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
var zipReader = getZipReaderForFile(xpiFile);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
LOG("installMultiXPI: failed to open xpi file: " + xpiFile.path);
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
|
|
|
|
var searchForEntries = ["*.xpi", "*.jar"];
|
|
|
|
var files = [];
|
|
|
|
for (var i = 0; i < searchForEntries.length; ++i) {
|
|
|
|
var entries = zipReader.findEntries(searchForEntries[i]);
|
|
|
|
while (entries.hasMore()) {
|
|
|
|
var entryName = entries.getNext();
|
2009-10-23 12:42:48 -07:00
|
|
|
var target = FileUtils.getFile(KEY_TEMPDIR, [entryName]);
|
2007-03-22 10:30:00 -07:00
|
|
|
try {
|
2009-10-23 12:42:48 -07:00
|
|
|
target.createUnique(Ci.nsILocalFile.NORMAL_FILE_TYPE,
|
|
|
|
FileUtils.PERMS_FILE);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
LOG("installMultiXPI: failed to create target file for extraction " +
|
|
|
|
" file = " + target.path + ", exception = " + e + "\n");
|
|
|
|
}
|
|
|
|
zipReader.extract(entryName, target);
|
|
|
|
files.push(target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
zipReader.close();
|
|
|
|
|
|
|
|
if (files.length == 0) {
|
|
|
|
LOG("Multiple Item Package: Item: \"" + fileURL.fileName + "\" does " +
|
|
|
|
"not contain a valid package to install.");
|
|
|
|
var bundle = BundleManager.getBundle(URI_EXTENSIONS_PROPERTIES);
|
|
|
|
showMessage("missingPackageFilesTitle",
|
|
|
|
[bundle.GetStringFromName("type-" + installData.type)],
|
|
|
|
"missingPackageFilesMessage", [installData.name,
|
|
|
|
bundle.GetStringFromName("type-" + installData.type)]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < files.length; ++i) {
|
|
|
|
em.installItemFromFileInternal(files[i], aInstallLocationKey, null);
|
|
|
|
files[i].remove(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An observer for the Extension Update System.
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
function IncompatibleObserver() {}
|
|
|
|
IncompatibleObserver.prototype = {
|
|
|
|
_xpi: null,
|
|
|
|
_installManifest: null,
|
2007-08-29 01:16:15 -07:00
|
|
|
|
|
|
|
/**
|
2007-03-22 10:30:00 -07:00
|
|
|
* Ask the Extension Update System if there are any version updates for
|
2007-08-29 01:16:15 -07:00
|
|
|
* this item that will allow it to be compatible with this version of
|
2007-03-22 10:30:00 -07:00
|
|
|
* the Application.
|
2008-03-14 16:34:32 -07:00
|
|
|
* @param item
|
|
|
|
* An nsIUpdateItem representing the item being installed.
|
2007-08-29 01:16:15 -07:00
|
|
|
* @param installManifest
|
2007-03-22 10:30:00 -07:00
|
|
|
* The Install Manifest datasource for the item.
|
2007-08-29 01:16:15 -07:00
|
|
|
* @param xpiFile
|
|
|
|
* The staged source XPI file that contains the item. Cleaned
|
2007-03-22 10:30:00 -07:00
|
|
|
* up by this process.
|
2008-03-14 16:34:32 -07:00
|
|
|
* @param installRDF
|
|
|
|
* The install.rdf file that was extracted from the xpi.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2008-11-02 04:13:48 -08:00
|
|
|
checkForUpdates: function IncObs_checkForUpdates(item, installManifest, xpiFile) {
|
2007-03-22 10:30:00 -07:00
|
|
|
this._xpi = xpiFile;
|
|
|
|
this._installManifest = installManifest;
|
2008-03-14 16:34:32 -07:00
|
|
|
|
2009-01-30 02:07:28 -08:00
|
|
|
em._callInstallListeners("onCompatibilityCheckStarted", item);
|
2008-03-14 16:34:32 -07:00
|
|
|
em._compatibilityCheckCount++;
|
2009-09-10 11:50:41 -07:00
|
|
|
var updater = new ExtensionItemUpdater(em);
|
|
|
|
updater.checkForUpdates([item], 1,
|
|
|
|
Ci.nsIExtensionManager.UPDATE_CHECK_COMPATIBILITY,
|
|
|
|
this, UPDATE_WHEN_ADDON_INSTALLED);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* See nsIExtensionManager.idl
|
|
|
|
*/
|
2008-11-02 04:13:48 -08:00
|
|
|
onUpdateStarted: function IncObs_onUpdateStarted() {
|
2007-03-22 10:30:00 -07:00
|
|
|
LOG("Phone Home Listener: Update Started");
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* See nsIExtensionManager.idl
|
|
|
|
*/
|
2008-11-02 04:13:48 -08:00
|
|
|
onUpdateEnded: function IncObs_onUpdateEnded() {
|
2007-03-22 10:30:00 -07:00
|
|
|
LOG("Phone Home Listener: Update Ended");
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* See nsIExtensionManager.idl
|
|
|
|
*/
|
2008-11-02 04:13:48 -08:00
|
|
|
onAddonUpdateStarted: function IncObs_onAddonUpdateStarted(addon) {
|
2007-08-29 01:16:15 -07:00
|
|
|
if (!addon)
|
2007-09-03 20:07:11 -07:00
|
|
|
throw Cr.NS_ERROR_INVALID_ARG;
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
LOG("Phone Home Listener: Update For " + addon.id + " started");
|
|
|
|
em.datasource.addIncompatibleUpdateItem(addon.name, this._xpi.path,
|
|
|
|
addon.type, addon.version);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* See nsIExtensionManager.idl
|
|
|
|
*/
|
2008-11-02 04:13:48 -08:00
|
|
|
onAddonUpdateEnded: function IncObs_onAddonUpdateEnded(addon, status) {
|
2007-08-29 01:16:15 -07:00
|
|
|
if (!addon)
|
2007-09-03 20:07:11 -07:00
|
|
|
throw Cr.NS_ERROR_INVALID_ARG;
|
2007-08-29 01:16:15 -07:00
|
|
|
|
|
|
|
LOG("Phone Home Listener: Update For " + addon.id + " ended, status = " + status);
|
2007-03-22 10:30:00 -07:00
|
|
|
em.datasource.removeDownload(this._xpi.path);
|
|
|
|
LOG("Version Check Phone Home Completed");
|
2008-03-14 16:34:32 -07:00
|
|
|
|
2009-01-30 02:07:28 -08:00
|
|
|
em._callInstallListeners("onCompatibilityCheckEnded", addon, status);
|
2008-03-14 16:34:32 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Only compatibility updates (e.g. STATUS_VERSIONINFO) are currently
|
|
|
|
// supported
|
2007-09-17 11:05:04 -07:00
|
|
|
if (status == Ci.nsIAddonUpdateCheckListener.STATUS_VERSIONINFO) {
|
2007-08-29 01:16:15 -07:00
|
|
|
em.datasource.setTargetApplicationInfo(addon.id,
|
|
|
|
addon.targetAppID,
|
2007-03-22 10:30:00 -07:00
|
|
|
addon.minAppVersion,
|
2007-08-29 01:16:15 -07:00
|
|
|
addon.maxAppVersion,
|
2007-03-22 10:30:00 -07:00
|
|
|
this._installManifest);
|
|
|
|
|
2008-03-14 16:34:32 -07:00
|
|
|
// Try and install again, but use the updated compatibility DB.
|
|
|
|
// This will send out an apropriate onInstallEnded notification for us.
|
2008-11-26 07:04:13 -08:00
|
|
|
var status = em.installItemFromFileInternal(this._xpi,
|
|
|
|
aInstallLocationKey,
|
|
|
|
this._installManifest);
|
|
|
|
|
|
|
|
// The install may still have failed at this point due to the blocklist
|
|
|
|
if (status == INSTALLERROR_SUCCESS) {
|
|
|
|
// Add the updated compatibility info to the datasource if done
|
|
|
|
if (StartupCache.entries[aInstallLocationKey][addon.id].op == OP_NONE) {
|
|
|
|
em.datasource.setTargetApplicationInfo(addon.id,
|
|
|
|
addon.targetAppID,
|
|
|
|
addon.minAppVersion,
|
|
|
|
addon.maxAppVersion,
|
|
|
|
null);
|
|
|
|
}
|
|
|
|
else { // needs a restart
|
|
|
|
// Add updatedMinVersion and updatedMaxVersion so it can be used
|
|
|
|
// to update the datasource during the installation or upgrade.
|
|
|
|
em.datasource.setUpdatedTargetAppInfo(addon.id,
|
|
|
|
addon.targetAppID,
|
|
|
|
addon.minAppVersion,
|
|
|
|
addon.maxAppVersion,
|
|
|
|
null);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
em.datasource.removeDownload(this._xpi.path);
|
|
|
|
showIncompatibleError(installData);
|
2008-03-14 16:34:32 -07:00
|
|
|
LOG("Add-on " + addon.id + " is incompatible with " +
|
2007-09-04 13:59:05 -07:00
|
|
|
BundleManager.appName + " " + gApp.version + ", Toolkit " +
|
|
|
|
gApp.platformVersion + ". Remote compatibility check did not " +
|
|
|
|
"resolve this.");
|
2009-01-30 02:07:28 -08:00
|
|
|
|
|
|
|
em._callInstallListeners("onInstallEnded", addon, INSTALLERROR_INCOMPATIBLE_VERSION);
|
2008-03-14 16:34:32 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// We are responsible for cleaning up this file!
|
|
|
|
InstallLocations.get(aInstallLocationKey).removeFile(this._xpi);
|
|
|
|
}
|
2008-03-14 16:34:32 -07:00
|
|
|
|
|
|
|
em._compatibilityCheckCount--;
|
|
|
|
// If there are no more compatibility checks running and no downloads in
|
|
|
|
// progress then the install operations are complete.
|
2009-01-30 02:07:28 -08:00
|
|
|
if (em._compatibilityCheckCount == 0 && em._transactions.length == 0)
|
|
|
|
em._callInstallListeners("onInstallsCompleted");
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2007-09-03 20:07:11 -07:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIAddonUpdateCheckListener])
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
var shouldPhoneHomeIfNecessary = false;
|
|
|
|
if (!aInstallManifest) {
|
2007-08-29 01:16:15 -07:00
|
|
|
// If we were not called with an Install Manifest, we were called from
|
2007-03-22 10:30:00 -07:00
|
|
|
// some other path than the Phone Home system, so we do want to phone
|
2008-03-14 16:34:32 -07:00
|
|
|
// home if the version is incompatible. As this is the first point in the
|
|
|
|
// install process we must notify observers here.
|
|
|
|
|
|
|
|
var addon = makeItem(getURIFromFile(aXPIFile).spec, "",
|
|
|
|
aInstallLocationKey, "", "", "",
|
|
|
|
getURIFromFile(aXPIFile).spec,
|
2009-06-12 05:50:08 -07:00
|
|
|
"", "", "", "", 0, gApp.ID);
|
2009-01-30 02:07:28 -08:00
|
|
|
this._callInstallListeners("onInstallStarted", addon);
|
2008-03-14 16:34:32 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
shouldPhoneHomeIfNecessary = true;
|
2008-04-11 02:44:41 -07:00
|
|
|
var installManifest = null;
|
2008-03-14 16:34:32 -07:00
|
|
|
var installManifestFile = extractRDFFileToTempDir(aXPIFile,
|
|
|
|
FILE_INSTALL_MANIFEST,
|
|
|
|
true);
|
2008-04-11 02:44:41 -07:00
|
|
|
if (installManifestFile.exists()) {
|
|
|
|
installManifest = getInstallManifest(installManifestFile);
|
|
|
|
installManifestFile.remove(false);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!installManifest) {
|
2007-08-29 01:16:15 -07:00
|
|
|
LOG("The Install Manifest supplied by this item is not well-formed. " +
|
2007-03-22 10:30:00 -07:00
|
|
|
"Installation will not proceed.");
|
2009-01-30 02:07:28 -08:00
|
|
|
this._callInstallListeners("onInstallEnded", addon, INSTALLERROR_INVALID_MANIFEST);
|
2008-11-26 07:04:13 -08:00
|
|
|
return INSTALLERROR_INVALID_MANIFEST;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
installManifest = aInstallManifest;
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var installData = this._getInstallData(installManifest);
|
2008-03-14 16:34:32 -07:00
|
|
|
// Recreate the add-on item with the full detail from the install manifest
|
|
|
|
addon = makeItem(installData.id, installData.version,
|
|
|
|
aInstallLocationKey,
|
2008-04-11 02:44:41 -07:00
|
|
|
installData.currentApp ? installData.currentApp.minVersion : "",
|
|
|
|
installData.currentApp ? installData.currentApp.maxVersion : "",
|
2008-03-14 16:34:32 -07:00
|
|
|
installData.name,
|
|
|
|
getURIFromFile(aXPIFile).spec,
|
|
|
|
"", /* XPI Update Hash */
|
|
|
|
"", /* Icon URL */
|
|
|
|
installData.updateURL || "",
|
|
|
|
installData.updateKey || "",
|
|
|
|
installData.type,
|
2008-04-11 02:44:41 -07:00
|
|
|
installData.currentApp ? installData.currentApp.id : "");
|
2008-03-14 16:34:32 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
switch (installData.error) {
|
|
|
|
case INSTALLERROR_INCOMPATIBLE_VERSION:
|
|
|
|
// Since the caller cleans up |aXPIFile|, and we're not yet sure whether or
|
2007-08-29 01:16:15 -07:00
|
|
|
// not we need it (we may need it if a remote version bump that makes it
|
|
|
|
// compatible is discovered by the call home) - so we must stage it for
|
2007-03-22 10:30:00 -07:00
|
|
|
// later ourselves.
|
|
|
|
if (shouldPhoneHomeIfNecessary && installData.currentApp) {
|
|
|
|
var installLocation = getInstallLocation(installData.id, aInstallLocationKey);
|
2008-03-14 16:34:32 -07:00
|
|
|
if (!installLocation)
|
2008-11-26 07:04:13 -08:00
|
|
|
return INSTALLERROR_INCOMPATIBLE_VERSION;
|
2007-03-22 10:30:00 -07:00
|
|
|
var stagedFile = installLocation.stageFile(aXPIFile, installData.id);
|
2008-03-14 16:34:32 -07:00
|
|
|
(new IncompatibleObserver(this)).checkForUpdates(addon, installManifest,
|
|
|
|
stagedFile);
|
2007-03-22 10:30:00 -07:00
|
|
|
// Return early to prevent deletion of the install manifest file.
|
2008-11-26 07:04:13 -08:00
|
|
|
return INSTALLERROR_PHONING_HOME;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// XXXben Look up XULRunnerSettingsThingy to see if there is a registered
|
|
|
|
// app that can handle this item, if so just stage and don't show
|
|
|
|
// this error!
|
|
|
|
showIncompatibleError(installData);
|
2007-09-04 13:59:05 -07:00
|
|
|
LOG("Add-on " + installData.id + " is incompatible with " +
|
|
|
|
BundleManager.appName + " " + gApp.version + ", Toolkit " +
|
|
|
|
gApp.platformVersion + ". Remote compatibility check was not performed.");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
break;
|
2008-11-02 04:13:48 -08:00
|
|
|
case INSTALLERROR_SOFTBLOCKED:
|
|
|
|
if (!showBlocklistMessage(installData, true))
|
|
|
|
break;
|
2008-11-26 07:04:13 -08:00
|
|
|
installData.error = INSTALLERROR_SUCCESS;
|
2008-11-02 04:13:48 -08:00
|
|
|
// Fall through to continue the install
|
2007-03-22 10:30:00 -07:00
|
|
|
case INSTALLERROR_SUCCESS:
|
|
|
|
// Installation of multiple extensions / themes contained within a single xpi.
|
2007-09-17 11:05:04 -07:00
|
|
|
if (installData.type == Ci.nsIUpdateItem.TYPE_MULTI_XPI) {
|
2007-03-22 10:30:00 -07:00
|
|
|
installMultiXPI(aXPIFile, installData);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stage the extension's XPI so it can be extracted at the next restart.
|
|
|
|
var installLocation = getInstallLocation(installData.id, aInstallLocationKey);
|
|
|
|
if (!installLocation) {
|
2007-08-29 01:16:15 -07:00
|
|
|
// No cleanup of any of the staged XPI files should be required here,
|
2007-03-22 10:30:00 -07:00
|
|
|
// because this should only ever fail on the first recurse through
|
|
|
|
// this function, BEFORE staging takes place... technically speaking
|
2007-08-29 01:16:15 -07:00
|
|
|
// a location could become readonly during the phone home process,
|
2007-03-22 10:30:00 -07:00
|
|
|
// but that's an edge case I don't care about.
|
2009-01-30 02:07:28 -08:00
|
|
|
this._callInstallListeners("onInstallEnded", addon, INSTALLERROR_RESTRICTED);
|
2008-11-26 07:04:13 -08:00
|
|
|
return INSTALLERROR_RESTRICTED;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Stage a copy of the XPI/JAR file for our own evil purposes...
|
|
|
|
stagedFile = installLocation.stageFile(aXPIFile, installData.id);
|
2007-08-29 01:16:15 -07:00
|
|
|
|
|
|
|
var restartRequired = this.installRequiresRestart(installData.id,
|
2007-03-22 10:30:00 -07:00
|
|
|
installData.type);
|
|
|
|
// Determine which configuration function to use based on whether or not
|
2007-08-29 01:16:15 -07:00
|
|
|
// there is data about this item in our datasource already - if there is
|
2007-03-22 10:30:00 -07:00
|
|
|
// we want to upgrade, otherwise we install fresh.
|
|
|
|
var ds = this.datasource;
|
|
|
|
if (installData.id in ds.visibleItems && ds.visibleItems[installData.id]) {
|
|
|
|
// We enter this function if any data corresponding to an existing GUID
|
|
|
|
// is found, regardless of its Install Location. We need to check before
|
|
|
|
// "upgrading" an item that Install Location of the new item is of equal
|
|
|
|
// or higher priority than the old item, to make sure the datasource only
|
|
|
|
// ever tracks metadata for active items.
|
|
|
|
var oldInstallLocation = this.getInstallLocation(installData.id);
|
|
|
|
if (oldInstallLocation.priority >= installLocation.priority) {
|
2007-08-29 01:16:15 -07:00
|
|
|
this._upgradeItem(installManifest, installData.id, installLocation,
|
2007-03-22 10:30:00 -07:00
|
|
|
installData.type);
|
|
|
|
if (!restartRequired) {
|
2007-12-04 07:56:58 -08:00
|
|
|
this._finalizeUpgrade(installData.id, installLocation);
|
2007-03-22 10:30:00 -07:00
|
|
|
this._finalizeInstall(installData.id, stagedFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2007-08-29 01:16:15 -07:00
|
|
|
this._configureForthcomingItem(installManifest, installData.id,
|
2007-03-22 10:30:00 -07:00
|
|
|
installLocation, installData.type);
|
2008-01-28 12:13:14 -08:00
|
|
|
if (!restartRequired) {
|
2007-03-22 10:30:00 -07:00
|
|
|
this._finalizeInstall(installData.id, stagedFile);
|
2008-01-28 12:13:14 -08:00
|
|
|
if (installData.type == Ci.nsIUpdateItem.TYPE_THEME) {
|
|
|
|
var internalName = this.datasource.getItemProperty(installData.id, "internalName");
|
|
|
|
if (gPref.getBoolPref(PREF_EM_DSS_ENABLED)) {
|
|
|
|
gPref.setCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN, internalName);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
gPref.setBoolPref(PREF_DSS_SWITCHPENDING, true);
|
|
|
|
gPref.setCharPref(PREF_DSS_SKIN_TO_SELECT, internalName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
this._updateManifests(restartRequired);
|
|
|
|
break;
|
|
|
|
case INSTALLERROR_INVALID_GUID:
|
2007-08-29 01:16:15 -07:00
|
|
|
LOG("Invalid GUID: Item has GUID: \"" + installData.id + "\"" +
|
2007-03-22 10:30:00 -07:00
|
|
|
" which is not well-formed.");
|
|
|
|
var bundle = BundleManager.getBundle(URI_EXTENSIONS_PROPERTIES);
|
2007-08-29 01:16:15 -07:00
|
|
|
showMessage("incompatibleTitle",
|
|
|
|
[bundle.GetStringFromName("type-" + installData.type)],
|
2007-03-22 10:30:00 -07:00
|
|
|
"invalidGUIDMessage", [installData.name, installData.id]);
|
|
|
|
break;
|
|
|
|
case INSTALLERROR_INVALID_VERSION:
|
2007-08-29 01:16:15 -07:00
|
|
|
LOG("Invalid Version: Item: \"" + installData.id + "\" has version " +
|
2007-03-22 10:30:00 -07:00
|
|
|
installData.version + " which is not well-formed.");
|
|
|
|
var bundle = BundleManager.getBundle(URI_EXTENSIONS_PROPERTIES);
|
2007-08-29 01:16:15 -07:00
|
|
|
showMessage("incompatibleTitle",
|
|
|
|
[bundle.GetStringFromName("type-" + installData.type)],
|
2007-03-22 10:30:00 -07:00
|
|
|
"invalidVersionMessage", [installData.name, installData.version]);
|
|
|
|
break;
|
|
|
|
case INSTALLERROR_INCOMPATIBLE_PLATFORM:
|
|
|
|
const osABI = gOSTarget + "_" + gXPCOMABI;
|
2007-08-29 01:16:15 -07:00
|
|
|
LOG("Incompatible Platform: Item: \"" + installData.id + "\" is not " +
|
2007-03-22 10:30:00 -07:00
|
|
|
"compatible with '" + osABI + "'.");
|
|
|
|
var bundle = BundleManager.getBundle(URI_EXTENSIONS_PROPERTIES);
|
2007-08-29 01:16:15 -07:00
|
|
|
showMessage("incompatibleTitle",
|
|
|
|
[bundle.GetStringFromName("type-" + installData.type)],
|
2007-03-22 10:30:00 -07:00
|
|
|
"incompatiblePlatformMessage",
|
|
|
|
[installData.name, BundleManager.appName, osABI]);
|
|
|
|
break;
|
|
|
|
case INSTALLERROR_BLOCKLISTED:
|
2007-08-29 01:16:15 -07:00
|
|
|
LOG("Blocklisted Item: Item: \"" + installData.id + "\" version " +
|
2007-03-22 10:30:00 -07:00
|
|
|
installData.version + " was not installed.");
|
2008-11-02 04:13:48 -08:00
|
|
|
showBlocklistMessage(installData, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2007-09-03 14:44:12 -07:00
|
|
|
case INSTALLERROR_INSECURE_UPDATE:
|
|
|
|
LOG("No secure updates: Item: \"" + installData.id + "\" version " +
|
|
|
|
installData.version + " was not installed.");
|
|
|
|
var bundle = BundleManager.getBundle(URI_EXTENSIONS_PROPERTIES);
|
|
|
|
showMessage("incompatibleTitle",
|
|
|
|
[bundle.GetStringFromName("type-" + installData.type)],
|
|
|
|
"insecureUpdateMessage", [installData.name]);
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Check to see if this item supports other applications and in that case
|
|
|
|
// stage the the XPI file in the location specified by those applications.
|
|
|
|
stageXPIForOtherApps(aXPIFile, installData);
|
|
|
|
|
2008-03-14 16:34:32 -07:00
|
|
|
// The install of this item is complete, notify observers
|
2009-01-30 02:07:28 -08:00
|
|
|
this._callInstallListeners("onInstallEnded", addon, installData.error);
|
2008-11-26 07:04:13 -08:00
|
|
|
return installData.error;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
2007-08-29 01:16:15 -07:00
|
|
|
* Whether or not this type's installation/uninstallation requires
|
2007-03-22 10:30:00 -07:00
|
|
|
* the application to be restarted.
|
|
|
|
* @param id
|
|
|
|
* The GUID of the item
|
|
|
|
* @param type
|
|
|
|
* The nsIUpdateItem type of the item
|
2007-08-29 01:16:15 -07:00
|
|
|
* @returns true if installation of an item of this type requires a
|
2007-03-22 10:30:00 -07:00
|
|
|
* restart.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
installRequiresRestart: function EM_installRequiresRestart(id, type) {
|
2007-03-22 10:30:00 -07:00
|
|
|
switch (type) {
|
2007-09-17 11:05:04 -07:00
|
|
|
case Ci.nsIUpdateItem.TYPE_THEME:
|
2007-03-22 10:30:00 -07:00
|
|
|
var internalName = this.datasource.getItemProperty(id, "internalName");
|
|
|
|
var needsRestart = false;
|
|
|
|
if (gPref.prefHasUserValue(PREF_DSS_SKIN_TO_SELECT))
|
|
|
|
needsRestart = internalName == gPref.getCharPref(PREF_DSS_SKIN_TO_SELECT);
|
|
|
|
if (!needsRestart &&
|
|
|
|
gPref.prefHasUserValue(PREF_GENERAL_SKINS_SELECTEDSKIN))
|
|
|
|
needsRestart = internalName == gPref.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN);
|
|
|
|
return needsRestart;
|
|
|
|
}
|
2008-03-06 18:02:49 -08:00
|
|
|
return ((type & Ci.nsIUpdateItem.TYPE_ADDON) > 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
2007-08-29 01:16:15 -07:00
|
|
|
* Perform initial configuration on an item that has just or will be
|
2007-03-22 10:30:00 -07:00
|
|
|
* installed. This inserts the item into the appropriate container in the
|
|
|
|
* datasource, so that the application UI shows the item even if it will
|
|
|
|
* not actually be installed until the next restart.
|
2007-08-29 01:16:15 -07:00
|
|
|
* @param installManifest
|
2007-03-22 10:30:00 -07:00
|
|
|
* The Install Manifest datasource that describes this item.
|
2007-08-29 01:16:15 -07:00
|
|
|
* @param id
|
2007-03-22 10:30:00 -07:00
|
|
|
* The GUID of this item.
|
|
|
|
* @param installLocation
|
|
|
|
* The Install Location where this item is installed.
|
|
|
|
* @param type
|
2007-08-29 01:16:15 -07:00
|
|
|
* The nsIUpdateItem type of this item.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_configureForthcomingItem: function EM__configureForthcomingItem(installManifest,
|
|
|
|
id,
|
|
|
|
installLocation,
|
|
|
|
type) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var ds = this.datasource;
|
|
|
|
ds.updateVisibleList(id, installLocation.name, false);
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-06-25 14:02:46 -07:00
|
|
|
var name = null;
|
2007-10-12 15:45:16 -07:00
|
|
|
var localized = findClosestLocalizedResource(installManifest, gInstallManifestRoot);
|
|
|
|
if (localized)
|
|
|
|
name = installManifest.GetTarget(localized, EM_R("name"), true);
|
|
|
|
else
|
2007-06-25 14:02:46 -07:00
|
|
|
name = EM_L(getManifestProperty(installManifest, "name"));
|
|
|
|
|
|
|
|
var props = { name : name,
|
2007-03-22 10:30:00 -07:00
|
|
|
version : EM_L(getManifestProperty(installManifest, "version")),
|
2007-06-30 10:17:03 -07:00
|
|
|
newVersion : EM_L(getManifestProperty(installManifest, "version")),
|
2007-03-22 10:30:00 -07:00
|
|
|
installLocation : EM_L(installLocation.name),
|
|
|
|
type : EM_I(type),
|
|
|
|
availableUpdateURL : null,
|
|
|
|
availableUpdateHash : null,
|
2007-09-05 18:20:11 -07:00
|
|
|
availableUpdateVersion: null,
|
|
|
|
availableUpdateInfo : null };
|
2008-07-25 09:23:25 -07:00
|
|
|
ds.setItemProperties(id, props);
|
2007-03-22 10:30:00 -07:00
|
|
|
ds.updateProperty(id, "availableUpdateURL");
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
this._setOp(id, OP_NEEDS_INSTALL);
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Insert it into the child list NOW rather than later because:
|
|
|
|
// - extensions installed using the command line need to be a member
|
|
|
|
// of a container during the install phase for the code to be able
|
|
|
|
// to identify profile vs. global
|
|
|
|
// - extensions installed through the UI should show some kind of
|
|
|
|
// feedback to indicate their presence is forthcoming (i.e. they
|
|
|
|
// will be available after a restart).
|
|
|
|
ds.insertItemIntoContainer(id);
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
this._notifyAction(id, EM_ITEM_INSTALLED);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Perform configuration on an item that has just or will be upgraded.
|
|
|
|
* @param installManifest
|
|
|
|
* The Install Manifest datasource that describes this item.
|
|
|
|
* @param itemID
|
|
|
|
* The GUID of this item.
|
|
|
|
* @param installLocation
|
|
|
|
* The Install Location where this item is installed.
|
|
|
|
* @param type
|
2007-08-29 01:16:15 -07:00
|
|
|
* The nsIUpdateItem type of this item.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_upgradeItem: function EM__upgradeItem(installManifest, id, installLocation, type) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Don't change any props that would need to be reset if the install fails.
|
|
|
|
// They will be reset as appropriate by the upgrade/install process.
|
|
|
|
var ds = this.datasource;
|
|
|
|
ds.updateVisibleList(id, installLocation.name, false);
|
|
|
|
var props = { installLocation : EM_L(installLocation.name),
|
|
|
|
type : EM_I(type),
|
2007-06-30 10:17:03 -07:00
|
|
|
newVersion : EM_L(getManifestProperty(installManifest, "version")),
|
2007-03-22 10:30:00 -07:00
|
|
|
availableUpdateURL : null,
|
|
|
|
availableUpdateHash : null,
|
2007-09-05 18:20:11 -07:00
|
|
|
availableUpdateVersion : null,
|
|
|
|
availableUpdateInfo : null };
|
2008-07-25 09:23:25 -07:00
|
|
|
ds.setItemProperties(id, props);
|
2007-03-22 10:30:00 -07:00
|
|
|
ds.updateProperty(id, "availableUpdateURL");
|
|
|
|
|
|
|
|
this._setOp(id, OP_NEEDS_UPGRADE);
|
|
|
|
this._notifyAction(id, EM_ITEM_UPGRADED);
|
|
|
|
},
|
|
|
|
|
2007-08-29 01:16:15 -07:00
|
|
|
/**
|
2007-03-22 10:30:00 -07:00
|
|
|
* Completes an Extension's installation.
|
|
|
|
* @param id
|
|
|
|
* The GUID of the Extension to install.
|
|
|
|
* @param file
|
|
|
|
* The XPI/JAR file to install from. If this is null, we try to
|
|
|
|
* determine the stage file location from the ID.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_finalizeInstall: function EM__finalizeInstall(id, file) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var ds = this.datasource;
|
|
|
|
var type = ds.getItemProperty(id, "type");
|
|
|
|
if (id == 0 || id == -1) {
|
2008-04-01 02:26:47 -07:00
|
|
|
ds.removeCorruptItem(id);
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
var installLocation = this.getInstallLocation(id);
|
|
|
|
if (!installLocation) {
|
|
|
|
// If the install location is null, that means we've reached the finalize
|
|
|
|
// state without the item ever having metadata added for it, which implies
|
|
|
|
// bogus data in the Startup Cache. Clear the entries and don't do anything
|
|
|
|
// else.
|
|
|
|
var entries = StartupCache.findEntries(id);
|
|
|
|
for (var i = 0; i < entries.length; ++i) {
|
|
|
|
var location = InstallLocations.get(entries[i].location);
|
|
|
|
StartupCache.clearEntry(location, id);
|
|
|
|
PendingOperations.clearItem(OP_NEEDS_INSTALL, id);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var itemLocation = installLocation.getItemLocation(id);
|
|
|
|
|
|
|
|
if (!file && "stageFile" in installLocation)
|
|
|
|
file = installLocation.getStageFile(id);
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2009-06-11 02:54:26 -07:00
|
|
|
// If there is a staged file then we must extract it to the correct place,
|
|
|
|
// otherwise we are dealing with a dropped-in directory.
|
|
|
|
if (file && file.exists())
|
|
|
|
safeInstallOperation(id, installLocation, file);
|
|
|
|
|
|
|
|
var metadataFile = installLocation.getItemFile(id, FILE_INSTALL_MANIFEST);
|
2009-12-17 13:12:00 -08:00
|
|
|
if (metadataFile && metadataFile.exists()) {
|
2009-06-11 02:54:26 -07:00
|
|
|
var metadataDS = getInstallManifest(metadataFile);
|
|
|
|
if (metadataDS) {
|
|
|
|
// Add metadata for the item to the extensions datasource
|
|
|
|
this.datasource.addItemMetadata(id, metadataDS, installLocation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
LOG("_finalizeInstall: install manifest for extension " + id + " at " +
|
|
|
|
metadataFile.path + " could not be loaded. Add-on is not usable.");
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-08-29 01:16:15 -07:00
|
|
|
// If the file was staged, we must clean it up ourselves, otherwise the
|
2007-03-22 10:30:00 -07:00
|
|
|
// EM caller is responsible for doing so (e.g. XPInstall)
|
|
|
|
if (file)
|
|
|
|
installLocation.removeFile(file);
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Clear the op flag from the Startup Cache and Pending Operations sets
|
|
|
|
StartupCache.put(installLocation, id, OP_NONE, true);
|
|
|
|
PendingOperations.clearItem(OP_NEEDS_INSTALL, id);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes an item's metadata in preparation for an upgrade-install.
|
|
|
|
* @param id
|
|
|
|
* The GUID of the item to uninstall.
|
2007-12-03 04:20:57 -08:00
|
|
|
* @param installLocation
|
|
|
|
* The nsIInstallLocation of the item
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_finalizeUpgrade: function EM__finalizeUpgrade(id, installLocation) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Retrieve the item properties *BEFORE* we clean the resource!
|
|
|
|
var ds = this.datasource;
|
|
|
|
|
|
|
|
var stagedFile = null;
|
|
|
|
if ("getStageFile" in installLocation)
|
|
|
|
stagedFile = installLocation.getStageFile(id);
|
|
|
|
|
|
|
|
if (stagedFile)
|
|
|
|
var installRDF = extractRDFFileToTempDir(stagedFile, FILE_INSTALL_MANIFEST, true);
|
|
|
|
else
|
|
|
|
installRDF = installLocation.getItemFile(id, FILE_INSTALL_MANIFEST);
|
2009-12-17 13:12:00 -08:00
|
|
|
if (installRDF && installRDF.exists()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var installManifest = getInstallManifest(installRDF);
|
|
|
|
if (installManifest) {
|
|
|
|
var type = getAddonTypeFromInstallManifest(installManifest);
|
|
|
|
var userDisabled = ds.getItemProperty(id, "userDisabled") == "true";
|
|
|
|
|
|
|
|
// Clean the item resource
|
|
|
|
ds.removeItemMetadata(id);
|
|
|
|
// Now set up the properties on the item to mimic an item in its
|
|
|
|
// "initial state" for installation.
|
2007-08-29 01:16:15 -07:00
|
|
|
this._configureForthcomingItem(installManifest, id, installLocation,
|
2007-03-22 10:30:00 -07:00
|
|
|
type);
|
|
|
|
if (userDisabled)
|
|
|
|
ds.setItemProperty(id, EM_R("userDisabled"), EM_L("true"));
|
|
|
|
}
|
|
|
|
if (stagedFile)
|
|
|
|
installRDF.remove(false);
|
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
// Clear the op flag from the Pending Operations set. Do NOT clear op flag in
|
2007-03-22 10:30:00 -07:00
|
|
|
// the startup cache since this may have been reset to OP_NEEDS_INSTALL by
|
|
|
|
// |_configureForthcomingItem|.
|
|
|
|
PendingOperations.clearItem(OP_NEEDS_UPGRADE, id);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Completes an item's uninstallation.
|
|
|
|
* @param id
|
|
|
|
* The GUID of the item to uninstall.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_finalizeUninstall: function EM__finalizeUninstall(id) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var ds = this.datasource;
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var installLocation = this.getInstallLocation(id);
|
|
|
|
if (!installLocation.itemIsManagedIndependently(id)) {
|
|
|
|
try {
|
2009-06-11 02:54:26 -07:00
|
|
|
// Passing null for the file to install will just cause the directory
|
2007-03-22 10:30:00 -07:00
|
|
|
// removed.
|
2009-06-11 02:54:26 -07:00
|
|
|
safeInstallOperation(id, installLocation, null);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
2007-12-11 16:56:09 -08:00
|
|
|
ERROR("_finalizeUninstall: failed to remove directory for item: " + id +
|
|
|
|
" at Install Location: " + installLocation.name + ", rolling back uninstall");
|
2008-03-27 13:06:41 -07:00
|
|
|
var manifest = installLocation.getItemFile(id, "FILE_INSTALL_MANIFEST");
|
|
|
|
// If there is no manifest then either the rollback failed, or there was
|
|
|
|
// no manifest in the first place. Either way this item is now invalid
|
|
|
|
// and we shouldn't try to re-install it.
|
2009-12-17 13:12:00 -08:00
|
|
|
if (manifest && manifest.exists()) {
|
2008-03-27 13:06:41 -07:00
|
|
|
// Removal of the files failed, reset the uninstalled flag and rewrite
|
|
|
|
// the install manifests so this item's components are registered.
|
|
|
|
// Clear the op flag from the Startup Cache
|
|
|
|
StartupCache.put(installLocation, id, OP_NONE, true);
|
|
|
|
var restartRequired = this.installRequiresRestart(id, ds.getItemProperty(id, "type"))
|
|
|
|
this._updateManifests(restartRequired);
|
|
|
|
return;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (installLocation.name == KEY_APP_PROFILE ||
|
2008-01-15 07:13:59 -08:00
|
|
|
installLocation.name == KEY_APP_GLOBAL ||
|
|
|
|
installLocation.name == KEY_APP_SYSTEM_USER) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Check for a pointer file and remove it if it exists
|
|
|
|
var pointerFile = installLocation.location.clone();
|
|
|
|
pointerFile.append(id);
|
|
|
|
if (pointerFile.exists() && !pointerFile.isDirectory())
|
|
|
|
pointerFile.remove(false);
|
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Clean the item resource
|
|
|
|
ds.removeItemMetadata(id);
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Do this LAST since inferences are made about an item based on
|
|
|
|
// what container it's in.
|
|
|
|
ds.removeItemFromContainer(id);
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Clear the op flag from the Startup Cache and the Pending Operations set.
|
|
|
|
StartupCache.clearEntry(installLocation, id);
|
|
|
|
PendingOperations.clearItem(OP_NEEDS_UNINSTALL, id);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Uninstalls an item. If the uninstallation cannot be performed immediately
|
|
|
|
* it is scheduled for the next restart.
|
|
|
|
* @param id
|
|
|
|
* The GUID of the item to uninstall.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
uninstallItem: function EM_uninstallItem(id) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var ds = this.datasource;
|
|
|
|
ds.updateDownloadState(PREFIX_ITEM_URI + id, null);
|
|
|
|
if (!ds.isDownloadItem(id)) {
|
|
|
|
var opType = ds.getItemProperty(id, "opType");
|
|
|
|
var installLocation = this.getInstallLocation(id);
|
|
|
|
// Removes any staged xpis for this item.
|
|
|
|
if (opType == OP_NEEDS_UPGRADE || opType == OP_NEEDS_INSTALL) {
|
|
|
|
var stageFile = installLocation.getStageFile(id);
|
|
|
|
if (stageFile)
|
|
|
|
installLocation.removeFile(stageFile);
|
|
|
|
}
|
|
|
|
// Addons with an opType of OP_NEEDS_INSTALL only have a staged xpi file
|
|
|
|
// and are removed immediately since the uninstall can't be canceled.
|
|
|
|
if (opType == OP_NEEDS_INSTALL) {
|
|
|
|
ds.removeItemMetadata(id);
|
|
|
|
ds.removeItemFromContainer(id);
|
|
|
|
ds.updateVisibleList(id, null, true);
|
|
|
|
StartupCache.clearEntry(installLocation, id);
|
|
|
|
this._updateManifests(false);
|
|
|
|
}
|
|
|
|
else {
|
2007-08-25 16:36:25 -07:00
|
|
|
if (opType == OP_NEEDS_UPGRADE)
|
2009-11-09 09:32:13 -08:00
|
|
|
ds.setItemProperty(id, EM_R("newVersion"), null);
|
2007-03-22 10:30:00 -07:00
|
|
|
this._setOp(id, OP_NEEDS_UNINSTALL);
|
|
|
|
var type = ds.getItemProperty(id, "type");
|
|
|
|
var restartRequired = this.installRequiresRestart(id, type);
|
|
|
|
if (!restartRequired) {
|
|
|
|
this._finalizeUninstall(id);
|
|
|
|
this._updateManifests(restartRequired);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Bad download entry - uri is url, e.g. "http://www.foo.com/test.xpi"
|
2007-08-29 01:16:15 -07:00
|
|
|
// ... just remove it from the list.
|
2007-03-22 10:30:00 -07:00
|
|
|
ds.removeCorruptDLItem(id);
|
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
this._notifyAction(id, EM_ITEM_UNINSTALLED);
|
|
|
|
},
|
|
|
|
|
2007-08-25 16:36:25 -07:00
|
|
|
/* See nsIExtensionManager.idl */
|
2008-08-15 08:23:48 -07:00
|
|
|
cancelInstallItem: function EM_cancelInstallItem(id) {
|
2007-08-25 16:36:25 -07:00
|
|
|
var ds = this.datasource;
|
|
|
|
var opType = ds.getItemProperty(id, "opType");
|
|
|
|
if (opType != OP_NEEDS_UPGRADE && opType != OP_NEEDS_INSTALL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ds.updateDownloadState(PREFIX_ITEM_URI + id, null);
|
|
|
|
var installLocation = this.getInstallLocation(id);
|
|
|
|
// Removes any staged xpis for this item.
|
|
|
|
var stageFile = installLocation.getStageFile(id);
|
|
|
|
if (stageFile)
|
|
|
|
installLocation.removeFile(stageFile);
|
|
|
|
// Addons with an opType of OP_NEEDS_INSTALL only have a staged xpi file
|
|
|
|
// and just need to be removed completely from the ds.
|
|
|
|
if (opType == OP_NEEDS_INSTALL) {
|
|
|
|
ds.removeItemMetadata(id);
|
|
|
|
ds.removeItemFromContainer(id);
|
|
|
|
ds.updateVisibleList(id, null, true);
|
|
|
|
StartupCache.clearEntry(installLocation, id);
|
|
|
|
this._updateManifests(false);
|
|
|
|
this._notifyAction(id, EM_ITEM_CANCEL);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Clear upgrade information and reset any request to enable/disable.
|
|
|
|
ds.setItemProperty(id, EM_R("newVersion"), null);
|
|
|
|
var appDisabled = ds.getItemProperty(id, "appDisabled");
|
|
|
|
var userDisabled = ds.getItemProperty(id, "userDisabled");
|
|
|
|
if (appDisabled == "true" || appDisabled == OP_NONE && userDisabled == OP_NONE) {
|
|
|
|
this._setOp(id, OP_NONE);
|
|
|
|
this._notifyAction(id, EM_ITEM_CANCEL);
|
|
|
|
}
|
|
|
|
else if (appDisabled == OP_NEEDS_DISABLE || userDisabled == OP_NEEDS_DISABLE) {
|
|
|
|
this._setOp(id, OP_NEEDS_DISABLE);
|
|
|
|
this._notifyAction(id, EM_ITEM_DISABLED);
|
|
|
|
}
|
|
|
|
else if (appDisabled == OP_NEEDS_ENABLE || userDisabled == OP_NEEDS_ENABLE) {
|
|
|
|
this._setOp(id, OP_NEEDS_ENABLE);
|
|
|
|
this._notifyAction(id, EM_ITEM_ENABLED);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this._setOp(id, OP_NONE);
|
|
|
|
this._notifyAction(id, EM_ITEM_CANCEL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Cancels a pending uninstall of an item
|
|
|
|
* @param id
|
|
|
|
* The ID of the item.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
cancelUninstallItem: function EM_cancelUninstallItem(id) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var ds = this.datasource;
|
|
|
|
var appDisabled = ds.getItemProperty(id, "appDisabled");
|
|
|
|
var userDisabled = ds.getItemProperty(id, "userDisabled");
|
|
|
|
if (appDisabled == "true" || appDisabled == OP_NONE && userDisabled == OP_NONE) {
|
|
|
|
this._setOp(id, OP_NONE);
|
|
|
|
this._notifyAction(id, EM_ITEM_CANCEL);
|
|
|
|
}
|
|
|
|
else if (appDisabled == OP_NEEDS_DISABLE || userDisabled == OP_NEEDS_DISABLE) {
|
|
|
|
this._setOp(id, OP_NEEDS_DISABLE);
|
|
|
|
this._notifyAction(id, EM_ITEM_DISABLED);
|
|
|
|
}
|
|
|
|
else if (appDisabled == OP_NEEDS_ENABLE || userDisabled == OP_NEEDS_ENABLE) {
|
|
|
|
this._setOp(id, OP_NEEDS_ENABLE);
|
|
|
|
this._notifyAction(id, EM_ITEM_ENABLED);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this._setOp(id, OP_NONE);
|
|
|
|
this._notifyAction(id, EM_ITEM_CANCEL);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2007-08-29 01:16:15 -07:00
|
|
|
* Sets the pending operation for a visible item.
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param id
|
|
|
|
* The GUID of the item
|
|
|
|
* @param op
|
|
|
|
* The name of the operation to be performed
|
2007-08-29 01:16:15 -07:00
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_setOp: function EM__setOp(id, op) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var location = this.getInstallLocation(id);
|
|
|
|
StartupCache.put(location, id, op, true);
|
|
|
|
PendingOperations.addItem(op, { locationKey: location.name, id: id });
|
|
|
|
var ds = this.datasource;
|
|
|
|
if (op == OP_NEEDS_INSTALL || op == OP_NEEDS_UPGRADE)
|
|
|
|
ds.updateDownloadState(PREFIX_ITEM_URI + id, "success");
|
|
|
|
|
|
|
|
ds.updateProperty(id, "opType");
|
|
|
|
ds.updateProperty(id, "updateable");
|
|
|
|
ds.updateProperty(id, "satisfiesDependencies");
|
|
|
|
var restartRequired = this.installRequiresRestart(id, ds.getItemProperty(id, "type"))
|
|
|
|
this._updateDependentItemsForID(id);
|
|
|
|
this._updateManifests(restartRequired);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Note on appDisabled and userDisabled property arcs.
|
|
|
|
* The appDisabled and userDisabled RDF property arcs are used to store
|
|
|
|
* the pending operation for app disabling and user disabling for an item as
|
|
|
|
* well as the user and app disabled status after the pending operation has
|
|
|
|
* been completed upon restart. When the appDisabled value changes the value
|
|
|
|
* of userDisabled is reset to prevent the state of widgets and status
|
|
|
|
* messages from being in an incorrect state.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enables an item for the application (e.g. the item satisfies all
|
|
|
|
* requirements like app compatibility for it to be enabled). The appDisabled
|
|
|
|
* property arc will be removed if the item will be app disabled on next
|
|
|
|
* restart to cancel the app disabled operation for the item otherwise the
|
|
|
|
* property value will be set to OP_NEEDS_ENABLE. The item's pending
|
|
|
|
* operations are then evaluated in order to set the operation to perform
|
|
|
|
* and notify the observers if the operation has been changed.
|
|
|
|
* See "Note on appDisabled and userDisabled property arcs" above.
|
|
|
|
* @param id
|
|
|
|
* The ID of the item to be enabled by the application.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_appEnableItem: function EM__appEnableItem(id) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var ds = this.datasource;
|
|
|
|
var appDisabled = ds.getItemProperty(id, "appDisabled");
|
|
|
|
if (appDisabled == OP_NONE || appDisabled == OP_NEEDS_ENABLE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var opType = ds.getItemProperty(id, "opType");
|
|
|
|
var userDisabled = ds.getItemProperty(id, "userDisabled");
|
|
|
|
// reset user disabled if it has a pending operation to prevent the ui
|
|
|
|
// state from getting confused as to an item's current state.
|
|
|
|
if (userDisabled == OP_NEEDS_DISABLE)
|
|
|
|
ds.setItemProperty(id, EM_R("userDisabled"), null);
|
|
|
|
else if (userDisabled == OP_NEEDS_ENABLE)
|
|
|
|
ds.setItemProperty(id, EM_R("userDisabled"), EM_L("true"));
|
|
|
|
|
|
|
|
if (appDisabled == OP_NEEDS_DISABLE)
|
|
|
|
ds.setItemProperty(id, EM_R("appDisabled"), null);
|
|
|
|
else if (appDisabled == "true")
|
|
|
|
ds.setItemProperty(id, EM_R("appDisabled"), EM_L(OP_NEEDS_ENABLE));
|
|
|
|
|
|
|
|
// Don't set a new operation when there is a pending uninstall operation.
|
|
|
|
if (opType == OP_NEEDS_UNINSTALL) {
|
|
|
|
this._updateDependentItemsForID(id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var operation, action;
|
|
|
|
// if this item is already enabled or user disabled don't set a pending
|
|
|
|
// operation - instead immediately enable it and reset the operation type
|
|
|
|
// if needed.
|
|
|
|
if (appDisabled == OP_NEEDS_DISABLE || appDisabled == OP_NONE ||
|
|
|
|
userDisabled == "true") {
|
|
|
|
if (opType != OP_NONE) {
|
|
|
|
operation = OP_NONE;
|
|
|
|
action = EM_ITEM_CANCEL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (opType != OP_NEEDS_ENABLE) {
|
|
|
|
operation = OP_NEEDS_ENABLE;
|
|
|
|
action = EM_ITEM_ENABLED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action) {
|
|
|
|
this._setOp(id, operation);
|
|
|
|
this._notifyAction(id, action);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ds.updateProperty(id, "satisfiesDependencies");
|
|
|
|
this._updateDependentItemsForID(id);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disables an item for the application (e.g. the item doesn't satisfy all
|
|
|
|
* requirements like app compatibility for it to be enabled). The appDisabled
|
|
|
|
* property arc will be set to true if the item will be app enabled on next
|
|
|
|
* restart to cancel the app enabled operation for the item otherwise the
|
|
|
|
* property value will be set to OP_NEEDS_DISABLE. The item's pending
|
|
|
|
* operations are then evaluated in order to set the operation to perform
|
|
|
|
* and notify the observers if the operation has been changed.
|
|
|
|
* See "Note on appDisabled and userDisabled property arcs" above.
|
|
|
|
* @param id
|
|
|
|
* The ID of the item to be disabled by the application.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_appDisableItem: function EM__appDisableItem(id) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var ds = this.datasource;
|
|
|
|
var appDisabled = ds.getItemProperty(id, "appDisabled");
|
|
|
|
if (appDisabled == "true" || appDisabled == OP_NEEDS_DISABLE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var opType = ds.getItemProperty(id, "opType");
|
|
|
|
var userDisabled = ds.getItemProperty(id, "userDisabled");
|
|
|
|
|
|
|
|
// reset user disabled if it has a pending operation to prevent the ui
|
|
|
|
// state from getting confused as to an item's current state.
|
|
|
|
if (userDisabled == OP_NEEDS_DISABLE)
|
|
|
|
ds.setItemProperty(id, EM_R("userDisabled"), null);
|
|
|
|
else if (userDisabled == OP_NEEDS_ENABLE)
|
|
|
|
ds.setItemProperty(id, EM_R("userDisabled"), EM_L("true"));
|
|
|
|
|
|
|
|
if (appDisabled == OP_NEEDS_ENABLE || userDisabled == OP_NEEDS_ENABLE ||
|
|
|
|
ds.getItemProperty(id, "userDisabled") == "true")
|
|
|
|
ds.setItemProperty(id, EM_R("appDisabled"), EM_L("true"));
|
|
|
|
else if (appDisabled == OP_NONE)
|
|
|
|
ds.setItemProperty(id, EM_R("appDisabled"), EM_L(OP_NEEDS_DISABLE));
|
|
|
|
|
|
|
|
// Don't set a new operation when there is a pending uninstall operation.
|
|
|
|
if (opType == OP_NEEDS_UNINSTALL) {
|
|
|
|
this._updateDependentItemsForID(id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var operation, action;
|
|
|
|
// if this item is already disabled don't set a pending operation - instead
|
|
|
|
// immediately disable it and reset the operation type if needed.
|
|
|
|
if (appDisabled == OP_NEEDS_ENABLE || appDisabled == "true" ||
|
|
|
|
userDisabled == OP_NEEDS_ENABLE || userDisabled == "true") {
|
|
|
|
if (opType != OP_NONE) {
|
|
|
|
operation = OP_NONE;
|
|
|
|
action = EM_ITEM_CANCEL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (opType != OP_NEEDS_DISABLE) {
|
|
|
|
operation = OP_NEEDS_DISABLE;
|
|
|
|
action = EM_ITEM_DISABLED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action) {
|
|
|
|
this._setOp(id, operation);
|
|
|
|
this._notifyAction(id, action);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ds.updateProperty(id, "satisfiesDependencies");
|
|
|
|
this._updateDependentItemsForID(id);
|
|
|
|
}
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Sets an item to be enabled by the user. If the item is already enabled this
|
|
|
|
* clears the needs-enable operation for the next restart.
|
|
|
|
* See "Note on appDisabled and userDisabled property arcs" above.
|
|
|
|
* @param id
|
|
|
|
* The ID of the item to be enabled by the user.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
enableItem: function EM_enableItem(id) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var ds = this.datasource;
|
|
|
|
var opType = ds.getItemProperty(id, "opType");
|
|
|
|
var appDisabled = ds.getItemProperty(id, "appDisabled");
|
|
|
|
var userDisabled = ds.getItemProperty(id, "userDisabled");
|
|
|
|
|
|
|
|
var operation, action;
|
|
|
|
// if this item is already enabled don't set a pending operation - instead
|
|
|
|
// immediately enable it and reset the operation type if needed.
|
|
|
|
if (appDisabled == OP_NONE &&
|
|
|
|
userDisabled == OP_NEEDS_DISABLE || userDisabled == OP_NONE) {
|
|
|
|
if (userDisabled == OP_NEEDS_DISABLE)
|
|
|
|
ds.setItemProperty(id, EM_R("userDisabled"), null);
|
|
|
|
if (opType != OP_NONE) {
|
|
|
|
operation = OP_NONE;
|
|
|
|
action = EM_ITEM_CANCEL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (userDisabled == "true")
|
|
|
|
ds.setItemProperty(id, EM_R("userDisabled"), EM_L(OP_NEEDS_ENABLE));
|
|
|
|
if (opType != OP_NEEDS_ENABLE) {
|
|
|
|
operation = OP_NEEDS_ENABLE;
|
|
|
|
action = EM_ITEM_ENABLED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action) {
|
|
|
|
this._setOp(id, operation);
|
|
|
|
this._notifyAction(id, action);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ds.updateProperty(id, "satisfiesDependencies");
|
|
|
|
this._updateDependentItemsForID(id);
|
|
|
|
}
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Sets an item to be disabled by the user. If the item is already disabled
|
|
|
|
* this clears the needs-disable operation for the next restart.
|
|
|
|
* See "Note on appDisabled and userDisabled property arcs" above.
|
|
|
|
* @param id
|
|
|
|
* The ID of the item to be disabled by the user.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
disableItem: function EM_disableItem(id) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var ds = this.datasource;
|
|
|
|
var opType = ds.getItemProperty(id, "opType");
|
|
|
|
var appDisabled = ds.getItemProperty(id, "appDisabled");
|
|
|
|
var userDisabled = ds.getItemProperty(id, "userDisabled");
|
|
|
|
|
|
|
|
var operation, action;
|
|
|
|
// if this item is already disabled don't set a pending operation - instead
|
|
|
|
// immediately disable it and reset the operation type if needed.
|
|
|
|
if (userDisabled == OP_NEEDS_ENABLE || userDisabled == "true" ||
|
|
|
|
appDisabled == OP_NEEDS_ENABLE) {
|
|
|
|
if (userDisabled != "true")
|
|
|
|
ds.setItemProperty(id, EM_R("userDisabled"), EM_L("true"));
|
|
|
|
if (opType != OP_NONE) {
|
|
|
|
operation = OP_NONE;
|
|
|
|
action = EM_ITEM_CANCEL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (userDisabled == OP_NONE)
|
|
|
|
ds.setItemProperty(id, EM_R("userDisabled"), EM_L(OP_NEEDS_DISABLE));
|
|
|
|
if (opType != OP_NEEDS_DISABLE) {
|
|
|
|
operation = OP_NEEDS_DISABLE;
|
|
|
|
action = EM_ITEM_DISABLED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action) {
|
|
|
|
this._setOp(id, operation);
|
|
|
|
this._notifyAction(id, action);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ds.updateProperty(id, "satisfiesDependencies");
|
|
|
|
this._updateDependentItemsForID(id);
|
|
|
|
}
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Determines whether an item should be disabled by the application.
|
|
|
|
* @param id
|
|
|
|
* The ID of the item to check
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_isUsableItem: function EM__isUsableItem(id) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var ds = this.datasource;
|
2009-08-06 07:24:52 -07:00
|
|
|
/* If the item is compatible and if it isn't blocklisted and has all
|
|
|
|
* dependencies satisfied then proceed to the security check */
|
|
|
|
if (ds.isCompatible(ds, getResourceForID(id), false) &&
|
2007-09-03 14:44:12 -07:00
|
|
|
ds.getItemProperty(id, "blocklisted") == "false" &&
|
|
|
|
ds.getItemProperty(id, "satisfiesDependencies") == "true") {
|
|
|
|
|
|
|
|
// appManaged items aren't updated so no need to check update security.
|
|
|
|
if (ds.getItemProperty(id, "appManaged") == "true")
|
|
|
|
return true;
|
|
|
|
|
|
|
|
/* If we are not ignoring update security then check that the item has
|
|
|
|
* a secure update mechanism */
|
|
|
|
return (!gCheckUpdateSecurity ||
|
|
|
|
ds.getItemProperty(id, "providesUpdatesSecurely") == "true");
|
|
|
|
}
|
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets an item's dependent items disabled state for the app based on whether
|
|
|
|
* its dependencies are met and the item is compatible.
|
|
|
|
* @param id
|
|
|
|
* The ID of the item whose dependent items will be checked
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_updateDependentItemsForID: function EM__updateDependentItemsForID(id) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var ds = this.datasource;
|
2009-11-07 00:21:07 -08:00
|
|
|
var dependentItems = this.getDependentItemListForID(id, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
for (var i = 0; i < dependentItems.length; ++i) {
|
|
|
|
var dependentID = dependentItems[i].id;
|
|
|
|
ds.updateProperty(dependentID, "satisfiesDependencies");
|
|
|
|
if (this._isUsableItem(dependentID))
|
|
|
|
this._appEnableItem(dependentID);
|
|
|
|
else
|
|
|
|
this._appDisableItem(dependentID);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notify observers of a change to an item that has been requested by the
|
2007-08-29 01:16:15 -07:00
|
|
|
* user.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_notifyAction: function EM__notifyAction(id, reason) {
|
2007-08-29 01:16:15 -07:00
|
|
|
gOS.notifyObservers(this.datasource.getItemForID(id),
|
2007-03-22 10:30:00 -07:00
|
|
|
EM_ACTION_REQUESTED_TOPIC, reason);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* See nsIExtensionManager.idl
|
|
|
|
*/
|
2008-10-21 17:48:52 -07:00
|
|
|
update: function EM_update(items, itemCount, updateCheckType, listener,
|
2009-09-10 11:50:41 -07:00
|
|
|
updateType, appVersion, platformVersion) {
|
|
|
|
|
|
|
|
// Callers through the API are only allowed to use update types declared
|
|
|
|
// in nsIExtensionManager.idl
|
|
|
|
if (updateType > MAX_PUBLIC_UPDATE_WHEN)
|
|
|
|
throw Cr.NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
|
2009-11-15 03:20:35 -08:00
|
|
|
for (var i = 0; i < itemCount; ++i) {
|
2007-08-29 01:16:15 -07:00
|
|
|
var currItem = items[i];
|
|
|
|
if (!currItem)
|
2007-09-03 20:07:11 -07:00
|
|
|
throw Cr.NS_ERROR_ILLEGAL_VALUE;
|
2007-08-29 01:16:15 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (items.length == 0)
|
2009-11-07 00:21:07 -08:00
|
|
|
items = this.getItemList(Ci.nsIUpdateItem.TYPE_ANY);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-11-17 04:52:03 -08:00
|
|
|
var updater = new ExtensionItemUpdater(this);
|
2008-10-21 17:48:52 -07:00
|
|
|
updater.checkForUpdates(items, items.length, updateCheckType, listener,
|
2009-09-10 11:50:41 -07:00
|
|
|
updateType, appVersion, platformVersion);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2008-11-02 04:13:48 -08:00
|
|
|
* See nsIExtensionManager.idl
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2008-11-02 04:13:48 -08:00
|
|
|
updateAndGetNewBlocklistedItems: function EM_updateAndGetNewBlocklistedItems(itemCount) {
|
|
|
|
if (!gBlocklist)
|
|
|
|
gBlocklist = Cc["@mozilla.org/extensions/blocklist;1"].
|
|
|
|
getService(Ci.nsIBlocklistService);
|
|
|
|
|
|
|
|
var list = [];
|
2007-03-22 10:30:00 -07:00
|
|
|
var ds = this.datasource;
|
2009-11-07 00:21:07 -08:00
|
|
|
var items = this.getItemList(Ci.nsIUpdateItem.TYPE_ANY);
|
2007-03-22 10:30:00 -07:00
|
|
|
for (var i = 0; i < items.length; ++i) {
|
|
|
|
var id = items[i].id;
|
2008-11-02 04:13:48 -08:00
|
|
|
|
|
|
|
// Get whether the add-on is currently disabled or set to be disabled.
|
|
|
|
var appDisabled = (ds.getItemProperty(id, "appDisabled") == "true" ||
|
|
|
|
ds.getItemProperty(id, "appDisabled") == OP_NEEDS_DISABLE);
|
|
|
|
var userDisabled = (ds.getItemProperty(id, "userDisabled") == "true" ||
|
|
|
|
ds.getItemProperty(id, "userDisabled") == OP_NEEDS_DISABLE);
|
|
|
|
var usable = this._isUsableItem(id);
|
|
|
|
var state = gBlocklist.getAddonBlocklistState(items[i].id, items[i].version);
|
|
|
|
|
|
|
|
// We only return items that are now blocked or to be warned about and aren't
|
|
|
|
// already disabled for some reason.
|
|
|
|
if (!appDisabled && !userDisabled && state != Ci.nsIBlocklistService.STATE_NOT_BLOCKED)
|
|
|
|
list.push(items[i]);
|
|
|
|
|
|
|
|
// Update the appDisabled status based on the new blocked state
|
|
|
|
if (usable)
|
2008-11-01 20:27:18 -07:00
|
|
|
this._appEnableItem(id);
|
2008-11-02 04:13:48 -08:00
|
|
|
else
|
|
|
|
this._appDisableItem(id);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-11-02 04:13:48 -08:00
|
|
|
// If the item was appDisabled and is now usable then it is something
|
|
|
|
// that is no longer hard blocked. If it is still to be warned about then
|
|
|
|
// just user disable it.
|
|
|
|
if (appDisabled && usable && !userDisabled &&
|
|
|
|
state == Ci.nsIBlocklistService.STATE_SOFTBLOCKED)
|
|
|
|
this.disableItem(id);
|
|
|
|
|
|
|
|
ds.updateProperty(id, "blocklisted");
|
|
|
|
ds.updateProperty(id, "blocklistedsoft");
|
|
|
|
}
|
2008-11-01 20:27:18 -07:00
|
|
|
|
2009-11-07 00:21:07 -08:00
|
|
|
if (itemCount)
|
|
|
|
itemCount.value = list.length;
|
2008-11-02 04:13:48 -08:00
|
|
|
return list;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns An enumeration of all registered Install Locations.
|
|
|
|
*/
|
|
|
|
get installLocations () {
|
|
|
|
return InstallLocations.enumeration;
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Gets the Install Location where a visible Item is stored.
|
|
|
|
* @param id
|
|
|
|
* The GUID of the item to locate an Install Location for.
|
|
|
|
* @returns The Install Location object where the item is stored.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
getInstallLocation: function EM_getInstallLocation(id) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var key = this.datasource.visibleItems[id];
|
|
|
|
return key ? InstallLocations.get(this.datasource.visibleItems[id]) : null;
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Gets a nsIUpdateItem for the item with the specified id.
|
|
|
|
* @param id
|
|
|
|
* The GUID of the item to construct a nsIUpdateItem for.
|
|
|
|
* @returns The nsIUpdateItem representing the item.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
getItemForID: function EM_getItemForID(id) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return this.datasource.getItemForID(id);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Retrieves a list of installed nsIUpdateItems of items that are dependent
|
|
|
|
* on another item.
|
|
|
|
* @param id
|
|
|
|
* The ID of the item that other items depend on.
|
|
|
|
* @param includeDisabled
|
|
|
|
* Whether to include disabled items in the set returned.
|
|
|
|
* @param countRef
|
|
|
|
* The XPCJS reference to the number of items returned.
|
|
|
|
* @returns An array of installed nsIUpdateItems that depend on the item
|
|
|
|
* specified by the id parameter.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
getDependentItemListForID: function EM_getDependentItemListForID(id,
|
|
|
|
includeDisabled,
|
|
|
|
countRef) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return this.datasource.getDependentItemListForID(id, includeDisabled, countRef);
|
|
|
|
},
|
|
|
|
|
2008-11-02 04:13:48 -08:00
|
|
|
/* See nsIExtensionManager.idl */
|
2008-08-15 08:23:48 -07:00
|
|
|
getItemList: function EM_getItemList(type, countRef) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return this.datasource.getItemList(type, countRef);
|
|
|
|
},
|
|
|
|
|
2007-08-29 01:16:15 -07:00
|
|
|
/* See nsIExtensionManager.idl */
|
2009-07-30 17:35:02 -07:00
|
|
|
getIncompatibleItemList: function EM_getIncompatibleItemList(appVersion,
|
2008-08-15 08:23:48 -07:00
|
|
|
platformVersion,
|
|
|
|
type,
|
|
|
|
includeDisabled,
|
|
|
|
countRef) {
|
2009-07-30 17:35:02 -07:00
|
|
|
var items = this.datasource.getIncompatibleItemList(appVersion ? appVersion : undefined,
|
2007-08-29 01:16:15 -07:00
|
|
|
platformVersion ? platformVersion : undefined,
|
2007-03-22 10:30:00 -07:00
|
|
|
type, includeDisabled);
|
2009-11-07 00:21:07 -08:00
|
|
|
if (countRef)
|
|
|
|
countRef.value = items.length;
|
2007-03-22 10:30:00 -07:00
|
|
|
return items;
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2007-03-22 10:30:00 -07:00
|
|
|
// Downloads
|
|
|
|
_transactions: [],
|
|
|
|
_downloadCount: 0,
|
2008-03-14 16:34:32 -07:00
|
|
|
_compatibilityCheckCount: 0,
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
2007-08-29 01:16:15 -07:00
|
|
|
* Ask the user if they really want to quit the application, since this will
|
2007-03-22 10:30:00 -07:00
|
|
|
* cancel one or more Extension/Theme downloads.
|
|
|
|
* @param subject
|
|
|
|
* A nsISupportsPRBool which this function sets to false if the user
|
|
|
|
* wishes to cancel all active downloads and quit the application,
|
|
|
|
* false otherwise.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_confirmCancelDownloadsOnQuit: function EM__confirmCancelDownloadsOnQuit(subject) {
|
2008-01-29 13:16:02 -08:00
|
|
|
// If user has already dismissed quit request, then do nothing
|
|
|
|
if ((subject instanceof Ci.nsISupportsPRBool) && subject.data)
|
|
|
|
return;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (this._downloadCount > 0) {
|
|
|
|
// The observers will be notified again after this so set the download
|
|
|
|
// count to 0 to prevent this dialog from being displayed again.
|
|
|
|
this._downloadCount = 0;
|
|
|
|
var result;
|
|
|
|
#ifndef XP_MACOSX
|
2007-08-29 01:16:15 -07:00
|
|
|
result = this._confirmCancelDownloads(this._downloadCount,
|
2007-03-22 10:30:00 -07:00
|
|
|
"quitCancelDownloadsAlertTitle",
|
|
|
|
"quitCancelDownloadsAlertMsgMultiple",
|
|
|
|
"quitCancelDownloadsAlertMsg",
|
|
|
|
"dontQuitButtonWin");
|
|
|
|
#else
|
|
|
|
result = this._confirmCancelDownloads(this._downloadCount,
|
|
|
|
"quitCancelDownloadsAlertTitle",
|
|
|
|
"quitCancelDownloadsAlertMsgMacMultiple",
|
|
|
|
"quitCancelDownloadsAlertMsgMac",
|
|
|
|
"dontQuitButtonMac");
|
|
|
|
#endif
|
2007-09-03 20:07:11 -07:00
|
|
|
if (subject instanceof Ci.nsISupportsPRBool)
|
2007-03-22 10:30:00 -07:00
|
|
|
subject.data = result;
|
|
|
|
}
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
2007-08-29 01:16:15 -07:00
|
|
|
* Ask the user if they really want to go offline, since this will cancel
|
2007-03-22 10:30:00 -07:00
|
|
|
* one or more Extension/Theme downloads.
|
|
|
|
* @param subject
|
|
|
|
* A nsISupportsPRBool which this function sets to false if the user
|
|
|
|
* wishes to cancel all active downloads and go offline, false
|
|
|
|
* otherwise.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_confirmCancelDownloadsOnOffline: function EM__confirmCancelDownloadsOnOffline(subject) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (this._downloadCount > 0) {
|
|
|
|
result = this._confirmCancelDownloads(this._downloadCount,
|
|
|
|
"offlineCancelDownloadsAlertTitle",
|
|
|
|
"offlineCancelDownloadsAlertMsgMultiple",
|
|
|
|
"offlineCancelDownloadsAlertMsg",
|
|
|
|
"dontGoOfflineButton");
|
2007-09-03 20:07:11 -07:00
|
|
|
if (subject instanceof Ci.nsISupportsPRBool)
|
2007-03-22 10:30:00 -07:00
|
|
|
subject.data = result;
|
|
|
|
}
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Ask the user whether or not they wish to cancel the Extension/Theme
|
|
|
|
* downloads which are currently under way.
|
|
|
|
* @param count
|
|
|
|
* The number of active downloads.
|
|
|
|
* @param title
|
|
|
|
* The key of the title for the message box to be displayed
|
|
|
|
* @param cancelMessageMultiple
|
|
|
|
* The key of the message to be displayed in the message box
|
|
|
|
* when there are > 1 active downloads.
|
|
|
|
* @param cancelMessageSingle
|
|
|
|
* The key of the message to be displayed in the message box
|
|
|
|
* when there is just one active download.
|
|
|
|
* @param dontCancelButton
|
2007-08-29 01:16:15 -07:00
|
|
|
* The key of the label to be displayed on the "Don't Cancel
|
2007-03-22 10:30:00 -07:00
|
|
|
* Downloads" button.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_confirmCancelDownloads: function EM__confirmCancelDownloads(count, title,
|
|
|
|
cancelMessageMultiple,
|
|
|
|
cancelMessageSingle,
|
|
|
|
dontCancelButton) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var bundle = BundleManager.getBundle(URI_DOWNLOADS_PROPERTIES);
|
|
|
|
var title = bundle.GetStringFromName(title);
|
|
|
|
var message, quitButton;
|
|
|
|
if (count > 1) {
|
|
|
|
message = bundle.formatStringFromName(cancelMessageMultiple, [count], 1);
|
|
|
|
quitButton = bundle.formatStringFromName("cancelDownloadsOKTextMultiple", [count], 1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
message = bundle.GetStringFromName(cancelMessageSingle);
|
|
|
|
quitButton = bundle.GetStringFromName("cancelDownloadsOKText");
|
|
|
|
}
|
|
|
|
var dontQuitButton = bundle.GetStringFromName(dontCancelButton);
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-09-03 20:07:11 -07:00
|
|
|
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
|
|
|
|
getService(Ci.nsIWindowMediator);
|
2007-03-22 10:30:00 -07:00
|
|
|
var win = wm.getMostRecentWindow("Extension:Manager");
|
2007-09-03 20:07:11 -07:00
|
|
|
const nsIPromptService = Ci.nsIPromptService;
|
|
|
|
var ps = Cc["@mozilla.org/embedcomp/prompt-service;1"].
|
|
|
|
getService(nsIPromptService);
|
2007-03-22 10:30:00 -07:00
|
|
|
var flags = (nsIPromptService.BUTTON_TITLE_IS_STRING * nsIPromptService.BUTTON_POS_0) +
|
|
|
|
(nsIPromptService.BUTTON_TITLE_IS_STRING * nsIPromptService.BUTTON_POS_1);
|
|
|
|
var rv = ps.confirmEx(win, title, message, flags, quitButton, dontQuitButton, null, null, { });
|
|
|
|
return rv == 1;
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
|
|
|
/* See nsIExtensionManager.idl */
|
2008-08-15 08:23:48 -07:00
|
|
|
addDownloads: function EM_addDownloads(items, itemCount, manager) {
|
2007-08-29 01:16:15 -07:00
|
|
|
if (itemCount == 0)
|
2007-09-03 20:07:11 -07:00
|
|
|
throw Cr.NS_ERROR_ILLEGAL_VALUE;
|
2007-08-29 01:16:15 -07:00
|
|
|
|
|
|
|
for (i = 0; i < itemCount; ++i) {
|
|
|
|
var currItem = items[i];
|
|
|
|
if (!currItem)
|
2007-09-03 20:07:11 -07:00
|
|
|
throw Cr.NS_ERROR_ILLEGAL_VALUE;
|
2007-08-29 01:16:15 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var ds = this.datasource;
|
|
|
|
// Add observers only if they aren't already added for an active download
|
|
|
|
if (this._downloadCount == 0) {
|
|
|
|
gOS.addObserver(this, "offline-requested", false);
|
|
|
|
gOS.addObserver(this, "quit-application-requested", false);
|
|
|
|
}
|
|
|
|
this._downloadCount += itemCount;
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var urls = [];
|
|
|
|
var hashes = [];
|
2007-10-19 07:00:49 -07:00
|
|
|
var txnID = Math.round(Math.random() * 100);
|
|
|
|
var txn = new ItemDownloadTransaction(this, txnID);
|
2007-03-22 10:30:00 -07:00
|
|
|
for (var i = 0; i < itemCount; ++i) {
|
|
|
|
var currItem = items[i];
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-10-19 07:00:49 -07:00
|
|
|
txn.addDownload(currItem);
|
2007-03-22 10:30:00 -07:00
|
|
|
urls.push(currItem.xpiURL);
|
|
|
|
hashes.push(currItem.xpiHash ? currItem.xpiHash : null);
|
|
|
|
// if this is an update remove the update metadata to prevent it from
|
|
|
|
// being updated during an install.
|
2007-10-19 07:00:49 -07:00
|
|
|
if (!manager) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var id = currItem.id
|
2008-12-19 04:25:27 -08:00
|
|
|
var props = {
|
2008-07-25 09:23:25 -07:00
|
|
|
availableUpdateURL: null,
|
|
|
|
availableUpdateHash: null,
|
|
|
|
availableUpdateVersion: null,
|
|
|
|
availableUpdateInfo: null
|
2008-12-19 04:25:27 -08:00
|
|
|
};
|
|
|
|
var updateVersion = ds.getItemProperty(id, "availableUpdateVersion");
|
|
|
|
var updateURL = ds.getItemProperty(id, "availableUpdateURL");
|
|
|
|
if (updateVersion && (updateURL == currItem.xpiURL))
|
|
|
|
props.newVersion = EM_L(updateVersion);
|
|
|
|
ds.setItemProperties(id, props);
|
2007-03-22 10:30:00 -07:00
|
|
|
ds.updateProperty(id, "availableUpdateURL");
|
2007-08-29 01:16:15 -07:00
|
|
|
ds.updateProperty(id, "updateable");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-10-19 07:00:49 -07:00
|
|
|
var id = !manager ? PREFIX_ITEM_URI + currItem.id : currItem.xpiURL;
|
2007-03-22 10:30:00 -07:00
|
|
|
ds.updateDownloadState(id, "waiting");
|
|
|
|
}
|
2007-08-31 04:36:42 -07:00
|
|
|
this._transactions.push(txn);
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-10-19 07:00:49 -07:00
|
|
|
if (manager) {
|
|
|
|
// XPIManager initiated -- let it know we're ready
|
|
|
|
manager.observe(txn, "xpinstall-progress", "open");
|
|
|
|
}
|
|
|
|
else {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Initiate an install from chrome
|
2007-09-03 20:07:11 -07:00
|
|
|
var xpimgr = Cc["@mozilla.org/xpinstall/install-manager;1"].
|
|
|
|
createInstance(Ci.nsIXPInstallManager);
|
2007-03-22 10:30:00 -07:00
|
|
|
xpimgr.initManagerWithHashes(urls, hashes, urls.length, txn);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2007-08-29 01:16:15 -07:00
|
|
|
* Download Operation State has changed from one to another.
|
|
|
|
*
|
2007-03-22 10:30:00 -07:00
|
|
|
* The nsIXPIProgressDialog implementation in the download transaction object
|
|
|
|
* forwards notifications through these methods which we then pass on to any
|
2007-08-29 01:16:15 -07:00
|
|
|
* front end objects implementing nsIExtensionDownloadListener that
|
|
|
|
* are listening. We maintain the master state of download operations HERE,
|
|
|
|
* not in the front end, because if the user closes the extension or theme
|
2007-03-22 10:30:00 -07:00
|
|
|
* managers during the downloads we need to maintain state and not terminate
|
2007-08-29 01:16:15 -07:00
|
|
|
* the download/install process.
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* @param transaction
|
2007-08-29 01:16:15 -07:00
|
|
|
* The ItemDownloadTransaction object receiving the download
|
2007-03-22 10:30:00 -07:00
|
|
|
* notifications from XPInstall.
|
|
|
|
* @param addon
|
|
|
|
* An object representing nsIUpdateItem for the addon being updated
|
|
|
|
* @param state
|
|
|
|
* The state we are entering
|
|
|
|
* @param value
|
|
|
|
* ???
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
onStateChange: function EM_onStateChange(transaction, addon, state, value) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var ds = this.datasource;
|
|
|
|
var id = addon.id != addon.xpiURL ? PREFIX_ITEM_URI + addon.id : addon.xpiURL;
|
2007-09-03 20:07:11 -07:00
|
|
|
const nsIXPIProgressDialog = Ci.nsIXPIProgressDialog;
|
2007-03-22 10:30:00 -07:00
|
|
|
switch (state) {
|
|
|
|
case nsIXPIProgressDialog.DOWNLOAD_START:
|
|
|
|
ds.updateDownloadState(id, "downloading");
|
2009-01-30 02:07:28 -08:00
|
|
|
this._callInstallListeners("onDownloadStarted", addon);
|
2008-03-14 16:34:32 -07:00
|
|
|
break;
|
|
|
|
case nsIXPIProgressDialog.DOWNLOAD_DONE:
|
2009-01-30 02:07:28 -08:00
|
|
|
this._callInstallListeners("onDownloadEnded", addon);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case nsIXPIProgressDialog.INSTALL_START:
|
|
|
|
ds.updateDownloadState(id, "finishing");
|
|
|
|
ds.updateDownloadProgress(id, null);
|
|
|
|
break;
|
|
|
|
case nsIXPIProgressDialog.INSTALL_DONE:
|
|
|
|
--this._downloadCount;
|
|
|
|
// From nsInstall.h
|
|
|
|
// SUCCESS = 0
|
|
|
|
// USER_CANCELLED = -210
|
2008-03-14 16:34:32 -07:00
|
|
|
if (value != 0 && value != -210 && id != addon.xpiURL) {
|
2007-03-22 10:30:00 -07:00
|
|
|
ds.updateDownloadState(id, "failure");
|
|
|
|
ds.updateDownloadProgress(id, null);
|
|
|
|
}
|
2007-10-19 07:00:49 -07:00
|
|
|
transaction.removeDownload(addon.xpiURL);
|
2008-03-14 16:34:32 -07:00
|
|
|
// A successful install will be passing notifications via installItemFromFile
|
2009-01-30 02:07:28 -08:00
|
|
|
if (value != 0)
|
|
|
|
this._callInstallListeners("onInstallEnded", addon, value);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case nsIXPIProgressDialog.DIALOG_CLOSE:
|
|
|
|
for (var i = 0; i < this._transactions.length; ++i) {
|
|
|
|
if (this._transactions[i].id == transaction.id) {
|
|
|
|
this._transactions.splice(i, 1);
|
|
|
|
// Remove the observers when all transactions have completed.
|
|
|
|
if (this._transactions.length == 0) {
|
|
|
|
gOS.removeObserver(this, "offline-requested");
|
|
|
|
gOS.removeObserver(this, "quit-application-requested");
|
2008-03-14 16:34:32 -07:00
|
|
|
|
|
|
|
// If there are no compatibility checks running then the install
|
|
|
|
// operations are complete.
|
2009-01-30 02:07:28 -08:00
|
|
|
if (this._compatibilityCheckCount == 0)
|
|
|
|
this._callInstallListeners("onInstallsCompleted");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-10-19 07:00:49 -07:00
|
|
|
// Remove any remaining downloads from this transaction
|
|
|
|
transaction.removeAllDownloads();
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
onProgress: function EM_onProgress(addon, value, maxValue) {
|
2009-01-30 02:07:28 -08:00
|
|
|
this._callInstallListeners("onDownloadProgress", addon, value, maxValue);
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var id = addon.id != addon.xpiURL ? PREFIX_ITEM_URI + addon.id : addon.xpiURL;
|
|
|
|
var progress = Math.round((value / maxValue) * 100);
|
|
|
|
this.datasource.updateDownloadProgress(id, progress);
|
|
|
|
},
|
|
|
|
|
2008-03-14 16:34:32 -07:00
|
|
|
_installListeners: [],
|
2008-08-15 08:23:48 -07:00
|
|
|
addInstallListener: function EM_addInstallListener(listener) {
|
2008-03-14 16:34:32 -07:00
|
|
|
for (var i = 0; i < this._installListeners.length; ++i) {
|
|
|
|
if (this._installListeners[i] == listener)
|
2007-03-22 10:30:00 -07:00
|
|
|
return i;
|
|
|
|
}
|
2008-03-14 16:34:32 -07:00
|
|
|
this._installListeners.push(listener);
|
|
|
|
return this._installListeners.length - 1;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
removeInstallListenerAt: function EM_removeInstallListenerAt(index) {
|
2009-01-30 02:07:28 -08:00
|
|
|
if (index < 0 || index >= this._installListeners.length)
|
2009-09-22 10:45:44 -07:00
|
|
|
throw Cr.NS_ERROR_INVALID_ARG;
|
2009-01-30 02:07:28 -08:00
|
|
|
|
|
|
|
this._installListeners[index] = null;
|
|
|
|
while (this._installListeners[this._installListeners.length - 1] === null)
|
|
|
|
this._installListeners.splice(this._installListeners.length - 1, 1);
|
|
|
|
},
|
|
|
|
|
|
|
|
_callInstallListeners: function EM__callInstallListeners(method) {
|
|
|
|
for (var i = 0; i < this._installListeners.length; ++i) {
|
|
|
|
try {
|
|
|
|
if (this._installListeners[i])
|
|
|
|
this._installListeners[i][method].apply(this._installListeners[i],
|
|
|
|
Array.slice(arguments, 1));
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
LOG("Failure in install listener's " + method + ": " + e);
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Extensions RDF Datasource
|
|
|
|
*/
|
|
|
|
_ds: null,
|
2007-07-08 03:15:11 -07:00
|
|
|
_ptr: null,
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-08-29 01:16:15 -07:00
|
|
|
/**
|
|
|
|
* Loads the Extensions Datasource. This should not be called unless:
|
2007-03-22 10:30:00 -07:00
|
|
|
* - a piece of Extensions UI is being shown, or
|
|
|
|
* - on startup and there has been a change to an Install Location
|
|
|
|
* ... it should NOT be called on every startup!
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_ensureDS: function EM__ensureDS() {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!this._ds) {
|
|
|
|
this._ds = new ExtensionsDataSource(this);
|
2007-07-08 03:15:11 -07:00
|
|
|
if (this._ds) {
|
2007-03-22 10:30:00 -07:00
|
|
|
this._ds.loadExtensions();
|
2007-08-08 02:43:36 -07:00
|
|
|
this._ptr = getContainer(this._ds, this._ds._itemRoot).DataSource;
|
2007-07-08 03:15:11 -07:00
|
|
|
gRDF.RegisterDataSource(this._ptr, true);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* See nsIExtensionManager.idl
|
|
|
|
*/
|
|
|
|
get datasource() {
|
|
|
|
this._ensureDS();
|
2008-11-28 14:20:10 -08:00
|
|
|
return this._ds;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-09-03 20:07:11 -07:00
|
|
|
// nsIClassInfo
|
|
|
|
flags: Ci.nsIClassInfo.SINGLETON,
|
|
|
|
implementationLanguage: Ci.nsIProgrammingLanguage.JAVASCRIPT,
|
|
|
|
getHelperForLanguage: function(language) null,
|
2007-03-22 10:30:00 -07:00
|
|
|
getInterfaces: function(count) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var interfaces = [Ci.nsIExtensionManager, Ci.nsIObserver];
|
2007-03-22 10:30:00 -07:00
|
|
|
count.value = interfaces.length;
|
|
|
|
return interfaces;
|
|
|
|
},
|
|
|
|
|
2007-09-03 20:07:11 -07:00
|
|
|
classDescription: "Extension Manager",
|
|
|
|
contractID: "@mozilla.org/extensions/manager;1",
|
|
|
|
classID: Components.ID("{8A115FAA-7DCB-4e8f-979B-5F53472F51CF}"),
|
2009-09-18 11:03:27 -07:00
|
|
|
_xpcom_categories: [{ category: "profile-after-change" },
|
|
|
|
{ category: "update-timer",
|
|
|
|
value: "@mozilla.org/extensions/manager;1," +
|
|
|
|
"getService,addon-background-update-timer," +
|
|
|
|
PREF_EM_UPDATE_INTERVAL + ",86400" }],
|
2008-08-14 02:43:43 -07:00
|
|
|
_xpcom_factory: {
|
|
|
|
createInstance: function(outer, iid) {
|
|
|
|
if (outer != null)
|
|
|
|
throw Cr.NS_ERROR_NO_AGGREGATION;
|
|
|
|
|
|
|
|
if (!gEmSingleton)
|
|
|
|
gEmSingleton = new ExtensionManager();
|
|
|
|
return gEmSingleton.QueryInterface(iid);
|
|
|
|
}
|
|
|
|
},
|
2007-09-03 20:07:11 -07:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIExtensionManager,
|
|
|
|
Ci.nsITimerCallback,
|
|
|
|
Ci.nsIObserver,
|
|
|
|
Ci.nsIClassInfo])
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This object implements nsIXPIProgressDialog and represents a collection of
|
2007-08-29 01:16:15 -07:00
|
|
|
* XPI/JAR download and install operations. There is one
|
2007-03-22 10:30:00 -07:00
|
|
|
* ItemDownloadTransaction per back-end XPInstallManager object. We maintain
|
|
|
|
* a collection of separate transaction objects because it's possible to have
|
2007-08-29 01:16:15 -07:00
|
|
|
* multiple separate XPInstall download/install operations going on
|
2007-03-22 10:30:00 -07:00
|
|
|
* simultaneously, each with its own XPInstallManager instance. For instance
|
|
|
|
* you could start downloading two extensions and then download a theme. Each
|
|
|
|
* of these operations would open the appropriate FE and have to be able to
|
|
|
|
* track each operation independently.
|
2007-08-29 01:16:15 -07:00
|
|
|
*
|
2007-03-22 10:30:00 -07:00
|
|
|
* @constructor
|
2007-10-19 07:00:49 -07:00
|
|
|
* @param manager
|
|
|
|
* The extension manager creating this transaction
|
|
|
|
* @param id
|
|
|
|
* The integer identifier of this transaction
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2007-10-19 07:00:49 -07:00
|
|
|
function ItemDownloadTransaction(manager, id) {
|
2007-03-22 10:30:00 -07:00
|
|
|
this._manager = manager;
|
|
|
|
this._downloads = [];
|
2007-10-19 07:00:49 -07:00
|
|
|
this.id = id;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
ItemDownloadTransaction.prototype = {
|
|
|
|
_manager : null,
|
|
|
|
_downloads : [],
|
|
|
|
id : -1,
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Add a download to this transaction
|
|
|
|
* @param addon
|
|
|
|
* An object implementing nsIUpdateItem for the item to be downloaded
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
addDownload: function ItemDownloadTransaction_addDownload(addon) {
|
2007-03-22 10:30:00 -07:00
|
|
|
this._downloads.push({ addon: addon, waiting: true });
|
|
|
|
this._manager.datasource.addDownload(addon);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Removes a download from this transaction
|
|
|
|
* @param url
|
|
|
|
* The URL to remove
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
removeDownload: function ItemDownloadTransaction_removeDownload(url) {
|
2007-03-22 10:30:00 -07:00
|
|
|
this._manager.datasource.removeDownload(url);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Remove all downloads from this transaction
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
removeAllDownloads: function ItemDownloadTransaction_removeAllDownloads() {
|
2007-03-22 10:30:00 -07:00
|
|
|
for (var i = 0; i < this._downloads.length; ++i) {
|
|
|
|
var addon = this._downloads[i].addon;
|
|
|
|
this.removeDownload(addon.xpiURL);
|
|
|
|
}
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Determine if this transaction is handling the download of a url.
|
|
|
|
* @param url
|
|
|
|
* The URL to look for
|
|
|
|
* @returns true if this transaction is downloading the supplied url.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
containsURL: function ItemDownloadTransaction_containsURL(url) {
|
2007-03-22 10:30:00 -07:00
|
|
|
for (var i = 0; i < this._downloads.length; ++i) {
|
|
|
|
if (this._downloads[i].addon.xpiURL == url)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* See nsIXPIProgressDialog.idl
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
onStateChange: function ItemDownloadTransaction_onStateChange(index, state, value) {
|
2007-08-29 01:16:15 -07:00
|
|
|
this._manager.onStateChange(this, this._downloads[index].addon,
|
2007-03-22 10:30:00 -07:00
|
|
|
state, value);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* See nsIXPIProgressDialog.idl
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
onProgress: function ItemDownloadTransaction_onProgress(index, value, maxValue) {
|
2007-03-22 10:30:00 -07:00
|
|
|
this._manager.onProgress(this._downloads[index].addon, value, maxValue);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-09-03 20:07:11 -07:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIXPIProgressDialog])
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2007-09-04 09:44:04 -07:00
|
|
|
/**
|
|
|
|
* A listener object that watches the background update check and notifies the
|
|
|
|
* user of any updates found.
|
|
|
|
*/
|
|
|
|
function BackgroundUpdateCheckListener(datasource) {
|
|
|
|
this._emDS = datasource;
|
|
|
|
}
|
|
|
|
BackgroundUpdateCheckListener.prototype = {
|
|
|
|
_updateCount: 0,
|
|
|
|
_emDS: null,
|
|
|
|
|
|
|
|
// nsIObserver implementation
|
2008-08-15 08:23:48 -07:00
|
|
|
observe: function BackgroundUpdateListener_observe(aSubject, aTopic, aData) {
|
2007-09-04 09:44:04 -07:00
|
|
|
if (aTopic != "alertclickcallback")
|
|
|
|
return;
|
|
|
|
|
|
|
|
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
|
|
|
|
getService(Ci.nsIWindowMediator);
|
|
|
|
var win = wm.getMostRecentWindow("Extension:Manager");
|
|
|
|
if (win) {
|
|
|
|
win.focus();
|
|
|
|
win.showView("updates");
|
|
|
|
// Don't show the update notification on next startup
|
|
|
|
gPref.setBoolPref(PREF_UPDATE_NOTIFYUSER, false);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
|
|
|
|
getService(Ci.nsIWindowWatcher);
|
|
|
|
var param = Cc["@mozilla.org/supports-array;1"].
|
|
|
|
createInstance(Ci.nsISupportsArray);
|
|
|
|
var arg = Cc["@mozilla.org/supports-string;1"].
|
|
|
|
createInstance(Ci.nsISupportsString);
|
|
|
|
arg.data = "updates";
|
|
|
|
param.AppendElement(arg);
|
2009-09-17 02:03:33 -07:00
|
|
|
ww.openWindow(null, URI_EXTENSION_MANAGER, null, FEATURES_EXTENSION_MANAGER, param);
|
2007-09-04 09:44:04 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// nsIAddonUpdateCheckListener implementation
|
2008-08-15 08:23:48 -07:00
|
|
|
onUpdateStarted: function BackgroundUpdateListener_onUpdateStarted() {
|
2007-09-04 09:44:04 -07:00
|
|
|
},
|
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
onUpdateEnded: function BackgroundUpdateListener_onUpdateEnded() {
|
2007-09-04 09:44:04 -07:00
|
|
|
if (this._updateCount > 0 && Cc["@mozilla.org/alerts-service;1"]) {
|
|
|
|
var extensionStrings = BundleManager.getBundle(URI_EXTENSIONS_PROPERTIES);
|
|
|
|
var title = extensionStrings.GetStringFromName("updateNotificationTitle");
|
|
|
|
var text;
|
|
|
|
if (this._updateCount > 1)
|
|
|
|
text = extensionStrings.formatStringFromName("multipleUpdateNotificationText",
|
|
|
|
[BundleManager.appName, this._updateCount], 2);
|
|
|
|
else
|
|
|
|
text = extensionStrings.formatStringFromName("updateNotificationText",
|
|
|
|
[BundleManager.appName], 1);
|
|
|
|
|
|
|
|
try {
|
|
|
|
var notifier = Cc["@mozilla.org/alerts-service;1"].
|
|
|
|
getService(Ci.nsIAlertsService);
|
|
|
|
notifier.showAlertNotification(URI_GENERIC_ICON_XPINSTALL,
|
|
|
|
title, text, true, "", this);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
LOG("Failed to retrieve alerts service, probably an unsupported " +
|
|
|
|
"platform - " + e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
onAddonUpdateStarted: function BackgroundUpdateListener_onAddonUpdateStarted(item) {
|
2007-09-04 09:44:04 -07:00
|
|
|
},
|
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
onAddonUpdateEnded: function BackgroundUpdateListener_onAddonUpdateEnded(item, status) {
|
2007-09-17 11:05:04 -07:00
|
|
|
if (status == Ci.nsIAddonUpdateCheckListener.STATUS_UPDATE) {
|
2007-09-04 09:44:04 -07:00
|
|
|
var lastupdate = this._emDS.getItemProperty(item.id, "availableUpdateVersion");
|
|
|
|
if (lastupdate != item.version) {
|
|
|
|
gPref.setBoolPref(PREF_UPDATE_NOTIFYUSER, true);
|
|
|
|
this._updateCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* A listener object to the update check process that routes notifications to
|
|
|
|
* the right places and keeps the datasource up to date.
|
|
|
|
*/
|
|
|
|
function AddonUpdateCheckListener(listener, datasource) {
|
|
|
|
this._listener = listener;
|
|
|
|
this._ds = datasource;
|
|
|
|
}
|
|
|
|
AddonUpdateCheckListener.prototype = {
|
|
|
|
_listener: null,
|
|
|
|
_ds: null,
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
onUpdateStarted: function AddonUpdateListener_onUpdateStarted() {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (this._listener)
|
|
|
|
this._listener.onUpdateStarted();
|
|
|
|
this._ds.onUpdateStarted();
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
onUpdateEnded: function AddonUpdateListener_onUpdateEnded() {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (this._listener)
|
|
|
|
this._listener.onUpdateEnded();
|
|
|
|
this._ds.onUpdateEnded();
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
onAddonUpdateStarted: function AddonUpdateListener_onAddonUpdateStarted(addon) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (this._listener)
|
|
|
|
this._listener.onAddonUpdateStarted(addon);
|
|
|
|
this._ds.onAddonUpdateStarted(addon);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
onAddonUpdateEnded: function AddonUpdateListener_onAddonUpdateEnded(addon, status) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (this._listener)
|
|
|
|
this._listener.onAddonUpdateEnded(addon, status);
|
|
|
|
this._ds.onAddonUpdateEnded(addon, status);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// ExtensionItemUpdater
|
|
|
|
//
|
2007-11-17 04:52:03 -08:00
|
|
|
function ExtensionItemUpdater(aEM)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
this._emDS = aEM._ds;
|
|
|
|
this._em = aEM;
|
|
|
|
|
|
|
|
getVersionChecker();
|
|
|
|
}
|
|
|
|
|
|
|
|
ExtensionItemUpdater.prototype = {
|
|
|
|
_emDS : null,
|
|
|
|
_em : null,
|
2007-06-25 08:51:51 -07:00
|
|
|
_updateCheckType : 0,
|
2009-09-10 11:50:41 -07:00
|
|
|
_updateType : 0,
|
2007-03-22 10:30:00 -07:00
|
|
|
_items : [],
|
|
|
|
_listener : null,
|
2007-08-16 14:17:45 -07:00
|
|
|
|
|
|
|
/* ExtensionItemUpdater
|
|
|
|
#
|
|
|
|
# When we check for updates to an item, there are two pieces of information
|
|
|
|
# that are returned - 1) info about the newest available version, if any,
|
|
|
|
# and 2) info about the currently installed version. The latter is provided
|
2007-08-29 01:16:15 -07:00
|
|
|
# primarily to inform the client of changes to the application compatibility
|
|
|
|
# metadata for the current item. Depending on the situation, either 2 or
|
2007-08-16 14:17:45 -07:00
|
|
|
# 1&2 may be what is required.
|
|
|
|
#
|
|
|
|
# Callers:
|
|
|
|
# 1 - nsUpdateService.js, user event
|
2007-08-29 01:16:15 -07:00
|
|
|
# User clicked on the update icon to invoke an update check,
|
2007-08-16 14:17:45 -07:00
|
|
|
# user clicked on an Extension/Theme and clicked "Update". In this
|
|
|
|
# case we want to update compatibility metadata about the installed
|
2007-08-29 01:16:15 -07:00
|
|
|
# version, and look for newer versions to offer.
|
2007-08-16 14:17:45 -07:00
|
|
|
# 2 - nsUpdateService.js, background event
|
|
|
|
# Timer fired, background update is being performed. In this case
|
2008-10-21 17:48:52 -07:00
|
|
|
# we also want to check for compatibility metadata and newer
|
|
|
|
# versions that will make the add-on compatible.
|
2007-08-16 14:17:45 -07:00
|
|
|
# 3 - Mismatch
|
|
|
|
# User upgraded to a newer version of the app, update compatibility
|
|
|
|
# metadata and look for newer versions.
|
|
|
|
# 4 - Install Phone Home
|
|
|
|
# User installed an item that was deemed incompatible based only
|
2007-08-29 01:16:15 -07:00
|
|
|
# on the information provided in the item's install.rdf manifest,
|
2007-08-16 14:17:45 -07:00
|
|
|
# we look ONLY for compatibility updates in this case to determine
|
|
|
|
# whether or not the item can be installed.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
checkForUpdates: function ExtensionItemUpdater_checkForUpdates(aItems,
|
|
|
|
aItemCount,
|
|
|
|
aUpdateCheckType,
|
2008-10-21 17:48:52 -07:00
|
|
|
aListener,
|
2009-09-10 11:50:41 -07:00
|
|
|
aUpdateType,
|
2008-10-21 17:48:52 -07:00
|
|
|
aAppVersion,
|
|
|
|
aPlatformVersion) {
|
|
|
|
if (aUpdateCheckType == Ci.nsIExtensionManager.UPDATE_NOTIFY_NEWVERSION) {
|
|
|
|
this._listener = aListener;
|
|
|
|
this._appVersion = aAppVersion ? aAppVersion : gApp.version;
|
|
|
|
this._platformVersion = aPlatformVersion ? aPlatformVersion
|
|
|
|
: gApp.platformVersion;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this._listener = new AddonUpdateCheckListener(aListener, this._emDS);
|
|
|
|
this._appVersion = gApp.version;
|
|
|
|
this._platformVersion = gApp.platformVersion;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (this._listener)
|
|
|
|
this._listener.onUpdateStarted();
|
2007-06-25 08:51:51 -07:00
|
|
|
this._updateCheckType = aUpdateCheckType;
|
2007-03-22 10:30:00 -07:00
|
|
|
this._items = aItems;
|
|
|
|
this._responseCount = aItemCount;
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2009-09-10 11:50:41 -07:00
|
|
|
this._updateType = aUpdateType;
|
|
|
|
// All update check types look for compatibility currently
|
|
|
|
this._updateType |= UPDATE_TYPE_COMPATIBILITY;
|
|
|
|
// Only two types also look for new versions
|
|
|
|
if (aUpdateCheckType == Ci.nsIExtensionManager.UPDATE_NOTIFY_NEWVERSION ||
|
|
|
|
aUpdateCheckType == Ci.nsIExtensionManager.UPDATE_CHECK_NEWVERSION)
|
|
|
|
this._updateType |= UPDATE_TYPE_NEWVERSION;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// This is the number of extensions/themes/etc that we found updates for.
|
|
|
|
this._updateCount = 0;
|
|
|
|
|
|
|
|
for (var i = 0; i < aItemCount; ++i) {
|
|
|
|
var e = this._items[i];
|
|
|
|
if (this._listener)
|
|
|
|
this._listener.onAddonUpdateStarted(e);
|
2007-06-25 08:51:51 -07:00
|
|
|
(new RDFItemUpdater(this)).checkForUpdates(e, aUpdateCheckType);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-09-05 00:33:15 -07:00
|
|
|
|
|
|
|
if (this._listener && aItemCount == 0)
|
|
|
|
this._listener.onUpdateEnded();
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// ExtensionItemUpdater
|
2008-08-15 08:23:48 -07:00
|
|
|
_applyVersionUpdates: function ExtensionItemUpdater__applyVersionUpdates(aLocalItem,
|
|
|
|
aRemoteItem) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var targetAppInfo = this._emDS.getTargetApplicationInfo(aLocalItem.id, this._emDS);
|
|
|
|
// If targetAppInfo is null this is for a new install. If the local item's
|
|
|
|
// maxVersion does not equal the targetAppInfo maxVersion then this is for
|
|
|
|
// an upgrade. In both of these cases return true if the remotely specified
|
|
|
|
// maxVersion is greater than the local item's maxVersion.
|
|
|
|
if (!targetAppInfo ||
|
|
|
|
gVersionChecker.compare(aLocalItem.maxAppVersion, targetAppInfo.maxVersion) != 0) {
|
|
|
|
if (gVersionChecker.compare(aLocalItem.maxAppVersion, aRemoteItem.maxAppVersion) < 0)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gVersionChecker.compare(targetAppInfo.maxVersion, aRemoteItem.maxAppVersion) < 0) {
|
2007-08-29 01:16:15 -07:00
|
|
|
// Remotely specified maxVersion is newer than the maxVersion
|
2007-03-22 10:30:00 -07:00
|
|
|
// for the installed Extension. Apply that change to the datasources.
|
2007-12-11 16:56:09 -08:00
|
|
|
this._emDS.setTargetApplicationInfo(aLocalItem.id,
|
|
|
|
aRemoteItem.targetAppID,
|
|
|
|
aRemoteItem.minAppVersion,
|
|
|
|
aRemoteItem.maxAppVersion,
|
|
|
|
null);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// If we got here through |checkForMismatches|, this extension has
|
|
|
|
// already been disabled, re-enable it.
|
|
|
|
var op = StartupCache.entries[aLocalItem.installLocationKey][aLocalItem.id].op;
|
|
|
|
if (op == OP_NEEDS_DISABLE ||
|
|
|
|
this._emDS.getItemProperty(aLocalItem.id, "appDisabled") == "true")
|
|
|
|
this._em._appEnableItem(aLocalItem.id);
|
|
|
|
return true;
|
|
|
|
}
|
2007-09-17 11:05:04 -07:00
|
|
|
else if (this._updateCheckType == Ci.nsIExtensionManager.UPDATE_SYNC_COMPATIBILITY)
|
2007-12-11 16:56:09 -08:00
|
|
|
this._emDS.setTargetApplicationInfo(aLocalItem.id,
|
|
|
|
aRemoteItem.targetAppID,
|
|
|
|
aRemoteItem.minAppVersion,
|
|
|
|
aRemoteItem.maxAppVersion,
|
|
|
|
null);
|
2007-03-22 10:30:00 -07:00
|
|
|
return false;
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-07-06 07:41:56 -07:00
|
|
|
/**
|
|
|
|
* Checks whether a discovered update is valid for install
|
|
|
|
* @param aLocalItem
|
|
|
|
* The already installed nsIUpdateItem that the update is for
|
2007-08-29 01:16:15 -07:00
|
|
|
* @param aRemoteItem
|
|
|
|
* The nsIUpdateItem we are trying to update to
|
2008-11-26 07:04:13 -08:00
|
|
|
* @param aUpdateCheckType
|
|
|
|
* The type of update check being performed
|
2007-08-29 01:16:15 -07:00
|
|
|
*
|
|
|
|
* @returns true if the item is compatible and is not blocklisted.
|
|
|
|
* false if the item is not compatible or is blocklisted.
|
|
|
|
*/
|
2008-11-26 07:04:13 -08:00
|
|
|
_isValidUpdate: function _isValidUpdate(aLocalItem, aRemoteItem, aUpdateCheckType) {
|
2007-08-29 01:16:15 -07:00
|
|
|
var appExtensionsVersion = (aRemoteItem.targetAppID != TOOLKIT_ID) ?
|
2008-10-21 17:48:52 -07:00
|
|
|
this._appVersion :
|
|
|
|
this._platformVersion;
|
2007-08-29 01:16:15 -07:00
|
|
|
|
|
|
|
var min = aRemoteItem.minAppVersion;
|
|
|
|
var max = aRemoteItem.maxAppVersion;
|
|
|
|
// Check if the update will only run on a newer version of the application.
|
2007-08-30 11:26:37 -07:00
|
|
|
if (!min || gVersionChecker.compare(appExtensionsVersion, min) < 0)
|
2007-03-22 10:30:00 -07:00
|
|
|
return false;
|
|
|
|
|
2007-08-29 01:16:15 -07:00
|
|
|
// Check if the update will only run on an older version of the application.
|
2007-08-30 11:26:37 -07:00
|
|
|
if (!max || gVersionChecker.compare(appExtensionsVersion, max) > 0)
|
2007-03-22 10:30:00 -07:00
|
|
|
return false;
|
|
|
|
|
2008-11-26 07:04:13 -08:00
|
|
|
// Ignore the blocklist for compatibility only checks.
|
|
|
|
if (aUpdateCheckType != Ci.nsIExtensionManager.UPDATE_CHECK_COMPATIBILITY) {
|
|
|
|
if (!gBlocklist)
|
|
|
|
gBlocklist = Cc["@mozilla.org/extensions/blocklist;1"].
|
|
|
|
getService(Ci.nsIBlocklistService);
|
|
|
|
// Denies updates that are hard blocked, soft blocked items will be warned
|
|
|
|
// about during the install.
|
|
|
|
if (gBlocklist.isAddonBlocklisted(aLocalItem.id, aRemoteItem.version,
|
|
|
|
this._appVersion, this._platformVersion))
|
|
|
|
return false;
|
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return true;
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
checkForDone: function ExtensionItemUpdater_checkForDone(item, status) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (this._listener) {
|
|
|
|
try {
|
|
|
|
this._listener.onAddonUpdateEnded(item, status);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
LOG("ExtensionItemUpdater:checkForDone: Failure in listener's onAddonUpdateEnded: " + e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (--this._responseCount == 0 && this._listener) {
|
|
|
|
try {
|
|
|
|
this._listener.onUpdateEnded();
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
LOG("ExtensionItemUpdater:checkForDone: Failure in listener's onUpdateEnded: " + e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2007-11-17 04:52:03 -08:00
|
|
|
/**
|
|
|
|
* Replaces %...% strings in an addon url (update and updateInfo) with
|
|
|
|
* appropriate values.
|
|
|
|
* @param aItem
|
|
|
|
* The nsIUpdateItem representing the item
|
2009-09-10 11:50:41 -07:00
|
|
|
* @param aAppVersion
|
|
|
|
* The application version to check for updates for
|
|
|
|
* @param aUpdateType
|
|
|
|
* The type of the update (see nsIExtensionManager)
|
2007-11-17 04:52:03 -08:00
|
|
|
* @param aURI
|
|
|
|
* The uri to escape
|
|
|
|
* @param aDS
|
|
|
|
* The extensions datasource
|
|
|
|
*
|
|
|
|
* @returns the appropriately escaped uri.
|
|
|
|
*/
|
2009-09-10 11:50:41 -07:00
|
|
|
function escapeAddonURI(aItem, aAppVersion, aUpdateType, aURI, aDS)
|
2007-11-17 04:52:03 -08:00
|
|
|
{
|
2008-01-18 10:20:04 -08:00
|
|
|
var itemStatus = "userEnabled";
|
2007-11-17 04:52:03 -08:00
|
|
|
if (aDS.getItemProperty(aItem.id, "userDisabled") == "true" ||
|
|
|
|
aDS.getItemProperty(aItem.id, "userDisabled") == OP_NEEDS_ENABLE)
|
|
|
|
itemStatus = "userDisabled";
|
2008-01-18 10:20:04 -08:00
|
|
|
else if (aDS.getItemProperty(aItem.id, "type") == Ci.nsIUpdateItem.TYPE_THEME) {
|
|
|
|
var currentSkin = gPref.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN);
|
|
|
|
if (aDS.getItemProperty(aItem.id, "internalName") != currentSkin)
|
|
|
|
itemStatus = "userDisabled";
|
|
|
|
}
|
2007-11-17 04:52:03 -08:00
|
|
|
|
|
|
|
if (aDS.getItemProperty(aItem.id, "compatible") == "false")
|
|
|
|
itemStatus += ",incompatible";
|
|
|
|
if (aDS.getItemProperty(aItem.id, "blocklisted") == "true")
|
|
|
|
itemStatus += ",blocklisted";
|
|
|
|
if (aDS.getItemProperty(aItem.id, "satisfiesDependencies") == "false")
|
|
|
|
itemStatus += ",needsDependencies";
|
|
|
|
|
|
|
|
aURI = aURI.replace(/%ITEM_ID%/g, aItem.id);
|
|
|
|
aURI = aURI.replace(/%ITEM_VERSION%/g, aItem.version);
|
|
|
|
aURI = aURI.replace(/%ITEM_MAXAPPVERSION%/g, aItem.maxAppVersion);
|
|
|
|
aURI = aURI.replace(/%ITEM_STATUS%/g, itemStatus);
|
|
|
|
aURI = aURI.replace(/%APP_ID%/g, gApp.ID);
|
2008-10-21 17:48:52 -07:00
|
|
|
aURI = aURI.replace(/%APP_VERSION%/g, aAppVersion ? aAppVersion : gApp.version);
|
2008-11-04 21:50:52 -08:00
|
|
|
aURI = aURI.replace(/%REQ_VERSION%/g, REQ_VERSION);
|
2007-11-17 04:52:03 -08:00
|
|
|
aURI = aURI.replace(/%APP_OS%/g, gOSTarget);
|
|
|
|
aURI = aURI.replace(/%APP_ABI%/g, gXPCOMABI);
|
|
|
|
aURI = aURI.replace(/%APP_LOCALE%/g, gLocale);
|
2008-10-21 17:48:52 -07:00
|
|
|
aURI = aURI.replace(/%CURRENT_APP_VERSION%/g, gApp.version);
|
2009-09-10 11:50:41 -07:00
|
|
|
if (aUpdateType)
|
|
|
|
aURI = aURI.replace(/%UPDATE_TYPE%/g, aUpdateType);
|
2007-11-17 04:52:03 -08:00
|
|
|
|
|
|
|
// Replace custom parameters (names of custom parameters must have at
|
|
|
|
// least 3 characters to prevent lookups for something like %D0%C8)
|
|
|
|
var catMan = null;
|
|
|
|
aURI = aURI.replace(/%(\w{3,})%/g, function(match, param) {
|
|
|
|
if (!catMan) {
|
|
|
|
catMan = Cc["@mozilla.org/categorymanager;1"].
|
|
|
|
getService(Ci.nsICategoryManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
var contractID = catMan.getCategoryEntry(CATEGORY_UPDATE_PARAMS, param);
|
|
|
|
var paramHandler = Cc[contractID].
|
|
|
|
getService(Ci.nsIPropertyBag2);
|
|
|
|
return paramHandler.getPropertyAsAString(param);
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
return match;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// escape() does not properly encode + symbols in any embedded FVF strings.
|
|
|
|
return aURI.replace(/\+/g, "%2B");
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
function RDFItemUpdater(aUpdater) {
|
|
|
|
this._updater = aUpdater;
|
|
|
|
}
|
|
|
|
|
|
|
|
RDFItemUpdater.prototype = {
|
|
|
|
_updater : null,
|
2007-06-25 08:51:51 -07:00
|
|
|
_updateCheckType : 0,
|
2007-03-22 10:30:00 -07:00
|
|
|
_item : null,
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
checkForUpdates: function RDFItemUpdater_checkForUpdates(aItem, aUpdateCheckType) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// A preference setting can disable updating for this item
|
|
|
|
try {
|
|
|
|
if (!gPref.getBoolPref(PREF_EM_ITEM_UPDATE_ENABLED.replace(/%UUID%/, aItem.id))) {
|
2007-09-17 11:05:04 -07:00
|
|
|
var status = Ci.nsIAddonUpdateCheckListener.STATUS_DISABLED;
|
2007-03-22 10:30:00 -07:00
|
|
|
this._updater.checkForDone(aItem, status);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e) { }
|
|
|
|
|
|
|
|
// Items managed by the app are not checked for updates.
|
|
|
|
var emDS = this._updater._emDS;
|
|
|
|
if (emDS.getItemProperty(aItem.id, "appManaged") == "true") {
|
2007-09-17 11:05:04 -07:00
|
|
|
var status = Ci.nsIAddonUpdateCheckListener.STATUS_APP_MANAGED;
|
2007-03-22 10:30:00 -07:00
|
|
|
this._updater.checkForDone(aItem, status);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Items that have a pending install, uninstall, or upgrade are not checked
|
|
|
|
// for updates.
|
|
|
|
var opType = emDS.getItemProperty(aItem.id, "opType");
|
2007-08-02 11:16:49 -07:00
|
|
|
if (opType) {
|
2007-09-17 11:05:04 -07:00
|
|
|
var status = Ci.nsIAddonUpdateCheckListener.STATUS_PENDING_OP;
|
2007-03-22 10:30:00 -07:00
|
|
|
this._updater.checkForDone(aItem, status);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var installLocation = InstallLocations.get(emDS.getInstallLocationKey(aItem.id));
|
2008-01-15 07:13:59 -08:00
|
|
|
// Don't check items for updates that are managed independently
|
|
|
|
if (installLocation && installLocation.itemIsManagedIndependently(aItem.id)) {
|
2007-09-17 11:05:04 -07:00
|
|
|
var status = Ci.nsIAddonUpdateCheckListener.STATUS_NOT_MANAGED;
|
2007-03-22 10:30:00 -07:00
|
|
|
this._updater.checkForDone(aItem, status);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't check items for updates if the location can't be written to except
|
|
|
|
// when performing a version only update.
|
2008-10-21 17:48:52 -07:00
|
|
|
if ((aUpdateCheckType == Ci.nsIExtensionManager.UPDATE_CHECK_NEWVERSION ||
|
|
|
|
aUpdateCheckType == Ci.nsIExtensionManager.UPDATE_NOTIFY_NEWVERSION) &&
|
2007-06-25 08:51:51 -07:00
|
|
|
(!installLocation || !installLocation.canAccess)) {
|
2007-09-17 11:05:04 -07:00
|
|
|
var status = Ci.nsIAddonUpdateCheckListener.STATUS_READ_ONLY;
|
2007-03-22 10:30:00 -07:00
|
|
|
this._updater.checkForDone(aItem, status);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-06-25 08:51:51 -07:00
|
|
|
this._updateCheckType = aUpdateCheckType;
|
2007-03-22 10:30:00 -07:00
|
|
|
this._item = aItem;
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Look for a custom update URI: 1) supplied by a pref, 2) supplied by the
|
|
|
|
// install manifest, 3) the default configuration
|
|
|
|
try {
|
|
|
|
var dsURI = gPref.getComplexValue(PREF_EM_ITEM_UPDATE_URL.replace(/%UUID%/, aItem.id),
|
2007-09-03 20:07:11 -07:00
|
|
|
Ci.nsIPrefLocalizedString).data;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
catch (e) { }
|
|
|
|
if (!dsURI)
|
|
|
|
dsURI = aItem.updateRDF;
|
2008-02-21 23:08:15 -08:00
|
|
|
if (!dsURI)
|
|
|
|
dsURI = gPref.getCharPref(PREF_UPDATE_DEFAULT_URL);
|
2007-08-15 00:49:12 -07:00
|
|
|
|
2009-09-10 11:50:41 -07:00
|
|
|
dsURI = escapeAddonURI(aItem, this._updater._appVersion,
|
|
|
|
this._updater._updateType, dsURI, emDS);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Verify that the URI provided is valid
|
|
|
|
try {
|
|
|
|
var uri = newURI(dsURI);
|
|
|
|
}
|
|
|
|
catch (e) {
|
2009-08-19 03:32:15 -07:00
|
|
|
WARN("RDFItemUpdater:checkForUpdates: There was an error loading the \r\n" +
|
|
|
|
" update datasource for: " + dsURI + ", item = " + aItem.id + ", error: " + e);
|
2007-08-29 01:16:15 -07:00
|
|
|
this._updater.checkForDone(aItem,
|
2007-09-17 11:05:04 -07:00
|
|
|
Ci.nsIAddonUpdateCheckListener.STATUS_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-08-29 01:16:15 -07:00
|
|
|
LOG("RDFItemUpdater:checkForUpdates sending a request to server for: " +
|
|
|
|
uri.spec + ", item = " + aItem.objectSource);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-09-03 20:07:11 -07:00
|
|
|
var request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].
|
2008-01-28 09:11:48 -08:00
|
|
|
createInstance(Ci.nsIXMLHttpRequest);
|
2007-03-22 10:30:00 -07:00
|
|
|
request.open("GET", uri.spec, true);
|
2009-10-13 12:45:20 -07:00
|
|
|
request.channel.notificationCallbacks = new gCertUtils.BadCertHandler();
|
2007-03-22 10:30:00 -07:00
|
|
|
request.overrideMimeType("text/xml");
|
2007-09-03 20:07:11 -07:00
|
|
|
request.channel.loadFlags |= Ci.nsIRequest.LOAD_BYPASS_CACHE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
var self = this;
|
|
|
|
request.onerror = function(event) { self.onXMLError(event, aItem); };
|
|
|
|
request.onload = function(event) { self.onXMLLoad(event, aItem); };
|
|
|
|
request.send(null);
|
|
|
|
},
|
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
onXMLLoad: function RDFItemUpdater_onXMLLoad(aEvent, aItem) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var request = aEvent.target;
|
|
|
|
try {
|
2009-10-13 12:45:20 -07:00
|
|
|
gCertUtils.checkCert(request.channel);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
// This may be overly restrictive in two cases: corporate installations
|
|
|
|
// with a corporate update server using an in-house CA cert (installed
|
|
|
|
// but not "built-in") and lone developers hosting their updates on a
|
|
|
|
// site with a self-signed cert (permanently accepted, otherwise the
|
|
|
|
// BadCertHandler would prevent getting this far). Update checks will
|
|
|
|
// fail in both these scenarios.
|
|
|
|
// How else can we protect the vast majority of updates served from AMO
|
|
|
|
// from the spoofing attack described in bug 340198 while allowing those
|
|
|
|
// other cases? A "hackme" pref? Domain-control certs are cheap, getting
|
|
|
|
// one should not be a barrier in either case.
|
|
|
|
LOG("RDFItemUpdater::onXMLLoad: " + e);
|
|
|
|
this._updater.checkForDone(aItem,
|
2007-09-17 11:05:04 -07:00
|
|
|
Ci.nsIAddonUpdateCheckListener.STATUS_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
var responseXML = request.responseXML;
|
|
|
|
|
|
|
|
// If the item does not have an update RDF and returns an error it is not
|
|
|
|
// treated as a failure since all items without an updateURL are checked
|
|
|
|
// for updates on AMO even if they are not hosted there.
|
|
|
|
if (!responseXML || responseXML.documentElement.namespaceURI == XMLURI_PARSE_ERROR ||
|
|
|
|
(request.status != 200 && request.status != 0)) {
|
2007-09-17 11:05:04 -07:00
|
|
|
this._updater.checkForDone(aItem, (aItem.updateRDF ? Ci.nsIAddonUpdateCheckListener.STATUS_FAILURE :
|
|
|
|
Ci.nsIAddonUpdateCheckListener.STATUS_NONE));
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-09-03 20:07:11 -07:00
|
|
|
var rdfParser = Cc["@mozilla.org/rdf/xml-parser;1"].
|
|
|
|
createInstance(Ci.nsIRDFXMLParser)
|
|
|
|
var ds = Cc["@mozilla.org/rdf/datasource;1?name=in-memory-datasource"].
|
|
|
|
createInstance(Ci.nsIRDFDataSource);
|
2007-03-22 10:30:00 -07:00
|
|
|
rdfParser.parseString(ds, request.channel.URI, request.responseText);
|
|
|
|
|
|
|
|
this.onDatasourceLoaded(ds, aItem);
|
|
|
|
},
|
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
onXMLError: function RDFItemUpdater_onXMLError(aEvent, aItem) {
|
2007-03-22 10:30:00 -07:00
|
|
|
try {
|
|
|
|
var request = aEvent.target;
|
|
|
|
// the following may throw (e.g. a local file or timeout)
|
|
|
|
var status = request.status;
|
|
|
|
}
|
|
|
|
catch (e) {
|
2007-09-03 20:07:11 -07:00
|
|
|
request = aEvent.target.channel.QueryInterface(Ci.nsIRequest);
|
2007-03-22 10:30:00 -07:00
|
|
|
status = request.status;
|
|
|
|
}
|
|
|
|
// this can fail when a network connection is not present.
|
|
|
|
try {
|
|
|
|
var statusText = request.statusText;
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
status = 0;
|
|
|
|
}
|
|
|
|
// When status is 0 we don't have a valid channel.
|
|
|
|
if (status == 0)
|
|
|
|
statusText = "nsIXMLHttpRequest channel unavailable";
|
|
|
|
|
2009-08-19 03:32:15 -07:00
|
|
|
WARN("RDFItemUpdater:onError: There was an error loading the \r\n" +
|
|
|
|
"the update datasource for item " + aItem.id + ", error: " + statusText);
|
2007-08-29 01:16:15 -07:00
|
|
|
this._updater.checkForDone(aItem,
|
2007-09-17 11:05:04 -07:00
|
|
|
Ci.nsIAddonUpdateCheckListener.STATUS_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
onDatasourceLoaded: function RDFItemUpdater_onDatasourceLoaded(aDatasource, aLocalItem) {
|
2007-08-16 14:17:45 -07:00
|
|
|
/*
|
|
|
|
# The extension update RDF file looks something like this:
|
2007-08-29 01:16:15 -07:00
|
|
|
#
|
2007-08-16 14:17:45 -07:00
|
|
|
# <RDF:Description about="urn:mozilla:extension:{GUID}">
|
|
|
|
# <em:updates>
|
|
|
|
# <RDF:Seq>
|
|
|
|
# <RDF:li resource="urn:mozilla:extension:{GUID}:4.9"/>
|
|
|
|
# <RDF:li resource="urn:mozilla:extension:{GUID}:5.0"/>
|
|
|
|
# </RDF:Seq>
|
|
|
|
# </em:updates>
|
|
|
|
# <!-- the version of the extension being offered -->
|
|
|
|
# <em:version>5.0</em:version>
|
|
|
|
# <em:updateLink>http://www.mysite.com/myext-50.xpi</em:updateLink>
|
|
|
|
# </RDF:Description>
|
2007-08-29 01:16:15 -07:00
|
|
|
#
|
2007-08-16 14:17:45 -07:00
|
|
|
# <RDF:Description about="urn:mozilla:extension:{GUID}:4.9">
|
|
|
|
# <em:version>4.9</em:version>
|
|
|
|
# <em:targetApplication>
|
|
|
|
# <RDF:Description>
|
|
|
|
# <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
|
|
|
|
# <em:minVersion>0.9</em:minVersion>
|
|
|
|
# <em:maxVersion>1.0</em:maxVersion>
|
|
|
|
# <em:updateLink>http://www.mysite.com/myext-49.xpi</em:updateLink>
|
|
|
|
# </RDF:Description>
|
|
|
|
# </em:targetApplication>
|
2007-08-29 01:16:15 -07:00
|
|
|
# </RDF:Description>
|
|
|
|
#
|
2007-08-16 14:17:45 -07:00
|
|
|
# If we get here because the following happened:
|
2007-08-29 01:16:15 -07:00
|
|
|
# 1) User was using Firefox 0.9 with ExtensionX 0.5 (minVersion 0.8,
|
2007-08-16 14:17:45 -07:00
|
|
|
# maxVersion 0.9 for Firefox)
|
|
|
|
# 2) User upgraded Firefox to 1.0
|
|
|
|
# 3) |checkForMismatches| deems ExtensionX 0.5 incompatible with this
|
|
|
|
# new version of Firefox on the basis of its maxVersion
|
|
|
|
# 4) ** We reach this point **
|
2007-08-29 01:16:15 -07:00
|
|
|
#
|
|
|
|
# If the version of ExtensionX (0.5) matches that provided by the
|
2007-08-16 14:17:45 -07:00
|
|
|
# server, then this is a cue that the author updated the rdf file
|
|
|
|
# or central repository to say "0.5 is ALSO compatible with Firefox 1.0,
|
|
|
|
# no changes are necessary." In this event, the local metadata for
|
2007-08-29 01:16:15 -07:00
|
|
|
# installed ExtensionX (0.5) is freshened with the new maxVersion,
|
|
|
|
# and we advance to the next item WITHOUT any download/install
|
2007-08-16 14:17:45 -07:00
|
|
|
# updates.
|
|
|
|
*/
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!aDatasource.GetAllResources().hasMoreElements()) {
|
2007-08-29 01:16:15 -07:00
|
|
|
LOG("RDFItemUpdater:onDatasourceLoaded: Datasource empty.\r\n" +
|
|
|
|
"If you are an Extension developer and were expecting there to be\r\n" +
|
|
|
|
"updates, this could mean any number of things, since the RDF system\r\n" +
|
|
|
|
"doesn't give up much in the way of information when the load fails.\r\n" +
|
|
|
|
"\r\nTry checking that: \r\n" +
|
|
|
|
" 1. Your remote RDF file exists at the location.\r\n" +
|
2007-09-03 14:44:12 -07:00
|
|
|
" 2. Your RDF file is valid XML (starts with <?xml version=\"1.0\"?>\r\n" +
|
2007-08-29 01:16:15 -07:00
|
|
|
" and loads in Firefox displaying pretty printed like other XML documents\r\n" +
|
|
|
|
" 3. Your server is sending the data in the correct MIME\r\n" +
|
2007-03-22 10:30:00 -07:00
|
|
|
" type (text/xml)");
|
2007-09-03 14:44:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we have an update key then the update manifest must be signed
|
|
|
|
if (aLocalItem.updateKey) {
|
|
|
|
var extensionRes = gRDF.GetResource(getItemPrefix(aLocalItem.type) + aLocalItem.id);
|
|
|
|
LOG(extensionRes.Value);
|
|
|
|
var signature = this._getPropertyFromResource(aDatasource, extensionRes, "signature", null);
|
|
|
|
if (signature) {
|
|
|
|
var serializer = new RDFSerializer();
|
|
|
|
try {
|
|
|
|
var updateString = serializer.serializeResource(aDatasource, extensionRes);
|
2007-09-03 20:07:11 -07:00
|
|
|
var verifier = Cc["@mozilla.org/security/datasignatureverifier;1"].
|
|
|
|
getService(Ci.nsIDataSignatureVerifier);
|
2007-09-03 14:44:12 -07:00
|
|
|
try {
|
|
|
|
if (!verifier.verifyData(updateString, signature, aLocalItem.updateKey)) {
|
2009-08-19 03:32:15 -07:00
|
|
|
WARN("RDFItemUpdater:onDatasourceLoaded: Update manifest for " +
|
|
|
|
aLocalItem.id + " failed signature check.");
|
2007-09-17 11:05:04 -07:00
|
|
|
this._updater.checkForDone(aLocalItem, Ci.nsIAddonUpdateCheckListener.STATUS_FAILURE);
|
2007-09-03 14:44:12 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e) {
|
2009-08-19 03:32:15 -07:00
|
|
|
WARN("RDFItemUpdater:onDatasourceLoaded: Failed to verify signature for " +
|
|
|
|
aLocalItem.id + ". This indicates a malformed update key or signature.");
|
2007-09-17 11:05:04 -07:00
|
|
|
this._updater.checkForDone(aLocalItem, Ci.nsIAddonUpdateCheckListener.STATUS_FAILURE);
|
2007-09-03 14:44:12 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e) {
|
2009-08-19 03:32:15 -07:00
|
|
|
WARN("RDFItemUpdater:onDatasourceLoaded: Failed to generate signature " +
|
|
|
|
"string for " + aLocalItem.id + ". Serializer threw " + e);
|
2007-09-17 11:05:04 -07:00
|
|
|
this._updater.checkForDone(aLocalItem, Ci.nsIAddonUpdateCheckListener.STATUS_FAILURE);
|
2007-09-03 14:44:12 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2009-08-19 03:32:15 -07:00
|
|
|
WARN("RDFItemUpdater:onDatasourceLoaded: Update manifest for " +
|
|
|
|
aLocalItem.id + " did not contain a signature.");
|
2007-09-17 11:05:04 -07:00
|
|
|
this._updater.checkForDone(aLocalItem, Ci.nsIAddonUpdateCheckListener.STATUS_FAILURE);
|
2007-09-03 14:44:12 -07:00
|
|
|
return;
|
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
}
|
2007-09-03 14:44:12 -07:00
|
|
|
/* If there is no updateKey either the update was over SSL, or it is an old
|
|
|
|
* addon that we are allowing a grace update. */
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Parse the response RDF
|
|
|
|
var newerItem, sameItem;
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Firefox 1.0PR+ update.rdf format
|
2008-10-21 17:48:52 -07:00
|
|
|
if (this._updateCheckType == Ci.nsIExtensionManager.UPDATE_CHECK_NEWVERSION ||
|
|
|
|
this._updateCheckType == Ci.nsIExtensionManager.UPDATE_NOTIFY_NEWVERSION) {
|
2007-08-29 01:16:15 -07:00
|
|
|
// Look for newer versions of this item, we only do this in "normal"
|
|
|
|
// mode... see comment by ExtensionItemUpdater_checkForUpdates
|
|
|
|
// about how we do this in all cases but Install Phone Home - which
|
2007-03-22 10:30:00 -07:00
|
|
|
// only needs to do a version check.
|
2007-08-30 11:26:37 -07:00
|
|
|
newerItem = this._parseV20UpdateInfo(aDatasource, aLocalItem,
|
2008-10-21 17:48:52 -07:00
|
|
|
this._updateCheckType);
|
2007-08-30 11:26:37 -07:00
|
|
|
|
|
|
|
if (newerItem) {
|
2007-03-22 10:30:00 -07:00
|
|
|
++this._updater._updateCount;
|
2007-08-30 11:26:37 -07:00
|
|
|
LOG("RDFItemUpdater:onDatasourceLoaded: Found a newer version of this item:\r\n" +
|
|
|
|
newerItem.objectSource);
|
2007-07-06 07:41:56 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Now look for updated version compatibility metadata for the currently
|
|
|
|
// installed version...
|
2007-08-30 11:26:37 -07:00
|
|
|
sameItem = this._parseV20UpdateInfo(aDatasource, aLocalItem,
|
2007-09-17 11:05:04 -07:00
|
|
|
Ci.nsIExtensionManager.UPDATE_CHECK_COMPATIBILITY);
|
2007-08-30 11:26:37 -07:00
|
|
|
|
|
|
|
if (sameItem) {
|
2007-07-06 07:41:56 -07:00
|
|
|
// Install-time updates are not written to the DS because there is no
|
|
|
|
// entry yet, EM just uses the notifications to ascertain (by hand)
|
2007-08-29 01:16:15 -07:00
|
|
|
// whether or not there is a remote maxVersion tweak that makes the
|
2007-07-06 07:41:56 -07:00
|
|
|
// item being installed compatible.
|
|
|
|
if (!this._updater._applyVersionUpdates(aLocalItem, sameItem))
|
2007-03-22 10:30:00 -07:00
|
|
|
sameItem = null;
|
2007-08-30 11:26:37 -07:00
|
|
|
else
|
|
|
|
LOG("RDFItemUpdater:onDatasourceLoaded: Found info about the installed\r\n" +
|
|
|
|
"version of this item: " + sameItem.objectSource);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-09-17 11:05:04 -07:00
|
|
|
var item = null, status = Ci.nsIAddonUpdateCheckListener.STATUS_NONE;
|
2008-10-21 17:48:52 -07:00
|
|
|
if ((this._updateCheckType == Ci.nsIExtensionManager.UPDATE_CHECK_NEWVERSION ||
|
|
|
|
this._updateCheckType == Ci.nsIExtensionManager.UPDATE_NOTIFY_NEWVERSION)
|
2007-06-25 08:51:51 -07:00
|
|
|
&& newerItem) {
|
2007-03-22 10:30:00 -07:00
|
|
|
item = newerItem;
|
2007-09-17 11:05:04 -07:00
|
|
|
status = Ci.nsIAddonUpdateCheckListener.STATUS_UPDATE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (sameItem) {
|
|
|
|
item = sameItem;
|
2007-09-17 11:05:04 -07:00
|
|
|
status = Ci.nsIAddonUpdateCheckListener.STATUS_VERSIONINFO;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
item = aLocalItem;
|
2007-09-17 11:05:04 -07:00
|
|
|
status = Ci.nsIAddonUpdateCheckListener.STATUS_NO_UPDATE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
// Only one call of this._updater.checkForDone is needed for RDF
|
2007-03-22 10:30:00 -07:00
|
|
|
// responses, since there is only one response per item.
|
|
|
|
this._updater.checkForDone(item, status);
|
|
|
|
},
|
|
|
|
|
2007-08-29 01:16:15 -07:00
|
|
|
// Get a compulsory property from a resource. Reports an error if the
|
|
|
|
// property was not present.
|
2008-08-15 08:23:48 -07:00
|
|
|
_getPropertyFromResource: function RDFItemUpdater__getPropertyFromResource(aDataSource,
|
|
|
|
aSourceResource,
|
|
|
|
aProperty,
|
|
|
|
aLocalItem) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var rv;
|
|
|
|
try {
|
|
|
|
var property = gRDF.GetResource(EM_NS(aProperty));
|
|
|
|
rv = stringData(aDataSource.GetTarget(aSourceResource, property, true));
|
|
|
|
if (rv === undefined)
|
2007-09-03 20:07:11 -07:00
|
|
|
throw Cr.NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
2007-08-29 01:16:15 -07:00
|
|
|
// XXXben show console message "aProperty" not found on aSourceResource.
|
2007-03-22 10:30:00 -07:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-08-30 11:26:37 -07:00
|
|
|
/**
|
|
|
|
* Parses the Firefox 1.0RC1+ update manifest format looking for new versions
|
2007-08-30 11:34:13 -07:00
|
|
|
* of updated compatibility information about the given add-on.
|
2007-08-30 11:26:37 -07:00
|
|
|
* @param aDataSource
|
|
|
|
* The update manifest's datasource
|
|
|
|
* @param aLocalItem
|
|
|
|
* The nsIUpdateItem representing the add-on being checked for updates.
|
|
|
|
* @param aUpdateCheckType
|
|
|
|
* The type of update check being performed. See the constants in
|
|
|
|
* nsIExtensionManager
|
2007-08-30 11:34:13 -07:00
|
|
|
* @returns An nsIUpdateItem holding the update's information if a valid
|
|
|
|
* update is found or null if not.
|
2007-08-30 11:26:37 -07:00
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_parseV20UpdateInfo: function RDFItemUpdater__parseV20UpdateInfo(aDataSource,
|
|
|
|
aLocalItem,
|
|
|
|
aUpdateCheckType) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var extensionRes = gRDF.GetResource(getItemPrefix(aLocalItem.type) + aLocalItem.id);
|
|
|
|
|
|
|
|
var updatesArc = gRDF.GetResource(EM_NS("updates"));
|
|
|
|
var updates = aDataSource.GetTarget(extensionRes, updatesArc, true);
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
try {
|
2007-09-03 20:07:11 -07:00
|
|
|
updates = updates.QueryInterface(Ci.nsIRDFResource);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
catch (e) {
|
2009-08-19 03:32:15 -07:00
|
|
|
WARN("RDFItemUpdater:_parseV20UpdateInfo: No updates were found for:\r\n" +
|
|
|
|
aLocalItem.id + "\r\n" +
|
|
|
|
"If you are an Extension developer and were expecting there to be\r\n" +
|
|
|
|
"updates, this could mean any number of things, since the RDF system\r\n" +
|
|
|
|
"doesn't give up much in the way of information when the load fails.\r\n" +
|
|
|
|
"\r\nTry checking that: \r\n" +
|
|
|
|
" 1. Your RDF File is correct - e.g. check that there is a top level\r\n" +
|
|
|
|
" RDF Resource with a URI urn:mozilla:extension:{GUID}, and that\r\n" +
|
|
|
|
" the <em:updates> listed all have matching GUIDs.");
|
2007-08-30 11:26:37 -07:00
|
|
|
return null;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-08-30 11:26:37 -07:00
|
|
|
// Track the newest update found
|
|
|
|
var updatedItem = null;
|
|
|
|
|
2007-09-03 20:07:11 -07:00
|
|
|
var cu = Cc["@mozilla.org/rdf/container-utils;1"].
|
|
|
|
getService(Ci.nsIRDFContainerUtils);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (cu.IsContainer(aDataSource, updates)) {
|
|
|
|
var ctr = getContainer(aDataSource, updates);
|
|
|
|
|
|
|
|
var versions = ctr.GetElements();
|
|
|
|
while (versions.hasMoreElements()) {
|
2007-08-29 01:16:15 -07:00
|
|
|
// There are two different methodologies for collecting version
|
2007-08-30 11:26:37 -07:00
|
|
|
// information depending on whether or not we've been invoked in
|
2007-08-29 01:16:15 -07:00
|
|
|
// "version updates only" mode or "version+newest" mode.
|
2007-09-03 20:07:11 -07:00
|
|
|
var version = versions.getNext().QueryInterface(Ci.nsIRDFResource);
|
2007-08-30 11:26:37 -07:00
|
|
|
var foundItem = this._parseV20Update(aDataSource, version, aLocalItem,
|
|
|
|
updatedItem ? updatedItem.version : aLocalItem.version,
|
|
|
|
aUpdateCheckType);
|
|
|
|
if (foundItem) {
|
|
|
|
// When not checking for new versions we can bail out on the first
|
|
|
|
// result.
|
|
|
|
if (aUpdateCheckType)
|
|
|
|
return foundItem;
|
|
|
|
updatedItem = foundItem;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2007-08-30 11:26:37 -07:00
|
|
|
return updatedItem;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-08-30 11:26:37 -07:00
|
|
|
/**
|
|
|
|
* Parses a single version's update entry looking for the best matching
|
2007-08-30 11:34:13 -07:00
|
|
|
* targetApplication entry.
|
2007-08-30 11:26:37 -07:00
|
|
|
* @param aDataSource
|
|
|
|
* The update manifest's datasource
|
|
|
|
* @param aUpdateResource
|
|
|
|
* The nsIRDFResource of the update entry.
|
|
|
|
* @param aLocalItem
|
|
|
|
* The nsIUpdateItem representing the add-on being checked for updates.
|
|
|
|
* @param aNewestVersionFound
|
|
|
|
* When checking for new versions holds the newest version of this
|
|
|
|
* add-on that we know about. Otherwise holds the current version.
|
|
|
|
* @param aUpdateCheckType
|
|
|
|
* The type of update check being performed. See the constants in
|
|
|
|
* nsIExtensionManager
|
2007-08-30 11:34:13 -07:00
|
|
|
* @returns An nsIUpdateItem holding the update's information if a valid
|
|
|
|
* update is found or null if not.
|
2007-08-30 11:26:37 -07:00
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_parseV20Update: function RDFItemUpdater__parseV20Update(aDataSource,
|
|
|
|
aUpdateResource,
|
|
|
|
aLocalItem,
|
|
|
|
aNewestVersionFound,
|
|
|
|
aUpdateCheckType) {
|
2007-08-29 01:16:15 -07:00
|
|
|
var version = this._getPropertyFromResource(aDataSource, aUpdateResource,
|
2007-03-22 10:30:00 -07:00
|
|
|
"version", aLocalItem);
|
2007-08-30 11:26:37 -07:00
|
|
|
/* If we are looking for new versions then test whether this discovered
|
|
|
|
* version is greater than any previously found update. Otherwise check
|
|
|
|
* if this update is for the same version as we have installed. */
|
|
|
|
var result = gVersionChecker.compare(version, aNewestVersionFound);
|
2008-10-21 17:48:52 -07:00
|
|
|
if ((aUpdateCheckType == Ci.nsIExtensionManager.UPDATE_CHECK_NEWVERSION ||
|
|
|
|
aUpdateCheckType == Ci.nsIExtensionManager.UPDATE_NOTIFY_NEWVERSION) ? result <= 0 : result != 0)
|
2007-08-30 11:26:37 -07:00
|
|
|
return null;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var taArc = gRDF.GetResource(EM_NS("targetApplication"));
|
|
|
|
var targetApps = aDataSource.GetTargets(aUpdateResource, taArc, true);
|
2007-08-30 11:26:37 -07:00
|
|
|
|
|
|
|
// Track the best update we have found so far
|
|
|
|
var newestUpdateItem = null;
|
2007-03-22 10:30:00 -07:00
|
|
|
while (targetApps.hasMoreElements()) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var targetApp = targetApps.getNext().QueryInterface(Ci.nsIRDFResource);
|
2007-08-29 01:16:15 -07:00
|
|
|
var appID = this._getPropertyFromResource(aDataSource, targetApp, "id", aLocalItem);
|
2007-11-17 04:52:03 -08:00
|
|
|
if (appID != gApp.ID && appID != TOOLKIT_ID)
|
2007-03-22 10:30:00 -07:00
|
|
|
continue;
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-09-03 14:44:12 -07:00
|
|
|
var updateLink = this._getPropertyFromResource(aDataSource, targetApp, "updateLink", aLocalItem);
|
|
|
|
var updateHash = this._getPropertyFromResource(aDataSource, targetApp, "updateHash", aLocalItem);
|
2008-10-21 17:48:52 -07:00
|
|
|
if (aUpdateCheckType == Ci.nsIExtensionManager.UPDATE_CHECK_NEWVERSION ||
|
|
|
|
aUpdateCheckType == Ci.nsIExtensionManager.UPDATE_NOTIFY_NEWVERSION) {
|
2007-09-03 14:44:12 -07:00
|
|
|
// New version information is useless without a link to get it from
|
|
|
|
if (!updateLink)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* If the update link is non-ssl and we do not have a hash or the hash
|
|
|
|
* is of an insecure nature then we must ignore this update. Bypass
|
|
|
|
* this if not checking update security. Currently we only consider
|
|
|
|
* the sha hashing algorithms as secure. */
|
|
|
|
if (gCheckUpdateSecurity && updateLink.substring(0, 6) != "https:" &&
|
|
|
|
(!updateHash || updateHash.substring(0, 3) != "sha")) {
|
2009-08-19 03:32:15 -07:00
|
|
|
WARN("RDFItemUpdater:_parseV20Update: Update for " + aLocalItem.id +
|
|
|
|
" at " + updateLink + " ignored because it is insecure. updateLink " +
|
|
|
|
" must be a https url or an updateHash must be specified.");
|
2007-09-03 14:44:12 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-30 11:26:37 -07:00
|
|
|
var updatedItem = makeItem(aLocalItem.id,
|
|
|
|
version,
|
|
|
|
aLocalItem.installLocationKey,
|
|
|
|
this._getPropertyFromResource(aDataSource, targetApp, "minVersion", aLocalItem),
|
|
|
|
this._getPropertyFromResource(aDataSource, targetApp, "maxVersion", aLocalItem),
|
|
|
|
aLocalItem.name,
|
2007-09-03 14:44:12 -07:00
|
|
|
updateLink,
|
|
|
|
updateHash,
|
2007-08-30 11:26:37 -07:00
|
|
|
"", /* Icon URL */
|
|
|
|
"", /* RDF Update URL */
|
2007-09-03 14:44:12 -07:00
|
|
|
"", /* Update Key */
|
2007-08-30 11:26:37 -07:00
|
|
|
aLocalItem.type,
|
|
|
|
appID);
|
|
|
|
|
2008-11-26 07:04:13 -08:00
|
|
|
if (this._updater._isValidUpdate(aLocalItem, updatedItem, aUpdateCheckType)) {
|
2007-09-17 11:05:04 -07:00
|
|
|
if (aUpdateCheckType == Ci.nsIExtensionManager.UPDATE_CHECK_NEWVERSION) {
|
2007-09-05 18:20:11 -07:00
|
|
|
var infourl = this._getPropertyFromResource(aDataSource, targetApp,
|
|
|
|
"updateInfoURL");
|
|
|
|
if (infourl)
|
|
|
|
infourl = EM_L(infourl);
|
|
|
|
this._updater._emDS.setItemProperty(aLocalItem.id,
|
|
|
|
EM_R("availableUpdateInfo"),
|
|
|
|
infourl);
|
|
|
|
}
|
2007-11-17 04:52:03 -08:00
|
|
|
if (appID == gApp.ID) {
|
2007-08-29 01:16:15 -07:00
|
|
|
// App takes precedence over toolkit. If we found the app, bail out.
|
2007-08-30 11:26:37 -07:00
|
|
|
return updatedItem;
|
2007-07-06 07:41:56 -07:00
|
|
|
}
|
2007-08-30 11:26:37 -07:00
|
|
|
newestUpdateItem = updatedItem;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2007-08-30 11:26:37 -07:00
|
|
|
return newestUpdateItem;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2007-09-03 14:44:12 -07:00
|
|
|
/**
|
|
|
|
* A serialisation method for RDF data that produces an identical string
|
|
|
|
* provided that the RDF assertions match.
|
|
|
|
* The serialisation is not complete, only assertions stemming from a given
|
|
|
|
* resource are included, multiple references to the same resource are not
|
|
|
|
* permitted, and the RDF prolog and epilog are not included.
|
|
|
|
* RDF Blob and Date literals are not supported.
|
|
|
|
*/
|
|
|
|
function RDFSerializer()
|
|
|
|
{
|
2007-09-03 20:07:11 -07:00
|
|
|
this.cUtils = Cc["@mozilla.org/rdf/container-utils;1"].
|
|
|
|
getService(Ci.nsIRDFContainerUtils);
|
2007-09-03 14:44:12 -07:00
|
|
|
this.resources = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
RDFSerializer.prototype = {
|
|
|
|
INDENT: " ", // The indent used for pretty-printing
|
|
|
|
resources: null, // Array of the resources that have been found
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Escapes characters from a string that should not appear in XML.
|
|
|
|
* @param string The string to be escaped
|
|
|
|
* @returns a string with all characters invalid in XML character data
|
|
|
|
* converted to entity references.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
escapeEntities: function RDFSerializer_escapeEntities(string)
|
2007-09-03 14:44:12 -07:00
|
|
|
{
|
|
|
|
string = string.replace(/&/g, "&");
|
|
|
|
string = string.replace(/</g, "<");
|
|
|
|
string = string.replace(/>/g, ">");
|
|
|
|
string = string.replace(/"/g, """);
|
|
|
|
return string;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Serializes all the elements of an RDF container.
|
|
|
|
* @param ds The datasource holding the data
|
|
|
|
* @param container The RDF container to output the child elements of
|
|
|
|
* @param indent The current level of indent for pretty-printing
|
|
|
|
* @returns a string containing the serialized elements.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
serializeContainerItems: function RDFSerializer_serializeContainerItems(ds, container, indent)
|
2007-09-03 14:44:12 -07:00
|
|
|
{
|
|
|
|
var result = "";
|
|
|
|
var items = container.GetElements();
|
|
|
|
while (items.hasMoreElements()) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var item = items.getNext().QueryInterface(Ci.nsIRDFResource);
|
2007-09-03 14:44:12 -07:00
|
|
|
result += indent + "<RDF:li>\n"
|
|
|
|
result += this.serializeResource(ds, item, indent + this.INDENT);
|
|
|
|
result += indent + "</RDF:li>\n"
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Serializes all em:* (see EM_NS) properties of an RDF resource except for
|
|
|
|
* the em:signature property. As this serialization is to be compared against
|
|
|
|
* the manifest signature it cannot contain the em:signature property itself.
|
|
|
|
* @param ds The datasource holding the data
|
|
|
|
* @param resource The RDF resource to output the properties of
|
|
|
|
* @param indent The current level of indent for pretty-printing
|
|
|
|
* @returns a string containing the serialized properties.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
serializeResourceProperties: function RDFSerializer_serializeResourceProperties(ds, resource, indent)
|
2007-09-03 14:44:12 -07:00
|
|
|
{
|
|
|
|
var result = "";
|
|
|
|
var items = [];
|
|
|
|
var arcs = ds.ArcLabelsOut(resource);
|
|
|
|
while (arcs.hasMoreElements()) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var arc = arcs.getNext().QueryInterface(Ci.nsIRDFResource);
|
2007-09-03 14:44:12 -07:00
|
|
|
if (arc.ValueUTF8.substring(0, PREFIX_NS_EM.length) != PREFIX_NS_EM)
|
|
|
|
continue;
|
|
|
|
var prop = arc.ValueUTF8.substring(PREFIX_NS_EM.length);
|
|
|
|
if (prop == "signature")
|
|
|
|
continue;
|
|
|
|
|
|
|
|
var targets = ds.GetTargets(resource, arc, true);
|
|
|
|
while (targets.hasMoreElements()) {
|
|
|
|
var target = targets.getNext();
|
2007-09-03 20:07:11 -07:00
|
|
|
if (target instanceof Ci.nsIRDFResource) {
|
2007-09-03 14:44:12 -07:00
|
|
|
var item = indent + "<em:" + prop + ">\n";
|
|
|
|
item += this.serializeResource(ds, target, indent + this.INDENT);
|
|
|
|
item += indent + "</em:" + prop + ">\n";
|
|
|
|
items.push(item);
|
|
|
|
}
|
2007-09-03 20:07:11 -07:00
|
|
|
else if (target instanceof Ci.nsIRDFLiteral) {
|
2007-09-03 14:44:12 -07:00
|
|
|
items.push(indent + "<em:" + prop + ">" + this.escapeEntities(target.Value) + "</em:" + prop + ">\n");
|
|
|
|
}
|
2007-09-03 20:07:11 -07:00
|
|
|
else if (target instanceof Ci.nsIRDFInt) {
|
2007-09-03 14:44:12 -07:00
|
|
|
items.push(indent + "<em:" + prop + " NC:parseType=\"Integer\">" + target.Value + "</em:" + prop + ">\n");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
throw new Error("Cannot serialize unknown literal type");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
items.sort();
|
|
|
|
result += items.join("");
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Recursively serializes an RDF resource and all resources it links to.
|
|
|
|
* This will only output EM_NS properties and will ignore any em:signature
|
|
|
|
* property.
|
|
|
|
* @param ds The datasource holding the data
|
|
|
|
* @param resource The RDF resource to serialize
|
|
|
|
* @param indent The current level of indent for pretty-printing.
|
|
|
|
* Leave undefined for no indent
|
|
|
|
* @returns a string containing the serialized resource.
|
|
|
|
* @throws if the RDF data contains multiple references to the same resource.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
serializeResource: function RDFSerializer_serializeResource(ds, resource, indent)
|
2007-09-03 14:44:12 -07:00
|
|
|
{
|
|
|
|
if (this.resources.indexOf(resource) != -1 ) {
|
|
|
|
// We cannot output multiple references to the same resource.
|
|
|
|
throw new Error("Cannot serialize multiple references to "+resource.Value);
|
|
|
|
}
|
|
|
|
if (indent === undefined)
|
|
|
|
indent = "";
|
|
|
|
|
|
|
|
this.resources.push(resource);
|
|
|
|
var container = null;
|
|
|
|
var type = "Description";
|
|
|
|
if (this.cUtils.IsSeq(ds, resource)) {
|
|
|
|
type = "Seq";
|
|
|
|
container = this.cUtils.MakeSeq(ds, resource);
|
|
|
|
}
|
|
|
|
else if (this.cUtils.IsAlt(ds, resource)) {
|
|
|
|
type = "Alt";
|
|
|
|
container = this.cUtils.MakeAlt(ds, resource);
|
|
|
|
}
|
|
|
|
else if (this.cUtils.IsBag(ds, resource)) {
|
|
|
|
type = "Bag";
|
|
|
|
container = this.cUtils.MakeBag(ds, resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
var result = indent + "<RDF:" + type;
|
|
|
|
if (!gRDF.IsAnonymousResource(resource))
|
|
|
|
result += " about=\"" + this.escapeEntities(resource.ValueUTF8) + "\"";
|
|
|
|
result += ">\n";
|
|
|
|
|
|
|
|
if (container)
|
|
|
|
result += this.serializeContainerItems(ds, container, indent + this.INDENT);
|
|
|
|
|
|
|
|
result += this.serializeResourceProperties(ds, resource, indent + this.INDENT);
|
|
|
|
|
|
|
|
result += indent + "</RDF:" + type + ">\n";
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
2007-08-29 01:16:15 -07:00
|
|
|
* A Datasource that holds Extensions.
|
2007-03-22 10:30:00 -07:00
|
|
|
* - Implements nsIRDFDataSource to drive UI
|
|
|
|
* - Uses a RDF/XML datasource for storage (this is undesirable)
|
2007-08-29 01:16:15 -07:00
|
|
|
*
|
2007-03-22 10:30:00 -07:00
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
function ExtensionsDataSource(em) {
|
|
|
|
this._em = em;
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
this._itemRoot = gRDF.GetResource(RDFURI_ITEM_ROOT);
|
|
|
|
this._defaultTheme = gRDF.GetResource(RDFURI_DEFAULT_THEME);
|
|
|
|
}
|
|
|
|
ExtensionsDataSource.prototype = {
|
|
|
|
_inner : null,
|
|
|
|
_em : null,
|
|
|
|
_itemRoot : null,
|
|
|
|
_defaultTheme : null,
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2008-11-28 14:20:10 -08:00
|
|
|
/**
|
|
|
|
* Called during application shutdown to clear any references held.
|
|
|
|
* The ExtensionsDataSource is unusable after calling this.
|
|
|
|
*/
|
|
|
|
shutdown: function EMDS_shutdown() {
|
|
|
|
this._inner = null;
|
|
|
|
this._em = null;
|
|
|
|
this._itemRoot = null;
|
|
|
|
this._defaultTheme = null;
|
|
|
|
},
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Determines if an item's dependencies are satisfied. An item's dependencies
|
|
|
|
* are satisifed when all items specified in the item's em:requires arc are
|
|
|
|
* installed, enabled, and the version is compatible based on the em:requires
|
|
|
|
* minVersion and maxVersion.
|
|
|
|
* @param id
|
|
|
|
* The ID of the item
|
|
|
|
* @returns true if the item's dependencies are satisfied.
|
|
|
|
* false if the item's dependencies are not satisfied.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
satisfiesDependencies: function EMDS_satisfiesDependencies(id) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var ds = this._inner;
|
|
|
|
var itemResource = getResourceForID(id);
|
|
|
|
var targets = ds.GetTargets(itemResource, EM_R("requires"), true);
|
|
|
|
if (!targets.hasMoreElements())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
getVersionChecker();
|
|
|
|
var idRes = EM_R("id");
|
|
|
|
var minVersionRes = EM_R("minVersion");
|
|
|
|
var maxVersionRes = EM_R("maxVersion");
|
|
|
|
while (targets.hasMoreElements()) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var target = targets.getNext().QueryInterface(Ci.nsIRDFResource);
|
2007-03-22 10:30:00 -07:00
|
|
|
var dependencyID = stringData(ds.GetTarget(target, idRes, true));
|
|
|
|
var version = null;
|
|
|
|
version = this.getItemProperty(dependencyID, "version");
|
|
|
|
if (version) {
|
|
|
|
var opType = this.getItemProperty(dependencyID, "opType");
|
|
|
|
if (opType == OP_NEEDS_DISABLE || opType == OP_NEEDS_UNINSTALL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (this.getItemProperty(dependencyID, "userDisabled") == "true" ||
|
|
|
|
this.getItemProperty(dependencyID, "appDisabled") == "true" ||
|
|
|
|
this.getItemProperty(dependencyID, "userDisabled") == OP_NEEDS_DISABLE ||
|
|
|
|
this.getItemProperty(dependencyID, "appDisabled") == OP_NEEDS_DISABLE)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
var minVersion = stringData(ds.GetTarget(target, minVersionRes, true));
|
|
|
|
var maxVersion = stringData(ds.GetTarget(target, maxVersionRes, true));
|
|
|
|
var compatible = (gVersionChecker.compare(version, minVersion) >= 0 &&
|
|
|
|
gVersionChecker.compare(version, maxVersion) <= 0);
|
|
|
|
if (!compatible)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if an item is compatible
|
|
|
|
* @param datasource
|
|
|
|
* The datasource to inspect for compatibility - can be the main
|
|
|
|
* datasource or an Install Manifest.
|
|
|
|
* @param source
|
|
|
|
* The RDF Resource of the item to inspect for compatibility.
|
2009-08-06 07:24:52 -07:00
|
|
|
* @param alwaysCheckVersion
|
|
|
|
* Set to true to only obey the compatibility information in the
|
|
|
|
* datasource. When false the compatibility range may be ignored
|
|
|
|
* if compatibility checking is disabled.
|
2007-08-29 01:16:15 -07:00
|
|
|
* @param appVersion
|
2007-03-22 10:30:00 -07:00
|
|
|
* The version of the application we are checking for compatibility
|
|
|
|
* against. If this parameter is undefined, the version of the running
|
|
|
|
* application is used.
|
2007-08-29 01:16:15 -07:00
|
|
|
* @param platformVersion
|
|
|
|
* The version of the toolkit to check compatibility against
|
|
|
|
* @returns true if the item is compatible with this version of the
|
2007-03-22 10:30:00 -07:00
|
|
|
* application, false, otherwise.
|
|
|
|
*/
|
2009-08-06 07:24:52 -07:00
|
|
|
isCompatible: function EMDS_isCompatible(datasource, source, alwaysCheckVersion,
|
|
|
|
appVersion, platformVersion) {
|
2007-08-29 01:16:15 -07:00
|
|
|
// The Default Theme is always compatible.
|
2007-03-22 10:30:00 -07:00
|
|
|
if (source.EqualsNode(this._defaultTheme))
|
|
|
|
return true;
|
|
|
|
|
2009-08-06 07:24:52 -07:00
|
|
|
// Items pending install have no target application info in the datasource
|
|
|
|
if (datasource === this &&
|
|
|
|
this._getItemProperty(source, "opType") == OP_NEEDS_INSTALL)
|
|
|
|
return true;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var appID = gApp.ID;
|
2007-08-29 01:16:15 -07:00
|
|
|
if (appVersion === undefined)
|
|
|
|
appVersion = gApp.version;
|
|
|
|
if (platformVersion === undefined)
|
|
|
|
var platformVersion = gApp.platformVersion;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var targets = datasource.GetTargets(source, EM_R("targetApplication"), true);
|
|
|
|
var idRes = EM_R("id");
|
|
|
|
var minVersionRes = EM_R("minVersion");
|
|
|
|
var maxVersionRes = EM_R("maxVersion");
|
2007-08-29 01:16:15 -07:00
|
|
|
var versionChecker = getVersionChecker();
|
|
|
|
var rv = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
while (targets.hasMoreElements()) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var targetApp = targets.getNext().QueryInterface(Ci.nsIRDFResource);
|
2007-03-22 10:30:00 -07:00
|
|
|
var id = stringData(datasource.GetTarget(targetApp, idRes, true));
|
|
|
|
var minVersion = stringData(datasource.GetTarget(targetApp, minVersionRes, true));
|
|
|
|
var maxVersion = stringData(datasource.GetTarget(targetApp, maxVersionRes, true));
|
|
|
|
if (id == appID) {
|
2009-08-06 07:24:52 -07:00
|
|
|
if (!alwaysCheckVersion && !gCheckCompatibility)
|
|
|
|
return true;
|
2007-08-29 01:16:15 -07:00
|
|
|
rv = (versionChecker.compare(appVersion, minVersion) >= 0) &&
|
|
|
|
(versionChecker.compare(appVersion, maxVersion) <= 0);
|
|
|
|
return rv; // App takes precedence over toolkit.
|
|
|
|
}
|
|
|
|
|
|
|
|
if (id == TOOLKIT_ID) {
|
2009-08-06 07:24:52 -07:00
|
|
|
if (!alwaysCheckVersion && !gCheckCompatibility)
|
|
|
|
return true;
|
2007-08-29 01:16:15 -07:00
|
|
|
rv = (versionChecker.compare(platformVersion, minVersion) >= 0) &&
|
|
|
|
(versionChecker.compare(platformVersion, maxVersion) <= 0);
|
|
|
|
// Keep looping, in case the app id is later.
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a list of items that are incompatible with a specific application version.
|
|
|
|
* @param appVersion
|
|
|
|
* The Version of the application to check for incompatibility against.
|
2007-08-29 01:16:15 -07:00
|
|
|
* @param platformVersion
|
|
|
|
* The version of the toolkit to check compatibility against
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param desiredType
|
|
|
|
* The nsIUpdateItem type of items to look for
|
|
|
|
* @param includeDisabled
|
|
|
|
* Whether or not disabled items should be included in the set returned
|
|
|
|
* @returns An array of nsIUpdateItems that are incompatible with the application
|
|
|
|
* ID/Version supplied.
|
|
|
|
*/
|
2009-07-30 17:35:02 -07:00
|
|
|
getIncompatibleItemList: function EMDS_getIncompatibleItemList(appVersion,
|
2008-08-15 08:23:48 -07:00
|
|
|
platformVersion,
|
|
|
|
desiredType,
|
|
|
|
includeDisabled) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var items = [];
|
|
|
|
var ctr = getContainer(this._inner, this._itemRoot);
|
|
|
|
var elements = ctr.GetElements();
|
|
|
|
while (elements.hasMoreElements()) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var item = elements.getNext().QueryInterface(Ci.nsIRDFResource);
|
2007-03-22 10:30:00 -07:00
|
|
|
var id = stripPrefix(item.Value, PREFIX_ITEM_URI);
|
|
|
|
var type = this.getItemProperty(id, "type");
|
|
|
|
// Skip this item if we're not seeking disabled items
|
|
|
|
if (!includeDisabled && this.getItemProperty(id, "isDisabled") == "true")
|
|
|
|
continue;
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// If the id of this item matches one of the items potentially installed
|
2007-08-29 01:16:15 -07:00
|
|
|
// with and maintained by this application AND it is installed in the
|
2007-03-22 10:30:00 -07:00
|
|
|
// global install location (i.e. the place installed by the app installer)
|
|
|
|
// it is and can be managed by the update file - it's not an item that has
|
|
|
|
// been manually installed by the user into their profile dir, and as such
|
|
|
|
// it is always compatible with the next release of the application since
|
|
|
|
// we will continue to support it.
|
|
|
|
var locationKey = this.getItemProperty(id, "installLocation");
|
|
|
|
var appManaged = this.getItemProperty(id, "appManaged") == "true";
|
|
|
|
if (appManaged && locationKey == KEY_APP_GLOBAL)
|
|
|
|
continue;
|
|
|
|
|
2007-08-29 01:16:15 -07:00
|
|
|
if (type != -1 && (type & desiredType) &&
|
2009-08-06 07:24:52 -07:00
|
|
|
!this.isCompatible(this, item, true, appVersion, platformVersion))
|
2007-03-22 10:30:00 -07:00
|
|
|
items.push(this.getItemForID(id));
|
|
|
|
}
|
|
|
|
return items;
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Gets a list of items of a specific type
|
|
|
|
* @param desiredType
|
|
|
|
* The nsIUpdateItem type of items to return
|
|
|
|
* @param countRef
|
|
|
|
* The XPCJS reference to the size of the returned array
|
|
|
|
* @returns An array of nsIUpdateItems, populated only with an item for |id|
|
|
|
|
* if |id| is non-null, otherwise all items matching the specified
|
|
|
|
* type.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
getItemList: function EMDS_getItemList(desiredType, countRef) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var items = [];
|
2007-08-29 01:16:15 -07:00
|
|
|
var ctr = getContainer(this, this._itemRoot);
|
2007-03-22 10:30:00 -07:00
|
|
|
var elements = ctr.GetElements();
|
|
|
|
while (elements.hasMoreElements()) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var e = elements.getNext().QueryInterface(Ci.nsIRDFResource);
|
2007-03-22 10:30:00 -07:00
|
|
|
var eID = stripPrefix(e.Value, PREFIX_ITEM_URI);
|
|
|
|
var type = this.getItemProperty(eID, "type");
|
|
|
|
if (type != -1 && type & desiredType)
|
|
|
|
items.push(this.getItemForID(eID));
|
|
|
|
}
|
2009-11-07 00:21:07 -08:00
|
|
|
if (countRef)
|
|
|
|
countRef.value = items.length;
|
2007-03-22 10:30:00 -07:00
|
|
|
return items;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves a list of installed nsIUpdateItems of items that are dependent
|
|
|
|
* on another item.
|
|
|
|
* @param id
|
|
|
|
* The ID of the item that other items depend on.
|
|
|
|
* @param includeDisabled
|
|
|
|
* Whether to include disabled items in the set returned.
|
|
|
|
* @param countRef
|
|
|
|
* The XPCJS reference to the number of items returned.
|
|
|
|
* @returns An array of installed nsIUpdateItems that depend on the item
|
|
|
|
* specified by the id parameter.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
getDependentItemListForID: function EMDS_getDependentItemListForID(id,
|
|
|
|
includeDisabled,
|
|
|
|
countRef) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var items = [];
|
|
|
|
var ds = this._inner;
|
|
|
|
var ctr = getContainer(this, this._itemRoot);
|
|
|
|
var elements = ctr.GetElements();
|
|
|
|
while (elements.hasMoreElements()) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var e = elements.getNext().QueryInterface(Ci.nsIRDFResource);
|
2007-03-22 10:30:00 -07:00
|
|
|
var dependentID = stripPrefix(e.Value, PREFIX_ITEM_URI);
|
|
|
|
var targets = ds.GetTargets(e, EM_R("requires"), true);
|
|
|
|
var idRes = EM_R("id");
|
|
|
|
while (targets.hasMoreElements()) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var target = targets.getNext().QueryInterface(Ci.nsIRDFResource);
|
2007-03-22 10:30:00 -07:00
|
|
|
var dependencyID = stringData(ds.GetTarget(target, idRes, true));
|
|
|
|
if (dependencyID == id) {
|
|
|
|
if (!includeDisabled && this.getItemProperty(dependentID, "isDisabled") == "true")
|
|
|
|
continue;
|
|
|
|
items.push(this.getItemForID(dependentID));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-11-07 00:21:07 -08:00
|
|
|
if (countRef)
|
|
|
|
countRef.value = items.length;
|
2007-03-22 10:30:00 -07:00
|
|
|
return items;
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Constructs an nsIUpdateItem for the given item ID
|
|
|
|
* @param id
|
|
|
|
* The GUID of the item to construct a nsIUpdateItem for
|
|
|
|
* @returns The nsIUpdateItem for the id.
|
2007-08-29 01:16:15 -07:00
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
getItemForID: function EMDS_getItemForID(id) {
|
2007-08-26 11:07:49 -07:00
|
|
|
if (!this.visibleItems[id])
|
|
|
|
return null;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var r = getResourceForID(id);
|
|
|
|
if (!r)
|
|
|
|
return null;
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var targetAppInfo = this.getTargetApplicationInfo(id, this);
|
|
|
|
var updateHash = this.getItemProperty(id, "availableUpdateHash");
|
2007-08-29 01:16:15 -07:00
|
|
|
return makeItem(id,
|
|
|
|
this.getItemProperty(id, "version"),
|
2007-03-22 10:30:00 -07:00
|
|
|
this.getItemProperty(id, "installLocation"),
|
|
|
|
targetAppInfo ? targetAppInfo.minVersion : "",
|
|
|
|
targetAppInfo ? targetAppInfo.maxVersion : "",
|
|
|
|
this.getItemProperty(id, "name"),
|
|
|
|
this.getItemProperty(id, "availableUpdateURL"),
|
|
|
|
updateHash ? updateHash : "",
|
2007-08-29 01:16:15 -07:00
|
|
|
this.getItemProperty(id, "iconURL"),
|
|
|
|
this.getItemProperty(id, "updateURL"),
|
2007-09-03 14:44:12 -07:00
|
|
|
this.getItemProperty(id, "updateKey"),
|
2007-08-29 01:16:15 -07:00
|
|
|
this.getItemProperty(id, "type"),
|
|
|
|
targetAppInfo ? targetAppInfo.appID : gApp.ID);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Gets the name of the Install Location where an item is installed.
|
|
|
|
* @param id
|
|
|
|
* The GUID of the item to locate an Install Location for
|
2007-08-29 01:16:15 -07:00
|
|
|
* @returns The string name of the Install Location where the item is
|
2007-03-22 10:30:00 -07:00
|
|
|
* installed.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
getInstallLocationKey: function EMDS_getInstallLocationKey(id) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return this.getItemProperty(id, "installLocation");
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Sets an RDF property on an item in a datasource. Does not create
|
|
|
|
* multiple assertions
|
|
|
|
* @param datasource
|
|
|
|
* The target datasource where the property should be set
|
|
|
|
* @param source
|
|
|
|
* The RDF Resource to set the property on
|
|
|
|
* @param property
|
|
|
|
* The RDF Resource of the property to set
|
|
|
|
* @param newValue
|
|
|
|
* The RDF Node containing the new property value
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_setProperty: function EMDS__setProperty(datasource, source, property, newValue) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var oldValue = datasource.GetTarget(source, property, true);
|
|
|
|
if (oldValue) {
|
|
|
|
if (newValue)
|
|
|
|
datasource.Change(source, property, oldValue, newValue);
|
|
|
|
else
|
|
|
|
datasource.Unassert(source, property, oldValue);
|
|
|
|
}
|
|
|
|
else if (newValue)
|
|
|
|
datasource.Assert(source, property, newValue, true);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Gets the updated target application info if it exists for an item from
|
|
|
|
* the Extensions datasource during an installation or upgrade.
|
|
|
|
* @param id
|
|
|
|
* The ID of the item to discover updated target application info for
|
|
|
|
* @returns A JS Object with the following properties:
|
|
|
|
* "id" The id of the item
|
|
|
|
* "minVersion" The updated minimum version of the target
|
|
|
|
* application that this item can run in
|
|
|
|
* "maxVersion" The updated maximum version of the target
|
|
|
|
* application that this item can run in
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
getUpdatedTargetAppInfo: function EMDS_getUpdatedTargetAppInfo(id) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// The default theme is always compatible so there is never update info.
|
|
|
|
if (getResourceForID(id).EqualsNode(this._defaultTheme))
|
|
|
|
return null;
|
|
|
|
|
|
|
|
var appID = gApp.ID;
|
|
|
|
var r = getResourceForID(id);
|
|
|
|
var targetApps = this._inner.GetTargets(r, EM_R("targetApplication"), true);
|
|
|
|
if (!targetApps.hasMoreElements())
|
2007-08-29 01:16:15 -07:00
|
|
|
targetApps = this._inner.GetTargets(gInstallManifestRoot, EM_R("targetApplication"), true);
|
|
|
|
var outData = null;
|
2007-03-22 10:30:00 -07:00
|
|
|
while (targetApps.hasMoreElements()) {
|
|
|
|
var targetApp = targetApps.getNext();
|
2007-09-03 20:07:11 -07:00
|
|
|
if (targetApp instanceof Ci.nsIRDFResource) {
|
2007-03-22 10:30:00 -07:00
|
|
|
try {
|
|
|
|
var foundAppID = stringData(this._inner.GetTarget(targetApp, EM_R("id"), true));
|
2007-08-29 01:16:15 -07:00
|
|
|
// Different target application?
|
|
|
|
if (foundAppID != appID && foundAppID != TOOLKIT_ID)
|
2007-03-22 10:30:00 -07:00
|
|
|
continue;
|
|
|
|
var updatedMinVersion = this._inner.GetTarget(targetApp, EM_R("updatedMinVersion"), true);
|
|
|
|
var updatedMaxVersion = this._inner.GetTarget(targetApp, EM_R("updatedMaxVersion"), true);
|
|
|
|
if (updatedMinVersion && updatedMaxVersion)
|
2007-09-07 15:59:25 -07:00
|
|
|
outData = { id : id,
|
|
|
|
targetAppID : foundAppID,
|
|
|
|
minVersion : stringData(updatedMinVersion),
|
|
|
|
maxVersion : stringData(updatedMaxVersion) };
|
2007-08-29 01:16:15 -07:00
|
|
|
if (foundAppID == appID)
|
|
|
|
return outData;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
catch (e) {
|
2007-03-22 10:30:00 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
return outData;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Sets the updated target application info for an item in the Extensions
|
|
|
|
* datasource during an installation or upgrade.
|
|
|
|
* @param id
|
|
|
|
* The ID of the item to set updated target application info for
|
2007-08-29 01:16:15 -07:00
|
|
|
* @param targetAppID
|
|
|
|
* The target application ID used for checking compatibility for this item.
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param updatedMinVersion
|
|
|
|
* The updated minimum version of the target application that this
|
|
|
|
* item can run in
|
|
|
|
* @param updatedMaxVersion
|
|
|
|
* The updated maximum version of the target application that this
|
|
|
|
* item can run in
|
2007-08-29 01:16:15 -07:00
|
|
|
*
|
|
|
|
* @note Add-ons can specify a targetApplication id of toolkit@mozilla.org in
|
|
|
|
* their install manifest for compatibility with all apps using a
|
|
|
|
* specific release of the toolkit.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
setUpdatedTargetAppInfo: function EMDS_setUpdatedTargetAppInfo(id, targetAppID,
|
|
|
|
updatedMinVersion,
|
|
|
|
updatedMaxVersion) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// The default theme is always compatible so it is never updated.
|
|
|
|
if (getResourceForID(id).EqualsNode(this._defaultTheme))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Version/Dependency Info
|
|
|
|
var updatedMinVersionRes = EM_R("updatedMinVersion");
|
|
|
|
var updatedMaxVersionRes = EM_R("updatedMaxVersion");
|
|
|
|
|
|
|
|
var appID = gApp.ID;
|
|
|
|
var r = getResourceForID(id);
|
|
|
|
var targetApps = this._inner.GetTargets(r, EM_R("targetApplication"), true);
|
|
|
|
// add updatedMinVersion and updatedMaxVersion for an install else an upgrade
|
|
|
|
if (!targetApps.hasMoreElements()) {
|
|
|
|
var idRes = EM_R("id");
|
|
|
|
var targetRes = getResourceForID(id);
|
|
|
|
var property = EM_R("targetApplication");
|
|
|
|
var anon = gRDF.GetAnonymousResource();
|
|
|
|
this._inner.Assert(anon, idRes, EM_L(appID), true);
|
|
|
|
this._inner.Assert(anon, updatedMinVersionRes, EM_L(updatedMinVersion), true);
|
|
|
|
this._inner.Assert(anon, updatedMaxVersionRes, EM_L(updatedMaxVersion), true);
|
|
|
|
this._inner.Assert(targetRes, property, anon, true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
while (targetApps.hasMoreElements()) {
|
|
|
|
var targetApp = targetApps.getNext();
|
2007-09-03 20:07:11 -07:00
|
|
|
if (targetApp instanceof Ci.nsIRDFResource) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var foundAppID = stringData(this._inner.GetTarget(targetApp, EM_R("id"), true));
|
2007-08-29 01:16:15 -07:00
|
|
|
// Different target application?
|
|
|
|
if (foundAppID != targetAppID)
|
2007-03-22 10:30:00 -07:00
|
|
|
continue;
|
|
|
|
this._inner.Assert(targetApp, updatedMinVersionRes, EM_L(updatedMinVersion), true);
|
|
|
|
this._inner.Assert(targetApp, updatedMaxVersionRes, EM_L(updatedMaxVersion), true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.Flush();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the target application info for an item from a datasource.
|
|
|
|
* @param id
|
|
|
|
* The GUID of the item to discover target application info for
|
|
|
|
* @param datasource
|
|
|
|
* The datasource to look up target application info in
|
|
|
|
* @returns A JS Object with the following properties:
|
2007-08-29 01:16:15 -07:00
|
|
|
* "appID" The target application ID used for checking
|
|
|
|
* compatibility for this item.
|
2007-03-22 10:30:00 -07:00
|
|
|
* "minVersion" The minimum version of the target application
|
|
|
|
* that this item can run in
|
|
|
|
* "maxVersion" The maximum version of the target application
|
|
|
|
* that this item can run in
|
|
|
|
* or null, if no target application data exists for the specified
|
|
|
|
* id in the supplied datasource.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
getTargetApplicationInfo: function EMDS_getTargetApplicationInfo(id, datasource) {
|
2007-08-29 01:16:15 -07:00
|
|
|
var appID = gApp.ID;
|
|
|
|
// The default theme is always compatible.
|
2007-03-22 10:30:00 -07:00
|
|
|
if (getResourceForID(id).EqualsNode(this._defaultTheme)) {
|
|
|
|
var ver = gApp.version;
|
2007-08-29 01:16:15 -07:00
|
|
|
return { appID: appID, minVersion: ver, maxVersion: ver };
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var r = getResourceForID(id);
|
|
|
|
var targetApps = datasource.GetTargets(r, EM_R("targetApplication"), true);
|
|
|
|
if (!targetApps)
|
|
|
|
return null;
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!targetApps.hasMoreElements())
|
2007-08-29 01:16:15 -07:00
|
|
|
targetApps = datasource.GetTargets(gInstallManifestRoot, EM_R("targetApplication"), true);
|
|
|
|
var outData = null;
|
2007-03-22 10:30:00 -07:00
|
|
|
while (targetApps.hasMoreElements()) {
|
|
|
|
var targetApp = targetApps.getNext();
|
2007-09-03 20:07:11 -07:00
|
|
|
if (targetApp instanceof Ci.nsIRDFResource) {
|
2007-03-22 10:30:00 -07:00
|
|
|
try {
|
|
|
|
var foundAppID = stringData(datasource.GetTarget(targetApp, EM_R("id"), true));
|
2007-08-29 01:16:15 -07:00
|
|
|
// Different target application?
|
|
|
|
if (foundAppID != appID && foundAppID != TOOLKIT_ID)
|
2007-03-22 10:30:00 -07:00
|
|
|
continue;
|
2007-08-29 01:16:15 -07:00
|
|
|
|
|
|
|
outData = { appID: foundAppID,
|
|
|
|
minVersion: stringData(datasource.GetTarget(targetApp, EM_R("minVersion"), true)),
|
|
|
|
maxVersion: stringData(datasource.GetTarget(targetApp, EM_R("maxVersion"), true)) };
|
|
|
|
if (foundAppID == appID)
|
|
|
|
return outData;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
catch (e) {
|
2007-03-22 10:30:00 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
return outData;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Sets the target application info for an item in a datasource.
|
|
|
|
* @param id
|
|
|
|
* The GUID of the item to discover target application info for
|
2007-08-29 01:16:15 -07:00
|
|
|
* @param targetAppID
|
|
|
|
* The target application ID used for checking compatibility for this
|
|
|
|
* item.
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param minVersion
|
|
|
|
* The minimum version of the target application that this item can
|
|
|
|
* run in
|
|
|
|
* @param maxVersion
|
|
|
|
* The maximum version of the target application that this item can
|
|
|
|
* run in
|
|
|
|
* @param datasource
|
2007-12-06 05:47:48 -08:00
|
|
|
* The datasource to look up target application info in
|
2007-08-29 01:16:15 -07:00
|
|
|
*
|
|
|
|
* @note Add-ons can specify a targetApplication id of toolkit@mozilla.org in
|
|
|
|
* their install manifest for compatibility with all apps using a
|
|
|
|
* specific release of the toolkit.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
setTargetApplicationInfo: function EMDS_setTargetApplicationInfo(id, targetAppID,
|
|
|
|
minVersion,
|
|
|
|
maxVersion,
|
|
|
|
datasource) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var targetDataSource = datasource;
|
|
|
|
if (!targetDataSource)
|
|
|
|
targetDataSource = this._inner;
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var appID = gApp.ID;
|
|
|
|
var r = getResourceForID(id);
|
|
|
|
var targetApps = targetDataSource.GetTargets(r, EM_R("targetApplication"), true);
|
|
|
|
if (!targetApps.hasMoreElements())
|
2007-08-29 01:16:15 -07:00
|
|
|
targetApps = datasource.GetTargets(gInstallManifestRoot, EM_R("targetApplication"), true);
|
2007-03-22 10:30:00 -07:00
|
|
|
while (targetApps.hasMoreElements()) {
|
|
|
|
var targetApp = targetApps.getNext();
|
2007-09-03 20:07:11 -07:00
|
|
|
if (targetApp instanceof Ci.nsIRDFResource) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var foundAppID = stringData(targetDataSource.GetTarget(targetApp, EM_R("id"), true));
|
2007-08-29 01:16:15 -07:00
|
|
|
// Different target application?
|
|
|
|
if (foundAppID != targetAppID)
|
2007-03-22 10:30:00 -07:00
|
|
|
continue;
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
this._setProperty(targetDataSource, targetApp, EM_R("minVersion"), EM_L(minVersion));
|
|
|
|
this._setProperty(targetDataSource, targetApp, EM_R("maxVersion"), EM_L(maxVersion));
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// If we were setting these properties on the main datasource, flush
|
|
|
|
// it now. (Don't flush changes set on Install Manifests - they are
|
|
|
|
// fleeting).
|
|
|
|
if (!datasource)
|
|
|
|
this.Flush();
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
|
|
|
/**
|
2007-03-22 10:30:00 -07:00
|
|
|
* Gets a property of an item
|
|
|
|
* @param id
|
|
|
|
* The GUID of the item
|
|
|
|
* @param property
|
|
|
|
* The name of the property (excluding EM_NS)
|
2007-08-29 01:16:15 -07:00
|
|
|
* @returns The literal value of the property, or undefined if there is no
|
2007-03-22 10:30:00 -07:00
|
|
|
* value.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
getItemProperty: function EMDS_getItemProperty(id, property) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var item = getResourceForID(id);
|
|
|
|
if (!item) {
|
|
|
|
LOG("getItemProperty failing for lack of an item. This means getResourceForItem \
|
|
|
|
failed to locate a resource for aItemID (item ID = " + id + ", property = " + property + ")");
|
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
else
|
2007-03-22 10:30:00 -07:00
|
|
|
return this._getItemProperty(item, property);
|
|
|
|
return undefined;
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Gets a property of an item resource
|
|
|
|
* @param itemResource
|
|
|
|
* The RDF Resource of the item
|
|
|
|
* @param property
|
|
|
|
* The name of the property (excluding EM_NS)
|
|
|
|
* @returns The literal value of the property, or undefined if there is no
|
|
|
|
* value.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_getItemProperty: function EMDS__getItemProperty(itemResource, property) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var target = this.GetTarget(itemResource, EM_R(property), true);
|
|
|
|
var value = stringData(target);
|
|
|
|
if (value === undefined)
|
|
|
|
value = intData(target);
|
|
|
|
return value === undefined ? "" : value;
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Sets a property on an item.
|
|
|
|
* @param id
|
|
|
|
* The GUID of the item
|
|
|
|
* @param propertyArc
|
|
|
|
* The RDF Resource of the property arc
|
|
|
|
* @param propertyValue
|
|
|
|
* A nsIRDFLiteral value of the property to be set
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
setItemProperty: function EMDS_setItemProperty(id, propertyArc, propertyValue) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var item = getResourceForID(id);
|
|
|
|
this._setProperty(this._inner, item, propertyArc, propertyValue);
|
2007-08-29 01:16:15 -07:00
|
|
|
this.Flush();
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2008-07-25 09:23:25 -07:00
|
|
|
/**
|
|
|
|
* Sets one or more properties for an item.
|
|
|
|
* @param id
|
|
|
|
* The ID of the item
|
|
|
|
* @param properties
|
|
|
|
* A JS object which maps properties to values.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
setItemProperties: function EMDS_setItemProperties(id, properties) {
|
2008-07-25 09:23:25 -07:00
|
|
|
var item = getResourceForID(id);
|
|
|
|
for (var key in properties)
|
|
|
|
this._setProperty(this._inner, item, EM_R(key), properties[key]);
|
|
|
|
this.Flush();
|
|
|
|
},
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Inserts the RDF resource for an item into a container.
|
|
|
|
* @param id
|
|
|
|
* The GUID of the item
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
insertItemIntoContainer: function EMDS_insertItemIntoContainer(id) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Get the target container and resource
|
|
|
|
var ctr = getContainer(this._inner, this._itemRoot);
|
|
|
|
var itemResource = getResourceForID(id);
|
2007-08-29 01:16:15 -07:00
|
|
|
// Don't bother adding the extension to the list if it's already there.
|
2007-03-22 10:30:00 -07:00
|
|
|
// (i.e. we're upgrading)
|
|
|
|
var oldIndex = ctr.IndexOf(itemResource);
|
|
|
|
if (oldIndex == -1)
|
|
|
|
ctr.AppendElement(itemResource);
|
|
|
|
this.Flush();
|
2007-08-29 01:16:15 -07:00
|
|
|
},
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes the RDF resource for an item from its container.
|
|
|
|
* @param id
|
|
|
|
* The GUID of the item
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
removeItemFromContainer: function EMDS_removeItemFromContainer(id) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var ctr = getContainer(this._inner, this._itemRoot);
|
|
|
|
var itemResource = getResourceForID(id);
|
|
|
|
ctr.RemoveElement(itemResource, true);
|
|
|
|
this.Flush();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2007-08-29 01:16:15 -07:00
|
|
|
* Removes a corrupt item entry from the extension list added due to buggy
|
|
|
|
* code in previous EM versions!
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param id
|
|
|
|
* The GUID of the item
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
removeCorruptItem: function EMDS_removeCorruptItem(id) {
|
2007-03-22 10:30:00 -07:00
|
|
|
this.removeItemMetadata(id);
|
|
|
|
this.removeItemFromContainer(id);
|
2008-04-01 02:26:47 -07:00
|
|
|
this.visibleItems[id] = null;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a corrupt download entry from the list
|
|
|
|
* @param uri
|
|
|
|
* The RDF URI of the item.
|
2007-08-29 01:16:15 -07:00
|
|
|
* @returns The RDF Resource of the removed entry
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
removeCorruptDLItem: function EMDS_removeCorruptDLItem(uri) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var itemResource = gRDF.GetResource(uri);
|
|
|
|
var ctr = getContainer(this._inner, this._itemRoot);
|
|
|
|
if (ctr.IndexOf(itemResource) != -1) {
|
|
|
|
ctr.RemoveElement(itemResource, true);
|
|
|
|
this._cleanResource(itemResource);
|
|
|
|
this.Flush();
|
|
|
|
}
|
|
|
|
return itemResource;
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-06-25 14:02:46 -07:00
|
|
|
/**
|
|
|
|
* Copies localized properties from an install manifest to the datasource
|
|
|
|
*
|
|
|
|
* @param installManifest
|
|
|
|
* The Install Manifest datasource we are copying from
|
|
|
|
* @param source
|
|
|
|
* The source resource of the localized properties
|
|
|
|
* @param target
|
|
|
|
* The target resource to store the localized properties
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_addLocalizedMetadata: function EMDS__addLocalizedMetadata(installManifest,
|
|
|
|
sourceRes, targetRes)
|
2007-06-25 14:02:46 -07:00
|
|
|
{
|
|
|
|
var singleProps = ["name", "description", "creator", "homepageURL"];
|
|
|
|
|
|
|
|
for (var i = 0; i < singleProps.length; ++i) {
|
|
|
|
var property = EM_R(singleProps[i]);
|
|
|
|
var literal = installManifest.GetTarget(sourceRes, property, true);
|
|
|
|
// If literal is null, _setProperty will remove any existing.
|
|
|
|
this._setProperty(this._inner, targetRes, property, literal);
|
2007-08-29 01:16:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Assert properties with multiple values
|
2007-06-25 14:02:46 -07:00
|
|
|
var manyProps = ["developer", "translator", "contributor"];
|
|
|
|
for (var i = 0; i < manyProps.length; ++i) {
|
|
|
|
var property = EM_R(manyProps[i]);
|
|
|
|
var literals = installManifest.GetTargets(sourceRes, property, true);
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-06-25 14:02:46 -07:00
|
|
|
var oldValues = this._inner.GetTargets(targetRes, property, true);
|
|
|
|
while (oldValues.hasMoreElements()) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var oldValue = oldValues.getNext().QueryInterface(Ci.nsIRDFNode);
|
2007-06-25 14:02:46 -07:00
|
|
|
this._inner.Unassert(targetRes, property, oldValue);
|
|
|
|
}
|
|
|
|
while (literals.hasMoreElements()) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var literal = literals.getNext().QueryInterface(Ci.nsIRDFNode);
|
2007-06-25 14:02:46 -07:00
|
|
|
this._inner.Assert(targetRes, property, literal, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Copies metadata from an Install Manifest Datasource into the Extensions
|
|
|
|
* DataSource.
|
|
|
|
* @param id
|
|
|
|
* The GUID of the item
|
|
|
|
* @param installManifest
|
|
|
|
* The Install Manifest datasource we are copying from
|
|
|
|
* @param installLocation
|
2007-08-29 01:16:15 -07:00
|
|
|
* The Install Location of the item.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
addItemMetadata: function EMDS_addItemMetadata(id, installManifest, installLocation) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var targetRes = getResourceForID(id);
|
2007-06-30 10:17:03 -07:00
|
|
|
// Remove any temporary assertions used for the install process
|
|
|
|
this._setProperty(this._inner, targetRes, EM_R("newVersion"), null);
|
2007-08-29 01:16:15 -07:00
|
|
|
// Copy the assertions over from the source datasource.
|
2007-03-22 10:30:00 -07:00
|
|
|
// Assert properties with single values
|
2007-06-25 14:02:46 -07:00
|
|
|
var singleProps = ["version", "updateURL", "updateService", "optionsURL",
|
2007-09-03 14:44:12 -07:00
|
|
|
"aboutURL", "iconURL", "internalName", "updateKey"];
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-08-29 01:16:15 -07:00
|
|
|
// Items installed into restricted Install Locations can also be locked
|
2009-09-18 07:11:26 -07:00
|
|
|
// (can't be removed or disabled)
|
2007-03-22 10:30:00 -07:00
|
|
|
if (installLocation.restricted)
|
2009-09-18 07:11:26 -07:00
|
|
|
singleProps = singleProps.concat(["locked"]);
|
2007-08-29 01:16:15 -07:00
|
|
|
if (installLocation.name == KEY_APP_GLOBAL)
|
2007-03-22 10:30:00 -07:00
|
|
|
singleProps = singleProps.concat(["appManaged"]);
|
|
|
|
for (var i = 0; i < singleProps.length; ++i) {
|
|
|
|
var property = EM_R(singleProps[i]);
|
|
|
|
var literal = installManifest.GetTarget(gInstallManifestRoot, property, true);
|
|
|
|
// If literal is null, _setProperty will remove any existing.
|
|
|
|
this._setProperty(this._inner, targetRes, property, literal);
|
2007-08-29 01:16:15 -07:00
|
|
|
}
|
|
|
|
|
2007-06-25 14:02:46 -07:00
|
|
|
var localizedProp = EM_R("localized");
|
|
|
|
var localeProp = EM_R("locale");
|
|
|
|
// Remove old localized properties
|
|
|
|
var oldValues = this._inner.GetTargets(targetRes, localizedProp, true);
|
|
|
|
while (oldValues.hasMoreElements()) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var oldValue = oldValues.getNext().QueryInterface(Ci.nsIRDFNode);
|
2007-06-25 14:02:46 -07:00
|
|
|
this._cleanResource(oldValue);
|
|
|
|
this._inner.Unassert(targetRes, localizedProp, oldValue);
|
|
|
|
}
|
|
|
|
// Add each localized property
|
|
|
|
var localizations = installManifest.GetTargets(gInstallManifestRoot, localizedProp, true);
|
|
|
|
while (localizations.hasMoreElements()) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var localization = localizations.getNext().QueryInterface(Ci.nsIRDFResource);
|
2007-06-25 14:02:46 -07:00
|
|
|
var anon = gRDF.GetAnonymousResource();
|
|
|
|
var literals = installManifest.GetTargets(localization, localeProp, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
while (literals.hasMoreElements()) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var literal = literals.getNext().QueryInterface(Ci.nsIRDFNode);
|
2007-06-25 14:02:46 -07:00
|
|
|
this._inner.Assert(anon, localeProp, literal, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-06-25 14:02:46 -07:00
|
|
|
this._addLocalizedMetadata(installManifest, localization, anon);
|
|
|
|
this._inner.Assert(targetRes, localizedProp, anon, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-06-25 14:02:46 -07:00
|
|
|
// Add the fallback properties
|
|
|
|
this._addLocalizedMetadata(installManifest, gInstallManifestRoot, targetRes);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Version/Dependency Info
|
|
|
|
var versionProps = ["targetApplication", "requires"];
|
|
|
|
var idRes = EM_R("id");
|
|
|
|
var minVersionRes = EM_R("minVersion");
|
|
|
|
var maxVersionRes = EM_R("maxVersion");
|
|
|
|
for (var i = 0; i < versionProps.length; ++i) {
|
|
|
|
var property = EM_R(versionProps[i]);
|
|
|
|
var newVersionInfos = installManifest.GetTargets(gInstallManifestRoot, property, true);
|
|
|
|
|
|
|
|
var oldVersionInfos = this._inner.GetTargets(targetRes, property, true);
|
|
|
|
while (oldVersionInfos.hasMoreElements()) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var oldVersionInfo = oldVersionInfos.getNext().QueryInterface(Ci.nsIRDFResource);
|
2007-03-22 10:30:00 -07:00
|
|
|
this._cleanResource(oldVersionInfo);
|
|
|
|
this._inner.Unassert(targetRes, property, oldVersionInfo);
|
|
|
|
}
|
|
|
|
while (newVersionInfos.hasMoreElements()) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var newVersionInfo = newVersionInfos.getNext().QueryInterface(Ci.nsIRDFResource);
|
2007-03-22 10:30:00 -07:00
|
|
|
var anon = gRDF.GetAnonymousResource();
|
|
|
|
this._inner.Assert(anon, idRes, installManifest.GetTarget(newVersionInfo, idRes, true), true);
|
|
|
|
this._inner.Assert(anon, minVersionRes, installManifest.GetTarget(newVersionInfo, minVersionRes, true), true);
|
|
|
|
this._inner.Assert(anon, maxVersionRes, installManifest.GetTarget(newVersionInfo, maxVersionRes, true), true);
|
|
|
|
this._inner.Assert(targetRes, property, anon, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.updateProperty(id, "opType");
|
|
|
|
this.updateProperty(id, "updateable");
|
|
|
|
this.Flush();
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Strips an item entry of all assertions.
|
|
|
|
* @param id
|
|
|
|
* The GUID of the item
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
removeItemMetadata: function EMDS_removeItemMetadata(id) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var item = getResourceForID(id);
|
2007-06-25 14:02:46 -07:00
|
|
|
var resources = ["targetApplication", "requires", "localized"];
|
2007-03-22 10:30:00 -07:00
|
|
|
for (var i = 0; i < resources.length; ++i) {
|
|
|
|
var targetApps = this._inner.GetTargets(item, EM_R(resources[i]), true);
|
|
|
|
while (targetApps.hasMoreElements()) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var targetApp = targetApps.getNext().QueryInterface(Ci.nsIRDFResource);
|
2007-03-22 10:30:00 -07:00
|
|
|
this._cleanResource(targetApp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this._cleanResource(item);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
2007-08-29 01:16:15 -07:00
|
|
|
* Strips a resource of all outbound assertions. We use methods like this
|
2007-03-22 10:30:00 -07:00
|
|
|
* since the RDFXMLDatasource will write out all assertions, even if they
|
2007-08-29 01:16:15 -07:00
|
|
|
* are not connected through our root.
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param resource
|
2007-08-29 01:16:15 -07:00
|
|
|
* The resource to clean.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_cleanResource: function EMDS__cleanResource(resource) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Remove outward arcs
|
|
|
|
var arcs = this._inner.ArcLabelsOut(resource);
|
|
|
|
while (arcs.hasMoreElements()) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var arc = arcs.getNext().QueryInterface(Ci.nsIRDFResource);
|
2007-03-22 10:30:00 -07:00
|
|
|
var targets = this._inner.GetTargets(resource, arc, true);
|
|
|
|
while (targets.hasMoreElements()) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var value = targets.getNext().QueryInterface(Ci.nsIRDFNode);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (value)
|
|
|
|
this._inner.Unassert(resource, arc, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Notify views that this propery has changed (this is for properties that
|
|
|
|
* are implemented by this datasource rather than by the inner in-memory
|
|
|
|
* datasource and thus do not get free change handling).
|
2007-08-29 01:16:15 -07:00
|
|
|
* @param id
|
2007-03-22 10:30:00 -07:00
|
|
|
* The GUID of the item to update the property for.
|
|
|
|
* @param property
|
|
|
|
* The property (less EM_NS) to update.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
updateProperty: function EMDS_updateProperty(id, property) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var item = getResourceForID(id);
|
|
|
|
this._updateProperty(item, property);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Notify views that this propery has changed (this is for properties that
|
|
|
|
* are implemented by this datasource rather than by the inner in-memory
|
|
|
|
* datasource and thus do not get free change handling). This allows updating
|
|
|
|
* properties for download items which don't have the em item prefix in there
|
|
|
|
( resource value. In most instances updateProperty should be used.
|
|
|
|
* @param item
|
|
|
|
* The item to update the property for.
|
|
|
|
* @param property
|
|
|
|
* The property (less EM_NS) to update.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_updateProperty: function EMDS__updateProperty(item, property) {
|
2007-06-21 16:17:08 -07:00
|
|
|
if (item) {
|
|
|
|
var propertyResource = EM_R(property);
|
|
|
|
var value = this.GetTarget(item, propertyResource, true);
|
|
|
|
for (var i = 0; i < this._observers.length; ++i) {
|
|
|
|
if (value)
|
2007-08-29 01:16:15 -07:00
|
|
|
this._observers[i].onChange(this, item, propertyResource,
|
2007-06-21 16:17:08 -07:00
|
|
|
EM_L(""), value);
|
|
|
|
else
|
2007-08-29 01:16:15 -07:00
|
|
|
this._observers[i].onUnassert(this, item, propertyResource,
|
2007-06-21 16:17:08 -07:00
|
|
|
EM_L(""));
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Determines if an Item is an active download
|
|
|
|
* @param id
|
|
|
|
* The ID of the item. This will be a uri scheme without the
|
|
|
|
* em item prefix so getProperty shouldn't be used.
|
|
|
|
* @returns true if the item is an active download, false otherwise.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
isDownloadItem: function EMDS_isDownloadItem(id) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var downloadURL = stringData(this.GetTarget(gRDF.GetResource(id), EM_R("downloadURL"), true));
|
|
|
|
return downloadURL && downloadURL != "";
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds an entry representing an active download to the appropriate container
|
|
|
|
* @param addon
|
2007-08-29 01:16:15 -07:00
|
|
|
* An object implementing nsIUpdateItem for the addon being
|
2007-03-22 10:30:00 -07:00
|
|
|
* downloaded.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
addDownload: function EMDS_addDownload(addon) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Updates have already been added to the datasource so we just update the
|
|
|
|
// download state.
|
|
|
|
if (addon.id != addon.xpiURL) {
|
|
|
|
this.updateDownloadState(PREFIX_ITEM_URI + addon.id, "waiting");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var res = gRDF.GetResource(addon.xpiURL);
|
|
|
|
this._setProperty(this._inner, res, EM_R("name"), EM_L(addon.name));
|
|
|
|
this._setProperty(this._inner, res, EM_R("version"), EM_L(addon.version));
|
|
|
|
this._setProperty(this._inner, res, EM_R("iconURL"), EM_L(addon.iconURL));
|
|
|
|
this._setProperty(this._inner, res, EM_R("downloadURL"), EM_L(addon.xpiURL));
|
|
|
|
this._setProperty(this._inner, res, EM_R("type"), EM_I(addon.type));
|
|
|
|
|
|
|
|
var ctr = getContainer(this._inner, this._itemRoot);
|
|
|
|
if (ctr.IndexOf(res) == -1)
|
|
|
|
ctr.AppendElement(res);
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
this.updateDownloadState(addon.xpiURL, "waiting");
|
|
|
|
this.Flush();
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Adds an entry representing an item that is incompatible and is being
|
|
|
|
* checked for a compatibility update.
|
|
|
|
* @param name
|
|
|
|
* The display name of the item being checked
|
|
|
|
* @param url
|
|
|
|
* The URL string of the xpi file that has been staged.
|
|
|
|
* @param type
|
|
|
|
* The nsIUpdateItem type of the item
|
|
|
|
* @param version
|
|
|
|
* The version of the item
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
addIncompatibleUpdateItem: function EMDS_addIncompatibleUpdateItem(name, url, type, version) {
|
2007-09-17 11:05:04 -07:00
|
|
|
var iconURL = (type == Ci.nsIUpdateItem.TYPE_THEME) ? URI_GENERIC_ICON_THEME :
|
|
|
|
URI_GENERIC_ICON_XPINSTALL;
|
2007-03-22 10:30:00 -07:00
|
|
|
var extensionsStrings = BundleManager.getBundle(URI_EXTENSIONS_PROPERTIES);
|
|
|
|
var updateMsg = extensionsStrings.formatStringFromName("incompatibleUpdateMessage",
|
|
|
|
[BundleManager.appName, name], 2)
|
|
|
|
|
|
|
|
var res = gRDF.GetResource(url);
|
|
|
|
this._setProperty(this._inner, res, EM_R("name"), EM_L(name));
|
|
|
|
this._setProperty(this._inner, res, EM_R("iconURL"), EM_L(iconURL));
|
|
|
|
this._setProperty(this._inner, res, EM_R("downloadURL"), EM_L(url));
|
|
|
|
this._setProperty(this._inner, res, EM_R("type"), EM_I(type));
|
|
|
|
this._setProperty(this._inner, res, EM_R("version"), EM_L(version));
|
|
|
|
this._setProperty(this._inner, res, EM_R("incompatibleUpdate"), EM_L("true"));
|
|
|
|
this._setProperty(this._inner, res, EM_R("description"), EM_L(updateMsg));
|
|
|
|
|
|
|
|
var ctr = getContainer(this._inner, this._itemRoot);
|
|
|
|
if (ctr.IndexOf(res) == -1)
|
|
|
|
ctr.AppendElement(res);
|
|
|
|
|
|
|
|
this.updateDownloadState(url, "incompatibleUpdate");
|
|
|
|
this.Flush();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes an active download from the appropriate container
|
|
|
|
* @param url
|
|
|
|
* The URL string of the active download to be removed
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
removeDownload: function EMDS_removeDownload(url) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var res = gRDF.GetResource(url);
|
|
|
|
var ctr = getContainer(this._inner, this._itemRoot);
|
2007-08-29 01:16:15 -07:00
|
|
|
if (ctr.IndexOf(res) != -1)
|
2007-03-22 10:30:00 -07:00
|
|
|
ctr.RemoveElement(res, true);
|
|
|
|
this._cleanResource(res);
|
|
|
|
this.updateDownloadState(url, null);
|
|
|
|
this.Flush();
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* A hash of RDF resource values (e.g. Add-on IDs or XPI URLs) that represent
|
|
|
|
* installation progress for a single browser session.
|
|
|
|
*/
|
|
|
|
_progressData: { },
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the install progress data for a given ID (e.g. Add-on IDs or
|
|
|
|
* XPI URLs).
|
|
|
|
* @param id
|
|
|
|
* The URL string of the active download to be removed
|
|
|
|
* @param state
|
|
|
|
* The current state in the installation process. If null the object
|
|
|
|
* is deleted from _progressData.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
updateDownloadState: function EMDS_updateDownloadState(id, state) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!state) {
|
|
|
|
if (id in this._progressData)
|
|
|
|
delete this._progressData[id];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
2007-08-29 01:16:15 -07:00
|
|
|
if (!(id in this._progressData))
|
2007-03-22 10:30:00 -07:00
|
|
|
this._progressData[id] = { };
|
|
|
|
this._progressData[id].state = state;
|
|
|
|
}
|
|
|
|
var item = gRDF.GetResource(id);
|
|
|
|
this._updateProperty(item, "state");
|
|
|
|
},
|
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
updateDownloadProgress: function EMDS_updateDownloadProgress(id, progress) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!progress) {
|
|
|
|
if (!(id in this._progressData))
|
|
|
|
return;
|
|
|
|
this._progressData[id].progress = null;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!(id in this._progressData))
|
|
|
|
this.updateDownloadState(id, "downloading");
|
|
|
|
|
|
|
|
if (this._progressData[id].progress == progress)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._progressData[id].progress = progress;
|
|
|
|
}
|
|
|
|
var item = gRDF.GetResource(id);
|
|
|
|
this._updateProperty(item, "progress");
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A GUID->location-key hash of items that are visible to the application.
|
|
|
|
* These are items that show up in the Extension/Themes etc UI. If there is
|
2007-08-29 01:16:15 -07:00
|
|
|
* an instance of the same item installed in Install Locations of differing
|
|
|
|
* profiles, the item at the highest priority location will appear in this
|
2007-03-22 10:30:00 -07:00
|
|
|
* list.
|
|
|
|
*/
|
|
|
|
visibleItems: { },
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
2007-08-29 01:16:15 -07:00
|
|
|
* Walk the list of installed items and determine what the visible list is,
|
|
|
|
* based on which items are visible at the highest priority locations.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_buildVisibleItemList: function EMDS__buildVisibleItemList() {
|
2007-03-22 10:30:00 -07:00
|
|
|
var ctr = getContainer(this, this._itemRoot);
|
|
|
|
var items = ctr.GetElements();
|
|
|
|
while (items.hasMoreElements()) {
|
2007-09-03 20:07:11 -07:00
|
|
|
var item = items.getNext().QueryInterface(Ci.nsIRDFResource);
|
2007-03-22 10:30:00 -07:00
|
|
|
// Resource URIs adopt the format: location-key,item-id
|
|
|
|
var id = stripPrefix(item.Value, PREFIX_ITEM_URI);
|
|
|
|
this.visibleItems[id] = this.getItemProperty(id, "installLocation");
|
|
|
|
}
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Updates an item's location in the visible item list.
|
|
|
|
* @param id
|
|
|
|
* The GUID of the item to update
|
|
|
|
* @param locationKey
|
|
|
|
* The name of the Install Location where the item is installed.
|
|
|
|
* @param forceReplace
|
2007-08-29 01:16:15 -07:00
|
|
|
* true if the new location should be used, regardless of its
|
2007-03-22 10:30:00 -07:00
|
|
|
* priority relationship to existing entries, false if the location
|
|
|
|
* should only be updated if its priority is lower than the existing
|
|
|
|
* value.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
updateVisibleList: function EMDS_updateVisibleList(id, locationKey, forceReplace) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (id in this.visibleItems && this.visibleItems[id]) {
|
|
|
|
var oldLocation = InstallLocations.get(this.visibleItems[id]);
|
|
|
|
var newLocation = InstallLocations.get(locationKey);
|
2008-05-23 01:49:59 -07:00
|
|
|
if (forceReplace || !oldLocation || newLocation.priority < oldLocation.priority)
|
2007-03-22 10:30:00 -07:00
|
|
|
this.visibleItems[id] = locationKey;
|
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
else
|
2007-03-22 10:30:00 -07:00
|
|
|
this.visibleItems[id] = locationKey;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load the Extensions Datasource from disk.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
loadExtensions: function EMDS_loadExtensions() {
|
2009-10-23 12:42:48 -07:00
|
|
|
var extensionsFile = FileUtils.getFile(KEY_PROFILEDIR, [FILE_EXTENSIONS]);
|
2007-03-22 10:30:00 -07:00
|
|
|
try {
|
|
|
|
this._inner = gRDF.GetDataSourceBlocking(getURLSpecFromFile(extensionsFile));
|
|
|
|
}
|
|
|
|
catch (e) {
|
2007-12-11 16:56:09 -08:00
|
|
|
ERROR("Datasource::loadExtensions: removing corrupted extensions datasource " +
|
|
|
|
" file = " + extensionsFile.path + ", exception = " + e + "\n");
|
2007-03-22 10:30:00 -07:00
|
|
|
extensionsFile.remove(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-09-03 20:07:11 -07:00
|
|
|
var cu = Cc["@mozilla.org/rdf/container-utils;1"].
|
|
|
|
getService(Ci.nsIRDFContainerUtils);
|
2007-03-22 10:30:00 -07:00
|
|
|
cu.MakeSeq(this._inner, this._itemRoot);
|
|
|
|
|
|
|
|
this._buildVisibleItemList();
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* See nsIExtensionManager.idl
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
onUpdateStarted: function EMDS_onUpdateStarted() {
|
2007-03-22 10:30:00 -07:00
|
|
|
LOG("Datasource: Update Started");
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* See nsIExtensionManager.idl
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
onUpdateEnded: function EMDS_onUpdateEnded() {
|
2007-03-22 10:30:00 -07:00
|
|
|
LOG("Datasource: Update Ended");
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* See nsIExtensionManager.idl
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
onAddonUpdateStarted: function EMDS_onAddonUpdateStarted(addon) {
|
2007-08-29 01:16:15 -07:00
|
|
|
if (!addon)
|
2007-09-03 20:07:11 -07:00
|
|
|
throw Cr.NS_ERROR_INVALID_ARG;
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
LOG("Datasource: Addon Update Started: " + addon.id);
|
|
|
|
this.updateProperty(addon.id, "availableUpdateURL");
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* See nsIExtensionManager.idl
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
onAddonUpdateEnded: function EMDS_onAddonUpdateEnded(addon, status) {
|
2007-08-29 01:16:15 -07:00
|
|
|
if (!addon)
|
2007-09-03 20:07:11 -07:00
|
|
|
throw Cr.NS_ERROR_INVALID_ARG;
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
LOG("Datasource: Addon Update Ended: " + addon.id + ", status: " + status);
|
|
|
|
var url = null, hash = null, version = null;
|
2007-09-17 11:05:04 -07:00
|
|
|
var updateAvailable = status == Ci.nsIAddonUpdateCheckListener.STATUS_UPDATE;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (updateAvailable) {
|
|
|
|
url = EM_L(addon.xpiURL);
|
|
|
|
if (addon.xpiHash)
|
|
|
|
hash = EM_L(addon.xpiHash);
|
|
|
|
version = EM_L(addon.version);
|
|
|
|
}
|
2008-07-25 09:23:25 -07:00
|
|
|
this.setItemProperties(addon.id, {
|
|
|
|
availableUpdateURL: url,
|
|
|
|
availableUpdateHash: hash,
|
|
|
|
availableUpdateVersion: version
|
|
|
|
});
|
2007-03-22 10:30:00 -07:00
|
|
|
this.updateProperty(addon.id, "availableUpdateURL");
|
|
|
|
},
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIRDFDataSource
|
|
|
|
get URI() {
|
|
|
|
return "rdf:extensions";
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
GetSource: function EMDS_GetSource(property, target, truthValue) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return this._inner.GetSource(property, target, truthValue);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
GetSources: function EMDS_GetSources(property, target, truthValue) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return this._inner.GetSources(property, target, truthValue);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
2009-08-20 02:59:07 -07:00
|
|
|
* Gets an URL to an item's image file
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param item
|
2007-08-29 01:16:15 -07:00
|
|
|
* The RDF Resource representing the item
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param fileName
|
|
|
|
* The file to locate a URL for
|
|
|
|
* @returns An RDF Resource to the URL discovered, or the fallback
|
2007-08-29 01:16:15 -07:00
|
|
|
* if the discovery failed.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2009-08-20 02:59:07 -07:00
|
|
|
_getImageURL: function EMDS__getImageURL(item, fileName) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var id = stripPrefix(item.Value, PREFIX_ITEM_URI);
|
|
|
|
var installLocation = this._em.getInstallLocation(id);
|
2008-05-23 01:49:59 -07:00
|
|
|
if (!installLocation)
|
2009-09-07 02:09:11 -07:00
|
|
|
return null;
|
2007-03-22 10:30:00 -07:00
|
|
|
var file = installLocation.getItemFile(id, fileName)
|
2009-12-17 13:12:00 -08:00
|
|
|
if (file && file.exists())
|
2007-03-22 10:30:00 -07:00
|
|
|
return gRDF.GetResource(getURLSpecFromFile(file));
|
|
|
|
|
2009-08-20 02:59:07 -07:00
|
|
|
return null;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the em:iconURL property (icon url of the item)
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_rdfGet_iconURL: function EMDS__rdfGet_iconURL(item, property) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var id = stripPrefix(item.Value, PREFIX_ITEM_URI);
|
2009-09-10 01:10:30 -07:00
|
|
|
|
|
|
|
var installLocation = this._em.getInstallLocation(id);
|
|
|
|
if (!this.isDownloadItem(id) && !installLocation)
|
|
|
|
return null;
|
2009-08-20 02:59:07 -07:00
|
|
|
|
|
|
|
// Try to pick an icon from the item's install folder
|
|
|
|
iconURL = this._getImageURL(item, "icon.png");
|
|
|
|
if (iconURL)
|
|
|
|
return iconURL;
|
|
|
|
|
2009-09-10 01:10:30 -07:00
|
|
|
var type = this.getItemProperty(id, "type");
|
2009-08-20 02:59:07 -07:00
|
|
|
if (type == Ci.nsIUpdateItem.TYPE_THEME)
|
|
|
|
return gRDF.GetResource(URI_GENERIC_ICON_THEME);
|
|
|
|
|
|
|
|
// Only look for an iconURL if the item is not disabled and safe mode isn't
|
|
|
|
// active
|
|
|
|
if (!inSafeMode() && this.getItemProperty(id, "isDisabled") != "true") {
|
|
|
|
var iconURL = stringData(this._inner.GetTarget(item, property, true));
|
|
|
|
if (iconURL) {
|
|
|
|
try {
|
|
|
|
var uri = newURI(iconURL);
|
|
|
|
var scheme = uri.scheme;
|
|
|
|
// Only allow chrome URIs normally. When an item is being installed
|
|
|
|
// allow http(s) URIs.
|
|
|
|
if (scheme == "chrome" || (scheme == "http" || scheme == "https") &&
|
|
|
|
this._inner.hasArcOut(item, EM_R("downloadURL")))
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-08-20 02:59:07 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return gRDF.GetResource(URI_GENERIC_ICON_XPINSTALL);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Get the em:previewImage property (preview image of the item)
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_rdfGet_previewImage: function EMDS__rdfGet_previewImage(item, property) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var type = this.getItemProperty(stripPrefix(item.Value, PREFIX_ITEM_URI), "type");
|
2009-08-20 02:59:07 -07:00
|
|
|
if (type == Ci.nsIUpdateItem.TYPE_THEME)
|
|
|
|
return this._getImageURL(item, "preview.png");
|
2007-03-22 10:30:00 -07:00
|
|
|
return null;
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* If we're in safe mode, the item is disabled by the user or app, or the
|
2009-08-19 03:22:14 -07:00
|
|
|
* item is to not an extension then don't offer an options url.
|
|
|
|
*/
|
|
|
|
_rdfGet_optionsURL: function EMDS__rdfGet_optionsURL(item, property) {
|
|
|
|
var id = stripPrefix(item.Value, PREFIX_ITEM_URI);
|
|
|
|
if (inSafeMode() || this.getItemProperty(id, "isDisabled") == "true" ||
|
|
|
|
this.getItemProperty(id, "type") != Ci.nsIUpdateItem.TYPE_EXTENSION)
|
|
|
|
return EM_L("");
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If we're in safe mode, the item is disabled by the user or app, the item
|
|
|
|
* is not an extension, or the item is to be upgraded force the generic about
|
|
|
|
* dialog for the item.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_rdfGet_aboutURL: function EMDS__rdfGet_aboutURL(item, property) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var id = stripPrefix(item.Value, PREFIX_ITEM_URI);
|
|
|
|
if (inSafeMode() || this.getItemProperty(id, "isDisabled") == "true" ||
|
2009-08-19 03:22:14 -07:00
|
|
|
this.getItemProperty(id, "type") != Ci.nsIUpdateItem.TYPE_EXTENSION ||
|
2007-03-22 10:30:00 -07:00
|
|
|
this.getItemProperty(id, "opType") == OP_NEEDS_UPGRADE)
|
|
|
|
return EM_L("");
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
_rdfGet_installDate: function EMDS__rdfGet_installDate(item, property) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var id = stripPrefix(item.Value, PREFIX_ITEM_URI);
|
|
|
|
var key = this.getItemProperty(id, "installLocation");
|
|
|
|
if (key && key in StartupCache.entries && id in StartupCache.entries[key] &&
|
|
|
|
StartupCache.entries[key][id] && StartupCache.entries[key][id].mtime)
|
|
|
|
return EM_D(StartupCache.entries[key][id].mtime * 1000000);
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the em:compatible property (whether or not this item is compatible)
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_rdfGet_compatible: function EMDS__rdfGet_compatible(item, property) {
|
2009-08-06 07:24:52 -07:00
|
|
|
var compatible = this.isCompatible(this, item, true);
|
|
|
|
return compatible ? EM_L("true") : EM_L("false");
|
2007-08-29 01:16:15 -07:00
|
|
|
},
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-09-03 14:44:12 -07:00
|
|
|
/**
|
|
|
|
* Get the providesUpdatesSecurely property (whether or not this item has a
|
|
|
|
* secure update mechanism)
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_rdfGet_providesUpdatesSecurely: function EMDS__rdfGet_providesUpdatesSecurely(item, property) {
|
2007-09-03 14:44:12 -07:00
|
|
|
var id = stripPrefix(item.Value, PREFIX_ITEM_URI);
|
|
|
|
if (this.getItemProperty(id, "updateKey") ||
|
|
|
|
!this.getItemProperty(id, "updateURL") ||
|
|
|
|
this.getItemProperty(id, "updateURL").substring(0, 6) == "https:")
|
|
|
|
return EM_L("true");
|
|
|
|
return EM_L("false");
|
|
|
|
},
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Get the em:blocklisted property (whether or not this item is blocklisted)
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_rdfGet_blocklisted: function EMDS__rdfGet_blocklisted(item, property) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var id = stripPrefix(item.Value, PREFIX_ITEM_URI);
|
|
|
|
var version = this.getItemProperty(id, "version");
|
2007-08-15 17:43:12 -07:00
|
|
|
if (!gBlocklist)
|
2007-09-03 20:07:11 -07:00
|
|
|
gBlocklist = Cc["@mozilla.org/extensions/blocklist;1"].
|
|
|
|
getService(Ci.nsIBlocklistService);
|
2008-11-02 04:13:48 -08:00
|
|
|
if (gBlocklist.getAddonBlocklistState(id, version) == Ci.nsIBlocklistService.STATE_BLOCKED)
|
|
|
|
return EM_L("true");
|
|
|
|
|
|
|
|
return EM_L("false");
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the em:blocklistedsoft property (whether or not this item is listed in the blocklist
|
|
|
|
* at a low severity)
|
|
|
|
*/
|
|
|
|
_rdfGet_blocklistedsoft: function EMDS__rdfGet_blocklistedsoft(item, property) {
|
|
|
|
var id = stripPrefix(item.Value, PREFIX_ITEM_URI);
|
|
|
|
var version = this.getItemProperty(id, "version");
|
|
|
|
if (!gBlocklist)
|
|
|
|
gBlocklist = Cc["@mozilla.org/extensions/blocklist;1"].
|
|
|
|
getService(Ci.nsIBlocklistService);
|
|
|
|
if (gBlocklist.getAddonBlocklistState(id, version) == Ci.nsIBlocklistService.STATE_SOFTBLOCKED)
|
2007-08-15 17:43:12 -07:00
|
|
|
return EM_L("true");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return EM_L("false");
|
2007-08-29 01:16:15 -07:00
|
|
|
},
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Get the em:state property (represents the current phase of an install).
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_rdfGet_state: function EMDS__rdfGet_state(item, property) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var id = item.Value;
|
|
|
|
if (id in this._progressData)
|
|
|
|
return EM_L(this._progressData[id].state);
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the em:progress property from the _progressData js object. By storing
|
|
|
|
* progress which is updated repeastedly during a download we avoid
|
|
|
|
* repeastedly writing it to the rdf file.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_rdfGet_progress: function EMDS__rdfGet_progress(item, property) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var id = item.Value;
|
|
|
|
if (id in this._progressData)
|
|
|
|
return EM_I(this._progressData[id].progress);
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the em:appManaged property. This prevents extensions from hiding
|
|
|
|
* extensions installed into locations other than the app-global location.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_rdfGet_appManaged: function EMDS__rdfGet_appManaged(item, property) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var id = stripPrefix(item.Value, PREFIX_ITEM_URI);
|
|
|
|
var locationKey = this.getItemProperty(id, "installLocation");
|
|
|
|
if (locationKey != KEY_APP_GLOBAL)
|
|
|
|
return EM_L("false");
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the em:locked property. This prevents extensions from locking
|
|
|
|
* extensions installed into locations other than restricted locations.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_rdfGet_locked: function EMDS__rdfGet_locked(item, property) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var id = stripPrefix(item.Value, PREFIX_ITEM_URI);
|
|
|
|
var installLocation = InstallLocations.get(this.getInstallLocationKey(id));
|
|
|
|
if (!installLocation || !installLocation.restricted)
|
|
|
|
return EM_L("false");
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the em:satisfiesDependencies property - literal string "false" for
|
|
|
|
* dependencies not satisfied (e.g. dependency disabled, incorrect version,
|
|
|
|
* not installed etc.), and literal string "true" for dependencies satisfied.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_rdfGet_satisfiesDependencies: function EMDS__rdfGet_satisfiesDependencies(item, property) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var id = stripPrefix(item.Value, PREFIX_ITEM_URI);
|
|
|
|
if (this.satisfiesDependencies(id))
|
|
|
|
return EM_L("true");
|
|
|
|
return EM_L("false");
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Get the em:opType property (controls widget state for the EM UI)
|
|
|
|
* from the Startup Cache (e.g. extensions.cache)
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_rdfGet_opType: function EMDS__rdfGet_opType(item, property) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var id = stripPrefix(item.Value, PREFIX_ITEM_URI);
|
|
|
|
var key = this.getItemProperty(id, "installLocation");
|
|
|
|
if (key in StartupCache.entries && id in StartupCache.entries[key] &&
|
|
|
|
StartupCache.entries[key][id] && StartupCache.entries[key][id].op != OP_NONE)
|
|
|
|
return EM_L(StartupCache.entries[key][id].op);
|
2007-06-21 16:17:08 -07:00
|
|
|
return null;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2007-08-29 01:16:15 -07:00
|
|
|
* Gets a localizable property. Install Manifests are generally only in one
|
|
|
|
* language, however an item can customize by providing localized prefs in
|
2007-03-22 10:30:00 -07:00
|
|
|
* the form:
|
|
|
|
*
|
|
|
|
* extensions.{GUID}.[name|description|creator|homepageURL]
|
|
|
|
*
|
|
|
|
* to specify localized text for each of these properties.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_getLocalizablePropertyValue: function EMDS__getLocalizablePropertyValue(item, property) {
|
2007-08-29 01:16:15 -07:00
|
|
|
// These are localizable properties that a language pack supplied by the
|
|
|
|
// Extension may override.
|
|
|
|
var prefName = PREF_EM_EXTENSION_FORMAT.replace(/%UUID%/,
|
|
|
|
stripPrefix(item.Value, PREFIX_ITEM_URI)) +
|
2007-03-22 10:30:00 -07:00
|
|
|
stripPrefix(property.Value, PREFIX_NS_EM);
|
|
|
|
try {
|
2007-08-29 01:16:15 -07:00
|
|
|
var value = gPref.getComplexValue(prefName,
|
2007-09-03 20:07:11 -07:00
|
|
|
Ci.nsIPrefLocalizedString);
|
2007-08-29 01:16:15 -07:00
|
|
|
if (value.data)
|
2007-03-22 10:30:00 -07:00
|
|
|
return EM_L(value.data);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
}
|
2007-07-02 12:33:39 -07:00
|
|
|
|
2007-10-12 15:45:16 -07:00
|
|
|
var localized = findClosestLocalizedResource(this._inner, item);
|
2007-07-02 12:33:39 -07:00
|
|
|
if (localized) {
|
|
|
|
var value = this._inner.GetTarget(localized, property, true);
|
|
|
|
return value ? value : EM_L("");
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
return null;
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Get the em:name property (name of the item)
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_rdfGet_name: function EMDS__rdfGet_name(item, property) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return this._getLocalizablePropertyValue(item, property);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Get the em:description property (description of the item)
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_rdfGet_description: function EMDS__rdfGet_description(item, property) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return this._getLocalizablePropertyValue(item, property);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Get the em:creator property (creator of the item)
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_rdfGet_creator: function EMDS__rdfGet_creator(item, property) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return this._getLocalizablePropertyValue(item, property);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Get the em:homepageURL property (homepage URL of the item)
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_rdfGet_homepageURL: function EMDS__rdfGet_homepageURL(item, property) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return this._getLocalizablePropertyValue(item, property);
|
|
|
|
},
|
2007-11-17 04:52:03 -08:00
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
_rdfGet_availableUpdateInfo: function EMDS__rdfGet_availableUpdateInfo(item, property) {
|
2007-11-17 04:52:03 -08:00
|
|
|
var id = stripPrefix(item.Value, PREFIX_ITEM_URI);
|
|
|
|
var uri = stringData(this._inner.GetTarget(item, EM_R("availableUpdateInfo"), true));
|
|
|
|
if (uri) {
|
2009-09-10 11:50:41 -07:00
|
|
|
uri = escapeAddonURI(this.getItemForID(id), null, null, uri, this);
|
2007-11-17 04:52:03 -08:00
|
|
|
return EM_L(uri);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the em:isDisabled property. This will be true if the item has a
|
|
|
|
* appDisabled or a userDisabled property that is true or OP_NEEDS_ENABLE.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_rdfGet_isDisabled: function EMDS__rdfGet_isDisabled(item, property) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var id = stripPrefix(item.Value, PREFIX_ITEM_URI);
|
|
|
|
if (this.getItemProperty(id, "userDisabled") == "true" ||
|
|
|
|
this.getItemProperty(id, "appDisabled") == "true" ||
|
|
|
|
this.getItemProperty(id, "userDisabled") == OP_NEEDS_ENABLE ||
|
|
|
|
this.getItemProperty(id, "appDisabled") == OP_NEEDS_ENABLE)
|
|
|
|
return EM_L("true");
|
|
|
|
return EM_L("false");
|
|
|
|
},
|
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
_rdfGet_addonID: function EMDS__rdfGet_addonID(item, property) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var id = this._inner.GetTarget(item, EM_R("downloadURL"), true) ? item.Value :
|
|
|
|
stripPrefix(item.Value, PREFIX_ITEM_URI);
|
|
|
|
return EM_L(id);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the em:updateable property - this specifies whether the item is
|
|
|
|
* allowed to be updated
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_rdfGet_updateable: function EMDS__rdfGet_updateable(item, property) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var id = stripPrefix(item.Value, PREFIX_ITEM_URI);
|
|
|
|
var opType = this.getItemProperty(id, "opType");
|
2007-07-09 13:53:20 -07:00
|
|
|
if (opType != OP_NONE || this.getItemProperty(id, "appManaged") == "true")
|
2007-03-22 10:30:00 -07:00
|
|
|
return EM_L("false");
|
|
|
|
|
|
|
|
if (getPref("getBoolPref", (PREF_EM_ITEM_UPDATE_ENABLED.replace(/%UUID%/, id), false)) == true)
|
|
|
|
return EM_L("false");
|
|
|
|
|
|
|
|
var installLocation = InstallLocations.get(this.getInstallLocationKey(id));
|
|
|
|
if (!installLocation || !installLocation.canAccess)
|
|
|
|
return EM_L("false");
|
|
|
|
|
|
|
|
return EM_L("true");
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* See nsIRDFDataSource.idl
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
GetTarget: function EMDS_GetTarget(source, property, truthValue) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!source)
|
|
|
|
return null;
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var target = null;
|
|
|
|
var getter = "_rdfGet_" + stripPrefix(property.Value, PREFIX_NS_EM);
|
|
|
|
if (getter in this)
|
|
|
|
target = this[getter](source, property);
|
|
|
|
|
|
|
|
return target || this._inner.GetTarget(source, property, truthValue);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Gets an enumeration of values of a localizable property. Install Manifests
|
2007-08-29 01:16:15 -07:00
|
|
|
* are generally only in one language, however an item can customize by
|
2007-03-22 10:30:00 -07:00
|
|
|
* providing localized prefs in the form:
|
|
|
|
*
|
|
|
|
* extensions.{GUID}.[contributor].1
|
|
|
|
* extensions.{GUID}.[contributor].2
|
|
|
|
* extensions.{GUID}.[contributor].3
|
|
|
|
* ...
|
|
|
|
*
|
|
|
|
* to specify localized text for each of these properties.
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_getLocalizablePropertyValues: function EMDS__getLocalizablePropertyValues(item, property) {
|
2007-08-29 01:16:15 -07:00
|
|
|
// These are localizable properties that a language pack supplied by the
|
|
|
|
// Extension may override.
|
2007-03-22 10:30:00 -07:00
|
|
|
var values = [];
|
2007-08-29 01:16:15 -07:00
|
|
|
var prefName = PREF_EM_EXTENSION_FORMAT.replace(/%UUID%/,
|
|
|
|
stripPrefix(item.Value, PREFIX_ITEM_URI)) +
|
2007-03-22 10:30:00 -07:00
|
|
|
stripPrefix(property.Value, PREFIX_NS_EM);
|
|
|
|
var i = 0;
|
|
|
|
while (true) {
|
|
|
|
try {
|
2007-08-29 01:16:15 -07:00
|
|
|
var value = gPref.getComplexValue(prefName + "." + ++i,
|
2007-09-03 20:07:11 -07:00
|
|
|
Ci.nsIPrefLocalizedString);
|
2007-08-29 01:16:15 -07:00
|
|
|
if (value.data)
|
2007-03-22 10:30:00 -07:00
|
|
|
values.push(EM_L(value.data));
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
try {
|
2007-08-29 01:16:15 -07:00
|
|
|
var value = gPref.getComplexValue(prefName,
|
2007-09-03 20:07:11 -07:00
|
|
|
Ci.nsIPrefLocalizedString);
|
2007-08-29 01:16:15 -07:00
|
|
|
if (value.data)
|
2007-03-22 10:30:00 -07:00
|
|
|
values.push(EM_L(value.data));
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-07-02 12:33:39 -07:00
|
|
|
if (values.length > 0)
|
|
|
|
return values;
|
|
|
|
|
2007-10-12 15:45:16 -07:00
|
|
|
var localized = findClosestLocalizedResource(this._inner, item);
|
2007-07-02 12:33:39 -07:00
|
|
|
if (localized) {
|
|
|
|
var targets = this._inner.GetTargets(localized, property, true);
|
|
|
|
while (targets.hasMoreElements())
|
|
|
|
values.push(targets.getNext());
|
|
|
|
return values;
|
|
|
|
}
|
|
|
|
return null;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the em:developer property (developers of the extension)
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_rdfGets_developer: function EMDS__rdfGets_developer(item, property) {
|
2007-08-29 01:16:15 -07:00
|
|
|
return this._getLocalizablePropertyValues(item, property);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the em:translator property (translators of the extension)
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_rdfGets_translator: function EMDS__rdfGets_translator(item, property) {
|
2007-08-29 01:16:15 -07:00
|
|
|
return this._getLocalizablePropertyValues(item, property);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Get the em:contributor property (contributors to the extension)
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
_rdfGets_contributor: function EMDS__rdfGets_contributor(item, property) {
|
2007-08-29 01:16:15 -07:00
|
|
|
return this._getLocalizablePropertyValues(item, property);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* See nsIRDFDataSource.idl
|
|
|
|
*/
|
2008-08-15 08:23:48 -07:00
|
|
|
GetTargets: function EMDS_GetTargets(source, property, truthValue) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!source)
|
|
|
|
return null;
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var ary = null;
|
|
|
|
var propertyName = stripPrefix(property.Value, PREFIX_NS_EM);
|
|
|
|
var getter = "_rdfGets_" + propertyName;
|
|
|
|
if (getter in this)
|
|
|
|
ary = this[getter](source, property);
|
|
|
|
else {
|
|
|
|
// The template builder calls GetTargets when single value properties
|
|
|
|
// are used in a triple.
|
|
|
|
getter = "_rdfGet_" + propertyName;
|
|
|
|
if (getter in this)
|
|
|
|
ary = [ this[getter](source, property) ];
|
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
|
|
|
|
return ary ? new ArrayEnumerator(ary)
|
2007-03-22 10:30:00 -07:00
|
|
|
: this._inner.GetTargets(source, property, truthValue);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
Assert: function EMDS_Assert(source, property, target, truthValue) {
|
2007-03-22 10:30:00 -07:00
|
|
|
this._inner.Assert(source, property, target, truthValue);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
Unassert: function EMDS_Unassert(source, property, target) {
|
2007-03-22 10:30:00 -07:00
|
|
|
this._inner.Unassert(source, property, target);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
Change: function EMDS_Change(source, property, oldTarget, newTarget) {
|
2007-03-22 10:30:00 -07:00
|
|
|
this._inner.Change(source, property, oldTarget, newTarget);
|
|
|
|
},
|
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
Move: function EMDS_Move(oldSource, newSource, property, target) {
|
2007-03-22 10:30:00 -07:00
|
|
|
this._inner.Move(oldSource, newSource, property, target);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
HasAssertion: function EMDS_HasAssertion(source, property, target, truthValue) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!source || !property || !target)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
var getter = "_rdfGet_" + stripPrefix(property.Value, PREFIX_NS_EM);
|
|
|
|
if (getter in this)
|
|
|
|
return this[getter](source, property) == target;
|
|
|
|
return this._inner.HasAssertion(source, property, target, truthValue);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
_observers: [],
|
2008-08-15 08:23:48 -07:00
|
|
|
AddObserver: function EMDS_AddObserver(observer) {
|
2007-03-22 10:30:00 -07:00
|
|
|
for (var i = 0; i < this._observers.length; ++i) {
|
2007-08-29 01:16:15 -07:00
|
|
|
if (this._observers[i] == observer)
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._observers.push(observer);
|
|
|
|
this._inner.AddObserver(observer);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
RemoveObserver: function EMDS_RemoveObserver(observer) {
|
2007-03-22 10:30:00 -07:00
|
|
|
for (var i = 0; i < this._observers.length; ++i) {
|
2007-08-29 01:16:15 -07:00
|
|
|
if (this._observers[i] == observer)
|
2007-03-22 10:30:00 -07:00
|
|
|
this._observers.splice(i, 1);
|
|
|
|
}
|
|
|
|
this._inner.RemoveObserver(observer);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
ArcLabelsIn: function EMDS_ArcLabelsIn(node) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return this._inner.ArcLabelsIn(node);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
ArcLabelsOut: function EMDS_ArcLabelsOut(source) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return this._inner.ArcLabelsOut(source);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
GetAllResources: function EMDS_GetAllResources() {
|
2007-03-22 10:30:00 -07:00
|
|
|
return this._inner.GetAllResources();
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
IsCommandEnabled: function EMDS_IsCommandEnabled(sources, command, arguments) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return this._inner.IsCommandEnabled(sources, command, arguments);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
DoCommand: function EMDS_DoCommand(sources, command, arguments) {
|
2007-03-22 10:30:00 -07:00
|
|
|
this._inner.DoCommand(sources, command, arguments);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
GetAllCmds: function EMDS_GetAllCmds(source) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return this._inner.GetAllCmds(source);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
hasArcIn: function EMDS_hasArcIn(node, arc) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return this._inner.hasArcIn(node, arc);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
hasArcOut: function EMDS_hasArcOut(source, arc) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return this._inner.hasArcOut(source, arc);
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
beginUpdateBatch: function EMDS_beginUpdateBatch() {
|
2007-03-22 10:30:00 -07:00
|
|
|
return this._inner.beginUpdateBatch();
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
endUpdateBatch: function EMDS_endUpdateBatch() {
|
2007-03-22 10:30:00 -07:00
|
|
|
return this._inner.endUpdateBatch();
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* See nsIRDFRemoteDataSource.idl
|
|
|
|
*/
|
|
|
|
get loaded() {
|
2007-09-03 20:07:11 -07:00
|
|
|
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
Init: function EMDS_Init(uri) {
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
Refresh: function EMDS_Refresh(blocking) {
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
Flush: function EMDS_Flush() {
|
2008-07-25 09:23:25 -07:00
|
|
|
// For some operations we block repeated flushing until all operations
|
|
|
|
// are complete to reduce file accesses that can trigger bug 431065
|
|
|
|
if (!gAllowFlush) {
|
|
|
|
gDSNeedsFlush = true;
|
|
|
|
return;
|
|
|
|
}
|
2007-09-03 20:07:11 -07:00
|
|
|
if (this._inner instanceof Ci.nsIRDFRemoteDataSource)
|
2007-03-22 10:30:00 -07:00
|
|
|
this._inner.Flush();
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
FlushTo: function EMDS_FlushTo(uri) {
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2008-11-28 14:20:10 -08:00
|
|
|
classDescription: "Extension Manager Data Source",
|
|
|
|
contractID: "@mozilla.org/rdf/datasource;1?name=extensions",
|
|
|
|
classID: Components.ID("{69BB8313-2D4F-45EC-97E0-D39DA58ECCE9}"),
|
|
|
|
_xpcom_factory: {
|
|
|
|
createInstance: function() Cc[ExtensionManager.prototype.contractID].
|
|
|
|
getService(Ci.nsIExtensionManager).datasource
|
|
|
|
},
|
2007-09-03 20:07:11 -07:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIRDFDataSource,
|
|
|
|
Ci.nsIRDFRemoteDataSource])
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2007-09-03 20:07:11 -07:00
|
|
|
function UpdateItem () {}
|
2007-03-22 10:30:00 -07:00
|
|
|
UpdateItem.prototype = {
|
|
|
|
/**
|
|
|
|
* See nsIUpdateService.idl
|
|
|
|
*/
|
|
|
|
init: function(id, version, installLocationKey, minAppVersion, maxAppVersion,
|
2007-09-03 14:44:12 -07:00
|
|
|
name, downloadURL, xpiHash, iconURL, updateURL, updateKey, type,
|
2007-08-29 01:16:15 -07:00
|
|
|
targetAppID) {
|
2007-03-22 10:30:00 -07:00
|
|
|
this._id = id;
|
|
|
|
this._version = version;
|
|
|
|
this._installLocationKey = installLocationKey;
|
|
|
|
this._minAppVersion = minAppVersion;
|
|
|
|
this._maxAppVersion = maxAppVersion;
|
|
|
|
this._name = name;
|
|
|
|
this._downloadURL = downloadURL;
|
|
|
|
this._xpiHash = xpiHash;
|
|
|
|
this._iconURL = iconURL;
|
|
|
|
this._updateURL = updateURL;
|
2007-09-03 14:44:12 -07:00
|
|
|
this._updateKey = updateKey;
|
2007-03-22 10:30:00 -07:00
|
|
|
this._type = type;
|
2007-08-29 01:16:15 -07:00
|
|
|
this._targetAppID = targetAppID;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* See nsIUpdateService.idl
|
|
|
|
*/
|
|
|
|
get id() { return this._id; },
|
|
|
|
get version() { return this._version; },
|
|
|
|
get installLocationKey(){ return this._installLocationKey;},
|
|
|
|
get minAppVersion() { return this._minAppVersion; },
|
|
|
|
get maxAppVersion() { return this._maxAppVersion; },
|
|
|
|
get name() { return this._name; },
|
|
|
|
get xpiURL() { return this._downloadURL; },
|
|
|
|
get xpiHash() { return this._xpiHash; },
|
|
|
|
get iconURL() { return this._iconURL },
|
|
|
|
get updateRDF() { return this._updateURL; },
|
2007-09-03 14:44:12 -07:00
|
|
|
get updateKey() { return this._updateKey; },
|
2007-03-22 10:30:00 -07:00
|
|
|
get type() { return this._type; },
|
2007-08-29 01:16:15 -07:00
|
|
|
get targetAppID() { return this._targetAppID; },
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* See nsIUpdateService.idl
|
|
|
|
*/
|
|
|
|
get objectSource() {
|
2007-08-29 01:16:15 -07:00
|
|
|
return { id : this._id,
|
|
|
|
version : this._version,
|
2007-03-22 10:30:00 -07:00
|
|
|
installLocationKey : this._installLocationKey,
|
|
|
|
minAppVersion : this._minAppVersion,
|
|
|
|
maxAppVersion : this._maxAppVersion,
|
2007-08-29 01:16:15 -07:00
|
|
|
name : this._name,
|
|
|
|
xpiURL : this._downloadURL,
|
2007-03-22 10:30:00 -07:00
|
|
|
xpiHash : this._xpiHash,
|
2007-08-29 01:16:15 -07:00
|
|
|
iconURL : this._iconURL,
|
2007-03-22 10:30:00 -07:00
|
|
|
updateRDF : this._updateURL,
|
2007-09-03 14:44:12 -07:00
|
|
|
updateKey : this._updateKey,
|
2007-08-29 01:16:15 -07:00
|
|
|
type : this._type,
|
|
|
|
targetAppID : this._targetAppID
|
2007-03-22 10:30:00 -07:00
|
|
|
}.toSource();
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-09-03 20:07:11 -07:00
|
|
|
classDescription: "Update Item",
|
|
|
|
contractID: "@mozilla.org/updates/item;1",
|
|
|
|
classID: Components.ID("{F3294B1C-89F4-46F8-98A0-44E1EAE92518}"),
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIUpdateItem])
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2007-09-03 20:07:11 -07:00
|
|
|
function NSGetModule(compMgr, fileSpec)
|
2008-11-28 14:20:10 -08:00
|
|
|
XPCOMUtils.generateModule([ExtensionManager, ExtensionsDataSource, UpdateItem]);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#if 0
|
2008-08-15 08:23:48 -07:00
|
|
|
/**
|
|
|
|
* Logs a message and stack trace to the console.
|
|
|
|
* @param string
|
|
|
|
* The string to write to the console.
|
|
|
|
*/
|
|
|
|
function STACK(string) {
|
|
|
|
dump("*** " + string + "\n");
|
|
|
|
stackTrace(arguments.callee.caller.arguments, -1);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
function stackTraceFunctionFormat(aFunctionName) {
|
|
|
|
var classDelimiter = aFunctionName.indexOf("_");
|
|
|
|
var className = aFunctionName.substr(0, classDelimiter);
|
|
|
|
if (!className)
|
|
|
|
className = "<global>";
|
|
|
|
var functionName = aFunctionName.substr(classDelimiter + 1, aFunctionName.length);
|
2007-08-29 01:16:15 -07:00
|
|
|
if (!functionName)
|
2007-03-22 10:30:00 -07:00
|
|
|
functionName = "<anonymous>";
|
|
|
|
return className + "::" + functionName;
|
|
|
|
}
|
|
|
|
|
2008-08-15 08:23:48 -07:00
|
|
|
function stackTraceArgumentsFormat(aArguments) {
|
|
|
|
arglist = "";
|
|
|
|
for (var i = 0; i < aArguments.length; i++) {
|
|
|
|
arglist += aArguments[i];
|
|
|
|
if (i < aArguments.length - 1)
|
|
|
|
arglist += ", ";
|
|
|
|
}
|
|
|
|
return arglist;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
function stackTrace(aArguments, aMaxCount) {
|
|
|
|
dump("=[STACKTRACE]=====================================================\n");
|
2008-08-15 08:23:48 -07:00
|
|
|
dump("*** at: " + stackTraceFunctionFormat(aArguments.callee.name) + "(" +
|
|
|
|
stackTraceArgumentsFormat(aArguments) + ")\n");
|
2007-03-22 10:30:00 -07:00
|
|
|
var temp = aArguments.callee.caller;
|
|
|
|
var count = 0;
|
|
|
|
while (temp) {
|
2008-08-15 08:23:48 -07:00
|
|
|
dump("*** " + stackTraceFunctionFormat(temp.name) + "(" +
|
|
|
|
stackTraceArgumentsFormat(temp.arguments) + ")\n");
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
temp = temp.arguments.callee.caller;
|
|
|
|
if (aMaxCount > 0 && ++count == aMaxCount)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
dump("==================================================================\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
function dumpFile(file) {
|
|
|
|
dump("*** file = " + file.path + ", exists = " + file.exists() + "\n");
|
|
|
|
}
|
|
|
|
#endif
|