summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autocomplete/autocomplete.cc
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-02 02:37:40 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-02 02:37:40 +0000
commit79845effcd569cb61784e8a8c221f839e6e23525 (patch)
treed86e942097765499876b48a5d764592e2b9c376f /chrome/browser/autocomplete/autocomplete.cc
parent9902c201466fe4a701f43a124f4d22b6829c87e6 (diff)
downloadchromium_src-79845effcd569cb61784e8a8c221f839e6e23525.zip
chromium_src-79845effcd569cb61784e8a8c221f839e6e23525.tar.gz
chromium_src-79845effcd569cb61784e8a8c221f839e6e23525.tar.bz2
Strip the trailing slash from URLs like "http://google.com/". This especially helps when the scheme has also been stripped, as it makes the hostname look less unbalanced. We're careful to avoid stripping the slash when doing so would confuse the omnibox.
This also moves to more aggressive stripping and/or unescaping in several places. In general, it seems like we should be as aggressive as is feasible. BUG=43587 TEST=Visit google.com. There should be no slash in the address bar. Review URL: http://codereview.chromium.org/2389002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48691 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete/autocomplete.cc')
-rw-r--r--chrome/browser/autocomplete/autocomplete.cc35
1 files changed, 23 insertions, 12 deletions
diff --git a/chrome/browser/autocomplete/autocomplete.cc b/chrome/browser/autocomplete/autocomplete.cc
index 035a1ea..d92677e 100644
--- a/chrome/browser/autocomplete/autocomplete.cc
+++ b/chrome/browser/autocomplete/autocomplete.cc
@@ -90,8 +90,6 @@ AutocompleteInput::Type AutocompleteInput::Parse(
const std::wstring& desired_tld,
url_parse::Parsed* parts,
std::wstring* scheme) {
- DCHECK(parts);
-
const size_t first_non_white = text.find_first_not_of(kWhitespaceWide, 0);
if (first_non_white == std::wstring::npos)
return INVALID; // All whitespace.
@@ -106,6 +104,9 @@ AutocompleteInput::Type AutocompleteInput::Parse(
// use the URLFixerUpper here because we want to be smart about what we
// consider a scheme. For example, we shouldn't consider www.google.com:80
// to have a scheme.
+ url_parse::Parsed local_parts;
+ if (!parts)
+ parts = &local_parts;
const std::wstring parsed_scheme(URLFixerUpper::SegmentURL(text, parts));
if (scheme)
*scheme = parsed_scheme;
@@ -344,6 +345,19 @@ void AutocompleteInput::ParseForEmphasizeComponents(
}
}
+// static
+std::wstring AutocompleteInput::FormattedStringWithEquivalentMeaning(
+ const GURL& url,
+ const std::wstring& formatted_url) {
+ if (!net::CanStripTrailingSlash(url))
+ return formatted_url;
+ const std::wstring url_with_path(formatted_url + L"/");
+ return (AutocompleteInput::Parse(formatted_url, std::wstring(), NULL, NULL) ==
+ AutocompleteInput::Parse(url_with_path, std::wstring(), NULL, NULL)) ?
+ formatted_url : url_with_path;
+}
+
+
bool AutocompleteInput::Equals(const AutocompleteInput& other) const {
return (text_ == other.text_) &&
(type_ == other.type_) &&
@@ -591,16 +605,13 @@ void AutocompleteProvider::UpdateStarredStateOfMatches() {
i->starred = bookmark_model->IsBookmarked(GURL(i->destination_url));
}
-std::wstring AutocompleteProvider::StringForURLDisplay(
- const GURL& url,
- bool check_accept_lang,
- bool trim_http) const {
- std::wstring languages = (check_accept_lang && profile_) ?
- profile_->GetPrefs()->GetString(prefs::kAcceptLanguages) : std::wstring();
- const net::FormatUrlTypes format_types = trim_http ?
- net::kFormatUrlOmitAll : net::kFormatUrlOmitUsernamePassword;
- return net::FormatUrl(url, languages, format_types, UnescapeRule::SPACES,
- NULL, NULL, NULL);
+std::wstring AutocompleteProvider::StringForURLDisplay(const GURL& url,
+ bool check_accept_lang,
+ bool trim_http) const {
+ return net::FormatUrl(url, (check_accept_lang && profile_) ?
+ profile_->GetPrefs()->GetString(prefs::kAcceptLanguages) : std::wstring(),
+ net::kFormatUrlOmitAll & ~(trim_http ? 0 : net::kFormatUrlOmitHTTP),
+ UnescapeRule::SPACES, NULL, NULL, NULL);
}
// AutocompleteResult ---------------------------------------------------------