Bug 1473828 - Use weak message manager listener to have message data be in sandbox compartment. r=jryans draft
authorAlexandre Poirot <poirot.alex@gmail.com>
Tue, 10 Jul 2018 15:10:19 -0700
changeset 817249 6846844aff20218441ac16b6dbd4f38ac5296b25
parent 817222 fcbee921a4cfd861bbaea4cd644d70f16cae74c7
push id116005
push userbmo:poirot.alex@gmail.com
push dateThu, 12 Jul 2018 10:03:18 +0000
reviewersjryans
bugs1473828
milestone63.0a1
Bug 1473828 - Use weak message manager listener to have message data be in sandbox compartment. r=jryans MozReview-Commit-ID: 4xWAZSv6FA2
devtools/shared/transport/child-transport.js
devtools/shared/worker/loader.js
--- a/devtools/shared/transport/child-transport.js
+++ b/devtools/shared/transport/child-transport.js
@@ -1,15 +1,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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 { Cr } = require("chrome");
+const { Ci, Cr } = require("chrome");
+const ChromeUtils = require("ChromeUtils");
 const flags = require("devtools/shared/flags");
 
 /**
  * A transport for the debugging protocol that uses nsIMessageManagers to
  * exchange packets with servers running in child processes.
  *
  * In the parent process, |mm| should be the nsIMessageSender for the
  * child process. In a child process, |mm| should be the child process
@@ -31,23 +32,25 @@ function ChildDebuggerTransport(mm, pref
  * nsIMessageSender conveys, and 'packet' to mean a remote debugging
  * protocol packet.
  */
 ChildDebuggerTransport.prototype = {
   constructor: ChildDebuggerTransport,
 
   hooks: null,
 
+  QueryInterface: ChromeUtils.generateQI([Ci.nsISupportsWeakReference]),
+
   _addListener() {
-    this._mm.addMessageListener(this._messageName, this);
+    this._mm.addWeakMessageListener(this._messageName, this);
   },
 
   _removeListener() {
     try {
-      this._mm.removeMessageListener(this._messageName, this);
+      this._mm.removeWeakMessageListener(this._messageName, this);
     } catch (e) {
       if (e.result != Cr.NS_ERROR_NULL_POINTER) {
         throw e;
       }
       // In some cases, especially when using messageManagers in non-e10s mode, we reach
       // this point with a dead messageManager which only throws errors but does not
       // seem to indicate in any other way that it is dead.
     }
--- a/devtools/shared/worker/loader.js
+++ b/devtools/shared/worker/loader.js
@@ -564,16 +564,17 @@ this.worker = new WorkerDebuggerLoader({
     "lazyRequireModule": lazyRequireModule,
     "retrieveConsoleEvents": this.retrieveConsoleEvents,
     "setConsoleEventHandler": this.setConsoleEventHandler,
   },
   loadSubScript: loadSubScript,
   modules: {
     "Debugger": Debugger,
     "Services": Object.create(null),
+    "ChromeUtils": Object.create(null),
     "chrome": chrome,
     "xpcInspector": xpcInspector
   },
   paths: {
     // ⚠ DISCUSSION ON DEV-DEVELOPER-TOOLS REQUIRED BEFORE MODIFYING ⚠
     "devtools": "resource://devtools",
     // ⚠ DISCUSSION ON DEV-DEVELOPER-TOOLS REQUIRED BEFORE MODIFYING ⚠
     "promise": "resource://gre/modules/Promise-backend.js",