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