Stop using PolicyCallback
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 25 Sep 2017 22:33:19 +0000 (22:33 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 25 Sep 2017 22:33:19 +0000 (22:33 +0000)
https://bugs.webkit.org/show_bug.cgi?id=176088

Reviewed by Andy Estes.

Source/WebCore:

This is what lambdas are for. No change in behavior.
Cancelling the callback is now the responsibility of the FrameLoaderClient, to whom we have given the lambda.
That is why there are changes in WebKit and WebKitLegacy where the FrameLoaderClient::cancelPolicyCheck finds the lambda it has stored.

* CMakeLists.txt:
* WebCore.xcodeproj/project.pbxproj:
* loader/DocumentLoader.cpp:
* loader/FrameLoader.cpp:
* loader/FrameLoaderClient.h:
* loader/PolicyCallback.cpp: Removed.
* loader/PolicyCallback.h: Removed.
* loader/PolicyChecker.cpp:
(WebCore::PolicyChecker::checkNavigationPolicy):
(WebCore::PolicyChecker::checkNewWindowPolicy):
(WebCore::PolicyChecker::stopCheck):
(WebCore::PolicyChecker::continueAfterNavigationPolicy): Deleted.
* loader/PolicyChecker.h:
(WebCore::PolicyChecker::setSuggestedFilename): Deleted.

Source/WebKit:

* WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
* WebProcess/WebPage/WebFrame.cpp:
(WebKit::WebFrame::invalidatePolicyListener):
* WebProcess/WebPage/WebFrame.h:
* WebProcess/WebPage/WebInspector.cpp:

Source/WebKitLegacy/mac:

* WebCoreSupport/WebFrameLoaderClient.mm:
(-[WebFramePolicyListener invalidate]):
(-[WebFramePolicyListener receivedPolicyDecision:]):

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

17 files changed:
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/loader/DocumentLoader.cpp
Source/WebCore/loader/FrameLoader.cpp
Source/WebCore/loader/FrameLoaderClient.h
Source/WebCore/loader/PolicyCallback.cpp [deleted file]
Source/WebCore/loader/PolicyCallback.h [deleted file]
Source/WebCore/loader/PolicyChecker.cpp
Source/WebCore/loader/PolicyChecker.h
Source/WebKit/ChangeLog
Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp
Source/WebKit/WebProcess/WebPage/WebFrame.cpp
Source/WebKit/WebProcess/WebPage/WebFrame.h
Source/WebKit/WebProcess/WebPage/WebInspector.cpp
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/WebCoreSupport/WebFrameLoaderClient.mm

index 9cfd434..fe1e096 100644 (file)
@@ -2116,7 +2116,6 @@ set(WebCore_SOURCES
     loader/NavigationScheduler.cpp
     loader/NetscapePlugInStreamLoader.cpp
     loader/PingLoader.cpp
-    loader/PolicyCallback.cpp
     loader/PolicyChecker.cpp
     loader/ProgressTracker.cpp
     loader/ResourceCryptographicDigest.cpp
index 1857dae..2bf9585 100644 (file)
@@ -1,3 +1,29 @@
+2017-09-25  Alex Christensen  <achristensen@webkit.org>
+
+        Stop using PolicyCallback
+        https://bugs.webkit.org/show_bug.cgi?id=176088
+
+        Reviewed by Andy Estes.
+
+        This is what lambdas are for. No change in behavior.
+        Cancelling the callback is now the responsibility of the FrameLoaderClient, to whom we have given the lambda.
+        That is why there are changes in WebKit and WebKitLegacy where the FrameLoaderClient::cancelPolicyCheck finds the lambda it has stored.
+
+        * CMakeLists.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * loader/DocumentLoader.cpp:
+        * loader/FrameLoader.cpp:
+        * loader/FrameLoaderClient.h:
+        * loader/PolicyCallback.cpp: Removed.
+        * loader/PolicyCallback.h: Removed.
+        * loader/PolicyChecker.cpp:
+        (WebCore::PolicyChecker::checkNavigationPolicy):
+        (WebCore::PolicyChecker::checkNewWindowPolicy):
+        (WebCore::PolicyChecker::stopCheck):
+        (WebCore::PolicyChecker::continueAfterNavigationPolicy): Deleted.
+        * loader/PolicyChecker.h:
+        (WebCore::PolicyChecker::setSuggestedFilename): Deleted.
+
 2017-09-25  Youenn Fablet  <youenn@apple.com>
 
         MediaStreamTrack.getSettings should compute its deviceId/groupId like enumerateDevices
index d4ccfcd..6d38b8a 100644 (file)
                952076061F2675FE007D2AAB /* CallTracerTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 952076021F2675F9007D2AAB /* CallTracerTypes.h */; };
                96ABA42314BCB80E00D56204 /* GraphicsContext3DOpenGLCommon.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 96ABA42214BCB80E00D56204 /* GraphicsContext3DOpenGLCommon.cpp */; };
                9703E1BF15DC4E37001F24C8 /* JSVoidCallback.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 97E9EC8B15DC492F004F2E71 /* JSVoidCallback.cpp */; };
