Chromium Code Reviews| Index: chrome/browser/ui/omnibox/omnibox_edit_model.cc |
| diff --git a/chrome/browser/ui/omnibox/omnibox_edit_model.cc b/chrome/browser/ui/omnibox/omnibox_edit_model.cc |
| index 64c2a89c51e5208294a29af966db2457f1d36ff2..87bee737e0d0494171b61bc6c96a3b37833695af 100644 |
| --- a/chrome/browser/ui/omnibox/omnibox_edit_model.cc |
| +++ b/chrome/browser/ui/omnibox/omnibox_edit_model.cc |
| @@ -127,6 +127,7 @@ OmniboxEditModel::OmniboxEditModel(OmniboxView* view, |
| just_deleted_text_(false), |
| has_temporary_text_(false), |
| is_temporary_text_set_by_instant_(false), |
| + is_instant_temporary_text_a_search_query_(false), |
| paste_state_(NONE), |
| control_key_state_(UP), |
| is_keyword_hint_(false), |
| @@ -220,6 +221,7 @@ void OmniboxEditModel::SetUserText(const string16& text) { |
| paste_state_ = NONE; |
| has_temporary_text_ = false; |
| is_temporary_text_set_by_instant_ = false; |
| + is_instant_temporary_text_a_search_query_ = false; |
| } |
| void OmniboxEditModel::FinalizeInstantQuery(const string16& input_text, |
| @@ -252,10 +254,7 @@ void OmniboxEditModel::SetInstantSuggestion( |
| case INSTANT_COMPLETE_NEVER: { |
| DCHECK_EQ(INSTANT_SUGGESTION_SEARCH, suggestion.type); |
| view_->SetInstantSuggestion(suggestion.text); |
| - SearchProvider* search_provider = |
| - autocomplete_controller()->search_provider(); |
| - if (search_provider) |
| - search_provider->ClearInstantSuggestion(); |
| + autocomplete_controller()->search_provider()->ClearInstantSuggestion(); |
| break; |
| } |
| @@ -264,6 +263,8 @@ void OmniboxEditModel::SetInstantSuggestion( |
| view_->SetInstantSuggestion(string16()); |
| has_temporary_text_ = true; |
| is_temporary_text_set_by_instant_ = true; |
| + is_instant_temporary_text_a_search_query_ = |
| + suggestion.type == INSTANT_SUGGESTION_SEARCH; |
| // Instant suggestions are never a keyword. |
| keyword_ = string16(); |
| is_keyword_hint_ = false; |
| @@ -478,6 +479,7 @@ void OmniboxEditModel::Revert() { |
| is_keyword_hint_ = false; |
| has_temporary_text_ = false; |
| is_temporary_text_set_by_instant_ = false; |
| + is_instant_temporary_text_a_search_query_ = false; |
| view_->SetWindowTextAndCaretPos(permanent_text_, |
| has_focus() ? permanent_text_.length() : 0, |
| false, true); |
| @@ -772,6 +774,7 @@ bool OmniboxEditModel::AcceptKeyword(EnteredKeywordModeMethod entered_method) { |
| bool save_original_selection = !has_temporary_text_; |
| has_temporary_text_ = true; |
| is_temporary_text_set_by_instant_ = false; |
| + is_instant_temporary_text_a_search_query_ = false; |
| view_->OnTemporaryTextMaybeChanged( |
| DisplayTextFromUserText(CurrentMatch().fill_into_edit), |
| save_original_selection, true); |
| @@ -911,6 +914,7 @@ void OmniboxEditModel::OnControlKeyChanged(bool pressed) { |
| InternalSetUserText(UserTextFromDisplayText(view_->GetText())); |
| has_temporary_text_ = false; |
| is_temporary_text_set_by_instant_ = false; |
| + is_instant_temporary_text_a_search_query_ = false; |
| } |
| if ((old_state != DOWN_WITH_CHANGE) && popup_->IsOpen()) { |
| // Autocomplete history provider results may change, so refresh the |
| @@ -979,6 +983,7 @@ void OmniboxEditModel::OnPopupDataChanged( |
| // Save the original selection and URL so it can be reverted later. |
| has_temporary_text_ = true; |
| is_temporary_text_set_by_instant_ = false; |
| + is_instant_temporary_text_a_search_query_ = false; |
| original_url_ = *destination_for_temporary_text_change; |
| inline_autocomplete_text_.clear(); |
| } |
| @@ -1084,6 +1089,7 @@ bool OmniboxEditModel::OnAfterPossibleChange(const string16& old_text, |
| InternalSetUserText(UserTextFromDisplayText(new_text)); |
| has_temporary_text_ = false; |
| is_temporary_text_set_by_instant_ = false; |
| + is_instant_temporary_text_a_search_query_ = false; |
| // Track when the user has deleted text so we won't allow inline |
| // autocomplete. |
| @@ -1188,6 +1194,7 @@ void OmniboxEditModel::OnResultChanged(bool default_match_changed) { |
| InternalSetUserText(UserTextFromDisplayText(view_->GetText())); |
| has_temporary_text_ = false; |
| is_temporary_text_set_by_instant_ = false; |
| + is_instant_temporary_text_a_search_query_ = false; |
| OnPopupBoundsChanged(gfx::Rect()); |
| delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_); |
| } |
| @@ -1251,9 +1258,36 @@ void OmniboxEditModel::InfoForCurrentSelection(AutocompleteMatch* match, |
| void OmniboxEditModel::GetInfoForCurrentText(AutocompleteMatch* match, |
| GURL* alternate_nav_url) const { |
| // If there's temporary text and it has been set by Instant, we won't find it |
| - // in the popup model, so classify the text anew. |
| - if ((popup_->IsOpen() || query_in_progress()) && |
| - !is_temporary_text_set_by_instant_) { |
| + // in the popup model, so create the match based on the type Instant told us |
| + // (SWYT for queries and UWYT for URLs). We do this instead of classifying the |
| + // text ourselves because the text may look like a URL, but Instant may expect |
| + // it to be a search (e.g.: a query for "amazon.com"). |
| + if (is_temporary_text_set_by_instant_) { |
| + const string16& text = view_->GetText(); |
| + AutocompleteInput input(text, string16::npos, string16(), GURL(), false, |
| + false, false, AutocompleteInput::BEST_MATCH); |
| + // Only the destination_url and the transition of the match will be be used |
| + // (to either navigate to the URL or let Instant commit its preview). The |
| + // match won't be used for logging, displaying in the dropdown, etc. So, |
| + // it's okay to pass in mostly bogus params (such as relevance = 0). |
| + // TODO(sreeram): Always using NO_SUGGESTIONS_AVAILABLE is wrong when |
| + // Instant is using the local fallback overlay. Fix. |
| + if (is_instant_temporary_text_a_search_query_) { |
| + const TemplateURL* default_provider = |
| + TemplateURLServiceFactory::GetForProfile(profile_)-> |
| + GetDefaultSearchProvider(); |
| + DCHECK(default_provider); |
| + DCHECK(default_provider->SupportsReplacement()); |
|
Peter Kasting
2013/04/27 02:15:26
I'm nervous about these two DCHECKs. I think they
sreeram
2013/04/27 02:21:56
Done. I had added the DCHECK because Instant now l
|
| + *match = SearchProvider::CreateSearchSuggestion(profile_, |
| + autocomplete_controller()->search_provider(), input, text, text, 0, |
| + AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, |
| + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, false, |
| + default_provider->keyword()); |
| + } else { |
| + *match = HistoryURLProvider::SuggestExactInput( |
| + autocomplete_controller()->history_url_provider(), input, false); |
| + } |
| + } else if (popup_->IsOpen() || query_in_progress()) { |
| InfoForCurrentSelection(match, alternate_nav_url); |
| } else { |
| AutocompleteClassifierFactory::GetForProfile(profile_)->Classify( |
| @@ -1270,6 +1304,7 @@ void OmniboxEditModel::RevertTemporaryText(bool revert_popup) { |
| just_deleted_text_ = false; |
| has_temporary_text_ = false; |
| is_temporary_text_set_by_instant_ = false; |
| + is_instant_temporary_text_a_search_query_ = false; |
| InstantController* instant = controller_->GetInstant(); |
| if (instant && notify_instant) { |
| @@ -1340,9 +1375,9 @@ bool OmniboxEditModel::DoInstant(const AutocompleteMatch& match) { |
| if (!instant || in_revert_) |
| return false; |
| - // Don't call Update() if the change is a result of a |
| + // Don't call Update() if the change is the result of an |
| // INSTANT_COMPLETE_REPLACE instant suggestion. |
| - if (has_temporary_text_ && is_temporary_text_set_by_instant_) |
| + if (is_temporary_text_set_by_instant_) |
| return false; |
| // The two pieces of text we want to send Instant, viz., what the user has |