2014-06-25 05:12:07 +00:00
|
|
|
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
2012-08-04 01:22:55 +00:00
|
|
|
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-08-16 00:43:12 +00:00
|
|
|
|
2011-07-19 20:16:35 +00:00
|
|
|
"use strict";
|
|
|
|
|
2007-08-16 00:43:12 +00:00
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cr = Components.results;
|
|
|
|
|
2007-08-25 06:12:05 +00:00
|
|
|
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
2010-12-20 22:01:12 +00:00
|
|
|
Components.utils.import("resource://gre/modules/Services.jsm");
|
2007-08-25 06:12:05 +00:00
|
|
|
|
2014-07-18 16:27:29 +00:00
|
|
|
try {
|
|
|
|
// AddonManager.jsm doesn't allow itself to be imported in the child
|
|
|
|
// process. We're used in the child process (for now), so guard against
|
|
|
|
// this.
|
|
|
|
Components.utils.import("resource://gre/modules/AddonManager.jsm");
|
|
|
|
} catch (e) {
|
|
|
|
}
|
|
|
|
|
2012-05-10 02:28:45 +00:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "FileUtils",
|
|
|
|
"resource://gre/modules/FileUtils.jsm");
|
2015-09-14 18:04:19 +00:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "UpdateUtils",
|
|
|
|
"resource://gre/modules/UpdateUtils.jsm");
|
2014-04-16 17:50:37 +00:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "OS",
|
|
|
|
"resource://gre/modules/osfile.jsm");
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "Task",
|
|
|
|
"resource://gre/modules/Task.jsm");
|
2012-05-10 02:28:45 +00:00
|
|
|
|
2015-03-04 15:48:04 +00:00
|
|
|
const TOOLKIT_ID = "toolkit@mozilla.org";
|
2007-08-16 00:43:12 +00:00
|
|
|
const KEY_PROFILEDIR = "ProfD";
|
2008-03-19 22:35:03 +00:00
|
|
|
const KEY_APPDIR = "XCurProcD";
|
2007-08-16 00:43:12 +00:00
|
|
|
const FILE_BLOCKLIST = "blocklist.xml";
|
2011-01-14 21:29:27 +00:00
|
|
|
const PREF_BLOCKLIST_LASTUPDATETIME = "app.update.lastUpdateTime.blocklist-background-update-timer";
|
2007-08-16 00:43:12 +00:00
|
|
|
const PREF_BLOCKLIST_URL = "extensions.blocklist.url";
|
2011-05-25 21:31:56 +00:00
|
|
|
const PREF_BLOCKLIST_ITEM_URL = "extensions.blocklist.itemURL";
|
2007-08-16 00:43:12 +00:00
|
|
|
const PREF_BLOCKLIST_ENABLED = "extensions.blocklist.enabled";
|
|
|
|
const PREF_BLOCKLIST_INTERVAL = "extensions.blocklist.interval";
|
2008-11-02 12:13:48 +00:00
|
|
|
const PREF_BLOCKLIST_LEVEL = "extensions.blocklist.level";
|
2011-02-24 11:20:02 +00:00
|
|
|
const PREF_BLOCKLIST_PINGCOUNTTOTAL = "extensions.blocklist.pingCountTotal";
|
|
|
|
const PREF_BLOCKLIST_PINGCOUNTVERSION = "extensions.blocklist.pingCountVersion";
|
2013-06-11 14:58:42 +00:00
|
|
|
const PREF_BLOCKLIST_SUPPRESSUI = "extensions.blocklist.suppressUI";
|
2009-10-02 11:26:04 +00:00
|
|
|
const PREF_PLUGINS_NOTIFYUSER = "plugins.update.notifyUser";
|
2008-04-25 17:10:02 +00:00
|
|
|
const PREF_GENERAL_USERAGENT_LOCALE = "general.useragent.locale";
|
|
|
|
const PREF_APP_DISTRIBUTION = "distribution.id";
|
|
|
|
const PREF_APP_DISTRIBUTION_VERSION = "distribution.version";
|
2007-08-16 00:43:12 +00:00
|
|
|
const PREF_EM_LOGGING_ENABLED = "extensions.logging.enabled";
|
|
|
|
const XMLURI_BLOCKLIST = "http://www.mozilla.org/2006/addons-blocklist";
|
|
|
|
const XMLURI_PARSE_ERROR = "http://www.mozilla.org/newlayout/xml/parsererror.xml"
|
2008-04-25 17:10:02 +00:00
|
|
|
const UNKNOWN_XPCOM_ABI = "unknownABI";
|
2008-11-02 12:13:48 +00:00
|
|
|
const URI_BLOCKLIST_DIALOG = "chrome://mozapps/content/extensions/blocklist.xul"
|
|
|
|
const DEFAULT_SEVERITY = 3;
|
|
|
|
const DEFAULT_LEVEL = 2;
|
|
|
|
const MAX_BLOCK_LEVEL = 3;
|
2009-10-02 11:26:04 +00:00
|
|
|
const SEVERITY_OUTDATED = 0;
|
2012-07-11 15:56:34 +00:00
|
|
|
const VULNERABILITYSTATUS_NONE = 0;
|
|
|
|
const VULNERABILITYSTATUS_UPDATE_AVAILABLE = 1;
|
|
|
|
const VULNERABILITYSTATUS_NO_UPDATE = 2;
|
2007-08-16 00:43:12 +00:00
|
|
|
|
2014-01-06 08:46:32 +00:00
|
|
|
const EXTENSION_BLOCK_FILTERS = ["id", "name", "creator", "homepageURL", "updateURL"];
|
|
|
|
|
2007-08-16 00:43:12 +00:00
|
|
|
var gLoggingEnabled = null;
|
2008-11-02 12:13:48 +00:00
|
|
|
var gBlocklistEnabled = true;
|
|
|
|
var gBlocklistLevel = DEFAULT_LEVEL;
|
2007-08-16 00:43:12 +00:00
|
|
|
|
2009-12-03 23:30:50 +00:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "gConsole",
|
|
|
|
"@mozilla.org/consoleservice;1",
|
|
|
|
"nsIConsoleService");
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "gVersionChecker",
|
|
|
|
"@mozilla.org/xpcom/version-comparator;1",
|
|
|
|
"nsIVersionComparator");
|
|
|
|
|
2015-01-07 05:08:00 +00:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "gCertBlocklistService",
|
|
|
|
"@mozilla.org/security/certblocklist;1",
|
|
|
|
"nsICertBlocklist");
|
|
|
|
|
2009-12-03 23:30:50 +00:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "gPref", function bls_gPref() {
|
|
|
|
return Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService).
|
2012-01-17 01:18:29 +00:00
|
|
|
QueryInterface(Ci.nsIPrefBranch);
|
2009-12-03 23:30:50 +00:00
|
|
|
});
|
|
|
|
|
2015-02-24 22:11:33 +00:00
|
|
|
// From appinfo in Services.jsm. It is not possible to use the one in
|
|
|
|
// Services.jsm since it will not successfully QueryInterface nsIXULAppInfo in
|
|
|
|
// xpcshell tests due to other code calling Services.appinfo before the
|
|
|
|
// nsIXULAppInfo is created by the tests.
|
2009-12-03 23:30:50 +00:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "gApp", function bls_gApp() {
|
2015-02-24 22:11:33 +00:00
|
|
|
let appinfo = Cc["@mozilla.org/xre/app-info;1"]
|
|
|
|
.getService(Ci.nsIXULRuntime);
|
|
|
|
try {
|
|
|
|
appinfo.QueryInterface(Ci.nsIXULAppInfo);
|
|
|
|
} catch (ex if ex instanceof Components.Exception &&
|
|
|
|
ex.result == Cr.NS_NOINTERFACE) {
|
|
|
|
// Not all applications implement nsIXULAppInfo (e.g. xpcshell doesn't).
|
|
|
|
}
|
|
|
|
return appinfo;
|
2009-12-03 23:30:50 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "gABI", function bls_gABI() {
|
|
|
|
let abi = null;
|
|
|
|
try {
|
|
|
|
abi = gApp.XPCOMABI;
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
LOG("BlockList Global gABI: XPCOM ABI unknown.");
|
|
|
|
}
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
// Mac universal build should report a different ABI than either macppc
|
|
|
|
// or mactel.
|
|
|
|
let macutils = Cc["@mozilla.org/xpcom/mac-utils;1"].
|
|
|
|
getService(Ci.nsIMacUtils);
|
|
|
|
|
|
|
|
if (macutils.isUniversalBinary)
|
2010-09-21 04:41:19 +00:00
|
|
|
abi += "-u-" + macutils.architecturesInBinary;
|
2009-12-03 23:30:50 +00:00
|
|
|
#endif
|
|
|
|
return abi;
|
|
|
|
});
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "gOSVersion", function bls_gOSVersion() {
|
|
|
|
let osVersion;
|
|
|
|
let sysInfo = Cc["@mozilla.org/system-info;1"].
|
|
|
|
getService(Ci.nsIPropertyBag2);
|
|
|
|
try {
|
|
|
|
osVersion = sysInfo.getProperty("name") + " " + sysInfo.getProperty("version");
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
LOG("BlockList Global gOSVersion: OS Version unknown.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (osVersion) {
|
|
|
|
try {
|
|
|
|
osVersion += " (" + sysInfo.getProperty("secondaryLibrary") + ")";
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
// Not all platforms have a secondary widget library, so an error is nothing to worry about.
|
|
|
|
}
|
|
|
|
osVersion = encodeURIComponent(osVersion);
|
|
|
|
}
|
|
|
|
return osVersion;
|
|
|
|
});
|
|
|
|
|
2007-08-16 00:43:12 +00:00
|
|
|
// shared code for suppressing bad cert dialogs
|
2009-12-03 23:30:50 +00:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "gCertUtils", function bls_gCertUtils() {
|
2009-10-13 19:45:20 +00:00
|
|
|
let temp = { };
|
|
|
|
Components.utils.import("resource://gre/modules/CertUtils.jsm", temp);
|
|
|
|
return temp;
|
|
|
|
});
|
2007-08-16 00:43:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Logs a string to the error console.
|
|
|
|
* @param string
|
|
|
|
* The string to write to the error console..
|
|
|
|
*/
|
|
|
|
function LOG(string) {
|
|
|
|
if (gLoggingEnabled) {
|
|
|
|
dump("*** " + string + "\n");
|
2009-12-03 23:30:50 +00:00
|
|
|
gConsole.logStringMessage(string);
|
2007-08-16 00:43:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a preference value, handling the case where there is no default.
|
|
|
|
* @param func
|
|
|
|
* The name of the preference function to call, on nsIPrefBranch
|
|
|
|
* @param preference
|
|
|
|
* The name of the preference
|
|
|
|
* @param defaultValue
|
|
|
|
* The default value to return in the event the preference has
|
|
|
|
* no setting
|
|
|
|
* @returns The value of the preference, or undefined if there was no
|
|
|
|
* user or default value.
|
|
|
|
*/
|
|
|
|
function getPref(func, preference, defaultValue) {
|
|
|
|
try {
|
|
|
|
return gPref[func](preference);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
}
|
|
|
|
return defaultValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs a URI to a spec.
|
|
|
|
* @param spec
|
|
|
|
* The spec to construct a URI to
|
|
|
|
* @returns The nsIURI constructed.
|
|
|
|
*/
|
|
|
|
function newURI(spec) {
|
|
|
|
var ioServ = Cc["@mozilla.org/network/io-service;1"].
|
|
|
|
getService(Ci.nsIIOService);
|
|
|
|
return ioServ.newURI(spec, null, null);
|
|
|
|
}
|
|
|
|
|
2008-11-02 12:13:48 +00:00
|
|
|
// Restarts the application checking in with observers first
|
|
|
|
function restartApp() {
|
|
|
|
// Notify all windows that an application quit has been requested.
|
|
|
|
var os = Cc["@mozilla.org/observer-service;1"].
|
|
|
|
getService(Ci.nsIObserverService);
|
|
|
|
var cancelQuit = Cc["@mozilla.org/supports-PRBool;1"].
|
|
|
|
createInstance(Ci.nsISupportsPRBool);
|
|
|
|
os.notifyObservers(cancelQuit, "quit-application-requested", null);
|
|
|
|
|
2011-01-14 21:29:27 +00:00
|
|
|
// Something aborted the quit process.
|
2008-11-02 12:13:48 +00:00
|
|
|
if (cancelQuit.data)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var as = Cc["@mozilla.org/toolkit/app-startup;1"].
|
|
|
|
getService(Ci.nsIAppStartup);
|
|
|
|
as.quit(Ci.nsIAppStartup.eRestart | Ci.nsIAppStartup.eAttemptQuit);
|
|
|
|
}
|
|
|
|
|
2007-11-07 08:56:29 +00:00
|
|
|
/**
|
|
|
|
* Checks whether this blocklist element is valid for the current OS and ABI.
|
|
|
|
* If the element has an "os" attribute then the current OS must appear in
|
2008-10-02 06:49:45 +00:00
|
|
|
* its comma separated list for the element to be valid. Similarly for the
|
2007-11-07 08:56:29 +00:00
|
|
|
* xpcomabi attribute.
|
|
|
|
*/
|
|
|
|
function matchesOSABI(blocklistElement) {
|
|
|
|
if (blocklistElement.hasAttribute("os")) {
|
|
|
|
var choices = blocklistElement.getAttribute("os").split(",");
|
|
|
|
if (choices.length > 0 && choices.indexOf(gApp.OS) < 0)
|
|
|
|
return false;
|
|
|
|
}
|
2011-01-14 21:29:27 +00:00
|
|
|
|
2007-11-07 08:56:29 +00:00
|
|
|
if (blocklistElement.hasAttribute("xpcomabi")) {
|
|
|
|
choices = blocklistElement.getAttribute("xpcomabi").split(",");
|
|
|
|
if (choices.length > 0 && choices.indexOf(gApp.XPCOMABI) < 0)
|
|
|
|
return false;
|
|
|
|
}
|
2011-01-14 21:29:27 +00:00
|
|
|
|
2007-11-07 08:56:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-04-25 17:10:02 +00:00
|
|
|
/**
|
|
|
|
* Gets the current value of the locale. It's possible for this preference to
|
|
|
|
* be localized, so we have to do a little extra work here. Similar code
|
|
|
|
* exists in nsHttpHandler.cpp when building the UA string.
|
|
|
|
*/
|
|
|
|
function getLocale() {
|
|
|
|
try {
|
|
|
|
// Get the default branch
|
2008-11-02 12:13:48 +00:00
|
|
|
var defaultPrefs = gPref.getDefaultBranch(null);
|
2011-05-17 04:12:40 +00:00
|
|
|
return defaultPrefs.getComplexValue(PREF_GENERAL_USERAGENT_LOCALE,
|
|
|
|
Ci.nsIPrefLocalizedString).data;
|
2008-04-25 17:10:02 +00:00
|
|
|
} catch (e) {}
|
|
|
|
|
|
|
|
return gPref.getCharPref(PREF_GENERAL_USERAGENT_LOCALE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the distribution pref values, from defaults only */
|
|
|
|
function getDistributionPrefValue(aPrefName) {
|
|
|
|
var prefValue = "default";
|
|
|
|
|
2008-11-02 12:13:48 +00:00
|
|
|
var defaults = gPref.getDefaultBranch(null);
|
2008-04-25 17:10:02 +00:00
|
|
|
try {
|
|
|
|
prefValue = defaults.getCharPref(aPrefName);
|
|
|
|
} catch (e) {
|
|
|
|
// use default when pref not found
|
|
|
|
}
|
|
|
|
|
|
|
|
return prefValue;
|
|
|
|
}
|
|
|
|
|
2012-11-27 03:40:00 +00:00
|
|
|
/**
|
|
|
|
* Parse a string representation of a regular expression. Needed because we
|
|
|
|
* use the /pattern/flags form (because it's detectable), which is only
|
|
|
|
* supported as a literal in JS.
|
|
|
|
*
|
|
|
|
* @param aStr
|
|
|
|
* String representation of regexp
|
|
|
|
* @return RegExp instance
|
|
|
|
*/
|
|
|
|
function parseRegExp(aStr) {
|
|
|
|
let lastSlash = aStr.lastIndexOf("/");
|
|
|
|
let pattern = aStr.slice(1, lastSlash);
|
|
|
|
let flags = aStr.slice(lastSlash + 1);
|
|
|
|
return new RegExp(pattern, flags);
|
|
|
|
}
|
|
|
|
|
2007-08-16 00:43:12 +00:00
|
|
|
/**
|
|
|
|
* Manages the Blocklist. The Blocklist is a representation of the contents of
|
|
|
|
* blocklist.xml and allows us to remotely disable / re-enable blocklisted
|
|
|
|
* items managed by the Extension Manager with an item's appDisabled property.
|
|
|
|
* It also blocklists plugins with data from blocklist.xml.
|
|
|
|
*/
|
|
|
|
|
|
|
|
function Blocklist() {
|
2014-05-15 13:14:00 +00:00
|
|
|
Services.obs.addObserver(this, "xpcom-shutdown", false);
|
|
|
|
Services.obs.addObserver(this, "sessionstore-windows-restored", false);
|
2009-12-03 23:30:50 +00:00
|
|
|
gLoggingEnabled = getPref("getBoolPref", PREF_EM_LOGGING_ENABLED, false);
|
|
|
|
gBlocklistEnabled = getPref("getBoolPref", PREF_BLOCKLIST_ENABLED, true);
|
|
|
|
gBlocklistLevel = Math.min(getPref("getIntPref", PREF_BLOCKLIST_LEVEL, DEFAULT_LEVEL),
|
|
|
|
MAX_BLOCK_LEVEL);
|
|
|
|
gPref.addObserver("extensions.blocklist.", this, false);
|
2014-01-31 19:46:04 +00:00
|
|
|
gPref.addObserver(PREF_EM_LOGGING_ENABLED, this, false);
|
2014-05-15 13:14:00 +00:00
|
|
|
this.wrappedJSObject = this;
|
2015-03-23 13:40:08 +00:00
|
|
|
// requests from child processes come in here, see receiveMessage.
|
2015-05-01 15:07:18 +00:00
|
|
|
Services.ppmm.addMessageListener("Blocklist:getPluginBlocklistState", this);
|
2015-05-01 15:07:19 +00:00
|
|
|
Services.ppmm.addMessageListener("Blocklist:content-blocklist-updated", this);
|
2007-08-16 00:43:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Blocklist.prototype = {
|
|
|
|
/**
|
|
|
|
* Extension ID -> array of Version Ranges
|
|
|
|
* Each value in the version range array is a JS Object that has the
|
|
|
|
* following properties:
|
|
|
|
* "minVersion" The minimum version in a version range (default = 0)
|
|
|
|
* "maxVersion" The maximum version in a version range (default = *)
|
|
|
|
* "targetApps" Application ID -> array of Version Ranges
|
|
|
|
* (default = current application ID)
|
|
|
|
* Each value in the version range array is a JS Object that
|
|
|
|
* has the following properties:
|
|
|
|
* "minVersion" The minimum version in a version range
|
|
|
|
* (default = 0)
|
|
|
|
* "maxVersion" The maximum version in a version range
|
|
|
|
* (default = *)
|
|
|
|
*/
|
|
|
|
_addonEntries: null,
|
|
|
|
_pluginEntries: null,
|
|
|
|
|
2015-03-23 13:40:08 +00:00
|
|
|
shutdown: function () {
|
|
|
|
Services.obs.removeObserver(this, "xpcom-shutdown");
|
2015-05-01 15:07:18 +00:00
|
|
|
Services.ppmm.removeMessageListener("Blocklist:getPluginBlocklistState", this);
|
2015-05-01 15:07:19 +00:00
|
|
|
Services.ppmm.removeMessageListener("Blocklist:content-blocklist-updated", this);
|
2015-03-23 13:40:08 +00:00
|
|
|
gPref.removeObserver("extensions.blocklist.", this);
|
|
|
|
gPref.removeObserver(PREF_EM_LOGGING_ENABLED, this);
|
|
|
|
},
|
|
|
|
|
2012-10-24 09:58:00 +00:00
|
|
|
observe: function Blocklist_observe(aSubject, aTopic, aData) {
|
2007-08-16 00:43:12 +00:00
|
|
|
switch (aTopic) {
|
|
|
|
case "xpcom-shutdown":
|
2015-03-23 13:40:08 +00:00
|
|
|
this.shutdown();
|
2007-08-16 00:43:12 +00:00
|
|
|
break;
|
2008-11-02 12:13:48 +00:00
|
|
|
case "nsPref:changed":
|
|
|
|
switch (aData) {
|
2014-01-31 19:46:04 +00:00
|
|
|
case PREF_EM_LOGGING_ENABLED:
|
|
|
|
gLoggingEnabled = getPref("getBoolPref", PREF_EM_LOGGING_ENABLED, false);
|
|
|
|
break;
|
2008-11-02 12:13:48 +00:00
|
|
|
case PREF_BLOCKLIST_ENABLED:
|
|
|
|
gBlocklistEnabled = getPref("getBoolPref", PREF_BLOCKLIST_ENABLED, true);
|
|
|
|
this._loadBlocklist();
|
|
|
|
this._blocklistUpdated(null, null);
|
|
|
|
break;
|
|
|
|
case PREF_BLOCKLIST_LEVEL:
|
|
|
|
gBlocklistLevel = Math.min(getPref("getIntPref", PREF_BLOCKLIST_LEVEL, DEFAULT_LEVEL),
|
|
|
|
MAX_BLOCK_LEVEL);
|
|
|
|
this._blocklistUpdated(null, null);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2014-05-15 13:14:00 +00:00
|
|
|
case "sessionstore-windows-restored":
|
|
|
|
Services.obs.removeObserver(this, "sessionstore-windows-restored");
|
|
|
|
this._preloadBlocklist();
|
|
|
|
break;
|
2007-08-16 00:43:12 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-03-23 13:40:08 +00:00
|
|
|
// Message manager message handlers
|
|
|
|
receiveMessage: function (aMsg) {
|
|
|
|
switch (aMsg.name) {
|
2015-05-01 15:07:18 +00:00
|
|
|
case "Blocklist:getPluginBlocklistState":
|
2015-03-23 13:40:08 +00:00
|
|
|
return this.getPluginBlocklistState(aMsg.data.addonData,
|
|
|
|
aMsg.data.appVersion,
|
|
|
|
aMsg.data.toolkitVersion);
|
2015-05-01 15:07:19 +00:00
|
|
|
case "Blocklist:content-blocklist-updated":
|
|
|
|
Services.obs.notifyObservers(null, "content-blocklist-updated", null);
|
|
|
|
break;
|
2015-03-23 13:40:08 +00:00
|
|
|
default:
|
|
|
|
throw new Error("Unknown blocklist message received from content: " + aMsg.name);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-11-02 12:13:48 +00:00
|
|
|
/* See nsIBlocklistService */
|
2014-01-06 08:46:32 +00:00
|
|
|
isAddonBlocklisted: function Blocklist_isAddonBlocklisted(addon, appVersion, toolkitVersion) {
|
|
|
|
return this.getAddonBlocklistState(addon, appVersion, toolkitVersion) ==
|
2008-11-02 12:13:48 +00:00
|
|
|
Ci.nsIBlocklistService.STATE_BLOCKED;
|
|
|
|
},
|
|
|
|
|
|
|
|
/* See nsIBlocklistService */
|
2014-01-06 08:46:32 +00:00
|
|
|
getAddonBlocklistState: function Blocklist_getAddonBlocklistState(addon, appVersion, toolkitVersion) {
|
2014-05-15 13:14:00 +00:00
|
|
|
if (!this._isBlocklistLoaded())
|
2008-03-19 22:35:03 +00:00
|
|
|
this._loadBlocklist();
|
2014-01-06 08:46:32 +00:00
|
|
|
return this._getAddonBlocklistState(addon, this._addonEntries,
|
2008-11-02 12:13:48 +00:00
|
|
|
appVersion, toolkitVersion);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Private version of getAddonBlocklistState that allows the caller to pass in
|
|
|
|
* the add-on blocklist entries to compare against.
|
|
|
|
*
|
|
|
|
* @param id
|
|
|
|
* The ID of the item to get the blocklist state for.
|
|
|
|
* @param version
|
|
|
|
* The version of the item to get the blocklist state for.
|
|
|
|
* @param addonEntries
|
|
|
|
* The add-on blocklist entries to compare against.
|
|
|
|
* @param appVersion
|
|
|
|
* The application version to compare to, will use the current
|
|
|
|
* version if null.
|
|
|
|
* @param toolkitVersion
|
|
|
|
* The toolkit version to compare to, will use the current version if
|
|
|
|
* null.
|
|
|
|
* @returns The blocklist state for the item, one of the STATE constants as
|
|
|
|
* defined in nsIBlocklistService.
|
|
|
|
*/
|
2014-01-06 08:46:32 +00:00
|
|
|
_getAddonBlocklistState: function Blocklist_getAddonBlocklistStateCall(addon,
|
|
|
|
addonEntries, appVersion, toolkitVersion) {
|
2008-11-02 12:13:48 +00:00
|
|
|
if (!gBlocklistEnabled)
|
|
|
|
return Ci.nsIBlocklistService.STATE_NOT_BLOCKED;
|
|
|
|
|
2015-02-24 22:11:33 +00:00
|
|
|
// Not all applications implement nsIXULAppInfo (e.g. xpcshell doesn't).
|
|
|
|
if (!appVersion && !gApp.version)
|
|
|
|
return Ci.nsIBlocklistService.STATE_NOT_BLOCKED;
|
|
|
|
|
2008-02-29 19:06:29 +00:00
|
|
|
if (!appVersion)
|
2007-08-16 00:43:12 +00:00
|
|
|
appVersion = gApp.version;
|
2008-02-29 19:06:29 +00:00
|
|
|
if (!toolkitVersion)
|
2007-08-16 00:43:12 +00:00
|
|
|
toolkitVersion = gApp.platformVersion;
|
|
|
|
|
2014-01-06 08:46:32 +00:00
|
|
|
var blItem = this._findMatchingAddonEntry(addonEntries, addon);
|
2007-08-16 00:43:12 +00:00
|
|
|
if (!blItem)
|
2008-11-02 12:13:48 +00:00
|
|
|
return Ci.nsIBlocklistService.STATE_NOT_BLOCKED;
|
2007-08-16 00:43:12 +00:00
|
|
|
|
2012-11-27 03:40:00 +00:00
|
|
|
for (let currentblItem of blItem.versions) {
|
2014-01-06 08:46:32 +00:00
|
|
|
if (currentblItem.includesItem(addon.version, appVersion, toolkitVersion))
|
2012-05-27 12:21:48 +00:00
|
|
|
return currentblItem.severity >= gBlocklistLevel ? Ci.nsIBlocklistService.STATE_BLOCKED :
|
2008-11-02 12:13:48 +00:00
|
|
|
Ci.nsIBlocklistService.STATE_SOFTBLOCKED;
|
2007-08-16 00:43:12 +00:00
|
|
|
}
|
2008-11-02 12:13:48 +00:00
|
|
|
return Ci.nsIBlocklistService.STATE_NOT_BLOCKED;
|
2007-08-16 00:43:12 +00:00
|
|
|
},
|
|
|
|
|
2013-09-14 17:27:09 +00:00
|
|
|
/**
|
|
|
|
* Returns the set of prefs of the add-on stored in the blocklist file
|
|
|
|
* (probably to revert them on disabling).
|
2014-01-06 08:46:32 +00:00
|
|
|
* @param addon
|
|
|
|
* The add-on whose to-be-reset prefs are to be found.
|
2013-09-14 17:27:09 +00:00
|
|
|
*/
|
2014-01-06 08:46:32 +00:00
|
|
|
_getAddonPrefs: function Blocklist_getAddonPrefs(addon) {
|
|
|
|
let entry = this._findMatchingAddonEntry(this._addonEntries, addon);
|
2013-09-14 17:27:09 +00:00
|
|
|
return entry.prefs.slice(0);
|
|
|
|
},
|
|
|
|
|
2012-11-27 03:40:00 +00:00
|
|
|
_findMatchingAddonEntry: function Blocklist_findMatchingAddonEntry(aAddonEntries,
|
2014-01-06 08:46:32 +00:00
|
|
|
aAddon) {
|
|
|
|
if (!aAddon)
|
|
|
|
return null;
|
|
|
|
// Returns true if the params object passes the constraints set by entry.
|
|
|
|
// (For every non-null property in entry, the same key must exist in
|
|
|
|
// params and value must be the same)
|
|
|
|
function checkEntry(entry, params) {
|
|
|
|
for (let [key, value] of entry) {
|
|
|
|
if (value === null || value === undefined)
|
|
|
|
continue;
|
|
|
|
if (params[key]) {
|
|
|
|
if (value instanceof RegExp) {
|
|
|
|
if (!value.test(params[key])) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (value !== params[key]) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2012-11-27 03:40:00 +00:00
|
|
|
}
|
2014-01-06 08:46:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
let params = {};
|
|
|
|
for (let filter of EXTENSION_BLOCK_FILTERS) {
|
|
|
|
params[filter] = aAddon[filter];
|
2012-11-27 03:40:00 +00:00
|
|
|
}
|
2014-01-06 08:46:32 +00:00
|
|
|
if (params.creator)
|
|
|
|
params.creator = params.creator.name;
|
|
|
|
for (let entry of aAddonEntries) {
|
|
|
|
if (checkEntry(entry.attributes, params)) {
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
2012-11-27 03:40:00 +00:00
|
|
|
},
|
|
|
|
|
2011-05-25 21:31:56 +00:00
|
|
|
/* See nsIBlocklistService */
|
2014-01-06 08:46:32 +00:00
|
|
|
getAddonBlocklistURL: function Blocklist_getAddonBlocklistURL(addon, appVersion, toolkitVersion) {
|
2011-05-25 21:31:56 +00:00
|
|
|
if (!gBlocklistEnabled)
|
|
|
|
return "";
|
|
|
|
|
2014-05-15 13:14:00 +00:00
|
|
|
if (!this._isBlocklistLoaded())
|
2011-05-25 21:31:56 +00:00
|
|
|
this._loadBlocklist();
|
|
|
|
|
2014-01-06 08:46:32 +00:00
|
|
|
let blItem = this._findMatchingAddonEntry(this._addonEntries, addon);
|
2011-05-25 21:31:56 +00:00
|
|
|
if (!blItem || !blItem.blockID)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
return this._createBlocklistURL(blItem.blockID);
|
|
|
|
},
|
|
|
|
|
2012-10-24 09:58:00 +00:00
|
|
|
_createBlocklistURL: function Blocklist_createBlocklistURL(id) {
|
2011-05-25 21:31:56 +00:00
|
|
|
let url = Services.urlFormatter.formatURLPref(PREF_BLOCKLIST_ITEM_URL);
|
|
|
|
url = url.replace(/%blockID%/g, id);
|
|
|
|
|
|
|
|
return url;
|
|
|
|
},
|
|
|
|
|
2012-10-24 09:58:00 +00:00
|
|
|
notify: function Blocklist_notify(aTimer) {
|
2008-11-02 12:13:48 +00:00
|
|
|
if (!gBlocklistEnabled)
|
2007-08-16 00:43:12 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
try {
|
|
|
|
var dsURI = gPref.getCharPref(PREF_BLOCKLIST_URL);
|
|
|
|
}
|
|
|
|
catch (e) {
|
2007-08-29 08:16:15 +00:00
|
|
|
LOG("Blocklist::notify: The " + PREF_BLOCKLIST_URL + " preference" +
|
2007-08-16 00:43:12 +00:00
|
|
|
" is missing!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-24 11:20:02 +00:00
|
|
|
var pingCountVersion = getPref("getIntPref", PREF_BLOCKLIST_PINGCOUNTVERSION, 0);
|
|
|
|
var pingCountTotal = getPref("getIntPref", PREF_BLOCKLIST_PINGCOUNTTOTAL, 1);
|
|
|
|
var daysSinceLastPing = 0;
|
2011-04-07 17:41:00 +00:00
|
|
|
if (pingCountVersion == 0) {
|
|
|
|
daysSinceLastPing = "new";
|
2010-09-21 04:41:19 +00:00
|
|
|
}
|
2011-01-14 21:29:27 +00:00
|
|
|
else {
|
|
|
|
// Seconds in one day is used because nsIUpdateTimerManager stores the
|
|
|
|
// last update time in seconds.
|
|
|
|
let secondsInDay = 60 * 60 * 24;
|
|
|
|
let lastUpdateTime = getPref("getIntPref", PREF_BLOCKLIST_LASTUPDATETIME, 0);
|
2011-02-24 11:20:02 +00:00
|
|
|
if (lastUpdateTime == 0) {
|
|
|
|
daysSinceLastPing = "invalid";
|
|
|
|
}
|
|
|
|
else {
|
2011-01-14 21:29:27 +00:00
|
|
|
let now = Math.round(Date.now() / 1000);
|
|
|
|
daysSinceLastPing = Math.floor((now - lastUpdateTime) / secondsInDay);
|
|
|
|
}
|
2011-02-24 11:20:02 +00:00
|
|
|
|
|
|
|
if (daysSinceLastPing == 0 || daysSinceLastPing == "invalid") {
|
|
|
|
pingCountVersion = pingCountTotal = "invalid";
|
2011-01-14 21:29:27 +00:00
|
|
|
}
|
2010-09-21 04:41:19 +00:00
|
|
|
}
|
|
|
|
|
2011-04-07 17:41:00 +00:00
|
|
|
if (pingCountVersion < 1)
|
|
|
|
pingCountVersion = 1;
|
|
|
|
if (pingCountTotal < 1)
|
|
|
|
pingCountTotal = 1;
|
|
|
|
|
2007-08-16 00:43:12 +00:00
|
|
|
dsURI = dsURI.replace(/%APP_ID%/g, gApp.ID);
|
2015-02-24 22:11:33 +00:00
|
|
|
// Not all applications implement nsIXULAppInfo (e.g. xpcshell doesn't).
|
|
|
|
if (gApp.version)
|
|
|
|
dsURI = dsURI.replace(/%APP_VERSION%/g, gApp.version);
|
2008-04-25 17:10:02 +00:00
|
|
|
dsURI = dsURI.replace(/%PRODUCT%/g, gApp.name);
|
2015-02-24 22:11:33 +00:00
|
|
|
// Not all applications implement nsIXULAppInfo (e.g. xpcshell doesn't).
|
|
|
|
if (gApp.version)
|
|
|
|
dsURI = dsURI.replace(/%VERSION%/g, gApp.version);
|
2008-04-25 17:10:02 +00:00
|
|
|
dsURI = dsURI.replace(/%BUILD_ID%/g, gApp.appBuildID);
|
|
|
|
dsURI = dsURI.replace(/%BUILD_TARGET%/g, gApp.OS + "_" + gABI);
|
|
|
|
dsURI = dsURI.replace(/%OS_VERSION%/g, gOSVersion);
|
|
|
|
dsURI = dsURI.replace(/%LOCALE%/g, getLocale());
|
2015-09-14 18:04:19 +00:00
|
|
|
dsURI = dsURI.replace(/%CHANNEL%/g, UpdateUtils.UpdateChannel);
|
2008-04-25 17:10:02 +00:00
|
|
|
dsURI = dsURI.replace(/%PLATFORM_VERSION%/g, gApp.platformVersion);
|
|
|
|
dsURI = dsURI.replace(/%DISTRIBUTION%/g,
|
|
|
|
getDistributionPrefValue(PREF_APP_DISTRIBUTION));
|
|
|
|
dsURI = dsURI.replace(/%DISTRIBUTION_VERSION%/g,
|
|
|
|
getDistributionPrefValue(PREF_APP_DISTRIBUTION_VERSION));
|
2011-02-24 11:20:02 +00:00
|
|
|
dsURI = dsURI.replace(/%PING_COUNT%/g, pingCountVersion);
|
|
|
|
dsURI = dsURI.replace(/%TOTAL_PING_COUNT%/g, pingCountTotal);
|
2011-01-14 21:29:27 +00:00
|
|
|
dsURI = dsURI.replace(/%DAYS_SINCE_LAST_PING%/g, daysSinceLastPing);
|
2008-04-25 17:10:02 +00:00
|
|
|
dsURI = dsURI.replace(/\+/g, "%2B");
|
|
|
|
|
2011-01-14 21:29:27 +00:00
|
|
|
// Under normal operations it will take around 5,883,516 years before the
|
2011-02-24 11:20:02 +00:00
|
|
|
// preferences used to store pingCountVersion and pingCountTotal will rollover
|
2011-01-14 21:29:27 +00:00
|
|
|
// so this code doesn't bother trying to do the "right thing" here.
|
2011-02-24 11:20:02 +00:00
|
|
|
if (pingCountVersion != "invalid") {
|
|
|
|
pingCountVersion++;
|
|
|
|
if (pingCountVersion > 2147483647) {
|
|
|
|
// Rollover to -1 if the value is greater than what is support by an
|
|
|
|
// integer preference. The -1 indicates that the counter has been reset.
|
|
|
|
pingCountVersion = -1;
|
|
|
|
}
|
|
|
|
gPref.setIntPref(PREF_BLOCKLIST_PINGCOUNTVERSION, pingCountVersion);
|
2010-09-21 04:41:19 +00:00
|
|
|
}
|
|
|
|
|
2011-02-24 11:20:02 +00:00
|
|
|
if (pingCountTotal != "invalid") {
|
|
|
|
pingCountTotal++;
|
|
|
|
if (pingCountTotal > 2147483647) {
|
|
|
|
// Rollover to 1 if the value is greater than what is support by an
|
|
|
|
// integer preference.
|
|
|
|
pingCountTotal = -1;
|
|
|
|
}
|
|
|
|
gPref.setIntPref(PREF_BLOCKLIST_PINGCOUNTTOTAL, pingCountTotal);
|
2011-01-14 21:29:27 +00:00
|
|
|
}
|
|
|
|
|
2007-08-16 00:43:12 +00:00
|
|
|
// Verify that the URI is valid
|
|
|
|
try {
|
|
|
|
var uri = newURI(dsURI);
|
|
|
|
}
|
|
|
|
catch (e) {
|
2007-08-29 08:16:15 +00:00
|
|
|
LOG("Blocklist::notify: There was an error creating the blocklist URI\r\n" +
|
2007-08-16 00:43:12 +00:00
|
|
|
"for: " + dsURI + ", error: " + e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-05-19 18:04:44 +00:00
|
|
|
LOG("Blocklist::notify: Requesting " + uri.spec);
|
2007-08-16 00:43:12 +00:00
|
|
|
var request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].
|
|
|
|
createInstance(Ci.nsIXMLHttpRequest);
|
|
|
|
request.open("GET", uri.spec, true);
|
2009-10-13 19:45:20 +00:00
|
|
|
request.channel.notificationCallbacks = new gCertUtils.BadCertHandler();
|
2007-08-16 00:43:12 +00:00
|
|
|
request.overrideMimeType("text/xml");
|
|
|
|
request.setRequestHeader("Cache-Control", "no-cache");
|
|
|
|
request.QueryInterface(Components.interfaces.nsIJSXMLHttpRequest);
|
|
|
|
|
|
|
|
var self = this;
|
2012-10-24 09:58:00 +00:00
|
|
|
request.addEventListener("error", function errorEventListener(event) {
|
|
|
|
self.onXMLError(event); }, false);
|
|
|
|
request.addEventListener("load", function loadEventListener(event) {
|
|
|
|
self.onXMLLoad(event); }, false);
|
2007-08-16 00:43:12 +00:00
|
|
|
request.send(null);
|
2008-11-02 12:13:48 +00:00
|
|
|
|
|
|
|
// When the blocklist loads we need to compare it to the current copy so
|
|
|
|
// make sure we have loaded it.
|
2014-05-15 13:14:00 +00:00
|
|
|
if (!this._isBlocklistLoaded())
|
2008-11-02 12:13:48 +00:00
|
|
|
this._loadBlocklist();
|
2007-08-16 00:43:12 +00:00
|
|
|
},
|
|
|
|
|
2014-04-16 17:50:37 +00:00
|
|
|
onXMLLoad: Task.async(function* (aEvent) {
|
|
|
|
let request = aEvent.target;
|
2007-08-16 00:43:12 +00:00
|
|
|
try {
|
2009-10-13 19:45:20 +00:00
|
|
|
gCertUtils.checkCert(request.channel);
|
2007-08-16 00:43:12 +00:00
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
LOG("Blocklist::onXMLLoad: " + e);
|
|
|
|
return;
|
|
|
|
}
|
2014-04-16 17:50:37 +00:00
|
|
|
let responseXML = request.responseXML;
|
2007-08-16 00:43:12 +00:00
|
|
|
if (!responseXML || responseXML.documentElement.namespaceURI == XMLURI_PARSE_ERROR ||
|
|
|
|
(request.status != 200 && request.status != 0)) {
|
|
|
|
LOG("Blocklist::onXMLLoad: there was an error during load");
|
|
|
|
return;
|
|
|
|
}
|
2008-11-02 12:13:48 +00:00
|
|
|
|
|
|
|
var oldAddonEntries = this._addonEntries;
|
|
|
|
var oldPluginEntries = this._pluginEntries;
|
2012-11-27 03:40:00 +00:00
|
|
|
this._addonEntries = [];
|
|
|
|
this._pluginEntries = [];
|
2008-11-02 12:13:48 +00:00
|
|
|
|
2014-04-16 17:50:37 +00:00
|
|
|
this._loadBlocklistFromString(request.responseText);
|
2008-11-02 12:13:48 +00:00
|
|
|
this._blocklistUpdated(oldAddonEntries, oldPluginEntries);
|
2014-04-16 17:50:37 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
let path = OS.Path.join(OS.Constants.Path.profileDir, FILE_BLOCKLIST);
|
|
|
|
yield OS.File.writeAtomic(path, request.responseText, {tmpPath: path + ".tmp"});
|
|
|
|
} catch (e) {
|
|
|
|
LOG("Blocklist::onXMLLoad: " + e);
|
|
|
|
}
|
|
|
|
}),
|
2007-08-16 00:43:12 +00:00
|
|
|
|
2012-10-24 09:58:00 +00:00
|
|
|
onXMLError: function Blocklist_onXMLError(aEvent) {
|
2007-08-16 00:43:12 +00:00
|
|
|
try {
|
|
|
|
var request = aEvent.target;
|
|
|
|
// the following may throw (e.g. a local file or timeout)
|
|
|
|
var status = request.status;
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
request = aEvent.target.channel.QueryInterface(Ci.nsIRequest);
|
|
|
|
status = request.status;
|
|
|
|
}
|
2011-02-16 13:14:16 +00:00
|
|
|
var statusText = "nsIXMLHttpRequest channel unavailable";
|
2007-08-16 00:43:12 +00:00
|
|
|
// When status is 0 we don't have a valid channel.
|
2011-02-16 13:14:16 +00:00
|
|
|
if (status != 0) {
|
|
|
|
try {
|
|
|
|
statusText = request.statusText;
|
|
|
|
} catch (e) {
|
|
|
|
}
|
|
|
|
}
|
2007-08-16 00:43:12 +00:00
|
|
|
LOG("Blocklist:onError: There was an error loading the blocklist file\r\n" +
|
|
|
|
statusText);
|
|
|
|
},
|
|
|
|
|
2008-03-19 22:35:03 +00:00
|
|
|
/**
|
|
|
|
* Finds the newest blocklist file from the application and the profile and
|
|
|
|
* load it or does nothing if neither exist.
|
|
|
|
*/
|
2012-10-24 09:58:00 +00:00
|
|
|
_loadBlocklist: function Blocklist_loadBlocklist() {
|
2012-11-27 03:40:00 +00:00
|
|
|
this._addonEntries = [];
|
|
|
|
this._pluginEntries = [];
|
2009-10-23 19:42:48 +00:00
|
|
|
var profFile = FileUtils.getFile(KEY_PROFILEDIR, [FILE_BLOCKLIST]);
|
2008-03-19 22:35:03 +00:00
|
|
|
if (profFile.exists()) {
|
|
|
|
this._loadBlocklistFromFile(profFile);
|
|
|
|
return;
|
|
|
|
}
|
2009-10-23 19:42:48 +00:00
|
|
|
var appFile = FileUtils.getFile(KEY_APPDIR, [FILE_BLOCKLIST]);
|
2008-03-20 06:31:20 +00:00
|
|
|
if (appFile.exists()) {
|
2008-03-19 22:35:03 +00:00
|
|
|
this._loadBlocklistFromFile(appFile);
|
2008-03-20 06:31:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
LOG("Blocklist::_loadBlocklist: no XML File found");
|
2008-03-19 22:35:03 +00:00
|
|
|
},
|
|
|
|
|
2007-08-16 00:43:12 +00:00
|
|
|
/**
|
2007-08-16 21:17:45 +00:00
|
|
|
# The blocklist XML file looks something like this:
|
|
|
|
#
|
|
|
|
# <blocklist xmlns="http://www.mozilla.org/2006/addons-blocklist">
|
|
|
|
# <emItems>
|
2011-05-25 21:31:56 +00:00
|
|
|
# <emItem id="item_1@domain" blockID="i1">
|
2013-09-14 17:27:09 +00:00
|
|
|
# <prefs>
|
|
|
|
# <pref>accessibility.accesskeycausesactivation</pref>
|
|
|
|
# <pref>accessibility.blockautorefresh</pref>
|
|
|
|
# </prefs>
|
2007-08-16 21:17:45 +00:00
|
|
|
# <versionRange minVersion="1.0" maxVersion="2.0.*">
|
|
|
|
# <targetApplication id="{ec8030f7-c20a-464f-9b0e-13a3a9e97384}">
|
|
|
|
# <versionRange minVersion="1.5" maxVersion="1.5.*"/>
|
|
|
|
# <versionRange minVersion="1.7" maxVersion="1.7.*"/>
|
|
|
|
# </targetApplication>
|
|
|
|
# <targetApplication id="toolkit@mozilla.org">
|
2007-08-29 08:16:15 +00:00
|
|
|
# <versionRange minVersion="1.9" maxVersion="1.9.*"/>
|
2007-08-16 21:17:45 +00:00
|
|
|
# </targetApplication>
|
|
|
|
# </versionRange>
|
|
|
|
# <versionRange minVersion="3.0" maxVersion="3.0.*">
|
|
|
|
# <targetApplication id="{ec8030f7-c20a-464f-9b0e-13a3a9e97384}">
|
|
|
|
# <versionRange minVersion="1.5" maxVersion="1.5.*"/>
|
|
|
|
# </targetApplication>
|
|
|
|
# <targetApplication id="toolkit@mozilla.org">
|
2007-08-29 08:16:15 +00:00
|
|
|
# <versionRange minVersion="1.9" maxVersion="1.9.*"/>
|
2007-08-16 21:17:45 +00:00
|
|
|
# </targetApplication>
|
|
|
|
# </versionRange>
|
|
|
|
# </emItem>
|
2011-05-25 21:31:56 +00:00
|
|
|
# <emItem id="item_2@domain" blockID="i2">
|
2007-08-16 21:17:45 +00:00
|
|
|
# <versionRange minVersion="3.1" maxVersion="4.*"/>
|
|
|
|
# </emItem>
|
|
|
|
# <emItem id="item_3@domain">
|
|
|
|
# <versionRange>
|
|
|
|
# <targetApplication id="{ec8030f7-c20a-464f-9b0e-13a3a9e97384}">
|
|
|
|
# <versionRange minVersion="1.5" maxVersion="1.5.*"/>
|
|
|
|
# </targetApplication>
|
|
|
|
# </versionRange>
|
|
|
|
# </emItem>
|
2011-05-25 21:31:56 +00:00
|
|
|
# <emItem id="item_4@domain" blockID="i3">
|
2007-08-16 21:17:45 +00:00
|
|
|
# <versionRange>
|
|
|
|
# <targetApplication>
|
|
|
|
# <versionRange minVersion="1.5" maxVersion="1.5.*"/>
|
|
|
|
# </targetApplication>
|
|
|
|
# </versionRange>
|
2012-11-27 03:40:00 +00:00
|
|
|
# <emItem id="/@badperson\.com$/"/>
|
2007-08-16 21:17:45 +00:00
|
|
|
# </emItems>
|
|
|
|
# <pluginItems>
|
2011-05-25 21:31:56 +00:00
|
|
|
# <pluginItem blockID="i4">
|
2007-08-16 21:17:45 +00:00
|
|
|
# <!-- All match tags must match a plugin to blocklist a plugin -->
|
|
|
|
# <match name="name" exp="some plugin"/>
|
|
|
|
# <match name="description" exp="1[.]2[.]3"/>
|
|
|
|
# </pluginItem>
|
|
|
|
# </pluginItems>
|
2015-01-07 05:08:00 +00:00
|
|
|
# <certItems>
|
|
|
|
# <!-- issuerName is the DER issuer name data base64 encoded... -->
|
|
|
|
# <certItem issuerName="MA0xCzAJBgNVBAMMAmNh">
|
|
|
|
# <!-- ... as is the serial number DER data -->
|
|
|
|
# <serialNumber>AkHVNA==</serialNumber>
|
|
|
|
# </certItem>
|
2015-03-31 22:10:09 +00:00
|
|
|
# <!-- subject is the DER subject name data base64 encoded... -->
|
|
|
|
# <certItem subject="MA0xCzAJBgNVBAMMAmNh" pubKeyHash="/xeHA5s+i9/z9d8qy6JEuE1xGoRYIwgJuTE/lmaGJ7M=">
|
|
|
|
# </certItem>
|
2015-01-07 05:08:00 +00:00
|
|
|
# </certItems>
|
2007-08-29 08:16:15 +00:00
|
|
|
# </blocklist>
|
2007-08-16 00:43:12 +00:00
|
|
|
*/
|
|
|
|
|
2012-10-24 09:58:00 +00:00
|
|
|
_loadBlocklistFromFile: function Blocklist_loadBlocklistFromFile(file) {
|
2008-11-02 12:13:48 +00:00
|
|
|
if (!gBlocklistEnabled) {
|
2007-08-16 00:43:12 +00:00
|
|
|
LOG("Blocklist::_loadBlocklistFromFile: blocklist is disabled");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-15 13:14:00 +00:00
|
|
|
let telemetry = Services.telemetry;
|
|
|
|
|
|
|
|
if (this._isBlocklistPreloaded()) {
|
|
|
|
telemetry.getHistogramById("BLOCKLIST_SYNC_FILE_LOAD").add(false);
|
|
|
|
this._loadBlocklistFromString(this._preloadedBlocklistContent);
|
|
|
|
delete this._preloadedBlocklistContent;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-08-16 00:43:12 +00:00
|
|
|
if (!file.exists()) {
|
2014-04-16 17:50:37 +00:00
|
|
|
LOG("Blocklist::_loadBlocklistFromFile: XML File does not exist " + file.path);
|
2007-08-16 00:43:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-15 13:14:00 +00:00
|
|
|
telemetry.getHistogramById("BLOCKLIST_SYNC_FILE_LOAD").add(true);
|
|
|
|
|
2014-04-16 17:50:37 +00:00
|
|
|
let text = "";
|
|
|
|
let fstream = null;
|
|
|
|
let cstream = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
fstream = Components.classes["@mozilla.org/network/file-input-stream;1"]
|
|
|
|
.createInstance(Components.interfaces.nsIFileInputStream);
|
|
|
|
cstream = Components.classes["@mozilla.org/intl/converter-input-stream;1"]
|
|
|
|
.createInstance(Components.interfaces.nsIConverterInputStream);
|
|
|
|
|
|
|
|
fstream.init(file, FileUtils.MODE_RDONLY, FileUtils.PERMS_FILE, 0);
|
|
|
|
cstream.init(fstream, "UTF-8", 0, 0);
|
|
|
|
|
2014-11-20 07:50:25 +00:00
|
|
|
let str = {};
|
|
|
|
let read = 0;
|
2014-04-16 17:50:37 +00:00
|
|
|
|
2014-11-20 07:50:25 +00:00
|
|
|
do {
|
|
|
|
read = cstream.readString(0xffffffff, str); // read as much as we can and put it in str.value
|
|
|
|
text += str.value;
|
|
|
|
} while (read != 0);
|
2014-04-16 17:50:37 +00:00
|
|
|
} catch (e) {
|
|
|
|
LOG("Blocklist::_loadBlocklistFromFile: Failed to load XML file " + e);
|
|
|
|
} finally {
|
2014-11-20 07:50:25 +00:00
|
|
|
if (cstream)
|
|
|
|
cstream.close();
|
|
|
|
if (fstream)
|
|
|
|
fstream.close();
|
2014-04-16 17:50:37 +00:00
|
|
|
}
|
|
|
|
|
2014-11-20 07:50:25 +00:00
|
|
|
if (text)
|
|
|
|
this._loadBlocklistFromString(text);
|
2014-04-16 17:50:37 +00:00
|
|
|
},
|
|
|
|
|
2014-05-15 13:14:00 +00:00
|
|
|
_isBlocklistLoaded: function() {
|
|
|
|
return this._addonEntries != null && this._pluginEntries != null;
|
|
|
|
},
|
|
|
|
|
|
|
|
_isBlocklistPreloaded: function() {
|
|
|
|
return this._preloadedBlocklistContent != null;
|
|
|
|
},
|
|
|
|
|
|
|
|
/* Used for testing */
|
|
|
|
_clear: function() {
|
|
|
|
this._addonEntries = null;
|
|
|
|
this._pluginEntries = null;
|
|
|
|
this._preloadedBlocklistContent = null;
|
|
|
|
},
|
|
|
|
|
|
|
|
_preloadBlocklist: Task.async(function*() {
|
|
|
|
let profPath = OS.Path.join(OS.Constants.Path.profileDir, FILE_BLOCKLIST);
|
|
|
|
try {
|
|
|
|
yield this._preloadBlocklistFile(profPath);
|
|
|
|
return;
|
|
|
|
} catch (e) {
|
|
|
|
LOG("Blocklist::_preloadBlocklist: Failed to load XML file " + e)
|
|
|
|
}
|
|
|
|
|
|
|
|
var appFile = FileUtils.getFile(KEY_APPDIR, [FILE_BLOCKLIST]);
|
|
|
|
try{
|
|
|
|
yield this._preloadBlocklistFile(appFile.path);
|
|
|
|
return;
|
|
|
|
} catch (e) {
|
|
|
|
LOG("Blocklist::_preloadBlocklist: Failed to load XML file " + e)
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG("Blocklist::_preloadBlocklist: no XML File found");
|
|
|
|
}),
|
|
|
|
|
|
|
|
_preloadBlocklistFile: Task.async(function* (path){
|
|
|
|
if (this._addonEntries) {
|
|
|
|
// The file has been already loaded.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gBlocklistEnabled) {
|
|
|
|
LOG("Blocklist::_preloadBlocklistFile: blocklist is disabled");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let text = yield OS.File.read(path, { encoding: "utf-8" });
|
|
|
|
|
|
|
|
if (!this._addonEntries) {
|
|
|
|
// Store the content only if a sync load has not been performed in the meantime.
|
|
|
|
this._preloadedBlocklistContent = text;
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
2014-04-16 17:50:37 +00:00
|
|
|
_loadBlocklistFromString : function Blocklist_loadBlocklistFromString(text) {
|
2007-08-16 00:43:12 +00:00
|
|
|
try {
|
|
|
|
var parser = Cc["@mozilla.org/xmlextras/domparser;1"].
|
|
|
|
createInstance(Ci.nsIDOMParser);
|
2014-04-16 17:50:37 +00:00
|
|
|
var doc = parser.parseFromString(text, "text/xml");
|
2007-08-16 00:43:12 +00:00
|
|
|
if (doc.documentElement.namespaceURI != XMLURI_BLOCKLIST) {
|
|
|
|
LOG("Blocklist::_loadBlocklistFromFile: aborting due to incorrect " +
|
|
|
|
"XML Namespace.\r\nExpected: " + XMLURI_BLOCKLIST + "\r\n" +
|
|
|
|
"Received: " + doc.documentElement.namespaceURI);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var childNodes = doc.documentElement.childNodes;
|
2012-05-27 12:21:48 +00:00
|
|
|
for (let element of childNodes) {
|
2010-12-20 22:01:12 +00:00
|
|
|
if (!(element instanceof Ci.nsIDOMElement))
|
|
|
|
continue;
|
|
|
|
switch (element.localName) {
|
|
|
|
case "emItems":
|
2010-12-20 23:01:39 +00:00
|
|
|
this._addonEntries = this._processItemNodes(element.childNodes, "em",
|
|
|
|
this._handleEmItemNode);
|
2010-12-20 22:01:12 +00:00
|
|
|
break;
|
|
|
|
case "pluginItems":
|
2010-12-20 23:01:39 +00:00
|
|
|
this._pluginEntries = this._processItemNodes(element.childNodes, "plugin",
|
|
|
|
this._handlePluginItemNode);
|
2010-12-20 22:01:12 +00:00
|
|
|
break;
|
2015-01-07 05:08:00 +00:00
|
|
|
case "certItems":
|
|
|
|
this._processItemNodes(element.childNodes, "cert",
|
|
|
|
this._handleCertItemNode.bind(this));
|
|
|
|
break;
|
2010-12-20 22:01:12 +00:00
|
|
|
default:
|
|
|
|
Services.obs.notifyObservers(element,
|
|
|
|
"blocklist-data-" + element.localName,
|
|
|
|
null);
|
|
|
|
}
|
|
|
|
}
|
2015-01-07 05:08:00 +00:00
|
|
|
gCertBlocklistService.saveEntries();
|
2007-08-16 00:43:12 +00:00
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
LOG("Blocklist::_loadBlocklistFromFile: Error constructing blocklist " + e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-10-24 09:58:00 +00:00
|
|
|
_processItemNodes: function Blocklist_processItemNodes(itemNodes, prefix, handler) {
|
2007-08-16 00:43:12 +00:00
|
|
|
var result = [];
|
|
|
|
var itemName = prefix + "Item";
|
|
|
|
for (var i = 0; i < itemNodes.length; ++i) {
|
2007-11-07 08:57:19 +00:00
|
|
|
var blocklistElement = itemNodes.item(i);
|
|
|
|
if (!(blocklistElement instanceof Ci.nsIDOMElement) ||
|
2007-08-16 00:43:12 +00:00
|
|
|
blocklistElement.localName != itemName)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
handler(blocklistElement, result);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
2015-01-07 05:08:00 +00:00
|
|
|
_handleCertItemNode: function Blocklist_handleCertItemNode(blocklistElement,
|
|
|
|
result) {
|
|
|
|
let issuer = blocklistElement.getAttribute("issuerName");
|
2015-03-31 22:10:09 +00:00
|
|
|
if (issuer) {
|
|
|
|
for (let snElement of blocklistElement.children) {
|
|
|
|
try {
|
|
|
|
gCertBlocklistService.revokeCertByIssuerAndSerial(issuer, snElement.textContent);
|
|
|
|
} catch (e) {
|
|
|
|
// we want to keep trying other elements since missing all items
|
|
|
|
// is worse than missing one
|
|
|
|
LOG("Blocklist::_handleCertItemNode: Error adding revoked cert by Issuer and Serial" + e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let pubKeyHash = blocklistElement.getAttribute("pubKeyHash");
|
|
|
|
let subject = blocklistElement.getAttribute("subject");
|
|
|
|
|
|
|
|
if (pubKeyHash && subject) {
|
2015-01-07 05:08:00 +00:00
|
|
|
try {
|
2015-03-31 22:10:09 +00:00
|
|
|
gCertBlocklistService.revokeCertBySubjectAndPubKey(subject, pubKeyHash);
|
2015-01-07 05:08:00 +00:00
|
|
|
} catch (e) {
|
2015-03-31 22:10:09 +00:00
|
|
|
LOG("Blocklist::_handleCertItemNode: Error adding revoked cert by Subject and PubKey" + e);
|
2015-01-07 05:08:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-10-24 09:58:00 +00:00
|
|
|
_handleEmItemNode: function Blocklist_handleEmItemNode(blocklistElement, result) {
|
2007-11-07 08:56:29 +00:00
|
|
|
if (!matchesOSABI(blocklistElement))
|
|
|
|
return;
|
|
|
|
|
2012-11-27 03:40:00 +00:00
|
|
|
let blockEntry = {
|
|
|
|
versions: [],
|
2013-09-14 17:27:09 +00:00
|
|
|
prefs: [],
|
2014-01-06 08:46:32 +00:00
|
|
|
blockID: null,
|
|
|
|
attributes: new Map()
|
|
|
|
// Atleast one of EXTENSION_BLOCK_FILTERS must get added to attributes
|
2012-11-27 03:40:00 +00:00
|
|
|
};
|
|
|
|
|
2014-01-06 08:46:32 +00:00
|
|
|
// Any filter starting with '/' is interpreted as a regex. So if an attribute
|
|
|
|
// starts with a '/' it must be checked via a regex.
|
|
|
|
function regExpCheck(attr) {
|
|
|
|
return attr.startsWith("/") ? parseRegExp(attr) : attr;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let filter of EXTENSION_BLOCK_FILTERS) {
|
|
|
|
let attr = blocklistElement.getAttribute(filter);
|
|
|
|
if (attr)
|
|
|
|
blockEntry.attributes.set(filter, regExpCheck(attr));
|
|
|
|
}
|
|
|
|
|
2013-09-14 17:27:09 +00:00
|
|
|
var childNodes = blocklistElement.childNodes;
|
2012-11-27 03:40:00 +00:00
|
|
|
|
2013-09-14 17:27:09 +00:00
|
|
|
for (let x = 0; x < childNodes.length; x++) {
|
|
|
|
var childElement = childNodes.item(x);
|
|
|
|
if (!(childElement instanceof Ci.nsIDOMElement))
|
2007-08-16 00:43:12 +00:00
|
|
|
continue;
|
2013-09-14 17:27:09 +00:00
|
|
|
if (childElement.localName === "prefs") {
|
|
|
|
let prefElements = childElement.childNodes;
|
|
|
|
for (let i = 0; i < prefElements.length; i++) {
|
|
|
|
let prefElement = prefElements.item(i);
|
|
|
|
if (!(prefElement instanceof Ci.nsIDOMElement) ||
|
|
|
|
prefElement.localName !== "pref")
|
|
|
|
continue;
|
|
|
|
blockEntry.prefs.push(prefElement.textContent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (childElement.localName === "versionRange")
|
|
|
|
blockEntry.versions.push(new BlocklistItemData(childElement));
|
2007-08-16 00:43:12 +00:00
|
|
|
}
|
|
|
|
// if only the extension ID is specified block all versions of the
|
|
|
|
// extension for the current application.
|
2012-11-27 03:40:00 +00:00
|
|
|
if (blockEntry.versions.length == 0)
|
|
|
|
blockEntry.versions.push(new BlocklistItemData(null));
|
|
|
|
|
|
|
|
blockEntry.blockID = blocklistElement.getAttribute("blockID");
|
2011-05-25 21:31:56 +00:00
|
|
|
|
2012-11-27 03:40:00 +00:00
|
|
|
result.push(blockEntry);
|
2007-08-16 00:43:12 +00:00
|
|
|
},
|
|
|
|
|
2012-10-24 09:58:00 +00:00
|
|
|
_handlePluginItemNode: function Blocklist_handlePluginItemNode(blocklistElement, result) {
|
2007-11-07 08:56:29 +00:00
|
|
|
if (!matchesOSABI(blocklistElement))
|
|
|
|
return;
|
|
|
|
|
2007-08-16 00:43:12 +00:00
|
|
|
var matchNodes = blocklistElement.childNodes;
|
2008-09-02 11:53:34 +00:00
|
|
|
var blockEntry = {
|
|
|
|
matches: {},
|
2011-05-25 21:31:56 +00:00
|
|
|
versions: [],
|
|
|
|
blockID: null,
|
2014-10-15 13:23:22 +00:00
|
|
|
infoURL: null,
|
2008-09-02 11:53:34 +00:00
|
|
|
};
|
2009-08-21 15:52:57 +00:00
|
|
|
var hasMatch = false;
|
2007-08-16 00:43:12 +00:00
|
|
|
for (var x = 0; x < matchNodes.length; ++x) {
|
2007-11-07 08:57:19 +00:00
|
|
|
var matchElement = matchNodes.item(x);
|
2008-09-02 11:53:34 +00:00
|
|
|
if (!(matchElement instanceof Ci.nsIDOMElement))
|
2007-08-16 00:43:12 +00:00
|
|
|
continue;
|
2008-09-02 11:53:34 +00:00
|
|
|
if (matchElement.localName == "match") {
|
|
|
|
var name = matchElement.getAttribute("name");
|
|
|
|
var exp = matchElement.getAttribute("exp");
|
2009-08-21 15:52:57 +00:00
|
|
|
try {
|
|
|
|
blockEntry.matches[name] = new RegExp(exp, "m");
|
|
|
|
hasMatch = true;
|
|
|
|
} catch (e) {
|
|
|
|
// Ignore invalid regular expressions
|
|
|
|
}
|
2008-09-02 11:53:34 +00:00
|
|
|
}
|
2014-10-15 13:23:22 +00:00
|
|
|
if (matchElement.localName == "versionRange") {
|
2008-09-02 11:53:34 +00:00
|
|
|
blockEntry.versions.push(new BlocklistItemData(matchElement));
|
2014-10-15 13:23:22 +00:00
|
|
|
}
|
|
|
|
else if (matchElement.localName == "infoURL") {
|
|
|
|
blockEntry.infoURL = matchElement.textContent;
|
|
|
|
}
|
2007-08-16 00:43:12 +00:00
|
|
|
}
|
2009-08-21 15:52:57 +00:00
|
|
|
// Plugin entries require *something* to match to an actual plugin
|
|
|
|
if (!hasMatch)
|
|
|
|
return;
|
2008-11-02 12:13:48 +00:00
|
|
|
// Add a default versionRange if there wasn't one specified
|
|
|
|
if (blockEntry.versions.length == 0)
|
|
|
|
blockEntry.versions.push(new BlocklistItemData(null));
|
2011-05-25 21:31:56 +00:00
|
|
|
|
|
|
|
blockEntry.blockID = blocklistElement.getAttribute("blockID");
|
|
|
|
|
2008-09-02 11:53:34 +00:00
|
|
|
result.push(blockEntry);
|
2007-08-16 00:43:12 +00:00
|
|
|
},
|
|
|
|
|
2008-11-02 12:13:48 +00:00
|
|
|
/* See nsIBlocklistService */
|
2012-10-24 09:58:00 +00:00
|
|
|
getPluginBlocklistState: function Blocklist_getPluginBlocklistState(plugin,
|
|
|
|
appVersion, toolkitVersion) {
|
2015-06-01 21:05:00 +00:00
|
|
|
#ifdef ANDROID
|
|
|
|
return Ci.nsIBlocklistService.STATE_NOT_BLOCKED;
|
|
|
|
#else
|
2014-05-15 13:14:00 +00:00
|
|
|
if (!this._isBlocklistLoaded())
|
2008-11-02 12:13:48 +00:00
|
|
|
this._loadBlocklist();
|
|
|
|
return this._getPluginBlocklistState(plugin, this._pluginEntries,
|
|
|
|
appVersion, toolkitVersion);
|
2015-06-01 21:05:00 +00:00
|
|
|
#endif // ifdef ANDROID
|
2008-11-02 12:13:48 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-02-19 18:07:59 +00:00
|
|
|
* Private helper to get the blocklist entry for a plugin given a set of
|
|
|
|
* blocklist entries and versions.
|
2008-11-02 12:13:48 +00:00
|
|
|
*
|
|
|
|
* @param plugin
|
|
|
|
* The nsIPluginTag to get the blocklist state for.
|
|
|
|
* @param pluginEntries
|
|
|
|
* The plugin blocklist entries to compare against.
|
|
|
|
* @param appVersion
|
|
|
|
* The application version to compare to, will use the current
|
|
|
|
* version if null.
|
|
|
|
* @param toolkitVersion
|
|
|
|
* The toolkit version to compare to, will use the current version if
|
|
|
|
* null.
|
2015-02-19 18:07:59 +00:00
|
|
|
* @returns {entry: blocklistEntry, version: blocklistEntryVersion},
|
|
|
|
* or null if there is no matching entry.
|
2008-11-02 12:13:48 +00:00
|
|
|
*/
|
2015-02-19 18:07:59 +00:00
|
|
|
_getPluginBlocklistEntry: function Blocklist_getPluginBlocklistEntry(plugin,
|
2012-10-24 09:58:00 +00:00
|
|
|
pluginEntries, appVersion, toolkitVersion) {
|
2008-11-02 12:13:48 +00:00
|
|
|
if (!gBlocklistEnabled)
|
2015-02-19 18:07:59 +00:00
|
|
|
return null;
|
2008-11-02 12:13:48 +00:00
|
|
|
|
2015-02-24 22:11:33 +00:00
|
|
|
// Not all applications implement nsIXULAppInfo (e.g. xpcshell doesn't).
|
|
|
|
if (!appVersion && !gApp.version)
|
|
|
|
return Ci.nsIBlocklistService.STATE_NOT_BLOCKED;
|
|
|
|
|
2008-11-02 12:13:48 +00:00
|
|
|
if (!appVersion)
|
|
|
|
appVersion = gApp.version;
|
|
|
|
if (!toolkitVersion)
|
|
|
|
toolkitVersion = gApp.platformVersion;
|
|
|
|
|
|
|
|
for each (var blockEntry in pluginEntries) {
|
2007-08-16 00:43:12 +00:00
|
|
|
var matchFailed = false;
|
2008-09-02 11:53:34 +00:00
|
|
|
for (var name in blockEntry.matches) {
|
|
|
|
if (!(name in plugin) ||
|
|
|
|
typeof(plugin[name]) != "string" ||
|
|
|
|
!blockEntry.matches[name].test(plugin[name])) {
|
2007-08-16 00:43:12 +00:00
|
|
|
matchFailed = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-02 11:53:34 +00:00
|
|
|
if (matchFailed)
|
|
|
|
continue;
|
|
|
|
|
2012-05-27 12:21:48 +00:00
|
|
|
for (let blockEntryVersion of blockEntry.versions) {
|
|
|
|
if (blockEntryVersion.includesItem(plugin.version, appVersion,
|
2015-02-19 18:07:59 +00:00
|
|
|
toolkitVersion)) {
|
|
|
|
return {entry: blockEntry, version: blockEntryVersion};
|
2009-10-02 11:26:04 +00:00
|
|
|
}
|
2007-08-16 00:43:12 +00:00
|
|
|
}
|
|
|
|
}
|
2008-09-02 11:53:34 +00:00
|
|
|
|
2015-02-19 18:07:59 +00:00
|
|
|
return null;
|
2007-08-16 00:43:12 +00:00
|
|
|
},
|
|
|
|
|
2014-10-15 13:23:22 +00:00
|
|
|
/**
|
2015-02-19 18:07:59 +00:00
|
|
|
* Private version of getPluginBlocklistState that allows the caller to pass in
|
|
|
|
* the plugin blocklist entries.
|
|
|
|
*
|
|
|
|
* @param plugin
|
|
|
|
* The nsIPluginTag to get the blocklist state for.
|
|
|
|
* @param pluginEntries
|
|
|
|
* The plugin blocklist entries to compare against.
|
|
|
|
* @param appVersion
|
|
|
|
* The application version to compare to, will use the current
|
|
|
|
* version if null.
|
|
|
|
* @param toolkitVersion
|
|
|
|
* The toolkit version to compare to, will use the current version if
|
|
|
|
* null.
|
|
|
|
* @returns The blocklist state for the item, one of the STATE constants as
|
|
|
|
* defined in nsIBlocklistService.
|
2014-10-15 13:23:22 +00:00
|
|
|
*/
|
2015-02-19 18:07:59 +00:00
|
|
|
_getPluginBlocklistState: function Blocklist_getPluginBlocklistState(plugin,
|
|
|
|
pluginEntries, appVersion, toolkitVersion) {
|
2011-05-25 21:31:56 +00:00
|
|
|
|
2015-02-19 18:07:59 +00:00
|
|
|
let r = this._getPluginBlocklistEntry(plugin, pluginEntries,
|
|
|
|
appVersion, toolkitVersion);
|
|
|
|
if (!r) {
|
|
|
|
return Ci.nsIBlocklistService.STATE_NOT_BLOCKED;
|
2014-10-15 13:23:22 +00:00
|
|
|
}
|
2011-05-25 21:31:56 +00:00
|
|
|
|
2015-02-19 18:07:59 +00:00
|
|
|
let {entry: blockEntry, version: blockEntryVersion} = r;
|
|
|
|
|
|
|
|
if (blockEntryVersion.severity >= gBlocklistLevel)
|
|
|
|
return Ci.nsIBlocklistService.STATE_BLOCKED;
|
|
|
|
if (blockEntryVersion.severity == SEVERITY_OUTDATED) {
|
|
|
|
let vulnerabilityStatus = blockEntryVersion.vulnerabilityStatus;
|
|
|
|
if (vulnerabilityStatus == VULNERABILITYSTATUS_UPDATE_AVAILABLE)
|
|
|
|
return Ci.nsIBlocklistService.STATE_VULNERABLE_UPDATE_AVAILABLE;
|
|
|
|
if (vulnerabilityStatus == VULNERABILITYSTATUS_NO_UPDATE)
|
|
|
|
return Ci.nsIBlocklistService.STATE_VULNERABLE_NO_UPDATE;
|
|
|
|
return Ci.nsIBlocklistService.STATE_OUTDATED;
|
|
|
|
}
|
|
|
|
return Ci.nsIBlocklistService.STATE_SOFTBLOCKED;
|
2014-10-15 13:23:22 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/* See nsIBlocklistService */
|
|
|
|
getPluginBlocklistURL: function Blocklist_getPluginBlocklistURL(plugin) {
|
2015-02-19 18:07:59 +00:00
|
|
|
if (!this._isBlocklistLoaded())
|
|
|
|
this._loadBlocklist();
|
|
|
|
|
|
|
|
let r = this._getPluginBlocklistEntry(plugin, this._pluginEntries);
|
|
|
|
if (!r) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
let {entry: blockEntry, version: blockEntryVersion} = r;
|
|
|
|
if (!blockEntry.blockID) {
|
2014-10-15 13:23:22 +00:00
|
|
|
return null;
|
2011-05-25 21:31:56 +00:00
|
|
|
}
|
2014-10-15 13:23:22 +00:00
|
|
|
|
|
|
|
return this._createBlocklistURL(blockEntry.blockID);
|
|
|
|
},
|
|
|
|
|
|
|
|
/* See nsIBlocklistService */
|
|
|
|
getPluginInfoURL: function (plugin) {
|
2015-02-19 18:07:59 +00:00
|
|
|
if (!this._isBlocklistLoaded())
|
|
|
|
this._loadBlocklist();
|
|
|
|
|
|
|
|
let r = this._getPluginBlocklistEntry(plugin, this._pluginEntries);
|
|
|
|
if (!r) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
let {entry: blockEntry, version: blockEntryVersion} = r;
|
|
|
|
if (!blockEntry.blockID) {
|
2014-10-15 13:23:22 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return blockEntry.infoURL;
|
2011-05-25 21:31:56 +00:00
|
|
|
},
|
|
|
|
|
2015-05-01 15:07:18 +00:00
|
|
|
_notifyObserversBlocklistUpdated: function () {
|
|
|
|
Services.obs.notifyObservers(this, "blocklist-updated", "");
|
|
|
|
Services.ppmm.broadcastAsyncMessage("Blocklist:blocklistInvalidated", {});
|
|
|
|
},
|
|
|
|
|
2012-10-24 09:58:00 +00:00
|
|
|
_blocklistUpdated: function Blocklist_blocklistUpdated(oldAddonEntries, oldPluginEntries) {
|
2008-11-02 12:13:48 +00:00
|
|
|
var addonList = [];
|
|
|
|
|
2013-09-14 17:27:09 +00:00
|
|
|
// A helper function that reverts the prefs passed to default values.
|
|
|
|
function resetPrefs(prefs) {
|
|
|
|
for (let pref of prefs)
|
|
|
|
gPref.clearUserPref(pref);
|
|
|
|
}
|
2010-04-26 18:45:22 +00:00
|
|
|
var self = this;
|
2013-09-14 17:27:09 +00:00
|
|
|
const types = ["extension", "theme", "locale", "dictionary", "service"];
|
2012-10-24 09:58:00 +00:00
|
|
|
AddonManager.getAddonsByTypes(types, function blocklistUpdated_getAddonsByTypes(addons) {
|
2010-04-26 18:45:22 +00:00
|
|
|
|
2012-05-27 12:21:48 +00:00
|
|
|
for (let addon of addons) {
|
2010-04-26 18:45:22 +00:00
|
|
|
let oldState = Ci.nsIBlocklistService.STATE_NOTBLOCKED;
|
|
|
|
if (oldAddonEntries)
|
2014-01-06 08:46:32 +00:00
|
|
|
oldState = self._getAddonBlocklistState(addon, oldAddonEntries);
|
|
|
|
let state = self.getAddonBlocklistState(addon);
|
2010-04-26 18:45:22 +00:00
|
|
|
|
2012-05-27 12:21:48 +00:00
|
|
|
LOG("Blocklist state for " + addon.id + " changed from " +
|
2010-05-06 19:57:58 +00:00
|
|
|
oldState + " to " + state);
|
2010-04-26 18:45:22 +00:00
|
|
|
|
|
|
|
// We don't want to re-warn about add-ons
|
|
|
|
if (state == oldState)
|
|
|
|
continue;
|
|
|
|
|
2013-09-14 17:27:09 +00:00
|
|
|
if (state === Ci.nsIBlocklistService.STATE_BLOCKED) {
|
|
|
|
// It's a hard block. We must reset certain preferences.
|
2014-01-06 08:46:32 +00:00
|
|
|
let prefs = self._getAddonPrefs(addon);
|
2013-09-14 17:27:09 +00:00
|
|
|
resetPrefs(prefs);
|
|
|
|
}
|
|
|
|
|
2011-05-19 18:04:44 +00:00
|
|
|
// Ensure that softDisabled is false if the add-on is not soft blocked
|
|
|
|
if (state != Ci.nsIBlocklistService.STATE_SOFTBLOCKED)
|
2012-05-27 12:21:48 +00:00
|
|
|
addon.softDisabled = false;
|
2011-05-19 18:04:44 +00:00
|
|
|
|
|
|
|
// Don't warn about add-ons becoming unblocked.
|
|
|
|
if (state == Ci.nsIBlocklistService.STATE_NOT_BLOCKED)
|
|
|
|
continue;
|
|
|
|
|
2010-04-26 18:45:22 +00:00
|
|
|
// If an add-on has dropped from hard to soft blocked just mark it as
|
2011-05-19 18:04:44 +00:00
|
|
|
// soft disabled and don't warn about it.
|
2010-04-26 18:45:22 +00:00
|
|
|
if (state == Ci.nsIBlocklistService.STATE_SOFTBLOCKED &&
|
|
|
|
oldState == Ci.nsIBlocklistService.STATE_BLOCKED) {
|
2012-05-27 12:21:48 +00:00
|
|
|
addon.softDisabled = true;
|
2010-04-26 18:45:22 +00:00
|
|
|
continue;
|
|
|
|
}
|
2008-11-02 12:13:48 +00:00
|
|
|
|
2010-04-26 18:45:22 +00:00
|
|
|
// If the add-on is already disabled for some reason then don't warn
|
|
|
|
// about it
|
2012-05-27 12:21:48 +00:00
|
|
|
if (!addon.isActive)
|
2010-04-26 18:45:22 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
addonList.push({
|
2012-05-27 12:21:48 +00:00
|
|
|
name: addon.name,
|
|
|
|
version: addon.version,
|
|
|
|
icon: addon.iconURL,
|
2010-04-26 18:45:22 +00:00
|
|
|
disable: false,
|
|
|
|
blocked: state == Ci.nsIBlocklistService.STATE_BLOCKED,
|
2012-05-27 12:21:48 +00:00
|
|
|
item: addon,
|
2014-01-06 08:46:32 +00:00
|
|
|
url: self.getAddonBlocklistURL(addon),
|
2010-04-26 18:45:22 +00:00
|
|
|
});
|
|
|
|
}
|
2010-04-26 18:45:22 +00:00
|
|
|
|
2010-04-26 18:45:22 +00:00
|
|
|
AddonManagerPrivate.updateAddonAppDisabledStates();
|
2010-04-26 18:45:22 +00:00
|
|
|
|
2010-04-26 18:45:22 +00:00
|
|
|
var phs = Cc["@mozilla.org/plugin/host;1"].
|
|
|
|
getService(Ci.nsIPluginHost);
|
|
|
|
var plugins = phs.getPluginTags();
|
|
|
|
|
2012-05-27 12:21:48 +00:00
|
|
|
for (let plugin of plugins) {
|
2010-04-26 18:45:22 +00:00
|
|
|
let oldState = -1;
|
|
|
|
if (oldPluginEntries)
|
2012-05-27 12:21:48 +00:00
|
|
|
oldState = self._getPluginBlocklistState(plugin, oldPluginEntries);
|
|
|
|
let state = self.getPluginBlocklistState(plugin);
|
|
|
|
LOG("Blocklist state for " + plugin.name + " changed from " +
|
2010-05-06 19:57:58 +00:00
|
|
|
oldState + " to " + state);
|
2010-04-26 18:45:22 +00:00
|
|
|
// We don't want to re-warn about items
|
|
|
|
if (state == oldState)
|
|
|
|
continue;
|
|
|
|
|
2013-06-11 14:58:42 +00:00
|
|
|
if (oldState == Ci.nsIBlocklistService.STATE_BLOCKED) {
|
2010-04-26 18:45:22 +00:00
|
|
|
if (state == Ci.nsIBlocklistService.STATE_SOFTBLOCKED)
|
2013-03-27 21:06:43 +00:00
|
|
|
plugin.enabledState = Ci.nsIPluginTag.STATE_DISABLED;
|
2009-10-02 11:26:04 +00:00
|
|
|
}
|
2012-05-27 12:21:48 +00:00
|
|
|
else if (!plugin.disabled && state != Ci.nsIBlocklistService.STATE_NOT_BLOCKED) {
|
2010-04-26 18:45:22 +00:00
|
|
|
if (state == Ci.nsIBlocklistService.STATE_OUTDATED) {
|
|
|
|
gPref.setBoolPref(PREF_PLUGINS_NOTIFYUSER, true);
|
|
|
|
}
|
2012-07-11 15:56:34 +00:00
|
|
|
else if (state != Ci.nsIBlocklistService.STATE_VULNERABLE_UPDATE_AVAILABLE &&
|
|
|
|
state != Ci.nsIBlocklistService.STATE_VULNERABLE_NO_UPDATE) {
|
2010-04-26 18:45:22 +00:00
|
|
|
addonList.push({
|
2012-05-27 12:21:48 +00:00
|
|
|
name: plugin.name,
|
|
|
|
version: plugin.version,
|
2010-04-26 18:45:22 +00:00
|
|
|
icon: "chrome://mozapps/skin/plugins/pluginGeneric.png",
|
|
|
|
disable: false,
|
|
|
|
blocked: state == Ci.nsIBlocklistService.STATE_BLOCKED,
|
2012-05-27 12:21:48 +00:00
|
|
|
item: plugin,
|
|
|
|
url: self.getPluginBlocklistURL(plugin),
|
2010-04-26 18:45:22 +00:00
|
|
|
});
|
|
|
|
}
|
2009-10-02 11:26:04 +00:00
|
|
|
}
|
2008-11-02 12:13:48 +00:00
|
|
|
}
|
|
|
|
|
2011-05-19 18:04:44 +00:00
|
|
|
if (addonList.length == 0) {
|
2015-05-01 15:07:18 +00:00
|
|
|
self._notifyObserversBlocklistUpdated();
|
2010-04-26 18:45:22 +00:00
|
|
|
return;
|
2011-05-19 18:04:44 +00:00
|
|
|
}
|
2010-05-01 18:04:44 +00:00
|
|
|
|
2010-09-02 01:35:06 +00:00
|
|
|
if ("@mozilla.org/addons/blocklist-prompt;1" in Cc) {
|
|
|
|
try {
|
|
|
|
let blockedPrompter = Cc["@mozilla.org/addons/blocklist-prompt;1"]
|
|
|
|
.getService(Ci.nsIBlocklistPrompt);
|
|
|
|
blockedPrompter.prompt(addonList);
|
|
|
|
} catch (e) {
|
|
|
|
LOG(e);
|
|
|
|
}
|
2015-05-01 15:07:18 +00:00
|
|
|
self._notifyObserversBlocklistUpdated();
|
2010-09-02 01:35:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-04-26 18:45:22 +00:00
|
|
|
var args = {
|
|
|
|
restart: false,
|
|
|
|
list: addonList
|
|
|
|
};
|
|
|
|
// This lets the dialog get the raw js object
|
|
|
|
args.wrappedJSObject = args;
|
|
|
|
|
2011-05-25 21:31:56 +00:00
|
|
|
/*
|
|
|
|
Some tests run without UI, so the async code listens to a message
|
|
|
|
that can be sent programatically
|
|
|
|
*/
|
2012-10-24 09:58:00 +00:00
|
|
|
let applyBlocklistChanges = function blocklistUpdated_applyBlocklistChanges() {
|
2012-05-27 12:21:48 +00:00
|
|
|
for (let addon of addonList) {
|
|
|
|
if (!addon.disable)
|
2011-05-25 21:31:56 +00:00
|
|
|
continue;
|
|
|
|
|
2012-05-27 12:21:48 +00:00
|
|
|
if (addon.item instanceof Ci.nsIPluginTag)
|
2013-03-27 21:06:43 +00:00
|
|
|
addon.item.enabledState = Ci.nsIPluginTag.STATE_DISABLED;
|
2013-09-14 17:27:09 +00:00
|
|
|
else {
|
|
|
|
// This add-on is softblocked.
|
2012-05-27 12:21:48 +00:00
|
|
|
addon.item.softDisabled = true;
|
2013-09-14 17:27:09 +00:00
|
|
|
// We must revert certain prefs.
|
2014-01-06 08:46:32 +00:00
|
|
|
let prefs = self._getAddonPrefs(addon.item);
|
2013-09-14 17:27:09 +00:00
|
|
|
resetPrefs(prefs);
|
|
|
|
}
|
2011-05-25 21:31:56 +00:00
|
|
|
}
|
2010-04-26 18:45:22 +00:00
|
|
|
|
2011-05-25 21:31:56 +00:00
|
|
|
if (args.restart)
|
|
|
|
restartApp();
|
2010-04-26 18:45:22 +00:00
|
|
|
|
2015-05-01 15:07:18 +00:00
|
|
|
self._notifyObserversBlocklistUpdated();
|
2011-07-19 20:16:35 +00:00
|
|
|
Services.obs.removeObserver(applyBlocklistChanges, "addon-blocklist-closed");
|
2010-04-26 18:45:22 +00:00
|
|
|
}
|
2008-11-02 12:13:48 +00:00
|
|
|
|
2013-06-11 14:58:42 +00:00
|
|
|
Services.obs.addObserver(applyBlocklistChanges, "addon-blocklist-closed", false);
|
|
|
|
|
|
|
|
if (getPref("getBoolPref", PREF_BLOCKLIST_SUPPRESSUI, false)) {
|
|
|
|
applyBlocklistChanges();
|
|
|
|
return;
|
|
|
|
}
|
2011-05-19 18:04:44 +00:00
|
|
|
|
2011-07-19 20:16:35 +00:00
|
|
|
function blocklistUnloadHandler(event) {
|
|
|
|
if (event.target.location == URI_BLOCKLIST_DIALOG) {
|
2011-07-22 02:20:21 +00:00
|
|
|
applyBlocklistChanges();
|
2011-07-19 20:16:35 +00:00
|
|
|
blocklistWindow.removeEventListener("unload", blocklistUnloadHandler);
|
2011-07-22 02:20:21 +00:00
|
|
|
}
|
2011-07-19 20:16:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let blocklistWindow = Services.ww.openWindow(null, URI_BLOCKLIST_DIALOG, "",
|
|
|
|
"chrome,centerscreen,dialog,titlebar", args);
|
2012-12-05 22:13:26 +00:00
|
|
|
if (blocklistWindow)
|
|
|
|
blocklistWindow.addEventListener("unload", blocklistUnloadHandler, false);
|
2010-04-26 18:45:22 +00:00
|
|
|
});
|
2007-08-16 00:43:12 +00:00
|
|
|
},
|
|
|
|
|
2007-08-25 06:12:05 +00:00
|
|
|
classID: Components.ID("{66354bc9-7ed1-4692-ae1d-8da97d6b205e}"),
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
|
|
|
|
Ci.nsIBlocklistService,
|
|
|
|
Ci.nsITimerCallback]),
|
2007-08-16 00:43:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper for constructing a blocklist.
|
|
|
|
*/
|
|
|
|
function BlocklistItemData(versionRangeElement) {
|
|
|
|
var versionRange = this.getBlocklistVersionRange(versionRangeElement);
|
|
|
|
this.minVersion = versionRange.minVersion;
|
|
|
|
this.maxVersion = versionRange.maxVersion;
|
2008-11-02 12:13:48 +00:00
|
|
|
if (versionRangeElement && versionRangeElement.hasAttribute("severity"))
|
|
|
|
this.severity = versionRangeElement.getAttribute("severity");
|
|
|
|
else
|
|
|
|
this.severity = DEFAULT_SEVERITY;
|
2012-07-11 15:56:34 +00:00
|
|
|
if (versionRangeElement && versionRangeElement.hasAttribute("vulnerabilitystatus")) {
|
|
|
|
this.vulnerabilityStatus = versionRangeElement.getAttribute("vulnerabilitystatus");
|
|
|
|
} else {
|
|
|
|
this.vulnerabilityStatus = VULNERABILITYSTATUS_NONE;
|
|
|
|
}
|
2007-08-16 00:43:12 +00:00
|
|
|
this.targetApps = { };
|
|
|
|
var found = false;
|
|
|
|
|
|
|
|
if (versionRangeElement) {
|
|
|
|
for (var i = 0; i < versionRangeElement.childNodes.length; ++i) {
|
2007-11-07 08:57:19 +00:00
|
|
|
var targetAppElement = versionRangeElement.childNodes.item(i);
|
|
|
|
if (!(targetAppElement instanceof Ci.nsIDOMElement) ||
|
2007-08-16 00:43:12 +00:00
|
|
|
targetAppElement.localName != "targetApplication")
|
|
|
|
continue;
|
|
|
|
found = true;
|
|
|
|
// default to the current application if id is not provided.
|
|
|
|
var appID = targetAppElement.hasAttribute("id") ? targetAppElement.getAttribute("id") : gApp.ID;
|
|
|
|
this.targetApps[appID] = this.getBlocklistAppVersions(targetAppElement);
|
|
|
|
}
|
|
|
|
}
|
2008-09-02 11:53:34 +00:00
|
|
|
// Default to all versions of the current application when no targetApplication
|
|
|
|
// elements were found
|
2007-08-16 00:43:12 +00:00
|
|
|
if (!found)
|
|
|
|
this.targetApps[gApp.ID] = this.getBlocklistAppVersions(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
BlocklistItemData.prototype = {
|
2008-09-02 11:53:34 +00:00
|
|
|
/**
|
|
|
|
* Tests if a version of an item is included in the version range and target
|
|
|
|
* application information represented by this BlocklistItemData using the
|
|
|
|
* provided application and toolkit versions.
|
|
|
|
* @param version
|
|
|
|
* The version of the item being tested.
|
|
|
|
* @param appVersion
|
|
|
|
* The application version to test with.
|
|
|
|
* @param toolkitVersion
|
|
|
|
* The toolkit version to test with.
|
|
|
|
* @returns True if the version range covers the item version and application
|
|
|
|
* or toolkit version.
|
|
|
|
*/
|
2012-10-24 09:58:00 +00:00
|
|
|
includesItem: function BlocklistItemData_includesItem(version, appVersion, toolkitVersion) {
|
2008-09-02 11:53:34 +00:00
|
|
|
// Some platforms have no version for plugins, these don't match if there
|
|
|
|
// was a min/maxVersion provided
|
|
|
|
if (!version && (this.minVersion || this.maxVersion))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Check if the item version matches
|
|
|
|
if (!this.matchesRange(version, this.minVersion, this.maxVersion))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Check if the application version matches
|
|
|
|
if (this.matchesTargetRange(gApp.ID, appVersion))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Check if the toolkit version matches
|
|
|
|
return this.matchesTargetRange(TOOLKIT_ID, toolkitVersion);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if a version is higher than or equal to the minVersion (if provided)
|
|
|
|
* and lower than or equal to the maxVersion (if provided).
|
|
|
|
* @param version
|
|
|
|
* The version to test.
|
|
|
|
* @param minVersion
|
|
|
|
* The minimum version. If null it is assumed that version is always
|
|
|
|
* larger.
|
|
|
|
* @param maxVersion
|
|
|
|
* The maximum version. If null it is assumed that version is always
|
|
|
|
* smaller.
|
|
|
|
*/
|
2012-10-24 09:58:00 +00:00
|
|
|
matchesRange: function BlocklistItemData_matchesRange(version, minVersion, maxVersion) {
|
2008-09-02 11:53:34 +00:00
|
|
|
if (minVersion && gVersionChecker.compare(version, minVersion) < 0)
|
|
|
|
return false;
|
|
|
|
if (maxVersion && gVersionChecker.compare(version, maxVersion) > 0)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests if there is a matching range for the given target application id and
|
|
|
|
* version.
|
|
|
|
* @param appID
|
|
|
|
* The application ID to test for, may be for an application or toolkit
|
|
|
|
* @param appVersion
|
|
|
|
* The version of the application to test for.
|
|
|
|
* @returns True if this version range covers the application version given.
|
|
|
|
*/
|
2012-10-24 09:58:00 +00:00
|
|
|
matchesTargetRange: function BlocklistItemData_matchesTargetRange(appID, appVersion) {
|
2008-09-02 11:53:34 +00:00
|
|
|
var blTargetApp = this.targetApps[appID];
|
|
|
|
if (!blTargetApp)
|
|
|
|
return false;
|
|
|
|
|
2012-05-27 12:21:48 +00:00
|
|
|
for (let app of blTargetApp) {
|
|
|
|
if (this.matchesRange(appVersion, app.minVersion, app.maxVersion))
|
2008-09-02 11:53:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves a version range (e.g. minVersion and maxVersion) for a
|
|
|
|
* blocklist item's targetApplication element.
|
|
|
|
* @param targetAppElement
|
|
|
|
* A targetApplication blocklist element.
|
|
|
|
* @returns An array of JS objects with the following properties:
|
|
|
|
* "minVersion" The minimum version in a version range (default = null).
|
|
|
|
* "maxVersion" The maximum version in a version range (default = null).
|
|
|
|
*/
|
2012-10-24 09:58:00 +00:00
|
|
|
getBlocklistAppVersions: function BlocklistItemData_getBlocklistAppVersions(targetAppElement) {
|
2007-08-16 00:43:12 +00:00
|
|
|
var appVersions = [ ];
|
|
|
|
|
|
|
|
if (targetAppElement) {
|
|
|
|
for (var i = 0; i < targetAppElement.childNodes.length; ++i) {
|
2007-11-07 08:57:19 +00:00
|
|
|
var versionRangeElement = targetAppElement.childNodes.item(i);
|
|
|
|
if (!(versionRangeElement instanceof Ci.nsIDOMElement) ||
|
2007-08-16 00:43:12 +00:00
|
|
|
versionRangeElement.localName != "versionRange")
|
|
|
|
continue;
|
|
|
|
appVersions.push(this.getBlocklistVersionRange(versionRangeElement));
|
|
|
|
}
|
|
|
|
}
|
2008-09-02 11:53:34 +00:00
|
|
|
// return minVersion = null and maxVersion = null if no specific versionRange
|
|
|
|
// elements were found
|
|
|
|
if (appVersions.length == 0)
|
|
|
|
appVersions.push(this.getBlocklistVersionRange(null));
|
2007-08-16 00:43:12 +00:00
|
|
|
return appVersions;
|
|
|
|
},
|
|
|
|
|
2008-09-02 11:53:34 +00:00
|
|
|
/**
|
|
|
|
* Retrieves a version range (e.g. minVersion and maxVersion) for a blocklist
|
|
|
|
* versionRange element.
|
|
|
|
* @param versionRangeElement
|
|
|
|
* The versionRange blocklist element.
|
|
|
|
* @returns A JS object with the following properties:
|
|
|
|
* "minVersion" The minimum version in a version range (default = null).
|
|
|
|
* "maxVersion" The maximum version in a version range (default = null).
|
|
|
|
*/
|
2012-10-24 09:58:00 +00:00
|
|
|
getBlocklistVersionRange: function BlocklistItemData_getBlocklistVersionRange(versionRangeElement) {
|
2008-09-02 11:53:34 +00:00
|
|
|
var minVersion = null;
|
|
|
|
var maxVersion = null;
|
2007-08-16 00:43:12 +00:00
|
|
|
if (!versionRangeElement)
|
|
|
|
return { minVersion: minVersion, maxVersion: maxVersion };
|
|
|
|
|
|
|
|
if (versionRangeElement.hasAttribute("minVersion"))
|
|
|
|
minVersion = versionRangeElement.getAttribute("minVersion");
|
|
|
|
if (versionRangeElement.hasAttribute("maxVersion"))
|
|
|
|
maxVersion = versionRangeElement.getAttribute("maxVersion");
|
|
|
|
|
|
|
|
return { minVersion: minVersion, maxVersion: maxVersion };
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-10-31 16:13:28 +00:00
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([Blocklist]);
|