-               97059977107D975200A50A7C /* PolicyCallback.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 97059973107D975200A50A7C /* PolicyCallback.cpp */; };
-               97059978107D975200A50A7C /* PolicyCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = 97059974107D975200A50A7C /* PolicyCallback.h */; settings = {ATTRIBUTES = (Private, ); }; };
                97059979107D975200A50A7C /* PolicyChecker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 97059975107D975200A50A7C /* PolicyChecker.cpp */; };
                9705997A107D975200A50A7C /* PolicyChecker.h in Headers */ = {isa = PBXBuildFile; fileRef = 97059976107D975200A50A7C /* PolicyChecker.h */; settings = {ATTRIBUTES = (Private, ); }; };
                970B728A144FFAC600F00A37 /* EventInterfaces.h in Headers */ = {isa = PBXBuildFile; fileRef = 970B7289144FFAC600F00A37 /* EventInterfaces.h */; settings = {ATTRIBUTES = (Private, ); }; };
                952076011F2675F9007D2AAB /* CallTracer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CallTracer.h; sourceTree = "<group>"; };
                952076021F2675F9007D2AAB /* CallTracerTypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CallTracerTypes.h; sourceTree = "<group>"; };
                96ABA42214BCB80E00D56204 /* GraphicsContext3DOpenGLCommon.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GraphicsContext3DOpenGLCommon.cpp; sourceTree = "<group>"; };
-               97059973107D975200A50A7C /* PolicyCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PolicyCallback.cpp; sourceTree = "<group>"; };
-               97059974107D975200A50A7C /* PolicyCallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PolicyCallback.h; sourceTree = "<group>"; };
                97059975107D975200A50A7C /* PolicyChecker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PolicyChecker.cpp; sourceTree = "<group>"; };
                97059976107D975200A50A7C /* PolicyChecker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PolicyChecker.h; sourceTree = "<group>"; };
                970B7289144FFAC600F00A37 /* EventInterfaces.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EventInterfaces.h; sourceTree = "<group>"; };
                                656D372B0ADBA5DE00A4554D /* NetscapePlugInStreamLoader.h */,
                                D0FF2A5B11F8C45A007E74E0 /* PingLoader.cpp */,
                                D0FF2A5C11F8C45A007E74E0 /* PingLoader.h */,
-                               97059973107D975200A50A7C /* PolicyCallback.cpp */,
-                               97059974107D975200A50A7C /* PolicyCallback.h */,
                                97059975107D975200A50A7C /* PolicyChecker.cpp */,
                                97059976107D975200A50A7C /* PolicyChecker.h */,
                                1A2A68210B5BEDE70002A480 /* ProgressTracker.cpp */,
                                B2B1F7170D00CAA8004AEA64 /* PointerEventsHitRules.h in Headers */,
                                3FF813A71DBA8640009BF001 /* PointerLockController.h in Headers */,
                                84730D921248F0B300D3A9C9 /* PointLightSource.h in Headers */,
-                               97059978107D975200A50A7C /* PolicyCallback.h in Headers */,
                                9705997A107D975200A50A7C /* PolicyChecker.h in Headers */,
                                FD45A957175D414C00C21EC8 /* PolygonShape.h in Headers */,
                                5174E20A10A1F44F00F95E6F /* PopStateEvent.h in Headers */,
                                B2B1F7160D00CAA8004AEA64 /* PointerEventsHitRules.cpp in Sources */,
                                5CFC4350192409E300A0D3B5 /* PointerLockController.cpp in Sources */,
                                A1E1154613015C4E0054AC8C /* PointLightSource.cpp in Sources */,
