Bug 1257565 - Remove coupling betweeen XML and Gfx
MozReview-Commit-ID: 4JDiU1ej9rR
--- a/toolkit/mozapps/extensions/nsBlocklistService.js
+++ b/toolkit/mozapps/extensions/nsBlocklistService.js
@@ -660,16 +660,17 @@ Blocklist.prototype = {
}
var oldAddonEntries = this._addonEntries;
var oldPluginEntries = this._pluginEntries;
this._loadBlocklistFromXMLString(request.responseText);
// We don't inform the users when the graphics blocklist changed at runtime.
// However addons and plugins blocking status is refreshed.
+ this._notifyObserversBlocklistGFX();
this._blocklistUpdated(oldAddonEntries, oldPluginEntries);
try {
let path = OS.Path.join(OS.Constants.Path.profileDir, FILE_BLOCKLIST);
yield OS.File.writeAtomic(path, request.responseText, {tmpPath: path + ".tmp"});
} catch (e) {
LOG("Blocklist::onXMLLoad: " + e);
}
@@ -703,16 +704,17 @@ Blocklist.prototype = {
*/
_loadBlocklist: function() {
if (!gBlocklistEnabled) {
LOG("Blocklist::_loadBlocklistFromFile: blocklist is disabled");
return;
}
const content = this._loadBlocklistFromFile(FILE_BLOCKLIST);
this._loadBlocklistFromXMLString(content);
+ this._notifyObserversBlocklistGFX();
},
_loadBlocklistFromFile: function(filename) {
let file = FileUtils.getFile(KEY_PROFILEDIR, [filename]);
if (!file.exists()) {
let appFile = FileUtils.getFile(KEY_APPDIR, [filename]);
if (appFile.exists()) {
file = appFile;
@@ -764,17 +766,19 @@ Blocklist.prototype = {
if (fstream)
fstream.close();
}
return text;
},
_isBlocklistLoaded: function() {
- return this._addonEntries != null && this._pluginEntries != null;
+ return (this._addonEntries != null &&
+ this._gfxEntries != null &&
+ this._pluginEntries != null);
},
/* Used for testing */
_clear: function() {
this._addonEntries = null;
this._gfxEntries = null;
this._pluginEntries = null;
this._preloadedBlocklistContent = {};
@@ -938,19 +942,16 @@ Blocklist.prototype = {
break;
default:
LOG("Blocklist::_loadBlocklistFromXMLString: ignored entries " + element.localName);
}
}
if (populateCertBlocklist) {
gCertBlocklistService.saveEntries();
}
- if (this._gfxEntries.length > 0) {
- this._notifyObserversBlocklistGFX();
- }
}
catch (e) {
LOG("Blocklist::_loadBlocklistFromXMLString: Error constructing blocklist " + e);
return;
}
},
_processItemNodes: function(itemNodes, itemName, handler) {
@@ -1298,16 +1299,19 @@ Blocklist.prototype = {
if (!blockEntry.blockID) {
return null;
}
return blockEntry.infoURL;
},
_notifyObserversBlocklistGFX: function () {
+ if (this._gfxEntries.length === 0) {
+ return;
+ }
// Notify `GfxInfoBase`, by passing a string serialization.
// This way we avoid spreading XML structure logics there.
const payload = this._gfxEntries.map((r) => {
return Object.keys(r).sort().filter((k) => !/id|last_modified/.test(k)).map((key) => {
let value = r[key];
if (Array.isArray(value)) {
value = value.join(",");
} else if (value.hasOwnProperty("minVersion")) {