1/*
2 * Copyright (C) 2017 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#pragma once
27
28#if ENABLE(APPLICATION_MANIFEST)
29
30#include <wtf/EnumTraits.h>
31#include <wtf/Optional.h>
32#include <wtf/URL.h>
33
34namespace WebCore {
35
36struct ApplicationManifest {
37 enum class Display {
38 Browser,
39 MinimalUI,
40 Standalone,
41 Fullscreen,
42 };
43
44 String name;
45 String shortName;
46 String description;
47 URL scope;
48 Display display;
49 URL startURL;
50
51 template<class Encoder> void encode(Encoder&) const;
52 template<class Decoder> static Optional<ApplicationManifest> decode(Decoder&);
53};
54
55template<class Encoder>
56void ApplicationManifest::encode(Encoder& encoder) const
57{
58 encoder << name << shortName << description << scope << display << startURL;
59}
60
61template<class Decoder>
62Optional<ApplicationManifest> ApplicationManifest::decode(Decoder& decoder)
63{
64 ApplicationManifest result;
65
66 if (!decoder.decode(result.name))
67 return WTF::nullopt;
68 if (!decoder.decode(result.shortName))
69 return WTF::nullopt;
70 if (!decoder.decode(result.description))
71 return WTF::nullopt;
72 if (!decoder.decode(result.scope))
73 return WTF::nullopt;
74 if (!decoder.decodeEnum(result.display))
75 return WTF::nullopt;
76 if (!decoder.decode(result.startURL))
77 return WTF::nullopt;
78
79 return result;
80}
81
82} // namespace WebCore
83
84namespace WTF {
85
86template<> struct EnumTraits<WebCore::ApplicationManifest::Display> {
87 using values = EnumValues<
88 WebCore::ApplicationManifest::Display,
89 WebCore::ApplicationManifest::Display::Browser,
90 WebCore::ApplicationManifest::Display::MinimalUI,
91 WebCore::ApplicationManifest::Display::Standalone,
92 WebCore::ApplicationManifest::Display::Fullscreen
93 >;
94};
95
96} // namespace WTF;
97
98#endif // ENABLE(APPLICATION_MANIFEST)
99
100