Add pop-up policy support in website policies.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 16 Jan 2018 19:12:43 +0000 (19:12 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 16 Jan 2018 19:12:43 +0000 (19:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=181544.
rdar://problem/30521400.

Patch by Zach Li <zachli@apple.com> on 2018-01-16
Reviewed by Alex Christensen.

Source/WebCore:

* loader/DocumentLoader.h:
Introduce pop-up policy getter and setter. Initialize
the policy as Default.
(WebCore::DocumentLoader::popUpPolicy const):
(WebCore::DocumentLoader::setPopUpPolicy):
* page/DOMWindow.cpp:
(WebCore::DOMWindow::allowPopUp):
Pop-up policy specified on a per-page basis holds
precedence over the global policy. If no pop-up policy
is specified during navigation, global policy is used.

Source/WebKit:

* Shared/WebsitePoliciesData.cpp: Encode and decode
pop-up policy.
(WebKit::WebsitePoliciesData::encode const):
(WebKit::WebsitePoliciesData::decode):
(WebKit::WebsitePoliciesData::applyToDocumentLoader):
Apply the pop-up policy from website policies to the
document loader.

* Shared/WebsitePoliciesData.h:

* Shared/WebsitePopUpPolicy.h:
Added for declaring enum WebsitePopUpPolicy.

* UIProcess/API/APIWforebsitePolicies.cpp:
Include pop-up policy in website policies.
(API::WebsitePolicies::WebsitePolicies):
(API::WebsitePolicies::data):
* UIProcess/API/APIWebsitePolicies.h:

* UIProcess/API/C/WKWebsitePolicies.cpp:
Added C API to get and set pop-up policy on
website policies.
(WKWebsitePoliciesGetPopUpPolicy):
(WKWebsitePoliciesSetPopUpPolicy):
* UIProcess/API/C/WKWebsitePolicies.h:

* UIProcess/API/Cocoa/_WKWebsitePolicies.h:
Added Obj-C API to get and set pop-up policy
on website policies.
* UIProcess/API/Cocoa/_WKWebsitePolicies.mm:
(-[_WKWebsitePolicies setPopUpPolicy:]):
(-[_WKWebsitePolicies popUpPolicy]):

* WebKit.xcodeproj/project.pbxproj:
Added WebsitePopUpPolicy.h.

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
Added pop-up-check.html.

* TestWebKitAPI/Tests/WebKit/pop-up-check.html: Added.

* TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm:
(-[PopUpPoliciesDelegate webView:decidePolicyForNavigationAction:decisionHandler:]):
(-[PopUpPoliciesDelegate _webView:decidePolicyForNavigationAction:decisionHandler:]):
(-[PopUpPoliciesDelegate webView:createWebViewWithConfiguration:forNavigationAction:windowFeatures:]):
(TEST):

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

18 files changed:
Source/WebCore/ChangeLog
Source/WebCore/loader/DocumentLoader.h
Source/WebCore/page/DOMWindow.cpp
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebsitePoliciesData.cpp
Source/WebKit/Shared/WebsitePoliciesData.h
Source/WebKit/Shared/WebsitePopUpPolicy.h [new file with mode: 0644]
Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp
Source/WebKit/UIProcess/API/APIWebsitePolicies.h
Source/WebKit/UIProcess/API/C/WKWebsitePolicies.cpp
Source/WebKit/UIProcess/API/C/WKWebsitePolicies.h
Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.h
Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.mm
Source/WebKit/WebKit.xcodeproj/project.pbxproj
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKit/pop-up-check.html [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm

index 68d17ca..7ae5635 100644 (file)
@@ -1,3 +1,22 @@
+2018-01-16  Zach Li  <zachli@apple.com>
+
+        Add pop-up policy support in website policies.
+        https://bugs.webkit.org/show_bug.cgi?id=181544.
+        rdar://problem/30521400.
+
+        Reviewed by Alex Christensen.
+
+        * loader/DocumentLoader.h:
+        Introduce pop-up policy getter and setter. Initialize
+        the policy as Default.
+        (WebCore::DocumentLoader::popUpPolicy const):
+        (WebCore::DocumentLoader::setPopUpPolicy):
+        * page/DOMWindow.cpp:
+        (WebCore::DOMWindow::allowPopUp):
+        Pop-up policy specified on a per-page basis holds
+        precedence over the global policy. If no pop-up policy
+        is specified during navigation, global policy is used.
+
 2018-01-16  Jer Noble  <jer.noble@apple.com>
 
         Crash playing audio-only HLS stream via hls.js (MSE)
index f5a3d35..6bdef8d 100644 (file)
@@ -99,6 +99,12 @@ enum class AutoplayQuirk {
     ArbitraryUserGestures = 1 << 2,
 };
 
+enum class PopUpPolicy {
+    Default, // Uses policies specified in frame settings.
+    Allow,
+    Block,
+};
+
 class DocumentLoader : public RefCounted<DocumentLoader>, public FrameDestructionObserver, private CachedRawResourceClient {
     WTF_MAKE_FAST_ALLOCATED;
     friend class ContentFilter;
@@ -249,6 +255,9 @@ public:
     OptionSet<AutoplayQuirk> allowedAutoplayQuirks() const { return m_allowedAutoplayQuirks; }
     void setAllowedAutoplayQuirks(OptionSet<AutoplayQuirk> allowedQuirks) { m_allowedAutoplayQuirks = allowedQuirks; }
 
+    PopUpPolicy popUpPolicy() const { return m_popUpPolicy; }
+    void setPopUpPolicy(PopUpPolicy popUpPolicy) { m_popUpPolicy = popUpPolicy; }
+
     void addSubresourceLoader(ResourceLoader*);
     void removeSubresourceLoader(ResourceLoader*);
     void addPlugInStreamLoader(ResourceLoader&);
@@ -499,6 +508,7 @@ private:
     bool m_userContentExtensionsEnabled { true };
     AutoplayPolicy m_autoplayPolicy { AutoplayPolicy::Default };
     OptionSet<AutoplayQuirk> m_allowedAutoplayQuirks;
+    PopUpPolicy m_popUpPolicy { PopUpPolicy::Default };
 
 #if ENABLE(SERVICE_WORKER)
     std::optional<ServiceWorkerRegistrationData> m_serviceWorkerRegistrationData;
index f1d1985..390e754 100644 (file)
@@ -358,6 +358,16 @@ FloatRect DOMWindow::adjustWindowRect(Page& page, const FloatRect& pendingChange
 
 bool DOMWindow::allowPopUp(Frame& firstFrame)
 {
+    if (DocumentLoader* documentLoader = firstFrame.loader().documentLoader()) {
+        // If pop-up policy was set during navigation, use it. If not, use the global settings.
+        PopUpPolicy popUpPolicy = documentLoader->popUpPolicy();
+        if (popUpPolicy == PopUpPolicy::Allow)
+            return true;
+
+        if (popUpPolicy == PopUpPolicy::Block)
+            return false;
+    }
+
     return UserGestureIndicator::processingUserGesture()
         || firstFrame.settings().javaScriptCanOpenWindowsAutomatically();
 }
index 9ebf92a..072c877 100644 (file)
@@ -1,3 +1,47 @@
+2018-01-16  Zach Li  <zachli@apple.com>
+
+        Add pop-up policy support in website policies.
+        https://bugs.webkit.org/show_bug.cgi?id=181544.
+        rdar://problem/30521400.
+
+        Reviewed by Alex Christensen.
+
+        * Shared/WebsitePoliciesData.cpp: Encode and decode
+        pop-up policy.
+        (WebKit::WebsitePoliciesData::encode const):
+        (WebKit::WebsitePoliciesData::decode):
+        (WebKit::WebsitePoliciesData::applyToDocumentLoader):
+        Apply the pop-up policy from website policies to the
+        document loader.
+
+        * Shared/WebsitePoliciesData.h:
+
+        * Shared/WebsitePopUpPolicy.h:
+        Added for declaring enum WebsitePopUpPolicy.
+
+        * UIProcess/API/APIWforebsitePolicies.cpp:
+        Include pop-up policy in website policies.
+        (API::WebsitePolicies::WebsitePolicies):
+        (API::WebsitePolicies::data):
+        * UIProcess/API/APIWebsitePolicies.h:
+
+        * UIProcess/API/C/WKWebsitePolicies.cpp:
+        Added C API to get and set pop-up policy on
+        website policies.
+        (WKWebsitePoliciesGetPopUpPolicy):
+        (WKWebsitePoliciesSetPopUpPolicy):
+        * UIProcess/API/C/WKWebsitePolicies.h:
+
+        * UIProcess/API/Cocoa/_WKWebsitePolicies.h:
+        Added Obj-C API to get and set pop-up policy
+        on website policies.
+        * UIProcess/API/Cocoa/_WKWebsitePolicies.mm:
+        (-[_WKWebsitePolicies setPopUpPolicy:]):
+        (-[_WKWebsitePolicies popUpPolicy]):
+
+        * WebKit.xcodeproj/project.pbxproj:
+        Added WebsitePopUpPolicy.h.
+
 2018-01-16  Fujii Hironori  <Hironori.Fujii@sony.com>
 
         [CMake][Mac] Fix the build errors
index 9860f01..6eb4be2 100644 (file)
@@ -40,6 +40,7 @@ void WebsitePoliciesData::encode(IPC::Encoder& encoder) const
     encoder << autoplayPolicy;
     encoder << allowedAutoplayQuirks;
     encoder << customHeaderFields;
+    encoder << popUpPolicy;
     encoder << websiteDataStoreParameters;
 }
 
@@ -64,7 +65,12 @@ std::optional<WebsitePoliciesData> WebsitePoliciesData::decode(IPC::Decoder& dec
     decoder >> customHeaderFields;
     if (!customHeaderFields)
         return std::nullopt;
-    
+
+    std::optional<WebsitePopUpPolicy> popUpPolicy;
+    decoder >> popUpPolicy;
+    if (!popUpPolicy)
+        return std::nullopt;
+
     std::optional<std::optional<WebsiteDataStoreParameters>> websiteDataStoreParameters;
     decoder >> websiteDataStoreParameters;
     if (!websiteDataStoreParameters)
@@ -75,6 +81,7 @@ std::optional<WebsitePoliciesData> WebsitePoliciesData::decode(IPC::Decoder& dec
         WTFMove(*allowedAutoplayQuirks),
         WTFMove(*autoplayPolicy),
         WTFMove(*customHeaderFields),
+        WTFMove(*popUpPolicy),
         WTFMove(*websiteDataStoreParameters),
     } };
 }
@@ -115,7 +122,19 @@ void WebsitePoliciesData::applyToDocumentLoader(WebsitePoliciesData&& websitePol
         documentLoader.setAutoplayPolicy(WebCore::AutoplayPolicy::Deny);
         break;
     }
-    
+
+    switch (websitePolicies.popUpPolicy) {
+    case WebsitePopUpPolicy::Default:
+        documentLoader.setPopUpPolicy(WebCore::PopUpPolicy::Default);
+        break;
+    case WebsitePopUpPolicy::Allow:
+        documentLoader.setPopUpPolicy(WebCore::PopUpPolicy::Allow);
+        break;
+    case WebsitePopUpPolicy::Block:
+        documentLoader.setPopUpPolicy(WebCore::PopUpPolicy::Block);
+        break;
+    }
+
     if (websitePolicies.websiteDataStoreParameters) {
         if (auto* frame = documentLoader.frame()) {
             if (auto* page = frame->page()) {
index 8c5ab33..447df65 100644 (file)
@@ -28,6 +28,7 @@
 #include "WebsiteAutoplayPolicy.h"
 #include "WebsiteAutoplayQuirk.h"
 #include "WebsiteDataStoreParameters.h"
+#include "WebsitePopUpPolicy.h"
 #include <WebCore/HTTPHeaderField.h>
 #include <wtf/OptionSet.h>
 
@@ -49,6 +50,7 @@ struct WebsitePoliciesData {
     OptionSet<WebsiteAutoplayQuirk> allowedAutoplayQuirks;
     WebsiteAutoplayPolicy autoplayPolicy { WebsiteAutoplayPolicy::Default };
     Vector<WebCore::HTTPHeaderField> customHeaderFields;
+    WebsitePopUpPolicy popUpPolicy { WebsitePopUpPolicy::Default };
     std::optional<WebsiteDataStoreParameters> websiteDataStoreParameters;
     
     void encode(IPC::Encoder&) const;
diff --git a/Source/WebKit/Shared/WebsitePopUpPolicy.h b/Source/WebKit/Shared/WebsitePopUpPolicy.h
new file mode 100644 (file)
index 0000000..7f8fb7d
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2018 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
+
+#include <wtf/EnumTraits.h>
+
+namespace WebKit {
+
+enum class WebsitePopUpPolicy {
+    Default,
+    Allow,
+    Block,
+};
+
+}
+
+namespace WTF {
+
+template<> struct EnumTraits<WebKit::WebsitePopUpPolicy> {
+    using values = EnumValues<
+        WebKit::WebsitePopUpPolicy,
+        WebKit::WebsitePopUpPolicy::Default,
+        WebKit::WebsitePopUpPolicy::Allow,
+        WebKit::WebsitePopUpPolicy::Block
+    >;
+};
+
+} // namespace WTF
+
index f2bff67..740b6b5 100644 (file)
@@ -33,11 +33,12 @@ namespace API {
 
 WebsitePolicies::WebsitePolicies() = default;
 
-WebsitePolicies::WebsitePolicies(bool contentBlockersEnabled, OptionSet<WebKit::WebsiteAutoplayQuirk> allowedAutoplayQuirks, WebKit::WebsiteAutoplayPolicy autoplayPolicy, Vector<WebCore::HTTPHeaderField>&& customHeaderFields, RefPtr<WebsiteDataStore>&& websiteDataStore)
+WebsitePolicies::WebsitePolicies(bool contentBlockersEnabled, OptionSet<WebKit::WebsiteAutoplayQuirk> allowedAutoplayQuirks, WebKit::WebsiteAutoplayPolicy autoplayPolicy, Vector<WebCore::HTTPHeaderField>&& customHeaderFields, WebKit::WebsitePopUpPolicy popUpPolicy, RefPtr<WebsiteDataStore>&& websiteDataStore)
     : m_contentBlockersEnabled(contentBlockersEnabled)
     , m_allowedAutoplayQuirks(allowedAutoplayQuirks)
     , m_autoplayPolicy(autoplayPolicy)
     , m_customHeaderFields(WTFMove(customHeaderFields))
+    , m_popUpPolicy(popUpPolicy)
     , m_websiteDataStore(WTFMove(websiteDataStore))
 { }
 
@@ -55,7 +56,7 @@ WebKit::WebsitePoliciesData WebsitePolicies::data()
     std::optional<WebKit::WebsiteDataStoreParameters> parameters;
     if (m_websiteDataStore)
         parameters = m_websiteDataStore->websiteDataStore().parameters();
-    return { contentBlockersEnabled(), allowedAutoplayQuirks(), autoplayPolicy(), customHeaderFields(), WTFMove(parameters) };
+    return { contentBlockersEnabled(), allowedAutoplayQuirks(), autoplayPolicy(), customHeaderFields(), popUpPolicy(), WTFMove(parameters) };
 }
 
 }
index 7da6c02..565127b 100644 (file)
@@ -28,6 +28,7 @@
 #include "APIObject.h"
 #include "WebsiteAutoplayPolicy.h"
 #include "WebsiteAutoplayQuirk.h"
+#include "WebsitePopUpPolicy.h"
 #include <WebCore/HTTPHeaderField.h>
 #include <wtf/EnumTraits.h>
 #include <wtf/OptionSet.h>
@@ -60,19 +61,23 @@ public:
     const Vector<WebCore::HTTPHeaderField>& customHeaderFields() const { return m_customHeaderFields; }
     Vector<WebCore::HTTPHeaderField>&& takeCustomHeaderFields() { return WTFMove(m_customHeaderFields); }
     void setCustomHeaderFields(Vector<WebCore::HTTPHeaderField>&& fields) { m_customHeaderFields = WTFMove(fields); }
-    
+
+    WebKit::WebsitePopUpPolicy popUpPolicy() const { return m_popUpPolicy; }
+    void setPopUpPolicy(WebKit::WebsitePopUpPolicy policy) { m_popUpPolicy = policy; }
+
     WebsiteDataStore* websiteDataStore() const { return m_websiteDataStore.get(); }
     void setWebsiteDataStore(RefPtr<WebsiteDataStore>&&);
 
     WebKit::WebsitePoliciesData data();
 
 private:
-    WebsitePolicies(bool contentBlockersEnabled, OptionSet<WebKit::WebsiteAutoplayQuirk>, WebKit::WebsiteAutoplayPolicy, Vector<WebCore::HTTPHeaderField>&&, RefPtr<WebsiteDataStore>&&);
+    WebsitePolicies(bool contentBlockersEnabled, OptionSet<WebKit::WebsiteAutoplayQuirk>, WebKit::WebsiteAutoplayPolicy, Vector<WebCore::HTTPHeaderField>&&, WebKit::WebsitePopUpPolicy, RefPtr<WebsiteDataStore>&&);
 
     bool m_contentBlockersEnabled { true };
     OptionSet<WebKit::WebsiteAutoplayQuirk> m_allowedAutoplayQuirks;
     WebKit::WebsiteAutoplayPolicy m_autoplayPolicy { WebKit::WebsiteAutoplayPolicy::Default };
     Vector<WebCore::HTTPHeaderField> m_customHeaderFields;
+    WebKit::WebsitePopUpPolicy m_popUpPolicy { WebKit::WebsitePopUpPolicy::Default };
     RefPtr<WebsiteDataStore> m_websiteDataStore;
 };
 
index a8f2ae3..058eeb6 100644 (file)
@@ -144,3 +144,33 @@ void WKWebsitePoliciesSetAutoplayPolicy(WKWebsitePoliciesRef websitePolicies, WK
     }
     ASSERT_NOT_REACHED();
 }
+
+WKWebsitePopUpPolicy WKWebsitePoliciesGetPopUpPolicy(WKWebsitePoliciesRef websitePolicies)
+{
+    switch (toImpl(websitePolicies)->popUpPolicy()) {
+    case WebsitePopUpPolicy::Default:
+        return kWKWebsitePopUpPolicyDefault;
+    case WebsitePopUpPolicy::Allow:
+        return kWKWebsitePopUpPolicyAllow;
+    case WebsitePopUpPolicy::Block:
+        return kWKWebsitePopUpPolicyBlock;
+    }
+    ASSERT_NOT_REACHED();
+    return kWKWebsitePopUpPolicyDefault;
+}
+
+void WKWebsitePoliciesSetPopUpPolicy(WKWebsitePoliciesRef websitePolicies, WKWebsitePopUpPolicy policy)
+{
+    switch (policy) {
+    case kWKWebsitePopUpPolicyDefault:
+        toImpl(websitePolicies)->setPopUpPolicy(WebsitePopUpPolicy::Default);
+        return;
+    case kWKWebsitePopUpPolicyAllow:
+        toImpl(websitePolicies)->setPopUpPolicy(WebsitePopUpPolicy::Allow);
+        return;
+    case kWKWebsitePopUpPolicyBlock:
+        toImpl(websitePolicies)->setPopUpPolicy(WebsitePopUpPolicy::Block);
+        return;
+    }
+    ASSERT_NOT_REACHED();
+}
index 4a22258..809833e 100644 (file)
@@ -47,6 +47,12 @@ enum {
     kWKWebsiteAutoplayQuirkArbitraryUserGestures = 1 << 2,
 };
 
+enum WKWebsitePopUpPolicy {
+    kWKWebsitePopUpPolicyDefault,
+    kWKWebsitePopUpPolicyAllow,
+    kWKWebsitePopUpPolicyBlock,
+};
+
 WK_EXPORT WKWebsitePoliciesRef WKWebsitePoliciesCreate();
 
 WK_EXPORT bool WKWebsitePoliciesGetContentBlockersEnabled(WKWebsitePoliciesRef);
@@ -61,6 +67,9 @@ WK_EXPORT void WKWebsitePoliciesSetAllowedAutoplayQuirks(WKWebsitePoliciesRef, W
 WK_EXPORT WKWebsiteAutoplayPolicy WKWebsitePoliciesGetAutoplayPolicy(WKWebsitePoliciesRef);
 WK_EXPORT void WKWebsitePoliciesSetAutoplayPolicy(WKWebsitePoliciesRef, WKWebsiteAutoplayPolicy);
 
+WK_EXPORT WKWebsitePopUpPolicy WKWebsitePoliciesGetPopUpPolicy(WKWebsitePoliciesRef);
+WK_EXPORT void WKWebsitePoliciesSetPopUpPolicy(WKWebsitePoliciesRef, WKWebsitePopUpPolicy);
+
 #ifdef __cplusplus
 }
 #endif
index 70422a7..f17914b 100644 (file)
@@ -40,6 +40,12 @@ typedef NS_OPTIONS(NSUInteger, _WKWebsiteAutoplayQuirk) {
     _WKWebsiteAutoplayQuirkArbitraryUserGestures = 1 << 2,
 } WK_API_AVAILABLE(macosx(10.13), ios(11.0));
 
+typedef NS_OPTIONS(NSUInteger, _WKWebsitePopUpPolicy) {
+    _WKWebsitePopUpPolicyDefault,
+    _WKWebsitePopUpPolicyAllow,
+    _WKWebsitePopUpPolicyBlock,
+} WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+
 @class WKWebsiteDataStore;
 
 WK_CLASS_AVAILABLE(macosx(10.12.3), ios(10.3))
@@ -49,6 +55,7 @@ WK_CLASS_AVAILABLE(macosx(10.12.3), ios(10.3))
 @property (nonatomic) _WKWebsiteAutoplayQuirk allowedAutoplayQuirks WK_API_AVAILABLE(macosx(10.13), ios(11.0));
 @property (nonatomic) _WKWebsiteAutoplayPolicy autoplayPolicy WK_API_AVAILABLE(macosx(10.13), ios(11.0));
 @property (nonatomic, copy) NSDictionary<NSString *, NSString *> *customHeaderFields WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+@property (nonatomic) _WKWebsitePopUpPolicy popUpPolicy WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 @property (nonatomic, strong) WKWebsiteDataStore *websiteDataStore WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 @end
index ac960b4..29b7380 100644 (file)
     }
 }
 
+- (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();
index 1d5b906..150eb84 100644 (file)
@@ -64,6 +64,7 @@
                076E884E1A13CADF005E90FC /* APIContextMenuClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 076E884D1A13CADF005E90FC /* APIContextMenuClient.h */; };
                07A5EBBB1C7BA43E00B9CA69 /* WKFrameHandleRef.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 07A5EBB91C7BA43E00B9CA69 /* WKFrameHandleRef.cpp */; };
                07A5EBBC1C7BA43E00B9CA69 /* WKFrameHandleRef.h in Headers */ = {isa = PBXBuildFile; fileRef = 07A5EBBA1C7BA43E00B9CA69 /* WKFrameHandleRef.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               0EDE85032004E75D00030560 /* WebsitePopUpPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = 0EDE85022004E74900030560 /* WebsitePopUpPolicy.h */; };
                0F08CF521D63C13A00B48DF1 /* WKFormSelectPicker.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F08CF511D63C13A00B48DF1 /* WKFormSelectPicker.h */; };
                0F08CF541D63C14000B48DF1 /* WKFormSelectPopover.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F08CF531D63C14000B48DF1 /* WKFormSelectPopover.h */; };
                0F0C365818C051BA00F607D7 /* RemoteLayerTreeHostIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0F0C365718C051BA00F607D7 /* RemoteLayerTreeHostIOS.mm */; };
                07A8F3861E64A8F900B668E8 /* CelestialSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CelestialSPI.h; sourceTree = "<group>"; };
                0867D6A5FE840307C02AAC07 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
                089C1667FE841158C02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
+               0EDE85022004E74900030560 /* WebsitePopUpPolicy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebsitePopUpPolicy.h; sourceTree = "<group>"; };
                0F08CF511D63C13A00B48DF1 /* WKFormSelectPicker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKFormSelectPicker.h; path = ios/forms/WKFormSelectPicker.h; sourceTree = "<group>"; };
                0F08CF531D63C14000B48DF1 /* WKFormSelectPopover.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKFormSelectPopover.h; path = ios/forms/WKFormSelectPopover.h; sourceTree = "<group>"; };
                0F0C365718C051BA00F607D7 /* RemoteLayerTreeHostIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RemoteLayerTreeHostIOS.mm; sourceTree = "<group>"; };
                                511F7D401EB1BCEE00E47B83 /* WebsiteDataStoreParameters.h */,
                                5C3AEA8E1FE1F1DF002318D3 /* WebsitePoliciesData.cpp */,
                                5C13024A1FE341A7000D9B31 /* WebsitePoliciesData.h */,