-                               97059977107D975200A50A7C /* PolicyCallback.cpp in Sources */,
                                97059979107D975200A50A7C /* PolicyChecker.cpp in Sources */,
                                FD45A959175D417100C21EC8 /* PolygonShape.cpp in Sources */,
                                5189F0DE10B46B0E00F3C739 /* PopStateEvent.cpp in Sources */,
index 3bdbd6f..1790f90 100644 (file)
@@ -75,6 +75,7 @@
 #include "SubresourceLoader.h"
 #include "TextResourceDecoder.h"
 #include <wtf/Assertions.h>
+#include <wtf/CompletionHandler.h>
 #include <wtf/NeverDestroyed.h>
 #include <wtf/Ref.h>
 #include <wtf/text/CString.h>
index a7d32a9..085826a 100644 (file)
 #include "UserContentController.h"
 #include "WindowFeatures.h"
 #include "XMLDocumentParser.h"
+#include <wtf/CompletionHandler.h>
 #include <wtf/CurrentTime.h>
 #include <wtf/Ref.h>
 #include <wtf/StdLibExtras.h>
index f1aad8f..8e29d61 100644 (file)
@@ -84,7 +84,6 @@ class MessageEvent;
 class NavigationAction;
 class Page;
 class PluginViewBase;
-class PolicyChecker;
 class PreviewLoaderClient;
 class ProtectionSpace;
 class RTCPeerConnectionHandler;
diff --git a/Source/WebCore/loader/PolicyCallback.cpp b/Source/WebCore/loader/PolicyCallback.cpp
deleted file mode 100644 (file)
index 608a14e..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
- * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
- * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
- *
- * 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. 
- * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
- *     its contributors may be used to endorse or promote products derived
- *     from this software without specific prior written permission. 
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE 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 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.
- */
-
-#include "config.h"
-#include "PolicyCallback.h"
-
-#include "FormState.h"
-#include "Frame.h"
-#include "FrameLoader.h"
-#include "HTMLFormElement.h"
-
-namespace WebCore {
-
-void PolicyCallback::set(const ResourceRequest& request, FormState* formState, NavigationPolicyDecisionFunction&& function)
-{
-    m_request = request;
-    m_formState = formState;
-    m_frameName = String();
-
-    m_navigationFunction = WTFMove(function);
-}
-
-void PolicyCallback::call(bool shouldContinue)
-{
-    if (m_navigationFunction)
-        m_navigationFunction(m_request, m_formState.get(), shouldContinue);
-}
-
-void PolicyCallback::clearRequest()
-{
-    m_request = ResourceRequest();
-    m_formState = nullptr;
-    m_frameName = String();
-}
-
-void PolicyCallback::cancel()
-{
-    clearRequest();
-    if (m_navigationFunction)
-        m_navigationFunction(m_request, m_formState.get(), false);
-}
-
-} // namespace WebCore
diff --git a/Source/WebCore/loader/PolicyCallback.h b/Source/WebCore/loader/PolicyCallback.h
deleted file mode 100644 (file)
index d8c335d..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
- * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
- *
- * 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. 
- * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
- *     its contributors may be used to endorse or promote products derived
- *     from this software without specific prior written permission. 
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE 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 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 "FrameLoaderTypes.h"
-#include "NavigationAction.h"
-#include "ResourceRequest.h"
-#include <functional>
-#include <wtf/Function.h>
-#include <wtf/RefPtr.h>
-#include <wtf/text/WTFString.h>
-
-namespace WebCore {
-
-class FormState;
-
-using NavigationPolicyDecisionFunction = Function<void(const ResourceRequest&, FormState*, bool shouldContinue)>;
-
-class PolicyCallback {
-public:
-    void set(const ResourceRequest&, FormState*, NavigationPolicyDecisionFunction&&);
-
-    const ResourceRequest& request() const { return m_request; }
-    void clearRequest();
-
-    void call(bool shouldContinue);
-    void cancel();
-
-private:
-    ResourceRequest m_request;
-    RefPtr<FormState> m_formState;
-    String m_frameName;
-    NavigationAction m_navigationAction;
-
-    NavigationPolicyDecisionFunction m_navigationFunction;
-};
-
-} // namespace WebCore
index 9341bbc..824fd3e 100644 (file)
@@ -44,6 +44,7 @@
 #include "HTMLFormElement.h"
 #include "HTMLFrameOwnerElement.h"
 #include "HTMLPlugInElement.h"
