Chromium Code Reviews| Index: third_party/WebKit/Source/platform/mojo/SecurityOriginStructTraits.h |
| diff --git a/third_party/WebKit/Source/platform/mojo/SecurityOriginStructTraits.h b/third_party/WebKit/Source/platform/mojo/SecurityOriginStructTraits.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..26a8015ccbf39a6532ea470598074ff1a858219e |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/platform/mojo/SecurityOriginStructTraits.h |
| @@ -0,0 +1,54 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef SecurityOriginStructTraits_h |
| +#define SecurityOriginStructTraits_h |
| + |
| +#include "platform/weborigin/SecurityOrigin.h" |
| +#include "url/mojo/origin.mojom-blink.h" |
| + |
| +namespace mojo { |
| + |
| +template <> |
| +struct StructTraits<url::mojom::blink::Origin, RefPtr<::blink::SecurityOrigin>> { |
| + static WTF::String scheme(const RefPtr<::blink::SecurityOrigin>& r) |
| + { |
| + return r->protocol(); |
| + } |
| + static WTF::String host(const RefPtr<::blink::SecurityOrigin>& r) |
| + { |
| + return r->host(); |
| + } |
| + static uint16_t port(const RefPtr<::blink::SecurityOrigin>& r) |
| + { |
| + return r->port(); |
| + } |
| + static bool unique(const RefPtr<::blink::SecurityOrigin>& r) |
| + { |
| + return r->isUnique(); |
| + } |
| + static bool Read(url::mojom::blink::OriginDataView data, RefPtr<::blink::SecurityOrigin>* out) |
| + { |
| + if (data.unique()) { |
| + *out = ::blink::SecurityOrigin::createUnique(); |
| + } else { |
| + WTF::String scheme, host; |
| + if (!data.ReadScheme(&scheme) || !data.ReadHost(&host)) |
| + return false; |
| + |
| + *out = ::blink::SecurityOrigin::create(scheme, host, data.port()); |
| + } |
| + |
| + // If a unique origin was created, but the unique flag wasn't set, then |
| + // the values provided to 'UnsafelyCreateOriginWithoutNormalization' were |
|
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
|
| + // invalid. |
| + if (!data.unique() && (*out)->isUnique()) |
| + return false; |
| + |
| + return true; |
| + } |
| +}; |
| +} |
| + |
| +#endif // SecurityOriginStructTraits_h |