Chromium Code Reviews| 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/logging.h" | |
| 9 #include "base/macros.h" | 10 #include "base/macros.h" |
| 10 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
| 12 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 13 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 14 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 15 #include "components/content_settings/core/browser/cookie_settings.h" | 16 #include "components/content_settings/core/browser/cookie_settings.h" |
| 16 #include "components/google/core/browser/google_util.h" | 17 #include "components/google/core/browser/google_util.h" |
| 17 #include "components/signin/core/common/profile_management_switches.h" | 18 #include "components/signin/core/common/profile_management_switches.h" |
| 18 #include "google_apis/gaia/gaia_auth_util.h" | 19 #include "google_apis/gaia/gaia_auth_util.h" |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 (google_util::IsGoogleDomainUrl( | 128 (google_util::IsGoogleDomainUrl( |
| 128 url, google_util::ALLOW_SUBDOMAIN, | 129 url, google_util::ALLOW_SUBDOMAIN, |
| 129 google_util::DISALLOW_NON_STANDARD_PORTS) || | 130 google_util::DISALLOW_NON_STANDARD_PORTS) || |
| 130 google_util::IsYoutubeDomainUrl( | 131 google_util::IsYoutubeDomainUrl( |
| 131 url, google_util::ALLOW_SUBDOMAIN, | 132 url, google_util::ALLOW_SUBDOMAIN, |
| 132 google_util::DISALLOW_NON_STANDARD_PORTS)); | 133 google_util::DISALLOW_NON_STANDARD_PORTS)); |
| 133 return is_google_url || IsDriveOrigin(origin) || | 134 return is_google_url || IsDriveOrigin(origin) || |
| 134 gaia::IsGaiaSignonRealm(origin); | 135 gaia::IsGaiaSignonRealm(origin); |
| 135 } | 136 } |
| 136 | 137 |
| 138 // Checks if the url has the required properties to have a | |
| 139 // X-Chrome-ID-Consistency-Request header. | |
| 140 bool IsUrlEligibleForXChromeIDConsistencyRequestHeader(const GURL& url) { | |
| 141 return gaia::IsGaiaSignonRealm(url.GetOrigin()); | |
| 142 } | |
| 143 | |
| 137 // Checks if the url has the required properties to have an account consistency | 144 // Checks if the url has the required properties to have an account consistency |
| 138 // header. | 145 // header. |
| 139 bool IsUrlEligibleForAccountConsistencyRequestHeader(const GURL& url) { | 146 bool IsUrlEligibleForAccountConsistencyRequestHeader(const GURL& url) { |
| 140 // TODO(droger): Support X-Chrome-ID-Consistency-Request. | 147 switch (switches::GetAccountConsistencyMethod()) { |
| 141 return IsUrlEligibleForXChromeConnectedHeader(url); | 148 case switches::AccountConsistencyMethod::kDisabled: |
| 149 // Mirror header can be added even if account consistency is disabled. | |
| 150 // Fall through. | |
| 151 case switches::AccountConsistencyMethod::kMirror: | |
| 152 return IsUrlEligibleForXChromeConnectedHeader(url); | |
| 153 case switches::AccountConsistencyMethod::kDice: | |
| 154 return IsUrlEligibleForXChromeIDConsistencyRequestHeader(url); | |
| 155 } | |
| 156 | |
| 157 NOTREACHED(); | |
| 158 return false; | |
| 142 } | 159 } |
| 143 | 160 |
| 161 // Builds the value of the header to be included in DICe requests. | |
| 162 std::string BuildDiceRequestIfPossible( | |
| 163 const GURL& url, | |
| 164 const content_settings::CookieSettings* cookie_settings) { | |
| 165 // If signin cookies are not allowed, don't add the header. | |
| 166 if (!SettingsAllowSigninCookies(cookie_settings)) | |
| 167 return std::string(); | |
| 168 | |
| 169 // Check if url is elligible for the header. | |
| 170 if (!IsUrlEligibleForXChromeIDConsistencyRequestHeader(url)) | |
| 171 return std::string(); | |
| 172 | |
| 173 return "client_id=" + GaiaUrls::GetInstance()->oauth2_chrome_client_id(); | |
| 174 } | |
| 175 | |
| 176 // Builds the value of the header to be included in Mirror requests. | |
| 144 std::string BuildMirrorRequestIfPossible( | 177 std::string BuildMirrorRequestIfPossible( |
| 145 bool is_header_request, | 178 bool is_header_request, |
| 146 const GURL& url, | 179 const GURL& url, |
| 147 const std::string& account_id, | 180 const std::string& account_id, |
| 148 const content_settings::CookieSettings* cookie_settings, | 181 const content_settings::CookieSettings* cookie_settings, |
| 149 int profile_mode_mask) { | 182 int profile_mode_mask) { |
| 150 if (account_id.empty()) | 183 if (account_id.empty()) |
| 151 return std::string(); | 184 return std::string(); |
| 152 | 185 |
| 153 // If signin cookies are not allowed, don't add the header. | 186 // If signin cookies are not allowed, don't add the header. |
| 154 if (!SettingsAllowSigninCookies(cookie_settings)) { | 187 if (!SettingsAllowSigninCookies(cookie_settings)) |
| 155 return std::string(); | 188 return std::string(); |
| 156 } | |
| 157 | 189 |
| 158 // Check if url is elligible for the header. | 190 // Check if url is elligible for the header. |
| 159 if (!IsUrlEligibleForXChromeConnectedHeader(url)) | 191 if (!IsUrlEligibleForXChromeConnectedHeader(url)) |
| 160 return std::string(); | 192 return std::string(); |
| 161 | 193 |
| 162 std::vector<std::string> parts; | 194 std::vector<std::string> parts; |
| 163 if (IsUrlEligibleToIncludeGaiaId(url, is_header_request)) { | 195 if (IsUrlEligibleToIncludeGaiaId(url, is_header_request)) { |
| 164 // Only set the GAIA Id on domains that actually requires it. | 196 // Only set the GAIA Id on domains that actually requires it. |
| 165 parts.push_back( | 197 parts.push_back( |
| 166 base::StringPrintf("%s=%s", kGaiaIdAttrName, account_id.c_str())); | 198 base::StringPrintf("%s=%s", kGaiaIdAttrName, account_id.c_str())); |
| 167 } | 199 } |
| 168 parts.push_back( | 200 parts.push_back( |
| 169 base::StringPrintf("%s=%s", kProfileModeAttrName, | 201 base::StringPrintf("%s=%s", kProfileModeAttrName, |
| 170 base::IntToString(profile_mode_mask).c_str())); | 202 base::IntToString(profile_mode_mask).c_str())); |
| 171 parts.push_back(base::StringPrintf( | 203 parts.push_back(base::StringPrintf( |
| 172 "%s=%s", kEnableAccountConsistencyAttrName, | 204 "%s=%s", kEnableAccountConsistencyAttrName, |
| 173 switches::IsAccountConsistencyMirrorEnabled() ? "true" : "false")); | 205 switches::IsAccountConsistencyMirrorEnabled() ? "true" : "false")); |
| 174 | 206 |
| 175 return base::JoinString(parts, is_header_request ? "," : ":"); | 207 return base::JoinString(parts, is_header_request ? "," : ":"); |
| 176 } | 208 } |
| 177 | 209 |
| 178 } // namespace | 210 } // namespace |
| 179 | 211 |
| 212 extern const char kChromeIDConsistencyRequestHeader[] = | |
| 213 "X-Chrome-ID-Consistency-Request"; | |
| 180 extern const char kChromeConnectedHeader[] = "X-Chrome-Connected"; | 214 extern const char kChromeConnectedHeader[] = "X-Chrome-Connected"; |
| 181 | 215 |
| 182 ManageAccountsParams::ManageAccountsParams() | 216 ManageAccountsParams::ManageAccountsParams() |
| 183 : service_type(GAIA_SERVICE_TYPE_NONE), | 217 : service_type(GAIA_SERVICE_TYPE_NONE), |
| 184 email(""), | 218 email(""), |
| 185 is_saml(false), | 219 is_saml(false), |
| 186 continue_url(""), | 220 continue_url(""), |
| 187 is_same_tab(false) { | 221 is_same_tab(false) { |
| 188 #if !defined(OS_IOS) | 222 #if !defined(OS_IOS) |
| 189 child_id = 0; | 223 child_id = 0; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 214 } | 248 } |
| 215 | 249 |
| 216 bool AppendOrRemoveAccountConsistentyRequestHeader( | 250 bool AppendOrRemoveAccountConsistentyRequestHeader( |
| 217 net::URLRequest* request, | 251 net::URLRequest* request, |
| 218 const GURL& redirect_url, | 252 const GURL& redirect_url, |
| 219 const std::string& account_id, | 253 const std::string& account_id, |
| 220 const content_settings::CookieSettings* cookie_settings, | 254 const content_settings::CookieSettings* cookie_settings, |
| 221 int profile_mode_mask) { | 255 int profile_mode_mask) { |
| 222 const GURL& url = redirect_url.is_empty() ? request->url() : redirect_url; | 256 const GURL& url = redirect_url.is_empty() ? request->url() : redirect_url; |
| 223 | 257 |
| 224 // TODO(droger): Support X-Chrome-ID-Consistency-Request. | 258 std::string header_name; |
| 225 std::string header_name = kChromeConnectedHeader; | 259 std::string header_value; |
| 226 std::string header_value = BuildMirrorRequestIfPossible( | 260 switch (switches::GetAccountConsistencyMethod()) { |
| 227 true /* is_header_request */, url, account_id, cookie_settings, | 261 case switches::AccountConsistencyMethod::kDice: |
| 228 profile_mode_mask); | 262 header_name = kChromeIDConsistencyRequestHeader; |
| 263 header_value = BuildDiceRequestIfPossible(url, cookie_settings); | |
| 264 break; | |
| 265 case switches::AccountConsistencyMethod::kDisabled: | |
| 266 // The mirror header is added even if account consistency is disabled. | |
| 267 // Fall through. | |
|
droger
2017/06/06 15:08:14
Sanity check: we never want to add the mirror head
| |
| 268 case switches::AccountConsistencyMethod::kMirror: | |
| 269 header_name = kChromeConnectedHeader; | |
| 270 header_value = BuildMirrorRequestIfPossible( | |
| 271 true /* is_header_request */, url, account_id, cookie_settings, | |
| 272 profile_mode_mask); | |
| 273 break; | |
| 274 } | |
| 229 | 275 |
| 230 if (!header_name.empty() && header_value.empty()) { | 276 if (!header_name.empty() && header_value.empty()) { |
| 231 // If the request is being redirected, and it has the account consistency | 277 // If the request is being redirected, and it has the account consistency |
| 232 // header, and current url is a Google URL, and the redirected one is not, | 278 // header, and current url is a Google URL, and the redirected one is not, |
| 233 // remove the header. | 279 // remove the header. |
| 234 if (!redirect_url.is_empty() && | 280 if (!redirect_url.is_empty() && |
| 235 request->extra_request_headers().HasHeader(header_name) && | 281 request->extra_request_headers().HasHeader(header_name) && |
| 236 IsUrlEligibleForAccountConsistencyRequestHeader(request->url()) && | 282 IsUrlEligibleForAccountConsistencyRequestHeader(request->url()) && |
| 237 !IsUrlEligibleForAccountConsistencyRequestHeader(redirect_url)) { | 283 !IsUrlEligibleForAccountConsistencyRequestHeader(redirect_url)) { |
| 238 request->RemoveRequestHeaderByName(header_name); | 284 request->RemoveRequestHeaderByName(header_name); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 !response_headers->GetNormalizedHeader( | 328 !response_headers->GetNormalizedHeader( |
| 283 kChromeManageAccountsHeader, &header_value)) { | 329 kChromeManageAccountsHeader, &header_value)) { |
| 284 return empty_params; | 330 return empty_params; |
| 285 } | 331 } |
| 286 | 332 |
| 287 DCHECK(switches::IsAccountConsistencyMirrorEnabled() && !is_off_the_record); | 333 DCHECK(switches::IsAccountConsistencyMirrorEnabled() && !is_off_the_record); |
| 288 return BuildManageAccountsParams(header_value); | 334 return BuildManageAccountsParams(header_value); |
| 289 } | 335 } |
| 290 | 336 |
| 291 } // namespace signin | 337 } // namespace signin |
| OLD | NEW |