| 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/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
| 12 #include "base/i18n/case_conversion.h" |
| 12 #include "base/i18n/icu_string_conversions.h" | 13 #include "base/i18n/icu_string_conversions.h" |
| 13 #include "base/i18n/rtl.h" | 14 #include "base/i18n/rtl.h" |
| 14 #include "base/logging.h" | 15 #include "base/logging.h" |
| 15 #include "base/macros.h" | 16 #include "base/macros.h" |
| 16 #include "base/metrics/field_trial.h" | 17 #include "base/metrics/field_trial.h" |
| 17 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/strings/string_piece.h" | 19 #include "base/strings/string_piece.h" |
| 19 #include "base/strings/string_split.h" | 20 #include "base/strings/string_split.h" |
| 20 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
| 21 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
| (...skipping 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1191 DCHECK(url.is_valid()); | 1192 DCHECK(url.is_valid()); |
| 1192 // Strip "www." off the front of the keyword; otherwise the keyword won't work | 1193 // Strip "www." off the front of the keyword; otherwise the keyword won't work |
| 1193 // properly. See http://code.google.com/p/chromium/issues/detail?id=6984 . | 1194 // properly. See http://code.google.com/p/chromium/issues/detail?id=6984 . |
| 1194 // |url|'s hostname may be IDN-encoded. Before generating |keyword| from it, | 1195 // |url|'s hostname may be IDN-encoded. Before generating |keyword| from it, |
| 1195 // convert to Unicode, so it won't look like a confusing punycode string. | 1196 // convert to Unicode, so it won't look like a confusing punycode string. |
| 1196 base::string16 keyword = url_formatter::StripWWW( | 1197 base::string16 keyword = url_formatter::StripWWW( |
| 1197 url_formatter::IDNToUnicode(url.host())); | 1198 url_formatter::IDNToUnicode(url.host())); |
| 1198 // Special case: if the host was exactly "www." (not sure this can happen but | 1199 // Special case: if the host was exactly "www." (not sure this can happen but |
| 1199 // perhaps with some weird intranet and custom DNS server?), ensure we at | 1200 // perhaps with some weird intranet and custom DNS server?), ensure we at |
| 1200 // least don't return the empty string. | 1201 // least don't return the empty string. |
| 1201 return keyword.empty() ? base::ASCIIToUTF16("www") : keyword; | 1202 return keyword.empty() ? base::ASCIIToUTF16("www") |
| 1203 : base::i18n::ToLower(keyword); |
| 1202 } | 1204 } |
| 1203 | 1205 |
| 1204 // static | 1206 // static |
| 1205 GURL TemplateURL::GenerateFaviconURL(const GURL& url) { | 1207 GURL TemplateURL::GenerateFaviconURL(const GURL& url) { |
| 1206 DCHECK(url.is_valid()); | 1208 DCHECK(url.is_valid()); |
| 1207 GURL::Replacements rep; | 1209 GURL::Replacements rep; |
| 1208 | 1210 |
| 1209 const char favicon_path[] = "/favicon.ico"; | 1211 const char favicon_path[] = "/favicon.ico"; |
| 1210 int favicon_path_len = arraysize(favicon_path) - 1; | 1212 int favicon_path_len = arraysize(favicon_path) - 1; |
| 1211 | 1213 |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1520 // patterns. This means that given patterns | 1522 // patterns. This means that given patterns |
| 1521 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], | 1523 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], |
| 1522 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would | 1524 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would |
| 1523 // return false. This is important for at least Google, where such URLs | 1525 // return false. This is important for at least Google, where such URLs |
| 1524 // are invalid. | 1526 // are invalid. |
| 1525 return !search_terms->empty(); | 1527 return !search_terms->empty(); |
| 1526 } | 1528 } |
| 1527 } | 1529 } |
| 1528 return false; | 1530 return false; |
| 1529 } | 1531 } |
| OLD | NEW |