Commit ec43bb1b authored by aroben@apple.com's avatar aroben@apple.com

Make WKBundlePageCanHandleRequest return true for empty document URLs

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: svn://svn.chromium.org/blink/trunk@81105 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent e8dd2abe
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.
......
......@@ -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
......@@ -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;
......
......@@ -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");
......
......@@ -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;
......
......@@ -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;
......
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.
......
......@@ -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 */; };
......@@ -111,6 +113,8 @@
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>"; };
......@@ -259,6 +263,8 @@
isa = PBXGroup;
children = (
BC90977B125571AE00083756 /* Resources */,
BC246D97132F1FE100B56D7C /* CanHandleRequest_Bundle.cpp */,
BC246D98132F1FE100B56D7C /* CanHandleRequest.cpp */,
BCB6803F126FBFE100642A61 /* DocumentStartUserScriptAlertCrash.cpp */,
BCB68041126FBFF100642A61 /* DocumentStartUserScriptAlertCrash_Bundle.cpp */,
1A5FEFDC1270E2A3000E2921 /* EvaluateJavaScript.cpp */,
......@@ -433,6 +439,7 @@
4BFDFFA9131477770061F24B /* HitTestResultNodeHandle.cpp in Sources */,
C0BD669D131D3CF700E18F2A /* ResponsivenessTimerDoesntFireEarly.cpp in Sources */,
F6C59E38132AC5E000176C09 /* SendingMessagesToTheWebProcessBeforeItIsValid.cpp in Sources */,
BC246D9A132F1FE100B56D7C /* CanHandleRequest.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -448,6 +455,7 @@
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;
};
......
/*
* 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
/*
* 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
......@@ -411,6 +411,10 @@
<Filter
Name="WebKit2"
>
<File
RelativePath="..\Tests\WebKit2\CanHandleRequest.cpp"
>
</File>
<File
RelativePath="..\Tests\WebKit2\DocumentStartUserScriptAlertCrash.cpp"
>
......@@ -479,6 +483,10 @@
RelativePath="..\Tests\WebKit2\RestoreSessionStateContainingFormData.cpp"
>
</File>
<File
RelativePath="..\Tests\WebKit2\SendingMessagesToTheWebProcessBeforeItIsValid.cpp"
>
</File>
<File
RelativePath="..\Tests\WebKit2\simple-accelerated-compositing.html"
>
......@@ -495,10 +503,6 @@
RelativePath="..\Tests\WebKit2\spacebar-scrolling.html"
>
</File>
<File
RelativePath="..\Tests\WebKit2\SendingMessagesToTheWebProcessBeforeItIsValid.cpp"
>
</File>
<File
RelativePath="..\Tests\WebKit2\SpacebarScrolling.cpp"
>
......
......@@ -399,6 +399,10 @@
<Filter
Name="WebKit2"
>
<File
RelativePath="..\Tests\WebKit2\CanHandleRequest_Bundle.cpp"
>
</File>
<File
RelativePath="..\Tests\WebKit2\DocumentStartUserScriptAlertCrash_Bundle.cpp"
>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment