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

Side by Side Diff: chrome/browser/prerender/prerender_contents.cc

Issue 6459005: Cancel prerender when we discover a download starting from a page we are prer... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Adding browser test Created 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/prerender/prerender_contents.h" 5 #include "chrome/browser/prerender/prerender_contents.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/background_contents_service.h" 9 #include "chrome/browser/background_contents_service.h"
10 #include "chrome/browser/browsing_instance.h" 10 #include "chrome/browser/browsing_instance.h"
11 #include "chrome/browser/prerender/prerender_manager.h" 11 #include "chrome/browser/prerender/prerender_manager.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/renderer_host/render_view_host.h" 13 #include "chrome/browser/renderer_host/render_view_host.h"
14 #include "chrome/browser/renderer_host/resource_request_details.h"
14 #include "chrome/browser/renderer_host/site_instance.h" 15 #include "chrome/browser/renderer_host/site_instance.h"
15 #include "chrome/browser/renderer_preferences_util.h" 16 #include "chrome/browser/renderer_preferences_util.h"
16 #include "chrome/browser/ui/login/login_prompt.h" 17 #include "chrome/browser/ui/login/login_prompt.h"
17 #include "chrome/common/extensions/extension_constants.h" 18 #include "chrome/common/extensions/extension_constants.h"
18 #include "chrome/common/notification_service.h" 19 #include "chrome/common/notification_service.h"
19 #include "chrome/common/url_constants.h" 20 #include "chrome/common/url_constants.h"
20 #include "chrome/common/view_types.h" 21 #include "chrome/common/view_types.h"
21 #include "chrome/common/render_messages.h" 22 #include "chrome/common/render_messages.h"
22 #include "chrome/common/render_messages_params.h" 23 #include "chrome/common/render_messages_params.h"
23 #include "ui/gfx/rect.h" 24 #include "ui/gfx/rect.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 Source<Profile>(profile_)); 76 Source<Profile>(profile_));
76 render_view_host_->CreateRenderView(string16()); 77 render_view_host_->CreateRenderView(string16());
77 78
78 // Register to cancel if Authentication is required. 79 // Register to cancel if Authentication is required.
79 registrar_.Add(this, NotificationType::AUTH_NEEDED, 80 registrar_.Add(this, NotificationType::AUTH_NEEDED,
80 NotificationService::AllSources()); 81 NotificationService::AllSources());
81 82
82 registrar_.Add(this, NotificationType::AUTH_CANCELLED, 83 registrar_.Add(this, NotificationType::AUTH_CANCELLED,
83 NotificationService::AllSources()); 84 NotificationService::AllSources());
84 85
86 // Register all responses to see if we should cancel.
87 registrar_.Add(this, NotificationType::DOWNLOAD_STARTED,
cbentzel 2011/02/09 12:19:15 Instead of registering with AllSources, you could
dominich 2011/02/09 22:33:30 Done.
88 NotificationService::AllSources());
89
85 DCHECK(load_start_time_.is_null()); 90 DCHECK(load_start_time_.is_null());
86 load_start_time_ = base::TimeTicks::Now(); 91 load_start_time_ = base::TimeTicks::Now();
87 92
88 ViewMsg_Navigate_Params params; 93 ViewMsg_Navigate_Params params;
89 params.url = prerender_url_; 94 params.url = prerender_url_;
90 params.transition = PageTransition::LINK; 95 params.transition = PageTransition::LINK;
91 params.navigation_type = ViewMsg_Navigate_Params::PRERENDER; 96 params.navigation_type = ViewMsg_Navigate_Params::PRERENDER;
92 render_view_host_->Navigate(params); 97 render_view_host_->Navigate(params);
93 } 98 }
94 99
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 LoginNotificationDetails* details_ptr = 204 LoginNotificationDetails* details_ptr =
200 Details<LoginNotificationDetails>(details).ptr(); 205 Details<LoginNotificationDetails>(details).ptr();
201 LoginHandler* handler = details_ptr->handler(); 206 LoginHandler* handler = details_ptr->handler();
202 DCHECK(handler != NULL); 207 DCHECK(handler != NULL);
203 RenderViewHostDelegate* delegate = handler->GetRenderViewHostDelegate(); 208 RenderViewHostDelegate* delegate = handler->GetRenderViewHostDelegate();
204 if (controller == NULL && delegate == this) 209 if (controller == NULL && delegate == this)
205 Destroy(FINAL_STATUS_AUTH_NEEDED); 210 Destroy(FINAL_STATUS_AUTH_NEEDED);
206 break; 211 break;
207 } 212 }
208 213
214 case NotificationType::DOWNLOAD_STARTED: {
215 // If the download is started from a RenderViewHost that we are
216 // delegating, kill the prerender. This will also stop the download and
217 // navigating to the page will restart it as expected.
218 RenderViewHostDelegate* rvhd =
219 Source<RenderViewHostDelegate>(source).ptr();
220 if (rvhd == this) {
221 Destroy(FINAL_STATUS_DOWNLOAD);
cbentzel 2011/02/09 12:11:14 Nit: I'd like an explicit return here, since Destr
dominich 2011/02/09 22:33:30 I'll add the same to the AUTH_* cases above.
dominich 2011/02/09 22:33:30 Done.
222 }
223 break;
224 }
225
209 default: 226 default:
210 NOTREACHED() << "Unexpected notification sent."; 227 NOTREACHED() << "Unexpected notification sent.";
211 break; 228 break;
212 } 229 }
213 } 230 }
214 231
215 void PrerenderContents::OnMessageBoxClosed(IPC::Message* reply_msg, 232 void PrerenderContents::OnMessageBoxClosed(IPC::Message* reply_msg,
216 bool success, 233 bool success,
217 const std::wstring& prompt) { 234 const std::wstring& prompt) {
218 render_view_host_->JavaScriptMessageBoxClosed(reply_msg, success, prompt); 235 render_view_host_->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 351
335 void PrerenderContents::DidStopLoading() { 352 void PrerenderContents::DidStopLoading() {
336 has_stopped_loading_ = true; 353 has_stopped_loading_ = true;
337 } 354 }
338 355
339 void PrerenderContents::Destroy(FinalStatus final_status) { 356 void PrerenderContents::Destroy(FinalStatus final_status) {
340 prerender_manager_->RemoveEntry(this); 357 prerender_manager_->RemoveEntry(this);
341 set_final_status(final_status); 358 set_final_status(final_status);
342 delete this; 359 delete this;
343 } 360 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698