Bug 677638 - MessageChannel and MessagePort disabled by pref, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 03 Sep 2013 14:39:03 +0200
changeset 145322 7c90e8e1b481a36958f06a24ae93b8e0568055fa
parent 145321 56da783d3638eafaf50ed34154eb4879199ff7ee
child 145323 192825330b3e4674d239f4563188dfb772ef7f25
push id33230
push useramarchesini@mozilla.com
push dateTue, 03 Sep 2013 12:39:37 +0000
treeherdermozilla-inbound@7c90e8e1b481 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs677638
milestone26.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 677638 - MessageChannel and MessagePort disabled by pref, r=smaug
dom/base/MessageChannel.cpp
dom/base/MessageChannel.h
dom/base/nsGlobalWindow.cpp
dom/base/test/Makefile.in
dom/base/test/test_messageChannel.html
dom/base/test/test_messageChannel_cloning.html
dom/base/test/test_messageChannel_pingpong.html
dom/base/test/test_messageChannel_post.html
dom/base/test/test_messageChannel_pref.html
dom/base/test/test_messageChannel_start.html
dom/base/test/test_messageChannel_transferable.html
dom/base/test/test_messageChannel_unshipped.html
dom/webidl/MessageChannel.webidl
dom/webidl/MessagePort.webidl
--- a/dom/base/MessageChannel.cpp
+++ b/dom/base/MessageChannel.cpp
@@ -1,14 +1,15 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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/. */
 
 #include "MessageChannel.h"
+#include "mozilla/Preferences.h"
 #include "mozilla/dom/MessageChannelBinding.h"
 #include "mozilla/dom/MessagePort.h"
 #include "nsContentUtils.h"
 #include "nsPIDOMWindow.h"
 
 namespace mozilla {
 namespace dom {
 
@@ -16,16 +17,34 @@ NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_3(
 NS_IMPL_CYCLE_COLLECTING_ADDREF(MessageChannel)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(MessageChannel)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MessageChannel)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
   NS_INTERFACE_MAP_ENTRY(nsISupports)
 NS_INTERFACE_MAP_END
 
+namespace {
+  bool gPrefInitialized = false;
+  bool gPrefEnabled = false;
+
+}
+
+
+/* static */ bool
+MessageChannel::PrefEnabled()
+{
+  if (!gPrefInitialized) {
+    Preferences::AddBoolVarCache(&gPrefEnabled, "dom.messageChannel.enabled");
+    gPrefInitialized = true;
+  }
+
+  return gPrefEnabled;
+}
+
 MessageChannel::MessageChannel(nsPIDOMWindow* aWindow)
   : mWindow(aWindow)
 {
   MOZ_COUNT_CTOR(MessageChannel);
   SetIsDOMBinding();
 
   mPort1 = new MessagePort(mWindow);
   mPort2 = new MessagePort(mWindow);
--- a/dom/base/MessageChannel.h
+++ b/dom/base/MessageChannel.h
@@ -23,16 +23,18 @@ class MessagePort;
 
 class MessageChannel MOZ_FINAL : public nsISupports
                                , public nsWrapperCache
 {
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(MessageChannel)
 
+  static bool PrefEnabled();
+
 public:
   MessageChannel(nsPIDOMWindow* aWindow);
 
   ~MessageChannel();
 
   nsPIDOMWindow*
   GetParentObject() const
   {
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -184,16 +184,17 @@
 #ifdef MOZ_LOGGING
 // so we can get logging even in release builds
 #define FORCE_PR_LOG 1
 #endif
 #include "prlog.h"
 #include "prenv.h"
 #include "prprf.h"
 
+#include "mozilla/dom/MessageChannel.h"
 #include "mozilla/dom/MessagePort.h"
 #include "mozilla/dom/MessagePortBinding.h"
 #include "mozilla/dom/indexedDB/IDBFactory.h"
 #include "mozilla/dom/quota/QuotaManager.h"
 
 #include "mozilla/dom/StructuredCloneTags.h"
 
 #ifdef MOZ_GAMEPAD
@@ -6777,17 +6778,17 @@ PostMessageReadStructuredClone(JSContext
                                                     val.address(),
                                                     getter_AddRefs(wrapper)))) {
           return JSVAL_TO_OBJECT(val);
         }
       }
     }
   }
 
