| 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> |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 #include "content/public/browser/notification_observer.h" | 45 #include "content/public/browser/notification_observer.h" |
| 46 #include "content/public/browser/notification_registrar.h" | 46 #include "content/public/browser/notification_registrar.h" |
| 47 #include "content/public/browser/notification_service.h" | 47 #include "content/public/browser/notification_service.h" |
| 48 #include "content/public/browser/notification_source.h" | 48 #include "content/public/browser/notification_source.h" |
| 49 #include "content/public/browser/notification_types.h" | 49 #include "content/public/browser/notification_types.h" |
| 50 #include "content/public/browser/web_contents_delegate.h" | 50 #include "content/public/browser/web_contents_delegate.h" |
| 51 #include "net/http/http_util.h" | 51 #include "net/http/http_util.h" |
| 52 #include "ui/base/l10n/l10n_util.h" | 52 #include "ui/base/l10n/l10n_util.h" |
| 53 #include "ui/gfx/codec/png_codec.h" | 53 #include "ui/gfx/codec/png_codec.h" |
| 54 | 54 |
| 55 using content::NavigationController; |
| 55 using content::NavigationEntry; | 56 using content::NavigationEntry; |
| 56 using content::WebContents; | 57 using content::WebContents; |
| 57 | 58 |
| 58 namespace { | 59 namespace { |
| 59 | 60 |
| 60 // Number of ms to delay before updating the omnibox bounds. This is only used | 61 // Number of ms to delay before updating the omnibox bounds. This is only used |
| 61 // when the bounds of the omnibox shrinks. If the bounds grows, we update | 62 // when the bounds of the omnibox shrinks. If the bounds grows, we update |
| 62 // immediately. | 63 // immediately. |
| 63 const int kUpdateBoundsDelayMS = 1000; | 64 const int kUpdateBoundsDelayMS = 1000; |
| 64 | 65 |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 : content::WebContentsObserver(loader->preview_contents()->web_contents()), | 290 : content::WebContentsObserver(loader->preview_contents()->web_contents()), |
| 290 loader_(loader), | 291 loader_(loader), |
| 291 registered_render_widget_host_(NULL), | 292 registered_render_widget_host_(NULL), |
| 292 waiting_for_new_page_(true), | 293 waiting_for_new_page_(true), |
| 293 is_mouse_down_from_activate_(false), | 294 is_mouse_down_from_activate_(false), |
| 294 user_typed_before_load_(false) { | 295 user_typed_before_load_(false) { |
| 295 DCHECK(loader->preview_contents()); | 296 DCHECK(loader->preview_contents()); |
| 296 registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED, | 297 registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED, |
| 297 content::Source<WebContents>(loader->preview_contents()->web_contents())); | 298 content::Source<WebContents>(loader->preview_contents()->web_contents())); |
| 298 registrar_.Add(this, content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR, | 299 registrar_.Add(this, content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR, |
| 299 content::Source<content::NavigationController>( | 300 content::Source<NavigationController>( |
| 300 &loader->preview_contents()->web_contents()->GetController())); | 301 &loader->preview_contents()->web_contents()->GetController())); |
| 301 } | 302 } |
| 302 | 303 |
| 303 void InstantLoader::TabContentsDelegateImpl::PrepareForNewLoad() { | 304 void InstantLoader::TabContentsDelegateImpl::PrepareForNewLoad() { |
| 304 user_typed_before_load_ = false; | 305 user_typed_before_load_ = false; |
| 305 waiting_for_new_page_ = true; | 306 waiting_for_new_page_ = true; |
| 306 add_page_vector_.clear(); | 307 add_page_vector_.clear(); |
| 307 UnregisterForPaintNotifications(); | 308 UnregisterForPaintNotifications(); |
| 308 } | 309 } |
| 309 | 310 |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 } | 773 } |
| 773 preview_tab_contents_delegate_->CommitHistory(template_url_id_ != 0); | 774 preview_tab_contents_delegate_->CommitHistory(template_url_id_ != 0); |
| 774 } | 775 } |
| 775 if (preview_contents_->web_contents()->GetRenderWidgetHostView()) { | 776 if (preview_contents_->web_contents()->GetRenderWidgetHostView()) { |
| 776 #if defined(OS_MACOSX) | 777 #if defined(OS_MACOSX) |
| 777 preview_contents_->web_contents()->GetRenderWidgetHostView()-> | 778 preview_contents_->web_contents()->GetRenderWidgetHostView()-> |
| 778 SetTakesFocusOnlyOnMouseDown(false); | 779 SetTakesFocusOnlyOnMouseDown(false); |
| 779 registrar_.Remove( | 780 registrar_.Remove( |
| 780 this, | 781 this, |
| 781 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | 782 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
| 782 content::Source<content::NavigationController>( | 783 content::Source<NavigationController>( |
| 783 &preview_contents_->web_contents()->GetController())); | 784 &preview_contents_->web_contents()->GetController())); |
| 784 #endif | 785 #endif |
| 785 } | 786 } |
| 786 preview_contents_->web_contents()->SetDelegate(NULL); | 787 preview_contents_->web_contents()->SetDelegate(NULL); |
| 787 ready_ = false; | 788 ready_ = false; |
| 788 } | 789 } |
| 789 update_bounds_timer_.Stop(); | 790 update_bounds_timer_.Stop(); |
| 790 AddPreviewUsageForHistogram(template_url_id_, | 791 AddPreviewUsageForHistogram(template_url_id_, |
| 791 type == INSTANT_COMMIT_DESTROY ? PREVIEW_DELETED : PREVIEW_COMMITTED); | 792 type == INSTANT_COMMIT_DESTROY ? PREVIEW_DELETED : PREVIEW_COMMITTED); |
| 792 return preview_contents_.release(); | 793 return preview_contents_.release(); |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 992 | 993 |
| 993 // Cleanup the old preview contents. | 994 // Cleanup the old preview contents. |
| 994 old_tc->constrained_window_tab_helper()->set_delegate(NULL); | 995 old_tc->constrained_window_tab_helper()->set_delegate(NULL); |
| 995 old_tc->core_tab_helper()->set_delegate(NULL); | 996 old_tc->core_tab_helper()->set_delegate(NULL); |
| 996 old_tc->web_contents()->SetDelegate(NULL); | 997 old_tc->web_contents()->SetDelegate(NULL); |
| 997 | 998 |
| 998 #if defined(OS_MACOSX) | 999 #if defined(OS_MACOSX) |
| 999 registrar_.Remove( | 1000 registrar_.Remove( |
| 1000 this, | 1001 this, |
| 1001 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | 1002 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
| 1002 content::Source<content::NavigationController>( | 1003 content::Source<NavigationController>( |
| 1003 &old_tc->web_contents()->GetController())); | 1004 &old_tc->web_contents()->GetController())); |
| 1004 #endif | 1005 #endif |
| 1005 registrar_.Remove( | 1006 registrar_.Remove( |
| 1006 this, | 1007 this, |
| 1007 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 1008 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 1008 content::Source<content::NavigationController>( | 1009 content::Source<NavigationController>( |
| 1009 &old_tc->web_contents()->GetController())); | 1010 &old_tc->web_contents()->GetController())); |
| 1010 | 1011 |
| 1011 // We prerendered so we should be ready to show. If we're ready, swap in | 1012 // We prerendered so we should be ready to show. If we're ready, swap in |
| 1012 // immediately, otherwise show the preview as normal. | 1013 // immediately, otherwise show the preview as normal. |
| 1013 if (ready_) | 1014 if (ready_) |
| 1014 delegate_->SwappedTabContents(this); | 1015 delegate_->SwappedTabContents(this); |
| 1015 else | 1016 else |
| 1016 ShowPreview(); | 1017 ShowPreview(); |
| 1017 } | 1018 } |
| 1018 | 1019 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1038 // If |preview_contents_| does not currently have a RWHV, we will call | 1039 // If |preview_contents_| does not currently have a RWHV, we will call |
| 1039 // SetTakesFocusOnlyOnMouseDown() as a result of the | 1040 // SetTakesFocusOnlyOnMouseDown() as a result of the |
| 1040 // RENDER_VIEW_HOST_CHANGED notification. | 1041 // RENDER_VIEW_HOST_CHANGED notification. |
| 1041 if (preview_contents_->web_contents()->GetRenderWidgetHostView()) { | 1042 if (preview_contents_->web_contents()->GetRenderWidgetHostView()) { |
| 1042 preview_contents_->web_contents()->GetRenderWidgetHostView()-> | 1043 preview_contents_->web_contents()->GetRenderWidgetHostView()-> |
| 1043 SetTakesFocusOnlyOnMouseDown(true); | 1044 SetTakesFocusOnlyOnMouseDown(true); |
| 1044 } | 1045 } |
| 1045 registrar_.Add( | 1046 registrar_.Add( |
| 1046 this, | 1047 this, |
| 1047 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | 1048 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
| 1048 content::Source<content::NavigationController>( | 1049 content::Source<NavigationController>( |
| 1049 &preview_contents_->web_contents()->GetController())); | 1050 &preview_contents_->web_contents()->GetController())); |
| 1050 #endif | 1051 #endif |
| 1051 | 1052 |
| 1052 registrar_.Add( | 1053 registrar_.Add( |
| 1053 this, | 1054 this, |
| 1054 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 1055 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 1055 content::Source<content::NavigationController>( | 1056 content::Source<NavigationController>( |
| 1056 &preview_contents_->web_contents()->GetController())); | 1057 &preview_contents_->web_contents()->GetController())); |
| 1057 | 1058 |
| 1058 gfx::Rect tab_bounds; | 1059 gfx::Rect tab_bounds; |
| 1059 tab_contents->web_contents()->GetView()->GetContainerBounds(&tab_bounds); | 1060 tab_contents->web_contents()->GetView()->GetContainerBounds(&tab_bounds); |
| 1060 preview_contents_->web_contents()->GetView()->SizeContents(tab_bounds.size()); | 1061 preview_contents_->web_contents()->GetView()->SizeContents(tab_bounds.size()); |
| 1061 } | 1062 } |
| 1062 | 1063 |
| 1063 void InstantLoader::CreatePreviewContents(TabContentsWrapper* tab_contents) { | 1064 void InstantLoader::CreatePreviewContents(TabContentsWrapper* tab_contents) { |
| 1064 TabContents* new_contents = | 1065 TabContents* new_contents = |
| 1065 new TabContents( | 1066 new TabContents( |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1107 host->Send(new ChromeViewMsg_SearchBoxResize( | 1108 host->Send(new ChromeViewMsg_SearchBoxResize( |
| 1108 host->routing_id(), GetOmniboxBoundsInTermsOfPreview())); | 1109 host->routing_id(), GetOmniboxBoundsInTermsOfPreview())); |
| 1109 } else { | 1110 } else { |
| 1110 host->Send(new ChromeViewMsg_SearchBoxChange( | 1111 host->Send(new ChromeViewMsg_SearchBoxChange( |
| 1111 host->routing_id(), user_text, verbatim, 0, 0)); | 1112 host->routing_id(), user_text, verbatim, 0, 0)); |
| 1112 } | 1113 } |
| 1113 | 1114 |
| 1114 frame_load_observer_.reset(new FrameLoadObserver( | 1115 frame_load_observer_.reset(new FrameLoadObserver( |
| 1115 this, preview_contents()->web_contents(), user_text, verbatim)); | 1116 this, preview_contents()->web_contents(), user_text, verbatim)); |
| 1116 } | 1117 } |
| OLD | NEW |