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

Side by Side Diff: chrome/browser/ui/search/instant_page.cc

Issue 14911005: Move instant support to SearchTabHelper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed instant support code from InstantPage Created 7 years, 7 months 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/ui/search/instant_page.h" 5 #include "chrome/browser/ui/search/instant_page.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/search/search.h"
9 #include "chrome/browser/ui/search/search_model.h"
10 #include "chrome/browser/ui/search/search_tab_helper.h"
8 #include "chrome/common/render_messages.h" 11 #include "chrome/common/render_messages.h"
9 #include "chrome/common/url_constants.h" 12 #include "chrome/common/url_constants.h"
10 #include "content/public/browser/navigation_controller.h" 13 #include "content/public/browser/navigation_controller.h"
11 #include "content/public/browser/navigation_details.h" 14 #include "content/public/browser/navigation_details.h"
12 #include "content/public/browser/navigation_entry.h" 15 #include "content/public/browser/navigation_entry.h"
13 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
14 #include "content/public/common/frame_navigate_params.h" 17 #include "content/public/common/frame_navigate_params.h"
15 #include "ui/base/resource/resource_bundle.h" 18 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/gfx/font.h" 19 #include "ui/gfx/font.h"
17 20
18 InstantPage::Delegate::~Delegate() { 21 InstantPage::Delegate::~Delegate() {
19 } 22 }
20 23
21 InstantPage::~InstantPage() { 24 InstantPage::~InstantPage() {
25 if (extended_enabled_ && contents())
samarth 2013/05/10 01:32:38 No reason to both checking extended_enabled_ now.
kmadhusu 2013/05/13 17:13:24 Done.
26 GetSearchModel()->RemoveObserver(this);
22 } 27 }
23 28
24 bool InstantPage::IsLocal() const { 29 bool InstantPage::IsLocal() const {
25 return contents() && 30 return contents() &&
26 (contents()->GetURL() == GURL(chrome::kChromeSearchLocalNtpUrl) || 31 (contents()->GetURL() == GURL(chrome::kChromeSearchLocalNtpUrl) ||
27 contents()->GetURL() == GURL(chrome::kChromeSearchLocalGoogleNtpUrl)); 32 contents()->GetURL() == GURL(chrome::kChromeSearchLocalGoogleNtpUrl));
28 } 33 }
29 34
30 void InstantPage::Update(const string16& text, 35 void InstantPage::Update(const string16& text,
31 size_t selection_start, 36 size_t selection_start,
(...skipping 28 matching lines...) Expand all
60 const gfx::Font& omnibox_font = 65 const gfx::Font& omnibox_font =
61 ui::ResourceBundle::GetSharedInstance().GetFont( 66 ui::ResourceBundle::GetSharedInstance().GetFont(
62 ui::ResourceBundle::MediumFont); 67 ui::ResourceBundle::MediumFont);
63 #endif 68 #endif
64 string16 omnibox_font_name = UTF8ToUTF16(omnibox_font.GetFontName()); 69 string16 omnibox_font_name = UTF8ToUTF16(omnibox_font.GetFontName());
65 size_t omnibox_font_size = omnibox_font.GetFontSize(); 70 size_t omnibox_font_size = omnibox_font.GetFontSize();
66 Send(new ChromeViewMsg_SearchBoxFontInformation( 71 Send(new ChromeViewMsg_SearchBoxFontInformation(
67 routing_id(), omnibox_font_name, omnibox_font_size)); 72 routing_id(), omnibox_font_name, omnibox_font_size));
68 } 73 }
69 74
70 void InstantPage::DetermineIfPageSupportsInstant() {
71 if (IsLocal()) {
72 // Local pages always support Instant. That's why we keep them around.
73 int page_id = contents()->GetController().GetActiveEntry()->GetPageID();
74 OnInstantSupportDetermined(page_id, true);
75 } else {
76 Send(new ChromeViewMsg_DetermineIfPageSupportsInstant(routing_id()));
77 }
78 }
79
80 void InstantPage::SendAutocompleteResults( 75 void InstantPage::SendAutocompleteResults(
81 const std::vector<InstantAutocompleteResult>& results) { 76 const std::vector<InstantAutocompleteResult>& results) {
82 Send(new ChromeViewMsg_SearchBoxAutocompleteResults(routing_id(), results)); 77 Send(new ChromeViewMsg_SearchBoxAutocompleteResults(routing_id(), results));
83 } 78 }
84 79
85 void InstantPage::UpOrDownKeyPressed(int count) { 80 void InstantPage::UpOrDownKeyPressed(int count) {
86 Send(new ChromeViewMsg_SearchBoxUpOrDownKeyPressed(routing_id(), count)); 81 Send(new ChromeViewMsg_SearchBoxUpOrDownKeyPressed(routing_id(), count));
87 } 82 }
88 83
89 void InstantPage::EscKeyPressed() { 84 void InstantPage::EscKeyPressed() {
(...skipping 24 matching lines...) Expand all
114 } 109 }
115 110
116 void InstantPage::SendMostVisitedItems( 111 void InstantPage::SendMostVisitedItems(
117 const std::vector<InstantMostVisitedItemIDPair>& items) { 112 const std::vector<InstantMostVisitedItemIDPair>& items) {
118 Send(new ChromeViewMsg_SearchBoxMostVisitedItemsChanged(routing_id(), items)); 113 Send(new ChromeViewMsg_SearchBoxMostVisitedItemsChanged(routing_id(), items));
119 } 114 }
120 115
121 InstantPage::InstantPage(Delegate* delegate, const std::string& instant_url) 116 InstantPage::InstantPage(Delegate* delegate, const std::string& instant_url)
122 : delegate_(delegate), 117 : delegate_(delegate),
123 instant_url_(instant_url), 118 instant_url_(instant_url),
119 extended_enabled_(chrome::IsInstantExtendedAPIEnabled()),
samarth 2013/05/10 01:32:38 Not necessary anymore not that regular Instant is
kmadhusu 2013/05/13 17:13:24 Done.
124 supports_instant_(false), 120 supports_instant_(false),
125 instant_support_determined_(false) { 121 instant_support_determined_(false) {
126 } 122 }
127 123
128 void InstantPage::SetContents(content::WebContents* contents) { 124 void InstantPage::SetContents(content::WebContents* contents) {
125 if (extended_enabled_ && web_contents())
126 GetSearchModel()->RemoveObserver(this);
127
129 Observe(contents); 128 Observe(contents);
129
130 if (extended_enabled_ && contents) {
131 SearchModel* model = GetSearchModel();
132 model->AddObserver(this);
133
134 // Already know whether the page supports instant.
135 if (model->instant_support() != INSTANT_SUPPORT_UNKNOWN)
136 SetSupportsInstant(model->instant_support() == INSTANT_SUPPORT_YES);
137 }
130 } 138 }
131 139
132 bool InstantPage::ShouldProcessRenderViewCreated() { 140 bool InstantPage::ShouldProcessRenderViewCreated() {
133 return false; 141 return false;
134 } 142 }
135 143
136 bool InstantPage::ShouldProcessRenderViewGone() { 144 bool InstantPage::ShouldProcessRenderViewGone() {
137 return false; 145 return false;
138 } 146 }
139 147
(...skipping 15 matching lines...) Expand all
155 163
156 bool InstantPage::ShouldProcessNavigateToURL() { 164 bool InstantPage::ShouldProcessNavigateToURL() {
157 return false; 165 return false;
158 } 166 }
159 167
160 void InstantPage::RenderViewCreated(content::RenderViewHost* render_view_host) { 168 void InstantPage::RenderViewCreated(content::RenderViewHost* render_view_host) {
161 if (ShouldProcessRenderViewCreated()) 169 if (ShouldProcessRenderViewCreated())
162 delegate_->InstantPageRenderViewCreated(contents()); 170 delegate_->InstantPageRenderViewCreated(contents());
163 } 171 }
164 172
165 void InstantPage::DidFinishLoad(
166 int64 /* frame_id */,
167 const GURL& /* validated_url */,
168 bool is_main_frame,
169 content::RenderViewHost* /* render_view_host */) {
170 if (is_main_frame && !supports_instant_)
171 DetermineIfPageSupportsInstant();
172 }
173
174 bool InstantPage::OnMessageReceived(const IPC::Message& message) { 173 bool InstantPage::OnMessageReceived(const IPC::Message& message) {
175 bool handled = true; 174 bool handled = true;
176 IPC_BEGIN_MESSAGE_MAP(InstantPage, message) 175 IPC_BEGIN_MESSAGE_MAP(InstantPage, message)
177 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SetSuggestions, OnSetSuggestions) 176 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SetSuggestions, OnSetSuggestions)
178 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_InstantSupportDetermined,
179 OnInstantSupportDetermined)
180 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ShowInstantOverlay, 177 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ShowInstantOverlay,
181 OnShowInstantOverlay) 178 OnShowInstantOverlay)
182 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_FocusOmnibox, OnFocusOmnibox) 179 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_FocusOmnibox, OnFocusOmnibox)
183 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxNavigate, 180 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxNavigate,
184 OnSearchBoxNavigate); 181 OnSearchBoxNavigate);
185 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem, 182 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem,
186 OnDeleteMostVisitedItem); 183 OnDeleteMostVisitedItem);
187 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion, 184 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion,
188 OnUndoMostVisitedDeletion); 185 OnUndoMostVisitedDeletion);
189 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions, 186 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 int64 /* frame_id */, 219 int64 /* frame_id */,
223 bool is_main_frame, 220 bool is_main_frame,
224 const GURL& /* validated_url */, 221 const GURL& /* validated_url */,
225 int /* error_code */, 222 int /* error_code */,
226 const string16& /* error_description */, 223 const string16& /* error_description */,
227 content::RenderViewHost* /* render_view_host */) { 224 content::RenderViewHost* /* render_view_host */) {
228 if (is_main_frame) 225 if (is_main_frame)
229 delegate_->InstantPageLoadFailed(contents()); 226 delegate_->InstantPageLoadFailed(contents());
230 } 227 }
231 228
232 void InstantPage::OnSetSuggestions( 229 void InstantPage::ModelChanged(const SearchModel::State& old_state,
233 int page_id, 230 const SearchModel::State& new_state) {
234 const std::vector<InstantSuggestion>& suggestions) { 231 if (old_state.instant_support != new_state.instant_support)
235 if (contents()->IsActiveEntry(page_id)) { 232 SetSupportsInstant(new_state.instant_support == INSTANT_SUPPORT_YES);
236 OnInstantSupportDetermined(page_id, true);
237 if (ShouldProcessSetSuggestions())
238 delegate_->SetSuggestions(contents(), suggestions);
239 }
240 } 233 }
241 234
242 void InstantPage::OnInstantSupportDetermined(int page_id, 235 SearchModel* InstantPage::GetSearchModel() {
243 bool supports_instant) { 236 return contents() ?
244 if (!contents()->IsActiveEntry(page_id) || supports_instant_) { 237 SearchTabHelper::FromWebContents(contents())->model() : NULL;
245 // Nothing to do if the page already supports Instant. 238 }
239
240 void InstantPage::SetSupportsInstant(bool supports_instant) {
241 if (instant_support_determined_ && supports_instant_ == supports_instant)
246 return; 242 return;
247 }
248 243
249 instant_support_determined_ = true; 244 instant_support_determined_ = true;
250 supports_instant_ = supports_instant; 245 supports_instant_ = supports_instant;
samarth 2013/05/10 01:32:38 Currently, once an InstantPage supports instant, w
samarth 2013/05/10 14:45:56 Thinking about this some more, doing (2) is still
kmadhusu 2013/05/13 17:13:24 ok.
251 delegate_->InstantSupportDetermined(contents(), supports_instant); 246 delegate_->InstantSupportDetermined(contents(), supports_instant);
252 247
253 // If the page doesn't support Instant, stop listening to it. 248 // If the page doesn't support Instant, stop listening to it.
254 if (!supports_instant) 249 if (!supports_instant)
255 Observe(NULL); 250 SetContents(NULL);
251 }
252
253 void InstantPage::OnSetSuggestions(
254 int page_id,
255 const std::vector<InstantSuggestion>& suggestions) {
256 if (contents()->IsActiveEntry(page_id)) {
257 SearchTabHelper::FromWebContents(contents())->
258 OnInstantSupportDeterminedMsgReceived(page_id, true);
259 if (ShouldProcessSetSuggestions())
260 delegate_->SetSuggestions(contents(), suggestions);
261 }
256 } 262 }
257 263
258 void InstantPage::OnShowInstantOverlay(int page_id, 264 void InstantPage::OnShowInstantOverlay(int page_id,
259 int height, 265 int height,
260 InstantSizeUnits units) { 266 InstantSizeUnits units) {
261 if (contents()->IsActiveEntry(page_id)) { 267 if (contents()->IsActiveEntry(page_id)) {
262 OnInstantSupportDetermined(page_id, true); 268 SearchTabHelper::FromWebContents(contents())->
269 OnInstantSupportDeterminedMsgReceived(page_id, true);
263 if (ShouldProcessShowInstantOverlay()) 270 if (ShouldProcessShowInstantOverlay())
264 delegate_->ShowInstantOverlay(contents(), height, units); 271 delegate_->ShowInstantOverlay(contents(), height, units);
265 } 272 }
266 } 273 }
267 274
268 void InstantPage::OnFocusOmnibox(int page_id, OmniboxFocusState state) { 275 void InstantPage::OnFocusOmnibox(int page_id, OmniboxFocusState state) {
269 if (contents()->IsActiveEntry(page_id)) { 276 if (contents()->IsActiveEntry(page_id)) {
270 OnInstantSupportDetermined(page_id, true); 277 SearchTabHelper::FromWebContents(contents())->
278 OnInstantSupportDeterminedMsgReceived(page_id, true);
271 if (ShouldProcessFocusOmnibox()) 279 if (ShouldProcessFocusOmnibox())
272 delegate_->FocusOmnibox(contents(), state); 280 delegate_->FocusOmnibox(contents(), state);
273 } 281 }
274 } 282 }
275 283
276 void InstantPage::OnSearchBoxNavigate(int page_id, 284 void InstantPage::OnSearchBoxNavigate(int page_id,
277 const GURL& url, 285 const GURL& url,
278 content::PageTransition transition, 286 content::PageTransition transition,
279 WindowOpenDisposition disposition) { 287 WindowOpenDisposition disposition) {
280 if (contents()->IsActiveEntry(page_id)) { 288 if (contents()->IsActiveEntry(page_id)) {
281 OnInstantSupportDetermined(page_id, true); 289 SearchTabHelper::FromWebContents(contents())->
290 OnInstantSupportDeterminedMsgReceived(page_id, true);
282 if (ShouldProcessNavigateToURL()) 291 if (ShouldProcessNavigateToURL())
283 delegate_->NavigateToURL(contents(), url, transition, disposition); 292 delegate_->NavigateToURL(contents(), url, transition, disposition);
284 } 293 }
285 } 294 }
286 295
287 void InstantPage::OnDeleteMostVisitedItem(InstantRestrictedID restricted_id) { 296 void InstantPage::OnDeleteMostVisitedItem(InstantRestrictedID restricted_id) {
288 delegate_->DeleteMostVisitedItem(restricted_id); 297 delegate_->DeleteMostVisitedItem(restricted_id);
289 } 298 }
290 299
291 void InstantPage::OnUndoMostVisitedDeletion(InstantRestrictedID restricted_id) { 300 void InstantPage::OnUndoMostVisitedDeletion(InstantRestrictedID restricted_id) {
292 delegate_->UndoMostVisitedDeletion(restricted_id); 301 delegate_->UndoMostVisitedDeletion(restricted_id);
293 } 302 }
294 303
295 void InstantPage::OnUndoAllMostVisitedDeletions() { 304 void InstantPage::OnUndoAllMostVisitedDeletions() {
296 delegate_->UndoAllMostVisitedDeletions(); 305 delegate_->UndoAllMostVisitedDeletions();
297 } 306 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698