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_
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"
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
{
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(
46 int frame_tree_node_id
,
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
,
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
,
68 ~ResourceRequestInfoImpl() override
;
70 // ResourceRequestInfo implementation:
71 ResourceContext
* GetContext() const override
;
72 int GetChildID() const override
;
73 int GetRouteID() const override
;
74 int GetOriginPID() const override
;
75 int GetRequestID() const override
;
76 int GetRenderFrameID() const override
;
77 bool IsMainFrame() const override
;
78 bool ParentIsMainFrame() const override
;
79 int GetParentRenderFrameID() const override
;
80 ResourceType
GetResourceType() const override
;
81 int GetProcessType() const override
;
82 blink::WebReferrerPolicy
GetReferrerPolicy() const override
;
83 blink::WebPageVisibilityState
GetVisibilityState() const override
;
84 ui::PageTransition
GetPageTransition() const override
;
85 bool HasUserGesture() const override
;
86 bool WasIgnoredByHandler() const override
;
87 bool GetAssociatedRenderFrame(int* render_process_id
,
88 int* render_frame_id
) const override
;
89 bool IsAsync() const override
;
90 bool IsDownload() const override
;
92 CONTENT_EXPORT
void AssociateWithRequest(net::URLRequest
* request
);
94 CONTENT_EXPORT GlobalRequestID
GetGlobalRequestID() const;
95 GlobalRoutingID
GetGlobalRoutingID() const;
98 // The id of the FrameTreeNode that initiated this request (for a navigation
100 int frame_tree_node_id() const { return frame_tree_node_id_
; }
102 // May be NULL (e.g., if process dies during a transfer).
103 ResourceMessageFilter
* filter() const {
104 return filter_
.get();
107 // Updates the data associated with this request after it is is transferred
108 // to a new renderer process. Not all data will change during a transfer.
109 // We do not expect the ResourceContext to change during navigation, so that
110 // does not need to be updated.
111 void UpdateForTransfer(int child_id
,
115 int parent_render_frame_id
,
116 base::WeakPtr
<ResourceMessageFilter
> filter
);
118 // CrossSiteResourceHandler for this request. May be null.
119 CrossSiteResourceHandler
* cross_site_handler() {
120 return cross_site_handler_
;
122 void set_cross_site_handler(CrossSiteResourceHandler
* h
) {
123 cross_site_handler_
= h
;
126 // Whether this request is part of a navigation that should replace the
127 // current session history entry. This state is shuffled up and down the stack
128 // for request transfers.
129 bool should_replace_current_entry() const {
130 return should_replace_current_entry_
;
133 // DetachableResourceHandler for this request. May be NULL.
134 DetachableResourceHandler
* detachable_handler() const {
135 return detachable_handler_
;
137 void set_detachable_handler(DetachableResourceHandler
* h
) {
138 detachable_handler_
= h
;
141 // Identifies the type of process (renderer, plugin, etc.) making the request.
142 int process_type() const { return process_type_
; }
144 // Downloads are allowed only as a top level request.
145 bool allow_download() const { return allow_download_
; }
147 // Whether this is a download.
148 void set_is_download(bool download
) { is_download_
= download
; }
150 // Whether this is a stream.
151 bool is_stream() const { return is_stream_
; }
152 void set_is_stream(bool stream
) { is_stream_
= stream
; }
154 void set_was_ignored_by_handler(bool value
) {
155 was_ignored_by_handler_
= value
;
158 // Whether this request has been counted towards the number of in flight
159 // requests, which is only true for requests that require a file descriptor
160 // for their shared memory buffer.
161 bool counted_as_in_flight_request() const {
162 return counted_as_in_flight_request_
;
164 void set_counted_as_in_flight_request(bool was_counted
) {
165 counted_as_in_flight_request_
= was_counted
;
168 // The approximate in-memory size (bytes) that we credited this request
169 // as consuming in |outstanding_requests_memory_cost_map_|.
170 int memory_cost() const { return memory_cost_
; }
171 void set_memory_cost(int cost
) { memory_cost_
= cost
; }
173 bool is_load_timing_enabled() const { return enable_load_timing_
; }
175 bool is_upload_progress_enabled() const { return enable_upload_progress_
; }
177 bool do_not_prompt_for_login() const { return do_not_prompt_for_login_
; }
178 void set_do_not_prompt_for_login(bool do_not_prompt
) {
179 do_not_prompt_for_login_
= do_not_prompt
;
183 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest
,
184 DeletedFilterDetached
);
185 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest
,
186 DeletedFilterDetachedRedirect
);
187 // Non-owning, may be NULL.
188 CrossSiteResourceHandler
* cross_site_handler_
;
189 DetachableResourceHandler
* detachable_handler_
;
194 const int frame_tree_node_id_
;
197 int render_frame_id_
;
199 bool parent_is_main_frame_
;
200 int parent_render_frame_id_
;
201 bool should_replace_current_entry_
;
204 bool allow_download_
;
205 bool has_user_gesture_
;
206 bool enable_load_timing_
;
207 bool enable_upload_progress_
;
208 bool do_not_prompt_for_login_
;
209 bool was_ignored_by_handler_
;
210 bool counted_as_in_flight_request_
;
211 ResourceType resource_type_
;
212 ui::PageTransition transition_type_
;
214 blink::WebReferrerPolicy referrer_policy_
;
215 blink::WebPageVisibilityState visibility_state_
;
216 ResourceContext
* context_
;
217 // The filter might be deleted without deleting this object if the process
218 // exits during a transfer.
219 base::WeakPtr
<ResourceMessageFilter
> filter_
;
222 DISALLOW_COPY_AND_ASSIGN(ResourceRequestInfoImpl
);
225 } // namespace content
227 #endif // CONTENT_BROWSER_LOADER_RESOURCE_REQUEST_INFO_IMPL_H_