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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 return true; | 121 return true; |
122 } | 122 } |
123 | 123 |
124 bool GetReactivationBrand(std::string* brand) { | 124 bool GetReactivationBrand(std::string* brand) { |
125 brand->clear(); | 125 brand->clear(); |
126 return true; | 126 return true; |
127 } | 127 } |
128 | 128 |
129 #endif | 129 #endif |
130 | 130 |
| 131 bool IsGoogleHomePageUrl(const std::string& url) { |
| 132 GURL original_url(url); |
| 133 if (!original_url.is_valid()) |
| 134 return false; |
| 135 |
| 136 // Make sure the scheme is valid. |
| 137 if (!original_url.SchemeIs("http") && !original_url.SchemeIs("https")) |
| 138 return false; |
| 139 |
| 140 // Make sure port is default for the respective scheme. |
| 141 if (!original_url.port().empty()) |
| 142 return false; |
| 143 |
| 144 // Accept only valid TLD. |
| 145 size_t tld_length = net::RegistryControlledDomainService::GetRegistryLength( |
| 146 original_url, false); |
| 147 if (tld_length == 0 || tld_length == std::string::npos) |
| 148 return false; |
| 149 |
| 150 // We only accept "www.google." in front of the TLD. |
| 151 std::string host = original_url.host(); |
| 152 host = host.substr(0, host.length() - tld_length); |
| 153 if (!LowerCaseEqualsASCII(host, "www.google.") && |
| 154 !LowerCaseEqualsASCII(host, "google.")) |
| 155 return false; |
| 156 |
| 157 // Make sure the path is a known home page path. |
| 158 std::string path(original_url.path()); |
| 159 if (!LowerCaseEqualsASCII(path, "/") && |
| 160 !LowerCaseEqualsASCII(path, "/webhp") && |
| 161 !StartsWithASCII(path, "/ig", false)) { |
| 162 return false; |
| 163 } |
| 164 |
| 165 return true; |
| 166 } |
| 167 |
131 bool IsOrganic(const std::string& brand) { | 168 bool IsOrganic(const std::string& brand) { |
132 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 169 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
133 if (command_line.HasSwitch(switches::kOrganicInstall)) | 170 if (command_line.HasSwitch(switches::kOrganicInstall)) |
134 return true; | 171 return true; |
135 | 172 |
136 #if defined(OS_MACOSX) | 173 #if defined(OS_MACOSX) |
137 if (brand.empty()) { | 174 if (brand.empty()) { |
138 // An empty brand string on Mac is used for channels other than stable, | 175 // An empty brand string on Mac is used for channels other than stable, |
139 // which are always organic. | 176 // which are always organic. |
140 return true; | 177 return true; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 const char* const kBrands[] = { | 217 const char* const kBrands[] = { |
181 "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE", | 218 "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE", |
182 "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", | 219 "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", |
183 }; | 220 }; |
184 const char* const* end = &kBrands[arraysize(kBrands)]; | 221 const char* const* end = &kBrands[arraysize(kBrands)]; |
185 const char* const* found = std::find(&kBrands[0], end, brand); | 222 const char* const* found = std::find(&kBrands[0], end, brand); |
186 return found != end; | 223 return found != end; |
187 } | 224 } |
188 | 225 |
189 } // namespace google_util | 226 } // namespace google_util |
OLD | NEW |