[Cocoa] Add new API around WKWebpagePreferences in WKNavigationDelegate and WKWebView...
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 3 Apr 2019 04:58:04 +0000 (04:58 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 3 Apr 2019 04:58:04 +0000 (04:58 +0000)
https://bugs.webkit.org/show_bug.cgi?id=196284
<rdar://problem/47228232>

Reviewed by Tim Horton.

Tests for both of these APIs will be added in a subsequent patch.

* Shared/API/Cocoa/WebKit.h:
* UIProcess/API/APIPageConfiguration.cpp:
(API::PageConfiguration::defaultWebsitePolicies const):
(API::PageConfiguration::setDefaultWebsitePolicies):
* UIProcess/API/APIPageConfiguration.h:
* UIProcess/API/Cocoa/WKNavigationDelegate.h:

Add a new navigation delegate hook to allow clients to return a WKWebpagePreference targeting the given
navigation action.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _initializeWithConfiguration:]):
* UIProcess/API/Cocoa/WKWebViewConfiguration.h:
* UIProcess/API/Cocoa/WKWebViewConfiguration.mm:

Add new API on WKWebViewConfiguration to specify a default WKWebpagePreference to use when navigating.

(-[WKWebViewConfiguration copyWithZone:]):
(-[WKWebViewConfiguration defaultWebpagePreferences]):
(-[WKWebViewConfiguration setDefaultWebpagePreferences:]):
* UIProcess/API/Cocoa/WKWebpagePreferences.h:
* UIProcess/Cocoa/NavigationState.h:
* UIProcess/Cocoa/NavigationState.mm:
(WebKit::NavigationState::setNavigationDelegate):
(WebKit::NavigationState::NavigationClient::decidePolicyForNavigationAction):

Invoke the new WKWebpagePreferences-based navigation delegate method.

* WebKit.xcodeproj/project.pbxproj:
* mac/postprocess-framework-headers.sh:
* mac/replace-webkit-additions-in-framework-headers.sh: Added.

Move logic in the "Postprocess Framework Headers" step responsible for stripping away included files from
WebKitAdditions out into a separate build phase, called "Replace WebKitAdditions in Framework Headers". This
ensures headers attempting to include from WebKitAdditions have these additional statements removed.

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

13 files changed:
Source/WebKit/ChangeLog
Source/WebKit/Shared/API/Cocoa/WebKit.h
Source/WebKit/UIProcess/API/APIPageConfiguration.cpp
Source/WebKit/UIProcess/API/APIPageConfiguration.h
Source/WebKit/UIProcess/API/Cocoa/WKNavigationDelegate.h
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfiguration.h
Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfiguration.mm
Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferences.h
Source/WebKit/UIProcess/Cocoa/NavigationState.h
Source/WebKit/UIProcess/Cocoa/NavigationState.mm
Source/WebKit/WebKit.xcodeproj/project.pbxproj
Source/WebKit/mac/postprocess-framework-headers.sh

index ea97a6a..6f64af9 100644 (file)
@@ -1,3 +1,49 @@
+2019-04-02  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [Cocoa] Add new API around WKWebpagePreferences in WKNavigationDelegate and WKWebViewConfiguration
+        https://bugs.webkit.org/show_bug.cgi?id=196284
+        <rdar://problem/47228232>
+
+        Reviewed by Tim Horton.
+
+        Tests for both of these APIs will be added in a subsequent patch.
+
+        * Shared/API/Cocoa/WebKit.h:
+        * UIProcess/API/APIPageConfiguration.cpp:
+        (API::PageConfiguration::defaultWebsitePolicies const):
+        (API::PageConfiguration::setDefaultWebsitePolicies):
+        * UIProcess/API/APIPageConfiguration.h:
+        * UIProcess/API/Cocoa/WKNavigationDelegate.h:
+
+        Add a new navigation delegate hook to allow clients to return a WKWebpagePreference targeting the given
+        navigation action.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _initializeWithConfiguration:]):
+        * UIProcess/API/Cocoa/WKWebViewConfiguration.h:
+        * UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
+
+        Add new API on WKWebViewConfiguration to specify a default WKWebpagePreference to use when navigating.
+
+        (-[WKWebViewConfiguration copyWithZone:]):
+        (-[WKWebViewConfiguration defaultWebpagePreferences]):
+        (-[WKWebViewConfiguration setDefaultWebpagePreferences:]):
+        * UIProcess/API/Cocoa/WKWebpagePreferences.h:
+        * UIProcess/Cocoa/NavigationState.h:
+        * UIProcess/Cocoa/NavigationState.mm:
+        (WebKit::NavigationState::setNavigationDelegate):
+        (WebKit::NavigationState::NavigationClient::decidePolicyForNavigationAction):
+
+        Invoke the new WKWebpagePreferences-based navigation delegate method.
+
+        * WebKit.xcodeproj/project.pbxproj:
+        * mac/postprocess-framework-headers.sh:
+        * mac/replace-webkit-additions-in-framework-headers.sh: Added.
+
+        Move logic in the "Postprocess Framework Headers" step responsible for stripping away included files from
+        WebKitAdditions out into a separate build phase, called "Replace WebKitAdditions in Framework Headers". This
+        ensures headers attempting to include from WebKitAdditions have these additional statements removed.
+
 2019-04-02  Geoffrey Garen  <ggaren@apple.com>
 
         Eliminate plugin sandbox exceptions
