[WebKit2] Introduce a public version of WKWebsitePolicies
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 2 Apr 2019 00:01:05 +0000 (00:01 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 2 Apr 2019 00:01:05 +0000 (00:01 +0000)
https://bugs.webkit.org/show_bug.cgi?id=195989
<rdar://problem/47228232>

Reviewed by Tim Horton.

Expose the existing _WKWebsitePolicies object as WKWebpagePreferences, in what will eventually become a public
header in the WebKit SDK (WKWebpagePreferences.h). Following a similar transitioning strategy as
_WKWebsiteDataStore and WKWebsiteDataStore, we move existing logic from _WKWebsitePolicies to WKWebpagePreferences
and make _WKWebsitePolicies a wrapper around WKWebpagePreferences.

No change in behavior.

* Shared/Cocoa/APIObject.mm:
(API::Object::newObject):

Wrap API::WebsitePolicies with WKWebpagePreferences.

* SourcesCocoa.txt:
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _updateWebsitePolicies:]):
* UIProcess/API/Cocoa/WKWebpagePreferences.h: Copied from Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePoliciesInternal.h.
* UIProcess/API/Cocoa/WKWebpagePreferences.mm: Copied from Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.mm.

Introduce WKWebpagePreferences.

(+[WKWebpagePreferences defaultPreferences]):
(-[WKWebpagePreferences dealloc]):
(-[WKWebpagePreferences init]):
(-[WKWebpagePreferences _setContentBlockersEnabled:]):
(-[WKWebpagePreferences _contentBlockersEnabled]):
(-[WKWebpagePreferences _setAllowedAutoplayQuirks:]):
(-[WKWebpagePreferences _allowedAutoplayQuirks]):
(-[WKWebpagePreferences _setAutoplayPolicy:]):
(-[WKWebpagePreferences _autoplayPolicy]):
(-[WKWebpagePreferences _setDeviceOrientationAndMotionAccessPolicy:]):
(-[WKWebpagePreferences _deviceOrientationAndMotionAccessPolicy]):
(-[WKWebpagePreferences _setPopUpPolicy:]):
(-[WKWebpagePreferences _popUpPolicy]):
(-[WKWebpagePreferences _customHeaderFields]):
(-[WKWebpagePreferences _setCustomHeaderFields:]):
(-[WKWebpagePreferences _websiteDataStore]):
(-[WKWebpagePreferences _setWebsiteDataStore:]):
(-[WKWebpagePreferences _setCustomUserAgent:]):
(-[WKWebpagePreferences _customUserAgent]):
(-[WKWebpagePreferences _setCustomJavaScriptUserAgentAsSiteSpecificQuirks:]):
(-[WKWebpagePreferences _customJavaScriptUserAgentAsSiteSpecificQuirks]):
(-[WKWebpagePreferences _setCustomNavigatorPlatform:]):
(-[WKWebpagePreferences _customNavigatorPlatform]):
(-[WKWebpagePreferences _apiObject]):
* UIProcess/API/Cocoa/WKWebpagePreferencesInternal.h: Copied from Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePoliciesInternal.h.
* UIProcess/API/Cocoa/WKWebpagePreferencesPrivate.h: Copied from Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.h.

Reintroduce all the interfaces currently available on _WKWebsitePolicies as underscore-prefixed SPI on
WKWebpagePreferences.

* UIProcess/API/Cocoa/_WKWebsitePolicies.h:
* UIProcess/API/Cocoa/_WKWebsitePolicies.mm:

Make _WKWebsitePolicies wrap WKWebpagePreferences, and plumb all existing SPI on WKWebsitePolicies through to
WKWebpagePreferences.

(-[_WKWebsitePolicies init]):
(-[_WKWebsitePolicies webpagePreferences]):
(-[_WKWebsitePolicies setContentBlockersEnabled:]):
(-[_WKWebsitePolicies contentBlockersEnabled]):
(-[_WKWebsitePolicies setAllowedAutoplayQuirks:]):
(-[_WKWebsitePolicies allowedAutoplayQuirks]):
(-[_WKWebsitePolicies setAutoplayPolicy:]):
(-[_WKWebsitePolicies autoplayPolicy]):
(-[_WKWebsitePolicies setDeviceOrientationAndMotionAccessPolicy:]):
(-[_WKWebsitePolicies deviceOrientationAndMotionAccessPolicy]):
(-[_WKWebsitePolicies setPopUpPolicy:]):
(-[_WKWebsitePolicies popUpPolicy]):
(-[_WKWebsitePolicies customHeaderFields]):
(-[_WKWebsitePolicies setCustomHeaderFields:]):
(-[_WKWebsitePolicies websiteDataStore]):
(-[_WKWebsitePolicies setWebsiteDataStore:]):
(-[_WKWebsitePolicies setCustomUserAgent:]):
(-[_WKWebsitePolicies customUserAgent]):
(-[_WKWebsitePolicies setCustomJavaScriptUserAgentAsSiteSpecificQuirks:]):
(-[_WKWebsitePolicies customJavaScriptUserAgentAsSiteSpecificQuirks]):
(-[_WKWebsitePolicies setCustomNavigatorPlatform:]):
(-[_WKWebsitePolicies customNavigatorPlatform]):
(-[_WKWebsitePolicies description]):
(-[_WKWebsitePolicies _apiObject]):
(-[_WKWebsitePolicies dealloc]): Deleted.
* UIProcess/API/Cocoa/_WKWebsitePoliciesInternal.h:
* UIProcess/Cocoa/NavigationState.mm:
(WebKit::NavigationState::NavigationClient::decidePolicyForNavigationAction):
* WebKit.xcodeproj/project.pbxproj:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@243726 268f45cc-cd09-0410-ab3c-d52691b4dbfc

13 files changed:
Source/WebKit/ChangeLog
Source/WebKit/Shared/Cocoa/APIObject.mm
Source/WebKit/SourcesCocoa.txt
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferences.h [new file with mode: 0644]
Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferences.mm [new file with mode: 0644]
Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferencesInternal.h [new file with mode: 0644]
Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferencesPrivate.h [new file with mode: 0644]
Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.h
Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.mm
Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePoliciesInternal.h
Source/WebKit/UIProcess/Cocoa/NavigationState.mm
Source/WebKit/WebKit.xcodeproj/project.pbxproj

index 14ef532..644593e 100644 (file)
@@ -1,5 +1,99 @@
 2019-04-01  Wenson Hsieh  <wenson_hsieh@apple.com>
 