+                               0EDE85022004E74900030560 /* WebsitePopUpPolicy.h */,
                                8360349D1ACB34D600626549 /* WebSQLiteDatabaseTracker.cpp */,
                                8360349E1ACB34D600626549 /* WebSQLiteDatabaseTracker.h */,
                                C0337DD7127A51B6008FF4F4 /* WebTouchEvent.cpp */,
                                4F601432155C5AA2001FBDE0 /* BlockingResponseMap.h in Headers */,
                                1A5705111BE410E600874AF1 /* BlockSPI.h in Headers */,
                                BC3065FA1259344E00E71278 /* CacheModel.h in Headers */,
+                               0EDE85032004E75D00030560 /* WebsitePopUpPolicy.h in Headers */,
                                41897ED81F415D8A0016FA42 /* CacheStorageEngine.h in Headers */,
                                41FABD2A1F4DE001006A6C97 /* CacheStorageEngineCache.h in Headers */,
                                41897EDA1F415D8A0016FA42 /* CacheStorageEngineConnection.h in Headers */,
index e0fbfc2..0b129bb 100644 (file)
@@ -1,3 +1,22 @@
+2018-01-16  Zach Li  <zachli@apple.com>
+
+        Add pop-up policy support in website policies.
+        https://bugs.webkit.org/show_bug.cgi?id=181544.
+        rdar://problem/30521400.
+
+        Reviewed by Alex Christensen.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        Added pop-up-check.html.
+
+        * TestWebKitAPI/Tests/WebKit/pop-up-check.html: Added.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm:
+        (-[PopUpPoliciesDelegate webView:decidePolicyForNavigationAction:decisionHandler:]):
+        (-[PopUpPoliciesDelegate _webView:decidePolicyForNavigationAction:decisionHandler:]):
+        (-[PopUpPoliciesDelegate webView:createWebViewWithConfiguration:forNavigationAction:windowFeatures:]):
+        (TEST):
+
 2018-01-16  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         [Attachment Support] Provide the `src` of an attachment to the UI delegate when an attachment is inserted
