Chromium Code Reviews| Index: content/public/common/manifest_struct_traits.h |
| diff --git a/content/public/common/manifest_struct_traits.h b/content/public/common/manifest_struct_traits.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d048df6ffbac043b84a5d932628d467f4601a736 |
| --- /dev/null |
| +++ b/content/public/common/manifest_struct_traits.h |
| @@ -0,0 +1,98 @@ |
| +// 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 CONTENT_PUBLIC_COMMON_MANIFEST_STRUCT_TRAITS_H_ |
| +#define CONTENT_PUBLIC_COMMON_MANIFEST_STRUCT_TRAITS_H_ |
| + |
| +#include "content/public/common/manifest.h" |
| +#include "mojo/public/cpp/bindings/string_traits_nullable_string16.h" |
| +#include "third_party/WebKit/public/platform/modules/manifest/manifest.mojom.h" |
| +#include "url/gurl.h" |
| +#include "url/mojo/url_gurl_struct_traits.h" |
| + |
| +namespace mojo { |
| + |
| +template <> |
| +struct StructTraits<blink::mojom::Manifest, content::Manifest> { |
| + static base::NullableString16 name(const content::Manifest& m); |
| + static base::NullableString16 short_name(const content::Manifest& m); |
| + static base::NullableString16 gcm_sender_id(const content::Manifest& m); |
| + |
| + static const GURL& start_url(const content::Manifest& m) { |
| + return m.start_url; |
| + } |
| + |
| + static blink::WebDisplayMode display(const content::Manifest& m) { |
| + return m.display; |
| + } |
| + |
| + static blink::WebScreenOrientationLockType orientation( |
| + const content::Manifest& m) { |
| + return m.orientation; |
| + } |
| + |
| + static int64_t theme_color(const content::Manifest& m) { |
| + if (m.theme_color < std::numeric_limits<int32_t>::min() || |
| + m.theme_color > std::numeric_limits<int32_t>::max()) { |
| + return content::Manifest::kInvalidOrMissingColor; |
|
dcheng
2016/06/01 23:38:42
Why do we need to do this check? From the comments
Sam McNally
2016/06/02 07:02:40
Done.
|
| + } |
| + return m.theme_color; |
| + } |
| + |
| + static int64_t background_color(const content::Manifest& m) { |
| + if (m.background_color < std::numeric_limits<int32_t>::min() || |
| + m.background_color > std::numeric_limits<int32_t>::max()) { |
| + return content::Manifest::kInvalidOrMissingColor; |
| + } |
| + return m.background_color; |
| + } |
| + |
| + static const std::vector<content::Manifest::Icon>& icons( |
| + const content::Manifest& m) { |
| + return m.icons; |
| + } |
| + |
| + static const std::vector<content::Manifest::RelatedApplication>& |
| + related_applications(const content::Manifest& m) { |
| + return m.related_applications; |
| + } |
| + |
| + static bool prefer_related_applications(const content::Manifest& m) { |
| + return m.prefer_related_applications; |
| + } |
| + |
| + static bool Read(blink::mojom::ManifestDataView data, content::Manifest* out); |
| +}; |
| + |
| +template <> |
| +struct StructTraits<blink::mojom::ManifestIcon, content::Manifest::Icon> { |
| + static const GURL& src(const content::Manifest::Icon& m) { return m.src; } |
| + |
| + static base::NullableString16 type(const content::Manifest::Icon& m); |
| + static mojo::Array<mojo::SizePtr> sizes(const content::Manifest::Icon& m); |
| + |
| + static bool Read(blink::mojom::ManifestIconDataView data, |
| + content::Manifest::Icon* out); |
| +}; |
| + |
| +template <> |
| +struct StructTraits<blink::mojom::RelatedApplication, |
| + content::Manifest::RelatedApplication> { |
| + static base::NullableString16 platform( |
| + const content::Manifest::RelatedApplication& m); |
| + |
| + static const GURL& url(const content::Manifest::RelatedApplication& m) { |
| + return m.url; |
| + } |
| + |
| + static base::NullableString16 id( |
| + const content::Manifest::RelatedApplication& m); |
| + |
| + static bool Read(blink::mojom::RelatedApplicationDataView data, |
| + content::Manifest::RelatedApplication* out); |
| +}; |
| + |
| +} // namespace mojo |
| + |
| +#endif // CONTENT_PUBLIC_COMMON_MANIFEST_STRUCT_TRAITS_H_ |