+        [WebKit2] Introduce a public version of WKWebsitePolicies
+        https://bugs.webkit.org/show_bug.cgi?id=195989
+        <rdar://problem/47228232>
+
+        Reviewed by Tim Horton.
+
+        Expose the existing _WKWebsitePolicies object as WKWebpagePreferences, in what will eventually become a public
+        header in the WebKit SDK (WKWebpagePreferences.h). Following a similar transitioning strategy as
+        _WKWebsiteDataStore and WKWebsiteDataStore, we move existing logic from _WKWebsitePolicies to WKWebpagePreferences
+        and make _WKWebsitePolicies a wrapper around WKWebpagePreferences.
+
+        No change in behavior.
+
+        * Shared/Cocoa/APIObject.mm:
+        (API::Object::newObject):
+
+        Wrap API::WebsitePolicies with WKWebpagePreferences.
+
+        * SourcesCocoa.txt:
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _updateWebsitePolicies:]):
+        * UIProcess/API/Cocoa/WKWebpagePreferences.h: Copied from Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePoliciesInternal.h.
+        * UIProcess/API/Cocoa/WKWebpagePreferences.mm: Copied from Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.mm.
+
+        Introduce WKWebpagePreferences.
+
+        (+[WKWebpagePreferences defaultPreferences]):
+        (-[WKWebpagePreferences dealloc]):
+        (-[WKWebpagePreferences init]):
+        (-[WKWebpagePreferences _setContentBlockersEnabled:]):
+        (-[WKWebpagePreferences _contentBlockersEnabled]):
+        (-[WKWebpagePreferences _setAllowedAutoplayQuirks:]):
+        (-[WKWebpagePreferences _allowedAutoplayQuirks]):
+        (-[WKWebpagePreferences _setAutoplayPolicy:]):
+        (-[WKWebpagePreferences _autoplayPolicy]):
+        (-[WKWebpagePreferences _setDeviceOrientationAndMotionAccessPolicy:]):
+        (-[WKWebpagePreferences _deviceOrientationAndMotionAccessPolicy]):
+        (-[WKWebpagePreferences _setPopUpPolicy:]):
+        (-[WKWebpagePreferences _popUpPolicy]):
+        (-[WKWebpagePreferences _customHeaderFields]):
+        (-[WKWebpagePreferences _setCustomHeaderFields:]):
+        (-[WKWebpagePreferences _websiteDataStore]):
+        (-[WKWebpagePreferences _setWebsiteDataStore:]):
+        (-[WKWebpagePreferences _setCustomUserAgent:]):
+        (-[WKWebpagePreferences _customUserAgent]):
+        (-[WKWebpagePreferences _setCustomJavaScriptUserAgentAsSiteSpecificQuirks:]):
+        (-[WKWebpagePreferences _customJavaScriptUserAgentAsSiteSpecificQuirks]):
+        (-[WKWebpagePreferences _setCustomNavigatorPlatform:]):
+        (-[WKWebpagePreferences _customNavigatorPlatform]):
+        (-[WKWebpagePreferences _apiObject]):
+        * UIProcess/API/Cocoa/WKWebpagePreferencesInternal.h: Copied from Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePoliciesInternal.h.
+        * UIProcess/API/Cocoa/WKWebpagePreferencesPrivate.h: Copied from Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.h.
+
+        Reintroduce all the interfaces currently available on _WKWebsitePolicies as underscore-prefixed SPI on
+        WKWebpagePreferences.
+
+        * UIProcess/API/Cocoa/_WKWebsitePolicies.h:
+        * UIProcess/API/Cocoa/_WKWebsitePolicies.mm:
+
+        Make _WKWebsitePolicies wrap WKWebpagePreferences, and plumb all existing SPI on WKWebsitePolicies through to
+        WKWebpagePreferences.
+
+        (-[_WKWebsitePolicies init]):
+        (-[_WKWebsitePolicies webpagePreferences]):
+        (-[_WKWebsitePolicies setContentBlockersEnabled:]):
+        (-[_WKWebsitePolicies contentBlockersEnabled]):
+        (-[_WKWebsitePolicies setAllowedAutoplayQuirks:]):
+        (-[_WKWebsitePolicies allowedAutoplayQuirks]):
+        (-[_WKWebsitePolicies setAutoplayPolicy:]):
+        (-[_WKWebsitePolicies autoplayPolicy]):
+        (-[_WKWebsitePolicies setDeviceOrientationAndMotionAccessPolicy:]):
+        (-[_WKWebsitePolicies deviceOrientationAndMotionAccessPolicy]):
+        (-[_WKWebsitePolicies setPopUpPolicy:]):
+        (-[_WKWebsitePolicies popUpPolicy]):
+        (-[_WKWebsitePolicies customHeaderFields]):
+        (-[_WKWebsitePolicies setCustomHeaderFields:]):
+        (-[_WKWebsitePolicies websiteDataStore]):
+        (-[_WKWebsitePolicies setWebsiteDataStore:]):
+        (-[_WKWebsitePolicies setCustomUserAgent:]):
+        (-[_WKWebsitePolicies customUserAgent]):
+        (-[_WKWebsitePolicies setCustomJavaScriptUserAgentAsSiteSpecificQuirks:]):
+        (-[_WKWebsitePolicies customJavaScriptUserAgentAsSiteSpecificQuirks]):
+        (-[_WKWebsitePolicies setCustomNavigatorPlatform:]):
+        (-[_WKWebsitePolicies customNavigatorPlatform]):
+        (-[_WKWebsitePolicies description]):
+        (-[_WKWebsitePolicies _apiObject]):
+        (-[_WKWebsitePolicies dealloc]): Deleted.
+        * UIProcess/API/Cocoa/_WKWebsitePoliciesInternal.h:
+        * UIProcess/Cocoa/NavigationState.mm:
+        (WebKit::NavigationState::NavigationClient::decidePolicyForNavigationAction):
+        * WebKit.xcodeproj/project.pbxproj:
+
+2019-04-01  Wenson Hsieh  <wenson_hsieh@apple.com>
+
         Unable to copy and paste a PDF from Notes into Mail compose body
         https://bugs.webkit.org/show_bug.cgi?id=196442
         <rdar://problem/48573098>
index c3be21c..37b9009 100644 (file)
@@ -63,6 +63,7 @@
 #import "WKWebProcessPlugInPageGroupInternal.h"
 #import "WKWebProcessPlugInRangeHandleInternal.h"
 #import "WKWebProcessPlugInScriptWorldInternal.h"
