2014-06-25 09:12:07 +04:00
|
|
|
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
2012-08-04 05:22:55 +04: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 04:43:12 +04:00
|
|
|
|
2011-07-20 00:16:35 +04:00
|
|
|
"use strict";
|
|
|
|
|
2018-04-20 02:01:24 +03:00
|
|
|
/* eslint "valid-jsdoc": [2, {requireReturn: false}] */
|
|
|
|
|
2018-04-25 03:46:44 +03:00
|
|
|
var EXPORTED_SYMBOLS = ["Blocklist"];
|
|
|
|
|
2019-01-17 21:18:31 +03:00
|
|
|
const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
|
|
|
const {AppConstants} = ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
|
2018-06-13 21:51:45 +03:00
|
|
|
XPCOMUtils.defineLazyGlobalGetters(this, ["XMLHttpRequest"]);
|
2007-08-25 10:12:05 +04:00
|
|
|
|
2018-04-25 03:46:44 +03:00
|
|
|
ChromeUtils.defineModuleGetter(this, "AddonManager",
|
|
|
|
"resource://gre/modules/AddonManager.jsm");
|
|
|
|
ChromeUtils.defineModuleGetter(this, "AddonManagerPrivate",
|
|
|
|
"resource://gre/modules/AddonManager.jsm");
|
2018-04-10 23:23:35 +03:00
|
|
|
ChromeUtils.defineModuleGetter(this, "CertUtils",
|
|
|
|
"resource://gre/modules/CertUtils.jsm");
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.defineModuleGetter(this, "FileUtils",
|
|
|
|
"resource://gre/modules/FileUtils.jsm");
|
|
|
|
ChromeUtils.defineModuleGetter(this, "UpdateUtils",
|
|
|
|
"resource://gre/modules/UpdateUtils.jsm");
|
|
|
|
ChromeUtils.defineModuleGetter(this, "OS",
|
|
|
|
"resource://gre/modules/osfile.jsm");
|
|
|
|
ChromeUtils.defineModuleGetter(this, "ServiceRequest",
|
|
|
|
"resource://gre/modules/ServiceRequest.jsm");
|
2012-05-10 06:28:45 +04:00
|
|
|
|
2018-06-13 21:51:45 +03:00
|
|
|
/**
|
|
|
|
# The blocklist XML file looks something like this:
|
|
|
|
#
|
|
|
|
# <blocklist xmlns="http://www.mozilla.org/2006/addons-blocklist">
|
|
|
|
# <emItems>
|
|
|
|
# <emItem id="item_1@domain" blockID="i1">
|
|
|
|
# <prefs>
|
|
|
|
# <pref>accessibility.accesskeycausesactivation</pref>
|
|
|
|
# <pref>accessibility.blockautorefresh</pref>
|
|
|
|
# </prefs>
|
|
|
|
# <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">
|
|
|
|
# <versionRange minVersion="1.9" maxVersion="1.9.*"/>
|
|
|
|
# </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">
|
|
|
|
# <versionRange minVersion="1.9" maxVersion="1.9.*"/>
|
|
|
|
# </targetApplication>
|
|
|
|
# </versionRange>
|
|
|
|
# </emItem>
|
|
|
|
# <emItem id="item_2@domain" blockID="i2">
|
|
|
|
# <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>
|
|
|
|
# <emItem id="item_4@domain" blockID="i3">
|
|
|
|
# <versionRange>
|
|
|
|
# <targetApplication>
|
|
|
|
# <versionRange minVersion="1.5" maxVersion="1.5.*"/>
|
|
|
|
# </targetApplication>
|
|
|
|
# </versionRange>
|
|
|
|
# <emItem id="/@badperson\.com$/"/>
|
|
|
|
# </emItems>
|
|
|
|
# <pluginItems>
|
|
|
|
# <pluginItem blockID="i4">
|
|
|
|
# <!-- 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>
|
|
|
|
# <gfxItems>
|
|
|
|
# <gfxItem ... />
|
|
|
|
# </gfxItems>
|
|
|
|
# </blocklist>
|
|
|
|
*/
|
|
|
|
|
2018-03-13 18:23:57 +03:00
|
|
|
// The remote settings updater is the new system in charge of fetching remote data
|
2017-04-20 11:35:04 +03:00
|
|
|
// securely and efficiently. It will replace the current XML-based system.
|
|
|
|
// See Bug 1257565 and Bug 1252456.
|
2018-04-25 03:46:44 +03:00
|
|
|
const BlocklistClients = {};
|
|
|
|
ChromeUtils.defineModuleGetter(BlocklistClients, "initialize",
|
|
|
|
"resource://services-common/blocklist-clients.js");
|
2017-04-20 11:35:04 +03:00
|
|
|
|
2015-03-04 18:48:04 +03:00
|
|
|
const TOOLKIT_ID = "toolkit@mozilla.org";
|
2007-08-16 04:43:12 +04:00
|
|
|
const KEY_PROFILEDIR = "ProfD";
|
2008-03-20 01:35:03 +03:00
|
|
|
const KEY_APPDIR = "XCurProcD";
|
2007-08-16 04:43:12 +04:00
|
|
|
const FILE_BLOCKLIST = "blocklist.xml";
|
2011-01-15 00:29:27 +03:00
|
|
|
const PREF_BLOCKLIST_LASTUPDATETIME = "app.update.lastUpdateTime.blocklist-background-update-timer";
|
2007-08-16 04:43:12 +04:00
|
|
|
const PREF_BLOCKLIST_URL = "extensions.blocklist.url";
|
2011-05-26 01:31:56 +04:00
|
|
|
const PREF_BLOCKLIST_ITEM_URL = "extensions.blocklist.itemURL";
|
2007-08-16 04:43:12 +04:00
|
|
|
const PREF_BLOCKLIST_ENABLED = "extensions.blocklist.enabled";
|
2018-01-31 14:45:53 +03:00
|
|
|
const PREF_BLOCKLIST_LAST_MODIFIED = "extensions.blocklist.lastModified";
|
2008-11-02 15:13:48 +03:00
|
|
|
const PREF_BLOCKLIST_LEVEL = "extensions.blocklist.level";
|
2011-02-24 14:20:02 +03:00
|
|
|
const PREF_BLOCKLIST_PINGCOUNTTOTAL = "extensions.blocklist.pingCountTotal";
|
|
|
|
const PREF_BLOCKLIST_PINGCOUNTVERSION = "extensions.blocklist.pingCountVersion";
|
2013-06-11 18:58:42 +04:00
|
|
|
const PREF_BLOCKLIST_SUPPRESSUI = "extensions.blocklist.suppressUI";
|
2008-04-25 21:10:02 +04:00
|
|
|
const PREF_APP_DISTRIBUTION = "distribution.id";
|
|
|
|
const PREF_APP_DISTRIBUTION_VERSION = "distribution.version";
|
2007-08-16 04:43:12 +04:00
|
|
|
const PREF_EM_LOGGING_ENABLED = "extensions.logging.enabled";
|
|
|
|
const XMLURI_BLOCKLIST = "http://www.mozilla.org/2006/addons-blocklist";
|
2017-10-15 21:50:30 +03:00
|
|
|
const XMLURI_PARSE_ERROR = "http://www.mozilla.org/newlayout/xml/parsererror.xml";
|
|
|
|
const URI_BLOCKLIST_DIALOG = "chrome://mozapps/content/extensions/blocklist.xul";
|
2008-11-02 15:13:48 +03:00
|
|
|
const DEFAULT_SEVERITY = 3;
|
|
|
|
const DEFAULT_LEVEL = 2;
|
|
|
|
const MAX_BLOCK_LEVEL = 3;
|
2009-10-02 15:26:04 +04:00
|
|
|
const SEVERITY_OUTDATED = 0;
|
2012-07-11 19:56:34 +04:00
|
|
|
const VULNERABILITYSTATUS_NONE = 0;
|
|
|
|
const VULNERABILITYSTATUS_UPDATE_AVAILABLE = 1;
|
|
|
|
const VULNERABILITYSTATUS_NO_UPDATE = 2;
|
2007-08-16 04:43:12 +04:00
|
|
|
|
2014-01-06 12:46:32 +04:00
|
|
|
const EXTENSION_BLOCK_FILTERS = ["id", "name", "creator", "homepageURL", "updateURL"];
|
|
|
|
|
2007-08-16 04:43:12 +04:00
|
|
|
var gLoggingEnabled = null;
|
2008-11-02 15:13:48 +03:00
|
|
|
var gBlocklistEnabled = true;
|
|
|
|
var gBlocklistLevel = DEFAULT_LEVEL;
|
2007-08-16 04:43:12 +04:00
|
|
|
|
2018-04-20 02:01:24 +03:00
|
|
|
/**
|
|
|
|
* @class nsIBlocklistPrompt
|
|
|
|
*
|
|
|
|
* nsIBlocklistPrompt is used, if available, by the default implementation of
|
|
|
|
* nsIBlocklistService to display a confirmation UI to the user before blocking
|
|
|
|
* extensions/plugins.
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @method prompt
|
|
|
|
*
|
|
|
|
* Prompt the user about newly blocked addons. The prompt is then resposible
|
|
|
|
* for soft-blocking any addons that need to be afterwards
|
|
|
|
*
|
|
|
|
* @param {object[]} aAddons
|
|
|
|
* An array of addons and plugins that are blocked. These are javascript
|
|
|
|
* objects with properties:
|
|
|
|
* name - the plugin or extension name,
|
|
|
|
* version - the version of the extension or plugin,
|
|
|
|
* icon - the plugin or extension icon,
|
|
|
|
* disable - can be used by the nsIBlocklistPrompt to allows users to decide
|
|
|
|
* whether a soft-blocked add-on should be disabled,
|
|
|
|
* blocked - true if the item is hard-blocked, false otherwise,
|
|
|
|
* item - the nsIPluginTag or Addon object
|
|
|
|
*/
|
|
|
|
|
2015-02-25 01:11:33 +03: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.
|
2015-11-20 03:35:41 +03:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "gApp", function() {
|
2017-11-22 16:35:52 +03:00
|
|
|
// eslint-disable-next-line mozilla/use-services
|
2015-02-25 01:11:33 +03:00
|
|
|
let appinfo = Cc["@mozilla.org/xre/app-info;1"]
|
|
|
|
.getService(Ci.nsIXULRuntime);
|
|
|
|
try {
|
|
|
|
appinfo.QueryInterface(Ci.nsIXULAppInfo);
|
2015-12-03 05:42:16 +03:00
|
|
|
} catch (ex) {
|
2015-02-25 01:11:33 +03:00
|
|
|
// Not all applications implement nsIXULAppInfo (e.g. xpcshell doesn't).
|
2015-12-03 05:42:16 +03:00
|
|
|
if (!(ex instanceof Components.Exception) ||
|
|
|
|
ex.result != Cr.NS_NOINTERFACE)
|
|
|
|
throw ex;
|
2015-02-25 01:11:33 +03:00
|
|
|
}
|
|
|
|
return appinfo;
|
2009-12-04 02:30:50 +03:00
|
|
|
});
|
|
|
|
|
2018-06-14 03:06:49 +03:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "gAppID", function() {
|
|
|
|
return gApp.ID;
|
|
|
|
});
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "gAppVersion", function() {
|
|
|
|
return gApp.version;
|
|
|
|
});
|
|
|
|
|
2015-11-20 03:35:41 +03:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "gABI", function() {
|
2009-12-04 02:30:50 +03:00
|
|
|
let abi = null;
|
|
|
|
try {
|
|
|
|
abi = gApp.XPCOMABI;
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (e) {
|
2009-12-04 02:30:50 +03:00
|
|
|
LOG("BlockList Global gABI: XPCOM ABI unknown.");
|
|
|
|
}
|
|
|
|
return abi;
|
|
|
|
});
|
|
|
|
|
2015-11-20 03:35:41 +03:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "gOSVersion", function() {
|
2009-12-04 02:30:50 +03:00
|
|
|
let osVersion;
|
|
|
|
try {
|
2017-11-22 16:35:52 +03:00
|
|
|
osVersion = Services.sysinfo.getProperty("name") + " " + Services.sysinfo.getProperty("version");
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (e) {
|
2009-12-04 02:30:50 +03:00
|
|
|
LOG("BlockList Global gOSVersion: OS Version unknown.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (osVersion) {
|
|
|
|
try {
|
2017-11-22 16:35:52 +03:00
|
|
|
osVersion += " (" + Services.sysinfo.getProperty("secondaryLibrary") + ")";
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (e) {
|
2009-12-04 02:30:50 +03:00
|
|
|
// Not all platforms have a secondary widget library, so an error is nothing to worry about.
|
|
|
|
}
|
|
|
|
osVersion = encodeURIComponent(osVersion);
|
|
|
|
}
|
|
|
|
return osVersion;
|
|
|
|
});
|
|
|
|
|
2007-08-16 04:43:12 +04:00
|
|
|
/**
|
|
|
|
* Logs a string to the error console.
|
2018-04-20 02:01:24 +03:00
|
|
|
* @param {string} string
|
|
|
|
* The string to write to the error console..
|
2007-08-16 04:43:12 +04:00
|
|
|
*/
|
|
|
|
function LOG(string) {
|
|
|
|
if (gLoggingEnabled) {
|
|
|
|
dump("*** " + string + "\n");
|
2018-02-21 19:37:47 +03:00
|
|
|
Services.console.logStringMessage(string);
|
2007-08-16 04:43:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-02 15:13:48 +03:00
|
|
|
// Restarts the application checking in with observers first
|
|
|
|
function restartApp() {
|
|
|
|
// Notify all windows that an application quit has been requested.
|
|
|
|
var cancelQuit = Cc["@mozilla.org/supports-PRBool;1"].
|
|
|
|
createInstance(Ci.nsISupportsPRBool);
|
2017-11-22 16:35:52 +03:00
|
|
|
Services.obs.notifyObservers(cancelQuit, "quit-application-requested");
|
2008-11-02 15:13:48 +03:00
|
|
|
|
2011-01-15 00:29:27 +03:00
|
|
|
// Something aborted the quit process.
|
2008-11-02 15:13:48 +03:00
|
|
|
if (cancelQuit.data)
|
|
|
|
return;
|
|
|
|
|
2017-11-22 16:35:52 +03:00
|
|
|
Services.startup.quit(Ci.nsIAppStartup.eRestart | Ci.nsIAppStartup.eAttemptQuit);
|
2008-11-02 15:13:48 +03:00
|
|
|
}
|
|
|
|
|
2007-11-07 11:56:29 +03: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 10:49:45 +04:00
|
|
|
* its comma separated list for the element to be valid. Similarly for the
|
2007-11-07 11:56:29 +03:00
|
|
|
* xpcomabi attribute.
|
2018-04-20 02:01:24 +03:00
|
|
|
*
|
|
|
|
* @param {Element} blocklistElement
|
|
|
|
* The blocklist element from an XML blocklist.
|
|
|
|
* @returns {bool}
|
|
|
|
* Whether the entry matches the current OS.
|
2007-11-07 11:56:29 +03:00
|
|
|
*/
|
|
|
|
function matchesOSABI(blocklistElement) {
|
2018-06-14 03:06:49 +03:00
|
|
|
let os = blocklistElement.getAttribute("os");
|
|
|
|
if (os) {
|
|
|
|
let choices = os.split(",");
|
2018-02-01 22:45:22 +03:00
|
|
|
if (choices.length > 0 && !choices.includes(gApp.OS))
|
2007-11-07 11:56:29 +03:00
|
|
|
return false;
|
|
|
|
}
|
2011-01-15 00:29:27 +03:00
|
|
|
|
2018-06-14 03:06:49 +03:00
|
|
|
let xpcomabi = blocklistElement.getAttribute("xpcomabi");
|
|
|
|
if (xpcomabi) {
|
|
|
|
let choices = xpcomabi.split(",");
|
2018-02-01 22:45:22 +03:00
|
|
|
if (choices.length > 0 && !choices.includes(gApp.XPCOMABI))
|
2007-11-07 11:56:29 +03:00
|
|
|
return false;
|
|
|
|
}
|
2011-01-15 00:29:27 +03:00
|
|
|
|
2007-11-07 11:56:29 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-04-25 21:10:02 +04: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.
|
2018-04-20 02:01:24 +03:00
|
|
|
*
|
|
|
|
* @returns {string} The current requested locale.
|
2008-04-25 21:10:02 +04:00
|
|
|
*/
|
|
|
|
function getLocale() {
|
2018-09-21 18:30:37 +03:00
|
|
|
return Services.locale.requestedLocale;
|
2008-04-25 21:10:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the distribution pref values, from defaults only */
|
|
|
|
function getDistributionPrefValue(aPrefName) {
|
2017-11-22 16:35:52 +03:00
|
|
|
return Services.prefs.getDefaultBranch(null).getCharPref(aPrefName, "default");
|
2008-04-25 21:10:02 +04:00
|
|
|
}
|
|
|
|
|
2007-08-16 04:43:12 +04: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.
|
|
|
|
*/
|
2018-04-25 03:46:44 +03:00
|
|
|
var Blocklist = {
|
|
|
|
_init() {
|
|
|
|
Services.obs.addObserver(this, "xpcom-shutdown");
|
|
|
|
|
|
|
|
gLoggingEnabled = Services.prefs.getBoolPref(PREF_EM_LOGGING_ENABLED, false);
|
|
|
|
gBlocklistEnabled = Services.prefs.getBoolPref(PREF_BLOCKLIST_ENABLED, true);
|
|
|
|
gBlocklistLevel = Math.min(Services.prefs.getIntPref(PREF_BLOCKLIST_LEVEL, DEFAULT_LEVEL),
|
|
|
|
MAX_BLOCK_LEVEL);
|
|
|
|
Services.prefs.addObserver("extensions.blocklist.", this);
|
|
|
|
Services.prefs.addObserver(PREF_EM_LOGGING_ENABLED, this);
|
|
|
|
|
2018-06-14 21:54:19 +03:00
|
|
|
// Instantiate Remote Settings clients for blocklists.
|
|
|
|
// Their initialization right here serves two purposes:
|
|
|
|
// - Make sure they are instantiated (it's cheap) in order to be included in the synchronization process;
|
|
|
|
// - Pave the way for Bug 1257565 which will leverage remote settings instead of the XML file
|
|
|
|
// to manage the blocklists state.
|
|
|
|
BlocklistClients.initialize();
|
|
|
|
|
2018-04-25 03:46:44 +03:00
|
|
|
// If the stub blocklist service deferred any queries because we
|
|
|
|
// weren't loaded yet, execute them now.
|
|
|
|
for (let entry of Services.blocklist.pluginQueries.splice(0)) {
|
|
|
|
entry.resolve(this.getPluginBlocklistState(entry.plugin,
|
|
|
|
entry.appVersion,
|
|
|
|
entry.toolkitVersion));
|
|
|
|
}
|
|
|
|
},
|
2007-08-16 04:43:12 +04:00
|
|
|
|
2018-04-20 02:01:24 +03:00
|
|
|
STATE_NOT_BLOCKED: Ci.nsIBlocklistService.STATE_NOT_BLOCKED,
|
|
|
|
STATE_SOFTBLOCKED: Ci.nsIBlocklistService.STATE_SOFTBLOCKED,
|
|
|
|
STATE_BLOCKED: Ci.nsIBlocklistService.STATE_BLOCKED,
|
|
|
|
STATE_OUTDATED: Ci.nsIBlocklistService.STATE_OUTDATED,
|
|
|
|
STATE_VULNERABLE_UPDATE_AVAILABLE: Ci.nsIBlocklistService.STATE_VULNERABLE_UPDATE_AVAILABLE,
|
|
|
|
STATE_VULNERABLE_NO_UPDATE: Ci.nsIBlocklistService.STATE_VULNERABLE_NO_UPDATE,
|
|
|
|
|
|
|
|
|
2007-08-16 04:43:12 +04:00
|
|
|
/**
|
|
|
|
* 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,
|
2016-05-04 17:12:19 +03:00
|
|
|
_gfxEntries: null,
|
2007-08-16 04:43:12 +04:00
|
|
|
_pluginEntries: null,
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
shutdown() {
|
2015-03-23 16:40:08 +03:00
|
|
|
Services.obs.removeObserver(this, "xpcom-shutdown");
|
2017-11-22 16:35:52 +03:00
|
|
|
Services.prefs.removeObserver("extensions.blocklist.", this);
|
|
|
|
Services.prefs.removeObserver(PREF_EM_LOGGING_ENABLED, this);
|
2015-03-23 16:40:08 +03:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
observe(aSubject, aTopic, aData) {
|
2007-08-16 04:43:12 +04:00
|
|
|
switch (aTopic) {
|
|
|
|
case "xpcom-shutdown":
|
2015-03-23 16:40:08 +03:00
|
|
|
this.shutdown();
|
2007-08-16 04:43:12 +04:00
|
|
|
break;
|
2018-03-15 19:16:11 +03:00
|
|
|
case "profile-after-change":
|
|
|
|
// We're only called here on non-Desktop-Firefox, and use this opportunity to try to
|
|
|
|
// load the blocklist asynchronously. On desktop Firefox, we load the list from
|
|
|
|
// nsBrowserGlue after sessionstore-windows-restored.
|
|
|
|
this.loadBlocklistAsync();
|
|
|
|
break;
|
2008-11-02 15:13:48 +03:00
|
|
|
case "nsPref:changed":
|
|
|
|
switch (aData) {
|
2014-01-31 23:46:04 +04:00
|
|
|
case PREF_EM_LOGGING_ENABLED:
|
2018-01-06 02:25:51 +03:00
|
|
|
gLoggingEnabled = Services.prefs.getBoolPref(PREF_EM_LOGGING_ENABLED, false);
|
2014-01-31 23:46:04 +04:00
|
|
|
break;
|
2008-11-02 15:13:48 +03:00
|
|
|
case PREF_BLOCKLIST_ENABLED:
|
2018-01-06 02:25:51 +03:00
|
|
|
gBlocklistEnabled = Services.prefs.getBoolPref(PREF_BLOCKLIST_ENABLED, true);
|
2018-06-13 21:51:45 +03:00
|
|
|
// This is a bit messy. Especially in tests, but in principle also by users toggling
|
|
|
|
// this preference repeatedly, plugin loads could race with each other if we don't
|
|
|
|
// enforce that they are applied sequentially.
|
|
|
|
// So we only update once the previous `_blocklistUpdated` call finishes running.
|
|
|
|
let lastUpdate = this._lastUpdate || undefined;
|
|
|
|
let newUpdate = this._lastUpdate = (async () => {
|
|
|
|
await lastUpdate;
|
|
|
|
this._clear();
|
|
|
|
await this.loadBlocklistAsync();
|
|
|
|
await this._blocklistUpdated(null, null);
|
|
|
|
if (newUpdate == this._lastUpdate) {
|
|
|
|
delete this._lastUpdate;
|
|
|
|
}
|
|
|
|
})().catch(Cu.reportError);
|
2008-11-02 15:13:48 +03:00
|
|
|
break;
|
|
|
|
case PREF_BLOCKLIST_LEVEL:
|
2018-01-06 02:25:51 +03:00
|
|
|
gBlocklistLevel = Math.min(Services.prefs.getIntPref(PREF_BLOCKLIST_LEVEL, DEFAULT_LEVEL),
|
2008-11-02 15:13:48 +03:00
|
|
|
MAX_BLOCK_LEVEL);
|
|
|
|
this._blocklistUpdated(null, null);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2015-03-23 16:40:08 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-04-20 02:01:24 +03:00
|
|
|
/**
|
|
|
|
* Determine the blocklist state of an add-on
|
|
|
|
* @param {Addon} addon
|
|
|
|
* The addon item to be checked.
|
|
|
|
* @param {string?} appVersion
|
|
|
|
* The version of the application we are checking in the blocklist.
|
|
|
|
* If this parameter is null, the version of the running application
|
|
|
|
* is used.
|
|
|
|
* @param {string?} toolkitVersion
|
|
|
|
* The version of the toolkit we are checking in the blocklist.
|
|
|
|
* If this parameter is null, the version of the running toolkit
|
|
|
|
* is used.
|
|
|
|
* @returns {integer} The STATE constant.
|
|
|
|
*/
|
2018-04-16 22:03:09 +03:00
|
|
|
async getAddonBlocklistState(addon, appVersion, toolkitVersion) {
|
|
|
|
await this.loadBlocklistAsync();
|
2014-01-06 12:46:32 +04:00
|
|
|
return this._getAddonBlocklistState(addon, this._addonEntries,
|
2008-11-02 15:13:48 +03:00
|
|
|
appVersion, toolkitVersion);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2017-07-04 04:05:52 +03:00
|
|
|
* Returns a matching blocklist entry for the given add-on, if one
|
|
|
|
* exists.
|
2008-11-02 15:13:48 +03:00
|
|
|
*
|
2018-04-20 02:01:24 +03:00
|
|
|
* @param {Addon} addon
|
|
|
|
* The add-on object of the item to get the blocklist state for.
|
|
|
|
* @param {object[]} addonEntries
|
|
|
|
* The add-on blocklist entries to compare against.
|
|
|
|
* @param {string?} appVersion
|
|
|
|
* The application version to compare to, will use the current
|
|
|
|
* version if null.
|
|
|
|
* @param {string?} toolkitVersion
|
|
|
|
* The toolkit version to compare to, will use the current version if
|
|
|
|
* null.
|
|
|
|
* @returns {object?}
|
|
|
|
* A blocklist entry for this item, with `state` and `url`
|
2017-07-04 04:05:52 +03:00
|
|
|
* properties indicating the block state and URL, if there is
|
|
|
|
* a matching blocklist entry, or null otherwise.
|
2008-11-02 15:13:48 +03:00
|
|
|
*/
|
2017-07-04 04:05:52 +03:00
|
|
|
_getAddonBlocklistEntry(addon, addonEntries, appVersion, toolkitVersion) {
|
2008-11-02 15:13:48 +03:00
|
|
|
if (!gBlocklistEnabled)
|
2017-07-04 04:05:52 +03:00
|
|
|
return null;
|
2008-11-02 15:13:48 +03:00
|
|
|
|
2015-02-25 01:11:33 +03:00
|
|
|
// Not all applications implement nsIXULAppInfo (e.g. xpcshell doesn't).
|
2018-06-14 03:06:49 +03:00
|
|
|
if (!appVersion && !gAppVersion)
|
2017-07-04 04:05:52 +03:00
|
|
|
return null;
|
2015-02-25 01:11:33 +03:00
|
|
|
|
2008-02-29 22:06:29 +03:00
|
|
|
if (!appVersion)
|
2018-06-14 03:06:49 +03:00
|
|
|
appVersion = gAppVersion;
|
2008-02-29 22:06:29 +03:00
|
|
|
if (!toolkitVersion)
|
2007-08-16 04:43:12 +04:00
|
|
|
toolkitVersion = gApp.platformVersion;
|
|
|
|
|
2014-01-06 12:46:32 +04:00
|
|
|
var blItem = this._findMatchingAddonEntry(addonEntries, addon);
|
2007-08-16 04:43:12 +04:00
|
|
|
if (!blItem)
|
2017-07-04 04:05:52 +03:00
|
|
|
return null;
|
2007-08-16 04:43:12 +04:00
|
|
|
|
2012-11-27 07:40:00 +04:00
|
|
|
for (let currentblItem of blItem.versions) {
|
2017-07-04 04:05:52 +03:00
|
|
|
if (currentblItem.includesItem(addon.version, appVersion, toolkitVersion)) {
|
|
|
|
return {
|
|
|
|
state: (currentblItem.severity >= gBlocklistLevel ?
|
|
|
|
Ci.nsIBlocklistService.STATE_BLOCKED : Ci.nsIBlocklistService.STATE_SOFTBLOCKED),
|
|
|
|
url: blItem.blockID && this._createBlocklistURL(blItem.blockID),
|
|
|
|
};
|
|
|
|
}
|
2007-08-16 04:43:12 +04:00
|
|
|
}
|
2017-07-04 04:05:52 +03:00
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2018-04-20 02:01:24 +03:00
|
|
|
/**
|
|
|
|
* Returns a promise that resolves to the blocklist entry.
|
|
|
|
* The blocklist entry is an object with `state` and `url`
|
|
|
|
* properties, if a blocklist entry for the add-on exists, or null
|
|
|
|
* otherwise.
|
|
|
|
|
|
|
|
* @param {Addon} addon
|
|
|
|
* The addon object to match.
|
|
|
|
* @param {string?} appVersion
|
|
|
|
* The version of the application we are checking in the blocklist.
|
|
|
|
* If this parameter is null, the version of the running application
|
|
|
|
* is used.
|
|
|
|
* @param {string?} toolkitVersion
|
|
|
|
* The version of the toolkit we are checking in the blocklist.
|
|
|
|
* If this parameter is null, the version of the running toolkit
|
|
|
|
* is used.
|
|
|
|
* @returns {Promise<object?>}
|
|
|
|
* The blocklist entry for the add-on, if one exists, or null
|
|
|
|
* otherwise.
|
|
|
|
*/
|
2018-04-09 18:00:38 +03:00
|
|
|
async getAddonBlocklistEntry(addon, appVersion, toolkitVersion) {
|
|
|
|
await this.loadBlocklistAsync();
|
2017-07-04 04:05:52 +03:00
|
|
|
return this._getAddonBlocklistEntry(addon, this._addonEntries,
|
|
|
|
appVersion, toolkitVersion);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Private version of getAddonBlocklistState that allows the caller to pass in
|
|
|
|
* the add-on blocklist entries to compare against.
|
|
|
|
*
|
2018-04-20 02:01:24 +03:00
|
|
|
* @param {Addon} addon
|
|
|
|
* The add-on object of the item to get the blocklist state for.
|
|
|
|
* @param {object[]} addonEntries
|
|
|
|
* The add-on blocklist entries to compare against.
|
|
|
|
* @param {string?} appVersion
|
|
|
|
* The application version to compare to, will use the current
|
|
|
|
* version if null.
|
|
|
|
* @param {string?} toolkitVersion
|
|
|
|
* The toolkit version to compare to, will use the current version if
|
|
|
|
* null.
|
|
|
|
* @returns {integer}
|
|
|
|
* The blocklist state for the item, one of the STATE constants as
|
|
|
|
* defined in nsIBlocklistService.
|
2017-07-04 04:05:52 +03:00
|
|
|
*/
|
|
|
|
_getAddonBlocklistState(addon, addonEntries, appVersion, toolkitVersion) {
|
|
|
|
let entry = this._getAddonBlocklistEntry(addon, addonEntries, appVersion, toolkitVersion);
|
|
|
|
if (entry)
|
|
|
|
return entry.state;
|
2008-11-02 15:13:48 +03:00
|
|
|
return Ci.nsIBlocklistService.STATE_NOT_BLOCKED;
|
2007-08-16 04:43:12 +04:00
|
|
|
},
|
|
|
|
|
2013-09-14 21:27:09 +04:00
|
|
|
/**
|
|
|
|
* Returns the set of prefs of the add-on stored in the blocklist file
|
|
|
|
* (probably to revert them on disabling).
|
2018-04-20 02:01:24 +03:00
|
|
|
* @param {Addon} addon
|
2014-01-06 12:46:32 +04:00
|
|
|
* The add-on whose to-be-reset prefs are to be found.
|
2018-04-20 02:01:24 +03:00
|
|
|
* @returns {string[]}
|
|
|
|
* An array of preference names.
|
2013-09-14 21:27:09 +04:00
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
_getAddonPrefs(addon) {
|
2014-01-06 12:46:32 +04:00
|
|
|
let entry = this._findMatchingAddonEntry(this._addonEntries, addon);
|
2013-09-14 21:27:09 +04:00
|
|
|
return entry.prefs.slice(0);
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
_findMatchingAddonEntry(aAddonEntries, aAddon) {
|
2014-01-06 12:46:32 +04:00
|
|
|
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) {
|
2018-06-14 03:06:49 +03:00
|
|
|
for (let [key, value] of Object.entries(entry)) {
|
2014-01-06 12:46:32 +04:00
|
|
|
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 07:40:00 +04:00
|
|
|
}
|
2014-01-06 12:46:32 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
let params = {};
|
|
|
|
for (let filter of EXTENSION_BLOCK_FILTERS) {
|
|
|
|
params[filter] = aAddon[filter];
|
2012-11-27 07:40:00 +04:00
|
|
|
}
|
2014-01-06 12:46:32 +04: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 07:40:00 +04:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
_createBlocklistURL(id) {
|
2011-05-26 01:31:56 +04:00
|
|
|
let url = Services.urlFormatter.formatURLPref(PREF_BLOCKLIST_ITEM_URL);
|
2018-04-27 17:56:46 +03:00
|
|
|
return url.replace(/%blockID%/g, id);
|
2011-05-26 01:31:56 +04:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
notify(aTimer) {
|
2008-11-02 15:13:48 +03:00
|
|
|
if (!gBlocklistEnabled)
|
2007-08-16 04:43:12 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
try {
|
2017-11-22 16:35:52 +03:00
|
|
|
var dsURI = Services.prefs.getCharPref(PREF_BLOCKLIST_URL);
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (e) {
|
2007-08-29 12:16:15 +04:00
|
|
|
LOG("Blocklist::notify: The " + PREF_BLOCKLIST_URL + " preference" +
|
2007-08-16 04:43:12 +04:00
|
|
|
" is missing!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-06 02:25:51 +03:00
|
|
|
var pingCountVersion = Services.prefs.getIntPref(PREF_BLOCKLIST_PINGCOUNTVERSION, 0);
|
|
|
|
var pingCountTotal = Services.prefs.getIntPref(PREF_BLOCKLIST_PINGCOUNTTOTAL, 1);
|
2011-02-24 14:20:02 +03:00
|
|
|
var daysSinceLastPing = 0;
|
2011-04-07 21:41:00 +04:00
|
|
|
if (pingCountVersion == 0) {
|
|
|
|
daysSinceLastPing = "new";
|
2016-12-31 05:47:25 +03:00
|
|
|
} else {
|
2011-01-15 00:29:27 +03:00
|
|
|
// Seconds in one day is used because nsIUpdateTimerManager stores the
|
|
|
|
// last update time in seconds.
|
|
|
|
let secondsInDay = 60 * 60 * 24;
|
2018-01-06 02:25:51 +03:00
|
|
|
let lastUpdateTime = Services.prefs.getIntPref(PREF_BLOCKLIST_LASTUPDATETIME, 0);
|
2011-02-24 14:20:02 +03:00
|
|
|
if (lastUpdateTime == 0) {
|
|
|
|
daysSinceLastPing = "invalid";
|
2016-12-31 05:47:25 +03:00
|
|
|
} else {
|
2011-01-15 00:29:27 +03:00
|
|
|
let now = Math.round(Date.now() / 1000);
|
|
|
|
daysSinceLastPing = Math.floor((now - lastUpdateTime) / secondsInDay);
|
|
|
|
}
|
2011-02-24 14:20:02 +03:00
|
|
|
|
|
|
|
if (daysSinceLastPing == 0 || daysSinceLastPing == "invalid") {
|
|
|
|
pingCountVersion = pingCountTotal = "invalid";
|
2011-01-15 00:29:27 +03:00
|
|
|
}
|
2010-09-21 08:41:19 +04:00
|
|
|
}
|
|
|
|
|
2011-04-07 21:41:00 +04:00
|
|
|
if (pingCountVersion < 1)
|
|
|
|
pingCountVersion = 1;
|
|
|
|
if (pingCountTotal < 1)
|
|
|
|
pingCountTotal = 1;
|
|
|
|
|
2018-06-14 03:06:49 +03:00
|
|
|
let replacements = {
|
|
|
|
APP_ID: gAppID,
|
|
|
|
PRODUCT: gApp.name,
|
|
|
|
BUILD_ID: gApp.appBuildID,
|
|
|
|
BUILD_TARGET: gApp.OS + "_" + gABI,
|
|
|
|
OS_VERSION: gOSVersion,
|
|
|
|
LOCALE: getLocale(),
|
|
|
|
CHANNEL: UpdateUtils.UpdateChannel,
|
|
|
|
PLATFORM_VERSION: gApp.platformVersion,
|
|
|
|
DISTRIBUTION: getDistributionPrefValue(PREF_APP_DISTRIBUTION),
|
|
|
|
DISTRIBUTION_VERSION: getDistributionPrefValue(PREF_APP_DISTRIBUTION_VERSION),
|
|
|
|
PING_COUNT: pingCountVersion,
|
|
|
|
TOTAL_PING_COUNT: pingCountTotal,
|
|
|
|
DAYS_SINCE_LAST_PING: daysSinceLastPing,
|
|
|
|
};
|
|
|
|
dsURI = dsURI.replace(/%([A-Z_]+)%/g, function(fullMatch, name) {
|
|
|
|
// Not all applications implement nsIXULAppInfo (e.g. xpcshell doesn't).
|
|
|
|
if (gAppVersion && (name == "APP_VERSION" || name == "VERSION")) {
|
|
|
|
return gAppVersion;
|
|
|
|
}
|
|
|
|
// Some items, like DAYS_SINCE_LAST_PING, can be undefined, so we can't just
|
|
|
|
// `return replacements[name] || fullMatch` or something like that.
|
|
|
|
if (!replacements.hasOwnProperty(name)) {
|
|
|
|
return fullMatch;
|
|
|
|
}
|
|
|
|
return replacements[name];
|
|
|
|
});
|
2008-04-25 21:10:02 +04:00
|
|
|
dsURI = dsURI.replace(/\+/g, "%2B");
|
|
|
|
|
2011-01-15 00:29:27 +03:00
|
|
|
// Under normal operations it will take around 5,883,516 years before the
|
2011-02-24 14:20:02 +03:00
|
|
|
// preferences used to store pingCountVersion and pingCountTotal will rollover
|
2011-01-15 00:29:27 +03:00
|
|
|
// so this code doesn't bother trying to do the "right thing" here.
|
2011-02-24 14:20:02 +03: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;
|
|
|
|
}
|
2017-11-22 16:35:52 +03:00
|
|
|
Services.prefs.setIntPref(PREF_BLOCKLIST_PINGCOUNTVERSION, pingCountVersion);
|
2010-09-21 08:41:19 +04:00
|
|
|
}
|
|
|
|
|
2011-02-24 14:20:02 +03: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;
|
|
|
|
}
|
2017-11-22 16:35:52 +03:00
|
|
|
Services.prefs.setIntPref(PREF_BLOCKLIST_PINGCOUNTTOTAL, pingCountTotal);
|
2011-01-15 00:29:27 +03:00
|
|
|
}
|
|
|
|
|
2007-08-16 04:43:12 +04:00
|
|
|
// Verify that the URI is valid
|
|
|
|
try {
|
2017-11-22 16:35:52 +03:00
|
|
|
var uri = Services.io.newURI(dsURI);
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (e) {
|
2007-08-29 12:16:15 +04:00
|
|
|
LOG("Blocklist::notify: There was an error creating the blocklist URI\r\n" +
|
2007-08-16 04:43:12 +04:00
|
|
|
"for: " + dsURI + ", error: " + e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-05-19 22:04:44 +04:00
|
|
|
LOG("Blocklist::notify: Requesting " + uri.spec);
|
2019-01-04 01:40:22 +03:00
|
|
|
let request = new ServiceRequest({mozAnon: true});
|
2007-08-16 04:43:12 +04:00
|
|
|
request.open("GET", uri.spec, true);
|
2018-04-10 23:23:35 +03:00
|
|
|
request.channel.notificationCallbacks = new CertUtils.BadCertHandler();
|
2007-08-16 04:43:12 +04:00
|
|
|
request.overrideMimeType("text/xml");
|
2018-01-31 14:45:53 +03:00
|
|
|
|
|
|
|
// The server will return a `304 Not Modified` response if the blocklist was
|
|
|
|
// not changed since last check.
|
|
|
|
const lastModified = Services.prefs.getCharPref(PREF_BLOCKLIST_LAST_MODIFIED, "");
|
|
|
|
if (lastModified) {
|
|
|
|
request.setRequestHeader("If-Modified-Since", lastModified);
|
|
|
|
} else {
|
|
|
|
request.setRequestHeader("Cache-Control", "no-cache");
|
|
|
|
}
|
2007-08-16 04:43:12 +04:00
|
|
|
|
2017-01-17 13:50:25 +03:00
|
|
|
request.addEventListener("error", event => this.onXMLError(event));
|
|
|
|
request.addEventListener("load", event => this.onXMLLoad(event));
|
2007-08-16 04:43:12 +04:00
|
|
|
request.send(null);
|
|
|
|
},
|
|
|
|
|
2017-05-12 15:42:39 +03:00
|
|
|
async onXMLLoad(aEvent) {
|
2014-04-16 21:50:37 +04:00
|
|
|
let request = aEvent.target;
|
2007-08-16 04:43:12 +04:00
|
|
|
try {
|
2018-04-10 23:23:35 +03:00
|
|
|
CertUtils.checkCert(request.channel);
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (e) {
|
2007-08-16 04:43:12 +04:00
|
|
|
LOG("Blocklist::onXMLLoad: " + e);
|
|
|
|
return;
|
|
|
|
}
|
2018-01-31 14:45:53 +03:00
|
|
|
|
2018-02-21 19:37:47 +03:00
|
|
|
let {status} = request;
|
|
|
|
if (status == 304) {
|
2018-01-31 14:45:53 +03:00
|
|
|
LOG("Blocklist::onXMLLoad: up to date.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-02-21 19:37:47 +03:00
|
|
|
if (status != 200 && status != 0) {
|
|
|
|
LOG("Blocklist::onXMLLoad: there was an error during load, got status: " + status);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let {responseXML} = request;
|
|
|
|
if (!responseXML || responseXML.documentElement.namespaceURI == XMLURI_PARSE_ERROR) {
|
|
|
|
LOG("Blocklist::onXMLLoad: there was an error during load, we got invalid XML");
|
2007-08-16 04:43:12 +04:00
|
|
|
return;
|
|
|
|
}
|
2008-11-02 15:13:48 +03:00
|
|
|
|
2018-01-31 14:45:53 +03:00
|
|
|
// Save current blocklist timestamp to pref.
|
|
|
|
const lastModified = request.getResponseHeader("Last-Modified") || "";
|
|
|
|
Services.prefs.setCharPref(PREF_BLOCKLIST_LAST_MODIFIED, lastModified);
|
|
|
|
|
2018-06-13 21:51:45 +03:00
|
|
|
if (!this.isLoaded) {
|
|
|
|
await this.loadBlocklistAsync();
|
|
|
|
}
|
|
|
|
|
2008-11-02 15:13:48 +03:00
|
|
|
var oldAddonEntries = this._addonEntries;
|
|
|
|
var oldPluginEntries = this._pluginEntries;
|
|
|
|
|
2018-06-14 03:16:59 +03:00
|
|
|
await this._loadBlocklistFromXML(responseXML);
|
2016-05-04 17:12:19 +03:00
|
|
|
// We don't inform the users when the graphics blocklist changed at runtime.
|
|
|
|
// However addons and plugins blocking status is refreshed.
|
2008-11-02 15:13:48 +03:00
|
|
|
this._blocklistUpdated(oldAddonEntries, oldPluginEntries);
|
2014-04-16 21:50:37 +04:00
|
|
|
|
|
|
|
try {
|
|
|
|
let path = OS.Path.join(OS.Constants.Path.profileDir, FILE_BLOCKLIST);
|
2017-05-12 15:42:39 +03:00
|
|
|
await OS.File.writeAtomic(path, request.responseText, {tmpPath: path + ".tmp"});
|
2014-04-16 21:50:37 +04:00
|
|
|
} catch (e) {
|
|
|
|
LOG("Blocklist::onXMLLoad: " + e);
|
|
|
|
}
|
2017-05-12 15:42:39 +03:00
|
|
|
},
|
2007-08-16 04:43:12 +04:00
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
onXMLError(aEvent) {
|
2007-08-16 04:43:12 +04:00
|
|
|
try {
|
|
|
|
var request = aEvent.target;
|
|
|
|
// the following may throw (e.g. a local file or timeout)
|
|
|
|
var status = request.status;
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (e) {
|
2007-08-16 04:43:12 +04:00
|
|
|
request = aEvent.target.channel.QueryInterface(Ci.nsIRequest);
|
|
|
|
status = request.status;
|
|
|
|
}
|
2018-02-09 04:09:57 +03:00
|
|
|
var statusText = "XMLHttpRequest channel unavailable";
|
2007-08-16 04:43:12 +04:00
|
|
|
// When status is 0 we don't have a valid channel.
|
2011-02-16 16:14:16 +03:00
|
|
|
if (status != 0) {
|
|
|
|
try {
|
|
|
|
statusText = request.statusText;
|
|
|
|
} catch (e) {
|
|
|
|
}
|
|
|
|
}
|
2007-08-16 04:43:12 +04:00
|
|
|
LOG("Blocklist:onError: There was an error loading the blocklist file\r\n" +
|
|
|
|
statusText);
|
|
|
|
},
|
|
|
|
|
2018-04-20 02:01:24 +03:00
|
|
|
/**
|
|
|
|
* Whether or not we've finished loading the blocklist.
|
|
|
|
*/
|
2018-03-06 19:31:24 +03:00
|
|
|
get isLoaded() {
|
2016-05-04 17:12:19 +03:00
|
|
|
return this._addonEntries != null && this._gfxEntries != null && this._pluginEntries != null;
|
2014-05-15 17:14:00 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/* Used for testing */
|
2016-12-30 02:34:54 +03:00
|
|
|
_clear() {
|
2014-05-15 17:14:00 +04:00
|
|
|
this._addonEntries = null;
|
2016-05-04 17:12:19 +03:00
|
|
|
this._gfxEntries = null;
|
2014-05-15 17:14:00 +04:00
|
|
|
this._pluginEntries = null;
|
2018-06-14 03:16:59 +03:00
|
|
|
delete this._loadPromise;
|
2014-05-15 17:14:00 +04:00
|
|
|
},
|
|
|
|
|
2018-04-20 02:01:24 +03:00
|
|
|
/**
|
|
|
|
* Trigger loading the blocklist content asynchronously.
|
|
|
|
*/
|
2018-03-15 19:16:11 +03:00
|
|
|
async loadBlocklistAsync() {
|
2018-04-09 18:00:38 +03:00
|
|
|
if (this.isLoaded) {
|
|
|
|
return;
|
|
|
|
}
|
2018-06-14 03:16:59 +03:00
|
|
|
if (!this._loadPromise) {
|
|
|
|
this._loadPromise = this._loadBlocklistAsyncInternal();
|
2018-04-09 18:00:38 +03:00
|
|
|
}
|
2018-06-14 03:16:59 +03:00
|
|
|
await this._loadPromise;
|
2018-04-09 18:00:38 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
async _loadBlocklistAsyncInternal() {
|
2014-05-15 17:14:00 +04:00
|
|
|
try {
|
2018-04-23 19:11:34 +03:00
|
|
|
// Get the path inside the try...catch because there's no profileDir in e.g. xpcshell tests.
|
2018-06-13 21:51:45 +03:00
|
|
|
let profFile = FileUtils.getFile(KEY_PROFILEDIR, [FILE_BLOCKLIST]);
|
2018-06-14 03:16:59 +03:00
|
|
|
await this._loadFileInternal(profFile);
|
2014-05-15 17:14:00 +04:00
|
|
|
return;
|
|
|
|
} catch (e) {
|
2018-03-15 19:16:11 +03:00
|
|
|
LOG("Blocklist::loadBlocklistAsync: Failed to load XML file " + e);
|
2014-05-15 17:14:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
var appFile = FileUtils.getFile(KEY_APPDIR, [FILE_BLOCKLIST]);
|
2016-08-04 10:28:58 +03:00
|
|
|
try {
|
2018-06-14 03:16:59 +03:00
|
|
|
await this._loadFileInternal(appFile);
|
2014-05-15 17:14:00 +04:00
|
|
|
return;
|
|
|
|
} catch (e) {
|
2018-03-15 19:16:11 +03:00
|
|
|
LOG("Blocklist::loadBlocklistAsync: Failed to load XML file " + e);
|
2014-05-15 17:14:00 +04:00
|
|
|
}
|
|
|
|
|
2018-03-15 19:16:11 +03:00
|
|
|
LOG("Blocklist::loadBlocklistAsync: no XML File found");
|
2018-04-09 18:00:38 +03:00
|
|
|
// Neither file is present, so we just add empty lists, to avoid JS errors fetching
|
|
|
|
// blocklist information otherwise.
|
|
|
|
this._addonEntries = [];
|
|
|
|
this._gfxEntries = [];
|
|
|
|
this._pluginEntries = [];
|
2017-05-12 15:42:39 +03:00
|
|
|
},
|
2014-05-15 17:14:00 +04:00
|
|
|
|
2018-06-14 03:16:59 +03:00
|
|
|
async _loadFileInternal(file) {
|
2018-04-09 18:00:38 +03:00
|
|
|
if (this.isLoaded) {
|
2014-05-15 17:14:00 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gBlocklistEnabled) {
|
2018-06-14 03:16:59 +03:00
|
|
|
LOG("Blocklist::_loadFileInternal: blocklist is disabled");
|
2014-05-15 17:14:00 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-13 21:51:45 +03:00
|
|
|
let xmlDoc = await new Promise((resolve, reject) => {
|
|
|
|
let request = new XMLHttpRequest();
|
|
|
|
request.open("GET", Services.io.newFileURI(file).spec, true);
|
|
|
|
request.overrideMimeType("text/xml");
|
|
|
|
request.addEventListener("error", reject);
|
|
|
|
request.addEventListener("load", function() {
|
|
|
|
let {status} = request;
|
|
|
|
if (status != 200 && status != 0) {
|
2018-06-14 03:16:59 +03:00
|
|
|
LOG("_loadFileInternal: there was an error during load, got status: " + status);
|
2018-06-13 21:51:45 +03:00
|
|
|
reject(new Error("Couldn't load blocklist file"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let doc = request.responseXML;
|
|
|
|
if (doc.documentElement.namespaceURI != XMLURI_BLOCKLIST) {
|
|
|
|
LOG("Blocklist::_loadBlocklistFromString: aborting due to incorrect " +
|
|
|
|
"XML Namespace.\nExpected: " + XMLURI_BLOCKLIST + "\n" +
|
|
|
|
"Received: " + doc.documentElement.namespaceURI);
|
|
|
|
reject(new Error("Local blocklist file has the wrong namespace!"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
resolve(doc);
|
|
|
|
});
|
|
|
|
request.send(null);
|
|
|
|
});
|
2014-05-15 17:14:00 +04:00
|
|
|
|
2018-06-13 21:51:45 +03:00
|
|
|
await new Promise(resolve => {
|
2018-06-14 03:16:59 +03:00
|
|
|
ChromeUtils.idleDispatch(async () => {
|
Bug 1371888 - cache plugin information in pluginreg.dat to avoid sync startup load, r=florian,mossop
This changes the pluginreg.dat format to include the blocklist state.
There is now only the saved blocklist state in a plugin tag instance, rather than
looking it up from in there using the blocklist service, so it was renamed from
mCachedBlocklistState to mBlocklistState. We pass the 'right' state to the plugin
instance when the plugintag is constructed. If we don't have state, we mark it as
unblocked.
mCachedBlocklistStateChanged was never read so it's being removed.
Bug 1439519 adds a 'blocklist-loaded' notification that is fired once the blocklist is loaded.
The plugin host implementation will listen to this in the parent process and update the
blocklist state of all the plugins, and broadcast changes to the child process, just like when
we update the blocklist from the server. We now also avoid re-sending plugin content to the
content processes if the plugin state hasn't changed as a result of the blocklist having been
loaded.
Finally, because new plugins should still get an up-to-date blocklist state, and
telemetry should get up-to-date data about which plugins are and aren't enabled
once we have that data, we ensure that once we've loaded the blocklist async,
we schedule an idle task to parse it and consider it loaded.
All this means that plugin blocklist information could be mistaken between the points where
a new plugin is installed and we first run Firefox with the new plugin, and the point where
we load the blocklist. Given the trade-offs, that size of window (tiny) seems OK, also given
that there's already a much larger window in blocklist updates (which only happen once every 24h).
MozReview-Commit-ID: 1gsojRkUzTw
--HG--
extra : rebase_source : 4709916b4674ada54f8a495fd2d16fcef8c58d20
2018-02-20 19:53:48 +03:00
|
|
|
if (!this.isLoaded) {
|
2018-06-14 03:16:59 +03:00
|
|
|
await this._loadBlocklistFromXML(xmlDoc);
|
Bug 1371888 - cache plugin information in pluginreg.dat to avoid sync startup load, r=florian,mossop
This changes the pluginreg.dat format to include the blocklist state.
There is now only the saved blocklist state in a plugin tag instance, rather than
looking it up from in there using the blocklist service, so it was renamed from
mCachedBlocklistState to mBlocklistState. We pass the 'right' state to the plugin
instance when the plugintag is constructed. If we don't have state, we mark it as
unblocked.
mCachedBlocklistStateChanged was never read so it's being removed.
Bug 1439519 adds a 'blocklist-loaded' notification that is fired once the blocklist is loaded.
The plugin host implementation will listen to this in the parent process and update the
blocklist state of all the plugins, and broadcast changes to the child process, just like when
we update the blocklist from the server. We now also avoid re-sending plugin content to the
content processes if the plugin state hasn't changed as a result of the blocklist having been
loaded.
Finally, because new plugins should still get an up-to-date blocklist state, and
telemetry should get up-to-date data about which plugins are and aren't enabled
once we have that data, we ensure that once we've loaded the blocklist async,
we schedule an idle task to parse it and consider it loaded.
All this means that plugin blocklist information could be mistaken between the points where
a new plugin is installed and we first run Firefox with the new plugin, and the point where
we load the blocklist. Given the trade-offs, that size of window (tiny) seems OK, also given
that there's already a much larger window in blocklist updates (which only happen once every 24h).
MozReview-Commit-ID: 1gsojRkUzTw
--HG--
extra : rebase_source : 4709916b4674ada54f8a495fd2d16fcef8c58d20
2018-02-20 19:53:48 +03:00
|
|
|
}
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
});
|
2017-05-12 15:42:39 +03:00
|
|
|
},
|
2014-05-15 17:14:00 +04:00
|
|
|
|
2018-06-14 03:16:59 +03:00
|
|
|
async _loadBlocklistFromXML(doc) {
|
Bug 1371888 - cache plugin information in pluginreg.dat to avoid sync startup load, r=florian,mossop
This changes the pluginreg.dat format to include the blocklist state.
There is now only the saved blocklist state in a plugin tag instance, rather than
looking it up from in there using the blocklist service, so it was renamed from
mCachedBlocklistState to mBlocklistState. We pass the 'right' state to the plugin
instance when the plugintag is constructed. If we don't have state, we mark it as
unblocked.
mCachedBlocklistStateChanged was never read so it's being removed.
Bug 1439519 adds a 'blocklist-loaded' notification that is fired once the blocklist is loaded.
The plugin host implementation will listen to this in the parent process and update the
blocklist state of all the plugins, and broadcast changes to the child process, just like when
we update the blocklist from the server. We now also avoid re-sending plugin content to the
content processes if the plugin state hasn't changed as a result of the blocklist having been
loaded.
Finally, because new plugins should still get an up-to-date blocklist state, and
telemetry should get up-to-date data about which plugins are and aren't enabled
once we have that data, we ensure that once we've loaded the blocklist async,
we schedule an idle task to parse it and consider it loaded.
All this means that plugin blocklist information could be mistaken between the points where
a new plugin is installed and we first run Firefox with the new plugin, and the point where
we load the blocklist. Given the trade-offs, that size of window (tiny) seems OK, also given
that there's already a much larger window in blocklist updates (which only happen once every 24h).
MozReview-Commit-ID: 1gsojRkUzTw
--HG--
extra : rebase_source : 4709916b4674ada54f8a495fd2d16fcef8c58d20
2018-02-20 19:53:48 +03:00
|
|
|
this._addonEntries = [];
|
|
|
|
this._gfxEntries = [];
|
|
|
|
this._pluginEntries = [];
|
2018-02-21 19:37:47 +03:00
|
|
|
try {
|
2018-06-13 21:53:33 +03:00
|
|
|
var children = doc.documentElement.children;
|
|
|
|
for (let element of children) {
|
2010-12-21 01:01:12 +03:00
|
|
|
switch (element.localName) {
|
|
|
|
case "emItems":
|
2018-06-14 03:16:59 +03:00
|
|
|
this._addonEntries = await this._processItemNodes(element.children, "emItem",
|
|
|
|
this._handleEmItemNode);
|
2010-12-21 01:01:12 +03:00
|
|
|
break;
|
|
|
|
case "pluginItems":
|
2018-06-14 03:16:59 +03:00
|
|
|
this._pluginEntries = await this._processItemNodes(element.children, "pluginItem",
|
|
|
|
this._handlePluginItemNode);
|
2010-12-21 01:01:12 +03:00
|
|
|
break;
|
2016-05-04 17:12:19 +03:00
|
|
|
case "gfxItems":
|
|
|
|
// Parse as simple list of objects.
|
2018-06-14 03:16:59 +03:00
|
|
|
this._gfxEntries = await this._processItemNodes(element.children, "gfxBlacklistEntry",
|
|
|
|
this._handleGfxBlacklistNode);
|
2016-05-04 17:12:19 +03:00
|
|
|
break;
|
2010-12-21 01:01:12 +03:00
|
|
|
default:
|
2018-02-21 19:37:47 +03:00
|
|
|
LOG("Blocklist::_loadBlocklistFromXML: ignored entries " + element.localName);
|
2010-12-21 01:01:12 +03:00
|
|
|
}
|
|
|
|
}
|
2016-05-04 17:12:19 +03:00
|
|
|
if (this._gfxEntries.length > 0) {
|
|
|
|
this._notifyObserversBlocklistGFX();
|
|
|
|
}
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (e) {
|
2018-02-21 19:37:47 +03:00
|
|
|
LOG("Blocklist::_loadBlocklistFromXML: Error constructing blocklist " + e);
|
2007-08-16 04:43:12 +04:00
|
|
|
}
|
2018-03-06 19:31:24 +03:00
|
|
|
// Dispatch to mainthread because consumers may try to construct nsIPluginHost
|
|
|
|
// again based on this notification, while we were called from nsIPluginHost
|
|
|
|
// anyway, leading to re-entrancy.
|
|
|
|
Services.tm.dispatchToMainThread(function() {
|
|
|
|
Services.obs.notifyObservers(null, "blocklist-loaded");
|
|
|
|
});
|
2007-08-16 04:43:12 +04:00
|
|
|
},
|
|
|
|
|
2018-06-14 03:16:59 +03:00
|
|
|
async _processItemNodes(items, itemName, handler) {
|
2007-08-16 04:43:12 +04:00
|
|
|
var result = [];
|
2018-06-14 03:16:59 +03:00
|
|
|
let deadline = await new Promise(ChromeUtils.idleDispatch);
|
2018-06-13 21:53:33 +03:00
|
|
|
for (let item of items) {
|
|
|
|
if (item.localName == itemName) {
|
|
|
|
handler(item, result);
|
|
|
|
}
|
2018-06-14 03:16:59 +03:00
|
|
|
if (!deadline || deadline.didTimeout || deadline.timeRemaining() < 1) {
|
|
|
|
deadline = await new Promise(ChromeUtils.idleDispatch);
|
|
|
|
}
|
2007-08-16 04:43:12 +04:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
_handleEmItemNode(blocklistElement, result) {
|
2007-11-07 11:56:29 +03:00
|
|
|
if (!matchesOSABI(blocklistElement))
|
|
|
|
return;
|
|
|
|
|
2012-11-27 07:40:00 +04:00
|
|
|
let blockEntry = {
|
|
|
|
versions: [],
|
2013-09-14 21:27:09 +04:00
|
|
|
prefs: [],
|
2014-01-06 12:46:32 +04:00
|
|
|
blockID: null,
|
2018-06-14 03:06:49 +03:00
|
|
|
attributes: {},
|
2014-01-06 12:46:32 +04:00
|
|
|
// Atleast one of EXTENSION_BLOCK_FILTERS must get added to attributes
|
2012-11-27 07:40:00 +04:00
|
|
|
};
|
|
|
|
|
2014-01-06 12:46:32 +04:00
|
|
|
for (let filter of EXTENSION_BLOCK_FILTERS) {
|
|
|
|
let attr = blocklistElement.getAttribute(filter);
|
2018-06-14 03:06:49 +03:00
|
|
|
if (attr) {
|
|
|
|
// Any filter starting with '/' is interpreted as a regex. So if an attribute
|
|
|
|
// starts with a '/' it must be checked via a regex.
|
|
|
|
if (attr.startsWith("/")) {
|
|
|
|
let lastSlash = attr.lastIndexOf("/");
|
|
|
|
let pattern = attr.slice(1, lastSlash);
|
|
|
|
let flags = attr.slice(lastSlash + 1);
|
|
|
|
blockEntry.attributes[filter] = new RegExp(pattern, flags);
|
|
|
|
} else {
|
|
|
|
blockEntry.attributes[filter] = attr;
|
|
|
|
}
|
|
|
|
}
|
2014-01-06 12:46:32 +04:00
|
|
|
}
|
|
|
|
|
2018-06-13 21:53:33 +03:00
|
|
|
var children = blocklistElement.children;
|
2012-11-27 07:40:00 +04:00
|
|
|
|
2018-06-13 21:53:33 +03:00
|
|
|
for (let childElement of children) {
|
2018-06-14 03:06:49 +03:00
|
|
|
let localName = childElement.localName;
|
|
|
|
if (localName == "prefs" && childElement.hasChildNodes) {
|
2018-06-13 21:53:33 +03:00
|
|
|
let prefElements = childElement.children;
|
|
|
|
for (let prefElement of prefElements) {
|
|
|
|
if (prefElement.localName == "pref") {
|
|
|
|
blockEntry.prefs.push(prefElement.textContent);
|
|
|
|
}
|
2013-09-14 21:27:09 +04:00
|
|
|
}
|
2018-06-14 03:06:49 +03:00
|
|
|
} else if (localName == "versionRange") {
|
2013-09-14 21:27:09 +04:00
|
|
|
blockEntry.versions.push(new BlocklistItemData(childElement));
|
2018-06-13 21:53:33 +03:00
|
|
|
}
|
2007-08-16 04:43:12 +04:00
|
|
|
}
|
|
|
|
// if only the extension ID is specified block all versions of the
|
|
|
|
// extension for the current application.
|
2012-11-27 07:40:00 +04:00
|
|
|
if (blockEntry.versions.length == 0)
|
|
|
|
blockEntry.versions.push(new BlocklistItemData(null));
|
|
|
|
|
|
|
|
blockEntry.blockID = blocklistElement.getAttribute("blockID");
|
2011-05-26 01:31:56 +04:00
|
|
|
|
2012-11-27 07:40:00 +04:00
|
|
|
result.push(blockEntry);
|
2007-08-16 04:43:12 +04:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
_handlePluginItemNode(blocklistElement, result) {
|
2007-11-07 11:56:29 +03:00
|
|
|
if (!matchesOSABI(blocklistElement))
|
|
|
|
return;
|
|
|
|
|
2018-06-13 21:53:33 +03:00
|
|
|
let children = blocklistElement.children;
|
2008-09-02 15:53:34 +04:00
|
|
|
var blockEntry = {
|
|
|
|
matches: {},
|
2011-05-26 01:31:56 +04:00
|
|
|
versions: [],
|
|
|
|
blockID: null,
|
2014-10-15 17:23:22 +04:00
|
|
|
infoURL: null,
|
2008-09-02 15:53:34 +04:00
|
|
|
};
|
2009-08-21 19:52:57 +04:00
|
|
|
var hasMatch = false;
|
2018-06-13 21:53:33 +03:00
|
|
|
for (let childElement of children) {
|
2018-06-14 03:06:49 +03:00
|
|
|
switch (childElement.localName) {
|
|
|
|
case "match":
|
|
|
|
var name = childElement.getAttribute("name");
|
|
|
|
var exp = childElement.getAttribute("exp");
|
|
|
|
try {
|
|
|
|
blockEntry.matches[name] = new RegExp(exp, "m");
|
|
|
|
hasMatch = true;
|
|
|
|
} catch (e) {
|
|
|
|
// Ignore invalid regular expressions
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "versionRange":
|
|
|
|
blockEntry.versions.push(new BlocklistItemData(childElement));
|
|
|
|
break;
|
|
|
|
case "infoURL":
|
|
|
|
blockEntry.infoURL = childElement.textContent;
|
|
|
|
break;
|
2014-10-15 17:23:22 +04:00
|
|
|
}
|
2007-08-16 04:43:12 +04:00
|
|
|
}
|
2009-08-21 19:52:57 +04:00
|
|
|
// Plugin entries require *something* to match to an actual plugin
|
|
|
|
if (!hasMatch)
|
|
|
|
return;
|
2008-11-02 15:13:48 +03:00
|
|
|
// Add a default versionRange if there wasn't one specified
|
|
|
|
if (blockEntry.versions.length == 0)
|
|
|
|
blockEntry.versions.push(new BlocklistItemData(null));
|
2011-05-26 01:31:56 +04:00
|
|
|
|
|
|
|
blockEntry.blockID = blocklistElement.getAttribute("blockID");
|
|
|
|
|
2008-09-02 15:53:34 +04:00
|
|
|
result.push(blockEntry);
|
2007-08-16 04:43:12 +04:00
|
|
|
},
|
|
|
|
|
2016-05-04 17:12:19 +03:00
|
|
|
// <gfxBlacklistEntry blockID="g60">
|
|
|
|
// <os>WINNT 6.0</os>
|
|
|
|
// <osversion>14</osversion> currently only used for Android
|
|
|
|
// <versionRange minVersion="42.0" maxVersion="13.0b2"/>
|
|
|
|
// <vendor>0x8086</vendor>
|
|
|
|
// <devices>
|
|
|
|
// <device>0x2582</device>
|
|
|
|
// <device>0x2782</device>
|
|
|
|
// </devices>
|
|
|
|
// <feature> DIRECT3D_10_LAYERS </feature>
|
|
|
|
// <featureStatus> BLOCKED_DRIVER_VERSION </featureStatus>
|
|
|
|
// <driverVersion> 8.52.322.2202 </driverVersion>
|
|
|
|
// <driverVersionMax> 8.52.322.2202 </driverVersionMax>
|
|
|
|
// <driverVersionComparator> LESS_THAN_OR_EQUAL </driverVersionComparator>
|
|
|
|
// <model>foo</model>
|
|
|
|
// <product>foo</product>
|
|
|
|
// <manufacturer>foo</manufacturer>
|
|
|
|
// <hardware>foo</hardware>
|
|
|
|
// </gfxBlacklistEntry>
|
2016-12-30 02:34:54 +03:00
|
|
|
_handleGfxBlacklistNode(blocklistElement, result) {
|
2016-05-04 17:12:19 +03:00
|
|
|
const blockEntry = {};
|
|
|
|
|
|
|
|
// The blockID attribute is always present in the actual data produced on server
|
|
|
|
// (see https://github.com/mozilla/addons-server/blob/2016.05.05/src/olympia/blocklist/templates/blocklist/blocklist.xml#L74)
|
|
|
|
// But it is sometimes missing in test fixtures.
|
|
|
|
if (blocklistElement.hasAttribute("blockID")) {
|
|
|
|
blockEntry.blockID = blocklistElement.getAttribute("blockID");
|
|
|
|
}
|
|
|
|
|
2018-06-13 21:53:33 +03:00
|
|
|
for (let matchElement of blocklistElement.children) {
|
2016-05-04 17:12:19 +03:00
|
|
|
let value;
|
|
|
|
if (matchElement.localName == "devices") {
|
|
|
|
value = [];
|
2018-06-13 21:53:33 +03:00
|
|
|
for (let childElement of matchElement.children) {
|
2018-06-14 01:39:05 +03:00
|
|
|
const childValue = (childElement.textContent || "").trim();
|
2016-05-04 17:12:19 +03:00
|
|
|
// Make sure no empty value is added.
|
|
|
|
if (childValue) {
|
|
|
|
if (/,/.test(childValue)) {
|
|
|
|
// Devices can't contain comma.
|
|
|
|
// (c.f serialization in _notifyObserversBlocklistGFX)
|
|
|
|
const e = new Error(`Unsupported device name ${childValue}`);
|
2018-02-28 20:51:33 +03:00
|
|
|
Cu.reportError(e);
|
2016-12-31 05:47:25 +03:00
|
|
|
} else {
|
2016-05-04 17:12:19 +03:00
|
|
|
value.push(childValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (matchElement.localName == "versionRange") {
|
2018-06-14 01:39:05 +03:00
|
|
|
value = {minVersion: (matchElement.getAttribute("minVersion") || "").trim() || "0",
|
|
|
|
maxVersion: (matchElement.getAttribute("maxVersion") || "").trim() || "*"};
|
2016-05-04 17:12:19 +03:00
|
|
|
} else {
|
2018-06-14 01:39:05 +03:00
|
|
|
value = (matchElement.textContent || "").trim();
|
2016-05-04 17:12:19 +03:00
|
|
|
}
|
|
|
|
if (value) {
|
|
|
|
blockEntry[matchElement.localName] = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result.push(blockEntry);
|
|
|
|
},
|
|
|
|
|
2008-11-02 15:13:48 +03:00
|
|
|
/* See nsIBlocklistService */
|
2018-04-23 19:11:34 +03:00
|
|
|
async getPluginBlocklistState(plugin, appVersion, toolkitVersion) {
|
2017-08-09 00:41:07 +03:00
|
|
|
if (AppConstants.platform == "android") {
|
2015-10-29 17:32:50 +03:00
|
|
|
return Ci.nsIBlocklistService.STATE_NOT_BLOCKED;
|
|
|
|
}
|
2018-04-23 19:11:34 +03:00
|
|
|
await this.loadBlocklistAsync();
|
2016-08-04 01:54:59 +03:00
|
|
|
return this._getPluginBlocklistState(plugin, this._pluginEntries,
|
|
|
|
appVersion, toolkitVersion);
|
2008-11-02 15:13:48 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-02-19 21:07:59 +03:00
|
|
|
* Private helper to get the blocklist entry for a plugin given a set of
|
|
|
|
* blocklist entries and versions.
|
2008-11-02 15:13:48 +03:00
|
|
|
*
|
2018-04-20 02:01:24 +03:00
|
|
|
* @param {nsIPluginTag} plugin
|
|
|
|
* The nsIPluginTag to get the blocklist state for.
|
|
|
|
* @param {object[]} pluginEntries
|
|
|
|
* The plugin blocklist entries to compare against.
|
|
|
|
* @param {string?} appVersion
|
|
|
|
* The application version to compare to, will use the current
|
|
|
|
* version if null.
|
|
|
|
* @param {string?} toolkitVersion
|
|
|
|
* The toolkit version to compare to, will use the current version if
|
|
|
|
* null.
|
|
|
|
* @returns {object?}
|
|
|
|
* {entry: blocklistEntry, version: blocklistEntryVersion},
|
|
|
|
* or null if there is no matching entry.
|
2008-11-02 15:13:48 +03:00
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
_getPluginBlocklistEntry(plugin, pluginEntries, appVersion, toolkitVersion) {
|
2008-11-02 15:13:48 +03:00
|
|
|
if (!gBlocklistEnabled)
|
2015-02-19 21:07:59 +03:00
|
|
|
return null;
|
2008-11-02 15:13:48 +03:00
|
|
|
|
2015-02-25 01:11:33 +03:00
|
|
|
// Not all applications implement nsIXULAppInfo (e.g. xpcshell doesn't).
|
2018-06-14 03:06:49 +03:00
|
|
|
if (!appVersion && !gAppVersion)
|
2015-02-25 01:11:33 +03:00
|
|
|
return Ci.nsIBlocklistService.STATE_NOT_BLOCKED;
|
|
|
|
|
2008-11-02 15:13:48 +03:00
|
|
|
if (!appVersion)
|
2018-06-14 03:06:49 +03:00
|
|
|
appVersion = gAppVersion;
|
2008-11-02 15:13:48 +03:00
|
|
|
if (!toolkitVersion)
|
|
|
|
toolkitVersion = gApp.platformVersion;
|
|
|
|
|
2018-01-29 01:10:11 +03:00
|
|
|
const pluginProperties = {
|
|
|
|
description: plugin.description,
|
|
|
|
filename: plugin.filename,
|
|
|
|
name: plugin.name,
|
|
|
|
version: plugin.version,
|
|
|
|
};
|
2015-10-18 22:57:14 +03:00
|
|
|
for (var blockEntry of pluginEntries) {
|
2007-08-16 04:43:12 +04:00
|
|
|
var matchFailed = false;
|
2008-09-02 15:53:34 +04:00
|
|
|
for (var name in blockEntry.matches) {
|
2018-01-29 01:10:11 +03:00
|
|
|
let pluginProperty = pluginProperties[name];
|
|
|
|
if (typeof(pluginProperty) !== "string" ||
|
|
|
|
!blockEntry.matches[name].test(pluginProperty)) {
|
2007-08-16 04:43:12 +04:00
|
|
|
matchFailed = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-02 15:53:34 +04:00
|
|
|
if (matchFailed)
|
|
|
|
continue;
|
|
|
|
|
2012-05-27 16:21:48 +04:00
|
|
|
for (let blockEntryVersion of blockEntry.versions) {
|
2018-01-29 01:10:11 +03:00
|
|
|
if (blockEntryVersion.includesItem(pluginProperties.version, appVersion,
|
2015-02-19 21:07:59 +03:00
|
|
|
toolkitVersion)) {
|
|
|
|
return {entry: blockEntry, version: blockEntryVersion};
|
2009-10-02 15:26:04 +04:00
|
|
|
}
|
2007-08-16 04:43:12 +04:00
|
|
|
}
|
|
|
|
}
|
2008-09-02 15:53:34 +04:00
|
|
|
|
2015-02-19 21:07:59 +03:00
|
|
|
return null;
|
2007-08-16 04:43:12 +04:00
|
|
|
},
|
|
|
|
|
2014-10-15 17:23:22 +04:00
|
|
|
/**
|
2015-02-19 21:07:59 +03:00
|
|
|
* Private version of getPluginBlocklistState that allows the caller to pass in
|
|
|
|
* the plugin blocklist entries.
|
|
|
|
*
|
2018-04-20 02:01:24 +03:00
|
|
|
* @param {nsIPluginTag} plugin
|
|
|
|
* The nsIPluginTag to get the blocklist state for.
|
|
|
|
* @param {object[]} pluginEntries
|
|
|
|
* The plugin blocklist entries to compare against.
|
|
|
|
* @param {string?} appVersion
|
|
|
|
* The application version to compare to, will use the current
|
|
|
|
* version if null.
|
|
|
|
* @param {string?} toolkitVersion
|
|
|
|
* The toolkit version to compare to, will use the current version if
|
|
|
|
* null.
|
|
|
|
* @returns {integer}
|
|
|
|
* The blocklist state for the item, one of the STATE constants as
|
|
|
|
* defined in nsIBlocklistService.
|
2014-10-15 17:23:22 +04:00
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
_getPluginBlocklistState(plugin, pluginEntries, appVersion, toolkitVersion) {
|
2015-02-19 21:07:59 +03:00
|
|
|
let r = this._getPluginBlocklistEntry(plugin, pluginEntries,
|
|
|
|
appVersion, toolkitVersion);
|
|
|
|
if (!r) {
|
|
|
|
return Ci.nsIBlocklistService.STATE_NOT_BLOCKED;
|
2014-10-15 17:23:22 +04:00
|
|
|
}
|
2011-05-26 01:31:56 +04:00
|
|
|
|
2016-11-17 00:01:16 +03:00
|
|
|
let {version: blockEntryVersion} = r;
|
2015-02-19 21:07:59 +03:00
|
|
|
|
|
|
|
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 17:23:22 +04:00
|
|
|
},
|
|
|
|
|
2018-04-27 17:56:46 +03:00
|
|
|
async getPluginBlockURL(plugin) {
|
|
|
|
await this.loadBlocklistAsync();
|
2015-02-19 21:07:59 +03:00
|
|
|
|
|
|
|
let r = this._getPluginBlocklistEntry(plugin, this._pluginEntries);
|
|
|
|
if (!r) {
|
|
|
|
return null;
|
|
|
|
}
|
2018-04-27 17:56:46 +03:00
|
|
|
let blockEntry = r.entry;
|
2015-02-19 21:07:59 +03:00
|
|
|
if (!blockEntry.blockID) {
|
2014-10-15 17:23:22 +04:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-04-27 17:56:46 +03:00
|
|
|
return blockEntry.infoURL || this._createBlocklistURL(blockEntry.blockID);
|
2011-05-26 01:31:56 +04:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
_notifyObserversBlocklistGFX() {
|
2018-06-14 01:39:05 +03:00
|
|
|
let sortedProps = [
|
|
|
|
"blockID", "devices", "driverVersion", "driverVersionComparator", "driverVersionMax",
|
|
|
|
"feature", "featureStatus", "hardware", "manufacturer", "model", "os", "osversion",
|
|
|
|
"product", "vendor", "versionRange",
|
|
|
|
];
|
2016-05-04 17:12:19 +03:00
|
|
|
// Notify `GfxInfoBase`, by passing a string serialization.
|
|
|
|
// This way we avoid spreading XML structure logics there.
|
2018-06-14 01:39:05 +03:00
|
|
|
let payload = [];
|
|
|
|
for (let gfxEntry of this._gfxEntries) {
|
|
|
|
let entryLines = [];
|
|
|
|
for (let key of sortedProps) {
|
|
|
|
if (gfxEntry[key]) {
|
|
|
|
let value = gfxEntry[key];
|
|
|
|
if (Array.isArray(value)) {
|
|
|
|
value = value.join(",");
|
|
|
|
} else if (value.maxVersion) {
|
|
|
|
// When XML is parsed, both minVersion and maxVersion are set.
|
|
|
|
value = value.minVersion + "," + value.maxVersion;
|
|
|
|
}
|
|
|
|
entryLines.push(key + ":" + value);
|
2016-05-04 17:12:19 +03:00
|
|
|
}
|
2018-06-14 01:39:05 +03:00
|
|
|
}
|
|
|
|
payload.push(entryLines.join("\t"));
|
|
|
|
}
|
|
|
|
Services.obs.notifyObservers(null, "blocklist-data-gfxItems", payload.join("\n"));
|
2016-05-04 17:12:19 +03:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
_notifyObserversBlocklistUpdated() {
|
2017-04-14 22:51:39 +03:00
|
|
|
Services.obs.notifyObservers(this, "blocklist-updated");
|
2015-05-01 18:07:18 +03:00
|
|
|
},
|
|
|
|
|
2018-04-09 18:00:38 +03:00
|
|
|
async _blocklistUpdated(oldAddonEntries, oldPluginEntries) {
|
2008-11-02 15:13:48 +03:00
|
|
|
var addonList = [];
|
|
|
|
|
2013-09-14 21:27:09 +04:00
|
|
|
// A helper function that reverts the prefs passed to default values.
|
|
|
|
function resetPrefs(prefs) {
|
|
|
|
for (let pref of prefs)
|
2017-11-22 16:35:52 +03:00
|
|
|
Services.prefs.clearUserPref(pref);
|
2013-09-14 21:27:09 +04:00
|
|
|
}
|
|
|
|
const types = ["extension", "theme", "locale", "dictionary", "service"];
|
2018-04-09 18:00:38 +03:00
|
|
|
let addons = await AddonManager.getAddonsByTypes(types);
|
|
|
|
for (let addon of addons) {
|
|
|
|
let oldState = addon.blocklistState;
|
|
|
|
if (addon.updateBlocklistState) {
|
|
|
|
await addon.updateBlocklistState(false);
|
|
|
|
} else if (oldAddonEntries) {
|
|
|
|
oldState = this._getAddonBlocklistState(addon, oldAddonEntries);
|
|
|
|
} else {
|
2018-04-23 19:11:34 +03:00
|
|
|
oldState = Ci.nsIBlocklistService.STATE_NOT_BLOCKED;
|
2018-04-09 18:00:38 +03:00
|
|
|
}
|
|
|
|
let state = addon.blocklistState;
|
2013-09-14 21:27:09 +04:00
|
|
|
|
2018-04-09 18:00:38 +03:00
|
|
|
LOG("Blocklist state for " + addon.id + " changed from " +
|
|
|
|
oldState + " to " + state);
|
2011-05-19 22:04:44 +04:00
|
|
|
|
2018-04-09 18:00:38 +03:00
|
|
|
// We don't want to re-warn about add-ons
|
|
|
|
if (state == oldState)
|
|
|
|
continue;
|
2011-05-19 22:04:44 +04:00
|
|
|
|
2018-04-09 18:00:38 +03:00
|
|
|
if (state === Ci.nsIBlocklistService.STATE_BLOCKED) {
|
|
|
|
// It's a hard block. We must reset certain preferences.
|
|
|
|
let prefs = this._getAddonPrefs(addon);
|
|
|
|
resetPrefs(prefs);
|
|
|
|
}
|
2008-11-02 15:13:48 +03:00
|
|
|
|
2018-04-09 18:00:38 +03:00
|
|
|
// Ensure that softDisabled is false if the add-on is not soft blocked
|
|
|
|
if (state != Ci.nsIBlocklistService.STATE_SOFTBLOCKED)
|
|
|
|
addon.softDisabled = false;
|
2010-04-26 22:45:22 +04:00
|
|
|
|
2018-04-09 18:00:38 +03:00
|
|
|
// Don't warn about add-ons becoming unblocked.
|
|
|
|
if (state == Ci.nsIBlocklistService.STATE_NOT_BLOCKED)
|
|
|
|
continue;
|
2018-04-09 18:00:38 +03:00
|
|
|
|
2018-04-09 18:00:38 +03:00
|
|
|
// If an add-on has dropped from hard to soft blocked just mark it as
|
|
|
|
// soft disabled and don't warn about it.
|
|
|
|
if (state == Ci.nsIBlocklistService.STATE_SOFTBLOCKED &&
|
|
|
|
oldState == Ci.nsIBlocklistService.STATE_BLOCKED) {
|
|
|
|
addon.softDisabled = true;
|
|
|
|
continue;
|
|
|
|
}
|
2018-04-15 13:12:56 +03:00
|
|
|
|
2018-04-09 18:00:38 +03:00
|
|
|
// If the add-on is already disabled for some reason then don't warn
|
|
|
|
// about it
|
|
|
|
if (!addon.isActive) {
|
|
|
|
// But mark it as softblocked if necessary. Note that we avoid setting
|
|
|
|
// softDisabled at the same time as userDisabled to make it clear
|
|
|
|
// which was the original cause of the add-on becoming disabled in a
|
|
|
|
// way that the user can change.
|
|
|
|
if (state == Ci.nsIBlocklistService.STATE_SOFTBLOCKED && !addon.userDisabled)
|
|
|
|
addon.softDisabled = true;
|
|
|
|
continue;
|
2008-11-02 15:13:48 +03:00
|
|
|
}
|
|
|
|
|
2018-04-09 18:00:38 +03:00
|
|
|
let entry = this._getAddonBlocklistEntry(addon, this._addonEntries);
|
|
|
|
addonList.push({
|
|
|
|
name: addon.name,
|
|
|
|
version: addon.version,
|
|
|
|
icon: addon.iconURL,
|
|
|
|
disable: false,
|
|
|
|
blocked: state == Ci.nsIBlocklistService.STATE_BLOCKED,
|
|
|
|
item: addon,
|
|
|
|
url: entry && entry.url,
|
|
|
|
});
|
|
|
|
}
|
2010-05-01 22:04:44 +04:00
|
|
|
|
2018-04-09 18:00:38 +03:00
|
|
|
AddonManagerPrivate.updateAddonAppDisabledStates();
|
|
|
|
|
|
|
|
var phs = Cc["@mozilla.org/plugin/host;1"].
|
|
|
|
getService(Ci.nsIPluginHost);
|
|
|
|
var plugins = phs.getPluginTags();
|
|
|
|
|
|
|
|
for (let plugin of plugins) {
|
|
|
|
let oldState = -1;
|
|
|
|
if (oldPluginEntries)
|
|
|
|
oldState = this._getPluginBlocklistState(plugin, oldPluginEntries);
|
2018-04-23 19:11:34 +03:00
|
|
|
let state = this._getPluginBlocklistState(plugin, this._pluginEntries);
|
2018-04-09 18:00:38 +03:00
|
|
|
LOG("Blocklist state for " + plugin.name + " changed from " +
|
|
|
|
oldState + " to " + state);
|
|
|
|
// We don't want to re-warn about items
|
|
|
|
if (state == oldState)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (oldState == Ci.nsIBlocklistService.STATE_BLOCKED) {
|
|
|
|
if (state == Ci.nsIBlocklistService.STATE_SOFTBLOCKED)
|
|
|
|
plugin.enabledState = Ci.nsIPluginTag.STATE_DISABLED;
|
|
|
|
} else if (!plugin.disabled && state != Ci.nsIBlocklistService.STATE_NOT_BLOCKED) {
|
|
|
|
if (state != Ci.nsIBlocklistService.STATE_OUTDATED &&
|
|
|
|
state != Ci.nsIBlocklistService.STATE_VULNERABLE_UPDATE_AVAILABLE &&
|
|
|
|
state != Ci.nsIBlocklistService.STATE_VULNERABLE_NO_UPDATE) {
|
|
|
|
addonList.push({
|
|
|
|
name: plugin.name,
|
|
|
|
version: plugin.version,
|
2018-11-22 08:49:22 +03:00
|
|
|
icon: "chrome://global/skin/plugins/pluginGeneric.svg",
|
2018-04-09 18:00:38 +03:00
|
|
|
disable: false,
|
|
|
|
blocked: state == Ci.nsIBlocklistService.STATE_BLOCKED,
|
|
|
|
item: plugin,
|
2018-04-27 17:56:46 +03:00
|
|
|
url: await this.getPluginBlockURL(plugin),
|
2018-04-09 18:00:38 +03:00
|
|
|
});
|
2018-04-15 13:12:56 +03:00
|
|
|
}
|
2010-09-02 05:35:06 +04:00
|
|
|
}
|
2018-04-09 18:00:38 +03:00
|
|
|
}
|
2010-09-02 05:35:06 +04:00
|
|
|
|
2018-04-09 18:00:38 +03:00
|
|
|
if (addonList.length == 0) {
|
|
|
|
this._notifyObserversBlocklistUpdated();
|
|
|
|
return;
|
|
|
|
}
|
2011-05-26 01:31:56 +04:00
|
|
|
|
2018-04-09 18:00:38 +03:00
|
|
|
if ("@mozilla.org/addons/blocklist-prompt;1" in Cc) {
|
|
|
|
try {
|
|
|
|
let blockedPrompter = Cc["@mozilla.org/addons/blocklist-prompt;1"]
|
2018-04-20 02:01:24 +03:00
|
|
|
.getService().wrappedJSObject;
|
2018-04-09 18:00:38 +03:00
|
|
|
blockedPrompter.prompt(addonList);
|
|
|
|
} catch (e) {
|
|
|
|
LOG(e);
|
2018-04-09 18:00:38 +03:00
|
|
|
}
|
2018-04-09 18:00:38 +03:00
|
|
|
this._notifyObserversBlocklistUpdated();
|
|
|
|
return;
|
|
|
|
}
|
2010-04-26 22:45:22 +04:00
|
|
|
|
2018-04-09 18:00:38 +03:00
|
|
|
var args = {
|
|
|
|
restart: false,
|
2018-08-31 08:59:17 +03:00
|
|
|
list: addonList,
|
2018-04-09 18:00:38 +03:00
|
|
|
};
|
|
|
|
// This lets the dialog get the raw js object
|
|
|
|
args.wrappedJSObject = args;
|
|
|
|
|
|
|
|
/*
|
|
|
|
Some tests run without UI, so the async code listens to a message
|
|
|
|
that can be sent programatically
|
|
|
|
*/
|
|
|
|
let applyBlocklistChanges = () => {
|
|
|
|
for (let addon of addonList) {
|
|
|
|
if (!addon.disable)
|
|
|
|
continue;
|
2010-04-26 22:45:22 +04:00
|
|
|
|
2018-04-09 18:00:38 +03:00
|
|
|
if (addon.item instanceof Ci.nsIPluginTag)
|
|
|
|
addon.item.enabledState = Ci.nsIPluginTag.STATE_DISABLED;
|
|
|
|
else {
|
|
|
|
// This add-on is softblocked.
|
|
|
|
addon.item.softDisabled = true;
|
|
|
|
// We must revert certain prefs.
|
|
|
|
let prefs = this._getAddonPrefs(addon.item);
|
|
|
|
resetPrefs(prefs);
|
2018-04-15 13:12:56 +03:00
|
|
|
}
|
2018-04-09 18:00:38 +03:00
|
|
|
}
|
2008-11-02 15:13:48 +03:00
|
|
|
|
2018-04-09 18:00:38 +03:00
|
|
|
if (args.restart)
|
|
|
|
restartApp();
|
2013-06-11 18:58:42 +04:00
|
|
|
|
2018-04-09 18:00:38 +03:00
|
|
|
this._notifyObserversBlocklistUpdated();
|
|
|
|
Services.obs.removeObserver(applyBlocklistChanges, "addon-blocklist-closed");
|
|
|
|
};
|
2011-05-19 22:04:44 +04:00
|
|
|
|
2018-04-09 18:00:38 +03:00
|
|
|
Services.obs.addObserver(applyBlocklistChanges, "addon-blocklist-closed");
|
2018-04-15 13:12:56 +03:00
|
|
|
|
2018-04-09 18:00:38 +03:00
|
|
|
if (Services.prefs.getBoolPref(PREF_BLOCKLIST_SUPPRESSUI, false)) {
|
|
|
|
applyBlocklistChanges();
|
|
|
|
return;
|
|
|
|
}
|
2011-07-20 00:16:35 +04:00
|
|
|
|
2018-04-09 18:00:38 +03:00
|
|
|
function blocklistUnloadHandler(event) {
|
|
|
|
if (event.target.location == URI_BLOCKLIST_DIALOG) {
|
|
|
|
applyBlocklistChanges();
|
|
|
|
blocklistWindow.removeEventListener("unload", blocklistUnloadHandler);
|
2018-04-15 13:12:56 +03:00
|
|
|
}
|
2018-04-09 18:00:38 +03:00
|
|
|
}
|
2018-04-15 13:12:56 +03:00
|
|
|
|
2018-04-09 18:00:38 +03:00
|
|
|
let blocklistWindow = Services.ww.openWindow(null, URI_BLOCKLIST_DIALOG, "",
|
|
|
|
"chrome,centerscreen,dialog,titlebar", args);
|
|
|
|
if (blocklistWindow)
|
|
|
|
blocklistWindow.addEventListener("unload", blocklistUnloadHandler);
|
2007-08-16 04:43:12 +04:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2018-04-20 02:01:24 +03:00
|
|
|
/*
|
2007-08-16 04:43:12 +04:00
|
|
|
* Helper for constructing a blocklist.
|
|
|
|
*/
|
|
|
|
function BlocklistItemData(versionRangeElement) {
|
2018-06-14 03:06:49 +03:00
|
|
|
this.targetApps = {};
|
|
|
|
let foundTarget = false;
|
|
|
|
this.severity = DEFAULT_SEVERITY;
|
|
|
|
this.vulnerabilityStatus = VULNERABILITYSTATUS_NONE;
|
2007-08-16 04:43:12 +04:00
|
|
|
if (versionRangeElement) {
|
2018-06-14 03:06:49 +03:00
|
|
|
let versionRange = this.getBlocklistVersionRange(versionRangeElement);
|
|
|
|
this.minVersion = versionRange.minVersion;
|
|
|
|
this.maxVersion = versionRange.maxVersion;
|
|
|
|
if (versionRangeElement.hasAttribute("severity"))
|
|
|
|
this.severity = versionRangeElement.getAttribute("severity");
|
|
|
|
if (versionRangeElement.hasAttribute("vulnerabilitystatus")) {
|
|
|
|
this.vulnerabilityStatus = versionRangeElement.getAttribute("vulnerabilitystatus");
|
|
|
|
}
|
2018-06-13 21:53:33 +03:00
|
|
|
for (let targetAppElement of versionRangeElement.children) {
|
2018-06-14 03:06:49 +03:00
|
|
|
if (targetAppElement.localName == "targetApplication") {
|
|
|
|
foundTarget = true;
|
|
|
|
// default to the current application if id is not provided.
|
|
|
|
let appID = targetAppElement.id || gAppID;
|
|
|
|
this.targetApps[appID] = this.getBlocklistAppVersions(targetAppElement);
|
|
|
|
}
|
2007-08-16 04:43:12 +04:00
|
|
|
}
|
2018-06-14 03:06:49 +03:00
|
|
|
} else {
|
|
|
|
this.minVersion = this.maxVersion = null;
|
2007-08-16 04:43:12 +04:00
|
|
|
}
|
2018-06-14 03:06:49 +03:00
|
|
|
|
2008-09-02 15:53:34 +04:00
|
|
|
// Default to all versions of the current application when no targetApplication
|
|
|
|
// elements were found
|
2018-06-14 03:06:49 +03:00
|
|
|
if (!foundTarget)
|
|
|
|
this.targetApps[gAppID] = [{minVersion: null, maxVersion: null}];
|
2007-08-16 04:43:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BlocklistItemData.prototype = {
|
2008-09-02 15:53:34 +04: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.
|
2018-04-20 02:01:24 +03:00
|
|
|
* @param {string} version
|
|
|
|
* The version of the item being tested.
|
|
|
|
* @param {string} appVersion
|
|
|
|
* The application version to test with.
|
|
|
|
* @param {string} toolkitVersion
|
|
|
|
* The toolkit version to test with.
|
|
|
|
* @returns {boolean}
|
|
|
|
* True if the version range covers the item version and application
|
|
|
|
* or toolkit version.
|
2008-09-02 15:53:34 +04:00
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
includesItem(version, appVersion, toolkitVersion) {
|
2008-09-02 15:53:34 +04: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
|
2018-06-14 03:06:49 +03:00
|
|
|
if (this.matchesTargetRange(gAppID, appVersion))
|
2008-09-02 15:53:34 +04:00
|
|
|
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).
|
2018-04-20 02:01:24 +03:00
|
|
|
* @param {string} version
|
|
|
|
* The version to test.
|
|
|
|
* @param {string?} minVersion
|
|
|
|
* The minimum version. If null it is assumed that version is always
|
|
|
|
* larger.
|
|
|
|
* @param {string?} maxVersion
|
|
|
|
* The maximum version. If null it is assumed that version is always
|
|
|
|
* smaller.
|
|
|
|
* @returns {boolean}
|
|
|
|
* Whether the item matches the range.
|
2008-09-02 15:53:34 +04:00
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
matchesRange(version, minVersion, maxVersion) {
|
2018-02-21 19:37:47 +03:00
|
|
|
if (minVersion && Services.vc.compare(version, minVersion) < 0)
|
2008-09-02 15:53:34 +04:00
|
|
|
return false;
|
2018-02-21 19:37:47 +03:00
|
|
|
if (maxVersion && Services.vc.compare(version, maxVersion) > 0)
|
2008-09-02 15:53:34 +04:00
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests if there is a matching range for the given target application id and
|
|
|
|
* version.
|
2018-04-20 02:01:24 +03:00
|
|
|
* @param {string} appID
|
|
|
|
* The application ID to test for, may be for an application or toolkit
|
|
|
|
* @param {string} appVersion
|
|
|
|
* The version of the application to test for.
|
|
|
|
* @returns {boolean}
|
|
|
|
* True if this version range covers the application version given.
|
2008-09-02 15:53:34 +04:00
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
matchesTargetRange(appID, appVersion) {
|
2008-09-02 15:53:34 +04:00
|
|
|
var blTargetApp = this.targetApps[appID];
|
|
|
|
if (!blTargetApp)
|
|
|
|
return false;
|
|
|
|
|
2012-05-27 16:21:48 +04:00
|
|
|
for (let app of blTargetApp) {
|
|
|
|
if (this.matchesRange(appVersion, app.minVersion, app.maxVersion))
|
2008-09-02 15:53:34 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves a version range (e.g. minVersion and maxVersion) for a
|
|
|
|
* blocklist item's targetApplication element.
|
2018-04-20 02:01:24 +03:00
|
|
|
* @param {Element} targetAppElement
|
|
|
|
* A targetApplication blocklist element.
|
|
|
|
* @returns {object[]}
|
|
|
|
* An array of JS objects with the following properties:
|
2008-09-02 15:53:34 +04:00
|
|
|
* "minVersion" The minimum version in a version range (default = null).
|
|
|
|
* "maxVersion" The maximum version in a version range (default = null).
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
getBlocklistAppVersions(targetAppElement) {
|
2007-08-16 04:43:12 +04:00
|
|
|
var appVersions = [ ];
|
|
|
|
|
|
|
|
if (targetAppElement) {
|
2018-06-13 21:53:33 +03:00
|
|
|
for (let versionRangeElement of targetAppElement.children) {
|
|
|
|
if (versionRangeElement.localName == "versionRange") {
|
|
|
|
appVersions.push(this.getBlocklistVersionRange(versionRangeElement));
|
|
|
|
}
|
2007-08-16 04:43:12 +04:00
|
|
|
}
|
|
|
|
}
|
2008-09-02 15:53:34 +04:00
|
|
|
// return minVersion = null and maxVersion = null if no specific versionRange
|
|
|
|
// elements were found
|
|
|
|
if (appVersions.length == 0)
|
2018-06-14 03:06:49 +03:00
|
|
|
appVersions.push({minVersion: null, maxVersion: null});
|
2007-08-16 04:43:12 +04:00
|
|
|
return appVersions;
|
|
|
|
},
|
|
|
|
|
2008-09-02 15:53:34 +04:00
|
|
|
/**
|
|
|
|
* Retrieves a version range (e.g. minVersion and maxVersion) for a blocklist
|
|
|
|
* versionRange element.
|
2018-04-20 02:01:24 +03:00
|
|
|
*
|
|
|
|
* @param {Element} versionRangeElement
|
|
|
|
* The versionRange blocklist element.
|
|
|
|
*
|
|
|
|
* @returns {Object}
|
|
|
|
* A JS object with the following properties:
|
2008-09-02 15:53:34 +04:00
|
|
|
* "minVersion" The minimum version in a version range (default = null).
|
|
|
|
* "maxVersion" The maximum version in a version range (default = null).
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
getBlocklistVersionRange(versionRangeElement) {
|
2018-06-14 03:06:49 +03:00
|
|
|
// getAttribute returns null if the attribute is not present.
|
|
|
|
let minVersion = versionRangeElement.getAttribute("minVersion");
|
|
|
|
let maxVersion = versionRangeElement.getAttribute("maxVersion");
|
2007-08-16 04:43:12 +04:00
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
return { minVersion, maxVersion };
|
2018-08-31 08:59:17 +03:00
|
|
|
},
|
2007-08-16 04:43:12 +04:00
|
|
|
};
|
|
|
|
|
2018-04-25 03:46:44 +03:00
|
|
|
Blocklist._init();
|