#ifndef NET_ANDROID_HTTP_AUTH_NEGOTIATE_ANDROID_H_
#define NET_ANDROID_HTTP_AUTH_NEGOTIATE_ANDROID_H_
#include <jni.h>
#include <memory>
#include <string>
#include "base/android/jni_android.h"
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "net/base/completion_once_callback.h"
#include "net/base/net_export.h"
#include "net/http/http_auth.h"
#include "net/http/http_auth_mechanism.h"
namespace base {
class TaskRunner;
}
namespace net {
class HttpAuthChallengeTokenizer;
class HttpAuthPreferences;
namespace android {
class NET_EXPORT_PRIVATE JavaNegotiateResultWrapper {
public:
scoped_refptr<base::TaskRunner> callback_task_runner_;
base::OnceCallback<void(int, const std::string&)> thread_safe_callback_;
JavaNegotiateResultWrapper(
const scoped_refptr<base::TaskRunner>& callback_task_runner,
base::OnceCallback<void(int, const std::string&)> thread_safe_callback);
void SetResult(JNIEnv* env,
int result,
const base::android::JavaParamRef<jstring>& token);
private:
~JavaNegotiateResultWrapper();
};
class NET_EXPORT_PRIVATE HttpAuthNegotiateAndroid : public HttpAuthMechanism {
public:
explicit HttpAuthNegotiateAndroid(const HttpAuthPreferences* prefs);
HttpAuthNegotiateAndroid(const HttpAuthNegotiateAndroid&) = delete;
HttpAuthNegotiateAndroid& operator=(const HttpAuthNegotiateAndroid&) = delete;
~HttpAuthNegotiateAndroid() override;
bool Init(const NetLogWithSource& net_log) override;
bool NeedsIdentity() const override;
bool AllowsExplicitCredentials() const override;
HttpAuth::AuthorizationResult ParseChallenge(
HttpAuthChallengeTokenizer* tok) override;
int GenerateAuthToken(const AuthCredentials* credentials,
const std::string& spn,
const std::string& channel_bindings,
std::string* auth_token,
const NetLogWithSource& net_log,
CompletionOnceCallback callback) override;
void SetDelegation(HttpAuth::DelegationType delegation_type) override;
int GenerateAuthTokenAndroid(const AuthCredentials* credentials,
const std::string& spn,
const std::string& channel_bindings,
std::string* auth_token,
CompletionOnceCallback callback);
bool can_delegate() const { return can_delegate_; }
void set_can_delegate(bool can_delegate) { can_delegate_ = can_delegate; }
const std::string& server_auth_token() const { return server_auth_token_; }
void set_server_auth_token(const std::string& server_auth_token) {
server_auth_token_ = server_auth_token;
}
std::string GetAuthAndroidNegotiateAccountType() const;
private:
void SetResultInternal(int result, const std::string& token);
raw_ptr<const HttpAuthPreferences> prefs_ = nullptr;
bool can_delegate_ = false;
bool first_challenge_ = true;
std::string server_auth_token_;
raw_ptr<std::string> auth_token_ = nullptr;
base::android::ScopedJavaGlobalRef<jobject> java_authenticator_;
net::CompletionOnceCallback completion_callback_;
base::WeakPtrFactory<HttpAuthNegotiateAndroid> weak_factory_{this};
};
}
}
#endif