| 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 |
| 18 class GoogleServiceAuthError; | 19 class GoogleServiceAuthError; |
| 19 | 20 |
| 20 namespace extensions { | 21 namespace extensions { |
| 21 | 22 |
| 22 class GetAuthTokenFunction : public AsyncExtensionFunction, | 23 class GetAuthTokenFunction : public AsyncExtensionFunction, |
| 23 public OAuth2MintTokenFlow::Delegate, | 24 public OAuth2MintTokenFlow::Delegate, |
| 24 public ExtensionInstallPrompt::Delegate { | 25 public ExtensionInstallPrompt::Delegate, |
| 26 public LoginUIService::Observer { |
| 25 public: | 27 public: |
| 26 DECLARE_EXTENSION_FUNCTION_NAME("experimental.identity.getAuthToken"); | 28 DECLARE_EXTENSION_FUNCTION_NAME("experimental.identity.getAuthToken"); |
| 27 | 29 |
| 28 GetAuthTokenFunction(); | 30 GetAuthTokenFunction(); |
| 29 | 31 |
| 30 private: | 32 protected: |
| 31 virtual ~GetAuthTokenFunction(); | 33 virtual ~GetAuthTokenFunction(); |
| 32 | 34 |
| 35 private: |
| 33 // ExtensionFunction: | 36 // ExtensionFunction: |
| 34 virtual bool RunImpl() OVERRIDE; | 37 virtual bool RunImpl() OVERRIDE; |
| 35 | 38 |
| 36 // OAuth2MintTokenFlow::Delegate implementation: | 39 // OAuth2MintTokenFlow::Delegate implementation: |
| 37 virtual void OnMintTokenSuccess(const std::string& access_token) OVERRIDE; | 40 virtual void OnMintTokenSuccess(const std::string& access_token) OVERRIDE; |
| 38 virtual void OnMintTokenFailure(const GoogleServiceAuthError& error) OVERRIDE; | 41 virtual void OnMintTokenFailure( |
| 42 const GoogleServiceAuthError& error) OVERRIDE; |
| 39 virtual void OnIssueAdviceSuccess( | 43 virtual void OnIssueAdviceSuccess( |
| 40 const IssueAdviceInfo& issue_advice) OVERRIDE; | 44 const IssueAdviceInfo& issue_advice) OVERRIDE; |
| 41 | 45 |
| 46 // LoginUIService::Observer implementation. |
| 47 virtual void OnLoginUIShown(LoginUIService::LoginUI* ui) OVERRIDE; |
| 48 virtual void OnLoginUIClosed(LoginUIService::LoginUI* ui) OVERRIDE; |
| 49 |
| 42 // ExtensionInstallPrompt::Delegate implementation: | 50 // ExtensionInstallPrompt::Delegate implementation: |
| 43 virtual void InstallUIProceed() OVERRIDE; | 51 virtual void InstallUIProceed() OVERRIDE; |
| 44 virtual void InstallUIAbort(bool user_initiated) OVERRIDE; | 52 virtual void InstallUIAbort(bool user_initiated) OVERRIDE; |
| 45 | 53 |
| 54 // Shows the login UI in a browser popup. |
| 55 bool StartLogin(); |
| 46 // Starts a MintTokenFlow with the given mode; Returns success. | 56 // Starts a MintTokenFlow with the given mode; Returns success. |
| 47 bool StartFlow(OAuth2MintTokenFlow::Mode mode); | 57 bool StartFlow(OAuth2MintTokenFlow::Mode mode); |
| 48 | 58 |
| 59 void ShowLoginPopup(); |
| 60 const Extension::OAuth2Info& GetOAuth2Info() const; |
| 61 |
| 62 // Checks if there is a master login token to mint tokens for the extension. |
| 63 bool HasLoginToken() const; |
| 64 |
| 65 // Gets the token mint flow mode based on a command-line flag. |
| 66 OAuth2MintTokenFlow::Mode GetTokenFlowMode() const; |
| 67 |
| 49 bool interactive_; | 68 bool interactive_; |
| 50 scoped_ptr<OAuth2MintTokenFlow> flow_; | 69 scoped_ptr<OAuth2MintTokenFlow> flow_; |
| 51 | 70 |
| 52 // When launched in interactive mode, and if there is no existing grant, | 71 // When launched in interactive mode, and if there is no existing grant, |
| 53 // a permissions prompt will be popped up to the user. | 72 // a permissions prompt will be popped up to the user. |
| 54 scoped_ptr<ExtensionInstallPrompt> install_ui_; | 73 scoped_ptr<ExtensionInstallPrompt> install_ui_; |
| 55 }; | 74 }; |
| 56 | 75 |
| 57 class LaunchWebAuthFlowFunction : public AsyncExtensionFunction, | 76 class LaunchWebAuthFlowFunction : public AsyncExtensionFunction, |
| 58 public WebAuthFlow::Delegate { | 77 public WebAuthFlow::Delegate { |
| 59 public: | 78 public: |
| 60 DECLARE_EXTENSION_FUNCTION_NAME("experimental.identity.launchWebAuthFlow"); | 79 DECLARE_EXTENSION_FUNCTION_NAME("experimental.identity.launchWebAuthFlow"); |
| 61 | 80 |
| 62 LaunchWebAuthFlowFunction(); | 81 LaunchWebAuthFlowFunction(); |
| 63 | 82 |
| 64 private: | 83 private: |
| 65 virtual ~LaunchWebAuthFlowFunction(); | 84 virtual ~LaunchWebAuthFlowFunction(); |
| 66 virtual bool RunImpl() OVERRIDE; | 85 virtual bool RunImpl() OVERRIDE; |
| 67 | 86 |
| 68 // WebAuthFlow::Delegate implementation. | 87 // WebAuthFlow::Delegate implementation. |
| 69 virtual void OnAuthFlowSuccess(const std::string& redirect_url) OVERRIDE; | 88 virtual void OnAuthFlowSuccess(const std::string& redirect_url) OVERRIDE; |
| 70 virtual void OnAuthFlowFailure() OVERRIDE; | 89 virtual void OnAuthFlowFailure() OVERRIDE; |
| 71 | 90 |
| 72 scoped_ptr<WebAuthFlow> auth_flow_; | 91 scoped_ptr<WebAuthFlow> auth_flow_; |
| 73 }; | 92 }; |
| 74 | 93 |
| 75 } // namespace extensions | 94 } // namespace extensions |
| 76 | 95 |
| 77 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_ | 96 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_ |
| OLD | NEW |