aw_http_auth_handler.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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
  3. // found in the LICENSE file.
  4. #ifndef ANDROID_WEBVIEW_BROWSER_AW_HTTP_AUTH_HANDLER_H_
  5. #define ANDROID_WEBVIEW_BROWSER_AW_HTTP_AUTH_HANDLER_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/android/jni_android.h"
  9. #include "base/android/scoped_java_ref.h"
  10. #include "base/memory/weak_ptr.h"
  11. #include "content/public/browser/content_browser_client.h"
  12. #include "content/public/browser/login_delegate.h"
  13. namespace content {
  14. class WebContents;
  15. }
  16. namespace net {
  17. class AuthChallengeInfo;
  18. }
  19. namespace android_webview {
  20. // Bridges the Java class of the same name and content::LoginDelegate.
  21. class AwHttpAuthHandler : public content::LoginDelegate {
  22. public:
  23. AwHttpAuthHandler(const net::AuthChallengeInfo& auth_info,
  24. content::WebContents* web_contents,
  25. bool first_auth_attempt,
  26. LoginAuthRequiredCallback callback);
  27. ~AwHttpAuthHandler() override;
  28. // from AwHttpAuthHandler
  29. bool HandleOnUIThread(content::WebContents* web_contents);
  30. void Proceed(JNIEnv* env,
  31. const base::android::JavaParamRef<jobject>& obj,
  32. const base::android::JavaParamRef<jstring>& username,
  33. const base::android::JavaParamRef<jstring>& password);
  34. void Cancel(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj);
  35. private:
  36. void Start();
  37. base::WeakPtr<content::WebContents> web_contents_;
  38. base::android::ScopedJavaGlobalRef<jobject> http_auth_handler_;
  39. std::string host_;
  40. std::string realm_;
  41. LoginAuthRequiredCallback callback_;
  42. base::WeakPtrFactory<AwHttpAuthHandler> weak_factory_{this};
  43. };
  44. } // namespace android_webview
  45. #endif // ANDROID_WEBVIEW_BROWSER_AW_HTTP_AUTH_HANDLER_H_