Unreviewed, rolling out r245401.
[WebKit-https.git] / Source / WebKit / UIProcess / API / APIWebsitePolicies.cpp
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 #include "config.h"
27 #include "APIWebsitePolicies.h"
28
29 #include "APIWebsiteDataStore.h"
30 #include "WebsitePoliciesData.h"
31
32 namespace API {
33
34 WebsitePolicies::WebsitePolicies() = default;
35
36 WebsitePolicies::WebsitePolicies(bool contentBlockersEnabled, OptionSet<WebKit::WebsiteAutoplayQuirk> allowedAutoplayQuirks, WebKit::WebsiteAutoplayPolicy autoplayPolicy, Vector<WebCore::HTTPHeaderField>&& customHeaderFields, WebKit::WebsitePopUpPolicy popUpPolicy, RefPtr<WebsiteDataStore>&& websiteDataStore)
37     : m_contentBlockersEnabled(contentBlockersEnabled)
38     , m_allowedAutoplayQuirks(allowedAutoplayQuirks)
39     , m_autoplayPolicy(autoplayPolicy)
40     , m_customHeaderFields(WTFMove(customHeaderFields))
41     , m_popUpPolicy(popUpPolicy)
42     , m_websiteDataStore(WTFMove(websiteDataStore))
43 { }
44
45 Ref<WebsitePolicies> WebsitePolicies::copy() const
46 {
47     auto policies = WebsitePolicies::create();
48     policies->setContentBlockersEnabled(m_contentBlockersEnabled);
49     policies->setAllowedAutoplayQuirks(m_allowedAutoplayQuirks);
50     policies->setAutoplayPolicy(m_autoplayPolicy);
51 #if ENABLE(DEVICE_ORIENTATION)
52     policies->setDeviceOrientationAndMotionAccessState(m_deviceOrientationAndMotionAccessState);
53 #endif
54     policies->setPopUpPolicy(m_popUpPolicy);
55     policies->setWebsiteDataStore(m_websiteDataStore.get());
56     policies->setCustomUserAgent(m_customUserAgent);
57     policies->setCustomJavaScriptUserAgentAsSiteSpecificQuirks(m_customJavaScriptUserAgentAsSiteSpecificQuirks);
58     policies->setCustomNavigatorPlatform(m_customNavigatorPlatform);
59     policies->setPreferredCompatibilityMode(m_preferredCompatibilityMode);
60     policies->setMetaViewportPolicy(m_metaViewportPolicy);
61     policies->setMediaSourcePolicy(m_mediaSourcePolicy);
62     policies->setSimulatedMouseEventsDispatchPolicy(m_simulatedMouseEventsDispatchPolicy);
63     Vector<WebCore::HTTPHeaderField> customHeaderFields;
64     customHeaderFields.reserveInitialCapacity(m_customHeaderFields.size());
65     for (auto& field : m_customHeaderFields)
66         customHeaderFields.append(WebCore::HTTPHeaderField(field));
67     policies->setCustomHeaderFields(WTFMove(customHeaderFields));
68     policies->setAllowSiteSpecificQuirksToOverrideCompatibilityMode(m_allowSiteSpecificQuirksToOverrideCompatibilityMode);
69     policies->setApplicationNameForUserAgentWithModernCompatibility(m_applicationNameForUserAgentWithModernCompatibility);
70     return policies;
71 }
72
73 WebsitePolicies::~WebsitePolicies()
74 {
75 }
76
77 void WebsitePolicies::setWebsiteDataStore(RefPtr<WebsiteDataStore>&& websiteDataStore)
78 {
79     m_websiteDataStore = WTFMove(websiteDataStore);
80 }
81
82 WebKit::WebsitePoliciesData WebsitePolicies::data()
83 {
84     return {
85         contentBlockersEnabled(),
86         allowedAutoplayQuirks(),
87         autoplayPolicy(),
88 #if ENABLE(DEVICE_ORIENTATION)
89         deviceOrientationAndMotionAccessState(),
90 #endif
91         customHeaderFields(),
92         popUpPolicy(),
93         m_websiteDataStore ? Optional<WebKit::WebsiteDataStoreParameters> { m_websiteDataStore->websiteDataStore().parameters() } : WTF::nullopt,
94         m_customUserAgent,
95         m_customJavaScriptUserAgentAsSiteSpecificQuirks,
96         m_customNavigatorPlatform,
97         m_metaViewportPolicy,
98         m_mediaSourcePolicy,
99         m_simulatedMouseEventsDispatchPolicy,
100     };
101 }
102
103 }
104