Commit 1c3ad0ea authored by mitz@apple.com's avatar mitz@apple.com
Browse files

<rdar://problem/8827065> REGRESSION (r71884): Cross-origin XHR fails if...

<rdar://problem/8827065> REGRESSION (r71884): Cross-origin XHR fails if willSendRequest changes the URL
https://bugs.webkit.org/show_bug.cgi?id=52419

Reviewed by Alexey Proskuryakov.

Source/WebCore: 

Test: http/tests/loading/cross-origin-XHR-willLoadRequest.html

* loader/ResourceLoader.cpp:
(WebCore::ResourceLoader::init): Complete r74453 by ensuring that m_request is only set after
willSendRequest(). Otherwise, willSendRequest() ends up calling into
ThreadableDocumentRequest::willSendRequest(), which cancels the request.

Tools: 

Allow to further control the behavior of the willSendRequest delegate callback by making it
set a different URL in the new request.

* DumpRenderTree/LayoutTestController.cpp:
(addURLToRedirectCallback): Added.
(LayoutTestController::staticFunctions): Added addURLToRedirect.
(LayoutTestController::addURLToRedirect): Added. Adds the redirection to the map.
(LayoutTestController::redirectionDestinationForURL): Added this getter.
* DumpRenderTree/LayoutTestController.h:
* DumpRenderTree/mac/ResourceLoadDelegate.mm:
(-[ResourceLoadDelegate webView:resource:willSendRequest:redirectResponse:fromDataSource:]): Check
if there is a redirection for the request’s URL, established by addURLToRedirect(), and if so,
change the URL in the new request to the redirect destination.

LayoutTests: 

* http/tests/loading/cross-origin-XHR-willLoadRequest-expected.txt: Added.
* http/tests/loading/cross-origin-XHR-willLoadRequest.html: Added.
* platform/gtk/Skipped: Skip the new test.
* platform/qt/Skipped: Ditto.
* platform/win/Skipped: Ditto.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@75768 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent f9ffc971
2011-01-13 Dan Bernstein <mitz@apple.com>
Reviewed by Alexey Proskuryakov.
<rdar://problem/8827065> REGRESSION (r71884): Cross-origin XHR fails if willSendRequest changes the URL
https://bugs.webkit.org/show_bug.cgi?id=52419
* http/tests/loading/cross-origin-XHR-willLoadRequest-expected.txt: Added.
* http/tests/loading/cross-origin-XHR-willLoadRequest.html: Added.
* platform/gtk/Skipped: Skip the new test.
* platform/qt/Skipped: Ditto.
* platform/win/Skipped: Ditto.
2011-01-13 Justin Schuh <jschuh@chromium.org>
 
Unreviewed chromium expectations update.
......
main frame - didStartProvisionalLoadForFrame
main frame - didCommitLoadForFrame
main frame - didFinishDocumentLoadForFrame
main frame - didHandleOnloadEventsForFrame
CONSOLE MESSAGE: line 1: XMLHttpRequest cannot load http://localhost:8000/loading/resources/foo.txt. Origin http://127.0.0.1:8000 is not allowed by Access-Control-Allow-Origin.
main frame - didFinishLoadForFrame
The console message above should report failure to load foo.txt due to cross-origin access, not a network error.
<script>
layoutTestController.dumpAsText();
layoutTestController.addURLToRedirect("http:/localhost:8000/loading/resources/bar.txt", "http://localhost:8000/loading/resources/foo.txt");
var request = new XMLHttpRequest();
request.open("GET", "http:/localhost:8000/loading/resources/bar.txt");
request.send();
</script>
<p>
The console message above should report failure to load foo.txt due to cross-origin access, not a network error.
</p>
......@@ -5593,3 +5593,6 @@ http/tests/xmlhttprequest/basic-auth-nopassword.html
# https://bugs.webkit.org/show_bug.cgi?id=52297
editing/input/page-up-down-scrolls.html
# DRT does not obey layoutTestController.addURLToRedirect()
http/tests/loading/cross-origin-XHR-willLoadRequest
......@@ -764,6 +764,9 @@ fast/ruby/rubyDOM-remove-rt2.html
fast/ruby/rubyDOM-remove-text1.html
fast/ruby/rubyDOM-remove-text2.html
# ------- not obeying layoutTestController.addURLToRedirect()
http/tests/loading/cross-origin-XHR-willLoadRequest
# ============================================================================= #
# Failing SVG tests
# ============================================================================= #
......
#
# Copyright (C) 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
# Copyright (C) 2007, 2008, 2009, 2010, 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
......@@ -1117,3 +1117,6 @@ fast/loader/user-stylesheet-fast-path.html
# DRT does not support toggling caret browsing on / off
editing/selection/caret-mode-paragraph-keys-navigation.html
# DRT does not obey addURLToRedirect
http/tests/loading/cross-origin-XHR-willLoadRequest
2011-01-13 Dan Bernstein <mitz@apple.com>
Reviewed by Alexey Proskuryakov.
<rdar://problem/8827065> REGRESSION (r71884): Cross-origin XHR fails if willSendRequest changes the URL
https://bugs.webkit.org/show_bug.cgi?id=52419
Test: http/tests/loading/cross-origin-XHR-willLoadRequest.html
* loader/ResourceLoader.cpp:
(WebCore::ResourceLoader::init): Complete r74453 by ensuring that m_request is only set after
willSendRequest(). Otherwise, willSendRequest() ends up calling into
ThreadableDocumentRequest::willSendRequest(), which cancels the request.
2011-01-13 Dan Bernstein <mitz@apple.com>
 
Reviewed by Mark Rowe.
......
/*
* Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
* Copyright (C) 2006, 2007, 2010, 2011 Apple Inc. All rights reserved.
* (C) 2007 Graham Dennis (graham.dennis@gmail.com)
*
* Redistribution and use in source and binary forms, with or without
......@@ -129,14 +129,13 @@ bool ResourceLoader::init(const ResourceRequest& r)
clientRequest.setFirstPartyForCookies(document->firstPartyForCookies());
}
m_request = clientRequest;
willSendRequest(m_request, ResourceResponse());
if (m_request.isNull()) {
willSendRequest(clientRequest, ResourceResponse());
if (clientRequest.isNull()) {
didFail(frameLoader()->cancelledError(m_request));
return false;
}
m_request = clientRequest;
return true;
}
......
2011-01-13 Dan Bernstein <mitz@apple.com>
Reviewed by Alexey Proskuryakov.
<rdar://problem/8827065> REGRESSION (r71884): Cross-origin XHR fails if willSendRequest changes the URL
https://bugs.webkit.org/show_bug.cgi?id=52419
Allow to further control the behavior of the willSendRequest delegate callback by making it
set a different URL in the new request.
* DumpRenderTree/LayoutTestController.cpp:
(addURLToRedirectCallback): Added.
(LayoutTestController::staticFunctions): Added addURLToRedirect.
(LayoutTestController::addURLToRedirect): Added. Adds the redirection to the map.
(LayoutTestController::redirectionDestinationForURL): Added this getter.
* DumpRenderTree/LayoutTestController.h:
* DumpRenderTree/mac/ResourceLoadDelegate.mm:
(-[ResourceLoadDelegate webView:resource:willSendRequest:redirectResponse:fromDataSource:]): Check
if there is a redirection for the request’s URL, established by addURLToRedirect(), and if so,
change the URL in the new request to the redirect destination.
2011-01-13 Eric Seidel <eric@webkit.org>
 
Reviewed by Mihai Parparita.
/*
* Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved.
* Copyright (C) 2007, 2008, 2009, 2011 Apple Inc. All rights reserved.
* Copyright (C) 2010 Joone Hur <joone@kldp.org>
*
* Redistribution and use in source and binary forms, with or without
......@@ -335,6 +335,31 @@ static JSValueRef addDisallowedURLCallback(JSContextRef context, JSObjectRef fun
return JSValueMakeUndefined(context);
}
static JSValueRef addURLToRedirectCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
if (argumentCount < 2)
return JSValueMakeUndefined(context);
JSRetainPtr<JSStringRef> origin(Adopt, JSValueToStringCopy(context, arguments[0], exception));
ASSERT(!*exception);
JSRetainPtr<JSStringRef> destination(Adopt, JSValueToStringCopy(context, arguments[1], exception));
ASSERT(!*exception);
size_t maxLength = JSStringGetMaximumUTF8CStringSize(origin.get());
char* originBuffer = new char[maxLength + 1];
JSStringGetUTF8CString(origin.get(), originBuffer, maxLength + 1);
maxLength = JSStringGetMaximumUTF8CStringSize(destination.get());
char* destinationBuffer = new char[maxLength + 1];
JSStringGetUTF8CString(destination.get(), destinationBuffer, maxLength + 1);
LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
controller->addURLToRedirect(originBuffer, destinationBuffer);
return JSValueMakeUndefined(context);
}
static JSValueRef callShouldCloseOnWebViewCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
// Has mac & windows implementation
......@@ -1930,6 +1955,7 @@ JSStaticFunction* LayoutTestController::staticFunctions()
static JSStaticFunction staticFunctions[] = {
{ "abortModal", abortModalCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
{ "addDisallowedURL", addDisallowedURLCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
{ "addURLToRedirect", addURLToRedirectCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
{ "addUserScript", addUserScriptCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
{ "addUserStyleSheet", addUserStyleSheetCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
{ "apiTestNewWindowDataLoadBaseURL", apiTestNewWindowDataLoadBaseURLCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
......@@ -2140,5 +2166,15 @@ void LayoutTestController::setPOSIXLocale(JSStringRef locale)
setlocale(LC_ALL, localeBuf);
}
void LayoutTestController::addURLToRedirect(std::string origin, std::string destination)
{
m_URLsToRedirect[origin] = destination;
}
const std::string& LayoutTestController::redirectionDestinationForURL(std::string origin)
{
return m_URLsToRedirect[origin];
}
const unsigned LayoutTestController::maxViewWidth = 800;
const unsigned LayoutTestController::maxViewHeight = 600;
......@@ -31,6 +31,7 @@
#include <JavaScriptCore/JSObjectRef.h>
#include <JavaScriptCore/JSRetainPtr.h>
#include <map>
#include <set>
#include <string>
#include <vector>
......@@ -45,6 +46,8 @@ public:
void makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception);
void addDisallowedURL(JSStringRef url);
void addURLToRedirect(std::string origin, std::string destination);
const std::string& redirectionDestinationForURL(std::string);
void clearAllApplicationCaches();
void clearAllDatabases();
void clearBackForwardList();
......@@ -361,6 +364,8 @@ private:
// origins which have been granted desktop notification access
std::vector<JSStringRef> m_desktopNotificationAllowedOrigins;
std::map<std::string, std::string> m_URLsToRedirect;
static JSClassRef getJSClass();
static JSStaticValue* staticValues();
......
/*
* Copyright (C) 2007, Apple Inc. All rights reserved.
* Copyright (C) 2007, 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
......@@ -165,6 +165,9 @@ using namespace std;
[newRequest setValue:nil forHTTPHeaderField:nsHeader];
[nsHeader release];
}
const std::string& destination = gLayoutTestController->redirectionDestinationForURL([[url absoluteString] UTF8String]);
if (destination.length())
[newRequest setURL:[NSURL URLWithString:[NSString stringWithUTF8String:destination.data()]]];
return [newRequest autorelease];
}
......
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