Bug 831108 - Process tab terminated (stop loading) on http://margaretleibovic.com/mural/. r=fabrice
authorGene Lian <clian@mozilla.com>
Fri, 18 Jan 2013 21:50:01 +0800
changeset 119385 01c964705be7d1481dde33d2c4dfbe913917241c
parent 119384 56efd49e70dd3994e07287b5a5bb1fd69327d98b
child 119386 4919e8091542aa7ea4204d833ddd4b735c45ab03
child 119402 3ffefc46a8bdd54083083cdb250e5615c7a92fed
push id24198
push userphilringnalda@gmail.com
push dateSun, 20 Jan 2013 20:46:18 +0000
treeherdermozilla-central@01c964705be7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfabrice
bugs831108
milestone21.0a1
first release with
nightly linux32
01c964705be7 / 21.0a1 / 20130121020044 / files
nightly linux64
01c964705be7 / 21.0a1 / 20130121020044 / files
nightly mac
01c964705be7 / 21.0a1 / 20130121020044 / files
nightly win32
01c964705be7 / 21.0a1 / 20130121020044 / files
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
Bug 831108 - Process tab terminated (stop loading) on http://margaretleibovic.com/mural/. r=fabrice
dom/messages/SystemMessageManager.js
--- a/dom/messages/SystemMessageManager.js
+++ b/dom/messages/SystemMessageManager.js
@@ -2,30 +2,31 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 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");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/ObjectWrapper.jsm");
 
 const kSystemMessageInternalReady = "system-message-internal-ready";
 
 XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
                                    "@mozilla.org/childprocessmessagemanager;1",
                                    "nsISyncMessageSender");
 
 function debug(aMsg) {
-  //dump("-- SystemMessageManager " + Date.now() + " : " + aMsg + "\n");
+   // dump("-- SystemMessageManager " + Date.now() + " : " + aMsg + "\n");
 }
 
 // Implementation of the DOM API for system messages
 
 function SystemMessageManager() {
   // Message handlers for this page.
   // We can have only one handler per message type.
   this._handlers = {};
@@ -76,17 +77,23 @@ SystemMessageManager.prototype = {
 
     // Notify the parent process the message is handled.
     cpmm.sendAsyncMessage("SystemMessageManager:HandleMessageDone",
                           { type: aType,
                             message: aMessage });
   },
 
   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;
     }
 
     let handlers = this._handlers;
     if (!aHandler) {
       // Setting the handler to null means we don't want to receive messages
@@ -101,16 +108,23 @@ SystemMessageManager.prototype = {
     // Ask for the list of currently pending messages.
     cpmm.sendAsyncMessage("SystemMessageManager:GetPendingMessages",
                           { type: aType,
                             uri: this._uri,
                             manifest: this._manifest });
   },
 
   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;
     }
 
     return cpmm.sendSyncMessage("SystemMessageManager:HasPendingMessages",
                                 { type: aType,
                                   uri: this._uri,
@@ -120,26 +134,32 @@ SystemMessageManager.prototype = {
   uninit: function sysMessMgr_uninit()  {
     this._handlers = null;
     this._pendings = null;
 
     if (this._isParentProcess) {
       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
                           });
   },
 
   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) {
       return;
     }
 
     if (aMessage.name == "SystemMessageManager:Message") {
       // Send an acknowledgement to parent to clean up the pending message,
@@ -169,16 +189,17 @@ SystemMessageManager.prototype = {
 
   // nsIDOMGlobalPropertyInitializer implementation.
   init: function sysMessMgr_init(aWindow) {
     debug("init");
     this.initHelper(aWindow, ["SystemMessageManager:Message",
                               "SystemMessageManager:GetPendingMessages:Return"]);
 
     let principal = aWindow.document.nodePrincipal;
+    this._isInBrowserElement = principal.isInBrowserElement;
     this._uri = principal.URI.spec;
 
     let appsService = Cc["@mozilla.org/AppsService;1"]
                         .getService(Ci.nsIAppsService);
     this._manifest = appsService.getManifestURLByLocalId(principal.appId);
 
     // Two cases are valid to register the manifest for the current process:
     // 1. This is asked by a child process (parent process must be ready).
@@ -203,16 +224,22 @@ SystemMessageManager.prototype = {
     if (aTopic === kSystemMessageInternalReady) {
       this._registerManifest();
     }
     // Call the DOMRequestIpcHelper.observe method.
     this.__proto__.__proto__.observe.call(this, aSubject, aTopic, aData);
   },
 
   _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,
                               innerWindowID: this.innerWindowID
                             });
       this._registerManifestReady = true;
     }
   },