| 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/icu_string_conversions.h" | 12 #include "base/i18n/icu_string_conversions.h" |
| 13 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/metrics/field_trial.h" | 16 #include "base/metrics/field_trial.h" |
| 17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/strings/string_piece.h" | 18 #include "base/strings/string_piece.h" |
| 19 #include "base/strings/string_split.h" | 19 #include "base/strings/string_split.h" |
| 20 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
| 21 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 23 #include "build/build_config.h" | 23 #include "build/build_config.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/search_engines/template_url_prepopulate_data.h" |
| 28 #include "components/url_formatter/url_formatter.h" | 29 #include "components/url_formatter/url_formatter.h" |
| 29 #include "google_apis/google_api_keys.h" | 30 #include "google_apis/google_api_keys.h" |
| 30 #include "net/base/escape.h" | 31 #include "net/base/escape.h" |
| 31 #include "net/base/mime_util.h" | 32 #include "net/base/mime_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 1287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1325 | 1326 |
| 1326 TemplateURL::Type TemplateURL::GetType() const { | 1327 TemplateURL::Type TemplateURL::GetType() const { |
| 1327 return extension_info_ ? extension_info_->type : NORMAL; | 1328 return extension_info_ ? extension_info_->type : NORMAL; |
| 1328 } | 1329 } |
| 1329 | 1330 |
| 1330 std::string TemplateURL::GetExtensionId() const { | 1331 std::string TemplateURL::GetExtensionId() const { |
| 1331 DCHECK(extension_info_); | 1332 DCHECK(extension_info_); |
| 1332 return extension_info_->extension_id; | 1333 return extension_info_->extension_id; |
| 1333 } | 1334 } |
| 1334 | 1335 |
| 1336 SearchEngineType TemplateURL::GetEngineType( |
| 1337 const SearchTermsData& search_terms_data) const { |
| 1338 return data_.GetEngineType(search_terms_data, this); |
| 1339 } |
| 1340 |
| 1335 bool TemplateURL::ExtractSearchTermsFromURL( | 1341 bool TemplateURL::ExtractSearchTermsFromURL( |
| 1336 const GURL& url, | 1342 const GURL& url, |
| 1337 const SearchTermsData& search_terms_data, | 1343 const SearchTermsData& search_terms_data, |
| 1338 base::string16* search_terms) const { | 1344 base::string16* search_terms) const { |
| 1339 return FindSearchTermsInURL(url, search_terms_data, search_terms, NULL, NULL); | 1345 return FindSearchTermsInURL(url, search_terms_data, search_terms, NULL, NULL); |
| 1340 } | 1346 } |
| 1341 | 1347 |
| 1342 bool TemplateURL::IsSearchURL(const GURL& url, | 1348 bool TemplateURL::IsSearchURL(const GURL& url, |
| 1343 const SearchTermsData& search_terms_data) const { | 1349 const SearchTermsData& search_terms_data) const { |
| 1344 base::string16 search_terms; | 1350 base::string16 search_terms; |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1535 // patterns. This means that given patterns | 1541 // patterns. This means that given patterns |
| 1536 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], | 1542 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], |
| 1537 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would | 1543 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would |
| 1538 // return false. This is important for at least Google, where such URLs | 1544 // return false. This is important for at least Google, where such URLs |
| 1539 // are invalid. | 1545 // are invalid. |
| 1540 return !search_terms->empty(); | 1546 return !search_terms->empty(); |
| 1541 } | 1547 } |
| 1542 } | 1548 } |
| 1543 return false; | 1549 return false; |
| 1544 } | 1550 } |
| OLD | NEW |