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