зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1390010: Part 3 - Limit the amount of schema data sent to web content processes. r=zombie
Web contetnt processes only need access to a small amount of schema data, but we currently send them the approximately 600K of full schema data that is mostly useless to them. This patch limits the schema data sent to web content processes to what they actually need, and sends the rest only to extension content processes. MozReview-Commit-ID: 6G0LThNTOu1 --HG-- extra : rebase_source : 36672ad6323e6466bba3e463fa4f0a16e3fd9090
This commit is contained in:
Родитель
0b7f63fe38
Коммит
d003f8b90f
|
@ -941,7 +941,7 @@ class SchemaAPIManager extends EventEmitter {
|
|||
|
||||
this._modulesJSONLoaded = false;
|
||||
|
||||
this.schemaURLs = new Set();
|
||||
this.schemaURLs = new Map();
|
||||
|
||||
this.apis = new DefaultWeakMap(() => new Map());
|
||||
|
||||
|
@ -1002,7 +1002,10 @@ class SchemaAPIManager extends EventEmitter {
|
|||
this.modules.set(name, details);
|
||||
|
||||
if (details.schema) {
|
||||
this.schemaURLs.add(details.schema);
|
||||
let content = (details.scopes &&
|
||||
(details.scopes.includes("content_parent") ||
|
||||
details.scopes.includes("content_child")));
|
||||
this.schemaURLs.set(details.schema, {content});
|
||||
}
|
||||
|
||||
for (let event of details.events || []) {
|
||||
|
|
|
@ -123,8 +123,8 @@ let apiManager = new class extends SchemaAPIManager {
|
|||
for (let [/* name */, url] of XPCOMUtils.enumerateCategoryEntries(CATEGORY_EXTENSION_SCHEMAS)) {
|
||||
promises.push(Schemas.load(url));
|
||||
}
|
||||
for (let url of this.schemaURLs) {
|
||||
promises.push(Schemas.load(url));
|
||||
for (let [url, {content}] of this.schemaURLs) {
|
||||
promises.push(Schemas.load(url, content));
|
||||
}
|
||||
for (let url of schemaURLs) {
|
||||
promises.push(Schemas.load(url));
|
||||
|
@ -564,17 +564,26 @@ class DevToolsExtensionPageContextParent extends ExtensionPageContextParent {
|
|||
ParentAPIManager = {
|
||||
proxyContexts: new Map(),
|
||||
|
||||
parentMessageManagers: new Set(),
|
||||
|
||||
init() {
|
||||
Services.obs.addObserver(this, "message-manager-close");
|
||||
Services.obs.addObserver(this, "ipc:content-created");
|
||||
|
||||
Services.mm.addMessageListener("API:CreateProxyContext", this);
|
||||
Services.mm.addMessageListener("API:CloseProxyContext", this, true);
|
||||
Services.mm.addMessageListener("API:Call", this);
|
||||
Services.mm.addMessageListener("API:AddListener", this);
|
||||
Services.mm.addMessageListener("API:RemoveListener", this);
|
||||
|
||||
this.schemaHook = this.schemaHook.bind(this);
|
||||
},
|
||||
|
||||
observe(subject, topic, data) {
|
||||
attachMessageManager(extension, processMessageManager) {
|
||||
extension.parentMessageManager = processMessageManager;
|
||||
},
|
||||
|
||||
async observe(subject, topic, data) {
|
||||
if (topic === "message-manager-close") {
|
||||
let mm = subject;
|
||||
for (let [childId, context] of this.proxyContexts) {
|
||||
|
@ -589,6 +598,23 @@ ParentAPIManager = {
|
|||
extension.parentMessageManager = null;
|
||||
}
|
||||
}
|
||||
|
||||
this.parentMessageManagers.delete(mm);
|
||||
} else if (topic === "ipc:content-created") {
|
||||
let mm = subject.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIMessageSender);
|
||||
if (mm.remoteType === E10SUtils.EXTENSION_REMOTE_TYPE) {
|
||||
this.parentMessageManagers.add(mm);
|
||||
mm.sendAsyncMessage("Schema:Add", Schemas.schemaJSON);
|
||||
|
||||
Schemas.schemaHook = this.schemaHook;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
schemaHook(schemas) {
|
||||
for (let mm of this.parentMessageManagers) {
|
||||
mm.sendAsyncMessage("Schema:Add", schemas);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -648,7 +674,7 @@ ParentAPIManager = {
|
|||
if (!extension.parentMessageManager) {
|
||||
let expectedRemoteType = extension.remote ? E10SUtils.EXTENSION_REMOTE_TYPE : null;
|
||||
if (target.remoteType === expectedRemoteType) {
|
||||
extension.parentMessageManager = processMessageManager;
|
||||
this.attachMessageManager(extension, processMessageManager);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2641,6 +2641,10 @@ this.Schemas = {
|
|||
// is useful for sending the JSON across processes.
|
||||
schemaJSON: new Map(),
|
||||
|
||||
// A separate map of schema JSON which should be available in all
|
||||
// content processes.
|
||||
contentSchemaJSON: new Map(),
|
||||
|
||||
// Map[<schema-name> -> Map[<symbol-name> -> Entry]]
|
||||
// This keeps track of all the schemas that have been loaded so far.
|
||||
rootNamespace: new Namespace("", []),
|
||||
|
@ -2697,7 +2701,9 @@ this.Schemas = {
|
|||
receiveMessage(msg) {
|
||||
switch (msg.name) {
|
||||
case "Schema:Add":
|
||||
this.schemaJSON.set(msg.data.url, msg.data.schema);
|
||||
for (let [url, schema] of msg.data) {
|
||||
this.schemaJSON.set(url, schema);
|
||||
}
|
||||
this.flushSchemas();
|
||||
break;
|
||||
|
||||
|
@ -2767,18 +2773,24 @@ this.Schemas = {
|
|||
return this._loadCachedSchemasPromise;
|
||||
},
|
||||
|
||||
addSchema(url, schema) {
|
||||
addSchema(url, schema, content = false) {
|
||||
this.schemaJSON.set(url, schema);
|
||||
|
||||
let data = Services.ppmm.initialProcessData;
|
||||
data["Extension:Schemas"] = this.schemaJSON;
|
||||
if (content) {
|
||||
this.contentSchemaJSON.set(url, schema);
|
||||
|
||||
Services.ppmm.broadcastAsyncMessage("Schema:Add", {url, schema});
|
||||
let data = Services.ppmm.initialProcessData;
|
||||
data["Extension:Schemas"] = this.contentSchemaJSON;
|
||||
|
||||
Services.ppmm.broadcastAsyncMessage("Schema:Add", [[url, schema]]);
|
||||
} else if (this.schemaHook) {
|
||||
this.schemaHook([[url, schema]]);
|
||||
}
|
||||
|
||||
this.flushSchemas();
|
||||
},
|
||||
|
||||
async load(url) {
|
||||
async load(url, content = false) {
|
||||
if (!isParentProcess) {
|
||||
return;
|
||||
}
|
||||
|
@ -2789,7 +2801,7 @@ this.Schemas = {
|
|||
await StartupCache.schemas.get(url, readJSONAndBlobbify));
|
||||
|
||||
if (!this.schemaJSON.has(url)) {
|
||||
this.addSchema(url, blob);
|
||||
this.addSchema(url, blob, content);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@
|
|||
"extension": {
|
||||
"url": "chrome://extensions/content/ext-extension.js",
|
||||
"schema": "chrome://extensions/content/schemas/extension.json",
|
||||
"scopes": ["addon_parent"],
|
||||
"scopes": ["addon_parent", "content_child"],
|
||||
"paths": [
|
||||
["extension"]
|
||||
]
|
||||
|
@ -136,7 +136,7 @@
|
|||
},
|
||||
"test": {
|
||||
"schema": "chrome://extensions/content/schemas/test.json",
|
||||
"scopes": []
|
||||
"scopes": ["content_child"]
|
||||
},
|
||||
"theme": {
|
||||
"url": "chrome://extensions/content/ext-theme.js",
|
||||
|
|
|
@ -377,7 +377,9 @@ ExtensionManager = {
|
|||
}
|
||||
|
||||
case "Schema:Add": {
|
||||
this.schemaJSON.set(data.url, data.schema);
|
||||
for (let [url, schema] of data) {
|
||||
this.schemaJSON.set(url, schema);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче