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

Side by Side Diff: components/search_engines/template_url.cc

Issue 1141743003: [Mobile] Upstream fix for yandex search engine (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Always switch on form factor when substituting {yandex:searchPath} Created 5 years, 7 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
« no previous file with comments | « components/search_engines/prepopulated_engines.json ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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
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
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 switch (ui::GetDeviceFormFactor()) {
692 case ui::DEVICE_FORM_FACTOR_DESKTOP:
693 url->insert(start, "yandsearch");
694 break;
695 case ui::DEVICE_FORM_FACTOR_PHONE:
696 url->insert(start, "touchsearch");
697 break;
698 case ui::DEVICE_FORM_FACTOR_TABLET:
699 url->insert(start, "padsearch");
700 break;
701 }
689 } else if (parameter == kInputEncodingParameter) { 702 } else if (parameter == kInputEncodingParameter) {
690 replacements->push_back(Replacement(ENCODING, start)); 703 replacements->push_back(Replacement(ENCODING, start));
691 } else if (parameter == kLanguageParameter) { 704 } else if (parameter == kLanguageParameter) {
692 replacements->push_back(Replacement(LANGUAGE, start)); 705 replacements->push_back(Replacement(LANGUAGE, start));
693 } else if (parameter == kOutputEncodingParameter) { 706 } else if (parameter == kOutputEncodingParameter) {
694 if (!optional) 707 if (!optional)
695 url->insert(start, kOutputEncodingType); 708 url->insert(start, kOutputEncodingType);
696 } else if ((parameter == kStartIndexParameter) || 709 } else if ((parameter == kStartIndexParameter) ||
697 (parameter == kStartPageParameter)) { 710 (parameter == kStartPageParameter)) {
698 // We don't support these. 711 // We don't support these.
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after
1543 // patterns. This means that given patterns 1556 // patterns. This means that given patterns
1544 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], 1557 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ],
1545 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would 1558 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would
1546 // return false. This is important for at least Google, where such URLs 1559 // return false. This is important for at least Google, where such URLs
1547 // are invalid. 1560 // are invalid.
1548 return !search_terms->empty(); 1561 return !search_terms->empty();
1549 } 1562 }
1550 } 1563 }
1551 return false; 1564 return false;
1552 } 1565 }
OLDNEW
« no previous file with comments | « components/search_engines/prepopulated_engines.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698