Skip to content

Commit

Permalink
Merge r221103 - Stop using PolicyChecker for ContentPolicy
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=175904

Reviewed by Tim Horton.

PolicyChecker is an artifact from the days before C++11.  Now we have lambdas which
have a cleaner flow than one class that exists to be effectively one of three lambda types.
Let's remove them one at a time, starting with ContentPolicy checks.

No change in behaviour.

* loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::responseReceived):
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::checkContentPolicy):
* loader/FrameLoader.h:
* loader/PolicyCallback.cpp:
(WebCore::PolicyCallback::set):
(WebCore::PolicyCallback::call):
(WebCore::PolicyCallback::cancel):
* loader/PolicyCallback.h:
* loader/PolicyChecker.cpp:
(WebCore::PolicyChecker::checkContentPolicy): Deleted.
(WebCore::PolicyChecker::continueAfterContentPolicy): Deleted.
* loader/PolicyChecker.h:
  • Loading branch information
achristensen07 authored and carlosgcampos committed Aug 30, 2017
1 parent bc3d1c8 commit 9f69772
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 45 deletions.
28 changes: 28 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,31 @@
2017-08-23 Alex Christensen <achristensen@webkit.org>

Stop using PolicyChecker for ContentPolicy
https://bugs.webkit.org/show_bug.cgi?id=175904

Reviewed by Tim Horton.

PolicyChecker is an artifact from the days before C++11. Now we have lambdas which
have a cleaner flow than one class that exists to be effectively one of three lambda types.
Let's remove them one at a time, starting with ContentPolicy checks.

No change in behaviour.

* loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::responseReceived):
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::checkContentPolicy):
* loader/FrameLoader.h:
* loader/PolicyCallback.cpp:
(WebCore::PolicyCallback::set):
(WebCore::PolicyCallback::call):
(WebCore::PolicyCallback::cancel):
* loader/PolicyCallback.h:
* loader/PolicyChecker.cpp:
(WebCore::PolicyChecker::checkContentPolicy): Deleted.
(WebCore::PolicyChecker::continueAfterContentPolicy): Deleted.
* loader/PolicyChecker.h:

2017-08-22 Zan Dobersek <zdobersek@igalia.com>

GLContext: zero-initialize the GLContext pointer in ThreadGlobalGLContext
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/loader/DocumentLoader.cpp
Expand Up @@ -704,7 +704,7 @@ void DocumentLoader::responseReceived(const ResourceResponse& response)
}
#endif

frameLoader()->policyChecker().checkContentPolicy(m_response, [this](PolicyAction policy) {
frameLoader()->checkContentPolicy(m_response, [this](PolicyAction policy) {
continueAfterContentPolicy(policy);
});
}
Expand Down
5 changes: 5 additions & 0 deletions Source/WebCore/loader/FrameLoader.cpp
Expand Up @@ -355,6 +355,11 @@ void FrameLoader::setDefersLoading(bool defers)
}
}

void FrameLoader::checkContentPolicy(const ResourceResponse& response, ContentPolicyDecisionFunction&& function)
{
client().dispatchDecidePolicyForResponse(response, activeDocumentLoader()->request(), WTFMove(function));
}

