Commit f9b0abcc authored by mitz@apple.com's avatar mitz@apple.com

Give the policy client the originating frame of a navigation action

https://bugs.webkit.org/show_bug.cgi?id=124431

Reviewed by Anders Carlsson.

Source/WebKit2: 

* Platform/CoreIPC/HandleMessage.h:
(CoreIPC::callMemberFunction): Added a seventh message parameter to this template.

* Shared/APIClientTraits.cpp: Defined API traits for WKPagePolicyClient, which now has two
versions.
* Shared/APIClientTraits.h: Declared APIClientTraits<WKPagePolicyClient>.

* UIProcess/API/C/WKPage.h: Added an originatingFrame parameter to
WKPageDecidePolicyForNavigationActionCallback and deprecated the old version. Bumped the
policy client version to 1.

* UIProcess/API/mac/WKBrowsingContextController.mm:
(setUpPagePolicyClient): Include the originating frame’s URL under the a new key in the
action information dictionary.
* UIProcess/API/mac/WKBrowsingContextPolicyDelegate.h: Declared
WKActionOriginatingFrameURLKey.

* UIProcess/WebInspectorProxy.cpp:
(WebKit::decidePolicyForNavigationAction): Added originatingFrame parameter.
(WebKit::WebInspectorProxy::createInspectorPage): Updated to the new version of the policy
client interface.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::decidePolicyForNavigationAction): Added originatingFrameID parameter
and passing the originating frame to the policy client.
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in: Added originatingFrameID paremeter to
DecidePolicyForNavigationAction.

* UIProcess/WebPolicyClient.cpp:
(WebKit::WebPolicyClient::decidePolicyForNavigationAction): Added originatingFrame
parameter, which is passed to the client callback.
* UIProcess/WebPolicyClient.h:

* WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
(WebKit::WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction): Determine the
originating frame for link activation and form submission actions and send its ID in the
DecidePolicyForNavigationAction message.

Tools: 

* MiniBrowser/mac/WK2BrowserWindowController.m:
(decidePolicyForNavigationAction): Added originatingFrame parameter.
(-[WK2BrowserWindowController awakeFromNib]): Updated for the new version of the policy
client.

* TestWebKitAPI/Tests/WebKit2/DownloadDecideDestinationCrash.cpp:
(TestWebKitAPI::decidePolicyForNavigationAction): Added originatingFrame parameter.
(TestWebKitAPI::setPagePolicyClient): Updated for the new version of the policy client.

* TestWebKitAPI/Tests/WebKit2/PageLoadBasic.cpp:
(TestWebKitAPI::decidePolicyForNavigationAction): Added originatingFrame parameter.
(TestWebKitAPI::TEST): Updated for the new version of the policy client.

