Make WKBundlePageCanHandleRequest return true for empty document URLs
authoraroben@apple.com <aroben@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 15 Mar 2011 04:30:44 +0000 (04:30 +0000)
committeraroben@apple.com <aroben@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 15 Mar 2011 04:30:44 +0000 (04:30 +0000)
Reviewed by Sam Weinig.

Source/WebKit2:

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::canHandleRequest): Return true for any URL schemes that are handled as
empty documents, and defer to the platform for everything else.

* WebProcess/WebPage/WebPage.h: Added platformCanHandleRequest.

* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::platformCanHandleRequest):
* WebProcess/WebPage/qt/WebPageQt.cpp:
(WebKit::WebPage::platformCanHandleRequest):
* WebProcess/WebPage/win/WebPageWin.cpp:
(WebKit::WebPage::platformCanHandleRequest):
Renamed from canHandleRequest.

Tools:

Test that WKBundlePageCanHandleRequest returns true for empty document URLs

* TestWebKitAPI/Tests/WebKit2/CanHandleRequest.cpp: Added.
(TestWebKitAPI::didReceiveMessageFromInjectedBundle): Store the result of the test.
(TestWebKitAPI::setInjectedBundleClient): Hook up our callback.
(TestWebKitAPI::TEST): Register "emptyscheme" as an empty document scheme, load a page to
ensure the web process is initialized, then ask the bundle to run the test and assert that
it succeeded.

* TestWebKitAPI/Tests/WebKit2/CanHandleRequest_Bundle.cpp: Added.
(TestWebKitAPI::CanHandleRequestTest::CanHandleRequestTest): Just call up to the base class.
(TestWebKitAPI::canHandleURL): Helper function to test whether WebKit2 claims to be able to
handle a given URL.
(TestWebKitAPI::runTest): Check that empty document URLs can be handled (and that an unknown
URL type cannot be handled).
(TestWebKitAPI::CanHandleRequestTest::didReceiveMessage): Run the test and return the
result.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/win/TestWebKitAPI.vcproj:
* TestWebKitAPI/win/TestWebKitAPIInjectedBundle.vcproj:
Added new files to the project.

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

12 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm
Source/WebKit2/WebProcess/WebPage/qt/WebPageQt.cpp
Source/WebKit2/WebProcess/WebPage/win/WebPageWin.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKit2/CanHandleRequest.cpp [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/WebKit2/CanHandleRequest_Bundle.cpp [new file with mode: 0644]
Tools/TestWebKitAPI/win/TestWebKitAPI.vcproj
Tools/TestWebKitAPI/win/TestWebKitAPIInjectedBundle.vcproj

index 5e4604b..340787c 100644 (file)
@@ -1,3 +1,23 @@
+2011-03-14  Adam Roben  <aroben@apple.com>
+
+        Make WKBundlePageCanHandleRequest return true for empty document URLs
+
+        Reviewed by Sam Weinig.
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::canHandleRequest): Return true for any URL schemes that are handled as
+        empty documents, and defer to the platform for everything else.
+
+        * WebProcess/WebPage/WebPage.h: Added platformCanHandleRequest.
+
+        * WebProcess/WebPage/mac/WebPageMac.mm:
+        (WebKit::WebPage::platformCanHandleRequest):
+        * WebProcess/WebPage/qt/WebPageQt.cpp:
+        (WebKit::WebPage::platformCanHandleRequest):
+        * WebProcess/WebPage/win/WebPageWin.cpp:
+        (WebKit::WebPage::platformCanHandleRequest):
+        Renamed from canHandleRequest.
+
 2011-03-14  Chris Fleizach  <cfleizach@apple.com>
 
         Reviewed by Beth Dakin.
index 7817290..036f6d1 100644 (file)
@@ -92,6 +92,7 @@
 #include <WebCore/RenderView.h>
 #include <WebCore/ReplaceSelectionCommand.h>
 #include <WebCore/ResourceRequest.h>
+#include <WebCore/SchemeRegistry.h>
 #include <WebCore/SerializedScriptValue.h>
 #include <WebCore/Settings.h>
 #include <WebCore/SharedBuffer.h>
@@ -2120,4 +2121,11 @@ void WebPage::platformDragEnded()
 }
 #endif
 
+bool WebPage::canHandleRequest(const WebCore::ResourceRequest& request)
+{
+    if (SchemeRegistry::shouldLoadURLSchemeAsEmptyDocument(request.url().protocol()))
+        return true;
+    return platformCanHandleRequest(request);
+}
+
 } // namespace WebKit
