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/string16.h" | 11 #include "base/string16.h" |
12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
13 #include "base/string_split.h" | 13 #include "base/string_split.h" |
14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/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/common/net/url_util.h" | 19 #include "chrome/common/net/url_util.h" |
20 #include "chrome/installer/util/google_update_settings.h" | 20 #include "chrome/installer/util/google_update_settings.h" |
21 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
22 #include "googleurl/src/url_parse.h" | 22 #include "googleurl/src/url_parse.h" |
23 #include "net/base/escape.h" | |
23 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 24 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
24 | 25 |
25 #if defined(OS_MACOSX) | 26 #if defined(OS_MACOSX) |
26 #include "chrome/browser/mac/keystone_glue.h" | 27 #include "chrome/browser/mac/keystone_glue.h" |
27 #endif | 28 #endif |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
31 const char* brand_for_testing = NULL; | 32 const char* brand_for_testing = NULL; |
32 | 33 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 return true; | 131 return true; |
131 } | 132 } |
132 | 133 |
133 bool GetReactivationBrand(std::string* brand) { | 134 bool GetReactivationBrand(std::string* brand) { |
134 brand->clear(); | 135 brand->clear(); |
135 return true; | 136 return true; |
136 } | 137 } |
137 | 138 |
138 #endif | 139 #endif |
139 | 140 |
141 string16 GetSearchTermsFromGoogleSearchURL(const GURL& url) { | |
142 if (!IsInstantExtendedAPIGoogleSearchUrl(url.spec())) | |
143 return string16(); | |
144 | |
145 std::vector<std::pair<std::string, std::string> > key_value_pairs; | |
146 base::SplitStringIntoKeyValuePairs(url.query(), '=', '&', &key_value_pairs); | |
Ilya Sherman
2012/08/23 19:50:51
Optional nit: Did you consider using ExtractQueryK
dominich
2012/08/23 20:45:37
Thanks for the pointer - that's much better.
| |
147 for (std::vector<std::pair<std::string, std::string> >::const_iterator it = | |
148 key_value_pairs.begin(); it != key_value_pairs.end(); ++it) { | |
149 if (it->first == "q") { | |
150 return net::UnescapeAndDecodeUTF8URLComponent( | |
151 it->second, | |
152 net::UnescapeRule::SPACES | | |
153 net::UnescapeRule::URL_SPECIAL_CHARS | | |
154 net::UnescapeRule::REPLACE_PLUS_WITH_SPACE, | |
155 NULL); | |
156 } | |
157 } | |
158 return string16(); | |
159 } | |
160 | |
140 bool IsGoogleDomainUrl(const std::string& url, SubdomainPermission permission) { | 161 bool IsGoogleDomainUrl(const std::string& url, SubdomainPermission permission) { |
141 GURL original_url(url); | 162 GURL original_url(url); |
142 return original_url.is_valid() && original_url.port().empty() && | 163 return original_url.is_valid() && original_url.port().empty() && |
143 (original_url.SchemeIs("http") || original_url.SchemeIs("https")) && | 164 (original_url.SchemeIs("http") || original_url.SchemeIs("https")) && |
144 google_util::IsGoogleHostname(original_url.host(), permission); | 165 google_util::IsGoogleHostname(original_url.host(), permission); |
145 } | 166 } |
146 | 167 |
147 bool IsGoogleHostname(const std::string& host, | 168 bool IsGoogleHostname(const std::string& host, |
148 SubdomainPermission permission) { | 169 SubdomainPermission permission) { |
149 size_t tld_length = | 170 size_t tld_length = |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
283 const char* const kBrands[] = { | 304 const char* const kBrands[] = { |
284 "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE", | 305 "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE", |
285 "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", "IDCM", | 306 "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", "IDCM", |
286 }; | 307 }; |
287 const char* const* end = &kBrands[arraysize(kBrands)]; | 308 const char* const* end = &kBrands[arraysize(kBrands)]; |
288 const char* const* found = std::find(&kBrands[0], end, brand); | 309 const char* const* found = std::find(&kBrands[0], end, brand); |
289 return found != end; | 310 return found != end; |
290 } | 311 } |
291 | 312 |
292 } // namespace google_util | 313 } // namespace google_util |
OLD | NEW |