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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 DCHECK(prerender_contents_.get() == NULL); | 248 DCHECK(prerender_contents_.get() == NULL); |
249 | 249 |
250 prerendering_has_started_ = true; | 250 prerendering_has_started_ = true; |
251 WebContents* new_contents = WebContents::Create( | 251 WebContents* new_contents = WebContents::Create( |
252 profile_, NULL, MSG_ROUTING_NONE, NULL, session_storage_namespace); | 252 profile_, NULL, MSG_ROUTING_NONE, NULL, session_storage_namespace); |
253 prerender_contents_.reset(new TabContentsWrapper(new_contents)); | 253 prerender_contents_.reset(new TabContentsWrapper(new_contents)); |
254 content::WebContentsObserver::Observe(new_contents); | 254 content::WebContentsObserver::Observe(new_contents); |
255 | 255 |
256 gfx::Rect tab_bounds = prerender_manager_->config().default_tab_bounds; | 256 gfx::Rect tab_bounds = prerender_manager_->config().default_tab_bounds; |
257 if (source_render_view_host) { | 257 if (source_render_view_host) { |
258 DCHECK(source_render_view_host->view() != NULL); | 258 DCHECK(source_render_view_host->GetView() != NULL); |
259 WebContents* source_wc = | 259 WebContents* source_wc = |
260 source_render_view_host->delegate()->GetAsWebContents(); | 260 source_render_view_host->GetDelegate()->GetAsWebContents(); |
261 if (source_wc) { | 261 if (source_wc) { |
262 // Set the size of the new TC to that of the old TC. | 262 // Set the size of the new TC to that of the old TC. |
263 source_wc->GetView()->GetContainerBounds(&tab_bounds); | 263 source_wc->GetView()->GetContainerBounds(&tab_bounds); |
264 } | 264 } |
265 } else { | 265 } else { |
266 // Try to get the active tab of the active browser and use that for tab | 266 // 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 | 267 // 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. | 268 // but we shouldn't be prerendering in that case anyway. |
269 Browser* active_browser = BrowserList::GetLastActiveWithProfile(profile_); | 269 Browser* active_browser = BrowserList::GetLastActiveWithProfile(profile_); |
270 if (active_browser) { | 270 if (active_browser) { |
271 WebContents* active_web_contents = active_browser->GetWebContentsAt( | 271 WebContents* active_web_contents = active_browser->GetWebContentsAt( |
272 active_browser->active_index()); | 272 active_browser->active_index()); |
273 if (active_web_contents) | 273 if (active_web_contents) |
274 active_web_contents->GetView()->GetContainerBounds(&tab_bounds); | 274 active_web_contents->GetView()->GetContainerBounds(&tab_bounds); |
275 } | 275 } |
276 } | 276 } |
277 | 277 |
278 tab_contents_delegate_.reset(new TabContentsDelegateImpl(this)); | 278 tab_contents_delegate_.reset(new TabContentsDelegateImpl(this)); |
279 new_contents->SetDelegate(tab_contents_delegate_.get()); | 279 new_contents->SetDelegate(tab_contents_delegate_.get()); |
280 | 280 |
281 // Set the size of the prerender TabContents. | 281 // Set the size of the prerender TabContents. |
282 prerender_contents_->web_contents()->GetView()->SizeContents( | 282 prerender_contents_->web_contents()->GetView()->SizeContents( |
283 tab_bounds.size()); | 283 tab_bounds.size()); |
284 | 284 |
285 // Register as an observer of the RenderViewHost so we get messages. | 285 // Register as an observer of the RenderViewHost so we get messages. |
286 render_view_host_observer_.reset( | 286 render_view_host_observer_.reset( |
287 new PrerenderRenderViewHostObserver(this, render_view_host_mutable())); | 287 new PrerenderRenderViewHostObserver(this, render_view_host_mutable())); |
288 | 288 |
289 child_id_ = render_view_host()->process()->GetID(); | 289 child_id_ = render_view_host()->GetProcess()->GetID(); |
290 route_id_ = render_view_host()->routing_id(); | 290 route_id_ = render_view_host()->GetRoutingID(); |
291 | 291 |
292 // Register this with the ResourceDispatcherHost as a prerender | 292 // Register this with the ResourceDispatcherHost as a prerender |
293 // RenderViewHost. This must be done before the Navigate message to catch all | 293 // RenderViewHost. This must be done before the Navigate message to catch all |
294 // resource requests, but as it is on the same thread as the Navigate message | 294 // resource requests, but as it is on the same thread as the Navigate message |
295 // (IO) there is no race condition. | 295 // (IO) there is no race condition. |
296 prerender_tracker_->OnPrerenderingStarted( | 296 prerender_tracker_->OnPrerenderingStarted( |
297 child_id_, | 297 child_id_, |
298 route_id_, | 298 route_id_, |
299 prerender_manager_); | 299 prerender_manager_); |
300 | 300 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 content::Details<RenderViewHost> new_render_view_host(details); | 413 content::Details<RenderViewHost> new_render_view_host(details); |
414 OnRenderViewHostCreated(new_render_view_host.ptr()); | 414 OnRenderViewHostCreated(new_render_view_host.ptr()); |
415 | 415 |
416 // When a new RenderView is created for a prerendering TabContents, | 416 // When a new RenderView is created for a prerendering TabContents, |
417 // tell the new RenderView it's being used for prerendering before any | 417 // tell the new RenderView it's being used for prerendering before any |
418 // navigations occur. Note that this is always triggered before the | 418 // navigations occur. Note that this is always triggered before the |
419 // first navigation, so there's no need to send the message just after | 419 // first navigation, so there's no need to send the message just after |
420 // the TabContents is created. | 420 // the TabContents is created. |
421 new_render_view_host->Send( | 421 new_render_view_host->Send( |
422 new ChromeViewMsg_SetIsPrerendering( | 422 new ChromeViewMsg_SetIsPrerendering( |
423 new_render_view_host->routing_id(), | 423 new_render_view_host->GetRoutingID(), |
424 true)); | 424 true)); |
425 | 425 |
426 // Make sure the size of the RenderViewHost has been passed to the new | 426 // Make sure the size of the RenderViewHost has been passed to the new |
427 // RenderView. Otherwise, the size may not be sent until the | 427 // RenderView. Otherwise, the size may not be sent until the |
428 // RenderViewReady event makes it from the render process to the UI | 428 // RenderViewReady event makes it from the render process to the UI |
429 // thread of the browser process. When the RenderView receives its | 429 // thread of the browser process. When the RenderView receives its |
430 // size, is also sets itself to be visible, which would then break the | 430 // size, is also sets itself to be visible, which would then break the |
431 // visibility API. | 431 // visibility API. |
432 new_render_view_host->WasResized(); | 432 new_render_view_host->WasResized(); |
433 prerender_contents_->web_contents()->HideContents(); | 433 prerender_contents_->web_contents()->HideContents(); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 // We may destroy the PrerenderContents before we have initialized the | 581 // We may destroy the PrerenderContents before we have initialized the |
582 // RenderViewHost. Otherwise set the Observer's PrerenderContents to NULL to | 582 // RenderViewHost. Otherwise set the Observer's PrerenderContents to NULL to |
583 // avoid any more messages being sent. | 583 // avoid any more messages being sent. |
584 if (render_view_host_observer_.get()) | 584 if (render_view_host_observer_.get()) |
585 render_view_host_observer_->set_prerender_contents(NULL); | 585 render_view_host_observer_->set_prerender_contents(NULL); |
586 } | 586 } |
587 | 587 |
588 base::ProcessMetrics* PrerenderContents::MaybeGetProcessMetrics() { | 588 base::ProcessMetrics* PrerenderContents::MaybeGetProcessMetrics() { |
589 if (process_metrics_.get() == NULL) { | 589 if (process_metrics_.get() == NULL) { |
590 // If a PrenderContents hasn't started prerending, don't be fully formed. | 590 // If a PrenderContents hasn't started prerending, don't be fully formed. |
591 if (!render_view_host() || !render_view_host()->process()) | 591 if (!render_view_host() || !render_view_host()->GetProcess()) |
592 return NULL; | 592 return NULL; |
593 base::ProcessHandle handle = render_view_host()->process()->GetHandle(); | 593 base::ProcessHandle handle = render_view_host()->GetProcess()->GetHandle(); |
594 if (handle == base::kNullProcessHandle) | 594 if (handle == base::kNullProcessHandle) |
595 return NULL; | 595 return NULL; |
596 #if !defined(OS_MACOSX) | 596 #if !defined(OS_MACOSX) |
597 process_metrics_.reset(base::ProcessMetrics::CreateProcessMetrics(handle)); | 597 process_metrics_.reset(base::ProcessMetrics::CreateProcessMetrics(handle)); |
598 #else | 598 #else |
599 process_metrics_.reset(base::ProcessMetrics::CreateProcessMetrics( | 599 process_metrics_.reset(base::ProcessMetrics::CreateProcessMetrics( |
600 handle, | 600 handle, |
601 MachBroker::GetInstance())); | 601 MachBroker::GetInstance())); |
602 #endif | 602 #endif |
603 } | 603 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 bool PrerenderContents::IsCrossSiteNavigationPending() const { | 659 bool PrerenderContents::IsCrossSiteNavigationPending() const { |
660 if (!prerender_contents_.get() || !prerender_contents_->web_contents()) | 660 if (!prerender_contents_.get() || !prerender_contents_->web_contents()) |
661 return false; | 661 return false; |
662 const WebContents* web_contents = prerender_contents_->web_contents(); | 662 const WebContents* web_contents = prerender_contents_->web_contents(); |
663 return (web_contents->GetSiteInstance() != | 663 return (web_contents->GetSiteInstance() != |
664 web_contents->GetPendingSiteInstance()); | 664 web_contents->GetPendingSiteInstance()); |
665 } | 665 } |
666 | 666 |
667 | 667 |
668 } // namespace prerender | 668 } // namespace prerender |
OLD | NEW |