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 ResourceRequestInfoImpl
* info
=
34 new ResourceRequestInfoImpl(
35 PROCESS_TYPE_RENDERER
, // process_type
36 render_process_id
, // child_id
37 render_view_id
, // route_id
40 render_frame_id
, // render_frame_id
41 resource_type
== RESOURCE_TYPE_MAIN_FRAME
, // is_main_frame
42 false, // parent_is_main_frame
43 0, // parent_render_frame_id
44 resource_type
, // resource_type
45 ui::PAGE_TRANSITION_LINK
, // transition_type
46 false, // should_replace_current_entry
49 true, // allow_download
50 false, // has_user_gesture
51 false, // enable load timing
52 false, // enable upload progress
53 blink::WebReferrerPolicyDefault
, // referrer_policy
54 blink::WebPageVisibilityStateVisible
, // visibility_state
56 base::WeakPtr
<ResourceMessageFilter
>(), // filter
57 is_async
); // is_async
58 info
->AssociateWithRequest(request
);
62 bool ResourceRequestInfo::GetRenderFrameForRequest(
63 const net::URLRequest
* request
,
64 int* render_process_id
,
65 int* render_frame_id
) {
66 URLRequestUserData
* user_data
= static_cast<URLRequestUserData
*>(
67 request
->GetUserData(URLRequestUserData::kUserDataKey
));
70 *render_process_id
= user_data
->render_process_id();
71 *render_frame_id
= user_data
->render_frame_id();
75 // ----------------------------------------------------------------------------
76 // ResourceRequestInfoImpl
79 ResourceRequestInfoImpl
* ResourceRequestInfoImpl::ForRequest(
80 net::URLRequest
* request
) {
81 return static_cast<ResourceRequestInfoImpl
*>(request
->GetUserData(NULL
));
85 const ResourceRequestInfoImpl
* ResourceRequestInfoImpl::ForRequest(
86 const net::URLRequest
* request
) {
87 return ForRequest(const_cast<net::URLRequest
*>(request
));
90 ResourceRequestInfoImpl::ResourceRequestInfoImpl(
98 bool parent_is_main_frame
,
99 int parent_render_frame_id
,
100 ResourceType resource_type
,
101 ui::PageTransition transition_type
,
102 bool should_replace_current_entry
,
106 bool has_user_gesture
,
107 bool enable_load_timing
,
108 bool enable_upload_progress
,
109 blink::WebReferrerPolicy referrer_policy
,
110 blink::WebPageVisibilityState visibility_state
,
111 ResourceContext
* context
,
112 base::WeakPtr
<ResourceMessageFilter
> filter
,
114 : cross_site_handler_(NULL
),
115 detachable_handler_(NULL
),
116 process_type_(process_type
),
119 origin_pid_(origin_pid
),
120 request_id_(request_id
),
121 render_frame_id_(render_frame_id
),
122 is_main_frame_(is_main_frame
),
123 parent_is_main_frame_(parent_is_main_frame
),
124 parent_render_frame_id_(parent_render_frame_id
),
125 should_replace_current_entry_(should_replace_current_entry
),
126 is_download_(is_download
),
127 is_stream_(is_stream
),
128 allow_download_(allow_download
),
129 has_user_gesture_(has_user_gesture
),
130 enable_load_timing_(enable_load_timing
),
131 enable_upload_progress_(enable_upload_progress
),
132 was_ignored_by_handler_(false),
133 counted_as_in_flight_request_(false),
134 resource_type_(resource_type
),
135 transition_type_(transition_type
),
137 referrer_policy_(referrer_policy
),
138 visibility_state_(visibility_state
),
141 is_async_(is_async
) {
144 ResourceRequestInfoImpl::~ResourceRequestInfoImpl() {
147 ResourceContext
* ResourceRequestInfoImpl::GetContext() const {
151 int ResourceRequestInfoImpl::GetChildID() const {
155 int ResourceRequestInfoImpl::GetRouteID() const {
159 int ResourceRequestInfoImpl::GetOriginPID() const {
163 int ResourceRequestInfoImpl::GetRequestID() const {
167 int ResourceRequestInfoImpl::GetRenderFrameID() const {
168 return render_frame_id_
;
171 bool ResourceRequestInfoImpl::IsMainFrame() const {
172 return is_main_frame_
;
175 bool ResourceRequestInfoImpl::ParentIsMainFrame() const {
176 return parent_is_main_frame_
;
179 int ResourceRequestInfoImpl::GetParentRenderFrameID() const {
180 return parent_render_frame_id_
;
183 ResourceType
ResourceRequestInfoImpl::GetResourceType() const {
184 return resource_type_
;
187 int ResourceRequestInfoImpl::GetProcessType() const {
188 return process_type_
;
191 blink::WebReferrerPolicy
ResourceRequestInfoImpl::GetReferrerPolicy() const {
192 return referrer_policy_
;
195 blink::WebPageVisibilityState
196 ResourceRequestInfoImpl::GetVisibilityState() const {
197 return visibility_state_
;
200 ui::PageTransition
ResourceRequestInfoImpl::GetPageTransition() const {
201 return transition_type_
;
204 bool ResourceRequestInfoImpl::HasUserGesture() const {
205 return has_user_gesture_
;
208 bool ResourceRequestInfoImpl::WasIgnoredByHandler() const {
209 return was_ignored_by_handler_
;
212 bool ResourceRequestInfoImpl::GetAssociatedRenderFrame(
213 int* render_process_id
,
214 int* render_frame_id
) const {
215 if (process_type_
== PROCESS_TYPE_PLUGIN
) {
216 *render_process_id
= origin_pid_
;
217 *render_frame_id
= render_frame_id_
;
219 *render_process_id
= child_id_
;
220 *render_frame_id
= render_frame_id_
;
225 bool ResourceRequestInfoImpl::IsAsync() const {
229 bool ResourceRequestInfoImpl::IsDownload() const {
233 void ResourceRequestInfoImpl::AssociateWithRequest(net::URLRequest
* request
) {
234 request
->SetUserData(NULL
, this);
235 int render_process_id
;
237 if (GetAssociatedRenderFrame(&render_process_id
, &render_frame_id
)) {
238 request
->SetUserData(
239 URLRequestUserData::kUserDataKey
,
240 new URLRequestUserData(render_process_id
, render_frame_id
));
244 GlobalRequestID
ResourceRequestInfoImpl::GetGlobalRequestID() const {
245 return GlobalRequestID(child_id_
, request_id_
);
248 GlobalRoutingID
ResourceRequestInfoImpl::GetGlobalRoutingID() const {
249 return GlobalRoutingID(child_id_
, route_id_
);
252 void ResourceRequestInfoImpl::UpdateForTransfer(
257 int parent_render_frame_id
,
258 base::WeakPtr
<ResourceMessageFilter
> filter
) {
259 child_id_
= child_id
;
260 route_id_
= route_id
;
261 origin_pid_
= origin_pid
;
262 request_id_
= request_id
;
263 parent_render_frame_id_
= parent_render_frame_id
;
267 } // namespace content