Commit fbaccee9 authored by jochen@chromium.org's avatar jochen@chromium.org

When switching processes during redirects, update the cookie policy

When we don't switch the process, the renderer takes care of updating
the policy. However, when we switch the process, the redirect is handled
in the browser, and we need to update the policy there.

BUG=262860
R=simonjam@chromium.org

Review URL: https://chromiumcodereview.appspot.com/22904002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@217113 0039d316-1c4b-4281-b951-d872f2087c98
parent 3f6fca23
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "content/browser/download/download_manager_impl.h"
#include "content/browser/web_contents/web_contents_impl.h"
......@@ -15,6 +16,8 @@
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "content/shell/shell.h"
#include "content/shell/shell_content_browser_client.h"
#include "content/shell/shell_network_delegate.h"
#include "content/test/content_browser_test.h"
#include "content/test/content_browser_test_utils.h"
#include "content/test/net/url_request_failed_job.h"
......@@ -426,4 +429,39 @@ IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest,
NavigateToURL(shell(), broken_url);
}
namespace {
scoped_ptr<net::test_server::HttpResponse> HandleRedirectRequest(
const std::string& request_path,
const net::test_server::HttpRequest& request) {
if (!StartsWithASCII(request.relative_url, request_path, true))
return scoped_ptr<net::test_server::HttpResponse>();
scoped_ptr<net::test_server::BasicHttpResponse> http_response(
new net::test_server::BasicHttpResponse);
http_response->set_code(net::HTTP_FOUND);
http_response->AddCustomHeader(
"Location", request.relative_url.substr(request_path.length()));
return http_response.PassAs<net::test_server::HttpResponse>();
}
} // namespace
// Test that we update the cookie policy URLs correctly when transferring
// navigations.
IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, CookiePolicy) {
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
embedded_test_server()->RegisterRequestHandler(
base::Bind(&HandleRedirectRequest, "/redirect?"));
std::string set_cookie_url(base::StringPrintf(
"http://localhost:%d/set_cookie.html", embedded_test_server()->port()));
GURL url(embedded_test_server()->GetURL("/redirect?" + set_cookie_url));
ShellContentBrowserClient::SetSwapProcessesForRedirect(true);
ShellNetworkDelegate::SetAcceptAllCookies(false);
CheckTitleTest(url, "cookie set");
}
} // namespace content
......@@ -1269,8 +1269,8 @@ void ResourceDispatcherHostImpl::BeginSaveFile(
}
void ResourceDispatcherHostImpl::MarkAsTransferredNavigation(
const GlobalRequestID& id) {
GetLoader(id)->MarkAsTransferring();
const GlobalRequestID& id, const GURL& target_url) {
GetLoader(id)->MarkAsTransferring(target_url);
}
void ResourceDispatcherHostImpl::ResumeDeferredNavigation(
......
......@@ -132,7 +132,8 @@ class CONTENT_EXPORT ResourceDispatcherHostImpl
// Marks the request as "parked". This happens if a request is
// redirected cross-site and needs to be resumed by a new render view.
void MarkAsTransferredNavigation(const GlobalRequestID& id);
void MarkAsTransferredNavigation(const GlobalRequestID& id,
const GURL& target_url);
// Resumes the request without transferring it to a new render view.
void ResumeDeferredNavigation(const GlobalRequestID& id);
......
......@@ -1681,7 +1681,8 @@ TEST_F(ResourceDispatcherHostTest, CancelRequestsForContextTransferred) {
MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah"));
GlobalRequestID global_request_id(filter_->child_id(), request_id);
host_.MarkAsTransferredNavigation(global_request_id);
host_.MarkAsTransferredNavigation(global_request_id,
GURL("http://example.com/blah"));
// And now simulate a cancellation coming from the renderer.
ResourceHostMsg_CancelRequest msg(filter_->child_id(), request_id);
......
......@@ -155,9 +155,15 @@ void ResourceLoader::ReportUploadProgress() {
}
}
void ResourceLoader::MarkAsTransferring() {
void ResourceLoader::MarkAsTransferring(const GURL& target_url) {
CHECK_EQ(GetRequestInfo()->GetResourceType(), ResourceType::MAIN_FRAME)
<< "Cannot transfer non-main frame navigations";
is_transferring_ = true;
// When transferring a request to another process, the renderer doesn't get
// a chance to update the cookie policy URL. Do it here instead.
request()->set_first_party_for_cookies(target_url);
// When an URLRequest is transferred to a new RenderViewHost, its
// ResourceHandler should not receive any notifications because it may depend
// on the state of the old RVH. We set a ResourceHandler that only allows
......
......@@ -42,7 +42,7 @@ class CONTENT_EXPORT ResourceLoader : public net::URLRequest::Delegate,
void ReportUploadProgress();
bool is_transferring() const { return is_transferring_; }
void MarkAsTransferring();
void MarkAsTransferring(const GURL& target_url);
void WillCompleteTransfer();
void CompleteTransfer(scoped_ptr<ResourceHandler> new_handler);
......
......@@ -70,7 +70,8 @@ void TransferNavigationResourceThrottle::WillRedirectRequest(
if (info->GetAssociatedRenderView(&render_process_id, &render_view_id)) {
GlobalRequestID global_id(info->GetChildID(), info->GetRequestID());
ResourceDispatcherHostImpl::Get()->MarkAsTransferredNavigation(global_id);
ResourceDispatcherHostImpl::Get()->MarkAsTransferredNavigation(global_id,
new_url);
BrowserThread::PostTask(
BrowserThread::UI,
......
......@@ -232,8 +232,22 @@ WebContents* Shell::OpenURLFromTab(WebContents* source,
const OpenURLParams& params) {
// The only one we implement for now.
DCHECK(params.disposition == CURRENT_TAB);
source->GetController().LoadURL(
params.url, params.referrer, params.transition, std::string());
NavigationController::LoadURLParams load_url_params(params.url);
load_url_params.referrer = params.referrer;
load_url_params.transition_type = params.transition;
load_url_params.extra_headers = params.extra_headers;
load_url_params.should_replace_current_entry =
params.should_replace_current_entry;
if (params.transferred_global_request_id != GlobalRequestID()) {
load_url_params.is_renderer_initiated = params.is_renderer_initiated;
load_url_params.transferred_global_request_id =
params.transferred_global_request_id;
} else if (params.is_renderer_initiated) {
load_url_params.is_renderer_initiated = true;
}
source->GetController().LoadURLWithParams(load_url_params);
return source;
}
......
......@@ -44,6 +44,7 @@ namespace content {
namespace {
ShellContentBrowserClient* g_browser_client;
bool g_swap_processes_for_redirect = false;
} // namespace
......@@ -51,6 +52,10 @@ ShellContentBrowserClient* ShellContentBrowserClient::Get() {
return g_browser_client;
}
void ShellContentBrowserClient::SetSwapProcessesForRedirect(bool swap) {
g_swap_processes_for_redirect = swap;
}
ShellContentBrowserClient::ShellContentBrowserClient()
: shell_browser_main_parts_(NULL) {
DCHECK(!g_browser_client);
......@@ -185,6 +190,13 @@ net::NetLog* ShellContentBrowserClient::GetNetLog() {
return shell_browser_main_parts_->net_log();
}
bool ShellContentBrowserClient::ShouldSwapProcessesForRedirect(
ResourceContext* resource_context,
const GURL& current_url,
const GURL& new_url) {
return g_swap_processes_for_redirect;
}
#if defined(OS_ANDROID)
void ShellContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
const CommandLine& command_line,
......
......@@ -27,6 +27,8 @@ class ShellContentBrowserClient : public ContentBrowserClient,
// Gets the current instance.
static ShellContentBrowserClient* Get();
static void SetSwapProcessesForRedirect(bool swap);
ShellContentBrowserClient();
virtual ~ShellContentBrowserClient();
......@@ -57,6 +59,9 @@ class ShellContentBrowserClient : public ContentBrowserClient,
WebContents* web_contents) OVERRIDE;
virtual QuotaPermissionContext* CreateQuotaPermissionContext() OVERRIDE;
virtual net::NetLog* GetNetLog() OVERRIDE;
virtual bool ShouldSwapProcessesForRedirect(ResourceContext* resource_context,
const GURL& current_url,
const GURL& new_url) OVERRIDE;
#if defined(OS_ANDROID)
virtual void GetAdditionalMappedFilesForChildProcess(
......
<!DOCTYPE html>
<html>
<head>
<title>Loading...</title>
<script>
if (document.cookie == "A=B")
document.title = "cookie set";
else
document.title = "cookie not set";
</script>
</head>
</html>
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