Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / browser / loader / resource_request_info_impl.cc
blob16a64bb4194d5f0ef7c58258c6e94321804015be
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 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 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 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 bool enable_load_timing,
107 blink::WebReferrerPolicy referrer_policy,
108 blink::WebPageVisibilityState visibility_state,
109 ResourceContext* context,
110 base::WeakPtr<ResourceMessageFilter> filter,
111 bool is_async)
112 : cross_site_handler_(NULL),
113 detachable_handler_(NULL),
114 process_type_(process_type),
115 child_id_(child_id),
116 route_id_(route_id),
117 origin_pid_(origin_pid),
118 request_id_(request_id),
119 render_frame_id_(render_frame_id),
120 is_main_frame_(is_main_frame),
121 parent_is_main_frame_(parent_is_main_frame),
122 parent_render_frame_id_(parent_render_frame_id),
123 should_replace_current_entry_(should_replace_current_entry),
124 is_download_(is_download),
125 is_stream_(is_stream),
126 allow_download_(allow_download),
127 has_user_gesture_(has_user_gesture),
128 enable_load_timing_(enable_load_timing),
129 was_ignored_by_handler_(false),
130 resource_type_(resource_type),
131 transition_type_(transition_type),
132 memory_cost_(0),
133 referrer_policy_(referrer_policy),
134 visibility_state_(visibility_state),
135 context_(context),
136 filter_(filter),
137 is_async_(is_async) {
140 ResourceRequestInfoImpl::~ResourceRequestInfoImpl() {
143 ResourceContext* ResourceRequestInfoImpl::GetContext() const {
144 return context_;
147 int ResourceRequestInfoImpl::GetChildID() const {
148 return child_id_;
151 int ResourceRequestInfoImpl::GetRouteID() const {
152 return route_id_;
155 int ResourceRequestInfoImpl::GetOriginPID() const {
156 return origin_pid_;
159 int ResourceRequestInfoImpl::GetRequestID() const {
160 return request_id_;
163 int ResourceRequestInfoImpl::GetRenderFrameID() const {
164 return render_frame_id_;
167 bool ResourceRequestInfoImpl::IsMainFrame() const {
168 return is_main_frame_;
171 bool ResourceRequestInfoImpl::ParentIsMainFrame() const {
172 return parent_is_main_frame_;
175 int ResourceRequestInfoImpl::GetParentRenderFrameID() const {
176 return parent_render_frame_id_;
179 ResourceType ResourceRequestInfoImpl::GetResourceType() const {
180 return resource_type_;
183 int ResourceRequestInfoImpl::GetProcessType() const {
184 return process_type_;
187 blink::WebReferrerPolicy ResourceRequestInfoImpl::GetReferrerPolicy() const {
188 return referrer_policy_;
191 blink::WebPageVisibilityState
192 ResourceRequestInfoImpl::GetVisibilityState() const {
193 return visibility_state_;
196 PageTransition ResourceRequestInfoImpl::GetPageTransition() const {
197 return transition_type_;
200 bool ResourceRequestInfoImpl::HasUserGesture() const {
201 return has_user_gesture_;
204 bool ResourceRequestInfoImpl::WasIgnoredByHandler() const {
205 return was_ignored_by_handler_;
208 bool ResourceRequestInfoImpl::GetAssociatedRenderFrame(
209 int* render_process_id,
210 int* render_frame_id) const {
211 if (process_type_ == PROCESS_TYPE_PLUGIN) {
212 *render_process_id = origin_pid_;
213 *render_frame_id = render_frame_id_;
214 } else {
215 *render_process_id = child_id_;
216 *render_frame_id = render_frame_id_;
218 return true;
221 bool ResourceRequestInfoImpl::IsAsync() const {
222 return is_async_;
225 bool ResourceRequestInfoImpl::IsDownload() const {
226 return is_download_;
229 void ResourceRequestInfoImpl::AssociateWithRequest(net::URLRequest* request) {
230 request->SetUserData(NULL, this);
231 int render_process_id;
232 int render_frame_id;
233 if (GetAssociatedRenderFrame(&render_process_id, &render_frame_id)) {
234 request->SetUserData(
235 URLRequestUserData::kUserDataKey,
236 new URLRequestUserData(render_process_id, render_frame_id));
240 GlobalRequestID ResourceRequestInfoImpl::GetGlobalRequestID() const {
241 return GlobalRequestID(child_id_, request_id_);
244 GlobalRoutingID ResourceRequestInfoImpl::GetGlobalRoutingID() const {
245 return GlobalRoutingID(child_id_, route_id_);
248 void ResourceRequestInfoImpl::UpdateForTransfer(
249 int child_id,
250 int route_id,
251 int origin_pid,
252 int request_id,
253 int parent_render_frame_id,
254 base::WeakPtr<ResourceMessageFilter> filter) {
255 child_id_ = child_id;
256 route_id_ = route_id;
257 origin_pid_ = origin_pid;
258 request_id_ = request_id;
259 parent_render_frame_id_ = parent_render_frame_id;
260 filter_ = filter;
263 } // namespace content