Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/string16.h" | 10 #include "base/string16.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 net::RegistryControlledDomainService::GetDomainAndRegistry( | 75 net::RegistryControlledDomainService::GetDomainAndRegistry( |
| 76 GoogleURLTracker::GoogleURL())); | 76 GoogleURLTracker::GoogleURL())); |
| 77 const size_t first_dot = google_domain.find('.'); | 77 const size_t first_dot = google_domain.find('.'); |
| 78 if (first_dot == std::string::npos) { | 78 if (first_dot == std::string::npos) { |
| 79 NOTREACHED(); | 79 NOTREACHED(); |
| 80 return url; | 80 return url; |
| 81 } | 81 } |
| 82 return AppendParam(url, "sd", google_domain.substr(first_dot + 1)); | 82 return AppendParam(url, "sd", google_domain.substr(first_dot + 1)); |
| 83 } | 83 } |
| 84 | 84 |
| 85 bool IsGoogleHomePageUrl(const std::string& url) { | |
|
SteveT
2011/11/28 21:04:49
Nit: Move down to roughly match header order.
Roger Tawa OOO till Jul 10th
2011/11/29 16:00:09
Done.
| |
| 86 GURL original_url(url); | |
| 87 if (!original_url.is_valid()) | |
| 88 return false; | |
| 89 | |
| 90 // Make sure the scheme is valid. | |
| 91 if (!original_url.SchemeIs("http") && !original_url.SchemeIs("https")) | |
| 92 return false; | |
| 93 | |
| 94 // Make sure port is default for the respective scheme. | |
| 95 if (!original_url.port().empty()) | |
|
SteveT
2011/11/28 21:04:49
Do we want to allow :80 and :443 for http and http
Roger Tawa OOO till Jul 10th
2011/11/29 16:00:09
GURL does not make it easy to detect default port
| |
| 96 return false; | |
| 97 | |
| 98 // Accept only valid TLD. | |
| 99 size_t tld_length = net::RegistryControlledDomainService::GetRegistryLength( | |
| 100 original_url, false); | |
| 101 if (tld_length == 0 || tld_length == std::string::npos) | |
| 102 return false; | |
| 103 | |
| 104 // We only accept "www.google." in front of the TLD. | |
| 105 std::string host = original_url.host(); | |
| 106 host = host.substr(0, host.length() - tld_length); | |
| 107 if (!LowerCaseEqualsASCII(host, "www.google.")) | |
| 108 return false; | |
| 109 | |
| 110 // Make sure the path is a known home page path. | |
| 111 std::string path(original_url.path()); | |
| 112 if (!LowerCaseEqualsASCII(path, "/") && | |
| 113 !LowerCaseEqualsASCII(path, "/webhp") && | |
| 114 !StartsWithASCII(path, "/ig", false)) { | |
| 115 return false; | |
| 116 } | |
| 117 | |
| 118 return true; | |
| 119 } | |
| 120 | |
| 85 #if defined(OS_WIN) | 121 #if defined(OS_WIN) |
| 86 | 122 |
| 87 bool GetBrand(std::string* brand) { | 123 bool GetBrand(std::string* brand) { |
| 88 if (brand_for_testing) { | 124 if (brand_for_testing) { |
| 89 brand->assign(brand_for_testing); | 125 brand->assign(brand_for_testing); |
| 90 return true; | 126 return true; |
| 91 } | 127 } |
| 92 | 128 |
| 93 string16 brand16; | 129 string16 brand16; |
| 94 bool ret = GoogleUpdateSettings::GetBrand(&brand16); | 130 bool ret = GoogleUpdateSettings::GetBrand(&brand16); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 const char* const kBrands[] = { | 216 const char* const kBrands[] = { |
| 181 "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE", | 217 "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE", |
| 182 "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", | 218 "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", |
| 183 }; | 219 }; |
| 184 const char* const* end = &kBrands[arraysize(kBrands)]; | 220 const char* const* end = &kBrands[arraysize(kBrands)]; |
| 185 const char* const* found = std::find(&kBrands[0], end, brand); | 221 const char* const* found = std::find(&kBrands[0], end, brand); |
| 186 return found != end; | 222 return found != end; |
| 187 } | 223 } |
| 188 | 224 |
| 189 } // namespace google_util | 225 } // namespace google_util |
| OLD | NEW |