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 PageTransition transition_type
,
54 bool should_replace_current_entry
,
58 bool has_user_gesture
,
59 bool enable_load_timing
,
60 blink::WebReferrerPolicy referrer_policy
,
61 blink::WebPageVisibilityState visibility_state
,
62 ResourceContext
* context
,
63 base::WeakPtr
<ResourceMessageFilter
> filter
,
65 virtual ~ResourceRequestInfoImpl();
67 // ResourceRequestInfo implementation:
68 virtual ResourceContext
* GetContext() const OVERRIDE
;
69 virtual int GetChildID() const OVERRIDE
;
70 virtual int GetRouteID() const OVERRIDE
;
71 virtual int GetOriginPID() const OVERRIDE
;
72 virtual int GetRequestID() const OVERRIDE
;
73 virtual int GetRenderFrameID() const OVERRIDE
;
74 virtual bool IsMainFrame() const OVERRIDE
;
75 virtual bool ParentIsMainFrame() const OVERRIDE
;
76 virtual int GetParentRenderFrameID() const OVERRIDE
;
77 virtual ResourceType
GetResourceType() const OVERRIDE
;
78 virtual int GetProcessType() const OVERRIDE
;
79 virtual blink::WebReferrerPolicy
GetReferrerPolicy() const OVERRIDE
;
80 virtual blink::WebPageVisibilityState
GetVisibilityState() const OVERRIDE
;
81 virtual PageTransition
GetPageTransition() const OVERRIDE
;
82 virtual bool HasUserGesture() const OVERRIDE
;
83 virtual bool WasIgnoredByHandler() const OVERRIDE
;
84 virtual bool GetAssociatedRenderFrame(int* render_process_id
,
85 int* render_frame_id
) const OVERRIDE
;
86 virtual bool IsAsync() const OVERRIDE
;
87 virtual 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 // The approximate in-memory size (bytes) that we credited this request
152 // as consuming in |outstanding_requests_memory_cost_map_|.
153 int memory_cost() const { return memory_cost_
; }
154 void set_memory_cost(int cost
) { memory_cost_
= cost
; }
156 bool is_load_timing_enabled() const { return enable_load_timing_
; }
159 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest
,
160 DeletedFilterDetached
);
161 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest
,
162 DeletedFilterDetachedRedirect
);
163 // Non-owning, may be NULL.
164 CrossSiteResourceHandler
* cross_site_handler_
;
165 DetachableResourceHandler
* detachable_handler_
;
172 int render_frame_id_
;
174 bool parent_is_main_frame_
;
175 int parent_render_frame_id_
;
176 bool should_replace_current_entry_
;
179 bool allow_download_
;
180 bool has_user_gesture_
;
181 bool enable_load_timing_
;
182 bool was_ignored_by_handler_
;
183 ResourceType resource_type_
;
184 PageTransition transition_type_
;
186 blink::WebReferrerPolicy referrer_policy_
;
187 blink::WebPageVisibilityState visibility_state_
;
188 ResourceContext
* context_
;
189 // The filter might be deleted without deleting this object if the process
190 // exits during a transfer.
191 base::WeakPtr
<ResourceMessageFilter
> filter_
;
194 DISALLOW_COPY_AND_ASSIGN(ResourceRequestInfoImpl
);
197 } // namespace content
199 #endif // CONTENT_BROWSER_LOADER_RESOURCE_REQUEST_INFO_IMPL_H_