From ae6a8b4355b2e0a7062037f06c3ea359b42bb4d5 Mon Sep 17 00:00:00 2001 From: Gene Lian Date: Fri, 18 Jan 2013 21:50:01 +0800 Subject: [PATCH] Bug 831108 - Process tab terminated (stop loading) on http://margaretleibovic.com/mural/. r=fabrice --- dom/messages/SystemMessageManager.js | 37 ++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/dom/messages/SystemMessageManager.js b/dom/messages/SystemMessageManager.js index 4c4cd192a30..d99f8eefacc 100644 --- a/dom/messages/SystemMessageManager.js +++ b/dom/messages/SystemMessageManager.js @@ -7,6 +7,7 @@ const Cc = Components.classes; const Ci = Components.interfaces; const Cu = Components.utils; +const Cr = Components.results; Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/DOMRequestHelper.jsm"); @@ -20,7 +21,7 @@ XPCOMUtils.defineLazyServiceGetter(this, "cpmm", "nsISyncMessageSender"); function debug(aMsg) { - //dump("-- SystemMessageManager " + Date.now() + " : " + aMsg + "\n"); + // dump("-- SystemMessageManager " + Date.now() + " : " + aMsg + "\n"); } // Implementation of the DOM API for system messages @@ -81,7 +82,13 @@ SystemMessageManager.prototype = { }, mozSetMessageHandler: function sysMessMgr_setMessageHandler(aType, aHandler) { - debug("setMessage handler for [" + aType + "] " + aHandler); + debug("set message handler for [" + aType + "] " + aHandler); + + if (this._isInBrowserElement) { + debug("the app loaded in the browser cannot set message handler"); + throw Cr.NS_ERROR_FAILURE; + } + if (!aType) { // Just bail out if we have no type. return; @@ -106,6 +113,13 @@ SystemMessageManager.prototype = { }, mozHasPendingMessage: function sysMessMgr_hasPendingMessage(aType) { + debug("asking pending message for [" + aType + "]"); + + if (this._isInBrowserElement) { + debug("the app loaded in the browser cannot ask pending message"); + throw Cr.NS_ERROR_FAILURE; + } + // If we have a handler for this type, we can't have any pending message. if (aType in this._handlers) { return false; @@ -125,6 +139,12 @@ SystemMessageManager.prototype = { Services.obs.removeObserver(this, kSystemMessageInternalReady); } + if (this._isInBrowserElement) { + debug("the app loaded in the browser doesn't need to unregister " + + "the manifest for listening to the system messages"); + return; + } + cpmm.sendAsyncMessage("SystemMessageManager:Unregister", { manifest: this._manifest, innerWindowID: this.innerWindowID @@ -132,9 +152,9 @@ SystemMessageManager.prototype = { }, receiveMessage: function sysMessMgr_receiveMessage(aMessage) { - debug("receiveMessage " + aMessage.name + " - " + - aMessage.data.type + " for " + aMessage.data.manifest + - " (" + this._manifest + ")"); + debug("receiveMessage " + aMessage.name + " for [" + aMessage.data.type + "] " + + "with manifest = " + aMessage.data.manifest + " (" + this._manifest + ") " + + "and uri = " + aMessage.data.uri + " (" + this._uri + ")"); let msg = aMessage.data; if (msg.manifest != this._manifest || msg.uri != this._uri) { @@ -174,6 +194,7 @@ SystemMessageManager.prototype = { "SystemMessageManager:GetPendingMessages:Return"]); let principal = aWindow.document.nodePrincipal; + this._isInBrowserElement = principal.isInBrowserElement; this._uri = principal.URI.spec; let appsService = Cc["@mozilla.org/AppsService;1"] @@ -208,6 +229,12 @@ SystemMessageManager.prototype = { }, _registerManifest: function sysMessMgr_registerManifest() { + if (this._isInBrowserElement) { + debug("the app loaded in the browser doesn't need to register " + + "the manifest for listening to the system messages"); + return; + } + if (!this._registerManifestReady) { cpmm.sendAsyncMessage("SystemMessageManager:Register", { manifest: this._manifest,