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 17 matching lines...) Expand all Loading... | |
28 #include "chrome/common/render_messages.h" | 28 #include "chrome/common/render_messages.h" |
29 #include "content/browser/renderer_host/render_view_host.h" | 29 #include "content/browser/renderer_host/render_view_host.h" |
30 #include "content/browser/renderer_host/render_widget_host.h" | 30 #include "content/browser/renderer_host/render_widget_host.h" |
31 #include "content/browser/renderer_host/render_widget_host_view.h" | 31 #include "content/browser/renderer_host/render_widget_host_view.h" |
32 #include "content/browser/tab_contents/navigation_controller.h" | 32 #include "content/browser/tab_contents/navigation_controller.h" |
33 #include "content/browser/tab_contents/navigation_entry.h" | 33 #include "content/browser/tab_contents/navigation_entry.h" |
34 #include "content/browser/tab_contents/provisional_load_details.h" | 34 #include "content/browser/tab_contents/provisional_load_details.h" |
35 #include "content/browser/tab_contents/tab_contents.h" | 35 #include "content/browser/tab_contents/tab_contents.h" |
36 #include "content/browser/tab_contents/tab_contents_delegate.h" | 36 #include "content/browser/tab_contents/tab_contents_delegate.h" |
37 #include "content/browser/tab_contents/tab_contents_view.h" | 37 #include "content/browser/tab_contents/tab_contents_view.h" |
38 #include "content/common/content_constants.h" | |
38 #include "content/common/notification_details.h" | 39 #include "content/common/notification_details.h" |
39 #include "content/common/notification_observer.h" | 40 #include "content/common/notification_observer.h" |
40 #include "content/common/notification_registrar.h" | 41 #include "content/common/notification_registrar.h" |
41 #include "content/common/notification_service.h" | 42 #include "content/common/notification_service.h" |
42 #include "content/common/notification_source.h" | 43 #include "content/common/notification_source.h" |
43 #include "content/common/notification_type.h" | 44 #include "content/common/notification_type.h" |
44 #include "content/common/page_transition_types.h" | 45 #include "content/common/page_transition_types.h" |
45 #include "content/common/renderer_preferences.h" | 46 #include "content/common/renderer_preferences.h" |
46 #include "net/http/http_util.h" | 47 #include "net/http/http_util.h" |
47 #include "ui/base/l10n/l10n_util.h" | 48 #include "ui/base/l10n/l10n_util.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
136 default: | 137 default: |
137 NOTREACHED(); | 138 NOTREACHED(); |
138 break; | 139 break; |
139 } | 140 } |
140 } | 141 } |
141 | 142 |
142 // TabContentsDelegateImpl ----------------------------------------------------- | 143 // TabContentsDelegateImpl ----------------------------------------------------- |
143 | 144 |
144 class InstantLoader::TabContentsDelegateImpl | 145 class InstantLoader::TabContentsDelegateImpl |
145 : public TabContentsDelegate, | 146 : public TabContentsDelegate, |
147 public TabContentsWrapperDelegate, | |
146 public NotificationObserver, | 148 public NotificationObserver, |
147 public TabContentsObserver, | 149 public TabContentsObserver, |
148 public DownloadTabHelperDelegate { | 150 public DownloadTabHelperDelegate { |
149 public: | 151 public: |
150 explicit TabContentsDelegateImpl(InstantLoader* loader); | 152 explicit TabContentsDelegateImpl(InstantLoader* loader); |
151 | 153 |
152 // Invoked prior to loading a new URL. | 154 // Invoked prior to loading a new URL. |
153 void PrepareForNewLoad(); | 155 void PrepareForNewLoad(); |
154 | 156 |
155 // Invoked when the preview paints. Invokes PreviewPainted on the loader. | 157 // Invoked when the preview paints. Invokes PreviewPainted on the loader. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
212 // move around. | 214 // move around. |
213 virtual void DragEnded() OVERRIDE; | 215 virtual void DragEnded() OVERRIDE; |
214 virtual void HandleMouseUp() OVERRIDE; | 216 virtual void HandleMouseUp() OVERRIDE; |
215 virtual void HandleMouseActivate() OVERRIDE; | 217 virtual void HandleMouseActivate() OVERRIDE; |
216 virtual bool OnGoToEntryOffset(int offset) OVERRIDE; | 218 virtual bool OnGoToEntryOffset(int offset) OVERRIDE; |
217 virtual bool ShouldAddNavigationToHistory( | 219 virtual bool ShouldAddNavigationToHistory( |
218 const history::HistoryAddPageArgs& add_page_args, | 220 const history::HistoryAddPageArgs& add_page_args, |
219 NavigationType::Type navigation_type) OVERRIDE; | 221 NavigationType::Type navigation_type) OVERRIDE; |
220 virtual bool ShouldShowHungRendererDialog() OVERRIDE; | 222 virtual bool ShouldShowHungRendererDialog() OVERRIDE; |
221 | 223 |
224 // TabContentsWrapperDelegate: | |
225 virtual void SwapTabContents(TabContentsWrapper* old_tc, | |
226 TabContentsWrapper* new_tc) OVERRIDE; | |
227 | |
222 // TabContentsObserver: | 228 // TabContentsObserver: |
223 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 229 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
224 | 230 |
225 // DownloadTabHelperDelegate: | 231 // DownloadTabHelperDelegate: |
226 virtual bool CanDownload(int request_id) OVERRIDE; | 232 virtual bool CanDownload(int request_id) OVERRIDE; |
227 virtual void OnStartDownload(DownloadItem* download, | 233 virtual void OnStartDownload(DownloadItem* download, |
228 TabContentsWrapper* tab) OVERRIDE; | 234 TabContentsWrapper* tab) OVERRIDE; |
229 | 235 |
230 private: | 236 private: |
231 typedef std::vector<scoped_refptr<history::HistoryAddPageArgs> > | 237 typedef std::vector<scoped_refptr<history::HistoryAddPageArgs> > |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
543 return false; | 549 return false; |
544 } | 550 } |
545 | 551 |
546 bool InstantLoader::TabContentsDelegateImpl::ShouldShowHungRendererDialog() { | 552 bool InstantLoader::TabContentsDelegateImpl::ShouldShowHungRendererDialog() { |
547 // If we allow the hung renderer dialog to be shown it'll gain focus, | 553 // If we allow the hung renderer dialog to be shown it'll gain focus, |
548 // stealing focus from the omnibox causing instant to be cancelled. Return | 554 // stealing focus from the omnibox causing instant to be cancelled. Return |
549 // false so that doesn't happen. | 555 // false so that doesn't happen. |
550 return false; | 556 return false; |
551 } | 557 } |
552 | 558 |
559 // If this is being called, something is swapping in to our preview_contents_ | |
560 // before we've added it to the tab strip. | |
561 void InstantLoader::TabContentsDelegateImpl::SwapTabContents( | |
562 TabContentsWrapper* old_tc, | |
563 TabContentsWrapper* new_tc) { | |
564 loader_->ReplacePreviewContents(old_tc, new_tc); | |
565 } | |
566 | |
567 | |
553 bool InstantLoader::TabContentsDelegateImpl::OnMessageReceived( | 568 bool InstantLoader::TabContentsDelegateImpl::OnMessageReceived( |
554 const IPC::Message& message) { | 569 const IPC::Message& message) { |
555 bool handled = true; | 570 bool handled = true; |
556 IPC_BEGIN_MESSAGE_MAP(TabContentsDelegateImpl, message) | 571 IPC_BEGIN_MESSAGE_MAP(TabContentsDelegateImpl, message) |
557 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSuggestions, OnSetSuggestions) | 572 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSuggestions, OnSetSuggestions) |
558 IPC_MESSAGE_HANDLER(ViewHostMsg_InstantSupportDetermined, | 573 IPC_MESSAGE_HANDLER(ViewHostMsg_InstantSupportDetermined, |
559 OnInstantSupportDetermined) | 574 OnInstantSupportDetermined) |
560 IPC_MESSAGE_UNHANDLED(handled = false) | 575 IPC_MESSAGE_UNHANDLED(handled = false) |
561 IPC_END_MESSAGE_MAP() | 576 IPC_END_MESSAGE_MAP() |
562 return handled; | 577 return handled; |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
984 | 999 |
985 if (preview_contents_.get() && is_showing_instant() && | 1000 if (preview_contents_.get() && is_showing_instant() && |
986 (force_if_waiting || !is_waiting_for_load())) { | 1001 (force_if_waiting || !is_waiting_for_load())) { |
987 last_omnibox_bounds_ = omnibox_bounds_; | 1002 last_omnibox_bounds_ = omnibox_bounds_; |
988 RenderViewHost* host = preview_contents_->render_view_host(); | 1003 RenderViewHost* host = preview_contents_->render_view_host(); |
989 host->Send(new ViewMsg_SearchBoxResize( | 1004 host->Send(new ViewMsg_SearchBoxResize( |
990 host->routing_id(), GetOmniboxBoundsInTermsOfPreview())); | 1005 host->routing_id(), GetOmniboxBoundsInTermsOfPreview())); |
991 } | 1006 } |
992 } | 1007 } |
993 | 1008 |
994 void InstantLoader::CreatePreviewContents(TabContentsWrapper* tab_contents) { | 1009 void InstantLoader::ReplacePreviewContents(TabContentsWrapper* old_tc, |
995 TabContents* new_contents = | 1010 TabContentsWrapper* new_tc) { |
996 new TabContents( | 1011 DCHECK(old_tc == preview_contents_); |
997 tab_contents->profile(), NULL, MSG_ROUTING_NONE, NULL, NULL); | 1012 // We release here without deleting so that the caller still has reponsibility |
998 preview_contents_.reset(new TabContentsWrapper(new_contents)); | 1013 // for deleting the TabContentsWrapper. |
1014 ignore_result(preview_contents_.release()); | |
1015 preview_contents_.reset(new_tc); | |
1016 | |
1017 // Make sure the new preview contents acts like the old one. | |
1018 SetupPreviewContents(old_tc); | |
1019 | |
1020 // Cleanup the old preview contents. | |
1021 old_tc->download_tab_helper()->set_delegate(NULL); | |
sky
2011/05/20 18:54:19
Why do you need to reset the download_tab_helper d
dominich
2011/05/20 23:22:34
It's set to the preview_tab_contents_delegate_ and
sky
2011/05/20 23:38:33
I see it. Sorry.
| |
1022 old_tc->tab_contents()->set_delegate(NULL); | |
1023 old_tc->set_delegate(NULL); | |
1024 | |
1025 #if defined(OS_MACOSX) | |
1026 registrar_.Remove(this, | |
1027 NotificationType::RENDER_VIEW_HOST_CHANGED, | |
1028 Source<NavigationController>(&old_tc->controller())); | |
1029 #endif | |
1030 registrar_.Remove(this, | |
1031 NotificationType::NAV_ENTRY_COMMITTED, | |
1032 Source<NavigationController>(&old_tc->controller())); | |
1033 | |
1034 // We prerendered so we should be ready to show. | |
1035 ShowPreview(); | |
sky
2011/05/20 18:54:19
If the tabcontents was already showing then the Sh
sky
2011/05/20 19:45:09
To deal with this you'll likely want to add a new
dominich
2011/05/20 23:22:34
When would this happen though? If we're swapping i
sky
2011/05/20 23:38:33
Is that always the case? Lets say foo.com is prere
| |
1036 } | |
1037 | |
1038 void InstantLoader::SetupPreviewContents(TabContentsWrapper* tab_contents) { | |
1039 preview_contents_->set_delegate(preview_tab_contents_delegate_.get()); | |
1040 preview_contents_->tab_contents()->set_delegate( | |
1041 preview_tab_contents_delegate_.get()); | |
999 preview_contents_->blocked_content_tab_helper()->SetAllContentsBlocked(true); | 1042 preview_contents_->blocked_content_tab_helper()->SetAllContentsBlocked(true); |
1000 // Propagate the max page id. That way if we end up merging the two | |
1001 // NavigationControllers (which happens if we commit) none of the page ids | |
1002 // will overlap. | |
1003 int32 max_page_id = tab_contents->tab_contents()->GetMaxPageID(); | |
1004 if (max_page_id != -1) | |
1005 preview_contents_->controller().set_max_restored_page_id(max_page_id + 1); | |
1006 | 1043 |
1007 preview_tab_contents_delegate_.reset(new TabContentsDelegateImpl(this)); | 1044 // Set the max page id to one greater than the largest we can ever have. |
1008 new_contents->set_delegate(preview_tab_contents_delegate_.get()); | 1045 // That way if we end up merging the two NavigationControllers (which happens |
1046 // if we commit) none of the page ids will overlap irregardless of how many | |
1047 // tabs have been opened in the mean-time. | |
1048 preview_contents_->controller().set_max_restored_page_id( | |
1049 content::kMaxSessionHistoryEntries + 1); | |
1050 | |
1009 preview_contents_->download_tab_helper()->set_delegate( | 1051 preview_contents_->download_tab_helper()->set_delegate( |
1010 preview_tab_contents_delegate_.get()); | 1052 preview_tab_contents_delegate_.get()); |
1011 | 1053 |
1012 gfx::Rect tab_bounds; | |
1013 tab_contents->view()->GetContainerBounds(&tab_bounds); | |
1014 preview_contents_->view()->SizeContents(tab_bounds.size()); | |
1015 | |
1016 #if defined(OS_MACOSX) | 1054 #if defined(OS_MACOSX) |
1017 // If |preview_contents_| does not currently have a RWHV, we will call | 1055 // If |preview_contents_| does not currently have a RWHV, we will call |
1018 // SetTakesFocusOnlyOnMouseDown() as a result of the | 1056 // SetTakesFocusOnlyOnMouseDown() as a result of the |
1019 // RENDER_VIEW_HOST_CHANGED notification. | 1057 // RENDER_VIEW_HOST_CHANGED notification. |
1020 if (preview_contents_->tab_contents()->GetRenderWidgetHostView()) { | 1058 if (preview_contents_->tab_contents()->GetRenderWidgetHostView()) { |
1021 preview_contents_->tab_contents()->GetRenderWidgetHostView()-> | 1059 preview_contents_->tab_contents()->GetRenderWidgetHostView()-> |
1022 SetTakesFocusOnlyOnMouseDown(true); | 1060 SetTakesFocusOnlyOnMouseDown(true); |
1023 } | 1061 } |
1024 registrar_.Add( | 1062 registrar_.Add( |
1025 this, | 1063 this, |
1026 NotificationType::RENDER_VIEW_HOST_CHANGED, | 1064 NotificationType::RENDER_VIEW_HOST_CHANGED, |
1027 Source<NavigationController>(&preview_contents_->controller())); | 1065 Source<NavigationController>(&preview_contents_->controller())); |
1028 #endif | 1066 #endif |
1029 | 1067 |
1030 registrar_.Add( | 1068 registrar_.Add( |
1031 this, | 1069 this, |
1032 NotificationType::NAV_ENTRY_COMMITTED, | 1070 NotificationType::NAV_ENTRY_COMMITTED, |
1033 Source<NavigationController>(&preview_contents_->controller())); | 1071 Source<NavigationController>(&preview_contents_->controller())); |
1034 | 1072 |
1073 gfx::Rect tab_bounds; | |
1074 tab_contents->view()->GetContainerBounds(&tab_bounds); | |
1075 preview_contents_->view()->SizeContents(tab_bounds.size()); | |
1076 } | |
1077 | |
1078 void InstantLoader::CreatePreviewContents(TabContentsWrapper* tab_contents) { | |
1079 TabContents* new_contents = | |
1080 new TabContents( | |
1081 tab_contents->profile(), NULL, MSG_ROUTING_NONE, NULL, NULL); | |
1082 preview_contents_.reset(new TabContentsWrapper(new_contents)); | |
1083 preview_tab_contents_delegate_.reset(new TabContentsDelegateImpl(this)); | |
1084 SetupPreviewContents(tab_contents); | |
1085 | |
1035 preview_contents_->tab_contents()->ShowContents(); | 1086 preview_contents_->tab_contents()->ShowContents(); |
1036 } | 1087 } |
OLD | NEW |