* WebKitTestRunner/TestController.cpp:
(WTR::TestController::createWebViewWithOptions): Updated for the new version of the policy
client.
(WTR::TestController::decidePolicyForNavigationAction): Added originatingFrame parameter.
* WebKitTestRunner/TestController.h:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@159358 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 1aa38677
2013-11-15 Dan Bernstein <mitz@apple.com>
Give the policy client the originating frame of a navigation action
https://bugs.webkit.org/show_bug.cgi?id=124431
Reviewed by Anders Carlsson.
* Platform/CoreIPC/HandleMessage.h:
(CoreIPC::callMemberFunction): Added a seventh message parameter to this template.
* Shared/APIClientTraits.cpp: Defined API traits for WKPagePolicyClient, which now has two
versions.
* Shared/APIClientTraits.h: Declared APIClientTraits<WKPagePolicyClient>.
* UIProcess/API/C/WKPage.h: Added an originatingFrame parameter to
WKPageDecidePolicyForNavigationActionCallback and deprecated the old version. Bumped the
policy client version to 1.
* UIProcess/API/mac/WKBrowsingContextController.mm:
(setUpPagePolicyClient): Include the originating frame’s URL under the a new key in the
action information dictionary.
* UIProcess/API/mac/WKBrowsingContextPolicyDelegate.h: Declared
WKActionOriginatingFrameURLKey.
* UIProcess/WebInspectorProxy.cpp:
(WebKit::decidePolicyForNavigationAction): Added originatingFrame parameter.
(WebKit::WebInspectorProxy::createInspectorPage): Updated to the new version of the policy
client interface.
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::decidePolicyForNavigationAction): Added originatingFrameID parameter
and passing the originating frame to the policy client.
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in: Added originatingFrameID paremeter to
DecidePolicyForNavigationAction.
* UIProcess/WebPolicyClient.cpp:
(WebKit::WebPolicyClient::decidePolicyForNavigationAction): Added originatingFrame
parameter, which is passed to the client callback.
* UIProcess/WebPolicyClient.h:
* WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
(WebKit::WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction): Determine the
originating frame for link activation and form submission actions and send its ID in the
DecidePolicyForNavigationAction message.
2013-11-15 Brady Eidson <beidson@apple.com>
Move execution of IDBTransactionBackendOperations to the IDBServerConnection
......
......@@ -358,10 +358,10 @@ void callMemberFunction(std::tuple<P1, P2, P3, P4, P5, P6>&& args, MessageDecode
(object->*function)(std::get<0>(args), std::get<1>(args), std::get<2>(args), std::get<3>(args), std::get<4>(args), std::get<5>(args), decoder, std::get<0>(replyArgs), std::get<1>(replyArgs));
}
template<typename C, typename MF, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename R1, typename R2, typename R3>
void callMemberFunction(std::tuple<P1, P2, P3, P4, P5, P6>&& args, MessageDecoder& decoder, std::tuple<R1, R2, R3>& replyArgs, C* object, MF function)
template<typename C, typename MF, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename R1, typename R2, typename R3>
void callMemberFunction(std::tuple<P1, P2, P3, P4, P5, P6, P7>&& args, MessageDecoder& decoder, std::tuple<R1, R2, R3>& replyArgs, C* object, MF function)
{
(object->*function)(std::get<0>(args), std::get<1>(args), std::get<2>(args), std::get<3>(args), std::get<4>(args), std::get<5>(args), decoder, std::get<0>(replyArgs), std::get<1>(replyArgs), std::get<2>(replyArgs));
(object->*function)(std::get<0>(args), std::get<1>(args), std::get<2>(args), std::get<3>(args), std::get<4>(args), std::get<5>(args), std::get<6>(args), decoder, std::get<0>(replyArgs), std::get<1>(replyArgs), std::get<2>(replyArgs));
}
// Main dispatch functions
......
......@@ -71,6 +71,11 @@ const size_t APIClientTraits<WKPageLoaderClient>::interfaceSizesByVersion[] = {
sizeof(WKPageLoaderClient)
};
const size_t APIClientTraits<WKPagePolicyClient>::interfaceSizesByVersion[] = {
offsetof(WKPagePolicyClient, decidePolicyForNavigationAction),
sizeof(WKPagePolicyClient)
};
const size_t APIClientTraits<WKPageUIClient>::interfaceSizesByVersion[] = {
offsetof(WKPageUIClient, createNewPage),
offsetof(WKPageUIClient, showColorPicker),
......
......@@ -68,6 +68,10 @@ template<> struct APIClientTraits<WKPageLoaderClient> {
static const size_t interfaceSizesByVersion[4];
};
template<> struct APIClientTraits<WKPagePolicyClient> {
static const size_t interfaceSizesByVersion[2];
};
template<> struct APIClientTraits<WKPageUIClient> {
static const size_t interfaceSizesByVersion[3];
};
......
......@@ -148,22 +148,28 @@ typedef struct WKPageLoaderClient WKPageLoaderClient;
enum { kWKPageLoaderClientCurrentVersion = 3 };
// Policy Client.
typedef void (*WKPageDecidePolicyForNavigationActionCallback)(WKPageRef page, WKFrameRef frame, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKEventMouseButton mouseButton, WKURLRequestRef request, WKFramePolicyListenerRef listener, WKTypeRef userData, const void* clientInfo);
typedef void (*WKPageDecidePolicyForNavigationActionCallback)(WKPageRef page, WKFrameRef frame, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKEventMouseButton mouseButton, WKFrameRef originatingFrame, WKURLRequestRef request, WKFramePolicyListenerRef listener, WKTypeRef userData, const void* clientInfo);
typedef void (*WKPageDecidePolicyForNewWindowActionCallback)(WKPageRef page, WKFrameRef frame, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKEventMouseButton mouseButton, WKURLRequestRef request, WKStringRef frameName, WKFramePolicyListenerRef listener, WKTypeRef userData, const void* clientInfo);
typedef void (*WKPageDecidePolicyForResponseCallback)(WKPageRef page, WKFrameRef frame, WKURLResponseRef response, WKURLRequestRef request, WKFramePolicyListenerRef listener, WKTypeRef userData, const void* clientInfo);
typedef void (*WKPageUnableToImplementPolicyCallback)(WKPageRef page, WKFrameRef frame, WKErrorRef error, WKTypeRef userData, const void* clientInfo);
// Deprecated
typedef void (*WKPageDecidePolicyForNavigationActionCallback_deprecatedForUseWithV0)(WKPageRef page, WKFrameRef frame, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKEventMouseButton mouseButton, WKURLRequestRef request, WKFramePolicyListenerRef listener, WKTypeRef userData, const void* clientInfo);
struct WKPagePolicyClient {
int version;
const void * clientInfo;
WKPageDecidePolicyForNavigationActionCallback decidePolicyForNavigationAction;
WKPageDecidePolicyForNewWindowActionCallback decidePolicyForNewWindowAction;
WKPageDecidePolicyForResponseCallback decidePolicyForResponse;
WKPageUnableToImplementPolicyCallback unableToImplementPolicy;
int version;
const void * clientInfo;
WKPageDecidePolicyForNavigationActionCallback_deprecatedForUseWithV0 decidePolicyForNavigationAction_deprecatedForUseWithV0;
WKPageDecidePolicyForNewWindowActionCallback decidePolicyForNewWindowAction;
WKPageDecidePolicyForResponseCallback decidePolicyForResponse;
WKPageUnableToImplementPolicyCallback unableToImplementPolicy;
// Version 1
WKPageDecidePolicyForNavigationActionCallback decidePolicyForNavigationAction;
};
typedef struct WKPagePolicyClient WKPagePolicyClient;
enum { kWKPagePolicyClientCurrentVersion = 0 };
enum { kWKPagePolicyClientCurrentVersion = 1 };
// Form Client.
typedef void (*WKPageWillSubmitFormCallback)(WKPageRef page, WKFrameRef frame, WKFrameRef sourceFrame, WKDictionaryRef values, WKTypeRef userData, WKFormSubmissionListenerRef listener, const void* clientInfo);
......
......@@ -81,6 +81,7 @@ NSString * const WKActionModifierFlagsKey = @"WKActionModifierFlagsKey";
NSString * const WKActionURLRequestKey = @"WKActionURLRequestKey";
NSString * const WKActionURLResponseKey = @"WKActionURLResponseKey";
NSString * const WKActionFrameNameKey = @"WKActionFrameNameKey";
NSString * const WKActionOriginatingFrameURLKey = @"WKActionOriginatingFrameURLKey";
@interface WKBrowsingContextControllerData : NSObject {
@public
......@@ -622,7 +623,7 @@ static void setUpPagePolicyClient(WKBrowsingContextController *browsingContext,
policyClient.version = kWKPagePolicyClientCurrentVersion;
policyClient.clientInfo = browsingContext;
policyClient.decidePolicyForNavigationAction = [](WKPageRef page, WKFrameRef frame, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKEventMouseButton mouseButton, WKURLRequestRef request, WKFramePolicyListenerRef listener, WKTypeRef userData, const void* clientInfo)
policyClient.decidePolicyForNavigationAction = [](WKPageRef page, WKFrameRef frame, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKEventMouseButton mouseButton, WKFrameRef originatingFrame, WKURLRequestRef request, WKFramePolicyListenerRef listener, WKTypeRef userData, const void* clientInfo)
{
WKBrowsingContextController *browsingContext = (WKBrowsingContextController *)clientInfo;
if ([browsingContext.policyDelegate respondsToSelector:@selector(browsingContextController:decidePolicyForNavigationAction:decisionHandler:)]) {
......@@ -633,6 +634,11 @@ static void setUpPagePolicyClient(WKBrowsingContextController *browsingContext,
WKActionMouseButtonKey: @(mouseButton),
WKActionURLRequestKey: adoptNS(WKURLRequestCopyNSURLRequest(request)).get()
};
if (originatingFrame) {
actionDictionary = [[actionDictionary mutableCopy] autorelease];
[(NSMutableDictionary *)actionDictionary setObject:[NSURL _web_URLWithWTFString:toImpl(originatingFrame)->url() relativeToURL:nil] forKey:WKActionOriginatingFrameURLKey];
}
[browsingContext.policyDelegate browsingContextController:browsingContext decidePolicyForNavigationAction:actionDictionary decisionHandler:makePolicyDecisionBlock(listener)];
} else
......
......@@ -28,13 +28,14 @@
@class WKBrowsingContextController;
/* Constants for policy action dictionaries */
WK_EXPORT extern NSString * const WKActionIsMainFrameKey; // NSNumber (BOOL)
WK_EXPORT extern NSString * const WKActionNavigationTypeKey; // NSNumber (WKNavigationType)
WK_EXPORT extern NSString * const WKActionMouseButtonKey; // NSNumber (0 for left button, 1 for middle button, 2 for right button)
WK_EXPORT extern NSString * const WKActionModifierFlagsKey; // NSNumber (unsigned)
WK_EXPORT extern NSString * const WKActionURLRequestKey; // NSURLRequest
WK_EXPORT extern NSString * const WKActionURLResponseKey; // NSURLResponse
WK_EXPORT extern NSString * const WKActionFrameNameKey; // NSString
WK_EXPORT extern NSString * const WKActionIsMainFrameKey; // NSNumber (BOOL)
WK_EXPORT extern NSString * const WKActionNavigationTypeKey; // NSNumber (WKNavigationType)
WK_EXPORT extern NSString * const WKActionMouseButtonKey; // NSNumber (0 for left button, 1 for middle button, 2 for right button)
WK_EXPORT extern NSString * const WKActionModifierFlagsKey; // NSNumber (unsigned)
WK_EXPORT extern NSString * const WKActionURLRequestKey; // NSURLRequest
WK_EXPORT extern NSString * const WKActionURLResponseKey; // NSURLResponse
WK_EXPORT extern NSString * const WKActionFrameNameKey; // NSString
WK_EXPORT extern NSString * const WKActionOriginatingFrameURLKey; // NSURL
typedef NS_ENUM(NSUInteger, WKNavigationType) {
WKNavigationTypeLinkClicked,
......
......@@ -372,7 +372,7 @@ static bool isMainInspectorPage(const WebInspectorProxy* webInspectorProxy, WKUR
return WebCore::SchemeRegistry::shouldTreatURLSchemeAsLocal(requestURL.protocol()) && decodeURLEscapeSequences(requestURL.path()) == decodeURLEscapeSequences(inspectorURL.path());
}
static void decidePolicyForNavigationAction(WKPageRef, WKFrameRef frameRef, WKFrameNavigationType, WKEventModifiers, WKEventMouseButton, WKURLRequestRef requestRef, WKFramePolicyListenerRef listenerRef, WKTypeRef, const void* clientInfo)
static void decidePolicyForNavigationAction(WKPageRef, WKFrameRef frameRef, WKFrameNavigationType, WKEventModifiers, WKEventMouseButton, WKFrameRef, WKURLRequestRef requestRef, WKFramePolicyListenerRef listenerRef, WKTypeRef, const void* clientInfo)
{
// Allow non-main frames to navigate anywhere.
if (!toImpl(frameRef)->isMainFrame()) {
......@@ -441,10 +441,11 @@ void WebInspectorProxy::createInspectorPage(uint64_t& inspectorPageID, WebPageCr
WKPagePolicyClient policyClient = {
kWKPagePolicyClientCurrentVersion,
this, /* clientInfo */
decidePolicyForNavigationAction,
0, /* decidePolicyForNavigationAction_deprecatedForUseWithV0 */
0, /* decidePolicyForNewWindowAction */
0, /* decidePolicyForResponse */
0 /* unableToImplementPolicy */
0, /* unableToImplementPolicy */
decidePolicyForNavigationAction
};
inspectorPage->initializePolicyClient(&policyClient);
......
......@@ -2403,7 +2403,7 @@ void WebPageProxy::frameDidBecomeFrameSet(uint64_t frameID, bool value)
}
// PolicyClient
void WebPageProxy::decidePolicyForNavigationAction(uint64_t frameID, uint32_t opaqueNavigationType, uint32_t opaqueModifiers, int32_t opaqueMouseButton, const ResourceRequest& request, uint64_t listenerID, CoreIPC::MessageDecoder& decoder, bool& receivedPolicyAction, uint64_t& policyAction, uint64_t& downloadID)
void WebPageProxy::decidePolicyForNavigationAction(uint64_t frameID, uint32_t opaqueNavigationType, uint32_t opaqueModifiers, int32_t opaqueMouseButton, uint64_t originatingFrameID, const ResourceRequest& request, uint64_t listenerID, CoreIPC::MessageDecoder& decoder, bool& receivedPolicyAction, uint64_t& policyAction, uint64_t& downloadID)
{
RefPtr<API::Object> userData;
WebContextUserMessageDecoder messageDecoder(userData, m_process.get());
......@@ -2420,6 +2420,7 @@ void WebPageProxy::decidePolicyForNavigationAction(uint64_t frameID, uint32_t op
NavigationType navigationType = static_cast<NavigationType>(opaqueNavigationType);
WebEvent::Modifiers modifiers = static_cast<WebEvent::Modifiers>(opaqueModifiers);
WebMouseEvent::Button mouseButton = static_cast<WebMouseEvent::Button>(opaqueMouseButton);
WebFrameProxy* originatingFrame = m_process->webFrame(originatingFrameID);
RefPtr<WebFramePolicyListenerProxy> listener = frame->setUpPolicyListenerProxy(listenerID);
......@@ -2428,7 +2429,7 @@ void WebPageProxy::decidePolicyForNavigationAction(uint64_t frameID, uint32_t op
m_inDecidePolicyForNavigationAction = true;
m_syncNavigationActionPolicyActionIsValid = false;
if (!m_policyClient.decidePolicyForNavigationAction(this, frame, navigationType, modifiers, mouseButton, request, listener.get(), userData.get()))
if (!m_policyClient.decidePolicyForNavigationAction(this, frame, navigationType, modifiers, mouseButton, originatingFrame, request, listener.get(), userData.get()))
listener->use();
m_inDecidePolicyForNavigationAction = false;
......
......@@ -789,7 +789,7 @@ private:
void didChangeProgress(double);
void didFinishProgress();
void decidePolicyForNavigationAction(uint64_t frameID, uint32_t navigationType, uint32_t modifiers, int32_t mouseButton, const WebCore::ResourceRequest&, uint64_t listenerID, CoreIPC::MessageDecoder&, bool& receivedPolicyAction, uint64_t& policyAction, uint64_t& downloadID);
void decidePolicyForNavigationAction(uint64_t frameID, uint32_t navigationType, uint32_t modifiers, int32_t mouseButton, uint64_t originatingFrameID, const WebCore::ResourceRequest&, uint64_t listenerID, CoreIPC::MessageDecoder&, bool& receivedPolicyAction, uint64_t& policyAction, uint64_t& downloadID);
void decidePolicyForNewWindowAction(uint64_t frameID, uint32_t navigationType, uint32_t modifiers, int32_t mouseButton, const WebCore::ResourceRequest&, const String& frameName, uint64_t listenerID, CoreIPC::MessageDecoder&);
void decidePolicyForResponse(uint64_t frameID, const WebCore::ResourceResponse&, const WebCore::ResourceRequest&, uint64_t listenerID, CoreIPC::MessageDecoder&);
void decidePolicyForResponseSync(uint64_t frameID, const WebCore::ResourceResponse&, const WebCore::ResourceRequest&, uint64_t listenerID, CoreIPC::MessageDecoder&, bool& receivedPolicyAction, uint64_t& policyAction, uint64_t& downloadID);
......
......@@ -97,7 +97,7 @@ messages -> WebPageProxy {
# Policy messages
DecidePolicyForResponseSync(uint64_t frameID, WebCore::ResourceResponse response, WebCore::ResourceRequest request, uint64_t listenerID, WebKit::InjectedBundleUserMessageEncoder userData) -> (bool receivedPolicyAction, uint64_t policyAction, uint64_t downloadID) Variadic
DecidePolicyForNavigationAction(uint64_t frameID, uint32_t navigationType, uint32_t modifiers, int32_t mouseButton, WebCore::ResourceRequest request, uint64_t listenerID, WebKit::InjectedBundleUserMessageEncoder userData) -> (bool receivedPolicyAction, uint64_t policyAction, uint64_t downloadID) Variadic
DecidePolicyForNavigationAction(uint64_t frameID, uint32_t navigationType, uint32_t modifiers, int32_t mouseButton, uint64_t originatingFrameID, WebCore::ResourceRequest request, uint64_t listenerID, WebKit::InjectedBundleUserMessageEncoder userData) -> (bool receivedPolicyAction, uint64_t policyAction, uint64_t downloadID) Variadic
DecidePolicyForNewWindowAction(uint64_t frameID, uint32_t navigationType, uint32_t modifiers, int32_t mouseButton, WebCore::ResourceRequest request, WTF::String frameName, uint64_t listenerID, WebKit::InjectedBundleUserMessageEncoder userData) Variadic
UnableToImplementPolicy(uint64_t frameID, WebCore::ResourceError error, WebKit::InjectedBundleUserMessageEncoder userData) Variadic
......
......@@ -34,14 +34,18 @@ using namespace WebCore;
namespace WebKit {
bool WebPolicyClient::decidePolicyForNavigationAction(WebPageProxy* page, WebFrameProxy* frame, NavigationType type, WebEvent::Modifiers modifiers, WebMouseEvent::Button mouseButton, const ResourceRequest& resourceRequest, WebFramePolicyListenerProxy* listener, API::Object* userData)
bool WebPolicyClient::decidePolicyForNavigationAction(WebPageProxy* page, WebFrameProxy* frame, NavigationType type, WebEvent::Modifiers modifiers, WebMouseEvent::Button mouseButton, WebFrameProxy* originatingFrame, const ResourceRequest& resourceRequest, WebFramePolicyListenerProxy* listener, API::Object* userData)
{
if (!m_client.decidePolicyForNavigationAction)
if (!m_client.decidePolicyForNavigationAction_deprecatedForUseWithV0 && !m_client.decidePolicyForNavigationAction)
return false;
RefPtr<WebURLRequest> request = WebURLRequest::create(resourceRequest);
m_client.decidePolicyForNavigationAction(toAPI(page), toAPI(frame), toAPI(type), toAPI(modifiers), toAPI(mouseButton), toAPI(request.get()), toAPI(listener), toAPI(userData), m_client.clientInfo);
if (m_client.decidePolicyForNavigationAction_deprecatedForUseWithV0)
m_client.decidePolicyForNavigationAction_deprecatedForUseWithV0(toAPI(page), toAPI(frame), toAPI(type), toAPI(modifiers), toAPI(mouseButton), toAPI(request.get()), toAPI(listener), toAPI(userData), m_client.clientInfo);
else
m_client.decidePolicyForNavigationAction(toAPI(page), toAPI(frame), toAPI(type), toAPI(modifiers), toAPI(mouseButton), toAPI(originatingFrame), toAPI(request.get()), toAPI(listener), toAPI(userData), m_client.clientInfo);
return true;
}
......
......@@ -50,7 +50,7 @@ class WebFramePolicyListenerProxy;
class WebPolicyClient : public APIClient<WKPagePolicyClient, kWKPagePolicyClientCurrentVersion> {
public:
bool decidePolicyForNavigationAction(WebPageProxy*, WebFrameProxy*, WebCore::NavigationType, WebEvent::Modifiers, WebMouseEvent::Button, const WebCore::ResourceRequest&, WebFramePolicyListenerProxy*, API::Object* userData);
bool decidePolicyForNavigationAction(WebPageProxy*, WebFrameProxy*, WebCore::NavigationType, WebEvent::Modifiers, WebMouseEvent::Button, WebFrameProxy* originatingFrame, const WebCore::ResourceRequest&, WebFramePolicyListenerProxy*, API::Object* userData);
bool decidePolicyForNewWindowAction(WebPageProxy*, WebFrameProxy*, WebCore::NavigationType, WebEvent::Modifiers, WebMouseEvent::Button, const WebCore::ResourceRequest&, const String& frameName, WebFramePolicyListenerProxy*, API::Object* userData);
bool decidePolicyForResponse(WebPageProxy*, WebFrameProxy*, const WebCore::ResourceResponse&, const WebCore::ResourceRequest&, WebFramePolicyListenerProxy*, API::Object* userData);
void unableToImplementPolicy(WebPageProxy*, WebFrameProxy*, const WebCore::ResourceError&, API::Object* userData);
......
......@@ -676,7 +676,7 @@ void WebFrameLoaderClient::dispatchDecidePolicyForNewWindowAction(const Navigati
webPage->send(Messages::WebPageProxy::DecidePolicyForNewWindowAction(m_frame->frameID(), action->navigationType(), action->modifiers(), action->mouseButton(), request, frameName, listenerID, InjectedBundleUserMessageEncoder(userData.get())));
}
void WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction(const NavigationAction& navigationAction, const ResourceRequest& request, PassRefPtr<FormState> formState, FramePolicyFunction function)
void WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction(const NavigationAction& navigationAction, const ResourceRequest& request, PassRefPtr<FormState> prpFormState, FramePolicyFunction function)
{
WebPage* webPage = m_frame->page();
if (!webPage)
......@@ -689,6 +689,7 @@ void WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction(const Navigat
}
RefPtr<API::Object> userData;
RefPtr<FormState> formState = prpFormState;
RefPtr<InjectedBundleNavigationAction> action = InjectedBundleNavigationAction::create(m_frame, navigationAction, formState);
......@@ -704,8 +705,26 @@ void WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction(const Navigat
uint64_t policyAction;
uint64_t downloadID;
RefPtr<WebFrame> originatingFrame;
switch (action->navigationType()) {
case NavigationTypeLinkClicked:
originatingFrame = action->hitTestResult()->frame();
break;
case NavigationTypeFormSubmitted:
case NavigationTypeFormResubmitted:
if (formState) {
if (WebFrameLoaderClient* originatingFrameLoaderClient = toWebFrameLoaderClient(formState->sourceDocument()->frame()->loader().client()))
originatingFrame = originatingFrameLoaderClient->webFrame();
}
break;
case NavigationTypeBackForward:
case NavigationTypeReload:
case NavigationTypeOther:
break;
}
// Notify the UIProcess.
if (!webPage->sendSync(Messages::WebPageProxy::DecidePolicyForNavigationAction(m_frame->frameID(), action->navigationType(), action->modifiers(), action->mouseButton(), request, listenerID, InjectedBundleUserMessageEncoder(userData.get())), Messages::WebPageProxy::DecidePolicyForNavigationAction::Reply(receivedPolicyAction, policyAction, downloadID)))
if (!webPage->sendSync(Messages::WebPageProxy::DecidePolicyForNavigationAction(m_frame->frameID(), action->navigationType(), action->modifiers(), action->mouseButton(), originatingFrame ? originatingFrame->frameID() : 0, request, listenerID, InjectedBundleUserMessageEncoder(userData.get())), Messages::WebPageProxy::DecidePolicyForNavigationAction::Reply(receivedPolicyAction, policyAction, downloadID)))
return;
// We call this synchronously because WebCore cannot gracefully handle a frame load without a synchronous navigation policy reply.
......
2013-11-15 Dan Bernstein <mitz@apple.com>
Give the policy client the originating frame of a navigation action
https://bugs.webkit.org/show_bug.cgi?id=124431
Reviewed by Anders Carlsson.
* MiniBrowser/mac/WK2BrowserWindowController.m:
(decidePolicyForNavigationAction): Added originatingFrame parameter.
(-[WK2BrowserWindowController awakeFromNib]): Updated for the new version of the policy
client.
* TestWebKitAPI/Tests/WebKit2/DownloadDecideDestinationCrash.cpp:
(TestWebKitAPI::decidePolicyForNavigationAction): Added originatingFrame parameter.
(TestWebKitAPI::setPagePolicyClient): Updated for the new version of the policy client.
* TestWebKitAPI/Tests/WebKit2/PageLoadBasic.cpp:
(TestWebKitAPI::decidePolicyForNavigationAction): Added originatingFrame parameter.
(TestWebKitAPI::TEST): Updated for the new version of the policy client.
* WebKitTestRunner/TestController.cpp:
(WTR::TestController::createWebViewWithOptions): Updated for the new version of the policy
client.
(WTR::TestController::decidePolicyForNavigationAction): Added originatingFrame parameter.
* WebKitTestRunner/TestController.h:
2013-11-15 Tim Horton <timothy_horton@apple.com>
build.webkit.org/dashboard should provide a way to focus on a subset of bots
......
......@@ -414,7 +414,7 @@ static void didChangeBackForwardList(WKPageRef page, WKBackForwardListItemRef ad
// MARK: Policy Client Callbacks
static void decidePolicyForNavigationAction(WKPageRef page, WKFrameRef frame, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKEventMouseButton mouseButton, WKURLRequestRef request, WKFramePolicyListenerRef listener, WKTypeRef userData, const void* clientInfo)
static void decidePolicyForNavigationAction(WKPageRef page, WKFrameRef frame, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKEventMouseButton mouseButton, WKFrameRef originatingFrame, WKURLRequestRef request, WKFramePolicyListenerRef listener, WKTypeRef userData, const void* clientInfo)
{
LOG(@"decidePolicyForNavigationAction");
WKFramePolicyListenerUse(listener);
......@@ -670,10 +670,11 @@ - (void)awakeFromNib
WKPagePolicyClient policyClient = {
kWKPagePolicyClientCurrentVersion,
self, /* clientInfo */
decidePolicyForNavigationAction,
0, /* decidePolicyForNavigationAction_deprecatedForUseWithV0 */
decidePolicyForNewWindowAction,
decidePolicyForResponse,
0 /* unableToImplementPolicy */
0, /* unableToImplementPolicy */
decidePolicyForNavigationAction,
};
WKPageSetPagePolicyClient(_webView.pageRef, &policyClient);
......
......@@ -32,7 +32,7 @@ namespace TestWebKitAPI {
static bool didDecideDestination;
static void decidePolicyForNavigationAction(WKPageRef, WKFrameRef, WKFrameNavigationType, WKEventModifiers, WKEventMouseButton, WKURLRequestRef, WKFramePolicyListenerRef listener, WKTypeRef, const void*)
static void decidePolicyForNavigationAction(WKPageRef, WKFrameRef, WKFrameNavigationType, WKEventModifiers, WKEventMouseButton, WKFrameRef, WKURLRequestRef, WKFramePolicyListenerRef listener, WKTypeRef, const void*)
{
WKFramePolicyListenerDownload(listener);
}
......@@ -57,6 +57,7 @@ static void setPagePolicyClient(WKPageRef page)
{
WKPagePolicyClient policyClient;
memset(&policyClient, 0, sizeof(policyClient));
policyClient.version = 1;
policyClient.decidePolicyForNavigationAction = decidePolicyForNavigationAction;
WKPageSetPagePolicyClient(page, &policyClient);
......
......@@ -85,7 +85,7 @@ static void didFinishLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef us
test1Done = true;
}
static void decidePolicyForNavigationAction(WKPageRef page, WKFrameRef frame, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKEventMouseButton mouseButton, WKURLRequestRef request, WKFramePolicyListenerRef listener, WKTypeRef userData, const void* clientInfo)
static void decidePolicyForNavigationAction(WKPageRef page, WKFrameRef frame, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKEventMouseButton mouseButton, WKFrameRef originatingFrame, WKURLRequestRef request, WKFramePolicyListenerRef listener, WKTypeRef userData, const void* clientInfo)
{
State* state = reinterpret_cast<State*>(const_cast<void*>(clientInfo));
EXPECT_FALSE(state->didStartProvisionalLoadForFrame);
......@@ -128,7 +128,7 @@ TEST(WebKit2, PageLoadBasic)
WKPagePolicyClient policyClient;
memset(&policyClient, 0, sizeof(policyClient));
policyClient.version = 0;
policyClient.version = 1;
policyClient.clientInfo = &state;
policyClient.decidePolicyForNavigationAction = decidePolicyForNavigationAction;
policyClient.decidePolicyForNewWindowAction = decidePolicyForNewWindowAction;
......
......@@ -488,10 +488,11 @@ void TestController::createWebViewWithOptions(WKDictionaryRef options)
WKPagePolicyClient pagePolicyClient = {
kWKPagePolicyClientCurrentVersion,
this,
decidePolicyForNavigationAction,
0, // decidePolicyForNavigationAction_deprecatedForUseWithV0
0, // decidePolicyForNewWindowAction
decidePolicyForResponse,
0, // unableToImplementPolicy
decidePolicyForNavigationAction,
};
WKPageSetPagePolicyClient(m_mainWebView->page(), &pagePolicyClient);
......@@ -1216,7 +1217,7 @@ void TestController::unavailablePluginButtonClicked(WKPageRef, WKPluginUnavailab
printf("MISSING PLUGIN BUTTON PRESSED\n");
}
void TestController::decidePolicyForNavigationAction(WKPageRef, WKFrameRef, WKFrameNavigationType, WKEventModifiers, WKEventMouseButton, WKURLRequestRef, WKFramePolicyListenerRef listener, WKTypeRef, const void* clientInfo)
void TestController::decidePolicyForNavigationAction(WKPageRef, WKFrameRef, WKFrameNavigationType, WKEventModifiers, WKEventMouseButton, WKFrameRef, WKURLRequestRef, WKFramePolicyListenerRef listener, WKTypeRef, const void* clientInfo)
{
static_cast<TestController*>(const_cast<void*>(clientInfo))->decidePolicyForNavigationAction(listener);
}
......
......@@ -152,7 +152,7 @@ private:
void didReceiveAuthenticationChallengeInFrame(WKPageRef, WKFrameRef, WKAuthenticationChallengeRef);
// WKPagePolicyClient
static void decidePolicyForNavigationAction(WKPageRef, WKFrameRef, WKFrameNavigationType, WKEventModifiers, WKEventMouseButton, WKURLRequestRef, WKFramePolicyListenerRef, WKTypeRef, const void*);
static void decidePolicyForNavigationAction(WKPageRef, WKFrameRef, WKFrameNavigationType, WKEventModifiers, WKEventMouseButton, WKFrameRef, WKURLRequestRef, WKFramePolicyListenerRef, WKTypeRef, const void*);
void decidePolicyForNavigationAction(WKFramePolicyListenerRef);
static void decidePolicyForResponse(WKPageRef, WKFrameRef, WKURLResponseRef, WKURLRequestRef, WKFramePolicyListenerRef, WKTypeRef, const void*);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment