| 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, RefPtr<::blink::SecurityOrigin>>
{ | 15 struct StructTraits<url::mojom::blink::Origin::DataView, RefPtr<::blink::Securit
yOrigin>> { |
| 16 static WTF::String scheme(const RefPtr<::blink::SecurityOrigin>& origin) | 16 static WTF::String scheme(const RefPtr<::blink::SecurityOrigin>& origin) |
| 17 { | 17 { |
| 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 { | 21 { |
| 22 return origin->host(); | 22 return origin->host(); |
| 23 } | 23 } |
| 24 static uint16_t port(const RefPtr<::blink::SecurityOrigin>& origin) | 24 static uint16_t port(const RefPtr<::blink::SecurityOrigin>& origin) |
| 25 { | 25 { |
| 26 return origin->effectivePort(); | 26 return origin->effectivePort(); |
| 27 } | 27 } |
| 28 static bool unique(const RefPtr<::blink::SecurityOrigin>& origin) | 28 static bool unique(const RefPtr<::blink::SecurityOrigin>& origin) |
| 29 { | 29 { |
| 30 return origin->isUnique(); | 30 return origin->isUnique(); |
| 31 } | 31 } |
| 32 static bool Read(url::mojom::blink::OriginDataView data, RefPtr<::blink::Sec
urityOrigin>* out) | 32 static bool Read(url::mojom::blink::Origin::DataView data, RefPtr<::blink::S
ecurityOrigin>* out) |
| 33 { | 33 { |
| 34 if (data.unique()) { | 34 if (data.unique()) { |
| 35 *out = ::blink::SecurityOrigin::createUnique(); | 35 *out = ::blink::SecurityOrigin::createUnique(); |
| 36 } else { | 36 } else { |
| 37 WTF::String scheme; | 37 WTF::String scheme; |
| 38 WTF::String host; | 38 WTF::String host; |
| 39 if (!data.ReadScheme(&scheme) || !data.ReadHost(&host)) | 39 if (!data.ReadScheme(&scheme) || !data.ReadHost(&host)) |
| 40 return false; | 40 return false; |
| 41 | 41 |
| 42 *out = ::blink::SecurityOrigin::create(scheme, host, data.port()); | 42 *out = ::blink::SecurityOrigin::create(scheme, host, data.port()); |
| 43 } | 43 } |
| 44 | 44 |
| 45 // 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 |
| 46 // the values provided to 'create' were invalid. | 46 // the values provided to 'create' were invalid. |
| 47 if (!data.unique() && (*out)->isUnique()) | 47 if (!data.unique() && (*out)->isUnique()) |
| 48 return false; | 48 return false; |
| 49 | 49 |
| 50 return true; | 50 return true; |
| 51 } | 51 } |
| 52 }; | 52 }; |
| 53 } | 53 } |
| 54 | 54 |
| 55 #endif // SecurityOriginStructTraits_h | 55 #endif // SecurityOriginStructTraits_h |
| OLD | NEW |