| Index: content/common/cookies_traits.h
|
| diff --git a/content/common/cookies_traits.h b/content/common/cookies_traits.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..f9fae5eeffabccf9653504115821f29459ab9045
|
| --- /dev/null
|
| +++ b/content/common/cookies_traits.h
|
| @@ -0,0 +1,132 @@
|
| +// 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.
|
| +
|
| +#ifndef CONTENT_COMMON_COOKIES_TRAITS_H_
|
| +#define CONTENT_COMMON_COOKIES_TRAITS_H_
|
| +
|
| +#include "content/common/cookies.mojom.h"
|
| +#include "mojo/public/cpp/bindings/enum_traits.h"
|
| +#include "net/cookies/cookie_constants.h"
|
| +#include "net/cookies/cookie_options.h"
|
| +#include "net/cookies/cookie_store.h"
|
| +
|
| +namespace mojo {
|
| +
|
| +template <>
|
| +struct EnumTraits<content::mojom::CookiePriority, net::CookiePriority> {
|
| + static content::mojom::CookiePriority ToMojom(net::CookiePriority input);
|
| + static bool FromMojom(content::mojom::CookiePriority input,
|
| + net::CookiePriority* output);
|
| +};
|
| +
|
| +template <>
|
| +struct EnumTraits<content::mojom::CookieSameSite, net::CookieSameSite> {
|
| + static content::mojom::CookieSameSite ToMojom(net::CookieSameSite input);
|
| + static bool FromMojom(content::mojom::CookieSameSite input,
|
| + net::CookieSameSite* output);
|
| +};
|
| +
|
| +template <>
|
| +struct EnumTraits<content::mojom::CookieSameSiteFilter,
|
| + net::CookieOptions::SameSiteCookieMode> {
|
| + static content::mojom::CookieSameSiteFilter ToMojom(
|
| + net::CookieOptions::SameSiteCookieMode input);
|
| +
|
| + static bool FromMojom(content::mojom::CookieSameSiteFilter input,
|
| + net::CookieOptions::SameSiteCookieMode* output);
|
| +};
|
| +
|
| +template <>
|
| +struct EnumTraits<content::mojom::CookieChangeCause,
|
| + net::CookieStore::ChangeCause> {
|
| + static content::mojom::CookieChangeCause ToMojom(
|
| + net::CookieStore::ChangeCause input);
|
| +
|
| + static bool FromMojom(content::mojom::CookieChangeCause input,
|
| + net::CookieStore::ChangeCause* output);
|
| +};
|
| +
|
| +template <>
|
| +struct StructTraits<content::mojom::CookieOptions, net::CookieOptions> {
|
| + static bool exclude_httponly(const net::CookieOptions& o) {
|
| + return o.exclude_httponly();
|
| + }
|
| + static content::mojom::CookieSameSiteFilter cookie_same_site_filter(
|
| + const net::CookieOptions& o) {
|
| + return EnumTraits<content::mojom::CookieSameSiteFilter,
|
| + net::CookieOptions::SameSiteCookieMode>::
|
| + ToMojom(o.same_site_cookie_mode());
|
| + }
|
| + static bool update_access_time(const net::CookieOptions& o) {
|
| + return o.update_access_time();
|
| + }
|
| + static base::Optional<base::Time> server_time(const net::CookieOptions& o) {
|
| + if (!o.has_server_time())
|
| + return base::Optional<base::Time>();
|
| + return base::Optional<base::Time>(o.server_time());
|
| + }
|
| +
|
| + static bool Read(const content::mojom::CookieOptions& mojo_options,
|
| + net::CookieOptions* cookie_options) {
|
| + if (mojo_options.exclude_httponly)
|
| + cookie_options->set_exclude_httponly();
|
| + else
|
| + cookie_options->set_include_httponly();
|
| + if (mojo_options.update_access_time)
|
| + cookie_options->set_update_access_time();
|
| + else
|
| + cookie_options->set_do_not_update_access_time();
|
| + cookie_options->set_server_time(
|
| + mojo_options.server_time ? *mojo_options.server_time : base::Time());
|
| + return true;
|
| + }
|
| +};
|
| +
|
| +template <>
|
| +struct StructTraits<content::mojom::CanonicalCookie, net::CanonicalCookie> {
|
| + static std::string name(const net::CanonicalCookie& c) { return c.Name(); }
|
| + static std::string value(const net::CanonicalCookie& c) { return c.Value(); }
|
| + static std::string domain(const net::CanonicalCookie& c) {
|
| + return c.Domain();
|
| + }
|
| + static std::string path(const net::CanonicalCookie& c) { return c.Path(); }
|
| + static base::Time creation(const net::CanonicalCookie& c) {
|
| + return c.CreationDate();
|
| + }
|
| + static base::Time expiry(const net::CanonicalCookie& c) {
|
| + return c.ExpiryDate();
|
| + }
|
| + static base::Time last_access(const net::CanonicalCookie& c) {
|
| + return c.LastAccessDate();
|
| + }
|
| + static bool secure(const net::CanonicalCookie& c) { return c.IsSecure(); }
|
| + static bool httponly(const net::CanonicalCookie& c) { return c.IsHttpOnly(); }
|
| + static content::mojom::CookieSameSite site_restrictions(
|
| + const net::CanonicalCookie& c) {
|
| + return EnumTraits<content::mojom::CookieSameSite,
|
| + net::CookieSameSite>::ToMojom(c.SameSite());
|
| + }
|
| + static content::mojom::CookiePriority priority(
|
| + const net::CanonicalCookie& c) {
|
| + return EnumTraits<content::mojom::CookiePriority,
|
| + net::CookiePriority>::ToMojom(c.Priority());
|
| + }
|
| +
|
| + static bool Read(const content::mojom::CanonicalCookie& cookie,
|
| + net::CanonicalCookie* out) {
|
| + // TODO(rdsmith): There's no point in allocating this object only to delete
|
| + // it at the end of the function; fix the CC declaration to avoid this.
|
| + std::unique_ptr<net::CanonicalCookie> output_cc(
|
| + net::CanonicalCookie::Create(
|
| + cookie.name, cookie.value, cookie.domain, cookie.path,
|
| + cookie.creation, cookie.expiry, cookie.last_access, cookie.secure,
|
| + cookie.httponly, cookie.site_restrictions, cookie.priority));
|
| + *out = *output_cc.get();
|
| + return true;
|
| + }
|
| +};
|
| +
|
| +} // namespace mojo
|
| +
|
| +#endif // CONTENT_COMMON_COOKIES_TRAITS_H_
|
|
|