| OLD | NEW | 
|    1 // Copyright 2017 The Chromium Authors. All rights reserved. |    1 // Copyright 2017 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/chrome_connected_header_helper.h" |    5 #include "components/signin/core/browser/chrome_connected_header_helper.h" | 
|    6  |    6  | 
|    7 #include <vector> |    7 #include <vector> | 
|    8  |    8  | 
 |    9 #include "base/logging.h" | 
|    9 #include "base/strings/string_number_conversions.h" |   10 #include "base/strings/string_number_conversions.h" | 
|   10 #include "base/strings/string_util.h" |   11 #include "base/strings/string_util.h" | 
|   11 #include "base/strings/stringprintf.h" |   12 #include "base/strings/stringprintf.h" | 
|   12 #include "components/google/core/browser/google_util.h" |   13 #include "components/google/core/browser/google_util.h" | 
|   13 #include "components/signin/core/common/profile_management_switches.h" |   14 #include "components/signin/core/common/profile_management_switches.h" | 
|   14 #include "google_apis/gaia/gaia_auth_util.h" |   15 #include "google_apis/gaia/gaia_auth_util.h" | 
|   15 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |   16 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 
|   16 #include "url/gurl.h" |   17 #include "url/gurl.h" | 
|   17  |   18  | 
|   18 namespace signin { |   19 namespace signin { | 
|   19  |   20  | 
|   20 namespace { |   21 namespace { | 
|   21  |   22  | 
 |   23 const char kContinueUrlAttrName[] = "continue_url"; | 
 |   24 const char kEmailAttrName[] = "email"; | 
|   22 const char kEnableAccountConsistencyAttrName[] = "enable_account_consistency"; |   25 const char kEnableAccountConsistencyAttrName[] = "enable_account_consistency"; | 
|   23 const char kGaiaIdAttrName[] = "id"; |   26 const char kGaiaIdAttrName[] = "id"; | 
 |   27 const char kIsSameTabAttrName[] = "is_same_tab"; | 
 |   28 const char kIsSamlAttrName[] = "is_saml"; | 
|   24 const char kProfileModeAttrName[] = "mode"; |   29 const char kProfileModeAttrName[] = "mode"; | 
 |   30 const char kServiceTypeAttrName[] = "action"; | 
 |   31  | 
 |   32 // Determines the service type that has been passed from Gaia in the header. | 
 |   33 GAIAServiceType GetGAIAServiceTypeFromHeader(const std::string& header_value) { | 
 |   34   if (header_value == "SIGNOUT") | 
 |   35     return GAIA_SERVICE_TYPE_SIGNOUT; | 
 |   36   else if (header_value == "INCOGNITO") | 
 |   37     return GAIA_SERVICE_TYPE_INCOGNITO; | 
 |   38   else if (header_value == "ADDSESSION") | 
 |   39     return GAIA_SERVICE_TYPE_ADDSESSION; | 
 |   40   else if (header_value == "REAUTH") | 
 |   41     return GAIA_SERVICE_TYPE_REAUTH; | 
 |   42   else if (header_value == "SIGNUP") | 
 |   43     return GAIA_SERVICE_TYPE_SIGNUP; | 
 |   44   else if (header_value == "DEFAULT") | 
 |   45     return GAIA_SERVICE_TYPE_DEFAULT; | 
 |   46   else | 
 |   47     return GAIA_SERVICE_TYPE_NONE; | 
 |   48 } | 
|   25  |   49  | 
|   26 }  // namespace |   50 }  // namespace | 
|   27  |   51  | 
|   28 // static |   52 // static | 
|   29 std::string ChromeConnectedHeaderHelper::BuildRequestCookieIfPossible( |   53 std::string ChromeConnectedHeaderHelper::BuildRequestCookieIfPossible( | 
|   30     const GURL& url, |   54     const GURL& url, | 
|   31     const std::string& account_id, |   55     const std::string& account_id, | 
|   32     const content_settings::CookieSettings* cookie_settings, |   56     const content_settings::CookieSettings* cookie_settings, | 
|   33     int profile_mode_mask) { |   57     int profile_mode_mask) { | 
|   34   ChromeConnectedHeaderHelper chrome_connected_helper; |   58   ChromeConnectedHeaderHelper chrome_connected_helper; | 
|   35   return chrome_connected_helper.BuildRequestHeaderIfPossible( |   59   return chrome_connected_helper.BuildRequestHeaderIfPossible( | 
|   36       false /* is_header_request */, url, account_id, cookie_settings, |   60       false /* is_header_request */, url, account_id, cookie_settings, | 
|   37       profile_mode_mask); |   61       profile_mode_mask); | 
|   38 } |   62 } | 
|   39  |   63  | 
 |   64 // static | 
 |   65 ManageAccountsParams ChromeConnectedHeaderHelper::BuildManageAccountsParams( | 
 |   66     const std::string& header_value) { | 
 |   67   DCHECK(!header_value.empty()); | 
 |   68   ManageAccountsParams params; | 
 |   69   ResponseHeaderDictionary header_dictionary = | 
 |   70       ParseAccountConsistencyResponseHeader(header_value); | 
 |   71   ResponseHeaderDictionary::const_iterator it = header_dictionary.begin(); | 
 |   72   for (; it != header_dictionary.end(); ++it) { | 
 |   73     const std::string key_name(it->first); | 
 |   74     if (key_name == kServiceTypeAttrName) { | 
 |   75       params.service_type = | 
 |   76           GetGAIAServiceTypeFromHeader(header_dictionary[kServiceTypeAttrName]); | 
 |   77     } else if (key_name == kEmailAttrName) { | 
 |   78       params.email = header_dictionary[kEmailAttrName]; | 
 |   79     } else if (key_name == kIsSamlAttrName) { | 
 |   80       params.is_saml = header_dictionary[kIsSamlAttrName] == "true"; | 
 |   81     } else if (key_name == kContinueUrlAttrName) { | 
 |   82       params.continue_url = header_dictionary[kContinueUrlAttrName]; | 
 |   83     } else if (key_name == kIsSameTabAttrName) { | 
 |   84       params.is_same_tab = header_dictionary[kIsSameTabAttrName] == "true"; | 
 |   85     } else { | 
 |   86       DLOG(WARNING) << "Unexpected Gaia header attribute '" << key_name << "'."; | 
 |   87     } | 
 |   88   } | 
 |   89   return params; | 
 |   90 } | 
 |   91  | 
|   40 bool ChromeConnectedHeaderHelper::IsUrlEligibleToIncludeGaiaId( |   92 bool ChromeConnectedHeaderHelper::IsUrlEligibleToIncludeGaiaId( | 
|   41     const GURL& url, |   93     const GURL& url, | 
|   42     bool is_header_request) { |   94     bool is_header_request) { | 
|   43   if (is_header_request) { |   95   if (is_header_request) { | 
|   44     // Gaia ID is only necessary for Drive. Don't set it otherwise. |   96     // Gaia ID is only necessary for Drive. Don't set it otherwise. | 
|   45     return IsDriveOrigin(url.GetOrigin()); |   97     return IsDriveOrigin(url.GetOrigin()); | 
|   46   } |   98   } | 
|   47  |   99  | 
|   48   // Cookie requests don't have the granularity to only include the Gaia ID for |  100   // Cookie requests don't have the granularity to only include the Gaia ID for | 
|   49   // Drive origin. Set it on all google.com instead. |  101   // Drive origin. Set it on all google.com instead. | 
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  109       base::StringPrintf("%s=%s", kProfileModeAttrName, |  161       base::StringPrintf("%s=%s", kProfileModeAttrName, | 
|  110                          base::IntToString(profile_mode_mask).c_str())); |  162                          base::IntToString(profile_mode_mask).c_str())); | 
|  111   parts.push_back(base::StringPrintf( |  163   parts.push_back(base::StringPrintf( | 
|  112       "%s=%s", kEnableAccountConsistencyAttrName, |  164       "%s=%s", kEnableAccountConsistencyAttrName, | 
|  113       switches::IsAccountConsistencyMirrorEnabled() ? "true" : "false")); |  165       switches::IsAccountConsistencyMirrorEnabled() ? "true" : "false")); | 
|  114  |  166  | 
|  115   return base::JoinString(parts, is_header_request ? "," : ":"); |  167   return base::JoinString(parts, is_header_request ? "," : ":"); | 
|  116 } |  168 } | 
|  117  |  169  | 
|  118 }  // namespace signin |  170 }  // namespace signin | 
| OLD | NEW |