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 // IPC messages for resource loading.
7 // NOTE: All messages must send an |int request_id| as their first parameter.
9 // Multiply-included message file, hence no include guard.
10 #include "base/memory/shared_memory.h"
11 #include "base/process/process.h"
12 #include "content/common/content_param_traits_macros.h"
13 #include "content/common/resource_request_body.h"
14 #include "content/common/service_worker/service_worker_types.h"
15 #include "content/public/common/common_param_traits.h"
16 #include "content/public/common/resource_response.h"
17 #include "ipc/ipc_message_macros.h"
18 #include "net/base/request_priority.h"
19 #include "net/http/http_response_info.h"
20 #include "net/url_request/redirect_info.h"
22 #ifndef CONTENT_COMMON_RESOURCE_MESSAGES_H_
23 #define CONTENT_COMMON_RESOURCE_MESSAGES_H_
26 struct LoadTimingInfo
;
30 struct ResourceDevToolsInfo
;
36 struct ParamTraits
<scoped_refptr
<net::HttpResponseHeaders
> > {
37 typedef scoped_refptr
<net::HttpResponseHeaders
> param_type
;
38 static void Write(Message
* m
, const param_type
& p
);
39 static bool Read(const Message
* m
, base::PickleIterator
* iter
, param_type
* r
);
40 static void Log(const param_type
& p
, std::string
* l
);
44 struct CONTENT_EXPORT ParamTraits
<storage::DataElement
> {
45 typedef storage::DataElement param_type
;
46 static void Write(Message
* m
, const param_type
& p
);
47 static bool Read(const Message
* m
, base::PickleIterator
* iter
, param_type
* r
);
48 static void Log(const param_type
& p
, std::string
* l
);
52 struct ParamTraits
<scoped_refptr
<content::ResourceDevToolsInfo
> > {
53 typedef scoped_refptr
<content::ResourceDevToolsInfo
> param_type
;
54 static void Write(Message
* m
, const param_type
& p
);
55 static bool Read(const Message
* m
, base::PickleIterator
* iter
, param_type
* r
);
56 static void Log(const param_type
& p
, std::string
* l
);
60 struct ParamTraits
<net::LoadTimingInfo
> {
61 typedef net::LoadTimingInfo param_type
;
62 static void Write(Message
* m
, const param_type
& p
);
63 static bool Read(const Message
* m
, base::PickleIterator
* iter
, param_type
* r
);
64 static void Log(const param_type
& p
, std::string
* l
);
68 struct ParamTraits
<scoped_refptr
<content::ResourceRequestBody
> > {
69 typedef scoped_refptr
<content::ResourceRequestBody
> param_type
;
70 static void Write(Message
* m
, const param_type
& p
);
71 static bool Read(const Message
* m
, base::PickleIterator
* iter
, param_type
* r
);
72 static void Log(const param_type
& p
, std::string
* l
);
77 #endif // CONTENT_COMMON_RESOURCE_MESSAGES_H_
80 #define IPC_MESSAGE_START ResourceMsgStart
81 #undef IPC_MESSAGE_EXPORT
82 #define IPC_MESSAGE_EXPORT CONTENT_EXPORT
84 IPC_ENUM_TRAITS_MAX_VALUE( \
85 net::HttpResponseInfo::ConnectionInfo
, \
86 net::HttpResponseInfo::NUM_OF_CONNECTION_INFOS
- 1)
88 IPC_ENUM_TRAITS_MAX_VALUE(content::FetchRequestMode
,
89 content::FETCH_REQUEST_MODE_LAST
)
91 IPC_ENUM_TRAITS_MAX_VALUE(content::FetchCredentialsMode
,
92 content::FETCH_CREDENTIALS_MODE_LAST
)
94 IPC_ENUM_TRAITS_MAX_VALUE(content::FetchRedirectMode
,
95 content::FetchRedirectMode::LAST
)
97 IPC_STRUCT_TRAITS_BEGIN(content::ResourceResponseHead
)
98 IPC_STRUCT_TRAITS_PARENT(content::ResourceResponseInfo
)
99 IPC_STRUCT_TRAITS_MEMBER(request_start
)
100 IPC_STRUCT_TRAITS_MEMBER(response_start
)
101 IPC_STRUCT_TRAITS_END()
103 IPC_STRUCT_TRAITS_BEGIN(content::SyncLoadResult
)
104 IPC_STRUCT_TRAITS_PARENT(content::ResourceResponseHead
)
105 IPC_STRUCT_TRAITS_MEMBER(error_code
)
106 IPC_STRUCT_TRAITS_MEMBER(final_url
)
107 IPC_STRUCT_TRAITS_MEMBER(data
)
108 IPC_STRUCT_TRAITS_END()
110 IPC_STRUCT_TRAITS_BEGIN(content::ResourceResponseInfo
)
111 IPC_STRUCT_TRAITS_MEMBER(request_time
)
112 IPC_STRUCT_TRAITS_MEMBER(response_time
)
113 IPC_STRUCT_TRAITS_MEMBER(headers
)
114 IPC_STRUCT_TRAITS_MEMBER(mime_type
)
115 IPC_STRUCT_TRAITS_MEMBER(charset
)
116 IPC_STRUCT_TRAITS_MEMBER(security_info
)
117 IPC_STRUCT_TRAITS_MEMBER(content_length
)
118 IPC_STRUCT_TRAITS_MEMBER(encoded_data_length
)
119 IPC_STRUCT_TRAITS_MEMBER(appcache_id
)
120 IPC_STRUCT_TRAITS_MEMBER(appcache_manifest_url
)
121 IPC_STRUCT_TRAITS_MEMBER(load_timing
)
122 IPC_STRUCT_TRAITS_MEMBER(devtools_info
)
123 IPC_STRUCT_TRAITS_MEMBER(download_file_path
)
124 IPC_STRUCT_TRAITS_MEMBER(was_fetched_via_spdy
)
125 IPC_STRUCT_TRAITS_MEMBER(was_npn_negotiated
)
126 IPC_STRUCT_TRAITS_MEMBER(was_alternate_protocol_available
)
127 IPC_STRUCT_TRAITS_MEMBER(connection_info
)
128 IPC_STRUCT_TRAITS_MEMBER(was_fetched_via_proxy
)
129 IPC_STRUCT_TRAITS_MEMBER(npn_negotiated_protocol
)
130 IPC_STRUCT_TRAITS_MEMBER(socket_address
)
131 IPC_STRUCT_TRAITS_MEMBER(was_fetched_via_service_worker
)
132 IPC_STRUCT_TRAITS_MEMBER(was_fallback_required_by_service_worker
)
133 IPC_STRUCT_TRAITS_MEMBER(original_url_via_service_worker
)
134 IPC_STRUCT_TRAITS_MEMBER(response_type_via_service_worker
)
135 IPC_STRUCT_TRAITS_MEMBER(service_worker_start_time
)
136 IPC_STRUCT_TRAITS_MEMBER(service_worker_ready_time
)
137 IPC_STRUCT_TRAITS_MEMBER(proxy_server
)
138 IPC_STRUCT_TRAITS_END()
140 IPC_STRUCT_TRAITS_BEGIN(net::RedirectInfo
)
141 IPC_STRUCT_TRAITS_MEMBER(status_code
)
142 IPC_STRUCT_TRAITS_MEMBER(new_method
)
143 IPC_STRUCT_TRAITS_MEMBER(new_url
)
144 IPC_STRUCT_TRAITS_MEMBER(new_first_party_for_cookies
)
145 IPC_STRUCT_TRAITS_MEMBER(new_referrer
)
146 IPC_STRUCT_TRAITS_END()
148 // Parameters for a resource request.
149 IPC_STRUCT_BEGIN(ResourceHostMsg_Request
)
150 // The request method: GET, POST, etc.
151 IPC_STRUCT_MEMBER(std::string
, method
)
153 // The requested URL.
154 IPC_STRUCT_MEMBER(GURL
, url
)
156 // Usually the URL of the document in the top-level window, which may be
157 // checked by the third-party cookie blocking policy. Leaving it empty may
158 // lead to undesired cookie blocking. Third-party cookie blocking can be
159 // bypassed by setting first_party_for_cookies = url, but this should ideally
160 // only be done if there really is no way to determine the correct value.
161 IPC_STRUCT_MEMBER(GURL
, first_party_for_cookies
)
163 // The referrer to use (may be empty).
164 IPC_STRUCT_MEMBER(GURL
, referrer
)
166 // The referrer policy to use.
167 IPC_STRUCT_MEMBER(blink::WebReferrerPolicy
, referrer_policy
)
169 // The frame's visiblity state.
170 IPC_STRUCT_MEMBER(blink::WebPageVisibilityState
, visiblity_state
)
172 // Additional HTTP request headers.
173 IPC_STRUCT_MEMBER(std::string
, headers
)
175 // net::URLRequest load flags (0 by default).
176 IPC_STRUCT_MEMBER(int, load_flags
)
178 // Process ID from which this request originated, or zero if it originated
179 // in the renderer itself.
180 // If kDirectNPAPIRequests isn't specified, then plugin requests get routed
181 // through the renderer and and this holds the pid of the plugin process.
182 // Otherwise this holds the render_process_id of the view that has the plugin.
183 IPC_STRUCT_MEMBER(int, origin_pid
)
185 // What this resource load is for (main frame, sub-frame, sub-resource,
187 IPC_STRUCT_MEMBER(content::ResourceType
, resource_type
)
189 // The priority of this request.
190 IPC_STRUCT_MEMBER(net::RequestPriority
, priority
)
192 // Used by plugin->browser requests to get the correct net::URLRequestContext.
193 IPC_STRUCT_MEMBER(uint32
, request_context
)
195 // Indicates which frame (or worker context) the request is being loaded into,
196 // or kAppCacheNoHostId.
197 IPC_STRUCT_MEMBER(int, appcache_host_id
)
199 // True if corresponding AppCache group should be resetted.
200 IPC_STRUCT_MEMBER(bool, should_reset_appcache
)
202 // Indicates which frame (or worker context) the request is being loaded into,
203 // or kInvalidServiceWorkerProviderId.
204 IPC_STRUCT_MEMBER(int, service_worker_provider_id
)
206 // True if the request should not be handled by the ServiceWorker.
207 IPC_STRUCT_MEMBER(bool, skip_service_worker
)
209 // The request mode passed to the ServiceWorker.
210 IPC_STRUCT_MEMBER(content::FetchRequestMode
, fetch_request_mode
)
212 // The credentials mode passed to the ServiceWorker.
213 IPC_STRUCT_MEMBER(content::FetchCredentialsMode
, fetch_credentials_mode
)
215 // The redirect mode used in Fetch API.
216 IPC_STRUCT_MEMBER(content::FetchRedirectMode
, fetch_redirect_mode
)
218 // The request context passed to the ServiceWorker.
219 IPC_STRUCT_MEMBER(content::RequestContextType
, fetch_request_context_type
)
221 // The frame type passed to the ServiceWorker.
222 IPC_STRUCT_MEMBER(content::RequestContextFrameType
, fetch_frame_type
)
224 // Optional resource request body (may be null).
225 IPC_STRUCT_MEMBER(scoped_refptr
<content::ResourceRequestBody
>,
228 IPC_STRUCT_MEMBER(bool, download_to_file
)
230 // True if the request was user initiated.
231 IPC_STRUCT_MEMBER(bool, has_user_gesture
)
233 // True if load timing data should be collected for request.
234 IPC_STRUCT_MEMBER(bool, enable_load_timing
)
236 // True if upload progress should be available for request.
237 IPC_STRUCT_MEMBER(bool, enable_upload_progress
)
239 // True if login prompts for this request should be supressed.
240 IPC_STRUCT_MEMBER(bool, do_not_prompt_for_login
)
242 // The routing id of the RenderFrame.
243 IPC_STRUCT_MEMBER(int, render_frame_id
)
245 // True if |frame_id| is the main frame of a RenderView.
246 IPC_STRUCT_MEMBER(bool, is_main_frame
)
248 // True if |parent_render_frame_id| is the main frame of a RenderView.
249 IPC_STRUCT_MEMBER(bool, parent_is_main_frame
)
251 // Identifies the parent frame of the frame that sent the request.
252 // -1 if unknown / invalid.
253 IPC_STRUCT_MEMBER(int, parent_render_frame_id
)
255 IPC_STRUCT_MEMBER(ui::PageTransition
, transition_type
)
257 // For navigations, whether this navigation should replace the current session
258 // history entry on commit.
259 IPC_STRUCT_MEMBER(bool, should_replace_current_entry
)
261 // The following two members identify a previous request that has been
262 // created before this navigation has been transferred to a new render view.
263 // This serves the purpose of recycling the old request.
264 // Unless this refers to a transferred navigation, these values are -1 and -1.
265 IPC_STRUCT_MEMBER(int, transferred_request_child_id
)
266 IPC_STRUCT_MEMBER(int, transferred_request_request_id
)
268 // Whether or not we should allow the URL to download.
269 IPC_STRUCT_MEMBER(bool, allow_download
)
272 // Parameters for a ResourceMsg_RequestComplete
273 IPC_STRUCT_BEGIN(ResourceMsg_RequestCompleteData
)
275 IPC_STRUCT_MEMBER(int, error_code
)
277 // Was ignored by the request handler.
278 IPC_STRUCT_MEMBER(bool, was_ignored_by_handler
)
280 // A copy of the data requested exists in the cache.
281 IPC_STRUCT_MEMBER(bool, exists_in_cache
)
283 // Serialized security info; see content/common/ssl_status_serialization.h.
284 IPC_STRUCT_MEMBER(std::string
, security_info
)
286 // Time the request completed.
287 IPC_STRUCT_MEMBER(base::TimeTicks
, completion_time
)
289 // Total amount of data received from the network.
290 IPC_STRUCT_MEMBER(int64
, encoded_data_length
)
293 // Resource messages sent from the browser to the renderer.
295 // Sent when the headers are available for a resource request.
296 IPC_MESSAGE_CONTROL2(ResourceMsg_ReceivedResponse
,
297 int /* request_id */,
298 content::ResourceResponseHead
)
300 // Sent when cached metadata from a resource request is ready.
301 IPC_MESSAGE_CONTROL2(ResourceMsg_ReceivedCachedMetadata
,
302 int /* request_id */,
303 std::vector
<char> /* data */)
305 // Sent as upload progress is being made.
306 IPC_MESSAGE_CONTROL3(ResourceMsg_UploadProgress
,
307 int /* request_id */,
308 int64
/* position */,
311 // Sent when the request has been redirected. The receiver is expected to
312 // respond with either a FollowRedirect message (if the redirect is to be
313 // followed) or a CancelRequest message (if it should not be followed).
314 IPC_MESSAGE_CONTROL3(ResourceMsg_ReceivedRedirect
,
315 int /* request_id */,
316 net::RedirectInfo
/* redirect_info */,
317 content::ResourceResponseHead
)
319 // Sent to set the shared memory buffer to be used to transmit response data to
320 // the renderer. Subsequent DataReceived messages refer to byte ranges in the
321 // shared memory buffer. The shared memory buffer should be retained by the
322 // renderer until the resource request completes.
324 // NOTE: The shared memory handle should already be mapped into the process
325 // that receives this message.
327 // TODO(darin): The |renderer_pid| parameter is just a temporary parameter,
328 // added to help in debugging crbug/160401.
330 IPC_MESSAGE_CONTROL4(ResourceMsg_SetDataBuffer
,
331 int /* request_id */,
332 base::SharedMemoryHandle
/* shm_handle */,
334 base::ProcessId
/* renderer_pid */)
336 // Sent when some data from a resource request is ready. The data offset and
337 // length specify a byte range into the shared memory buffer provided by the
338 // SetDataBuffer message.
339 IPC_MESSAGE_CONTROL4(ResourceMsg_DataReceived
,
340 int /* request_id */,
341 int /* data_offset */,
342 int /* data_length */,
343 int /* encoded_data_length */)
345 // Sent when some data from a resource request has been downloaded to
346 // file. This is only called in the 'download_to_file' case and replaces
347 // ResourceMsg_DataReceived in the call sequence in that case.
348 IPC_MESSAGE_CONTROL3(ResourceMsg_DataDownloaded
,
349 int /* request_id */,
351 int /* encoded_data_length */)
353 // Sent when the request has been completed.
354 IPC_MESSAGE_CONTROL2(ResourceMsg_RequestComplete
,
355 int /* request_id */,
356 ResourceMsg_RequestCompleteData
)
358 // Resource messages sent from the renderer to the browser.
360 // Makes a resource request via the browser.
361 IPC_MESSAGE_CONTROL3(ResourceHostMsg_RequestResource
,
362 int /* routing_id */,
363 int /* request_id */,
364 ResourceHostMsg_Request
)
366 // Cancels a resource request with the ID given as the parameter.
367 IPC_MESSAGE_CONTROL1(ResourceHostMsg_CancelRequest
,
368 int /* request_id */)
370 // Follows a redirect that occured for the resource request with the ID given
372 IPC_MESSAGE_CONTROL1(ResourceHostMsg_FollowRedirect
,
373 int /* request_id */)
375 // Makes a synchronous resource request via the browser.
376 IPC_SYNC_MESSAGE_ROUTED2_1(ResourceHostMsg_SyncLoad
,
377 int /* request_id */,
378 ResourceHostMsg_Request
,
379 content::SyncLoadResult
)
381 // Sent when the renderer process is done processing a DataReceived
383 IPC_MESSAGE_CONTROL1(ResourceHostMsg_DataReceived_ACK
,
384 int /* request_id */)
386 // Sent when the renderer has processed a DataDownloaded message.
387 IPC_MESSAGE_CONTROL1(ResourceHostMsg_DataDownloaded_ACK
,
388 int /* request_id */)
390 // Sent by the renderer process to acknowledge receipt of a
391 // UploadProgress message.
392 IPC_MESSAGE_CONTROL1(ResourceHostMsg_UploadProgress_ACK
,
393 int /* request_id */)
395 // Sent when the renderer process deletes a resource loader.
396 IPC_MESSAGE_CONTROL1(ResourceHostMsg_ReleaseDownloadedFile
,
397 int /* request_id */)
399 // Sent by the renderer when a resource request changes priority.
400 IPC_MESSAGE_CONTROL3(ResourceHostMsg_DidChangePriority
,
401 int /* request_id */,
402 net::RequestPriority
,
403 int /* intra_priority_value */)