aw_web_resource_intercept_response.cc 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. #include "android_webview/browser/network_service/aw_web_resource_intercept_response.h"
  5. #include <memory>
  6. #include <utility>
  7. #include "android_webview/browser_jni_headers/AwWebResourceInterceptResponse_jni.h"
  8. #include "base/android/jni_android.h"
  9. #include "components/embedder_support/android/util/web_resource_response.h"
  10. using base::android::ScopedJavaLocalRef;
  11. namespace android_webview {
  12. AwWebResourceInterceptResponse::AwWebResourceInterceptResponse(
  13. const base::android::JavaRef<jobject>& obj)
  14. : java_object_(obj) {}
  15. AwWebResourceInterceptResponse::~AwWebResourceInterceptResponse() = default;
  16. bool AwWebResourceInterceptResponse::RaisedException(JNIEnv* env) const {
  17. return Java_AwWebResourceInterceptResponse_getRaisedException(env,
  18. java_object_);
  19. }
  20. bool AwWebResourceInterceptResponse::HasResponse(JNIEnv* env) const {
  21. return !!Java_AwWebResourceInterceptResponse_getResponse(env, java_object_);
  22. }
  23. std::unique_ptr<embedder_support::WebResourceResponse>
  24. AwWebResourceInterceptResponse::GetResponse(JNIEnv* env) const {
  25. ScopedJavaLocalRef<jobject> j_response =
  26. Java_AwWebResourceInterceptResponse_getResponse(env, java_object_);
  27. if (!j_response)
  28. return nullptr;
  29. return std::make_unique<embedder_support::WebResourceResponse>(j_response);
  30. }
  31. } // namespace android_webview