Title: [224902] trunk
Revision
224902
Author
commit-qu...@webkit.org
Date
2017-11-15 14:56:59 -0800 (Wed, 15 Nov 2017)

Log Message

ReloadFromOrigin loads should not select any service worker
https://bugs.webkit.org/show_bug.cgi?id=179736

Patch by Youenn Fablet <you...@apple.com> on 2017-11-15
Reviewed by Brady Eidson.

Source/WebCore:

Test: http/tests/workers/service/shift-reload-navigation.html

In case of ReloadFromOrigin (equivalent of shift reload), do not select any service worker.

* loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::startLoadingMainResource):
* loader/FrameLoader.h:
(WebCore::FrameLoader::isReloadingFromOrigin const):

LayoutTests:

* http/tests/workers/service/resources/shift-reload-navigation.js: Added.
(async.test):
* http/tests/workers/service/shift-reload-navigation-expected.txt: Added.
* http/tests/workers/service/shift-reload-navigation.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (224901 => 224902)


--- trunk/LayoutTests/ChangeLog	2017-11-15 22:30:26 UTC (rev 224901)
+++ trunk/LayoutTests/ChangeLog	2017-11-15 22:56:59 UTC (rev 224902)
@@ -1,3 +1,15 @@
+2017-11-15  Youenn Fablet  <you...@apple.com>
+
+        ReloadFromOrigin loads should not select any service worker
+        https://bugs.webkit.org/show_bug.cgi?id=179736
+
+        Reviewed by Brady Eidson.
+
+        * http/tests/workers/service/resources/shift-reload-navigation.js: Added.
+        (async.test):
+        * http/tests/workers/service/shift-reload-navigation-expected.txt: Added.
+        * http/tests/workers/service/shift-reload-navigation.html: Added.
+
 2017-11-15  Antoine Quint  <grao...@apple.com>
 
         [Web Animations] Implement basic to-from animations

Added: trunk/LayoutTests/http/tests/workers/service/resources/shift-reload-navigation.js (0 => 224902)


