From 76e7da2f3993ed156cc633d84f0c0d8ce3475e47 Mon Sep 17 00:00:00 2001 From: "pkasting@chromium.org" Date: Fri, 18 Jun 2010 22:44:49 +0000 Subject: 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 --- chrome/browser/autocomplete/autocomplete.cc | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'chrome/browser/autocomplete/autocomplete.cc') diff --git a/chrome/browser/autocomplete/autocomplete.cc b/chrome/browser/autocomplete/autocomplete.cc index d92677e..cdaa56f 100644 --- a/chrome/browser/autocomplete/autocomplete.cc +++ b/chrome/browser/autocomplete/autocomplete.cc @@ -572,23 +572,13 @@ void AutocompleteProvider::SetProfile(Profile* profile) { } // static -size_t AutocompleteProvider::TrimHttpPrefix(std::wstring* url) { +bool AutocompleteProvider::HasHTTPScheme(const std::wstring& input) { + std::string utf8_input(WideToUTF8(input)); url_parse::Component scheme; - if (!url_util::FindAndCompareScheme(WideToUTF8(*url), chrome::kHttpScheme, - &scheme)) - return 0; // Not "http". - - // Erase scheme plus up to two slashes. - size_t prefix_len = scheme.end() + 1; // "http:" - const size_t after_slashes = std::min(url->length(), - static_cast(scheme.end() + 3)); - while ((prefix_len < after_slashes) && ((*url)[prefix_len] == L'/')) - ++prefix_len; - if (prefix_len == url->length()) - url->clear(); - else - url->erase(url->begin(), url->begin() + prefix_len); - return prefix_len; + if (url_util::FindAndCompareScheme(utf8_input, chrome::kViewSourceScheme, + &scheme)) + utf8_input.erase(0, scheme.end() + 1); + return url_util::FindAndCompareScheme(utf8_input, chrome::kHttpScheme, NULL); } void AutocompleteProvider::UpdateStarredStateOfMatches() { -- cgit v1.1