From 23ce62fbf61e4fabd8776604ca73a70891235276 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabrice=20Desr=C3=A9?= Date: Wed, 15 Aug 2012 09:00:02 -0700 Subject: [PATCH] Bug 782859 - Add e10s support the ContentHandler component [r=vingtetun] --- b2g/chrome/content/shell.js | 35 ++++++++++++++++++++++---------- b2g/components/ContentHandler.js | 6 +++++- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/b2g/chrome/content/shell.js b/b2g/chrome/content/shell.js index 7da9d790435b..b2f0c84b0317 100644 --- a/b2g/chrome/content/shell.js +++ b/b2g/chrome/content/shell.js @@ -44,6 +44,11 @@ XPCOMUtils.defineLazyGetter(this, 'DebuggerServer', function() { return DebuggerServer; }); +XPCOMUtils.defineLazyGetter(this, "ppmm", function() { + return Cc["@mozilla.org/parentprocessmessagemanager;1"] + .getService(Ci.nsIFrameMessageManager); +}); + function getContentWindow() { return shell.contentBrowser.contentWindow; } @@ -149,6 +154,8 @@ var shell = { }); this.contentBrowser.src = homeURL; + + ppmm.addMessageListener("content-handler", this); }, stop: function shell_stop() { @@ -159,6 +166,7 @@ var shell = { window.removeEventListener('mozfullscreenchange', this); window.removeEventListener('sizemodechange', this); this.contentBrowser.removeEventListener('mozbrowserloadstart', this, true); + ppmm.removeMessageListener("content-handler", this); #ifndef MOZ_WIDGET_GONK delete Services.audioManager; @@ -298,13 +306,29 @@ var shell = { break; } }, + sendEvent: function shell_sendEvent(content, type, details) { let event = content.document.createEvent('CustomEvent'); event.initCustomEvent(type, true, true, details ? details : {}); content.dispatchEvent(event); }, + sendChromeEvent: function shell_sendChromeEvent(details) { this.sendEvent(getContentWindow(), "mozChromeEvent", details); + }, + + receiveMessage: function shell_receiveMessage(message) { + if (message.name != 'content-handler') { + return; + } + let handler = message.json; + new MozActivity({ + name: 'view', + data: { + type: handler.type, + url: handler.url + } + }); } }; @@ -602,17 +626,6 @@ window.addEventListener('ContentStart', function ss_onContentStart() { }); }); -Services.obs.addObserver(function ContentHandler(subject, topic, data) { - let handler = JSON.parse(data); - new MozActivity({ - name: 'view', - data: { - type: handler.type, - url: handler.url - } - }); -}, 'content-handler', false); - (function geolocationStatusTracker() { let gGeolocationActiveCount = 0; diff --git a/b2g/components/ContentHandler.js b/b2g/components/ContentHandler.js index 26fa5dd300fb..e77bd37d42c8 100644 --- a/b2g/components/ContentHandler.js +++ b/b2g/components/ContentHandler.js @@ -13,6 +13,10 @@ const PDF_CONTENT_TYPE = "application/pdf"; Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/Services.jsm"); +XPCOMUtils.defineLazyGetter(this, "cpmm", function() { + return Cc["@mozilla.org/childprocessmessagemanager;1"].getService(Ci.nsIFrameMessageManager); +}); + function log(aMsg) { let msg = "ContentHandler.js: " + (aMsg.join ? aMsg.join("") : aMsg); Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService) @@ -36,7 +40,7 @@ ContentHandler.prototype = { "type": aMimetype, "url": aRequest.URI.spec }; - Services.obs.notifyObservers(this, "content-handler", JSON.stringify(detail)); + cpmm.sendAsyncMessage("content-handler", detail); aRequest.cancel(Cr.NS_BINDING_ABORTED); },