summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-08 23:03:49 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-08 23:03:49 +0000
commite918c1104a9341d331beb045c46a1c44d73c3b54 (patch)
tree9b448c92021f256dc8a7cc18623614c3dcd40116 /chrome/browser
parentcd8ee6d879df0e491a81f1d59ac8d982d7bdc2a8 (diff)
downloadchromium_src-e918c1104a9341d331beb045c46a1c44d73c3b54.zip
chromium_src-e918c1104a9341d331beb045c46a1c44d73c3b54.tar.gz
chromium_src-e918c1104a9341d331beb045c46a1c44d73c3b54.tar.bz2
Fixes bug in handling of spaces in the search provider. The problem
occurred because AutocompleteInput strips whitespace, but whitespace matters for suggest text. BUG=65701 TEST=see bug Review URL: http://codereview.chromium.org/5561008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68659 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/autocomplete/autocomplete.cc10
-rw-r--r--chrome/browser/autocomplete/autocomplete.h3
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit.cc6
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit.h3
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc3
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_mac.mm6
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_model.cc6
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_model.h3
-rw-r--r--chrome/browser/autocomplete/search_provider.cc36
-rw-r--r--chrome/browser/autocomplete/search_provider.h16
-rw-r--r--chrome/browser/gtk/location_bar_view_gtk.cc9
-rw-r--r--chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm9
-rw-r--r--chrome/browser/ui/views/location_bar/location_bar_view.cc12
13 files changed, 86 insertions, 36 deletions
diff --git a/chrome/browser/autocomplete/autocomplete.cc b/chrome/browser/autocomplete/autocomplete.cc
index b5c77f0..867cc07 100644
--- a/chrome/browser/autocomplete/autocomplete.cc
+++ b/chrome/browser/autocomplete/autocomplete.cc
@@ -82,14 +82,20 @@ AutocompleteInput::AutocompleteInput(const std::wstring& text,
canonicalized_url_ = canonicalized_url;
}
- if (type_ == FORCED_QUERY && text_[0] == L'?')
- text_.erase(0, 1);
+ RemoveForcedQueryStringIfNecessary(type_, &text_);
}
AutocompleteInput::~AutocompleteInput() {
}
// static
+void AutocompleteInput::RemoveForcedQueryStringIfNecessary(Type type,
+ std::wstring* text) {
+ if (type == FORCED_QUERY && !text->empty() && (*text)[0] == L'?')
+ text->erase(0, 1);
+}
+
+// static
std::string AutocompleteInput::TypeToString(Type type) {
switch (type) {
case INVALID: return "invalid";
diff --git a/chrome/browser/autocomplete/autocomplete.h b/chrome/browser/autocomplete/autocomplete.h
index dbf5c0e..8388265 100644
--- a/chrome/browser/autocomplete/autocomplete.h
+++ b/chrome/browser/autocomplete/autocomplete.h
@@ -188,6 +188,9 @@ class AutocompleteInput {
bool synchronous_only);
~AutocompleteInput();
+ // If type is |FORCED_QUERY| and |text| starts with '?', it is removed.
+ static void RemoveForcedQueryStringIfNecessary(Type type, std::wstring* text);
+
// Converts |type| to a string representation. Used in logging.
static std::string TypeToString(Type type);
diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc
index 69244ceb..8d31941 100644
--- a/chrome/browser/autocomplete/autocomplete_edit.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit.cc
@@ -158,8 +158,10 @@ void AutocompleteEditModel::SetUserText(const std::wstring& text) {
has_temporary_text_ = false;
}
-void AutocompleteEditModel::FinalizeInstantQuery(const std::wstring& text) {
- popup_->FinalizeInstantQuery(text);
+void AutocompleteEditModel::FinalizeInstantQuery(
+ const std::wstring& input_text,
+ const std::wstring& suggest_text) {
+ popup_->FinalizeInstantQuery(input_text, suggest_text);
}
void AutocompleteEditModel::GetDataForURLExport(GURL* url,
diff --git a/chrome/browser/autocomplete/autocomplete_edit.h b/chrome/browser/autocomplete/autocomplete_edit.h
index b9854ff..983a5f5 100644
--- a/chrome/browser/autocomplete/autocomplete_edit.h
+++ b/chrome/browser/autocomplete/autocomplete_edit.h
@@ -214,7 +214,8 @@ class AutocompleteEditModel : public NotificationObserver {
void SetUserText(const std::wstring& text);
// Calls through to SearchProvider::FinalizeInstantQuery.
- void FinalizeInstantQuery(const std::wstring& text);
+ void FinalizeInstantQuery(const std::wstring& input_text,
+ const std::wstring& suggest_text);
// Reverts the edit model back to its unedited state (permanent text showing,
// no user input in progress).
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
index e70dee8..f020e2e4 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
@@ -1798,7 +1798,8 @@ bool AutocompleteEditViewGtk::CommitInstantSuggestion() {
if (!suggestion || !*suggestion)
return false;
- model()->FinalizeInstantQuery(GetText() + UTF8ToWide(suggestion));
+ model()->FinalizeInstantQuery(GetText(),
+ UTF8ToWide(suggestion));
return true;
}
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
index 248a3b2..97981f9 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
@@ -477,10 +477,12 @@ bool AutocompleteEditViewMac::CommitSuggestText() {
if (suggest_text_length_ == 0)
return false;
+ std::wstring input_text(GetText());
suggest_text_length_ = 0;
+ std::wstring text(GetText());
// Call SetText() to force a redraw and move the cursor to the end.
- SetText(GetText());
- model()->FinalizeInstantQuery(GetText());
+ SetText(text);
+ model()->FinalizeInstantQuery(input_text, text.substr(input_text.size()));
return true;
}
diff --git a/chrome/browser/autocomplete/autocomplete_popup_model.cc b/chrome/browser/autocomplete/autocomplete_popup_model.cc
index af83a0d..6b4384e 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_model.cc
+++ b/chrome/browser/autocomplete/autocomplete_popup_model.cc
@@ -236,10 +236,12 @@ bool AutocompletePopupModel::GetKeywordForMatch(const AutocompleteMatch& match,
return true;
}
-void AutocompletePopupModel::FinalizeInstantQuery(const std::wstring& text) {
+void AutocompletePopupModel::FinalizeInstantQuery(
+ const std::wstring& input_text,
+ const std::wstring& suggest_text) {
if (IsOpen()) {
SearchProvider* search_provider = controller_->search_provider();
- search_provider->FinalizeInstantQuery(text);
+ search_provider->FinalizeInstantQuery(input_text, suggest_text);
}
}
diff --git a/chrome/browser/autocomplete/autocomplete_popup_model.h b/chrome/browser/autocomplete/autocomplete_popup_model.h
index 19bfae1..9c5384f 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_model.h
+++ b/chrome/browser/autocomplete/autocomplete_popup_model.h
@@ -100,7 +100,8 @@ class AutocompletePopupModel : public NotificationObserver {
std::wstring* keyword) const;
// Calls through to SearchProvider::FinalizeInstantQuery.
- void FinalizeInstantQuery(const std::wstring& text);
+ void FinalizeInstantQuery(const std::wstring& input_text,
+ const std::wstring& suggest_text);
// Returns a pointer to a heap-allocated AutocompleteLog containing the
// current input text, selected match, and result set. The caller is
diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc
index 2671828..bd5a949 100644
--- a/chrome/browser/autocomplete/search_provider.cc
+++ b/chrome/browser/autocomplete/search_provider.cc
@@ -63,20 +63,26 @@ SearchProvider::SearchProvider(ACProviderListener* listener, Profile* profile)
instant_finalized_(false) {
}
-void SearchProvider::FinalizeInstantQuery(const std::wstring& text) {
+void SearchProvider::FinalizeInstantQuery(const std::wstring& input_text,
+ const std::wstring& suggest_text) {
if (done_ || instant_finalized_)
return;
instant_finalized_ = true;
UpdateDone();
- if (text.empty()) {
+ if (input_text.empty()) {
// We only need to update the listener if we're actually done.
if (done_)
listener_->OnProviderUpdate(false);
return;
}
+ std::wstring adjusted_input_text(input_text);
+ AutocompleteInput::RemoveForcedQueryStringIfNecessary(input_.type(),
+ &adjusted_input_text);
+
+ const std::wstring text = adjusted_input_text + suggest_text;
// Remove any matches that are identical to |text|. We don't use the
// destination_url for comparison as it varies depending upon the index passed
// to TemplateURL::ReplaceSearchTerms.
@@ -96,9 +102,11 @@ void SearchProvider::FinalizeInstantQuery(const std::wstring& text) {
TemplateURLRef::NO_SUGGESTIONS_AVAILABLE :
TemplateURLRef::NO_SUGGESTION_CHOSEN;
MatchMap match_map;
- AddMatchToMap(text, CalculateRelevanceForWhatYouTyped() + 1,
+ AddMatchToMap(text, adjusted_input_text,
+ CalculateRelevanceForWhatYouTyped() + 1,
AutocompleteMatch::SEARCH_SUGGEST,
- did_not_accept_default_suggestion, false, &match_map);
+ did_not_accept_default_suggestion, false,
+ input_.initial_prevent_inline_autocomplete(), &match_map);
DCHECK_EQ(1u, match_map.size());
matches_.push_back(match_map.begin()->second);
@@ -507,9 +515,11 @@ void SearchProvider::ConvertResultsToAutocompleteMatches() {
TemplateURLRef::NO_SUGGESTIONS_AVAILABLE :
TemplateURLRef::NO_SUGGESTION_CHOSEN;
if (providers_.valid_default_provider()) {
- AddMatchToMap(input_.text(), CalculateRelevanceForWhatYouTyped(),
+ AddMatchToMap(input_.text(), input_.text(),
+ CalculateRelevanceForWhatYouTyped(),
AutocompleteMatch::SEARCH_WHAT_YOU_TYPED,
- did_not_accept_default_suggestion, false, &map);
+ did_not_accept_default_suggestion, false,
+ input_.initial_prevent_inline_autocomplete(), &map);
}
AddHistoryResultsToMap(keyword_history_results_, true,
@@ -564,9 +574,11 @@ void SearchProvider::AddHistoryResultsToMap(const HistoryResults& results,
for (HistoryResults::const_iterator i(results.begin()); i != results.end();
++i) {
AddMatchToMap(UTF16ToWide(i->term),
+ is_keyword ? keyword_input_text_ : input_.text(),
CalculateRelevanceForHistory(i->time, is_keyword),
AutocompleteMatch::SEARCH_HISTORY, did_not_accept_suggestion,
- is_keyword, map);
+ is_keyword, input_.initial_prevent_inline_autocomplete(),
+ map);
}
}
@@ -577,10 +589,12 @@ void SearchProvider::AddSuggestResultsToMap(
MatchMap* map) {
for (size_t i = 0; i < suggest_results.size(); ++i) {
AddMatchToMap(suggest_results[i],
+ is_keyword ? keyword_input_text_ : input_.text(),
CalculateRelevanceForSuggestion(suggest_results.size(), i,
is_keyword),
AutocompleteMatch::SEARCH_SUGGEST,
- static_cast<int>(i), is_keyword, map);
+ static_cast<int>(i), is_keyword,
+ input_.initial_prevent_inline_autocomplete(), map);
}
}
@@ -665,13 +679,13 @@ int SearchProvider::CalculateRelevanceForNavigation(size_t num_results,
}
void SearchProvider::AddMatchToMap(const std::wstring& query_string,
+ const std::wstring& input_text,
int relevance,
AutocompleteMatch::Type type,
int accepted_suggestion,
bool is_keyword,
+ bool prevent_inline_autocomplete,
MatchMap* map) {
- const std::wstring& input_text =
- is_keyword ? keyword_input_text_ : input_.text();
AutocompleteMatch match(this, relevance, false, type);
std::vector<size_t> content_param_offsets;
const TemplateURL& provider = is_keyword ? providers_.keyword_provider() :
@@ -736,7 +750,7 @@ void SearchProvider::AddMatchToMap(const std::wstring& query_string,
}
match.fill_into_edit.append(query_string);
// Not all suggestions start with the original input.
- if (!input_.prevent_inline_autocomplete() &&
+ if (!prevent_inline_autocomplete &&
!match.fill_into_edit.compare(search_start, input_text.length(),
input_text))
match.inline_autocomplete_offset = search_start + input_text.length();
diff --git a/chrome/browser/autocomplete/search_provider.h b/chrome/browser/autocomplete/search_provider.h
index 6667f1e..addd02e 100644
--- a/chrome/browser/autocomplete/search_provider.h
+++ b/chrome/browser/autocomplete/search_provider.h
@@ -52,10 +52,15 @@ class SearchProvider : public AutocompleteProvider,
}
#endif
- // Marks the instant query as done. If |text| is non-empty this changes the
- // 'search what you typed' results text to |text|. This also marks the search
- // provider as no longer needing to wait for the instant result.
- void FinalizeInstantQuery(const std::wstring& text);
+ // Marks the instant query as done. If |input_text| is non-empty this changes
+ // the 'search what you typed' results text to |input_text| + |suggest_text|.
+ // |input_text| is the text the user input into the edit. |input_text| differs
+ // from |input_.text()| if the input contained whitespace.
+ //
+ // This method also marks the search provider as no longer needing to wait for
+ // the instant result.
+ void FinalizeInstantQuery(const std::wstring& input_text,
+ const std::wstring& suggest_text);
// AutocompleteProvider
virtual void Start(const AutocompleteInput& input,
@@ -247,11 +252,14 @@ class SearchProvider : public AutocompleteProvider,
// the supplied relevance. Adds this match to |map|; if such a match already
// exists, whichever one has lower relevance is eliminated.
void AddMatchToMap(const std::wstring& query_string,
+ const std::wstring& input_text,
int relevance,
AutocompleteMatch::Type type,
int accepted_suggestion,
bool is_keyword,
+ bool prevent_inline_autocomplete,
MatchMap* map);
+
// Returns an AutocompleteMatch for a navigational suggestion.
AutocompleteMatch NavigationToMatch(const NavigationResult& query_string,
int relevance,
diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc
index b82bcfd..0602f3b 100644
--- a/chrome/browser/gtk/location_bar_view_gtk.cc
+++ b/chrome/browser/gtk/location_bar_view_gtk.cc
@@ -547,11 +547,14 @@ void LocationBarViewGtk::OnChanged() {
WideToUTF16(location_entry_->GetText()),
location_entry_->model()->UseVerbatimInstant(),
&suggested_text);
- if (!instant->MightSupportInstant())
- location_entry_->model()->FinalizeInstantQuery(std::wstring());
+ if (!instant->MightSupportInstant()) {
+ location_entry_->model()->FinalizeInstantQuery(std::wstring(),
+ std::wstring());
+ }
} else {
instant->DestroyPreviewContents();
- location_entry_->model()->FinalizeInstantQuery(std::wstring());
+ location_entry_->model()->FinalizeInstantQuery(std::wstring(),
+ std::wstring());
}
}
diff --git a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm
index d45e692..f1a69af 100644
--- a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm
+++ b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm
@@ -324,11 +324,14 @@ void LocationBarViewMac::OnChanged() {
WideToUTF16(edit_view_->GetText()),
edit_view_->model()->UseVerbatimInstant(),
&suggested_text);
- if (!instant->MightSupportInstant())
- edit_view_->model()->FinalizeInstantQuery(std::wstring());
+ if (!instant->MightSupportInstant()) {
+ edit_view_->model()->FinalizeInstantQuery(std::wstring(),
+ std::wstring());
+ }
} else {
instant->DestroyPreviewContents();
- edit_view_->model()->FinalizeInstantQuery(std::wstring());
+ edit_view_->model()->FinalizeInstantQuery(std::wstring(),
+ std::wstring());
}
}
diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.cc b/chrome/browser/ui/views/location_bar/location_bar_view.cc
index 8fe7bdb..4e9cdcf 100644
--- a/chrome/browser/ui/views/location_bar/location_bar_view.cc
+++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc
@@ -779,7 +779,8 @@ bool LocationBarView::OnCommitSuggestedText(const std::wstring& typed_text) {
return false;
}
location_entry_->model()->FinalizeInstantQuery(
- typed_text + suggested_text_view_->GetText());
+ typed_text,
+ suggested_text_view_->GetText());
return true;
}
@@ -852,11 +853,14 @@ void LocationBarView::OnChanged() {
WideToUTF16(location_entry_->GetText()),
location_entry_->model()->UseVerbatimInstant(),
&suggested_text);
- if (!instant->MightSupportInstant())
- location_entry_->model()->FinalizeInstantQuery(std::wstring());
+ if (!instant->MightSupportInstant()) {
+ location_entry_->model()->FinalizeInstantQuery(std::wstring(),
+ std::wstring());
+ }
} else {
instant->DestroyPreviewContents();
- location_entry_->model()->FinalizeInstantQuery(std::wstring());
+ location_entry_->model()->FinalizeInstantQuery(std::wstring(),
+ std::wstring());
}
}