+#include <wtf/CompletionHandler.h>
 
 #if USE(QUICK_LOOK)
 #include "QuickLook.h"
@@ -75,12 +76,12 @@ PolicyChecker::PolicyChecker(Frame& frame)
 {
 }
 
-void PolicyChecker::checkNavigationPolicy(const ResourceRequest& newRequest, bool didReceiveRedirectResponse, NavigationPolicyDecisionFunction function)
+void PolicyChecker::checkNavigationPolicy(const ResourceRequest& newRequest, bool didReceiveRedirectResponse, NavigationPolicyDecisionFunction&& function)
 {
     checkNavigationPolicy(newRequest, didReceiveRedirectResponse, m_frame.loader().activeDocumentLoader(), nullptr, WTFMove(function));
 }
 
-void PolicyChecker::checkNavigationPolicy(const ResourceRequest& request, bool didReceiveRedirectResponse, DocumentLoader* loader, FormState* formState, NavigationPolicyDecisionFunction function)
+void PolicyChecker::checkNavigationPolicy(const ResourceRequest& request, bool didReceiveRedirectResponse, DocumentLoader* loader, FormState* formState, NavigationPolicyDecisionFunction&& function)
 {
     NavigationAction action = loader->triggeringAction();
     if (action.isEmpty()) {
@@ -91,7 +92,7 @@ void PolicyChecker::checkNavigationPolicy(const ResourceRequest& request, bool d
     // Don't ask more than once for the same request or if we are loading an empty URL.
     // This avoids confusion on the part of the client.
     if (equalIgnoringHeaderFields(request, loader->lastCheckedRequest()) || (!request.isNull() && request.url().isEmpty())) {
-        function(request, 0, true);
+        function(request, nullptr, true);
         loader->setLastCheckedRequest(request);
         return;
     }
@@ -106,7 +107,7 @@ void PolicyChecker::checkNavigationPolicy(const ResourceRequest& request, bool d
 #endif
         if (isBackForwardLoadType(m_loadType))
             m_loadType = FrameLoadType::Reload;
-        function(request, 0, shouldContinue);
+        function(request, nullptr, shouldContinue);
         return;
     }
 
@@ -116,20 +117,16 @@ void PolicyChecker::checkNavigationPolicy(const ResourceRequest& request, bool d
             // reveal that the frame was blocked. This way, it looks like any other cross-origin page load.
             m_frame.ownerElement()->dispatchEvent(Event::create(eventNames().loadEvent, false, false));
         }
-        function(request, 0, false);
+        function(request, nullptr, false);
         return;
     }
 
     loader->setLastCheckedRequest(request);
 
-    m_callback.set(request, formState, WTFMove(function));
-
 #if USE(QUICK_LOOK)
     // Always allow QuickLook-generated URLs based on the protocol scheme.
-    if (!request.isNull() && isQuickLookPreviewURL(request.url())) {
-        continueAfterNavigationPolicy(PolicyUse);
-        return;
-    }
+    if (!request.isNull() && isQuickLookPreviewURL(request.url()))
+        return function(request, formState, true);
 #endif
 
 #if ENABLE(CONTENT_FILTERING)
@@ -139,29 +136,43 @@ void PolicyChecker::checkNavigationPolicy(const ResourceRequest& request, bool d
             if (unblocked)
                 frame->loader().reload();
         });
-        continueAfterNavigationPolicy(PolicyIgnore);
-        return;
+        return function({ }, nullptr, false);
     }
     m_contentFilterUnblockHandler = { };
 #endif
 
     m_delegateIsDecidingNavigationPolicy = true;
