#ifndef CHROME_BROWSER_EXTENSIONS_API_IDENTITY_GAIA_REMOTE_CONSENT_FLOW_H_
#define CHROME_BROWSER_EXTENSIONS_API_IDENTITY_GAIA_REMOTE_CONSENT_FLOW_H_
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/extensions/api/identity/extension_token_key.h"
#include "chrome/browser/extensions/api/identity/web_auth_flow.h"
#include "components/signin/public/identity_manager/accounts_cookie_mutator.h"
#include "content/public/browser/storage_partition.h"
#include "google_apis/gaia/oauth2_mint_token_flow.h"
#include "net/cookies/cookie_access_result.h"
namespace extensions {
class GaiaRemoteConsentFlow : public WebAuthFlow::Delegate {
public:
enum Failure {
NONE = 0,
WINDOW_CLOSED = 1,
LOAD_FAILED = 2,
INVALID_CONSENT_RESULT = 4,
NO_GRANT = 5,
CANNOT_CREATE_WINDOW = 7,
SET_RESOLUTION_COOKIES_FAILED = 8,
kMaxValue = SET_RESOLUTION_COOKIES_FAILED
};
class Delegate {
public:
virtual ~Delegate();
virtual void OnGaiaRemoteConsentFlowFailed(Failure failure) = 0;
virtual void OnGaiaRemoteConsentFlowApproved(
const std::string& consent_result,
const GaiaId& gaia_id) = 0;
};
GaiaRemoteConsentFlow(Delegate* delegate,
Profile* profile,
const ExtensionTokenKey& token_key,
const RemoteConsentResolutionData& resolution_data,
bool user_gesture);
~GaiaRemoteConsentFlow() override;
GaiaRemoteConsentFlow(const GaiaRemoteConsentFlow& other) = delete;
GaiaRemoteConsentFlow& operator=(const GaiaRemoteConsentFlow& other) = delete;
void Start();
void ReactToConsentResult(const std::string& consent_result);
void OnAuthFlowFailure(WebAuthFlow::Failure failure) override;
void OnNavigationFinished(
content::NavigationHandle* navigation_handle) override;
void SetWebAuthFlowForTesting(std::unique_ptr<WebAuthFlow> web_auth_flow);
WebAuthFlow* GetWebAuthFlowForTesting() const;
private:
void OnResolutionDataCookiesSet(
const std::vector<net::CookieAccessResult>& cookie_set_result);
void DetachWebAuthFlow();
network::mojom::CookieManager* GetCookieManagerForPartition();
const raw_ptr<Delegate> delegate_;
const raw_ptr<Profile> profile_;
const RemoteConsentResolutionData resolution_data_;
const bool user_gesture_;
std::unique_ptr<WebAuthFlow> web_flow_;
bool web_flow_started_;
base::WeakPtrFactory<GaiaRemoteConsentFlow> weak_factory{this};
};
}
#endif