OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 public OAuth2MintTokenFlow::Delegate, | 182 public OAuth2MintTokenFlow::Delegate, |
183 public IdentitySigninFlow::Delegate, | 183 public IdentitySigninFlow::Delegate, |
184 public OAuth2TokenService::Consumer, | 184 public OAuth2TokenService::Consumer, |
185 public IdentityAPI::ShutdownObserver { | 185 public IdentityAPI::ShutdownObserver { |
186 public: | 186 public: |
187 DECLARE_EXTENSION_FUNCTION("identity.getAuthToken", | 187 DECLARE_EXTENSION_FUNCTION("identity.getAuthToken", |
188 EXPERIMENTAL_IDENTITY_GETAUTHTOKEN); | 188 EXPERIMENTAL_IDENTITY_GETAUTHTOKEN); |
189 | 189 |
190 IdentityGetAuthTokenFunction(); | 190 IdentityGetAuthTokenFunction(); |
191 | 191 |
| 192 const ExtensionTokenKey* GetExtensionTokenKeyForTest() { |
| 193 return token_key_.get(); |
| 194 } |
| 195 |
192 protected: | 196 protected: |
193 virtual ~IdentityGetAuthTokenFunction(); | 197 virtual ~IdentityGetAuthTokenFunction(); |
194 | 198 |
195 // IdentitySigninFlow::Delegate implementation: | 199 // IdentitySigninFlow::Delegate implementation: |
196 virtual void SigninSuccess() OVERRIDE; | 200 virtual void SigninSuccess() OVERRIDE; |
197 virtual void SigninFailed() OVERRIDE; | 201 virtual void SigninFailed() OVERRIDE; |
198 | 202 |
199 // GaiaWebAuthFlow::Delegate implementation: | 203 // GaiaWebAuthFlow::Delegate implementation: |
200 virtual void OnGaiaFlowFailure(GaiaWebAuthFlow::Failure failure, | 204 virtual void OnGaiaFlowFailure(GaiaWebAuthFlow::Failure failure, |
201 GoogleServiceAuthError service_error, | 205 GoogleServiceAuthError service_error, |
202 const std::string& oauth_error) OVERRIDE; | 206 const std::string& oauth_error) OVERRIDE; |
203 virtual void OnGaiaFlowCompleted(const std::string& access_token, | 207 virtual void OnGaiaFlowCompleted(const std::string& access_token, |
204 const std::string& expiration) OVERRIDE; | 208 const std::string& expiration) OVERRIDE; |
205 | 209 |
| 210 // Starts a login access token request. |
| 211 virtual void StartLoginAccessTokenRequest(); |
| 212 |
206 // OAuth2TokenService::Consumer implementation: | 213 // OAuth2TokenService::Consumer implementation: |
207 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, | 214 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
208 const std::string& access_token, | 215 const std::string& access_token, |
209 const base::Time& expiration_time) OVERRIDE; | 216 const base::Time& expiration_time) OVERRIDE; |
210 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, | 217 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
211 const GoogleServiceAuthError& error) OVERRIDE; | 218 const GoogleServiceAuthError& error) OVERRIDE; |
212 | 219 |
213 scoped_ptr<OAuth2TokenService::Request> login_token_request_; | 220 scoped_ptr<OAuth2TokenService::Request> login_token_request_; |
214 | 221 |
215 private: | 222 private: |
216 FRIEND_TEST_ALL_PREFIXES(GetAuthTokenFunctionTest, | 223 FRIEND_TEST_ALL_PREFIXES(GetAuthTokenFunctionTest, |
217 ComponentWithChromeClientId); | 224 ComponentWithChromeClientId); |
218 FRIEND_TEST_ALL_PREFIXES(GetAuthTokenFunctionTest, | 225 FRIEND_TEST_ALL_PREFIXES(GetAuthTokenFunctionTest, |
219 ComponentWithNormalClientId); | 226 ComponentWithNormalClientId); |
220 FRIEND_TEST_ALL_PREFIXES(GetAuthTokenFunctionTest, InteractiveQueueShutdown); | 227 FRIEND_TEST_ALL_PREFIXES(GetAuthTokenFunctionTest, InteractiveQueueShutdown); |
221 FRIEND_TEST_ALL_PREFIXES(GetAuthTokenFunctionTest, NoninteractiveShutdown); | 228 FRIEND_TEST_ALL_PREFIXES(GetAuthTokenFunctionTest, NoninteractiveShutdown); |
222 friend class MockGetAuthTokenFunction; | |
223 | 229 |
224 // ExtensionFunction: | 230 // ExtensionFunction: |
225 virtual bool RunAsync() OVERRIDE; | 231 virtual bool RunAsync() OVERRIDE; |
226 | 232 |
227 // Helpers to report async function results to the caller. | 233 // Helpers to report async function results to the caller. |
228 void StartAsyncRun(); | 234 void StartAsyncRun(); |
229 void CompleteAsyncRun(bool success); | 235 void CompleteAsyncRun(bool success); |
230 void CompleteFunctionWithResult(const std::string& access_token); | 236 void CompleteFunctionWithResult(const std::string& access_token); |
231 void CompleteFunctionWithError(const std::string& error); | 237 void CompleteFunctionWithError(const std::string& error); |
232 | 238 |
233 // Initiate/complete the sub-flows. | 239 // Initiate/complete the sub-flows. |
234 void StartSigninFlow(); | 240 void StartSigninFlow(); |
235 void StartMintTokenFlow(IdentityMintRequestQueue::MintType type); | 241 void StartMintTokenFlow(IdentityMintRequestQueue::MintType type); |
236 void CompleteMintTokenFlow(); | 242 void CompleteMintTokenFlow(); |
237 | 243 |
238 // IdentityMintRequestQueue::Request implementation: | 244 // IdentityMintRequestQueue::Request implementation: |
239 virtual void StartMintToken(IdentityMintRequestQueue::MintType type) OVERRIDE; | 245 virtual void StartMintToken(IdentityMintRequestQueue::MintType type) OVERRIDE; |
240 | 246 |
241 // OAuth2MintTokenFlow::Delegate implementation: | 247 // OAuth2MintTokenFlow::Delegate implementation: |
242 virtual void OnMintTokenSuccess(const std::string& access_token, | 248 virtual void OnMintTokenSuccess(const std::string& access_token, |
243 int time_to_live) OVERRIDE; | 249 int time_to_live) OVERRIDE; |
244 virtual void OnMintTokenFailure( | 250 virtual void OnMintTokenFailure( |
245 const GoogleServiceAuthError& error) OVERRIDE; | 251 const GoogleServiceAuthError& error) OVERRIDE; |
246 virtual void OnIssueAdviceSuccess( | 252 virtual void OnIssueAdviceSuccess( |
247 const IssueAdviceInfo& issue_advice) OVERRIDE; | 253 const IssueAdviceInfo& issue_advice) OVERRIDE; |
248 | 254 |
249 // IdentityAPI::ShutdownObserver implementation: | 255 // IdentityAPI::ShutdownObserver implementation: |
250 virtual void OnShutdown() OVERRIDE; | 256 virtual void OnShutdown() OVERRIDE; |
251 | 257 |
252 // Starts a login access token request. | |
253 virtual void StartLoginAccessTokenRequest(); | |
254 | |
255 #if defined(OS_CHROMEOS) | 258 #if defined(OS_CHROMEOS) |
256 // Starts a login access token request for device robot account. This method | 259 // Starts a login access token request for device robot account. This method |
257 // will be called only in enterprise kiosk mode in ChromeOS. | 260 // will be called only in enterprise kiosk mode in ChromeOS. |
258 virtual void StartDeviceLoginAccessTokenRequest(); | 261 virtual void StartDeviceLoginAccessTokenRequest(); |
259 #endif | 262 #endif |
260 | 263 |
261 // Starts a mint token request to GAIA. | 264 // Starts a mint token request to GAIA. |
262 void StartGaiaRequest(const std::string& login_access_token); | 265 void StartGaiaRequest(const std::string& login_access_token); |
263 | 266 |
264 // Methods for invoking UI. Overridable for testing. | 267 // Methods for invoking UI. Overridable for testing. |
265 virtual void ShowLoginPopup(); | 268 virtual void ShowLoginPopup(); |
266 virtual void ShowOAuthApprovalDialog(const IssueAdviceInfo& issue_advice); | 269 virtual void ShowOAuthApprovalDialog(const IssueAdviceInfo& issue_advice); |
267 // Caller owns the returned instance. | 270 // Caller owns the returned instance. |
268 virtual OAuth2MintTokenFlow* CreateMintTokenFlow( | 271 virtual OAuth2MintTokenFlow* CreateMintTokenFlow( |
269 const std::string& login_access_token); | 272 const std::string& login_access_token); |
270 | 273 |
271 // Checks if there is a master login token to mint tokens for the extension. | 274 // Checks if there is a master login token to mint tokens for the extension. |
272 virtual bool HasLoginToken() const; | 275 bool HasLoginToken() const; |
273 | 276 |
274 // Maps OAuth2 protocol errors to an error message returned to the | 277 // Maps OAuth2 protocol errors to an error message returned to the |
275 // developer in chrome.runtime.lastError. | 278 // developer in chrome.runtime.lastError. |
276 std::string MapOAuth2ErrorToDescription(const std::string& error); | 279 std::string MapOAuth2ErrorToDescription(const std::string& error); |
277 | 280 |
278 std::string GetOAuth2ClientId() const; | 281 std::string GetOAuth2ClientId() const; |
279 | 282 |
280 bool should_prompt_for_scopes_; | 283 bool should_prompt_for_scopes_; |
281 IdentityMintRequestQueue::MintType mint_token_flow_type_; | 284 IdentityMintRequestQueue::MintType mint_token_flow_type_; |
282 scoped_ptr<OAuth2MintTokenFlow> mint_token_flow_; | 285 scoped_ptr<OAuth2MintTokenFlow> mint_token_flow_; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 // Helper to initialize final URL prefix. | 347 // Helper to initialize final URL prefix. |
345 void InitFinalRedirectURLPrefix(const std::string& extension_id); | 348 void InitFinalRedirectURLPrefix(const std::string& extension_id); |
346 | 349 |
347 scoped_ptr<WebAuthFlow> auth_flow_; | 350 scoped_ptr<WebAuthFlow> auth_flow_; |
348 GURL final_url_prefix_; | 351 GURL final_url_prefix_; |
349 }; | 352 }; |
350 | 353 |
351 } // namespace extensions | 354 } // namespace extensions |
352 | 355 |
353 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_ | 356 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_ |
OLD | NEW |