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 <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 81 |
82 // TabContentsDelegate implementation: | 82 // TabContentsDelegate implementation: |
83 virtual bool ShouldAddNavigationToHistory( | 83 virtual bool ShouldAddNavigationToHistory( |
84 const history::HistoryAddPageArgs& add_page_args, | 84 const history::HistoryAddPageArgs& add_page_args, |
85 NavigationType::Type navigation_type) OVERRIDE { | 85 NavigationType::Type navigation_type) OVERRIDE { |
86 add_page_vector_.push_back( | 86 add_page_vector_.push_back( |
87 scoped_refptr<history::HistoryAddPageArgs>(add_page_args.Clone())); | 87 scoped_refptr<history::HistoryAddPageArgs>(add_page_args.Clone())); |
88 return false; | 88 return false; |
89 } | 89 } |
90 | 90 |
| 91 bool CanDownload(TabContents* source, int request_id) OVERRIDE { |
| 92 prerender_contents_->Destroy(FINAL_STATUS_DOWNLOAD); |
| 93 // Cancel the download. |
| 94 return false; |
| 95 } |
| 96 |
| 97 void OnStartDownload(TabContents* source, DownloadItem* download) OVERRIDE { |
| 98 // Prerendered pages should never be able to download files. |
| 99 NOTREACHED(); |
| 100 } |
| 101 |
91 // Commits the History of Pages to the given TabContents. | 102 // Commits the History of Pages to the given TabContents. |
92 void CommitHistory(TabContentsWrapper* tab) { | 103 void CommitHistory(TabContentsWrapper* tab) { |
93 for (size_t i = 0; i < add_page_vector_.size(); ++i) | 104 for (size_t i = 0; i < add_page_vector_.size(); ++i) |
94 tab->history_tab_helper()->UpdateHistoryForNavigation( | 105 tab->history_tab_helper()->UpdateHistoryForNavigation( |
95 add_page_vector_[i].get()); | 106 add_page_vector_[i].get()); |
96 } | 107 } |
97 | 108 |
98 private: | 109 private: |
99 typedef std::vector<scoped_refptr<history::HistoryAddPageArgs> > | 110 typedef std::vector<scoped_refptr<history::HistoryAddPageArgs> > |
100 AddPageVector; | 111 AddPageVector; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 const RenderViewHost* source_render_view_host) { | 154 const RenderViewHost* source_render_view_host) { |
144 DCHECK(profile_ != NULL); | 155 DCHECK(profile_ != NULL); |
145 DCHECK(!prerendering_has_started_); | 156 DCHECK(!prerendering_has_started_); |
146 DCHECK(prerender_contents_.get() == NULL); | 157 DCHECK(prerender_contents_.get() == NULL); |
147 | 158 |
148 prerendering_has_started_ = true; | 159 prerendering_has_started_ = true; |
149 TabContents* new_contents = new TabContents(profile_, NULL, MSG_ROUTING_NONE, | 160 TabContents* new_contents = new TabContents(profile_, NULL, MSG_ROUTING_NONE, |
150 NULL, NULL); | 161 NULL, NULL); |
151 prerender_contents_.reset(new TabContentsWrapper(new_contents)); | 162 prerender_contents_.reset(new TabContentsWrapper(new_contents)); |
152 TabContentsObserver::Observe(new_contents); | 163 TabContentsObserver::Observe(new_contents); |
153 prerender_contents_->download_tab_helper()->set_delegate(this); | |
154 | 164 |
155 gfx::Rect tab_bounds; | 165 gfx::Rect tab_bounds; |
156 if (source_render_view_host) { | 166 if (source_render_view_host) { |
157 DCHECK(source_render_view_host->view() != NULL); | 167 DCHECK(source_render_view_host->view() != NULL); |
158 TabContents* source_tc = | 168 TabContents* source_tc = |
159 source_render_view_host->delegate()->GetAsTabContents(); | 169 source_render_view_host->delegate()->GetAsTabContents(); |
160 if (source_tc) { | 170 if (source_tc) { |
161 // So that history merging will work, get the max page ID | 171 // So that history merging will work, get the max page ID |
162 // of the old page as a starting id. | 172 // of the old page as a starting id. |
163 starting_page_id_ = source_tc->GetMaxPageID(); | 173 starting_page_id_ = source_tc->GetMaxPageID(); |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 } | 520 } |
511 set_final_status(final_status); | 521 set_final_status(final_status); |
512 | 522 |
513 // We may destroy the PrerenderContents before we have initialized the | 523 // We may destroy the PrerenderContents before we have initialized the |
514 // RenderViewHost. Otherwise set the Observer's PrerenderContents to NULL to | 524 // RenderViewHost. Otherwise set the Observer's PrerenderContents to NULL to |
515 // avoid any more messages being sent. | 525 // avoid any more messages being sent. |
516 if (render_view_host_observer_.get()) | 526 if (render_view_host_observer_.get()) |
517 render_view_host_observer_->set_prerender_contents(NULL); | 527 render_view_host_observer_->set_prerender_contents(NULL); |
518 } | 528 } |
519 | 529 |
520 bool PrerenderContents::CanDownload(int request_id) { | |
521 Destroy(FINAL_STATUS_DOWNLOAD); | |
522 // Cancel the download. | |
523 return false; | |
524 } | |
525 | |
526 void PrerenderContents::OnStartDownload(DownloadItem* download, | |
527 TabContentsWrapper* tab) { | |
528 // Prerendered pages should never be able to download files. | |
529 NOTREACHED(); | |
530 } | |
531 | |
532 base::ProcessMetrics* PrerenderContents::MaybeGetProcessMetrics() { | 530 base::ProcessMetrics* PrerenderContents::MaybeGetProcessMetrics() { |
533 if (process_metrics_.get() == NULL) { | 531 if (process_metrics_.get() == NULL) { |
534 // If a PrenderContents hasn't started prerending, don't be fully formed. | 532 // If a PrenderContents hasn't started prerending, don't be fully formed. |
535 if (!render_view_host() || !render_view_host()->process()) | 533 if (!render_view_host() || !render_view_host()->process()) |
536 return NULL; | 534 return NULL; |
537 base::ProcessHandle handle = render_view_host()->process()->GetHandle(); | 535 base::ProcessHandle handle = render_view_host()->process()->GetHandle(); |
538 if (handle == base::kNullProcessHandle) | 536 if (handle == base::kNullProcessHandle) |
539 return NULL; | 537 return NULL; |
540 #if !defined(OS_MACOSX) | 538 #if !defined(OS_MACOSX) |
541 process_metrics_.reset(base::ProcessMetrics::CreateProcessMetrics(handle)); | 539 process_metrics_.reset(base::ProcessMetrics::CreateProcessMetrics(handle)); |
(...skipping 15 matching lines...) Expand all Loading... |
557 size_t private_bytes, shared_bytes; | 555 size_t private_bytes, shared_bytes; |
558 if (metrics->GetMemoryBytes(&private_bytes, &shared_bytes) && | 556 if (metrics->GetMemoryBytes(&private_bytes, &shared_bytes) && |
559 private_bytes > prerender_manager_->config().max_bytes) { | 557 private_bytes > prerender_manager_->config().max_bytes) { |
560 Destroy(FINAL_STATUS_MEMORY_LIMIT_EXCEEDED); | 558 Destroy(FINAL_STATUS_MEMORY_LIMIT_EXCEEDED); |
561 } | 559 } |
562 } | 560 } |
563 | 561 |
564 TabContentsWrapper* PrerenderContents::ReleasePrerenderContents() { | 562 TabContentsWrapper* PrerenderContents::ReleasePrerenderContents() { |
565 prerender_contents_->tab_contents()->set_delegate(NULL); | 563 prerender_contents_->tab_contents()->set_delegate(NULL); |
566 render_view_host_observer_.reset(); | 564 render_view_host_observer_.reset(); |
567 prerender_contents_->download_tab_helper()->set_delegate(NULL); | |
568 TabContentsObserver::Observe(NULL); | 565 TabContentsObserver::Observe(NULL); |
569 return prerender_contents_.release(); | 566 return prerender_contents_.release(); |
570 } | 567 } |
571 | 568 |
572 RenderViewHostDelegate* PrerenderContents::GetRenderViewHostDelegate() { | 569 RenderViewHostDelegate* PrerenderContents::GetRenderViewHostDelegate() { |
573 if (!prerender_contents_.get()) | 570 if (!prerender_contents_.get()) |
574 return NULL; | 571 return NULL; |
575 return prerender_contents_->tab_contents(); | 572 return prerender_contents_->tab_contents(); |
576 } | 573 } |
577 | 574 |
(...skipping 17 matching lines...) Expand all Loading... |
595 return NULL; | 592 return NULL; |
596 DictionaryValue* dict_value = new DictionaryValue(); | 593 DictionaryValue* dict_value = new DictionaryValue(); |
597 dict_value->SetString("url", prerender_url_.spec()); | 594 dict_value->SetString("url", prerender_url_.spec()); |
598 base::TimeTicks current_time = base::TimeTicks::Now(); | 595 base::TimeTicks current_time = base::TimeTicks::Now(); |
599 base::TimeDelta duration = current_time - load_start_time_; | 596 base::TimeDelta duration = current_time - load_start_time_; |
600 dict_value->SetInteger("duration", duration.InSeconds()); | 597 dict_value->SetInteger("duration", duration.InSeconds()); |
601 return dict_value; | 598 return dict_value; |
602 } | 599 } |
603 | 600 |
604 } // namespace prerender | 601 } // namespace prerender |
OLD | NEW |