| 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/instant/instant_loader.h" | 5 #include "chrome/browser/instant/instant_loader.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/i18n/case_conversion.h" | 13 #include "base/i18n/case_conversion.h" |
| 14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
| 15 #include "base/timer.h" | 15 #include "base/timer.h" |
| 16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "chrome/browser/favicon/favicon_service.h" | 18 #include "chrome/browser/favicon/favicon_service.h" |
| 19 #include "chrome/browser/history/history_marshaling.h" | 19 #include "chrome/browser/history/history_marshaling.h" |
| 20 #include "chrome/browser/history/history_tab_helper.h" | 20 #include "chrome/browser/history/history_tab_helper.h" |
| 21 #include "chrome/browser/instant/instant_loader_delegate.h" | 21 #include "chrome/browser/instant/instant_loader_delegate.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/search_engines/template_url.h" | 23 #include "chrome/browser/search_engines/template_url.h" |
| 24 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" | 24 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" |
| 25 #include "chrome/browser/ui/download/download_tab_helper.h" | 25 #include "chrome/browser/ui/download/download_tab_helper.h" |
| 26 #include "chrome/browser/ui/download/download_tab_helper_delegate.h" | 26 #include "chrome/browser/ui/download/download_tab_helper_delegate.h" |
| 27 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 27 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 28 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h" | 28 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h" |
| 29 #include "chrome/common/chrome_notification_types.h" |
| 29 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
| 30 #include "chrome/common/render_messages.h" | 31 #include "chrome/common/render_messages.h" |
| 31 #include "content/browser/renderer_host/render_view_host.h" | 32 #include "content/browser/renderer_host/render_view_host.h" |
| 32 #include "content/browser/renderer_host/render_widget_host.h" | 33 #include "content/browser/renderer_host/render_widget_host.h" |
| 33 #include "content/browser/renderer_host/render_widget_host_view.h" | 34 #include "content/browser/renderer_host/render_widget_host_view.h" |
| 34 #include "content/browser/tab_contents/navigation_details.h" | 35 #include "content/browser/tab_contents/navigation_details.h" |
| 35 #include "content/browser/tab_contents/navigation_entry.h" | 36 #include "content/browser/tab_contents/navigation_entry.h" |
| 36 #include "content/browser/tab_contents/provisional_load_details.h" | 37 #include "content/browser/tab_contents/provisional_load_details.h" |
| 37 #include "content/browser/tab_contents/tab_contents.h" | 38 #include "content/browser/tab_contents/tab_contents.h" |
| 38 #include "content/browser/tab_contents/tab_contents_delegate.h" | 39 #include "content/browser/tab_contents/tab_contents_delegate.h" |
| 39 #include "content/browser/tab_contents/tab_contents_view.h" | 40 #include "content/browser/tab_contents/tab_contents_view.h" |
| 41 #include "content/common/content_notification_types.h" |
| 40 #include "content/common/notification_details.h" | 42 #include "content/common/notification_details.h" |
| 41 #include "content/common/notification_observer.h" | 43 #include "content/common/notification_observer.h" |
| 42 #include "content/common/notification_registrar.h" | 44 #include "content/common/notification_registrar.h" |
| 43 #include "content/common/notification_service.h" | 45 #include "content/common/notification_service.h" |
| 44 #include "content/common/notification_source.h" | 46 #include "content/common/notification_source.h" |
| 45 #include "content/common/notification_type.h" | |
| 46 #include "content/common/page_transition_types.h" | 47 #include "content/common/page_transition_types.h" |
| 47 #include "content/common/renderer_preferences.h" | 48 #include "content/common/renderer_preferences.h" |
| 48 #include "net/http/http_util.h" | 49 #include "net/http/http_util.h" |
| 49 #include "ui/base/l10n/l10n_util.h" | 50 #include "ui/base/l10n/l10n_util.h" |
| 50 #include "ui/gfx/codec/png_codec.h" | 51 #include "ui/gfx/codec/png_codec.h" |
| 51 | 52 |
| 52 namespace { | 53 namespace { |
| 53 | 54 |
| 54 // Number of ms to delay before updating the omnibox bounds. This is only used | 55 // Number of ms to delay before updating the omnibox bounds. This is only used |
| 55 // when the bounds of the omnibox shrinks. If the bounds grows, we update | 56 // when the bounds of the omnibox shrinks. If the bounds grows, we update |
| (...skipping 15 matching lines...) Expand all Loading... |
| 71 public: | 72 public: |
| 72 FrameLoadObserver(InstantLoader* loader, | 73 FrameLoadObserver(InstantLoader* loader, |
| 73 TabContents* tab_contents, | 74 TabContents* tab_contents, |
| 74 const string16& text, | 75 const string16& text, |
| 75 bool verbatim) | 76 bool verbatim) |
| 76 : loader_(loader), | 77 : loader_(loader), |
| 77 tab_contents_(tab_contents), | 78 tab_contents_(tab_contents), |
| 78 text_(text), | 79 text_(text), |
| 79 verbatim_(verbatim), | 80 verbatim_(verbatim), |
| 80 unique_id_(tab_contents_->controller().pending_entry()->unique_id()) { | 81 unique_id_(tab_contents_->controller().pending_entry()->unique_id()) { |
| 81 registrar_.Add(this, NotificationType::LOAD_COMPLETED_MAIN_FRAME, | 82 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 82 Source<TabContents>(tab_contents_)); | 83 Source<TabContents>(tab_contents_)); |
| 83 } | 84 } |
| 84 | 85 |
| 85 // Sets the text to send to the page. | 86 // Sets the text to send to the page. |
| 86 void set_text(const string16& text) { text_ = text; } | 87 void set_text(const string16& text) { text_ = text; } |
| 87 | 88 |
| 88 // Sets whether verbatim results are obtained rather than predictive. | 89 // Sets whether verbatim results are obtained rather than predictive. |
| 89 void set_verbatim(bool verbatim) { verbatim_ = verbatim; } | 90 void set_verbatim(bool verbatim) { verbatim_ = verbatim; } |
| 90 | 91 |
| 91 // NotificationObserver: | 92 // NotificationObserver: |
| 92 virtual void Observe(NotificationType type, | 93 virtual void Observe(int type, |
| 93 const NotificationSource& source, | 94 const NotificationSource& source, |
| 94 const NotificationDetails& details) OVERRIDE; | 95 const NotificationDetails& details) OVERRIDE; |
| 95 | 96 |
| 96 private: | 97 private: |
| 97 InstantLoader* loader_; | 98 InstantLoader* loader_; |
| 98 | 99 |
| 99 // The TabContents we're listening for changes on. | 100 // The TabContents we're listening for changes on. |
| 100 TabContents* tab_contents_; | 101 TabContents* tab_contents_; |
| 101 | 102 |
| 102 // Text to send down to the page. | 103 // Text to send down to the page. |
| 103 string16 text_; | 104 string16 text_; |
| 104 | 105 |
| 105 // Whether verbatim results are obtained. | 106 // Whether verbatim results are obtained. |
| 106 bool verbatim_; | 107 bool verbatim_; |
| 107 | 108 |
| 108 // unique_id of the NavigationEntry we're waiting on. | 109 // unique_id of the NavigationEntry we're waiting on. |
| 109 const int unique_id_; | 110 const int unique_id_; |
| 110 | 111 |
| 111 // Registers and unregisters us for notifications. | 112 // Registers and unregisters us for notifications. |
| 112 NotificationRegistrar registrar_; | 113 NotificationRegistrar registrar_; |
| 113 | 114 |
| 114 DISALLOW_COPY_AND_ASSIGN(FrameLoadObserver); | 115 DISALLOW_COPY_AND_ASSIGN(FrameLoadObserver); |
| 115 }; | 116 }; |
| 116 | 117 |
| 117 void InstantLoader::FrameLoadObserver::Observe( | 118 void InstantLoader::FrameLoadObserver::Observe( |
| 118 NotificationType type, | 119 int type, |
| 119 const NotificationSource& source, | 120 const NotificationSource& source, |
| 120 const NotificationDetails& details) { | 121 const NotificationDetails& details) { |
| 121 switch (type.value) { | 122 switch (type) { |
| 122 case NotificationType::LOAD_COMPLETED_MAIN_FRAME: { | 123 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: { |
| 123 int page_id = *(Details<int>(details).ptr()); | 124 int page_id = *(Details<int>(details).ptr()); |
| 124 NavigationEntry* active_entry = | 125 NavigationEntry* active_entry = |
| 125 tab_contents_->controller().GetActiveEntry(); | 126 tab_contents_->controller().GetActiveEntry(); |
| 126 if (!active_entry || active_entry->page_id() != page_id || | 127 if (!active_entry || active_entry->page_id() != page_id || |
| 127 active_entry->unique_id() != unique_id_) { | 128 active_entry->unique_id() != unique_id_) { |
| 128 return; | 129 return; |
| 129 } | 130 } |
| 130 loader_->SendBoundsToPage(true); | 131 loader_->SendBoundsToPage(true); |
| 131 // TODO: support real cursor position. | 132 // TODO: support real cursor position. |
| 132 int text_length = static_cast<int>(text_.size()); | 133 int text_length = static_cast<int>(text_.size()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 void SetLastHistoryURLAndPrune(const GURL& url); | 170 void SetLastHistoryURLAndPrune(const GURL& url); |
| 170 | 171 |
| 171 // Commits the currently buffered history. | 172 // Commits the currently buffered history. |
| 172 void CommitHistory(bool supports_instant); | 173 void CommitHistory(bool supports_instant); |
| 173 | 174 |
| 174 void RegisterForPaintNotifications(RenderWidgetHost* render_widget_host); | 175 void RegisterForPaintNotifications(RenderWidgetHost* render_widget_host); |
| 175 | 176 |
| 176 void UnregisterForPaintNotifications(); | 177 void UnregisterForPaintNotifications(); |
| 177 | 178 |
| 178 // NotificationObserver: | 179 // NotificationObserver: |
| 179 virtual void Observe(NotificationType type, | 180 virtual void Observe(int type, |
| 180 const NotificationSource& source, | 181 const NotificationSource& source, |
| 181 const NotificationDetails& details) OVERRIDE; | 182 const NotificationDetails& details) OVERRIDE; |
| 182 | 183 |
| 183 // TabContentsDelegate: | 184 // TabContentsDelegate: |
| 184 virtual void NavigationStateChanged(const TabContents* source, | 185 virtual void NavigationStateChanged(const TabContents* source, |
| 185 unsigned changed_flags) OVERRIDE; | 186 unsigned changed_flags) OVERRIDE; |
| 186 virtual std::string GetNavigationHeaders(const GURL& url) OVERRIDE; | 187 virtual std::string GetNavigationHeaders(const GURL& url) OVERRIDE; |
| 187 virtual bool ShouldFocusConstrainedWindow() OVERRIDE; | 188 virtual bool ShouldFocusConstrainedWindow() OVERRIDE; |
| 188 virtual void WillShowConstrainedWindow(TabContents* source) OVERRIDE; | 189 virtual void WillShowConstrainedWindow(TabContents* source) OVERRIDE; |
| 189 virtual bool ShouldSuppressDialogs() OVERRIDE; | 190 virtual bool ShouldSuppressDialogs() OVERRIDE; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 | 262 |
| 262 InstantLoader::TabContentsDelegateImpl::TabContentsDelegateImpl( | 263 InstantLoader::TabContentsDelegateImpl::TabContentsDelegateImpl( |
| 263 InstantLoader* loader) | 264 InstantLoader* loader) |
| 264 : TabContentsObserver(loader->preview_contents()->tab_contents()), | 265 : TabContentsObserver(loader->preview_contents()->tab_contents()), |
| 265 loader_(loader), | 266 loader_(loader), |
| 266 registered_render_widget_host_(NULL), | 267 registered_render_widget_host_(NULL), |
| 267 waiting_for_new_page_(true), | 268 waiting_for_new_page_(true), |
| 268 is_mouse_down_from_activate_(false), | 269 is_mouse_down_from_activate_(false), |
| 269 user_typed_before_load_(false) { | 270 user_typed_before_load_(false) { |
| 270 DCHECK(loader->preview_contents()); | 271 DCHECK(loader->preview_contents()); |
| 271 registrar_.Add(this, NotificationType::INTERSTITIAL_ATTACHED, | 272 registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED, |
| 272 Source<TabContents>(loader->preview_contents()->tab_contents())); | 273 Source<TabContents>(loader->preview_contents()->tab_contents())); |
| 273 registrar_.Add(this, NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR, | 274 registrar_.Add(this, content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR, |
| 274 Source<NavigationController>(&loader->preview_contents()->controller())); | 275 Source<NavigationController>(&loader->preview_contents()->controller())); |
| 275 } | 276 } |
| 276 | 277 |
| 277 void InstantLoader::TabContentsDelegateImpl::PrepareForNewLoad() { | 278 void InstantLoader::TabContentsDelegateImpl::PrepareForNewLoad() { |
| 278 user_typed_before_load_ = false; | 279 user_typed_before_load_ = false; |
| 279 waiting_for_new_page_ = true; | 280 waiting_for_new_page_ = true; |
| 280 add_page_vector_.clear(); | 281 add_page_vector_.clear(); |
| 281 UnregisterForPaintNotifications(); | 282 UnregisterForPaintNotifications(); |
| 282 } | 283 } |
| 283 | 284 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 } | 348 } |
| 348 } | 349 } |
| 349 } | 350 } |
| 350 | 351 |
| 351 void InstantLoader::TabContentsDelegateImpl::RegisterForPaintNotifications( | 352 void InstantLoader::TabContentsDelegateImpl::RegisterForPaintNotifications( |
| 352 RenderWidgetHost* render_widget_host) { | 353 RenderWidgetHost* render_widget_host) { |
| 353 DCHECK(registered_render_widget_host_ == NULL); | 354 DCHECK(registered_render_widget_host_ == NULL); |
| 354 registered_render_widget_host_ = render_widget_host; | 355 registered_render_widget_host_ = render_widget_host; |
| 355 Source<RenderWidgetHost> source = | 356 Source<RenderWidgetHost> source = |
| 356 Source<RenderWidgetHost>(registered_render_widget_host_); | 357 Source<RenderWidgetHost>(registered_render_widget_host_); |
| 357 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DID_PAINT, | 358 registrar_.Add(this, content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT, |
| 358 source); | 359 source); |
| 359 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED, | 360 registrar_.Add(this, content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
| 360 source); | 361 source); |
| 361 } | 362 } |
| 362 | 363 |
| 363 void InstantLoader::TabContentsDelegateImpl::UnregisterForPaintNotifications() { | 364 void InstantLoader::TabContentsDelegateImpl::UnregisterForPaintNotifications() { |
| 364 if (registered_render_widget_host_) { | 365 if (registered_render_widget_host_) { |
| 365 Source<RenderWidgetHost> source = | 366 Source<RenderWidgetHost> source = |
| 366 Source<RenderWidgetHost>(registered_render_widget_host_); | 367 Source<RenderWidgetHost>(registered_render_widget_host_); |
| 367 registrar_.Remove(this, NotificationType::RENDER_WIDGET_HOST_DID_PAINT, | 368 registrar_.Remove(this, content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT, |
| 368 source); | 369 source); |
| 369 registrar_.Remove(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED, | 370 registrar_.Remove(this, content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
| 370 source); | 371 source); |
| 371 registered_render_widget_host_ = NULL; | 372 registered_render_widget_host_ = NULL; |
| 372 } | 373 } |
| 373 } | 374 } |
| 374 | 375 |
| 375 void InstantLoader::TabContentsDelegateImpl::Observe( | 376 void InstantLoader::TabContentsDelegateImpl::Observe( |
| 376 NotificationType type, | 377 int type, |
| 377 const NotificationSource& source, | 378 const NotificationSource& source, |
| 378 const NotificationDetails& details) { | 379 const NotificationDetails& details) { |
| 379 switch (type.value) { | 380 switch (type) { |
| 380 case NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR: | 381 case content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR: |
| 381 if (Details<ProvisionalLoadDetails>(details)->url() == loader_->url_) { | 382 if (Details<ProvisionalLoadDetails>(details)->url() == loader_->url_) { |
| 382 // This typically happens with downloads (which are disabled with | 383 // This typically happens with downloads (which are disabled with |
| 383 // instant active). To ensure the download happens when the user presses | 384 // instant active). To ensure the download happens when the user presses |
| 384 // enter we set needs_reload_ to true, which triggers a reload. | 385 // enter we set needs_reload_ to true, which triggers a reload. |
| 385 loader_->needs_reload_ = true; | 386 loader_->needs_reload_ = true; |
| 386 } | 387 } |
| 387 break; | 388 break; |
| 388 case NotificationType::RENDER_WIDGET_HOST_DID_PAINT: | 389 case content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT: |
| 389 UnregisterForPaintNotifications(); | 390 UnregisterForPaintNotifications(); |
| 390 PreviewPainted(); | 391 PreviewPainted(); |
| 391 break; | 392 break; |
| 392 case NotificationType::RENDER_WIDGET_HOST_DESTROYED: | 393 case content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: |
| 393 UnregisterForPaintNotifications(); | 394 UnregisterForPaintNotifications(); |
| 394 break; | 395 break; |
| 395 case NotificationType::INTERSTITIAL_ATTACHED: | 396 case content::NOTIFICATION_INTERSTITIAL_ATTACHED: |
| 396 PreviewPainted(); | 397 PreviewPainted(); |
| 397 break; | 398 break; |
| 398 default: | 399 default: |
| 399 NOTREACHED() << "Got a notification we didn't register for."; | 400 NOTREACHED() << "Got a notification we didn't register for."; |
| 400 } | 401 } |
| 401 } | 402 } |
| 402 | 403 |
| 403 void InstantLoader::TabContentsDelegateImpl::NavigationStateChanged( | 404 void InstantLoader::TabContentsDelegateImpl::NavigationStateChanged( |
| 404 const TabContents* source, | 405 const TabContents* source, |
| 405 unsigned changed_flags) { | 406 unsigned changed_flags) { |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 void InstantLoader::TabContentsDelegateImpl::OnInstantSupportDetermined( | 545 void InstantLoader::TabContentsDelegateImpl::OnInstantSupportDetermined( |
| 545 int32 page_id, | 546 int32 page_id, |
| 546 bool result) { | 547 bool result) { |
| 547 TabContents* source = loader_->preview_contents()->tab_contents(); | 548 TabContents* source = loader_->preview_contents()->tab_contents(); |
| 548 if (!source->controller().GetActiveEntry() || | 549 if (!source->controller().GetActiveEntry() || |
| 549 page_id != source->controller().GetActiveEntry()->page_id()) | 550 page_id != source->controller().GetActiveEntry()->page_id()) |
| 550 return; | 551 return; |
| 551 | 552 |
| 552 Details<const bool> details(&result); | 553 Details<const bool> details(&result); |
| 553 NotificationService::current()->Notify( | 554 NotificationService::current()->Notify( |
| 554 NotificationType::INSTANT_SUPPORT_DETERMINED, | 555 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, |
| 555 NotificationService::AllSources(), | 556 NotificationService::AllSources(), |
| 556 details); | 557 details); |
| 557 | 558 |
| 558 if (result) | 559 if (result) |
| 559 loader_->PageFinishedLoading(); | 560 loader_->PageFinishedLoading(); |
| 560 else | 561 else |
| 561 loader_->PageDoesntSupportInstant(user_typed_before_load_); | 562 loader_->PageDoesntSupportInstant(user_typed_before_load_); |
| 562 } | 563 } |
| 563 | 564 |
| 564 void InstantLoader::TabContentsDelegateImpl | 565 void InstantLoader::TabContentsDelegateImpl |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 preview_tab_contents_delegate_->SetLastHistoryURLAndPrune(url); | 741 preview_tab_contents_delegate_->SetLastHistoryURLAndPrune(url); |
| 741 } | 742 } |
| 742 preview_tab_contents_delegate_->CommitHistory(template_url_id_ != 0); | 743 preview_tab_contents_delegate_->CommitHistory(template_url_id_ != 0); |
| 743 } | 744 } |
| 744 if (preview_contents_->tab_contents()->GetRenderWidgetHostView()) { | 745 if (preview_contents_->tab_contents()->GetRenderWidgetHostView()) { |
| 745 #if defined(OS_MACOSX) | 746 #if defined(OS_MACOSX) |
| 746 preview_contents_->tab_contents()->GetRenderWidgetHostView()-> | 747 preview_contents_->tab_contents()->GetRenderWidgetHostView()-> |
| 747 SetTakesFocusOnlyOnMouseDown(false); | 748 SetTakesFocusOnlyOnMouseDown(false); |
| 748 registrar_.Remove( | 749 registrar_.Remove( |
| 749 this, | 750 this, |
| 750 NotificationType::RENDER_VIEW_HOST_CHANGED, | 751 chrome::RENDER_VIEW_HOST_CHANGED, |
| 751 Source<NavigationController>(&preview_contents_->controller())); | 752 Source<NavigationController>(&preview_contents_->controller())); |
| 752 #endif | 753 #endif |
| 753 } | 754 } |
| 754 preview_contents_->tab_contents()->set_delegate(NULL); | 755 preview_contents_->tab_contents()->set_delegate(NULL); |
| 755 preview_contents_->download_tab_helper()->set_delegate(NULL); | 756 preview_contents_->download_tab_helper()->set_delegate(NULL); |
| 756 ready_ = false; | 757 ready_ = false; |
| 757 } | 758 } |
| 758 update_bounds_timer_.Stop(); | 759 update_bounds_timer_.Stop(); |
| 759 return preview_contents_.release(); | 760 return preview_contents_.release(); |
| 760 } | 761 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 delegate_->InstantStatusChanged(this); | 847 delegate_->InstantStatusChanged(this); |
| 847 } | 848 } |
| 848 | 849 |
| 849 void InstantLoader::ShowPreview() { | 850 void InstantLoader::ShowPreview() { |
| 850 if (!ready_) { | 851 if (!ready_) { |
| 851 ready_ = true; | 852 ready_ = true; |
| 852 delegate_->InstantStatusChanged(this); | 853 delegate_->InstantStatusChanged(this); |
| 853 } | 854 } |
| 854 } | 855 } |
| 855 | 856 |
| 856 void InstantLoader::Observe(NotificationType type, | 857 void InstantLoader::Observe(int type, |
| 857 const NotificationSource& source, | 858 const NotificationSource& source, |
| 858 const NotificationDetails& details) { | 859 const NotificationDetails& details) { |
| 859 #if defined(OS_MACOSX) | 860 #if defined(OS_MACOSX) |
| 860 if (type.value == NotificationType::RENDER_VIEW_HOST_CHANGED) { | 861 if (type == chrome::RENDER_VIEW_HOST_CHANGED) { |
| 861 if (preview_contents_->tab_contents()->GetRenderWidgetHostView()) { | 862 if (preview_contents_->tab_contents()->GetRenderWidgetHostView()) { |
| 862 preview_contents_->tab_contents()->GetRenderWidgetHostView()-> | 863 preview_contents_->tab_contents()->GetRenderWidgetHostView()-> |
| 863 SetTakesFocusOnlyOnMouseDown(true); | 864 SetTakesFocusOnlyOnMouseDown(true); |
| 864 } | 865 } |
| 865 return; | 866 return; |
| 866 } | 867 } |
| 867 #endif | 868 #endif |
| 868 if (type.value == NotificationType::NAV_ENTRY_COMMITTED) { | 869 if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) { |
| 869 content::LoadCommittedDetails* load_details = | 870 content::LoadCommittedDetails* load_details = |
| 870 Details<content::LoadCommittedDetails>(details).ptr(); | 871 Details<content::LoadCommittedDetails>(details).ptr(); |
| 871 if (load_details->is_main_frame) { | 872 if (load_details->is_main_frame) { |
| 872 if (load_details->http_status_code == kHostBlacklistStatusCode) { | 873 if (load_details->http_status_code == kHostBlacklistStatusCode) { |
| 873 delegate_->AddToBlacklist(this, load_details->entry->url()); | 874 delegate_->AddToBlacklist(this, load_details->entry->url()); |
| 874 } else { | 875 } else { |
| 875 SetHTTPStatusOK(load_details->http_status_code == 200); | 876 SetHTTPStatusOK(load_details->http_status_code == 200); |
| 876 } | 877 } |
| 877 } | 878 } |
| 878 return; | 879 return; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 947 // Make sure the new preview contents acts like the old one. | 948 // Make sure the new preview contents acts like the old one. |
| 948 SetupPreviewContents(old_tc); | 949 SetupPreviewContents(old_tc); |
| 949 | 950 |
| 950 // Cleanup the old preview contents. | 951 // Cleanup the old preview contents. |
| 951 old_tc->download_tab_helper()->set_delegate(NULL); | 952 old_tc->download_tab_helper()->set_delegate(NULL); |
| 952 old_tc->tab_contents()->set_delegate(NULL); | 953 old_tc->tab_contents()->set_delegate(NULL); |
| 953 old_tc->set_delegate(NULL); | 954 old_tc->set_delegate(NULL); |
| 954 | 955 |
| 955 #if defined(OS_MACOSX) | 956 #if defined(OS_MACOSX) |
| 956 registrar_.Remove(this, | 957 registrar_.Remove(this, |
| 957 NotificationType::RENDER_VIEW_HOST_CHANGED, | 958 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
| 958 Source<NavigationController>(&old_tc->controller())); | 959 Source<NavigationController>(&old_tc->controller())); |
| 959 #endif | 960 #endif |
| 960 registrar_.Remove(this, | 961 registrar_.Remove(this, |
| 961 NotificationType::NAV_ENTRY_COMMITTED, | 962 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 962 Source<NavigationController>(&old_tc->controller())); | 963 Source<NavigationController>(&old_tc->controller())); |
| 963 | 964 |
| 964 // We prerendered so we should be ready to show. If we're ready, swap in | 965 // We prerendered so we should be ready to show. If we're ready, swap in |
| 965 // immediately, otherwise show the preview as normal. | 966 // immediately, otherwise show the preview as normal. |
| 966 if (ready_) | 967 if (ready_) |
| 967 delegate_->SwappedTabContents(this); | 968 delegate_->SwappedTabContents(this); |
| 968 else | 969 else |
| 969 ShowPreview(); | 970 ShowPreview(); |
| 970 } | 971 } |
| 971 | 972 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 988 #if defined(OS_MACOSX) | 989 #if defined(OS_MACOSX) |
| 989 // If |preview_contents_| does not currently have a RWHV, we will call | 990 // If |preview_contents_| does not currently have a RWHV, we will call |
| 990 // SetTakesFocusOnlyOnMouseDown() as a result of the | 991 // SetTakesFocusOnlyOnMouseDown() as a result of the |
| 991 // RENDER_VIEW_HOST_CHANGED notification. | 992 // RENDER_VIEW_HOST_CHANGED notification. |
| 992 if (preview_contents_->tab_contents()->GetRenderWidgetHostView()) { | 993 if (preview_contents_->tab_contents()->GetRenderWidgetHostView()) { |
| 993 preview_contents_->tab_contents()->GetRenderWidgetHostView()-> | 994 preview_contents_->tab_contents()->GetRenderWidgetHostView()-> |
| 994 SetTakesFocusOnlyOnMouseDown(true); | 995 SetTakesFocusOnlyOnMouseDown(true); |
| 995 } | 996 } |
| 996 registrar_.Add( | 997 registrar_.Add( |
| 997 this, | 998 this, |
| 998 NotificationType::RENDER_VIEW_HOST_CHANGED, | 999 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
| 999 Source<NavigationController>(&preview_contents_->controller())); | 1000 Source<NavigationController>(&preview_contents_->controller())); |
| 1000 #endif | 1001 #endif |
| 1001 | 1002 |
| 1002 registrar_.Add( | 1003 registrar_.Add( |
| 1003 this, | 1004 this, |
| 1004 NotificationType::NAV_ENTRY_COMMITTED, | 1005 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 1005 Source<NavigationController>(&preview_contents_->controller())); | 1006 Source<NavigationController>(&preview_contents_->controller())); |
| 1006 | 1007 |
| 1007 gfx::Rect tab_bounds; | 1008 gfx::Rect tab_bounds; |
| 1008 tab_contents->view()->GetContainerBounds(&tab_bounds); | 1009 tab_contents->view()->GetContainerBounds(&tab_bounds); |
| 1009 preview_contents_->view()->SizeContents(tab_bounds.size()); | 1010 preview_contents_->view()->SizeContents(tab_bounds.size()); |
| 1010 } | 1011 } |
| 1011 | 1012 |
| 1012 void InstantLoader::CreatePreviewContents(TabContentsWrapper* tab_contents) { | 1013 void InstantLoader::CreatePreviewContents(TabContentsWrapper* tab_contents) { |
| 1013 TabContents* new_contents = | 1014 TabContents* new_contents = |
| 1014 new TabContents( | 1015 new TabContents( |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1040 CommandLine* cl = CommandLine::ForCurrentProcess(); | 1041 CommandLine* cl = CommandLine::ForCurrentProcess(); |
| 1041 if (cl->HasSwitch(switches::kInstantURL)) | 1042 if (cl->HasSwitch(switches::kInstantURL)) |
| 1042 instant_url = GURL(cl->GetSwitchValueASCII(switches::kInstantURL)); | 1043 instant_url = GURL(cl->GetSwitchValueASCII(switches::kInstantURL)); |
| 1043 preview_contents_->controller().LoadURL(instant_url, GURL(), transition_type); | 1044 preview_contents_->controller().LoadURL(instant_url, GURL(), transition_type); |
| 1044 RenderViewHost* host = preview_contents_->render_view_host(); | 1045 RenderViewHost* host = preview_contents_->render_view_host(); |
| 1045 host->Send(new ViewMsg_SearchBoxChange( | 1046 host->Send(new ViewMsg_SearchBoxChange( |
| 1046 host->routing_id(), user_text, verbatim, 0, 0)); | 1047 host->routing_id(), user_text, verbatim, 0, 0)); |
| 1047 frame_load_observer_.reset(new FrameLoadObserver( | 1048 frame_load_observer_.reset(new FrameLoadObserver( |
| 1048 this, preview_contents()->tab_contents(), user_text, verbatim)); | 1049 this, preview_contents()->tab_contents(), user_text, verbatim)); |
| 1049 } | 1050 } |
| OLD | NEW |