+#import "WKWebpagePreferencesInternal.h"
 #import "WKWebsiteDataRecordInternal.h"
 #import "WKWebsiteDataStoreInternal.h"
 #import "WKWindowFeaturesInternal.h"
@@ -82,7 +83,6 @@
 #import "_WKUserStyleSheetInternal.h"
 #import "_WKVisitedLinkStoreInternal.h"
 #import "_WKWebsiteDataStoreConfigurationInternal.h"
-#import "_WKWebsitePoliciesInternal.h"
 
 #if ENABLE(APPLICATION_MANIFEST)
 #import "_WKApplicationManifestInternal.h"
@@ -346,7 +346,7 @@ void* Object::newObject(size_t size, Type type)
         break;
 
     case Type::WebsitePolicies:
-        wrapper = [_WKWebsitePolicies alloc];
+        wrapper = [WKWebpagePreferences alloc];
         break;
 
     case Type::WindowFeatures:
index 351164f..f2277fa 100644 (file)
@@ -306,6 +306,7 @@ UIProcess/API/Cocoa/WKWebsiteDataRecord.mm
 UIProcess/API/Cocoa/WKWebsiteDataStore.mm
 UIProcess/API/Cocoa/WKWebView.mm
 UIProcess/API/Cocoa/WKWebViewConfiguration.mm
+UIProcess/API/Cocoa/WKWebpagePreferences.mm
 UIProcess/API/Cocoa/WKWindowFeatures.mm
 
 UIProcess/API/mac/WKView.mm
index d8e9436..d64ad9c 100644 (file)
@@ -77,6 +77,7 @@
 #import "WKUserContentControllerInternal.h"
 #import "WKWebViewConfigurationInternal.h"
 #import "WKWebViewContentProvider.h"
+#import "WKWebpagePreferencesInternal.h"
 #import "WKWebsiteDataStoreInternal.h"
 #import "WebBackForwardList.h"
 #import "WebCertificateInfo.h"
