| 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" |
| 11 #include "base/task.h" | 11 #include "base/task.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/history/history_tab_helper.h" | 13 #include "chrome/browser/history/history_tab_helper.h" |
| 14 #include "chrome/browser/history/history_types.h" | 14 #include "chrome/browser/history/history_types.h" |
| 15 #include "chrome/browser/prerender/prerender_final_status.h" | 15 #include "chrome/browser/prerender/prerender_final_status.h" |
| 16 #include "chrome/browser/prerender/prerender_manager.h" | 16 #include "chrome/browser/prerender/prerender_manager.h" |
| 17 #include "chrome/browser/prerender/prerender_render_view_host_observer.h" | 17 #include "chrome/browser/prerender/prerender_render_view_host_observer.h" |
| 18 #include "chrome/browser/prerender/prerender_tracker.h" | 18 #include "chrome/browser/prerender/prerender_tracker.h" |
| 19 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 20 #include "chrome/browser/ui/browser_list.h" | 20 #include "chrome/browser/ui/browser_list.h" |
| 21 #include "chrome/browser/ui/download/download_tab_helper.h" | 21 #include "chrome/browser/ui/download/download_tab_helper.h" |
| 22 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 22 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 23 #include "chrome/common/chrome_notification_types.h" |
| 23 #include "chrome/common/icon_messages.h" | 24 #include "chrome/common/icon_messages.h" |
| 24 #include "chrome/common/render_messages.h" | 25 #include "chrome/common/render_messages.h" |
| 25 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
| 26 #include "content/browser/renderer_host/render_view_host.h" | 27 #include "content/browser/renderer_host/render_view_host.h" |
| 27 #include "content/browser/renderer_host/resource_request_details.h" | 28 #include "content/browser/renderer_host/resource_request_details.h" |
| 28 #include "content/browser/tab_contents/tab_contents_delegate.h" | 29 #include "content/browser/tab_contents/tab_contents_delegate.h" |
| 29 #include "content/browser/tab_contents/tab_contents_view.h" | 30 #include "content/browser/tab_contents/tab_contents_view.h" |
| 30 #include "content/common/notification_service.h" | 31 #include "content/common/notification_service.h" |
| 31 #include "content/common/view_messages.h" | 32 #include "content/common/view_messages.h" |
| 32 #include "ui/gfx/rect.h" | 33 #include "ui/gfx/rect.h" |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 prerender_manager_); | 223 prerender_manager_); |
| 223 | 224 |
| 224 // Close ourselves when the application is shutting down. | 225 // Close ourselves when the application is shutting down. |
| 225 notification_registrar_.Add(this, NotificationType::APP_TERMINATING, | 226 notification_registrar_.Add(this, NotificationType::APP_TERMINATING, |
| 226 NotificationService::AllSources()); | 227 NotificationService::AllSources()); |
| 227 | 228 |
| 228 // Register for our parent profile to shutdown, so we can shut ourselves down | 229 // Register for our parent profile to shutdown, so we can shut ourselves down |
| 229 // as well (should only be called for OTR profiles, as we should receive | 230 // as well (should only be called for OTR profiles, as we should receive |
| 230 // APP_TERMINATING before non-OTR profiles are destroyed). | 231 // APP_TERMINATING before non-OTR profiles are destroyed). |
| 231 // TODO(tburkard): figure out if this is needed. | 232 // TODO(tburkard): figure out if this is needed. |
| 232 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, | 233 notification_registrar_.Add(this, chrome::PROFILE_DESTROYED, |
| 233 Source<Profile>(profile_)); | 234 Source<Profile>(profile_)); |
| 234 | 235 |
| 235 // Register to inform new RenderViews that we're prerendering. | 236 // Register to inform new RenderViews that we're prerendering. |
| 236 notification_registrar_.Add( | 237 notification_registrar_.Add( |
| 237 this, NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB, | 238 this, NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB, |
| 238 Source<TabContents>(new_contents)); | 239 Source<TabContents>(new_contents)); |
| 239 | 240 |
| 240 // Register to be told when the RenderView is ready, so we can hide it. | 241 // Register to be told when the RenderView is ready, so we can hide it. |
| 241 // It will automatically be set to visible when we resize it, otherwise. | 242 // It will automatically be set to visible when we resize it, otherwise. |
| 242 notification_registrar_.Add(this, NotificationType::TAB_CONTENTS_CONNECTED, | 243 notification_registrar_.Add(this, NotificationType::TAB_CONTENTS_CONNECTED, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 delete ReleasePrerenderContents(); | 309 delete ReleasePrerenderContents(); |
| 309 | 310 |
| 310 // The following URLs are no longer rendering. | 311 // The following URLs are no longer rendering. |
| 311 prerender_tracker_->RemovePrerenderURLsOnUIThread(alias_urls_); | 312 prerender_tracker_->RemovePrerenderURLsOnUIThread(alias_urls_); |
| 312 } | 313 } |
| 313 | 314 |
| 314 void PrerenderContents::Observe(NotificationType type, | 315 void PrerenderContents::Observe(NotificationType type, |
| 315 const NotificationSource& source, | 316 const NotificationSource& source, |
| 316 const NotificationDetails& details) { | 317 const NotificationDetails& details) { |
| 317 switch (type.value) { | 318 switch (type.value) { |
| 318 case NotificationType::PROFILE_DESTROYED: | 319 case chrome::PROFILE_DESTROYED: |
| 319 Destroy(FINAL_STATUS_PROFILE_DESTROYED); | 320 Destroy(FINAL_STATUS_PROFILE_DESTROYED); |
| 320 return; | 321 return; |
| 321 | 322 |
| 322 case NotificationType::APP_TERMINATING: | 323 case NotificationType::APP_TERMINATING: |
| 323 Destroy(FINAL_STATUS_APP_TERMINATING); | 324 Destroy(FINAL_STATUS_APP_TERMINATING); |
| 324 return; | 325 return; |
| 325 | 326 |
| 326 case NotificationType::RESOURCE_RECEIVED_REDIRECT: { | 327 case NotificationType::RESOURCE_RECEIVED_REDIRECT: { |
| 327 // RESOURCE_RECEIVED_REDIRECT can come for any resource on a page. | 328 // RESOURCE_RECEIVED_REDIRECT can come for any resource on a page. |
| 328 // If it's a redirect on the top-level resource, the name needs | 329 // If it's a redirect on the top-level resource, the name needs |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 return NULL; | 594 return NULL; |
| 594 DictionaryValue* dict_value = new DictionaryValue(); | 595 DictionaryValue* dict_value = new DictionaryValue(); |
| 595 dict_value->SetString("url", prerender_url_.spec()); | 596 dict_value->SetString("url", prerender_url_.spec()); |
| 596 base::TimeTicks current_time = base::TimeTicks::Now(); | 597 base::TimeTicks current_time = base::TimeTicks::Now(); |
| 597 base::TimeDelta duration = current_time - load_start_time_; | 598 base::TimeDelta duration = current_time - load_start_time_; |
| 598 dict_value->SetInteger("duration", duration.InSeconds()); | 599 dict_value->SetInteger("duration", duration.InSeconds()); |
| 599 return dict_value; | 600 return dict_value; |
| 600 } | 601 } |
| 601 | 602 |
| 602 } // namespace prerender | 603 } // namespace prerender |
| OLD | NEW |