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

Side by Side Diff: chrome/browser/ui/omnibox/omnibox_edit_model.cc

Issue 17391005: Remove Instant hooks from SearchProvider. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/omnibox/omnibox_edit_model.h" 5 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/format_macros.h" 10 #include "base/format_macros.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "chrome/app/chrome_command_ids.h" 16 #include "chrome/app/chrome_command_ids.h"
17 #include "chrome/browser/autocomplete/autocomplete_classifier.h" 17 #include "chrome/browser/autocomplete/autocomplete_classifier.h"
18 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" 18 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
19 #include "chrome/browser/autocomplete/autocomplete_input.h" 19 #include "chrome/browser/autocomplete/autocomplete_input.h"
20 #include "chrome/browser/autocomplete/autocomplete_provider.h" 20 #include "chrome/browser/autocomplete/autocomplete_provider.h"
21 #include "chrome/browser/autocomplete/extension_app_provider.h" 21 #include "chrome/browser/autocomplete/extension_app_provider.h"
22 #include "chrome/browser/autocomplete/history_url_provider.h" 22 #include "chrome/browser/autocomplete/history_url_provider.h"
23 #include "chrome/browser/autocomplete/keyword_provider.h" 23 #include "chrome/browser/autocomplete/keyword_provider.h"
24 #include "chrome/browser/autocomplete/search_provider.h"
25 #include "chrome/browser/bookmarks/bookmark_utils.h" 24 #include "chrome/browser/bookmarks/bookmark_utils.h"
26 #include "chrome/browser/command_updater.h" 25 #include "chrome/browser/command_updater.h"
27 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" 26 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h"
28 #include "chrome/browser/google/google_url_tracker.h" 27 #include "chrome/browser/google/google_url_tracker.h"
29 #include "chrome/browser/net/predictor.h" 28 #include "chrome/browser/net/predictor.h"
30 #include "chrome/browser/net/url_fixer_upper.h" 29 #include "chrome/browser/net/url_fixer_upper.h"
31 #include "chrome/browser/omnibox/omnibox_log.h" 30 #include "chrome/browser/omnibox/omnibox_log.h"
32 #include "chrome/browser/predictors/autocomplete_action_predictor.h" 31 #include "chrome/browser/predictors/autocomplete_action_predictor.h"
33 #include "chrome/browser/predictors/autocomplete_action_predictor_factory.h" 32 #include "chrome/browser/predictors/autocomplete_action_predictor_factory.h"
34 #include "chrome/browser/prerender/prerender_field_trial.h" 33 #include "chrome/browser/prerender/prerender_field_trial.h"
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 void OmniboxEditModel::SetUserText(const string16& text) { 219 void OmniboxEditModel::SetUserText(const string16& text) {
221 SetInputInProgress(true); 220 SetInputInProgress(true);
222 InternalSetUserText(text); 221 InternalSetUserText(text);
223 paste_state_ = NONE; 222 paste_state_ = NONE;
224 has_temporary_text_ = false; 223 has_temporary_text_ = false;
225 is_temporary_text_set_by_instant_ = false; 224 is_temporary_text_set_by_instant_ = false;
226 selected_instant_autocomplete_match_index_ = OmniboxPopupModel::kNoMatch; 225 selected_instant_autocomplete_match_index_ = OmniboxPopupModel::kNoMatch;
227 is_instant_temporary_text_a_search_query_ = false; 226 is_instant_temporary_text_a_search_query_ = false;
228 } 227 }
229 228
230 void OmniboxEditModel::FinalizeInstantQuery(
231 const string16& input_text,
232 const InstantSuggestion& suggestion) {
233 // Should only get called for the HTML popup.
234 #if defined(HTML_INSTANT_EXTENDED_POPUP)
235 if (!popup_model()->result().empty()) {
236 // When a IME is active and a candidate window is open, we don't show
237 // the omnibox popup, though |result()| may be available. Thus we check
238 // whether result().empty() or not instead of whether IsOpen() or not.
239 // We need the finalization of instant query when result() is available.
240 SearchProvider* search_provider =
241 autocomplete_controller()->search_provider();
242 // There may be no providers during testing; guard against that.
243 if (search_provider)
244 search_provider->FinalizeInstantQuery(input_text, suggestion);
245 }
246 #endif
247 }
248
249 void OmniboxEditModel::SetInstantSuggestion( 229 void OmniboxEditModel::SetInstantSuggestion(
250 const InstantSuggestion& suggestion) { 230 const InstantSuggestion& suggestion) {
251 // Should only get called for the HTML popup. 231 // Should only get called for the HTML popup.
252 #if defined(HTML_INSTANT_EXTENDED_POPUP) 232 #if defined(HTML_INSTANT_EXTENDED_POPUP)
253 switch (suggestion.behavior) { 233 switch (suggestion.behavior) {
254 case INSTANT_COMPLETE_NOW: 234 case INSTANT_COMPLETE_NOW:
255 view_->SetInstantSuggestion(string16()); 235 view_->SetInstantSuggestion(string16());
256 if (!suggestion.text.empty())
257 FinalizeInstantQuery(view_->GetText(), suggestion);
258 break; 236 break;
259 237
260 case INSTANT_COMPLETE_NEVER: { 238 case INSTANT_COMPLETE_NEVER: {
261 DCHECK_EQ(INSTANT_SUGGESTION_SEARCH, suggestion.type); 239 DCHECK_EQ(INSTANT_SUGGESTION_SEARCH, suggestion.type);
262 view_->SetInstantSuggestion(suggestion.text); 240 view_->SetInstantSuggestion(suggestion.text);
263 autocomplete_controller()->search_provider()->ClearInstantSuggestion();
264 break; 241 break;
265 } 242 }
266 243
267 case INSTANT_COMPLETE_REPLACE: { 244 case INSTANT_COMPLETE_REPLACE: {
268 const bool save_original_selection = !has_temporary_text_; 245 const bool save_original_selection = !has_temporary_text_;
269 view_->SetInstantSuggestion(string16()); 246 view_->SetInstantSuggestion(string16());
270 has_temporary_text_ = true; 247 has_temporary_text_ = true;
271 is_temporary_text_set_by_instant_ = true; 248 is_temporary_text_set_by_instant_ = true;
272 selected_instant_autocomplete_match_index_ = 249 selected_instant_autocomplete_match_index_ =
273 suggestion.autocomplete_match_index; 250 suggestion.autocomplete_match_index;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 performed_instant = omnibox_controller_->DoInstant( 313 performed_instant = omnibox_controller_->DoInstant(
337 current_match, user_text, view_->GetText(), start, end, 314 current_match, user_text, view_->GetText(), start, end,
338 user_input_in_progress_, in_escape_handler_, 315 user_input_in_progress_, in_escape_handler_,
339 view_->DeleteAtEndPressed() || just_deleted_text_, 316 view_->DeleteAtEndPressed() || just_deleted_text_,
340 KeywordIsSelected()); 317 KeywordIsSelected());
341 } 318 }
342 319
343 if (!performed_instant) { 320 if (!performed_instant) {
344 // Hide any suggestions we might be showing. 321 // Hide any suggestions we might be showing.
345 view_->SetInstantSuggestion(string16()); 322 view_->SetInstantSuggestion(string16());
346
347 // No need to wait any longer for Instant.
348 FinalizeInstantQuery(string16(), InstantSuggestion());
349 } 323 }
350 324
351 switch (recommended_action) { 325 switch (recommended_action) {
352 case AutocompleteActionPredictor::ACTION_PRERENDER: 326 case AutocompleteActionPredictor::ACTION_PRERENDER:
353 // It's possible that there is no current page, for instance if the tab 327 // It's possible that there is no current page, for instance if the tab
354 // has been closed or on return from a sleep state. 328 // has been closed or on return from a sleep state.
355 // (http://crbug.com/105689) 329 // (http://crbug.com/105689)
356 if (!delegate_->CurrentPageExists()) 330 if (!delegate_->CurrentPageExists())
357 break; 331 break;
358 // Ask for prerendering if the destination URL is different than the 332 // Ask for prerendering if the destination URL is different than the
(...skipping 1066 matching lines...) Expand 10 before | Expand all | Expand 10 after
1425 instant->OmniboxFocusChanged(state, reason, NULL); 1399 instant->OmniboxFocusChanged(state, reason, NULL);
1426 1400
1427 // Update state and notify view if the omnibox has focus and the caret 1401 // Update state and notify view if the omnibox has focus and the caret
1428 // visibility changed. 1402 // visibility changed.
1429 const bool was_caret_visible = is_caret_visible(); 1403 const bool was_caret_visible = is_caret_visible();
1430 focus_state_ = state; 1404 focus_state_ = state;
1431 if (focus_state_ != OMNIBOX_FOCUS_NONE && 1405 if (focus_state_ != OMNIBOX_FOCUS_NONE &&
1432 is_caret_visible() != was_caret_visible) 1406 is_caret_visible() != was_caret_visible)
1433 view_->ApplyCaretVisibility(); 1407 view_->ApplyCaretVisibility();
1434 } 1408 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698