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/public/common/common_param_traits.h"
15 #include "content/public/common/resource_response.h"
16 #include "ipc/ipc_message_macros.h"
17 #include "net/base/request_priority.h"
18 #include "net/http/http_response_info.h"
19 #include "net/url_request/redirect_info.h"
21 #ifndef CONTENT_COMMON_RESOURCE_MESSAGES_H_
22 #define CONTENT_COMMON_RESOURCE_MESSAGES_H_
25 struct LoadTimingInfo
;
29 struct ResourceDevToolsInfo
;
35 struct ParamTraits
<scoped_refptr
<net::HttpResponseHeaders
> > {
36 typedef scoped_refptr
<net::HttpResponseHeaders
> param_type
;
37 static void Write(Message
* m
, const param_type
& p
);
38 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
);
39 static void Log(const param_type
& p
, std::string
* l
);
43 struct CONTENT_EXPORT ParamTraits
<storage::DataElement
> {
44 typedef storage::DataElement param_type
;
45 static void Write(Message
* m
, const param_type
& p
);
46 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
);
47 static void Log(const param_type
& p
, std::string
* l
);
51 struct ParamTraits
<scoped_refptr
<content::ResourceDevToolsInfo
> > {
52 typedef scoped_refptr
<content::ResourceDevToolsInfo
> param_type
;
53 static void Write(Message
* m
, const param_type
& p
);
54 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
);
55 static void Log(const param_type
& p
, std::string
* l
);
59 struct ParamTraits
<net::LoadTimingInfo
> {
60 typedef net::LoadTimingInfo param_type
;
61 static void Write(Message
* m
, const param_type
& p
);
62 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
);
63 static void Log(const param_type
& p
, std::string
* l
);
67 struct ParamTraits
<scoped_refptr
<content::ResourceRequestBody
> > {
68 typedef scoped_refptr
<content::ResourceRequestBody
> param_type
;
69 static void Write(Message
* m
, const param_type
& p
);
70 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
);
71 static void Log(const param_type
& p
, std::string
* l
);
76 #endif // CONTENT_COMMON_RESOURCE_MESSAGES_H_
79 #define IPC_MESSAGE_START ResourceMsgStart
80 #undef IPC_MESSAGE_EXPORT
81 #define IPC_MESSAGE_EXPORT CONTENT_EXPORT
83 IPC_ENUM_TRAITS_MAX_VALUE( \
84 net::HttpResponseInfo::ConnectionInfo
, \
85 net::HttpResponseInfo::NUM_OF_CONNECTION_INFOS
- 1)
87 IPC_STRUCT_TRAITS_BEGIN(content::ResourceResponseHead
)
88 IPC_STRUCT_TRAITS_PARENT(content::ResourceResponseInfo
)
89 IPC_STRUCT_TRAITS_MEMBER(request_start
)
90 IPC_STRUCT_TRAITS_MEMBER(response_start
)
91 IPC_STRUCT_TRAITS_END()
93 IPC_STRUCT_TRAITS_BEGIN(content::SyncLoadResult
)
94 IPC_STRUCT_TRAITS_PARENT(content::ResourceResponseHead
)
95 IPC_STRUCT_TRAITS_MEMBER(error_code
)
96 IPC_STRUCT_TRAITS_MEMBER(final_url
)
97 IPC_STRUCT_TRAITS_MEMBER(data
)
98 IPC_STRUCT_TRAITS_END()
100 IPC_STRUCT_TRAITS_BEGIN(content::ResourceResponseInfo
)
101 IPC_STRUCT_TRAITS_MEMBER(request_time
)
102 IPC_STRUCT_TRAITS_MEMBER(response_time
)
103 IPC_STRUCT_TRAITS_MEMBER(headers
)
104 IPC_STRUCT_TRAITS_MEMBER(mime_type
)
105 IPC_STRUCT_TRAITS_MEMBER(charset
)
106 IPC_STRUCT_TRAITS_MEMBER(security_info
)
107 IPC_STRUCT_TRAITS_MEMBER(content_length
)
108 IPC_STRUCT_TRAITS_MEMBER(encoded_data_length
)
109 IPC_STRUCT_TRAITS_MEMBER(appcache_id
)
110 IPC_STRUCT_TRAITS_MEMBER(appcache_manifest_url
)
111 IPC_STRUCT_TRAITS_MEMBER(load_timing
)
112 IPC_STRUCT_TRAITS_MEMBER(devtools_info
)
113 IPC_STRUCT_TRAITS_MEMBER(download_file_path
)
114 IPC_STRUCT_TRAITS_MEMBER(was_fetched_via_spdy
)
115 IPC_STRUCT_TRAITS_MEMBER(was_npn_negotiated
)
116 IPC_STRUCT_TRAITS_MEMBER(was_alternate_protocol_available
)
117 IPC_STRUCT_TRAITS_MEMBER(connection_info
)
118 IPC_STRUCT_TRAITS_MEMBER(was_fetched_via_proxy
)
119 IPC_STRUCT_TRAITS_MEMBER(npn_negotiated_protocol
)
120 IPC_STRUCT_TRAITS_MEMBER(socket_address
)
121 IPC_STRUCT_TRAITS_MEMBER(was_fetched_via_service_worker
)
122 IPC_STRUCT_TRAITS_MEMBER(original_url_via_service_worker
)
123 IPC_STRUCT_TRAITS_END()
125 IPC_STRUCT_TRAITS_BEGIN(net::RedirectInfo
)
126 IPC_STRUCT_TRAITS_MEMBER(status_code
)
127 IPC_STRUCT_TRAITS_MEMBER(new_method
)
128 IPC_STRUCT_TRAITS_MEMBER(new_url
)
129 IPC_STRUCT_TRAITS_MEMBER(new_first_party_for_cookies
)
130 IPC_STRUCT_TRAITS_MEMBER(new_referrer
)
131 IPC_STRUCT_TRAITS_END()
133 // Parameters for a resource request.
134 IPC_STRUCT_BEGIN(ResourceHostMsg_Request
)
135 // The request method: GET, POST, etc.
136 IPC_STRUCT_MEMBER(std::string
, method
)
138 // The requested URL.
139 IPC_STRUCT_MEMBER(GURL
, url
)
141 // Usually the URL of the document in the top-level window, which may be
142 // checked by the third-party cookie blocking policy. Leaving it empty may
143 // lead to undesired cookie blocking. Third-party cookie blocking can be
144 // bypassed by setting first_party_for_cookies = url, but this should ideally
145 // only be done if there really is no way to determine the correct value.
146 IPC_STRUCT_MEMBER(GURL
, first_party_for_cookies
)
148 // The referrer to use (may be empty).
149 IPC_STRUCT_MEMBER(GURL
, referrer
)
151 // The referrer policy to use.
152 IPC_STRUCT_MEMBER(blink::WebReferrerPolicy
, referrer_policy
)
154 // The frame's visiblity state.
155 IPC_STRUCT_MEMBER(blink::WebPageVisibilityState
, visiblity_state
)
157 // Additional HTTP request headers.
158 IPC_STRUCT_MEMBER(std::string
, headers
)
160 // net::URLRequest load flags (0 by default).
161 IPC_STRUCT_MEMBER(int, load_flags
)
163 // Process ID from which this request originated, or zero if it originated
164 // in the renderer itself.
165 // If kDirectNPAPIRequests isn't specified, then plugin requests get routed
166 // through the renderer and and this holds the pid of the plugin process.
167 // Otherwise this holds the render_process_id of the view that has the plugin.
168 IPC_STRUCT_MEMBER(int, origin_pid
)
170 // What this resource load is for (main frame, sub-frame, sub-resource,
172 IPC_STRUCT_MEMBER(content::ResourceType
, resource_type
)
174 // The priority of this request.
175 IPC_STRUCT_MEMBER(net::RequestPriority
, priority
)
177 // Used by plugin->browser requests to get the correct net::URLRequestContext.
178 IPC_STRUCT_MEMBER(uint32
, request_context
)
180 // Indicates which frame (or worker context) the request is being loaded into,
181 // or kAppCacheNoHostId.
182 IPC_STRUCT_MEMBER(int, appcache_host_id
)
184 // Indicates which frame (or worker context) the request is being loaded into,
185 // or kInvalidServiceWorkerProviderId.
186 IPC_STRUCT_MEMBER(int, service_worker_provider_id
)
188 // True if the request should not be handled by the ServiceWorker.
189 IPC_STRUCT_MEMBER(bool, skip_service_worker
)
191 // Optional resource request body (may be null).
192 IPC_STRUCT_MEMBER(scoped_refptr
<content::ResourceRequestBody
>,
195 IPC_STRUCT_MEMBER(bool, download_to_file
)
197 // True if the request was user initiated.
198 IPC_STRUCT_MEMBER(bool, has_user_gesture
)
200 // True if load timing data should be collected for request.
201 IPC_STRUCT_MEMBER(bool, enable_load_timing
)
203 // The routing id of the RenderFrame.
204 IPC_STRUCT_MEMBER(int, render_frame_id
)
206 // True if |frame_id| is the main frame of a RenderView.
207 IPC_STRUCT_MEMBER(bool, is_main_frame
)
209 // True if |parent_render_frame_id| is the main frame of a RenderView.
210 IPC_STRUCT_MEMBER(bool, parent_is_main_frame
)
212 // Identifies the parent frame of the frame that sent the request.
213 // -1 if unknown / invalid.
214 IPC_STRUCT_MEMBER(int, parent_render_frame_id
)
216 IPC_STRUCT_MEMBER(content::PageTransition
, transition_type
)
218 // For navigations, whether this navigation should replace the current session
219 // history entry on commit.
220 IPC_STRUCT_MEMBER(bool, should_replace_current_entry
)
222 // The following two members identify a previous request that has been
223 // created before this navigation has been transferred to a new render view.
224 // This serves the purpose of recycling the old request.
225 // Unless this refers to a transferred navigation, these values are -1 and -1.
226 IPC_STRUCT_MEMBER(int, transferred_request_child_id
)
227 IPC_STRUCT_MEMBER(int, transferred_request_request_id
)
229 // Whether or not we should allow the URL to download.
230 IPC_STRUCT_MEMBER(bool, allow_download
)
233 // Parameters for a ResourceMsg_RequestComplete
234 IPC_STRUCT_BEGIN(ResourceMsg_RequestCompleteData
)
236 IPC_STRUCT_MEMBER(int, error_code
)
238 // Was ignored by the request handler.
239 IPC_STRUCT_MEMBER(bool, was_ignored_by_handler
)
241 // A copy of the data requested exists in the cache.
242 IPC_STRUCT_MEMBER(bool, exists_in_cache
)
244 // Serialized security info; see content/common/ssl_status_serialization.h.
245 IPC_STRUCT_MEMBER(std::string
, security_info
)
247 // Time the request completed.
248 IPC_STRUCT_MEMBER(base::TimeTicks
, completion_time
)
250 // Total amount of data received from the network.
251 IPC_STRUCT_MEMBER(int64
, encoded_data_length
)
254 // Resource messages sent from the browser to the renderer.
256 // Sent when the headers are available for a resource request.
257 IPC_MESSAGE_CONTROL2(ResourceMsg_ReceivedResponse
,
258 int /* request_id */,
259 content::ResourceResponseHead
)
261 // Sent when cached metadata from a resource request is ready.
262 IPC_MESSAGE_CONTROL2(ResourceMsg_ReceivedCachedMetadata
,
263 int /* request_id */,
264 std::vector
<char> /* data */)
266 // Sent as upload progress is being made.
267 IPC_MESSAGE_CONTROL3(ResourceMsg_UploadProgress
,
268 int /* request_id */,
269 int64
/* position */,
272 // Sent when the request has been redirected. The receiver is expected to
273 // respond with either a FollowRedirect message (if the redirect is to be
274 // followed) or a CancelRequest message (if it should not be followed).
275 IPC_MESSAGE_CONTROL3(ResourceMsg_ReceivedRedirect
,
276 int /* request_id */,
277 net::RedirectInfo
/* redirect_info */,
278 content::ResourceResponseHead
)
280 // Sent to set the shared memory buffer to be used to transmit response data to
281 // the renderer. Subsequent DataReceived messages refer to byte ranges in the
282 // shared memory buffer. The shared memory buffer should be retained by the
283 // renderer until the resource request completes.
285 // NOTE: The shared memory handle should already be mapped into the process
286 // that receives this message.
288 // TODO(darin): The |renderer_pid| parameter is just a temporary parameter,
289 // added to help in debugging crbug/160401.
291 IPC_MESSAGE_CONTROL4(ResourceMsg_SetDataBuffer
,
292 int /* request_id */,
293 base::SharedMemoryHandle
/* shm_handle */,
295 base::ProcessId
/* renderer_pid */)
297 // Sent when some data from a resource request is ready. The data offset and
298 // length specify a byte range into the shared memory buffer provided by the
299 // SetDataBuffer message.
300 IPC_MESSAGE_CONTROL4(ResourceMsg_DataReceived
,
301 int /* request_id */,
302 int /* data_offset */,
303 int /* data_length */,
304 int /* encoded_data_length */)
306 // Sent when some data from a resource request has been downloaded to
307 // file. This is only called in the 'download_to_file' case and replaces
308 // ResourceMsg_DataReceived in the call sequence in that case.
309 IPC_MESSAGE_CONTROL3(ResourceMsg_DataDownloaded
,
310 int /* request_id */,
312 int /* encoded_data_length */)
314 // Sent when the request has been completed.
315 IPC_MESSAGE_CONTROL2(ResourceMsg_RequestComplete
,
316 int /* request_id */,
317 ResourceMsg_RequestCompleteData
)
319 // Resource messages sent from the renderer to the browser.
321 // Makes a resource request via the browser.
322 IPC_MESSAGE_CONTROL3(ResourceHostMsg_RequestResource
,
323 int /* routing_id */,
324 int /* request_id */,
325 ResourceHostMsg_Request
)
327 // Cancels a resource request with the ID given as the parameter.
328 IPC_MESSAGE_CONTROL1(ResourceHostMsg_CancelRequest
,
329 int /* request_id */)
331 // Follows a redirect that occured for the resource request with the ID given
333 IPC_MESSAGE_CONTROL1(ResourceHostMsg_FollowRedirect
,
334 int /* request_id */)
336 // Makes a synchronous resource request via the browser.
337 IPC_SYNC_MESSAGE_ROUTED2_1(ResourceHostMsg_SyncLoad
,
338 int /* request_id */,
339 ResourceHostMsg_Request
,
340 content::SyncLoadResult
)
342 // Sent when the renderer process is done processing a DataReceived
344 IPC_MESSAGE_CONTROL1(ResourceHostMsg_DataReceived_ACK
,
345 int /* request_id */)
347 // Sent when the renderer has processed a DataDownloaded message.
348 IPC_MESSAGE_CONTROL1(ResourceHostMsg_DataDownloaded_ACK
,
349 int /* request_id */)
351 // Sent by the renderer process to acknowledge receipt of a
352 // UploadProgress message.
353 IPC_MESSAGE_CONTROL1(ResourceHostMsg_UploadProgress_ACK
,
354 int /* request_id */)
356 // Sent when the renderer process deletes a resource loader.
357 IPC_MESSAGE_CONTROL1(ResourceHostMsg_ReleaseDownloadedFile
,
358 int /* request_id */)
360 // Sent by the renderer when a resource request changes priority.
361 IPC_MESSAGE_CONTROL3(ResourceHostMsg_DidChangePriority
,
362 int /* request_id */,
363 net::RequestPriority
,
364 int /* intra_priority_value */)