index c7faacb..3707e87 100644 (file)
@@ -33,6 +33,7 @@
                07E1F6A21FFC44FA0096C7EC /* getDisplayMedia.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 07E1F6A11FFC44F90096C7EC /* getDisplayMedia.html */; };
                07E1F6A31FFC4B760096C7EC /* GetDisplayMedia.mm in Sources */ = {isa = PBXBuildFile; fileRef = 07E1F6A01FFC3A080096C7EC /* GetDisplayMedia.mm */; };
                07E499911F9E56DF002F1EF3 /* GetUserMediaReprompt.mm in Sources */ = {isa = PBXBuildFile; fileRef = 07E499901F9E56A1002F1EF3 /* GetUserMediaReprompt.mm */; };
+               0EBBCC661FFF9E0C00FA42AB /* pop-up-check.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 0EBBCC651FFF9DCE00FA42AB /* pop-up-check.html */; };
                0F139E771A423A5B00F590F5 /* WeakObjCPtr.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0F139E751A423A5300F590F5 /* WeakObjCPtr.mm */; };
                0F139E781A423A6B00F590F5 /* PlatformUtilitiesCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0F139E721A423A2B00F590F5 /* PlatformUtilitiesCocoa.mm */; };
                0F139E791A42457000F590F5 /* PlatformUtilitiesCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0F139E721A423A2B00F590F5 /* PlatformUtilitiesCocoa.mm */; };
                        dstPath = TestWebKitAPI.resources;
                        dstSubfolderSpec = 7;
                        files = (
+                               0EBBCC661FFF9E0C00FA42AB /* pop-up-check.html in Copy Resources */,
                                1A9E52C913E65EF4006917F5 /* 18-characters.html in Copy Resources */,
                                379028B914FAC24C007E6B43 /* acceptsFirstMouse.html in Copy Resources */,
                                1C2B81871C8925A000A5529F /* Ahem.ttf in Copy Resources */,
                07EDEFAC1EB9400C00D43292 /* UserMediaDisabled.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = UserMediaDisabled.mm; sourceTree = "<group>"; };
                0BCD833414857CE400EA2003 /* HashMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HashMap.cpp; sourceTree = "<group>"; };
                0BCD85691485C98B00EA2003 /* SetForScope.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SetForScope.cpp; sourceTree = "<group>"; };
+               0EBBCC651FFF9DCE00FA42AB /* pop-up-check.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "pop-up-check.html"; sourceTree = "<group>"; };
                0F139E721A423A2B00F590F5 /* PlatformUtilitiesCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = PlatformUtilitiesCocoa.mm; path = cocoa/PlatformUtilitiesCocoa.mm; sourceTree = "<group>"; };
                0F139E751A423A5300F590F5 /* WeakObjCPtr.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WeakObjCPtr.mm; path = cocoa/WeakObjCPtr.mm; sourceTree = "<group>"; };
                0F17BBD415AF6C4D007AB753 /* WebCoreStatisticsWithNoWebProcess.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebCoreStatisticsWithNoWebProcess.cpp; sourceTree = "<group>"; };
                                5797FE321EB15A8900B2F4A0 /* navigation-client-default-crypto.html */,
                                C99B675E1E39735C00FC6C80 /* no-autoplay-with-controls.html */,
                                CEA6CF2719CCF69D0064F5A7 /* open-and-close-window.html */,
+                               0EBBCC651FFF9DCE00FA42AB /* pop-up-check.html */,
                                F6FDDDD514241C48004F1729 /* push-state.html */,
                                0F5651F81FCE50E800310FBC /* scroll-to-anchor.html */,
                                7A66BDB71EAF150100CCC924 /* set-long-title.html */,
diff --git a/Tools/TestWebKitAPI/Tests/WebKit/pop-up-check.html b/Tools/TestWebKitAPI/Tests/WebKit/pop-up-check.html
new file mode 100644 (file)
index 0000000..f9f95ea
--- /dev/null
@@ -0,0 +1,20 @@
+<html>
+    <head>
+        <script>
+            function openPopUpWindow() {
+                var popUpWindow = window.open('https://www.webkit.org', '', 'width=300, height=300');
+                if (popUpWindow) {
+                    try {
+                        window.webkit.messageHandlers.testHandler.postMessage("pop-up-allowed");
+                    } catch(e) { }
+                } else {
+                    try {
+                        window.webkit.messageHandlers.testHandler.postMessage("pop-up-blocked");
+                    } catch(e) { }
+                }
+            }
+        </script>
+    </head>
+    <body onload="openPopUpWindow()">
+    </body>
+</html>
index 8509554..746ce7d 100644 (file)
@@ -787,6 +787,61 @@ TEST(WebKit, CustomHeaderFields)
     TestWebKitAPI::Util::run(&fourthTestDone);
 }
 
