Bug 1196514 - remove dom.messagechannel.enabled pref, r=smaug

This commit is contained in:
Andrea Marchesini 2015-08-20 08:34:38 +01:00
parent c8578157c2
commit ce594e8b18
28 changed files with 68 additions and 293 deletions

View File

@ -14,30 +14,27 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=913761
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=913761">Mozilla Bug 913761</a>
<script type="application/javascript">
function runTest() {
var transportChannel = new MessageChannel();
transportChannel.port1.onmessage = function (event) {
ok(true, 'Port Returned.');
var portToService = event.data.port;
portToService.onmessage = function (event) {
ok(true, "message received");
SimpleTest.finish();
};
portToService.postMessage('READY?');
}
var serviceChannel = new MessageChannel();
serviceChannel.port1.onmessage = function (event) {
if (event.data == 'READY?') {
this.postMessage('READY!');
}
}
transportChannel.port2.postMessage({ port: serviceChannel.port2}, [serviceChannel.port2]);
var transportChannel = new MessageChannel();
transportChannel.port1.onmessage = function (event) {
ok(true, 'Port Returned.');
var portToService = event.data.port;
portToService.onmessage = function (event) {
ok(true, "message received");
SimpleTest.finish();
};
portToService.postMessage('READY?');
}
var serviceChannel = new MessageChannel();
serviceChannel.port1.onmessage = function (event) {
if (event.data == 'READY?') {
this.postMessage('READY!');
}
}
transportChannel.port2.postMessage({ port: serviceChannel.port2}, [serviceChannel.port2]);
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]}, runTest);
</script>
</body>
</html>

View File

@ -107,7 +107,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=912456
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]}, runTest);
runTest();
</script>
</body>

View File

@ -385,7 +385,7 @@ function next() {
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]}, next);
next();
</script>
</body>
</html>

View File

@ -60,7 +60,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=848294
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]}, runTest);
runTest();
</script>
</body>
</html>

View File

