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 "platform/wtf/text/WTFString.h" | 9 #include "platform/wtf/text/WTFString.h" |
10 #include "url/mojo/origin.mojom-blink.h" | 10 #include "url/mojo/origin.mojom-blink.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 WTF::String suborigin(const RefPtr<::blink::SecurityOrigin>& origin) { | 26 static WTF::String suborigin(const RefPtr<::blink::SecurityOrigin>& origin) { |
27 WTF::String suborigin = origin->GetSuborigin()->GetName(); | 27 WTF::String suborigin = origin->GetSuborigin()->GetName(); |
28 return suborigin.IsNull() ? "" : suborigin; | 28 return suborigin.IsNull() ? "" : suborigin; |
29 } | 29 } |
30 static bool unique(const RefPtr<::blink::SecurityOrigin>& origin) { | 30 static bool opaque(const RefPtr<::blink::SecurityOrigin>& origin) { |
31 return origin->IsUnique(); | 31 return origin->IsUnique(); |
32 } | 32 } |
33 static bool Read(url::mojom::blink::Origin::DataView data, | 33 static bool Read(url::mojom::blink::Origin::DataView data, |
34 RefPtr<::blink::SecurityOrigin>* out) { | 34 RefPtr<::blink::SecurityOrigin>* out) { |
35 if (data.unique()) { | 35 if (data.opaque()) { |
36 *out = ::blink::SecurityOrigin::CreateUnique(); | 36 *out = ::blink::SecurityOrigin::CreateUnique(); |
37 } else { | 37 } else { |
38 WTF::String scheme; | 38 WTF::String scheme; |
39 WTF::String host; | 39 WTF::String host; |
40 WTF::String suborigin; | 40 WTF::String suborigin; |
41 if (!data.ReadScheme(&scheme) || !data.ReadHost(&host) || | 41 if (!data.ReadScheme(&scheme) || !data.ReadHost(&host) || |
42 !data.ReadSuborigin(&suborigin)) | 42 !data.ReadSuborigin(&suborigin)) |
43 return false; | 43 return false; |
44 | 44 |
45 *out = | 45 *out = |
46 ::blink::SecurityOrigin::Create(scheme, host, data.port(), suborigin); | 46 ::blink::SecurityOrigin::Create(scheme, host, data.port(), suborigin); |
47 } | 47 } |
48 | 48 |
49 // If a unique origin was created, but the unique flag wasn't set, then | 49 // If a unique origin was created, but the opaque flag wasn't set, then |
50 // the values provided to 'create' were invalid. | 50 // the values provided to 'create' were invalid. |
51 if (!data.unique() && (*out)->IsUnique()) | 51 if (!data.opaque() && (*out)->IsUnique()) |
52 return false; | 52 return false; |
53 | 53 |
54 return true; | 54 return true; |
55 } | 55 } |
56 }; | 56 }; |
57 } | 57 } |
58 | 58 |
59 #endif // SecurityOriginStructTraits_h | 59 #endif // SecurityOriginStructTraits_h |
OLD | NEW |