index 53fc53d..4b48a40 100644 (file)
@@ -52,6 +52,7 @@
 #import <WebKit/WKUserScript.h>
 #import <WebKit/WKWebView.h>
 #import <WebKit/WKWebViewConfiguration.h>
+#import <WebKit/WKWebpagePreferences.h>
 #import <WebKit/WKWebsiteDataRecord.h>
 #import <WebKit/WKWebsiteDataStore.h>
 #import <WebKit/WKWindowFeatures.h>
index 1f049c2..177b999 100644 (file)
@@ -27,6 +27,7 @@
 #include "APIPageConfiguration.h"
 
 #include "APIProcessPoolConfiguration.h"
+#include "APIWebsitePolicies.h"
 #include "WebPageGroup.h"
 #include "WebPageProxy.h"
 #include "WebPreferences.h"
@@ -164,6 +165,16 @@ void PageConfiguration::setWebsiteDataStore(API::WebsiteDataStore* websiteDataSt
         m_sessionID = PAL::SessionID();
 }
 
+WebsitePolicies* PageConfiguration::defaultWebsitePolicies() const
+{
+    return m_defaultWebsitePolicies.get();
+}
+
+void PageConfiguration::setDefaultWebsitePolicies(WebsitePolicies* policies)
+{
+    m_defaultWebsitePolicies = policies;
+}
+
 PAL::SessionID PageConfiguration::sessionID()
 {
     ASSERT(!m_websiteDataStore || m_websiteDataStore->websiteDataStore().sessionID() == m_sessionID || m_sessionID == PAL::SessionID::legacyPrivateSessionID());
index b5fa6ff..64a494a 100644 (file)
@@ -45,6 +45,7 @@ namespace API {
 
 class ApplicationManifest;
 class WebsiteDataStore;
+class WebsitePolicies;
 
 class PageConfiguration : public ObjectImpl<Object::Type::PageConfiguration> {
 public:
@@ -81,6 +82,9 @@ public:
     WebsiteDataStore* websiteDataStore();
     void setWebsiteDataStore(WebsiteDataStore*);
 
+    WebsitePolicies* defaultWebsitePolicies() const;
+    void setDefaultWebsitePolicies(WebsitePolicies*);
+
     // FIXME: Once PageConfigurations *always* have a data store, get rid of the separate sessionID.
     PAL::SessionID sessionID();
     void setSessionID(PAL::SessionID);
@@ -135,6 +139,7 @@ private:
     RefPtr<WebKit::VisitedLinkStore> m_visitedLinkStore;
 
     RefPtr<WebsiteDataStore> m_websiteDataStore;
+    RefPtr<WebsitePolicies> m_defaultWebsitePolicies;
     // FIXME: We currently have to pass the session ID separately here to support the legacy private browsing session.
     // Once we get rid of it we should get rid of this configuration parameter as well.
     PAL::SessionID m_sessionID;
index 8ee462c..e4b54e9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014 Apple Inc. All rights reserved.
+ * Copyright (C) 2014-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
@@ -33,6 +33,7 @@ NS_ASSUME_NONNULL_BEGIN
 @class WKNavigationAction;
 @class WKNavigationResponse;
 @class WKWebView;
+@class WKWebpagePreferences;
 
 /*! @enum WKNavigationActionPolicy
  @abstract The policy to pass back to the decision handler from the
@@ -73,6 +74,20 @@ typedef NS_ENUM(NSInteger, WKNavigationResponsePolicy) {
  */
 - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler;
 
+/*! @abstract Decides whether to allow or cancel a navigation.
+ @param webView The web view invoking the delegate method.
+ @param navigationAction Descriptive information about the action
+ triggering the navigation request.
+ @param preferences The default set of webpage preferences. This may be
+ changed by setting defaultWebpagePreferences on WKWebViewConfiguration.
+ @param decisionHandler The policy decision handler to call to allow or cancel
+ the navigation. The arguments are one of the constants of the enumerated type
+ WKNavigationActionPolicy, as well as an instance of WKWebpagePreferences.
+ @discussion If you implement this method,
+ -webView:decidePolicyForNavigationAction:decisionHandler: will not be called.
+ */
+- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction withPreferences:(WKWebpagePreferences *)preferences decisionHandler:(void (^)(WKNavigationActionPolicy, WKWebpagePreferences *))decisionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+
 /*! @abstract Decides whether to allow or cancel a navigation after its
  response is known.
  @param webView The web view invoking the delegate method.
index d64ad9c..cf40032 100644 (file)
@@ -574,6 +574,7 @@ static void validate(WKWebViewConfiguration *configuration)
     pageConfiguration->setUserContentController([_configuration userContentController]->_userContentControllerProxy.get());
     pageConfiguration->setVisitedLinkStore([_configuration _visitedLinkStore]->_visitedLinkStore.get());
     pageConfiguration->setWebsiteDataStore([_configuration websiteDataStore]->_websiteDataStore.get());
+    pageConfiguration->setDefaultWebsitePolicies([_configuration defaultWebpagePreferences]->_websitePolicies.get());
 
 #if PLATFORM(MAC)
     if (auto pageGroup = WebKit::toImpl([configuration _pageGroup])) {
index 75faded..42d24a9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014-2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2014-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
@@ -33,6 +33,7 @@ NS_ASSUME_NONNULL_BEGIN
 @class WKPreferences;
 @class WKProcessPool;
 @class WKUserContentController;
+@class WKWebpagePreferences;
 @class WKWebsiteDataStore;
 @protocol WKURLSchemeHandler;
 
@@ -129,6 +130,12 @@ WK_CLASS_AVAILABLE(macos(10.10), ios(8.0))
 
 @property (nonatomic) WKAudiovisualMediaTypes mediaTypesRequiringUserActionForPlayback WK_API_AVAILABLE(macos(10.12), ios(10.0));
 
+/*! @abstract The set of default webpage preferences to use when loading and rendering content.
+ @discussion These default webpage preferences are additionally passed to the navigation delegate
+ in -webView:decidePolicyForNavigationAction:withPreferences:decisionHandler:.
+ */
+@property (null_resettable, nonatomic, copy) WKWebpagePreferences *defaultWebpagePreferences WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+
 #if TARGET_OS_IPHONE
 /*! @abstract A Boolean value indicating whether HTML5 videos play inline
  (YES) or use the native full-screen controller (NO).
index d602aaf..7e8916a 100644 (file)
@@ -118,6 +118,7 @@ static bool defaultShouldDecidePolicyBeforeLoadingQuickLookPreview()
     LazyInitialized<RetainPtr<WKUserContentController>> _userContentController;
     LazyInitialized<RetainPtr<_WKVisitedLinkStore>> _visitedLinkStore;
     LazyInitialized<RetainPtr<WKWebsiteDataStore>> _websiteDataStore;
+    LazyInitialized<RetainPtr<WKWebpagePreferences>> _defaultWebpagePreferences;
     WeakObjCPtr<WKWebView> _relatedWebView;
     WeakObjCPtr<WKWebView> _alternateWebViewForNavigationGestures;
     RetainPtr<NSString> _groupIdentifier;
@@ -357,6 +358,7 @@ static bool defaultShouldDecidePolicyBeforeLoadingQuickLookPreview()
     configuration.preferences = self.preferences;
     configuration.userContentController = self.userContentController;
     configuration.websiteDataStore = self.websiteDataStore;
+    configuration.defaultWebpagePreferences = self.defaultWebpagePreferences;
     configuration._visitedLinkStore = self._visitedLinkStore;
     configuration._relatedWebView = _relatedWebView.get().get();
     configuration._alternateWebViewForNavigationGestures = _alternateWebViewForNavigationGestures.get().get();
@@ -473,6 +475,18 @@ static bool defaultShouldDecidePolicyBeforeLoadingQuickLookPreview()
     _websiteDataStore.set(websiteDataStore);
 }
 
+- (WKWebpagePreferences *)defaultWebpagePreferences
+{
+    return _defaultWebpagePreferences.get([] {
+        return WKWebpagePreferences.defaultPreferences;
+    });
+}
+
+- (void)setDefaultWebpagePreferences:(WKWebpagePreferences *)defaultWebpagePreferences
+{
+    _defaultWebpagePreferences.set(defaultWebpagePreferences ?: WKWebpagePreferences.defaultPreferences);
+}
+
 static NSString *defaultApplicationNameForUserAgent()
 {
 #if PLATFORM(IOS_FAMILY)
index c96726e..5b13663 100644 (file)
 
 #import <WebKit/WKFoundation.h>
 
+#if USE(APPLE_INTERNAL_SDK)
+#import <WebKitAdditions/WKWebpagePreferencesAdditionsBefore.h>
+#endif
+
 /*! 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.
@@ -32,4 +36,8 @@
 WK_CLASS_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA))
 @interface WKWebpagePreferences : NSObject
 
+#if USE(APPLE_INTERNAL_SDK)
+#import <WebKitAdditions/WKWebpagePreferencesAdditionsAfter.h>
+#endif
+
 @end
index 1f0d5f4..da6bf5c 100644 (file)
@@ -186,6 +186,7 @@ private:
 
     struct {
         bool webViewDecidePolicyForNavigationActionDecisionHandler : 1;
+        bool webViewDecidePolicyForNavigationActionWithPreferencesDecisionHandler : 1;
         bool webViewDecidePolicyForNavigationActionDecisionHandlerWebsitePolicies : 1;
         bool webViewDecidePolicyForNavigationActionUserInfoDecisionHandlerWebsitePolicies : 1;
         bool webViewDecidePolicyForNavigationResponseDecisionHandler : 1;
index 54cdf51..32c6591 100644 (file)
@@ -30,6 +30,7 @@
 #import "APIFrameInfo.h"
 #import "APINavigationData.h"
 #import "APINavigationResponse.h"
+#import "APIPageConfiguration.h"
 #import "APIString.h"
 #import "APIURL.h"
 #import "APIWebsiteDataStore.h"
@@ -148,6 +149,7 @@ void NavigationState::setNavigationDelegate(id <WKNavigationDelegate> delegate)
     m_navigationDelegate = delegate;
 
     m_navigationDelegateMethods.webViewDecidePolicyForNavigationActionDecisionHandler = [delegate respondsToSelector:@selector(webView:decidePolicyForNavigationAction:decisionHandler:)];
+    m_navigationDelegateMethods.webViewDecidePolicyForNavigationActionWithPreferencesDecisionHandler = [delegate respondsToSelector:@selector(webView:decidePolicyForNavigationAction:withPreferences:decisionHandler:)];
     m_navigationDelegateMethods.webViewDecidePolicyForNavigationActionDecisionHandlerWebsitePolicies = [delegate respondsToSelector:@selector(_webView:decidePolicyForNavigationAction:decisionHandler:)];
     m_navigationDelegateMethods.webViewDecidePolicyForNavigationActionUserInfoDecisionHandlerWebsitePolicies = [delegate respondsToSelector:@selector(_webView:decidePolicyForNavigationAction:userInfo:decisionHandler:)];
     m_navigationDelegateMethods.webViewDecidePolicyForNavigationResponseDecisionHandler = [delegate respondsToSelector:@selector(webView:decidePolicyForNavigationResponse:decisionHandler:)];
@@ -508,18 +510,20 @@ static void tryInterceptNavigation(Ref<API::NavigationAction>&& navigationAction
 void NavigationState::NavigationClient::decidePolicyForNavigationAction(WebPageProxy& webPageProxy, Ref<API::NavigationAction>&& navigationAction, Ref<WebFramePolicyListenerProxy>&& listener, API::Object* userInfo)
 {
     bool subframeNavigation = navigationAction->targetFrame() && !navigationAction->targetFrame()->isMainFrame();
+    auto defaultWebsitePolicies = makeRefPtr(webPageProxy.configuration().defaultWebsitePolicies());
 
     if (!m_navigationState.m_navigationDelegateMethods.webViewDecidePolicyForNavigationActionDecisionHandler
+        && !m_navigationState.m_navigationDelegateMethods.webViewDecidePolicyForNavigationActionWithPreferencesDecisionHandler
         && !m_navigationState.m_navigationDelegateMethods.webViewDecidePolicyForNavigationActionDecisionHandlerWebsitePolicies
         && !m_navigationState.m_navigationDelegateMethods.webViewDecidePolicyForNavigationActionUserInfoDecisionHandlerWebsitePolicies) {
-        auto completionHandler = [webPage = makeRef(webPageProxy), listener = WTFMove(listener), navigationAction = navigationAction.copyRef()] (bool interceptedNavigation) {
+        auto completionHandler = [webPage = makeRef(webPageProxy), listener = WTFMove(listener), navigationAction = navigationAction.copyRef(), defaultWebsitePolicies] (bool interceptedNavigation) {
             if (interceptedNavigation) {
                 listener->ignore();
                 return;
             }
 
             if (!navigationAction->targetFrame()) {
-                listener->use();
+                listener->use(defaultWebsitePolicies.get());
                 return;
             }
 
@@ -528,7 +532,7 @@ void NavigationState::NavigationClient::decidePolicyForNavigationAction(WebPageP
                 if (navigationAction->shouldPerformDownload())
                     listener->download();
                 else
-                    listener->use();
+                    listener->use(defaultWebsitePolicies.get());
                 return;
             }
 
@@ -548,11 +552,19 @@ void NavigationState::NavigationClient::decidePolicyForNavigationAction(WebPageP
     if (!navigationDelegate)
         return;
 
+    bool delegateHasWebpagePreferences = m_navigationState.m_navigationDelegateMethods.webViewDecidePolicyForNavigationActionWithPreferencesDecisionHandler;
     bool delegateHasWebsitePolicies = m_navigationState.m_navigationDelegateMethods.webViewDecidePolicyForNavigationActionDecisionHandlerWebsitePolicies || m_navigationState.m_navigationDelegateMethods.webViewDecidePolicyForNavigationActionUserInfoDecisionHandlerWebsitePolicies;
-    
-    auto checker = CompletionHandlerCallChecker::create(navigationDelegate.get(), delegateHasWebsitePolicies ? @selector(_webView:decidePolicyForNavigationAction:decisionHandler:) : @selector(webView:decidePolicyForNavigationAction:decisionHandler:));
-    
-    auto decisionHandlerWithPolicies = [localListener = WTFMove(listener), navigationAction = navigationAction.copyRef(), checker = WTFMove(checker), webPageProxy = makeRef(webPageProxy), subframeNavigation](WKNavigationActionPolicy actionPolicy, id policiesOrPreferences) mutable {
+
+    auto selectorForCompletionHandlerChecker = ([&] () -> SEL {
+        if (delegateHasWebpagePreferences)
+            return @selector(webView:decidePolicyForNavigationAction:withPreferences:decisionHandler:);
+        if (delegateHasWebsitePolicies)
+            return @selector(_webView:decidePolicyForNavigationAction:decisionHandler:);
+        return @selector(webView:decidePolicyForNavigationAction:decisionHandler:);
+    })();
+
+    auto checker = CompletionHandlerCallChecker::create(navigationDelegate.get(), selectorForCompletionHandlerChecker);
+    auto decisionHandlerWithPreferencesOrPolicies = [localListener = WTFMove(listener), navigationAction = navigationAction.copyRef(), checker = WTFMove(checker), webPageProxy = makeRef(webPageProxy), subframeNavigation, defaultWebsitePolicies] (WKNavigationActionPolicy actionPolicy, id policiesOrPreferences) mutable {
         if (checker->completionHandlerHasBeenCalled())
             return;
         checker->didCallCompletionHandler();
@@ -564,19 +576,21 @@ void NavigationState::NavigationClient::decidePolicyForNavigationAction(WebPageP
             apiWebsitePolicies = [policiesOrPreferences webpagePreferences]->_websitePolicies.get();
         else if (policiesOrPreferences)
             [NSException raise:NSInvalidArgumentException format:@"Expected policies of class %@, but got %@", NSStringFromClass(_WKWebsitePolicies.self), [policiesOrPreferences class]];
+        else
+            apiWebsitePolicies = defaultWebsitePolicies;
 
         if (apiWebsitePolicies) {
             if (auto* websiteDataStore = apiWebsitePolicies->websiteDataStore()) {
                 auto sessionID = websiteDataStore->websiteDataStore().sessionID();
                 if (!sessionID.isEphemeral() && sessionID != PAL::SessionID::defaultSessionID())
-                    [NSException raise:NSInvalidArgumentException format:@"_WKWebsitePolicies.websiteDataStore must be nil, default, or non-persistent."];
+                    [NSException raise:NSInvalidArgumentException format:@"WKWebpagePreferences._websiteDataStore must be nil, default, or non-persistent."];
                 if (subframeNavigation)
-                    [NSException raise:NSInvalidArgumentException format:@"_WKWebsitePolicies.websiteDataStore must be nil for subframe navigations."];
+                    [NSException raise:NSInvalidArgumentException format:@"WKWebpagePreferences._websiteDataStore must be nil for subframe navigations."];
             }
             if (!apiWebsitePolicies->customUserAgent().isNull() && subframeNavigation)
-                [NSException raise:NSInvalidArgumentException format:@"_WKWebsitePolicies.customUserAgent must be nil for subframe navigations."];
+                [NSException raise:NSInvalidArgumentException format:@"WKWebpagePreferences._customUserAgent must be nil for subframe navigations."];
             if (!apiWebsitePolicies->customNavigatorPlatform().isNull() && subframeNavigation)
-                [NSException raise:NSInvalidArgumentException format:@"_WKWebsitePolicies.customNavigatorPlatform must be nil for subframe navigations."];
+                [NSException raise:NSInvalidArgumentException format:@"WKWebpagePreferences._customNavigatorPlatform must be nil for subframe navigations."];
         }
 
         switch (actionPolicy) {
@@ -612,9 +626,11 @@ void NavigationState::NavigationClient::decidePolicyForNavigationAction(WebPageP
             break;
         }
     };
-    
-    if (delegateHasWebsitePolicies) {
-        auto decisionHandler = makeBlockPtr(WTFMove(decisionHandlerWithPolicies));
+
+    if (delegateHasWebpagePreferences)
+        [navigationDelegate webView:m_navigationState.m_webView decidePolicyForNavigationAction:wrapper(navigationAction) withPreferences:wrapper(defaultWebsitePolicies) decisionHandler:makeBlockPtr(WTFMove(decisionHandlerWithPreferencesOrPolicies)).get()];
+    else if (delegateHasWebsitePolicies) {
+        auto decisionHandler = makeBlockPtr(WTFMove(decisionHandlerWithPreferencesOrPolicies));
         if (m_navigationState.m_navigationDelegateMethods.webViewDecidePolicyForNavigationActionUserInfoDecisionHandlerWebsitePolicies)
             [(id <WKNavigationDelegatePrivate>)navigationDelegate _webView:m_navigationState.m_webView decidePolicyForNavigationAction:wrapper(navigationAction) userInfo:userInfo ? static_cast<id <NSSecureCoding>>(userInfo->wrapper()) : nil decisionHandler:decisionHandler.get()];
         else {
@@ -623,10 +639,10 @@ void NavigationState::NavigationClient::decidePolicyForNavigationAction(WebPageP
             ALLOW_DEPRECATED_DECLARATIONS_END
         }
     } else {
-        auto decisionHandlerWithoutPolicies = [decisionHandlerWithPolicies = WTFMove(decisionHandlerWithPolicies)] (WKNavigationActionPolicy actionPolicy) mutable {
-            decisionHandlerWithPolicies(actionPolicy, nil);
+        auto decisionHandler = [decisionHandlerWithPreferencesOrPolicies = WTFMove(decisionHandlerWithPreferencesOrPolicies)] (WKNavigationActionPolicy actionPolicy) mutable {
+            decisionHandlerWithPreferencesOrPolicies(actionPolicy, nil);
         };
-        [navigationDelegate webView:m_navigationState.m_webView decidePolicyForNavigationAction:wrapper(navigationAction) decisionHandler:makeBlockPtr(WTFMove(decisionHandlerWithoutPolicies)).get()];
+        [navigationDelegate webView:m_navigationState.m_webView decidePolicyForNavigationAction:wrapper(navigationAction) decisionHandler:makeBlockPtr(WTFMove(decisionHandler)).get()];
     }
 }
 
index 7f5ffda..ccb5011 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, ); }; };
+               F438CD1C2241421400DE6DDA /* WKWebpagePreferences.h in Headers */ = {isa = PBXBuildFile; fileRef = F438CD1B224140A600DE6DDA /* WKWebpagePreferences.h */; settings = {ATTRIBUTES = (Public, ); }; };
                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, ); }; };
                        children = (
                                1A8B66B21BC45B010082DF77 /* WKBundleMac.h */,
                                1A8B66B11BC45B010082DF77 /* WKBundleMac.mm */,
-                               C6A4CA092252899800169289 /* WKBundlePageMac.h */,
-                               C6A4CA0A2252899800169289 /* WKBundlePageMac.mm */,
                                7CF47FFD17276AE3008ACB91 /* WKBundlePageBannerMac.h */,
                                7CF47FFC17276AE3008ACB91 /* WKBundlePageBannerMac.mm */,
+                               C6A4CA092252899800169289 /* WKBundlePageMac.h */,
+                               C6A4CA0A2252899800169289 /* WKBundlePageMac.mm */,
                        );
                        path = mac;
                        sourceTree = "<group>";
                                1AB474E6184D44B40051B622 /* WKBundlePageFullScreenClient.h in Headers */,
                                BC7B633D12A45D1200D174A4 /* WKBundlePageGroup.h in Headers */,
                                1AB474D8184D43FD0051B622 /* WKBundlePageLoaderClient.h in Headers */,
