зеркало из https://github.com/mozilla/pjs.git
Bug 430120: Update blocklist URL to include same info as update URL. r=robstrong, a=beltzner
This commit is contained in:
Родитель
48120474d0
Коммит
fe528d2528
|
@ -80,7 +80,7 @@ pref("extensions.getAddons.search.url", "https://services.addons.mozilla.org/%LO
|
|||
// Blocklist preferences
|
||||
pref("extensions.blocklist.enabled", true);
|
||||
pref("extensions.blocklist.interval", 86400);
|
||||
pref("extensions.blocklist.url", "https://addons.mozilla.org/blocklist/1/%APP_ID%/%APP_VERSION%/");
|
||||
pref("extensions.blocklist.url", "https://addons.mozilla.org/blocklist/2/%APP_ID%/%APP_VERSION%/%PRODUCT%/%BUILD_ID%/%BUILD_TARGET%/%LOCALE%/%CHANNEL%/%OS_VERSION%/%DISTRIBUTION%/%DISTRIBUTION_VERSION%/");
|
||||
pref("extensions.blocklist.detailsURL", "http://%LOCALE%.www.mozilla.com/%LOCALE%/blocklist/");
|
||||
|
||||
// Dictionary download preference
|
||||
|
|
|
@ -52,9 +52,15 @@ const FILE_BLOCKLIST = "blocklist.xml";
|
|||
const PREF_BLOCKLIST_URL = "extensions.blocklist.url";
|
||||
const PREF_BLOCKLIST_ENABLED = "extensions.blocklist.enabled";
|
||||
const PREF_BLOCKLIST_INTERVAL = "extensions.blocklist.interval";
|
||||
const PREF_GENERAL_USERAGENT_LOCALE = "general.useragent.locale";
|
||||
const PREF_PARTNER_BRANCH = "app.partner.";
|
||||
const PREF_APP_DISTRIBUTION = "distribution.id";
|
||||
const PREF_APP_DISTRIBUTION_VERSION = "distribution.version";
|
||||
const PREF_APP_UPDATE_CHANNEL = "app.update.channel";
|
||||
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"
|
||||
const UNKNOWN_XPCOM_ABI = "unknownABI";
|
||||
|
||||
const MODE_RDONLY = 0x01;
|
||||
const MODE_WRONLY = 0x02;
|
||||
|
@ -71,6 +77,8 @@ var gOS = null;
|
|||
var gConsole = null;
|
||||
var gVersionChecker = null;
|
||||
var gLoggingEnabled = null;
|
||||
var gABI = null;
|
||||
var gOSVersion = null;
|
||||
|
||||
// shared code for suppressing bad cert dialogs
|
||||
#include ../../shared/src/badCertHandler.js
|
||||
|
@ -200,6 +208,77 @@ function matchesOSABI(blocklistElement) {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
||||
.getService(Components.interfaces.nsIPrefService);
|
||||
var defaultPrefs = prefs.getDefaultBranch(null);
|
||||
return defaultPrefs.getCharPref(PREF_GENERAL_USERAGENT_LOCALE);
|
||||
} catch (e) {}
|
||||
|
||||
return gPref.getCharPref(PREF_GENERAL_USERAGENT_LOCALE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the update channel from defaults only. We do this to ensure that
|
||||
* the channel is tightly coupled with the application and does not apply
|
||||
* to other installations of the application that may use the same profile.
|
||||
*/
|
||||
function getUpdateChannel() {
|
||||
var channel = "default";
|
||||
var prefName;
|
||||
var prefValue;
|
||||
|
||||
var defaults =
|
||||
gPref.QueryInterface(Components.interfaces.nsIPrefService).
|
||||
getDefaultBranch(null);
|
||||
try {
|
||||
channel = defaults.getCharPref(PREF_APP_UPDATE_CHANNEL);
|
||||
} catch (e) {
|
||||
// use default when pref not found
|
||||
}
|
||||
|
||||
try {
|
||||
var partners = gPref.getChildList(PREF_PARTNER_BRANCH, { });
|
||||
if (partners.length) {
|
||||
channel += "-cck";
|
||||
partners.sort();
|
||||
|
||||
for each (prefName in partners) {
|
||||
prefValue = gPref.getCharPref(prefName);
|
||||
channel += "-" + prefValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
Components.utils.reportError(e);
|
||||
}
|
||||
|
||||
return channel;
|
||||
}
|
||||
|
||||
/* Get the distribution pref values, from defaults only */
|
||||
function getDistributionPrefValue(aPrefName) {
|
||||
var prefValue = "default";
|
||||
|
||||
var defaults =
|
||||
gPref.QueryInterface(Components.interfaces.nsIPrefService).
|
||||
getDefaultBranch(null);
|
||||
try {
|
||||
prefValue = defaults.getCharPref(aPrefName);
|
||||
} catch (e) {
|
||||
// use default when pref not found
|
||||
}
|
||||
|
||||
return prefValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Manages the Blocklist. The Blocklist is a representation of the contents of
|
||||
* blocklist.xml and allows us to remotely disable / re-enable blocklisted
|
||||
|
@ -220,6 +299,45 @@ function Blocklist() {
|
|||
gOS = Cc["@mozilla.org/observer-service;1"].
|
||||
getService(Ci.nsIObserverService);
|
||||
gOS.addObserver(this, "xpcom-shutdown", false);
|
||||
|
||||
// Not all builds have a known ABI
|
||||
try {
|
||||
gABI = gApp.XPCOMABI;
|
||||
}
|
||||
catch (e) {
|
||||
LOG("Blocklist: XPCOM ABI unknown.");
|
||||
gABI = UNKNOWN_XPCOM_ABI;
|
||||
}
|
||||
|
||||
var osVersion;
|
||||
var sysInfo = Components.classes["@mozilla.org/system-info;1"]
|
||||
.getService(Components.interfaces.nsIPropertyBag2);
|
||||
try {
|
||||
osVersion = sysInfo.getProperty("name") + " " + sysInfo.getProperty("version");
|
||||
}
|
||||
catch (e) {
|
||||
LOG("Blocklist: 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.
|
||||
}
|
||||
gOSVersion = encodeURIComponent(osVersion);
|
||||
}
|
||||
|
||||
#ifdef XP_MACOSX
|
||||
// Mac universal build should report a different ABI than either macppc
|
||||
// or mactel.
|
||||
var macutils = Components.classes["@mozilla.org/xpcom/mac-utils;1"]
|
||||
.getService(Components.interfaces.nsIMacUtils);
|
||||
|
||||
if (macutils.isUniversalBinary)
|
||||
gABI = "Universal-gcc3";
|
||||
#endif
|
||||
}
|
||||
|
||||
Blocklist.prototype = {
|
||||
|
@ -329,6 +447,20 @@ Blocklist.prototype = {
|
|||
|
||||
dsURI = dsURI.replace(/%APP_ID%/g, gApp.ID);
|
||||
dsURI = dsURI.replace(/%APP_VERSION%/g, gApp.version);
|
||||
dsURI = dsURI.replace(/%PRODUCT%/g, gApp.name);
|
||||
dsURI = dsURI.replace(/%VERSION%/g, gApp.version);
|
||||
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());
|
||||
dsURI = dsURI.replace(/%CHANNEL%/g, getUpdateChannel());
|
||||
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));
|
||||
dsURI = dsURI.replace(/\+/g, "%2B");
|
||||
|
||||
// Verify that the URI is valid
|
||||
try {
|
||||
var uri = newURI(dsURI);
|
||||
|
|
|
@ -0,0 +1,158 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Dave Townsend <dtownsend@oxymoronical.com>.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 2008
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL
|
||||
*
|
||||
* ***** END LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
const BLOCKLIST_TIMER = "blocklist-background-update-timer";
|
||||
const PREF_BLOCKLIST_URL = "extensions.blocklist.url";
|
||||
const PREF_BLOCKLIST_ENABLED = "extensions.blocklist.enabled";
|
||||
const PREF_APP_DISTRIBUTION = "distribution.id";
|
||||
const PREF_APP_DISTRIBUTION_VERSION = "distribution.version";
|
||||
const PREF_APP_UPDATE_CHANNEL = "app.update.channel";
|
||||
const PREF_GENERAL_USERAGENT_LOCALE = "general.useragent.locale";
|
||||
|
||||
// Get the HTTP server.
|
||||
do_import_script("netwerk/test/httpserver/httpd.js");
|
||||
var testserver;
|
||||
var gOSVersion;
|
||||
|
||||
// This is a replacement for the timer service so we can trigger timers
|
||||
var timerService = {
|
||||
|
||||
timers: {},
|
||||
|
||||
registerTimer: function(id, callback, interval) {
|
||||
this.timers[id] = callback;
|
||||
},
|
||||
|
||||
hasTimer: function(id) {
|
||||
return id in this.timers;
|
||||
},
|
||||
|
||||
fireTimer: function(id) {
|
||||
this.timers[id].notify(null);
|
||||
},
|
||||
|
||||
QueryInterface: function(iid) {
|
||||
if (iid.equals(Components.interfaces.nsIUpdateTimerManager)
|
||||
|| iid.equals(Components.interfaces.nsISupports))
|
||||
return this;
|
||||
|
||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
};
|
||||
|
||||
var TimerServiceFactory = {
|
||||
createInstance: function (outer, iid) {
|
||||
if (outer != null)
|
||||
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
||||
return timerService.QueryInterface(iid);
|
||||
}
|
||||
};
|
||||
var registrar = Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar);
|
||||
registrar.registerFactory(Components.ID("{61189e7a-6b1b-44b8-ac81-f180a6105085}"), "TimerService",
|
||||
"@mozilla.org/updates/timer-manager;1", TimerServiceFactory);
|
||||
|
||||
function failHandler(metadata, response) {
|
||||
do_throw("Should not have attempted to retrieve the blocklist when it is disabled");
|
||||
}
|
||||
|
||||
function pathHandler(metadata, response) {
|
||||
do_check_eq(metadata.queryString,
|
||||
"xpcshell@tests.mozilla.org&1&XPCShell&1&2007010101&" +
|
||||
"XPCShell_noarch-spidermonkey&locale&updatechannel&" +
|
||||
gOSVersion + "&1.9&distribution&distribution-version");
|
||||
do_test_finished();
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
var osVersion;
|
||||
var sysInfo = Components.classes["@mozilla.org/system-info;1"]
|
||||
.getService(Components.interfaces.nsIPropertyBag2);
|
||||
try {
|
||||
osVersion = sysInfo.getProperty("name") + " " + sysInfo.getProperty("version");
|
||||
if (osVersion) {
|
||||
try {
|
||||
osVersion += " (" + sysInfo.getProperty("secondaryLibrary") + ")";
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
gOSVersion = encodeURIComponent(osVersion);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
|
||||
|
||||
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
|
||||
|
||||
testserver = new nsHttpServer();
|
||||
testserver.registerPathHandler("/1", failHandler);
|
||||
testserver.registerPathHandler("/2", pathHandler);
|
||||
testserver.start(4444);
|
||||
|
||||
// Initialise the blocklist service
|
||||
var blocklist = Components.classes["@mozilla.org/extensions/blocklist;1"]
|
||||
.getService(Components.interfaces.nsIBlocklistService)
|
||||
.QueryInterface(Components.interfaces.nsIObserver);
|
||||
blocklist.observe(null, "app-startup", "");
|
||||
blocklist.observe(null, "profile-after-change", "");
|
||||
|
||||
do_check_true(timerService.hasTimer(BLOCKLIST_TIMER));
|
||||
|
||||
do_test_pending();
|
||||
|
||||
// This should have no effect as the blocklist is disabled
|
||||
gPrefs.setCharPref(PREF_BLOCKLIST_URL, "http://localhost:4444/1");
|
||||
gPrefs.setBoolPref(PREF_BLOCKLIST_ENABLED, false);
|
||||
timerService.fireTimer(BLOCKLIST_TIMER);
|
||||
|
||||
// Some values have to be on the default branch to work
|
||||
var defaults = gPrefs.QueryInterface(Components.interfaces.nsIPrefService)
|
||||
.getDefaultBranch(null);
|
||||
defaults.setCharPref(PREF_APP_UPDATE_CHANNEL, "updatechannel");
|
||||
defaults.setCharPref(PREF_APP_DISTRIBUTION, "distribution");
|
||||
defaults.setCharPref(PREF_APP_DISTRIBUTION_VERSION, "distribution-version");
|
||||
defaults.setCharPref(PREF_GENERAL_USERAGENT_LOCALE, "locale");
|
||||
|
||||
// This should correctly escape everything
|
||||
gPrefs.setCharPref(PREF_BLOCKLIST_URL, "http://localhost:4444/2?" +
|
||||
"%APP_ID%&%APP_VERSION%&%PRODUCT%&%VERSION%&%BUILD_ID%&" +
|
||||
"%BUILD_TARGET%&%LOCALE%&%CHANNEL%&" +
|
||||
"%OS_VERSION%&%PLATFORM_VERSION%&%DISTRIBUTION%&%DISTRIBUTION_VERSION%");
|
||||
gPrefs.setBoolPref(PREF_BLOCKLIST_ENABLED, true);
|
||||
timerService.fireTimer(BLOCKLIST_TIMER);
|
||||
}
|
Загрузка…
Ссылка в новой задаче