1 // Copyright 2016 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 5 #ifndef ANDROID_WEBVIEW_BROWSER_NETWORK_SERVICE_AW_WEB_RESOURCE_REQUEST_H_ 6 #define ANDROID_WEBVIEW_BROWSER_NETWORK_SERVICE_AW_WEB_RESOURCE_REQUEST_H_ 7 8 #include <string> 9 #include <vector> 10 11 #include "base/android/scoped_java_ref.h" 12 #include "base/optional.h" 13 14 namespace net { 15 class HttpRequestHeaders; 16 } 17 18 namespace network { 19 struct ResourceRequest; 20 } 21 22 namespace android_webview { 23 24 // A passive data structure only used to carry request information. This 25 // class should be copyable. 26 // The fields are ultimately guided by android.webkit.WebResourceRequest: 27 // https://developer.android.com/reference/android/webkit/WebResourceRequest.html 28 struct AwWebResourceRequest final { 29 explicit AwWebResourceRequest(const network::ResourceRequest& request); 30 AwWebResourceRequest(const std::string& in_url, 31 const std::string& in_method, 32 bool in_is_main_frame, 33 bool in_has_user_gesture, 34 const net::HttpRequestHeaders& in_headers); 35 36 // Add default copy/move/assign operators. Adding explicit destructor 37 // prevents generating move operator. 38 AwWebResourceRequest(const AwWebResourceRequest& other); 39 AwWebResourceRequest(AwWebResourceRequest&& other); 40 AwWebResourceRequest& operator=(AwWebResourceRequest&& other); 41 ~AwWebResourceRequest(); 42 43 // The java equivalent 44 struct AwJavaWebResourceRequest { 45 AwJavaWebResourceRequest(); 46 ~AwJavaWebResourceRequest(); 47 48 base::android::ScopedJavaLocalRef<jstring> jurl; 49 base::android::ScopedJavaLocalRef<jstring> jmethod; 50 base::android::ScopedJavaLocalRef<jobjectArray> jheader_names; 51 base::android::ScopedJavaLocalRef<jobjectArray> jheader_values; 52 }; 53 54 // Convenience method to convert AwWebResourceRequest to Java equivalent. 55 static void ConvertToJava(JNIEnv* env, 56 const AwWebResourceRequest& request, 57 AwJavaWebResourceRequest* jRequest); 58 59 std::string url; 60 std::string method; 61 bool is_main_frame; 62 bool has_user_gesture; 63 std::vector<std::string> header_names; 64 std::vector<std::string> header_values; 65 base::Optional<bool> is_renderer_initiated; 66 }; 67 68 } // namespace android_webview 69 70 #endif // ANDROID_WEBVIEW_BROWSER_NETWORK_SERVICE_AW_WEB_RESOURCE_REQUEST_H_ 71