Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 redirects. | |
|
Charlie Reis
2011/04/11 21:15:52
Please add "from this RenderViewHostDelegate," sin
cbentzel
2011/04/12 18:07:59
Done.
| |
| 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 Loading... | |
| 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. | |
|
Charlie Reis
2011/04/11 21:15:52
How are you distinguishing whether it's top-level
cbentzel
2011/04/11 21:18:35
I'll change to resource_type(). This was using "Ma
cbentzel
2011/04/12 18:07:59
resource_type() is much clearer about what's going
| |
| 336 DCHECK(Source<RenderViewHostDelegate>(source).ptr() == this); | |
| 337 ResourceRedirectDetails* resource_redirect_details = | |
| 338 Details<ResourceRedirectDetails>(details).ptr(); | |
| 339 CHECK(resource_redirect_details != NULL); | |
|
Charlie Reis
2011/04/11 21:15:52
I think Chrome style is to omit the "!= NULL".
cbentzel
2011/04/12 18:07:59
Done.
| |
| 340 if (MatchesURL(resource_redirect_details->url())) { | |
| 341 if (!AddAliasURL(resource_redirect_details->new_url())) | |
| 342 Destroy(FINAL_STATUS_HTTPS); | |
| 343 } | |
| 344 break; | |
| 345 } | |
| 346 | |
| 325 default: | 347 default: |
| 326 NOTREACHED() << "Unexpected notification sent."; | 348 NOTREACHED() << "Unexpected notification sent."; |
| 327 break; | 349 break; |
| 328 } | 350 } |
| 329 } | 351 } |
| 330 | 352 |
| 331 void PrerenderContents::OnMessageBoxClosed(IPC::Message* reply_msg, | 353 void PrerenderContents::OnMessageBoxClosed(IPC::Message* reply_msg, |
| 332 bool success, | 354 bool success, |
| 333 const std::wstring& prompt) { | 355 const std::wstring& prompt) { |
| 334 render_view_host_->JavaScriptMessageBoxClosed(reply_msg, success, prompt); | 356 render_view_host_->JavaScriptMessageBoxClosed(reply_msg, success, prompt); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 405 void PrerenderContents::ShowCreatedFullscreenWidget(int route_id) { | 427 void PrerenderContents::ShowCreatedFullscreenWidget(int route_id) { |
| 406 NOTIMPLEMENTED(); | 428 NOTIMPLEMENTED(); |
| 407 } | 429 } |
| 408 | 430 |
| 409 bool PrerenderContents::OnMessageReceived(const IPC::Message& message) { | 431 bool PrerenderContents::OnMessageReceived(const IPC::Message& message) { |
| 410 bool handled = true; | 432 bool handled = true; |
| 411 bool message_is_ok = true; | 433 bool message_is_ok = true; |
| 412 IPC_BEGIN_MESSAGE_MAP_EX(PrerenderContents, message, message_is_ok) | 434 IPC_BEGIN_MESSAGE_MAP_EX(PrerenderContents, message, message_is_ok) |
| 413 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame, | 435 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame, |
| 414 OnDidStartProvisionalLoadForFrame) | 436 OnDidStartProvisionalLoadForFrame) |
| 415 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad, | |
| 416 OnDidRedirectProvisionalLoad) | |
| 417 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL) | 437 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL) |
| 418 IPC_MESSAGE_HANDLER(ViewHostMsg_MaybeCancelPrerender, | 438 IPC_MESSAGE_HANDLER(ViewHostMsg_MaybeCancelPrerender, |
| 419 OnMaybeCancelPrerender) | 439 OnMaybeCancelPrerender) |
| 420 IPC_MESSAGE_UNHANDLED(handled = false) | 440 IPC_MESSAGE_UNHANDLED(handled = false) |
| 421 IPC_END_MESSAGE_MAP_EX() | 441 IPC_END_MESSAGE_MAP_EX() |
| 422 | 442 |
| 423 return handled; | 443 return handled; |
| 424 } | 444 } |
| 425 | 445 |
| 426 void PrerenderContents::OnDidStartProvisionalLoadForFrame(int64 frame_id, | 446 void PrerenderContents::OnDidStartProvisionalLoadForFrame(int64 frame_id, |
| 427 bool is_main_frame, | 447 bool is_main_frame, |
| 428 const GURL& url) { | 448 const GURL& url) { |
| 429 if (is_main_frame) { | 449 if (is_main_frame) { |
| 430 if (!AddAliasURL(url)) { | 450 if (!AddAliasURL(url)) { |
| 431 Destroy(FINAL_STATUS_HTTPS); | 451 Destroy(FINAL_STATUS_HTTPS); |
| 432 return; | 452 return; |
| 433 } | 453 } |
| 434 | 454 |
| 435 // Usually, this event fires if the user clicks or enters a new URL. | 455 // 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. | 456 // 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 | 457 // 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 | 458 // 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. | 459 // has_stopped_loading_ so that the spinner won't be stopped. |
| 440 has_stopped_loading_ = false; | 460 has_stopped_loading_ = false; |
| 441 } | 461 } |
| 442 } | 462 } |
| 443 | 463 |
| 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(int32 page_id, | 464 void PrerenderContents::OnUpdateFaviconURL(int32 page_id, |
| 452 const GURL& icon_url) { | 465 const GURL& icon_url) { |
| 453 icon_url_ = icon_url; | 466 icon_url_ = icon_url; |
| 454 } | 467 } |
| 455 | 468 |
| 456 void PrerenderContents::OnMaybeCancelPrerender( | 469 void PrerenderContents::OnMaybeCancelPrerender( |
| 457 PrerenderCancellationReason reason) { | 470 PrerenderCancellationReason reason) { |
| 458 switch (reason) { | 471 switch (reason) { |
| 459 case PRERENDER_CANCELLATION_REASON_HTML5_MEDIA: | 472 case PRERENDER_CANCELLATION_REASON_HTML5_MEDIA: |
| 460 Destroy(FINAL_STATUS_HTML5_MEDIA); | 473 Destroy(FINAL_STATUS_HTML5_MEDIA); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 523 return; | 536 return; |
| 524 | 537 |
| 525 size_t private_bytes, shared_bytes; | 538 size_t private_bytes, shared_bytes; |
| 526 if (metrics->GetMemoryBytes(&private_bytes, &shared_bytes)) { | 539 if (metrics->GetMemoryBytes(&private_bytes, &shared_bytes)) { |
| 527 if (private_bytes > kMaxPrerenderPrivateMB * 1024 * 1024) | 540 if (private_bytes > kMaxPrerenderPrivateMB * 1024 * 1024) |
| 528 Destroy(FINAL_STATUS_MEMORY_LIMIT_EXCEEDED); | 541 Destroy(FINAL_STATUS_MEMORY_LIMIT_EXCEEDED); |
| 529 } | 542 } |
| 530 } | 543 } |
| 531 | 544 |
| 532 } // namespace prerender | 545 } // namespace prerender |
| OLD | NEW |