@@ -5128,7 +5129,7 @@ FOR_EACH_PRIVATE_WKCONTENTVIEW_ACTION(FORWARD_ACTION_TO_WKCONTENTVIEW)
 
 - (void)_updateWebsitePolicies:(_WKWebsitePolicies *)websitePolicies
 {
-    auto data = websitePolicies->_websitePolicies->data();
+    auto data = websitePolicies.webpagePreferences->_websitePolicies->data();
     if (data.websiteDataStoreParameters)
         [NSException raise:NSInvalidArgumentException format:@"Updating WKWebsiteDataStore is only supported during decidePolicyForNavigationAction."];
     _page->updateWebsitePolicies(WTFMove(data));
diff --git a/Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferences.h b/Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferences.h
new file mode 100644 (file)
index 0000000..c96726e
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <WebKit/WKFoundation.h>
+
+/*! A WKWebpagePreferences object is a collection of properties that
+ determine the preferences to use when loading and rendering a page.
+ @discussion Contains properties used to determine webpage preferences.
+ */
+WK_CLASS_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA))
+@interface WKWebpagePreferences : NSObject
+
+@end
diff --git a/Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferences.mm b/Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferences.mm
new file mode 100644 (file)
index 0000000..ac178dc
--- /dev/null
@@ -0,0 +1,255 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "WKWebpagePreferences.h"
+
+#import "WKWebpagePreferencesInternal.h"
+#import "WKWebsiteDataStoreInternal.h"
+#import "_WKWebsitePoliciesInternal.h"
+#import <wtf/RetainPtr.h>
+
+@implementation WKWebpagePreferences
+
++ (instancetype)defaultPreferences
+{
+    return [[[self alloc] init] autorelease];
+}
+
+- (void)dealloc
+{
+    _websitePolicies->API::WebsitePolicies::~WebsitePolicies();
+
+    [super dealloc];
+}
+
+- (instancetype)init
+{
+    if (!(self = [super init]))
+        return nil;
+
+    API::Object::constructInWrapper<API::WebsitePolicies>(self);
+
+    return self;
+}
+
+- (void)_setContentBlockersEnabled:(BOOL)contentBlockersEnabled
+{
+    _websitePolicies->setContentBlockersEnabled(contentBlockersEnabled);
+}
+
+- (BOOL)_contentBlockersEnabled
+{
+    return _websitePolicies->contentBlockersEnabled();
+}
+
+- (void)_setAllowedAutoplayQuirks:(_WKWebsiteAutoplayQuirk)allowedQuirks
+{
+    OptionSet<WebKit::WebsiteAutoplayQuirk> quirks;
+
+    if (allowedQuirks & _WKWebsiteAutoplayQuirkInheritedUserGestures)
+        quirks.add(WebKit::WebsiteAutoplayQuirk::InheritedUserGestures);
+
+    if (allowedQuirks & _WKWebsiteAutoplayQuirkSynthesizedPauseEvents)
+        quirks.add(WebKit::WebsiteAutoplayQuirk::SynthesizedPauseEvents);
+
+    if (allowedQuirks & _WKWebsiteAutoplayQuirkArbitraryUserGestures)
+        quirks.add(WebKit::WebsiteAutoplayQuirk::ArbitraryUserGestures);
+
+    if (allowedQuirks & _WKWebsiteAutoplayQuirkPerDocumentAutoplayBehavior)
+        quirks.add(WebKit::WebsiteAutoplayQuirk::PerDocumentAutoplayBehavior);
+
+    _websitePolicies->setAllowedAutoplayQuirks(quirks);
+}
+
+- (_WKWebsiteAutoplayQuirk)_allowedAutoplayQuirks
+{
+    _WKWebsiteAutoplayQuirk quirks = 0;
+    auto allowedQuirks = _websitePolicies->allowedAutoplayQuirks();
+
+    if (allowedQuirks.contains(WebKit::WebsiteAutoplayQuirk::InheritedUserGestures))
+        quirks |= _WKWebsiteAutoplayQuirkInheritedUserGestures;
+
+    if (allowedQuirks.contains(WebKit::WebsiteAutoplayQuirk::SynthesizedPauseEvents))
+        quirks |= _WKWebsiteAutoplayQuirkSynthesizedPauseEvents;
+
+    if (allowedQuirks.contains(WebKit::WebsiteAutoplayQuirk::ArbitraryUserGestures))
+        quirks |= _WKWebsiteAutoplayQuirkArbitraryUserGestures;
+
+    if (allowedQuirks.contains(WebKit::WebsiteAutoplayQuirk::PerDocumentAutoplayBehavior))
+        quirks |= _WKWebsiteAutoplayQuirkPerDocumentAutoplayBehavior;
+
+    return quirks;
+}
+
+- (void)_setAutoplayPolicy:(_WKWebsiteAutoplayPolicy)policy
+{
+    switch (policy) {
+    case _WKWebsiteAutoplayPolicyDefault:
+        _websitePolicies->setAutoplayPolicy(WebKit::WebsiteAutoplayPolicy::Default);
+        break;
+    case _WKWebsiteAutoplayPolicyAllow:
+        _websitePolicies->setAutoplayPolicy(WebKit::WebsiteAutoplayPolicy::Allow);
+        break;
+    case _WKWebsiteAutoplayPolicyAllowWithoutSound:
+        _websitePolicies->setAutoplayPolicy(WebKit::WebsiteAutoplayPolicy::AllowWithoutSound);
+        break;
+    case _WKWebsiteAutoplayPolicyDeny:
+        _websitePolicies->setAutoplayPolicy(WebKit::WebsiteAutoplayPolicy::Deny);
+        break;
+    }
+}
+
+- (_WKWebsiteAutoplayPolicy)_autoplayPolicy
+{
+    switch (_websitePolicies->autoplayPolicy()) {
+    case WebKit::WebsiteAutoplayPolicy::Default:
+        return _WKWebsiteAutoplayPolicyDefault;
+    case WebKit::WebsiteAutoplayPolicy::Allow:
+        return _WKWebsiteAutoplayPolicyAllow;
+    case WebKit::WebsiteAutoplayPolicy::AllowWithoutSound:
+        return _WKWebsiteAutoplayPolicyAllowWithoutSound;
+    case WebKit::WebsiteAutoplayPolicy::Deny:
+        return _WKWebsiteAutoplayPolicyDeny;
+    }
+}
+
+- (void)_setDeviceOrientationAndMotionAccessPolicy:(_WKWebsiteDeviceOrientationAndMotionAccessPolicy)policy
+{
+    switch (policy) {
+    case _WKWebsiteDeviceOrientationAndMotionAccessPolicyAsk:
+        _websitePolicies->setDeviceOrientationAndMotionAccessState(WTF::nullopt);
+        break;
+    case _WKWebsiteDeviceOrientationAndMotionAccessPolicyGrant:
+        _websitePolicies->setDeviceOrientationAndMotionAccessState(true);
+        break;
+    case _WKWebsiteDeviceOrientationAndMotionAccessPolicyDeny:
+        _websitePolicies->setDeviceOrientationAndMotionAccessState(false);
+        break;
+    }
+}
+
+- (_WKWebsiteDeviceOrientationAndMotionAccessPolicy)_deviceOrientationAndMotionAccessPolicy
+{
+    if (!_websitePolicies->deviceOrientationAndMotionAccessState())
+        return _WKWebsiteDeviceOrientationAndMotionAccessPolicyAsk;
+    return *_websitePolicies->deviceOrientationAndMotionAccessState() ? _WKWebsiteDeviceOrientationAndMotionAccessPolicyGrant : _WKWebsiteDeviceOrientationAndMotionAccessPolicyDeny;
+}
+
+- (void)_setPopUpPolicy:(_WKWebsitePopUpPolicy)policy
+{
+    switch (policy) {
+    case _WKWebsitePopUpPolicyDefault:
+        _websitePolicies->setPopUpPolicy(WebKit::WebsitePopUpPolicy::Default);
+        break;
+    case _WKWebsitePopUpPolicyAllow:
+        _websitePolicies->setPopUpPolicy(WebKit::WebsitePopUpPolicy::Allow);
+        break;
+    case _WKWebsitePopUpPolicyBlock:
+        _websitePolicies->setPopUpPolicy(WebKit::WebsitePopUpPolicy::Block);
+        break;
+    }
+}
+
+- (_WKWebsitePopUpPolicy)_popUpPolicy
+{
+    switch (_websitePolicies->popUpPolicy()) {
+    case WebKit::WebsitePopUpPolicy::Default:
+        return _WKWebsitePopUpPolicyDefault;
+    case WebKit::WebsitePopUpPolicy::Allow:
+        return _WKWebsitePopUpPolicyAllow;
+    case WebKit::WebsitePopUpPolicy::Block:
+        return _WKWebsitePopUpPolicyBlock;
+    }
+}
+
+- (NSDictionary<NSString *, NSString *> *)_customHeaderFields
+{
+    const auto& fields = _websitePolicies->customHeaderFields();
+    auto dictionary = adoptNS([[NSMutableDictionary alloc] initWithCapacity:fields.size()]);
+    for (const auto& field : fields)
+        [dictionary setObject:field.value() forKey:field.name()];
+    return dictionary.autorelease();
+}
+
+- (void)_setCustomHeaderFields:(NSDictionary<NSString *, NSString *> *)fields
+{
+    Vector<WebCore::HTTPHeaderField> parsedFields;
+    parsedFields.reserveInitialCapacity(fields.count);
+
+    for (NSString *name in fields) {
+        auto field = WebCore::HTTPHeaderField::create(name, [fields objectForKey:name]);
+        if (field && startsWithLettersIgnoringASCIICase(field->name(), "x-"))
+            parsedFields.uncheckedAppend(WTFMove(*field));
+    }
+    _websitePolicies->setCustomHeaderFields(WTFMove(parsedFields));
+}
+
+- (WKWebsiteDataStore *)_websiteDataStore
+{
+    return wrapper(_websitePolicies->websiteDataStore());
+}
+
+- (void)_setWebsiteDataStore:(WKWebsiteDataStore *)websiteDataStore
+{
+    _websitePolicies->setWebsiteDataStore(websiteDataStore->_websiteDataStore.get());
+}
+
+- (void)_setCustomUserAgent:(NSString *)customUserAgent
+{
+    _websitePolicies->setCustomUserAgent(customUserAgent);
+}
+
+- (NSString *)_customUserAgent
+{
+    return _websitePolicies->customUserAgent();
+}
+
+- (void)_setCustomJavaScriptUserAgentAsSiteSpecificQuirks:(NSString *)customUserAgent
+{
+    _websitePolicies->setCustomJavaScriptUserAgentAsSiteSpecificQuirks(customUserAgent);
+}
+
+- (NSString *)_customJavaScriptUserAgentAsSiteSpecificQuirks
+{
+    return _websitePolicies->customJavaScriptUserAgentAsSiteSpecificQuirks();
+}
+
+- (void)_setCustomNavigatorPlatform:(NSString *)customNavigatorPlatform
+{
+    _websitePolicies->setCustomNavigatorPlatform(customNavigatorPlatform);
+}
+
+- (NSString *)_customNavigatorPlatform
+{
+    return _websitePolicies->customNavigatorPlatform();
+}
+
+- (API::Object&)_apiObject
+{
+    return *_websitePolicies;
+}
+
+@end
diff --git a/Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferencesInternal.h b/Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferencesInternal.h
new file mode 100644 (file)
index 0000000..6d8130f
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#import "APIWebsitePolicies.h"
+#import "WKObject.h"
+#import "WKWebpagePreferencesPrivate.h"
+#import "_WKWebsitePolicies.h"
+
+namespace WebKit {
+
+template<> struct WrapperTraits<API::WebsitePolicies> {
+    using WrapperClass = WKWebpagePreferences;
+};
+
+}
+
+@interface WKWebpagePreferences () <WKObject> {
+@package
+    API::ObjectStorage<API::WebsitePolicies> _websitePolicies;
+}
+
+@property (class, nonatomic, readonly) WKWebpagePreferences *defaultPreferences;
+@end
diff --git a/Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferencesPrivate.h b/Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferencesPrivate.h
new file mode 100644 (file)
index 0000000..66a2ebc
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#import <WebKit/WKFoundation.h>
+#import <WebKit/WKWebpagePreferences.h>
+#import <WebKit/WKWebsiteDataStore.h>
+
+typedef NS_ENUM(NSInteger, _WKWebsiteAutoplayPolicy) {
+    _WKWebsiteAutoplayPolicyDefault,
+    _WKWebsiteAutoplayPolicyAllow,
+    _WKWebsiteAutoplayPolicyAllowWithoutSound,
+    _WKWebsiteAutoplayPolicyDeny
+} WK_API_AVAILABLE(macos(10.13), ios(11.0));
+
+typedef NS_OPTIONS(NSUInteger, _WKWebsiteAutoplayQuirk) {
+    _WKWebsiteAutoplayQuirkSynthesizedPauseEvents = 1 << 0,
+    _WKWebsiteAutoplayQuirkInheritedUserGestures = 1 << 1,
+    _WKWebsiteAutoplayQuirkArbitraryUserGestures = 1 << 2,
+    _WKWebsiteAutoplayQuirkPerDocumentAutoplayBehavior = 1 << 3,
+} WK_API_AVAILABLE(macos(10.13), ios(11.0));
+
+typedef NS_OPTIONS(NSUInteger, _WKWebsitePopUpPolicy) {
+    _WKWebsitePopUpPolicyDefault,
+    _WKWebsitePopUpPolicyAllow,
+    _WKWebsitePopUpPolicyBlock,
+} WK_API_AVAILABLE(macos(10.14), ios(12.0));
+
+typedef NS_OPTIONS(NSUInteger, _WKWebsiteDeviceOrientationAndMotionAccessPolicy) {
+    _WKWebsiteDeviceOrientationAndMotionAccessPolicyAsk,
+    _WKWebsiteDeviceOrientationAndMotionAccessPolicyGrant,
+    _WKWebsiteDeviceOrientationAndMotionAccessPolicyDeny,
+} WK_API_AVAILABLE(macos(10.14), ios(12.0));
+
+@interface WKWebpagePreferences (WKPrivate)
+
+@property (nonatomic, setter=_setContentBlockersEnabled:) BOOL _contentBlockersEnabled;
+@property (nonatomic, setter=_setAllowedAutoplayQuirks:) _WKWebsiteAutoplayQuirk _allowedAutoplayQuirks;
+@property (nonatomic, setter=_setAutoplayPolicy:) _WKWebsiteAutoplayPolicy _autoplayPolicy;
+@property (nonatomic, copy, setter=_setCustomHeaderFields:) NSDictionary<NSString *, NSString *> *_customHeaderFields;
+@property (nonatomic, setter=_setPopUpPolicy:) _WKWebsitePopUpPolicy _popUpPolicy;
+@property (nonatomic, strong, setter=_setWebsiteDataStore:) WKWebsiteDataStore *_websiteDataStore;
+@property (nonatomic, copy, setter=_setCustomUserAgent:) NSString *_customUserAgent;
+@property (nonatomic, copy, setter=_setCustomJavaScriptUserAgentAsSiteSpecificQuirks:) NSString *_customJavaScriptUserAgentAsSiteSpecificQuirks;
+@property (nonatomic, copy, setter=_setCustomNavigatorPlatform:) NSString *_customNavigatorPlatform;
+@property (nonatomic, setter=_setDeviceOrientationAndMotionAccessPolicy:) _WKWebsiteDeviceOrientationAndMotionAccessPolicy _deviceOrientationAndMotionAccessPolicy;
+
+@end
index 0d9b3ff..f8ca908 100644 (file)
  */
 
 #import <WebKit/WKFoundation.h>
