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

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

Issue 16124009: Revert 204709 "Move instant support to SearchTabHelper." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 6 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"
11 #include "chrome/common/render_messages.h" 8 #include "chrome/common/render_messages.h"
12 #include "chrome/common/url_constants.h" 9 #include "chrome/common/url_constants.h"
13 #include "content/public/browser/navigation_controller.h" 10 #include "content/public/browser/navigation_controller.h"
14 #include "content/public/browser/navigation_details.h" 11 #include "content/public/browser/navigation_details.h"
15 #include "content/public/browser/navigation_entry.h" 12 #include "content/public/browser/navigation_entry.h"
16 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
17 #include "content/public/common/frame_navigate_params.h" 14 #include "content/public/common/frame_navigate_params.h"
18 #include "ui/base/resource/resource_bundle.h" 15 #include "ui/base/resource/resource_bundle.h"
19 #include "ui/gfx/font.h" 16 #include "ui/gfx/font.h"
20 17
21 InstantPage::Delegate::~Delegate() { 18 InstantPage::Delegate::~Delegate() {
22 } 19 }
23 20
24 InstantPage::~InstantPage() { 21 InstantPage::~InstantPage() {
25 if (contents())
26 GetSearchModel()->RemoveObserver(this);
27 } 22 }
28 23
29 bool InstantPage::supports_instant() const { 24 bool InstantPage::supports_instant() const {
30 return supports_instant_; 25 return supports_instant_;
31 } 26 }
32 27
33 bool InstantPage::IsLocal() const { 28 bool InstantPage::IsLocal() const {
34 return contents() && 29 return contents() &&
35 (contents()->GetURL() == GURL(chrome::kChromeSearchLocalNtpUrl) || 30 (contents()->GetURL() == GURL(chrome::kChromeSearchLocalNtpUrl) ||
36 contents()->GetURL() == GURL(chrome::kChromeSearchLocalGoogleNtpUrl)); 31 contents()->GetURL() == GURL(chrome::kChromeSearchLocalGoogleNtpUrl));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 const gfx::Font& omnibox_font = 64 const gfx::Font& omnibox_font =
70 ui::ResourceBundle::GetSharedInstance().GetFont( 65 ui::ResourceBundle::GetSharedInstance().GetFont(
71 ui::ResourceBundle::MediumFont); 66 ui::ResourceBundle::MediumFont);
72 #endif 67 #endif
73 string16 omnibox_font_name = UTF8ToUTF16(omnibox_font.GetFontName()); 68 string16 omnibox_font_name = UTF8ToUTF16(omnibox_font.GetFontName());
74 size_t omnibox_font_size = omnibox_font.GetFontSize(); 69 size_t omnibox_font_size = omnibox_font.GetFontSize();
75 Send(new ChromeViewMsg_SearchBoxFontInformation( 70 Send(new ChromeViewMsg_SearchBoxFontInformation(
76 routing_id(), omnibox_font_name, omnibox_font_size)); 71 routing_id(), omnibox_font_name, omnibox_font_size));
77 } 72 }
78 73
74 void InstantPage::DetermineIfPageSupportsInstant() {
75 if (IsLocal()) {
76 // Local pages always support Instant. That's why we keep them around.
77 int page_id = contents()->GetController().GetActiveEntry()->GetPageID();
78 OnInstantSupportDetermined(page_id, true);
79 } else {
80 Send(new ChromeViewMsg_DetermineIfPageSupportsInstant(routing_id()));
81 }
82 }
83
79 void InstantPage::SendAutocompleteResults( 84 void InstantPage::SendAutocompleteResults(
80 const std::vector<InstantAutocompleteResult>& results) { 85 const std::vector<InstantAutocompleteResult>& results) {
81 Send(new ChromeViewMsg_SearchBoxAutocompleteResults(routing_id(), results)); 86 Send(new ChromeViewMsg_SearchBoxAutocompleteResults(routing_id(), results));
82 } 87 }
83 88
84 void InstantPage::UpOrDownKeyPressed(int count) { 89 void InstantPage::UpOrDownKeyPressed(int count) {
85 Send(new ChromeViewMsg_SearchBoxUpOrDownKeyPressed(routing_id(), count)); 90 Send(new ChromeViewMsg_SearchBoxUpOrDownKeyPressed(routing_id(), count));
86 } 91 }
87 92
88 void InstantPage::EscKeyPressed() { 93 void InstantPage::EscKeyPressed() {
(...skipping 28 matching lines...) Expand all
117 Send(new ChromeViewMsg_SearchBoxMostVisitedItemsChanged(routing_id(), items)); 122 Send(new ChromeViewMsg_SearchBoxMostVisitedItemsChanged(routing_id(), items));
118 } 123 }
119 124
120 void InstantPage::ToggleVoiceSearch() { 125 void InstantPage::ToggleVoiceSearch() {
121 Send(new ChromeViewMsg_SearchBoxToggleVoiceSearch(routing_id())); 126 Send(new ChromeViewMsg_SearchBoxToggleVoiceSearch(routing_id()));
122 } 127 }
123 128
124 InstantPage::InstantPage(Delegate* delegate, const std::string& instant_url) 129 InstantPage::InstantPage(Delegate* delegate, const std::string& instant_url)
125 : delegate_(delegate), 130 : delegate_(delegate),
126 instant_url_(instant_url), 131 instant_url_(instant_url),
127 supports_instant_(false) { 132 supports_instant_(false),
133 instant_support_determined_(false) {
128 } 134 }
129 135
130 void InstantPage::SetContents(content::WebContents* contents) { 136 void InstantPage::SetContents(content::WebContents* contents) {
131 if (web_contents())
132 GetSearchModel()->RemoveObserver(this);
133
134 Observe(contents); 137 Observe(contents);
135
136 if (!contents) {
137 supports_instant_ = false;
138 return;
139 }
140
141 SearchModel* model = GetSearchModel();
142 model->AddObserver(this);
143
144 // Already know whether the page supports instant.
145 if (model->instant_support() != INSTANT_SUPPORT_UNKNOWN)
146 SetSupportsInstant(model->instant_support() == INSTANT_SUPPORT_YES);
147 } 138 }
148 139
149 bool InstantPage::ShouldProcessRenderViewCreated() { 140 bool InstantPage::ShouldProcessRenderViewCreated() {
150 return false; 141 return false;
151 } 142 }
152 143
153 bool InstantPage::ShouldProcessRenderViewGone() { 144 bool InstantPage::ShouldProcessRenderViewGone() {
154 return false; 145 return false;
155 } 146 }
156 147
(...skipping 15 matching lines...) Expand all
172 163
173 bool InstantPage::ShouldProcessNavigateToURL() { 164 bool InstantPage::ShouldProcessNavigateToURL() {
174 return false; 165 return false;
175 } 166 }
176 167
177 void InstantPage::RenderViewCreated(content::RenderViewHost* render_view_host) { 168 void InstantPage::RenderViewCreated(content::RenderViewHost* render_view_host) {
178 if (ShouldProcessRenderViewCreated()) 169 if (ShouldProcessRenderViewCreated())
179 delegate_->InstantPageRenderViewCreated(contents()); 170 delegate_->InstantPageRenderViewCreated(contents());
180 } 171 }
181 172
173 void InstantPage::DidFinishLoad(
174 int64 /* frame_id */,
175 const GURL& /* validated_url */,
176 bool is_main_frame,
177 content::RenderViewHost* /* render_view_host */) {
178 if (is_main_frame && !supports_instant_)
179 DetermineIfPageSupportsInstant();
180 }
181
182 bool InstantPage::OnMessageReceived(const IPC::Message& message) { 182 bool InstantPage::OnMessageReceived(const IPC::Message& message) {
183 bool handled = true; 183 bool handled = true;
184 IPC_BEGIN_MESSAGE_MAP(InstantPage, message) 184 IPC_BEGIN_MESSAGE_MAP(InstantPage, message)
185 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SetSuggestions, OnSetSuggestions) 185 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SetSuggestions, OnSetSuggestions)
186 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_InstantSupportDetermined,
187 OnInstantSupportDetermined)
186 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ShowInstantOverlay, 188 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ShowInstantOverlay,
187 OnShowInstantOverlay) 189 OnShowInstantOverlay)
188 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_FocusOmnibox, OnFocusOmnibox) 190 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_FocusOmnibox, OnFocusOmnibox)
189 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxNavigate, 191 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxNavigate,
190 OnSearchBoxNavigate); 192 OnSearchBoxNavigate);
191 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem, 193 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem,
192 OnDeleteMostVisitedItem); 194 OnDeleteMostVisitedItem);
193 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion, 195 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion,
194 OnUndoMostVisitedDeletion); 196 OnUndoMostVisitedDeletion);
195 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions, 197 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 int64 /* frame_id */, 230 int64 /* frame_id */,
229 bool is_main_frame, 231 bool is_main_frame,
230 const GURL& /* validated_url */, 232 const GURL& /* validated_url */,
231 int /* error_code */, 233 int /* error_code */,
232 const string16& /* error_description */, 234 const string16& /* error_description */,
233 content::RenderViewHost* /* render_view_host */) { 235 content::RenderViewHost* /* render_view_host */) {
234 if (is_main_frame) 236 if (is_main_frame)
235 delegate_->InstantPageLoadFailed(contents()); 237 delegate_->InstantPageLoadFailed(contents());
236 } 238 }
237 239
238 void InstantPage::ModelChanged(const SearchModel::State& old_state,
239 const SearchModel::State& new_state) {
240 if (old_state.instant_support != new_state.instant_support)
241 SetSupportsInstant(new_state.instant_support == INSTANT_SUPPORT_YES);
242 }
243
244 SearchModel* InstantPage::GetSearchModel() {
245 return contents() ?
246 SearchTabHelper::FromWebContents(contents())->model() : NULL;
247 }
248
249 void InstantPage::SetSupportsInstant(bool supports_instant) {
250 // Nothing to do if the page already supports Instant.
251 if (supports_instant_)
252 return;
253
254 supports_instant_ = supports_instant;
255 delegate_->InstantSupportDetermined(contents(), supports_instant);
256
257 // If the page doesn't support Instant, stop listening to it.
258 if (!supports_instant)
259 SetContents(NULL);
260 }
261
262 void InstantPage::OnSetSuggestions( 240 void InstantPage::OnSetSuggestions(
263 int page_id, 241 int page_id,
264 const std::vector<InstantSuggestion>& suggestions) { 242 const std::vector<InstantSuggestion>& suggestions) {
265 if (!contents()->IsActiveEntry(page_id)) 243 if (!contents()->IsActiveEntry(page_id))
266 return; 244 return;
267 245
268 SearchTabHelper::FromWebContents(contents())->InstantSupportChanged(true); 246 OnInstantSupportDetermined(page_id, true);
269 if (!ShouldProcessSetSuggestions()) 247 if (!ShouldProcessSetSuggestions())
270 return; 248 return;
271 249
272 delegate_->SetSuggestions(contents(), suggestions); 250 delegate_->SetSuggestions(contents(), suggestions);
273 } 251 }
274 252
253 void InstantPage::OnInstantSupportDetermined(int page_id,
254 bool supports_instant) {
255 if (!contents()->IsActiveEntry(page_id) || supports_instant_) {
256 // Nothing to do if the page already supports Instant.
257 return;
258 }
259
260 instant_support_determined_ = true;
261 supports_instant_ = supports_instant;
262 delegate_->InstantSupportDetermined(contents(), supports_instant);
263
264 // If the page doesn't support Instant, stop listening to it.
265 if (!supports_instant)
266 Observe(NULL);
267 }
268
275 void InstantPage::OnShowInstantOverlay(int page_id, 269 void InstantPage::OnShowInstantOverlay(int page_id,
276 int height, 270 int height,
277 InstantSizeUnits units) { 271 InstantSizeUnits units) {
278 if (!contents()->IsActiveEntry(page_id)) 272 if (!contents()->IsActiveEntry(page_id))
279 return; 273 return;
280 274
281 SearchTabHelper::FromWebContents(contents())->InstantSupportChanged(true); 275 OnInstantSupportDetermined(page_id, true);
282 delegate_->LogDropdownShown(); 276 delegate_->LogDropdownShown();
283 if (!ShouldProcessShowInstantOverlay()) 277 if (!ShouldProcessShowInstantOverlay())
284 return; 278 return;
285 279
286 delegate_->ShowInstantOverlay(contents(), height, units); 280 delegate_->ShowInstantOverlay(contents(), height, units);
287 } 281 }
288 282
289 void InstantPage::OnFocusOmnibox(int page_id, OmniboxFocusState state) { 283 void InstantPage::OnFocusOmnibox(int page_id, OmniboxFocusState state) {
290 if (!contents()->IsActiveEntry(page_id)) 284 if (!contents()->IsActiveEntry(page_id))
291 return; 285 return;
292 286
293 SearchTabHelper::FromWebContents(contents())->InstantSupportChanged(true); 287 OnInstantSupportDetermined(page_id, true);
294 if (!ShouldProcessFocusOmnibox()) 288 if (!ShouldProcessFocusOmnibox())
295 return; 289 return;
296 290
297 delegate_->FocusOmnibox(contents(), state); 291 delegate_->FocusOmnibox(contents(), state);
298 } 292 }
299 293
300 void InstantPage::OnSearchBoxNavigate(int page_id, 294 void InstantPage::OnSearchBoxNavigate(int page_id,
301 const GURL& url, 295 const GURL& url,
302 content::PageTransition transition, 296 content::PageTransition transition,
303 WindowOpenDisposition disposition, 297 WindowOpenDisposition disposition,
304 bool is_search_type) { 298 bool is_search_type) {
305 if (!contents()->IsActiveEntry(page_id)) 299 if (!contents()->IsActiveEntry(page_id))
306 return; 300 return;
307 301
308 SearchTabHelper::FromWebContents(contents())->InstantSupportChanged(true); 302 OnInstantSupportDetermined(page_id, true);
309 if (!ShouldProcessNavigateToURL()) 303 if (!ShouldProcessNavigateToURL())
310 return; 304 return;
311 305
312 delegate_->NavigateToURL( 306 delegate_->NavigateToURL(
313 contents(), url, transition, disposition, is_search_type); 307 contents(), url, transition, disposition, is_search_type);
314 } 308 }
315 309
316 void InstantPage::OnDeleteMostVisitedItem(const GURL& url) { 310 void InstantPage::OnDeleteMostVisitedItem(const GURL& url) {
317 // TODO(kmadhusu): Call delegate_->DeleteMostVisitedItem() only if the message
318 // is for the active entry and if the page should process the message.
319 delegate_->DeleteMostVisitedItem(url); 311 delegate_->DeleteMostVisitedItem(url);
320 } 312 }
321 313
322 void InstantPage::OnUndoMostVisitedDeletion(const GURL& url) { 314 void InstantPage::OnUndoMostVisitedDeletion(const GURL& url) {
323 // TODO(kmadhusu): Call delegate_->UndoMostVisitedDeletion() only if the
324 // message is for the active entry and if the page should process the message.
325 delegate_->UndoMostVisitedDeletion(url); 315 delegate_->UndoMostVisitedDeletion(url);
326 } 316 }
327 317
328 void InstantPage::OnUndoAllMostVisitedDeletions() { 318 void InstantPage::OnUndoAllMostVisitedDeletions() {
329 // TODO(kmadhusu): Call delegate_->UndoAllMostVisitedDeletions() only if the
330 // message is for the active entry and if the page should process the message.
331 delegate_->UndoAllMostVisitedDeletions(); 319 delegate_->UndoAllMostVisitedDeletions();
332 } 320 }
OLDNEW
« no previous file with comments | « trunk/src/chrome/browser/ui/search/instant_page.h ('k') | trunk/src/chrome/browser/ui/search/instant_page_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698