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 GetAuthTokenFunction : public AsyncExtensionFunction, | 25 class GetAuthTokenFunction : 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 GetAuthTokenFunction(); | 32 GetAuthTokenFunction(); |
29 | 33 |
34 static const char kInvalidClientId[]; | |
Mihai Parparita -not on Chrome
2012/07/17 01:01:00
I don't think it's worth exposing these constants
Munjal (Google)
2012/07/19 22:35:42
That is what I did first. But then I thought that
Mihai Parparita -not on Chrome
2012/07/20 18:02:32
In that case, to be consistent with other exported
Munjal (Google)
2012/07/20 18:54:14
Done.
| |
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 ~GetAuthTokenFunction(); | |
43 | |
30 private: | 44 private: |
31 virtual ~GetAuthTokenFunction(); | 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 virtual const std::string& GetExtensionId() const; | |
78 virtual const Extension::OAuth2Info& GetOAuth2Info() const; | |
79 // Caller owns the returned instance. | |
80 virtual OAuth2MintTokenFlow* CreateMintTokenFlow( | |
81 OAuth2MintTokenFlow::Mode mode); | |
82 | |
83 // Checks if there is a master login token to mint tokens for the extension. | |
84 virtual bool HasLoginToken() const; | |
85 | |
86 // Gets the token mint flow mode based on a command-line flag. | |
87 OAuth2MintTokenFlow::Mode GetTokenFlowMode() const; | |
88 | |
49 bool interactive_; | 89 bool interactive_; |
50 scoped_ptr<OAuth2MintTokenFlow> flow_; | 90 scoped_ptr<OAuth2MintTokenFlow> flow_; |
51 | 91 |
52 // When launched in interactive mode, and if there is no existing grant, | 92 // When launched in interactive mode, and if there is no existing grant, |
53 // a permissions prompt will be popped up to the user. | 93 // a permissions prompt will be popped up to the user. |
54 scoped_ptr<ExtensionInstallPrompt> install_ui_; | 94 scoped_ptr<ExtensionInstallPrompt> install_ui_; |
55 }; | 95 }; |
56 | 96 |
57 class LaunchWebAuthFlowFunction : public AsyncExtensionFunction, | 97 class LaunchWebAuthFlowFunction : public AsyncExtensionFunction, |
58 public WebAuthFlow::Delegate { | 98 public WebAuthFlow::Delegate { |
59 public: | 99 public: |
60 DECLARE_EXTENSION_FUNCTION_NAME("experimental.identity.launchWebAuthFlow"); | 100 DECLARE_EXTENSION_FUNCTION_NAME("experimental.identity.launchWebAuthFlow"); |
61 | 101 |
102 static const char kInvalidRedirect[]; | |
103 | |
62 LaunchWebAuthFlowFunction(); | 104 LaunchWebAuthFlowFunction(); |
63 | 105 |
64 private: | 106 private: |
65 virtual ~LaunchWebAuthFlowFunction(); | 107 virtual ~LaunchWebAuthFlowFunction(); |
66 virtual bool RunImpl() OVERRIDE; | 108 virtual bool RunImpl() OVERRIDE; |
67 | 109 |
68 // WebAuthFlow::Delegate implementation. | 110 // WebAuthFlow::Delegate implementation. |
69 virtual void OnAuthFlowSuccess(const std::string& redirect_url) OVERRIDE; | 111 virtual void OnAuthFlowSuccess(const std::string& redirect_url) OVERRIDE; |
70 virtual void OnAuthFlowFailure() OVERRIDE; | 112 virtual void OnAuthFlowFailure() OVERRIDE; |
71 | 113 |
72 scoped_ptr<WebAuthFlow> auth_flow_; | 114 scoped_ptr<WebAuthFlow> auth_flow_; |
73 }; | 115 }; |
74 | 116 |
75 } // namespace extensions | 117 } // namespace extensions |
76 | 118 |
77 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_ | 119 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_ |
OLD | NEW |