1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
Description: Add Ubuntu id into search queries to get credit.
Author: Chad Miller <chad.miller@canonical.com>
--- a/components/search_engines/prepopulated_engines.json
+++ b/components/search_engines/prepopulated_engines.json
@@ -52,7 +52,7 @@
"name": "\u767e\u5ea6",
"keyword": "baidu.com",
"favicon_url": "https://www.baidu.com/favicon.ico",
- "search_url": "https://www.baidu.com/#ie={inputEncoding}&wd={searchTerms}",
+ "search_url": "https://www.baidu.com/#ie={inputEncoding}&tn=ubuntuu_cb&wd={searchTerms}",
"alternate_urls": [
"https://www.baidu.com/s?ie={inputEncoding}&wd={searchTerms}",
"https://www.baidu.com/s?ie={inputEncoding}&word={searchTerms}",
@@ -99,7 +99,7 @@
"name": "DuckDuckGo",
"keyword": "duckduckgo.com",
"favicon_url": "https://duckduckgo.com/favicon.ico",
- "search_url": "https://duckduckgo.com/?q={searchTerms}",
+ "search_url": "https://duckduckgo.com/?q={searchTerms}&t=canonical",
"suggest_url": "https://duckduckgo.com/ac/?q={searchTerms}&type=list",
"type": "SEARCH_ENGINE_DUCKDUCKGO",
"id": 92
--- a/components/search_engines/template_url.cc
+++ b/components/search_engines/template_url.cc
@@ -949,6 +949,9 @@ std::string TemplateURLRef::HandleReplac
std::string url = parsed_url_;
+ bool is_google_search = false;
+ bool ubuntu_credit_for_search = false;
+
// replacements_ is ordered in ascending order, as such we need to iterate
// from the back.
for (auto i = replacements_.rbegin(); i != replacements_.rend(); ++i) {
@@ -977,6 +980,7 @@ std::string TemplateURLRef::HandleReplac
case GOOGLE_BASE_URL:
DCHECK(!i->is_post_param);
+ is_google_search = true;
HandleReplacement(
std::string(), search_terms_data.GoogleBaseURLValue(), *i, &url);
break;
@@ -1095,7 +1099,8 @@ std::string TemplateURLRef::HandleReplac
case GOOGLE_SEARCH_CLIENT: {
DCHECK(!i->is_post_param);
- std::string client = search_terms_data.GetSearchClient();
+ ubuntu_credit_for_search = true;
+ std::string client = "ubuntu";
if (!client.empty())
HandleReplacement("client", client, *i, &url);
break;
@@ -1214,6 +1219,13 @@ std::string TemplateURLRef::HandleReplac
}
}
+ /* Google search template from prefs might not have a client token. */
+ if (is_google_search && !ubuntu_credit_for_search) {
+ if (url.find_first_of('?', 8) != std::string::npos) { // perhaps no GET params
+ url.append("&client=ubuntu");
+ }
+ }
+
if (!post_params_.empty())
EncodeFormData(post_params_, post_content);
|