Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Unified Diff: third_party/WebKit/Source/platform/mojo/SecurityOriginStructTraits.h

Issue 2000253006: Implement URL and Origin typemaps/struct traits for blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: try to fix gyp rules Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..b632da4fc95e53259ebba2ff8259e52505847c77
--- /dev/null
+++ b/third_party/WebKit/Source/platform/mojo/SecurityOriginStructTraits.h
@@ -0,0 +1,55 @@
+// 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"
+#include "wtf/text/WTFString.h"
+
+namespace mojo {
+
+template <>
+struct StructTraits<url::mojom::blink::Origin, RefPtr<::blink::SecurityOrigin>> {
+ static WTF::String scheme(const RefPtr<::blink::SecurityOrigin>& origin)
+ {
+ return origin->protocol();
+ }
+ static WTF::String host(const RefPtr<::blink::SecurityOrigin>& origin)
+ {
+ return origin->host();
+ }
+ static uint16_t port(const RefPtr<::blink::SecurityOrigin>& origin)
+ {
+ return origin->port();
+ }
+ static bool unique(const RefPtr<::blink::SecurityOrigin>& origin)
+ {
+ return origin->isUnique();
+ }
+ static bool Read(url::mojom::blink::OriginDataView data, RefPtr<::blink::SecurityOrigin>* out)
+ {
+ if (data.unique()) {
+ *out = ::blink::SecurityOrigin::createUnique();
+ } else {
+ WTF::String scheme;
+ WTF::String 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 'create' were invalid.
+ if (!data.unique() && (*out)->isUnique())
+ return false;
+
+ return true;
+ }
+};
+}
+
+#endif // SecurityOriginStructTraits_h

Powered by Google App Engine
This is Rietveld 408576698