From 4ad032d55cca37f4a2842ead1d6f618aacc94bde Mon Sep 17 00:00:00 2001 From: YUKI Hiroshi Date: Fri, 13 Mar 2015 16:37:02 +0900 Subject: [PATCH] Listen messages from the content process with single listener for the window, instead of separate listeners for each frame. If we register listeners for each frame, they don't work after the type of related browser is changed between remote and in-process. --- modules/contentBridge.js | 23 +++++++++++++++++------ modules/window.js | 5 +++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/modules/contentBridge.js b/modules/contentBridge.js index 3bc01439..6deed73a 100644 --- a/modules/contentBridge.js +++ b/modules/contentBridge.js @@ -50,6 +50,14 @@ function ContentBridge(aTab, aTabBrowser) { this.init(aTab, aTabBrowser); } + +ContentBridge.install = function CB_installScript(aWindow) { + aWindow.messageManager.loadFrameScript(TreeStyleTabConstants.CONTENT_SCRIPT_AUTOHIDE, true); +}; + +ContentBridge.uninstall = function CB_installScript(aWindow) { + aWindow.messageManager.sendAsyncCommand(TreeStyleTabConstants.COMMAND_SHUTDOWN); +}; ContentBridge.prototype = inherit(TreeStyleTabConstants, { mTab : null, @@ -62,16 +70,13 @@ ContentBridge.prototype = inherit(TreeStyleTabConstants, { this.handleMessage = this.handleMessage.bind(this); this.checkPluginAreaExistenceResolvers = {}; - var manager = this.mTab.linkedBrowser.messageManager; - // manager.loadFrameScript(this.CONTENT_SCRIPT, true); - manager.loadFrameScript(this.CONTENT_SCRIPT_AUTOHIDE, true); + var manager = this.mTab.ownerDocument.defaultView.messageManager; manager.addMessageListener(this.MESSAGE_TYPE, this.handleMessage); }, destroy : function CB_destroy() { - var manager = this.mTab.linkedBrowser.messageManager; + var manager = this.mTab.ownerDocument.defaultView.messageManager; manager.removeMessageListener(this.MESSAGE_TYPE, this.handleMessage); - this.sendAsyncCommand(this.COMMAND_SHUTDOWN); delete this.mTab; delete this.mTabBrowser; @@ -97,7 +102,13 @@ ContentBridge.prototype = inherit(TreeStyleTabConstants, { }, handleMessage : function CB_handleMessage(aMessage) { - // dump(JSON.stringify(aMessage.json)+'\n'); +// dump('*********************handleMessage*******************\n'); +// dump('TARGET IS: '+aMessage.target.localName+'\n'); +// dump(JSON.stringify(aMessage.json)+'\n'); + + if (aMessage.target != this.mTab.linkedBrowser) + return; + switch (aMessage.json.command) { case this.COMMAND_REPORT_MOUSEDOWN: diff --git a/modules/window.js b/modules/window.js index b8072154..ae2fc177 100644 --- a/modules/window.js +++ b/modules/window.js @@ -65,6 +65,7 @@ XPCOMUtils.defineLazyModuleGetter(this, 'AutoHideWindow', 'resource://treestylet XPCOMUtils.defineLazyModuleGetter(this, 'TreeStyleTabThemeManager', 'resource://treestyletab-modules/themeManager.js'); XPCOMUtils.defineLazyModuleGetter(this, 'FullscreenObserver', 'resource://treestyletab-modules/fullscreenObserver.js'); XPCOMUtils.defineLazyModuleGetter(this, 'BrowserUIShowHideObserver', 'resource://treestyletab-modules/browserUIShowHideObserver.js'); +XPCOMUtils.defineLazyModuleGetter(this, 'ContentBridge', 'resource://treestyletab-modules/contentBridge.js'); XPCOMUtils.defineLazyServiceGetter(this, 'SessionStore', '@mozilla.org/browser/sessionstore;1', 'nsISessionStore'); @@ -419,6 +420,8 @@ TreeStyleTabWindow.prototype = inherit(TreeStyleTabBase, { this.initUninstallationListener(); + ContentBridge.install(w); + w.TreeStyleTabWindowHelper.onBeforeBrowserInit(); this.initTabBrowser(this.browser); w.TreeStyleTabWindowHelper.onAfterBrowserInit(); @@ -535,6 +538,8 @@ TreeStyleTabWindow.prototype = inherit(TreeStyleTabBase, { w.messageManager.removeMessageListener('SessionStore:restoreTabContentStarted', this); + ContentBridge.uninstall(w); + this.fullscreenObserver.destroy(); delete this.fullscreenObserver;