Use multiline attribute to check for IA2_STATE_MULTILINE.
[chromium-blink-merge.git] / content / browser / loader / resource_request_info_impl.cc
blobbe8ffa0ead4395e41906ad70e172b029d5f8f10d
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_main_frame,
33 bool parent_is_main_frame,
34 bool allow_download,
35 bool is_async) {
36 // Make sure both |is_main_frame| and |parent_is_main_frame| aren't set at the
37 // same time.
38 DCHECK(!(is_main_frame && parent_is_main_frame));
40 // Make sure RESOURCE_TYPE_MAIN_FRAME is declared as being fetched as part of
41 // the main frame.
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 0, // origin_pid
50 0, // request_id
51 render_frame_id, // render_frame_id
52 is_main_frame, // is_main_frame
53 parent_is_main_frame, // parent_is_main_frame
54 0, // parent_render_frame_id
55 resource_type, // resource_type
56 ui::PAGE_TRANSITION_LINK, // transition_type
57 false, // should_replace_current_entry
58 false, // is_download
59 false, // is_stream
60 allow_download, // allow_download
61 false, // has_user_gesture
62 false, // enable load timing
63 false, // enable upload progress
64 false, // do_not_prompt_for_login
65 blink::WebReferrerPolicyDefault, // referrer_policy
66 blink::WebPageVisibilityStateVisible, // visibility_state
67 context, // context
68 base::WeakPtr<ResourceMessageFilter>(), // filter
69 is_async); // is_async
70 info->AssociateWithRequest(request);
73 // static
74 bool ResourceRequestInfo::GetRenderFrameForRequest(
75 const net::URLRequest* request,
76 int* render_process_id,
77 int* render_frame_id) {
78 URLRequestUserData* user_data = static_cast<URLRequestUserData*>(
79 request->GetUserData(URLRequestUserData::kUserDataKey));
80 if (!user_data)
81 return false;
82 *render_process_id = user_data->render_process_id();
83 *render_frame_id = user_data->render_frame_id();
84 return true;
87 // ----------------------------------------------------------------------------
88 // ResourceRequestInfoImpl
90 // static
91 ResourceRequestInfoImpl* ResourceRequestInfoImpl::ForRequest(
92 net::URLRequest* request) {
93 return static_cast<ResourceRequestInfoImpl*>(request->GetUserData(NULL));
96 // static
97 const ResourceRequestInfoImpl* ResourceRequestInfoImpl::ForRequest(
98 const net::URLRequest* request) {
99 return ForRequest(const_cast<net::URLRequest*>(request));
102 ResourceRequestInfoImpl::ResourceRequestInfoImpl(
103 int process_type,
104 int child_id,
105 int route_id,
106 int origin_pid,
107 int request_id,
108 int render_frame_id,
109 bool is_main_frame,
110 bool parent_is_main_frame,
111 int parent_render_frame_id,
112 ResourceType resource_type,
113 ui::PageTransition transition_type,
114 bool should_replace_current_entry,
115 bool is_download,
116 bool is_stream,
117 bool allow_download,
118 bool has_user_gesture,
119 bool enable_load_timing,
120 bool enable_upload_progress,
121 bool do_not_prompt_for_login,
122 blink::WebReferrerPolicy referrer_policy,
123 blink::WebPageVisibilityState visibility_state,
124 ResourceContext* context,
125 base::WeakPtr<ResourceMessageFilter> filter,
126 bool is_async)
127 : cross_site_handler_(NULL),
128 detachable_handler_(NULL),
129 process_type_(process_type),
130 child_id_(child_id),
131 route_id_(route_id),
132 origin_pid_(origin_pid),
133 request_id_(request_id),
134 render_frame_id_(render_frame_id),
135 is_main_frame_(is_main_frame),
136 parent_is_main_frame_(parent_is_main_frame),
137 parent_render_frame_id_(parent_render_frame_id),
138 should_replace_current_entry_(should_replace_current_entry),
139 is_download_(is_download),
140 is_stream_(is_stream),
141 allow_download_(allow_download),
142 has_user_gesture_(has_user_gesture),
143 enable_load_timing_(enable_load_timing),
144 enable_upload_progress_(enable_upload_progress),
145 do_not_prompt_for_login_(do_not_prompt_for_login),
146 was_ignored_by_handler_(false),
147 counted_as_in_flight_request_(false),
148 resource_type_(resource_type),
149 transition_type_(transition_type),
150 memory_cost_(0),
151 referrer_policy_(referrer_policy),
152 visibility_state_(visibility_state),
153 context_(context),
154 filter_(filter),
155 is_async_(is_async) {
158 ResourceRequestInfoImpl::~ResourceRequestInfoImpl() {
161 ResourceContext* ResourceRequestInfoImpl::GetContext() const {
162 return context_;
165 int ResourceRequestInfoImpl::GetChildID() const {
166 return child_id_;
169 int ResourceRequestInfoImpl::GetRouteID() const {
170 return route_id_;
173 int ResourceRequestInfoImpl::GetOriginPID() const {
174 return origin_pid_;
177 int ResourceRequestInfoImpl::GetRequestID() const {
178 return request_id_;
181 int ResourceRequestInfoImpl::GetRenderFrameID() const {
182 return render_frame_id_;
185 bool ResourceRequestInfoImpl::IsMainFrame() const {
186 return is_main_frame_;
189 bool ResourceRequestInfoImpl::ParentIsMainFrame() const {
190 return parent_is_main_frame_;
193 int ResourceRequestInfoImpl::GetParentRenderFrameID() const {
194 return parent_render_frame_id_;
197 ResourceType ResourceRequestInfoImpl::GetResourceType() const {
198 return resource_type_;
201 int ResourceRequestInfoImpl::GetProcessType() const {
202 return process_type_;
205 blink::WebReferrerPolicy ResourceRequestInfoImpl::GetReferrerPolicy() const {
206 return referrer_policy_;
209 blink::WebPageVisibilityState
210 ResourceRequestInfoImpl::GetVisibilityState() const {
211 return visibility_state_;
214 ui::PageTransition ResourceRequestInfoImpl::GetPageTransition() const {
215 return transition_type_;
218 bool ResourceRequestInfoImpl::HasUserGesture() const {
219 return has_user_gesture_;
222 bool ResourceRequestInfoImpl::WasIgnoredByHandler() const {
223 return was_ignored_by_handler_;
226 bool ResourceRequestInfoImpl::GetAssociatedRenderFrame(
227 int* render_process_id,
228 int* render_frame_id) const {
229 if (process_type_ == PROCESS_TYPE_PLUGIN) {
230 *render_process_id = origin_pid_;
231 *render_frame_id = render_frame_id_;
232 } else {
233 *render_process_id = child_id_;
234 *render_frame_id = render_frame_id_;
236 return true;
239 bool ResourceRequestInfoImpl::IsAsync() const {
240 return is_async_;
243 bool ResourceRequestInfoImpl::IsDownload() const {
244 return is_download_;
247 void ResourceRequestInfoImpl::AssociateWithRequest(net::URLRequest* request) {
248 request->SetUserData(NULL, this);
249 int render_process_id;
250 int render_frame_id;
251 if (GetAssociatedRenderFrame(&render_process_id, &render_frame_id)) {
252 request->SetUserData(
253 URLRequestUserData::kUserDataKey,
254 new URLRequestUserData(render_process_id, render_frame_id));
258 GlobalRequestID ResourceRequestInfoImpl::GetGlobalRequestID() const {
259 return GlobalRequestID(child_id_, request_id_);
262 GlobalRoutingID ResourceRequestInfoImpl::GetGlobalRoutingID() const {
263 return GlobalRoutingID(child_id_, route_id_);
266 void ResourceRequestInfoImpl::UpdateForTransfer(
267 int child_id,
268 int route_id,
269 int origin_pid,
270 int request_id,
271 int parent_render_frame_id,
272 base::WeakPtr<ResourceMessageFilter> filter) {
273 child_id_ = child_id;
274 route_id_ = route_id;
275 origin_pid_ = origin_pid;
276 request_id_ = request_id;
277 parent_render_frame_id_ = parent_render_frame_id;
278 filter_ = filter;
281 } // namespace content