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

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

Issue 23458032: Handle view-source: URLs better in the history providers. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 3 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/history_url_provider.cc
===================================================================
--- chrome/browser/autocomplete/history_url_provider.cc (revision 220656)
+++ chrome/browser/autocomplete/history_url_provider.cc (working copy)
@@ -344,6 +344,7 @@
// |match_location| below. StringForURLDisplay() and TrimHttpPrefix() have
// slightly different behavior as well (the latter will strip even without
// two slashes after the scheme).
+ DCHECK(!trim_http || !HasHTTPScheme(input.text()));
string16 display_string(provider->StringForURLDisplay(url, false, false));
const size_t offset = trim_http ? TrimHttpPrefix(&display_string) : 0;
match.fill_into_edit =
@@ -360,22 +361,21 @@
match.contents = display_string;
const URLPrefix* best_prefix = URLPrefix::BestURLPrefix(
UTF8ToUTF16(match.destination_url.spec()), input.text());
+ // It's possible for match.destination_url to not contain the user's input
+ // at all (so |best_prefix| is NULL), for example if the input is
+ // "view-source:x" and |destination_url| has an inserted "http://" in the
+ // middle.
+ if (best_prefix == NULL) {
+ AutocompleteMatch::ClassifyMatchInString(input.text(), match.contents,
+ ACMatchClassification::URL,
+ &match.contents_class);
+ } else {
+ AutocompleteMatch::ClassifyLocationInString(
+ best_prefix->prefix.length() - offset, input.text().length(),
+ match.contents.length(), ACMatchClassification::URL,
+ &match.contents_class);
+ }
- // We only want to trim the HTTP scheme off our match if the user didn't
- // explicitly type "http:".
- DCHECK(!trim_http || !HasHTTPScheme(input.text()));
-
- // Because of the vagaries of GURL, it's possible for match.destination_url
- // to not contain the user's input at all (so |best_prefix| is NULL).
- // In this case don't mark anything as a match.
- const size_t match_location = (best_prefix == NULL) ?
- string16::npos : best_prefix->prefix.length() - offset;
- AutocompleteMatch::ClassifyLocationInString(match_location,
- input.text().length(),
- match.contents.length(),
- ACMatchClassification::URL,
- &match.contents_class);
-
match.is_history_what_you_typed_match = true;
}
« no previous file with comments | « chrome/browser/autocomplete/history_provider.cc ('k') | chrome/browser/autocomplete/history_url_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698