OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/google/google_util.h" | 5 #include "chrome/browser/google/google_util.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/strings/string16.h" | 11 #include "base/strings/string16.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/google/google_url_tracker.h" | 17 #include "chrome/browser/google/google_url_tracker.h" |
18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
19 #include "chrome/installer/util/google_update_settings.h" | 19 #include "chrome/installer/util/google_update_settings.h" |
20 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 20 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
21 #include "net/base/url_util.h" | 21 #include "net/base/url_util.h" |
22 #include "url/gurl.h" | 22 #include "url/gurl.h" |
23 | 23 |
24 #if defined(OS_MACOSX) | 24 #if defined(OS_MACOSX) |
25 #include "chrome/browser/mac/keystone_glue.h" | 25 #include "chrome/browser/mac/keystone_glue.h" |
26 #elif defined(OS_CHROMEOS) | 26 #elif defined(OS_CHROMEOS) |
27 #include "chrome/browser/google/google_util_chromeos.h" | 27 #include "chrome/browser/google/google_util_chromeos.h" |
28 #endif | 28 #endif |
29 | 29 |
30 // Only use Link Doctor on official builds. It uses an API key, too, but | |
31 // seems best to just disable it, for more responsive error pages and to reduce | |
32 // server load. | |
30 #if defined(GOOGLE_CHROME_BUILD) | 33 #if defined(GOOGLE_CHROME_BUILD) |
31 #include "chrome/browser/google/linkdoctor_internal/linkdoctor_internal.h" | 34 #define LINKDOCTOR_SERVER_REQUEST_URL "https://www.googleapis.com/rpc" |
32 #endif | 35 #else |
33 | 36 #define LINKDOCTOR_SERVER_REQUEST_URL "" |
34 #ifndef LINKDOCTOR_SERVER_REQUEST_URL | |
35 #define LINKDOCTOR_SERVER_REQUEST_URL std::string() | |
36 #endif | 37 #endif |
37 | 38 |
38 | 39 |
39 // Helpers -------------------------------------------------------------------- | 40 // Helpers -------------------------------------------------------------------- |
40 | 41 |
41 namespace { | 42 namespace { |
42 | 43 |
43 const char* brand_for_testing = NULL; | 44 const char* brand_for_testing = NULL; |
44 bool gUseMockLinkDoctorBaseURLForTesting = false; | 45 bool gUseMockLinkDoctorBaseURLForTesting = false; |
45 | 46 |
(...skipping 21 matching lines...) Expand all Loading... | |
67 GURL LinkDoctorBaseURL() { | 68 GURL LinkDoctorBaseURL() { |
68 if (gUseMockLinkDoctorBaseURLForTesting) | 69 if (gUseMockLinkDoctorBaseURLForTesting) |
69 return GURL("http://mock.linkdoctor.url/for?testing"); | 70 return GURL("http://mock.linkdoctor.url/for?testing"); |
70 return GURL(LINKDOCTOR_SERVER_REQUEST_URL); | 71 return GURL(LINKDOCTOR_SERVER_REQUEST_URL); |
71 } | 72 } |
72 | 73 |
73 void SetMockLinkDoctorBaseURLForTesting() { | 74 void SetMockLinkDoctorBaseURLForTesting() { |
74 gUseMockLinkDoctorBaseURLForTesting = true; | 75 gUseMockLinkDoctorBaseURLForTesting = true; |
75 } | 76 } |
76 | 77 |
77 GURL AppendGoogleLocaleParam(const GURL& url) { | 78 std::string GetGoogleLocale() { |
78 // Google does not yet recognize 'nb' for Norwegian Bokmal, but it uses | |
79 // 'no' for that. | |
80 std::string locale = g_browser_process->GetApplicationLocale(); | 79 std::string locale = g_browser_process->GetApplicationLocale(); |
81 if (locale == "nb") | 80 if (locale == "nb") |
82 locale = "no"; | 81 return "no"; |
83 return net::AppendQueryParameter(url, "hl", locale); | 82 return locale; |
83 } | |
84 | |
85 GURL AppendGoogleLocaleParam(const GURL& url) { | |
86 return net::AppendQueryParameter(url, "hl", GetGoogleLocale()); | |
84 } | 87 } |
85 | 88 |
86 std::string StringAppendGoogleLocaleParam(const std::string& url) { | 89 std::string StringAppendGoogleLocaleParam(const std::string& url) { |
87 GURL original_url(url); | 90 GURL original_url(url); |
88 DCHECK(original_url.is_valid()); | 91 DCHECK(original_url.is_valid()); |
89 GURL localized_url = AppendGoogleLocaleParam(original_url); | 92 GURL localized_url = AppendGoogleLocaleParam(original_url); |
90 return localized_url.spec(); | 93 return localized_url.spec(); |
91 } | 94 } |
92 | 95 |
93 GURL AppendGoogleTLDParam(Profile* profile, const GURL& url) { | 96 std::string GetGoogleCountryCodeCode(Profile* profile) { |
94 const std::string google_domain( | 97 const std::string google_domain( |
95 net::registry_controlled_domains::GetDomainAndRegistry( | 98 net::registry_controlled_domains::GetDomainAndRegistry( |
96 GoogleURLTracker::GoogleURL(profile), | 99 GoogleURLTracker::GoogleURL(profile), |
97 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES)); | 100 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES)); |
98 const size_t first_dot = google_domain.find('.'); | 101 const size_t last_dot = google_domain.find_last_of('.'); |
99 if (first_dot == std::string::npos) { | 102 if (last_dot == std::string::npos) { |
100 NOTREACHED(); | 103 NOTREACHED(); |
101 return url; | 104 return ""; |
102 } | 105 } |
103 return net::AppendQueryParameter(url, "sd", | 106 std::string tld = google_domain.substr(last_dot + 1); |
104 google_domain.substr(first_dot + 1)); | 107 // Assume the com TLD implies the US. |
108 if (tld == "com") | |
109 return "us"; | |
110 // The CLDR code for the UK is "GB". | |
111 if (tld == "uk") | |
112 return "gb"; | |
mmenke
2014/02/04 19:43:56
Added support for "cat", which seems to be the onl
| |
113 return tld; | |
114 } | |
115 | |
116 GURL GetGoogleSearchURL(Profile* profile) { | |
117 GURL url = GoogleURLTracker::GoogleURL(profile); | |
118 | |
119 // The url returned by the tracker does not include search path. | |
120 std::string search_path = "search"; | |
121 GURL::Replacements replace_path; | |
122 replace_path.SetPathStr(search_path); | |
123 return url.ReplaceComponents(replace_path); | |
105 } | 124 } |
106 | 125 |
107 #if defined(OS_WIN) | 126 #if defined(OS_WIN) |
108 | 127 |
109 bool GetBrand(std::string* brand) { | 128 bool GetBrand(std::string* brand) { |
110 if (brand_for_testing) { | 129 if (brand_for_testing) { |
111 brand->assign(brand_for_testing); | 130 brand->assign(brand_for_testing); |
112 return true; | 131 return true; |
113 } | 132 } |
114 | 133 |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
286 DCHECK(brand_for_testing == NULL); | 305 DCHECK(brand_for_testing == NULL); |
287 brand_for_testing = brand_.c_str(); | 306 brand_for_testing = brand_.c_str(); |
288 } | 307 } |
289 | 308 |
290 BrandForTesting::~BrandForTesting() { | 309 BrandForTesting::~BrandForTesting() { |
291 brand_for_testing = NULL; | 310 brand_for_testing = NULL; |
292 } | 311 } |
293 | 312 |
294 | 313 |
295 } // namespace google_util | 314 } // namespace google_util |
OLD | NEW |