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 #include "content/browser/loader/resource_request_info_impl.h"
7 #include "content/browser/loader/global_routing_id.h"
8 #include "content/browser/loader/resource_message_filter.h"
9 #include "content/common/net/url_request_user_data.h"
10 #include "content/public/browser/global_request_id.h"
11 #include "content/public/common/process_type.h"
12 #include "net/url_request/url_request.h"
16 // ----------------------------------------------------------------------------
17 // ResourceRequestInfo
20 const ResourceRequestInfo
* ResourceRequestInfo::ForRequest(
21 const net::URLRequest
* request
) {
22 return ResourceRequestInfoImpl::ForRequest(request
);
26 void ResourceRequestInfo::AllocateForTesting(net::URLRequest
* request
,
27 ResourceType resource_type
,
28 ResourceContext
* context
,
29 int render_process_id
,
33 bool parent_is_main_frame
,
36 // Make sure both |is_main_frame| and |parent_is_main_frame| aren't set at the
38 DCHECK(!(is_main_frame
&& parent_is_main_frame
));
40 // Make sure RESOURCE_TYPE_MAIN_FRAME is declared as being fetched as part of
42 DCHECK(resource_type
!= RESOURCE_TYPE_MAIN_FRAME
|| is_main_frame
);
44 ResourceRequestInfoImpl
* info
=
45 new ResourceRequestInfoImpl(
46 PROCESS_TYPE_RENDERER
, // process_type
47 render_process_id
, // child_id
48 render_view_id
, // route_id
49 -1, // frame_tree_node_id
52 render_frame_id
, // render_frame_id
53 is_main_frame
, // is_main_frame
54 parent_is_main_frame
, // parent_is_main_frame
55 0, // parent_render_frame_id
56 resource_type
, // resource_type
57 ui::PAGE_TRANSITION_LINK
, // transition_type
58 false, // should_replace_current_entry
61 allow_download
, // allow_download
62 false, // has_user_gesture
63 false, // enable load timing
64 request
->has_upload(), // enable upload progress
65 false, // do_not_prompt_for_login
66 blink::WebReferrerPolicyDefault
, // referrer_policy
67 blink::WebPageVisibilityStateVisible
, // visibility_state
69 base::WeakPtr
<ResourceMessageFilter
>(), // filter
70 is_async
); // is_async
71 info
->AssociateWithRequest(request
);
75 bool ResourceRequestInfo::GetRenderFrameForRequest(
76 const net::URLRequest
* request
,
77 int* render_process_id
,
78 int* render_frame_id
) {
79 URLRequestUserData
* user_data
= static_cast<URLRequestUserData
*>(
80 request
->GetUserData(URLRequestUserData::kUserDataKey
));
83 *render_process_id
= user_data
->render_process_id();
84 *render_frame_id
= user_data
->render_frame_id();
88 // ----------------------------------------------------------------------------
89 // ResourceRequestInfoImpl
92 ResourceRequestInfoImpl
* ResourceRequestInfoImpl::ForRequest(
93 net::URLRequest
* request
) {
94 return static_cast<ResourceRequestInfoImpl
*>(request
->GetUserData(NULL
));
98 const ResourceRequestInfoImpl
* ResourceRequestInfoImpl::ForRequest(
99 const net::URLRequest
* request
) {
100 return ForRequest(const_cast<net::URLRequest
*>(request
));
103 ResourceRequestInfoImpl::ResourceRequestInfoImpl(
107 int frame_tree_node_id
,
112 bool parent_is_main_frame
,
113 int parent_render_frame_id
,
114 ResourceType resource_type
,
115 ui::PageTransition transition_type
,
116 bool should_replace_current_entry
,
120 bool has_user_gesture
,
121 bool enable_load_timing
,
122 bool enable_upload_progress
,
123 bool do_not_prompt_for_login
,
124 blink::WebReferrerPolicy referrer_policy
,
125 blink::WebPageVisibilityState visibility_state
,
126 ResourceContext
* context
,
127 base::WeakPtr
<ResourceMessageFilter
> filter
,
129 : cross_site_handler_(NULL
),
130 detachable_handler_(NULL
),
131 process_type_(process_type
),
134 frame_tree_node_id_(frame_tree_node_id
),
135 origin_pid_(origin_pid
),
136 request_id_(request_id
),
137 render_frame_id_(render_frame_id
),
138 is_main_frame_(is_main_frame
),
139 parent_is_main_frame_(parent_is_main_frame
),
140 parent_render_frame_id_(parent_render_frame_id
),
141 should_replace_current_entry_(should_replace_current_entry
),
142 is_download_(is_download
),
143 is_stream_(is_stream
),
144 allow_download_(allow_download
),
145 has_user_gesture_(has_user_gesture
),
146 enable_load_timing_(enable_load_timing
),
147 enable_upload_progress_(enable_upload_progress
),
148 do_not_prompt_for_login_(do_not_prompt_for_login
),
149 was_ignored_by_handler_(false),
150 counted_as_in_flight_request_(false),
151 resource_type_(resource_type
),
152 transition_type_(transition_type
),
154 referrer_policy_(referrer_policy
),
155 visibility_state_(visibility_state
),
158 is_async_(is_async
) {
161 ResourceRequestInfoImpl::~ResourceRequestInfoImpl() {
164 ResourceContext
* ResourceRequestInfoImpl::GetContext() const {
168 int ResourceRequestInfoImpl::GetChildID() const {
172 int ResourceRequestInfoImpl::GetRouteID() const {
176 int ResourceRequestInfoImpl::GetOriginPID() const {
180 int ResourceRequestInfoImpl::GetRequestID() const {
184 int ResourceRequestInfoImpl::GetRenderFrameID() const {
185 return render_frame_id_
;
188 bool ResourceRequestInfoImpl::IsMainFrame() const {
189 return is_main_frame_
;
192 bool ResourceRequestInfoImpl::ParentIsMainFrame() const {
193 return parent_is_main_frame_
;
196 int ResourceRequestInfoImpl::GetParentRenderFrameID() const {
197 return parent_render_frame_id_
;
200 ResourceType
ResourceRequestInfoImpl::GetResourceType() const {
201 return resource_type_
;
204 int ResourceRequestInfoImpl::GetProcessType() const {
205 return process_type_
;
208 blink::WebReferrerPolicy
ResourceRequestInfoImpl::GetReferrerPolicy() const {
209 return referrer_policy_
;
212 blink::WebPageVisibilityState
213 ResourceRequestInfoImpl::GetVisibilityState() const {
214 return visibility_state_
;
217 ui::PageTransition
ResourceRequestInfoImpl::GetPageTransition() const {
218 return transition_type_
;
221 bool ResourceRequestInfoImpl::HasUserGesture() const {
222 return has_user_gesture_
;
225 bool ResourceRequestInfoImpl::WasIgnoredByHandler() const {
226 return was_ignored_by_handler_
;
229 bool ResourceRequestInfoImpl::GetAssociatedRenderFrame(
230 int* render_process_id
,
231 int* render_frame_id
) const {
232 if (process_type_
== PROCESS_TYPE_PLUGIN
) {
233 *render_process_id
= origin_pid_
;
234 *render_frame_id
= render_frame_id_
;
236 *render_process_id
= child_id_
;
237 *render_frame_id
= render_frame_id_
;
242 bool ResourceRequestInfoImpl::IsAsync() const {
246 bool ResourceRequestInfoImpl::IsDownload() const {
250 void ResourceRequestInfoImpl::AssociateWithRequest(net::URLRequest
* request
) {
251 request
->SetUserData(NULL
, this);
252 int render_process_id
;
254 if (GetAssociatedRenderFrame(&render_process_id
, &render_frame_id
)) {
255 request
->SetUserData(
256 URLRequestUserData::kUserDataKey
,
257 new URLRequestUserData(render_process_id
, render_frame_id
));
261 GlobalRequestID
ResourceRequestInfoImpl::GetGlobalRequestID() const {
262 return GlobalRequestID(child_id_
, request_id_
);
265 GlobalRoutingID
ResourceRequestInfoImpl::GetGlobalRoutingID() const {
266 return GlobalRoutingID(child_id_
, route_id_
);
269 void ResourceRequestInfoImpl::UpdateForTransfer(
274 int parent_render_frame_id
,
275 base::WeakPtr
<ResourceMessageFilter
> filter
) {
276 child_id_
= child_id
;
277 route_id_
= route_id
;
278 origin_pid_
= origin_pid
;
279 request_id_
= request_id
;
280 parent_render_frame_id_
= parent_render_frame_id
;
284 } // namespace content