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/process.h"
11 #include "base/shared_memory.h"
12 #include "content/common/content_param_traits_macros.h"
13 #include "content/public/common/common_param_traits.h"
14 #include "content/public/common/resource_response.h"
15 #include "ipc/ipc_message_macros.h"
16 #include "net/base/request_priority.h"
17 #include "webkit/glue/resource_request_body.h"
19 #ifndef CONTENT_COMMON_RESOURCE_MESSAGES_H_
20 #define CONTENT_COMMON_RESOURCE_MESSAGES_H_
23 struct LoadTimingInfo
;
26 namespace webkit_glue
{
27 struct ResourceDevToolsInfo
;
33 struct ParamTraits
<scoped_refptr
<net::HttpResponseHeaders
> > {
34 typedef scoped_refptr
<net::HttpResponseHeaders
> param_type
;
35 static void Write(Message
* m
, const param_type
& p
);
36 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
);
37 static void Log(const param_type
& p
, std::string
* l
);
41 struct CONTENT_EXPORT ParamTraits
<webkit_base::DataElement
> {
42 typedef webkit_base::DataElement param_type
;
43 static void Write(Message
* m
, const param_type
& p
);
44 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
);
45 static void Log(const param_type
& p
, std::string
* l
);
49 struct ParamTraits
<scoped_refptr
<webkit_glue::ResourceDevToolsInfo
> > {
50 typedef scoped_refptr
<webkit_glue::ResourceDevToolsInfo
> param_type
;
51 static void Write(Message
* m
, const param_type
& p
);
52 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
);
53 static void Log(const param_type
& p
, std::string
* l
);
57 struct ParamTraits
<net::LoadTimingInfo
> {
58 typedef net::LoadTimingInfo param_type
;
59 static void Write(Message
* m
, const param_type
& p
);
60 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
);
61 static void Log(const param_type
& p
, std::string
* l
);
65 struct ParamTraits
<scoped_refptr
<webkit_glue::ResourceRequestBody
> > {
66 typedef scoped_refptr
<webkit_glue::ResourceRequestBody
> param_type
;
67 static void Write(Message
* m
, const param_type
& p
);
68 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
);
69 static void Log(const param_type
& p
, std::string
* l
);
74 #endif // CONTENT_COMMON_RESOURCE_MESSAGES_H_
77 #define IPC_MESSAGE_START ResourceMsgStart
78 #undef IPC_MESSAGE_EXPORT
79 #define IPC_MESSAGE_EXPORT CONTENT_EXPORT
81 IPC_STRUCT_TRAITS_BEGIN(content::ResourceResponseHead
)
82 IPC_STRUCT_TRAITS_PARENT(webkit_glue::ResourceResponseInfo
)
83 IPC_STRUCT_TRAITS_MEMBER(error_code
)
84 IPC_STRUCT_TRAITS_MEMBER(request_start
)
85 IPC_STRUCT_TRAITS_MEMBER(response_start
)
86 IPC_STRUCT_TRAITS_END()
88 IPC_STRUCT_TRAITS_BEGIN(content::SyncLoadResult
)
89 IPC_STRUCT_TRAITS_PARENT(content::ResourceResponseHead
)
90 IPC_STRUCT_TRAITS_MEMBER(final_url
)
91 IPC_STRUCT_TRAITS_MEMBER(data
)
92 IPC_STRUCT_TRAITS_END()
94 IPC_STRUCT_TRAITS_BEGIN(webkit_glue::ResourceResponseInfo
)
95 IPC_STRUCT_TRAITS_MEMBER(request_time
)
96 IPC_STRUCT_TRAITS_MEMBER(response_time
)
97 IPC_STRUCT_TRAITS_MEMBER(headers
)
98 IPC_STRUCT_TRAITS_MEMBER(mime_type
)
99 IPC_STRUCT_TRAITS_MEMBER(charset
)
100 IPC_STRUCT_TRAITS_MEMBER(security_info
)
101 IPC_STRUCT_TRAITS_MEMBER(content_length
)
102 IPC_STRUCT_TRAITS_MEMBER(encoded_data_length
)
103 IPC_STRUCT_TRAITS_MEMBER(appcache_id
)
104 IPC_STRUCT_TRAITS_MEMBER(appcache_manifest_url
)
105 IPC_STRUCT_TRAITS_MEMBER(load_timing
)
106 IPC_STRUCT_TRAITS_MEMBER(devtools_info
)
107 IPC_STRUCT_TRAITS_MEMBER(download_file_path
)
108 IPC_STRUCT_TRAITS_MEMBER(was_fetched_via_spdy
)
109 IPC_STRUCT_TRAITS_MEMBER(was_npn_negotiated
)
110 IPC_STRUCT_TRAITS_MEMBER(was_alternate_protocol_available
)
111 IPC_STRUCT_TRAITS_MEMBER(was_fetched_via_proxy
)
112 IPC_STRUCT_TRAITS_MEMBER(npn_negotiated_protocol
)
113 IPC_STRUCT_TRAITS_MEMBER(socket_address
)
114 IPC_STRUCT_TRAITS_END()
116 // Parameters for a resource request.
117 IPC_STRUCT_BEGIN(ResourceHostMsg_Request
)
118 // The request method: GET, POST, etc.
119 IPC_STRUCT_MEMBER(std::string
, method
)
121 // The requested URL.
122 IPC_STRUCT_MEMBER(GURL
, url
)
124 // Usually the URL of the document in the top-level window, which may be
125 // checked by the third-party cookie blocking policy. Leaving it empty may
126 // lead to undesired cookie blocking. Third-party cookie blocking can be
127 // bypassed by setting first_party_for_cookies = url, but this should ideally
128 // only be done if there really is no way to determine the correct value.
129 IPC_STRUCT_MEMBER(GURL
, first_party_for_cookies
)
131 // The referrer to use (may be empty).
132 IPC_STRUCT_MEMBER(GURL
, referrer
)
134 // The referrer policy to use.
135 IPC_STRUCT_MEMBER(WebKit::WebReferrerPolicy
, referrer_policy
)
137 // Additional HTTP request headers.
138 IPC_STRUCT_MEMBER(std::string
, headers
)
140 // net::URLRequest load flags (0 by default).
141 IPC_STRUCT_MEMBER(int, load_flags
)
143 // Process ID from which this request originated, or zero if it originated
144 // in the renderer itself.
145 IPC_STRUCT_MEMBER(int, origin_pid
)
147 // What this resource load is for (main frame, sub-frame, sub-resource,
149 IPC_STRUCT_MEMBER(ResourceType::Type
, resource_type
)
151 // The priority of this request.
152 IPC_STRUCT_MEMBER(net::RequestPriority
, priority
)
154 // Used by plugin->browser requests to get the correct net::URLRequestContext.
155 IPC_STRUCT_MEMBER(uint32
, request_context
)
157 // Indicates which frame (or worker context) the request is being loaded into,
159 IPC_STRUCT_MEMBER(int, appcache_host_id
)
161 // Optional resource request body (may be null).
162 IPC_STRUCT_MEMBER(scoped_refptr
<webkit_glue::ResourceRequestBody
>,
165 IPC_STRUCT_MEMBER(bool, download_to_file
)
167 // True if the request was user initiated.
168 IPC_STRUCT_MEMBER(bool, has_user_gesture
)
170 // True if |frame_id| is the main frame of a RenderView.
171 IPC_STRUCT_MEMBER(bool, is_main_frame
)
173 // Identifies the frame within the RenderView that sent the request.
174 // -1 if unknown / invalid.
175 IPC_STRUCT_MEMBER(int64
, frame_id
)
177 // True if |parent_frame_id| is the main frame of a RenderView.
178 IPC_STRUCT_MEMBER(bool, parent_is_main_frame
)
180 // Identifies the parent frame of the frame that sent the request.
181 // -1 if unknown / invalid.
182 IPC_STRUCT_MEMBER(int64
, parent_frame_id
)
184 IPC_STRUCT_MEMBER(content::PageTransition
, transition_type
)
186 // The following two members identify a previous request that has been
187 // created before this navigation has been transferred to a new render view.
188 // This serves the purpose of recycling the old request.
189 // Unless this refers to a transferred navigation, these values are -1 and -1.
190 IPC_STRUCT_MEMBER(int, transferred_request_child_id
)
191 IPC_STRUCT_MEMBER(int, transferred_request_request_id
)
193 // Whether or not we should allow the URL to download.
194 IPC_STRUCT_MEMBER(bool, allow_download
)
197 // Resource messages sent from the browser to the renderer.
199 // Sent when the headers are available for a resource request.
200 IPC_MESSAGE_ROUTED2(ResourceMsg_ReceivedResponse
,
201 int /* request_id */,
202 content::ResourceResponseHead
)
204 // Sent when cached metadata from a resource request is ready.
205 IPC_MESSAGE_ROUTED2(ResourceMsg_ReceivedCachedMetadata
,
206 int /* request_id */,
207 std::vector
<char> /* data */)
209 // Sent as upload progress is being made.
210 IPC_MESSAGE_ROUTED3(ResourceMsg_UploadProgress
,
211 int /* request_id */,
212 int64
/* position */,
215 // Sent when the request has been redirected. The receiver is expected to
216 // respond with either a FollowRedirect message (if the redirect is to be
217 // followed) or a CancelRequest message (if it should not be followed).
218 IPC_MESSAGE_ROUTED3(ResourceMsg_ReceivedRedirect
,
219 int /* request_id */,
221 content::ResourceResponseHead
)
223 // Sent to set the shared memory buffer to be used to transmit response data to
224 // the renderer. Subsequent DataReceived messages refer to byte ranges in the
225 // shared memory buffer. The shared memory buffer should be retained by the
226 // renderer until the resource request completes.
228 // NOTE: The shared memory handle should already be mapped into the process
229 // that receives this message.
231 // TODO(darin): The |renderer_pid| parameter is just a temporary parameter,
232 // added to help in debugging crbug/160401.
234 IPC_MESSAGE_ROUTED4(ResourceMsg_SetDataBuffer
,
235 int /* request_id */,
236 base::SharedMemoryHandle
/* shm_handle */,
238 base::ProcessId
/* renderer_pid */)
240 // Sent when some data from a resource request is ready. The data offset and
241 // length specify a byte range into the shared memory buffer provided by the
242 // SetDataBuffer message.
243 IPC_MESSAGE_ROUTED4(ResourceMsg_DataReceived
,
244 int /* request_id */,
245 int /* data_offset */,
246 int /* data_length */,
247 int /* encoded_data_length */)
249 // Sent when some data from a resource request has been downloaded to
250 // file. This is only called in the 'download_to_file' case and replaces
251 // ResourceMsg_DataReceived in the call sequence in that case.
252 IPC_MESSAGE_ROUTED2(ResourceMsg_DataDownloaded
,
253 int /* request_id */,
256 // Sent when the request has been completed.
257 IPC_MESSAGE_ROUTED5(ResourceMsg_RequestComplete
,
258 int /* request_id */,
259 int /* error_code */,
260 bool /* was_ignored_by_handler */,
261 std::string
/* security info */,
262 base::TimeTicks
/* completion_time */)
264 // Resource messages sent from the renderer to the browser.
266 // Makes a resource request via the browser.
267 IPC_MESSAGE_ROUTED2(ResourceHostMsg_RequestResource
,
268 int /* request_id */,
269 ResourceHostMsg_Request
)
271 // Cancels a resource request with the ID given as the parameter.
272 IPC_MESSAGE_ROUTED1(ResourceHostMsg_CancelRequest
,
273 int /* request_id */)
275 // Follows a redirect that occured for the resource request with the ID given
277 IPC_MESSAGE_ROUTED3(ResourceHostMsg_FollowRedirect
,
278 int /* request_id */,
279 bool /* has_new_first_party_for_cookies */,
280 GURL
/* new_first_party_for_cookies */)
282 // Makes a synchronous resource request via the browser.
283 IPC_SYNC_MESSAGE_ROUTED2_1(ResourceHostMsg_SyncLoad
,
284 int /* request_id */,
285 ResourceHostMsg_Request
,
286 content::SyncLoadResult
)
288 // Sent when the renderer process is done processing a DataReceived
290 IPC_MESSAGE_ROUTED1(ResourceHostMsg_DataReceived_ACK
,
291 int /* request_id */)
293 // Sent when the renderer has processed a DataDownloaded message.
294 IPC_MESSAGE_ROUTED1(ResourceHostMsg_DataDownloaded_ACK
,
295 int /* request_id */)
297 // Sent by the renderer process to acknowledge receipt of a
298 // UploadProgress message.
299 IPC_MESSAGE_ROUTED1(ResourceHostMsg_UploadProgress_ACK
,
300 int /* request_id */)
302 // Sent when the renderer process deletes a resource loader.
303 IPC_MESSAGE_CONTROL1(ResourceHostMsg_ReleaseDownloadedFile
,
304 int /* request_id */)
306 // Sent by the renderer when a resource request changes priority.
307 IPC_MESSAGE_ROUTED2(ResourceHostMsg_DidChangePriority
,
308 int /* request_id */,
309 net::RequestPriority
)