| Index: content/common/push_messaging_param_traits.cc
|
| diff --git a/content/common/push_messaging_param_traits.cc b/content/common/push_messaging_param_traits.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..aa1d30efe8298f04eab14ffe73521f8b839a903f
|
| --- /dev/null
|
| +++ b/content/common/push_messaging_param_traits.cc
|
| @@ -0,0 +1,131 @@
|
| +// Copyright 2017 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/push_messaging_param_traits.h"
|
| +
|
| +namespace mojo {
|
| +
|
| +static_assert(content::PushRegistrationStatus::PUSH_REGISTRATION_STATUS_LAST ==
|
| + static_cast<content::PushRegistrationStatus>(
|
| + content::mojom::PushRegistrationStatus::LAST),
|
| + "PushRegistrationStatus enums must match");
|
| +
|
| +static_assert(blink::WebPushError::ErrorType::ErrorTypeLast ==
|
| + static_cast<blink::WebPushError::ErrorType>(
|
| + content::mojom::PushErrorType::LAST),
|
| + "PushErrorType enums must match");
|
| +
|
| +static_assert(
|
| + content::PushGetRegistrationStatus::PUSH_GETREGISTRATION_STATUS_LAST ==
|
| + static_cast<content::PushGetRegistrationStatus>(
|
| + content::mojom::PushGetRegistrationStatus::LAST),
|
| + "PushGetRegistrationStatus enums must match");
|
| +
|
| +static_assert(blink::WebPushPermissionStatus::WebPushPermissionStatusLast ==
|
| + static_cast<blink::WebPushPermissionStatus>(
|
| + content::mojom::PushPermissionStatus::LAST),
|
| + "PushPermissionStatus enums must match");
|
| +
|
| +// static
|
| +bool StructTraits<content::mojom::PushSubscriptionOptionsDataView,
|
| + content::PushSubscriptionOptions>::
|
| + Read(content::mojom::PushSubscriptionOptionsDataView data,
|
| + content::PushSubscriptionOptions* out) {
|
| + out->user_visible_only = data.user_visible_only();
|
| + if (!data.ReadSenderInfo(&out->sender_info))
|
| + return false;
|
| +
|
| + return true;
|
| +}
|
| +
|
| +// static
|
| +content::mojom::PushRegistrationStatus EnumTraits<
|
| + content::mojom::PushRegistrationStatus,
|
| + content::PushRegistrationStatus>::ToMojom(content::PushRegistrationStatus
|
| + input) {
|
| + CHECK(input >= content::PushRegistrationStatus::
|
| + PUSH_REGISTRATION_STATUS_SUCCESS_FROM_PUSH_SERVICE &&
|
| + input <=
|
| + content::PushRegistrationStatus::PUSH_REGISTRATION_STATUS_LAST);
|
| + return static_cast<content::mojom::PushRegistrationStatus>(input);
|
| +}
|
| +
|
| +// static
|
| +bool EnumTraits<content::mojom::PushRegistrationStatus,
|
| + content::PushRegistrationStatus>::
|
| + FromMojom(content::mojom::PushRegistrationStatus input,
|
| + content::PushRegistrationStatus* output) {
|
| + CHECK(input >=
|
| + content::mojom::PushRegistrationStatus::SUCCESS_FROM_PUSH_SERVICE &&
|
| + input <= content::mojom::PushRegistrationStatus::LAST);
|
| + *output = static_cast<content::PushRegistrationStatus>(input);
|
| + return true;
|
| +}
|
| +
|
| +// static
|
| +content::mojom::PushErrorType
|
| +EnumTraits<content::mojom::PushErrorType, blink::WebPushError::ErrorType>::
|
| + ToMojom(blink::WebPushError::ErrorType input) {
|
| + CHECK(input >= blink::WebPushError::ErrorType::ErrorTypeAbort &&
|
| + input <= blink::WebPushError::ErrorType::ErrorTypeInvalidState);
|
| + return static_cast<content::mojom::PushErrorType>(input);
|
| +}
|
| +
|
| +// static
|
| +bool EnumTraits<content::mojom::PushErrorType, blink::WebPushError::ErrorType>::
|
| + FromMojom(content::mojom::PushErrorType input,
|
| + blink::WebPushError::ErrorType* output) {
|
| + CHECK(input >= content::mojom::PushErrorType::ABORT &&
|
| + input <= content::mojom::PushErrorType::INVALID_STATE);
|
| + *output = static_cast<blink::WebPushError::ErrorType>(input);
|
| + return true;
|
| +}
|
| +
|
| +// static
|
| +content::mojom::PushGetRegistrationStatus
|
| +EnumTraits<content::mojom::PushGetRegistrationStatus,
|
| + content::PushGetRegistrationStatus>::
|
| + ToMojom(content::PushGetRegistrationStatus input) {
|
| + CHECK(
|
| + input >= content::PushGetRegistrationStatus::
|
| + PUSH_GETREGISTRATION_STATUS_SUCCESS &&
|
| + input <=
|
| + content::PushGetRegistrationStatus::PUSH_GETREGISTRATION_STATUS_LAST);
|
| + return static_cast<content::mojom::PushGetRegistrationStatus>(input);
|
| +}
|
| +
|
| +// static
|
| +bool EnumTraits<content::mojom::PushGetRegistrationStatus,
|
| + content::PushGetRegistrationStatus>::
|
| + FromMojom(content::mojom::PushGetRegistrationStatus input,
|
| + content::PushGetRegistrationStatus* output) {
|
| + CHECK(input >= content::mojom::PushGetRegistrationStatus::SUCCESS &&
|
| + input <= content::mojom::PushGetRegistrationStatus::LAST);
|
| + *output = static_cast<content::PushGetRegistrationStatus>(input);
|
| + return true;
|
| +}
|
| +
|
| +// static
|
| +content::mojom::PushPermissionStatus EnumTraits<
|
| + content::mojom::PushPermissionStatus,
|
| + blink::WebPushPermissionStatus>::ToMojom(blink::WebPushPermissionStatus
|
| + input) {
|
| + CHECK(input >=
|
| + blink::WebPushPermissionStatus::WebPushPermissionStatusGranted &&
|
| + input <= blink::WebPushPermissionStatus::WebPushPermissionStatusLast);
|
| + return static_cast<content::mojom::PushPermissionStatus>(input);
|
| +}
|
| +
|
| +// static
|
| +bool EnumTraits<content::mojom::PushPermissionStatus,
|
| + blink::WebPushPermissionStatus>::
|
| + FromMojom(content::mojom::PushPermissionStatus input,
|
| + blink::WebPushPermissionStatus* output) {
|
| + CHECK(input >= content::mojom::PushPermissionStatus::GRANTED &&
|
| + input <= content::mojom::PushPermissionStatus::LAST);
|
| + *output = static_cast<blink::WebPushPermissionStatus>(input);
|
| + return true;
|
| +}
|
| +
|
| +} // namespace mojo
|
|
|