зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1317101 - Part 5: Simply remote view initialization code, and fix some inconsistent handling. r=billm
MozReview-Commit-ID: 65BE0oF3rpI --HG-- extra : rebase_source : c65b403f2960edaf6e5e46ee94d76c39f8507dba extra : source : 225ad2535585ff6ce38e1e9f8fe5371194a70658
This commit is contained in:
Родитель
a9b0112912
Коммит
b6d9dc9190
|
@ -225,6 +225,7 @@ class BasePopup {
|
|||
this.browser.setAttribute("disableglobalhistory", "true");
|
||||
this.browser.setAttribute("transparent", "true");
|
||||
this.browser.setAttribute("class", "webextension-popup-browser");
|
||||
this.browser.setAttribute("webextension-view-type", "popup");
|
||||
this.browser.setAttribute("tooltip", "aHTMLTooltip");
|
||||
|
||||
// We only need flex sizing for the sake of the slide-in sub-views of the
|
||||
|
@ -240,14 +241,6 @@ class BasePopup {
|
|||
viewNode.appendChild(this.browser);
|
||||
|
||||
extensions.emit("extension-browser-inserted", this.browser);
|
||||
let windowId = WindowManager.getId(this.browser.ownerGlobal);
|
||||
this.browser.messageManager.sendAsyncMessage("Extension:InitExtensionView", {
|
||||
viewType: "popup",
|
||||
windowId,
|
||||
});
|
||||
// TODO(robwu): Rework this to use the Extension:ExtensionViewLoaded message
|
||||
// to detect loads and so on. And definitely move this content logic inside
|
||||
// a file in the child process.
|
||||
|
||||
let initBrowser = browser => {
|
||||
let mm = browser.messageManager;
|
||||
|
@ -279,7 +272,7 @@ class BasePopup {
|
|||
stylesheets: this.STYLESHEETS,
|
||||
});
|
||||
|
||||
this.browser.setAttribute("src", popupURL);
|
||||
this.browser.loadURI(popupURL);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ const {
|
|||
getMessageManager,
|
||||
getUniqueId,
|
||||
injectAPI,
|
||||
promiseEvent,
|
||||
} = ExtensionUtils;
|
||||
|
||||
const {
|
||||
|
@ -862,16 +863,14 @@ class ContentGlobal {
|
|||
this.tabId = -1;
|
||||
this.windowId = -1;
|
||||
this.initialized = false;
|
||||
|
||||
this.global.addMessageListener("Extension:InitExtensionView", this);
|
||||
this.global.addMessageListener("Extension:SetTabAndWindowId", this);
|
||||
|
||||
this.initialDocuments = new WeakSet();
|
||||
}
|
||||
|
||||
uninit() {
|
||||
this.global.removeMessageListener("Extension:InitExtensionView", this);
|
||||
this.global.removeMessageListener("Extension:SetTabAndWindowId", this);
|
||||
this.global.removeEventListener("DOMContentLoaded", this);
|
||||
}
|
||||
|
||||
ensureInitialized() {
|
||||
|
@ -889,18 +888,13 @@ class ContentGlobal {
|
|||
case "Extension:InitExtensionView":
|
||||
// The view type is initialized once and then fixed.
|
||||
this.global.removeMessageListener("Extension:InitExtensionView", this);
|
||||
let {viewType, url} = data;
|
||||
this.viewType = viewType;
|
||||
this.global.addEventListener("DOMContentLoaded", this);
|
||||
if (url) {
|
||||
// TODO(robwu): Remove this check. It is only here because the popup
|
||||
// implementation does not always load a URL at the initialization,
|
||||
// and the logic is too complex to fix at once.
|
||||
let {document} = this.global.content;
|
||||
this.initialDocuments.add(document);
|
||||
document.location.replace(url);
|
||||
}
|
||||
/* Falls through to allow these properties to be initialized at once */
|
||||
this.viewType = data.viewType;
|
||||
|
||||
promiseEvent(this.global, "DOMContentLoaded", true).then(() => {
|
||||
this.global.sendAsyncMessage("Extension:ExtensionViewLoaded");
|
||||
});
|
||||
|
||||
/* FALLTHROUGH */
|
||||
case "Extension:SetTabAndWindowId":
|
||||
this.handleSetTabAndWindowId(data);
|
||||
break;
|
||||
|
@ -909,6 +903,7 @@ class ContentGlobal {
|
|||
|
||||
handleSetTabAndWindowId(data) {
|
||||
let {tabId, windowId} = data;
|
||||
|
||||
if (tabId) {
|
||||
// Tab IDs are not expected to change.
|
||||
if (this.tabId !== -1 && tabId !== this.tabId) {
|
||||
|
@ -916,6 +911,7 @@ class ContentGlobal {
|
|||
}
|
||||
this.tabId = tabId;
|
||||
}
|
||||
|
||||
if (windowId !== undefined) {
|
||||
// Window IDs may change if a tab is moved to a different location.
|
||||
// Note: This is the ID of the browser window for the extension API.
|
||||
|
@ -924,21 +920,6 @@ class ContentGlobal {
|
|||
}
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
// "DOMContentLoaded" event.
|
||||
handleEvent(event) {
|
||||
let {document} = this.global.content;
|
||||
if (event.target === document) {
|
||||
// If the document was still being loaded at the time of navigation, then
|
||||
// the DOMContentLoaded event is fired for the old document. Ignore it.
|
||||
if (this.initialDocuments.has(document)) {
|
||||
this.initialDocuments.delete(document);
|
||||
return;
|
||||
}
|
||||
this.global.removeEventListener("DOMContentLoaded", this);
|
||||
this.global.sendAsyncMessage("Extension:ExtensionViewLoaded");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ExtensionChild = {
|
||||
|
|
|
@ -229,6 +229,19 @@ GlobalManager = {
|
|||
ExtensionContent.uninit(this);
|
||||
});
|
||||
`, false);
|
||||
|
||||
let viewType = browser.getAttribute("webextension-view-type");
|
||||
if (viewType) {
|
||||
let data = {viewType};
|
||||
|
||||
let {getBrowserInfo} = apiManager.global;
|
||||
if (getBrowserInfo) {
|
||||
Object.assign(data, getBrowserInfo(browser));
|
||||
}
|
||||
|
||||
browser.messageManager.sendAsyncMessage("Extension:InitExtensionView",
|
||||
data);
|
||||
}
|
||||
},
|
||||
|
||||
getExtension(extensionId) {
|
||||
|
|
|
@ -74,13 +74,12 @@ BackgroundPage.prototype = {
|
|||
let browser = chromeDoc.createElement("browser");
|
||||
browser.setAttribute("type", "content");
|
||||
browser.setAttribute("disableglobalhistory", "true");
|
||||
browser.setAttribute("webextension-view-type", "background");
|
||||
chromeDoc.documentElement.appendChild(browser);
|
||||
|
||||
extensions.emit("extension-browser-inserted", browser);
|
||||
browser.messageManager.sendAsyncMessage("Extension:InitExtensionView", {
|
||||
viewType: "background",
|
||||
url,
|
||||
});
|
||||
|
||||
browser.loadURI(url);
|
||||
|
||||
yield new Promise(resolve => {
|
||||
browser.messageManager.addMessageListener("Extension:ExtensionViewLoaded", function onLoad() {
|
||||
|
|
Загрузка…
Ссылка в новой задаче