Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: chrome/browser/instant/instant_loader.cc

Issue 8865004: Create CoreTabHelper, move remaining core TCW functionality into it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: lots of helpers now Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
15 #include "base/string_number_conversions.h" 15 #include "base/string_number_conversions.h"
16 #include "base/timer.h" 16 #include "base/timer.h"
17 #include "base/utf_string_conversions.h" 17 #include "base/utf_string_conversions.h"
18 #include "base/values.h" 18 #include "base/values.h"
19 #include "chrome/browser/favicon/favicon_service.h" 19 #include "chrome/browser/favicon/favicon_service.h"
20 #include "chrome/browser/history/history_marshaling.h" 20 #include "chrome/browser/history/history_marshaling.h"
21 #include "chrome/browser/history/history_tab_helper.h" 21 #include "chrome/browser/history/history_tab_helper.h"
22 #include "chrome/browser/instant/instant_loader_delegate.h" 22 #include "chrome/browser/instant/instant_loader_delegate.h"
23 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/search_engines/template_url.h" 24 #include "chrome/browser/search_engines/template_url.h"
25 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" 25 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h"
26 #include "chrome/browser/ui/constrained_window_tab_helper.h" 26 #include "chrome/browser/ui/constrained_window_tab_helper.h"
27 #include "chrome/browser/ui/constrained_window_tab_helper_delegate.h" 27 #include "chrome/browser/ui/constrained_window_tab_helper_delegate.h"
28 #include "chrome/browser/ui/tab_contents/core_tab_helper.h"
29 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h"
28 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 30 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
29 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h"
30 #include "chrome/common/chrome_notification_types.h" 31 #include "chrome/common/chrome_notification_types.h"
31 #include "chrome/common/chrome_switches.h" 32 #include "chrome/common/chrome_switches.h"
32 #include "chrome/common/render_messages.h" 33 #include "chrome/common/render_messages.h"
33 #include "content/browser/renderer_host/render_view_host.h" 34 #include "content/browser/renderer_host/render_view_host.h"
34 #include "content/browser/renderer_host/render_widget_host.h" 35 #include "content/browser/renderer_host/render_widget_host.h"
35 #include "content/browser/renderer_host/render_widget_host_view.h" 36 #include "content/browser/renderer_host/render_widget_host_view.h"
36 #include "content/browser/tab_contents/navigation_details.h" 37 #include "content/browser/tab_contents/navigation_details.h"
37 #include "content/browser/tab_contents/navigation_entry.h" 38 #include "content/browser/tab_contents/navigation_entry.h"
38 #include "content/browser/tab_contents/provisional_load_details.h" 39 #include "content/browser/tab_contents/provisional_load_details.h"
39 #include "content/browser/tab_contents/tab_contents.h" 40 #include "content/browser/tab_contents/tab_contents.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 default: 157 default:
157 NOTREACHED(); 158 NOTREACHED();
158 break; 159 break;
159 } 160 }
160 } 161 }
161 162
162 // TabContentsDelegateImpl ----------------------------------------------------- 163 // TabContentsDelegateImpl -----------------------------------------------------
163 164
164 class InstantLoader::TabContentsDelegateImpl 165 class InstantLoader::TabContentsDelegateImpl
165 : public TabContentsDelegate, 166 : public TabContentsDelegate,
166 public TabContentsWrapperDelegate, 167 public CoreTabHelperDelegate,
167 public ConstrainedWindowTabHelperDelegate, 168 public ConstrainedWindowTabHelperDelegate,
168 public content::NotificationObserver, 169 public content::NotificationObserver,
169 public TabContentsObserver { 170 public TabContentsObserver {
170 public: 171 public:
171 explicit TabContentsDelegateImpl(InstantLoader* loader); 172 explicit TabContentsDelegateImpl(InstantLoader* loader);
172 173
173 // Invoked prior to loading a new URL. 174 // Invoked prior to loading a new URL.
174 void PrepareForNewLoad(); 175 void PrepareForNewLoad();
175 176
176 // Invoked when the preview paints. Invokes PreviewPainted on the loader. 177 // Invoked when the preview paints. Invokes PreviewPainted on the loader.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 // move around. 216 // move around.
216 virtual void DragEnded() OVERRIDE; 217 virtual void DragEnded() OVERRIDE;
217 virtual bool CanDownload(TabContents* source, int request_id) OVERRIDE; 218 virtual bool CanDownload(TabContents* source, int request_id) OVERRIDE;
218 virtual void HandleMouseUp() OVERRIDE; 219 virtual void HandleMouseUp() OVERRIDE;
219 virtual void HandleMouseActivate() OVERRIDE; 220 virtual void HandleMouseActivate() OVERRIDE;
220 virtual bool OnGoToEntryOffset(int offset) OVERRIDE; 221 virtual bool OnGoToEntryOffset(int offset) OVERRIDE;
221 virtual bool ShouldAddNavigationToHistory( 222 virtual bool ShouldAddNavigationToHistory(
222 const history::HistoryAddPageArgs& add_page_args, 223 const history::HistoryAddPageArgs& add_page_args,
223 content::NavigationType navigation_type) OVERRIDE; 224 content::NavigationType navigation_type) OVERRIDE;
224 225
225 // TabContentsWrapperDelegate: 226 // CoreTabHelperDelegate:
226 virtual void SwapTabContents(TabContentsWrapper* old_tc, 227 virtual void SwapTabContents(TabContentsWrapper* old_tc,
227 TabContentsWrapper* new_tc) OVERRIDE; 228 TabContentsWrapper* new_tc) OVERRIDE;
228 229
229 // ConstrainedWindowTabHelperDelegate: 230 // ConstrainedWindowTabHelperDelegate:
230 virtual void WillShowConstrainedWindow(TabContentsWrapper* source) OVERRIDE; 231 virtual void WillShowConstrainedWindow(TabContentsWrapper* source) OVERRIDE;
231 virtual bool ShouldFocusConstrainedWindow() OVERRIDE; 232 virtual bool ShouldFocusConstrainedWindow() OVERRIDE;
232 233
233 // TabContentsObserver: 234 // TabContentsObserver:
234 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 235 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
235 236
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 // We release here without deleting so that the caller still has reponsibility 974 // We release here without deleting so that the caller still has reponsibility
974 // for deleting the TabContentsWrapper. 975 // for deleting the TabContentsWrapper.
975 ignore_result(preview_contents_.release()); 976 ignore_result(preview_contents_.release());
976 preview_contents_.reset(new_tc); 977 preview_contents_.reset(new_tc);
977 978
978 // Make sure the new preview contents acts like the old one. 979 // Make sure the new preview contents acts like the old one.
979 SetupPreviewContents(old_tc); 980 SetupPreviewContents(old_tc);
980 981
981 // Cleanup the old preview contents. 982 // Cleanup the old preview contents.
982 old_tc->constrained_window_tab_helper()->set_delegate(NULL); 983 old_tc->constrained_window_tab_helper()->set_delegate(NULL);
984 old_tc->core_tab_helper()->set_delegate(NULL);
983 old_tc->tab_contents()->set_delegate(NULL); 985 old_tc->tab_contents()->set_delegate(NULL);
984 old_tc->set_delegate(NULL);
985 986
986 #if defined(OS_MACOSX) 987 #if defined(OS_MACOSX)
987 registrar_.Remove( 988 registrar_.Remove(
988 this, 989 this,
989 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, 990 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
990 content::Source<NavigationController>(&old_tc->controller())); 991 content::Source<NavigationController>(&old_tc->controller()));
991 #endif 992 #endif
992 registrar_.Remove(this, 993 registrar_.Remove(this,
993 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 994 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
994 content::Source<NavigationController>(&old_tc->controller())); 995 content::Source<NavigationController>(&old_tc->controller()));
995 996
996 // We prerendered so we should be ready to show. If we're ready, swap in 997 // We prerendered so we should be ready to show. If we're ready, swap in
997 // immediately, otherwise show the preview as normal. 998 // immediately, otherwise show the preview as normal.
998 if (ready_) 999 if (ready_)
999 delegate_->SwappedTabContents(this); 1000 delegate_->SwappedTabContents(this);
1000 else 1001 else
1001 ShowPreview(); 1002 ShowPreview();
1002 } 1003 }
1003 1004
1004 void InstantLoader::SetupPreviewContents(TabContentsWrapper* tab_contents) { 1005 void InstantLoader::SetupPreviewContents(TabContentsWrapper* tab_contents) {
1005 preview_contents_->set_delegate(preview_tab_contents_delegate_.get());
1006 preview_contents_->tab_contents()->set_delegate( 1006 preview_contents_->tab_contents()->set_delegate(
1007 preview_tab_contents_delegate_.get()); 1007 preview_tab_contents_delegate_.get());
1008 preview_contents_->blocked_content_tab_helper()->SetAllContentsBlocked(true); 1008 preview_contents_->blocked_content_tab_helper()->SetAllContentsBlocked(true);
1009 preview_contents_->constrained_window_tab_helper()->set_delegate( 1009 preview_contents_->constrained_window_tab_helper()->set_delegate(
1010 preview_tab_contents_delegate_.get()); 1010 preview_tab_contents_delegate_.get());
1011 preview_contents_->core_tab_helper()->set_delegate(
1012 preview_tab_contents_delegate_.get());
1011 1013
1012 // Propagate the max page id. That way if we end up merging the two 1014 // Propagate the max page id. That way if we end up merging the two
1013 // NavigationControllers (which happens if we commit) none of the page ids 1015 // NavigationControllers (which happens if we commit) none of the page ids
1014 // will overlap. 1016 // will overlap.
1015 int32 max_page_id = tab_contents->tab_contents()->GetMaxPageID(); 1017 int32 max_page_id = tab_contents->tab_contents()->GetMaxPageID();
1016 if (max_page_id != -1) 1018 if (max_page_id != -1)
1017 preview_contents_->controller().set_max_restored_page_id(max_page_id + 1); 1019 preview_contents_->controller().set_max_restored_page_id(max_page_id + 1);
1018 1020
1019 #if defined(OS_MACOSX) 1021 #if defined(OS_MACOSX)
1020 // If |preview_contents_| does not currently have a RWHV, we will call 1022 // If |preview_contents_| does not currently have a RWHV, we will call
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 host->Send(new ChromeViewMsg_SearchBoxResize( 1089 host->Send(new ChromeViewMsg_SearchBoxResize(
1088 host->routing_id(), GetOmniboxBoundsInTermsOfPreview())); 1090 host->routing_id(), GetOmniboxBoundsInTermsOfPreview()));
1089 } else { 1091 } else {
1090 host->Send(new ChromeViewMsg_SearchBoxChange( 1092 host->Send(new ChromeViewMsg_SearchBoxChange(
1091 host->routing_id(), user_text, verbatim, 0, 0)); 1093 host->routing_id(), user_text, verbatim, 0, 0));
1092 } 1094 }
1093 1095
1094 frame_load_observer_.reset(new FrameLoadObserver( 1096 frame_load_observer_.reset(new FrameLoadObserver(
1095 this, preview_contents()->tab_contents(), user_text, verbatim)); 1097 this, preview_contents()->tab_contents(), user_text, verbatim));
1096 } 1098 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698