+@interface PopUpPoliciesDelegate : NSObject <WKNavigationDelegate, WKUIDelegatePrivate>
+@property (nonatomic, copy) _WKWebsitePopUpPolicy(^popUpPolicyForURL)(NSURL *);
+@end
+
+@implementation PopUpPoliciesDelegate
+
+- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
+{
+    // _webView:decidePolicyForNavigationAction:decisionHandler: should be called instead if it is implemented.
+    EXPECT_TRUE(false);
+    decisionHandler(WKNavigationActionPolicyAllow);
+}
+
+- (void)_webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy, _WKWebsitePolicies *))decisionHandler
+{
+    _WKWebsitePolicies *websitePolicies = [[[_WKWebsitePolicies alloc] init] autorelease];
+    if (_popUpPolicyForURL)
+        websitePolicies.popUpPolicy = _popUpPolicyForURL(navigationAction.request.URL);
+    decisionHandler(WKNavigationActionPolicyAllow, websitePolicies);
+}
+
+- (nullable WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures
+{
+    return [[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration];
+}
+
+@end
+
+TEST(WebKit, WebsitePoliciesPopUp)
+{
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+
+    auto delegate = adoptNS([[PopUpPoliciesDelegate alloc] init]);
+    [webView setNavigationDelegate:delegate.get()];
+    [webView setUIDelegate:delegate.get()];
+
+    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"pop-up-check" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+
+    [delegate setPopUpPolicyForURL:^_WKWebsitePopUpPolicy(NSURL *) {
+        return _WKWebsitePopUpPolicyBlock;
+    }];
+
+    [webView loadRequest:request];
+    [webView waitForMessage:@"pop-up-blocked"];
+
+    [delegate setPopUpPolicyForURL:^_WKWebsitePopUpPolicy(NSURL *) {
+        return _WKWebsitePopUpPolicyAllow;
+    }];
+
+    [webView loadRequest:request];
+    [webView waitForMessage:@"pop-up-allowed"];
+}
+
 static bool done;
 
 @interface WebsitePoliciesWebsiteDataStoreDelegate : NSObject <WKNavigationDelegatePrivate, WKURLSchemeHandler, WKUIDelegate>