| 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 #ifndef COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_HEADER_HELPER_H_ | 5 #ifndef COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_HEADER_HELPER_H_ |
| 6 #define COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_HEADER_HELPER_H_ | 6 #define COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_HEADER_HELPER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "build/build_config.h" // For OS_IOS | 10 #include "build/build_config.h" // For OS_IOS |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 // Profile mode flags. | 24 // Profile mode flags. |
| 25 enum ProfileMode { | 25 enum ProfileMode { |
| 26 PROFILE_MODE_DEFAULT = 0, | 26 PROFILE_MODE_DEFAULT = 0, |
| 27 // Incognito mode disabled by enterprise policy or by parental controls. | 27 // Incognito mode disabled by enterprise policy or by parental controls. |
| 28 PROFILE_MODE_INCOGNITO_DISABLED = 1 << 0, | 28 PROFILE_MODE_INCOGNITO_DISABLED = 1 << 0, |
| 29 // Adding account disabled in the Android-for-EDU mode. | 29 // Adding account disabled in the Android-for-EDU mode. |
| 30 PROFILE_MODE_ADD_ACCOUNT_DISABLED = 1 << 1 | 30 PROFILE_MODE_ADD_ACCOUNT_DISABLED = 1 << 1 |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 extern const char kChromeConnectedHeader[]; | 33 extern const char kChromeConnectedHeader[]; |
| 34 extern const char kDiceRequestHeader[]; |
| 34 | 35 |
| 35 // The ServiceType specified by GAIA in the response header accompanying the 204 | 36 // The ServiceType specified by Gaia in the response header accompanying the 204 |
| 36 // response. This indicates the action Chrome is supposed to lead the user to | 37 // response. This indicates the action Chrome is supposed to lead the user to |
| 37 // perform. | 38 // perform. |
| 38 enum GAIAServiceType { | 39 enum GAIAServiceType { |
| 39 GAIA_SERVICE_TYPE_NONE = 0, // No GAIA response header. | 40 GAIA_SERVICE_TYPE_NONE = 0, // No Gaia response header. |
| 40 GAIA_SERVICE_TYPE_SIGNOUT, // Logout all existing sessions. | 41 GAIA_SERVICE_TYPE_SIGNOUT, // Logout all existing sessions. |
| 41 GAIA_SERVICE_TYPE_INCOGNITO, // Open an incognito tab. | 42 GAIA_SERVICE_TYPE_INCOGNITO, // Open an incognito tab. |
| 42 GAIA_SERVICE_TYPE_ADDSESSION, // Add a secondary account. | 43 GAIA_SERVICE_TYPE_ADDSESSION, // Add a secondary account. |
| 43 GAIA_SERVICE_TYPE_REAUTH, // Re-authenticate an account. | 44 GAIA_SERVICE_TYPE_REAUTH, // Re-authenticate an account. |
| 44 GAIA_SERVICE_TYPE_SIGNUP, // Create a new account. | 45 GAIA_SERVICE_TYPE_SIGNUP, // Create a new account. |
| 45 GAIA_SERVICE_TYPE_DEFAULT, // All other cases. | 46 GAIA_SERVICE_TYPE_DEFAULT, // All other cases. |
| 46 }; | 47 }; |
| 47 | 48 |
| 48 // Struct describing the paramters received in the manage account header. | 49 // Struct describing the paramters received in the manage account header. |
| 49 struct ManageAccountsParams { | 50 struct ManageAccountsParams { |
| 50 // The requested service type such as "ADDSESSION". | 51 // The requested service type such as "ADDSESSION". |
| 51 GAIAServiceType service_type; | 52 GAIAServiceType service_type; |
| 52 // The prefilled email. | 53 // The prefilled email. |
| 53 std::string email; | 54 std::string email; |
| 54 // Whether |email| is a saml account. | 55 // Whether |email| is a saml account. |
| 55 bool is_saml; | 56 bool is_saml; |
| 56 // The continue URL after the requested service is completed successfully. | 57 // The continue URL after the requested service is completed successfully. |
| 57 // Defaults to the current URL if empty. | 58 // Defaults to the current URL if empty. |
| 58 std::string continue_url; | 59 std::string continue_url; |
| 59 // Whether the continue URL should be loaded in the same tab. | 60 // Whether the continue URL should be loaded in the same tab. |
| 60 bool is_same_tab; | 61 bool is_same_tab; |
| 61 | 62 |
| 62 // iOS has no notion of route and child IDs. | 63 // iOS has no notion of route and child IDs. |
| 63 #if !defined(OS_IOS) | 64 #if !defined(OS_IOS) |
| 64 // The child id associated with the web content of the request. | 65 // The child ID associated with the web content of the request. |
| 65 int child_id; | 66 int child_id; |
| 66 // The route id associated with the web content of the request. | 67 // The route ID associated with the web content of the request. |
| 67 int route_id; | 68 int route_id; |
| 68 #endif // !defined(OS_IOS) | 69 #endif // !defined(OS_IOS) |
| 69 | 70 |
| 70 ManageAccountsParams(); | 71 ManageAccountsParams(); |
| 71 ManageAccountsParams(const ManageAccountsParams& other); | 72 ManageAccountsParams(const ManageAccountsParams& other); |
| 72 }; | 73 }; |
| 73 | 74 |
| 75 // Base class for managing the signin headers (Dice and Chrome-Connected). |
| 76 class SigninHeaderHelper { |
| 77 public: |
| 78 // Appends or remove the header to a network request if necessary. |
| 79 bool AppendOrRemoveRequestHeader( |
| 80 net::URLRequest* request, |
| 81 const char* header_name, |
| 82 const GURL& redirect_url, |
| 83 const std::string& account_id, |
| 84 const content_settings::CookieSettings* cookie_settings, |
| 85 int profile_mode_mask); |
| 86 |
| 87 protected: |
| 88 SigninHeaderHelper() {} |
| 89 virtual ~SigninHeaderHelper() {} |
| 90 |
| 91 // Returns the value of the request header, or empty if the header should not |
| 92 // be added. Calls into BuildRequestHeader() which is customized by |
| 93 // subclasses. |
| 94 std::string BuildRequestHeaderIfPossible( |
| 95 bool is_header_request, |
| 96 const GURL& url, |
| 97 const std::string& account_id, |
| 98 const content_settings::CookieSettings* cookie_settings, |
| 99 int profile_mode_mask); |
| 100 |
| 101 private: |
| 102 // Returns whether the url is eligible for the request header. |
| 103 virtual bool IsUrlEligibleForRequestHeader(const GURL& url) = 0; |
| 104 |
| 105 // Returns the value of the request header, or empty if the header should not |
| 106 // be added. |
| 107 // The request is assumed to be eligible. |
| 108 virtual std::string BuildRequestHeader(bool is_header_request, |
| 109 const GURL& url, |
| 110 const std::string& account_id, |
| 111 int profile_mode_mask) = 0; |
| 112 }; |
| 113 |
| 74 // Returns true if signin cookies are allowed. | 114 // Returns true if signin cookies are allowed. |
| 75 bool SettingsAllowSigninCookies( | 115 bool SettingsAllowSigninCookies( |
| 76 const content_settings::CookieSettings* cookie_settings); | 116 const content_settings::CookieSettings* cookie_settings); |
| 77 | 117 |
| 78 // Returns the CHROME_CONNECTED cookie, or an empty string if it should not be | 118 // Returns the CHROME_CONNECTED cookie, or an empty string if it should not be |
| 79 // added to the request to |url|. | 119 // added to the request to |url|. |
| 80 std::string BuildMirrorRequestCookieIfPossible( | 120 std::string BuildMirrorRequestCookieIfPossible( |
| 81 const GURL& url, | 121 const GURL& url, |
| 82 const std::string& account_id, | 122 const std::string& account_id, |
| 83 const content_settings::CookieSettings* cookie_settings, | 123 const content_settings::CookieSettings* cookie_settings, |
| 84 int profile_mode_mask); | 124 int profile_mode_mask); |
| 85 | 125 |
| 86 // Adds account consistency header to all Gaia requests from a connected | 126 // Adds account consistency header to all Gaia requests from a connected |
| 87 // profile, with the exception of requests from gaia webview. | 127 // profile, with the exception of requests from gaia webview. |
| 88 // Removes the header in case it should not be transfered to a redirected url. | 128 // Removes the header in case it should not be transfered to a redirected url. |
| 89 bool AppendOrRemoveAccountConsistentyRequestHeader( | 129 void AppendOrRemoveAccountConsistentyRequestHeader( |
| 90 net::URLRequest* request, | 130 net::URLRequest* request, |
| 91 const GURL& redirect_url, | 131 const GURL& redirect_url, |
| 92 const std::string& account_id, | 132 const std::string& account_id, |
| 93 const content_settings::CookieSettings* cookie_settings, | 133 const content_settings::CookieSettings* cookie_settings, |
| 94 int profile_mode_mask); | 134 int profile_mode_mask); |
| 95 | 135 |
| 96 // Returns the parameters contained in the X-Chrome-Manage-Accounts response | 136 // Returns the parameters contained in the X-Chrome-Manage-Accounts response |
| 97 // header. | 137 // header. |
| 98 ManageAccountsParams BuildManageAccountsParams(const std::string& header_value); | 138 ManageAccountsParams BuildManageAccountsParams(const std::string& header_value); |
| 99 | 139 |
| 100 // Returns the parameters contained in the X-Chrome-Manage-Accounts response | 140 // Returns the parameters contained in the X-Chrome-Manage-Accounts response |
| 101 // header. | 141 // header. |
| 102 // If the request does not have a response header or if the header contains | 142 // If the request does not have a response header or if the header contains |
| 103 // garbage, then |service_type| is set to |GAIA_SERVICE_TYPE_NONE|. | 143 // garbage, then |service_type| is set to |GAIA_SERVICE_TYPE_NONE|. |
| 104 ManageAccountsParams BuildManageAccountsParamsIfExists(net::URLRequest* request, | 144 ManageAccountsParams BuildManageAccountsParamsIfExists(net::URLRequest* request, |
| 105 bool is_off_the_record); | 145 bool is_off_the_record); |
| 106 | 146 |
| 107 } // namespace signin | 147 } // namespace signin |
| 108 | 148 |
| 109 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_HEADER_HELPER_H_ | 149 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_HEADER_HELPER_H_ |
| OLD | NEW |