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.
4
5// IPC messages for resource loading.
6//
7// NOTE: All messages must send an |int request_id| as their first parameter.
8
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"
20
21#ifndef CONTENT_COMMON_RESOURCE_MESSAGES_H_
22#define CONTENT_COMMON_RESOURCE_MESSAGES_H_
23
24namespace net {
25struct LoadTimingInfo;
26}
27
28namespace content {
29struct ResourceDevToolsInfo;
30}
31
32namespace IPC {
33
34template <>
35struct 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);
40};
41
42template <>
43struct 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);
48};
49
50template <>
51struct 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);
56};
57
58template <>
59struct 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);
64};
65
66template <>
67struct 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);
72};
73
74}  // namespace IPC
75
76#endif  // CONTENT_COMMON_RESOURCE_MESSAGES_H_
77
78
79#define IPC_MESSAGE_START ResourceMsgStart
80#undef IPC_MESSAGE_EXPORT
81#define IPC_MESSAGE_EXPORT CONTENT_EXPORT
82
83IPC_ENUM_TRAITS_MAX_VALUE( \
84    net::HttpResponseInfo::ConnectionInfo, \
85    net::HttpResponseInfo::NUM_OF_CONNECTION_INFOS - 1)
86
87IPC_STRUCT_TRAITS_BEGIN(content::ResourceResponseHead)
88IPC_STRUCT_TRAITS_PARENT(content::ResourceResponseInfo)
89  IPC_STRUCT_TRAITS_MEMBER(request_start)
90  IPC_STRUCT_TRAITS_MEMBER(response_start)
91IPC_STRUCT_TRAITS_END()
92
93IPC_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)
98IPC_STRUCT_TRAITS_END()
99
100IPC_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_MEMBER(service_worker_fetch_start)
124  IPC_STRUCT_TRAITS_MEMBER(service_worker_fetch_ready)
125  IPC_STRUCT_TRAITS_MEMBER(service_worker_fetch_end)
126IPC_STRUCT_TRAITS_END()
127
128IPC_STRUCT_TRAITS_BEGIN(net::RedirectInfo)
129  IPC_STRUCT_TRAITS_MEMBER(status_code)
130  IPC_STRUCT_TRAITS_MEMBER(new_method)
131  IPC_STRUCT_TRAITS_MEMBER(new_url)
132  IPC_STRUCT_TRAITS_MEMBER(new_first_party_for_cookies)
133  IPC_STRUCT_TRAITS_MEMBER(new_referrer)
134IPC_STRUCT_TRAITS_END()
135
136// Parameters for a resource request.
137IPC_STRUCT_BEGIN(ResourceHostMsg_Request)
138  // The request method: GET, POST, etc.
139  IPC_STRUCT_MEMBER(std::string, method)
140
141  // The requested URL.
142  IPC_STRUCT_MEMBER(GURL, url)
143
144  // Usually the URL of the document in the top-level window, which may be
145  // checked by the third-party cookie blocking policy. Leaving it empty may
146  // lead to undesired cookie blocking. Third-party cookie blocking can be
147  // bypassed by setting first_party_for_cookies = url, but this should ideally
148  // only be done if there really is no way to determine the correct value.
149  IPC_STRUCT_MEMBER(GURL, first_party_for_cookies)
150
151  // The referrer to use (may be empty).
152  IPC_STRUCT_MEMBER(GURL, referrer)
153
154  // The referrer policy to use.
155  IPC_STRUCT_MEMBER(blink::WebReferrerPolicy, referrer_policy)
156
157  // The frame's visiblity state.
158  IPC_STRUCT_MEMBER(blink::WebPageVisibilityState, visiblity_state)
159
160  // Additional HTTP request headers.
161  IPC_STRUCT_MEMBER(std::string, headers)
162
163  // net::URLRequest load flags (0 by default).
164  IPC_STRUCT_MEMBER(int, load_flags)
165
166  // Process ID from which this request originated, or zero if it originated
167  // in the renderer itself.
168  // If kDirectNPAPIRequests isn't specified, then plugin requests get routed
169  // through the renderer and and this holds the pid of the plugin process.
170  // Otherwise this holds the render_process_id of the view that has the plugin.
171  IPC_STRUCT_MEMBER(int, origin_pid)
172
173  // What this resource load is for (main frame, sub-frame, sub-resource,
174  // object).
175  IPC_STRUCT_MEMBER(content::ResourceType, resource_type)
176
177  // The priority of this request.
178  IPC_STRUCT_MEMBER(net::RequestPriority, priority)
179
180  // Used by plugin->browser requests to get the correct net::URLRequestContext.
181  IPC_STRUCT_MEMBER(uint32, request_context)
182
183  // Indicates which frame (or worker context) the request is being loaded into,
184  // or kAppCacheNoHostId.
185  IPC_STRUCT_MEMBER(int, appcache_host_id)
186
187  // Indicates which frame (or worker context) the request is being loaded into,
188  // or kInvalidServiceWorkerProviderId.
189  IPC_STRUCT_MEMBER(int, service_worker_provider_id)
190
191  // True if the request should not be handled by the ServiceWorker.
192  IPC_STRUCT_MEMBER(bool, skip_service_worker)
193
194  // Optional resource request body (may be null).
195  IPC_STRUCT_MEMBER(scoped_refptr<content::ResourceRequestBody>,
196                    request_body)
197
198  IPC_STRUCT_MEMBER(bool, download_to_file)
199
200  // True if the request was user initiated.
201  IPC_STRUCT_MEMBER(bool, has_user_gesture)
202
203  // True if load timing data should be collected for request.
204  IPC_STRUCT_MEMBER(bool, enable_load_timing)
205
206  // The routing id of the RenderFrame.
207  IPC_STRUCT_MEMBER(int, render_frame_id)
208
209  // True if |frame_id| is the main frame of a RenderView.
210  IPC_STRUCT_MEMBER(bool, is_main_frame)
211
212  // True if |parent_render_frame_id| is the main frame of a RenderView.
213  IPC_STRUCT_MEMBER(bool, parent_is_main_frame)
214
215  // Identifies the parent frame of the frame that sent the request.
216  // -1 if unknown / invalid.
217  IPC_STRUCT_MEMBER(int, parent_render_frame_id)
218
219  IPC_STRUCT_MEMBER(ui::PageTransition, transition_type)
220
221  // For navigations, whether this navigation should replace the current session
222  // history entry on commit.
223  IPC_STRUCT_MEMBER(bool, should_replace_current_entry)
224
225  // The following two members identify a previous request that has been
226  // created before this navigation has been transferred to a new render view.
227  // This serves the purpose of recycling the old request.
228  // Unless this refers to a transferred navigation, these values are -1 and -1.
229  IPC_STRUCT_MEMBER(int, transferred_request_child_id)
230  IPC_STRUCT_MEMBER(int, transferred_request_request_id)
231
232  // Whether or not we should allow the URL to download.
233  IPC_STRUCT_MEMBER(bool, allow_download)
234IPC_STRUCT_END()
235
236// Parameters for a ResourceMsg_RequestComplete
237IPC_STRUCT_BEGIN(ResourceMsg_RequestCompleteData)
238  // The error code.
239  IPC_STRUCT_MEMBER(int, error_code)
240
241  // Was ignored by the request handler.
242  IPC_STRUCT_MEMBER(bool, was_ignored_by_handler)
243
244  // A copy of the data requested exists in the cache.
245  IPC_STRUCT_MEMBER(bool, exists_in_cache)
246
247  // Serialized security info; see content/common/ssl_status_serialization.h.
248  IPC_STRUCT_MEMBER(std::string, security_info)
249
250  // Time the request completed.
251  IPC_STRUCT_MEMBER(base::TimeTicks, completion_time)
252
253  // Total amount of data received from the network.
254  IPC_STRUCT_MEMBER(int64, encoded_data_length)
255IPC_STRUCT_END()
256
257// Resource messages sent from the browser to the renderer.
258
259// Sent when the headers are available for a resource request.
260IPC_MESSAGE_CONTROL2(ResourceMsg_ReceivedResponse,
261                     int /* request_id */,
262                     content::ResourceResponseHead)
263
264// Sent when cached metadata from a resource request is ready.
265IPC_MESSAGE_CONTROL2(ResourceMsg_ReceivedCachedMetadata,
266                     int /* request_id */,
267                     std::vector<char> /* data */)
268
269// Sent as upload progress is being made.
270IPC_MESSAGE_CONTROL3(ResourceMsg_UploadProgress,
271                     int /* request_id */,
272                     int64 /* position */,
273                     int64 /* size */)
274
275// Sent when the request has been redirected.  The receiver is expected to
276// respond with either a FollowRedirect message (if the redirect is to be
277// followed) or a CancelRequest message (if it should not be followed).
278IPC_MESSAGE_CONTROL3(ResourceMsg_ReceivedRedirect,
279                     int /* request_id */,
280                     net::RedirectInfo /* redirect_info */,
281                     content::ResourceResponseHead)
282
283// Sent to set the shared memory buffer to be used to transmit response data to
284// the renderer.  Subsequent DataReceived messages refer to byte ranges in the
285// shared memory buffer.  The shared memory buffer should be retained by the
286// renderer until the resource request completes.
287//
288// NOTE: The shared memory handle should already be mapped into the process
289// that receives this message.
290//
291// TODO(darin): The |renderer_pid| parameter is just a temporary parameter,
292// added to help in debugging crbug/160401.
293//
294IPC_MESSAGE_CONTROL4(ResourceMsg_SetDataBuffer,
295                     int /* request_id */,
296                     base::SharedMemoryHandle /* shm_handle */,
297                     int /* shm_size */,
298                     base::ProcessId /* renderer_pid */)
299
300// Sent when some data from a resource request is ready.  The data offset and
301// length specify a byte range into the shared memory buffer provided by the
302// SetDataBuffer message.
303IPC_MESSAGE_CONTROL4(ResourceMsg_DataReceived,
304                     int /* request_id */,
305                     int /* data_offset */,
306                     int /* data_length */,
307                     int /* encoded_data_length */)
308
309// Sent when some data from a resource request has been downloaded to
310// file. This is only called in the 'download_to_file' case and replaces
311// ResourceMsg_DataReceived in the call sequence in that case.
312IPC_MESSAGE_CONTROL3(ResourceMsg_DataDownloaded,
313                     int /* request_id */,
314                     int /* data_len */,
315                     int /* encoded_data_length */)
316
317// Sent when the request has been completed.
318IPC_MESSAGE_CONTROL2(ResourceMsg_RequestComplete,
319                     int /* request_id */,
320                     ResourceMsg_RequestCompleteData)
321
322// Resource messages sent from the renderer to the browser.
323
324// Makes a resource request via the browser.
325IPC_MESSAGE_CONTROL3(ResourceHostMsg_RequestResource,
326                    int /* routing_id */,
327                    int /* request_id */,
328                    ResourceHostMsg_Request)
329
330// Cancels a resource request with the ID given as the parameter.
331IPC_MESSAGE_CONTROL1(ResourceHostMsg_CancelRequest,
332                     int /* request_id */)
333
334// Follows a redirect that occured for the resource request with the ID given
335// as the parameter.
336IPC_MESSAGE_CONTROL1(ResourceHostMsg_FollowRedirect,
337                     int /* request_id */)
338
339// Makes a synchronous resource request via the browser.
340IPC_SYNC_MESSAGE_ROUTED2_1(ResourceHostMsg_SyncLoad,
341                           int /* request_id */,
342                           ResourceHostMsg_Request,
343                           content::SyncLoadResult)
344
345// Sent when the renderer process is done processing a DataReceived
346// message.
347IPC_MESSAGE_CONTROL1(ResourceHostMsg_DataReceived_ACK,
348                     int /* request_id */)
349
350// Sent when the renderer has processed a DataDownloaded message.
351IPC_MESSAGE_CONTROL1(ResourceHostMsg_DataDownloaded_ACK,
352                     int /* request_id */)
353
354// Sent by the renderer process to acknowledge receipt of a
355// UploadProgress message.
356IPC_MESSAGE_CONTROL1(ResourceHostMsg_UploadProgress_ACK,
357                     int /* request_id */)
358
359// Sent when the renderer process deletes a resource loader.
360IPC_MESSAGE_CONTROL1(ResourceHostMsg_ReleaseDownloadedFile,
361                     int /* request_id */)
362
363// Sent by the renderer when a resource request changes priority.
364IPC_MESSAGE_CONTROL3(ResourceHostMsg_DidChangePriority,
365                     int /* request_id */,
366                     net::RequestPriority,
367                     int /* intra_priority_value */)
368