+                               C6A4CA0B2252899800169289 /* WKBundlePageMac.h in Headers */,
                                ED82A7F2128C6FAF004477B3 /* WKBundlePageOverlay.h in Headers */,
                                1AB474EA184D45130051B622 /* WKBundlePagePolicyClient.h in Headers */,
                                BC1B419811D41D570011E8DD /* WKBundlePagePrivate.h in Headers */,
                                1AB474DE184D44590051B622 /* WKBundlePageUIClient.h in Headers */,
                                BCF049E711FE20F600F86A58 /* WKBundlePrivate.h in Headers */,
                                BC60C5791240A546008C5E29 /* WKBundleRangeHandle.h in Headers */,
-                               C6A4CA0B2252899800169289 /* WKBundlePageMac.h in Headers */,
                                BC5D24C716CD73C5007D5461 /* WKBundleRangeHandlePrivate.h in Headers */,
                                BC14DF9F120B635F00826C0C /* WKBundleScriptWorld.h in Headers */,
                                BC4075F6124FF0270068F20A /* WKCertificateInfo.h in Headers */,
                                1A6280C81919956B006AD9F9 /* Migrate WebKitLegacy Headers */,
                                375A248817E5048E00C9A086 /* Postprocess WKBase.h */,
                                1AD98ECF191D867300CAA6DF /* Postprocess WKFoundation.h */,
