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