| OLD | NEW |
| 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/search_engines/template_url.h" | 5 #include "components/search_engines/template_url.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/format_macros.h" | 12 #include "base/format_macros.h" |
| 13 #include "base/i18n/icu_string_conversions.h" | 13 #include "base/i18n/icu_string_conversions.h" |
| 14 #include "base/i18n/rtl.h" | 14 #include "base/i18n/rtl.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/metrics/field_trial.h" | 16 #include "base/metrics/field_trial.h" |
| 17 #include "base/rand_util.h" | 17 #include "base/rand_util.h" |
| 18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/strings/string_piece.h" | 19 #include "base/strings/string_piece.h" |
| 20 #include "base/strings/string_split.h" | 20 #include "base/strings/string_split.h" |
| 21 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
| 22 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
| 23 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
| 24 #include "components/google/core/browser/google_util.h" | 24 #include "components/google/core/browser/google_util.h" |
| 25 #include "components/metrics/proto/omnibox_input_type.pb.h" | 25 #include "components/metrics/proto/omnibox_input_type.pb.h" |
| 26 #include "components/search_engines/search_engines_switches.h" | 26 #include "components/search_engines/search_engines_switches.h" |
| 27 #include "components/search_engines/search_terms_data.h" | 27 #include "components/search_engines/search_terms_data.h" |
| 28 #include "components/url_formatter/url_formatter.h" |
| 28 #include "google_apis/google_api_keys.h" | 29 #include "google_apis/google_api_keys.h" |
| 29 #include "net/base/escape.h" | 30 #include "net/base/escape.h" |
| 30 #include "net/base/mime_util.h" | 31 #include "net/base/mime_util.h" |
| 31 #include "net/base/net_util.h" | 32 #include "net/base/net_util.h" |
| 32 #include "ui/base/device_form_factor.h" | 33 #include "ui/base/device_form_factor.h" |
| 33 #include "url/gurl.h" | 34 #include "url/gurl.h" |
| 34 | 35 |
| 35 namespace { | 36 namespace { |
| 36 | 37 |
| 37 // The TemplateURLRef has any number of terms that need to be replaced. Each of | 38 // The TemplateURLRef has any number of terms that need to be replaced. Each of |
| (...skipping 1172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1210 base::string16 TemplateURL::GenerateKeyword( | 1211 base::string16 TemplateURL::GenerateKeyword( |
| 1211 const GURL& url, | 1212 const GURL& url, |
| 1212 const std::string& accept_languages) { | 1213 const std::string& accept_languages) { |
| 1213 DCHECK(url.is_valid()); | 1214 DCHECK(url.is_valid()); |
| 1214 // Strip "www." off the front of the keyword; otherwise the keyword won't work | 1215 // Strip "www." off the front of the keyword; otherwise the keyword won't work |
| 1215 // properly. See http://code.google.com/p/chromium/issues/detail?id=6984 . | 1216 // properly. See http://code.google.com/p/chromium/issues/detail?id=6984 . |
| 1216 // |url|'s hostname may be IDN-encoded. Before generating |keyword| from it, | 1217 // |url|'s hostname may be IDN-encoded. Before generating |keyword| from it, |
| 1217 // convert to Unicode using the user's accept-languages, so it won't look like | 1218 // convert to Unicode using the user's accept-languages, so it won't look like |
| 1218 // a confusing punycode string. | 1219 // a confusing punycode string. |
| 1219 base::string16 keyword = | 1220 base::string16 keyword = |
| 1220 net::StripWWW(net::IDNToUnicode(url.host(), accept_languages)); | 1221 net::StripWWW(url_formatter::IDNToUnicode(url.host(), accept_languages)); |
| 1221 // Special case: if the host was exactly "www." (not sure this can happen but | 1222 // Special case: if the host was exactly "www." (not sure this can happen but |
| 1222 // perhaps with some weird intranet and custom DNS server?), ensure we at | 1223 // perhaps with some weird intranet and custom DNS server?), ensure we at |
| 1223 // least don't return the empty string. | 1224 // least don't return the empty string. |
| 1224 return keyword.empty() ? base::ASCIIToUTF16("www") : keyword; | 1225 return keyword.empty() ? base::ASCIIToUTF16("www") : keyword; |
| 1225 } | 1226 } |
| 1226 | 1227 |
| 1227 // static | 1228 // static |
| 1228 GURL TemplateURL::GenerateFaviconURL(const GURL& url) { | 1229 GURL TemplateURL::GenerateFaviconURL(const GURL& url) { |
| 1229 DCHECK(url.is_valid()); | 1230 DCHECK(url.is_valid()); |
| 1230 GURL::Replacements rep; | 1231 GURL::Replacements rep; |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1513 // patterns. This means that given patterns | 1514 // patterns. This means that given patterns |
| 1514 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], | 1515 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], |
| 1515 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would | 1516 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would |
| 1516 // return false. This is important for at least Google, where such URLs | 1517 // return false. This is important for at least Google, where such URLs |
| 1517 // are invalid. | 1518 // are invalid. |
| 1518 return !search_terms->empty(); | 1519 return !search_terms->empty(); |
| 1519 } | 1520 } |
| 1520 } | 1521 } |
| 1521 return false; | 1522 return false; |
| 1522 } | 1523 } |
| OLD | NEW |