+                               F4EFBAD522540CBB00049BA6 /* Replace WebKitAdditions in Framework Headers */,
                                1A1D2115191D96380001619F /* Postprocess Framework Headers */,
                                2E16B6F42019BC25008996D6 /* Copy Additional Resources */,
                                8DC2EF520486A6940098B216 /* Resources */,
                        shellPath = /bin/sh;
                        shellScript = "UNLOCK_SCRIPT_PATH=\"${SRCROOT}/../../../Internal/Tools/Scripts/unlock-safari-engineering-keychain-if-needed\"\n\n[[ -x \"${UNLOCK_SCRIPT_PATH}\" ]] && exec \"${UNLOCK_SCRIPT_PATH}\"\n\nexit 0\n";
                };
+               F4EFBAD522540CBB00049BA6 /* Replace WebKitAdditions in Framework Headers */ = {
+                       isa = PBXShellScriptBuildPhase;
+                       buildActionMask = 2147483647;
+                       files = (
+                       );
+                       inputPaths = (
+                       );
+                       name = "Replace WebKitAdditions in Framework Headers";
+                       outputPaths = (
+                       );
+                       runOnlyForDeploymentPostprocessing = 0;
+                       shellPath = /bin/sh;
+                       shellScript = "if [ \"${ACTION}\" = \"build\" -o \"${ACTION}\" = \"install\" -o \"${ACTION}\" = \"installhdrs\" -o \"${ACTION}\" = \"installapi\" ]; then\n    for HEADERS_DIRECTORY in \"${PUBLIC_HEADERS_FOLDER_PATH}\" \"${PRIVATE_HEADERS_FOLDER_PATH}\"; do\n        for HEADER_PATH in \"${TARGET_BUILD_DIR}/${HEADERS_DIRECTORY}/\"*.h; do\n            if [[ ! -z `grep '#import <WebKitAdditions/.*\\.h>' \"${HEADER_PATH}\"` ]]; then\n                python \"${SRCROOT}/mac/replace-webkit-additions-includes.py\" \"${HEADER_PATH}\" \"${BUILT_PRODUCTS_DIR}\" \"${SDKROOT}\" || exit $?\n            fi\n        done\n    done\nfi\n";
+               };
 /* End PBXShellScriptBuildPhase section */
 
 /* Begin PBXSourcesBuildPhase section */
                                2D11B7A72126A283006F8878 /* UnifiedSource44-mm.mm in Sources */,
                                2D11B7A82126A283006F8878 /* UnifiedSource44.cpp in Sources */,
                                2D11B7A92126A283006F8878 /* UnifiedSource45-mm.mm in Sources */,
