Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(826)

Side by Side Diff: chrome/browser/autocomplete/history_url_provider.cc

Issue 23458032: Handle view-source: URLs better in the history providers. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/autocomplete/history_url_provider.h" 5 #include "chrome/browser/autocomplete/history_url_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 const GURL& url = input.canonicalized_url(); 337 const GURL& url = input.canonicalized_url();
338 if (url.is_valid()) { 338 if (url.is_valid()) {
339 match.destination_url = url; 339 match.destination_url = url;
340 340
341 // Trim off "http://" if the user didn't type it. 341 // Trim off "http://" if the user didn't type it.
342 // NOTE: We use TrimHttpPrefix() here rather than StringForURLDisplay() to 342 // NOTE: We use TrimHttpPrefix() here rather than StringForURLDisplay() to
343 // strip the scheme as we need to know the offset so we can adjust the 343 // strip the scheme as we need to know the offset so we can adjust the
344 // |match_location| below. StringForURLDisplay() and TrimHttpPrefix() have 344 // |match_location| below. StringForURLDisplay() and TrimHttpPrefix() have
345 // slightly different behavior as well (the latter will strip even without 345 // slightly different behavior as well (the latter will strip even without
346 // two slashes after the scheme). 346 // two slashes after the scheme).
347 DCHECK(!trim_http || !HasHTTPScheme(input.text()));
347 string16 display_string(provider->StringForURLDisplay(url, false, false)); 348 string16 display_string(provider->StringForURLDisplay(url, false, false));
348 const size_t offset = trim_http ? TrimHttpPrefix(&display_string) : 0; 349 const size_t offset = trim_http ? TrimHttpPrefix(&display_string) : 0;
349 match.fill_into_edit = 350 match.fill_into_edit =
350 AutocompleteInput::FormattedStringWithEquivalentMeaning(url, 351 AutocompleteInput::FormattedStringWithEquivalentMeaning(url,
351 display_string); 352 display_string);
352 match.allowed_to_be_default_match = true; 353 match.allowed_to_be_default_match = true;
353 // NOTE: Don't set match.inline_autocompletion to something non-empty here; 354 // NOTE: Don't set match.inline_autocompletion to something non-empty here;
354 // it's surprising and annoying. 355 // it's surprising and annoying.
355 356
356 // Try to highlight "innermost" match location. If we fix up "w" into 357 // Try to highlight "innermost" match location. If we fix up "w" into
357 // "www.w.com", we want to highlight the fifth character, not the first. 358 // "www.w.com", we want to highlight the fifth character, not the first.
358 // This relies on match.destination_url being the non-prefix-trimmed version 359 // This relies on match.destination_url being the non-prefix-trimmed version
359 // of match.contents. 360 // of match.contents.
360 match.contents = display_string; 361 match.contents = display_string;
361 const URLPrefix* best_prefix = URLPrefix::BestURLPrefix( 362 const URLPrefix* best_prefix = URLPrefix::BestURLPrefix(
362 UTF8ToUTF16(match.destination_url.spec()), input.text()); 363 UTF8ToUTF16(match.destination_url.spec()), input.text());
363 364 // It's possible for match.destination_url to not contain the user's input
364 // We only want to trim the HTTP scheme off our match if the user didn't 365 // at all (so |best_prefix| is NULL), for example if the input is
365 // explicitly type "http:". 366 // "view-source:x" and |destination_url| has an inserted "http://" in the
366 DCHECK(!trim_http || !HasHTTPScheme(input.text())); 367 // middle.
367 368 if (best_prefix == NULL) {
368 // Because of the vagaries of GURL, it's possible for match.destination_url 369 AutocompleteMatch::ClassifyMatchInString(input.text(), match.contents,
369 // to not contain the user's input at all (so |best_prefix| is NULL). 370 ACMatchClassification::URL,
370 // In this case don't mark anything as a match. 371 &match.contents_class);
371 const size_t match_location = (best_prefix == NULL) ? 372 } else {
372 string16::npos : best_prefix->prefix.length() - offset; 373 AutocompleteMatch::ClassifyLocationInString(
373 AutocompleteMatch::ClassifyLocationInString(match_location, 374 best_prefix->prefix.length() - offset, input.text().length(),
374 input.text().length(), 375 match.contents.length(), ACMatchClassification::URL,
375 match.contents.length(), 376 &match.contents_class);
376 ACMatchClassification::URL, 377 }
377 &match.contents_class);
378 378
379 match.is_history_what_you_typed_match = true; 379 match.is_history_what_you_typed_match = true;
380 } 380 }
381 381
382 return match; 382 return match;
383 } 383 }
384 384
385 void HistoryURLProvider::Start(const AutocompleteInput& input, 385 void HistoryURLProvider::Start(const AutocompleteInput& input,
386 bool minimal_changes) { 386 bool minimal_changes) {
387 // NOTE: We could try hard to do less work in the |minimal_changes| case 387 // NOTE: We could try hard to do less work in the |minimal_changes| case
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 &match.contents_class); 1088 &match.contents_class);
1089 } 1089 }
1090 match.description = info.title(); 1090 match.description = info.title();
1091 AutocompleteMatch::ClassifyMatchInString(params->input.text(), 1091 AutocompleteMatch::ClassifyMatchInString(params->input.text(),
1092 info.title(), 1092 info.title(),
1093 ACMatchClassification::NONE, 1093 ACMatchClassification::NONE,
1094 &match.description_class); 1094 &match.description_class);
1095 RecordAdditionalInfoFromUrlRow(info, &match); 1095 RecordAdditionalInfoFromUrlRow(info, &match);
1096 return match; 1096 return match;
1097 } 1097 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/history_provider.cc ('k') | chrome/browser/autocomplete/history_url_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698