f4976093587e4b8fb3d5ba09ff9b9c04e3d2f8e5
[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 manualPrevalentResource { };
51     
52     void encode(IPC::Encoder& encoder) const
53     {
54         encoder << directory;
55         encoder << directoryExtensionHandle;
56         encoder << enabled;
57         encoder << isItpStateExplicitlySet;
58         encoder << enableLogTestingEvent;
59         encoder << shouldIncludeLocalhost;
60         encoder << enableDebugMode;
61 #if ENABLE(RESOURCE_LOAD_STATISTICS)
62         encoder << thirdPartyCookieBlockingMode;
63         encoder << sameSiteStrictEnforcementEnabled;
64 #endif
65         encoder << firstPartyWebsiteDataRemovalMode;
66         encoder << manualPrevalentResource;
67     }
68
69     static Optional<ResourceLoadStatisticsParameters> decode(IPC::Decoder& decoder)
70     {
71         Optional<String> directory;
72         decoder >> directory;
73         if (!directory)
74             return WTF::nullopt;
75         
76         Optional<SandboxExtension::Handle> directoryExtensionHandle;
77         decoder >> directoryExtensionHandle;
78         if (!directoryExtensionHandle)
79             return WTF::nullopt;
80         
81         Optional<bool> enabled;
82         decoder >> enabled;
83         if (!enabled)
84             return WTF::nullopt;
85
86         Optional<bool> isItpStateExplicitlySet;
87         decoder >> isItpStateExplicitlySet;
88         if (!isItpStateExplicitlySet)
89             return WTF::nullopt;
90
91         Optional<bool> enableLogTestingEvent;
92         decoder >> enableLogTestingEvent;
93         if (!enableLogTestingEvent)
94             return WTF::nullopt;
95
96         Optional<bool> shouldIncludeLocalhost;
97         decoder >> shouldIncludeLocalhost;
98         if (!shouldIncludeLocalhost)
99             return WTF::nullopt;
100
101         Optional<bool> enableDebugMode;
102         decoder >> enableDebugMode;
103         if (!enableDebugMode)
104             return WTF::nullopt;
105
106 #if ENABLE(RESOURCE_LOAD_STATISTICS)
107         Optional<WebCore::ThirdPartyCookieBlockingMode> thirdPartyCookieBlockingMode;
108         decoder >> thirdPartyCookieBlockingMode;
109         if (!thirdPartyCookieBlockingMode)
110             return WTF::nullopt;
111
112         Optional<WebCore::SameSiteStrictEnforcementEnabled> sameSiteStrictEnforcementEnabled;
113         decoder >> sameSiteStrictEnforcementEnabled;
114         if (!sameSiteStrictEnforcementEnabled)
115             return WTF::nullopt;
116 #endif
117
118         Optional<WebCore::FirstPartyWebsiteDataRemovalMode> firstPartyWebsiteDataRemovalMode;
119         decoder >> firstPartyWebsiteDataRemovalMode;
120         if (!firstPartyWebsiteDataRemovalMode)
121             return WTF::nullopt;
122
123         Optional<WebCore::RegistrableDomain> manualPrevalentResource;
124         decoder >> manualPrevalentResource;
125         if (!manualPrevalentResource)
126             return WTF::nullopt;
127
128         return {{
129             WTFMove(*directory),
130             WTFMove(*directoryExtensionHandle),
131             WTFMove(*enabled),
132             WTFMove(*isItpStateExplicitlySet),
133             WTFMove(*enableLogTestingEvent),
134             WTFMove(*shouldIncludeLocalhost),
135             WTFMove(*enableDebugMode),
136 #if ENABLE(RESOURCE_LOAD_STATISTICS)
137             WTFMove(*thirdPartyCookieBlockingMode),
138             WTFMove(*sameSiteStrictEnforcementEnabled),
139 #endif
140             WTFMove(*firstPartyWebsiteDataRemovalMode),
141             WTFMove(*manualPrevalentResource),
142         }};
143     }
144 };
145
146 } // namespace WebKit