Add SPI to configure WebsiteDataStores with a URL for standalone web applications...
[WebKit-https.git] / Source / WebKit / Shared / ResourceLoadStatisticsParameters.h
1 /*
2  * Copyright (C) 2020 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 #include "ArgumentCoders.h"
29 #include "SandboxExtension.h"
30 #include <WebCore/NetworkStorageSession.h>
31 #include <WebCore/RegistrableDomain.h>
32 #include <wtf/text/WTFString.h>
33
34 namespace WebKit {
35
36 struct ResourceLoadStatisticsParameters {
37
38     String directory;
39     SandboxExtension::Handle directoryExtensionHandle;
40     bool enabled { false };
41     bool isItpStateExplicitlySet { false };
42     bool enableLogTestingEvent { false };
43     bool shouldIncludeLocalhost { true };
44     bool enableDebugMode { false };
45 #if ENABLE(RESOURCE_LOAD_STATISTICS)
46     WebCore::ThirdPartyCookieBlockingMode thirdPartyCookieBlockingMode { WebCore::ThirdPartyCookieBlockingMode::All };
47     WebCore::SameSiteStrictEnforcementEnabled sameSiteStrictEnforcementEnabled { WebCore::SameSiteStrictEnforcementEnabled::No };
48 #endif
49     WebCore::FirstPartyWebsiteDataRemovalMode firstPartyWebsiteDataRemovalMode { WebCore::FirstPartyWebsiteDataRemovalMode::AllButCookies };
50     WebCore::RegistrableDomain standaloneApplicationDomain { };
51     WebCore::RegistrableDomain manualPrevalentResource { };
52     
53     void encode(IPC::Encoder& encoder) const
54     {
55         encoder << directory;
56         encoder << directoryExtensionHandle;
57         encoder << enabled;
58         encoder << isItpStateExplicitlySet;
59         encoder << enableLogTestingEvent;
60         encoder << shouldIncludeLocalhost;
61         encoder << enableDebugMode;
62 #if ENABLE(RESOURCE_LOAD_STATISTICS)
63         encoder << thirdPartyCookieBlockingMode;
64         encoder << sameSiteStrictEnforcementEnabled;
65 #endif
66         encoder << firstPartyWebsiteDataRemovalMode;
67         encoder << standaloneApplicationDomain;
68         encoder << manualPrevalentResource;
69     }
70
71     static Optional<ResourceLoadStatisticsParameters> decode(IPC::Decoder& decoder)
72     {
73         Optional<String> directory;
74         decoder >> directory;
75         if (!directory)
76             return WTF::nullopt;
77         
78         Optional<SandboxExtension::Handle> directoryExtensionHandle;
79         decoder >> directoryExtensionHandle;
80         if (!directoryExtensionHandle)
81             return WTF::nullopt;
82         
83         Optional<bool> enabled;
84         decoder >> enabled;
85         if (!enabled)
86             return WTF::nullopt;
87
88         Optional<bool> isItpStateExplicitlySet;
89         decoder >> isItpStateExplicitlySet;
90         if (!isItpStateExplicitlySet)
91             return WTF::nullopt;
92
93         Optional<bool> enableLogTestingEvent;
94         decoder >> enableLogTestingEvent;
95         if (!enableLogTestingEvent)
96             return WTF::nullopt;
97
98         Optional<bool> shouldIncludeLocalhost;
99         decoder >> shouldIncludeLocalhost;
100         if (!shouldIncludeLocalhost)
101             return WTF::nullopt;
102
103         Optional<bool> enableDebugMode;
104         decoder >> enableDebugMode;
105         if (!enableDebugMode)
106             return WTF::nullopt;
107
108 #if ENABLE(RESOURCE_LOAD_STATISTICS)
109         Optional<WebCore::ThirdPartyCookieBlockingMode> thirdPartyCookieBlockingMode;
110         decoder >> thirdPartyCookieBlockingMode;
111         if (!thirdPartyCookieBlockingMode)
112             return WTF::nullopt;
113
114         Optional<WebCore::SameSiteStrictEnforcementEnabled> sameSiteStrictEnforcementEnabled;
115         decoder >> sameSiteStrictEnforcementEnabled;
116         if (!sameSiteStrictEnforcementEnabled)
117             return WTF::nullopt;
118 #endif
119
120         Optional<WebCore::FirstPartyWebsiteDataRemovalMode> firstPartyWebsiteDataRemovalMode;
121         decoder >> firstPartyWebsiteDataRemovalMode;
122         if (!firstPartyWebsiteDataRemovalMode)
123             return WTF::nullopt;
124
125         Optional<WebCore::RegistrableDomain> standaloneApplicationDomain;
126         decoder >> standaloneApplicationDomain;
127         if (!standaloneApplicationDomain)
128             return WTF::nullopt;
129
130         Optional<WebCore::RegistrableDomain> manualPrevalentResource;
131         decoder >> manualPrevalentResource;
132         if (!manualPrevalentResource)
133             return WTF::nullopt;
134
135         return {{
136             WTFMove(*directory),
137             WTFMove(*directoryExtensionHandle),
138             WTFMove(*enabled),
139             WTFMove(*isItpStateExplicitlySet),
140             WTFMove(*enableLogTestingEvent),
141             WTFMove(*shouldIncludeLocalhost),
142             WTFMove(*enableDebugMode),
143 #if ENABLE(RESOURCE_LOAD_STATISTICS)
144             WTFMove(*thirdPartyCookieBlockingMode),
145             WTFMove(*sameSiteStrictEnforcementEnabled),
146 #endif
147             WTFMove(*firstPartyWebsiteDataRemovalMode),
148             WTFMove(*standaloneApplicationDomain),
149             WTFMove(*manualPrevalentResource),
150         }};
151     }
152 };
153
154 } // namespace WebKit