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) {
string16 output = UTF8ToUTF16(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.
if (canonical_gurl.SchemeIs(chrome::kHttpScheme) &&
!url_util::FindAndCompareScheme(UTF16ToUTF8(input_text),
chrome::kHttpScheme, NULL))
if (!HasHTTPScheme(input_text))
TrimHttpPrefix(&output);
// Make the number of trailing slashes on the output exactly match the input.
......
......@@ -344,6 +344,7 @@ AutocompleteMatch HistoryURLProvider::SuggestExactInput(
// |match_location| below. StringForURLDisplay() and TrimHttpPrefix() have
// slightly different behavior as well (the latter will strip even without
// two slashes after the scheme).
DCHECK(!trim_http || !HasHTTPScheme(input.text()));
string16 display_string(provider->StringForURLDisplay(url, false, false));
const size_t offset = trim_http ? TrimHttpPrefix(&display_string) : 0;
match.fill_into_edit =
......@@ -360,21 +361,20 @@ AutocompleteMatch HistoryURLProvider::SuggestExactInput(
match.contents = display_string;
const URLPrefix* best_prefix = URLPrefix::BestURLPrefix(
UTF8ToUTF16(match.destination_url.spec()), input.text());
// We only want to trim the HTTP scheme off our match if the user didn't
// explicitly type "http:".
DCHECK(!trim_http || !HasHTTPScheme(input.text()));
// Because of the vagaries of GURL, it's possible for match.destination_url
// to not contain the user's input at all (so |best_prefix| is NULL).
// In this case don't mark anything as a match.
const size_t match_location = (best_prefix == NULL) ?
string16::npos : best_prefix->prefix.length() - offset;
AutocompleteMatch::ClassifyLocationInString(match_location,
input.text().length(),
match.contents.length(),
ACMatchClassification::URL,
&match.contents_class);
// It's possible for match.destination_url to not contain the user's input
// at all (so |best_prefix| is NULL), for example if the input is
// "view-source:x" and |destination_url| has an inserted "http://" in the
// middle.
if (best_prefix == NULL) {
AutocompleteMatch::ClassifyMatchInString(input.text(), match.contents,
ACMatchClassification::URL,
&match.contents_class);
} else {
AutocompleteMatch::ClassifyLocationInString(
best_prefix->prefix.length() - offset, input.text().length(),
match.contents.length(), ACMatchClassification::URL,
&match.contents_class);
}
match.is_history_what_you_typed_match = true;
}
......
......@@ -754,7 +754,8 @@ TEST_F(HistoryURLProviderTest, CrashDueToFixup) {
// This test passes if we don't crash. The results don't matter.
const char* const test_cases[] = {
"//c",
"\\@st"
"\\@st",
"view-source:x",
};
for (size_t i = 0; i < arraysize(test_cases); ++i) {
AutocompleteInput input(ASCIIToUTF16(test_cases[i]), string16::npos,
......@@ -847,6 +848,8 @@ TEST_F(HistoryURLProviderTest, SuggestExactInput) {
"www.w.com", {0, npos, npos}, 0 },
{ "www.w.com", false,
"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", {0, npos, npos}, npos },
{ "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