index 01924fb..a573de2 100644 (file)
@@ -486,6 +486,8 @@ private:
 
     void platformDragEnded();
 
+    static bool platformCanHandleRequest(const WebCore::ResourceRequest&);
+
     OwnPtr<WebCore::Page> m_page;
     RefPtr<WebFrame> m_mainFrame;
     RefPtr<InjectedBundleBackForwardList> m_backForwardList;
index 09b82d3..bd1b109 100644 (file)
@@ -472,10 +472,10 @@ String WebPage::cachedResponseMIMETypeForURL(const WebCore::KURL& url)
     return [[cachedResponse response] MIMEType];
 }
 
-bool WebPage::canHandleRequest(const WebCore::ResourceRequest& request)
+bool WebPage::platformCanHandleRequest(const WebCore::ResourceRequest& request)
 {
     if ([NSURLConnection canHandleRequest:request.nsURLRequest()])
-        return YES;
+        return true;
 
     // FIXME: Return true if this scheme is any one WebKit2 knows how to handle.
     return request.url().protocolIs("applewebdata");
index cad0c04..de8385c 100644 (file)
@@ -277,7 +277,7 @@ String WebPage::cachedResponseMIMETypeForURL(const WebCore::KURL&)
     return String();
 }
 
-bool WebPage::canHandleRequest(const WebCore::ResourceRequest&)
+bool WebPage::platformCanHandleRequest(const WebCore::ResourceRequest&)
 {
     // FIXME: Implement
     return true;
index 73ba2b2..f937144 100644 (file)
@@ -296,10 +296,9 @@ String WebPage::cachedResponseMIMETypeForURL(const WebCore::KURL& url)
 #endif
 }
 
-bool WebPage::canHandleRequest(const WebCore::ResourceRequest& request)
+bool WebPage::platformCanHandleRequest(const WebCore::ResourceRequest& request)
 {
 #if USE(CFNETWORK)
-     // FIXME: Are there other requests we need to be able to handle? WebKit1's WebView.cpp has a FIXME here as well.
     return CFURLProtocolCanHandleRequest(request.cfURLRequest());
 #else
     return true;
index b11c7fa..58c19b3 100644 (file)
@@ -1,3 +1,30 @@
+2011-03-14  Adam Roben  <aroben@apple.com>
+
+        Test that WKBundlePageCanHandleRequest returns true for empty document URLs
+
+        Reviewed by Sam Weinig.
+
+        * TestWebKitAPI/Tests/WebKit2/CanHandleRequest.cpp: Added.
+        (TestWebKitAPI::didReceiveMessageFromInjectedBundle): Store the result of the test.
+        (TestWebKitAPI::setInjectedBundleClient): Hook up our callback.
+        (TestWebKitAPI::TEST): Register "emptyscheme" as an empty document scheme, load a page to
+        ensure the web process is initialized, then ask the bundle to run the test and assert that
+        it succeeded.
+
+        * TestWebKitAPI/Tests/WebKit2/CanHandleRequest_Bundle.cpp: Added.
+        (TestWebKitAPI::CanHandleRequestTest::CanHandleRequestTest): Just call up to the base class.
+        (TestWebKitAPI::canHandleURL): Helper function to test whether WebKit2 claims to be able to
+        handle a given URL.
+        (TestWebKitAPI::runTest): Check that empty document URLs can be handled (and that an unknown
+        URL type cannot be handled).
+        (TestWebKitAPI::CanHandleRequestTest::didReceiveMessage): Run the test and return the
+        result.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/win/TestWebKitAPI.vcproj:
+        * TestWebKitAPI/win/TestWebKitAPIInjectedBundle.vcproj:
+        Added new files to the project.
+
 2011-03-14  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed, rolling out r81094.
index 7179cfb..8bc12a7 100644 (file)
@@ -18,6 +18,8 @@
                BC131885117114B600B69727 /* PlatformUtilitiesMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC131884117114B600B69727 /* PlatformUtilitiesMac.mm */; };
                BC131A9B1171316900B69727 /* main.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC131A9A1171316900B69727 /* main.mm */; };
                BC131AA9117131FC00B69727 /* TestsController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC131AA8117131FC00B69727 /* TestsController.cpp */; };
