diff --git a/dom/base/WebSocket.cpp b/dom/base/WebSocket.cpp index 09101c43566a..8395f1e2f2e3 100644 --- a/dom/base/WebSocket.cpp +++ b/dom/base/WebSocket.cpp @@ -1666,18 +1666,17 @@ WebSocketImpl::Init(JSContext* aCx, nsCOMPtr innerWindow; while (true) { - if (principal) { - bool isNullPrincipal = true; - isNullPrincipal = principal->GetIsNullPrincipal(); - if (isNullPrincipal || nsContentUtils::IsSystemPrincipal(principal)) { - break; - } + if (principal && !principal->GetIsNullPrincipal()) { + break; } if (!innerWindow) { innerWindow = do_QueryInterface(globalObject); - if (NS_WARN_IF(!innerWindow)) { - return NS_ERROR_DOM_SECURITY_ERR; + if (!innerWindow) { + // If we are in a XPConnect sandbox or in a JS component, + // innerWindow will be null. There is nothing on top of this to be + // considered. + break; } } diff --git a/dom/base/test/iframe_webSocket_sandbox.html b/dom/base/test/iframe_webSocket_sandbox.html new file mode 100644 index 000000000000..ba14d92e5620 --- /dev/null +++ b/dom/base/test/iframe_webSocket_sandbox.html @@ -0,0 +1,62 @@ + + + + diff --git a/dom/base/test/mochitest.ini b/dom/base/test/mochitest.ini index 670dd5ae0a06..5d59fe1ea7b8 100644 --- a/dom/base/test/mochitest.ini +++ b/dom/base/test/mochitest.ini @@ -804,6 +804,9 @@ skip-if = toolkit == 'android' skip-if = toolkit == 'android' [test_websocket_permessage_deflate.html] skip-if = toolkit == 'android' +[test_webSocket_sandbox.html] +skip-if = toolkit == 'android' +support-files = iframe_webSocket_sandbox.html [test_websocket1.html] skip-if = toolkit == 'android' [test_websocket2.html] diff --git a/dom/base/test/test_webSocket_sandbox.html b/dom/base/test/test_webSocket_sandbox.html new file mode 100644 index 000000000000..b343fa784f39 --- /dev/null +++ b/dom/base/test/test_webSocket_sandbox.html @@ -0,0 +1,34 @@ + + + + Bug 1252751 + + + + +
+ + + +