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