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

Unified Diff: chrome/browser/autocomplete/autocomplete_match.cc

Issue 353223002: Omnibox: Fix URL-What-You-Typed Allowed-To-Be-Default-Match Issues (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: polish Created 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/autocomplete/autocomplete_match.cc
diff --git a/chrome/browser/autocomplete/autocomplete_match.cc b/chrome/browser/autocomplete/autocomplete_match.cc
index 37dfca009444ba0485cc889be725d86c9d63c2d6..091775b1a27cbd1b61a674caf9b5b0a0da6a9baf 100644
--- a/chrome/browser/autocomplete/autocomplete_match.cc
+++ b/chrome/browser/autocomplete/autocomplete_match.cc
@@ -345,17 +345,21 @@ bool AutocompleteMatch::IsSpecializedSearchType(Type type) {
type == AutocompleteMatchType::SEARCH_SUGGEST_ANSWER;
}
-void AutocompleteMatch::ComputeStrippedDestinationURL(Profile* profile) {
- stripped_destination_url = destination_url;
- if (!stripped_destination_url.is_valid())
- return;
+// static
+GURL AutocompleteMatch::GURLToStrippedGURL(
+ const GURL& url, Profile* profile, const base::string16& keyword) {
Peter Kasting 2014/06/30 23:02:58 Nit: One arg per line
Mark P 2014/06/30 23:27:36 Done.
+ if (!url.is_valid())
+ return url;
+
+ GURL stripped_destination_url = url;
// If the destination URL looks like it was generated from a TemplateURL,
// remove all substitutions other than the search terms. This allows us
// to eliminate cases like past search URLs from history that differ only
// by some obscure query param from each other or from the search/keyword
// provider matches.
- TemplateURL* template_url = GetTemplateURL(profile, true);
+ TemplateURL* template_url = GetTemplateURLWithKeyword(
+ profile, keyword, stripped_destination_url.host());
UIThreadSearchTermsData search_terms_data(profile);
if (template_url != NULL &&
template_url->SupportsReplacement(search_terms_data)) {
@@ -397,6 +401,12 @@ void AutocompleteMatch::ComputeStrippedDestinationURL(Profile* profile) {
if (needs_replacement)
stripped_destination_url = stripped_destination_url.ReplaceComponents(
replacements);
+ return stripped_destination_url;
+}
+
+void AutocompleteMatch::ComputeStrippedDestinationURL(Profile* profile) {
+ stripped_destination_url =
+ GURLToStrippedGURL(destination_url, profile, keyword);
}
void AutocompleteMatch::GetKeywordUIState(Profile* profile,
@@ -419,6 +429,17 @@ base::string16 AutocompleteMatch::GetSubstitutingExplicitlyInvokedKeyword(
TemplateURL* AutocompleteMatch::GetTemplateURL(
Profile* profile, bool allow_fallback_to_destination_host) const {
+ return GetTemplateURLWithKeyword(
+ profile, keyword,
+ allow_fallback_to_destination_host ? destination_url.host()
Peter Kasting 2014/06/30 23:02:58 Nit: Break after '?' instead of before ':' (aka I
Mark P 2014/06/30 23:27:36 Done.
+ : std::string());
+}
+
+// static
+TemplateURL* AutocompleteMatch::GetTemplateURLWithKeyword(
+ Profile* profile,
+ const base::string16& keyword,
+ const std::string& host) {
DCHECK(profile);
TemplateURLService* template_url_service =
TemplateURLServiceFactory::GetForProfile(profile);
@@ -426,9 +447,8 @@ TemplateURL* AutocompleteMatch::GetTemplateURL(
return NULL;
TemplateURL* template_url = keyword.empty() ? NULL :
template_url_service->GetTemplateURLForKeyword(keyword);
- if (template_url == NULL && allow_fallback_to_destination_host) {
- template_url = template_url_service->GetTemplateURLForHost(
- destination_url.host());
+ if (template_url == NULL && !host.empty()) {
+ template_url = template_url_service->GetTemplateURLForHost(host);
}
return template_url;
}

Powered by Google App Engine
This is Rietveld 408576698