| 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 = prerender_manager_->config().default_tab_bounds; |
| 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 |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 if (is_main_frame) { | 525 if (is_main_frame) { |
| 525 if (!AddAliasURL(validated_url)) | 526 if (!AddAliasURL(validated_url)) |
| 526 return; | 527 return; |
| 527 | 528 |
| 528 // Usually, this event fires if the user clicks or enters a new URL. | 529 // 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. | 530 // 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 | 531 // 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 | 532 // 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. | 533 // has_stopped_loading_ so that the spinner won't be stopped. |
| 533 has_stopped_loading_ = false; | 534 has_stopped_loading_ = false; |
| 535 has_finished_loading_ = false; |
| 534 } | 536 } |
| 535 } | 537 } |
| 536 | 538 |
| 539 void PrerenderContents::DidFinishLoad(int64 frame_id, |
| 540 const GURL& validated_url, |
| 541 bool is_main_frame) { |
| 542 if (is_main_frame) |
| 543 has_finished_loading_ = true; |
| 544 } |
| 545 |
| 537 bool PrerenderContents::ShouldSuppressDialogs() { | 546 bool PrerenderContents::ShouldSuppressDialogs() { |
| 538 // Always suppress JavaScript messages if they're triggered by a page being | 547 // Always suppress JavaScript messages if they're triggered by a page being |
| 539 // prerendered. | 548 // prerendered. |
| 540 // We still want to show the user the message when they navigate to this | 549 // We still want to show the user the message when they navigate to this |
| 541 // page, so cancel this prerender. | 550 // page, so cancel this prerender. |
| 542 Destroy(FINAL_STATUS_JAVASCRIPT_ALERT); | 551 Destroy(FINAL_STATUS_JAVASCRIPT_ALERT); |
| 543 return true; | 552 return true; |
| 544 } | 553 } |
| 545 | 554 |
| 546 void PrerenderContents::Destroy(FinalStatus final_status) { | 555 void PrerenderContents::Destroy(FinalStatus final_status) { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 bool PrerenderContents::IsCrossSiteNavigationPending() const { | 660 bool PrerenderContents::IsCrossSiteNavigationPending() const { |
| 652 if (!prerender_contents_.get() || !prerender_contents_->web_contents()) | 661 if (!prerender_contents_.get() || !prerender_contents_->web_contents()) |
| 653 return false; | 662 return false; |
| 654 const WebContents* web_contents = prerender_contents_->web_contents(); | 663 const WebContents* web_contents = prerender_contents_->web_contents(); |
| 655 return (web_contents->GetSiteInstance() != | 664 return (web_contents->GetSiteInstance() != |
| 656 web_contents->GetPendingSiteInstance()); | 665 web_contents->GetPendingSiteInstance()); |
| 657 } | 666 } |
| 658 | 667 |
| 659 | 668 |
| 660 } // namespace prerender | 669 } // namespace prerender |
| OLD | NEW |