WebKit2 decidePolicyForNavigationAction should include mouse button information
authorweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 20 Sep 2010 04:06:45 +0000 (04:06 +0000)
committerweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 20 Sep 2010 04:06:45 +0000 (04:06 +0000)
<rdar://problem/8413165>
https://bugs.webkit.org/show_bug.cgi?id=46060

Reviewed by Anders Carlsson.

WebKit2:

* UIProcess/API/C/WKAPICast.h:
(WebKit::toRef):
* UIProcess/API/C/WKPage.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::didReceiveMessage):
(WebKit::WebPageProxy::decidePolicyForNavigationAction):
(WebKit::WebPageProxy::decidePolicyForNewWindowAction):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPolicyClient.cpp:
(WebKit::WebPolicyClient::decidePolicyForNavigationAction):
(WebKit::WebPolicyClient::decidePolicyForNewWindowAction):
* UIProcess/WebPolicyClient.h:
* WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
(WebKit::findMouseEvent):
(WebKit::mouseButtonForNavigationAction):
(WebKit::WebFrameLoaderClient::dispatchDecidePolicyForNewWindowAction):
(WebKit::WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction):

WebKitTools:

* MiniBrowser/mac/BrowserWindowController.m:
(decidePolicyForNavigationAction):
(decidePolicyForNewWindowAction):

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

WebKit2/ChangeLog
WebKit2/UIProcess/API/C/WKAPICast.h
WebKit2/UIProcess/API/C/WKPage.h
WebKit2/UIProcess/WebPageProxy.cpp
WebKit2/UIProcess/WebPageProxy.h
WebKit2/UIProcess/WebPolicyClient.cpp
WebKit2/UIProcess/WebPolicyClient.h
WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp
WebKitTools/ChangeLog
WebKitTools/MiniBrowser/mac/BrowserWindowController.m

index 2dc4c29..39ee585 100644 (file)
@@ -1,3 +1,29 @@
+2010-09-19  Sam Weinig  <sam@webkit.org>
+
+        Reviewed by Anders Carlsson.
+
+        WebKit2 decidePolicyForNavigationAction should include mouse button information
+        <rdar://problem/8413165>
+        https://bugs.webkit.org/show_bug.cgi?id=46060
+
+        * UIProcess/API/C/WKAPICast.h:
+        (WebKit::toRef):
+        * UIProcess/API/C/WKPage.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::didReceiveMessage):
+        (WebKit::WebPageProxy::decidePolicyForNavigationAction):
+        (WebKit::WebPageProxy::decidePolicyForNewWindowAction):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPolicyClient.cpp:
+        (WebKit::WebPolicyClient::decidePolicyForNavigationAction):
+        (WebKit::WebPolicyClient::decidePolicyForNewWindowAction):
+        * UIProcess/WebPolicyClient.h:
+        * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
+        (WebKit::findMouseEvent):
+        (WebKit::mouseButtonForNavigationAction):
+        (WebKit::WebFrameLoaderClient::dispatchDecidePolicyForNewWindowAction):
+        (WebKit::WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction):
+
 2010-09-19  Csaba Osztrogon√°c  <ossy@webkit.org>
 
         [Qt] Unreviewed buildfix after r67813.
index 9b5283f..1eae27a 100644 (file)
@@ -244,6 +244,28 @@ inline WKEventModifiers toRef(WebEvent::Modifiers modifiers)
     return wkModifiers;
 }
 
+inline WKEventMouseButton toRef(WebMouseEvent::Button mouseButton)
+{
+    WKEventMouseButton wkMouseButton = kWKEventMouseButtonNoButton;
+
+    switch (mouseButton) {
+    case WebMouseEvent::NoButton:
+        wkMouseButton = kWKEventMouseButtonNoButton;
+        break;
+    case WebMouseEvent::LeftButton:
+        wkMouseButton = kWKEventMouseButtonLeftButton;
+        break;
+    case WebMouseEvent::MiddleButton:
+        wkMouseButton = kWKEventMouseButtonMiddleButton;
+        break;
+    case WebMouseEvent::RightButton:
+        wkMouseButton = kWKEventMouseButtonRightButton;
+        break;
+    }
+
+    return wkMouseButton;
+}
+
 } // namespace WebKit
 
 #endif // WKAPICast_h
