[refactor] More post-NSS WebCrypto cleanups (utility functions).
[chromium-blink-merge.git] / content / browser / loader / resource_request_info_impl.h
blobf0251e51325e14ecf88755cb3ec335597b704b31
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_LOADER_RESOURCE_REQUEST_INFO_IMPL_H_
6 #define CONTENT_BROWSER_LOADER_RESOURCE_REQUEST_INFO_IMPL_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/gtest_prod_util.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/supports_user_data.h"
16 #include "content/public/browser/resource_request_info.h"
17 #include "content/public/common/referrer.h"
18 #include "content/public/common/resource_type.h"
19 #include "net/base/load_states.h"
21 namespace content {
22 class CrossSiteResourceHandler;
23 class DetachableResourceHandler;
24 class ResourceContext;
25 class ResourceMessageFilter;
26 struct GlobalRequestID;
27 struct GlobalRoutingID;
29 // Holds the data ResourceDispatcherHost associates with each request.
30 // Retrieve this data by calling ResourceDispatcherHost::InfoForRequest.
31 class ResourceRequestInfoImpl : public ResourceRequestInfo,
32 public base::SupportsUserData::Data {
33 public:
34 // Returns the ResourceRequestInfoImpl associated with the given URLRequest.
35 CONTENT_EXPORT static ResourceRequestInfoImpl* ForRequest(
36 net::URLRequest* request);
38 // And, a const version for cases where you only need read access.
39 CONTENT_EXPORT static const ResourceRequestInfoImpl* ForRequest(
40 const net::URLRequest* request);
42 CONTENT_EXPORT ResourceRequestInfoImpl(
43 int process_type,
44 int child_id,
45 int route_id,
46 int frame_tree_node_id,
47 int origin_pid,
48 int request_id,
49 int render_frame_id,
50 bool is_main_frame,
51 bool parent_is_main_frame,
52 int parent_render_frame_id,
53 ResourceType resource_type,
54 ui::PageTransition transition_type,
55 bool should_replace_current_entry,
56 bool is_download,
57 bool is_stream,
58 bool allow_download,
59 bool has_user_gesture,
60 bool enable_load_timing,
61 bool enable_upload_progress,
62 bool do_not_prompt_for_login,
63 blink::WebReferrerPolicy referrer_policy,
64 blink::WebPageVisibilityState visibility_state,
65 ResourceContext* context,
66 base::WeakPtr<ResourceMessageFilter> filter,
67 bool report_raw_headers,
68 bool is_async);
69 ~ResourceRequestInfoImpl() override;
71 // ResourceRequestInfo implementation:
72 ResourceContext* GetContext() const override;
73 int GetChildID() const override;
74 int GetRouteID() const override;
75 int GetOriginPID() const override;
76 int GetRequestID() const override;
77 int GetRenderFrameID() const override;
78 bool IsMainFrame() const override;
79 bool ParentIsMainFrame() const override;
80 int GetParentRenderFrameID() const override;
81 ResourceType GetResourceType() const override;
82 int GetProcessType() const override;
83 blink::WebReferrerPolicy GetReferrerPolicy() const override;
84 blink::WebPageVisibilityState GetVisibilityState() const override;
85 ui::PageTransition GetPageTransition() const override;
86 bool HasUserGesture() const override;
87 bool WasIgnoredByHandler() const override;
88 bool GetAssociatedRenderFrame(int* render_process_id,
89 int* render_frame_id) const override;
90 bool IsAsync() const override;
91 bool IsDownload() const override;
92 bool ShouldReportRawHeaders() const;
94 CONTENT_EXPORT void AssociateWithRequest(net::URLRequest* request);
96 CONTENT_EXPORT GlobalRequestID GetGlobalRequestID() const;
97 GlobalRoutingID GetGlobalRoutingID() const;
99 // PlzNavigate
100 // The id of the FrameTreeNode that initiated this request (for a navigation
101 // request).
102 int frame_tree_node_id() const { return frame_tree_node_id_; }
104 // May be NULL (e.g., if process dies during a transfer).
105 ResourceMessageFilter* filter() const {
106 return filter_.get();
109 // Updates the data associated with this request after it is is transferred
110 // to a new renderer process. Not all data will change during a transfer.
111 // We do not expect the ResourceContext to change during navigation, so that
112 // does not need to be updated.
113 void UpdateForTransfer(int child_id,
114 int route_id,
115 int origin_pid,
116 int request_id,
117 int parent_render_frame_id,
118 base::WeakPtr<ResourceMessageFilter> filter);
120 // CrossSiteResourceHandler for this request. May be null.
121 CrossSiteResourceHandler* cross_site_handler() {
122 return cross_site_handler_;
124 void set_cross_site_handler(CrossSiteResourceHandler* h) {
125 cross_site_handler_ = h;
128 // 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
130 // for request transfers.
131 bool should_replace_current_entry() const {
132 return should_replace_current_entry_;
135 // DetachableResourceHandler for this request. May be NULL.
136 DetachableResourceHandler* detachable_handler() const {
137 return detachable_handler_;
139 void set_detachable_handler(DetachableResourceHandler* h) {
140 detachable_handler_ = h;
143 // Identifies the type of process (renderer, plugin, etc.) making the request.
144 int process_type() const { return process_type_; }
146 // Downloads are allowed only as a top level request.
147 bool allow_download() const { return allow_download_; }
149 // Whether this is a download.
150 void set_is_download(bool download) { is_download_ = download; }
152 // Whether this is a stream.
153 bool is_stream() const { return is_stream_; }
154 void set_is_stream(bool stream) { is_stream_ = stream; }
156 void set_was_ignored_by_handler(bool value) {
157 was_ignored_by_handler_ = value;
160 // Whether this request has been counted towards the number of in flight
161 // requests, which is only true for requests that require a file descriptor
162 // for their shared memory buffer.
163 bool counted_as_in_flight_request() const {
164 return counted_as_in_flight_request_;
166 void set_counted_as_in_flight_request(bool was_counted) {
167 counted_as_in_flight_request_ = was_counted;
170 // The approximate in-memory size (bytes) that we credited this request
171 // as consuming in |outstanding_requests_memory_cost_map_|.
172 int memory_cost() const { return memory_cost_; }
173 void set_memory_cost(int cost) { memory_cost_ = cost; }
175 bool is_load_timing_enabled() const { return enable_load_timing_; }
177 bool is_upload_progress_enabled() const { return enable_upload_progress_; }
179 bool do_not_prompt_for_login() const { return do_not_prompt_for_login_; }
180 void set_do_not_prompt_for_login(bool do_not_prompt) {
181 do_not_prompt_for_login_ = do_not_prompt;
184 private:
185 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest,
186 DeletedFilterDetached);
187 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest,
188 DeletedFilterDetachedRedirect);
189 // Non-owning, may be NULL.
190 CrossSiteResourceHandler* cross_site_handler_;
191 DetachableResourceHandler* detachable_handler_;
193 int process_type_;
194 int child_id_;
195 int route_id_;
196 const int frame_tree_node_id_;
197 int origin_pid_;
198 int request_id_;
199 int render_frame_id_;
200 bool is_main_frame_;
201 bool parent_is_main_frame_;
202 int parent_render_frame_id_;
203 bool should_replace_current_entry_;
204 bool is_download_;
205 bool is_stream_;
206 bool allow_download_;
207 bool has_user_gesture_;
208 bool enable_load_timing_;
209 bool enable_upload_progress_;
210 bool do_not_prompt_for_login_;
211 bool was_ignored_by_handler_;
212 bool counted_as_in_flight_request_;
213 ResourceType resource_type_;
214 ui::PageTransition transition_type_;
215 int memory_cost_;
216 blink::WebReferrerPolicy referrer_policy_;
217 blink::WebPageVisibilityState visibility_state_;
218 ResourceContext* context_;
219 // The filter might be deleted without deleting this object if the process
220 // exits during a transfer.
221 base::WeakPtr<ResourceMessageFilter> filter_;
222 bool report_raw_headers_;
223 bool is_async_;
225 DISALLOW_COPY_AND_ASSIGN(ResourceRequestInfoImpl);
228 } // namespace content
230 #endif // CONTENT_BROWSER_LOADER_RESOURCE_REQUEST_INFO_IMPL_H_