Bug 1368102: Part 7 - Remove ScriptMatcher and use WebExtensionConentScript directly. r=mixedpuppy

MozReview-Commit-ID: 5upkXMiivBn

--HG--
extra : rebase_source : 9d16872a69576bbc364866dfd24d1ad6dc755d3e
This commit is contained in:
Kris Maglione 2017-06-04 13:29:03 -07:00
Родитель c908bc3b61
Коммит 2f16ad43cb
3 изменённых файлов: 20 добавлений и 38 удалений

Просмотреть файл

@ -1112,7 +1112,7 @@ this.Extension = class extends ExtensionData {
Management.emit("shutdown", this);
this.emit("shutdown");
Services.ppmm.broadcastAsyncMessage("Extension:Shutdown", {id: this.id});
await this.broadcast("Extension:Shutdown", {id: this.id});
MessageChannel.abortResponses({extensionId: this.id});

Просмотреть файл

@ -227,6 +227,11 @@ class Script {
return this.cssURLs.map(url => this.cssCache.get(url));
}
preload() {
this.loadCSS();
this.compileScripts();
}
cleanup(window) {
if (!this.removeCss && this.cssURLs.length) {
let winUtils = getWinUtils(window);
@ -243,6 +248,10 @@ class Script {
}
}
matchesWindow(window) {
return this.matcher.matchesWindow(window);
}
async injectInto(window) {
let context = this.extension.getContext(window);

Просмотреть файл

@ -64,36 +64,10 @@ var extensions = new DefaultWeakMap(policy => {
return extension;
});
class ScriptMatcher {
constructor(matcher) {
this.matcher = matcher;
this._script = null;
}
get script() {
if (!this._script) {
this._script = new ExtensionContent.Script(extensions.get(this.matcher.extension),
this.matcher);
}
return this._script;
}
preload() {
let {script} = this;
script.loadCSS();
script.compileScripts();
}
matchesWindow(window) {
return this.matcher.matchesWindow(window);
}
injectInto(window) {
return this.script.injectInto(window);
}
}
var contentScripts = new DefaultWeakMap(matcher => {
return new ExtensionContent.Script(extensions.get(matcher.extension),
matcher);
});
function getMessageManager(window) {
let docShell = window.document.docShell.QueryInterface(Ci.nsIInterfaceRequestor);
@ -139,7 +113,7 @@ class ExtensionGlobal {
let matcher = new WebExtensionContentScript(policy, parseScriptOptions(data.options));
let options = Object.assign(matcher, {
Object.assign(matcher, {
wantReturnValue: data.options.wantReturnValue,
removeCSS: data.options.remove_css,
cssOrigin: data.options.css_origin,
@ -147,7 +121,7 @@ class ExtensionGlobal {
jsCode: data.options.jsCode,
});
let script = new ScriptMatcher(options);
let script = contentScripts.get(matcher);
return ExtensionContent.handleExtensionExecute(this.global, target, data.options, script);
case "WebNavigation:GetFrame":
@ -158,8 +132,6 @@ class ExtensionGlobal {
}
}
let scriptMatchers = new DefaultWeakMap(matcher => new ScriptMatcher(matcher));
// Responsible for creating ExtensionContexts and injecting content
// scripts into them when new documents are created.
DocumentManager = {
@ -261,7 +233,7 @@ DocumentManager = {
for (let window of this.enumerateWindows()) {
for (let script of extension.contentScripts) {
if (script.matchesWindow(window)) {
scriptMatchers.get(script).injectInto(window);
contentScripts.get(script).injectInto(window);
}
}
}
@ -428,6 +400,7 @@ ExtensionManager = {
if (isContentProcess) {
policy.active = false;
}
Services.cpmm.sendAsyncMessage("Extension:ShutdownComplete");
break;
}
@ -459,12 +432,12 @@ ExtensionProcessScript.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.mozIExtensionProcessScript]),
preloadContentScript(contentScript) {
scriptMatchers.get(contentScript).preload();
contentScripts.get(contentScript).preload();
},
loadContentScript(contentScript, window) {
if (DocumentManager.globals.has(getMessageManager(window))) {
scriptMatchers.get(contentScript).injectInto(window);
contentScripts.get(contentScript).injectInto(window);
}
},
};