зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1445990 - fix initialization of blocklist service in non-browser apps, r=florian
MozReview-Commit-ID: GK4SA8gJ8Pf --HG-- extra : rebase_source : ad3ff814d634e885da37e16801d701fd79f78ea3
This commit is contained in:
Родитель
f629d09118
Коммит
4fe837deef
|
@ -1212,6 +1212,10 @@ BrowserGlue.prototype = {
|
|||
Services.tm.idleDispatchToMainThread(() => {
|
||||
LanguagePrompt.init();
|
||||
});
|
||||
|
||||
Services.tm.idleDispatchToMainThread(() => {
|
||||
Services.blocklist.loadBlocklistAsync();
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
component {66354bc9-7ed1-4692-ae1d-8da97d6b205e} nsBlocklistService.js process=main
|
||||
contract @mozilla.org/extensions/blocklist;1 {66354bc9-7ed1-4692-ae1d-8da97d6b205e} process=main
|
||||
category profile-after-change nsBlocklistService @mozilla.org/extensions/blocklist;1 process=main
|
||||
#ifndef MOZ_BUILD_APP_IS_BROWSER
|
||||
category profile-after-change nsBlocklistService @mozilla.org/extensions/blocklist;1 process=main
|
||||
#endif
|
||||
|
||||
category update-timer nsBlocklistService @mozilla.org/extensions/blocklist;1,getService,blocklist-background-update-timer,extensions.blocklist.interval,86400
|
||||
component {4399533d-08d1-458c-a87a-235f74451cfa} addonManager.js
|
||||
|
|
|
@ -9,6 +9,9 @@ SPHINX_TREES['addon-manager'] = 'docs'
|
|||
with Files('docs/**'):
|
||||
SCHEDULES.exclusive = ['docs']
|
||||
|
||||
if CONFIG['MOZ_BUILD_APP'] == 'browser':
|
||||
DEFINES['MOZ_BUILD_APP_IS_BROWSER'] = True
|
||||
|
||||
if CONFIG['MOZ_BUILD_APP'] == 'mobile/android':
|
||||
DEFINES['MOZ_FENNEC'] = True
|
||||
|
||||
|
|
|
@ -221,7 +221,6 @@ function parseRegExp(aStr) {
|
|||
|
||||
function Blocklist() {
|
||||
Services.obs.addObserver(this, "xpcom-shutdown");
|
||||
Services.obs.addObserver(this, "sessionstore-windows-restored");
|
||||
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),
|
||||
|
@ -229,8 +228,6 @@ function Blocklist() {
|
|||
Services.prefs.addObserver("extensions.blocklist.", this);
|
||||
Services.prefs.addObserver(PREF_EM_LOGGING_ENABLED, this);
|
||||
this.wrappedJSObject = this;
|
||||
// requests from child processes come in here, see receiveMessage.
|
||||
Services.ppmm.addMessageListener("Blocklist:content-blocklist-updated", this);
|
||||
}
|
||||
|
||||
Blocklist.prototype = {
|
||||
|
@ -255,7 +252,6 @@ Blocklist.prototype = {
|
|||
|
||||
shutdown() {
|
||||
Services.obs.removeObserver(this, "xpcom-shutdown");
|
||||
Services.ppmm.removeMessageListener("Blocklist:content-blocklist-updated", this);
|
||||
Services.prefs.removeObserver("extensions.blocklist.", this);
|
||||
Services.prefs.removeObserver(PREF_EM_LOGGING_ENABLED, this);
|
||||
},
|
||||
|
@ -265,6 +261,12 @@ Blocklist.prototype = {
|
|||
case "xpcom-shutdown":
|
||||
this.shutdown();
|
||||
break;
|
||||
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;
|
||||
case "nsPref:changed":
|
||||
switch (aData) {
|
||||
case PREF_EM_LOGGING_ENABLED:
|
||||
|
@ -282,25 +284,9 @@ Blocklist.prototype = {
|
|||
break;
|
||||
}
|
||||
break;
|
||||
case "sessionstore-windows-restored":
|
||||
Services.obs.removeObserver(this, "sessionstore-windows-restored");
|
||||
this._preloadBlocklist();
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
// Message manager message handlers
|
||||
receiveMessage(aMsg) {
|
||||
switch (aMsg.name) {
|
||||
case "Blocklist:content-blocklist-updated":
|
||||
Services.obs.notifyObservers(null, "content-blocklist-updated");
|
||||
break;
|
||||
default:
|
||||
throw new Error("Unknown blocklist message received from content: " + aMsg.name);
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
|
||||
/* See nsIBlocklistService */
|
||||
isAddonBlocklisted(addon, appVersion, toolkitVersion) {
|
||||
return this.getAddonBlocklistState(addon, appVersion, toolkitVersion) ==
|
||||
|
@ -797,13 +783,13 @@ Blocklist.prototype = {
|
|||
this._pluginEntries = null;
|
||||
},
|
||||
|
||||
async _preloadBlocklist() {
|
||||
async loadBlocklistAsync() {
|
||||
let profPath = OS.Path.join(OS.Constants.Path.profileDir, FILE_BLOCKLIST);
|
||||
try {
|
||||
await this._preloadBlocklistFile(profPath);
|
||||
return;
|
||||
} catch (e) {
|
||||
LOG("Blocklist::_preloadBlocklist: Failed to load XML file " + e);
|
||||
LOG("Blocklist::loadBlocklistAsync: Failed to load XML file " + e);
|
||||
}
|
||||
|
||||
var appFile = FileUtils.getFile(KEY_APPDIR, [FILE_BLOCKLIST]);
|
||||
|
@ -811,10 +797,10 @@ Blocklist.prototype = {
|
|||
await this._preloadBlocklistFile(appFile.path);
|
||||
return;
|
||||
} catch (e) {
|
||||
LOG("Blocklist::_preloadBlocklist: Failed to load XML file " + e);
|
||||
LOG("Blocklist::loadBlocklistAsync: Failed to load XML file " + e);
|
||||
}
|
||||
|
||||
LOG("Blocklist::_preloadBlocklist: no XML File found");
|
||||
LOG("Blocklist::loadBlocklistAsync: no XML File found");
|
||||
},
|
||||
|
||||
async _preloadBlocklistFile(path) {
|
||||
|
|
|
@ -14,7 +14,7 @@ add_task(async function() {
|
|||
scope.OS.File.read = () => triedToRead = true;
|
||||
blocklist._loadBlocklist();
|
||||
Assert.ok(blocklist.isLoaded);
|
||||
await blocklist._preloadBlocklist();
|
||||
await blocklist.loadBlocklistAsync();
|
||||
Assert.ok(!triedToRead);
|
||||
scope.OS.File.read = read;
|
||||
blocklist._clear();
|
||||
|
@ -22,7 +22,7 @@ add_task(async function() {
|
|||
info("sync -> async complete");
|
||||
|
||||
// async first. Check that once we preload the content, that is sufficient.
|
||||
await blocklist._preloadBlocklist();
|
||||
await blocklist.loadBlocklistAsync();
|
||||
Assert.ok(blocklist.isLoaded);
|
||||
// Calling _loadBlocklist now would just re-load the list sync.
|
||||
|
||||
|
@ -40,7 +40,7 @@ add_task(async function() {
|
|||
});
|
||||
};
|
||||
|
||||
await blocklist._preloadBlocklist();
|
||||
await blocklist.loadBlocklistAsync();
|
||||
// We're mostly just checking this doesn't error out.
|
||||
Assert.ok(blocklist.isLoaded);
|
||||
info("mixed async/sync test complete");
|
||||
|
|
|
@ -133,6 +133,11 @@ interface nsIBlocklistService : nsISupports
|
|||
* Whether or not we've finished loading the blocklist.
|
||||
*/
|
||||
readonly attribute boolean isLoaded;
|
||||
|
||||
/**
|
||||
* Trigger loading the blocklist content asynchronously.
|
||||
*/
|
||||
void loadBlocklistAsync();
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Загрузка…
Ссылка в новой задаче