-    m_suggestedFilename = action.downloadAttribute().isEmpty() ? nullAtom() : action.downloadAttribute();
-    m_frame.loader().client().dispatchDecidePolicyForNavigationAction(action, request, didReceiveRedirectResponse, formState, [this](PolicyAction action) {
-        continueAfterNavigationPolicy(action);
+    String suggestedFilename = action.downloadAttribute().isEmpty() ? nullAtom() : action.downloadAttribute();
+    ResourceRequest requestCopy = request;
+    m_frame.loader().client().dispatchDecidePolicyForNavigationAction(action, request, didReceiveRedirectResponse, formState, [this, function = WTFMove(function), request = WTFMove(requestCopy), formState = makeRefPtr(formState), suggestedFilename = WTFMove(suggestedFilename)](PolicyAction policyAction) mutable {
+        switch (policyAction) {
+        case PolicyDownload:
+            m_frame.loader().setOriginalURLForDownloadRequest(request);
+            m_frame.loader().client().startDownload(request, suggestedFilename);
+            FALLTHROUGH;
+        case PolicyIgnore:
+            return function({ }, nullptr, false);
+        case PolicyUse:
+            if (!m_frame.loader().client().canHandleRequest(request)) {
+                handleUnimplementablePolicy(m_frame.loader().client().cannotShowURLError(request));
+                return function({ }, nullptr, false);
+            }
+            return function(request, formState.get(), true);
+        }
+        ASSERT_NOT_REACHED();
     });
     m_delegateIsDecidingNavigationPolicy = false;
 }
 
-void PolicyChecker::checkNewWindowPolicy(NavigationAction&& navigationAction, const ResourceRequest& request, FormState* formState, const String& frameName, NewWindowPolicyDecisionFunction function)
+void PolicyChecker::checkNewWindowPolicy(NavigationAction&& navigationAction, const ResourceRequest& request, FormState* formState, const String& frameName, NewWindowPolicyDecisionFunction&& function)
 {
     if (m_frame.document() && m_frame.document()->isSandboxed(SandboxPopups))
-        return continueAfterNavigationPolicy(PolicyIgnore);
+        return function({ }, nullptr, { }, { }, false);
 
     if (!DOMWindow::allowPopUp(m_frame))
-        return continueAfterNavigationPolicy(PolicyIgnore);
+        return function({ }, nullptr, { }, { }, false);
 
-    m_frame.loader().client().dispatchDecidePolicyForNewWindowAction(navigationAction, request, formState, frameName, [frame = makeRef(m_frame), request, formState = makeRefPtr(formState), frameName, navigationAction, function = WTFMove(function)](PolicyAction policyAction) {
+    m_frame.loader().client().dispatchDecidePolicyForNewWindowAction(navigationAction, request, formState, frameName, [frame = makeRef(m_frame), request, formState = makeRefPtr(formState), frameName, navigationAction, function = WTFMove(function)](PolicyAction policyAction) mutable {
         switch (policyAction) {
         case PolicyDownload:
             frame->loader().client().startDownload(request);
@@ -180,8 +191,6 @@ void PolicyChecker::checkNewWindowPolicy(NavigationAction&& navigationAction, co
 void PolicyChecker::stopCheck()
 {
     m_frame.loader().client().cancelPolicyCheck();
-    PolicyCallback callback = WTFMove(m_callback);
-    callback.cancel();
 }
 
 void PolicyChecker::cannotShowMIMEType(const ResourceResponse& response)
@@ -189,38 +198,6 @@ void PolicyChecker::cannotShowMIMEType(const ResourceResponse& response)
     handleUnimplementablePolicy(m_frame.loader().client().cannotShowMIMETypeError(response));
 }
 
-void PolicyChecker::continueAfterNavigationPolicy(PolicyAction policy)
-{
-    PolicyCallback callback = WTFMove(m_callback);
-
-    bool shouldContinue = policy == PolicyUse;
-
-    switch (policy) {
-        case PolicyIgnore:
-            callback.clearRequest();
-            break;
-        case PolicyDownload: {
-            ResourceRequest request = callback.request();
-            m_frame.loader().setOriginalURLForDownloadRequest(request);
-            m_frame.loader().client().startDownload(request, m_suggestedFilename);
-            callback.clearRequest();
-            break;
-        }
-        case PolicyUse: {
-            ResourceRequest request(callback.request());
-
-            if (!m_frame.loader().client().canHandleRequest(request)) {
-                handleUnimplementablePolicy(m_frame.loader().client().cannotShowURLError(callback.request()));
-                callback.clearRequest();
-                shouldContinue = false;
-            }
-            break;
-        }
-    }
-
-    callback.call(shouldContinue);
-}
-
 void PolicyChecker::handleUnimplementablePolicy(const ResourceError& error)
 {
     m_delegateIsHandlingUnimplementablePolicy = true;
index ef4cc9c..d47e36c 100644 (file)
@@ -30,7 +30,6 @@
 #pragma once
 
 #include "FrameLoaderTypes.h"
-#include "PolicyCallback.h"
 #include "ResourceRequest.h"
 #include <wtf/text/WTFString.h>
 
 #include "ContentFilterUnblockHandler.h"
 #endif
 
+namespace WTF {
+template<typename> class CompletionHandler;
+}
+
 namespace WebCore {
 
 class DocumentLoader;
@@ -47,7 +50,8 @@ class NavigationAction;
 class ResourceError;
 class ResourceResponse;
 
-using NewWindowPolicyDecisionFunction = WTF::Function<void(const ResourceRequest&, FormState*, const String& frameName, const NavigationAction&, bool shouldContinue)>;
+using NewWindowPolicyDecisionFunction = WTF::CompletionHandler<void(const ResourceRequest&, FormState*, const String& frameName, const NavigationAction&, bool shouldContinue)>;
+using NavigationPolicyDecisionFunction = WTF::CompletionHandler<void(const ResourceRequest&, FormState*, bool shouldContinue)>;
 
 class PolicyChecker {
     WTF_MAKE_NONCOPYABLE(PolicyChecker);
@@ -55,9 +59,9 @@ class PolicyChecker {
 public:
     explicit PolicyChecker(Frame&);
 
-    void checkNavigationPolicy(const ResourceRequest&, bool didReceiveRedirectResponse, DocumentLoader*, FormState*, NavigationPolicyDecisionFunction);
-    void checkNavigationPolicy(const ResourceRequest&, bool didReceiveRedirectResponse, NavigationPolicyDecisionFunction);
-    void checkNewWindowPolicy(NavigationAction&&, const ResourceRequest&, FormState*, const String& frameName, NewWindowPolicyDecisionFunction);
+    void checkNavigationPolicy(const ResourceRequest&, bool didReceiveRedirectResponse, DocumentLoader*, FormState*, NavigationPolicyDecisionFunction&&);
+    void checkNavigationPolicy(const ResourceRequest&, bool didReceiveRedirectResponse, NavigationPolicyDecisionFunction&&);
+    void checkNewWindowPolicy(NavigationAction&&, const ResourceRequest&, FormState*, const String& frameName, NewWindowPolicyDecisionFunction&&);
 
     void stopCheck();
 
@@ -66,8 +70,6 @@ public:
     FrameLoadType loadType() const { return m_loadType; }
     void setLoadType(FrameLoadType loadType) { m_loadType = loadType; }
 
-    void setSuggestedFilename(const String& suggestedFilename) { m_suggestedFilename = suggestedFilename; }
-
     bool delegateIsDecidingNavigationPolicy() const { return m_delegateIsDecidingNavigationPolicy; }
     bool delegateIsHandlingUnimplementablePolicy() const { return m_delegateIsHandlingUnimplementablePolicy; }
 
@@ -76,8 +78,6 @@ public:
 #endif
 
 private:
-    void continueAfterNavigationPolicy(PolicyAction);
-
     void handleUnimplementablePolicy(const ResourceError&);
 
     Frame& m_frame;
@@ -89,8 +89,6 @@ private:
     // that WebKit conveys this value as the WebActionNavigationTypeKey value
     // on navigation action delegate callbacks.
     FrameLoadType m_loadType;
-    PolicyCallback m_callback;
-    String m_suggestedFilename;
 
 #if ENABLE(CONTENT_FILTERING)
     ContentFilterUnblockHandler m_contentFilterUnblockHandler;
index 54414fa..d6f724a 100644 (file)
@@ -1,3 +1,16 @@
+2017-09-25  Alex Christensen  <achristensen@webkit.org>
+
+        Stop using PolicyCallback
+        https://bugs.webkit.org/show_bug.cgi?id=176088
+
+        Reviewed by Andy Estes.
+
+        * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
+        * WebProcess/WebPage/WebFrame.cpp:
+        (WebKit::WebFrame::invalidatePolicyListener):
+        * WebProcess/WebPage/WebFrame.h:
+        * WebProcess/WebPage/WebInspector.cpp:
+
 2017-09-25  Chris Dumez  <cdumez@apple.com>
 
         [WK2] Add API to query if a download was user-initiated
index 86e7e83..382d0af 100644 (file)
@@ -77,6 +77,7 @@
 #include <WebCore/Page.h>
 #include <WebCore/PluginData.h>
 #include <WebCore/PluginDocument.h>
+#include <WebCore/PolicyChecker.h>
 #include <WebCore/ProgressTracker.h>
 #include <WebCore/ResourceError.h>
 #include <WebCore/ScriptController.h>
index 0d9861b..b19a44c 100644 (file)
@@ -240,7 +240,8 @@ void WebFrame::invalidatePolicyListener()
 
     m_policyDownloadID = { };
     m_policyListenerID = 0;
-    m_policyFunction = nullptr;
+    if (auto function = std::exchange(m_policyFunction, nullptr))
+        function(PolicyIgnore);
 }
 
 void WebFrame::didReceivePolicyDecision(uint64_t listenerID, PolicyAction action, uint64_t navigationID, DownloadID downloadID)
@@ -254,7 +255,8 @@ void WebFrame::didReceivePolicyDecision(uint64_t listenerID, PolicyAction action
     if (listenerID != m_policyListenerID)
         return;
 
-    ASSERT(m_policyFunction);
+    if (!m_policyFunction)
+        return;
 
     FramePolicyFunction function = WTFMove(m_policyFunction);
 
index ff37d67..6f89bbf 100644 (file)
@@ -33,8 +33,8 @@
 #include <JavaScriptCore/JSBase.h>
 #include <WebCore/FrameLoaderClient.h>
 #include <WebCore/FrameLoaderTypes.h>
-#include <WebCore/PolicyChecker.h>
 #include <wtf/Forward.h>
+#include <wtf/HashMap.h>
 #include <wtf/RefPtr.h>
 #include <wtf/RetainPtr.h>
 
index 6a890b2..72f5bf9 100644 (file)
@@ -41,6 +41,7 @@
 #include <WebCore/InspectorFrontendClient.h>
 #include <WebCore/InspectorPageAgent.h>
 #include <WebCore/MainFrame.h>
+#include <WebCore/NavigationAction.h>
 #include <WebCore/NotImplemented.h>
 #include <WebCore/Page.h>
 #include <WebCore/ScriptController.h>
index 9c00404..515690b 100644 (file)
@@ -1,3 +1,14 @@
+2017-09-25  Alex Christensen  <achristensen@webkit.org>
+
+        Stop using PolicyCallback
+        https://bugs.webkit.org/show_bug.cgi?id=176088
+
+        Reviewed by Andy Estes.
+
+        * WebCoreSupport/WebFrameLoaderClient.mm:
+        (-[WebFramePolicyListener invalidate]):
+        (-[WebFramePolicyListener receivedPolicyDecision:]):
+
 2017-09-25  Sam Weinig  <sam@webkit.org>
 
         Remove unnecessary userVisibleString EditorClient function
index f620570..beebf13 100644 (file)
@@ -2409,6 +2409,8 @@ void WebFrameLoaderClient::finishedLoadingIcon(uint64_t callbackID, SharedBuffer
 - (void)invalidate
 {
     _frame = nullptr;
+    if (auto policyFunction = std::exchange(_policyFunction, nullptr))
+        policyFunction(PolicyIgnore);
 }
 
 - (void)dealloc
@@ -2425,11 +2427,8 @@ void WebFrameLoaderClient::finishedLoadingIcon(uint64_t callbackID, SharedBuffer
     if (!frame)
         return;
 
-    FramePolicyFunction policyFunction = WTFMove(_policyFunction);
-    _policyFunction = nullptr;
-
-    ASSERT(policyFunction);
-    policyFunction(action);
+    if (auto policyFunction = std::exchange(_policyFunction, nullptr))
+        policyFunction(action);
 }
 
 - (void)ignore