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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 // static | 142 // static |
143 PrerenderContents::Factory* PrerenderContents::CreateFactory() { | 143 PrerenderContents::Factory* PrerenderContents::CreateFactory() { |
144 return new PrerenderContentsFactoryImpl(); | 144 return new PrerenderContentsFactoryImpl(); |
145 } | 145 } |
146 | 146 |
147 void PrerenderContents::StartPrerendering( | 147 void PrerenderContents::StartPrerendering( |
148 const RenderViewHost* source_render_view_host) { | 148 const RenderViewHost* source_render_view_host) { |
149 DCHECK(profile_ != NULL); | 149 DCHECK(profile_ != NULL); |
150 DCHECK(!prerendering_has_started_); | 150 DCHECK(!prerendering_has_started_); |
151 DCHECK(prerender_contents_.get() == NULL); | 151 DCHECK(prerender_contents_.get() == NULL); |
152 DCHECK(source_render_view_host != NULL); | |
153 DCHECK(source_render_view_host->view() != NULL); | |
154 | 152 |
155 prerendering_has_started_ = true; | 153 prerendering_has_started_ = true; |
156 TabContents* new_contents = new TabContents(profile_, NULL, MSG_ROUTING_NONE, | 154 TabContents* new_contents = new TabContents(profile_, NULL, MSG_ROUTING_NONE, |
157 NULL, NULL); | 155 NULL, NULL); |
158 prerender_contents_.reset(new TabContentsWrapper(new_contents)); | 156 prerender_contents_.reset(new TabContentsWrapper(new_contents)); |
159 TabContentsObserver::Observe(new_contents); | 157 TabContentsObserver::Observe(new_contents); |
160 prerender_contents_->download_tab_helper()->set_delegate(this); | 158 prerender_contents_->download_tab_helper()->set_delegate(this); |
161 | 159 |
162 TabContents* source_tc = | 160 if (source_render_view_host) { |
163 source_render_view_host->delegate()->GetAsTabContents(); | 161 TabContents* source_tc = |
164 if (source_tc) { | 162 source_render_view_host->delegate()->GetAsTabContents(); |
165 // So that history merging will work, get the max page ID | 163 if (source_tc) { |
166 // of the old page, and add a safety margin of 10 to it (for things | 164 // So that history merging will work, get the max page ID |
167 // such as redirects). | 165 // of the old page, and add a safety margin of 10 to it (for things |
168 starting_page_id_ = source_tc->GetMaxPageID(); | 166 // such as redirects). |
169 if (starting_page_id_ < 0) | 167 starting_page_id_ = source_tc->GetMaxPageID(); |
170 starting_page_id_ = 0; | 168 if (starting_page_id_ < 0) |
171 starting_page_id_ += kPrerenderPageIdOffset; | 169 starting_page_id_ = 0; |
172 prerender_contents_->controller().set_max_restored_page_id( | 170 starting_page_id_ += kPrerenderPageIdOffset; |
173 starting_page_id_); | 171 prerender_contents_->controller().set_max_restored_page_id( |
| 172 starting_page_id_); |
174 | 173 |
175 tab_contents_delegate_.reset(new TabContentsDelegateImpl(this)); | 174 tab_contents_delegate_.reset(new TabContentsDelegateImpl(this)); |
176 new_contents->set_delegate(tab_contents_delegate_.get()); | 175 new_contents->set_delegate(tab_contents_delegate_.get()); |
177 | 176 |
178 // Set the size of the new TC to that of the old TC. | 177 // Set the size of the new TC to that of the old TC. |
179 gfx::Rect tab_bounds; | 178 gfx::Rect tab_bounds; |
180 source_tc->view()->GetContainerBounds(&tab_bounds); | 179 source_tc->view()->GetContainerBounds(&tab_bounds); |
181 prerender_contents_->view()->SizeContents(tab_bounds.size()); | 180 prerender_contents_->view()->SizeContents(tab_bounds.size()); |
| 181 } |
182 } | 182 } |
183 | 183 |
184 // Register as an observer of the RenderViewHost so we get messages. | 184 // Register as an observer of the RenderViewHost so we get messages. |
185 render_view_host_observer_.reset( | 185 render_view_host_observer_.reset( |
186 new PrerenderRenderViewHostObserver(this, render_view_host_mutable())); | 186 new PrerenderRenderViewHostObserver(this, render_view_host_mutable())); |
187 | 187 |
188 child_id_ = render_view_host()->process()->id(); | 188 child_id_ = render_view_host()->process()->id(); |
189 route_id_ = render_view_host()->routing_id(); | 189 route_id_ = render_view_host()->routing_id(); |
190 | 190 |
191 // Register this with the ResourceDispatcherHost as a prerender | 191 // Register this with the ResourceDispatcherHost as a prerender |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 return NULL; | 552 return NULL; |
553 return prerender_contents_->render_view_host(); | 553 return prerender_contents_->render_view_host(); |
554 } | 554 } |
555 | 555 |
556 void PrerenderContents::CommitHistory(TabContentsWrapper* tab) { | 556 void PrerenderContents::CommitHistory(TabContentsWrapper* tab) { |
557 if (tab_contents_delegate_.get()) | 557 if (tab_contents_delegate_.get()) |
558 tab_contents_delegate_->CommitHistory(tab); | 558 tab_contents_delegate_->CommitHistory(tab); |
559 } | 559 } |
560 | 560 |
561 } // namespace prerender | 561 } // namespace prerender |
OLD | NEW |