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 SecurityOriginStructTraits_h | 5 #ifndef SecurityOriginStructTraits_h |
6 #define SecurityOriginStructTraits_h | 6 #define SecurityOriginStructTraits_h |
7 | 7 |
8 #include "platform/weborigin/SecurityOrigin.h" | 8 #include "platform/weborigin/SecurityOrigin.h" |
9 #include "url/mojo/origin.mojom-blink.h" | 9 #include "url/mojo/origin.mojom-blink.h" |
10 #include "wtf/text/WTFString.h" | 10 #include "wtf/text/WTFString.h" |
11 | 11 |
12 namespace mojo { | 12 namespace mojo { |
13 | 13 |
14 template <> | 14 template <> |
15 struct StructTraits<url::mojom::blink::Origin::DataView, | 15 struct StructTraits<url::mojom::blink::Origin::DataView, |
16 RefPtr<::blink::SecurityOrigin>> { | 16 RefPtr<::blink::SecurityOrigin>> { |
17 static WTF::String scheme(const RefPtr<::blink::SecurityOrigin>& origin) { | 17 static WTF::String scheme(const RefPtr<::blink::SecurityOrigin>& origin) { |
18 return origin->protocol(); | 18 return origin->protocol(); |
19 } | 19 } |
20 static WTF::String host(const RefPtr<::blink::SecurityOrigin>& origin) { | 20 static WTF::String host(const RefPtr<::blink::SecurityOrigin>& origin) { |
21 return origin->host(); | 21 return origin->host(); |
22 } | 22 } |
23 static uint16_t port(const RefPtr<::blink::SecurityOrigin>& origin) { | 23 static uint16_t port(const RefPtr<::blink::SecurityOrigin>& origin) { |
24 return origin->effectivePort(); | 24 return origin->effectivePort(); |
25 } | 25 } |
26 static bool unique(const RefPtr<::blink::SecurityOrigin>& origin) { | 26 static bool opaque(const RefPtr<::blink::SecurityOrigin>& origin) { |
27 return origin->isUnique(); | 27 return origin->isUnique(); |
28 } | 28 } |
29 static bool Read(url::mojom::blink::Origin::DataView data, | 29 static bool Read(url::mojom::blink::Origin::DataView data, |
30 RefPtr<::blink::SecurityOrigin>* out) { | 30 RefPtr<::blink::SecurityOrigin>* out) { |
31 if (data.unique()) { | 31 if (data.opaque()) { |
32 *out = ::blink::SecurityOrigin::createUnique(); | 32 *out = ::blink::SecurityOrigin::createUnique(); |
33 } else { | 33 } else { |
34 WTF::String scheme; | 34 WTF::String scheme; |
35 WTF::String host; | 35 WTF::String host; |
36 if (!data.ReadScheme(&scheme) || !data.ReadHost(&host)) | 36 if (!data.ReadScheme(&scheme) || !data.ReadHost(&host)) |
37 return false; | 37 return false; |
38 | 38 |
39 *out = ::blink::SecurityOrigin::create(scheme, host, data.port()); | 39 *out = ::blink::SecurityOrigin::create(scheme, host, data.port()); |
40 } | 40 } |
41 | 41 |
42 // If a unique origin was created, but the unique flag wasn't set, then | 42 // If a unique origin was created, but the opaque flag wasn't set, then |
43 // the values provided to 'create' were invalid. | 43 // the values provided to 'create' were invalid. |
44 if (!data.unique() && (*out)->isUnique()) | 44 if (!data.opaque() && (*out)->isUnique()) |
45 return false; | 45 return false; |
46 | 46 |
47 return true; | 47 return true; |
48 } | 48 } |
49 }; | 49 }; |
50 } | 50 } |
51 | 51 |
52 #endif // SecurityOriginStructTraits_h | 52 #endif // SecurityOriginStructTraits_h |
OLD | NEW |