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
, 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
, 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
, 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
, 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
, 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_STRUCT_TRAITS_BEGIN(content::ResourceResponseHead
)
95 IPC_STRUCT_TRAITS_PARENT(content::ResourceResponseInfo
)
96 IPC_STRUCT_TRAITS_MEMBER(request_start
)
97 IPC_STRUCT_TRAITS_MEMBER(response_start
)
98 IPC_STRUCT_TRAITS_END()
100 IPC_STRUCT_TRAITS_BEGIN(content::SyncLoadResult
)
101 IPC_STRUCT_TRAITS_PARENT(content::ResourceResponseHead
)
102 IPC_STRUCT_TRAITS_MEMBER(error_code
)
103 IPC_STRUCT_TRAITS_MEMBER(final_url
)
104 IPC_STRUCT_TRAITS_MEMBER(data
)
105 IPC_STRUCT_TRAITS_END()
107 IPC_STRUCT_TRAITS_BEGIN(content::ResourceResponseInfo
)
108 IPC_STRUCT_TRAITS_MEMBER(request_time
)
109 IPC_STRUCT_TRAITS_MEMBER(response_time
)
110 IPC_STRUCT_TRAITS_MEMBER(headers
)
111 IPC_STRUCT_TRAITS_MEMBER(mime_type
)
112 IPC_STRUCT_TRAITS_MEMBER(charset
)
113 IPC_STRUCT_TRAITS_MEMBER(security_info
)
114 IPC_STRUCT_TRAITS_MEMBER(content_length
)
115 IPC_STRUCT_TRAITS_MEMBER(encoded_data_length
)
116 IPC_STRUCT_TRAITS_MEMBER(appcache_id
)
117 IPC_STRUCT_TRAITS_MEMBER(appcache_manifest_url
)
118 IPC_STRUCT_TRAITS_MEMBER(load_timing
)
119 IPC_STRUCT_TRAITS_MEMBER(devtools_info
)
120 IPC_STRUCT_TRAITS_MEMBER(download_file_path
)
121 IPC_STRUCT_TRAITS_MEMBER(was_fetched_via_spdy
)
122 IPC_STRUCT_TRAITS_MEMBER(was_npn_negotiated
)
123 IPC_STRUCT_TRAITS_MEMBER(was_alternate_protocol_available
)
124 IPC_STRUCT_TRAITS_MEMBER(connection_info
)
125 IPC_STRUCT_TRAITS_MEMBER(was_fetched_via_proxy
)
126 IPC_STRUCT_TRAITS_MEMBER(npn_negotiated_protocol
)
127 IPC_STRUCT_TRAITS_MEMBER(socket_address
)
128 IPC_STRUCT_TRAITS_MEMBER(was_fetched_via_service_worker
)
129 IPC_STRUCT_TRAITS_MEMBER(was_fallback_required_by_service_worker
)
130 IPC_STRUCT_TRAITS_MEMBER(original_url_via_service_worker
)
131 IPC_STRUCT_TRAITS_MEMBER(response_type_via_service_worker
)
132 IPC_STRUCT_TRAITS_MEMBER(service_worker_fetch_start
)
133 IPC_STRUCT_TRAITS_MEMBER(service_worker_fetch_ready
)
134 IPC_STRUCT_TRAITS_MEMBER(service_worker_fetch_end
)
135 IPC_STRUCT_TRAITS_MEMBER(proxy_server
)
136 IPC_STRUCT_TRAITS_END()
138 IPC_STRUCT_TRAITS_BEGIN(net::RedirectInfo
)
139 IPC_STRUCT_TRAITS_MEMBER(status_code
)
140 IPC_STRUCT_TRAITS_MEMBER(new_method
)
141 IPC_STRUCT_TRAITS_MEMBER(new_url
)
142 IPC_STRUCT_TRAITS_MEMBER(new_first_party_for_cookies
)
143 IPC_STRUCT_TRAITS_MEMBER(new_referrer
)
144 IPC_STRUCT_TRAITS_END()
146 // Parameters for a resource request.
147 IPC_STRUCT_BEGIN(ResourceHostMsg_Request
)
148 // The request method: GET, POST, etc.
149 IPC_STRUCT_MEMBER(std::string
, method
)
151 // The requested URL.
152 IPC_STRUCT_MEMBER(GURL
, url
)
154 // Usually the URL of the document in the top-level window, which may be
155 // checked by the third-party cookie blocking policy. Leaving it empty may
156 // lead to undesired cookie blocking. Third-party cookie blocking can be
157 // bypassed by setting first_party_for_cookies = url, but this should ideally
158 // only be done if there really is no way to determine the correct value.
159 IPC_STRUCT_MEMBER(GURL
, first_party_for_cookies
)
161 // The referrer to use (may be empty).
162 IPC_STRUCT_MEMBER(GURL
, referrer
)
164 // The referrer policy to use.
165 IPC_STRUCT_MEMBER(blink::WebReferrerPolicy
, referrer_policy
)
167 // The frame's visiblity state.
168 IPC_STRUCT_MEMBER(blink::WebPageVisibilityState
, visiblity_state
)
170 // Additional HTTP request headers.
171 IPC_STRUCT_MEMBER(std::string
, headers
)
173 // net::URLRequest load flags (0 by default).
174 IPC_STRUCT_MEMBER(int, load_flags
)
176 // Process ID from which this request originated, or zero if it originated
177 // in the renderer itself.
178 // If kDirectNPAPIRequests isn't specified, then plugin requests get routed
179 // through the renderer and and this holds the pid of the plugin process.
180 // Otherwise this holds the render_process_id of the view that has the plugin.
181 IPC_STRUCT_MEMBER(int, origin_pid
)
183 // What this resource load is for (main frame, sub-frame, sub-resource,
185 IPC_STRUCT_MEMBER(content::ResourceType
, resource_type
)
187 // The priority of this request.
188 IPC_STRUCT_MEMBER(net::RequestPriority
, priority
)
190 // Used by plugin->browser requests to get the correct net::URLRequestContext.
191 IPC_STRUCT_MEMBER(uint32
, request_context
)
193 // Indicates which frame (or worker context) the request is being loaded into,
194 // or kAppCacheNoHostId.
195 IPC_STRUCT_MEMBER(int, appcache_host_id
)
197 // True if corresponding AppCache group should be resetted.
198 IPC_STRUCT_MEMBER(bool, should_reset_appcache
)
200 // Indicates which frame (or worker context) the request is being loaded into,
201 // or kInvalidServiceWorkerProviderId.
202 IPC_STRUCT_MEMBER(int, service_worker_provider_id
)
204 // True if the request should not be handled by the ServiceWorker.
205 IPC_STRUCT_MEMBER(bool, skip_service_worker
)
207 // The request mode passed to the ServiceWorker.
208 IPC_STRUCT_MEMBER(content::FetchRequestMode
, fetch_request_mode
)
210 // The credentials mode passed to the ServiceWorker.
211 IPC_STRUCT_MEMBER(content::FetchCredentialsMode
, fetch_credentials_mode
)
213 // The request context passed to the ServiceWorker.
214 IPC_STRUCT_MEMBER(content::RequestContextType
, fetch_request_context_type
)
216 // The frame type passed to the ServiceWorker.
217 IPC_STRUCT_MEMBER(content::RequestContextFrameType
, fetch_frame_type
)
219 // Optional resource request body (may be null).
220 IPC_STRUCT_MEMBER(scoped_refptr
<content::ResourceRequestBody
>,
223 IPC_STRUCT_MEMBER(bool, download_to_file
)
225 // True if the request was user initiated.
226 IPC_STRUCT_MEMBER(bool, has_user_gesture
)
228 // True if load timing data should be collected for request.
229 IPC_STRUCT_MEMBER(bool, enable_load_timing
)
231 // True if upload progress should be available for request.
232 IPC_STRUCT_MEMBER(bool, enable_upload_progress
)
234 // True if login prompts for this request should be supressed.
235 IPC_STRUCT_MEMBER(bool, do_not_prompt_for_login
)
237 // The routing id of the RenderFrame.
238 IPC_STRUCT_MEMBER(int, render_frame_id
)
240 // True if |frame_id| is the main frame of a RenderView.
241 IPC_STRUCT_MEMBER(bool, is_main_frame
)
243 // True if |parent_render_frame_id| is the main frame of a RenderView.
244 IPC_STRUCT_MEMBER(bool, parent_is_main_frame
)
246 // Identifies the parent frame of the frame that sent the request.
247 // -1 if unknown / invalid.
248 IPC_STRUCT_MEMBER(int, parent_render_frame_id
)
250 IPC_STRUCT_MEMBER(ui::PageTransition
, transition_type
)
252 // For navigations, whether this navigation should replace the current session
253 // history entry on commit.
254 IPC_STRUCT_MEMBER(bool, should_replace_current_entry
)
256 // The following two members identify a previous request that has been
257 // created before this navigation has been transferred to a new render view.
258 // This serves the purpose of recycling the old request.
259 // Unless this refers to a transferred navigation, these values are -1 and -1.
260 IPC_STRUCT_MEMBER(int, transferred_request_child_id
)
261 IPC_STRUCT_MEMBER(int, transferred_request_request_id
)
263 // Whether or not we should allow the URL to download.
264 IPC_STRUCT_MEMBER(bool, allow_download
)
267 // Parameters for a ResourceMsg_RequestComplete
268 IPC_STRUCT_BEGIN(ResourceMsg_RequestCompleteData
)
270 IPC_STRUCT_MEMBER(int, error_code
)
272 // Was ignored by the request handler.
273 IPC_STRUCT_MEMBER(bool, was_ignored_by_handler
)
275 // A copy of the data requested exists in the cache.
276 IPC_STRUCT_MEMBER(bool, exists_in_cache
)
278 // Serialized security info; see content/common/ssl_status_serialization.h.
279 IPC_STRUCT_MEMBER(std::string
, security_info
)
281 // Time the request completed.
282 IPC_STRUCT_MEMBER(base::TimeTicks
, completion_time
)
284 // Total amount of data received from the network.
285 IPC_STRUCT_MEMBER(int64
, encoded_data_length
)
288 // Resource messages sent from the browser to the renderer.
290 // Sent when the headers are available for a resource request.
291 IPC_MESSAGE_CONTROL2(ResourceMsg_ReceivedResponse
,
292 int /* request_id */,
293 content::ResourceResponseHead
)
295 // Sent when cached metadata from a resource request is ready.
296 IPC_MESSAGE_CONTROL2(ResourceMsg_ReceivedCachedMetadata
,
297 int /* request_id */,
298 std::vector
<char> /* data */)
300 // Sent as upload progress is being made.
301 IPC_MESSAGE_CONTROL3(ResourceMsg_UploadProgress
,
302 int /* request_id */,
303 int64
/* position */,
306 // Sent when the request has been redirected. The receiver is expected to
307 // respond with either a FollowRedirect message (if the redirect is to be
308 // followed) or a CancelRequest message (if it should not be followed).
309 IPC_MESSAGE_CONTROL3(ResourceMsg_ReceivedRedirect
,
310 int /* request_id */,
311 net::RedirectInfo
/* redirect_info */,
312 content::ResourceResponseHead
)
314 // Sent to set the shared memory buffer to be used to transmit response data to
315 // the renderer. Subsequent DataReceived messages refer to byte ranges in the
316 // shared memory buffer. The shared memory buffer should be retained by the
317 // renderer until the resource request completes.
319 // NOTE: The shared memory handle should already be mapped into the process
320 // that receives this message.
322 // TODO(darin): The |renderer_pid| parameter is just a temporary parameter,
323 // added to help in debugging crbug/160401.
325 IPC_MESSAGE_CONTROL4(ResourceMsg_SetDataBuffer
,
326 int /* request_id */,
327 base::SharedMemoryHandle
/* shm_handle */,
329 base::ProcessId
/* renderer_pid */)
331 // Sent when some data from a resource request is ready. The data offset and
332 // length specify a byte range into the shared memory buffer provided by the
333 // SetDataBuffer message.
334 IPC_MESSAGE_CONTROL4(ResourceMsg_DataReceived
,
335 int /* request_id */,
336 int /* data_offset */,
337 int /* data_length */,
338 int /* encoded_data_length */)
340 // Sent when some data from a resource request has been downloaded to
341 // file. This is only called in the 'download_to_file' case and replaces
342 // ResourceMsg_DataReceived in the call sequence in that case.
343 IPC_MESSAGE_CONTROL3(ResourceMsg_DataDownloaded
,
344 int /* request_id */,
346 int /* encoded_data_length */)
348 // Sent when the request has been completed.
349 IPC_MESSAGE_CONTROL2(ResourceMsg_RequestComplete
,
350 int /* request_id */,
351 ResourceMsg_RequestCompleteData
)
353 // Resource messages sent from the renderer to the browser.
355 // Makes a resource request via the browser.
356 IPC_MESSAGE_CONTROL3(ResourceHostMsg_RequestResource
,
357 int /* routing_id */,
358 int /* request_id */,
359 ResourceHostMsg_Request
)
361 // Cancels a resource request with the ID given as the parameter.
362 IPC_MESSAGE_CONTROL1(ResourceHostMsg_CancelRequest
,
363 int /* request_id */)
365 // Follows a redirect that occured for the resource request with the ID given
367 IPC_MESSAGE_CONTROL1(ResourceHostMsg_FollowRedirect
,
368 int /* request_id */)
370 // Makes a synchronous resource request via the browser.
371 IPC_SYNC_MESSAGE_ROUTED2_1(ResourceHostMsg_SyncLoad
,
372 int /* request_id */,
373 ResourceHostMsg_Request
,
374 content::SyncLoadResult
)
376 // Sent when the renderer process is done processing a DataReceived
378 IPC_MESSAGE_CONTROL1(ResourceHostMsg_DataReceived_ACK
,
379 int /* request_id */)
381 // Sent when the renderer has processed a DataDownloaded message.
382 IPC_MESSAGE_CONTROL1(ResourceHostMsg_DataDownloaded_ACK
,
383 int /* request_id */)
385 // Sent by the renderer process to acknowledge receipt of a
386 // UploadProgress message.
387 IPC_MESSAGE_CONTROL1(ResourceHostMsg_UploadProgress_ACK
,
388 int /* request_id */)
390 // Sent when the renderer process deletes a resource loader.
391 IPC_MESSAGE_CONTROL1(ResourceHostMsg_ReleaseDownloadedFile
,
392 int /* request_id */)
394 // Sent by the renderer when a resource request changes priority.
395 IPC_MESSAGE_CONTROL3(ResourceHostMsg_DidChangePriority
,
396 int /* request_id */,
397 net::RequestPriority
,
398 int /* intra_priority_value */)