Title: [244321] trunk
Revision
244321
Author
[email protected]
Date
2019-04-15 19:01:32 -0700 (Mon, 15 Apr 2019)

Log Message

URL set by document.open() is not communicated to the UIProcess
https://bugs.webkit.org/show_bug.cgi?id=196941
<rdar://problem/49237544>

Reviewed by Geoffrey Garen.

Source/WebCore:

Notify the FrameLoaderClient whenever an explicit open was done and provide it with
the latest document URL.

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

Source/WebKit:

Whenever the UIProcess is notified of an explicit document.open() call, update the
PageLoadState to make sure the URL is up-to-date. Also make sure the page / process
knows it committed a load (i.e. It is no longer showing the initially empty document).

* UIProcess/PageLoadState.cpp:
(WebKit::PageLoadState::didExplicitOpen):
* UIProcess/PageLoadState.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/open-window-then-write-to-it.html: Added.
* TestWebKitAPI/Tests/WebKitCocoa/OpenAndCloseWindow.mm:
(-[OpenWindowThenDocumentOpenUIDelegate webView:createWebViewWithConfiguration:forNavigationAction:windowFeatures:]):
(TEST):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (244320 => 244321)


--- trunk/Source/WebCore/ChangeLog	2019-04-16 01:55:50 UTC (rev 244320)
+++ trunk/Source/WebCore/ChangeLog	2019-04-16 02:01:32 UTC (rev 244321)
@@ -1,3 +1,18 @@
+2019-04-15  Chris Dumez  <[email protected]>
+
+        URL set by document.open() is not communicated to the UIProcess
+        https://bugs.webkit.org/show_bug.cgi?id=196941
+        <rdar://problem/49237544>
+
+        Reviewed by Geoffrey Garen.
+
+        Notify the FrameLoaderClient whenever an explicit open was done and provide it with
+        the latest document URL.
+
+        * loader/FrameLoader.cpp:
+        (WebCore::FrameLoader::didExplicitOpen):
+        * loader/FrameLoaderClient.h:
+
 2019-04-15  Eike Rathke  <[email protected]>
 
         Fix logic flow for error log

Modified: trunk/Source/WebCore/loader/FrameLoader.cpp (244320 => 244321)


--- trunk/Source/WebCore/loader/FrameLoader.cpp	2019-04-16 01:55:50 UTC (rev 244320)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp	2019-04-16 02:01:32 UTC (rev 244321)
@@ -592,6 +592,8 @@
     // Calling document.open counts as committing the first real document load.
     if (!m_stateMachine.committedFirstRealDocumentLoad())
         m_stateMachine.advanceTo(FrameLoaderStateMachine::DisplayingInitialEmptyDocumentPostCommit);
+
+    m_client.dispatchDidExplicitOpen(m_frame.document() ? m_frame.document()->url() : URL());
     
     // Prevent window.open(url) -- eg window.open("about:blank") -- from blowing away results
     // from a subsequent window.document.open / window.document.write call. 

Modified: trunk/Source/WebCore/loader/FrameLoaderClient.h (244320 => 244321)


--- trunk/Source/WebCore/loader/FrameLoaderClient.h	2019-04-16 01:55:50 UTC (rev 244320)
+++ trunk/Source/WebCore/loader/FrameLoaderClient.h	2019-04-16 02:01:32 UTC (rev 244321)
@@ -181,6 +181,7 @@
     virtual void dispatchDidFailLoad(const ResourceError&) = 0;
     virtual void dispatchDidFinishDocumentLoad() = 0;
     virtual void dispatchDidFinishLoad() = 0;
+    virtual void dispatchDidExplicitOpen(const URL&) { }
 #if ENABLE(DATA_DETECTION)
     virtual void dispatchDidFinishDataDetection(NSArray *detectionResults) = 0;
 #endif

Modified: trunk/Source/WebKit/ChangeLog (244320 => 244321)


--- trunk/Source/WebKit/ChangeLog	2019-04-16 01:55:50 UTC (rev 244320)
+++ trunk/Source/WebKit/ChangeLog	2019-04-16 02:01:32 UTC (rev 244321)
@@ -1,3 +1,26 @@
+2019-04-15  Chris Dumez  <[email protected]>
+
+        URL set by document.open() is not communicated to the UIProcess
+        https://bugs.webkit.org/show_bug.cgi?id=196941
+        <rdar://problem/49237544>
+
+        Reviewed by Geoffrey Garen.
+
+        Whenever the UIProcess is notified of an explicit document.open() call, update the
+        PageLoadState to make sure the URL is up-to-date. Also make sure the page / process
+        knows it committed a load (i.e. It is no longer showing the initially empty document).
+
+        * UIProcess/PageLoadState.cpp:
+        (WebKit::PageLoadState::didExplicitOpen):
+        * UIProcess/PageLoadState.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-04-15  Alex Christensen  <[email protected]>
 
         Stop using hyphenationFactor

Modified: trunk/Source/WebKit/UIProcess/PageLoadState.cpp (244320 => 244321)


--- trunk/Source/WebKit/UIProcess/PageLoadState.cpp	2019-04-16 01:55:50 UTC (rev 244320)
+++ trunk/Source/WebKit/UIProcess/PageLoadState.cpp	2019-04-16 02:01:32 UTC (rev 244321)
@@ -246,6 +246,15 @@
     m_uncommittedState.pendingAPIRequestURL = String();
 }
 
+void PageLoadState::didExplicitOpen(const Transaction::Token& token, const String& url)
+{
+    ASSERT_UNUSED(token, &token.m_pageLoadState == this);
+
+    m_uncommittedState.state = State::Finished;
+    m_uncommittedState.url = ""
+    m_uncommittedState.provisionalURL = String();
+}
+
 void PageLoadState::didStartProvisionalLoad(const Transaction::Token& token, const String& url, const String& unreachableURL)
 {
     ASSERT_UNUSED(token, &token.m_pageLoadState == this);

Modified: trunk/Source/WebKit/UIProcess/PageLoadState.h (244320 => 244321)


--- trunk/Source/WebKit/UIProcess/PageLoadState.h	2019-04-16 01:55:50 UTC (rev 244320)
+++ trunk/Source/WebKit/UIProcess/PageLoadState.h	2019-04-16 02:01:32 UTC (rev 244321)
@@ -143,6 +143,7 @@
     void clearPendingAPIRequestURL(const Transaction::Token&);
 
     void didStartProvisionalLoad(const Transaction::Token&, const String& url, const String& unreachableURL);
+    void didExplicitOpen(const Transaction::Token&, const String& url);
     void didReceiveServerRedirectForProvisionalLoad(const Transaction::Token&, const String& url);
     void didFailProvisionalLoad(const Transaction::Token&);
 

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (244320 => 244321)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2019-04-16 01:55:50 UTC (rev 244320)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2019-04-16 02:01:32 UTC (rev 244321)
@@ -3922,6 +3922,23 @@
         m_navigationClient->didStartProvisionalNavigation(*this, navigation.get(), process->transformHandlesToObjects(userData.object()).get());
 }
 
+void WebPageProxy::didExplicitOpenForFrame(uint64_t frameID, URL&& url)
+{
+    auto* frame = m_process->webFrame(frameID);
+    MESSAGE_CHECK(m_process, frame);
+    MESSAGE_CHECK_URL(m_process, url);
+
+    auto transaction = m_pageLoadState.transaction();
+
+    if (frame->isMainFrame())
+        m_pageLoadState.didExplicitOpen(transaction, url);
+
+    m_hasCommittedAnyProvisionalLoads = true;
+    m_process->didCommitProvisionalLoad();
+
+    m_pageLoadState.commitChanges();
+}
+
 void WebPageProxy::didReceiveServerRedirectForProvisionalLoadForFrame(uint64_t frameID, uint64_t navigationID, ResourceRequest&& request, const UserData& userData)
 {
     didReceiveServerRedirectForProvisionalLoadForFrameShared(m_process.copyRef(), frameID, navigationID, WTFMove(request), userData);

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (244320 => 244321)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2019-04-16 01:55:50 UTC (rev 244320)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2019-04-16 02:01:32 UTC (rev 244321)
@@ -1591,6 +1591,7 @@
     void didFailLoadForFrame(uint64_t frameID, uint64_t navigationID, const WebCore::ResourceError&, const UserData&);
     void didSameDocumentNavigationForFrame(uint64_t frameID, uint64_t navigationID, uint32_t sameDocumentNavigationType, URL&&, const UserData&);
     void didChangeMainDocument(uint64_t frameID);
+    void didExplicitOpenForFrame(uint64_t frameID, URL&&);
 
     void didReceiveTitleForFrame(uint64_t frameID, const String&, const UserData&);
     void didFirstLayoutForFrame(uint64_t frameID, const UserData&);

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in (244320 => 244321)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in	2019-04-16 01:55:50 UTC (rev 244320)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in	2019-04-16 02:01:32 UTC (rev 244321)
@@ -140,7 +140,8 @@
     DidRunInsecureContentForFrame(uint64_t frameID, WebKit::UserData userData)
     DidDetectXSSForFrame(uint64_t frameID, WebKit::UserData userData)
     DidSameDocumentNavigationForFrame(uint64_t frameID, uint64_t navigationID, uint32_t type, URL url, WebKit::UserData userData)
-    DidChangeMainDocument(uint64_t frameID);
+    DidChangeMainDocument(uint64_t frameID)
+    DidExplicitOpenForFrame(uint64_t frameID, URL url)
     DidDestroyNavigation(uint64_t navigationID)
 
     HasInsecureContent() -> (enum:bool WebCore::HasInsecureContent hasInsecureContent) Synchronous

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp (244320 => 244321)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp	2019-04-16 01:55:50 UTC (rev 244320)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp	2019-04-16 02:01:32 UTC (rev 244321)
@@ -458,6 +458,16 @@
     notImplemented();
 }
 
+void WebFrameLoaderClient::dispatchDidExplicitOpen(const URL& url)
+{
+    auto* webPage = m_frame->page();
+    if (!webPage)
+        return;
+
+    // Notify the UIProcess.
+    webPage->send(Messages::WebPageProxy::DidExplicitOpenForFrame(m_frame->frameID(), url));
+}
+
 void WebFrameLoaderClient::dispatchDidStartProvisionalLoad()
 {
     WebPage* webPage = m_frame->page();

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.h (244320 => 244321)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.h	2019-04-16 01:55:50 UTC (rev 244320)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.h	2019-04-16 02:01:32 UTC (rev 244321)
@@ -116,6 +116,7 @@
     void dispatchDidFailLoad(const WebCore::ResourceError&) final;
     void dispatchDidFinishDocumentLoad() final;
     void dispatchDidFinishLoad() final;
+    void dispatchDidExplicitOpen(const URL&) final;
 
     void dispatchDidReachLayoutMilestone(OptionSet<WebCore::LayoutMilestone>) final;
     void dispatchDidLayout() final;

Modified: trunk/Tools/ChangeLog (244320 => 244321)


--- trunk/Tools/ChangeLog	2019-04-16 01:55:50 UTC (rev 244320)
+++ trunk/Tools/ChangeLog	2019-04-16 02:01:32 UTC (rev 244321)
@@ -1,3 +1,19 @@
+2019-04-15  Chris Dumez  <[email protected]>
+
+        URL set by document.open() is not communicated to the UIProcess
+        https://bugs.webkit.org/show_bug.cgi?id=196941
+        <rdar://problem/49237544>
+
+        Reviewed by Geoffrey Garen.
+
+        Add API test coverage.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit/open-window-then-write-to-it.html: Added.
+        * TestWebKitAPI/Tests/WebKitCocoa/OpenAndCloseWindow.mm:
+        (-[OpenWindowThenDocumentOpenUIDelegate webView:createWebViewWithConfiguration:forNavigationAction:windowFeatures:]):
+        (TEST):
+
 2019-04-15  Dean Johnson  <[email protected]>
 
         Using Tools/Scripts/clean-webkit should not install requests

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (244320 => 244321)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2019-04-16 01:55:50 UTC (rev 244320)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2019-04-16 02:01:32 UTC (rev 244321)
@@ -188,6 +188,7 @@
 		466C3843210637DE006A88DE /* notify-resourceLoadObserver.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 466C3842210637CE006A88DE /* notify-resourceLoadObserver.html */; };
 		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 */; };
 		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 */; };
@@ -1243,6 +1244,7 @@
 				074994421EA5034B000DA44F /* ondevicechange.html in Copy Resources */,
 				CEA6CF2819CCF69D0064F5A7 /* open-and-close-window.html in Copy Resources */,
 				7CCB99231D3B4A46003922F6 /* open-multiple-external-url.html in Copy Resources */,
+				468BC45522653A1000A36C96 /* open-window-then-write-to-it.html in Copy Resources */,
 				290A9BB91735F63800D71BBC /* OpenNewWindow.html in Copy Resources */,
 				83148B09202AC78D00BADE99 /* override-builtins-test.html in Copy Resources */,
 				CEBCA1391E3A807A00C73293 /* page-with-csp-iframe.html in Copy Resources */,
@@ -1576,6 +1578,7 @@
 		466C3842210637CE006A88DE /* notify-resourceLoadObserver.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "notify-resourceLoadObserver.html"; sourceTree = "<group>"; };
 		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>"; };
 		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>"; };
@@ -3418,6 +3421,7 @@
 				C99B675E1E39735C00FC6C80 /* no-autoplay-with-controls.html */,
 				4A410F4D19AF7BEF002EBAB6 /* ondevicechange.html */,
 				CEA6CF2719CCF69D0064F5A7 /* open-and-close-window.html */,
+				468BC454226539C800A36C96 /* open-window-then-write-to-it.html */,
 				83148B08202AC76800BADE99 /* override-builtins-test.html */,
 				0EBBCC651FFF9DCE00FA42AB /* pop-up-check.html */,
 				F6FDDDD514241C48004F1729 /* push-state.html */,

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit/open-window-then-write-to-it.html (0 => 244321)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit/open-window-then-write-to-it.html	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit/open-window-then-write-to-it.html	2019-04-16 02:01:32 UTC (rev 244321)
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script>
+_onload_ = () => {
+    w = window.open("#", "name", "width=400,height=400")
+    w.document.open();
+    w.document.write("TEST");
+    w.document.close();
+};
+</script>
+</body>
+</html>

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/OpenAndCloseWindow.mm (244320 => 244321)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/OpenAndCloseWindow.mm	2019-04-16 01:55:50 UTC (rev 244320)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/OpenAndCloseWindow.mm	2019-04-16 02:01:32 UTC (rev 244321)
@@ -282,3 +282,38 @@
     EXPECT_FALSE([openWindowFeatures _fullscreenDisplay].boolValue);
     openWindowFeatures = nullptr;
 }
+
+@interface OpenWindowThenDocumentOpenUIDelegate : NSObject <WKUIDelegate>
+@end
+
+@implementation OpenWindowThenDocumentOpenUIDelegate
+
+- (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures
+{
+    openedWebView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration]);
+    [openedWebView setUIDelegate:sharedUIDelegate.get()];
+    return openedWebView.get();
+}
+
+@end
+
+TEST(WebKit, OpenWindowThenDocumentOpen)
+{
+    resetToConsistentState();
+
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+
+    auto uiDelegate = adoptNS([[OpenWindowThenDocumentOpenUIDelegate alloc] init]);
+    [webView setUIDelegate:uiDelegate.get()];
+    [webView configuration].preferences._javascript_CanOpenWindowsAutomatically = YES;
+
+    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"open-window-then-write-to-it" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+    [webView loadRequest:request];
+
+    while (!openedWebView)
+        TestWebKitAPI::Util::sleep(0.1);
+
+    // Both WebViews should have the same URL because of document.open().
+    while (![[[openedWebView URL] absoluteString] isEqualToString:[[webView URL] absoluteString]])
+        TestWebKitAPI::Util::sleep(0.1);
+}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to