OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 const content::Referrer& referrer, | 213 const content::Referrer& referrer, |
214 Origin origin, | 214 Origin origin, |
215 uint8 experiment_id) | 215 uint8 experiment_id) |
216 : prerender_manager_(prerender_manager), | 216 : prerender_manager_(prerender_manager), |
217 prerender_tracker_(prerender_tracker), | 217 prerender_tracker_(prerender_tracker), |
218 prerender_url_(url), | 218 prerender_url_(url), |
219 referrer_(referrer), | 219 referrer_(referrer), |
220 profile_(profile), | 220 profile_(profile), |
221 page_id_(0), | 221 page_id_(0), |
222 has_stopped_loading_(false), | 222 has_stopped_loading_(false), |
223 has_finished_loading_(false), | |
223 final_status_(FINAL_STATUS_MAX), | 224 final_status_(FINAL_STATUS_MAX), |
224 prerendering_has_started_(false), | 225 prerendering_has_started_(false), |
225 match_complete_status_(MATCH_COMPLETE_DEFAULT), | 226 match_complete_status_(MATCH_COMPLETE_DEFAULT), |
226 prerendering_has_been_cancelled_(false), | 227 prerendering_has_been_cancelled_(false), |
227 child_id_(-1), | 228 child_id_(-1), |
228 route_id_(-1), | 229 route_id_(-1), |
229 origin_(origin), | 230 origin_(origin), |
230 experiment_id_(experiment_id) { | 231 experiment_id_(experiment_id) { |
231 DCHECK(prerender_manager != NULL); | 232 DCHECK(prerender_manager != NULL); |
232 } | 233 } |
(...skipping 13 matching lines...) Expand all Loading... | |
246 DCHECK(profile_ != NULL); | 247 DCHECK(profile_ != NULL); |
247 DCHECK(!prerendering_has_started_); | 248 DCHECK(!prerendering_has_started_); |
248 DCHECK(prerender_contents_.get() == NULL); | 249 DCHECK(prerender_contents_.get() == NULL); |
249 | 250 |
250 prerendering_has_started_ = true; | 251 prerendering_has_started_ = true; |
251 WebContents* new_contents = WebContents::Create( | 252 WebContents* new_contents = WebContents::Create( |
252 profile_, NULL, MSG_ROUTING_NONE, NULL, session_storage_namespace); | 253 profile_, NULL, MSG_ROUTING_NONE, NULL, session_storage_namespace); |
253 prerender_contents_.reset(new TabContentsWrapper(new_contents)); | 254 prerender_contents_.reset(new TabContentsWrapper(new_contents)); |
254 content::WebContentsObserver::Observe(new_contents); | 255 content::WebContentsObserver::Observe(new_contents); |
255 | 256 |
256 gfx::Rect tab_bounds(640, 480); | 257 gfx::Rect tab_bounds(640, 480); |
dominich
2012/02/14 01:11:20
This is a recent change, but a default is set here
| |
257 if (source_render_view_host) { | 258 if (source_render_view_host) { |
258 DCHECK(source_render_view_host->view() != NULL); | 259 DCHECK(source_render_view_host->view() != NULL); |
259 WebContents* source_wc = | 260 WebContents* source_wc = |
260 source_render_view_host->delegate()->GetAsWebContents(); | 261 source_render_view_host->delegate()->GetAsWebContents(); |
261 if (source_wc) { | 262 if (source_wc) { |
262 // Set the size of the new TC to that of the old TC. | 263 // Set the size of the new TC to that of the old TC. |
263 source_wc->GetView()->GetContainerBounds(&tab_bounds); | 264 source_wc->GetView()->GetContainerBounds(&tab_bounds); |
264 } | 265 } |
265 } else { | 266 } else { |
266 // Try to get the active tab of the active browser and use that for tab | 267 // Try to get the active tab of the active browser and use that for tab |
267 // bounds. If the browser has never been active, we will fail to get a size | 268 // bounds. If the browser has never been active, we will fail to get a size |
268 // but we shouldn't be prerendering in that case anyway. | 269 // but we shouldn't be prerendering in that case anyway. |
269 Browser* active_browser = BrowserList::GetLastActiveWithProfile(profile_); | 270 Browser* active_browser = BrowserList::GetLastActiveWithProfile(profile_); |
270 if (active_browser) { | 271 if (active_browser) { |
271 WebContents* active_web_contents = active_browser->GetWebContentsAt( | 272 WebContents* active_web_contents = active_browser->GetWebContentsAt( |
272 active_browser->active_index()); | 273 active_browser->active_index()); |
273 if (active_web_contents) | 274 if (active_web_contents) |
274 active_web_contents->GetView()->GetContainerBounds(&tab_bounds); | 275 active_web_contents->GetView()->GetContainerBounds(&tab_bounds); |
276 } else { | |
277 gfx::Rect default_tab_bounds = prerender_manager_->default_tab_bounds(); | |
dominich
2012/02/14 01:11:20
So you don't need this unless you want to override
Jay Civelli
2012/02/14 03:13:51
Moved to the config, as you suggested later on.
| |
278 if (!default_tab_bounds.IsEmpty()) | |
279 tab_bounds = default_tab_bounds; | |
275 } | 280 } |
276 } | 281 } |
277 | 282 |
278 tab_contents_delegate_.reset(new TabContentsDelegateImpl(this)); | 283 tab_contents_delegate_.reset(new TabContentsDelegateImpl(this)); |
279 new_contents->SetDelegate(tab_contents_delegate_.get()); | 284 new_contents->SetDelegate(tab_contents_delegate_.get()); |
280 | 285 |
281 // Set the size of the prerender TabContents. | 286 // Set the size of the prerender TabContents. |
282 prerender_contents_->web_contents()->GetView()->SizeContents( | 287 prerender_contents_->web_contents()->GetView()->SizeContents( |
283 tab_bounds.size()); | 288 tab_bounds.size()); |
284 | 289 |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
505 | 510 |
506 void PrerenderContents::OnJSOutOfMemory() { | 511 void PrerenderContents::OnJSOutOfMemory() { |
507 Destroy(FINAL_STATUS_JS_OUT_OF_MEMORY); | 512 Destroy(FINAL_STATUS_JS_OUT_OF_MEMORY); |
508 } | 513 } |
509 | 514 |
510 void PrerenderContents::RenderViewGone(base::TerminationStatus status) { | 515 void PrerenderContents::RenderViewGone(base::TerminationStatus status) { |
511 Destroy(FINAL_STATUS_RENDERER_CRASHED); | 516 Destroy(FINAL_STATUS_RENDERER_CRASHED); |
512 } | 517 } |
513 | 518 |
514 void PrerenderContents::DidStopLoading() { | 519 void PrerenderContents::DidStopLoading() { |
515 has_stopped_loading_ = true; | 520 has_stopped_loading_ = true; |
dominich
2012/02/14 01:11:20
Do you need to set has_finished_loading_ = false e
Jay Civelli
2012/02/14 03:13:51
Do you mean has_finished_loading_ = true?
I don't
| |
516 } | 521 } |
517 | 522 |
518 void PrerenderContents::DidStartProvisionalLoadForFrame( | 523 void PrerenderContents::DidStartProvisionalLoadForFrame( |
519 int64 frame_id, | 524 int64 frame_id, |
520 bool is_main_frame, | 525 bool is_main_frame, |
521 const GURL& validated_url, | 526 const GURL& validated_url, |
522 bool is_error_page, | 527 bool is_error_page, |
523 RenderViewHost* render_view_host) { | 528 RenderViewHost* render_view_host) { |
524 if (is_main_frame) { | 529 if (is_main_frame) { |
525 if (!AddAliasURL(validated_url)) | 530 if (!AddAliasURL(validated_url)) |
526 return; | 531 return; |
527 | 532 |
528 // Usually, this event fires if the user clicks or enters a new URL. | 533 // Usually, this event fires if the user clicks or enters a new URL. |
529 // Neither of these can happen in the case of an invisible prerender. | 534 // Neither of these can happen in the case of an invisible prerender. |
530 // So the cause is: Some JavaScript caused a new URL to be loaded. In that | 535 // So the cause is: Some JavaScript caused a new URL to be loaded. In that |
531 // case, the spinner would start again in the browser, so we must reset | 536 // case, the spinner would start again in the browser, so we must reset |
532 // has_stopped_loading_ so that the spinner won't be stopped. | 537 // has_stopped_loading_ so that the spinner won't be stopped. |
533 has_stopped_loading_ = false; | 538 has_stopped_loading_ = false; |
539 has_finished_loading_ = false; | |
534 } | 540 } |
535 } | 541 } |
536 | 542 |
543 void PrerenderContents::DidFinishLoad(int64 frame_id, | |
544 const GURL& validated_url, | |
545 bool is_main_frame) { | |
546 if (is_main_frame) | |
547 has_finished_loading_ = true; | |
548 } | |
549 | |
537 bool PrerenderContents::ShouldSuppressDialogs() { | 550 bool PrerenderContents::ShouldSuppressDialogs() { |
538 // Always suppress JavaScript messages if they're triggered by a page being | 551 // Always suppress JavaScript messages if they're triggered by a page being |
539 // prerendered. | 552 // prerendered. |
540 // We still want to show the user the message when they navigate to this | 553 // We still want to show the user the message when they navigate to this |
541 // page, so cancel this prerender. | 554 // page, so cancel this prerender. |
542 Destroy(FINAL_STATUS_JAVASCRIPT_ALERT); | 555 Destroy(FINAL_STATUS_JAVASCRIPT_ALERT); |
543 return true; | 556 return true; |
544 } | 557 } |
545 | 558 |
546 void PrerenderContents::Destroy(FinalStatus final_status) { | 559 void PrerenderContents::Destroy(FinalStatus final_status) { |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
651 bool PrerenderContents::IsCrossSiteNavigationPending() const { | 664 bool PrerenderContents::IsCrossSiteNavigationPending() const { |
652 if (!prerender_contents_.get() || !prerender_contents_->web_contents()) | 665 if (!prerender_contents_.get() || !prerender_contents_->web_contents()) |
653 return false; | 666 return false; |
654 const WebContents* web_contents = prerender_contents_->web_contents(); | 667 const WebContents* web_contents = prerender_contents_->web_contents(); |
655 return (web_contents->GetSiteInstance() != | 668 return (web_contents->GetSiteInstance() != |
656 web_contents->GetPendingSiteInstance()); | 669 web_contents->GetPendingSiteInstance()); |
657 } | 670 } |
658 | 671 |
659 | 672 |
660 } // namespace prerender | 673 } // namespace prerender |
OLD | NEW |