Stop using PolicyCallback
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: http://svn.webkit.org/repository/webkit/trunk@222472 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/loader/DocumentLoader.cpp b/Source/WebCore/loader/DocumentLoader.cpp
index 3bdbd6f..1790f90 100644
--- a/Source/WebCore/loader/DocumentLoader.cpp
+++ b/Source/WebCore/loader/DocumentLoader.cpp
@@ -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>
diff --git a/Source/WebCore/loader/FrameLoader.cpp b/Source/WebCore/loader/FrameLoader.cpp
index a7d32a9..085826a 100644
--- a/Source/WebCore/loader/FrameLoader.cpp
+++ b/Source/WebCore/loader/FrameLoader.cpp
@@ -119,6 +119,7 @@
#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>
diff --git a/Source/WebCore/loader/FrameLoaderClient.h b/Source/WebCore/loader/FrameLoaderClient.h
index f1aad8f..8e29d61 100644
--- a/Source/WebCore/loader/FrameLoaderClient.h
+++ b/Source/WebCore/loader/FrameLoaderClient.h
@@ -84,7 +84,6 @@
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
index 608a14e..0000000
--- a/Source/WebCore/loader/PolicyCallback.cpp
+++ /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
index d8c335d..0000000
--- a/Source/WebCore/loader/PolicyCallback.h
+++ /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
diff --git a/Source/WebCore/loader/PolicyChecker.cpp b/Source/WebCore/loader/PolicyChecker.cpp
index 9341bbc..824fd3e 100644
--- a/Source/WebCore/loader/PolicyChecker.cpp
+++ b/Source/WebCore/loader/PolicyChecker.cpp
@@ -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 @@
{
}
-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 @@
// 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 @@
#endif
if (isBackForwardLoadType(m_loadType))
m_loadType = FrameLoadType::Reload;
- function(request, 0, shouldContinue);
+ function(request, nullptr, shouldContinue);
return;
}
@@ -116,20 +117,16 @@
// 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 @@
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::stopCheck()
{
m_frame.loader().client().cancelPolicyCheck();
- PolicyCallback callback = WTFMove(m_callback);
- callback.cancel();
}
void PolicyChecker::cannotShowMIMEType(const ResourceResponse& response)
@@ -189,38 +198,6 @@
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;
diff --git a/Source/WebCore/loader/PolicyChecker.h b/Source/WebCore/loader/PolicyChecker.h
index ef4cc9c..d47e36c 100644
--- a/Source/WebCore/loader/PolicyChecker.h
+++ b/Source/WebCore/loader/PolicyChecker.h
@@ -30,7 +30,6 @@
#pragma once
#include "FrameLoaderTypes.h"
-#include "PolicyCallback.h"
#include "ResourceRequest.h"
#include <wtf/text/WTFString.h>
@@ -38,6 +37,10 @@
#include "ContentFilterUnblockHandler.h"
#endif
+namespace WTF {
+template<typename> class CompletionHandler;
+}
+
namespace WebCore {
class DocumentLoader;
@@ -47,7 +50,8 @@
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 @@
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 @@
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 @@
#endif
private:
- void continueAfterNavigationPolicy(PolicyAction);
-
void handleUnimplementablePolicy(const ResourceError&);
Frame& m_frame;
@@ -89,8 +89,6 @@
// 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;