OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/signin/signin_header_helper.h" | 5 #include "chrome/browser/signin/signin_header_helper.h" |
6 | 6 |
7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 10 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 | 199 |
200 // Only set the header for Drive always, and other Google properties if | 200 // Only set the header for Drive always, and other Google properties if |
201 // new-profile-management is enabled. | 201 // new-profile-management is enabled. |
202 // Vasquette, which is integrated with most Google properties, needs the | 202 // Vasquette, which is integrated with most Google properties, needs the |
203 // header to redirect certain user actions to Chrome native UI. Drive needs | 203 // header to redirect certain user actions to Chrome native UI. Drive needs |
204 // the header to tell if the current user is connected. The drive path is a | 204 // the header to tell if the current user is connected. The drive path is a |
205 // temporary workaround until the more generic chrome.principals API is | 205 // temporary workaround until the more generic chrome.principals API is |
206 // available. | 206 // available. |
207 const GURL& url = redirect_url.is_empty() ? request->url() : redirect_url; | 207 const GURL& url = redirect_url.is_empty() ? request->url() : redirect_url; |
208 GURL origin(url.GetOrigin()); | 208 GURL origin(url.GetOrigin()); |
209 bool is_new_profile_management = switches::IsNewProfileManagement(); | 209 bool is_enable_account_consistency = switches::IsEnableAccountConsistency(); |
210 bool is_google_url = | 210 bool is_google_url = |
211 !switches::IsEnableWebBasedSignin() && | 211 !switches::IsEnableWebBasedSignin() && |
212 is_new_profile_management && | 212 is_enable_account_consistency && |
213 (google_util::IsGoogleDomainUrl( | 213 (google_util::IsGoogleDomainUrl( |
214 url, | 214 url, |
215 google_util::ALLOW_SUBDOMAIN, | 215 google_util::ALLOW_SUBDOMAIN, |
216 google_util::DISALLOW_NON_STANDARD_PORTS) || | 216 google_util::DISALLOW_NON_STANDARD_PORTS) || |
217 google_util::IsYoutubeDomainUrl( | 217 google_util::IsYoutubeDomainUrl( |
218 url, | 218 url, |
219 google_util::ALLOW_SUBDOMAIN, | 219 google_util::ALLOW_SUBDOMAIN, |
220 google_util::DISALLOW_NON_STANDARD_PORTS)); | 220 google_util::DISALLOW_NON_STANDARD_PORTS)); |
221 if (!is_google_url && !IsDriveOrigin(origin)) | 221 if (!is_google_url && !IsDriveOrigin(origin)) |
222 return false; | 222 return false; |
223 | 223 |
224 std::string account_id(io_data->google_services_account_id()->GetValue()); | 224 std::string account_id(io_data->google_services_account_id()->GetValue()); |
225 | 225 |
226 int profile_mode_mask = PROFILE_MODE_DEFAULT; | 226 int profile_mode_mask = PROFILE_MODE_DEFAULT; |
227 if (io_data->incognito_availibility()->GetValue() == | 227 if (io_data->incognito_availibility()->GetValue() == |
228 IncognitoModePrefs::DISABLED || | 228 IncognitoModePrefs::DISABLED || |
229 IncognitoModePrefs::ArePlatformParentalControlsEnabledCached()) { | 229 IncognitoModePrefs::ArePlatformParentalControlsEnabledCached()) { |
230 profile_mode_mask |= PROFILE_MODE_INCOGNITO_DISABLED; | 230 profile_mode_mask |= PROFILE_MODE_INCOGNITO_DISABLED; |
231 } | 231 } |
232 | 232 |
233 // TODO(guohui): needs to make a new flag for enabling account consistency. | 233 // TODO(guohui): needs to make a new flag for enabling account consistency. |
234 std::string header_value(base::StringPrintf("%s=%s,%s=%s,%s=%s", | 234 std::string header_value(base::StringPrintf("%s=%s,%s=%s,%s=%s", |
235 kGaiaIdAttrName, account_id.c_str(), | 235 kGaiaIdAttrName, account_id.c_str(), |
236 kProfileModeAttrName, base::IntToString(profile_mode_mask).c_str(), | 236 kProfileModeAttrName, base::IntToString(profile_mode_mask).c_str(), |
237 kEnableAccountConsistencyAttrName, | 237 kEnableAccountConsistencyAttrName, |
238 is_new_profile_management ? "true" : "false")); | 238 is_enable_account_consistency ? "true" : "false")); |
239 request->SetExtraRequestHeaderByName( | 239 request->SetExtraRequestHeaderByName( |
240 kChromeConnectedHeader, header_value, false); | 240 kChromeConnectedHeader, header_value, false); |
241 return true; | 241 return true; |
242 } | 242 } |
243 | 243 |
244 void ProcessMirrorResponseHeaderIfExists( | 244 void ProcessMirrorResponseHeaderIfExists( |
245 net::URLRequest* request, | 245 net::URLRequest* request, |
246 ProfileIOData* io_data, | 246 ProfileIOData* io_data, |
247 int child_id, | 247 int child_id, |
248 int route_id) { | 248 int route_id) { |
249 #if defined(OS_IOS) | 249 #if defined(OS_IOS) |
250 NOTREACHED(); | 250 NOTREACHED(); |
251 #else | 251 #else |
252 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 252 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
253 if (!gaia::IsGaiaSignonRealm(request->url().GetOrigin())) | 253 if (!gaia::IsGaiaSignonRealm(request->url().GetOrigin())) |
254 return; | 254 return; |
255 | 255 |
256 std::string header_value; | 256 std::string header_value; |
257 if (!request->response_headers()->GetNormalizedHeader( | 257 if (!request->response_headers()->GetNormalizedHeader( |
258 kChromeManageAccountsHeader, &header_value)) { | 258 kChromeManageAccountsHeader, &header_value)) { |
259 return; | 259 return; |
260 } | 260 } |
261 | 261 |
262 DCHECK(switches::IsNewProfileManagement() && !io_data->IsOffTheRecord()); | 262 DCHECK(switches::IsEnableAccountConsistency() && !io_data->IsOffTheRecord()); |
263 ManageAccountsParams params(BuildManageAccountsParams(header_value)); | 263 ManageAccountsParams params(BuildManageAccountsParams(header_value)); |
264 if (params.service_type == GAIA_SERVICE_TYPE_NONE) | 264 if (params.service_type == GAIA_SERVICE_TYPE_NONE) |
265 return; | 265 return; |
266 | 266 |
267 params.child_id = child_id; | 267 params.child_id = child_id; |
268 params.route_id = route_id; | 268 params.route_id = route_id; |
269 content::BrowserThread::PostTask( | 269 content::BrowserThread::PostTask( |
270 content::BrowserThread::UI, FROM_HERE, | 270 content::BrowserThread::UI, FROM_HERE, |
271 base::Bind(ProcessMirrorHeaderUIThread, child_id, route_id, params)); | 271 base::Bind(ProcessMirrorHeaderUIThread, child_id, route_id, params)); |
272 #endif // defined(OS_IOS) | 272 #endif // defined(OS_IOS) |
273 } | 273 } |
274 | 274 |
275 } // namespace signin | 275 } // namespace signin |
OLD | NEW |