Commit da7434ad authored by bweinstein@apple.com's avatar bweinstein@apple.com
Browse files

Source/WebKit2: WebKit2: Assertion when calling didPerform*Redirect on null...

Source/WebKit2: WebKit2: Assertion when calling didPerform*Redirect on null source/destination URL string
https://bugs.webkit.org/show_bug.cgi?id=67794
<rdar://problem/9892024>
        
Don't call didPerformClientRedirect or didPerformServerRedirect when source or destination URL string
is empty or null.
        
If we call didPerformClientRedirect or didPerformServerRedirect when the source or destination is null,
it causes an assert in WKURLCF::WKURLCopyCFURL when we try to convert the WKURLRef into a CFURLRef.

Reviewed by Brady Eidson.

* UIProcess/WebContext.cpp:
(WebKit::WebContext::didPerformClientRedirect): Return early if the source or destination URL string is empty or null.
(WebKit::WebContext::didPerformServerRedirect): Ditto.

Tools: WebKit2: Assertion when calling didPerform*Redirect on null source/destination URL string
https://bugs.webkit.org/show_bug.cgi?id=67794
<rdar://problem/9892024>
        
Add a test that we don't send a didPerformServerRedirect when a load is cancelled from willSendRequest.

Reviewed by Brady Eidson.

* TestWebKitAPI/Tests/WebKit2/LoadCanceledNoServerRedirectCallback.cpp: Added.
(TestWebKitAPI::didFinishLoadForFrame): Set flags on whether we've loaded the main frame, iframe, or both.
(TestWebKitAPI::didPerformServerRedirect): Set a flag for whether we've performed a server redirect.
(TestWebKitAPI::TEST): Set up a WKPageLoaderClient and WKContextHistoryClient, and load simple-iframe.html.
    Once both frames have loaded (main frame and blocked iframe), make sure that we have never called
    didPerformServerRedirect.

* TestWebKitAPI/Tests/WebKit2/LoadCanceledNoServerRedirectCallback_Bundle.cpp: Added.
(TestWebKitAPI::LoadCanceledNoServerRedirectCallbackTest::LoadCanceledNoServerRedirectCallbackTest): Initialize
    our InjectedBundleTest.
(TestWebKitAPI::LoadCanceledNoServerRedirectCallbackTest::willSendRequestForFrame): If we are dealing with a request
    from the main frame (the main resource in simple-iframe.html), allow it. If not (dealing with the iframe), block
    the request.
(TestWebKitAPI::LoadCanceledNoServerRedirectCallbackTest::didCreatePage): Set up the WKBundlePageResourceLoadClient.