@ -235,7 +235,6 @@ function setupEnvironment() {
SpecialPowers.pushPrefEnv({
'set': [
['canvas.capturestream.enabled', true],
['dom.messageChannel.enabled', true],
['media.peerconnection.enabled', true],
['media.peerconnection.identity.enabled', true],
['media.peerconnection.identity.timeout', 120000],

View File

@ -105,8 +105,7 @@ function testMultipleFingerprints() {
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({
set: [ [ 'dom.messageChannel.enabled', true ],
[ 'media.peerconnection.identity.enabled', true ] ]
set: [ [ 'media.peerconnection.identity.enabled', true ] ]
}, testMultipleFingerprints);
</script>
</body>

View File

@ -162,9 +162,7 @@ function run_all_tests() {
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({
set: [ [ 'dom.messageChannel.enabled', true ] ]
}, run_all_tests);
run_all_tests();
</script>
</body>
</html>

View File

@ -6,7 +6,6 @@
#include "MessageChannel.h"
#include "mozilla/Preferences.h"
#include "mozilla/dom/MessageChannelBinding.h"
#include "mozilla/dom/MessagePort.h"
#include "mozilla/dom/Navigator.h"
@ -30,149 +29,6 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MessageChannel)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
namespace {
bool gPrefInitialized = false;
bool gPrefEnabled = false;
bool
CheckPermission(nsIPrincipal* aPrincipal, bool aCallerChrome)
{
MOZ_ASSERT(NS_IsMainThread());
if (!gPrefInitialized) {
Preferences::AddBoolVarCache(&gPrefEnabled, "dom.messageChannel.enabled");
gPrefInitialized = true;
}
// Enabled by pref
if (gPrefEnabled) {
return true;
}
// Chrome callers are allowed.
if (aCallerChrome) {
return true;
}
nsCOMPtr<nsIURI> uri;
if (NS_FAILED(aPrincipal->GetURI(getter_AddRefs(uri))) || !uri) {
return false;
}
bool isResource = false;
if (NS_FAILED(uri->SchemeIs("resource", &isResource))) {
return false;
}
return isResource;
}
nsIPrincipal*
GetPrincipalFromWorkerPrivate(workers::WorkerPrivate* aWorkerPrivate)
{
MOZ_ASSERT(NS_IsMainThread());
nsIPrincipal* principal = aWorkerPrivate->GetPrincipal();
if (principal) {
return principal;
}
// Walk up to our containing page
workers::WorkerPrivate* wp = aWorkerPrivate;
while (wp->GetParent()) {
wp = wp->GetParent();
}
nsPIDOMWindow* window = wp->GetWindow();
if (!window) {
return nullptr;
}
nsIDocument* doc = window->GetExtantDoc();
if (!doc) {
return nullptr;
}
return doc->NodePrincipal();
}
// A WorkerMainThreadRunnable to synchronously dispatch the call of
// CheckPermission() from the worker thread to the main thread.
class CheckPermissionRunnable final : public workers::WorkerMainThreadRunnable
{
public:
bool mResult;
bool mCallerChrome;
explicit CheckPermissionRunnable(workers::WorkerPrivate* aWorkerPrivate)
: workers::WorkerMainThreadRunnable(aWorkerPrivate)
, mResult(false)
, mCallerChrome(false)
{
MOZ_ASSERT(aWorkerPrivate);
aWorkerPrivate->AssertIsOnWorkerThread();
mCallerChrome = aWorkerPrivate->UsesSystemPrincipal();
}
protected:
virtual bool
MainThreadRun() override
{
MOZ_ASSERT(NS_IsMainThread());
nsIPrincipal* principal = GetPrincipalFromWorkerPrivate(mWorkerPrivate);
if (!principal) {
return true;
}
bool isNullPrincipal;
nsresult rv = principal->GetIsNullPrincipal(&isNullPrincipal);
if (NS_WARN_IF(NS_FAILED(rv))) {
return true;
}
if (NS_WARN_IF(isNullPrincipal)) {
return true;
}
mResult = CheckPermission(principal, mCallerChrome);
return true;
}
};
} // namespace
/* static */ bool
MessageChannel::Enabled(JSContext* aCx, JSObject* aGlobal)
{
if (NS_IsMainThread()) {
JS::Rooted<JSObject*> global(aCx, aGlobal);
nsCOMPtr<nsPIDOMWindow> win = Navigator::GetWindowFromGlobal(global);
if (!win) {
return false;
}
nsIDocument* doc = win->GetExtantDoc();
if (!doc) {
return false;
}
return CheckPermission(doc->NodePrincipal(),
nsContentUtils::IsCallerChrome());
}
workers::WorkerPrivate* workerPrivate =
workers::GetWorkerPrivateFromContext(aCx);
workerPrivate->AssertIsOnWorkerThread();
nsRefPtr<CheckPermissionRunnable> runnable =
new CheckPermissionRunnable(workerPrivate);
runnable->Dispatch(aCx);
return runnable->mResult;
}
MessageChannel::MessageChannel(nsPIDOMWindow* aWindow)
: mWindow(aWindow)
{

View File

@ -28,9 +28,6 @@ public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(MessageChannel)
static bool Enabled(JSContext* aCx, JSObject* aGlobal);
public:
nsPIDOMWindow*
GetParentObject() const
{

View File

@ -14,7 +14,6 @@ support-files =
[test_messageChannel_cloning.html]
[test_messageChannel_pingpong.html]
[test_messageChannel_post.html]
[test_messageChannel_pref.html]
[test_messageChannel_start.html]
[test_messageChannel_transferable.html]
[test_messageChannel_unshipped.html]

View File

@ -21,29 +21,23 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=677638
</pre>
<script type="application/javascript">
function runTest() {
/** Test for Bug 677638 **/
var a = new MessageChannel();
ok(a, "MessageChannel created");
/** 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>

View File

@ -109,7 +109,7 @@ function runTest() {
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]}, runTest);
runTest();
</script>
</body>
</html>

View File

@ -32,7 +32,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1178076
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]}, runTest);
runTest();
</script>
</body>
</html>

View File

@ -64,7 +64,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=677638
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]}, runTest);
runTest();
</script>
</body>
</html>

View File

@ -16,21 +16,15 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1176034
</pre>
<script type="application/javascript">
function runTests() {
var mc = new MessageChannel();
var mc = new MessageChannel();
try {
postMessage(42, "*", [ mc.port1, window ]);
ok(false, "Something went wrong.");
} catch(e) {
ok(true, "PostMessage should fail and we should not leak.");
}
SimpleTest.finish();
try {
postMessage(42, "*", [ mc.port1, window ]);
ok(false, "Something went wrong.");
} catch(e) {
ok(true, "PostMessage should fail and we should not leak.");
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]}, runTests);
</script>
</body>
</html>

View File

@ -71,7 +71,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=677638
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]}, runTest);
runTest();
</script>
</body>
</html>

View File

@ -70,7 +70,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=677638
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]}, start);
start();
</script>
</body>
</html>

View File

@ -1,42 +0,0 @@
<!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?");
}
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", false]]},
function() {
runTest(false);
SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]},
function() {
runTest(true);
SimpleTest.finish();
});
});
</script>
</body>
</html>

View File

@ -16,7 +16,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=677638
</pre>
<script type="application/javascript">
function runTest() {
var a = new MessageChannel();
var status = false;
@ -27,11 +26,7 @@ function runTest() {
}
ok(status, "Transfering the same port should throw");
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]}, runTest);
</script>
</body>
</html>

View File

@ -20,19 +20,16 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=677638
</pre>
<script type="application/javascript">
function runTest() {
var a = new SharedWorker('sharedWorker_messageChannel.js');
a.port.onmessage = function(evt) {
is(evt.ports.length, 1, "We received a port.");
evt.ports[0].onmessage = function(e) {
is(e.data, 42, "Message reiceved back!");
SimpleTest.finish();
}
evt.ports[0].postMessage(42);
var a = new SharedWorker('sharedWorker_messageChannel.js');
a.port.onmessage = function(evt) {
is(evt.ports.length, 1, "We received a port.");
evt.ports[0].onmessage = function(e) {
is(e.data, 42, "Message reiceved back!");
SimpleTest.finish();
}
evt.ports[0].postMessage(42);
}
SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]}, runTest);
SimpleTest.waitForExplicitFinish();
</script>
</body>

View File

@ -15,22 +15,19 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=677638
<script type="application/javascript">
function runTest() {
var iframe = document.createElement('iframe');
iframe.setAttribute('src', "iframe_messageChannel_sharedWorker2.html");
document.getElementById('content').appendChild(iframe);
var iframe = document.createElement('iframe');
iframe.setAttribute('src', "iframe_messageChannel_sharedWorker2.html");
document.getElementById('content').appendChild(iframe);
var a = new SharedWorker('sharedWorker2_messageChannel.js');
a.port.onmessage = function(evt) {
is(evt.ports.length, 1, "We received a port.");
evt.ports[0].onmessage = function(e) {
is(e.data, "Hello from the iframe!", "Message reiceved from the iframe!");
SimpleTest.finish();
}
var a = new SharedWorker('sharedWorker2_messageChannel.js');
a.port.onmessage = function(evt) {
is(evt.ports.length, 1, "We received a port.");
evt.ports[0].onmessage = function(e) {
is(e.data, "Hello from the iframe!", "Message reiceved from the iframe!");
SimpleTest.finish();
}
}
SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]}, runTest);
SimpleTest.waitForExplicitFinish();
</script>
</body>

View File

@ -229,7 +229,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=677638
SimpleTest.waitForExplicitFinish();
SimpleTest.requestFlakyTimeout("untriaged");
SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]}, runTests);
runTests();
</script>
</body>
</html>

View File

@ -105,7 +105,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=677638
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]}, runTests);
runTests();
</script>
</body>
</html>

View File

@ -117,7 +117,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=677638
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]}, runTests);
runTests();
</script>
</body>
</html>

View File

@ -54,7 +54,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=677638
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]}, runTests);
runTests();
</script>
</body>
</html>

View File

@ -7,8 +7,7 @@
* http://www.whatwg.org/specs/web-apps/current-work/#channel-messaging
*/
[Constructor, Func="MessageChannel::Enabled",
Exposed=(Window,Worker)]
[Constructor, Exposed=(Window,Worker)]
interface MessageChannel {
readonly attribute MessagePort port1;
readonly attribute MessagePort port2;

View File

@ -202,7 +202,6 @@
SpecialPowers.pushPrefEnv({"set": [
["dom.serviceWorkers.exemptFromPerDomainMax", true],
["dom.serviceWorkers.interception.enabled", true],
["dom.messageChannel.enabled", true],
["dom.serviceWorkers.enabled", true],
["dom.serviceWorkers.testing.enabled", true],
["dom.caches.testing.enabled", true],

View File

@ -4885,9 +4885,6 @@ pref("dom.system_update.debug", false);
// UDPSocket API
pref("dom.udpsocket.enabled", false);
// MessageChannel enabled by default.
pref("dom.messageChannel.enabled", true);
// Disable before keyboard events and after keyboard events by default.
pref("dom.beforeAfterKeyboardEvent.enabled", false);