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

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

Issue 6824054: PrerenderContents uses RESOURCE_RECEIVED_REDIRECT notification. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 9 years, 8 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/process_util.h" 7 #include "base/process_util.h"
8 #include "base/task.h" 8 #include "base/task.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/background_contents_service.h" 10 #include "chrome/browser/background_contents_service.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/prerender/prerender_final_status.h" 12 #include "chrome/browser/prerender/prerender_final_status.h"
13 #include "chrome/browser/prerender/prerender_manager.h" 13 #include "chrome/browser/prerender/prerender_manager.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/renderer_preferences_util.h" 15 #include "chrome/browser/renderer_preferences_util.h"
16 #include "chrome/browser/ui/login/login_prompt.h" 16 #include "chrome/browser/ui/login/login_prompt.h"
17 #include "chrome/common/extensions/extension_constants.h" 17 #include "chrome/common/extensions/extension_constants.h"
18 #include "chrome/common/render_messages.h" 18 #include "chrome/common/render_messages.h"
19 #include "chrome/common/extensions/extension_messages.h" 19 #include "chrome/common/extensions/extension_messages.h"
20 #include "chrome/common/url_constants.h" 20 #include "chrome/common/url_constants.h"
21 #include "chrome/common/view_types.h" 21 #include "chrome/common/view_types.h"
22 #include "content/browser/browsing_instance.h" 22 #include "content/browser/browsing_instance.h"
23 #include "content/browser/renderer_host/render_view_host.h" 23 #include "content/browser/renderer_host/render_view_host.h"
24 #include "content/browser/renderer_host/resource_dispatcher_host.h" 24 #include "content/browser/renderer_host/resource_dispatcher_host.h"
25 #include "content/browser/renderer_host/resource_request_details.h"
25 #include "content/browser/site_instance.h" 26 #include "content/browser/site_instance.h"
26 #include "content/common/notification_service.h" 27 #include "content/common/notification_service.h"
27 #include "content/common/view_messages.h" 28 #include "content/common/view_messages.h"
28 #include "ui/gfx/rect.h" 29 #include "ui/gfx/rect.h"
29 30
30 #if defined(OS_MACOSX) 31 #if defined(OS_MACOSX)
31 #include "chrome/browser/mach_broker_mac.h" 32 #include "chrome/browser/mach_broker_mac.h"
32 #endif 33 #endif
33 34
34 namespace prerender { 35 namespace prerender {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 registrar_.Add(this, NotificationType::AUTH_NEEDED, 132 registrar_.Add(this, NotificationType::AUTH_NEEDED,
132 NotificationService::AllSources()); 133 NotificationService::AllSources());
133 134
134 registrar_.Add(this, NotificationType::AUTH_CANCELLED, 135 registrar_.Add(this, NotificationType::AUTH_CANCELLED,
135 NotificationService::AllSources()); 136 NotificationService::AllSources());
136 137
137 // Register all responses to see if we should cancel. 138 // Register all responses to see if we should cancel.
138 registrar_.Add(this, NotificationType::DOWNLOAD_INITIATED, 139 registrar_.Add(this, NotificationType::DOWNLOAD_INITIATED,
139 NotificationService::AllSources()); 140 NotificationService::AllSources());
140 141
142 // Register for redirect notifications sourced from |this|.
143 registrar_.Add(this, NotificationType::RESOURCE_RECEIVED_REDIRECT,
144 Source<RenderViewHostDelegate>(this));
145
141 DCHECK(load_start_time_.is_null()); 146 DCHECK(load_start_time_.is_null());
142 load_start_time_ = base::TimeTicks::Now(); 147 load_start_time_ = base::TimeTicks::Now();
143 148
144 ViewMsg_Navigate_Params params; 149 ViewMsg_Navigate_Params params;
145 params.page_id = -1; 150 params.page_id = -1;
146 params.pending_history_list_offset = -1; 151 params.pending_history_list_offset = -1;
147 params.current_history_list_offset = -1; 152 params.current_history_list_offset = -1;
148 params.current_history_list_length = 0; 153 params.current_history_list_length = 0;
149 params.url = prerender_url_; 154 params.url = prerender_url_;
150 params.transition = PageTransition::LINK; 155 params.transition = PageTransition::LINK;
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 DCHECK(NotificationService::NoDetails() == details); 320 DCHECK(NotificationService::NoDetails() == details);
316 RenderViewHost* rvh = Source<RenderViewHost>(source).ptr(); 321 RenderViewHost* rvh = Source<RenderViewHost>(source).ptr();
317 CHECK(rvh != NULL); 322 CHECK(rvh != NULL);
318 if (rvh->delegate() == this) { 323 if (rvh->delegate() == this) {
319 Destroy(FINAL_STATUS_DOWNLOAD); 324 Destroy(FINAL_STATUS_DOWNLOAD);
320 return; 325 return;
321 } 326 }
322 break; 327 break;
323 } 328 }
324 329
330 case NotificationType::RESOURCE_RECEIVED_REDIRECT: {
331 // RESOURCE_RECEIVED_REDIRECT can come for any resource on a page.
332 // If it's a redirect on the top-level resource, the name needs
333 // to be remembered for future matching, and if it redirects to
334 // an https resource, it needs to be canceled. If a subresource
335 // is redirected, nothing changes.
336 DCHECK(Source<RenderViewHostDelegate>(source).ptr() == this);
337 ResourceRedirectDetails* resource_redirect_details =
338 Details<ResourceRedirectDetails>(details).ptr();
339 CHECK(resource_redirect_details);
340 if (resource_redirect_details->resource_type() ==
341 ResourceType::MAIN_FRAME) {
342 if (!AddAliasURL(resource_redirect_details->new_url()))
343 Destroy(FINAL_STATUS_HTTPS);
344 }
345 break;
346 }
347
325 default: 348 default:
326 NOTREACHED() << "Unexpected notification sent."; 349 NOTREACHED() << "Unexpected notification sent.";
327 break; 350 break;
328 } 351 }
329 } 352 }
330 353
331 void PrerenderContents::OnMessageBoxClosed(IPC::Message* reply_msg, 354 void PrerenderContents::OnMessageBoxClosed(IPC::Message* reply_msg,
332 bool success, 355 bool success,
333 const std::wstring& prompt) { 356 const std::wstring& prompt) {
334 render_view_host_->JavaScriptMessageBoxClosed(reply_msg, success, prompt); 357 render_view_host_->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 void PrerenderContents::ShowCreatedFullscreenWidget(int route_id) { 428 void PrerenderContents::ShowCreatedFullscreenWidget(int route_id) {
406 NOTIMPLEMENTED(); 429 NOTIMPLEMENTED();
407 } 430 }
408 431
409 bool PrerenderContents::OnMessageReceived(const IPC::Message& message) { 432 bool PrerenderContents::OnMessageReceived(const IPC::Message& message) {
410 bool handled = true; 433 bool handled = true;
411 bool message_is_ok = true; 434 bool message_is_ok = true;
412 IPC_BEGIN_MESSAGE_MAP_EX(PrerenderContents, message, message_is_ok) 435 IPC_BEGIN_MESSAGE_MAP_EX(PrerenderContents, message, message_is_ok)
413 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame, 436 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
414 OnDidStartProvisionalLoadForFrame) 437 OnDidStartProvisionalLoadForFrame)
415 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
416 OnDidRedirectProvisionalLoad)
417 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL) 438 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
418 IPC_MESSAGE_HANDLER(ViewHostMsg_MaybeCancelPrerender, 439 IPC_MESSAGE_HANDLER(ViewHostMsg_MaybeCancelPrerender,
419 OnMaybeCancelPrerender) 440 OnMaybeCancelPrerender)
420 IPC_MESSAGE_UNHANDLED(handled = false) 441 IPC_MESSAGE_UNHANDLED(handled = false)
421 IPC_END_MESSAGE_MAP_EX() 442 IPC_END_MESSAGE_MAP_EX()
422 443
423 return handled; 444 return handled;
424 } 445 }
425 446
426 void PrerenderContents::OnDidStartProvisionalLoadForFrame(int64 frame_id, 447 void PrerenderContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
427 bool is_main_frame, 448 bool is_main_frame,
428 const GURL& url) { 449 const GURL& url) {
429 if (is_main_frame) { 450 if (is_main_frame) {
430 if (!AddAliasURL(url)) { 451 if (!AddAliasURL(url)) {
431 Destroy(FINAL_STATUS_HTTPS); 452 Destroy(FINAL_STATUS_HTTPS);
432 return; 453 return;
433 } 454 }
434 455
435 // Usually, this event fires if the user clicks or enters a new URL. 456 // Usually, this event fires if the user clicks or enters a new URL.
436 // Neither of these can happen in the case of an invisible prerender. 457 // Neither of these can happen in the case of an invisible prerender.
437 // So the cause is: Some JavaScript caused a new URL to be loaded. In that 458 // So the cause is: Some JavaScript caused a new URL to be loaded. In that
438 // case, the spinner would start again in the browser, so we must reset 459 // case, the spinner would start again in the browser, so we must reset
439 // has_stopped_loading_ so that the spinner won't be stopped. 460 // has_stopped_loading_ so that the spinner won't be stopped.
440 has_stopped_loading_ = false; 461 has_stopped_loading_ = false;
441 } 462 }
442 } 463 }
443 464
444 void PrerenderContents::OnDidRedirectProvisionalLoad(int32 page_id,
445 const GURL& source_url,
446 const GURL& target_url) {
447 if (!AddAliasURL(target_url))
448 Destroy(FINAL_STATUS_HTTPS);
449 }
450
451 void PrerenderContents::OnUpdateFaviconURL( 465 void PrerenderContents::OnUpdateFaviconURL(
452 int32 page_id, 466 int32 page_id,
453 const std::vector<FaviconURL>& urls) { 467 const std::vector<FaviconURL>& urls) {
454 LOG(INFO) << "PrerenderContents::OnUpdateFaviconURL" << icon_url_; 468 LOG(INFO) << "PrerenderContents::OnUpdateFaviconURL" << icon_url_;
455 for (std::vector<FaviconURL>::const_iterator i = urls.begin(); 469 for (std::vector<FaviconURL>::const_iterator i = urls.begin();
456 i != urls.end(); ++i) { 470 i != urls.end(); ++i) {
457 if (i->icon_type == FAVICON) { 471 if (i->icon_type == FAVICON) {
458 icon_url_ = i->icon_url; 472 icon_url_ = i->icon_url;
459 LOG(INFO) << icon_url_; 473 LOG(INFO) << icon_url_;
460 return; 474 return;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 return; 546 return;
533 547
534 size_t private_bytes, shared_bytes; 548 size_t private_bytes, shared_bytes;
535 if (metrics->GetMemoryBytes(&private_bytes, &shared_bytes)) { 549 if (metrics->GetMemoryBytes(&private_bytes, &shared_bytes)) {
536 if (private_bytes > kMaxPrerenderPrivateMB * 1024 * 1024) 550 if (private_bytes > kMaxPrerenderPrivateMB * 1024 * 1024)
537 Destroy(FINAL_STATUS_MEMORY_LIMIT_EXCEEDED); 551 Destroy(FINAL_STATUS_MEMORY_LIMIT_EXCEEDED);
538 } 552 }
539 } 553 }
540 554
541 } // namespace prerender 555 } // namespace prerender
OLDNEW
« no previous file with comments | « chrome/browser/prerender/prerender_contents.h ('k') | chrome/test/data/prerender/prerender_embedded_content.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698