Skip to content

Commit

Permalink
Replace member variables in APIWebsitePolicies with WebsitePoliciesData
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=268955
rdar://122511776

Reviewed by Alex Christensen.

* Source/WebKit/Shared/WebsitePoliciesData.h:
* Source/WebKit/Shared/WebsitePoliciesData.serialization.in:
* Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp:
(API::WebsitePolicies::copy const):
(API::WebsitePolicies::data):
* Source/WebKit/UIProcess/API/APIWebsitePolicies.h:

Canonical link: https://commits.webkit.org/274291@main
  • Loading branch information
charliewolfe committed Feb 8, 2024
1 parent 1021d66 commit 4407f0d
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 174 deletions.
24 changes: 14 additions & 10 deletions Source/WebKit/Shared/WebsitePoliciesData.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#pragma once

#include "WebContentMode.h"
#include "WebsiteAutoplayPolicy.h"
#include "WebsiteAutoplayQuirk.h"
#include "WebsiteLegacyOverflowScrollingTouchPolicy.h"
Expand Down Expand Up @@ -53,30 +54,33 @@ namespace WebKit {
struct WebsitePoliciesData {
static void applyToDocumentLoader(WebsitePoliciesData&&, WebCore::DocumentLoader&);

WebCore::ContentExtensionEnablement contentExtensionEnablement;
HashMap<WTF::String, Vector<WTF::String>> activeContentRuleListActionPatterns;
OptionSet<WebsiteAutoplayQuirk> allowedAutoplayQuirks;
WebsiteAutoplayPolicy autoplayPolicy { WebsiteAutoplayPolicy::Default };
#if ENABLE(DEVICE_ORIENTATION)
WebCore::DeviceOrientationOrMotionPermissionState deviceOrientationAndMotionAccessState;
#endif
HashMap<String, Vector<String>> activeContentRuleListActionPatterns;
Vector<WebCore::CustomHeaderFields> customHeaderFields;
WebsitePopUpPolicy popUpPolicy { WebsitePopUpPolicy::Default };
String customUserAgent;
String customUserAgentAsSiteSpecificQuirks;
String customNavigatorPlatform;
String applicationNameForDesktopUserAgent;
OptionSet<WebCore::AdvancedPrivacyProtections> advancedPrivacyProtections;
OptionSet<WebsiteAutoplayQuirk> allowedAutoplayQuirks;
WebCore::ContentExtensionEnablement contentExtensionEnablement { WebCore::ContentExtensionDefaultEnablement::Enabled, { } };
WebsiteAutoplayPolicy autoplayPolicy { WebsiteAutoplayPolicy::Default };
WebsitePopUpPolicy popUpPolicy { WebsitePopUpPolicy::Default };
WebsiteMetaViewportPolicy metaViewportPolicy { WebsiteMetaViewportPolicy::Default };
WebsiteMediaSourcePolicy mediaSourcePolicy { WebsiteMediaSourcePolicy::Default };
WebsiteSimulatedMouseEventsDispatchPolicy simulatedMouseEventsDispatchPolicy { WebsiteSimulatedMouseEventsDispatchPolicy::Default };
WebsiteLegacyOverflowScrollingTouchPolicy legacyOverflowScrollingTouchPolicy { WebsiteLegacyOverflowScrollingTouchPolicy::Default };
bool allowContentChangeObserverQuirk { false };
WebCore::AllowsContentJavaScript allowsContentJavaScript { WebCore::AllowsContentJavaScript::Yes };
WebCore::MouseEventPolicy mouseEventPolicy { WebCore::MouseEventPolicy::Default };
WebCore::ModalContainerObservationPolicy modalContainerObservationPolicy { WebCore::ModalContainerObservationPolicy::Disabled };
WebCore::ColorSchemePreference colorSchemePreference { WebCore::ColorSchemePreference::NoPreference };
OptionSet<WebCore::AdvancedPrivacyProtections> advancedPrivacyProtections;
WebContentMode preferredContentMode { WebContentMode::Recommended };
#if ENABLE(DEVICE_ORIENTATION)
WebCore::DeviceOrientationOrMotionPermissionState deviceOrientationAndMotionAccessState { WebCore::DeviceOrientationOrMotionPermissionState::Prompt };
#endif
bool allowContentChangeObserverQuirk { false };
bool idempotentModeAutosizingOnlyHonorsPercentages { false };
bool allowPrivacyProxy { true };
bool allowSiteSpecificQuirksToOverrideContentMode { false };
};

} // namespace WebKit
29 changes: 19 additions & 10 deletions Source/WebKit/Shared/WebsitePoliciesData.serialization.in
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,38 @@ enum class WebKit::WebsiteLegacyOverflowScrollingTouchPolicy : uint8_t {
Enable
};

enum class WebKit::WebContentMode : uint8_t {
Recommended,
Mobile,
Desktop
};

struct WebKit::WebsitePoliciesData {
WebCore::ContentExtensionEnablement contentExtensionEnablement;
HashMap<WTF::String, Vector<WTF::String>> activeContentRuleListActionPatterns;
Vector<WebCore::CustomHeaderFields> customHeaderFields;
WTF::String customUserAgent;
WTF::String customUserAgentAsSiteSpecificQuirks;
WTF::String customNavigatorPlatform;
WTF::String applicationNameForDesktopUserAgent;
OptionSet<WebCore::AdvancedPrivacyProtections> advancedPrivacyProtections;
OptionSet<WebKit::WebsiteAutoplayQuirk> allowedAutoplayQuirks;
WebCore::ContentExtensionEnablement contentExtensionEnablement;
WebKit::WebsiteAutoplayPolicy autoplayPolicy;
#if ENABLE(DEVICE_ORIENTATION)
WebCore::DeviceOrientationOrMotionPermissionState deviceOrientationAndMotionAccessState;
#endif
Vector<WebCore::CustomHeaderFields> customHeaderFields;
WebKit::WebsitePopUpPolicy popUpPolicy;
String customUserAgent;
String customUserAgentAsSiteSpecificQuirks;
String customNavigatorPlatform;
WebKit::WebsiteMetaViewportPolicy metaViewportPolicy;
WebKit::WebsiteMediaSourcePolicy mediaSourcePolicy;
WebKit::WebsiteSimulatedMouseEventsDispatchPolicy simulatedMouseEventsDispatchPolicy;
WebKit::WebsiteLegacyOverflowScrollingTouchPolicy legacyOverflowScrollingTouchPolicy;
bool allowContentChangeObserverQuirk;
WebCore::AllowsContentJavaScript allowsContentJavaScript;
WebCore::MouseEventPolicy mouseEventPolicy;
WebCore::ModalContainerObservationPolicy modalContainerObservationPolicy;
WebCore::ColorSchemePreference colorSchemePreference;
OptionSet<WebCore::AdvancedPrivacyProtections> advancedPrivacyProtections;
WebKit::WebContentMode preferredContentMode;
#if ENABLE(DEVICE_ORIENTATION)
WebCore::DeviceOrientationOrMotionPermissionState deviceOrientationAndMotionAccessState;
#endif
bool allowContentChangeObserverQuirk;
bool idempotentModeAutosizingOnlyHonorsPercentages;
bool allowPrivacyProxy;
bool allowSiteSpecificQuirksToOverrideContentMode;
};
60 changes: 2 additions & 58 deletions Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,37 +38,10 @@ WebsitePolicies::WebsitePolicies() = default;
Ref<WebsitePolicies> WebsitePolicies::copy() const
{
auto policies = WebsitePolicies::create();
policies->m_contentExtensionEnablement = m_contentExtensionEnablement;
policies->m_activeContentRuleListActionPatterns = m_activeContentRuleListActionPatterns;
policies->setAllowedAutoplayQuirks(m_allowedAutoplayQuirks);
policies->setAutoplayPolicy(m_autoplayPolicy);
#if ENABLE(DEVICE_ORIENTATION)
policies->setDeviceOrientationAndMotionAccessState(m_deviceOrientationAndMotionAccessState);
#endif
policies->setPopUpPolicy(m_popUpPolicy);
policies->setWebsiteDataStore(m_websiteDataStore.get());
policies->setCustomUserAgent(m_customUserAgent);
policies->setCustomUserAgentAsSiteSpecificQuirks(m_customUserAgentAsSiteSpecificQuirks);
policies->setCustomNavigatorPlatform(m_customNavigatorPlatform);
policies->setPreferredContentMode(m_preferredContentMode);
policies->setMetaViewportPolicy(m_metaViewportPolicy);
policies->setMediaSourcePolicy(m_mediaSourcePolicy);
policies->setSimulatedMouseEventsDispatchPolicy(m_simulatedMouseEventsDispatchPolicy);
policies->setLegacyOverflowScrollingTouchPolicy(m_legacyOverflowScrollingTouchPolicy);
policies->setAllowContentChangeObserverQuirk(m_allowContentChangeObserverQuirk);
policies->m_data = m_data;
policies->setWebsiteDataStore(m_websiteDataStore.get());
policies->setUserContentController(m_userContentController.get());
policies->setAdvancedPrivacyProtections(m_advancedPrivacyProtections);
policies->setIdempotentModeAutosizingOnlyHonorsPercentages(m_idempotentModeAutosizingOnlyHonorsPercentages);
policies->setCustomHeaderFields(Vector<WebCore::CustomHeaderFields> { m_customHeaderFields });
policies->setAllowSiteSpecificQuirksToOverrideContentMode(m_allowSiteSpecificQuirksToOverrideContentMode);
policies->setApplicationNameForDesktopUserAgent(m_applicationNameForDesktopUserAgent);
policies->setAllowsContentJavaScript(m_allowsContentJavaScript);
policies->setLockdownModeEnabled(m_lockdownModeEnabled);
policies->setMouseEventPolicy(m_mouseEventPolicy);
policies->setModalContainerObservationPolicy(m_modalContainerObservationPolicy);
policies->setColorSchemePreference(m_colorSchemePreference);
policies->setAllowPrivacyProxy(m_allowPrivacyProxy);
return policies;
}

