| Index: content/common/manifest_type_converters.cc
|
| diff --git a/content/common/manifest_type_converters.cc b/content/common/manifest_type_converters.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1f51f6966c22b919e3ca742f3c2c8a64497541de
|
| --- /dev/null
|
| +++ b/content/common/manifest_type_converters.cc
|
| @@ -0,0 +1,138 @@
|
| +// 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.
|
| +
|
| +#include "content/common/manifest_type_converters.h"
|
| +
|
| +#include <limits>
|
| +#include <string>
|
| +
|
| +#include "mojo/common/common_type_converters.h"
|
| +#include "mojo/converters/geometry/geometry_type_converters.h"
|
| +#include "third_party/WebKit/public/platform/WebDisplayMode.h"
|
| +#include "third_party/WebKit/public/platform/modules/screen_orientation/WebScreenOrientationLockType.h"
|
| +#include "ui/gfx/geometry/size.h"
|
| +#include "url/gurl.h"
|
| +
|
| +namespace mojo {
|
| +
|
| +mojo::String TypeConverter<mojo::String, base::NullableString16>::Convert(
|
| + const base::NullableString16& input) {
|
| + if (input.is_null())
|
| + return mojo::String(nullptr);
|
| +
|
| + return mojo::String::From(
|
| + input.string().substr(0, content::Manifest::kMaxIPCStringLength));
|
| +}
|
| +
|
| +base::NullableString16
|
| +TypeConverter<base::NullableString16, mojo::String>::Convert(
|
| + mojo::String input) {
|
| + if (input.is_null())
|
| + return base::NullableString16();
|
| +
|
| + return base::NullableString16(input.To<base::string16>().substr(
|
| + 0, content::Manifest::kMaxIPCStringLength),
|
| + false);
|
| +}
|
| +
|
| +blink::mojom::ManifestPtr
|
| +TypeConverter<blink::mojom::ManifestPtr, content::Manifest>::Convert(
|
| + const content::Manifest& input) {
|
| + if (input.IsEmpty())
|
| + return nullptr;
|
| +
|
| + blink::mojom::ManifestPtr output = blink::mojom::Manifest::New();
|
| + output->name = mojo::String::From(input.name);
|
| + output->short_name = mojo::String::From(input.short_name);
|
| + output->start_url = input.start_url;
|
| + output->display = static_cast<blink::mojom::DisplayMode>(input.display);
|
| + output->orientation =
|
| + static_cast<blink::mojom::ScreenOrientationLockType>(input.orientation);
|
| + output->icons = decltype(output->icons)::From(input.icons);
|
| + output->related_applications =
|
| + decltype(output->related_applications)::From(input.related_applications);
|
| + output->prefer_related_applications = input.prefer_related_applications;
|
| + output->theme_color = input.theme_color;
|
| + output->background_color = input.background_color;
|
| + output->gcm_sender_id = mojo::String::From(input.gcm_sender_id);
|
| + return output;
|
| +}
|
| +
|
| +content::Manifest
|
| +TypeConverter<content::Manifest, blink::mojom::ManifestPtr>::Convert(
|
| + const blink::mojom::ManifestPtr& input) {
|
| + content::Manifest output;
|
| + if (!input)
|
| + return output;
|
| +
|
| + output.name = input->name.To<base::NullableString16>();
|
| + output.short_name = input->short_name.To<base::NullableString16>();
|
| + output.start_url = input->start_url.is_valid() ? input->start_url : GURL();
|
| + output.display = static_cast<blink::WebDisplayMode>(input->display);
|
| + output.orientation =
|
| + static_cast<blink::WebScreenOrientationLockType>(input->orientation);
|
| + output.icons = input->icons.To<decltype(output.icons)>();
|
| + output.related_applications =
|
| + input->related_applications.To<decltype(output.related_applications)>();
|
| + output.prefer_related_applications = input->prefer_related_applications;
|
| + output.theme_color = input->theme_color;
|
| + output.background_color = input->background_color;
|
| + // theme_color and background_color are 32 bit unsigned integers with 64 bit
|
| + // integers simply being used to encode the occurence of an error. Therefore,
|
| + // any value outside the range of a 32 bit integer is invalid.
|
| + if (output.theme_color < std::numeric_limits<int32_t>::min() ||
|
| + output.theme_color > std::numeric_limits<int32_t>::max())
|
| + output.theme_color = content::Manifest::kInvalidOrMissingColor;
|
| + if (output.background_color < std::numeric_limits<int32_t>::min() ||
|
| + output.background_color > std::numeric_limits<int32_t>::max())
|
| + output.background_color = content::Manifest::kInvalidOrMissingColor;
|
| +
|
| + output.gcm_sender_id = input->gcm_sender_id.To<base::NullableString16>();
|
| + return output;
|
| +}
|
| +
|
| +blink::mojom::ManifestIconPtr
|
| +TypeConverter<blink::mojom::ManifestIconPtr, content::Manifest::Icon>::Convert(
|
| + const content::Manifest::Icon& input) {
|
| + blink::mojom::ManifestIconPtr output = blink::mojom::ManifestIcon::New();
|
| + output->src = input.src;
|
| + output->type = mojo::String::From(input.type);
|
| + output->sizes = decltype(output->sizes)::From(input.sizes);
|
| + return output;
|
| +}
|
| +
|
| +content::Manifest::Icon
|
| +TypeConverter<content::Manifest::Icon, blink::mojom::ManifestIconPtr>::Convert(
|
| + const blink::mojom::ManifestIconPtr& input) {
|
| + content::Manifest::Icon output;
|
| + output.src = input->src.is_valid() ? input->src : GURL();
|
| + output.type = input->type.To<base::NullableString16>();
|
| + output.sizes = input->sizes.To<decltype(output.sizes)>();
|
| + return output;
|
| +}
|
| +
|
| +blink::mojom::RelatedApplicationPtr
|
| +TypeConverter<blink::mojom::RelatedApplicationPtr,
|
| + content::Manifest::RelatedApplication>::
|
| + Convert(const content::Manifest::RelatedApplication& input) {
|
| + blink::mojom::RelatedApplicationPtr output =
|
| + blink::mojom::RelatedApplication::New();
|
| + output->platform = mojo::String::From(input.platform);
|
| + output->url = input.url;
|
| + output->id = mojo::String::From(input.id);
|
| + return output;
|
| +}
|
| +
|
| +content::Manifest::RelatedApplication
|
| +TypeConverter<content::Manifest::RelatedApplication,
|
| + blink::mojom::RelatedApplicationPtr>::
|
| + Convert(const blink::mojom::RelatedApplicationPtr& input) {
|
| + content::Manifest::RelatedApplication output;
|
| + output.platform = input->platform.To<base::NullableString16>();
|
| + output.url = input->url.is_valid() ? input->url : GURL();
|
| + output.id = input->id.To<base::NullableString16>();
|
| + return output;
|
| +}
|
| +
|
| +} // namespace mojo
|
|
|