Bug 1368102: Part 7 - Remove ScriptMatcher and use WebExtensionConentScript directly. r=mixedpuppy
MozReview-Commit-ID: 5upkXMiivBn
This commit is contained in:
@@ -1112,7 +1112,7 @@ this.Extension = class extends ExtensionData {
|
|||||||
Management.emit("shutdown", this);
|
Management.emit("shutdown", this);
|
||||||
this.emit("shutdown");
|
this.emit("shutdown");
|
||||||
|
|
||||||
Services.ppmm.broadcastAsyncMessage("Extension:Shutdown", {id: this.id});
|
await this.broadcast("Extension:Shutdown", {id: this.id});
|
||||||
|
|
||||||
MessageChannel.abortResponses({extensionId: this.id});
|
MessageChannel.abortResponses({extensionId: this.id});
|
||||||
|
|
||||||
|
|||||||
@@ -227,6 +227,11 @@ class Script {
|
|||||||
return this.cssURLs.map(url => this.cssCache.get(url));
|
return this.cssURLs.map(url => this.cssCache.get(url));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
preload() {
|
||||||
|
this.loadCSS();
|
||||||
|
this.compileScripts();
|
||||||
|
}
|
||||||
|
|
||||||
cleanup(window) {
|
cleanup(window) {
|
||||||
if (!this.removeCss && this.cssURLs.length) {
|
if (!this.removeCss && this.cssURLs.length) {
|
||||||
let winUtils = getWinUtils(window);
|
let winUtils = getWinUtils(window);
|
||||||
@@ -243,6 +248,10 @@ class Script {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
matchesWindow(window) {
|
||||||
|
return this.matcher.matchesWindow(window);
|
||||||
|
}
|
||||||
|
|
||||||
async injectInto(window) {
|
async injectInto(window) {
|
||||||
let context = this.extension.getContext(window);
|
let context = this.extension.getContext(window);
|
||||||
|
|
||||||
|
|||||||
@@ -64,36 +64,10 @@ var extensions = new DefaultWeakMap(policy => {
|
|||||||
return extension;
|
return extension;
|
||||||
});
|
});
|
||||||
|
|
||||||
class ScriptMatcher {
|
var contentScripts = new DefaultWeakMap(matcher => {
|
||||||
constructor(matcher) {
|
return new ExtensionContent.Script(extensions.get(matcher.extension),
|
||||||
this.matcher = 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getMessageManager(window) {
|
function getMessageManager(window) {
|
||||||
let docShell = window.document.docShell.QueryInterface(Ci.nsIInterfaceRequestor);
|
let docShell = window.document.docShell.QueryInterface(Ci.nsIInterfaceRequestor);
|
||||||
@@ -139,7 +113,7 @@ class ExtensionGlobal {
|
|||||||
|
|
||||||
let matcher = new WebExtensionContentScript(policy, parseScriptOptions(data.options));
|
let matcher = new WebExtensionContentScript(policy, parseScriptOptions(data.options));
|
||||||
|
|
||||||
let options = Object.assign(matcher, {
|
Object.assign(matcher, {
|
||||||
wantReturnValue: data.options.wantReturnValue,
|
wantReturnValue: data.options.wantReturnValue,
|
||||||
removeCSS: data.options.remove_css,
|
removeCSS: data.options.remove_css,
|
||||||
cssOrigin: data.options.css_origin,
|
cssOrigin: data.options.css_origin,
|
||||||
@@ -147,7 +121,7 @@ class ExtensionGlobal {
|
|||||||
jsCode: data.options.jsCode,
|
jsCode: data.options.jsCode,
|
||||||
});
|
});
|
||||||
|
|
||||||
let script = new ScriptMatcher(options);
|
let script = contentScripts.get(matcher);
|
||||||
|
|
||||||
return ExtensionContent.handleExtensionExecute(this.global, target, data.options, script);
|
return ExtensionContent.handleExtensionExecute(this.global, target, data.options, script);
|
||||||
case "WebNavigation:GetFrame":
|
case "WebNavigation:GetFrame":
|
||||||
@@ -158,8 +132,6 @@ class ExtensionGlobal {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let scriptMatchers = new DefaultWeakMap(matcher => new ScriptMatcher(matcher));
|
|
||||||
|
|
||||||
// Responsible for creating ExtensionContexts and injecting content
|
// Responsible for creating ExtensionContexts and injecting content
|
||||||
// scripts into them when new documents are created.
|
// scripts into them when new documents are created.
|
||||||
DocumentManager = {
|
DocumentManager = {
|
||||||
@@ -261,7 +233,7 @@ DocumentManager = {
|
|||||||
for (let window of this.enumerateWindows()) {
|
for (let window of this.enumerateWindows()) {
|
||||||
for (let script of extension.contentScripts) {
|
for (let script of extension.contentScripts) {
|
||||||
if (script.matchesWindow(window)) {
|
if (script.matchesWindow(window)) {
|
||||||
scriptMatchers.get(script).injectInto(window);
|
contentScripts.get(script).injectInto(window);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -428,6 +400,7 @@ ExtensionManager = {
|
|||||||
if (isContentProcess) {
|
if (isContentProcess) {
|
||||||
policy.active = false;
|
policy.active = false;
|
||||||
}
|
}
|
||||||
|
Services.cpmm.sendAsyncMessage("Extension:ShutdownComplete");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -459,12 +432,12 @@ ExtensionProcessScript.prototype = {
|
|||||||
QueryInterface: XPCOMUtils.generateQI([Ci.mozIExtensionProcessScript]),
|
QueryInterface: XPCOMUtils.generateQI([Ci.mozIExtensionProcessScript]),
|
||||||
|
|
||||||
preloadContentScript(contentScript) {
|
preloadContentScript(contentScript) {
|
||||||
scriptMatchers.get(contentScript).preload();
|
contentScripts.get(contentScript).preload();
|
||||||
},
|
},
|
||||||
|
|
||||||
loadContentScript(contentScript, window) {
|
loadContentScript(contentScript, window) {
|
||||||
if (DocumentManager.globals.has(getMessageManager(window))) {
|
if (DocumentManager.globals.has(getMessageManager(window))) {
|
||||||
scriptMatchers.get(contentScript).injectInto(window);
|
contentScripts.get(contentScript).injectInto(window);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user