Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: content/common/service_worker/service_worker_fetch_request_struct_traits.cc

Issue 2762303002: Enable transmitting Fetch Requests over Mojo (Closed)
Patch Set: Enable transmitting Fetch Requests over Mojo Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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 #include "content/common/service_worker/service_worker_fetch_request_struct_trai ts.h"
6
7 #include "base/logging.h"
8 #include "content/public/common/referrer_struct_traits.h"
9 #include "url/mojo/url_gurl_struct_traits.h"
10
11 namespace mojo {
12
13 using blink::mojom::FetchCredentialsMode;
14 using blink::mojom::FetchRedirectMode;
15 using blink::mojom::FetchRequestMode;
16 using blink::mojom::RequestContextFrameType;
17 using blink::mojom::RequestContextType;
18 using blink::mojom::ServiceWorkerFetchType;
19
20 FetchCredentialsMode
21 EnumTraits<FetchCredentialsMode, content::FetchCredentialsMode>::ToMojom(
22 content::FetchCredentialsMode input) {
23 switch (input) {
24 case content::FETCH_CREDENTIALS_MODE_OMIT:
25 return FetchCredentialsMode::OMIT;
26 case content::FETCH_CREDENTIALS_MODE_SAME_ORIGIN:
27 return FetchCredentialsMode::SAME_ORIGIN;
28 case content::FETCH_CREDENTIALS_MODE_INCLUDE:
29 return FetchCredentialsMode::INCLUDE;
30 case content::FETCH_CREDENTIALS_MODE_PASSWORD:
31 return FetchCredentialsMode::PASSWORD;
32 }
33
34 NOTREACHED();
35 return FetchCredentialsMode::OMIT;
36 }
37
38 bool EnumTraits<FetchCredentialsMode, content::FetchCredentialsMode>::FromMojom(
39 FetchCredentialsMode input,
40 content::FetchCredentialsMode* out) {
41 switch (input) {
42 case FetchCredentialsMode::OMIT:
43 *out = content::FETCH_CREDENTIALS_MODE_OMIT;
44 return true;
45 case FetchCredentialsMode::SAME_ORIGIN:
46 *out = content::FETCH_CREDENTIALS_MODE_SAME_ORIGIN;
47 return true;
48 case FetchCredentialsMode::INCLUDE:
49 *out = content::FETCH_CREDENTIALS_MODE_INCLUDE;
50 return true;
51 case FetchCredentialsMode::PASSWORD:
52 *out = content::FETCH_CREDENTIALS_MODE_PASSWORD;
53 return true;
54 }
55
56 return false;
57 }
58
59 FetchRedirectMode
60 EnumTraits<FetchRedirectMode, content::FetchRedirectMode>::ToMojom(
61 content::FetchRedirectMode input) {
62 switch (input) {
63 case content::FetchRedirectMode::FOLLOW_MODE:
64 return FetchRedirectMode::FOLLOW;
65 case content::FetchRedirectMode::ERROR_MODE:
66 return FetchRedirectMode::ERROR;
67 case content::FetchRedirectMode::MANUAL_MODE:
68 return FetchRedirectMode::MANUAL;
69 }
70
71 NOTREACHED();
72 return FetchRedirectMode::ERROR;
73 }
74
75 bool EnumTraits<FetchRedirectMode, content::FetchRedirectMode>::FromMojom(
76 FetchRedirectMode input,
77 content::FetchRedirectMode* out) {
78 switch (input) {
79 case FetchRedirectMode::FOLLOW:
80 *out = content::FetchRedirectMode::FOLLOW_MODE;
81 return true;
82 case FetchRedirectMode::ERROR:
83 *out = content::FetchRedirectMode::ERROR_MODE;
84 return true;
85 case FetchRedirectMode::MANUAL:
86 *out = content::FetchRedirectMode::MANUAL_MODE;
87 return true;
88 }
89
90 return false;
91 }
92
93 FetchRequestMode
94 EnumTraits<FetchRequestMode, content::FetchRequestMode>::ToMojom(
95 content::FetchRequestMode input) {
96 switch (input) {
97 case content::FETCH_REQUEST_MODE_SAME_ORIGIN:
98 return FetchRequestMode::SAME_ORIGIN;
99 case content::FETCH_REQUEST_MODE_NO_CORS:
100 return FetchRequestMode::NO_CORS;
101 case content::FETCH_REQUEST_MODE_CORS:
102 return FetchRequestMode::CORS;
103 case content::FETCH_REQUEST_MODE_CORS_WITH_FORCED_PREFLIGHT:
104 return FetchRequestMode::CORS_WITH_FORCED_PREFLIGHT;
105 case content::FETCH_REQUEST_MODE_NAVIGATE:
106 return FetchRequestMode::NAVIGATE;
107 }
108
109 NOTREACHED();
110 return FetchRequestMode::NO_CORS;
111 }
112
113 bool EnumTraits<FetchRequestMode, content::FetchRequestMode>::FromMojom(
114 FetchRequestMode input,
115 content::FetchRequestMode* out) {
116 switch (input) {
117 case FetchRequestMode::SAME_ORIGIN:
118 *out = content::FETCH_REQUEST_MODE_SAME_ORIGIN;
119 return true;
120 case FetchRequestMode::NO_CORS:
121 *out = content::FETCH_REQUEST_MODE_NO_CORS;
122 return true;
123 case FetchRequestMode::CORS:
124 *out = content::FETCH_REQUEST_MODE_CORS;
125 return true;
126 case FetchRequestMode::CORS_WITH_FORCED_PREFLIGHT:
127 *out = content::FETCH_REQUEST_MODE_CORS_WITH_FORCED_PREFLIGHT;
128 return true;
129 case FetchRequestMode::NAVIGATE:
130 *out = content::FETCH_REQUEST_MODE_NAVIGATE;
131 return true;
132 }
133
134 return false;
135 }
136
137 RequestContextFrameType
138 EnumTraits<RequestContextFrameType, content::RequestContextFrameType>::ToMojom(
139 content::RequestContextFrameType input) {
140 switch (input) {
141 case content::REQUEST_CONTEXT_FRAME_TYPE_AUXILIARY:
142 return RequestContextFrameType::AUXILIARY;
143 case content::REQUEST_CONTEXT_FRAME_TYPE_NESTED:
144 return RequestContextFrameType::NESTED;
145 case content::REQUEST_CONTEXT_FRAME_TYPE_NONE:
146 return RequestContextFrameType::NONE;
147 case content::REQUEST_CONTEXT_FRAME_TYPE_TOP_LEVEL:
148 return RequestContextFrameType::TOP_LEVEL;
149 }
150
151 NOTREACHED();
152 return RequestContextFrameType::NONE;
153 }
154
155 bool EnumTraits<RequestContextFrameType, content::RequestContextFrameType>::
156 FromMojom(RequestContextFrameType input,
157 content::RequestContextFrameType* out) {
158 switch (input) {
159 case RequestContextFrameType::AUXILIARY:
160 *out = content::REQUEST_CONTEXT_FRAME_TYPE_AUXILIARY;
161 return true;
162 case RequestContextFrameType::NESTED:
163 *out = content::REQUEST_CONTEXT_FRAME_TYPE_NESTED;
164 return true;
165 case RequestContextFrameType::NONE:
166 *out = content::REQUEST_CONTEXT_FRAME_TYPE_NONE;
167 return true;
168 case RequestContextFrameType::TOP_LEVEL:
169 *out = content::REQUEST_CONTEXT_FRAME_TYPE_TOP_LEVEL;
170 return true;
171 }
172
173 return false;
174 }
175
176 RequestContextType
177 EnumTraits<RequestContextType, content::RequestContextType>::ToMojom(
178 content::RequestContextType input) {
179 switch (input) {
180 case content::REQUEST_CONTEXT_TYPE_UNSPECIFIED:
181 return RequestContextType::UNSPECIFIED;
182 case content::REQUEST_CONTEXT_TYPE_AUDIO:
183 return RequestContextType::AUDIO;
184 case content::REQUEST_CONTEXT_TYPE_BEACON:
185 return RequestContextType::BEACON;
186 case content::REQUEST_CONTEXT_TYPE_CSP_REPORT:
187 return RequestContextType::CSP_REPORT;
188 case content::REQUEST_CONTEXT_TYPE_DOWNLOAD:
189 return RequestContextType::DOWNLOAD;
190 case content::REQUEST_CONTEXT_TYPE_EMBED:
191 return RequestContextType::EMBED;
192 case content::REQUEST_CONTEXT_TYPE_EVENT_SOURCE:
193 return RequestContextType::EVENT_SOURCE;
194 case content::REQUEST_CONTEXT_TYPE_FAVICON:
195 return RequestContextType::FAVICON;
196 case content::REQUEST_CONTEXT_TYPE_FETCH:
197 return RequestContextType::FETCH;
198 case content::REQUEST_CONTEXT_TYPE_FONT:
199 return RequestContextType::FONT;
200 case content::REQUEST_CONTEXT_TYPE_FORM:
201 return RequestContextType::FORM;
202 case content::REQUEST_CONTEXT_TYPE_FRAME:
203 return RequestContextType::FRAME;
204 case content::REQUEST_CONTEXT_TYPE_HYPERLINK:
205 return RequestContextType::HYPERLINK;
206 case content::REQUEST_CONTEXT_TYPE_IFRAME:
207 return RequestContextType::IFRAME;
208 case content::REQUEST_CONTEXT_TYPE_IMAGE:
209 return RequestContextType::IMAGE;
210 case content::REQUEST_CONTEXT_TYPE_IMAGE_SET:
211 return RequestContextType::IMAGE_SET;
212 case content::REQUEST_CONTEXT_TYPE_IMPORT:
213 return RequestContextType::IMPORT;
214 case content::REQUEST_CONTEXT_TYPE_INTERNAL:
215 return RequestContextType::INTERNAL;
216 case content::REQUEST_CONTEXT_TYPE_LOCATION:
217 return RequestContextType::LOCATION;
218 case content::REQUEST_CONTEXT_TYPE_MANIFEST:
219 return RequestContextType::MANIFEST;
220 case content::REQUEST_CONTEXT_TYPE_OBJECT:
221 return RequestContextType::OBJECT;
222 case content::REQUEST_CONTEXT_TYPE_PING:
223 return RequestContextType::PING;
224 case content::REQUEST_CONTEXT_TYPE_PLUGIN:
225 return RequestContextType::PLUGIN;
226 case content::REQUEST_CONTEXT_TYPE_PREFETCH:
227 return RequestContextType::PREFETCH;
228 case content::REQUEST_CONTEXT_TYPE_SCRIPT:
229 return RequestContextType::SCRIPT;
230 case content::REQUEST_CONTEXT_TYPE_SERVICE_WORKER:
231 return RequestContextType::SERVICE_WORKER;
232 case content::REQUEST_CONTEXT_TYPE_SHARED_WORKER:
233 return RequestContextType::SHARED_WORKER;
234 case content::REQUEST_CONTEXT_TYPE_SUBRESOURCE:
235 return RequestContextType::SUBRESOURCE;
236 case content::REQUEST_CONTEXT_TYPE_STYLE:
237 return RequestContextType::STYLE;
238 case content::REQUEST_CONTEXT_TYPE_TRACK:
239 return RequestContextType::TRACK;
240 case content::REQUEST_CONTEXT_TYPE_VIDEO:
241 return RequestContextType::VIDEO;
242 case content::REQUEST_CONTEXT_TYPE_WORKER:
243 return RequestContextType::WORKER;
244 case content::REQUEST_CONTEXT_TYPE_XML_HTTP_REQUEST:
245 return RequestContextType::XML_HTTP_REQUEST;
246 case content::REQUEST_CONTEXT_TYPE_XSLT:
247 return RequestContextType::XSLT;
248 }
249
250 NOTREACHED();
251 return RequestContextType::UNSPECIFIED;
252 }
253
254 bool EnumTraits<RequestContextType, content::RequestContextType>::FromMojom(
255 RequestContextType input,
256 content::RequestContextType* out) {
257 switch (input) {
258 case RequestContextType::UNSPECIFIED:
259 *out = content::REQUEST_CONTEXT_TYPE_UNSPECIFIED;
260 return true;
261 case RequestContextType::AUDIO:
262 *out = content::REQUEST_CONTEXT_TYPE_AUDIO;
263 return true;
264 case RequestContextType::BEACON:
265 *out = content::REQUEST_CONTEXT_TYPE_BEACON;
266 return true;
267 case RequestContextType::CSP_REPORT:
268 *out = content::REQUEST_CONTEXT_TYPE_CSP_REPORT;
269 return true;
270 case RequestContextType::DOWNLOAD:
271 *out = content::REQUEST_CONTEXT_TYPE_DOWNLOAD;
272 return true;
273 case RequestContextType::EMBED:
274 *out = content::REQUEST_CONTEXT_TYPE_EMBED;
275 return true;
276 case RequestContextType::EVENT_SOURCE:
277 *out = content::REQUEST_CONTEXT_TYPE_EVENT_SOURCE;
278 return true;
279 case RequestContextType::FAVICON:
280 *out = content::REQUEST_CONTEXT_TYPE_FAVICON;
281 return true;
282 case RequestContextType::FETCH:
283 *out = content::REQUEST_CONTEXT_TYPE_FETCH;
284 return true;
285 case RequestContextType::FONT:
286 *out = content::REQUEST_CONTEXT_TYPE_FONT;
287 return true;
288 case RequestContextType::FORM:
289 *out = content::REQUEST_CONTEXT_TYPE_FORM;
290 return true;
291 case RequestContextType::FRAME:
292 *out = content::REQUEST_CONTEXT_TYPE_FRAME;
293 return true;
294 case RequestContextType::HYPERLINK:
295 *out = content::REQUEST_CONTEXT_TYPE_HYPERLINK;
296 return true;
297 case RequestContextType::IFRAME:
298 *out = content::REQUEST_CONTEXT_TYPE_IFRAME;
299 return true;
300 case RequestContextType::IMAGE:
301 *out = content::REQUEST_CONTEXT_TYPE_IMAGE;
302 return true;
303 case RequestContextType::IMAGE_SET:
304 *out = content::REQUEST_CONTEXT_TYPE_IMAGE_SET;
305 return true;
306 case RequestContextType::IMPORT:
307 *out = content::REQUEST_CONTEXT_TYPE_IMPORT;
308 return true;
309 case RequestContextType::INTERNAL:
310 *out = content::REQUEST_CONTEXT_TYPE_INTERNAL;
311 return true;
312 case RequestContextType::LOCATION:
313 *out = content::REQUEST_CONTEXT_TYPE_LOCATION;
314 return true;
315 case RequestContextType::MANIFEST:
316 *out = content::REQUEST_CONTEXT_TYPE_MANIFEST;
317 return true;
318 case RequestContextType::OBJECT:
319 *out = content::REQUEST_CONTEXT_TYPE_OBJECT;
320 return true;
321 case RequestContextType::PING:
322 *out = content::REQUEST_CONTEXT_TYPE_PING;
323 return true;
324 case RequestContextType::PLUGIN:
325 *out = content::REQUEST_CONTEXT_TYPE_PLUGIN;
326 return true;
327 case RequestContextType::PREFETCH:
328 *out = content::REQUEST_CONTEXT_TYPE_PREFETCH;
329 return true;
330 case RequestContextType::SCRIPT:
331 *out = content::REQUEST_CONTEXT_TYPE_SCRIPT;
332 return true;
333 case RequestContextType::SERVICE_WORKER:
334 *out = content::REQUEST_CONTEXT_TYPE_SERVICE_WORKER;
335 return true;
336 case RequestContextType::SHARED_WORKER:
337 *out = content::REQUEST_CONTEXT_TYPE_SHARED_WORKER;
338 return true;
339 case RequestContextType::SUBRESOURCE:
340 *out = content::REQUEST_CONTEXT_TYPE_SUBRESOURCE;
341 return true;
342 case RequestContextType::STYLE:
343 *out = content::REQUEST_CONTEXT_TYPE_STYLE;
344 return true;
345 case RequestContextType::TRACK:
346 *out = content::REQUEST_CONTEXT_TYPE_TRACK;
347 return true;
348 case RequestContextType::VIDEO:
349 *out = content::REQUEST_CONTEXT_TYPE_VIDEO;
350 return true;
351 case RequestContextType::WORKER:
352 *out = content::REQUEST_CONTEXT_TYPE_WORKER;
353 return true;
354 case RequestContextType::XML_HTTP_REQUEST:
355 *out = content::REQUEST_CONTEXT_TYPE_XML_HTTP_REQUEST;
356 return true;
357 case RequestContextType::XSLT:
358 *out = content::REQUEST_CONTEXT_TYPE_XSLT;
359 return true;
360 }
361
362 return false;
363 }
364
365 ServiceWorkerFetchType
366 EnumTraits<ServiceWorkerFetchType, content::ServiceWorkerFetchType>::ToMojom(
367 content::ServiceWorkerFetchType input) {
368 switch (input) {
369 case content::ServiceWorkerFetchType::FETCH:
370 return ServiceWorkerFetchType::FETCH;
371 case content::ServiceWorkerFetchType::FOREIGN_FETCH:
372 return ServiceWorkerFetchType::FOREIGN_FETCH;
373 }
374
375 NOTREACHED();
376 return ServiceWorkerFetchType::FETCH;
377 }
378
379 bool EnumTraits<ServiceWorkerFetchType, content::ServiceWorkerFetchType>::
380 FromMojom(ServiceWorkerFetchType input,
381 content::ServiceWorkerFetchType* out) {
382 switch (input) {
383 case ServiceWorkerFetchType::FETCH:
384 *out = content::ServiceWorkerFetchType::FETCH;
385 return true;
386 case ServiceWorkerFetchType::FOREIGN_FETCH:
387 *out = content::ServiceWorkerFetchType::FOREIGN_FETCH;
388 return true;
389 }
390
391 return false;
392 }
393
394 std::map<std::string, std::string>
395 StructTraits<blink::mojom::FetchAPIRequestDataView,
396 content::ServiceWorkerFetchRequest>::
397 headers(const content::ServiceWorkerFetchRequest& request) {
398 return std::map<std::string, std::string>();
dcheng 2017/03/24 05:27:47 Is this something we expect to eventually implemen
Peter Beverloo 2017/03/24 18:48:42 We actually need it as part of this CL, so yes. Th
Peter Beverloo 2017/03/24 18:48:42 Regarding performance, that's really unfortunate.
399 }
400
401 bool StructTraits<blink::mojom::FetchAPIRequestDataView,
402 content::ServiceWorkerFetchRequest>::
403 Read(blink::mojom::FetchAPIRequestDataView data,
404 content::ServiceWorkerFetchRequest* out) {
405 std::unordered_map<std::string, std::string> headers;
406 base::Optional<std::string> blob_uuid;
407 if (!data.ReadMode(&out->mode) ||
408 !data.ReadRequestContextType(&out->request_context_type) ||
409 !data.ReadFrameType(&out->frame_type) || !data.ReadUrl(&out->url) ||
410 !data.ReadMethod(&out->method) || !data.ReadHeaders(&headers) ||
411 !data.ReadBlobUuid(&blob_uuid) || !data.ReadReferrer(&out->referrer) ||
412 !data.ReadCredentialsMode(&out->credentials_mode) ||
413 !data.ReadRedirectMode(&out->redirect_mode) ||
414 !data.ReadClientId(&out->client_id) ||
415 !data.ReadFetchType(&out->fetch_type)) {
416 return false;
417 }
418
419 out->is_main_resource_load = data.is_main_resource_load();
420 for (const auto& pair : headers)
421 out->headers.insert(pair);
422 if (blob_uuid) {
423 out->blob_uuid = blob_uuid.value();
424 out->blob_size = data.blob_size();
425 }
426 out->is_reload = data.is_reload();
427 return true;
428 }
429
430 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698