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

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: Changed source of notification and now notify on all entry points for download initiation. 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"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 Source<Profile>(profile_)); 75 Source<Profile>(profile_));
76 render_view_host_->CreateRenderView(string16()); 76 render_view_host_->CreateRenderView(string16());
77 77
78 // Register to cancel if Authentication is required. 78 // Register to cancel if Authentication is required.
79 registrar_.Add(this, NotificationType::AUTH_NEEDED, 79 registrar_.Add(this, NotificationType::AUTH_NEEDED,
80 NotificationService::AllSources()); 80 NotificationService::AllSources());
81 81
82 registrar_.Add(this, NotificationType::AUTH_CANCELLED, 82 registrar_.Add(this, NotificationType::AUTH_CANCELLED,
83 NotificationService::AllSources()); 83 NotificationService::AllSources());
84 84
85 // Register all responses to see if we should cancel.
86 registrar_.Add(this, NotificationType::DOWNLOAD_INITIATED,
87 NotificationService::AllSources());
88
85 DCHECK(load_start_time_.is_null()); 89 DCHECK(load_start_time_.is_null());
86 load_start_time_ = base::TimeTicks::Now(); 90 load_start_time_ = base::TimeTicks::Now();
87 91
88 ViewMsg_Navigate_Params params; 92 ViewMsg_Navigate_Params params;
89 params.url = prerender_url_; 93 params.url = prerender_url_;
90 params.transition = PageTransition::LINK; 94 params.transition = PageTransition::LINK;
91 params.navigation_type = ViewMsg_Navigate_Params::PRERENDER; 95 params.navigation_type = ViewMsg_Navigate_Params::PRERENDER;
92 render_view_host_->Navigate(params); 96 render_view_host_->Navigate(params);
93 } 97 }
94 98
95 void PrerenderContents::set_final_status(FinalStatus final_status) { 99 void PrerenderContents::set_final_status(FinalStatus final_status) {
96 DCHECK(final_status >= FINAL_STATUS_USED && final_status < FINAL_STATUS_MAX); 100 DCHECK(final_status >= FINAL_STATUS_USED && final_status < FINAL_STATUS_MAX);
97 DCHECK_EQ(FINAL_STATUS_MAX, final_status_); 101 DCHECK_EQ(FINAL_STATUS_MAX, final_status_);
102
98 final_status_ = final_status; 103 final_status_ = final_status;
99 } 104 }
100 105
101 PrerenderContents::FinalStatus PrerenderContents::final_status() const { 106 PrerenderContents::FinalStatus PrerenderContents::final_status() const {
102 return final_status_; 107 return final_status_;
103 } 108 }
104 109
105 PrerenderContents::~PrerenderContents() { 110 PrerenderContents::~PrerenderContents() {
106 DCHECK(final_status_ != FINAL_STATUS_MAX); 111 DCHECK(final_status_ != FINAL_STATUS_MAX);
107 UMA_HISTOGRAM_ENUMERATION("Prerender.FinalStatus", 112 UMA_HISTOGRAM_ENUMERATION("Prerender.FinalStatus",
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 return false; 184 return false;
180 } 185 }
181 186
182 void PrerenderContents::Observe(NotificationType type, 187 void PrerenderContents::Observe(NotificationType type,
183 const NotificationSource& source, 188 const NotificationSource& source,
184 const NotificationDetails& details) { 189 const NotificationDetails& details) {
185 switch (type.value) { 190 switch (type.value) {
186 case NotificationType::PROFILE_DESTROYED: 191 case NotificationType::PROFILE_DESTROYED:
187 Destroy(FINAL_STATUS_PROFILE_DESTROYED); 192 Destroy(FINAL_STATUS_PROFILE_DESTROYED);
188 return; 193 return;
194
189 case NotificationType::APP_TERMINATING: 195 case NotificationType::APP_TERMINATING:
190 Destroy(FINAL_STATUS_APP_TERMINATING); 196 Destroy(FINAL_STATUS_APP_TERMINATING);
191 return; 197 return;
192 198
193 case NotificationType::AUTH_NEEDED: 199 case NotificationType::AUTH_NEEDED:
194 case NotificationType::AUTH_CANCELLED: { 200 case NotificationType::AUTH_CANCELLED: {
195 // Prerendered pages have a NULL controller and the login handler should 201 // Prerendered pages have a NULL controller and the login handler should
196 // be referencing us as the render view host delegate. 202 // be referencing us as the render view host delegate.
197 NavigationController* controller = 203 NavigationController* controller =
198 Source<NavigationController>(source).ptr(); 204 Source<NavigationController>(source).ptr();
199 LoginNotificationDetails* details_ptr = 205 LoginNotificationDetails* details_ptr =
200 Details<LoginNotificationDetails>(details).ptr(); 206 Details<LoginNotificationDetails>(details).ptr();
201 LoginHandler* handler = details_ptr->handler(); 207 LoginHandler* handler = details_ptr->handler();
202 DCHECK(handler != NULL); 208 DCHECK(handler != NULL);
203 RenderViewHostDelegate* delegate = handler->GetRenderViewHostDelegate(); 209 RenderViewHostDelegate* delegate = handler->GetRenderViewHostDelegate();
204 if (controller == NULL && delegate == this) 210 if (controller == NULL && delegate == this) {
205 Destroy(FINAL_STATUS_AUTH_NEEDED); 211 Destroy(FINAL_STATUS_AUTH_NEEDED);
212 return;
213 }
206 break; 214 break;
207 } 215 }
208 216
217 case NotificationType::DOWNLOAD_INITIATED: {
218 // If the download is started from a RenderViewHost that we are
219 // delegating, kill the prerender. This cancels any pending requests
220 // though the download never actually started thanks to the
221 // DownloadRequestLimiter.
222 DCHECK(details == NotificationService::NoDetails());
223 RenderViewHost* rvh = Source<RenderViewHost>(source).ptr();
224 if (rvh->delegate() == this) {
cbentzel 2011/02/10 19:32:18 May not hurt to be defensive and check that rvh is
dominich 2011/02/10 20:02:17 Done.
225 Destroy(FINAL_STATUS_DOWNLOAD);
226 }
227 return;
cbentzel 2011/02/10 19:32:18 move return next to Destroy and make this break, t
dominich 2011/02/10 20:02:17 Done.
228 }
229
209 default: 230 default:
210 NOTREACHED() << "Unexpected notification sent."; 231 NOTREACHED() << "Unexpected notification sent.";
211 break; 232 break;
212 } 233 }
213 } 234 }
214 235
215 void PrerenderContents::OnMessageBoxClosed(IPC::Message* reply_msg, 236 void PrerenderContents::OnMessageBoxClosed(IPC::Message* reply_msg,
216 bool success, 237 bool success,
217 const std::wstring& prompt) { 238 const std::wstring& prompt) {
218 render_view_host_->JavaScriptMessageBoxClosed(reply_msg, success, prompt); 239 render_view_host_->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 361
341 void PrerenderContents::DidStopLoading() { 362 void PrerenderContents::DidStopLoading() {
342 has_stopped_loading_ = true; 363 has_stopped_loading_ = true;
343 } 364 }
344 365
345 void PrerenderContents::Destroy(FinalStatus final_status) { 366 void PrerenderContents::Destroy(FinalStatus final_status) {
346 prerender_manager_->RemoveEntry(this); 367 prerender_manager_->RemoveEntry(this);
347 set_final_status(final_status); 368 set_final_status(final_status);
348 delete this; 369 delete this;
349 } 370 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698