зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1484373: Part 11 - Fold mostly-empty DocumentManager singleton into ExtensionManager. r=mixedpuppy
Differential Revision: https://phabricator.services.mozilla.com/D3701 --HG-- extra : rebase_source : 6f56651e4187625b073209277e5bc17954ad7a5a extra : histedit_source : e7ef1bd1a49daf311decfc4e23a20c8ec72e4d30
This commit is contained in:
Родитель
8a20a1620e
Коммит
7f4d4b874b
|
@ -56,7 +56,6 @@ var extensions = new DefaultWeakMap(policy => {
|
|||
return extension;
|
||||
});
|
||||
|
||||
var DocumentManager;
|
||||
var ExtensionManager;
|
||||
|
||||
class ExtensionGlobal {
|
||||
|
@ -104,34 +103,12 @@ class ExtensionGlobal {
|
|||
}
|
||||
}
|
||||
|
||||
// Responsible for creating ExtensionContexts and injecting content
|
||||
// scripts into them when new documents are created.
|
||||
DocumentManager = {
|
||||
globals: new Map(),
|
||||
|
||||
// Initialize listeners that we need regardless of whether extensions are
|
||||
// enabled.
|
||||
earlyInit() {
|
||||
// eslint-disable-next-line mozilla/balanced-listeners
|
||||
Services.obs.addObserver((subject) => this.initGlobal(subject),
|
||||
"tab-content-frameloader-created");
|
||||
},
|
||||
|
||||
// Initialize a frame script global which extension contexts may be loaded
|
||||
// into.
|
||||
initGlobal(global) {
|
||||
this.globals.set(global, new ExtensionGlobal(global));
|
||||
// eslint-disable-next-line mozilla/balanced-listeners
|
||||
global.addEventListener("unload", () => {
|
||||
this.globals.delete(global);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
ExtensionManager = {
|
||||
// WeakMap<WebExtensionPolicy, Map<string, WebExtensionContentScript>>
|
||||
registeredContentScripts: new DefaultWeakMap((policy) => new Map()),
|
||||
|
||||
globals: new WeakMap(),
|
||||
|
||||
init() {
|
||||
MessageChannel.setupMessageManagers([Services.cpmm]);
|
||||
|
||||
|
@ -141,6 +118,11 @@ ExtensionManager = {
|
|||
Services.cpmm.addMessageListener("Extension:RegisterContentScript", this);
|
||||
Services.cpmm.addMessageListener("Extension:UnregisterContentScripts", this);
|
||||
|
||||
// eslint-disable-next-line mozilla/balanced-listeners
|
||||
Services.obs.addObserver(
|
||||
global => this.globals.set(global, new ExtensionGlobal(global)),
|
||||
"tab-content-frameloader-created");
|
||||
|
||||
for (let id of sharedData.get("extensions/activeIDs") || []) {
|
||||
this.initExtension(getData({id}));
|
||||
}
|
||||
|
@ -291,7 +273,7 @@ ExtensionProcessScript.prototype = {
|
|||
extensions,
|
||||
|
||||
getFrameData(global, force) {
|
||||
let extGlobal = DocumentManager.globals.get(global);
|
||||
let extGlobal = ExtensionManager.globals.get(global);
|
||||
return extGlobal && extGlobal.getFrameData(force);
|
||||
},
|
||||
|
||||
|
@ -326,5 +308,4 @@ ExtensionProcessScript.prototype = {
|
|||
|
||||
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([ExtensionProcessScript]);
|
||||
|
||||
DocumentManager.earlyInit();
|
||||
ExtensionManager.init();
|
||||
|
|
Загрузка…
Ссылка в новой задаче