summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-21 23:33:18 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-21 23:33:18 +0000
commit99ba0ce2e950180ee5df7aec2c800422203463af (patch)
tree39139fa90e0e2acc09514f946b98715c4ea4b7a4 /chrome/browser
parented04d9617d5f244efae81b237df7db41bc142cca (diff)
downloadchromium_src-99ba0ce2e950180ee5df7aec2c800422203463af.zip
chromium_src-99ba0ce2e950180ee5df7aec2c800422203463af.tar.gz
chromium_src-99ba0ce2e950180ee5df7aec2c800422203463af.tar.bz2
Better omnibox handling of numeric input. Now we search based on the user's original input instead of a transformed dotted quad when typing numeric hostnames; this should help noticeably in countries like China where such hostnames ("56.com") are popular.
Original patch by Fumitoshi Ukai (see http://codereview.chromium.org/88011 ), r=me. BUG=10054 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14156 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/autocomplete/history_url_provider.cc43
-rw-r--r--chrome/browser/autocomplete/history_url_provider.h2
-rw-r--r--chrome/browser/autocomplete/history_url_provider_unittest.cc12
3 files changed, 46 insertions, 11 deletions
diff --git a/chrome/browser/autocomplete/history_url_provider.cc b/chrome/browser/autocomplete/history_url_provider.cc
index 1aa7471..4ddeefd 100644
--- a/chrome/browser/autocomplete/history_url_provider.cc
+++ b/chrome/browser/autocomplete/history_url_provider.cc
@@ -357,20 +357,43 @@ bool HistoryURLProvider::PromoteMatchForInlineAutocomplete(
}
// static
-std::wstring HistoryURLProvider::FixupUserInput(const std::wstring& input) {
+std::wstring HistoryURLProvider::FixupUserInput(
+ const AutocompleteInput& input) {
+ const std::wstring& input_text = input.text();
// Fixup and canonicalize user input.
- const GURL canonical_gurl(URLFixerUpper::FixupURL(WideToUTF8(input),
+ const GURL canonical_gurl(URLFixerUpper::FixupURL(WideToUTF8(input_text),
std::string()));
- std::wstring output(UTF8ToWide(canonical_gurl.possibly_invalid_spec()));
- if (output.empty())
- return input; // This probably won't happen, but there are no guarantees.
+ 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.
+ return input_text;
+ }
+ // If the user types a number, GURL will convert it to a dotted quad.
+ // However, if the parser did not mark this as a URL, then the user probably
+ // didn't intend this interpretation. Since this can break history matching
+ // for hostname beginning with numbers (e.g. input of "17173" will be matched
+ // against "0.0.67.21" instead of the original "17173", failing to find
+ // "17173.com"), swap the original hostname in for the fixed-up one.
+ if ((input.type() != AutocompleteInput::URL) &&
+ canonical_gurl.HostIsIPAddress()) {
+ std::string original_hostname =
+ WideToUTF8(input_text.substr(input.parts().host.begin,
+ input.parts().host.len));
+ const url_parse::Parsed& parts =
+ canonical_gurl.parsed_for_possibly_invalid_spec();
+ // parts.host must not be empty when HostIsIPAddress() is true.
+ DCHECK(parts.host.is_nonempty());
+ canonical_gurl_str.replace(parts.host.begin, parts.host.len,
+ original_hostname);
+ }
+ std::wstring output(UTF8ToWide(canonical_gurl_str));
// Don't prepend a scheme when the user didn't have one. Since the fixer
// upper only prepends the "http" scheme, that's all we need to check for.
url_parse::Component scheme;
if (canonical_gurl.SchemeIs(chrome::kHttpScheme) &&
- !url_util::FindAndCompareScheme(WideToUTF8(input), chrome::kHttpScheme,
- &scheme))
+ !url_util::FindAndCompareScheme(WideToUTF8(input_text),
+ chrome::kHttpScheme, &scheme))
TrimHttpPrefix(&output);
// Make the number of trailing slashes on the output exactly match the input.
@@ -387,9 +410,9 @@ std::wstring HistoryURLProvider::FixupUserInput(const std::wstring& input) {
// trailing slashes (if the scheme is the only thing in the input). It's not
// clear that the result of fixup really matters in this case, but there's no
// harm in making sure.
- const size_t last_input_nonslash = input.find_last_not_of(L"/\\");
+ const size_t last_input_nonslash = input_text.find_last_not_of(L"/\\");
const size_t num_input_slashes = (last_input_nonslash == std::wstring::npos) ?
- input.length() : (input.length() - 1 - last_input_nonslash);
+ input_text.length() : (input_text.length() - 1 - last_input_nonslash);
const size_t last_output_nonslash = output.find_last_not_of(L"/\\");
const size_t num_output_slashes =
(last_output_nonslash == std::wstring::npos) ?
@@ -640,7 +663,7 @@ void HistoryURLProvider::RunAutocompletePasses(const AutocompleteInput& input,
// it did, then holding "ctrl" would change all the results from the
// HistoryURLProvider provider, not just the What You Typed Result.
AutocompleteInput fixed_input(input);
- const std::wstring fixed_text(FixupUserInput(input.text()));
+ const std::wstring fixed_text(FixupUserInput(input));
if (fixed_text.empty()) {
// Conceivably fixup could result in an empty string (although I don't
// have cases where this happens offhand). We can't do anything with
diff --git a/chrome/browser/autocomplete/history_url_provider.h b/chrome/browser/autocomplete/history_url_provider.h
index ff75a39..00e03da 100644
--- a/chrome/browser/autocomplete/history_url_provider.h
+++ b/chrome/browser/autocomplete/history_url_provider.h
@@ -258,7 +258,7 @@ class HistoryURLProvider : public AutocompleteProvider {
// Note that we don't do this in AutocompleteInput's constructor, because if
// e.g. we convert a Unicode hostname to punycode, other providers will show
// output that surprises the user ("Search Google for xn--6ca.com").
- static std::wstring FixupUserInput(const std::wstring& input);
+ static std::wstring FixupUserInput(const AutocompleteInput& input);
// Trims "http:" and up to two subsequent slashes from |url|. Returns the
// number of characters that were trimmed.
diff --git a/chrome/browser/autocomplete/history_url_provider_unittest.cc b/chrome/browser/autocomplete/history_url_provider_unittest.cc
index 0e0bef8..b4b7ee8 100644
--- a/chrome/browser/autocomplete/history_url_provider_unittest.cc
+++ b/chrome/browser/autocomplete/history_url_provider_unittest.cc
@@ -82,6 +82,9 @@ static TestURLInfo test_db[] = {
{"http://bogussite.com/a", L"Bogus A", 10002, 10000, false},
{"http://bogussite.com/b", L"Bogus B", 10001, 10000, false},
{"http://bogussite.com/c", L"Bogus C", 10000, 10000, false},
+
+ // Domain name with number.
+ {"http://www.17173.com/", L"Domain with number", 3, 3, false},
};
class HistoryURLProviderTest : public testing::Test,
@@ -351,4 +354,13 @@ TEST_F(HistoryURLProviderTest, Fixup) {
// rather than "0.0.0.56.com".
std::string fixup_3[] = {"http://www.56.com/"};
RunTest(L"56", L"com", true, fixup_3, arraysize(fixup_3));
+
+ // An input looks like a IP address like "127.0.0.1" should result in
+ // "http://127.0.0.1/".
+ std::string fixup_4[] = {"http://127.0.0.1/"};
+ RunTest(L"127.0.0.1", std::wstring(), false, fixup_4, arraysize(fixup_4));
+
+ // An number "17173" should result in "http://www.17173.com/" in db.
+ std::string fixup_5[] = {"http://www.17173.com/"};
+ RunTest(L"17173", std::wstring(), false, fixup_5, arraysize(fixup_5));
}