diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-18 22:44:49 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-18 22:44:49 +0000 |
commit | 76e7da2f3993ed156cc633d84f0c0d8ce3475e47 (patch) | |
tree | 0bf83bcc78d1c22ce608289415d1bcd39761694c /chrome/browser/autocomplete/history_url_provider.cc | |
parent | 2f1412eee183dfb9e04777827aae4a8766fc9f45 (diff) | |
download | chromium_src-76e7da2f3993ed156cc633d84f0c0d8ce3475e47.zip chromium_src-76e7da2f3993ed156cc633d84f0c0d8ce3475e47.tar.gz chromium_src-76e7da2f3993ed156cc633d84f0c0d8ce3475e47.tar.bz2 |
Make FixupURL() return a GURL instead of a string (i.e. do fixup + canonicalization). Nearly every caller was already doing this.
This in turn allows us to do better fixup/canonicalization of view-source: URLs. We now convert "view-source:google.com" into "view-source:http://google.com/".
With a few changes scattered through the omnibox code, this also means we can do HTTP-stripping on view-source: URLs, and support the user typing in things like the case above. This also fixes some weirdness where if you tried to type something starting with "view-source:", the What You Typed match in the dropdown would show only a scheme, or a scheme plus "http:", in some cases.
BUG=46612
TEST="view-source:google.com" should work.
Review URL: http://codereview.chromium.org/2817011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50290 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete/history_url_provider.cc')
-rw-r--r-- | chrome/browser/autocomplete/history_url_provider.cc | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/chrome/browser/autocomplete/history_url_provider.cc b/chrome/browser/autocomplete/history_url_provider.cc index 703b909..1952a65 100644 --- a/chrome/browser/autocomplete/history_url_provider.cc +++ b/chrome/browser/autocomplete/history_url_provider.cc @@ -365,7 +365,7 @@ std::wstring HistoryURLProvider::FixupUserInput( const std::wstring& input_text = input.text(); // Fixup and canonicalize user input. const GURL canonical_gurl(URLFixerUpper::FixupURL(WideToUTF8(input_text), - std::string())); + std::string())); std::string canonical_gurl_str(canonical_gurl.possibly_invalid_spec()); if (canonical_gurl_str.empty()) { // This probably won't happen, but there are no guarantees. @@ -428,6 +428,23 @@ std::wstring HistoryURLProvider::FixupUserInput( } // static +size_t HistoryURLProvider::TrimHttpPrefix(std::wstring* url) { + // Find any "http:". + if (!HasHTTPScheme(*url)) + return 0; + size_t scheme_pos = url->find(ASCIIToWide(chrome::kHttpScheme) + L":"); + DCHECK(scheme_pos != std::wstring::npos); + + // Erase scheme plus up to two slashes. + size_t prefix_end = scheme_pos + strlen(chrome::kHttpScheme) + 1; + const size_t after_slashes = std::min(url->length(), prefix_end + 2); + while ((prefix_end < after_slashes) && ((*url)[prefix_end] == L'/')) + ++prefix_end; + url->erase(scheme_pos, prefix_end - scheme_pos); + return (scheme_pos == 0) ? prefix_end : 0; +} + +// static bool HistoryURLProvider::IsHostOnly(const GURL& url) { DCHECK(url.is_valid()); return (!url.has_path() || (url.path() == "/")) && !url.has_query() && @@ -627,8 +644,7 @@ void HistoryURLProvider::RunAutocompletePasses( // Create a match for exactly what the user typed. This will only be used as // a fallback in case we can't get the history service or URL DB; otherwise, // we'll run this again in DoAutocomplete() and use that result instead. - const bool trim_http = !url_util::FindAndCompareScheme( - WideToUTF8(input.text()), chrome::kHttpScheme, NULL); + const bool trim_http = !HasHTTPScheme(input.text()); // Don't do this for queries -- while we can sometimes mark up a match for // this, it's not what the user wants, and just adds noise. if ((input.type() != AutocompleteInput::QUERY) && |