Changeset 184151 in webkit


Ignore:
Timestamp:
May 11, 2015, 10:38:11 PM (10 years ago)
Author:
mitz@apple.com
Message:

Source/WebCore:
WebCore part of <rdar://problem/20878075> Trying to navigate to an invalid URL loads about:blank, but -[WKWebView URL] returns the invalid URL

Reviewed by Alexey Proskuryakov.

Test: TestWebKitAPI/Tests/WebKit2Cocoa/ProvisionalURLChange.mm

In some cases, trying to navigate to an invalid URL results in navigation to about:blank.
When the about:blank load is committed, the UI process still thinks that the provisional
URL is the original, invalid URL, and updates its state to reflect that that’s the URL that
has been committed.

The provisional URL changes (1) when a provisional load begins, (2) when a server redirect
happens, (3) when the client changes the request in willSendRequest, and (4) in this
about:blank case. For (1) and (2), there are frame loader client callbacks. (3) is client-
initiated. So this patch addresses (4).

  • loader/DocumentLoader.cpp:

(WebCore::DocumentLoader::maybeLoadEmpty): If our request URL is changing to about:blank and
while loading the main resource, call FrameLoaderClient::dispatchDidChangeProvisionalURL.

  • loader/FrameLoaderClient.h: Added dispatchDidChangeProvisionalURL with an empty

implementation.

Source/WebKit2:
WebKit2 part of <rdar://problem/20878075> Trying to navigate to an invalid URL loads about:blank, but -[WKWebView URL] returns the invalid URL

Reviewed by Alexey Proskuryakov.

  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::didChangeProvisionalURLForFrame): Added. Update internal state the
same way we update it for server redirects, but don’t make client callbacks. Clients
observing the URL property will see it change.

  • UIProcess/WebPageProxy.h:
  • UIProcess/WebPageProxy.messages.in: Added DidChangeProvisionalURLForFrame.
  • WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:

(WebKit::WebFrameLoaderClient::dispatchDidChangeProvisionalURL): Override this new
FrameLoaderClient function to send a DidChangeProvisionalURLForFrame message to the UI
process.

  • WebProcess/WebCoreSupport/WebFrameLoaderClient.h:

Tools:
Test for <rdar://problem/20878075> Trying to navigate to an invalid URL loads about:blank, but -[WKWebView URL] returns the invalid URL

Reviewed by Alexey Proskuryakov.

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WebKit2Cocoa/LoadAlternateHTMLString.mm: Fixed copyright header.
  • TestWebKitAPI/Tests/WebKit2Cocoa/ProvisionalURLChange.mm: Added.

(-[ProvisionalURLChangeController webView:didFinishNavigation:]):