-
-typedef NS_ENUM(NSInteger, _WKWebsiteAutoplayPolicy) {
-    _WKWebsiteAutoplayPolicyDefault,
-    _WKWebsiteAutoplayPolicyAllow,
-    _WKWebsiteAutoplayPolicyAllowWithoutSound,
-    _WKWebsiteAutoplayPolicyDeny
-} WK_API_AVAILABLE(macos(10.13), ios(11.0));
-
-typedef NS_OPTIONS(NSUInteger, _WKWebsiteAutoplayQuirk) {
-    _WKWebsiteAutoplayQuirkSynthesizedPauseEvents = 1 << 0,
-    _WKWebsiteAutoplayQuirkInheritedUserGestures = 1 << 1,
-    _WKWebsiteAutoplayQuirkArbitraryUserGestures = 1 << 2,
-    _WKWebsiteAutoplayQuirkPerDocumentAutoplayBehavior = 1 << 3,
-} WK_API_AVAILABLE(macos(10.13), ios(11.0));
-
-typedef NS_OPTIONS(NSUInteger, _WKWebsitePopUpPolicy) {
-    _WKWebsitePopUpPolicyDefault,
-    _WKWebsitePopUpPolicyAllow,
-    _WKWebsitePopUpPolicyBlock,
-} WK_API_AVAILABLE(macos(10.14), ios(12.0));
-
-typedef NS_OPTIONS(NSUInteger, _WKWebsiteDeviceOrientationAndMotionAccessPolicy) {
-    _WKWebsiteDeviceOrientationAndMotionAccessPolicyAsk,
-    _WKWebsiteDeviceOrientationAndMotionAccessPolicyGrant,
-    _WKWebsiteDeviceOrientationAndMotionAccessPolicyDeny,
-} WK_API_AVAILABLE(macos(10.14), ios(12.0));
+#import <WebKit/WKWebpagePreferencesPrivate.h>
 
 @class WKWebsiteDataStore;
 
