Remove PlatformFile from profile_browsertest
[chromium-blink-merge.git] / content / browser / loader / resource_request_info_impl.cc
blob03d925ee7869dc35851883554e67dedefe7dec71
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/browser/worker_host/worker_service_impl.h"
10 #include "content/common/net/url_request_user_data.h"
11 #include "content/public/browser/global_request_id.h"
12 #include "net/url_request/url_request.h"
14 namespace content {
16 // ----------------------------------------------------------------------------
17 // ResourceRequestInfo
19 // static
20 const ResourceRequestInfo* ResourceRequestInfo::ForRequest(
21 const net::URLRequest* request) {
22 return ResourceRequestInfoImpl::ForRequest(request);
25 // static
26 void ResourceRequestInfo::AllocateForTesting(
27 net::URLRequest* request,
28 ResourceType::Type resource_type,
29 ResourceContext* context,
30 int render_process_id,
31 int render_view_id,
32 int render_frame_id,
33 bool is_async) {
34 ResourceRequestInfoImpl* info =
35 new ResourceRequestInfoImpl(
36 PROCESS_TYPE_RENDERER, // process_type
37 render_process_id, // child_id
38 render_view_id, // route_id
39 0, // origin_pid
40 0, // request_id
41 render_frame_id, // render_frame_id
42 resource_type == ResourceType::MAIN_FRAME, // is_main_frame
43 false, // parent_is_main_frame
44 0, // parent_render_frame_id
45 resource_type, // resource_type
46 PAGE_TRANSITION_LINK, // transition_type
47 false, // should_replace_current_entry
48 false, // is_download
49 false, // is_stream
50 true, // allow_download
51 false, // has_user_gesture
52 blink::WebReferrerPolicyDefault, // referrer_policy
53 blink::WebPageVisibilityStateVisible, // visibility_state
54 context, // context
55 base::WeakPtr<ResourceMessageFilter>(), // filter
56 is_async); // is_async
57 info->AssociateWithRequest(request);
60 // static
61 bool ResourceRequestInfo::GetRenderFrameForRequest(
62 const net::URLRequest* request,
63 int* render_process_id,
64 int* render_frame_id) {
65 URLRequestUserData* user_data = static_cast<URLRequestUserData*>(
66 request->GetUserData(URLRequestUserData::kUserDataKey));
67 if (!user_data)
68 return false;
69 *render_process_id = user_data->render_process_id();
70 *render_frame_id = user_data->render_frame_id();
71 return true;
74 // ----------------------------------------------------------------------------
75 // ResourceRequestInfoImpl
77 // static
78 ResourceRequestInfoImpl* ResourceRequestInfoImpl::ForRequest(
79 net::URLRequest* request) {
80 return static_cast<ResourceRequestInfoImpl*>(request->GetUserData(NULL));
83 // static
84 const ResourceRequestInfoImpl* ResourceRequestInfoImpl::ForRequest(
85 const net::URLRequest* request) {
86 return ForRequest(const_cast<net::URLRequest*>(request));
89 ResourceRequestInfoImpl::ResourceRequestInfoImpl(
90 int process_type,
91 int child_id,
92 int route_id,
93 int origin_pid,
94 int request_id,
95 int render_frame_id,
96 bool is_main_frame,
97 bool parent_is_main_frame,
98 int parent_render_frame_id,
99 ResourceType::Type resource_type,
100 PageTransition transition_type,
101 bool should_replace_current_entry,
102 bool is_download,
103 bool is_stream,
104 bool allow_download,
105 bool has_user_gesture,
106 blink::WebReferrerPolicy referrer_policy,
107 blink::WebPageVisibilityState visibility_state,
108 ResourceContext* context,
109 base::WeakPtr<ResourceMessageFilter> filter,
110 bool is_async)
111 : cross_site_handler_(NULL),
112 detachable_handler_(NULL),
113 process_type_(process_type),
114 child_id_(child_id),
115 route_id_(route_id),
116 origin_pid_(origin_pid),
117 request_id_(request_id),
118 render_frame_id_(render_frame_id),
119 is_main_frame_(is_main_frame),
120 parent_is_main_frame_(parent_is_main_frame),
121 parent_render_frame_id_(parent_render_frame_id),
122 should_replace_current_entry_(should_replace_current_entry),
123 is_download_(is_download),
124 is_stream_(is_stream),
125 allow_download_(allow_download),
126 has_user_gesture_(has_user_gesture),
127 was_ignored_by_handler_(false),
128 resource_type_(resource_type),
129 transition_type_(transition_type),
130 memory_cost_(0),
131 referrer_policy_(referrer_policy),
132 visibility_state_(visibility_state),
133 context_(context),
134 filter_(filter),
135 is_async_(is_async) {
138 ResourceRequestInfoImpl::~ResourceRequestInfoImpl() {
141 ResourceContext* ResourceRequestInfoImpl::GetContext() const {
142 return context_;
145 int ResourceRequestInfoImpl::GetChildID() const {
146 return child_id_;
149 int ResourceRequestInfoImpl::GetRouteID() const {
150 return route_id_;
153 int ResourceRequestInfoImpl::GetOriginPID() const {
154 return origin_pid_;
157 int ResourceRequestInfoImpl::GetRequestID() const {
158 return request_id_;
161 int ResourceRequestInfoImpl::GetRenderFrameID() const {
162 return render_frame_id_;
165 bool ResourceRequestInfoImpl::IsMainFrame() const {
166 return is_main_frame_;
169 bool ResourceRequestInfoImpl::ParentIsMainFrame() const {
170 return parent_is_main_frame_;
173 int ResourceRequestInfoImpl::GetParentRenderFrameID() const {
174 return parent_render_frame_id_;
177 ResourceType::Type ResourceRequestInfoImpl::GetResourceType() const {
178 return resource_type_;
181 int ResourceRequestInfoImpl::GetProcessType() const {
182 return process_type_;
185 blink::WebReferrerPolicy ResourceRequestInfoImpl::GetReferrerPolicy() const {
186 return referrer_policy_;
189 blink::WebPageVisibilityState
190 ResourceRequestInfoImpl::GetVisibilityState() const {
191 return visibility_state_;
194 PageTransition ResourceRequestInfoImpl::GetPageTransition() const {
195 return transition_type_;
198 bool ResourceRequestInfoImpl::HasUserGesture() const {
199 return has_user_gesture_;
202 bool ResourceRequestInfoImpl::WasIgnoredByHandler() const {
203 return was_ignored_by_handler_;
206 bool ResourceRequestInfoImpl::GetAssociatedRenderFrame(
207 int* render_process_id,
208 int* render_frame_id) const {
209 // If the request is from the worker process, find a content that owns the
210 // worker.
211 if (process_type_ == PROCESS_TYPE_WORKER) {
212 // Need to display some related UI for this network request - pick an
213 // arbitrary parent to do so.
214 if (!WorkerServiceImpl::GetInstance()->GetRendererForWorker(
215 child_id_, render_process_id, render_frame_id)) {
216 *render_process_id = -1;
217 *render_frame_id = -1;
218 return false;
220 } else if (process_type_ == PROCESS_TYPE_PLUGIN) {
221 *render_process_id = origin_pid_;
222 *render_frame_id = render_frame_id_;
223 } else {
224 *render_process_id = child_id_;
225 *render_frame_id = render_frame_id_;
227 return true;
230 bool ResourceRequestInfoImpl::IsAsync() const {
231 return is_async_;
234 bool ResourceRequestInfoImpl::IsDownload() const {
235 return is_download_;
238 void ResourceRequestInfoImpl::AssociateWithRequest(net::URLRequest* request) {
239 request->SetUserData(NULL, this);
240 int render_process_id;
241 int render_frame_id;
242 if (GetAssociatedRenderFrame(&render_process_id, &render_frame_id)) {
243 request->SetUserData(
244 URLRequestUserData::kUserDataKey,
245 new URLRequestUserData(render_process_id, render_frame_id));
249 GlobalRequestID ResourceRequestInfoImpl::GetGlobalRequestID() const {
250 return GlobalRequestID(child_id_, request_id_);
253 GlobalRoutingID ResourceRequestInfoImpl::GetGlobalRoutingID() const {
254 return GlobalRoutingID(child_id_, route_id_);
257 void ResourceRequestInfoImpl::UpdateForTransfer(
258 int child_id,
259 int route_id,
260 int origin_pid,
261 int request_id,
262 int parent_render_frame_id,
263 base::WeakPtr<ResourceMessageFilter> filter) {
264 child_id_ = child_id;
265 route_id_ = route_id;
266 origin_pid_ = origin_pid;
267 request_id_ = request_id;
268 parent_render_frame_id_ = parent_render_frame_id;
269 filter_ = filter;
272 } // namespace content