+               BC246D9A132F1FE100B56D7C /* CanHandleRequest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC246D98132F1FE100B56D7C /* CanHandleRequest.cpp */; };
+               BC246D9C132F1FF000B56D7C /* CanHandleRequest_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC246D97132F1FE100B56D7C /* CanHandleRequest_Bundle.cpp */; };
                BC2D004912A9FDFA00E732A3 /* PageLoadDidChangeLocationWithinPageForFrame.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC2D004812A9FDFA00E732A3 /* PageLoadDidChangeLocationWithinPageForFrame.cpp */; };
                BC2D006412AA04CE00E732A3 /* file-with-anchor.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = BC2D004A12A9FEB300E732A3 /* file-with-anchor.html */; };
                BC575A90126E74D3006F0F12 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BCB9E9F011235BDE00A137E0 /* Cocoa.framework */; };
                BC131A9A1171316900B69727 /* main.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = main.mm; sourceTree = "<group>"; };
                BC131A9E1171317C00B69727 /* TestWebKitAPIPrefix.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestWebKitAPIPrefix.h; sourceTree = "<group>"; };
                BC131AA8117131FC00B69727 /* TestsController.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.cpp; fileEncoding = 4; path = TestsController.cpp; sourceTree = "<group>"; };
+               BC246D97132F1FE100B56D7C /* CanHandleRequest_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CanHandleRequest_Bundle.cpp; sourceTree = "<group>"; };
+               BC246D98132F1FE100B56D7C /* CanHandleRequest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CanHandleRequest.cpp; sourceTree = "<group>"; };
                BC2D004812A9FDFA00E732A3 /* PageLoadDidChangeLocationWithinPageForFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PageLoadDidChangeLocationWithinPageForFrame.cpp; sourceTree = "<group>"; };
                BC2D004A12A9FEB300E732A3 /* file-with-anchor.html */ = {isa = PBXFileReference; explicitFileType = text.html; fileEncoding = 4; path = "file-with-anchor.html"; sourceTree = "<group>"; };
                BC575946126E7351006F0F12 /* InjectedBundleMain.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InjectedBundleMain.cpp; sourceTree = "<group>"; };
                        isa = PBXGroup;
                        children = (
                                BC90977B125571AE00083756 /* Resources */,
+                               BC246D97132F1FE100B56D7C /* CanHandleRequest_Bundle.cpp */,
+                               BC246D98132F1FE100B56D7C /* CanHandleRequest.cpp */,
                                BCB6803F126FBFE100642A61 /* DocumentStartUserScriptAlertCrash.cpp */,
                                BCB68041126FBFF100642A61 /* DocumentStartUserScriptAlertCrash_Bundle.cpp */,
                                1A5FEFDC1270E2A3000E2921 /* EvaluateJavaScript.cpp */,
                                4BFDFFA9131477770061F24B /* HitTestResultNodeHandle.cpp in Sources */,
                                C0BD669D131D3CF700E18F2A /* ResponsivenessTimerDoesntFireEarly.cpp in Sources */,
                                F6C59E38132AC5E000176C09 /* SendingMessagesToTheWebProcessBeforeItIsValid.cpp in Sources */,
+                               BC246D9A132F1FE100B56D7C /* CanHandleRequest.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                BCB68042126FBFF100642A61 /* DocumentStartUserScriptAlertCrash_Bundle.cpp in Sources */,
                                4BFDFFA71314776C0061F24B /* HitTestResultNodeHandle_Bundle.cpp in Sources */,
                                C0BD669F131D3CFF00E18F2A /* ResponsivenessTimerDoesntFireEarly_Bundle.cpp in Sources */,