index d5e9c91..c57bd9d 100644 (file)
  */
 
 #import "config.h"
-#import "_WKWebsitePoliciesInternal.h"
 
+#import "WKWebpagePreferencesInternal.h"
 #import "WKWebsiteDataStoreInternal.h"
+#import "_WKWebsitePoliciesInternal.h"
 
 @implementation _WKWebsitePolicies
 
-- (void)dealloc
-{
-    _websitePolicies->API::WebsitePolicies::~WebsitePolicies();
-    
-    [super dealloc];
-}
-
 - (instancetype)init
 {
     if (!(self = [super init]))
         return nil;
-    
-    API::Object::constructInWrapper<API::WebsitePolicies>(self);
-    
+
+    _webpagePreferences = adoptNS([[WKWebpagePreferences alloc] init]);
     return self;
 }
 
+- (WKWebpagePreferences *)webpagePreferences
+{
+    return _webpagePreferences.get();
+}
+
 - (void)setContentBlockersEnabled:(BOOL)contentBlockersEnabled
 {
-    _websitePolicies->setContentBlockersEnabled(contentBlockersEnabled);
+    [_webpagePreferences _setContentBlockersEnabled:contentBlockersEnabled];
 }
 
 - (BOOL)contentBlockersEnabled
 {
-    return _websitePolicies->contentBlockersEnabled();
+    return [_webpagePreferences _contentBlockersEnabled];
 }
 
 - (void)setAllowedAutoplayQuirks:(_WKWebsiteAutoplayQuirk)allowedQuirks
 {
-    OptionSet<WebKit::WebsiteAutoplayQuirk> quirks;
-
-    if (allowedQuirks & _WKWebsiteAutoplayQuirkInheritedUserGestures)
-        quirks.add(WebKit::WebsiteAutoplayQuirk::InheritedUserGestures);
-
-    if (allowedQuirks & _WKWebsiteAutoplayQuirkSynthesizedPauseEvents)
-        quirks.add(WebKit::WebsiteAutoplayQuirk::SynthesizedPauseEvents);
-
-    if (allowedQuirks & _WKWebsiteAutoplayQuirkArbitraryUserGestures)
-        quirks.add(WebKit::WebsiteAutoplayQuirk::ArbitraryUserGestures);
-
-    if (allowedQuirks & _WKWebsiteAutoplayQuirkPerDocumentAutoplayBehavior)
-        quirks.add(WebKit::WebsiteAutoplayQuirk::PerDocumentAutoplayBehavior);
-
-    _websitePolicies->setAllowedAutoplayQuirks(quirks);
+    [_webpagePreferences _setAllowedAutoplayQuirks:allowedQuirks];
 }
 
 - (_WKWebsiteAutoplayQuirk)allowedAutoplayQuirks
 {
-    _WKWebsiteAutoplayQuirk quirks = 0;
-    auto allowedQuirks = _websitePolicies->allowedAutoplayQuirks();
-
-    if (allowedQuirks.contains(WebKit::WebsiteAutoplayQuirk::InheritedUserGestures))
-        quirks |= _WKWebsiteAutoplayQuirkInheritedUserGestures;
-
-    if (allowedQuirks.contains(WebKit::WebsiteAutoplayQuirk::SynthesizedPauseEvents))
-        quirks |= _WKWebsiteAutoplayQuirkSynthesizedPauseEvents;
-
-    if (allowedQuirks.contains(WebKit::WebsiteAutoplayQuirk::ArbitraryUserGestures))
-        quirks |= _WKWebsiteAutoplayQuirkArbitraryUserGestures;
-
-    if (allowedQuirks.contains(WebKit::WebsiteAutoplayQuirk::PerDocumentAutoplayBehavior))
-        quirks |= _WKWebsiteAutoplayQuirkPerDocumentAutoplayBehavior;
-
-    return quirks;
+    return [_webpagePreferences _allowedAutoplayQuirks];
 }
 
 - (void)setAutoplayPolicy:(_WKWebsiteAutoplayPolicy)policy
 {
-    switch (policy) {
-    case _WKWebsiteAutoplayPolicyDefault:
-        _websitePolicies->setAutoplayPolicy(WebKit::WebsiteAutoplayPolicy::Default);
-        break;
-    case _WKWebsiteAutoplayPolicyAllow:
-        _websitePolicies->setAutoplayPolicy(WebKit::WebsiteAutoplayPolicy::Allow);
-        break;
-    case _WKWebsiteAutoplayPolicyAllowWithoutSound:
-        _websitePolicies->setAutoplayPolicy(WebKit::WebsiteAutoplayPolicy::AllowWithoutSound);
-        break;
-    case _WKWebsiteAutoplayPolicyDeny:
-        _websitePolicies->setAutoplayPolicy(WebKit::WebsiteAutoplayPolicy::Deny);
-        break;
-    }
+    [_webpagePreferences _setAutoplayPolicy:policy];
 }
 
 - (_WKWebsiteAutoplayPolicy)autoplayPolicy
 {
-    switch (_websitePolicies->autoplayPolicy()) {
-    case WebKit::WebsiteAutoplayPolicy::Default:
-        return _WKWebsiteAutoplayPolicyDefault;
-    case WebKit::WebsiteAutoplayPolicy::Allow:
-        return _WKWebsiteAutoplayPolicyAllow;
-    case WebKit::WebsiteAutoplayPolicy::AllowWithoutSound:
-        return _WKWebsiteAutoplayPolicyAllowWithoutSound;
-    case WebKit::WebsiteAutoplayPolicy::Deny:
-        return _WKWebsiteAutoplayPolicyDeny;
-    }
+    return [_webpagePreferences _autoplayPolicy];
 }
 
 - (void)setDeviceOrientationAndMotionAccessPolicy:(_WKWebsiteDeviceOrientationAndMotionAccessPolicy)policy
 {
-    switch (policy) {
-    case _WKWebsiteDeviceOrientationAndMotionAccessPolicyAsk:
-        _websitePolicies->setDeviceOrientationAndMotionAccessState(WTF::nullopt);
-        break;
-    case _WKWebsiteDeviceOrientationAndMotionAccessPolicyGrant:
-        _websitePolicies->setDeviceOrientationAndMotionAccessState(true);
-        break;
-    case _WKWebsiteDeviceOrientationAndMotionAccessPolicyDeny:
-        _websitePolicies->setDeviceOrientationAndMotionAccessState(false);
-        break;
-    }
+    [_webpagePreferences _setDeviceOrientationAndMotionAccessPolicy:policy];
 }
 
 - (_WKWebsiteDeviceOrientationAndMotionAccessPolicy)deviceOrientationAndMotionAccessPolicy
 {
-    if (!_websitePolicies->deviceOrientationAndMotionAccessState())
-        return _WKWebsiteDeviceOrientationAndMotionAccessPolicyAsk;
-    return *_websitePolicies->deviceOrientationAndMotionAccessState() ? _WKWebsiteDeviceOrientationAndMotionAccessPolicyGrant : _WKWebsiteDeviceOrientationAndMotionAccessPolicyDeny;
+    return [_webpagePreferences _deviceOrientationAndMotionAccessPolicy];
 }
 
 - (void)setPopUpPolicy:(_WKWebsitePopUpPolicy)policy
 {
-    switch (policy) {
-    case _WKWebsitePopUpPolicyDefault:
-        _websitePolicies->setPopUpPolicy(WebKit::WebsitePopUpPolicy::Default);
-        break;
-    case _WKWebsitePopUpPolicyAllow:
-        _websitePolicies->setPopUpPolicy(WebKit::WebsitePopUpPolicy::Allow);
-        break;
-    case _WKWebsitePopUpPolicyBlock:
-        _websitePolicies->setPopUpPolicy(WebKit::WebsitePopUpPolicy::Block);
-        break;
-    }
+    [_webpagePreferences _setPopUpPolicy:policy];
 }
 
 - (_WKWebsitePopUpPolicy)popUpPolicy
 {
-    switch (_websitePolicies->popUpPolicy()) {
-    case WebKit::WebsitePopUpPolicy::Default:
-        return _WKWebsitePopUpPolicyDefault;
-    case WebKit::WebsitePopUpPolicy::Allow:
-        return _WKWebsitePopUpPolicyAllow;
-    case WebKit::WebsitePopUpPolicy::Block:
-        return _WKWebsitePopUpPolicyBlock;
-    }
+    return [_webpagePreferences _popUpPolicy];
 }
 
 - (NSDictionary<NSString *, NSString *> *)customHeaderFields
 {
-    const auto& fields = _websitePolicies->customHeaderFields();
-    NSMutableDictionary *dictionary = [[[NSMutableDictionary alloc] initWithCapacity:fields.size()] autorelease];
-    for (const auto& field : fields)
-        [dictionary setObject:field.value() forKey:field.name()];
-    return dictionary;
+    return [_webpagePreferences _customHeaderFields];
 }
 
 - (void)setCustomHeaderFields:(NSDictionary<NSString *, NSString *> *)fields
 {
-    Vector<WebCore::HTTPHeaderField> parsedFields;
-    parsedFields.reserveInitialCapacity(fields.count);
-    
-    for (NSString* name in fields) {
-        auto field = WebCore::HTTPHeaderField::create(name, [fields objectForKey:name]);
-        if (field && startsWithLettersIgnoringASCIICase(field->name(), "x-"))
-            parsedFields.uncheckedAppend(WTFMove(*field));
-    }
-    _websitePolicies->setCustomHeaderFields(WTFMove(parsedFields));
+    [_webpagePreferences _setCustomHeaderFields:fields];
 }
 
 - (WKWebsiteDataStore *)websiteDataStore
 {
-    return wrapper(_websitePolicies->websiteDataStore());
+    return [_webpagePreferences _websiteDataStore];
 }
 
 - (void)setWebsiteDataStore:(WKWebsiteDataStore *)websiteDataStore
 {
-    _websitePolicies->setWebsiteDataStore(websiteDataStore->_websiteDataStore.get());
+    [_webpagePreferences _setWebsiteDataStore:websiteDataStore];
 }
 
 - (void)setCustomUserAgent:(NSString *)customUserAgent
 {
-    _websitePolicies->setCustomUserAgent(customUserAgent);
+    [_webpagePreferences _setCustomUserAgent:customUserAgent];
 }
 
 - (NSString *)customUserAgent
 {
-    return _websitePolicies->customUserAgent();
+    return [_webpagePreferences _customUserAgent];
 }
 
 - (void)setCustomJavaScriptUserAgentAsSiteSpecificQuirks:(NSString *)customUserAgent
 {
-    _websitePolicies->setCustomJavaScriptUserAgentAsSiteSpecificQuirks(customUserAgent);
+    [_webpagePreferences _setCustomJavaScriptUserAgentAsSiteSpecificQuirks:customUserAgent];
 }
 
 - (NSString *)customJavaScriptUserAgentAsSiteSpecificQuirks
 {
-    return _websitePolicies->customJavaScriptUserAgentAsSiteSpecificQuirks();
+    return [_webpagePreferences _customJavaScriptUserAgentAsSiteSpecificQuirks];
 }
 
 - (void)setCustomNavigatorPlatform:(NSString *)customNavigatorPlatform
 {
-    _websitePolicies->setCustomNavigatorPlatform(customNavigatorPlatform);
+    [_webpagePreferences _setCustomNavigatorPlatform:customNavigatorPlatform];
 }
 
 - (NSString *)customNavigatorPlatform
 {
-    return _websitePolicies->customNavigatorPlatform();
+    return [_webpagePreferences _customNavigatorPlatform];
 }
 
 - (NSString *)description
 {
-    return [NSString stringWithFormat:@"<%@: %p; contentBlockersEnabled = %d>", NSStringFromClass(self.class), self, self.contentBlockersEnabled];
+    return [NSString stringWithFormat:@"<%@ %@>", self.class, [_webpagePreferences description]];
 }
 
 - (API::Object&)_apiObject
 {
-    return *_websitePolicies;
+    return [_webpagePreferences _apiObject];
 }
 
 @end