--- trunk/LayoutTests/http/tests/workers/service/resources/shift-reload-navigation.js	                        (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/resources/shift-reload-navigation.js	2017-11-15 22:56:59 UTC (rev 224902)
@@ -0,0 +1,37 @@
+async function test()
+{
+    try {
+        try {
+            var response = await fetch("http://localhost:8080/resources/square100.png.fromserviceworker");
+            log("Failed: fetch suceeded unexpectedly");
+        } catch(e) {
+            log("PASS: Fetch failed as expected with: " + e);
+        }
+
+        var frame = await interceptedFrame("resources/service-worker-crossorigin-fetch-worker.js", "/");
+
+        var response = await frame.contentWindow.fetch("http://localhost:8080/resources/square100.png.fromserviceworker");
+        var buffer =  await response.arrayBuffer();
+        log("PASS: Got response with buffer byte length being " + buffer.byteLength);
+
+        if (!frame.contentWindow.internals)
+            return Promise.rejects("Test requires internals API");
+
+        await new Promise(resolve => {
+            frame._onload_ = resolve;
+            frame.contentWindow.internals.forceReload(true);
+        });
+
+        // On shift reload, frame should bypass its service worker.
+        try {
+            var response = await fetch("http://localhost:8080/resources/square100.png.fromserviceworker");
+            log("Failed: fetch suceeded unexpectedly");
+        } catch(e) {
+            log("PASS: Fetch failed as expected with: " + e);
+        }
+    } catch(e) {
+        log("FAIL: Got exception: " + e);
+    }
+    finishSWTest();
+}
+test();

Added: trunk/LayoutTests/http/tests/workers/service/shift-reload-navigation-expected.txt (0 => 224902)


--- trunk/LayoutTests/http/tests/workers/service/shift-reload-navigation-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/shift-reload-navigation-expected.txt	2017-11-15 22:56:59 UTC (rev 224902)
@@ -0,0 +1,8 @@
+CONSOLE MESSAGE: Origin http://127.0.0.1:8000 is not allowed by Access-Control-Allow-Origin.
+CONSOLE MESSAGE: Fetch API cannot load http://localhost:8080/resources/square100.png.fromserviceworker. Origin http://127.0.0.1:8000 is not allowed by Access-Control-Allow-Origin.
+CONSOLE MESSAGE: Origin http://127.0.0.1:8000 is not allowed by Access-Control-Allow-Origin.
+CONSOLE MESSAGE: Fetch API cannot load http://localhost:8080/resources/square100.png.fromserviceworker. Origin http://127.0.0.1:8000 is not allowed by Access-Control-Allow-Origin.
+PASS: Fetch failed as expected with: TypeError: Origin http://127.0.0.1:8000 is not allowed by Access-Control-Allow-Origin.
+PASS: Got response with buffer byte length being 12940
+PASS: Fetch failed as expected with: TypeError: Origin http://127.0.0.1:8000 is not allowed by Access-Control-Allow-Origin.
+

Added: trunk/LayoutTests/http/tests/workers/service/shift-reload-navigation.html (0 => 224902)


--- trunk/LayoutTests/http/tests/workers/service/shift-reload-navigation.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/shift-reload-navigation.html	2017-11-15 22:56:59 UTC (rev 224902)
@@ -0,0 +1,8 @@
+<html>
+<head>
+<script src=""
+</head>
+<body>
+    <script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (224901 => 224902)


--- trunk/Source/WebCore/ChangeLog	2017-11-15 22:30:26 UTC (rev 224901)
+++ trunk/Source/WebCore/ChangeLog	2017-11-15 22:56:59 UTC (rev 224902)
@@ -1,3 +1,19 @@
+2017-11-15  Youenn Fablet  <you...@apple.com>
+
+        ReloadFromOrigin loads should not select any service worker
+        https://bugs.webkit.org/show_bug.cgi?id=179736
+
+        Reviewed by Brady Eidson.
+
+        Test: http/tests/workers/service/shift-reload-navigation.html
+
+        In case of ReloadFromOrigin (equivalent of shift reload), do not select any service worker.
+
+        * loader/DocumentLoader.cpp:
+        (WebCore::DocumentLoader::startLoadingMainResource):
+        * loader/FrameLoader.h:
+        (WebCore::FrameLoader::isReloadingFromOrigin const):
+
 2017-11-15  Zalan Bujtas  <za...@apple.com>
 
         AX triggers sync layout while building the render tree on www.macrumors.com.

Modified: trunk/Source/WebCore/loader/DocumentLoader.cpp (224901 => 224902)


--- trunk/Source/WebCore/loader/DocumentLoader.cpp	2017-11-15 22:30:26 UTC (rev 224901)
+++ trunk/Source/WebCore/loader/DocumentLoader.cpp	2017-11-15 22:56:59 UTC (rev 224902)
@@ -1488,7 +1488,8 @@
         RELEASE_LOG_IF_ALLOWED("startLoadingMainResource: Starting load (frame = %p, main = %d)", m_frame, m_frame->isMainFrame());
 
 #if ENABLE(SERVICE_WORKER)
-        if (m_frame && m_frame->page() && RuntimeEnabledFeatures::sharedFeatures().serviceWorkerEnabled()) {
+        auto tryLoadingThroughServiceWorker = !frameLoader()->isReloadingFromOrigin() && m_frame->page() && RuntimeEnabledFeatures::sharedFeatures().serviceWorkerEnabled();
+        if (tryLoadingThroughServiceWorker) {
             auto origin = (!m_frame->isMainFrame() && m_frame->document()) ? makeRef(m_frame->document()->topOrigin()) : SecurityOrigin::create(request.url());
             auto& connection = ServiceWorkerProvider::singleton().serviceWorkerConnectionForSession(m_frame->page()->sessionID());
             if (connection.mayHaveServiceWorkerRegisteredForOrigin(origin)) {

Modified: trunk/Source/WebCore/loader/FrameLoader.h (224901 => 224902)


--- trunk/Source/WebCore/loader/FrameLoader.h	2017-11-15 22:30:26 UTC (rev 224901)
+++ trunk/Source/WebCore/loader/FrameLoader.h	2017-11-15 22:56:59 UTC (rev 224902)
@@ -298,6 +298,7 @@
 
     bool isAlwaysOnLoggingAllowed() const;
     bool shouldSuppressTextInputFromEditing() const;
+    bool isReloadingFromOrigin() const { return m_loadType == FrameLoadType::ReloadFromOrigin; }
 
 private:
     enum FormSubmissionCacheLoadPolicy {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to