-                               C6A4CA0C2252899800169289 /* WKBundlePageMac.mm in Sources */,
                                2D11B7AA2126A283006F8878 /* UnifiedSource45.cpp in Sources */,
                                2D11B7AB2126A283006F8878 /* UnifiedSource46-mm.mm in Sources */,
                                2D11B7AC2126A283006F8878 /* UnifiedSource46.cpp in Sources */,
                                1AAF08B719269E6D00B6390C /* WebUserContentControllerMessageReceiver.cpp in Sources */,
                                7C361D78192803BD0036A59D /* WebUserContentControllerProxyMessageReceiver.cpp in Sources */,
                                2D92A78F212B6AB100F493FD /* WebWheelEvent.cpp in Sources */,
+                               C6A4CA0C2252899800169289 /* WKBundlePageMac.mm in Sources */,
                                2D931169212F61B200044BFE /* WKContentView.mm in Sources */,
                                2D93116A212F61B500044BFE /* WKContentViewInteraction.mm in Sources */,
                                637281A321ADC744009E0DE6 /* WKDownloadProgress.mm in Sources */,
index 9d6cbab..07106b4 100755 (executable)
@@ -48,14 +48,6 @@ function process_definitions () {
     source "${DEFINITIONS_FILE}"
 }
 
-function replace_webkit_additions_includes () {
-    if [[ -z `grep '#import <WebKitAdditions/.*\.h>' "${1}"` ]]; then
-        return 0
-    fi
-    python "$(dirname $0)/replace-webkit-additions-includes.py" "${1}" "${BUILT_PRODUCTS_DIR}" "${SDKROOT}"
-    return $?
-}
-
 function rewrite_headers () {
     if [[ "${WK_PLATFORM_NAME}" == "macosx" ]]; then
         [[ -n ${OSX_VERSION} ]] || OSX_VERSION=${MACOSX_DEPLOYMENT_TARGET}
@@ -89,7 +81,6 @@ function rewrite_headers () {
     for HEADER_PATH in "${1}/"*.h; do
         if [[ "$HEADER_PATH" -nt $TIMESTAMP_PATH ]]; then
             ditto "${HEADER_PATH}" "${TARGET_TEMP_DIR}/${HEADER_PATH##*/}"
-            replace_webkit_additions_includes "${TARGET_TEMP_DIR}/${HEADER_PATH##*/}"
             sed -i .tmp -E "${SED_OPTIONS[@]}" "${TARGET_TEMP_DIR}/${HEADER_PATH##*/}" || exit $?
             mv "${TARGET_TEMP_DIR}/${HEADER_PATH##*/}" "$HEADER_PATH"
         fi