OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef URL_MOJO_ORIGIN_STRUCT_TRAITS_H_ | 5 #ifndef URL_MOJO_ORIGIN_STRUCT_TRAITS_H_ |
6 #define URL_MOJO_ORIGIN_STRUCT_TRAITS_H_ | 6 #define URL_MOJO_ORIGIN_STRUCT_TRAITS_H_ |
7 | 7 |
8 #include "base/strings/string_piece.h" | 8 #include "base/strings/string_piece.h" |
9 #include "url/mojo/origin.mojom.h" | 9 #include "url/mojo/origin.mojom.h" |
10 #include "url/origin.h" | 10 #include "url/origin.h" |
11 | 11 |
12 namespace mojo { | 12 namespace mojo { |
13 | 13 |
14 template <> | 14 template <> |
15 struct StructTraits<url::mojom::Origin, url::Origin> { | 15 struct StructTraits<url::mojom::Origin, url::Origin> { |
16 static base::StringPiece scheme(const url::Origin& r) { | 16 static base::StringPiece scheme(const url::Origin& r) { |
17 return base::StringPiece(r.scheme()); | 17 return base::StringPiece(r.scheme()); |
18 } | 18 } |
19 static base::StringPiece host(const url::Origin& r) { | 19 static base::StringPiece host(const url::Origin& r) { |
20 return base::StringPiece(r.host()); | 20 return base::StringPiece(r.host()); |
21 } | 21 } |
22 static uint16_t port(const url::Origin& r) { | 22 static uint16_t port(const url::Origin& r) { |
23 return r.port(); | 23 return r.port(); |
24 } | 24 } |
25 static bool unique(const url::Origin& r) { | 25 static bool unique(const url::Origin& r) { |
26 return r.unique(); | 26 return r.unique(); |
27 } | 27 } |
28 static bool Read(url::mojom::Origin::Reader r, url::Origin* out) { | 28 static bool Read(url::mojom::OriginDataView data, url::Origin* out) { |
29 *out = r.unique() ? url::Origin() | 29 if (data.is_null()) { |
dcheng
2016/05/11 18:04:22
Why/when would data be null? Why do we consider th
yzshen1
2016/05/11 18:18:25
Imagine we have a mojo interface like this:
inter
| |
30 : url::Origin::UnsafelyCreateOriginWithoutNormalization( | 30 *out = url::Origin(); |
31 r.scheme(), r.host(), r.port()); | 31 return true; |
32 } | |
33 | |
34 if (data.unique()) { | |
35 *out = url::Origin(); | |
36 } else { | |
37 base::StringPiece scheme, host; | |
38 if (!data.ReadScheme(&scheme) || !data.ReadHost(&host)) | |
39 return false; | |
40 | |
41 *out = url::Origin::UnsafelyCreateOriginWithoutNormalization(scheme, host, | |
42 data.port()); | |
43 } | |
32 | 44 |
33 // If a unique origin was created, but the unique flag wasn't set, then | 45 // If a unique origin was created, but the unique flag wasn't set, then |
34 // the values provided to 'UnsafelyCreateOriginWithoutNormalization' were | 46 // the values provided to 'UnsafelyCreateOriginWithoutNormalization' were |
35 // invalid. | 47 // invalid. |
36 if (!r.unique() && out->unique()) | 48 if (!data.unique() && out->unique()) |
37 return false; | 49 return false; |
38 | 50 |
39 return true; | 51 return true; |
40 } | 52 } |
41 }; | 53 }; |
42 | 54 |
43 } | 55 } |
44 | 56 |
45 #endif // URL_MOJO_ORIGIN_STRUCT_TRAITS_H_ | 57 #endif // URL_MOJO_ORIGIN_STRUCT_TRAITS_H_ |
OLD | NEW |