aw_web_resource_intercept_response.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2019 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_NETWORK_SERVICE_AW_WEB_RESOURCE_INTERCEPT_RESPONSE_H_
  5. #define ANDROID_WEBVIEW_BROWSER_NETWORK_SERVICE_AW_WEB_RESOURCE_INTERCEPT_RESPONSE_H_
  6. #include <memory>
  7. #include <vector>
  8. #include "base/android/jni_android.h"
  9. #include "base/android/scoped_java_ref.h"
  10. #include "base/compiler_specific.h"
  11. namespace embedder_support {
  12. class WebResourceResponse;
  13. }
  14. namespace android_webview {
  15. class AwWebResourceInterceptResponse {
  16. public:
  17. AwWebResourceInterceptResponse() = delete;
  18. // It is expected that |obj| is an instance of the Java-side
  19. // org.chromium.android_webview.AwWebResourceInterceptResponse class.
  20. explicit AwWebResourceInterceptResponse(
  21. const base::android::JavaRef<jobject>& obj);
  22. AwWebResourceInterceptResponse(const AwWebResourceInterceptResponse&) =
  23. delete;
  24. AwWebResourceInterceptResponse& operator=(
  25. const AwWebResourceInterceptResponse&) = delete;
  26. ~AwWebResourceInterceptResponse();
  27. // True if the call to shouldInterceptRequest raised an exception.
  28. bool RaisedException(JNIEnv* env) const;
  29. // True if this object contains a response.
  30. bool HasResponse(JNIEnv* env) const;
  31. // The response returned by the Java-side handler. Caller should first check
  32. // if an exception was caught via RaisedException() before calling
  33. // this method. A null value means do not intercept the response.
  34. std::unique_ptr<embedder_support::WebResourceResponse> GetResponse(
  35. JNIEnv* env) const;
  36. private:
  37. base::android::ScopedJavaGlobalRef<jobject> java_object_;
  38. };
  39. } // namespace android_webview
  40. #endif // ANDROID_WEBVIEW_BROWSER_NETWORK_SERVICE_AW_WEB_RESOURCE_INTERCEPT_RESPONSE_H_