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 13 matching lines...) Expand all Loading... | |
24 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 24 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
25 #include "chrome/common/extensions/extension_constants.h" | 25 #include "chrome/common/extensions/extension_constants.h" |
26 #include "chrome/common/extensions/extension_messages.h" | 26 #include "chrome/common/extensions/extension_messages.h" |
27 #include "chrome/common/icon_messages.h" | 27 #include "chrome/common/icon_messages.h" |
28 #include "chrome/common/render_messages.h" | 28 #include "chrome/common/render_messages.h" |
29 #include "chrome/common/url_constants.h" | 29 #include "chrome/common/url_constants.h" |
30 #include "content/browser/browsing_instance.h" | 30 #include "content/browser/browsing_instance.h" |
31 #include "content/browser/renderer_host/render_view_host.h" | 31 #include "content/browser/renderer_host/render_view_host.h" |
32 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 32 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
33 #include "content/browser/renderer_host/resource_request_details.h" | 33 #include "content/browser/renderer_host/resource_request_details.h" |
34 #include "content/browser/resource_context.h" | |
34 #include "content/browser/site_instance.h" | 35 #include "content/browser/site_instance.h" |
35 #include "content/browser/tab_contents/tab_contents_delegate.h" | 36 #include "content/browser/tab_contents/tab_contents_delegate.h" |
36 #include "content/browser/tab_contents/tab_contents_view.h" | 37 #include "content/browser/tab_contents/tab_contents_view.h" |
37 #include "content/common/notification_service.h" | 38 #include "content/common/notification_service.h" |
38 #include "content/common/view_messages.h" | 39 #include "content/common/view_messages.h" |
39 #include "ui/gfx/rect.h" | 40 #include "ui/gfx/rect.h" |
40 | 41 |
41 #if defined(OS_MACOSX) | 42 #if defined(OS_MACOSX) |
42 #include "chrome/browser/mach_broker_mac.h" | 43 #include "chrome/browser/mach_broker_mac.h" |
43 #endif | 44 #endif |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 PrerenderRenderWidgetHostView* view = | 180 PrerenderRenderWidgetHostView* view = |
180 new PrerenderRenderWidgetHostView(render_view_host_, this); | 181 new PrerenderRenderWidgetHostView(render_view_host_, this); |
181 view->Init(source_render_view_host->view()); | 182 view->Init(source_render_view_host->view()); |
182 | 183 |
183 child_id_ = render_view_host_->process()->id(); | 184 child_id_ = render_view_host_->process()->id(); |
184 route_id_ = render_view_host_->routing_id(); | 185 route_id_ = render_view_host_->routing_id(); |
185 | 186 |
186 // Register this with the PrerenderTracker as a prerendering RenderViewHost. | 187 // Register this with the PrerenderTracker as a prerendering RenderViewHost. |
187 // This must be done before the Navigate message to catch all resource | 188 // This must be done before the Navigate message to catch all resource |
188 // requests. | 189 // requests. |
189 PrerenderTracker::GetInstance()->OnPrerenderingStarted(child_id_, route_id_, | 190 g_browser_process->prerender_tracker()->OnPrerenderingStarted( |
cbentzel
2011/05/24 11:37:19
Would it make more sense to pass the PrerenderTrac
dominich
2011/05/24 15:10:28
I prefer to be explicit about where this is coming
cbentzel
2011/05/24 15:13:25
I wasn't worried about performance, just dislike r
jam
2011/05/24 16:06:24
I don't think this makes ownership murky. It's a
dominich
2011/05/24 16:54:21
Done.
| |
190 prerender_manager_); | 191 child_id_, |
192 route_id_, | |
193 prerender_manager_); | |
191 | 194 |
192 // Close ourselves when the application is shutting down. | 195 // Close ourselves when the application is shutting down. |
193 notification_registrar_.Add(this, NotificationType::APP_TERMINATING, | 196 notification_registrar_.Add(this, NotificationType::APP_TERMINATING, |
194 NotificationService::AllSources()); | 197 NotificationService::AllSources()); |
195 | 198 |
196 // Register for our parent profile to shutdown, so we can shut ourselves down | 199 // Register for our parent profile to shutdown, so we can shut ourselves down |
197 // as well (should only be called for OTR profiles, as we should receive | 200 // as well (should only be called for OTR profiles, as we should receive |
198 // APP_TERMINATING before non-OTR profiles are destroyed). | 201 // APP_TERMINATING before non-OTR profiles are destroyed). |
199 // TODO(tburkard): figure out if this is needed. | 202 // TODO(tburkard): figure out if this is needed. |
200 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, | 203 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
283 render_view_host_observer_.reset( | 286 render_view_host_observer_.reset( |
284 new PrerenderRenderViewHostObserver(this, render_view_host_mutable())); | 287 new PrerenderRenderViewHostObserver(this, render_view_host_mutable())); |
285 | 288 |
286 child_id_ = render_view_host()->process()->id(); | 289 child_id_ = render_view_host()->process()->id(); |
287 route_id_ = render_view_host()->routing_id(); | 290 route_id_ = render_view_host()->routing_id(); |
288 | 291 |
289 // Register this with the ResourceDispatcherHost as a prerender | 292 // Register this with the ResourceDispatcherHost as a prerender |
290 // 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 |
291 // 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 |
292 // (IO) there is no race condition. | 295 // (IO) there is no race condition. |
293 PrerenderTracker::GetInstance()->OnPrerenderingStarted(child_id_, route_id_, | 296 g_browser_process->prerender_tracker()->OnPrerenderingStarted( |
294 prerender_manager_); | 297 child_id_, |
298 route_id_, | |
299 prerender_manager_); | |
295 | 300 |
296 // Close ourselves when the application is shutting down. | 301 // Close ourselves when the application is shutting down. |
297 notification_registrar_.Add(this, NotificationType::APP_TERMINATING, | 302 notification_registrar_.Add(this, NotificationType::APP_TERMINATING, |
298 NotificationService::AllSources()); | 303 NotificationService::AllSources()); |
299 | 304 |
300 // Register for our parent profile to shutdown, so we can shut ourselves down | 305 // Register for our parent profile to shutdown, so we can shut ourselves down |
301 // as well (should only be called for OTR profiles, as we should receive | 306 // as well (should only be called for OTR profiles, as we should receive |
302 // APP_TERMINATING before non-OTR profiles are destroyed). | 307 // APP_TERMINATING before non-OTR profiles are destroyed). |
303 // TODO(tburkard): figure out if this is needed. | 308 // TODO(tburkard): figure out if this is needed. |
304 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, | 309 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
370 // If we haven't even started prerendering, we were just in the control | 375 // If we haven't even started prerendering, we were just in the control |
371 // group, which means we do not want to record the status. | 376 // group, which means we do not want to record the status. |
372 if (prerendering_has_started()) | 377 if (prerendering_has_started()) |
373 RecordFinalStatus(final_status_); | 378 RecordFinalStatus(final_status_); |
374 | 379 |
375 // Only delete the RenderViewHost if we own it. | 380 // Only delete the RenderViewHost if we own it. |
376 if (render_view_host_) | 381 if (render_view_host_) |
377 render_view_host_->Shutdown(); | 382 render_view_host_->Shutdown(); |
378 | 383 |
379 if (child_id_ != -1 && route_id_ != -1) { | 384 if (child_id_ != -1 && route_id_ != -1) { |
380 PrerenderTracker::GetInstance()->OnPrerenderingFinished( | 385 g_browser_process->prerender_tracker()->OnPrerenderingFinished( |
381 child_id_, route_id_); | 386 child_id_, route_id_); |
382 } | 387 } |
383 | 388 |
384 // If we still have a TabContents, clean up anything we need to and then | 389 // If we still have a TabContents, clean up anything we need to and then |
385 // destroy it. | 390 // destroy it. |
386 if (prerender_contents_.get()) | 391 if (prerender_contents_.get()) |
387 delete ReleasePrerenderContents(); | 392 delete ReleasePrerenderContents(); |
388 } | 393 } |
389 | 394 |
390 RenderViewHostDelegate::View* PrerenderContents::GetViewDelegate() { | 395 RenderViewHostDelegate::View* PrerenderContents::GetViewDelegate() { |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
713 | 718 |
714 void PrerenderContents::Destroy(FinalStatus final_status) { | 719 void PrerenderContents::Destroy(FinalStatus final_status) { |
715 if (prerender_manager_->IsPendingDelete(this)) | 720 if (prerender_manager_->IsPendingDelete(this)) |
716 return; | 721 return; |
717 | 722 |
718 if (child_id_ != -1 && route_id_ != -1) { | 723 if (child_id_ != -1 && route_id_ != -1) { |
719 // Cancel the prerender in the PrerenderTracker. This is needed | 724 // Cancel the prerender in the PrerenderTracker. This is needed |
720 // because destroy may be called directly from the UI thread without calling | 725 // because destroy may be called directly from the UI thread without calling |
721 // TryCancel(). This is difficult to completely avoid, since prerendering | 726 // TryCancel(). This is difficult to completely avoid, since prerendering |
722 // can be cancelled before a RenderView is created. | 727 // can be cancelled before a RenderView is created. |
723 bool is_cancelled = | 728 bool is_cancelled = g_browser_process->prerender_tracker()->TryCancel( |
724 PrerenderTracker::GetInstance()->TryCancel(child_id_, route_id_, | 729 child_id_, route_id_, final_status); |
725 final_status); | |
726 CHECK(is_cancelled); | 730 CHECK(is_cancelled); |
727 | 731 |
728 // A different final status may have been set already from another thread. | 732 // A different final status may have been set already from another thread. |
729 // If so, use it instead. | 733 // If so, use it instead. |
730 if (!PrerenderTracker::GetInstance()->GetFinalStatus(child_id_, route_id_, | 734 if (!g_browser_process->prerender_tracker()->GetFinalStatus( |
731 &final_status)) { | 735 child_id_, route_id_, &final_status)) { |
732 NOTREACHED(); | 736 NOTREACHED(); |
733 } | 737 } |
734 } | 738 } |
735 | 739 |
736 prerender_manager_->MoveEntryToPendingDelete(this); | 740 prerender_manager_->MoveEntryToPendingDelete(this); |
737 set_final_status(final_status); | 741 set_final_status(final_status); |
738 // We may destroy the PrerenderContents before we have initialized the | 742 // We may destroy the PrerenderContents before we have initialized the |
739 // RenderViewHost. Otherwise set the Observer's PrerenderContents to NULL to | 743 // RenderViewHost. Otherwise set the Observer's PrerenderContents to NULL to |
740 // avoid any more messages being sent. | 744 // avoid any more messages being sent. |
741 if (render_view_host_observer_.get()) | 745 if (render_view_host_observer_.get()) |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
825 } | 829 } |
826 return render_view_host_; | 830 return render_view_host_; |
827 } | 831 } |
828 | 832 |
829 void PrerenderContents::CommitHistory(TabContents* tc) { | 833 void PrerenderContents::CommitHistory(TabContents* tc) { |
830 if (tab_contents_delegate_.get()) | 834 if (tab_contents_delegate_.get()) |
831 tab_contents_delegate_->CommitHistory(tc); | 835 tab_contents_delegate_->CommitHistory(tc); |
832 } | 836 } |
833 | 837 |
834 } // namespace prerender | 838 } // namespace prerender |
OLD | NEW |