+                               BC246D9C132F1FF000B56D7C /* CanHandleRequest_Bundle.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/CanHandleRequest.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/CanHandleRequest.cpp
new file mode 100644 (file)
index 0000000..8460847
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * 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 "Test.h"
+
+#include "PlatformUtilities.h"
+#include "PlatformWebView.h"
+#include <WebKit2/WKContextPrivate.h>
+#include <WebKit2/WKNumber.h>
+
+namespace TestWebKitAPI {
+
+static bool didReceiveMessage;
+static bool canHandleRequest;
+
+static void didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef body, const void*)
+{
+    didReceiveMessage = true;
+
+    TEST_ASSERT(WKStringIsEqualToUTF8CString(messageName, "DidCheckCanHandleRequest"));
+    TEST_ASSERT(WKGetTypeID(body) == WKBooleanGetTypeID());
+    canHandleRequest = WKBooleanGetValue(static_cast<WKBooleanRef>(body));
+}
+
+static void setInjectedBundleClient(WKContextRef context)
+{
+    WKContextInjectedBundleClient injectedBundleClient;
+    memset(&injectedBundleClient, 0, sizeof(injectedBundleClient));
+    injectedBundleClient.didReceiveMessageFromInjectedBundle = didReceiveMessageFromInjectedBundle;
+
+    WKContextSetInjectedBundleClient(context, &injectedBundleClient);
+}
+
+TEST(WebKit2, CanHandleRequest)
+{
+    WKRetainPtr<WKContextRef> context = Util::adoptWK(Util::createContextForInjectedBundleTest("CanHandleRequestTest"));
+    setInjectedBundleClient(context.get());
+
+    _WKContextRegisterURLSchemeAsEmptyDocument(context.get(), Util::toWK("emptyscheme").get());
+
+    PlatformWebView webView(context.get());
+
+    WKPageLoadURL(webView.page(), Util::adoptWK(Util::createURLForResource("simple", "html")).get());
+
+    WKContextPostMessageToInjectedBundle(context.get(), Util::toWK("CheckCanHandleRequest").get(), 0);
+    Util::run(&didReceiveMessage);
+    TEST_ASSERT(canHandleRequest);
+}
+
+} // namespace TestWebKitAPI
diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/CanHandleRequest_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/CanHandleRequest_Bundle.cpp
new file mode 100644 (file)
index 0000000..a253362
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * 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 "InjectedBundleTest.h"
+
+#include "PlatformUtilities.h"
+#include <WebKit2/WKBundlePage.h>
+
+namespace TestWebKitAPI {
+
+class CanHandleRequestTest : public InjectedBundleTest {
+public:
+    CanHandleRequestTest(const std::string& identifier);
+
+private:
+    virtual void didReceiveMessage(WKBundleRef, WKStringRef messageName, WKTypeRef messageBody);
+};
+
+static InjectedBundleTest::Register<CanHandleRequestTest> registrar("CanHandleRequestTest");
+
+CanHandleRequestTest::CanHandleRequestTest(const std::string& identifier)
+    : InjectedBundleTest(identifier)
+{
+}
+
+static bool canHandleURL(const char* url)
+{
+    return WKBundlePageCanHandleRequest(Util::adoptWK(WKURLRequestCreateWithWKURL(Util::adoptWK(WKURLCreateWithUTF8CString(url)).get())).get());
+}
+
+static bool runTest()
+{
+    return canHandleURL("about:blank") && canHandleURL("emptyscheme://") && !canHandleURL("notascheme://");
+}
+
+void CanHandleRequestTest::didReceiveMessage(WKBundleRef bundle, WKStringRef messageName, WKTypeRef)
+{
+    if (!WKStringIsEqualToUTF8CString(messageName, "CheckCanHandleRequest"))
+        return;
+
+    WKBundlePostMessage(bundle, Util::toWK("DidCheckCanHandleRequest").get(), Util::adoptWK(WKBooleanCreate(runTest())).get());
+}
+
+} // namespace TestWebKitAPI
index 00b4205..65f86f8 100644 (file)
                                Name="WebKit2"
                                >
                                <File
+                                       RelativePath="..\Tests\WebKit2\CanHandleRequest.cpp"
+                                       >
+                               </File>
+                               <File
                                        RelativePath="..\Tests\WebKit2\DocumentStartUserScriptAlertCrash.cpp"
                                        >
                                </File>
                                        >
                                </File>
                                <File
+                                       RelativePath="..\Tests\WebKit2\SendingMessagesToTheWebProcessBeforeItIsValid.cpp"
+                                       >
+                               </File>
+                               <File
                                        RelativePath="..\Tests\WebKit2\simple-accelerated-compositing.html"
                                        >
                                </File>
                                        >
                                </File>
                                <File
-                                       RelativePath="..\Tests\WebKit2\SendingMessagesToTheWebProcessBeforeItIsValid.cpp"
-                                       >
-                               </File>
-                               <File
                                        RelativePath="..\Tests\WebKit2\SpacebarScrolling.cpp"
                                        >
                                </File>
index 3b18238..678ad22 100644 (file)
                                Name="WebKit2"
                                >
                                <File
+                                       RelativePath="..\Tests\WebKit2\CanHandleRequest_Bundle.cpp"
+                                       >
+                               </File>
+                               <File
                                        RelativePath="..\Tests\WebKit2\DocumentStartUserScriptAlertCrash_Bundle.cpp"
                                        >
                                </File>