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

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

Issue 115885: Hoist TrimHttpPrefix() so we only have one copy, not one per provider.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 6 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/histogram.h" 10 #include "base/histogram.h"
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 const url_parse::Parsed& parts = 365 const url_parse::Parsed& parts =
366 canonical_gurl.parsed_for_possibly_invalid_spec(); 366 canonical_gurl.parsed_for_possibly_invalid_spec();
367 // parts.host must not be empty when HostIsIPAddress() is true. 367 // parts.host must not be empty when HostIsIPAddress() is true.
368 DCHECK(parts.host.is_nonempty()); 368 DCHECK(parts.host.is_nonempty());
369 canonical_gurl_str.replace(parts.host.begin, parts.host.len, 369 canonical_gurl_str.replace(parts.host.begin, parts.host.len,
370 original_hostname); 370 original_hostname);
371 } 371 }
372 std::wstring output(UTF8ToWide(canonical_gurl_str)); 372 std::wstring output(UTF8ToWide(canonical_gurl_str));
373 // Don't prepend a scheme when the user didn't have one. Since the fixer 373 // Don't prepend a scheme when the user didn't have one. Since the fixer
374 // upper only prepends the "http" scheme, that's all we need to check for. 374 // upper only prepends the "http" scheme, that's all we need to check for.
375 url_parse::Component scheme;
376 if (canonical_gurl.SchemeIs(chrome::kHttpScheme) && 375 if (canonical_gurl.SchemeIs(chrome::kHttpScheme) &&
377 !url_util::FindAndCompareScheme(WideToUTF8(input_text), 376 !url_util::FindAndCompareScheme(WideToUTF8(input_text),
378 chrome::kHttpScheme, &scheme)) 377 chrome::kHttpScheme, NULL))
379 TrimHttpPrefix(&output); 378 TrimHttpPrefix(&output);
380 379
381 // Make the number of trailing slashes on the output exactly match the input. 380 // Make the number of trailing slashes on the output exactly match the input.
382 // Examples of why not doing this would matter: 381 // Examples of why not doing this would matter:
383 // * The user types "a" and has this fixed up to "a/". Now no other sites 382 // * The user types "a" and has this fixed up to "a/". Now no other sites
384 // beginning with "a" will match. 383 // beginning with "a" will match.
385 // * The user types "file:" and has this fixed up to "file://". Now inline 384 // * The user types "file:" and has this fixed up to "file://". Now inline
386 // autocomplete will append too few slashes, resulting in e.g. "file:/b..." 385 // autocomplete will append too few slashes, resulting in e.g. "file:/b..."
387 // instead of "file:///b..." 386 // instead of "file:///b..."
388 // * The user types "http:/" and has this fixed up to "http:". Now inline 387 // * The user types "http:/" and has this fixed up to "http:". Now inline
(...skipping 12 matching lines...) Expand all
401 output.length() : (output.length() - 1 - last_output_nonslash); 400 output.length() : (output.length() - 1 - last_output_nonslash);
402 if (num_output_slashes < num_input_slashes) 401 if (num_output_slashes < num_input_slashes)
403 output.append(num_input_slashes - num_output_slashes, '/'); 402 output.append(num_input_slashes - num_output_slashes, '/');
404 else if (num_output_slashes > num_input_slashes) 403 else if (num_output_slashes > num_input_slashes)
405 output.erase(output.length() - num_output_slashes + num_input_slashes); 404 output.erase(output.length() - num_output_slashes + num_input_slashes);
406 405
407 return output; 406 return output;
408 } 407 }
409 408
410 // static 409 // static
411 size_t HistoryURLProvider::TrimHttpPrefix(std::wstring* url) {
412 url_parse::Component scheme;
413 if (!url_util::FindAndCompareScheme(WideToUTF8(*url), chrome::kHttpScheme,
414 &scheme))
415 return 0; // Not "http".
416
417 // Erase scheme plus up to two slashes.
418 size_t prefix_len = scheme.end() + 1; // "http:"
419 const size_t after_slashes = std::min(url->length(),
420 static_cast<size_t>(scheme.end() + 3));
421 while ((prefix_len < after_slashes) && ((*url)[prefix_len] == L'/'))
422 ++prefix_len;
423 if (prefix_len == url->length())
424 url->clear();
425 else
426 url->erase(url->begin(), url->begin() + prefix_len);
427 return prefix_len;
428 }
429
430 // static
431 bool HistoryURLProvider::IsHostOnly(const GURL& url) { 410 bool HistoryURLProvider::IsHostOnly(const GURL& url) {
432 DCHECK(url.is_valid()); 411 DCHECK(url.is_valid());
433 return (!url.has_path() || (url.path() == "/")) && !url.has_query() && 412 return (!url.has_path() || (url.path() == "/")) && !url.has_query() &&
434 !url.has_ref(); 413 !url.has_ref();
435 } 414 }
436 415
437 // static 416 // static
438 bool HistoryURLProvider::CompareHistoryMatch(const HistoryMatch& a, 417 bool HistoryURLProvider::CompareHistoryMatch(const HistoryMatch& a,
439 const HistoryMatch& b) { 418 const HistoryMatch& b) {
440 // A URL that has been typed at all is better than one that has never been 419 // A URL that has been typed at all is better than one that has never been
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 history_match.input_location - offset, params->input.text().length(), 832 history_match.input_location - offset, params->input.text().length(),
854 match.contents.length(), ACMatchClassification::URL, 833 match.contents.length(), ACMatchClassification::URL,
855 &match.contents_class); 834 &match.contents_class);
856 match.description = info.title(); 835 match.description = info.title();
857 AutocompleteMatch::ClassifyMatchInString(params->input.text(), info.title(), 836 AutocompleteMatch::ClassifyMatchInString(params->input.text(), info.title(),
858 ACMatchClassification::NONE, 837 ACMatchClassification::NONE,
859 &match.description_class); 838 &match.description_class);
860 839
861 return match; 840 return match;
862 } 841 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/history_url_provider.h ('k') | chrome/browser/autocomplete/search_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698