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

Side by Side Diff: components/omnibox/browser/autocomplete_match.cc

Issue 1171333003: Move net::FormatUrl and friends outside of //net and into //components (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase again now that CQ is fixed Created 5 years, 4 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/omnibox/browser/autocomplete_match.h" 5 #include "components/omnibox/browser/autocomplete_match.h"
6 6
7 #include "base/i18n/time_formatting.h" 7 #include "base/i18n/time_formatting.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/string16.h" 9 #include "base/strings/string16.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_piece.h" 11 #include "base/strings/string_piece.h"
12 #include "base/strings/string_split.h" 12 #include "base/strings/string_split.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "components/omnibox/browser/autocomplete_provider.h" 16 #include "components/omnibox/browser/autocomplete_provider.h"
17 #include "components/omnibox/browser/suggestion_answer.h" 17 #include "components/omnibox/browser/suggestion_answer.h"
18 #include "components/search_engines/template_url.h" 18 #include "components/search_engines/template_url.h"
19 #include "components/search_engines/template_url_service.h" 19 #include "components/search_engines/template_url_service.h"
20 #include "components/url_formatter/url_formatter.h"
20 #include "grit/components_scaled_resources.h" 21 #include "grit/components_scaled_resources.h"
21 #include "net/base/net_util.h"
22 22
23 namespace { 23 namespace {
24 24
25 bool IsTrivialClassification(const ACMatchClassifications& classifications) { 25 bool IsTrivialClassification(const ACMatchClassifications& classifications) {
26 return classifications.empty() || 26 return classifications.empty() ||
27 ((classifications.size() == 1) && 27 ((classifications.size() == 1) &&
28 (classifications.back().style == ACMatchClassification::NONE)); 28 (classifications.back().style == ACMatchClassification::NONE));
29 } 29 }
30 30
31 // Returns true if one of the |terms_prefixed_by_http_or_https| matches the 31 // Returns true if one of the |terms_prefixed_by_http_or_https| matches the
32 // beginning of the URL (sans scheme). (Recall that 32 // beginning of the URL (sans scheme). (Recall that
33 // |terms_prefixed_by_http_or_https|, for the input "http://a b" will be 33 // |terms_prefixed_by_http_or_https|, for the input "http://a b" will be
34 // ["a"].) This suggests that the user wants a particular URL with a scheme 34 // ["a"].) This suggests that the user wants a particular URL with a scheme
35 // in mind, hence the caller should not consider another URL like this one 35 // in mind, hence the caller should not consider another URL like this one
36 // but with a different scheme to be a duplicate. |languages| is used to 36 // but with a different scheme to be a duplicate. |languages| is used to
37 // format punycoded URLs to decide if they match. 37 // format punycoded URLs to decide if they match.
38 bool WordMatchesURLContent( 38 bool WordMatchesURLContent(
39 const std::vector<base::string16>& terms_prefixed_by_http_or_https, 39 const std::vector<base::string16>& terms_prefixed_by_http_or_https,
40 const std::string& languages, 40 const std::string& languages,
41 const GURL& url) { 41 const GURL& url) {
42 size_t prefix_length = 42 size_t prefix_length =
43 url.scheme().length() + strlen(url::kStandardSchemeSeparator); 43 url.scheme().length() + strlen(url::kStandardSchemeSeparator);
44 DCHECK_GE(url.spec().length(), prefix_length); 44 DCHECK_GE(url.spec().length(), prefix_length);
45 const base::string16& formatted_url = net::FormatUrl( 45 const base::string16& formatted_url = url_formatter::FormatUrl(
46 url, languages, net::kFormatUrlOmitNothing, net::UnescapeRule::NORMAL, 46 url, languages, url_formatter::kFormatUrlOmitNothing,
47 NULL, NULL, &prefix_length); 47 net::UnescapeRule::NORMAL, nullptr, nullptr, &prefix_length);
48 if (prefix_length == base::string16::npos) 48 if (prefix_length == base::string16::npos)
49 return false; 49 return false;
50 const base::string16& formatted_url_without_scheme = 50 const base::string16& formatted_url_without_scheme =
51 formatted_url.substr(prefix_length); 51 formatted_url.substr(prefix_length);
52 for (const auto& term : terms_prefixed_by_http_or_https) { 52 for (const auto& term : terms_prefixed_by_http_or_https) {
53 if (base::StartsWith(formatted_url_without_scheme, term, 53 if (base::StartsWith(formatted_url_without_scheme, term,
54 base::CompareCase::SENSITIVE)) 54 base::CompareCase::SENSITIVE))
55 return true; 55 return true;
56 } 56 }
57 return false; 57 return false;
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 << " is unsorted in relation to last offset of " << last_offset 635 << " is unsorted in relation to last offset of " << last_offset
636 << ". Provider: " << provider_name << "."; 636 << ". Provider: " << provider_name << ".";
637 DCHECK_LT(i->offset, text.length()) 637 DCHECK_LT(i->offset, text.length())
638 << " Classification of [" << i->offset << "," << text.length() 638 << " Classification of [" << i->offset << "," << text.length()
639 << "] is out of bounds for \"" << text << "\". Provider: " 639 << "] is out of bounds for \"" << text << "\". Provider: "
640 << provider_name << "."; 640 << provider_name << ".";
641 last_offset = i->offset; 641 last_offset = i->offset;
642 } 642 }
643 } 643 }
644 #endif 644 #endif
OLDNEW
« no previous file with comments | « components/omnibox/browser/autocomplete_input.cc ('k') | components/omnibox/browser/autocomplete_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698