Apply _RELATIVE relocations ahead of others.
[chromium-blink-merge.git] / content / browser / loader / resource_request_info_impl.cc
blob8cae9a5c93bc3a0b6824558674256f30a5b2fe1b
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"
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(net::URLRequest* request,
27 ResourceType resource_type,
28 ResourceContext* context,
29 int render_process_id,
30 int render_view_id,
31 int render_frame_id,
32 bool is_async) {
33 ResourceRequestInfoImpl* info =
34 new ResourceRequestInfoImpl(
35 PROCESS_TYPE_RENDERER, // process_type
36 render_process_id, // child_id
37 render_view_id, // route_id
38 0, // origin_pid
39 0, // request_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
47 false, // is_download
48 false, // is_stream
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
55 context, // context
56 base::WeakPtr<ResourceMessageFilter>(), // filter
57 is_async); // is_async
58 info->AssociateWithRequest(request);
61 // static
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));
68 if (!user_data)
69 return false;
70 *render_process_id = user_data->render_process_id();
71 *render_frame_id = user_data->render_frame_id();
72 return true;
75 // ----------------------------------------------------------------------------
76 // ResourceRequestInfoImpl
78 // static
79 ResourceRequestInfoImpl* ResourceRequestInfoImpl::ForRequest(
80 net::URLRequest* request) {
81 return static_cast<ResourceRequestInfoImpl*>(request->GetUserData(NULL));
84 // static
85 const ResourceRequestInfoImpl* ResourceRequestInfoImpl::ForRequest(
86 const net::URLRequest* request) {
87 return ForRequest(const_cast<net::URLRequest*>(request));
90 ResourceRequestInfoImpl::ResourceRequestInfoImpl(
91 int process_type,
92 int child_id,
93 int route_id,
94 int origin_pid,
95 int request_id,
96 int render_frame_id,
97 bool is_main_frame,
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,
103 bool is_download,
104 bool is_stream,
105 bool allow_download,
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,
113 bool is_async)
114 : cross_site_handler_(NULL),
115 detachable_handler_(NULL),
116 process_type_(process_type),
117 child_id_(child_id),
118 route_id_(route_id),
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),
136 memory_cost_(0),
137 referrer_policy_(referrer_policy),
138 visibility_state_(visibility_state),
139 context_(context),
140 filter_(filter),
141 is_async_(is_async) {
144 ResourceRequestInfoImpl::~ResourceRequestInfoImpl() {
147 ResourceContext* ResourceRequestInfoImpl::GetContext() const {
148 return context_;
151 int ResourceRequestInfoImpl::GetChildID() const {
152 return child_id_;
155 int ResourceRequestInfoImpl::GetRouteID() const {
156 return route_id_;
159 int ResourceRequestInfoImpl::GetOriginPID() const {
160 return origin_pid_;
163 int ResourceRequestInfoImpl::GetRequestID() const {
164 return request_id_;
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_;
218 } else {
219 *render_process_id = child_id_;
220 *render_frame_id = render_frame_id_;
222 return true;
225 bool ResourceRequestInfoImpl::IsAsync() const {
226 return is_async_;
229 bool ResourceRequestInfoImpl::IsDownload() const {
230 return is_download_;
233 void ResourceRequestInfoImpl::AssociateWithRequest(net::URLRequest* request) {
234 request->SetUserData(NULL, this);
235 int render_process_id;
236 int render_frame_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(
253 int child_id,
254 int route_id,
255 int origin_pid,
256 int request_id,
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;
264 filter_ = filter;
267 } // namespace content