OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_LOADER_RESOURCE_REQUEST_INFO_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_LOADER_RESOURCE_REQUEST_INFO_IMPL_H_ |
6 #define CONTENT_BROWSER_LOADER_RESOURCE_REQUEST_INFO_IMPL_H_ | 6 #define CONTENT_BROWSER_LOADER_RESOURCE_REQUEST_INFO_IMPL_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/supports_user_data.h" | 15 #include "base/supports_user_data.h" |
16 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 16 #include "content/browser/loader/resource_requester_info.h" |
17 #include "content/common/resource_request_body_impl.h" | 17 #include "content/common/resource_request_body_impl.h" |
18 #include "content/public/browser/navigation_ui_data.h" | 18 #include "content/public/browser/navigation_ui_data.h" |
19 #include "content/public/browser/resource_request_info.h" | 19 #include "content/public/browser/resource_request_info.h" |
20 #include "content/public/common/referrer.h" | 20 #include "content/public/common/referrer.h" |
21 #include "content/public/common/resource_type.h" | 21 #include "content/public/common/resource_type.h" |
22 #include "net/base/load_states.h" | 22 #include "net/base/load_states.h" |
23 | 23 |
24 namespace content { | 24 namespace content { |
25 class DetachableResourceHandler; | 25 class DetachableResourceHandler; |
26 class ResourceContext; | 26 class ResourceContext; |
27 class ResourceMessageFilter; | 27 class ResourceMessageFilter; |
28 struct GlobalRequestID; | 28 struct GlobalRequestID; |
29 struct GlobalRoutingID; | 29 struct GlobalRoutingID; |
30 | 30 |
31 // Holds the data ResourceDispatcherHost associates with each request. | 31 // Holds the data ResourceDispatcherHost associates with each request. |
32 // Retrieve this data by calling ResourceDispatcherHost::InfoForRequest. | 32 // Retrieve this data by calling ResourceDispatcherHost::InfoForRequest. |
33 class ResourceRequestInfoImpl : public ResourceRequestInfo, | 33 class ResourceRequestInfoImpl : public ResourceRequestInfo, |
34 public base::SupportsUserData::Data { | 34 public base::SupportsUserData::Data { |
35 public: | 35 public: |
36 // Returns the ResourceRequestInfoImpl associated with the given URLRequest. | 36 // Returns the ResourceRequestInfoImpl associated with the given URLRequest. |
37 CONTENT_EXPORT static ResourceRequestInfoImpl* ForRequest( | 37 CONTENT_EXPORT static ResourceRequestInfoImpl* ForRequest( |
38 net::URLRequest* request); | 38 net::URLRequest* request); |
39 | 39 |
40 // And, a const version for cases where you only need read access. | 40 // And, a const version for cases where you only need read access. |
41 CONTENT_EXPORT static const ResourceRequestInfoImpl* ForRequest( | 41 CONTENT_EXPORT static const ResourceRequestInfoImpl* ForRequest( |
42 const net::URLRequest* request); | 42 const net::URLRequest* request); |
43 | 43 |
44 CONTENT_EXPORT ResourceRequestInfoImpl( | 44 CONTENT_EXPORT ResourceRequestInfoImpl( |
45 int process_type, | 45 std::unique_ptr<ResourceRequesterInfo> requester_info, |
46 int child_id, | |
47 int route_id, | 46 int route_id, |
48 int frame_tree_node_id, | 47 int frame_tree_node_id, |
49 int origin_pid, | 48 int origin_pid, |
50 int request_id, | 49 int request_id, |
51 int render_frame_id, | 50 int render_frame_id, |
52 bool is_main_frame, | 51 bool is_main_frame, |
53 bool parent_is_main_frame, | 52 bool parent_is_main_frame, |
54 ResourceType resource_type, | 53 ResourceType resource_type, |
55 ui::PageTransition transition_type, | 54 ui::PageTransition transition_type, |
56 bool should_replace_current_entry, | 55 bool should_replace_current_entry, |
57 bool is_download, | 56 bool is_download, |
58 bool is_stream, | 57 bool is_stream, |
59 bool allow_download, | 58 bool allow_download, |
60 bool has_user_gesture, | 59 bool has_user_gesture, |
61 bool enable_load_timing, | 60 bool enable_load_timing, |
62 bool enable_upload_progress, | 61 bool enable_upload_progress, |
63 bool do_not_prompt_for_login, | 62 bool do_not_prompt_for_login, |
64 blink::WebReferrerPolicy referrer_policy, | 63 blink::WebReferrerPolicy referrer_policy, |
65 blink::WebPageVisibilityState visibility_state, | 64 blink::WebPageVisibilityState visibility_state, |
66 ResourceContext* context, | 65 ResourceContext* context, |
67 base::WeakPtr<ResourceMessageFilter> filter, | |
68 bool report_raw_headers, | 66 bool report_raw_headers, |
69 bool is_async, | 67 bool is_async, |
70 bool is_using_lofi, | 68 bool is_using_lofi, |
71 const std::string& original_headers, | 69 const std::string& original_headers, |
72 const scoped_refptr<ResourceRequestBodyImpl> body, | 70 const scoped_refptr<ResourceRequestBodyImpl> body, |
73 bool initiated_in_secure_context); | 71 bool initiated_in_secure_context); |
74 ~ResourceRequestInfoImpl() override; | 72 ~ResourceRequestInfoImpl() override; |
75 | 73 |
76 // ResourceRequestInfo implementation: | 74 // ResourceRequestInfo implementation: |
77 WebContentsGetter GetWebContentsGetterForRequest() const override; | 75 WebContentsGetter GetWebContentsGetterForRequest() const override; |
(...skipping 24 matching lines...) Expand all Loading... |
102 | 100 |
103 CONTENT_EXPORT int GetRequestID() const; | 101 CONTENT_EXPORT int GetRequestID() const; |
104 CONTENT_EXPORT GlobalRequestID GetGlobalRequestID() const; | 102 CONTENT_EXPORT GlobalRequestID GetGlobalRequestID() const; |
105 GlobalRoutingID GetGlobalRoutingID() const; | 103 GlobalRoutingID GetGlobalRoutingID() const; |
106 | 104 |
107 // PlzNavigate | 105 // PlzNavigate |
108 // The id of the FrameTreeNode that initiated this request (for a navigation | 106 // The id of the FrameTreeNode that initiated this request (for a navigation |
109 // request). | 107 // request). |
110 int frame_tree_node_id() const { return frame_tree_node_id_; } | 108 int frame_tree_node_id() const { return frame_tree_node_id_; } |
111 | 109 |
112 // May be NULL (e.g., if process dies during a transfer). | 110 const ResourceRequesterInfo& requester_info() const { |
113 ResourceMessageFilter* filter() const { | 111 return *(requester_info_.get()); |
114 return filter_.get(); | |
115 } | 112 } |
116 | 113 |
117 // Updates the data associated with this request after it is is transferred | 114 // Updates the data associated with this request after it is is transferred |
118 // to a new renderer process. Not all data will change during a transfer. | 115 // to a new renderer process. Not all data will change during a transfer. |
119 // We do not expect the ResourceContext to change during navigation, so that | 116 // We do not expect the ResourceContext to change during navigation, so that |
120 // does not need to be updated. | 117 // does not need to be updated. |
121 void UpdateForTransfer(int child_id, | 118 void UpdateForTransfer(int route_id, |
122 int route_id, | |
123 int render_frame_id, | 119 int render_frame_id, |
124 int origin_pid, | 120 int origin_pid, |
125 int request_id, | 121 int request_id, |
126 base::WeakPtr<ResourceMessageFilter> filter); | 122 std::unique_ptr<ResourceRequesterInfo> requester_info); |
127 | 123 |
128 // Whether this request is part of a navigation that should replace the | 124 // Whether this request is part of a navigation that should replace the |
129 // current session history entry. This state is shuffled up and down the stack | 125 // current session history entry. This state is shuffled up and down the stack |
130 // for request transfers. | 126 // for request transfers. |
131 bool should_replace_current_entry() const { | 127 bool should_replace_current_entry() const { |
132 return should_replace_current_entry_; | 128 return should_replace_current_entry_; |
133 } | 129 } |
134 | 130 |
135 // DetachableResourceHandler for this request. May be NULL. | 131 // DetachableResourceHandler for this request. May be NULL. |
136 DetachableResourceHandler* detachable_handler() const { | 132 DetachableResourceHandler* detachable_handler() const { |
137 return detachable_handler_; | 133 return detachable_handler_; |
138 } | 134 } |
139 void set_detachable_handler(DetachableResourceHandler* h) { | 135 void set_detachable_handler(DetachableResourceHandler* h) { |
140 detachable_handler_ = h; | 136 detachable_handler_ = h; |
141 } | 137 } |
142 | 138 |
143 // Identifies the type of process (renderer, plugin, etc.) making the request. | |
144 int process_type() const { return process_type_; } | |
145 | |
146 // Downloads are allowed only as a top level request. | 139 // Downloads are allowed only as a top level request. |
147 bool allow_download() const { return allow_download_; } | 140 bool allow_download() const { return allow_download_; } |
148 | 141 |
149 // Whether this is a download. | 142 // Whether this is a download. |
150 void set_is_download(bool download) { is_download_ = download; } | 143 void set_is_download(bool download) { is_download_ = download; } |
151 | 144 |
152 // Whether this is a stream. | 145 // Whether this is a stream. |
153 bool is_stream() const { return is_stream_; } | 146 bool is_stream() const { return is_stream_; } |
154 void set_is_stream(bool stream) { is_stream_ = stream; } | 147 void set_is_stream(bool stream) { is_stream_ = stream; } |
155 | 148 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 } | 183 } |
191 void set_initiated_in_secure_context_for_testing(bool secure) { | 184 void set_initiated_in_secure_context_for_testing(bool secure) { |
192 initiated_in_secure_context_ = secure; | 185 initiated_in_secure_context_ = secure; |
193 } | 186 } |
194 | 187 |
195 void set_navigation_ui_data( | 188 void set_navigation_ui_data( |
196 std::unique_ptr<NavigationUIData> navigation_ui_data) { | 189 std::unique_ptr<NavigationUIData> navigation_ui_data) { |
197 navigation_ui_data_ = std::move(navigation_ui_data); | 190 navigation_ui_data_ = std::move(navigation_ui_data); |
198 } | 191 } |
199 | 192 |
200 // PlzNavigate: used in navigations to store the ServiceWorkerContext, since | |
201 // the ResourceMessageFilter will be null in this case. All other requests | |
202 // should access the ServiceWorkerContext through the ResourceMessageFilter. | |
203 void set_service_worker_context( | |
204 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context) { | |
205 service_worker_context_ = service_worker_context; | |
206 } | |
207 ServiceWorkerContextWrapper* service_worker_context() const { | |
208 return service_worker_context_.get(); | |
209 } | |
210 | |
211 private: | 193 private: |
212 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 194 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
213 DeletedFilterDetached); | 195 DeletedFilterDetached); |
214 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 196 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
215 DeletedFilterDetachedRedirect); | 197 DeletedFilterDetachedRedirect); |
216 // Non-owning, may be NULL. | 198 // Non-owning, may be NULL. |
217 DetachableResourceHandler* detachable_handler_; | 199 DetachableResourceHandler* detachable_handler_; |
218 | 200 |
219 int process_type_; | 201 std::unique_ptr<ResourceRequesterInfo> requester_info_; |
220 int child_id_; | |
221 int route_id_; | 202 int route_id_; |
222 const int frame_tree_node_id_; | 203 const int frame_tree_node_id_; |
223 int origin_pid_; | 204 int origin_pid_; |
224 int request_id_; | 205 int request_id_; |
225 int render_frame_id_; | 206 int render_frame_id_; |
226 bool is_main_frame_; | 207 bool is_main_frame_; |
227 bool parent_is_main_frame_; | 208 bool parent_is_main_frame_; |
228 bool should_replace_current_entry_; | 209 bool should_replace_current_entry_; |
229 bool is_download_; | 210 bool is_download_; |
230 bool is_stream_; | 211 bool is_stream_; |
231 bool allow_download_; | 212 bool allow_download_; |
232 bool has_user_gesture_; | 213 bool has_user_gesture_; |
233 bool enable_load_timing_; | 214 bool enable_load_timing_; |
234 bool enable_upload_progress_; | 215 bool enable_upload_progress_; |
235 bool do_not_prompt_for_login_; | 216 bool do_not_prompt_for_login_; |
236 bool was_ignored_by_handler_; | 217 bool was_ignored_by_handler_; |
237 bool counted_as_in_flight_request_; | 218 bool counted_as_in_flight_request_; |
238 ResourceType resource_type_; | 219 ResourceType resource_type_; |
239 ui::PageTransition transition_type_; | 220 ui::PageTransition transition_type_; |
240 int memory_cost_; | 221 int memory_cost_; |
241 blink::WebReferrerPolicy referrer_policy_; | 222 blink::WebReferrerPolicy referrer_policy_; |
242 blink::WebPageVisibilityState visibility_state_; | 223 blink::WebPageVisibilityState visibility_state_; |
243 ResourceContext* context_; | 224 ResourceContext* context_; |
244 // The filter might be deleted without deleting this object if the process | |
245 // exits during a transfer. | |
246 base::WeakPtr<ResourceMessageFilter> filter_; | |
247 bool report_raw_headers_; | 225 bool report_raw_headers_; |
248 bool is_async_; | 226 bool is_async_; |
249 bool is_using_lofi_; | 227 bool is_using_lofi_; |
250 const std::string original_headers_; | 228 const std::string original_headers_; |
251 scoped_refptr<ResourceRequestBodyImpl> body_; | 229 scoped_refptr<ResourceRequestBodyImpl> body_; |
252 bool initiated_in_secure_context_; | 230 bool initiated_in_secure_context_; |
253 std::unique_ptr<NavigationUIData> navigation_ui_data_; | 231 std::unique_ptr<NavigationUIData> navigation_ui_data_; |
254 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; | |
255 | 232 |
256 DISALLOW_COPY_AND_ASSIGN(ResourceRequestInfoImpl); | 233 DISALLOW_COPY_AND_ASSIGN(ResourceRequestInfoImpl); |
257 }; | 234 }; |
258 | 235 |
259 } // namespace content | 236 } // namespace content |
260 | 237 |
261 #endif // CONTENT_BROWSER_LOADER_RESOURCE_REQUEST_INFO_IMPL_H_ | 238 #endif // CONTENT_BROWSER_LOADER_RESOURCE_REQUEST_INFO_IMPL_H_ |
OLD | NEW |