index aae6b02..23e5461 100644 (file)
  */
 
 #import "_WKWebsitePolicies.h"
+#import <wtf/RetainPtr.h>
 
-#import "APIWebsitePolicies.h"
-#import "WKObject.h"
+@class WKWebpagePreferences;
 
-namespace WebKit {
-
-template<> struct WrapperTraits<API::WebsitePolicies> {
-    using WrapperClass = _WKWebsitePolicies;
-};
-
-}
-
-@interface _WKWebsitePolicies () <WKObject> {
+@interface _WKWebsitePolicies ()
+{
 @package
-    API::ObjectStorage<API::WebsitePolicies> _websitePolicies;
+    RetainPtr<WKWebpagePreferences> _webpagePreferences;
 }
+
+@property (nonatomic, readonly) WKWebpagePreferences *webpagePreferences;
+
 @end
index 524063a..ead5795 100644 (file)
@@ -54,6 +54,7 @@
 #import "WKNavigationResponseInternal.h"
 #import "WKReloadFrameErrorRecoveryAttempter.h"
 #import "WKWebViewInternal.h"
+#import "WKWebpagePreferencesInternal.h"
 #import "WebCredential.h"
 #import "WebFrameProxy.h"
 #import "WebNavigationState.h"
@@ -556,7 +557,7 @@ void NavigationState::NavigationClient::decidePolicyForNavigationAction(WebPageP
             return;
         checker->didCallCompletionHandler();
 
-        RefPtr<API::WebsitePolicies> apiWebsitePolicies = websitePolicies ? websitePolicies->_websitePolicies.get() : nullptr;
+        RefPtr<API::WebsitePolicies> apiWebsitePolicies = [websitePolicies webpagePreferences] ? [websitePolicies webpagePreferences]->_websitePolicies.get() : nullptr;
         if (apiWebsitePolicies) {
             if (auto* websiteDataStore = apiWebsitePolicies->websiteDataStore()) {
                 auto sessionID = websiteDataStore->websiteDataStore().sessionID();
index fff1a5e..f6fdfd6 100644 (file)
                ECA680D81E690E2500731D20 /* WebProcessCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = ECA680D71E690DF800731D20 /* WebProcessCocoa.h */; settings = {ATTRIBUTES = (Private, ); }; };
                ED82A7F2128C6FAF004477B3 /* WKBundlePageOverlay.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A22F0FF1289FCD90085E74F /* WKBundlePageOverlay.h */; settings = {ATTRIBUTES = (Private, ); }; };
                F409BA181E6E64BC009DA28E /* WKDragDestinationAction.h in Headers */ = {isa = PBXBuildFile; fileRef = F409BA171E6E64B3009DA28E /* WKDragDestinationAction.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               F438CD1C2241421400DE6DDA /* WKWebpagePreferences.h in Headers */ = {isa = PBXBuildFile; fileRef = F438CD1B224140A600DE6DDA /* WKWebpagePreferences.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               F438CD1F22414D4000DE6DDA /* WKWebpagePreferencesInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = F438CD1E22414D4000DE6DDA /* WKWebpagePreferencesInternal.h */; };
+               F438CD212241F69500DE6DDA /* WKWebpagePreferencesPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = F438CD202241F69500DE6DDA /* WKWebpagePreferencesPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
                F44291921FA591C9002CC93E /* _WKAttachment.h in Headers */ = {isa = PBXBuildFile; fileRef = F44291911FA59107002CC93E /* _WKAttachment.h */; settings = {ATTRIBUTES = (Private, ); }; };
                F44291961FA5942A002CC93E /* _WKAttachmentInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = F44291951FA5942A002CC93E /* _WKAttachmentInternal.h */; };
                F44DFEB21E9E752F0038D196 /* WebIconUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = F44DFEB01E9E752F0038D196 /* WebIconUtilities.h */; };
                F409BA171E6E64B3009DA28E /* WKDragDestinationAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKDragDestinationAction.h; sourceTree = "<group>"; };
                F40D1B68220BDC0F00B49A01 /* WebAutocorrectionContext.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = WebAutocorrectionContext.h; path = ios/WebAutocorrectionContext.h; sourceTree = "<group>"; };
                F41056612130699A0092281D /* APIAttachmentCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = APIAttachmentCocoa.mm; sourceTree = "<group>"; };
+               F438CD1B224140A600DE6DDA /* WKWebpagePreferences.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WKWebpagePreferences.h; sourceTree = "<group>"; };
+               F438CD1D22414AD600DE6DDA /* WKWebpagePreferences.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebpagePreferences.mm; sourceTree = "<group>"; };
+               F438CD1E22414D4000DE6DDA /* WKWebpagePreferencesInternal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WKWebpagePreferencesInternal.h; sourceTree = "<group>"; };
+               F438CD202241F69500DE6DDA /* WKWebpagePreferencesPrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WKWebpagePreferencesPrivate.h; sourceTree = "<group>"; };
                F44291911FA59107002CC93E /* _WKAttachment.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = _WKAttachment.h; sourceTree = "<group>"; };
                F44291931FA59311002CC93E /* _WKAttachment.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = _WKAttachment.mm; sourceTree = "<group>"; };
                F44291951FA5942A002CC93E /* _WKAttachmentInternal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = _WKAttachmentInternal.h; sourceTree = "<group>"; };
                                1AAF089819267EE500B6390C /* WKUserScript.mm */,
                                1AAF089C19267FC800B6390C /* WKUserScriptInternal.h */,
                                7C882DF61C7E995E006BF731 /* WKUserScriptPrivate.h */,
+                               F438CD1B224140A600DE6DDA /* WKWebpagePreferences.h */,
+                               F438CD1D22414AD600DE6DDA /* WKWebpagePreferences.mm */,
+                               F438CD1E22414D4000DE6DDA /* WKWebpagePreferencesInternal.h */,
+                               F438CD202241F69500DE6DDA /* WKWebpagePreferencesPrivate.h */,
                                1A4832CA1A9BC465008B4DFE /* WKWebsiteDataRecord.h */,
                                1A4832C91A9BC465008B4DFE /* WKWebsiteDataRecord.mm */,
                                1A4832CD1A9BC484008B4DFE /* WKWebsiteDataRecordInternal.h */,
                                C5E1AFE916B20B75006CC1F2 /* WKWebArchive.h in Headers */,
                                C5E1AFEB16B20B7E006CC1F2 /* WKWebArchiveResource.h in Headers */,
                                2D1E8223216FFF5100A15265 /* WKWebEvent.h in Headers */,
+                               F438CD1C2241421400DE6DDA /* WKWebpagePreferences.h in Headers */,
+                               F438CD1F22414D4000DE6DDA /* WKWebpagePreferencesInternal.h in Headers */,
+                               F438CD212241F69500DE6DDA /* WKWebpagePreferencesPrivate.h in Headers */,
                                5CADDE05215046BD0067D309 /* WKWebProcess.h in Headers */,
                                1AA2E56718D77508003814BD /* WKWebProcessBundleParameters.h in Headers */,
                                BC989D82161A7E5D000D46D3 /* WKWebProcessPlugIn.h in Headers */,