* TestWebKitAPI/Tests/WebKit2/simple-iframe.html: Added.
        
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Add new files.
* TestWebKitAPI/win/TestWebKitAPI.vcproj: Ditto.
* TestWebKitAPI/win/TestWebKitAPIInjectedBundle.vcproj: Ditto.
* TestWebKitAPI/win/copy-resources.cmd: Ditto.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@94812 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent f41a7da7
2011-09-08 Brian Weinstein <bweinstein@apple.com>
WebKit2: Assertion when calling didPerform*Redirect on null source/destination URL string
https://bugs.webkit.org/show_bug.cgi?id=67794
<rdar://problem/9892024>
Don't call didPerformClientRedirect or didPerformServerRedirect when source or destination URL string
is empty or null.
If we call didPerformClientRedirect or didPerformServerRedirect when the source or destination is null,
it causes an assert in WKURLCF::WKURLCopyCFURL when we try to convert the WKURLRef into a CFURLRef.
Reviewed by Brady Eidson.
* UIProcess/WebContext.cpp:
(WebKit::WebContext::didPerformClientRedirect): Return early if the source or destination URL string is empty or null.
(WebKit::WebContext::didPerformServerRedirect): Ditto.
2011-09-08 Sam Weinig <sam@webkit.org>
Remove the Completion object from JSC, I have never liked it
......
......@@ -432,6 +432,9 @@ void WebContext::didPerformClientRedirect(uint64_t pageID, const String& sourceU
WebPageProxy* page = m_process->webPage(pageID);
if (!page)
return;
if (sourceURLString.isEmpty() || destinationURLString.isEmpty())
return;
WebFrameProxy* frame = m_process->webFrame(frameID);
MESSAGE_CHECK(frame);
......@@ -446,6 +449,9 @@ void WebContext::didPerformServerRedirect(uint64_t pageID, const String& sourceU
if (!page)
return;
if (sourceURLString.isEmpty() || destinationURLString.isEmpty())
return;
WebFrameProxy* frame = m_process->webFrame(frameID);
MESSAGE_CHECK(frame);
MESSAGE_CHECK(frame->page() == page);
......
2011-09-08 Brian Weinstein <bweinstein@apple.com>
WebKit2: Assertion when calling didPerform*Redirect on null source/destination URL string
https://bugs.webkit.org/show_bug.cgi?id=67794
<rdar://problem/9892024>
Add a test that we don't send a didPerformServerRedirect when a load is cancelled from willSendRequest.
Reviewed by Brady Eidson.
* TestWebKitAPI/Tests/WebKit2/LoadCanceledNoServerRedirectCallback.cpp: Added.
(TestWebKitAPI::didFinishLoadForFrame): Set flags on whether we've loaded the main frame, iframe, or both.
(TestWebKitAPI::didPerformServerRedirect): Set a flag for whether we've performed a server redirect.
(TestWebKitAPI::TEST): Set up a WKPageLoaderClient and WKContextHistoryClient, and load simple-iframe.html.
Once both frames have loaded (main frame and blocked iframe), make sure that we have never called
didPerformServerRedirect.
* TestWebKitAPI/Tests/WebKit2/LoadCanceledNoServerRedirectCallback_Bundle.cpp: Added.
(TestWebKitAPI::LoadCanceledNoServerRedirectCallbackTest::LoadCanceledNoServerRedirectCallbackTest): Initialize
our InjectedBundleTest.
(TestWebKitAPI::LoadCanceledNoServerRedirectCallbackTest::willSendRequestForFrame): If we are dealing with a request
from the main frame (the main resource in simple-iframe.html), allow it. If not (dealing with the iframe), block
the request.
(TestWebKitAPI::LoadCanceledNoServerRedirectCallbackTest::didCreatePage): Set up the WKBundlePageResourceLoadClient.
* TestWebKitAPI/Tests/WebKit2/simple-iframe.html: Added.
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Add new files.
* TestWebKitAPI/win/TestWebKitAPI.vcproj: Ditto.
* TestWebKitAPI/win/TestWebKitAPIInjectedBundle.vcproj: Ditto.
* TestWebKitAPI/win/copy-resources.cmd: Ditto.
2011-09-08 David Levin <levin@chromium.org>
 
check-webkit-style: Ref|Own Ptr& should be allowed as a parameter.
......@@ -17,6 +17,9 @@
333B9CE21277F23100FEFCE3 /* PreventEmptyUserAgent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 333B9CE11277F23100FEFCE3 /* PreventEmptyUserAgent.cpp */; };
33BE5AF5137B5A6C00705813 /* MouseMoveAfterCrash.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 33BE5AF4137B5A6C00705813 /* MouseMoveAfterCrash.cpp */; };
33BE5AF9137B5AAE00705813 /* MouseMoveAfterCrash_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 33BE5AF8137B5AAE00705813 /* MouseMoveAfterCrash_Bundle.cpp */; };
33DC8911141953A300747EF7 /* LoadCanceledNoServerRedirectCallback.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 33DC8910141953A300747EF7 /* LoadCanceledNoServerRedirectCallback.cpp */; };
33DC8912141955FE00747EF7 /* simple-iframe.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 33DC890E1419539300747EF7 /* simple-iframe.html */; };
33DC89141419579F00747EF7 /* LoadCanceledNoServerRedirectCallback_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 33DC89131419579F00747EF7 /* LoadCanceledNoServerRedirectCallback_Bundle.cpp */; };
33E79E06137B5FD900E32D99 /* mouse-move-listener.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 33E79E05137B5FCE00E32D99 /* mouse-move-listener.html */; };
37200B9213A16230007A4FAD /* VectorReverse.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37200B9113A16230007A4FAD /* VectorReverse.cpp */; };
3799AD3A14120A43005EB0C6 /* StringByEvaluatingJavaScriptFromString.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3799AD3914120A43005EB0C6 /* StringByEvaluatingJavaScriptFromString.mm */; };
......@@ -108,6 +111,7 @@
dstPath = "";
dstSubfolderSpec = 7;
files = (
33DC8912141955FE00747EF7 /* simple-iframe.html in Copy Resources */,
1A9E52C913E65EF4006917F5 /* 18-characters.html in Copy Resources */,
C07E6CB213FD73930038B22B /* devicePixelRatio.html in Copy Resources */,
33E79E06137B5FD900E32D99 /* mouse-move-listener.html in Copy Resources */,
......@@ -135,6 +139,9 @@
333B9CE11277F23100FEFCE3 /* PreventEmptyUserAgent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PreventEmptyUserAgent.cpp; sourceTree = "<group>"; };
33BE5AF4137B5A6C00705813 /* MouseMoveAfterCrash.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MouseMoveAfterCrash.cpp; sourceTree = "<group>"; };
33BE5AF8137B5AAE00705813 /* MouseMoveAfterCrash_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MouseMoveAfterCrash_Bundle.cpp; sourceTree = "<group>"; };
33DC890E1419539300747EF7 /* simple-iframe.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "simple-iframe.html"; sourceTree = "<group>"; };
33DC8910141953A300747EF7 /* LoadCanceledNoServerRedirectCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LoadCanceledNoServerRedirectCallback.cpp; sourceTree = "<group>"; };
33DC89131419579F00747EF7 /* LoadCanceledNoServerRedirectCallback_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LoadCanceledNoServerRedirectCallback_Bundle.cpp; sourceTree = "<group>"; };
33E79E05137B5FCE00E32D99 /* mouse-move-listener.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "mouse-move-listener.html"; sourceTree = "<group>"; };
37200B9113A16230007A4FAD /* VectorReverse.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = VectorReverse.cpp; path = WTF/VectorReverse.cpp; sourceTree = "<group>"; };
3799AD3914120A43005EB0C6 /* StringByEvaluatingJavaScriptFromString.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = StringByEvaluatingJavaScriptFromString.mm; sourceTree = "<group>"; };
......@@ -339,6 +346,8 @@
4BFDFFA61314776C0061F24B /* HitTestResultNodeHandle_Bundle.cpp */,
BC575AAC126E83B9006F0F12 /* InjectedBundleBasic.cpp */,
BC575AAF126E83C8006F0F12 /* InjectedBundleBasic_Bundle.cpp */,
33DC8910141953A300747EF7 /* LoadCanceledNoServerRedirectCallback.cpp */,
33DC89131419579F00747EF7 /* LoadCanceledNoServerRedirectCallback_Bundle.cpp */,
33BE5AF4137B5A6C00705813 /* MouseMoveAfterCrash.cpp */,
33BE5AF8137B5AAE00705813 /* MouseMoveAfterCrash_Bundle.cpp */,
BC909779125571AB00083756 /* PageLoadBasic.cpp */,
......@@ -376,6 +385,7 @@
33E79E05137B5FCE00E32D99 /* mouse-move-listener.html */,
1ADBEFBC130C6A0100D61D19 /* simple-accelerated-compositing.html */,
C0ADBE8412FCA6B600D2C129 /* simple-form.html */,
33DC890E1419539300747EF7 /* simple-iframe.html */,
BC909778125571AB00083756 /* simple.html */,
C02B7882126615410026BF0F /* spacebar-scrolling.html */,
);
......@@ -570,6 +580,7 @@
A7A966DB140ECCC8005EF9B4 /* CheckedArithmeticOperations.cpp in Sources */,
939BA91714103412001A01BD /* DeviceScaleFactorOnBack.mm in Sources */,
3799AD3A14120A43005EB0C6 /* StringByEvaluatingJavaScriptFromString.mm in Sources */,
33DC8911141953A300747EF7 /* LoadCanceledNoServerRedirectCallback.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -588,6 +599,7 @@
BC246D9C132F1FF000B56D7C /* CanHandleRequest_Bundle.cpp in Sources */,
33BE5AF9137B5AAE00705813 /* MouseMoveAfterCrash_Bundle.cpp in Sources */,
1AEDE22613E5E7E700E62FE8 /* InjectedBundleControllerMac.mm in Sources */,
33DC89141419579F00747EF7 /* LoadCanceledNoServerRedirectCallback_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 "JavaScriptTest.h"
#include "PlatformUtilities.h"
#include "PlatformWebView.h"
#include <WebKit2/WKContext.h>
#include <WebKit2/WKFrame.h>
#include <WebKit2/WKRetainPtr.h>
namespace TestWebKitAPI {
static bool loadedMainFrame;
static bool loadedIFrame;
static bool loadedAllFrames;
static bool performedServerRedirect;
static void didFinishLoadForFrame(WKPageRef, WKFrameRef frame, WKTypeRef, const void*)
{
if (WKFrameIsMainFrame(frame))
loadedMainFrame = true;
else
loadedIFrame = true;
loadedAllFrames = loadedMainFrame && loadedIFrame;
}
static void didPerformServerRedirect(WKContextRef context, WKPageRef page, WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef frame, const void *clientInfo)
{
performedServerRedirect = true;
}
TEST(WebKit2, LoadCanceledNoServerRedirectCallback)
{
WKRetainPtr<WKContextRef> context(AdoptWK, Util::createContextForInjectedBundleTest("LoadCanceledNoServerRedirectCallbackTest"));
WKContextInjectedBundleClient injectedBundleClient;
memset(&injectedBundleClient, 0, sizeof(injectedBundleClient));
injectedBundleClient.version = 0;
injectedBundleClient.clientInfo = 0;
WKContextSetInjectedBundleClient(context.get(), &injectedBundleClient);
PlatformWebView webView(context.get());
WKPageLoaderClient loaderClient;
memset(&loaderClient, 0, sizeof(loaderClient));
loaderClient.version = 0;
loaderClient.didFinishLoadForFrame = didFinishLoadForFrame;
WKPageSetPageLoaderClient(webView.page(), &loaderClient);
WKContextHistoryClient historyClient;
memset(&historyClient, 0, sizeof(historyClient));
historyClient.version = 0;
historyClient.didPerformServerRedirect = didPerformServerRedirect;
WKContextSetHistoryClient(context.get(), &historyClient);
WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("simple-iframe", "html"));
WKPageLoadURL(webView.page(), url.get());
Util::run(&loadedAllFrames);
// We shouldn't have performed a server redirect when the iframe load was cancelled.
EXPECT_FALSE(performedServerRedirect);
}
} // namespace TestWebKitAPI
/*
* Copyright (C) 2010 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 "Test.h"
#include <WebKit2/WKBundlePage.h>
#include <WebKit2/WKBundleFrame.h>
#include <WebKit2/WKRetainPtr.h>
#include <wtf/Assertions.h>
namespace TestWebKitAPI {
class LoadCanceledNoServerRedirectCallbackTest : public InjectedBundleTest {
public:
LoadCanceledNoServerRedirectCallbackTest(const std::string& identifier)
: InjectedBundleTest(identifier)
{
}
static WKURLRequestRef willSendRequestForFrame(WKBundlePageRef, WKBundleFrameRef frame, uint64_t resourceIdentifier, WKURLRequestRef request, WKURLResponseRef redirectResponse, const void *clientInfo)
{
// Allow the loading of the main resource, but don't allow the loading of an iframe, return null from willSendRequest.
if (WKBundleFrameIsMainFrame(frame)) {
WKRetainPtr<WKURLRequestRef> newRequest = request;
return newRequest.leakRef();
}
return 0;
}
virtual void didCreatePage(WKBundleRef bundle, WKBundlePageRef page)
{
WKBundlePageResourceLoadClient resourceLoadClient;
memset(&resourceLoadClient, 0, sizeof(resourceLoadClient));
resourceLoadClient.version = 0;
resourceLoadClient.willSendRequestForFrame = willSendRequestForFrame;
WKBundlePageSetResourceLoadClient(page, &resourceLoadClient);
}
};
static InjectedBundleTest::Register<LoadCanceledNoServerRedirectCallbackTest> registrar("LoadCanceledNoServerRedirectCallbackTest");
} // namespace TestWebKitAPI
<html>
<body>
Simple HTML file.
<iframe src="simple.html"></iframe>
</body>
</html>
......@@ -483,6 +483,10 @@
RelativePath="..\Tests\WebKit2\InjectedBundleBasic.cpp"
>
</File>
<File
RelativePath="..\Tests\WebKit2\LoadCanceledNoServerRedirectCallback.cpp"
>
</File>
<File
RelativePath="..\Tests\WebKit2\mouse-move-listener.html"
>
......@@ -519,6 +523,10 @@
RelativePath="..\Tests\WebKit2\simple-form.html"
>
</File>
<File
RelativePath="..\Tests\WebKit2\simple-iframe.html"
>
</File>
<File
RelativePath="..\Tests\WebKit2\simple.html"
>
......
......@@ -419,6 +419,10 @@
RelativePath="..\Tests\WebKit2\InjectedBundleBasic_Bundle.cpp"
>
</File>
<File
RelativePath="..\Tests\WebKit2\LoadCanceledNoServerRedirectCallback_Bundle.cpp"
>
</File>
<File
RelativePath="..\Tests\WebKit2\MouseMoveAfterCrash_Bundle.cpp"
>
......
......@@ -16,6 +16,7 @@ for %%f in (
..\Tests\WebKit2\simple.html
..\Tests\WebKit2\simple-accelerated-compositing.html
..\Tests\WebKit2\simple-form.html
..\Tests\WebKit2\simple-iframe.html
..\Tests\WebKit2\spacebar-scrolling.html
) do (
xcopy /y /d %%f "%ResourcesDirectory%"
......
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