-  if (tag == SCTAG_DOM_MESSAGEPORT) {
+  if (MessageChannel::PrefEnabled() && tag == SCTAG_DOM_MESSAGEPORT) {
     NS_ASSERTION(!data, "Data should be empty");
 
     MessagePort* port;
     if (JS_ReadBytes(reader, &port, sizeof(port))) {
       JS::Rooted<JSObject*> global(cx, JS::CurrentGlobalOrNull(cx));
       if (global) {
         JS::Rooted<JSObject*> obj(cx, port->WrapObject(cx, global));
         if (JS_WrapObject(cx, obj.address())) {
@@ -6832,24 +6833,26 @@ PostMessageWriteStructuredClone(JSContex
       scTag = SCTAG_DOM_FILELIST;
 
     if (scTag)
       return JS_WriteUint32Pair(writer, scTag, 0) &&
              JS_WriteBytes(writer, &supports, sizeof(supports)) &&
              scInfo->event->StoreISupports(supports);
   }
 
-  MessagePort* port = nullptr;
-  nsresult rv = UNWRAP_OBJECT(MessagePort, cx, obj, port);
-  if (NS_SUCCEEDED(rv) && scInfo->subsumes) {
-    nsRefPtr<MessagePort> newPort = port->Clone(scInfo->window);
-
-    return JS_WriteUint32Pair(writer, SCTAG_DOM_MESSAGEPORT, 0) &&
-           JS_WriteBytes(writer, &newPort, sizeof(newPort)) &&
-           scInfo->event->StoreISupports(newPort);
+  if (MessageChannel::PrefEnabled()) {
+    MessagePort* port = nullptr;
+    nsresult rv = UNWRAP_OBJECT(MessagePort, cx, obj, port);
+    if (NS_SUCCEEDED(rv) && scInfo->subsumes) {
+      nsRefPtr<MessagePort> newPort = port->Clone(scInfo->window);
+
+      return JS_WriteUint32Pair(writer, SCTAG_DOM_MESSAGEPORT, 0) &&
+             JS_WriteBytes(writer, &newPort, sizeof(newPort)) &&
+             scInfo->event->StoreISupports(newPort);
+    }
   }
 
   const JSStructuredCloneCallbacks* runtimeCallbacks =
     js::GetContextStructuredCloneCallbacks(cx);
 
   if (runtimeCallbacks) {
     return runtimeCallbacks->write(cx, writer, obj, nullptr);
   }
--- a/dom/base/test/Makefile.in
+++ b/dom/base/test/Makefile.in
@@ -36,16 +36,17 @@ MOCHITEST_FILES = \
   iframe_messageChannel_cloning.html \
   test_messageChannel_post.html \
   iframe_messageChannel_post.html \
   test_messageChannel_transferable.html \
   test_messageChannel_start.html \
   test_messageChannel_pingpong.html \
   iframe_messageChannel_pingpong.html \
   test_messageChannel_unshipped.html \
+  test_messageChannel_pref.html \
   $(NULL)
 
 MOCHITEST_CHROME_FILES = \
    test_bug715041.xul \
    test_bug715041_removal.xul \
    test_domrequesthelper.xul \
    $(NULL)
 
--- a/dom/base/test/test_messageChannel.html
+++ b/dom/base/test/test_messageChannel.html
@@ -16,28 +16,34 @@ https://bugzilla.mozilla.org/show_bug.cg
 <div id="content" style="display: none">
   <iframe name="x" id="x"></iframe>
   <iframe name="y" id="y"></iframe>
 </div>
 <pre id="test">
 </pre>
   <script type="application/javascript">
 
-  /** Test for Bug 677638 **/
-  var a = new MessageChannel();
-  ok(a, "MessageChannel created");
+  function runTest() {
+    /** Test for Bug 677638 **/
+    var a = new MessageChannel();
+    ok(a, "MessageChannel created");
 
-  var port1 = a.port1;
-  ok(port1, "MessageChannel.port1 exists");
-  is(port1, a.port1, "MessageChannel.port1 is port1");
+    var port1 = a.port1;
+    ok(port1, "MessageChannel.port1 exists");
+    is(port1, a.port1, "MessageChannel.port1 is port1");
 
-  var port2 = a.port2;
-  ok(port2, "MessageChannel.port1 exists");
-  is(port2, a.port2, "MessageChannel.port2 is port2");
+    var port2 = a.port2;
+    ok(port2, "MessageChannel.port1 exists");
+    is(port2, a.port2, "MessageChannel.port2 is port2");
 
-  [ 'postMessage', 'start', 'close' ].forEach(function(e) {
-    ok(e in port1, "MessagePort1." + e + " exists");
-    ok(e in port2, "MessagePort2." + e + " exists");
-  });
+    [ 'postMessage', 'start', 'close' ].forEach(function(e) {
+      ok(e in port1, "MessagePort1." + e + " exists");
+      ok(e in port2, "MessagePort2." + e + " exists");
+    });
 
+    SimpleTest.finish();
+  }
+
+  SimpleTest.waitForExplicitFinish();
+  SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]}, runTest);
   </script>
 </body>
 </html>
--- a/dom/base/test/test_messageChannel_cloning.html
+++ b/dom/base/test/test_messageChannel_cloning.html
@@ -59,12 +59,12 @@ https://bugzilla.mozilla.org/show_bug.cg
       return;
     }
 
     var test = tests.shift();
     test();
   }
 
   SimpleTest.waitForExplicitFinish();
-  runTest();
+  SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]}, runTest);
   </script>
 </body>
 </html>
--- a/dom/base/test/test_messageChannel_pingpong.html
+++ b/dom/base/test/test_messageChannel_pingpong.html
@@ -11,64 +11,67 @@ https://bugzilla.mozilla.org/show_bug.cg
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=677638">Mozilla Bug 677638</a>
 <div id="content"></div>
 <pre id="test">
 </pre>
   <script type="application/javascript">
 
-  var MAX = 100;
+  function runTest() {
+    var MAX = 100;
 
-  var a = new MessageChannel();
-  ok(a, "MessageChannel created");
+    var a = new MessageChannel();
+    ok(a, "MessageChannel created");
+
+    // Populate the message queue of this port.
+    for (var i = 0; i < MAX; ++i) {
+      a.port1.postMessage(i);
+    }
 
-  // Populate the message queue of this port.
-  for (var i = 0; i < MAX; ++i) {
-    a.port1.postMessage(i);
-  }
+    window.addEventListener('message', receiveMessage, false);
+    function receiveMessage(evt) {
 
-  window.addEventListener('message', receiveMessage, false);
-  function receiveMessage(evt) {
+      // This test sends the port from this window to the iframe and viceversa.
+      if (evt.data.type == 'PORT') {
+        var port = evt.data.port;
+        var counter = 0;
+        port.onmessage = function(evt) {
+          // only 1 message should be received by this port.
+          if (counter++ == 0) {
+            ok(evt.data % 2, "The number " + evt.data + " has been received correctly by the main window");
 
-    // This test sends the port from this window to the iframe and viceversa.
-    if (evt.data.type == 'PORT') {
-      var port = evt.data.port;
-      var counter = 0;
-      port.onmessage = function(evt) {
-        // only 1 message should be received by this port.
-        if (counter++ == 0) {
-          ok(evt.data % 2, "The number " + evt.data + " has been received correctly by the main window");
-
-          if (evt.data < MAX - 1) {
-            ifr.contentWindow.postMessage({ type: 'PORT', port: port }, '*');
+            if (evt.data < MAX - 1) {
+              ifr.contentWindow.postMessage({ type: 'PORT', port: port }, '*');
+            } else {
+              SimpleTest.finish();
+            }
           } else {
-            SimpleTest.finish();
+            ok(false, "Wrong message!");
           }
-        } else {
-          ok(false, "Wrong message!");
         }
+      } else if (evt.data.type == 'OK') {
+        ok(true, evt.data.msg);
+      } else if (evt.data.type == 'KO') {
+        ok(false, evt.data.msg);
+      } else {
+        ok(false, "Unknown message");
       }
-    } else if (evt.data.type == 'OK') {
-      ok(true, evt.data.msg);
-    } else if (evt.data.type == 'KO') {
-      ok(false, evt.data.msg);
-    } else {
-      ok(false, "Unknown message");
+    }
+
+    var div = document.getElementById("content");
+    ok(div, "Parent exists");
+
+    var ifr = document.createElement("iframe");
+    ifr.addEventListener("load", iframeLoaded, false);
+    ifr.setAttribute('src', "iframe_messageChannel_pingpong.html");
+    div.appendChild(ifr);
+
+    function iframeLoaded() {
+      ifr.contentWindow.postMessage({ type: 'PORT', port: a.port2 }, '*');
     }
   }
 
-  var div = document.getElementById("content");
-  ok(div, "Parent exists");
-
-  var ifr = document.createElement("iframe");
-  ifr.addEventListener("load", iframeLoaded, false);
-  ifr.setAttribute('src', "iframe_messageChannel_pingpong.html");
-  div.appendChild(ifr);
-
-  function iframeLoaded() {
-    ifr.contentWindow.postMessage({ type: 'PORT', port: a.port2 }, '*');
-  }
-
   SimpleTest.waitForExplicitFinish();
+  SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]}, runTest);
   </script>
 </body>
 </html>
--- a/dom/base/test/test_messageChannel_post.html
+++ b/dom/base/test/test_messageChannel_post.html
@@ -11,59 +11,62 @@ https://bugzilla.mozilla.org/show_bug.cg
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=677638">Mozilla Bug 677638</a>
 <div id="content"></div>
 <pre id="test">
 </pre>
   <script type="application/javascript">
 
-  var a = new MessageChannel();
-  ok(a, "MessageChannel created");
+  function start() {
+    var a = new MessageChannel();
+    ok(a, "MessageChannel created");
+
+    window.addEventListener('message', receiveMessage, false);
+    function receiveMessage(evt) {
+      if (evt.data.status == 'READY') {
+        runTest();
+      } else {
+        ok(false, "Unknown message");
+      }
+    }
+
+    var div = document.getElementById("content");
+    ok(div, "Parent exists");
+
+    var ifr = document.createElement("iframe");
+    ifr.addEventListener("load", iframeLoaded, false);
+    ifr.setAttribute('src', "iframe_messageChannel_post.html");
+    div.appendChild(ifr);
 
-  window.addEventListener('message', receiveMessage, false);
-  function receiveMessage(evt) {
-    if (evt.data.status == 'READY') {
+    function iframeLoaded() {
+      ifr.contentWindow.postMessage({ port: a.port2 }, '*');
+    }
+
+    var tests = [ 42,
+                  null,
+                  undefined,
+                  "hello world",
+                  new Blob([]),
+                  true ];
+
+    a.port1.onmessage = function(evt) {
+      ok(tests.length, "We are waiting for a message");
+      is(tests[0], evt.data, "Value ok: " + tests[0]);
+      tests.shift();
       runTest();
-    } else {
-      ok(false, "Unknown message");
+    }
+
+    function runTest() {
+      if (!tests.length) {
+        SimpleTest.finish();
+        return;
+      }
+
+      a.port1.postMessage(tests[0]);
     }
   }
 
-  var div = document.getElementById("content");
-  ok(div, "Parent exists");
-
-  var ifr = document.createElement("iframe");
-  ifr.addEventListener("load", iframeLoaded, false);
-  ifr.setAttribute('src', "iframe_messageChannel_post.html");
-  div.appendChild(ifr);
-
-  function iframeLoaded() {
-    ifr.contentWindow.postMessage({ port: a.port2 }, '*');
-  }
-
-  var tests = [ 42,
-                null,
-                undefined,
-                "hello world",
-                new Blob([]),
-                true ];
-
-  a.port1.onmessage = function(evt) {
-    ok(tests.length, "We are waiting for a message");
-    is(tests[0], evt.data, "Value ok: " + tests[0]);
-    tests.shift();
-    runTest();
-  }
-
-  function runTest() {
-    if (!tests.length) {
-      SimpleTest.finish();
-      return;
-    }
-
-    a.port1.postMessage(tests[0]);
-  }
-
   SimpleTest.waitForExplicitFinish();
+  SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]}, start);
   </script>
 </body>
 </html>
new file mode 100644
--- /dev/null
+++ b/dom/base/test/test_messageChannel_pref.html
@@ -0,0 +1,42 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=677638
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 677638 - pref</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=677638">Mozilla Bug 677638</a>
+<div id="content"></div>
+<pre id="test">
+</pre>
+  <script type="application/javascript">
+
+  function runTest(what) {
+    var status;
+    try {
+      status = MessageChannel;
+      ok(what, "Should MessageChannel exist?");
+    } catch(e) {
+      ok(!what, "Should MessageChannel exist?");
+    }
+    try {
+      status = MessagePort;
+      ok(what, "Should MessagePort exist?");
+    } catch(e) {
+      ok(!what, "Should MessagePort exist?");
+    }
+  }
+
+  SimpleTest.waitForExplicitFinish();
+
+  runTest(false);
+  SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]},
+                            function() { runTest(true); SimpleTest.finish(); });
+  </script>
+</body>
+</html>
--- a/dom/base/test/test_messageChannel_start.html
+++ b/dom/base/test/test_messageChannel_start.html
@@ -223,12 +223,12 @@ https://bugzilla.mozilla.org/show_bug.cg
     testAddEventListener1AndStart,
     testAddEventListener2AndStart,
     testTimer,
     testAddEventListenerAndStartWrongOrder,
     testOnMessageClone,
   ];
 
   SimpleTest.waitForExplicitFinish();
-  runTests();
+  SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]}, runTests);
   </script>
 </body>
 </html>
--- a/dom/base/test/test_messageChannel_transferable.html
+++ b/dom/base/test/test_messageChannel_transferable.html
@@ -11,54 +11,57 @@ https://bugzilla.mozilla.org/show_bug.cg
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=677638">Mozilla Bug 677638</a>
 <div id="content"></div>
 <pre id="test">
 </pre>
   <script type="application/javascript">
 
-  var a = new MessageChannel();
-  ok(a, "MessageChannel created");
+  function start() {
+    var a = new MessageChannel();
+    ok(a, "MessageChannel created");
+
+    window.addEventListener('message', receiveMessage, false);
+    function receiveMessage(evt) {
+      if (evt.data.status == 'READY') {
+        runTest();
+      } else {
+        ok(false, "Unknown message");
+      }
+    }
+
+    var div = document.getElementById("content");
+    ok(div, "Parent exists");
+
+    var ifr = document.createElement("iframe");
+    ifr.addEventListener("load", iframeLoaded, false);
+    ifr.setAttribute('src', "iframe_messageChannel_post.html");
+    div.appendChild(ifr);
 
-  window.addEventListener('message', receiveMessage, false);
-  function receiveMessage(evt) {
-    if (evt.data.status == 'READY') {
-      runTest();
-    } else {
-      ok(false, "Unknown message");
+    function iframeLoaded() {
+      ifr.contentWindow.postMessage({ port: a.port2 }, '*');
+    }
+
+    a.port1.addEventListener('message', receivePortMessage, false);
+    function receivePortMessage(evt) {
+      is(evt.data.ab.byteLength, size, "The size is: " + size + " == " + ab.byteLength);
+      SimpleTest.finish();
+    }
+
+    // Start() is not implicity invoked when addEventListener is used.
+    a.port1.start();
+
+    var size = 1024 * 1024 * 32;
+    var ab = new ArrayBuffer(size);
+    is(ab.byteLength, size, "The size is: " + size + " == " + ab.byteLength);
+
+    function runTest() {
+      a.port1.postMessage({ab: ab, cb: ab}, [ab]);
+      ok(ab.byteLength == 0, "PostMessage - The size is: 0 == " + ab.byteLength)
     }
   }
 
-  var div = document.getElementById("content");
-  ok(div, "Parent exists");
-
-  var ifr = document.createElement("iframe");
-  ifr.addEventListener("load", iframeLoaded, false);
-  ifr.setAttribute('src', "iframe_messageChannel_post.html");
-  div.appendChild(ifr);
-
-  function iframeLoaded() {
-    ifr.contentWindow.postMessage({ port: a.port2 }, '*');
-  }
-
-  a.port1.addEventListener('message', receivePortMessage, false);
-  function receivePortMessage(evt) {
-    is(evt.data.ab.byteLength, size, "The size is: " + size + " == " + ab.byteLength);
-    SimpleTest.finish();
-  }
-
-  // Start() is not implicity invoked when addEventListener is used.
-  a.port1.start();
-
-  var size = 1024 * 1024 * 32;
-  var ab = new ArrayBuffer(size);
-  is(ab.byteLength, size, "The size is: " + size + " == " + ab.byteLength);
-
-  function runTest() {
-    a.port1.postMessage({ab: ab, cb: ab}, [ab]);
-    ok(ab.byteLength == 0, "PostMessage - The size is: 0 == " + ab.byteLength)
-  }
-
   SimpleTest.waitForExplicitFinish();
+  SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]}, start);
   </script>
 </body>
 </html>
