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 "components/signin/core/browser/signin_header_helper.h" | 5 #include "components/signin/core/browser/signin_header_helper.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
15 #include "components/content_settings/core/browser/cookie_settings.h" | 15 #include "components/content_settings/core/browser/cookie_settings.h" |
16 #include "components/google/core/browser/google_util.h" | 16 #include "components/google/core/browser/google_util.h" |
17 #include "components/signin/core/common/profile_management_switches.h" | 17 #include "components/signin/core/common/profile_management_switches.h" |
18 #include "google_apis/gaia/gaia_auth_util.h" | 18 #include "google_apis/gaia/gaia_auth_util.h" |
19 #include "google_apis/gaia/gaia_urls.h" | 19 #include "google_apis/gaia/gaia_urls.h" |
20 #include "net/base/escape.h" | 20 #include "net/base/escape.h" |
| 21 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
21 #include "net/http/http_response_headers.h" | 22 #include "net/http/http_response_headers.h" |
22 #include "net/url_request/url_request.h" | 23 #include "net/url_request/url_request.h" |
23 #include "url/gurl.h" | 24 #include "url/gurl.h" |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
27 // Dictionary of fields in a mirror response header. | 28 // Dictionary of fields in a mirror response header. |
28 typedef std::map<std::string, std::string> MirrorResponseHeaderDictionary; | 29 typedef std::map<std::string, std::string> MirrorResponseHeaderDictionary; |
29 | 30 |
30 const char kChromeManageAccountsHeader[] = "X-Chrome-Manage-Accounts"; | 31 const char kChromeManageAccountsHeader[] = "X-Chrome-Manage-Accounts"; |
(...skipping 11 matching lines...) Expand all Loading... |
42 return false; | 43 return false; |
43 | 44 |
44 const GURL kGoogleDriveURL("https://drive.google.com"); | 45 const GURL kGoogleDriveURL("https://drive.google.com"); |
45 const GURL kGoogleDocsURL("https://docs.google.com"); | 46 const GURL kGoogleDocsURL("https://docs.google.com"); |
46 return url == kGoogleDriveURL || url == kGoogleDocsURL; | 47 return url == kGoogleDriveURL || url == kGoogleDocsURL; |
47 } | 48 } |
48 | 49 |
49 bool IsUrlEligibleToIncludeGaiaId(const GURL& url, bool is_header_request) { | 50 bool IsUrlEligibleToIncludeGaiaId(const GURL& url, bool is_header_request) { |
50 if (is_header_request) { | 51 if (is_header_request) { |
51 // GAIA Id is only necessary for Drive. Don't set it otherwise. | 52 // GAIA Id is only necessary for Drive. Don't set it otherwise. |
52 return IsDriveOrigin(url); | 53 return IsDriveOrigin(url.GetOrigin()); |
53 } | 54 } |
54 | 55 |
55 // Cookie requests don't have the granularity to only include the GAIA Id for | 56 // Cookie requests don't have the granularity to only include the GAIA Id for |
56 // Drive origin. Set it on all google.com instead. | 57 // Drive origin. Set it on all google.com instead. |
57 if (!url.SchemeIsCryptographic()) | 58 if (!url.SchemeIsCryptographic()) |
58 return false; | 59 return false; |
59 | 60 |
60 const GURL kGoogleDotComURL("https://google.com"); | 61 const std::string kGoogleDomain = "google.com"; |
61 return url == kGoogleDotComURL; | 62 std::string domain = net::registry_controlled_domains::GetDomainAndRegistry( |
| 63 url, net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); |
| 64 return domain == kGoogleDomain; |
62 } | 65 } |
63 | 66 |
64 // Determines the service type that has been passed from GAIA in the header. | 67 // Determines the service type that has been passed from GAIA in the header. |
65 signin::GAIAServiceType GetGAIAServiceTypeFromHeader( | 68 signin::GAIAServiceType GetGAIAServiceTypeFromHeader( |
66 const std::string& header_value) { | 69 const std::string& header_value) { |
67 if (header_value == "SIGNOUT") | 70 if (header_value == "SIGNOUT") |
68 return signin::GAIA_SERVICE_TYPE_SIGNOUT; | 71 return signin::GAIA_SERVICE_TYPE_SIGNOUT; |
69 else if (header_value == "INCOGNITO") | 72 else if (header_value == "INCOGNITO") |
70 return signin::GAIA_SERVICE_TYPE_INCOGNITO; | 73 return signin::GAIA_SERVICE_TYPE_INCOGNITO; |
71 else if (header_value == "ADDSESSION") | 74 else if (header_value == "ADDSESSION") |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 if (!signin::SettingsAllowSigninCookies(cookie_settings)) { | 117 if (!signin::SettingsAllowSigninCookies(cookie_settings)) { |
115 return std::string(); | 118 return std::string(); |
116 } | 119 } |
117 | 120 |
118 // Check if url is elligible for the header. | 121 // Check if url is elligible for the header. |
119 if (!signin::IsUrlEligibleForXChromeConnectedHeader(url)) | 122 if (!signin::IsUrlEligibleForXChromeConnectedHeader(url)) |
120 return std::string(); | 123 return std::string(); |
121 | 124 |
122 std::vector<std::string> parts; | 125 std::vector<std::string> parts; |
123 if (IsUrlEligibleToIncludeGaiaId(url, is_header_request)) { | 126 if (IsUrlEligibleToIncludeGaiaId(url, is_header_request)) { |
124 // Only google.com requires the GAIA ID, don't send it to other domains. | 127 // Only set the GAIA Id on domains that actually requires it. |
125 parts.push_back( | 128 parts.push_back( |
126 base::StringPrintf("%s=%s", kGaiaIdAttrName, account_id.c_str())); | 129 base::StringPrintf("%s=%s", kGaiaIdAttrName, account_id.c_str())); |
127 } | 130 } |
128 parts.push_back( | 131 parts.push_back( |
129 base::StringPrintf("%s=%s", kProfileModeAttrName, | 132 base::StringPrintf("%s=%s", kProfileModeAttrName, |
130 base::IntToString(profile_mode_mask).c_str())); | 133 base::IntToString(profile_mode_mask).c_str())); |
131 parts.push_back(base::StringPrintf( | 134 parts.push_back(base::StringPrintf( |
132 "%s=%s", kEnableAccountConsistencyAttrName, | 135 "%s=%s", kEnableAccountConsistencyAttrName, |
133 switches::IsEnableAccountConsistency() ? "true" : "false")); | 136 switches::IsEnableAccountConsistency() ? "true" : "false")); |
134 | 137 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 !response_headers->GetNormalizedHeader( | 245 !response_headers->GetNormalizedHeader( |
243 kChromeManageAccountsHeader, &header_value)) { | 246 kChromeManageAccountsHeader, &header_value)) { |
244 return empty_params; | 247 return empty_params; |
245 } | 248 } |
246 | 249 |
247 DCHECK(switches::IsEnableAccountConsistency() && !is_off_the_record); | 250 DCHECK(switches::IsEnableAccountConsistency() && !is_off_the_record); |
248 return BuildManageAccountsParams(header_value); | 251 return BuildManageAccountsParams(header_value); |
249 } | 252 } |
250 | 253 |
251 // Checks if the url has the required properties to have an | 254 // Checks if the url has the required properties to have an |
252 // X-CHROME-CONNECTED header. | 255 // X-Chrome-Connected header. |
253 bool IsUrlEligibleForXChromeConnectedHeader(const GURL& url) { | 256 bool IsUrlEligibleForXChromeConnectedHeader(const GURL& url) { |
254 // Only set the header for Drive and Gaia always, and other Google properties | 257 // Only set the header for Drive and Gaia always, and other Google properties |
255 // if account consistency is enabled. | 258 // if account consistency is enabled. |
256 // Vasquette, which is integrated with most Google properties, needs the | 259 // Vasquette, which is integrated with most Google properties, needs the |
257 // header to redirect certain user actions to Chrome native UI. Drive and Gaia | 260 // header to redirect certain user actions to Chrome native UI. Drive and Gaia |
258 // need the header to tell if the current user is connected. The drive path is | 261 // need the header to tell if the current user is connected. The drive path is |
259 // a temporary workaround until the more generic chrome.principals API is | 262 // a temporary workaround until the more generic chrome.principals API is |
260 // available. | 263 // available. |
261 | 264 |
262 // Consider the account id sensitive and limit it to secure domains. | 265 // Consider the account id sensitive and limit it to secure domains. |
263 if (!url.SchemeIsCryptographic()) | 266 if (!url.SchemeIsCryptographic()) |
264 return false; | 267 return false; |
265 | 268 |
266 GURL origin(url.GetOrigin()); | 269 GURL origin(url.GetOrigin()); |
267 bool is_enable_account_consistency = switches::IsEnableAccountConsistency(); | 270 bool is_enable_account_consistency = switches::IsEnableAccountConsistency(); |
268 bool is_google_url = is_enable_account_consistency && | 271 bool is_google_url = is_enable_account_consistency && |
269 (google_util::IsGoogleDomainUrl( | 272 (google_util::IsGoogleDomainUrl( |
270 url, google_util::ALLOW_SUBDOMAIN, | 273 url, google_util::ALLOW_SUBDOMAIN, |
271 google_util::DISALLOW_NON_STANDARD_PORTS) || | 274 google_util::DISALLOW_NON_STANDARD_PORTS) || |
272 google_util::IsYoutubeDomainUrl( | 275 google_util::IsYoutubeDomainUrl( |
273 url, google_util::ALLOW_SUBDOMAIN, | 276 url, google_util::ALLOW_SUBDOMAIN, |
274 google_util::DISALLOW_NON_STANDARD_PORTS)); | 277 google_util::DISALLOW_NON_STANDARD_PORTS)); |
275 return is_google_url || IsDriveOrigin(origin) || | 278 return is_google_url || IsDriveOrigin(origin) || |
276 gaia::IsGaiaSignonRealm(origin); | 279 gaia::IsGaiaSignonRealm(origin); |
277 } | 280 } |
278 | 281 |
279 } // namespace signin | 282 } // namespace signin |
OLD | NEW |