Title: [207325] trunk
Revision
207325
Author
carlo...@webkit.org
Date
2016-10-13 23:29:36 -0700 (Thu, 13 Oct 2016)

Log Message

WebView and WebPage URLs not updated after URL is modified by InjectedBundlePageResourceLoadClient::willSendRequestForFrame
https://bugs.webkit.org/show_bug.cgi?id=146306

Reviewed by Darin Adler.

Source/WebCore:

Notify about the provisional URL change when new request set for main resource load in DocumentLoader has a
different URL than the previous one.

* loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::setRequest):

Tools:

Add unit test to check that the committed URL is updated when changed in willSendRequest callback.

* TestWebKitAPI/CMakeLists.txt:
* TestWebKitAPI/PlatformEfl.cmake:
* TestWebKitAPI/PlatformGTK.cmake:
* TestWebKitAPI/Tests/WebKit2/ProvisionalURLAfterWillSendRequestCallback.cpp: Added.
(TestWebKitAPI::didCommitLoadForFrame):
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebKit2/ProvisionalURLAfterWillSendRequestCallback_Bundle.cpp: Added.
(TestWebKitAPI::ProvisionalURLAfterWillSendRequestCallbackTest::ProvisionalURLAfterWillSendRequestCallbackTest):
(TestWebKitAPI::ProvisionalURLAfterWillSendRequestCallbackTest::willSendRequestForFrame):
(TestWebKitAPI::ProvisionalURLAfterWillSendRequestCallbackTest::didCommitLoadForFrame):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (207324 => 207325)


--- trunk/Source/WebCore/ChangeLog	2016-10-14 06:19:12 UTC (rev 207324)
+++ trunk/Source/WebCore/ChangeLog	2016-10-14 06:29:36 UTC (rev 207325)
@@ -1,3 +1,16 @@
+2016-10-13  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        WebView and WebPage URLs not updated after URL is modified by InjectedBundlePageResourceLoadClient::willSendRequestForFrame
+        https://bugs.webkit.org/show_bug.cgi?id=146306
+
+        Reviewed by Darin Adler.
+
+        Notify about the provisional URL change when new request set for main resource load in DocumentLoader has a
+        different URL than the previous one.
+
+        * loader/DocumentLoader.cpp:
+        (WebCore::DocumentLoader::setRequest):
+
 2016-10-13  Youenn Fablet  <you...@apple.com>
 
         Update serializer and iterator binding generated code

Modified: trunk/Source/WebCore/loader/DocumentLoader.cpp (207324 => 207325)


--- trunk/Source/WebCore/loader/DocumentLoader.cpp	2016-10-14 06:19:12 UTC (rev 207324)
+++ trunk/Source/WebCore/loader/DocumentLoader.cpp	2016-10-14 06:29:36 UTC (rev 207325)
@@ -234,8 +234,11 @@
 
     handlingUnreachableURL = m_substituteData.isValid() && !m_substituteData.failingURL().isEmpty();
 
+    bool shouldNotifyAboutProvisionalURLChange = false;
     if (handlingUnreachableURL)
         m_committed = false;
+    else if (isLoadingMainResource() && req.url() != m_request.url())
+        shouldNotifyAboutProvisionalURLChange = true;
 
     // We should never be getting a redirect callback after the data
     // source is committed, except in the unreachable URL case. It 
@@ -243,6 +246,8 @@
     ASSERT(!m_committed);
 
     m_request = req;
+    if (shouldNotifyAboutProvisionalURLChange)
+        frameLoader()->client().dispatchDidChangeProvisionalURL();
 }
 
 void DocumentLoader::setMainDocumentError(const ResourceError& error)

Modified: trunk/Tools/ChangeLog (207324 => 207325)


--- trunk/Tools/ChangeLog	2016-10-14 06:19:12 UTC (rev 207324)
+++ trunk/Tools/ChangeLog	2016-10-14 06:29:36 UTC (rev 207325)
@@ -1,3 +1,23 @@
+2016-10-13  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        WebView and WebPage URLs not updated after URL is modified by InjectedBundlePageResourceLoadClient::willSendRequestForFrame
+        https://bugs.webkit.org/show_bug.cgi?id=146306
+
+        Reviewed by Darin Adler.
+
+        Add unit test to check that the committed URL is updated when changed in willSendRequest callback.
+
+        * TestWebKitAPI/CMakeLists.txt:
+        * TestWebKitAPI/PlatformEfl.cmake:
+        * TestWebKitAPI/PlatformGTK.cmake:
+        * TestWebKitAPI/Tests/WebKit2/ProvisionalURLAfterWillSendRequestCallback.cpp: Added.
+        (TestWebKitAPI::didCommitLoadForFrame):
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/Tests/WebKit2/ProvisionalURLAfterWillSendRequestCallback_Bundle.cpp: Added.
+        (TestWebKitAPI::ProvisionalURLAfterWillSendRequestCallbackTest::ProvisionalURLAfterWillSendRequestCallbackTest):
+        (TestWebKitAPI::ProvisionalURLAfterWillSendRequestCallbackTest::willSendRequestForFrame):
+        (TestWebKitAPI::ProvisionalURLAfterWillSendRequestCallbackTest::didCommitLoadForFrame):
+
 2016-10-13  Alex Christensen  <achristen...@webkit.org>
 
         Hosts of URLs with non-special schemes should be case-sensitive, and non-ASCII characters in such hosts should be punycode-encoded

