Commit 513fa26d authored by pkasting@chromium.org's avatar pkasting@chromium.org

Handle view-source: URLs better in the history providers.

This makes fixup strip the "http://" scheme back out when the user didn't type
it, even when it was inserted after "view-source:".

This also fixes highlighting of such input in the resulting matches.

BUG=286451
TEST=Typing "view-source:x" doesn't crash, and highlights correctly in the dropdown
R=beaudoin@chromium.org

Review URL: https://codereview.chromium.org/23458032

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@222097 0039d316-1c4b-4281-b951-d872f2087c98
parent 8c0e82ad
...@@ -95,9 +95,7 @@ bool HistoryProvider::FixupUserInput(AutocompleteInput* input) { ...@@ -95,9 +95,7 @@ bool HistoryProvider::FixupUserInput(AutocompleteInput* input) {
string16 output = UTF8ToUTF16(canonical_gurl_str); string16 output = UTF8ToUTF16(canonical_gurl_str);
// Don't prepend a scheme when the user didn't have one. Since the fixer // 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. // upper only prepends the "http" scheme, that's all we need to check for.
if (canonical_gurl.SchemeIs(chrome::kHttpScheme) && if (!HasHTTPScheme(input_text))
!url_util::FindAndCompareScheme(UTF16ToUTF8(input_text),
chrome::kHttpScheme, NULL))
TrimHttpPrefix(&output); TrimHttpPrefix(&output);
// Make the number of trailing slashes on the output exactly match the input. // Make the number of trailing slashes on the output exactly match the input.
......
...@@ -344,6 +344,7 @@ AutocompleteMatch HistoryURLProvider::SuggestExactInput( ...@@ -344,6 +344,7 @@ AutocompleteMatch HistoryURLProvider::SuggestExactInput(
// |match_location| below. StringForURLDisplay() and TrimHttpPrefix() have // |match_location| below. StringForURLDisplay() and TrimHttpPrefix() have
// slightly different behavior as well (the latter will strip even without // slightly different behavior as well (the latter will strip even without
// two slashes after the scheme). // two slashes after the scheme).
DCHECK(!trim_http || !HasHTTPScheme(input.text()));
string16 display_string(provider->StringForURLDisplay(url, false, false)); string16 display_string(provider->StringForURLDisplay(url, false, false));
const size_t offset = trim_http ? TrimHttpPrefix(&display_string) : 0; const size_t offset = trim_http ? TrimHttpPrefix(&display_string) : 0;
match.fill_into_edit = match.fill_into_edit =
...@@ -360,21 +361,20 @@ AutocompleteMatch HistoryURLProvider::SuggestExactInput( ...@@ -360,21 +361,20 @@ AutocompleteMatch HistoryURLProvider::SuggestExactInput(
match.contents = display_string; match.contents = display_string;
const URLPrefix* best_prefix = URLPrefix::BestURLPrefix( const URLPrefix* best_prefix = URLPrefix::BestURLPrefix(
UTF8ToUTF16(match.destination_url.spec()), input.text()); UTF8ToUTF16(match.destination_url.spec()), input.text());
// It's possible for match.destination_url to not contain the user's input
// We only want to trim the HTTP scheme off our match if the user didn't // at all (so |best_prefix| is NULL), for example if the input is
// explicitly type "http:". // "view-source:x" and |destination_url| has an inserted "http://" in the
DCHECK(!trim_http || !HasHTTPScheme(input.text())); // middle.
if (best_prefix == NULL) {
// Because of the vagaries of GURL, it's possible for match.destination_url AutocompleteMatch::ClassifyMatchInString(input.text(), match.contents,
// to not contain the user's input at all (so |best_prefix| is NULL). ACMatchClassification::URL,
// In this case don't mark anything as a match. &match.contents_class);
const size_t match_location = (best_prefix == NULL) ? } else {
string16::npos : best_prefix->prefix.length() - offset; AutocompleteMatch::ClassifyLocationInString(
AutocompleteMatch::ClassifyLocationInString(match_location, best_prefix->prefix.length() - offset, input.text().length(),
input.text().length(), match.contents.length(), ACMatchClassification::URL,
match.contents.length(), &match.contents_class);
ACMatchClassification::URL, }
&match.contents_class);
match.is_history_what_you_typed_match = true; match.is_history_what_you_typed_match = true;
} }
......
...@@ -754,7 +754,8 @@ TEST_F(HistoryURLProviderTest, CrashDueToFixup) { ...@@ -754,7 +754,8 @@ TEST_F(HistoryURLProviderTest, CrashDueToFixup) {
// This test passes if we don't crash. The results don't matter. // This test passes if we don't crash. The results don't matter.
const char* const test_cases[] = { const char* const test_cases[] = {
"//c", "//c",
"\\@st" "\\@st",
"view-source:x",
}; };
for (size_t i = 0; i < arraysize(test_cases); ++i) { for (size_t i = 0; i < arraysize(test_cases); ++i) {
AutocompleteInput input(ASCIIToUTF16(test_cases[i]), string16::npos, AutocompleteInput input(ASCIIToUTF16(test_cases[i]), string16::npos,
...@@ -847,6 +848,8 @@ TEST_F(HistoryURLProviderTest, SuggestExactInput) { ...@@ -847,6 +848,8 @@ TEST_F(HistoryURLProviderTest, SuggestExactInput) {
"www.w.com", {0, npos, npos}, 0 }, "www.w.com", {0, npos, npos}, 0 },
{ "www.w.com", false, { "www.w.com", false,
"http://www.w.com", {0, 7, npos}, 1 }, "http://www.w.com", {0, 7, npos}, 1 },
{ "view-source:w", true,
"view-source:w", {0, npos, npos}, 0 },
{ "view-source:www.w.com/", true, { "view-source:www.w.com/", true,
"view-source:www.w.com", {0, npos, npos}, npos }, "view-source:www.w.com", {0, npos, npos}, npos },
{ "view-source:www.w.com/", false, { "view-source:www.w.com/", false,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment