Skip to content

Commit

Permalink
[e10s] load frame script with window message manager
Browse files Browse the repository at this point in the history
  • Loading branch information
gomita committed Oct 28, 2014
1 parent 20524a3 commit 0df14fd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 33 deletions.
43 changes: 16 additions & 27 deletions chrome/content/tabscope/overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,19 @@ var TabScope = {
// [Linux] remove |noautohide| to avoid losing focus on browser
if (this.popup.getAttribute("_os") == "Linux")
this.popup.removeAttribute("noautohide");
// [e10s] load frame script into every browser in window
if (gMultiProcessBrowser) {
window.messageManager.loadFrameScript("chrome://tabscope/content/remote.js", true);
window.messageManager.addMessageListener("TabScopeRemote:Response", this);
}
},

uninit: function() {
// [e10s] stop listening the response from remote
if (gMultiProcessBrowser) {
window.messageManager.removeDelayedFrameScript("chrome://tabscope/content/remote.js");
window.messageManager.removeMessageListener("TabScopeRemote:Response", this);
}
this._cancelDelayedOpen();
// [backmonitor] should close popup explicitly
this.popup.hidePopup();
Expand Down Expand Up @@ -207,12 +217,10 @@ var TabScope = {
else {
// when mouse pointer moves from one tab to another...
// popup is already opened, so move it now
this._setupRemote(false);
this._tab.linkedBrowser.removeProgressListener(this);
this._tab.linkedBrowser.removeEventListener("MozAfterPaint", this, false);
this._tab.removeEventListener("TabAttrModified", this, false);
this._tab = event.target;
this._setupRemote(true);
this._tab.linkedBrowser.addProgressListener(this, this._notifyMask);
this._tab.linkedBrowser.addEventListener("MozAfterPaint", this, false);
this._tab.addEventListener("TabAttrModified", this, false);
Expand Down Expand Up @@ -284,7 +292,12 @@ var TabScope = {
break;
case "popupshowing":
this.log("open popup"); // #debug
this._setupRemote(true);
// [e10s]
if (gMultiProcessBrowser) {
this._messageId = 0;
this._waitingId = 0;
this.canvas._scale = 0;
}
this._tab.linkedBrowser.addProgressListener(this, this._notifyMask);
this._tab.linkedBrowser.addEventListener("MozAfterPaint", this, false);
this._tab.addEventListener("TabAttrModified", this, false);
Expand Down Expand Up @@ -315,7 +328,6 @@ var TabScope = {
break;
case "popuphiding":
this.log("close popup"); // #debug
this._setupRemote(false);
this._tab.linkedBrowser.removeProgressListener(this);
this._tab.linkedBrowser.removeEventListener("MozAfterPaint", this, false);
this._tab.removeEventListener("TabAttrModified", this, false);
Expand Down Expand Up @@ -905,29 +917,6 @@ var TabScope = {
// [e10s] the message id which is waiting for the response
_waitingId: 0,

// [e10s] init/uninit TabScope child in remote browser assosiated with |_tab|
_setupRemote: function(aInit) {
if (!gMultiProcessBrowser)
return;
var mm = this._tab.linkedBrowser.messageManager;
if (aInit) {
this._messageId = 0;
this._waitingId = 0;
this.canvas._scale = 0;
// load frame script into browser
if (!this._tab.linkedBrowser.hasAttribute("tabscope:remote")) {
mm.loadFrameScript("chrome://tabscope/content/remote.js", true);
this._tab.linkedBrowser.setAttribute("tabscope:remote", "true");
}
mm.addMessageListener("TabScopeRemote:Response", this);
mm.sendAsyncMessage("TabScope:OpenPopup", {});
}
else {
mm.sendAsyncMessage("TabScope:ClosePopup", {});
mm.removeMessageListener("TabScopeRemote:Response", this);
}
},

// [e10s] send message to remote browser
// if |aWait| is true, no messages will be sent/received until receiving the response
// which id equals to |_waitingId|.
Expand Down
15 changes: 9 additions & 6 deletions chrome/content/tabscope/remote.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
let TabScopeRemote = {

init: function() {
// #debug-begin
Components.utils.import("resource://gre/modules/Services.jsm");
this.log("init: " + new Date().toLocaleTimeString());
// #debug-end
addMessageListener("TabScope:OpenPopup", this);
addMessageListener("TabScope:ClosePopup", this);
addMessageListener("TabScope:Preview", this);
Expand All @@ -9,12 +13,12 @@ let TabScopeRemote = {
},

receiveMessage: function(aMsg) {
this.log(aMsg.name + "\t" + aMsg.data.toSource()); // #debug
// #debug-begin
let data = { id: aMsg.data.id };
for (let key in aMsg.data) data[key] = aMsg.data[key];
this.log(aMsg.name + "\t" + data.toSource());
// #debug-end
switch (aMsg.name) {
case "TabScope:OpenPopup":
break;
case "TabScope:ClosePopup":
break;
case "TabScope:Preview":
this._updatePreview(aMsg.data);
break;
Expand Down Expand Up @@ -116,7 +120,6 @@ let TabScopeRemote = {

log: function(aText) {
// dump("tabscope:remote> " + aText + "\n");
Components.utils.import("resource://gre/modules/Services.jsm");
Services.console.logStringMessage("TabScopeRemote> " + aText);
},

Expand Down

0 comments on commit 0df14fd

Please sign in to comment.