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 false, // report_raw_headers
71 is_async
); // is_async
72 info
->AssociateWithRequest(request
);
76 bool ResourceRequestInfo::GetRenderFrameForRequest(
77 const net::URLRequest
* request
,
78 int* render_process_id
,
79 int* render_frame_id
) {
80 URLRequestUserData
* user_data
= static_cast<URLRequestUserData
*>(
81 request
->GetUserData(URLRequestUserData::kUserDataKey
));
84 *render_process_id
= user_data
->render_process_id();
85 *render_frame_id
= user_data
->render_frame_id();
89 // ----------------------------------------------------------------------------
90 // ResourceRequestInfoImpl
93 ResourceRequestInfoImpl
* ResourceRequestInfoImpl::ForRequest(
94 net::URLRequest
* request
) {
95 return static_cast<ResourceRequestInfoImpl
*>(request
->GetUserData(NULL
));
99 const ResourceRequestInfoImpl
* ResourceRequestInfoImpl::ForRequest(
100 const net::URLRequest
* request
) {
101 return ForRequest(const_cast<net::URLRequest
*>(request
));
104 ResourceRequestInfoImpl::ResourceRequestInfoImpl(
108 int frame_tree_node_id
,
113 bool parent_is_main_frame
,
114 int parent_render_frame_id
,
115 ResourceType resource_type
,
116 ui::PageTransition transition_type
,
117 bool should_replace_current_entry
,
121 bool has_user_gesture
,
122 bool enable_load_timing
,
123 bool enable_upload_progress
,
124 bool do_not_prompt_for_login
,
125 blink::WebReferrerPolicy referrer_policy
,
126 blink::WebPageVisibilityState visibility_state
,
127 ResourceContext
* context
,
128 base::WeakPtr
<ResourceMessageFilter
> filter
,
129 bool report_raw_headers
,
131 : cross_site_handler_(NULL
),
132 detachable_handler_(NULL
),
133 process_type_(process_type
),
136 frame_tree_node_id_(frame_tree_node_id
),
137 origin_pid_(origin_pid
),
138 request_id_(request_id
),
139 render_frame_id_(render_frame_id
),
140 is_main_frame_(is_main_frame
),
141 parent_is_main_frame_(parent_is_main_frame
),
142 parent_render_frame_id_(parent_render_frame_id
),
143 should_replace_current_entry_(should_replace_current_entry
),
144 is_download_(is_download
),
145 is_stream_(is_stream
),
146 allow_download_(allow_download
),
147 has_user_gesture_(has_user_gesture
),
148 enable_load_timing_(enable_load_timing
),
149 enable_upload_progress_(enable_upload_progress
),
150 do_not_prompt_for_login_(do_not_prompt_for_login
),
151 was_ignored_by_handler_(false),
152 counted_as_in_flight_request_(false),
153 resource_type_(resource_type
),
154 transition_type_(transition_type
),
156 referrer_policy_(referrer_policy
),
157 visibility_state_(visibility_state
),
160 report_raw_headers_(report_raw_headers
),
161 is_async_(is_async
) {
164 ResourceRequestInfoImpl::~ResourceRequestInfoImpl() {
167 ResourceContext
* ResourceRequestInfoImpl::GetContext() const {
171 int ResourceRequestInfoImpl::GetChildID() const {
175 int ResourceRequestInfoImpl::GetRouteID() const {
179 int ResourceRequestInfoImpl::GetOriginPID() const {
183 int ResourceRequestInfoImpl::GetRequestID() const {
187 int ResourceRequestInfoImpl::GetRenderFrameID() const {
188 return render_frame_id_
;
191 bool ResourceRequestInfoImpl::IsMainFrame() const {
192 return is_main_frame_
;
195 bool ResourceRequestInfoImpl::ParentIsMainFrame() const {
196 return parent_is_main_frame_
;
199 int ResourceRequestInfoImpl::GetParentRenderFrameID() const {
200 return parent_render_frame_id_
;
203 ResourceType
ResourceRequestInfoImpl::GetResourceType() const {
204 return resource_type_
;
207 int ResourceRequestInfoImpl::GetProcessType() const {
208 return process_type_
;
211 blink::WebReferrerPolicy
ResourceRequestInfoImpl::GetReferrerPolicy() const {
212 return referrer_policy_
;
215 blink::WebPageVisibilityState
216 ResourceRequestInfoImpl::GetVisibilityState() const {
217 return visibility_state_
;
220 ui::PageTransition
ResourceRequestInfoImpl::GetPageTransition() const {
221 return transition_type_
;
224 bool ResourceRequestInfoImpl::HasUserGesture() const {
225 return has_user_gesture_
;
228 bool ResourceRequestInfoImpl::WasIgnoredByHandler() const {
229 return was_ignored_by_handler_
;
232 bool ResourceRequestInfoImpl::GetAssociatedRenderFrame(
233 int* render_process_id
,
234 int* render_frame_id
) const {
235 if (process_type_
== PROCESS_TYPE_PLUGIN
) {
236 *render_process_id
= origin_pid_
;
237 *render_frame_id
= render_frame_id_
;
239 *render_process_id
= child_id_
;
240 *render_frame_id
= render_frame_id_
;
245 bool ResourceRequestInfoImpl::IsAsync() const {
249 bool ResourceRequestInfoImpl::IsDownload() const {
253 bool ResourceRequestInfoImpl::ShouldReportRawHeaders() const {
254 return report_raw_headers_
;
257 void ResourceRequestInfoImpl::AssociateWithRequest(net::URLRequest
* request
) {
258 request
->SetUserData(NULL
, this);
259 int render_process_id
;
261 if (GetAssociatedRenderFrame(&render_process_id
, &render_frame_id
)) {
262 request
->SetUserData(
263 URLRequestUserData::kUserDataKey
,
264 new URLRequestUserData(render_process_id
, render_frame_id
));
268 GlobalRequestID
ResourceRequestInfoImpl::GetGlobalRequestID() const {
269 return GlobalRequestID(child_id_
, request_id_
);
272 GlobalRoutingID
ResourceRequestInfoImpl::GetGlobalRoutingID() const {
273 return GlobalRoutingID(child_id_
, route_id_
);
276 void ResourceRequestInfoImpl::UpdateForTransfer(
281 int parent_render_frame_id
,
282 base::WeakPtr
<ResourceMessageFilter
> filter
) {
283 child_id_
= child_id
;
284 route_id_
= route_id
;
285 origin_pid_
= origin_pid
;
286 request_id_
= request_id
;
287 parent_render_frame_id_
= parent_render_frame_id
;
291 } // namespace content