WKFrameIsDisplayingMarkupDocument() should return true after a window.open/document...
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Oct 2019 18:36:22 +0000 (18:36 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Oct 2019 18:36:22 +0000 (18:36 +0000)
https://bugs.webkit.org/show_bug.cgi?id=203587
<rdar://problem/56717726>

Reviewed by Alex Christensen.

Source/WebCore:

When doing a document.open(), we were propagating the document's URL to the UIProcess but not its
MIME type. WKFrameIsDisplayingMarkupDocument() was relying on this MIME type.

* loader/FrameLoader.cpp:
(WebCore::FrameLoader::didExplicitOpen):
* loader/FrameLoaderClient.h:

Source/WebKit:

When doing a document.open(), we were propagating the document's URL to the UIProcess but not its
MIME type. WKFrameIsDisplayingMarkupDocument() was relying on this MIME type.

* UIProcess/WebFrameProxy.cpp:
(WebKit::WebFrameProxy::didExplicitOpen):
* UIProcess/WebFrameProxy.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::didExplicitOpenForFrame):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
(WebKit::WebFrameLoaderClient::dispatchDidExplicitOpen):
* WebProcess/WebCoreSupport/WebFrameLoaderClient.h:

Tools:

Add API test coverage.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit/CloseFromWithinCreatePage.cpp:
(TestWebKitAPI::createNewPageThenClose):
(TestWebKitAPI::TEST):
(TestWebKitAPI::createNewPage):
* TestWebKitAPI/Tests/WebKit/window-open-then-document-open.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@251787 268f45cc-cd09-0410-ab3c-d52691b4dbfc

15 files changed:
Source/WebCore/ChangeLog
Source/WebCore/loader/FrameLoader.cpp
Source/WebCore/loader/FrameLoaderClient.h
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/WebFrameProxy.cpp
Source/WebKit/UIProcess/WebFrameProxy.h
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/UIProcess/WebPageProxy.messages.in
Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp
Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.h
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKit/CloseFromWithinCreatePage.cpp
Tools/TestWebKitAPI/Tests/WebKit/window-open-then-document-open.html [new file with mode: 0644]

index 4b9c328..447c487 100644 (file)
@@ -1,3 +1,18 @@
+2019-10-30  Chris Dumez  <cdumez@apple.com>
+
+        WKFrameIsDisplayingMarkupDocument() should return true after a window.open/document.write
+        https://bugs.webkit.org/show_bug.cgi?id=203587
+        <rdar://problem/56717726>
+
+        Reviewed by Alex Christensen.
+
+        When doing a document.open(), we were propagating the document's URL to the UIProcess but not its
+        MIME type. WKFrameIsDisplayingMarkupDocument() was relying on this MIME type.
+
+        * loader/FrameLoader.cpp:
+        (WebCore::FrameLoader::didExplicitOpen):
+        * loader/FrameLoaderClient.h:
+
 2019-10-30  Antoine Quint  <graouts@apple.com>
 
         [Web Animations] Precompute an animation effect's active duration and end time
index b78c853..26246f7 100644 (file)
@@ -595,7 +595,8 @@ void FrameLoader::didExplicitOpen()
     if (!m_stateMachine.committedFirstRealDocumentLoad())
         m_stateMachine.advanceTo(FrameLoaderStateMachine::DisplayingInitialEmptyDocumentPostCommit);
 
-    m_client.dispatchDidExplicitOpen(m_frame.document() ? m_frame.document()->url() : URL());
+    if (auto* document = m_frame.document())
+        m_client.dispatchDidExplicitOpen(document->url(), document->contentType());
     
     // Prevent window.open(url) -- eg window.open("about:blank") -- from blowing away results
     // from a subsequent window.document.open / window.document.write call. 
index e1046ba..838b18f 100644 (file)
@@ -178,7 +178,7 @@ public:
     virtual void dispatchDidFailLoad(const ResourceError&) = 0;
     virtual void dispatchDidFinishDocumentLoad() = 0;
     virtual void dispatchDidFinishLoad() = 0;
-    virtual void dispatchDidExplicitOpen(const URL&) { }
+    virtual void dispatchDidExplicitOpen(const URL&, const String& /* mimeType */) { }
 #if ENABLE(DATA_DETECTION)
     virtual void dispatchDidFinishDataDetection(NSArray *detectionResults) = 0;
 #endif
index 840ddc0..4178a76 100644 (file)
@@ -1,5 +1,27 @@
 2019-10-30  Chris Dumez  <cdumez@apple.com>
 
+        WKFrameIsDisplayingMarkupDocument() should return true after a window.open/document.write
+        https://bugs.webkit.org/show_bug.cgi?id=203587
+        <rdar://problem/56717726>
+
+        Reviewed by Alex Christensen.
+
+        When doing a document.open(), we were propagating the document's URL to the UIProcess but not its
+        MIME type. WKFrameIsDisplayingMarkupDocument() was relying on this MIME type.
+
+        * UIProcess/WebFrameProxy.cpp:
+        (WebKit::WebFrameProxy::didExplicitOpen):
+        * UIProcess/WebFrameProxy.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::didExplicitOpenForFrame):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+        * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
+        (WebKit::WebFrameLoaderClient::dispatchDidExplicitOpen):
+        * WebProcess/WebCoreSupport/WebFrameLoaderClient.h:
+
+2019-10-30  Chris Dumez  <cdumez@apple.com>
+
         REGRESSION (r238252): HTTP POST is losing application/x-www-form-urlencoded body if there's a redirect to different host
         https://bugs.webkit.org/show_bug.cgi?id=201950
         <rdar://problem/55577782>
index db224b6..c1c958b 100644 (file)
@@ -146,9 +146,10 @@ void WebFrameProxy::didStartProvisionalLoad(const URL& url)
     m_frameLoadState.didStartProvisionalLoad(url);
 }
 
-void WebFrameProxy::didExplicitOpen(const URL& url)
+void WebFrameProxy::didExplicitOpen(URL&& url, String&& mimeType)
 {
-    m_frameLoadState.didExplicitOpen(url);
+    m_MIMEType = WTFMove(mimeType);
+    m_frameLoadState.didExplicitOpen(WTFMove(url));
 }
 
 void WebFrameProxy::didReceiveServerRedirectForProvisionalLoad(const URL& url)
index 094f9ff..bf6d896 100644 (file)
@@ -111,7 +111,7 @@ public:
     void getResourceData(API::URL*, Function<void (API::Data*, CallbackBase::Error)>&&);
 
     void didStartProvisionalLoad(const URL&);
-    void didExplicitOpen(const URL&);
+    void didExplicitOpen(URL&&, String&& mimeType);
     void didReceiveServerRedirectForProvisionalLoad(const URL&);
     void didFailProvisionalLoad();
     void didCommitLoad(const String& contentType, WebCertificateInfo&, bool containsPluginDocument);
index 7088bd1..f395062 100644 (file)
@@ -4132,7 +4132,7 @@ void WebPageProxy::didStartProvisionalLoadForFrameShared(Ref<WebProcessProxy>&&
 #endif
 }
 
-void WebPageProxy::didExplicitOpenForFrame(FrameIdentifier frameID, URL&& url)
+void WebPageProxy::didExplicitOpenForFrame(FrameIdentifier frameID, URL&& url, String&& mimeType)
 {
     auto* frame = m_process->webFrame(frameID);
     MESSAGE_CHECK(m_process, frame);
@@ -4143,7 +4143,7 @@ void WebPageProxy::didExplicitOpenForFrame(FrameIdentifier frameID, URL&& url)
     if (frame->isMainFrame())
         m_pageLoadState.didExplicitOpen(transaction, url);
 
-    frame->didExplicitOpen(url);
+    frame->didExplicitOpen(WTFMove(url), WTFMove(mimeType));
 
     m_hasCommittedAnyProvisionalLoads = true;
     m_process->didCommitProvisionalLoad();
index 0d859ac..38653e2 100644 (file)
@@ -1675,7 +1675,7 @@ private:
     void didFailLoadForFrame(WebCore::FrameIdentifier, uint64_t navigationID, const WebCore::ResourceError&, const UserData&);
     void didSameDocumentNavigationForFrame(WebCore::FrameIdentifier, uint64_t navigationID, uint32_t sameDocumentNavigationType, URL&&, const UserData&);
     void didChangeMainDocument(WebCore::FrameIdentifier);
-    void didExplicitOpenForFrame(WebCore::FrameIdentifier, URL&&);
+    void didExplicitOpenForFrame(WebCore::FrameIdentifier, URL&&, String&& mimeType);
 
     void didReceiveTitleForFrame(WebCore::FrameIdentifier, const String&, const UserData&);
     void didFirstLayoutForFrame(WebCore::FrameIdentifier, const UserData&);
index ce72bed..2269aa6 100644 (file)
@@ -142,7 +142,7 @@ messages -> WebPageProxy {
     DidDetectXSSForFrame(WebCore::FrameIdentifier frameID, WebKit::UserData userData)
     DidSameDocumentNavigationForFrame(WebCore::FrameIdentifier frameID, uint64_t navigationID, uint32_t type, URL url, WebKit::UserData userData)
     DidChangeMainDocument(WebCore::FrameIdentifier frameID)
-    DidExplicitOpenForFrame(WebCore::FrameIdentifier frameID, URL url)
+    DidExplicitOpenForFrame(WebCore::FrameIdentifier frameID, URL url, String mimeType)
     DidDestroyNavigation(uint64_t navigationID)
 
     HasInsecureContent() -> (enum:bool WebCore::HasInsecureContent hasInsecureContent) Synchronous
index 7f2dd3e..d3f7879 100644 (file)
@@ -477,14 +477,14 @@ void WebFrameLoaderClient::dispatchWillClose()
     notImplemented();
 }
 
-void WebFrameLoaderClient::dispatchDidExplicitOpen(const URL& url)
+void WebFrameLoaderClient::dispatchDidExplicitOpen(const URL& url, const String& mimeType)
 {
     auto* webPage = m_frame->page();
     if (!webPage)
         return;
 
     // Notify the UIProcess.
-    webPage->send(Messages::WebPageProxy::DidExplicitOpenForFrame(m_frame->frameID(), url));
+    webPage->send(Messages::WebPageProxy::DidExplicitOpenForFrame(m_frame->frameID(), url, mimeType));
 }
 
 void WebFrameLoaderClient::dispatchDidStartProvisionalLoad()
index aec0339..a9dd93c 100644 (file)
@@ -119,7 +119,7 @@ private:
     void dispatchDidFailLoad(const WebCore::ResourceError&) final;
     void dispatchDidFinishDocumentLoad() final;
     void dispatchDidFinishLoad() final;
-    void dispatchDidExplicitOpen(const URL&) final;
+    void dispatchDidExplicitOpen(const URL&, const String& mimeType) final;
 
     void dispatchDidReachLayoutMilestone(OptionSet<WebCore::LayoutMilestone>) final;
     void dispatchDidLayout() final;
index ad8a400..df43475 100644 (file)
@@ -1,3 +1,20 @@
+2019-10-30  Chris Dumez  <cdumez@apple.com>
+
+        WKFrameIsDisplayingMarkupDocument() should return true after a window.open/document.write
+        https://bugs.webkit.org/show_bug.cgi?id=203587
+        <rdar://problem/56717726>
+
+        Reviewed by Alex Christensen.
+
+        Add API test coverage.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit/CloseFromWithinCreatePage.cpp:
+        (TestWebKitAPI::createNewPageThenClose):
+        (TestWebKitAPI::TEST):
+        (TestWebKitAPI::createNewPage):
+        * TestWebKitAPI/Tests/WebKit/window-open-then-document-open.html: Added.
+
 2019-10-29  Andy Estes  <aestes@apple.com>
 
         [Quick Look] Clean up LegacyPreviewLoaderClients
index 3597dc8..7c09189 100644 (file)
                467C565321B5ED130057516D /* GetSessionCookie.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 467C565121B5ECDF0057516D /* GetSessionCookie.html */; };
                467C565421B5ED130057516D /* SetSessionCookie.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 467C565221B5ECDF0057516D /* SetSessionCookie.html */; };
                468BC45522653A1000A36C96 /* open-window-then-write-to-it.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 468BC454226539C800A36C96 /* open-window-then-write-to-it.html */; };
+               468F2F942368DAF100F4B864 /* window-open-then-document-open.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 468F2F932368DAA700F4B864 /* window-open-then-document-open.html */; };
                46918EFC2237283C00468DFE /* DeviceOrientation.mm in Sources */ = {isa = PBXBuildFile; fileRef = 46918EFB2237283500468DFE /* DeviceOrientation.mm */; };
                46A911592108E6780078D40D /* CustomUserAgent.mm in Sources */ = {isa = PBXBuildFile; fileRef = 46A911582108E66B0078D40D /* CustomUserAgent.mm */; };
                46AE5A3720F9066D00E0873E /* SimpleServiceWorkerRegistrations-4.sqlite3 in Copy Resources */ = {isa = PBXBuildFile; fileRef = 4656A75720F9054F0002E21F /* SimpleServiceWorkerRegistrations-4.sqlite3 */; };
                                5120C83E1E67678F0025B250 /* WebsiteDataStoreCustomPaths.html in Copy Resources */,
                                2E131C181D83A98A001BA36C /* wide-autoplaying-video-with-audio.html in Copy Resources */,
                                CE14F1A4181873B0001C2705 /* WillPerformClientRedirectToURLCrash.html in Copy Resources */,
+                               468F2F942368DAF100F4B864 /* window-open-then-document-open.html in Copy Resources */,
                                A5E2027515B21F6E00C13E14 /* WindowlessWebViewWithMedia.html in Copy Resources */,
                        );
                        name = "Copy Resources";
                467C565121B5ECDF0057516D /* GetSessionCookie.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = GetSessionCookie.html; sourceTree = "<group>"; };
                467C565221B5ECDF0057516D /* SetSessionCookie.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = SetSessionCookie.html; sourceTree = "<group>"; };
                468BC454226539C800A36C96 /* open-window-then-write-to-it.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "open-window-then-write-to-it.html"; sourceTree = "<group>"; };
+               468F2F932368DAA700F4B864 /* window-open-then-document-open.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "window-open-then-document-open.html"; sourceTree = "<group>"; };
                46918EFB2237283500468DFE /* DeviceOrientation.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DeviceOrientation.mm; sourceTree = "<group>"; };
                46A911582108E66B0078D40D /* CustomUserAgent.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CustomUserAgent.mm; sourceTree = "<group>"; };
                46C519D81D355A7300DAA51A /* LocalStorageNullEntries.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LocalStorageNullEntries.mm; sourceTree = "<group>"; };
                                C9C9A91C21DED79400FDE96E /* video-with-play-button.html */,
                                07CD32F72065B72A0064A4BE /* video.html */,
                                1C2B81841C8924A200A5529F /* webfont.html */,
+                               468F2F932368DAA700F4B864 /* window-open-then-document-open.html */,
                        );
                        name = Resources;
                        sourceTree = "<group>";
index b3b3bc3..2885f52 100644 (file)
@@ -42,7 +42,7 @@ static void runJavaScriptAlert(WKPageRef page, WKStringRef alertText, WKFrameRef
     testDone = true;
 }
 
-static WKPageRef createNewPage(WKPageRef page, WKURLRequestRef urlRequest, WKDictionaryRef features, WKEventModifiers modifiers, WKEventMouseButton mouseButton, const void *clientInfo)
+static WKPageRef createNewPageThenClose(WKPageRef page, WKURLRequestRef urlRequest, WKDictionaryRef features, WKEventModifiers modifiers, WKEventMouseButton mouseButton, const void *clientInfo)
 {
     EXPECT_TRUE(openedWebView == nullptr);
 
@@ -71,7 +71,7 @@ TEST(WebKit, CloseFromWithinCreatePage)
     memset(&uiClient, 0, sizeof(uiClient));
 
     uiClient.base.version = 5;
-    uiClient.createNewPage = createNewPage;
+    uiClient.createNewPage = createNewPageThenClose;
     uiClient.runJavaScriptAlert = runJavaScriptAlert;
     WKPageSetPageUIClient(webView.page(), &uiClient.base);
 
@@ -89,6 +89,55 @@ TEST(WebKit, CloseFromWithinCreatePage)
     openedWebView = nullptr;
 }
 
+static WKPageRef createNewPage(WKPageRef page, WKURLRequestRef urlRequest, WKDictionaryRef features, WKEventModifiers modifiers, WKEventMouseButton mouseButton, const void *clientInfo)
+{
+    EXPECT_TRUE(openedWebView == nullptr);
+
+    openedWebView = makeUnique<PlatformWebView>(page);
+
+    WKPageUIClientV5 uiClient;
+    memset(&uiClient, 0, sizeof(uiClient));
+
+    uiClient.base.version = 5;
+    uiClient.runJavaScriptAlert = runJavaScriptAlert;
+    WKPageSetPageUIClient(openedWebView->page(), &uiClient.base);
+
+    WKRetain(openedWebView->page());
+    return openedWebView->page();
+}
+
+TEST(WebKit, CreatePageThenDocumentOpenMIMEType)
+{
+    WKRetainPtr<WKContextRef> context = adoptWK(WKContextCreateWithConfiguration(nullptr));
+
+    PlatformWebView webView(context.get());
+
+    WKPageUIClientV5 uiClient;
+    memset(&uiClient, 0, sizeof(uiClient));
+
+    uiClient.base.version = 5;
+    uiClient.createNewPage = createNewPage;
+    uiClient.runJavaScriptAlert = runJavaScriptAlert;
+    WKPageSetPageUIClient(webView.page(), &uiClient.base);
+
+    // Allow file URLs to load non-file resources
+    WKRetainPtr<WKPreferencesRef> preferences = adoptWK(WKPreferencesCreate());
+    WKPageGroupRef pageGroup = WKPageGetPageGroup(webView.page());
+    WKPreferencesSetUniversalAccessFromFileURLsAllowed(preferences.get(), true);
+    WKPageGroupSetPreferences(pageGroup, preferences.get());
+
+    testDone = false;
+    WKRetainPtr<WKURLRef> url = adoptWK(Util::createURLForResource("window-open-then-document-open", "html"));
+    WKPageLoadURL(webView.page(), url.get());
+    Util::run(&testDone);
+
+    auto page = openedWebView->page();
+    auto mainFrame = WKPageGetMainFrame(page);
+    EXPECT_TRUE(WKFrameIsDisplayingMarkupDocument(mainFrame));
+
+    openedWebView = nullptr;
+}
+
 }
 
 #endif
diff --git a/Tools/TestWebKitAPI/Tests/WebKit/window-open-then-document-open.html b/Tools/TestWebKitAPI/Tests/WebKit/window-open-then-document-open.html
new file mode 100644 (file)
index 0000000..f612f5f
--- /dev/null
@@ -0,0 +1,13 @@
+<html>
+<body>
+<script>
+function runTest()
+{
+    w = window.open("foo.html");
+    w.document.open();
+    w.document.write("<html><body><script>setTimeout(() => { alert('foo'); }, 0);<" + "/script></body></html>");
+}
+</script>
+<body onload="runTest()">
+</body>
+</html>