Expand All @@ -86,36 +59,7 @@ void WebsitePolicies::setUserContentController(RefPtr<WebKit::WebUserContentCont

WebKit::WebsitePoliciesData WebsitePolicies::data()
{
Vector<WebCore::CustomHeaderFields> customHeaderFields;
customHeaderFields.reserveInitialCapacity(this->customHeaderFields().size());
customHeaderFields.appendVector(this->customHeaderFields());

return {
m_contentExtensionEnablement,
activeContentRuleListActionPatterns(),
allowedAutoplayQuirks(),
autoplayPolicy(),
#if ENABLE(DEVICE_ORIENTATION)
deviceOrientationAndMotionAccessState(),
#endif
WTFMove(customHeaderFields),
popUpPolicy(),
m_customUserAgent,
m_customUserAgentAsSiteSpecificQuirks,
m_customNavigatorPlatform,
m_metaViewportPolicy,
m_mediaSourcePolicy,
m_simulatedMouseEventsDispatchPolicy,
m_legacyOverflowScrollingTouchPolicy,
m_allowContentChangeObserverQuirk,
m_allowsContentJavaScript,
m_mouseEventPolicy,
m_modalContainerObservationPolicy,
m_colorSchemePreference,
m_advancedPrivacyProtections,
m_idempotentModeAutosizingOnlyHonorsPercentages,
m_allowPrivacyProxy
};
return m_data;
}

bool WebsitePolicies::lockdownModeEnabled() const
Expand Down
Loading

0 comments on commit 4407f0d

Please sign in to comment.