--- a/dom/base/test/test_messageChannel_unshipped.html
+++ b/dom/base/test/test_messageChannel_unshipped.html
@@ -112,12 +112,12 @@ https://bugzilla.mozilla.org/show_bug.cg
       return;
     }
 
     var test = tests.shift();
     test();
   }
 
   SimpleTest.waitForExplicitFinish();
-  runTests();
+  SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]}, runTests);
   </script>
 </body>
 </html>
--- a/dom/webidl/MessageChannel.webidl
+++ b/dom/webidl/MessageChannel.webidl
@@ -2,13 +2,13 @@
 /* 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/.
  *
  * For more information on this interface, please see
  * http://www.whatwg.org/specs/web-apps/current-work/#channel-messaging
  */
 
-[Constructor]
+[Constructor, Pref="dom.messageChannel.enabled"]
 interface MessageChannel {
   readonly attribute MessagePort port1;
   readonly attribute MessagePort port2;
 };
--- a/dom/webidl/MessagePort.webidl
+++ b/dom/webidl/MessagePort.webidl
@@ -2,16 +2,17 @@
 /* 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/.
  *
  * For more information on this interface, please see
  * http://www.whatwg.org/specs/web-apps/current-work/#channel-messaging
  */
 
+[Pref="dom.messageChannel.enabled"]
 interface MessagePort : EventTarget {
   // TODO void postMessage(any message, optional sequence<Transferable> transfer);
   [Throws]
   void postMessage(any message, optional any transfer);
 
   void start();
   void close();