index acb36c4..5131d60 100644 (file)
@@ -56,6 +56,14 @@ enum {
 };
 typedef uint32_t WKEventModifiers;
 
+enum {
+    kWKEventMouseButtonNoButton = -1,
+    kWKEventMouseButtonLeftButton = 0,
+    kWKEventMouseButtonMiddleButton = 1,
+    kWKEventMouseButtonRightButton = 2,
+};
+typedef uint32_t WKEventMouseButton;
+
 // FrameLoad Client
 typedef void (*WKPageDidStartProvisionalLoadForFrameCallback)(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void *clientInfo);
 typedef void (*WKPageDidReceiveServerRedirectForProvisionalLoadForFrameCallback)(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void *clientInfo);
@@ -110,8 +118,8 @@ struct WKPageLoaderClient {
 typedef struct WKPageLoaderClient WKPageLoaderClient;
 
 // Policy Client.
-typedef void (*WKPageDecidePolicyForNavigationActionCallback)(WKPageRef page, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKURLRef url, WKFrameRef frame, WKFramePolicyListenerRef listener, const void *clientInfo);
-typedef void (*WKPageDecidePolicyForNewWindowActionCallback)(WKPageRef page, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKURLRef url, WKFrameRef frame, WKFramePolicyListenerRef listener, const void *clientInfo);
+typedef void (*WKPageDecidePolicyForNavigationActionCallback)(WKPageRef page, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKEventMouseButton mouseButton, WKURLRef url, WKFrameRef frame, WKFramePolicyListenerRef listener, const void *clientInfo);
+typedef void (*WKPageDecidePolicyForNewWindowActionCallback)(WKPageRef page, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKEventMouseButton mouseButton, WKURLRef url, WKFrameRef frame, WKFramePolicyListenerRef listener, const void *clientInfo);
 typedef void (*WKPageDecidePolicyForMIMETypeCallback)(WKPageRef page, WKStringRef MIMEType, WKURLRef url, WKFrameRef frame, WKFramePolicyListenerRef listener, const void *clientInfo);
 
 struct WKPagePolicyClient {
index d51c4de..1eb3d08 100644 (file)
@@ -694,22 +694,24 @@ void WebPageProxy::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::M
             uint64_t frameID;
             uint32_t navigationType;
             uint32_t modifiers;
+            int32_t mouseButton;
             String url;
             uint64_t listenerID;
-            if (!arguments->decode(CoreIPC::Out(frameID, navigationType, modifiers, url, listenerID)))
+            if (!arguments->decode(CoreIPC::Out(frameID, navigationType, modifiers, mouseButton, url, listenerID)))
                 return;
-            decidePolicyForNavigationAction(process()->webFrame(frameID), static_cast<NavigationType>(navigationType), static_cast<WebEvent::Modifiers>(modifiers), url, listenerID);
+            decidePolicyForNavigationAction(process()->webFrame(frameID), static_cast<NavigationType>(navigationType), static_cast<WebEvent::Modifiers>(modifiers), static_cast<WebMouseEvent::Button>(mouseButton), url, listenerID);
             break;
         }
         case WebPageProxyMessage::DecidePolicyForNewWindowAction: {
             uint64_t frameID;
             uint32_t navigationType;
             uint32_t modifiers;
+            int32_t mouseButton;
             String url;
             uint64_t listenerID;
-            if (!arguments->decode(CoreIPC::Out(frameID, navigationType, modifiers, url, listenerID)))
+            if (!arguments->decode(CoreIPC::Out(frameID, navigationType, modifiers, url, mouseButton, listenerID)))
                 return;
-            decidePolicyForNewWindowAction(process()->webFrame(frameID), static_cast<NavigationType>(navigationType), static_cast<WebEvent::Modifiers>(modifiers), url, listenerID);
+            decidePolicyForNewWindowAction(process()->webFrame(frameID), static_cast<NavigationType>(navigationType), static_cast<WebEvent::Modifiers>(modifiers), static_cast<WebMouseEvent::Button>(mouseButton), url, listenerID);
             break;
         }
         case WebPageProxyMessage::DecidePolicyForMIMEType: {
@@ -1038,17 +1040,17 @@ void WebPageProxy::didFirstVisuallyNonEmptyLayoutForFrame(WebFrameProxy* frame,
 
 // PolicyClient
 
-void WebPageProxy::decidePolicyForNavigationAction(WebFrameProxy* frame, NavigationType navigationType, WebEvent::Modifiers modifiers, const String& url, uint64_t listenerID)
+void WebPageProxy::decidePolicyForNavigationAction(WebFrameProxy* frame, NavigationType navigationType, WebEvent::Modifiers modifiers, WebMouseEvent::Button mouseButton, const String& url, uint64_t listenerID)
 {
     RefPtr<WebFramePolicyListenerProxy> listener = frame->setUpPolicyListenerProxy(listenerID);
-    if (!m_policyClient.decidePolicyForNavigationAction(this, navigationType, modifiers, url, frame, listener.get()))
+    if (!m_policyClient.decidePolicyForNavigationAction(this, navigationType, modifiers, mouseButton, url, frame, listener.get()))
         listener->use();
 }
 
-void WebPageProxy::decidePolicyForNewWindowAction(WebFrameProxy* frame, NavigationType navigationType, WebEvent::Modifiers modifiers, const String& url, uint64_t listenerID)
+void WebPageProxy::decidePolicyForNewWindowAction(WebFrameProxy* frame, NavigationType navigationType, WebEvent::Modifiers modifiers, WebMouseEvent::Button mouseButton, const String& url, uint64_t listenerID)
 {
     RefPtr<WebFramePolicyListenerProxy> listener = frame->setUpPolicyListenerProxy(listenerID);
-    if (!m_policyClient.decidePolicyForNewWindowAction(this, navigationType, modifiers, url, frame, listener.get()))
+    if (!m_policyClient.decidePolicyForNewWindowAction(this, navigationType, modifiers, mouseButton, url, frame, listener.get()))
         listener->use();
 }
 
index 4a1387d..fe41ccc 100644 (file)
@@ -219,8 +219,8 @@ private:
     void didChangeProgress(double);
     void didFinishProgress();
     
-    void decidePolicyForNavigationAction(WebFrameProxy*, WebCore::NavigationType navigationType, WebEvent::Modifiers modifiers, const String& url, uint64_t listenerID);
-    void decidePolicyForNewWindowAction(WebFrameProxy*, WebCore::NavigationType navigationType, WebEvent::Modifiers modifiers, const String& url, uint64_t listenerID);
+    void decidePolicyForNavigationAction(WebFrameProxy*, WebCore::NavigationType, WebEvent::Modifiers, WebMouseEvent::Button, const String& url, uint64_t listenerID);
+    void decidePolicyForNewWindowAction(WebFrameProxy*, WebCore::NavigationType, WebEvent::Modifiers, WebMouseEvent::Button, const String& url, uint64_t listenerID);
     void decidePolicyForMIMEType(WebFrameProxy*, const String& MIMEType, const String& url, uint64_t listenerID);
 
     void willSubmitForm(WebFrameProxy* frame, WebFrameProxy* frameSource, Vector<std::pair<String, String> >& textFieldValues, APIObject* userData, uint64_t listenerID);
index 81f0da9..b359cd6 100644 (file)
@@ -45,21 +45,21 @@ void WebPolicyClient::initialize(const WKPagePolicyClient* client)
         memset(&m_pagePolicyClient, 0, sizeof(m_pagePolicyClient));
 }
 
-bool WebPolicyClient::decidePolicyForNavigationAction(WebPageProxy* page, NavigationType type, WebEvent::Modifiers modifiers, const String& url, WebFrameProxy* frame, WebFramePolicyListenerProxy* listener)
+bool WebPolicyClient::decidePolicyForNavigationAction(WebPageProxy* page, NavigationType type, WebEvent::Modifiers modifiers, WebMouseEvent::Button mouseButton, const String& url, WebFrameProxy* frame, WebFramePolicyListenerProxy* listener)
 {
     if (!m_pagePolicyClient.decidePolicyForNavigationAction)
         return false;
 
-    m_pagePolicyClient.decidePolicyForNavigationAction(toRef(page), toRef(type), toRef(modifiers), toURLRef(url.impl()), toRef(frame), toRef(listener), m_pagePolicyClient.clientInfo);
+    m_pagePolicyClient.decidePolicyForNavigationAction(toRef(page), toRef(type), toRef(modifiers), toRef(mouseButton), toURLRef(url.impl()), toRef(frame), toRef(listener), m_pagePolicyClient.clientInfo);
     return true;
 }
 
-bool WebPolicyClient::decidePolicyForNewWindowAction(WebPageProxy* page, NavigationType type, WebEvent::Modifiers modifiers, const String& url, WebFrameProxy* frame, WebFramePolicyListenerProxy* listener)
+bool WebPolicyClient::decidePolicyForNewWindowAction(WebPageProxy* page, NavigationType type, WebEvent::Modifiers modifiers, WebMouseEvent::Button mouseButton, const String& url, WebFrameProxy* frame, WebFramePolicyListenerProxy* listener)
 {
     if (!m_pagePolicyClient.decidePolicyForNewWindowAction)
         return false;
 
-    m_pagePolicyClient.decidePolicyForNewWindowAction(toRef(page), toRef(type), toRef(modifiers), toURLRef(url.impl()), toRef(frame), toRef(listener), m_pagePolicyClient.clientInfo);
+    m_pagePolicyClient.decidePolicyForNewWindowAction(toRef(page), toRef(type), toRef(modifiers), toRef(mouseButton), toURLRef(url.impl()), toRef(frame), toRef(listener), m_pagePolicyClient.clientInfo);
     return true;
 }
 
index 686919c..16bcd64 100644 (file)
@@ -42,8 +42,8 @@ public:
     WebPolicyClient();
     void initialize(const WKPagePolicyClient*);
 
-    bool decidePolicyForNavigationAction(WebPageProxy*, WebCore::NavigationType, WebEvent::Modifiers, const String& url, WebFrameProxy*, WebFramePolicyListenerProxy*);
-    bool decidePolicyForNewWindowAction(WebPageProxy*, WebCore::NavigationType, WebEvent::Modifiers, const String& url, WebFrameProxy*, WebFramePolicyListenerProxy*);
+    bool decidePolicyForNavigationAction(WebPageProxy*, WebCore::NavigationType, WebEvent::Modifiers, WebMouseEvent::Button, const String& url, WebFrameProxy*, WebFramePolicyListenerProxy*);
+    bool decidePolicyForNewWindowAction(WebPageProxy*, WebCore::NavigationType, WebEvent::Modifiers, WebMouseEvent::Button, const String& url, WebFrameProxy*, WebFramePolicyListenerProxy*);
     bool decidePolicyForMIMEType(WebPageProxy*, const String&, const String& url, WebFrameProxy*, WebFramePolicyListenerProxy*);
 
 private:
index ea34287..86ef574 100644 (file)
@@ -53,6 +53,7 @@
 #include <WebCore/FrameView.h>
 #include <WebCore/HTMLFormElement.h>
 #include <WebCore/MIMETypeRegistry.h>
+#include <WebCore/MouseEvent.h>
 #include <WebCore/Page.h>
 #include <WebCore/PluginData.h>
 #include <WebCore/ProgressTracker.h>
@@ -466,6 +467,28 @@ static uint32_t modifiersForNavigationAction(const NavigationAction& navigationA
     return modifiers;
 }
 
+static const MouseEvent* findMouseEvent(const Event* event)
+{
+    for (const Event* e = event; e; e = e->underlyingEvent()) {
+        if (e->isMouseEvent())
+            return static_cast<const MouseEvent*>(e);
+    }
+    return 0;
+}
+
+static int32_t mouseButtonForNavigationAction(const NavigationAction& navigationAction)
+{
+    const MouseEvent* mouseEvent = findMouseEvent(navigationAction.event());
+    if (!mouseEvent)
+        return -1;
+
+    if (!mouseEvent->buttonDown())
+        return -1;
+
+    return mouseEvent->button();
+}
+
+
 void WebFrameLoaderClient::dispatchDecidePolicyForMIMEType(FramePolicyFunction function, const String& MIMEType, const ResourceRequest& request)
 {
     if (m_frame->coreFrame()->loader()->documentLoader()->url().isEmpty() && request.url() == blankURL()) {
@@ -498,10 +521,12 @@ void WebFrameLoaderClient::dispatchDecidePolicyForNewWindowAction(FramePolicyFun
     // FIXME: Pass the frame name.
     const String& url = request.url().string(); // FIXME: Pass entire request.
 
+    uint32_t navigationType = static_cast<uint32_t>(navigationAction.type());
     uint32_t modifiers = modifiersForNavigationAction(navigationAction);
+    int32_t mouseButton = mouseButtonForNavigationAction(navigationAction);
 
     WebProcess::shared().connection()->send(WebPageProxyMessage::DecidePolicyForNewWindowAction, webPage->pageID(),
-                                            CoreIPC::In(m_frame->frameID(), (uint32_t)navigationAction.type(), modifiers, url, listenerID));
+                                            CoreIPC::In(m_frame->frameID(), navigationType, modifiers, mouseButton, url, listenerID));
 }
 
 void WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction(FramePolicyFunction function, const NavigationAction& navigationAction, const ResourceRequest& request, PassRefPtr<FormState>)
@@ -522,10 +547,12 @@ void WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction(FramePolicyFu
     // FIXME: Pass more than just the navigation action type.
     const String& url = request.url().string(); // FIXME: Pass entire request.
 
+    uint32_t navigationType = static_cast<uint32_t>(navigationAction.type());
     uint32_t modifiers = modifiersForNavigationAction(navigationAction);
+    int32_t mouseButton = mouseButtonForNavigationAction(navigationAction);
 
     WebProcess::shared().connection()->send(WebPageProxyMessage::DecidePolicyForNavigationAction, webPage->pageID(),
-                                            CoreIPC::In(m_frame->frameID(), (uint32_t)navigationAction.type(), modifiers, url, listenerID));
+                                            CoreIPC::In(m_frame->frameID(), navigationType, modifiers, mouseButton, url, listenerID));
 }
 
 void WebFrameLoaderClient::cancelPolicyCheck()
index 253442b..48503e4 100644 (file)
@@ -1,3 +1,15 @@
+2010-09-19  Sam Weinig  <sam@webkit.org>
+
+        Reviewed by Anders Carlsson.
+
+        WebKit2 decidePolicyForNavigationAction should include mouse button information
+        <rdar://problem/8413165>
+        https://bugs.webkit.org/show_bug.cgi?id=46060
+
+        * MiniBrowser/mac/BrowserWindowController.m:
+        (decidePolicyForNavigationAction):
+        (decidePolicyForNewWindowAction):
+
 2010-09-19  Daniel Bates  <dbates@rim.com>
 
         Reviewed by Martin Robinson.
index bc17c70..9398e56 100644 (file)
@@ -337,13 +337,13 @@ static void didChangeBackForwardList(WKPageRef page, const void *clientInfo)
 
 #pragma mark Policy Client Callbacks
 
-static void decidePolicyForNavigationAction(WKPageRef page, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKURLRef url, WKFrameRef frame, WKFramePolicyListenerRef listener, const void *clientInfo)
+static void decidePolicyForNavigationAction(WKPageRef page, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKEventMouseButton mouseButton, WKURLRef url, WKFrameRef frame, WKFramePolicyListenerRef listener, const void *clientInfo)
 {
     LOG(@"decidePolicyForNavigationAction");
     WKFramePolicyListenerUse(listener);
 }
 
-static void decidePolicyForNewWindowAction(WKPageRef page, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKURLRef url, WKFrameRef frame, WKFramePolicyListenerRef listener, const void *clientInfo)
+static void decidePolicyForNewWindowAction(WKPageRef page, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKEventMouseButton mouseButton, WKURLRef url, WKFrameRef frame, WKFramePolicyListenerRef listener, const void *clientInfo)
 {
     LOG(@"decidePolicyForNewWindowAction");
     WKFramePolicyListenerUse(listener);