Modified: trunk/Tools/TestWebKitAPI/CMakeLists.txt (207324 => 207325)


--- trunk/Tools/TestWebKitAPI/CMakeLists.txt	2016-10-14 06:19:12 UTC (rev 207324)
+++ trunk/Tools/TestWebKitAPI/CMakeLists.txt	2016-10-14 06:29:36 UTC (rev 207325)
@@ -149,6 +149,7 @@
         ${TESTWEBKITAPI_DIR}/Tests/WebKit2/NewFirstVisuallyNonEmptyLayoutFrames_Bundle.cpp
         ${TESTWEBKITAPI_DIR}/Tests/WebKit2/NewFirstVisuallyNonEmptyLayout_Bundle.cpp
         ${TESTWEBKITAPI_DIR}/Tests/WebKit2/ParentFrame_Bundle.cpp
+        ${TESTWEBKITAPI_DIR}/Tests/WebKit2/ProvisionalURLAfterWillSendRequestCallback_Bundle.cpp
         ${TESTWEBKITAPI_DIR}/Tests/WebKit2/ResponsivenessTimerDoesntFireEarly_Bundle.cpp
         ${TESTWEBKITAPI_DIR}/Tests/WebKit2/ShouldGoToBackForwardListItem_Bundle.cpp
         ${TESTWEBKITAPI_DIR}/Tests/WebKit2/TextFieldDidBeginAndEndEditing_Bundle.cpp

Modified: trunk/Tools/TestWebKitAPI/PlatformEfl.cmake (207324 => 207325)


--- trunk/Tools/TestWebKitAPI/PlatformEfl.cmake	2016-10-14 06:19:12 UTC (rev 207324)
+++ trunk/Tools/TestWebKitAPI/PlatformEfl.cmake	2016-10-14 06:29:36 UTC (rev 207325)
@@ -97,6 +97,7 @@
     PendingAPIRequestURL
     PreventEmptyUserAgent
     PrivateBrowsingPushStateNoHistoryCallback
+    ProvisionalURLAfterWillSendRequestCallback
     ResponsivenessTimerDoesntFireEarly
     ShouldGoToBackForwardListItem
     TerminateTwice

Modified: trunk/Tools/TestWebKitAPI/PlatformGTK.cmake (207324 => 207325)


--- trunk/Tools/TestWebKitAPI/PlatformGTK.cmake	2016-10-14 06:19:12 UTC (rev 207324)
+++ trunk/Tools/TestWebKitAPI/PlatformGTK.cmake	2016-10-14 06:29:36 UTC (rev 207325)
@@ -101,6 +101,7 @@
     ${TESTWEBKITAPI_DIR}/Tests/WebKit2/PendingAPIRequestURL.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebKit2/PreventEmptyUserAgent.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebKit2/PrivateBrowsingPushStateNoHistoryCallback.cpp
