| 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" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 base::SplitString(str, '&', ¶meters); | 37 base::SplitString(str, '&', ¶meters); |
| 38 for (std::vector<std::string>::const_iterator itr = parameters.begin(); | 38 for (std::vector<std::string>::const_iterator itr = parameters.begin(); |
| 39 itr != parameters.end(); | 39 itr != parameters.end(); |
| 40 ++itr) { | 40 ++itr) { |
| 41 if (StartsWithASCII(*itr, "q=", false) && itr->size() > 2) | 41 if (StartsWithASCII(*itr, "q=", false) && itr->size() > 2) |
| 42 return true; | 42 return true; |
| 43 } | 43 } |
| 44 return false; | 44 return false; |
| 45 } | 45 } |
| 46 | 46 |
| 47 // True if |url| is an HTTP[S] request with host "[www.]google.<TLD>" and no | |
| 48 // explicit port. | |
| 49 bool IsGoogleDomainUrl(const GURL& url) { | |
| 50 return url.is_valid() && (url.SchemeIs("http") || url.SchemeIs("https")) && | |
| 51 url.port().empty() && google_util::IsGoogleHostname(url.host()); | |
| 52 } | |
| 53 | |
| 54 } // anonymous namespace | 47 } // anonymous namespace |
| 55 | 48 |
| 56 namespace google_util { | 49 namespace google_util { |
| 57 | 50 |
| 58 const char kLinkDoctorBaseURL[] = | 51 const char kLinkDoctorBaseURL[] = |
| 59 "http://linkhelp.clients.google.com/tbproxy/lh/fixurl"; | 52 "http://linkhelp.clients.google.com/tbproxy/lh/fixurl"; |
| 60 | 53 |
| 61 BrandForTesting::BrandForTesting(const std::string& brand) : brand_(brand) { | 54 BrandForTesting::BrandForTesting(const std::string& brand) : brand_(brand) { |
| 62 DCHECK(brand_for_testing == NULL); | 55 DCHECK(brand_for_testing == NULL); |
| 63 brand_for_testing = brand_.c_str(); | 56 brand_for_testing = brand_.c_str(); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 return true; | 128 return true; |
| 136 } | 129 } |
| 137 | 130 |
| 138 bool GetReactivationBrand(std::string* brand) { | 131 bool GetReactivationBrand(std::string* brand) { |
| 139 brand->clear(); | 132 brand->clear(); |
| 140 return true; | 133 return true; |
| 141 } | 134 } |
| 142 | 135 |
| 143 #endif | 136 #endif |
| 144 | 137 |
| 145 bool IsGoogleHostname(const std::string& host) { | 138 bool IsGoogleDomainUrl(const std::string& url, SubdomainPermission permission) { |
| 139 GURL original_url(url); |
| 140 return original_url.is_valid() && original_url.port().empty() && |
| 141 (original_url.SchemeIs("http") || original_url.SchemeIs("https")) && |
| 142 google_util::IsGoogleHostname(original_url.host(), permission); |
| 143 } |
| 144 |
| 145 bool IsGoogleHostname(const std::string& host, |
| 146 SubdomainPermission permission) { |
| 146 size_t tld_length = | 147 size_t tld_length = |
| 147 net::RegistryControlledDomainService::GetRegistryLength(host, false); | 148 net::RegistryControlledDomainService::GetRegistryLength(host, false); |
| 148 if ((tld_length == 0) || (tld_length == std::string::npos)) | 149 if ((tld_length == 0) || (tld_length == std::string::npos)) |
| 149 return false; | 150 return false; |
| 150 std::string host_minus_tld(host, 0, host.length() - tld_length); | 151 std::string host_minus_tld(host, 0, host.length() - tld_length); |
| 151 return LowerCaseEqualsASCII(host_minus_tld, "www.google.") || | 152 if (LowerCaseEqualsASCII(host_minus_tld, "google.")) |
| 152 LowerCaseEqualsASCII(host_minus_tld, "google."); | 153 return true; |
| 154 if (permission == ALLOW_SUBDOMAIN) |
| 155 return EndsWith(host_minus_tld, ".google.", false); |
| 156 return LowerCaseEqualsASCII(host_minus_tld, "www.google."); |
| 153 } | 157 } |
| 154 | 158 |
| 155 bool IsGoogleHomePageUrl(const std::string& url) { | 159 bool IsGoogleHomePageUrl(const std::string& url) { |
| 156 GURL original_url(url); | 160 GURL original_url(url); |
| 157 | 161 |
| 158 // First check to see if this has a Google domain. | 162 // First check to see if this has a Google domain. |
| 159 if (!IsGoogleDomainUrl(original_url)) | 163 if (!IsGoogleDomainUrl(url, DISALLOW_SUBDOMAIN)) |
| 160 return false; | 164 return false; |
| 161 | 165 |
| 162 // Make sure the path is a known home page path. | 166 // Make sure the path is a known home page path. |
| 163 std::string path(original_url.path()); | 167 std::string path(original_url.path()); |
| 164 if (path != "/" && path != "/webhp" && | 168 if (path != "/" && path != "/webhp" && |
| 165 !StartsWithASCII(path, "/ig", false)) { | 169 !StartsWithASCII(path, "/ig", false)) { |
| 166 return false; | 170 return false; |
| 167 } | 171 } |
| 168 | 172 |
| 169 return true; | 173 return true; |
| 170 } | 174 } |
| 171 | 175 |
| 172 bool IsGoogleSearchUrl(const std::string& url) { | 176 bool IsGoogleSearchUrl(const std::string& url) { |
| 173 GURL original_url(url); | 177 GURL original_url(url); |
| 174 | 178 |
| 175 // First check to see if this has a Google domain. | 179 // First check to see if this has a Google domain. |
| 176 if (!IsGoogleDomainUrl(original_url)) | 180 if (!IsGoogleDomainUrl(url, DISALLOW_SUBDOMAIN)) |
| 177 return false; | 181 return false; |
| 178 | 182 |
| 179 // Make sure the path is a known search path. | 183 // Make sure the path is a known search path. |
| 180 std::string path(original_url.path()); | 184 std::string path(original_url.path()); |
| 181 bool has_valid_path = false; | 185 bool has_valid_path = false; |
| 182 bool is_home_page_base = false; | 186 bool is_home_page_base = false; |
| 183 if (path == "/search") { | 187 if (path == "/search") { |
| 184 has_valid_path = true; | 188 has_valid_path = true; |
| 185 } else if (path == "/webhp" || path == "/") { | 189 } else if (path == "/webhp" || path == "/") { |
| 186 // Note that we allow both "/" and "" paths, but GURL spits them | 190 // Note that we allow both "/" and "" paths, but GURL spits them |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 const char* const kBrands[] = { | 258 const char* const kBrands[] = { |
| 255 "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE", | 259 "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE", |
| 256 "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", "IDCM", | 260 "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", "IDCM", |
| 257 }; | 261 }; |
| 258 const char* const* end = &kBrands[arraysize(kBrands)]; | 262 const char* const* end = &kBrands[arraysize(kBrands)]; |
| 259 const char* const* found = std::find(&kBrands[0], end, brand); | 263 const char* const* found = std::find(&kBrands[0], end, brand); |
| 260 return found != end; | 264 return found != end; |
| 261 } | 265 } |
| 262 | 266 |
| 263 } // namespace google_util | 267 } // namespace google_util |
| OLD | NEW |