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(
50 bool parent_is_main_frame
,
51 int parent_render_frame_id
,
52 ResourceType resource_type
,
53 ui::PageTransition transition_type
,
54 bool should_replace_current_entry
,
58 bool has_user_gesture
,
59 bool enable_load_timing
,
60 bool enable_upload_progress
,
61 blink::WebReferrerPolicy referrer_policy
,
62 blink::WebPageVisibilityState visibility_state
,
63 ResourceContext
* context
,
64 base::WeakPtr
<ResourceMessageFilter
> filter
,
66 ~ResourceRequestInfoImpl() override
;
68 // ResourceRequestInfo implementation:
69 ResourceContext
* GetContext() const override
;
70 int GetChildID() const override
;
71 int GetRouteID() const override
;
72 int GetOriginPID() const override
;
73 int GetRequestID() const override
;
74 int GetRenderFrameID() const override
;
75 bool IsMainFrame() const override
;
76 bool ParentIsMainFrame() const override
;
77 int GetParentRenderFrameID() const override
;
78 ResourceType
GetResourceType() const override
;
79 int GetProcessType() const override
;
80 blink::WebReferrerPolicy
GetReferrerPolicy() const override
;
81 blink::WebPageVisibilityState
GetVisibilityState() const override
;
82 ui::PageTransition
GetPageTransition() const override
;
83 bool HasUserGesture() const override
;
84 bool WasIgnoredByHandler() const override
;
85 bool GetAssociatedRenderFrame(int* render_process_id
,
86 int* render_frame_id
) const override
;
87 bool IsAsync() const override
;
88 bool IsDownload() const override
;
90 CONTENT_EXPORT
void AssociateWithRequest(net::URLRequest
* request
);
92 CONTENT_EXPORT GlobalRequestID
GetGlobalRequestID() const;
93 GlobalRoutingID
GetGlobalRoutingID() const;
95 // May be NULL (e.g., if process dies during a transfer).
96 ResourceMessageFilter
* filter() const {
100 // Updates the data associated with this request after it is is transferred
101 // to a new renderer process. Not all data will change during a transfer.
102 // We do not expect the ResourceContext to change during navigation, so that
103 // does not need to be updated.
104 void UpdateForTransfer(int child_id
,
108 int parent_render_frame_id
,
109 base::WeakPtr
<ResourceMessageFilter
> filter
);
111 // CrossSiteResourceHandler for this request. May be null.
112 CrossSiteResourceHandler
* cross_site_handler() {
113 return cross_site_handler_
;
115 void set_cross_site_handler(CrossSiteResourceHandler
* h
) {
116 cross_site_handler_
= h
;
119 // Whether this request is part of a navigation that should replace the
120 // current session history entry. This state is shuffled up and down the stack
121 // for request transfers.
122 bool should_replace_current_entry() const {
123 return should_replace_current_entry_
;
126 // DetachableResourceHandler for this request. May be NULL.
127 DetachableResourceHandler
* detachable_handler() const {
128 return detachable_handler_
;
130 void set_detachable_handler(DetachableResourceHandler
* h
) {
131 detachable_handler_
= h
;
134 // Identifies the type of process (renderer, plugin, etc.) making the request.
135 int process_type() const { return process_type_
; }
137 // Downloads are allowed only as a top level request.
138 bool allow_download() const { return allow_download_
; }
140 // Whether this is a download.
141 void set_is_download(bool download
) { is_download_
= download
; }
143 // Whether this is a stream.
144 bool is_stream() const { return is_stream_
; }
145 void set_is_stream(bool stream
) { is_stream_
= stream
; }
147 void set_was_ignored_by_handler(bool value
) {
148 was_ignored_by_handler_
= value
;
151 // Whether this request has been counted towards the number of in flight
152 // requests, which is only true for requests that require a file descriptor
153 // for their shared memory buffer.
154 bool counted_as_in_flight_request() const {
155 return counted_as_in_flight_request_
;
157 void set_counted_as_in_flight_request(bool was_counted
) {
158 counted_as_in_flight_request_
= was_counted
;
161 // The approximate in-memory size (bytes) that we credited this request
162 // as consuming in |outstanding_requests_memory_cost_map_|.
163 int memory_cost() const { return memory_cost_
; }
164 void set_memory_cost(int cost
) { memory_cost_
= cost
; }
166 bool is_load_timing_enabled() const { return enable_load_timing_
; }
168 bool is_upload_progress_enabled() const { return enable_upload_progress_
; }
171 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest
,
172 DeletedFilterDetached
);
173 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest
,
174 DeletedFilterDetachedRedirect
);
175 // Non-owning, may be NULL.
176 CrossSiteResourceHandler
* cross_site_handler_
;
177 DetachableResourceHandler
* detachable_handler_
;
184 int render_frame_id_
;
186 bool parent_is_main_frame_
;
187 int parent_render_frame_id_
;
188 bool should_replace_current_entry_
;
191 bool allow_download_
;
192 bool has_user_gesture_
;
193 bool enable_load_timing_
;
194 bool enable_upload_progress_
;
195 bool was_ignored_by_handler_
;
196 bool counted_as_in_flight_request_
;
197 ResourceType resource_type_
;
198 ui::PageTransition transition_type_
;
200 blink::WebReferrerPolicy referrer_policy_
;
201 blink::WebPageVisibilityState visibility_state_
;
202 ResourceContext
* context_
;
203 // The filter might be deleted without deleting this object if the process
204 // exits during a transfer.
205 base::WeakPtr
<ResourceMessageFilter
> filter_
;
208 DISALLOW_COPY_AND_ASSIGN(ResourceRequestInfoImpl
);
211 } // namespace content
213 #endif // CONTENT_BROWSER_LOADER_RESOURCE_REQUEST_INFO_IMPL_H_