void FrameLoader::changeLocation(FrameLoadRequest&& request)
{
urlSelected(WTFMove(request), nullptr);
Expand Down
4 changes: 4 additions & 0 deletions Source/WebCore/loader/FrameLoader.h
Expand Up @@ -83,6 +83,8 @@ struct WindowFeatures;
WEBCORE_EXPORT bool isBackForwardLoadType(FrameLoadType);
WEBCORE_EXPORT bool isReload(FrameLoadType);

using ContentPolicyDecisionFunction = WTF::Function<void(PolicyAction)>;

class FrameLoader {
WTF_MAKE_NONCOPYABLE(FrameLoader);
public:
Expand Down Expand Up @@ -207,6 +209,8 @@ class FrameLoader {

void setDefersLoading(bool);

void checkContentPolicy(const ResourceResponse&, ContentPolicyDecisionFunction&&);

void didExplicitOpen();

// Callbacks from DocumentWriter
Expand Down
24 changes: 0 additions & 24 deletions Source/WebCore/loader/PolicyCallback.cpp
Expand Up @@ -46,7 +46,6 @@ void PolicyCallback::set(const ResourceRequest& request, FormState* formState, N

m_navigationFunction = WTFMove(function);
m_newWindowFunction = nullptr;
m_contentFunction = nullptr;
}

void PolicyCallback::set(const ResourceRequest& request, FormState* formState, const String& frameName, const NavigationAction& navigationAction, NewWindowPolicyDecisionFunction&& function)
Expand All @@ -58,18 +57,6 @@ void PolicyCallback::set(const ResourceRequest& request, FormState* formState, c

m_navigationFunction = nullptr;
m_newWindowFunction = WTFMove(function);
m_contentFunction = nullptr;
}

void PolicyCallback::set(ContentPolicyDecisionFunction&& function)
{
m_request = ResourceRequest();
m_formState = nullptr;
m_frameName = String();

m_navigationFunction = nullptr;
m_newWindowFunction = nullptr;
m_contentFunction = WTFMove(function);
}

void PolicyCallback::call(bool shouldContinue)
Expand All @@ -78,15 +65,6 @@ void PolicyCallback::call(bool shouldContinue)
m_navigationFunction(m_request, m_formState.get(), shouldContinue);
if (m_newWindowFunction)
m_newWindowFunction(m_request, m_formState.get(), m_frameName, m_navigationAction, shouldContinue);
ASSERT(!m_contentFunction);
}

void PolicyCallback::call(PolicyAction action)
{
ASSERT(!m_navigationFunction);
ASSERT(!m_newWindowFunction);
ASSERT(m_contentFunction);
m_contentFunction(action);
}

void PolicyCallback::clearRequest()
Expand All @@ -103,8 +81,6 @@ void PolicyCallback::cancel()
m_navigationFunction(m_request, m_formState.get(), false);
if (m_newWindowFunction)
m_newWindowFunction(m_request, m_formState.get(), m_frameName, m_navigationAction, false);
if (m_contentFunction)
m_contentFunction(PolicyIgnore);
}

} // namespace WebCore
4 changes: 0 additions & 4 deletions Source/WebCore/loader/PolicyCallback.h
Expand Up @@ -41,21 +41,18 @@ namespace WebCore {

class FormState;

using ContentPolicyDecisionFunction = Function<void(PolicyAction)>;
using NavigationPolicyDecisionFunction = Function<void(const ResourceRequest&, FormState*, bool shouldContinue)>;
using NewWindowPolicyDecisionFunction = Function<void(const ResourceRequest&, FormState*, const String& frameName, const NavigationAction&, bool shouldContinue)>;

class PolicyCallback {
public:
void set(const ResourceRequest&, FormState*, NavigationPolicyDecisionFunction&&);
void set(const ResourceRequest&, FormState*, const String& frameName, const NavigationAction&, NewWindowPolicyDecisionFunction&&);
void set(ContentPolicyDecisionFunction&&);

const ResourceRequest& request() const { return m_request; }
void clearRequest();

void call(bool shouldContinue);
void call(PolicyAction);
void cancel();

private:
Expand All @@ -66,7 +63,6 @@ class PolicyCallback {

NavigationPolicyDecisionFunction m_navigationFunction;
NewWindowPolicyDecisionFunction m_newWindowFunction;
ContentPolicyDecisionFunction m_contentFunction;
};

} // namespace WebCore
14 changes: 0 additions & 14 deletions Source/WebCore/loader/PolicyChecker.cpp
Expand Up @@ -167,14 +167,6 @@ void PolicyChecker::checkNewWindowPolicy(const NavigationAction& action, const R
});
}

void PolicyChecker::checkContentPolicy(const ResourceResponse& response, ContentPolicyDecisionFunction function)
{
m_callback.set(WTFMove(function));
m_frame.loader().client().dispatchDecidePolicyForResponse(response, m_frame.loader().activeDocumentLoader()->request(), [this](PolicyAction action) {
continueAfterContentPolicy(action);
});
}

void PolicyChecker::cancelCheck()
{
m_frame.loader().client().cancelPolicyCheck();
Expand Down Expand Up @@ -251,12 +243,6 @@ void PolicyChecker::continueAfterNewWindowPolicy(PolicyAction policy)
callback.call(policy == PolicyUse);
}

void PolicyChecker::continueAfterContentPolicy(PolicyAction policy)
{
PolicyCallback callback = WTFMove(m_callback);
callback.call(policy);
}

void PolicyChecker::handleUnimplementablePolicy(const ResourceError& error)
{
m_delegateIsHandlingUnimplementablePolicy = true;
Expand Down
2 changes: 0 additions & 2 deletions Source/WebCore/loader/PolicyChecker.h
Expand Up @@ -56,7 +56,6 @@ class PolicyChecker {
void checkNavigationPolicy(const ResourceRequest&, bool didReceiveRedirectResponse, DocumentLoader*, FormState*, NavigationPolicyDecisionFunction);
void checkNavigationPolicy(const ResourceRequest&, bool didReceiveRedirectResponse, NavigationPolicyDecisionFunction);
void checkNewWindowPolicy(const NavigationAction&, const ResourceRequest&, FormState*, const String& frameName, NewWindowPolicyDecisionFunction);
void checkContentPolicy(const ResourceResponse&, ContentPolicyDecisionFunction);

// FIXME: These are different. They could use better names.
void cancelCheck();
Expand Down Expand Up @@ -86,7 +85,6 @@ class PolicyChecker {
private:
void continueAfterNavigationPolicy(PolicyAction);
void continueAfterNewWindowPolicy(PolicyAction);
void continueAfterContentPolicy(PolicyAction);

void handleUnimplementablePolicy(const ResourceError&);

Expand Down

0 comments on commit 9f69772

Please sign in to comment.