Bug 1142727 - Do not intercept sandboxed iframes with service workers; r=nsm
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 24 Mar 2015 13:59:07 -0400
changeset 265743 2c2fa3984d844d598cb231c1f10637cd92db2452
parent 265742 6773b2f30d90ba25c0d29cff8375695e65bb3617
child 265744 0d8119189d66bb56028d2e31cf00b5d4612f265f
push id830
push userraliiev@mozilla.com
push dateFri, 19 Jun 2015 19:24:37 +0000
treeherdermozilla-release@932614382a68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnsm
bugs1142727
milestone39.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 1142727 - Do not intercept sandboxed iframes with service workers; r=nsm This is temporary until we clarify what we want to do with these iframes in the spec.
docshell/base/nsDocShell.cpp
dom/workers/test/serviceworkers/fetch/sandbox/index.html
dom/workers/test/serviceworkers/fetch/sandbox/intercepted_index.html
dom/workers/test/serviceworkers/fetch/sandbox/register.html
dom/workers/test/serviceworkers/fetch/sandbox/sandbox_test.js
dom/workers/test/serviceworkers/fetch/sandbox/unregister.html
dom/workers/test/serviceworkers/mochitest.ini
dom/workers/test/serviceworkers/test_sandbox_intercept.html
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -13945,16 +13945,21 @@ nsDocShell::MaybeNotifyKeywordSearchLoad
   }
 #endif
 }
 
 NS_IMETHODIMP
 nsDocShell::ShouldPrepareForIntercept(nsIURI* aURI, bool aIsNavigate, bool* aShouldIntercept)
 {
   *aShouldIntercept = false;
+  if (mSandboxFlags) {
+    // If we're sandboxed, don't intercept.
+    return NS_OK;
+  }
+
   nsCOMPtr<nsIServiceWorkerManager> swm = mozilla::services::GetServiceWorkerManager();
   if (!swm) {
     return NS_OK;
   }
 
   if (aIsNavigate) {
     return swm->IsAvailableForURI(aURI, aShouldIntercept);
   }
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/serviceworkers/fetch/sandbox/index.html
@@ -0,0 +1,5 @@
+<!DOCTYPE html>
+<script>
+  window.parent.postMessage({status: "ok", result: true, message: "The iframe is not being intercepted"}, "*");
+  window.parent.postMessage({status: "done"}, "*");
+</script>
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/serviceworkers/fetch/sandbox/intercepted_index.html
@@ -0,0 +1,5 @@
+<!DOCTYPE html>
+<script>
+  window.parent.postMessage({status: "ok", result: false, message: "The iframe is being intercepted"}, "*");
+  window.parent.postMessage({status: "done"}, "*");
+</script>
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/serviceworkers/fetch/sandbox/register.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<script>
+  function ok(v, msg) {
+    window.parent.postMessage({status: "ok", result: !!v, message: msg}, "*");
+  }
+
+  var isDone = false;
+  function done(reg) {
+    if (!isDone) {
+      ok(reg.waiting || reg.active, "Either active or waiting worker should be available.");
+      window.parent.postMessage({status: "registrationdone"}, "*");
+      isDone = true;
+    }
+  }
+
+  navigator.serviceWorker.register("sandbox_test.js", {scope: "."})
+    .then(function(registration) {
+      if (registration.installing) {
+        registration.installing.onstatechange = function(e) {
+          done(registration);
+        };
+      } else {
+        done(registration);
+      }
+    });
+</script>
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/serviceworkers/fetch/sandbox/sandbox_test.js
@@ -0,0 +1,5 @@
+self.addEventListener("fetch", function(event) {
+  if (event.request.url.indexOf("index.html") >= 0) {
+    event.respondWith(fetch("intercepted_index.html"));
+  }
+});
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/serviceworkers/fetch/sandbox/unregister.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<script>
+  navigator.serviceWorker.getRegistration(".").then(function(registration) {
+    registration.unregister().then(function(success) {
+      if (success) {
+        window.parent.postMessage({status: "unregistrationdone"}, "*");
+      }
+    });
+  });
+</script>
--- a/dom/workers/test/serviceworkers/mochitest.ini
+++ b/dom/workers/test/serviceworkers/mochitest.ini
@@ -29,16 +29,21 @@ support-files =
   fetch/https/index.html
   fetch/https/register.html
   fetch/https/unregister.html
   fetch/https/https_test.js
   fetch/https/clonedresponse/index.html
   fetch/https/clonedresponse/register.html
   fetch/https/clonedresponse/unregister.html
   fetch/https/clonedresponse/https_test.js
+  fetch/sandbox/index.html
+  fetch/sandbox/intercepted_index.html
+  fetch/sandbox/register.html
+  fetch/sandbox/unregister.html
+  fetch/sandbox/sandbox_test.js
   match_all_properties_worker.js
   match_all_clients/match_all_controlled.html
   test_serviceworker_interfaces.js
   serviceworker_wrapper.js
   message_receiver.html
   close_test.js
   serviceworker_not_sharedworker.js
   match_all_client/match_all_client_id.html
@@ -63,8 +68,9 @@ support-files =
 [test_post_message.html]
 [test_post_message_advanced.html]
 [test_post_message_source.html]
 [test_match_all_client_properties.html]
 [test_close.html]
 [test_serviceworker_interfaces.html]
 [test_serviceworker_not_sharedworker.html]
 [test_match_all_client_id.html]
+[test_sandbox_intercept.html]
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/serviceworkers/test_sandbox_intercept.html
@@ -0,0 +1,51 @@
+<!--
+  Any copyright is dedicated to the Public Domain.
+  http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Bug 1142727 - Test that sandboxed iframes are not intercepted</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<p id="display"></p>
+<div id="content">
+<iframe sandbox="allow-scripts allow-same-origin"></iframe>
+</div>
+<pre id="test"></pre>
+<script class="testbody" type="text/javascript">
+
+  var iframe;
+  function runTest() {
+    iframe = document.querySelector("iframe");
+    iframe.src = "/tests/dom/workers/test/serviceworkers/fetch/sandbox/register.html";
+    var ios;
+    window.onmessage = function(e) {
+      if (e.data.status == "ok") {
+        ok(e.data.result, e.data.message);
+      } else if (e.data.status == "registrationdone") {
+        iframe.src = "/tests/dom/workers/test/serviceworkers/fetch/sandbox/index.html";
+      } else if (e.data.status == "done") {
+        iframe.src = "/tests/dom/workers/test/serviceworkers/fetch/sandbox/unregister.html";
+      } else if (e.data.status == "unregistrationdone") {
+        window.onmessage = null;
+        ok(true, "Test finished successfully");
+        SimpleTest.finish();
+      }
+    };
+  }
+
+  SimpleTest.waitForExplicitFinish();
+  onload = function() {
+    SpecialPowers.pushPrefEnv({"set": [
+      ["dom.serviceWorkers.exemptFromPerDomainMax", true],
+      ["dom.serviceWorkers.enabled", true],
+      ["dom.serviceWorkers.testing.enabled", true],
+    ]}, runTest);
+  };
+</script>
+</pre>
+</body>
+</html>