Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: chrome/browser/google/google_util.cc

Issue 8728004: Add more flexible handling of what is considered a google home page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Address review comments, PSO checks for good/bad URLs Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/google/google_util.h ('k') | chrome/browser/google/google_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « chrome/browser/google/google_util.h ('k') | chrome/browser/google/google_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698