+    ${TESTWEBKITAPI_DIR}/Tests/WebKit2/ProvisionalURLAfterWillSendRequestCallback.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebKit2/ReloadPageAfterCrash.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebKit2/ResizeWindowAfterCrash.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebKit2/RestoreSessionStateContainingFormData.cpp

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2/ProvisionalURLAfterWillSendRequestCallback.cpp (0 => 207325)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/ProvisionalURLAfterWillSendRequestCallback.cpp	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/ProvisionalURLAfterWillSendRequestCallback.cpp	2016-10-14 06:29:36 UTC (rev 207325)
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2016 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if WK_HAVE_C_SPI
+
+#include "PlatformUtilities.h"
+#include "PlatformWebView.h"
+#include "Test.h"
+#include <WebKit/WKContext.h>
+#include <WebKit/WKFrame.h>
+#include <WebKit/WKRetainPtr.h>
+
+namespace TestWebKitAPI {
+
+static bool committedLoad;
+
+static void didCommitLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void*)
+{
+    if (!WKFrameIsMainFrame(frame))
+        return;
+
+    // The provisional URL should be null.
+    EXPECT_NULL(WKFrameCopyProvisionalURL(frame));
+
+    // The committed URL is the last known provisional URL.
+    WKRetainPtr<WKURLRef> committedURL = adoptWK(WKFrameCopyURL(frame));
+    ASSERT_NOT_NULL(committedURL.get());
+    WKRetainPtr<WKURLRef> activeURL = adoptWK(WKPageCopyActiveURL(page));
+    ASSERT_NOT_NULL(activeURL.get());
+    EXPECT_TRUE(WKURLIsEqual(committedURL.get(), activeURL.get()));
+    assert(WKGetTypeID(userData) == WKURLGetTypeID());
+    EXPECT_TRUE(WKURLIsEqual(committedURL.get(), static_cast<WKURLRef>(userData)));
+
+    WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("simple2", "html"));
+    EXPECT_TRUE(WKURLIsEqual(committedURL.get(), url.get()));
+
+    committedLoad = true;
+}
+
+TEST(WebKit2, ProvisionalURLAfterWillSendRequestCallback)
+{
+    WKRetainPtr<WKContextRef> context(AdoptWK, Util::createContextForInjectedBundleTest("ProvisionalURLAfterWillSendRequestCallbackTest"));
+
+    WKContextInjectedBundleClientV0 injectedBundleClient;
+    memset(&injectedBundleClient, 0, sizeof(injectedBundleClient));
+    injectedBundleClient.base.version = 0;
+    WKContextSetInjectedBundleClient(context.get(), &injectedBundleClient.base);
+
+    PlatformWebView webView(context.get());
+
+    WKPageLoaderClientV0 loaderClient;
+    memset(&loaderClient, 0, sizeof(loaderClient));
+
+    loaderClient.base.version = 0;
+    loaderClient.didCommitLoadForFrame = didCommitLoadForFrame;
+    WKPageSetPageLoaderClient(webView.page(), &loaderClient.base);
+
+    WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("simple", "html"));
+    WKPageLoadURL(webView.page(), url.get());
+    Util::run(&committedLoad);
+}
+
+} // namespace TestWebKitAPI
+
+#endif

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2/ProvisionalURLAfterWillSendRequestCallback_Bundle.cpp (0 => 207325)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/ProvisionalURLAfterWillSendRequestCallback_Bundle.cpp	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/ProvisionalURLAfterWillSendRequestCallback_Bundle.cpp	2016-10-14 06:29:36 UTC (rev 207325)
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2016 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if WK_HAVE_C_SPI
+
+#include "InjectedBundleTest.h"
+#include "PlatformUtilities.h"
+#include "Test.h"
+#include <WebKit/WKBundleFrame.h>
+#include <WebKit/WKBundlePage.h>
+#include <WebKit/WKRetainPtr.h>
+
+namespace TestWebKitAPI {
+
+class ProvisionalURLAfterWillSendRequestCallbackTest : public InjectedBundleTest {
+public:
+    ProvisionalURLAfterWillSendRequestCallbackTest(const std::string& identifier)
+        : InjectedBundleTest(identifier)
+    {
+    }
+
+    static WKURLRequestRef willSendRequestForFrame(WKBundlePageRef, WKBundleFrameRef frame, uint64_t resourceIdentifier, WKURLRequestRef request, WKURLResponseRef redirectResponse, const void*)
+    {
+        if (!WKBundleFrameIsMainFrame(frame)) {
+            WKRetainPtr<WKURLRequestRef> newRequest = request;
+            return newRequest.leakRef();
+        }
+
+        // Change the main frame URL.
+        WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("simple2", "html"));
+        return WKURLRequestCreateWithWKURL(url.get());
+    }
+
+    static void didCommitLoadForFrame(WKBundlePageRef, WKBundleFrameRef frame, WKTypeRef* userData, const void*)
+    {
+        if (!WKBundleFrameIsMainFrame(frame))
+            return;
+        *userData = WKBundleFrameCopyURL(frame);
+    }
+
+    void didCreatePage(WKBundleRef bundle, WKBundlePageRef page) override
+    {
+        WKBundlePageResourceLoadClientV0 resourceLoadClient;
+        memset(&resourceLoadClient, 0, sizeof(resourceLoadClient));
+        resourceLoadClient.base.version = 0;
+        resourceLoadClient.willSendRequestForFrame = willSendRequestForFrame;
+        WKBundlePageSetResourceLoadClient(page, &resourceLoadClient.base);
+
+        WKBundlePageLoaderClientV0 pageLoaderClient;
+        memset(&pageLoaderClient, 0, sizeof(pageLoaderClient));
+        pageLoaderClient.base.version = 0;
+        pageLoaderClient.didCommitLoadForFrame = didCommitLoadForFrame;
+        WKBundlePageSetPageLoaderClient(page, &pageLoaderClient.base);
+    }
+};
+
+static InjectedBundleTest::Register<ProvisionalURLAfterWillSendRequestCallbackTest> registrar("ProvisionalURLAfterWillSendRequestCallbackTest");
+
+} // namespace TestWebKitAPI
+
+#endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to