Location:
trunk
Files:
1 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r184150 r184151  
     12015-05-11  Dan Bernstein  <mitz@apple.com>
     2
     3        WebCore part of <rdar://problem/20878075> Trying to navigate to an invalid URL loads about:blank, but -[WKWebView URL] returns the invalid URL
     4
     5        Reviewed by Alexey Proskuryakov.
     6
     7        Test: TestWebKitAPI/Tests/WebKit2Cocoa/ProvisionalURLChange.mm
     8
     9        In some cases, trying to navigate to an invalid URL results in navigation to about:blank.
     10        When the about:blank load is committed, the UI process still thinks that the provisional
     11        URL is the original, invalid URL, and updates its state to reflect that that’s the URL that
     12        has been committed.
     13
     14        The provisional URL changes (1) when a provisional load begins, (2) when a server redirect
     15        happens, (3) when the client changes the request in willSendRequest, and (4) in this
     16        about:blank case. For (1) and (2), there are frame loader client callbacks. (3) is client-
     17        initiated. So this patch addresses (4).
     18
     19        * loader/DocumentLoader.cpp:
     20        (WebCore::DocumentLoader::maybeLoadEmpty): If our request URL is changing to about:blank and
     21        while loading the main resource, call FrameLoaderClient::dispatchDidChangeProvisionalURL.
     22        * loader/FrameLoaderClient.h: Added dispatchDidChangeProvisionalURL with an empty
     23        implementation.
     24
    1252015-05-11  Zalan Bujtas  <zalan@apple.com>
    226
  • trunk/Source/WebCore/loader/DocumentLoader.cpp

    r183555 r184151  
    13551355        return false;
    13561356
    1357     if (m_request.url().isEmpty() && !frameLoader()->stateMachine().creatingInitialEmptyDocument())
     1357    if (m_request.url().isEmpty() && !frameLoader()->stateMachine().creatingInitialEmptyDocument()) {
    13581358        m_request.setURL(blankURL());
     1359        if (isLoadingMainResource())
     1360            frameLoader()->client().dispatchDidChangeProvisionalURL();
     1361    }
     1362
    13591363    String mimeType = shouldLoadEmpty ? "text/html" : frameLoader()->client().generatedMIMETypeForURLScheme(m_request.url().protocol());
    13601364    m_response = ResourceResponse(m_request.url(), mimeType, 0, String());
  • trunk/Source/WebCore/loader/FrameLoaderClient.h

    r182351 r184151  
    155155        virtual void dispatchDidHandleOnloadEvents() = 0;
    156156        virtual void dispatchDidReceiveServerRedirectForProvisionalLoad() = 0;
     157        virtual void dispatchDidChangeProvisionalURL() { }
    157158        virtual void dispatchDidCancelClientRedirect() = 0;
    158159        virtual void dispatchWillPerformClientRedirect(const URL&, double interval, double fireDate) = 0;
  • trunk/Source/WebKit2/ChangeLog

    r184149 r184151  
     12015-05-11  Dan Bernstein  <mitz@apple.com>
     2
     3        WebKit2 part of <rdar://problem/20878075> Trying to navigate to an invalid URL loads about:blank, but -[WKWebView URL] returns the invalid URL
     4
     5        Reviewed by Alexey Proskuryakov.
     6
     7        * UIProcess/WebPageProxy.cpp:
     8        (WebKit::WebPageProxy::didChangeProvisionalURLForFrame): Added. Update internal state the
     9        same way we update it for server redirects, but don’t make client callbacks. Clients
     10        observing the URL property will see it change.
     11        * UIProcess/WebPageProxy.h:
     12
     13        * UIProcess/WebPageProxy.messages.in: Added DidChangeProvisionalURLForFrame.
     14
     15        * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
     16        (WebKit::WebFrameLoaderClient::dispatchDidChangeProvisionalURL): Override this new
     17        FrameLoaderClient function to send a DidChangeProvisionalURLForFrame message to the UI
     18        process.
     19        * WebProcess/WebCoreSupport/WebFrameLoaderClient.h:
     20
    1212015-05-11  Dan Bernstein  <mitz@apple.com>
    222
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp

    r184066 r184151  
    28392839}
    28402840
     2841void WebPageProxy::didChangeProvisionalURLForFrame(uint64_t frameID, uint64_t, const String& url)
     2842{
     2843    WebFrameProxy* frame = m_process->webFrame(frameID);
     2844    MESSAGE_CHECK(frame);
     2845    MESSAGE_CHECK(frame->frameLoadState().state() == FrameLoadState::State::Provisional);
     2846    MESSAGE_CHECK_URL(url);
     2847
     2848    auto transaction = m_pageLoadState.transaction();
     2849
     2850    // Internally, we handle this the same way we handle a server redirect. There are no client callbacks
     2851    // for this, but if this is the main frame, clients may observe a change to the page's URL.
     2852    if (frame->isMainFrame())
     2853        m_pageLoadState.didReceiveServerRedirectForProvisionalLoad(transaction, url);
     2854
     2855    frame->didReceiveServerRedirectForProvisionalLoad(url);
     2856}
     2857
    28412858void WebPageProxy::didFailProvisionalLoadForFrame(uint64_t frameID, uint64_t navigationID, const String& provisionalURL, const ResourceError& error, const UserData& userData)
    28422859{
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.h

    r184011 r184151  
    10891089    void didStartProvisionalLoadForFrame(uint64_t frameID, uint64_t navigationID, const String& url, const String& unreachableURL, const UserData&);
    10901090    void didReceiveServerRedirectForProvisionalLoadForFrame(uint64_t frameID, uint64_t navigationID, const String&, const UserData&);
     1091    void didChangeProvisionalURLForFrame(uint64_t frameID, uint64_t navigationID, const String& url);
    10911092    void didFailProvisionalLoadForFrame(uint64_t frameID, uint64_t navigationID, const String& provisionalURL, const WebCore::ResourceError&, const UserData&);
    10921093    void didCommitLoadForFrame(uint64_t frameID, uint64_t navigationID, const String& mimeType, bool frameHasCustomContentProvider, uint32_t frameLoadType, const WebCore::CertificateInfo&, const UserData&);
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in

    r184011 r184151  
    130130    DidStartProvisionalLoadForFrame(uint64_t frameID, uint64_t navigationID, String url, String unreachableURL, WebKit::UserData userData)
    131131    DidReceiveServerRedirectForProvisionalLoadForFrame(uint64_t frameID, uint64_t navigationID, String url, WebKit::UserData userData)
     132    DidChangeProvisionalURLForFrame(uint64_t frameID, uint64_t navigationID, String url)
    132133    DidFailProvisionalLoadForFrame(uint64_t frameID, uint64_t navigationID, String provisionalURL, WebCore::ResourceError error, WebKit::UserData userData)
    133134    DidCommitLoadForFrame(uint64_t frameID, uint64_t navigationID, String mimeType, bool hasCustomContentProvider, uint32_t loadType, WebCore::CertificateInfo certificateInfo, WebKit::UserData userData)
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp

    r183698 r184151  
    295295}
    296296
     297void WebFrameLoaderClient::dispatchDidChangeProvisionalURL()
     298{
     299    WebPage* webPage = m_frame->page();
     300    if (!webPage)
     301        return;
     302
     303    WebDocumentLoader& documentLoader = static_cast<WebDocumentLoader&>(*m_frame->coreFrame()->loader().provisionalDocumentLoader());
     304    webPage->send(Messages::WebPageProxy::DidChangeProvisionalURLForFrame(m_frame->frameID(), documentLoader.navigationID(), documentLoader.url().string()));
     305}
     306
    297307void WebFrameLoaderClient::dispatchDidCancelClientRedirect()
    298308{
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.h

    r180985 r184151  
    8181    virtual void dispatchDidHandleOnloadEvents() override;
    8282    virtual void dispatchDidReceiveServerRedirectForProvisionalLoad() override;
     83    virtual void dispatchDidChangeProvisionalURL() override;
    8384    virtual void dispatchDidCancelClientRedirect() override;
    8485    virtual void dispatchWillPerformClientRedirect(const WebCore::URL&, double interval, double fireDate) override;
  • trunk/Tools/ChangeLog

    r184146 r184151  
     12015-05-11  Dan Bernstein  <mitz@apple.com>
     2
     3        Test for <rdar://problem/20878075> Trying to navigate to an invalid URL loads about:blank, but -[WKWebView URL] returns the invalid URL
     4
     5        Reviewed by Alexey Proskuryakov.
     6
     7        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     8        * TestWebKitAPI/Tests/WebKit2Cocoa/LoadAlternateHTMLString.mm: Fixed copyright header.
     9        * TestWebKitAPI/Tests/WebKit2Cocoa/ProvisionalURLChange.mm: Added.
     10        (-[ProvisionalURLChangeController webView:didFinishNavigation:]):
     11
    1122015-05-11  Jake Nielsen  <jacob_nielsen@apple.com>
    213
     
    812823
    813824        * gtk/install-dependencies:
     825
     8262015-05-01  Dan Bernstein  <mitz@apple.com>
     827
     828        Test for <rdar://problem/8636045> Back/forward navigation to an error page in Safari breaks the back-forward list
     829        https://bugs.webkit.org/show_bug.cgi?id=144501
     830
     831        Reviewed by Darin Adler.
     832
     833        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     834        * TestWebKitAPI/Tests/WebKit2Cocoa/LoadAlternateHTMLString.mm: Added.
     835        (-[LoadAlternateHTMLStringFromProvisionalLoadErrorController webView:didFailProvisionalNavigation:withError:]):
     836        (-[LoadAlternateHTMLStringFromProvisionalLoadErrorController webView:didFinishNavigation:]):
    814837
    8158382015-05-01  Mario Sanchez Prada  <mario@endlessm.com>
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r183933 r184151  
    4343                379028B914FAC24C007E6B43 /* acceptsFirstMouse.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 379028B814FABE49007E6B43 /* acceptsFirstMouse.html */; };
    4444                37D36ED71AF42ECD00BAF5D9 /* LoadAlternateHTMLString.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37D36ED61AF42ECD00BAF5D9 /* LoadAlternateHTMLString.mm */; };
     45                37D36F321B004DD400BAF5D9 /* ProvisionalURLChange.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37D36F311B004DD400BAF5D9 /* ProvisionalURLChange.mm */; };
    4546                37DC6791140D7D7600ABCCDB /* DOMRangeOfString.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 37DC678F140D7D3A00ABCCDB /* DOMRangeOfString.html */; };
    4647                37E1064C1697681800B78BD0 /* DOMHTMLTableCellElementCellAbove.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 37E1064B169767F700B78BD0 /* DOMHTMLTableCellElementCellAbove.html */; };
     
    491492                37C784DE197C8F2E0010A496 /* RenderedImageFromDOMNode.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RenderedImageFromDOMNode.mm; sourceTree = "<group>"; };
    492493                37D36ED61AF42ECD00BAF5D9 /* LoadAlternateHTMLString.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LoadAlternateHTMLString.mm; sourceTree = "<group>"; };
     494                37D36F311B004DD400BAF5D9 /* ProvisionalURLChange.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ProvisionalURLChange.mm; sourceTree = "<group>"; };
    493495                37DC678B140D7C5000ABCCDB /* DOMRangeOfString.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DOMRangeOfString.mm; sourceTree = "<group>"; };
    494496                37DC678F140D7D3A00ABCCDB /* DOMRangeOfString.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = DOMRangeOfString.html; sourceTree = "<group>"; };
     
    830832                                A1A4FE5D18DD3DB700B5EA8A /* Download.mm */,
    831833                                2D1FE0AF1AD465C1006CD9E6 /* FixedLayoutSize.mm */,
     834                                37D36ED61AF42ECD00BAF5D9 /* LoadAlternateHTMLString.mm */,
    832835                                1ABC3DED1899BE6D004F0626 /* Navigation.mm */,
    833836                                CEA6CF2219CCF5BD0064F5A7 /* OpenAndCloseWindow.mm */,
    834837                                C95501BE19AD2FAF0049BE3E /* Preferences.mm */,
     838                                37D36F311B004DD400BAF5D9 /* ProvisionalURLChange.mm */,
    835839                                7CC3E1FA197E234100BE6252 /* UserContentController.mm */,
    836840                                0F3B94A51A77266C00DE3272 /* WKWebViewEvaluateJavaScript.mm */,
    837                                 37D36ED61AF42ECD00BAF5D9 /* LoadAlternateHTMLString.mm */,
    838841                        );
    839842                        name = "WebKit2 Cocoa";
     
    14261429                                7CCE7EBA1A411A7E00447C4C /* DeviceScaleFactorOnBack.mm in Sources */,
    14271430                                7CCE7EE91A411AE600447C4C /* DidAssociateFormControls.cpp in Sources */,
     1431                                37D36F321B004DD400BAF5D9 /* ProvisionalURLChange.mm in Sources */,
    14281432                                7CCE7EEA1A411AE600447C4C /* DidNotHandleKeyDown.cpp in Sources */,
    14291433                                7CCE7EEB1A411AE600447C4C /* DocumentStartUserScriptAlertCrash.cpp in Sources */,
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/LoadAlternateHTMLString.mm

    r183698 r184151  
    11/*
    2  * Copyright (C) 2014 Apple Inc. All rights reserved.
     2 * Copyright (C) 2015 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
Note: See TracChangeset for help on using the changeset viewer.