Commit 390b102f authored by abarth@webkit.org's avatar abarth@webkit.org

2009-10-07 Adam Barth <abarth@webkit.org>

        Reviewed by Eric Seidel.

        Move PolicyChecker to it's own file
        https://bugs.webkit.org/show_bug.cgi?id=30193

        This is just moving code around and re-naming things.

        * GNUmakefile.am:
        * WebCore.gypi:
        * WebCore.pro:
        * WebCore.vcproj/WebCore.vcproj:
        * WebCore.xcodeproj/project.pbxproj:
        * loader/FrameLoader.cpp:
        * loader/FrameLoader.h:
        * loader/PolicyCallback.cpp: Added.
        (WebCore::PolicyCallback::PolicyCallback):
        (WebCore::PolicyCallback::~PolicyCallback):
        (WebCore::PolicyCallback::clear):
        (WebCore::PolicyCallback::set):
        (WebCore::PolicyCallback::call):
        (WebCore::PolicyCallback::clearRequest):
        (WebCore::PolicyCallback::cancel):
        * loader/PolicyCallback.h: Added.
        (WebCore::PolicyCallback::request):
        * loader/PolicyCheck.cpp: Removed.
        * loader/PolicyCheck.h: Removed.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@49290 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent eb976d11
2009-10-07 Adam Barth <abarth@webkit.org>
Reviewed by Eric Seidel.
Move PolicyChecker to it's own file
https://bugs.webkit.org/show_bug.cgi?id=30193
This is just moving code around and re-naming things.
* GNUmakefile.am:
* WebCore.gypi:
* WebCore.pro:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* loader/FrameLoader.cpp:
* loader/FrameLoader.h:
* loader/PolicyCallback.cpp: Added.
(WebCore::PolicyCallback::PolicyCallback):
(WebCore::PolicyCallback::~PolicyCallback):
(WebCore::PolicyCallback::clear):
(WebCore::PolicyCallback::set):
(WebCore::PolicyCallback::call):
(WebCore::PolicyCallback::clearRequest):
(WebCore::PolicyCallback::cancel):
* loader/PolicyCallback.h: Added.
(WebCore::PolicyCallback::request):
* loader/PolicyCheck.cpp: Removed.
* loader/PolicyCheck.h: Removed.
2009-10-07 Joel Stanley <joel@jms.id.au>
Reviewed by Mark Rowe.
......@@ -1245,8 +1245,10 @@ webcore_sources += \
WebCore/loader/PlaceholderDocument.h \
WebCore/loader/PluginDocument.cpp \
WebCore/loader/PluginDocument.h \
WebCore/loader/PolicyCheck.cpp \
WebCore/loader/PolicyCheck.h \
WebCore/loader/PolicyCallback.cpp \
WebCore/loader/PolicyCallback.h \
WebCore/loader/PolicyChecker.cpp \
WebCore/loader/PolicyChecker.h \
WebCore/loader/ProgressTracker.cpp \
WebCore/loader/ProgressTracker.h \
WebCore/loader/RedirectScheduler.cpp \
......
......@@ -1631,8 +1631,10 @@
'loader/PlaceholderDocument.h',
'loader/PluginDocument.cpp',
'loader/PluginDocument.h',
'loader/PolicyCheck.cpp',
'loader/PolicyCheck.h',
'loader/PolicyCallback.cpp',
'loader/PolicyCallback.h',
'loader/PolicyChecker.cpp',
'loader/PolicyChecker.h',
'loader/ProgressTracker.cpp',
'loader/ProgressTracker.h',
'loader/RedirectScheduler.cpp',
......
......@@ -1113,7 +1113,8 @@ SOURCES += \
loader/NetscapePlugInStreamLoader.cpp \
loader/PlaceholderDocument.cpp \
loader/PluginDocument.cpp \
loader/PolicyCheck.cpp \
loader/PolicyCallback.cpp \
loader/PolicyChecker.cpp \
loader/ProgressTracker.cpp \
loader/RedirectScheduler.cpp \
loader/Request.cpp \
......
......@@ -17489,11 +17489,19 @@
>
</File>
<File
RelativePath="..\loader\PolicyCheck.cpp"
RelativePath="..\loader\PolicyCallback.cpp"
>
</File>
<File
RelativePath="..\loader\PolicyCheck.h"
RelativePath="..\loader\PolicyCallback.h"
>
</File>
<File
RelativePath="..\loader\PolicyChecker.cpp"
>
</File>
<File
RelativePath="..\loader\PolicyChecker.h"
>
</File>
<File
......
......@@ -2345,10 +2345,12 @@
93F9B7A00BA6032600854064 /* JSCDATASection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93F9B79E0BA6032600854064 /* JSCDATASection.cpp */; };
93F9B7A10BA6032600854064 /* JSCDATASection.h in Headers */ = {isa = PBXBuildFile; fileRef = 93F9B79F0BA6032600854064 /* JSCDATASection.h */; };
93FDAFCA0B11307400E2746F /* EditorInsertAction.h in Headers */ = {isa = PBXBuildFile; fileRef = 93FDAFC90B11307400E2746F /* EditorInsertAction.h */; settings = {ATTRIBUTES = (Private, ); }; };
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, ); }; };
979F43D31075E44A0000F83B /* RedirectScheduler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 979F43D11075E44A0000F83B /* RedirectScheduler.cpp */; };
979F43D41075E44A0000F83B /* RedirectScheduler.h in Headers */ = {isa = PBXBuildFile; fileRef = 979F43D21075E44A0000F83B /* RedirectScheduler.h */; settings = {ATTRIBUTES = (Private, ); }; };
97BC63B81076C97F002C2142 /* PolicyCheck.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 97BC63B61076C97F002C2142 /* PolicyCheck.cpp */; };
97BC63B91076C97F002C2142 /* PolicyCheck.h in Headers */ = {isa = PBXBuildFile; fileRef = 97BC63B71076C97F002C2142 /* PolicyCheck.h */; settings = {ATTRIBUTES = (Private, ); }; };
97DD4D860FDF4D6E00ECF9A4 /* XSSAuditor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 97DD4D840FDF4D6D00ECF9A4 /* XSSAuditor.cpp */; };
97DD4D870FDF4D6E00ECF9A4 /* XSSAuditor.h in Headers */ = {isa = PBXBuildFile; fileRef = 97DD4D850FDF4D6E00ECF9A4 /* XSSAuditor.h */; };
A17C81220F2A5CF7005DAAEB /* HTMLElementFactory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A17C81200F2A5CF7005DAAEB /* HTMLElementFactory.cpp */; };
......@@ -7536,10 +7538,12 @@
93F9B79E0BA6032600854064 /* JSCDATASection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCDATASection.cpp; sourceTree = "<group>"; };
93F9B79F0BA6032600854064 /* JSCDATASection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSCDATASection.h; sourceTree = "<group>"; };
93FDAFC90B11307400E2746F /* EditorInsertAction.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = EditorInsertAction.h; 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>"; };
979F43D11075E44A0000F83B /* RedirectScheduler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RedirectScheduler.cpp; sourceTree = "<group>"; };
979F43D21075E44A0000F83B /* RedirectScheduler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RedirectScheduler.h; sourceTree = "<group>"; };
97BC63B61076C97F002C2142 /* PolicyCheck.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PolicyCheck.cpp; sourceTree = "<group>"; };
97BC63B71076C97F002C2142 /* PolicyCheck.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PolicyCheck.h; sourceTree = "<group>"; };
97DD4D840FDF4D6D00ECF9A4 /* XSSAuditor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XSSAuditor.cpp; sourceTree = "<group>"; };
97DD4D850FDF4D6E00ECF9A4 /* XSSAuditor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XSSAuditor.h; sourceTree = "<group>"; };
A17C81200F2A5CF7005DAAEB /* HTMLElementFactory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLElementFactory.cpp; sourceTree = "<group>"; };
......@@ -14588,8 +14592,10 @@
377C4CDD1014E9F600B9AE42 /* PlaceholderDocument.h */,
1AC694C50A3B1676003F5049 /* PluginDocument.cpp */,
1AC694C60A3B1676003F5049 /* PluginDocument.h */,
97BC63B61076C97F002C2142 /* PolicyCheck.cpp */,
97BC63B71076C97F002C2142 /* PolicyCheck.h */,
97059973107D975200A50A7C /* PolicyCallback.cpp */,
97059974107D975200A50A7C /* PolicyCallback.h */,
97059975107D975200A50A7C /* PolicyChecker.cpp */,
97059976107D975200A50A7C /* PolicyChecker.h */,
1A2A68210B5BEDE70002A480 /* ProgressTracker.cpp */,
1A2A68220B5BEDE70002A480 /* ProgressTracker.h */,
979F43D11075E44A0000F83B /* RedirectScheduler.cpp */,
......@@ -17964,9 +17970,10 @@
979F43D41075E44A0000F83B /* RedirectScheduler.h in Headers */,
BC9462D8107A7B4C00857193 /* BeforeLoadEvent.h in Headers */,
BC946348107A936600857193 /* JSBeforeLoadEvent.h in Headers */,
97BC63B91076C97F002C2142 /* PolicyCheck.h in Headers */,
1449E24C107D4A8400B5793F /* JSCallbackData.h in Headers */,
A75E497610752ACB00C9B896 /* SerializedScriptValue.h in Headers */,
97059978107D975200A50A7C /* PolicyCallback.h in Headers */,
9705997A107D975200A50A7C /* PolicyChecker.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -20086,9 +20093,10 @@
5DB1BC6B10715A6400EFAA49 /* TransformSourceLibxslt.cpp in Sources */,
979F43D31075E44A0000F83B /* RedirectScheduler.cpp in Sources */,
BC946346107A934B00857193 /* JSBeforeLoadEvent.cpp in Sources */,
97BC63B81076C97F002C2142 /* PolicyCheck.cpp in Sources */,
1449E287107D4DB400B5793F /* JSCallbackData.cpp in Sources */,
A75E497710752ACB00C9B896 /* SerializedScriptValue.cpp in Sources */,
97059977107D975200A50A7C /* PolicyCallback.cpp in Sources */,
97059979107D975200A50A7C /* PolicyChecker.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -2163,43 +2163,11 @@ bool FrameLoader::willLoadMediaElementURL(KURL& url)
return error.isNull();
}
void PolicyChecker::handleUnimplementablePolicy(const ResourceError& error)
{
m_delegateIsHandlingUnimplementablePolicy = true;
m_frame->loader()->client()->dispatchUnableToImplementPolicy(error);
m_delegateIsHandlingUnimplementablePolicy = false;
}
void PolicyChecker::cannotShowMIMEType(const ResourceResponse& response)
{
handleUnimplementablePolicy(m_frame->loader()->client()->cannotShowMIMETypeError(response));
}
ResourceError FrameLoader::interruptionForPolicyChangeError(const ResourceRequest& request)
{
return m_client->interruptForPolicyChangeError(request);
}
PolicyChecker::PolicyChecker(Frame* frame)
: m_frame(frame)
, m_delegateIsDecidingNavigationPolicy(false)
, m_delegateIsHandlingUnimplementablePolicy(false)
, m_loadType(FrameLoadTypeStandard)
{
}
void PolicyChecker::checkNavigationPolicy(const ResourceRequest& newRequest, NavigationPolicyDecisionFunction function, void* argument)
{
checkNavigationPolicy(newRequest, m_frame->loader()->activeDocumentLoader(), 0, function, argument);
}
void PolicyChecker::checkContentPolicy(const String& MIMEType, ContentPolicyDecisionFunction function, void* argument)
{
m_policyCheck.set(function, argument);
m_frame->loader()->client()->dispatchDecidePolicyForMIMEType(&PolicyChecker::continueAfterContentPolicy,
MIMEType, m_frame->loader()->activeDocumentLoader()->request());
}
bool FrameLoader::shouldReloadToHandleUnreachableURL(DocumentLoader* docLoader)
{
KURL unreachableURL = docLoader->unreachableURL();
......@@ -2851,12 +2819,6 @@ String FrameLoader::generatedMIMETypeForURLScheme(const String& URLScheme)
return m_client->generatedMIMETypeForURLScheme(URLScheme);
}
void PolicyChecker::cancelCheck()
{
m_frame->loader()->client()->cancelPolicyCheck();
m_policyCheck.clear();
}
void FrameLoader::didReceiveServerRedirectForProvisionalLoadForFrame()
{
m_client->dispatchDidReceiveServerRedirectForProvisionalLoad();
......@@ -2976,14 +2938,6 @@ CachePolicy FrameLoader::subresourceCachePolicy() const
return CachePolicyVerify;
}
void PolicyChecker::stopCheck()
{
m_frame->loader()->client()->cancelPolicyCheck();
PolicyCheck check = m_policyCheck;
m_policyCheck.clear();
check.cancel();
}
void FrameLoader::checkLoadCompleteForThisFrame()
{
ASSERT(m_client->hasWebView());
......@@ -3082,20 +3036,6 @@ void FrameLoader::checkLoadCompleteForThisFrame()
ASSERT_NOT_REACHED();
}
void PolicyChecker::continueAfterContentPolicy(PolicyAction policy)
{
PolicyCheck check = m_policyCheck;
m_policyCheck.clear();
check.call(policy);
}
void PolicyChecker::continueLoadAfterWillSubmitForm(PolicyAction)
{
// See header file for an explaination of why this function
// isn't like the others.
m_frame->loader()->continueLoadAfterWillSubmitForm();
}
void FrameLoader::continueLoadAfterWillSubmitForm()
{
if (!m_provisionalDocumentLoader)
......@@ -3588,100 +3528,6 @@ bool FrameLoader::shouldScrollToAnchor(bool isFormSubmission, FrameLoadType load
&& !m_frame->document()->isFrameSet();
}
void PolicyChecker::checkNewWindowPolicy(const NavigationAction& action, NewWindowPolicyDecisionFunction function,
const ResourceRequest& request, PassRefPtr<FormState> formState, const String& frameName, void* argument)
{
m_policyCheck.set(request, formState, frameName, function, argument);
m_frame->loader()->client()->dispatchDecidePolicyForNewWindowAction(&PolicyChecker::continueAfterNewWindowPolicy,
action, request, formState, frameName);
}
void PolicyChecker::continueAfterNewWindowPolicy(PolicyAction policy)
{
PolicyCheck check = m_policyCheck;
m_policyCheck.clear();
switch (policy) {
case PolicyIgnore:
check.clearRequest();
break;
case PolicyDownload:
m_frame->loader()->client()->startDownload(check.request());
check.clearRequest();
break;
case PolicyUse:
break;
}
check.call(policy == PolicyUse);
}
void PolicyChecker::checkNavigationPolicy(const ResourceRequest& request, DocumentLoader* loader,
PassRefPtr<FormState> formState, NavigationPolicyDecisionFunction function, void* argument)
{
NavigationAction action = loader->triggeringAction();
if (action.isEmpty()) {
action = NavigationAction(request.url(), NavigationTypeOther);
loader->setTriggeringAction(action);
}
// 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(argument, request, 0, true);
loader->setLastCheckedRequest(request);
return;
}
// We are always willing to show alternate content for unreachable URLs;
// treat it like a reload so it maintains the right state for b/f list.
if (loader->substituteData().isValid() && !loader->substituteData().failingURL().isEmpty()) {
if (isBackForwardLoadType(m_loadType))
m_loadType = FrameLoadTypeReload;
function(argument, request, 0, true);
return;
}
loader->setLastCheckedRequest(request);
m_policyCheck.set(request, formState.get(), function, argument);
m_delegateIsDecidingNavigationPolicy = true;
m_frame->loader()->client()->dispatchDecidePolicyForNavigationAction(&PolicyChecker::continueAfterNavigationPolicy,
action, request, formState);
m_delegateIsDecidingNavigationPolicy = false;
}
void PolicyChecker::continueAfterNavigationPolicy(PolicyAction policy)
{
PolicyCheck check = m_policyCheck;
m_policyCheck.clear();
bool shouldContinue = policy == PolicyUse;
switch (policy) {
case PolicyIgnore:
check.clearRequest();
break;
case PolicyDownload:
m_frame->loader()->client()->startDownload(check.request());
check.clearRequest();
break;
case PolicyUse: {
ResourceRequest request(check.request());
if (!m_frame->loader()->client()->canHandleRequest(request)) {
handleUnimplementablePolicy(m_frame->loader()->cannotShowURLError(check.request()));
check.clearRequest();
shouldContinue = false;
}
break;
}
}
check.call(shouldContinue);
}
void FrameLoader::callContinueLoadAfterNavigationPolicy(void* argument,
const ResourceRequest& request, PassRefPtr<FormState> formState, bool shouldContinue)
{
......@@ -3758,7 +3604,6 @@ void FrameLoader::continueLoadAfterNavigationPolicy(const ResourceRequest&, Pass
continueLoadAfterWillSubmitForm();
}
void FrameLoader::callContinueLoadAfterNewWindowPolicy(void* argument,
const ResourceRequest& request, PassRefPtr<FormState> formState, const String& frameName, bool shouldContinue)
{
......
......@@ -32,7 +32,8 @@
#include "CachePolicy.h"
#include "FrameLoaderTypes.h"
#include "PolicyCheck.h"
#include "PolicyCallback.h"
#include "PolicyChecker.h"
#include "RedirectScheduler.h"
#include "ResourceRequest.h"
#include "ThreadableLoader.h"
......@@ -78,53 +79,6 @@ namespace WebCore {
bool isBackForwardLoadType(FrameLoadType);
class PolicyChecker : public Noncopyable {
public:
PolicyChecker(Frame*);
void checkNavigationPolicy(const ResourceRequest&, DocumentLoader*, PassRefPtr<FormState>, NavigationPolicyDecisionFunction, void* argument);
void checkNavigationPolicy(const ResourceRequest&, NavigationPolicyDecisionFunction, void* argument);
void checkNewWindowPolicy(const NavigationAction&, NewWindowPolicyDecisionFunction, const ResourceRequest&, PassRefPtr<FormState>, const String& frameName, void* argument);
void checkContentPolicy(const String& MIMEType, ContentPolicyDecisionFunction, void* argument);
// FIXME: These are different. They could use better names.
void cancelCheck();
void stopCheck();
void cannotShowMIMEType(const ResourceResponse&);
FrameLoadType loadType() const { return m_loadType; }
void setLoadType(FrameLoadType loadType) { m_loadType = loadType; }
bool delegateIsDecidingNavigationPolicy() const { return m_delegateIsDecidingNavigationPolicy; }
bool delegateIsHandlingUnimplementablePolicy() const { return m_delegateIsHandlingUnimplementablePolicy; }
// FIXME: This function is a cheat. Basically, this is just an asynchronouc callback
// from the FrameLoaderClient, but this callback uses the policy types and so has to
// live on this object. In the long term, we should create a type for non-policy
// callbacks from the FrameLoaderClient and remove this vestige. I just don't have
// the heart to hack on all the platforms to make that happen right now.
void continueLoadAfterWillSubmitForm(PolicyAction);
private:
void continueAfterNavigationPolicy(PolicyAction);
void continueAfterNewWindowPolicy(PolicyAction);
void continueAfterContentPolicy(PolicyAction);
void handleUnimplementablePolicy(const ResourceError&);
Frame* m_frame;
bool m_delegateIsDecidingNavigationPolicy;
bool m_delegateIsHandlingUnimplementablePolicy;
// This identifies the type of navigation action which prompted this load. Note
// that WebKit conveys this value as the WebActionNavigationTypeKey value
// on navigation action delegate callbacks.
FrameLoadType m_loadType;
PolicyCheck m_policyCheck;
};
class FrameLoader : public Noncopyable {
public:
FrameLoader(Frame*, FrameLoaderClient*);
......
......@@ -29,7 +29,7 @@
*/
#include "config.h"
#include "PolicyCheck.h"
#include "PolicyCallback.h"
#include "FormState.h"
#include "Frame.h"
......@@ -38,18 +38,18 @@
namespace WebCore {
PolicyCheck::PolicyCheck()
PolicyCallback::PolicyCallback()
: m_navigationFunction(0)
, m_newWindowFunction(0)
, m_contentFunction(0)
{
}
PolicyCheck::~PolicyCheck()
PolicyCallback::~PolicyCallback()
{
}
void PolicyCheck::clear()
void PolicyCallback::clear()
{
clearRequest();
m_navigationFunction = 0;
......@@ -57,7 +57,7 @@ void PolicyCheck::clear()
m_contentFunction = 0;
}
void PolicyCheck::set(const ResourceRequest& request, PassRefPtr<FormState> formState,
void PolicyCallback::set(const ResourceRequest& request, PassRefPtr<FormState> formState,
NavigationPolicyDecisionFunction function, void* argument)
{
m_request = request;
......@@ -70,7 +70,7 @@ void PolicyCheck::set(const ResourceRequest& request, PassRefPtr<FormState> form
m_argument = argument;
}
void PolicyCheck::set(const ResourceRequest& request, PassRefPtr<FormState> formState,
void PolicyCallback::set(const ResourceRequest& request, PassRefPtr<FormState> formState,
const String& frameName, NewWindowPolicyDecisionFunction function, void* argument)
{
m_request = request;
......@@ -83,7 +83,7 @@ void PolicyCheck::set(const ResourceRequest& request, PassRefPtr<FormState> form
m_argument = argument;
}
void PolicyCheck::set(ContentPolicyDecisionFunction function, void* argument)
void PolicyCallback::set(ContentPolicyDecisionFunction function, void* argument)
{
m_request = ResourceRequest();
m_formState = 0;
......@@ -95,7 +95,7 @@ void PolicyCheck::set(ContentPolicyDecisionFunction function, void* argument)
m_argument = argument;
}
void PolicyCheck::call(bool shouldContinue)
void PolicyCallback::call(bool shouldContinue)
{
if (m_navigationFunction)
m_navigationFunction(m_argument, m_request, m_formState.get(), shouldContinue);
......@@ -104,7 +104,7 @@ void PolicyCheck::call(bool shouldContinue)
ASSERT(!m_contentFunction);
}
void PolicyCheck::call(PolicyAction action)
void PolicyCallback::call(PolicyAction action)
{
ASSERT(!m_navigationFunction);
ASSERT(!m_newWindowFunction);
......@@ -112,14 +112,14 @@ void PolicyCheck::call(PolicyAction action)
m_contentFunction(m_argument, action);
}
void PolicyCheck::clearRequest()
void PolicyCallback::clearRequest()
{
m_request = ResourceRequest();
m_formState = 0;
m_frameName = String();
}
void PolicyCheck::cancel()
void PolicyCallback::cancel()
{
clearRequest();
if (m_navigationFunction)
......
......@@ -27,8 +27,8 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef PolicyCheck_h
#define PolicyCheck_h
#ifndef PolicyCallback_h
#define PolicyCallback_h
#include "FrameLoaderTypes.h"
#include "PlatformString.h"
......@@ -45,10 +45,10 @@ namespace WebCore {
const ResourceRequest&, PassRefPtr<FormState>, const String& frameName, bool shouldContinue);
typedef void (*ContentPolicyDecisionFunction)(void* argument, PolicyAction);
class PolicyCheck {
class PolicyCallback {
public:
PolicyCheck();
~PolicyCheck();
PolicyCallback();
~PolicyCallback();
void clear();
void set(const ResourceRequest&, PassRefPtr<FormState>,
......@@ -77,4 +77,4 @@ namespace WebCore {
} // namespace WebCore
#endif // PolicyCheck_h
#endif // PolicyCallback_h
/*
* 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 Computer, 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 "PolicyChecker.h"
#include "DocumentLoader.h"
#include "FormState.h"
#include "Frame.h"
#include "FrameLoader.h"
#include "FrameLoaderClient.h"
#include "HTMLFormElement.h"
namespace WebCore {
PolicyChecker::PolicyChecker(Frame* frame)
: m_frame(frame)
, m_delegateIsDecidingNavigationPolicy(false)
, m_delegateIsHandlingUnimplementablePolicy(false)
, m_loadType(FrameLoadTypeStandard)
{
}
void PolicyChecker::checkNavigationPolicy(const ResourceRequest& newRequest, NavigationPolicyDecisionFunction function, void* argument)
{
checkNavigationPolicy(newRequest, m_frame->loader()->activeDocumentLoader(), 0, function, argument);
}
void PolicyChecker::checkNavigationPolicy(const ResourceRequest& request, DocumentLoader* loader,
PassRefPtr<FormState> formState, NavigationPolicyDecisionFunction function, void* argument)
{
NavigationAction action = loader->triggeringAction();
if (action.isEmpty()) {
action = NavigationAction(request.url(), NavigationTypeOther);
loader->setTriggeringAction(action);
}
// 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(argument, request, 0, true);
loader->setLastCheckedRequest(request);
return;
}
// We are always willing to show alternate content for unreachable URLs;
// treat it like a reload so it maintains the right state for b/f list.
if (loader->substituteData().isValid() && !loader->substituteData().failingURL().isEmpty()) {
if (isBackForwardLoadType(m_loadType))
m_loadType = FrameLoadTypeReload;
function(argument, request, 0, true);
return;
}
loader->setLastCheckedRequest(request);
m_callback.set(request, formState.get(), function, argument);
m_delegateIsDecidingNavigationPolicy = true;
m_frame->loader()->client()->dispatchDecidePolicyForNavigationAction(&PolicyChecker::continueAfterNavigationPolicy,
action, request, formState);
m_delegateIsDecidingNavigationPolicy = false;
}
void PolicyChecker::checkNewWindowPolicy(const NavigationAction& action, NewWindowPolicyDecisionFunction function,
const ResourceRequest& request, PassRefPtr<FormState> formState, const String& frameName, void* argument)
{
m_callback.set(request, formState, frameName, function, argument);
m_frame->loader()->client()->dispatchDecidePolicyForNewWindowAction(&PolicyChecker::continueAfterNewWindowPolicy,