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 <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "chrome/browser/extensions/api/identity/web_auth_flow.h" | 12 #include "chrome/browser/extensions/api/identity/web_auth_flow.h" |
13 #include "chrome/browser/extensions/app_notify_channel_setup.h" | 13 #include "chrome/browser/extensions/app_notify_channel_setup.h" |
14 #include "chrome/browser/extensions/extension_install_prompt.h" | 14 #include "chrome/browser/extensions/extension_install_prompt.h" |
15 #include "chrome/browser/extensions/extension_function.h" | 15 #include "chrome/browser/extensions/extension_function.h" |
| 16 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
16 #include "chrome/common/net/gaia/oauth2_mint_token_flow.h" | 17 #include "chrome/common/net/gaia/oauth2_mint_token_flow.h" |
17 | 18 |
| 19 class GetAuthTokenFunctionTest; |
| 20 class MockGetAuthTokenFunction; |
18 class GoogleServiceAuthError; | 21 class GoogleServiceAuthError; |
19 | 22 |
20 namespace extensions { | 23 namespace extensions { |
21 | 24 |
22 class IdentityGetAuthTokenFunction : public AsyncExtensionFunction, | 25 class IdentityGetAuthTokenFunction : public AsyncExtensionFunction, |
23 public OAuth2MintTokenFlow::Delegate, | 26 public OAuth2MintTokenFlow::Delegate, |
24 public ExtensionInstallPrompt::Delegate { | 27 public ExtensionInstallPrompt::Delegate, |
| 28 public LoginUIService::Observer { |
25 public: | 29 public: |
26 DECLARE_EXTENSION_FUNCTION_NAME("experimental.identity.getAuthToken"); | 30 DECLARE_EXTENSION_FUNCTION_NAME("experimental.identity.getAuthToken"); |
27 | 31 |
28 IdentityGetAuthTokenFunction(); | 32 IdentityGetAuthTokenFunction(); |
29 | 33 |
| 34 static const char kInvalidClientId[]; |
| 35 static const char kInvalidScopes[]; |
| 36 static const char kAuthFailure[]; |
| 37 static const char kNoGrant[]; |
| 38 static const char kUserRejected[]; |
| 39 static const char kUserNotSignedIn[]; |
| 40 |
| 41 protected: |
| 42 virtual ~IdentityGetAuthTokenFunction(); |
| 43 |
30 private: | 44 private: |
31 virtual ~IdentityGetAuthTokenFunction(); | 45 friend class ::GetAuthTokenFunctionTest; |
| 46 friend class ::MockGetAuthTokenFunction; |
32 | 47 |
33 // ExtensionFunction: | 48 // ExtensionFunction: |
34 virtual bool RunImpl() OVERRIDE; | 49 virtual bool RunImpl() OVERRIDE; |
35 | 50 |
36 // OAuth2MintTokenFlow::Delegate implementation: | 51 // OAuth2MintTokenFlow::Delegate implementation: |
37 virtual void OnMintTokenSuccess(const std::string& access_token) OVERRIDE; | 52 virtual void OnMintTokenSuccess(const std::string& access_token) OVERRIDE; |
38 virtual void OnMintTokenFailure(const GoogleServiceAuthError& error) OVERRIDE; | 53 virtual void OnMintTokenFailure( |
| 54 const GoogleServiceAuthError& error) OVERRIDE; |
39 virtual void OnIssueAdviceSuccess( | 55 virtual void OnIssueAdviceSuccess( |
40 const IssueAdviceInfo& issue_advice) OVERRIDE; | 56 const IssueAdviceInfo& issue_advice) OVERRIDE; |
41 | 57 |
| 58 // LoginUIService::Observer implementation. |
| 59 virtual void OnLoginUIShown(LoginUIService::LoginUI* ui) OVERRIDE { |
| 60 // Do nothing when login ui is shown. |
| 61 } |
| 62 virtual void OnLoginUIClosed(LoginUIService::LoginUI* ui) OVERRIDE; |
| 63 |
42 // ExtensionInstallPrompt::Delegate implementation: | 64 // ExtensionInstallPrompt::Delegate implementation: |
43 virtual void InstallUIProceed() OVERRIDE; | 65 virtual void InstallUIProceed() OVERRIDE; |
44 virtual void InstallUIAbort(bool user_initiated) OVERRIDE; | 66 virtual void InstallUIAbort(bool user_initiated) OVERRIDE; |
45 | 67 |
| 68 // Shows the login UI in a browser popup. |
| 69 bool StartLogin(); |
46 // Starts a MintTokenFlow with the given mode; Returns success. | 70 // Starts a MintTokenFlow with the given mode; Returns success. |
47 bool StartFlow(OAuth2MintTokenFlow::Mode mode); | 71 bool StartFlow(OAuth2MintTokenFlow::Mode mode); |
48 | 72 |
| 73 virtual void StartObservingLoginService(); |
| 74 virtual void StopObservingLoginService(); |
| 75 virtual void ShowLoginPopup(); |
| 76 virtual void ShowOAuthApprovalDialog(const IssueAdviceInfo& issue_advice); |
| 77 // Caller owns the returned instance. |
| 78 virtual OAuth2MintTokenFlow* CreateMintTokenFlow( |
| 79 OAuth2MintTokenFlow::Mode mode); |
| 80 |
| 81 // Checks if there is a master login token to mint tokens for the extension. |
| 82 virtual bool HasLoginToken() const; |
| 83 |
| 84 // Gets the token mint flow mode based on a command-line flag. |
| 85 OAuth2MintTokenFlow::Mode GetTokenFlowMode() const; |
| 86 |
49 bool interactive_; | 87 bool interactive_; |
50 scoped_ptr<OAuth2MintTokenFlow> flow_; | 88 scoped_ptr<OAuth2MintTokenFlow> flow_; |
51 | 89 |
52 // When launched in interactive mode, and if there is no existing grant, | 90 // When launched in interactive mode, and if there is no existing grant, |
53 // a permissions prompt will be popped up to the user. | 91 // a permissions prompt will be popped up to the user. |
54 scoped_ptr<ExtensionInstallPrompt> install_ui_; | 92 scoped_ptr<ExtensionInstallPrompt> install_ui_; |
55 }; | 93 }; |
56 | 94 |
57 class IdentityLaunchWebAuthFlowFunction : public AsyncExtensionFunction, | 95 class IdentityLaunchWebAuthFlowFunction : public AsyncExtensionFunction, |
58 public WebAuthFlow::Delegate { | 96 public WebAuthFlow::Delegate { |
59 public: | 97 public: |
60 DECLARE_EXTENSION_FUNCTION_NAME("experimental.identity.launchWebAuthFlow"); | 98 DECLARE_EXTENSION_FUNCTION_NAME("experimental.identity.launchWebAuthFlow"); |
61 | 99 |
| 100 static const char kInvalidRedirect[]; |
| 101 |
62 IdentityLaunchWebAuthFlowFunction(); | 102 IdentityLaunchWebAuthFlowFunction(); |
63 | 103 |
64 private: | 104 private: |
65 virtual ~IdentityLaunchWebAuthFlowFunction(); | 105 virtual ~IdentityLaunchWebAuthFlowFunction(); |
66 virtual bool RunImpl() OVERRIDE; | 106 virtual bool RunImpl() OVERRIDE; |
67 | 107 |
68 // WebAuthFlow::Delegate implementation. | 108 // WebAuthFlow::Delegate implementation. |
69 virtual void OnAuthFlowSuccess(const std::string& redirect_url) OVERRIDE; | 109 virtual void OnAuthFlowSuccess(const std::string& redirect_url) OVERRIDE; |
70 virtual void OnAuthFlowFailure() OVERRIDE; | 110 virtual void OnAuthFlowFailure() OVERRIDE; |
71 | 111 |
72 scoped_ptr<WebAuthFlow> auth_flow_; | 112 scoped_ptr<WebAuthFlow> auth_flow_; |
73 }; | 113 }; |
74 | 114 |
75 } // namespace extensions | 115 } // namespace extensions |
76 | 116 |
77 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_ | 117 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_ |
OLD | NEW |