Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Unified Diff: content/browser/loader/cross_site_resource_handler.cc

Issue 143183009: When cross-site navigations are cancelled, delete the request being transferred (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: reupload, undo unneeded change Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/loader/cross_site_resource_handler.cc
===================================================================
--- content/browser/loader/cross_site_resource_handler.cc (revision 250813)
+++ content/browser/loader/cross_site_resource_handler.cc (working copy)
@@ -13,6 +13,7 @@
#include "content/browser/cross_site_request_manager.h"
#include "content/browser/loader/resource_dispatcher_host_impl.h"
#include "content/browser/loader/resource_request_info_impl.h"
+#include "content/browser/renderer_host/cross_site_request_transfer.h"
#include "content/browser/renderer_host/render_view_host_delegate.h"
#include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/public/browser/browser_thread.h"
@@ -30,17 +31,21 @@
namespace {
+bool leak_requests_for_testing_ = false;
Charlie Reis 2014/02/13 22:12:19 This seems unfortunate, but I don't have a better
mmenke 2014/02/14 16:30:02 I agree. I couldn't think of something better to
+
// The parameters to OnCrossSiteResponseHelper exceed the number of arguments
// base::Bind supports.
struct CrossSiteResponseParams {
- CrossSiteResponseParams(int render_view_id,
- const GlobalRequestID& global_request_id,
- bool is_transfer,
- const std::vector<GURL>& transfer_url_chain,
- const Referrer& referrer,
- PageTransition page_transition,
- int64 frame_id,
- bool should_replace_current_entry)
+ CrossSiteResponseParams(
+ int render_view_id,
+ const GlobalRequestID& global_request_id,
+ bool is_transfer,
+ const std::vector<GURL>& transfer_url_chain,
+ const Referrer& referrer,
+ PageTransition page_transition,
+ int64 frame_id,
+ bool should_replace_current_entry,
+ CrossSiteResourceHandler* cross_site_resource_handler)
: render_view_id(render_view_id),
global_request_id(global_request_id),
is_transfer(is_transfer),
@@ -48,7 +53,8 @@
referrer(referrer),
page_transition(page_transition),
frame_id(frame_id),
- should_replace_current_entry(should_replace_current_entry) {
+ should_replace_current_entry(should_replace_current_entry),
+ cross_site_resource_handler(cross_site_resource_handler) {
}
int render_view_id;
@@ -59,18 +65,29 @@
PageTransition page_transition;
int64 frame_id;
bool should_replace_current_entry;
+ CrossSiteResourceHandler* cross_site_resource_handler;
};
void OnCrossSiteResponseHelper(const CrossSiteResponseParams& params) {
+ scoped_ptr<CrossSiteRequestTransfer> cross_site_request_transfer;
+ if (params.is_transfer) {
+ cross_site_request_transfer.reset(new CrossSiteRequestTransfer(
+ params.cross_site_resource_handler));
+ }
+
RenderViewHostImpl* rvh =
RenderViewHostImpl::FromID(params.global_request_id.child_id,
params.render_view_id);
if (rvh) {
rvh->OnCrossSiteResponse(
- params.global_request_id, params.is_transfer,
+ params.global_request_id, cross_site_request_transfer.Pass(),
params.transfer_url_chain, params.referrer,
params.page_transition, params.frame_id,
params.should_replace_current_entry);
+ } else if (leak_requests_for_testing_ && cross_site_request_transfer) {
+ // Some unit tests expect requests to be leaked in this case, so they can
+ // pass them along manually.
+ cross_site_request_transfer->ReleaseRequest();
}
}
@@ -83,8 +100,7 @@
has_started_response_(false),
in_cross_site_transition_(false),
completed_during_transition_(false),
- did_defer_(false),
- completed_status_() {
+ did_defer_(false) {
}
CrossSiteResourceHandler::~CrossSiteResourceHandler() {
@@ -259,6 +275,27 @@
}
}
+void CrossSiteResourceHandler::AbortTransfer() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+
+ // Cancelling the request is not strictly necessary, since nothing is
Charlie Reis 2014/02/13 22:12:19 Is it not done by the CancelRequest call below? (
mmenke 2014/02/14 16:30:02 No, it's not. Despite its name, ResourceDispatche
Charlie Reis 2014/02/15 01:25:44 Ah.
+ // listening to it, but it makes for clearer logs and cleaner tests.
+ request()->Cancel();
+
+ // Clean up the request.
+ ResourceRequestInfoImpl* info = GetRequestInfo();
+ ResourceDispatcherHostImpl::Get()->CancelRequest(info->GetChildID(),
+ info->GetRequestID());
+
+ // |this| should now be deleted.
+}
+
+// static
+void CrossSiteResourceHandler::SetLeakRequestsForTesting(
+ bool leak_requests_for_testing) {
+ leak_requests_for_testing_ = leak_requests_for_testing;
+}
+
// Prepare to render the cross-site response in a new RenderViewHost, by
// telling the old RenderViewHost to run its onunload handler.
void CrossSiteResourceHandler::StartCrossSiteTransition(
@@ -306,7 +343,8 @@
referrer,
info->GetPageTransition(),
frame_id,
- info->should_replace_current_entry())));
+ info->should_replace_current_entry(),
+ this)));
}
void CrossSiteResourceHandler::ResumeIfDeferred() {

Powered by Google App Engine
This is Rietveld 408576698