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" | |
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>& r) | |
16 { | |
17 return r->protocol(); | |
18 } | |
19 static WTF::String host(const RefPtr<::blink::SecurityOrigin>& r) | |
20 { | |
21 return r->host(); | |
22 } | |
23 static uint16_t port(const RefPtr<::blink::SecurityOrigin>& r) | |
24 { | |
25 return r->port(); | |
26 } | |
27 static bool unique(const RefPtr<::blink::SecurityOrigin>& r) | |
28 { | |
29 return r->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, host; | |
37 if (!data.ReadScheme(&scheme) || !data.ReadHost(&host)) | |
38 return false; | |
39 | |
40 *out = ::blink::SecurityOrigin::create(scheme, host, data.port()); | |
41 } | |
42 | |
43 // If a unique origin was created, but the unique flag wasn't set, then | |
44 // the values provided to 'UnsafelyCreateOriginWithoutNormalization' wer e | |
yzshen1
2016/05/25 16:43:15
Is this comment up to date? I didn't see 'Unsafely
Marijn Kruisselbrink
2016/05/25 16:55:21
Fixed
| |
45 // invalid. | |
46 if (!data.unique() && (*out)->isUnique()) | |
47 return false; | |
48 | |
49 return true; | |
50 } | |
51 }; | |
52 } | |
53 | |
54 #endif // SecurityOriginStructTraits_h | |
OLD | NEW |