Chromium Code Reviews| 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" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 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 "components/google/core/browser/google_util.h" | 23 #include "components/google/core/browser/google_util.h" |
| 24 #include "components/metrics/proto/omnibox_input_type.pb.h" | 24 #include "components/metrics/proto/omnibox_input_type.pb.h" |
| 25 #include "components/search_engines/search_engines_switches.h" | 25 #include "components/search_engines/search_engines_switches.h" |
| 26 #include "components/search_engines/search_terms_data.h" | 26 #include "components/search_engines/search_terms_data.h" |
| 27 #include "google_apis/google_api_keys.h" | 27 #include "google_apis/google_api_keys.h" |
| 28 #include "net/base/escape.h" | 28 #include "net/base/escape.h" |
| 29 #include "net/base/mime_util.h" | 29 #include "net/base/mime_util.h" |
| 30 #include "net/base/net_util.h" | 30 #include "net/base/net_util.h" |
| 31 #include "ui/base/device_form_factor.h" | |
| 31 #include "url/gurl.h" | 32 #include "url/gurl.h" |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| 35 // The TemplateURLRef has any number of terms that need to be replaced. Each of | 36 // The TemplateURLRef has any number of terms that need to be replaced. Each of |
| 36 // the terms is enclosed in braces. If the character preceeding the final | 37 // the terms is enclosed in braces. If the character preceeding the final |
| 37 // brace is a ?, it indicates the term is optional and can be replaced with | 38 // brace is a ?, it indicates the term is optional and can be replaced with |
| 38 // an empty string. | 39 // an empty string. |
| 39 const char kStartParameter = '{'; | 40 const char kStartParameter = '{'; |
| 40 const char kEndParameter = '}'; | 41 const char kEndParameter = '}'; |
| (...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 679 #endif | 680 #endif |
| 680 } else if (parameter == kGoogleSuggestAPIKeyParameter) { | 681 } else if (parameter == kGoogleSuggestAPIKeyParameter) { |
| 681 url->insert(start, | 682 url->insert(start, |
| 682 net::EscapeQueryParamValue(google_apis::GetAPIKey(), false)); | 683 net::EscapeQueryParamValue(google_apis::GetAPIKey(), false)); |
| 683 } else if (parameter == kGoogleSuggestClient) { | 684 } else if (parameter == kGoogleSuggestClient) { |
| 684 replacements->push_back(Replacement(GOOGLE_SUGGEST_CLIENT, start)); | 685 replacements->push_back(Replacement(GOOGLE_SUGGEST_CLIENT, start)); |
| 685 } else if (parameter == kGoogleSuggestRequestId) { | 686 } else if (parameter == kGoogleSuggestRequestId) { |
| 686 replacements->push_back(Replacement(GOOGLE_SUGGEST_REQUEST_ID, start)); | 687 replacements->push_back(Replacement(GOOGLE_SUGGEST_REQUEST_ID, start)); |
| 687 } else if (parameter == kGoogleUnescapedSearchTermsParameter) { | 688 } else if (parameter == kGoogleUnescapedSearchTermsParameter) { |
| 688 replacements->push_back(Replacement(GOOGLE_UNESCAPED_SEARCH_TERMS, start)); | 689 replacements->push_back(Replacement(GOOGLE_UNESCAPED_SEARCH_TERMS, start)); |
| 690 } else if (parameter == "yandex:searchPath") { | |
| 691 #if defined(OS_ANDROID) || defined(OS_IOS) | |
|
Peter Kasting
2015/05/18 18:25:58
Maybe instead of the #ifs here we should be using
sdefresne
2015/05/19 09:09:20
Done.
| |
| 692 if (ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_TABLET) | |
| 693 url->insert(start, "padsearch"); | |
| 694 else | |
| 695 url->insert(start, "touchsearch"); | |
| 696 #else | |
| 697 url->insert(start, "yandsearch"); | |
| 698 #endif | |
| 689 } else if (parameter == kInputEncodingParameter) { | 699 } else if (parameter == kInputEncodingParameter) { |
| 690 replacements->push_back(Replacement(ENCODING, start)); | 700 replacements->push_back(Replacement(ENCODING, start)); |
| 691 } else if (parameter == kLanguageParameter) { | 701 } else if (parameter == kLanguageParameter) { |
| 692 replacements->push_back(Replacement(LANGUAGE, start)); | 702 replacements->push_back(Replacement(LANGUAGE, start)); |
| 693 } else if (parameter == kOutputEncodingParameter) { | 703 } else if (parameter == kOutputEncodingParameter) { |
| 694 if (!optional) | 704 if (!optional) |
| 695 url->insert(start, kOutputEncodingType); | 705 url->insert(start, kOutputEncodingType); |
| 696 } else if ((parameter == kStartIndexParameter) || | 706 } else if ((parameter == kStartIndexParameter) || |
| 697 (parameter == kStartPageParameter)) { | 707 (parameter == kStartPageParameter)) { |
| 698 // We don't support these. | 708 // We don't support these. |
| (...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1543 // patterns. This means that given patterns | 1553 // patterns. This means that given patterns |
| 1544 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], | 1554 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], |
| 1545 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would | 1555 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would |
| 1546 // return false. This is important for at least Google, where such URLs | 1556 // return false. This is important for at least Google, where such URLs |
| 1547 // are invalid. | 1557 // are invalid. |
| 1548 return !search_terms->empty(); | 1558 return !search_terms->empty(); |
| 1549 } | 1559 } |
| 1550 } | 1560 } |
| 1551 return false; | 1561 return false; |
| 1552 } | 1562 } |
| OLD | NEW |