| 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" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 NotificationType::PRERENDER_CONTENTS_STARTED, | 101 NotificationType::PRERENDER_CONTENTS_STARTED, |
| 102 Source<std::pair<int, int> >(&process_view_pair), | 102 Source<std::pair<int, int> >(&process_view_pair), |
| 103 NotificationService::NoDetails()); | 103 NotificationService::NoDetails()); |
| 104 | 104 |
| 105 // Create the RenderView, so it can receive messages. | 105 // Create the RenderView, so it can receive messages. |
| 106 render_view_host_->CreateRenderView(string16()); | 106 render_view_host_->CreateRenderView(string16()); |
| 107 | 107 |
| 108 // Hide the RVH, so that we will run at a lower CPU priority. | 108 // Hide the RVH, so that we will run at a lower CPU priority. |
| 109 // Once the RVH is being swapped into a tab, we will Restore it again. | 109 // Once the RVH is being swapped into a tab, we will Restore it again. |
| 110 render_view_host_->WasHidden(); | 110 render_view_host_->WasHidden(); |
| 111 render_view_host_->AllowScriptToClose(true); | |
| 112 | 111 |
| 113 // Register this with the ResourceDispatcherHost as a prerender | 112 // Register this with the ResourceDispatcherHost as a prerender |
| 114 // RenderViewHost. This must be done before the Navigate message to catch all | 113 // RenderViewHost. This must be done before the Navigate message to catch all |
| 115 // resource requests, but as it is on the same thread as the Navigate message | 114 // resource requests, but as it is on the same thread as the Navigate message |
| 116 // (IO) there is no race condition. | 115 // (IO) there is no race condition. |
| 117 ResourceDispatcherHost* rdh = g_browser_process->resource_dispatcher_host(); | 116 ResourceDispatcherHost* rdh = g_browser_process->resource_dispatcher_host(); |
| 118 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 117 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 119 NewRunnableFunction(&AddChildRoutePair, rdh, | 118 NewRunnableFunction(&AddChildRoutePair, rdh, |
| 120 process_id, view_id)); | 119 process_id, view_id)); |
| 121 | 120 |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 NOTIMPLEMENTED(); | 431 NOTIMPLEMENTED(); |
| 433 } | 432 } |
| 434 | 433 |
| 435 bool PrerenderContents::OnMessageReceived(const IPC::Message& message) { | 434 bool PrerenderContents::OnMessageReceived(const IPC::Message& message) { |
| 436 bool handled = true; | 435 bool handled = true; |
| 437 bool message_is_ok = true; | 436 bool message_is_ok = true; |
| 438 IPC_BEGIN_MESSAGE_MAP_EX(PrerenderContents, message, message_is_ok) | 437 IPC_BEGIN_MESSAGE_MAP_EX(PrerenderContents, message, message_is_ok) |
| 439 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame, | 438 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame, |
| 440 OnDidStartProvisionalLoadForFrame) | 439 OnDidStartProvisionalLoadForFrame) |
| 441 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL) | 440 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL) |
| 442 IPC_MESSAGE_HANDLER(ViewHostMsg_MaybeCancelPrerender, | 441 IPC_MESSAGE_HANDLER(ViewHostMsg_MaybeCancelPrerenderForHTML5Media, |
| 443 OnMaybeCancelPrerender) | 442 OnMaybeCancelPrerenderForHTML5Media) |
| 444 IPC_MESSAGE_UNHANDLED(handled = false) | 443 IPC_MESSAGE_UNHANDLED(handled = false) |
| 445 IPC_END_MESSAGE_MAP_EX() | 444 IPC_END_MESSAGE_MAP_EX() |
| 446 | 445 |
| 447 return handled; | 446 return handled; |
| 448 } | 447 } |
| 449 | 448 |
| 450 void PrerenderContents::OnDidStartProvisionalLoadForFrame(int64 frame_id, | 449 void PrerenderContents::OnDidStartProvisionalLoadForFrame(int64 frame_id, |
| 451 bool is_main_frame, | 450 bool is_main_frame, |
| 452 const GURL& url) { | 451 const GURL& url) { |
| 453 if (is_main_frame) { | 452 if (is_main_frame) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 472 for (std::vector<FaviconURL>::const_iterator i = urls.begin(); | 471 for (std::vector<FaviconURL>::const_iterator i = urls.begin(); |
| 473 i != urls.end(); ++i) { | 472 i != urls.end(); ++i) { |
| 474 if (i->icon_type == FAVICON) { | 473 if (i->icon_type == FAVICON) { |
| 475 icon_url_ = i->icon_url; | 474 icon_url_ = i->icon_url; |
| 476 LOG(INFO) << icon_url_; | 475 LOG(INFO) << icon_url_; |
| 477 return; | 476 return; |
| 478 } | 477 } |
| 479 } | 478 } |
| 480 } | 479 } |
| 481 | 480 |
| 482 void PrerenderContents::OnMaybeCancelPrerender( | 481 void PrerenderContents::OnMaybeCancelPrerenderForHTML5Media() { |
| 483 PrerenderCancellationReason reason) { | 482 Destroy(FINAL_STATUS_HTML5_MEDIA); |
| 484 switch (reason) { | |
| 485 case PRERENDER_CANCELLATION_REASON_HTML5_MEDIA: | |
| 486 Destroy(FINAL_STATUS_HTML5_MEDIA); | |
| 487 return; | |
| 488 default: | |
| 489 LOG(DFATAL) << "Invalid reason " << reason | |
| 490 << " in OnMaybeCancelPrerender."; | |
| 491 } | |
| 492 } | 483 } |
| 493 | 484 |
| 494 bool PrerenderContents::AddAliasURL(const GURL& url) { | 485 bool PrerenderContents::AddAliasURL(const GURL& url) { |
| 495 if (!url.SchemeIs("http")) | 486 if (!url.SchemeIs("http")) |
| 496 return false; | 487 return false; |
| 497 alias_urls_.push_back(url); | 488 alias_urls_.push_back(url); |
| 498 return true; | 489 return true; |
| 499 } | 490 } |
| 500 | 491 |
| 501 bool PrerenderContents::MatchesURL(const GURL& url) const { | 492 bool PrerenderContents::MatchesURL(const GURL& url) const { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 return; | 540 return; |
| 550 | 541 |
| 551 size_t private_bytes, shared_bytes; | 542 size_t private_bytes, shared_bytes; |
| 552 if (metrics->GetMemoryBytes(&private_bytes, &shared_bytes)) { | 543 if (metrics->GetMemoryBytes(&private_bytes, &shared_bytes)) { |
| 553 if (private_bytes > kMaxPrerenderPrivateMB * 1024 * 1024) | 544 if (private_bytes > kMaxPrerenderPrivateMB * 1024 * 1024) |
| 554 Destroy(FINAL_STATUS_MEMORY_LIMIT_EXCEEDED); | 545 Destroy(FINAL_STATUS_MEMORY_LIMIT_EXCEEDED); |
| 555 } | 546 } |
| 556 } | 547 } |
| 557 | 548 |
| 558 } // namespace prerender | 549 } // namespace prerender |
| OLD | NEW |