Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(251)

Side by Side Diff: content/browser/loader/resource_request_info_impl.h

Issue 2481093003: Introduce ResourceRequesterInfo to abstract the requester of resource request (Closed)
Patch Set: fix URLLoaderFactoryImplTest/URLLoaderFactoryImplTest.GetFailedResponse2 Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include <utility> 10 #include <utility>
11 11
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/memory/weak_ptr.h"
17 #include "base/supports_user_data.h" 16 #include "base/supports_user_data.h"
18 #include "content/browser/service_worker/service_worker_context_wrapper.h" 17 #include "content/browser/loader/resource_requester_info.h"
19 #include "content/common/resource_request_body_impl.h" 18 #include "content/common/resource_request_body_impl.h"
20 #include "content/common/url_loader.mojom.h" 19 #include "content/common/url_loader.mojom.h"
21 #include "content/public/browser/navigation_ui_data.h" 20 #include "content/public/browser/navigation_ui_data.h"
22 #include "content/public/browser/resource_request_info.h" 21 #include "content/public/browser/resource_request_info.h"
23 #include "content/public/common/referrer.h" 22 #include "content/public/common/referrer.h"
24 #include "content/public/common/resource_type.h" 23 #include "content/public/common/resource_type.h"
25 #include "net/base/load_states.h" 24 #include "net/base/load_states.h"
26 25
27 namespace content { 26 namespace content {
28 class DetachableResourceHandler; 27 class DetachableResourceHandler;
29 class ResourceContext; 28 class ResourceContext;
30 class ResourceMessageFilter;
31 struct GlobalRequestID; 29 struct GlobalRequestID;
32 struct GlobalRoutingID; 30 struct GlobalRoutingID;
33 31
34 // Holds the data ResourceDispatcherHost associates with each request. 32 // Holds the data ResourceDispatcherHost associates with each request.
35 // Retrieve this data by calling ResourceDispatcherHost::InfoForRequest. 33 // Retrieve this data by calling ResourceDispatcherHost::InfoForRequest.
36 class ResourceRequestInfoImpl : public ResourceRequestInfo, 34 class ResourceRequestInfoImpl : public ResourceRequestInfo,
37 public base::SupportsUserData::Data { 35 public base::SupportsUserData::Data {
38 public: 36 public:
39 using TransferCallback = 37 using TransferCallback =
40 base::Callback<void(mojom::URLLoaderAssociatedRequest, 38 base::Callback<void(mojom::URLLoaderAssociatedRequest,
41 mojom::URLLoaderClientAssociatedPtr)>; 39 mojom::URLLoaderClientAssociatedPtr)>;
42 40
43 // Returns the ResourceRequestInfoImpl associated with the given URLRequest. 41 // Returns the ResourceRequestInfoImpl associated with the given URLRequest.
44 CONTENT_EXPORT static ResourceRequestInfoImpl* ForRequest( 42 CONTENT_EXPORT static ResourceRequestInfoImpl* ForRequest(
45 net::URLRequest* request); 43 net::URLRequest* request);
46 44
47 // And, a const version for cases where you only need read access. 45 // And, a const version for cases where you only need read access.
48 CONTENT_EXPORT static const ResourceRequestInfoImpl* ForRequest( 46 CONTENT_EXPORT static const ResourceRequestInfoImpl* ForRequest(
49 const net::URLRequest* request); 47 const net::URLRequest* request);
50 48
51 CONTENT_EXPORT ResourceRequestInfoImpl( 49 CONTENT_EXPORT ResourceRequestInfoImpl(
52 int process_type, 50 scoped_refptr<ResourceRequesterInfo> requester_info,
53 int child_id,
54 int route_id, 51 int route_id,
55 int frame_tree_node_id, 52 int frame_tree_node_id,
56 int origin_pid, 53 int origin_pid,
57 int request_id, 54 int request_id,
58 int render_frame_id, 55 int render_frame_id,
59 bool is_main_frame, 56 bool is_main_frame,
60 bool parent_is_main_frame, 57 bool parent_is_main_frame,
61 ResourceType resource_type, 58 ResourceType resource_type,
62 ui::PageTransition transition_type, 59 ui::PageTransition transition_type,
63 bool should_replace_current_entry, 60 bool should_replace_current_entry,
64 bool is_download, 61 bool is_download,
65 bool is_stream, 62 bool is_stream,
66 bool allow_download, 63 bool allow_download,
67 bool has_user_gesture, 64 bool has_user_gesture,
68 bool enable_load_timing, 65 bool enable_load_timing,
69 bool enable_upload_progress, 66 bool enable_upload_progress,
70 bool do_not_prompt_for_login, 67 bool do_not_prompt_for_login,
71 blink::WebReferrerPolicy referrer_policy, 68 blink::WebReferrerPolicy referrer_policy,
72 blink::WebPageVisibilityState visibility_state, 69 blink::WebPageVisibilityState visibility_state,
73 ResourceContext* context, 70 ResourceContext* context,
74 base::WeakPtr<ResourceMessageFilter> filter,
75 bool report_raw_headers, 71 bool report_raw_headers,
76 bool is_async, 72 bool is_async,
77 bool is_using_lofi, 73 bool is_using_lofi,
78 const std::string& original_headers, 74 const std::string& original_headers,
79 const scoped_refptr<ResourceRequestBodyImpl> body, 75 const scoped_refptr<ResourceRequestBodyImpl> body,
80 bool initiated_in_secure_context); 76 bool initiated_in_secure_context);
81 ~ResourceRequestInfoImpl() override; 77 ~ResourceRequestInfoImpl() override;
82 78
83 // ResourceRequestInfo implementation: 79 // ResourceRequestInfo implementation:
84 WebContentsGetter GetWebContentsGetterForRequest() const override; 80 WebContentsGetter GetWebContentsGetterForRequest() const override;
(...skipping 24 matching lines...) Expand all
109 CONTENT_EXPORT void AssociateWithRequest(net::URLRequest* request); 105 CONTENT_EXPORT void AssociateWithRequest(net::URLRequest* request);
110 106
111 CONTENT_EXPORT int GetRequestID() const; 107 CONTENT_EXPORT int GetRequestID() const;
112 GlobalRoutingID GetGlobalRoutingID() const; 108 GlobalRoutingID GetGlobalRoutingID() const;
113 109
114 // PlzNavigate 110 // PlzNavigate
115 // The id of the FrameTreeNode that initiated this request (for a navigation 111 // The id of the FrameTreeNode that initiated this request (for a navigation
116 // request). 112 // request).
117 int frame_tree_node_id() const { return frame_tree_node_id_; } 113 int frame_tree_node_id() const { return frame_tree_node_id_; }
118 114
119 // May be NULL (e.g., if process dies during a transfer). 115 ResourceRequesterInfo* requester_info() { return requester_info_.get(); }
120 ResourceMessageFilter* filter() const {
121 return filter_.get();
122 }
123 116
124 // Updates the data associated with this request after it is is transferred 117 // Updates the data associated with this request after it is is transferred
125 // to a new renderer process. Not all data will change during a transfer. 118 // to a new renderer process. Not all data will change during a transfer.
126 // We do not expect the ResourceContext to change during navigation, so that 119 // We do not expect the ResourceContext to change during navigation, so that
127 // does not need to be updated. 120 // does not need to be updated.
128 void UpdateForTransfer(int child_id, 121 void UpdateForTransfer(int route_id,
129 int route_id,
130 int render_frame_id, 122 int render_frame_id,
131 int origin_pid, 123 int origin_pid,
132 int request_id, 124 int request_id,
133 base::WeakPtr<ResourceMessageFilter> filter, 125 ResourceRequesterInfo* requester_info,
134 mojom::URLLoaderAssociatedRequest url_loader_request, 126 mojom::URLLoaderAssociatedRequest url_loader_request,
135 mojom::URLLoaderClientAssociatedPtr url_loader_client); 127 mojom::URLLoaderClientAssociatedPtr url_loader_client);
136 128
137 // Whether this request is part of a navigation that should replace the 129 // Whether this request is part of a navigation that should replace the
138 // current session history entry. This state is shuffled up and down the stack 130 // current session history entry. This state is shuffled up and down the stack
139 // for request transfers. 131 // for request transfers.
140 bool should_replace_current_entry() const { 132 bool should_replace_current_entry() const {
141 return should_replace_current_entry_; 133 return should_replace_current_entry_;
142 } 134 }
143 135
144 // DetachableResourceHandler for this request. May be NULL. 136 // DetachableResourceHandler for this request. May be NULL.
145 DetachableResourceHandler* detachable_handler() const { 137 DetachableResourceHandler* detachable_handler() const {
146 return detachable_handler_; 138 return detachable_handler_;
147 } 139 }
148 void set_detachable_handler(DetachableResourceHandler* h) { 140 void set_detachable_handler(DetachableResourceHandler* h) {
149 detachable_handler_ = h; 141 detachable_handler_ = h;
150 } 142 }
151 143
152 // Identifies the type of process (renderer, plugin, etc.) making the request.
153 int process_type() const { return process_type_; }
154
155 // Downloads are allowed only as a top level request. 144 // Downloads are allowed only as a top level request.
156 bool allow_download() const { return allow_download_; } 145 bool allow_download() const { return allow_download_; }
157 146
158 // Whether this is a download. 147 // Whether this is a download.
159 void set_is_download(bool download) { is_download_ = download; } 148 void set_is_download(bool download) { is_download_ = download; }
160 149
161 // Whether this is a stream. 150 // Whether this is a stream.
162 bool is_stream() const { return is_stream_; } 151 bool is_stream() const { return is_stream_; }
163 void set_is_stream(bool stream) { is_stream_ = stream; } 152 void set_is_stream(bool stream) { is_stream_ = stream; }
164 153
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 } 188 }
200 void set_initiated_in_secure_context_for_testing(bool secure) { 189 void set_initiated_in_secure_context_for_testing(bool secure) {
201 initiated_in_secure_context_ = secure; 190 initiated_in_secure_context_ = secure;
202 } 191 }
203 192
204 void set_navigation_ui_data( 193 void set_navigation_ui_data(
205 std::unique_ptr<NavigationUIData> navigation_ui_data) { 194 std::unique_ptr<NavigationUIData> navigation_ui_data) {
206 navigation_ui_data_ = std::move(navigation_ui_data); 195 navigation_ui_data_ = std::move(navigation_ui_data);
207 } 196 }
208 197
209 // PlzNavigate: used in navigations to store the ServiceWorkerContext, since
210 // the ResourceMessageFilter will be null in this case. All other requests
211 // should access the ServiceWorkerContext through the ResourceMessageFilter.
212 void set_service_worker_context(
213 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context) {
214 service_worker_context_ = service_worker_context;
215 }
216 ServiceWorkerContextWrapper* service_worker_context() const {
217 return service_worker_context_.get();
218 }
219
220 void set_on_transfer(const TransferCallback& on_transfer) { 198 void set_on_transfer(const TransferCallback& on_transfer) {
221 on_transfer_ = on_transfer; 199 on_transfer_ = on_transfer;
222 } 200 }
223 201
224 private: 202 private:
225 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, 203 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest,
226 DeletedFilterDetached); 204 DeletedFilterDetached);
227 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, 205 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest,
228 DeletedFilterDetachedRedirect); 206 DeletedFilterDetachedRedirect);
229 // Non-owning, may be NULL. 207 // Non-owning, may be NULL.
230 DetachableResourceHandler* detachable_handler_; 208 DetachableResourceHandler* detachable_handler_;
231 209
232 int process_type_; 210 scoped_refptr<ResourceRequesterInfo> requester_info_;
233 int child_id_;
234 int route_id_; 211 int route_id_;
235 const int frame_tree_node_id_; 212 const int frame_tree_node_id_;
236 int origin_pid_; 213 int origin_pid_;
237 int request_id_; 214 int request_id_;
238 int render_frame_id_; 215 int render_frame_id_;
239 bool is_main_frame_; 216 bool is_main_frame_;
240 bool parent_is_main_frame_; 217 bool parent_is_main_frame_;
241 bool should_replace_current_entry_; 218 bool should_replace_current_entry_;
242 bool is_download_; 219 bool is_download_;
243 bool is_stream_; 220 bool is_stream_;
244 bool allow_download_; 221 bool allow_download_;
245 bool has_user_gesture_; 222 bool has_user_gesture_;
246 bool enable_load_timing_; 223 bool enable_load_timing_;
247 bool enable_upload_progress_; 224 bool enable_upload_progress_;
248 bool do_not_prompt_for_login_; 225 bool do_not_prompt_for_login_;
249 bool was_ignored_by_handler_; 226 bool was_ignored_by_handler_;
250 bool counted_as_in_flight_request_; 227 bool counted_as_in_flight_request_;
251 ResourceType resource_type_; 228 ResourceType resource_type_;
252 ui::PageTransition transition_type_; 229 ui::PageTransition transition_type_;
253 int memory_cost_; 230 int memory_cost_;
254 blink::WebReferrerPolicy referrer_policy_; 231 blink::WebReferrerPolicy referrer_policy_;
255 blink::WebPageVisibilityState visibility_state_; 232 blink::WebPageVisibilityState visibility_state_;
256 ResourceContext* context_; 233 ResourceContext* context_;
257 // The filter might be deleted without deleting this object if the process
258 // exits during a transfer.
259 base::WeakPtr<ResourceMessageFilter> filter_;
260 bool report_raw_headers_; 234 bool report_raw_headers_;
261 bool is_async_; 235 bool is_async_;
262 bool is_using_lofi_; 236 bool is_using_lofi_;
263 const std::string original_headers_; 237 const std::string original_headers_;
264 scoped_refptr<ResourceRequestBodyImpl> body_; 238 scoped_refptr<ResourceRequestBodyImpl> body_;
265 bool initiated_in_secure_context_; 239 bool initiated_in_secure_context_;
266 std::unique_ptr<NavigationUIData> navigation_ui_data_; 240 std::unique_ptr<NavigationUIData> navigation_ui_data_;
267 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_;
268 241
269 // This callback is set by MojoAsyncResourceHandler to update its mojo binding 242 // This callback is set by MojoAsyncResourceHandler to update its mojo binding
270 // and remote endpoint. This callback will be removed once PlzNavigate is 243 // and remote endpoint. This callback will be removed once PlzNavigate is
271 // shipped. 244 // shipped.
272 TransferCallback on_transfer_; 245 TransferCallback on_transfer_;
273 246
274 DISALLOW_COPY_AND_ASSIGN(ResourceRequestInfoImpl); 247 DISALLOW_COPY_AND_ASSIGN(ResourceRequestInfoImpl);
275 }; 248 };
276 249
277 } // namespace content 250 } // namespace content
278 251
279 #endif // CONTENT_BROWSER_LOADER_RESOURCE_REQUEST_INFO_IMPL_H_ 252 #endif // CONTENT_BROWSER_LOADER_RESOURCE_REQUEST_INFO_IMPL_H_
OLDNEW
« no previous file with comments | « content/browser/loader/resource_message_filter.cc ('k') | content/browser/loader/resource_request_info_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698