зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1385090 - Pass Remote Pages instance from AboutNewTab on override r=mossop
MozReview-Commit-ID: 7oBsmIUpQXs --HG-- extra : rebase_source : 63df4d8968031e23fd1973bce56bc95bfe6705be
This commit is contained in:
Родитель
35584ea463
Коммит
7babb467c7
|
@ -126,11 +126,9 @@ this.ActivityStreamMessageChannel = class ActivityStreamMessageChannel {
|
|||
* between the main process and child pages
|
||||
*/
|
||||
createChannel() {
|
||||
// RemotePageManager must be disabled for about:newtab, since only one can exist at once
|
||||
if (this.pageURL === ABOUT_NEW_TAB_URL) {
|
||||
AboutNewTab.override();
|
||||
}
|
||||
this.channel = new RemotePages(this.pageURL);
|
||||
// Receive AboutNewTab's Remote Pages instance, if it exists, on override
|
||||
const channel = this.pageURL === ABOUT_NEW_TAB_URL && AboutNewTab.override(true);
|
||||
this.channel = channel || new RemotePages(this.pageURL);
|
||||
this.channel.addMessageListener("RemotePage:Init", this.onNewTabInit);
|
||||
this.channel.addMessageListener("RemotePage:Load", this.onNewTabLoad);
|
||||
this.channel.addMessageListener("RemotePage:Unload", this.onNewTabUnload);
|
||||
|
@ -141,11 +139,16 @@ this.ActivityStreamMessageChannel = class ActivityStreamMessageChannel {
|
|||
* destroyChannel - Destroys the RemotePages channel
|
||||
*/
|
||||
destroyChannel() {
|
||||
this.channel.destroy();
|
||||
this.channel = null;
|
||||
this.channel.removeMessageListener("RemotePage:Init", this.onNewTabInit);
|
||||
this.channel.removeMessageListener("RemotePage:Load", this.onNewTabLoad);
|
||||
this.channel.removeMessageListener("RemotePage:Unload", this.onNewTabUnload);
|
||||
this.channel.removeMessageListener(this.incomingMessageName, this.onMessage);
|
||||
if (this.pageURL === ABOUT_NEW_TAB_URL) {
|
||||
AboutNewTab.reset();
|
||||
AboutNewTab.reset(this.channel);
|
||||
} else {
|
||||
this.channel.destroy();
|
||||
}
|
||||
this.channel = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,14 +26,14 @@ var AboutNewTab = {
|
|||
|
||||
isOverridden: false,
|
||||
|
||||
init() {
|
||||
init(pageListener) {
|
||||
if (this.isOverridden) {
|
||||
return;
|
||||
}
|
||||
this.pageListener = new RemotePages("about:newtab");
|
||||
this.pageListener.addMessageListener("NewTab:Customize", this.customize.bind(this));
|
||||
this.pageListener = pageListener || new RemotePages("about:newtab");
|
||||
this.pageListener.addMessageListener("NewTab:Customize", this.customize);
|
||||
this.pageListener.addMessageListener("NewTab:MaybeShowMigrateMessage",
|
||||
this.maybeShowMigrateMessage.bind(this));
|
||||
this.maybeShowMigrateMessage);
|
||||
},
|
||||
|
||||
maybeShowMigrateMessage({ target }) {
|
||||
|
@ -56,13 +56,24 @@ var AboutNewTab = {
|
|||
}
|
||||
},
|
||||
|
||||
override() {
|
||||
this.uninit();
|
||||
override(shouldPassPageListener) {
|
||||
this.isOverridden = true;
|
||||
const pageListener = this.pageListener;
|
||||
if (!pageListener) {
|
||||
return;
|
||||
}
|
||||
if (shouldPassPageListener) {
|
||||
this.pageListener = null;
|
||||
pageListener.removeMessageListener("NewTab:Customize", this.customize);
|
||||
pageListener.removeMessageListener("NewTab:MaybeShowMigrateMessage",
|
||||
this.maybeShowMigrateMessage);
|
||||
return pageListener;
|
||||
}
|
||||
this.uninit();
|
||||
},
|
||||
|
||||
reset() {
|
||||
reset(pageListener) {
|
||||
this.isOverridden = false;
|
||||
this.init();
|
||||
this.init(pageListener);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
this.EXPORTED_SYMBOLS = ["RemotePages", "RemotePageManager", "PageListener"];
|
||||
|
||||
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
|
||||
const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
@ -127,7 +127,15 @@ RemotePages.prototype = {
|
|||
// Sends a message to all known pages
|
||||
sendAsyncMessage(name, data = null) {
|
||||
for (let port of this.messagePorts.values()) {
|
||||
port.sendAsyncMessage(name, data);
|
||||
try {
|
||||
port.sendAsyncMessage(name, data);
|
||||
}
|
||||
catch (e) {
|
||||
// Unless the port is in the process of unloading, something strange
|
||||
// happened but allow other ports to receive the message
|
||||
if (e.result !== Cr.NS_ERROR_NOT_INITIALIZED)
|
||||
Cu.reportError(e);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче