Changeset 244321 in webkit


Ignore:
Timestamp:
Apr 15, 2019 7:01:32 PM (5 years ago)
Author:
Chris Dumez
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):

Location:
trunk
Files:
1 added
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r244320 r244321  
     12019-04-15  Chris Dumez  <cdumez@apple.com>
     2
     3        URL set by document.open() is not communicated to the UIProcess
     4        https://bugs.webkit.org/show_bug.cgi?id=196941
     5        <rdar://problem/49237544>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        Notify the FrameLoaderClient whenever an explicit open was done and provide it with
     10        the latest document URL.
     11
     12        * loader/FrameLoader.cpp:
     13        (WebCore::FrameLoader::didExplicitOpen):
     14        * loader/FrameLoaderClient.h:
     15
    1162019-04-15  Eike Rathke  <erack@redhat.com>
    217
  • trunk/Source/WebCore/loader/FrameLoader.cpp

    r244161 r244321  
    593593    if (!m_stateMachine.committedFirstRealDocumentLoad())
    594594        m_stateMachine.advanceTo(FrameLoaderStateMachine::DisplayingInitialEmptyDocumentPostCommit);
     595
     596    m_client.dispatchDidExplicitOpen(m_frame.document() ? m_frame.document()->url() : URL());
    595597   
    596598    // Prevent window.open(url) -- eg window.open("about:blank") -- from blowing away results
  • trunk/Source/WebCore/loader/FrameLoaderClient.h

    r244161 r244321  
    182182    virtual void dispatchDidFinishDocumentLoad() = 0;
    183183    virtual void dispatchDidFinishLoad() = 0;
     184    virtual void dispatchDidExplicitOpen(const URL&) { }
    184185#if ENABLE(DATA_DETECTION)
    185186    virtual void dispatchDidFinishDataDetection(NSArray *detectionResults) = 0;
  • trunk/Source/WebKit/ChangeLog

    r244319 r244321  
     12019-04-15  Chris Dumez  <cdumez@apple.com>
     2
     3        URL set by document.open() is not communicated to the UIProcess
     4        https://bugs.webkit.org/show_bug.cgi?id=196941
     5        <rdar://problem/49237544>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        Whenever the UIProcess is notified of an explicit document.open() call, update the
     10        PageLoadState to make sure the URL is up-to-date. Also make sure the page / process
     11        knows it committed a load (i.e. It is no longer showing the initially empty document).
     12
     13        * UIProcess/PageLoadState.cpp:
     14        (WebKit::PageLoadState::didExplicitOpen):
     15        * UIProcess/PageLoadState.h:
     16        * UIProcess/WebPageProxy.cpp:
     17        (WebKit::WebPageProxy::didExplicitOpenForFrame):
     18        * UIProcess/WebPageProxy.h:
     19        * UIProcess/WebPageProxy.messages.in:
     20        * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
     21        (WebKit::WebFrameLoaderClient::dispatchDidExplicitOpen):
     22        * WebProcess/WebCoreSupport/WebFrameLoaderClient.h:
     23
    1242019-04-15  Alex Christensen  <achristensen@webkit.org>
    225
  • trunk/Source/WebKit/UIProcess/PageLoadState.cpp

    r238817 r244321  
    247247}
    248248
     249void PageLoadState::didExplicitOpen(const Transaction::Token& token, const String& url)
     250{
     251    ASSERT_UNUSED(token, &token.m_pageLoadState == this);
     252
     253    m_uncommittedState.state = State::Finished;
     254    m_uncommittedState.url = url;
     255    m_uncommittedState.provisionalURL = String();
     256}
     257
    249258void PageLoadState::didStartProvisionalLoad(const Transaction::Token& token, const String& url, const String& unreachableURL)
    250259{
  • trunk/Source/WebKit/UIProcess/PageLoadState.h

    r242788 r244321  
    144144
    145145    void didStartProvisionalLoad(const Transaction::Token&, const String& url, const String& unreachableURL);
     146    void didExplicitOpen(const Transaction::Token&, const String& url);
    146147    void didReceiveServerRedirectForProvisionalLoad(const Transaction::Token&, const String& url);
    147148    void didFailProvisionalLoad(const Transaction::Token&);
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r244307 r244321  
    39233923}
    39243924
     3925void WebPageProxy::didExplicitOpenForFrame(uint64_t frameID, URL&& url)
     3926{
     3927    auto* frame = m_process->webFrame(frameID);
     3928    MESSAGE_CHECK(m_process, frame);
     3929    MESSAGE_CHECK_URL(m_process, url);
     3930
     3931    auto transaction = m_pageLoadState.transaction();
     3932
     3933    if (frame->isMainFrame())
     3934        m_pageLoadState.didExplicitOpen(transaction, url);
     3935
     3936    m_hasCommittedAnyProvisionalLoads = true;
     3937    m_process->didCommitProvisionalLoad();
     3938
     3939    m_pageLoadState.commitChanges();
     3940}
     3941
    39253942void WebPageProxy::didReceiveServerRedirectForProvisionalLoadForFrame(uint64_t frameID, uint64_t navigationID, ResourceRequest&& request, const UserData& userData)
    39263943{
  • trunk/Source/WebKit/UIProcess/WebPageProxy.h

    r244307 r244321  
    15921592    void didSameDocumentNavigationForFrame(uint64_t frameID, uint64_t navigationID, uint32_t sameDocumentNavigationType, URL&&, const UserData&);
    15931593    void didChangeMainDocument(uint64_t frameID);
     1594    void didExplicitOpenForFrame(uint64_t frameID, URL&&);
    15941595
    15951596    void didReceiveTitleForFrame(uint64_t frameID, const String&, const UserData&);
  • trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in

    r244307 r244321  
    141141    DidDetectXSSForFrame(uint64_t frameID, WebKit::UserData userData)
    142142    DidSameDocumentNavigationForFrame(uint64_t frameID, uint64_t navigationID, uint32_t type, URL url, WebKit::UserData userData)
    143     DidChangeMainDocument(uint64_t frameID);
     143    DidChangeMainDocument(uint64_t frameID)
     144    DidExplicitOpenForFrame(uint64_t frameID, URL url)
    144145    DidDestroyNavigation(uint64_t navigationID)
    145146
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp

    r244212 r244321  
    459459}
    460460
     461void WebFrameLoaderClient::dispatchDidExplicitOpen(const URL& url)
     462{
     463    auto* webPage = m_frame->page();
     464    if (!webPage)
     465        return;
     466
     467    // Notify the UIProcess.
     468    webPage->send(Messages::WebPageProxy::DidExplicitOpenForFrame(m_frame->frameID(), url));
     469}
     470
    461471void WebFrameLoaderClient::dispatchDidStartProvisionalLoad()
    462472{
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.h

    r244161 r244321  
    117117    void dispatchDidFinishDocumentLoad() final;
    118118    void dispatchDidFinishLoad() final;
     119    void dispatchDidExplicitOpen(const URL&) final;
    119120
    120121    void dispatchDidReachLayoutMilestone(OptionSet<WebCore::LayoutMilestone>) final;
  • trunk/Tools/ChangeLog

    r244310 r244321  
     12019-04-15  Chris Dumez  <cdumez@apple.com>
     2
     3        URL set by document.open() is not communicated to the UIProcess
     4        https://bugs.webkit.org/show_bug.cgi?id=196941
     5        <rdar://problem/49237544>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        Add API test coverage.
     10
     11        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     12        * TestWebKitAPI/Tests/WebKit/open-window-then-write-to-it.html: Added.
     13        * TestWebKitAPI/Tests/WebKitCocoa/OpenAndCloseWindow.mm:
     14        (-[OpenWindowThenDocumentOpenUIDelegate webView:createWebViewWithConfiguration:forNavigationAction:windowFeatures:]):
     15        (TEST):
     16
    1172019-04-15  Dean Johnson  <dean_johnson@apple.com>
    218
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r244151 r244321  
    189189                467C565321B5ED130057516D /* GetSessionCookie.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 467C565121B5ECDF0057516D /* GetSessionCookie.html */; };
    190190                467C565421B5ED130057516D /* SetSessionCookie.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 467C565221B5ECDF0057516D /* SetSessionCookie.html */; };
     191                468BC45522653A1000A36C96 /* open-window-then-write-to-it.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 468BC454226539C800A36C96 /* open-window-then-write-to-it.html */; };
    191192                46918EFC2237283C00468DFE /* DeviceOrientation.mm in Sources */ = {isa = PBXBuildFile; fileRef = 46918EFB2237283500468DFE /* DeviceOrientation.mm */; };
    192193                46A911592108E6780078D40D /* CustomUserAgent.mm in Sources */ = {isa = PBXBuildFile; fileRef = 46A911582108E66B0078D40D /* CustomUserAgent.mm */; };
     
    12441245                                CEA6CF2819CCF69D0064F5A7 /* open-and-close-window.html in Copy Resources */,
    12451246                                7CCB99231D3B4A46003922F6 /* open-multiple-external-url.html in Copy Resources */,
     1247                                468BC45522653A1000A36C96 /* open-window-then-write-to-it.html in Copy Resources */,
    12461248                                290A9BB91735F63800D71BBC /* OpenNewWindow.html in Copy Resources */,
    12471249                                83148B09202AC78D00BADE99 /* override-builtins-test.html in Copy Resources */,
     
    15771579                467C565121B5ECDF0057516D /* GetSessionCookie.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = GetSessionCookie.html; sourceTree = "<group>"; };
    15781580                467C565221B5ECDF0057516D /* SetSessionCookie.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = SetSessionCookie.html; sourceTree = "<group>"; };
     1581                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>"; };
    15791582                46918EFB2237283500468DFE /* DeviceOrientation.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DeviceOrientation.mm; sourceTree = "<group>"; };
    15801583                46A911582108E66B0078D40D /* CustomUserAgent.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CustomUserAgent.mm; sourceTree = "<group>"; };
     
    34193422                                4A410F4D19AF7BEF002EBAB6 /* ondevicechange.html */,
    34203423                                CEA6CF2719CCF69D0064F5A7 /* open-and-close-window.html */,
     3424                                468BC454226539C800A36C96 /* open-window-then-write-to-it.html */,
    34213425                                83148B08202AC76800BADE99 /* override-builtins-test.html */,
    34223426                                0EBBCC651FFF9DCE00FA42AB /* pop-up-check.html */,
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/OpenAndCloseWindow.mm

    r242339 r244321  
    283283    openWindowFeatures = nullptr;
    284284}
     285
     286@interface OpenWindowThenDocumentOpenUIDelegate : NSObject <WKUIDelegate>
     287@end
     288
     289@implementation OpenWindowThenDocumentOpenUIDelegate
     290
     291- (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures
     292{
     293    openedWebView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration]);
     294    [openedWebView setUIDelegate:sharedUIDelegate.get()];
     295    return openedWebView.get();
     296}
     297
     298@end
     299
     300TEST(WebKit, OpenWindowThenDocumentOpen)
     301{
     302    resetToConsistentState();
     303
     304    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
     305
     306    auto uiDelegate = adoptNS([[OpenWindowThenDocumentOpenUIDelegate alloc] init]);
     307    [webView setUIDelegate:uiDelegate.get()];
     308    [webView configuration].preferences.javaScriptCanOpenWindowsAutomatically = YES;
     309
     310    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"open-window-then-write-to-it" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     311    [webView loadRequest:request];
     312
     313    while (!openedWebView)
     314        TestWebKitAPI::Util::sleep(0.1);
     315
     316    // Both WebViews should have the same URL because of document.open().
     317    while (![[[openedWebView URL] absoluteString] isEqualToString:[[webView URL] absoluteString]])
     318        TestWebKitAPI::Util::sleep(0.1);
     319}
Note: See TracChangeset for help on using the changeset viewer.