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 17 matching lines...) Expand all Loading... | |
61 url.query() == url_.query(); | 62 url.query() == url_.query(); |
62 } | 63 } |
63 GURL url_; | 64 GURL url_; |
64 }; | 65 }; |
65 | 66 |
66 } // end namespace | 67 } // end namespace |
67 | 68 |
68 class PrerenderContentsFactoryImpl : public PrerenderContents::Factory { | 69 class PrerenderContentsFactoryImpl : public PrerenderContents::Factory { |
69 public: | 70 public: |
70 virtual PrerenderContents* CreatePrerenderContents( | 71 virtual PrerenderContents* CreatePrerenderContents( |
71 PrerenderManager* prerender_manager, Profile* profile, const GURL& url, | 72 PrerenderManager* prerender_manager, Profile* profile, |
73 PrerenderTracker* prerender_tracker, | |
74 const GURL& url, | |
72 const GURL& referrer) OVERRIDE { | 75 const GURL& referrer) OVERRIDE { |
73 return new PrerenderContents(prerender_manager, profile, url, referrer); | 76 return new PrerenderContents(prerender_manager, profile, prerender_tracker, |
77 url, referrer); | |
74 } | 78 } |
75 }; | 79 }; |
76 | 80 |
77 // TabContentsDelegateImpl ----------------------------------------------------- | 81 // TabContentsDelegateImpl ----------------------------------------------------- |
78 | 82 |
79 class PrerenderContents::TabContentsDelegateImpl | 83 class PrerenderContents::TabContentsDelegateImpl |
80 : public TabContentsDelegate { | 84 : public TabContentsDelegate { |
81 public: | 85 public: |
82 explicit TabContentsDelegateImpl(PrerenderContents* prerender_contents) : | 86 explicit TabContentsDelegateImpl(PrerenderContents* prerender_contents) : |
83 prerender_contents_(prerender_contents) { | 87 prerender_contents_(prerender_contents) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 AddPageVector; | 122 AddPageVector; |
119 | 123 |
120 // Caches pages to be added to the history. | 124 // Caches pages to be added to the history. |
121 AddPageVector add_page_vector_; | 125 AddPageVector add_page_vector_; |
122 | 126 |
123 PrerenderContents* prerender_contents_; | 127 PrerenderContents* prerender_contents_; |
124 }; | 128 }; |
125 | 129 |
126 PrerenderContents::PrerenderContents(PrerenderManager* prerender_manager, | 130 PrerenderContents::PrerenderContents(PrerenderManager* prerender_manager, |
127 Profile* profile, | 131 Profile* profile, |
132 PrerenderTracker* prerender_tracker, | |
128 const GURL& url, | 133 const GURL& url, |
129 const GURL& referrer) | 134 const GURL& referrer) |
130 : prerender_manager_(prerender_manager), | 135 : prerender_manager_(prerender_manager), |
131 render_view_host_(NULL), | 136 render_view_host_(NULL), |
132 prerender_url_(url), | 137 prerender_url_(url), |
133 referrer_(referrer), | 138 referrer_(referrer), |
134 profile_(profile), | 139 profile_(profile), |
140 prerender_tracker_(prerender_tracker), | |
135 page_id_(0), | 141 page_id_(0), |
136 ALLOW_THIS_IN_INITIALIZER_LIST(tab_contents_observer_registrar_(this)), | 142 ALLOW_THIS_IN_INITIALIZER_LIST(tab_contents_observer_registrar_(this)), |
137 has_stopped_loading_(false), | 143 has_stopped_loading_(false), |
138 final_status_(FINAL_STATUS_MAX), | 144 final_status_(FINAL_STATUS_MAX), |
139 prerendering_has_started_(false), | 145 prerendering_has_started_(false), |
140 prerendering_has_been_cancelled_(false), | 146 prerendering_has_been_cancelled_(false), |
141 child_id_(-1), | 147 child_id_(-1), |
142 route_id_(-1), | 148 route_id_(-1), |
143 starting_page_id_(-1) { | 149 starting_page_id_(-1) { |
144 DCHECK(prerender_manager != NULL); | 150 DCHECK(prerender_manager != NULL); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 PrerenderRenderWidgetHostView* view = | 186 PrerenderRenderWidgetHostView* view = |
181 new PrerenderRenderWidgetHostView(render_view_host_, this); | 187 new PrerenderRenderWidgetHostView(render_view_host_, this); |
182 view->Init(source_render_view_host->view()); | 188 view->Init(source_render_view_host->view()); |
183 | 189 |
184 child_id_ = render_view_host_->process()->id(); | 190 child_id_ = render_view_host_->process()->id(); |
185 route_id_ = render_view_host_->routing_id(); | 191 route_id_ = render_view_host_->routing_id(); |
186 | 192 |
187 // Register this with the PrerenderTracker as a prerendering RenderViewHost. | 193 // Register this with the PrerenderTracker as a prerendering RenderViewHost. |
188 // This must be done before the Navigate message to catch all resource | 194 // This must be done before the Navigate message to catch all resource |
189 // requests. | 195 // requests. |
190 PrerenderTracker::GetInstance()->OnPrerenderingStarted(child_id_, route_id_, | 196 prerender_tracker_->OnPrerenderingStarted( |
191 prerender_manager_); | 197 child_id_, |
198 route_id_, | |
199 prerender_manager_); | |
192 | 200 |
193 // Close ourselves when the application is shutting down. | 201 // Close ourselves when the application is shutting down. |
194 notification_registrar_.Add(this, NotificationType::APP_TERMINATING, | 202 notification_registrar_.Add(this, NotificationType::APP_TERMINATING, |
195 NotificationService::AllSources()); | 203 NotificationService::AllSources()); |
196 | 204 |
197 // Register for our parent profile to shutdown, so we can shut ourselves down | 205 // Register for our parent profile to shutdown, so we can shut ourselves down |
198 // as well (should only be called for OTR profiles, as we should receive | 206 // as well (should only be called for OTR profiles, as we should receive |
199 // APP_TERMINATING before non-OTR profiles are destroyed). | 207 // APP_TERMINATING before non-OTR profiles are destroyed). |
200 // TODO(tburkard): figure out if this is needed. | 208 // TODO(tburkard): figure out if this is needed. |
201 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, | 209 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
284 render_view_host_observer_.reset( | 292 render_view_host_observer_.reset( |
285 new PrerenderRenderViewHostObserver(this, render_view_host_mutable())); | 293 new PrerenderRenderViewHostObserver(this, render_view_host_mutable())); |
286 | 294 |
287 child_id_ = render_view_host()->process()->id(); | 295 child_id_ = render_view_host()->process()->id(); |
288 route_id_ = render_view_host()->routing_id(); | 296 route_id_ = render_view_host()->routing_id(); |
289 | 297 |
290 // Register this with the ResourceDispatcherHost as a prerender | 298 // Register this with the ResourceDispatcherHost as a prerender |
291 // RenderViewHost. This must be done before the Navigate message to catch all | 299 // RenderViewHost. This must be done before the Navigate message to catch all |
292 // resource requests, but as it is on the same thread as the Navigate message | 300 // resource requests, but as it is on the same thread as the Navigate message |
293 // (IO) there is no race condition. | 301 // (IO) there is no race condition. |
294 PrerenderTracker::GetInstance()->OnPrerenderingStarted(child_id_, route_id_, | 302 prerender_tracker_->OnPrerenderingStarted( |
295 prerender_manager_); | 303 child_id_, |
304 route_id_, | |
305 prerender_manager_); | |
296 | 306 |
297 // Close ourselves when the application is shutting down. | 307 // Close ourselves when the application is shutting down. |
298 notification_registrar_.Add(this, NotificationType::APP_TERMINATING, | 308 notification_registrar_.Add(this, NotificationType::APP_TERMINATING, |
299 NotificationService::AllSources()); | 309 NotificationService::AllSources()); |
300 | 310 |
301 // Register for our parent profile to shutdown, so we can shut ourselves down | 311 // Register for our parent profile to shutdown, so we can shut ourselves down |
302 // as well (should only be called for OTR profiles, as we should receive | 312 // as well (should only be called for OTR profiles, as we should receive |
303 // APP_TERMINATING before non-OTR profiles are destroyed). | 313 // APP_TERMINATING before non-OTR profiles are destroyed). |
304 // TODO(tburkard): figure out if this is needed. | 314 // TODO(tburkard): figure out if this is needed. |
305 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, | 315 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
374 // If we haven't even started prerendering, we were just in the control | 384 // If we haven't even started prerendering, we were just in the control |
375 // group, which means we do not want to record the status. | 385 // group, which means we do not want to record the status. |
376 if (prerendering_has_started()) | 386 if (prerendering_has_started()) |
377 RecordFinalStatus(final_status_); | 387 RecordFinalStatus(final_status_); |
378 | 388 |
379 // Only delete the RenderViewHost if we own it. | 389 // Only delete the RenderViewHost if we own it. |
380 if (render_view_host_) | 390 if (render_view_host_) |
381 render_view_host_->Shutdown(); | 391 render_view_host_->Shutdown(); |
382 | 392 |
383 if (child_id_ != -1 && route_id_ != -1) { | 393 if (child_id_ != -1 && route_id_ != -1) { |
384 PrerenderTracker::GetInstance()->OnPrerenderingFinished( | 394 prerender_tracker_->OnPrerenderingFinished( |
mmenke
2011/05/24 17:56:22
nit: This now fits on a single line.
dominich
2011/05/24 18:01:47
Done.
| |
385 child_id_, route_id_); | 395 child_id_, route_id_); |
386 } | 396 } |
387 | 397 |
388 // If we still have a TabContents, clean up anything we need to and then | 398 // If we still have a TabContents, clean up anything we need to and then |
389 // destroy it. | 399 // destroy it. |
390 if (prerender_contents_.get()) | 400 if (prerender_contents_.get()) |
391 delete ReleasePrerenderContents(); | 401 delete ReleasePrerenderContents(); |
392 } | 402 } |
393 | 403 |
394 RenderViewHostDelegate::View* PrerenderContents::GetViewDelegate() { | 404 RenderViewHostDelegate::View* PrerenderContents::GetViewDelegate() { |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
720 return; | 730 return; |
721 | 731 |
722 prerendering_has_been_cancelled_ = true; | 732 prerendering_has_been_cancelled_ = true; |
723 prerender_manager_->MoveEntryToPendingDelete(this); | 733 prerender_manager_->MoveEntryToPendingDelete(this); |
724 | 734 |
725 if (child_id_ != -1 && route_id_ != -1) { | 735 if (child_id_ != -1 && route_id_ != -1) { |
726 // Cancel the prerender in the PrerenderTracker. This is needed | 736 // Cancel the prerender in the PrerenderTracker. This is needed |
727 // because destroy may be called directly from the UI thread without calling | 737 // because destroy may be called directly from the UI thread without calling |
728 // TryCancel(). This is difficult to completely avoid, since prerendering | 738 // TryCancel(). This is difficult to completely avoid, since prerendering |
729 // can be cancelled before a RenderView is created. | 739 // can be cancelled before a RenderView is created. |
730 bool is_cancelled = | 740 bool is_cancelled = prerender_tracker_->TryCancel( |
731 PrerenderTracker::GetInstance()->TryCancel(child_id_, route_id_, | 741 child_id_, route_id_, final_status); |
732 final_status); | |
733 CHECK(is_cancelled); | 742 CHECK(is_cancelled); |
734 | 743 |
735 // A different final status may have been set already from another thread. | 744 // A different final status may have been set already from another thread. |
736 // If so, use it instead. | 745 // If so, use it instead. |
737 if (!PrerenderTracker::GetInstance()->GetFinalStatus(child_id_, route_id_, | 746 if (!prerender_tracker_->GetFinalStatus(child_id_, route_id_, |
738 &final_status)) { | 747 &final_status)) { |
739 NOTREACHED(); | 748 NOTREACHED(); |
740 } | 749 } |
741 } | 750 } |
742 set_final_status(final_status); | 751 set_final_status(final_status); |
743 | 752 |
744 // We may destroy the PrerenderContents before we have initialized the | 753 // We may destroy the PrerenderContents before we have initialized the |
745 // RenderViewHost. Otherwise set the Observer's PrerenderContents to NULL to | 754 // RenderViewHost. Otherwise set the Observer's PrerenderContents to NULL to |
746 // avoid any more messages being sent. | 755 // avoid any more messages being sent. |
747 if (render_view_host_observer_.get()) | 756 if (render_view_host_observer_.get()) |
748 render_view_host_observer_->set_prerender_contents(NULL); | 757 render_view_host_observer_->set_prerender_contents(NULL); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
831 } | 840 } |
832 return render_view_host_; | 841 return render_view_host_; |
833 } | 842 } |
834 | 843 |
835 void PrerenderContents::CommitHistory(TabContents* tc) { | 844 void PrerenderContents::CommitHistory(TabContents* tc) { |
836 if (tab_contents_delegate_.get()) | 845 if (tab_contents_delegate_.get()) |
837 tab_contents_delegate_->CommitHistory(tc); | 846 tab_contents_delegate_->CommitHistory(tc); |
838 } | 847 } |
839 | 848 |
840 } // namespace prerender | 849 } // namespace prerender |
OLD | NEW |