[GTK] WebKitWebView::create should receive information about the navigation action
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 2 Jul 2014 07:19:46 +0000 (07:19 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 2 Jul 2014 07:19:46 +0000 (07:19 +0000)
https://bugs.webkit.org/show_bug.cgi?id=133680

Reviewed by Martin Robinson.

Source/WebKit2:
Add WebKitNavigationAction boxed type representing a navigation
action to be passed as parameter of WebKitWebView::create
signal. In the future it could be also for the
WebKitNavigationPolicyDecision class. The class contains
information about a navigation action like the navigation type,
the request, the mouse button and key modifiers and whether it was
started by a user gesture. This information is needed to be able
to implement a proper popup blocker. Since all that information is
not provided by the C API, we have switched the UI client to use a
custom client derived from API::UIClient. This also avoids a lot
of toAPI -> toImpl unneeded conversions.

* PlatformGTK.cmake: Add new files to compilation.
* UIProcess/API/gtk/WebKitHitTestResult.cpp:
(webkitHitTestResultCreate): Use a WebHitTestResult::Data const
reference instead of a pointer to a WebHitTestResult.
(webkitHitTestResultCompare): Ditto.
* UIProcess/API/gtk/WebKitHitTestResultPrivate.h:
* UIProcess/API/gtk/WebKitNavigationAction.cpp: Added.
(webkitNavigationActionCreate): Create a WebKitNavigationAction
for the given ResourceRequest and NavigationActionData.
(webkit_navigation_action_copy):
(webkit_navigation_action_free):
(webkit_navigation_action_get_navigation_type):
(webkit_navigation_action_get_mouse_button):
(webkit_navigation_action_get_modifiers):
(webkit_navigation_action_get_request):
(webkit_navigation_action_is_user_gesture):
* UIProcess/API/gtk/WebKitNavigationAction.h: Added.
* UIProcess/API/gtk/WebKitNavigationActionPrivate.h: Added.
* UIProcess/API/gtk/WebKitNavigationPolicyDecision.h:
* UIProcess/API/gtk/WebKitPrivate.cpp:
(toGdkModifiers):
(toWebKitNavigationType):
(toWebKitMouseButton):
* UIProcess/API/gtk/WebKitPrivate.h:
* UIProcess/API/gtk/WebKitUIClient.cpp:
(UIClient::UIClient): Implement the UIClient using a custom class.
(attachUIClientToView): Set the UIClient directly to the WebPageProxy.
(createNewPage): Deleted.
(showPage): Deleted.
(closePage): Deleted.
(runJavaScriptAlert): Deleted.
(runJavaScriptConfirm): Deleted.
(runJavaScriptPrompt): Deleted.
(toolbarsAreVisible): Deleted.
(setToolbarsAreVisible): Deleted.
(menuBarIsVisible): Deleted.
(setMenuBarIsVisible): Deleted.
(statusBarIsVisible): Deleted.
(setStatusBarIsVisible): Deleted.
(isResizable): Deleted.
(setIsResizable): Deleted.
(getWindowFrame): Deleted.
(setWindowFrame): Deleted.
(mouseDidMoveOverElement): Deleted.
(printFrame): Deleted.
(runOpenPanel): Deleted.
(decidePolicyForGeolocationPermissionRequest): Deleted.
(runModal): Deleted.
* UIProcess/API/gtk/WebKitWebView.cpp:
(webkitWebViewCreate): Add WebKitNavigationAction parameter.
(webkit_web_view_class_init): Add WebKitNavigationAction paramter
to CREATE signal.
(webkitWebViewCreateNewPage): Add WebKitNavigationAction parameter
and pass it to the signal callbacks.
(webkitWebViewMouseTargetChanged): Use a WebHitTestResult::Data
const reference.
(webkitWebViewPopulateContextMenu): Ditto.
* UIProcess/API/gtk/WebKitWebView.h:
* UIProcess/API/gtk/WebKitWebViewPrivate.h:
* UIProcess/API/gtk/WebKitWindowProperties.cpp:
(webkitWindowPropertiesUpdateFromWebWindowFeatures): Use a
WebCore::WindowFeatures const reference.
* UIProcess/API/gtk/WebKitWindowPropertiesPrivate.h:
* UIProcess/API/gtk/docs/webkit2gtk-docs.sgml: Add new section.
* UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add new symbols.
* UIProcess/API/gtk/webkit2.h: Include WebKitNavigationAction.h.

Tools:
Add unit test to check the WebKitNavigationAction passed to
WebKitWebView::create callback.

* MiniBrowser/gtk/BrowserWindow.c:
(webViewCreate): Add WebKitNavigationAction parameter.
* TestWebKitAPI/Tests/WebKit2Gtk/TestMultiprocess.cpp:
* TestWebKitAPI/Tests/WebKit2Gtk/TestPrinting.cpp:
* TestWebKitAPI/Tests/WebKit2Gtk/TestUIClient.cpp:
(testWebViewCreateNavigationData):
(beforeAll):
* TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitPolicyClient.cpp:
(createCallback):

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

25 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/PlatformGTK.cmake
Source/WebKit2/UIProcess/API/gtk/WebKitHitTestResult.cpp
Source/WebKit2/UIProcess/API/gtk/WebKitHitTestResultPrivate.h
Source/WebKit2/UIProcess/API/gtk/WebKitNavigationAction.cpp [new file with mode: 0644]
Source/WebKit2/UIProcess/API/gtk/WebKitNavigationAction.h [new file with mode: 0644]
Source/WebKit2/UIProcess/API/gtk/WebKitNavigationActionPrivate.h [new file with mode: 0644]
Source/WebKit2/UIProcess/API/gtk/WebKitNavigationPolicyDecision.h
Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.cpp
Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h
Source/WebKit2/UIProcess/API/gtk/WebKitUIClient.cpp
Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp
Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h
Source/WebKit2/UIProcess/API/gtk/WebKitWebViewPrivate.h
Source/WebKit2/UIProcess/API/gtk/WebKitWindowProperties.cpp
Source/WebKit2/UIProcess/API/gtk/WebKitWindowPropertiesPrivate.h
Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml
Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt
Source/WebKit2/UIProcess/API/gtk/webkit2.h
Tools/ChangeLog
Tools/MiniBrowser/gtk/BrowserWindow.c
Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestMultiprocess.cpp
Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestPrinting.cpp
Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestUIClient.cpp
Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitPolicyClient.cpp

index 376f066..be12ea0 100644 (file)
@@ -1,3 +1,89 @@
+2014-07-02  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] WebKitWebView::create should receive information about the navigation action
+        https://bugs.webkit.org/show_bug.cgi?id=133680
+
+        Reviewed by Martin Robinson.
+
+        Add WebKitNavigationAction boxed type representing a navigation
+        action to be passed as parameter of WebKitWebView::create
+        signal. In the future it could be also for the
+        WebKitNavigationPolicyDecision class. The class contains
+        information about a navigation action like the navigation type,
+        the request, the mouse button and key modifiers and whether it was
+        started by a user gesture. This information is needed to be able
+        to implement a proper popup blocker. Since all that information is
+        not provided by the C API, we have switched the UI client to use a
+        custom client derived from API::UIClient. This also avoids a lot
+        of toAPI -> toImpl unneeded conversions.
+
+        * PlatformGTK.cmake: Add new files to compilation.
+        * UIProcess/API/gtk/WebKitHitTestResult.cpp:
+        (webkitHitTestResultCreate): Use a WebHitTestResult::Data const
+        reference instead of a pointer to a WebHitTestResult.
+        (webkitHitTestResultCompare): Ditto.
+        * UIProcess/API/gtk/WebKitHitTestResultPrivate.h:
+        * UIProcess/API/gtk/WebKitNavigationAction.cpp: Added.
+        (webkitNavigationActionCreate): Create a WebKitNavigationAction
+        for the given ResourceRequest and NavigationActionData.
+        (webkit_navigation_action_copy):
+        (webkit_navigation_action_free):
+        (webkit_navigation_action_get_navigation_type):
+        (webkit_navigation_action_get_mouse_button):
+        (webkit_navigation_action_get_modifiers):
+        (webkit_navigation_action_get_request):
+        (webkit_navigation_action_is_user_gesture):
+        * UIProcess/API/gtk/WebKitNavigationAction.h: Added.
+        * UIProcess/API/gtk/WebKitNavigationActionPrivate.h: Added.
+        * UIProcess/API/gtk/WebKitNavigationPolicyDecision.h:
+        * UIProcess/API/gtk/WebKitPrivate.cpp:
+        (toGdkModifiers):
+        (toWebKitNavigationType):
+        (toWebKitMouseButton):
+        * UIProcess/API/gtk/WebKitPrivate.h:
+        * UIProcess/API/gtk/WebKitUIClient.cpp:
+        (UIClient::UIClient): Implement the UIClient using a custom class.
+        (attachUIClientToView): Set the UIClient directly to the WebPageProxy.
+        (createNewPage): Deleted.
+        (showPage): Deleted.
+        (closePage): Deleted.
+        (runJavaScriptAlert): Deleted.
+        (runJavaScriptConfirm): Deleted.
+        (runJavaScriptPrompt): Deleted.
+        (toolbarsAreVisible): Deleted.
+        (setToolbarsAreVisible): Deleted.
+        (menuBarIsVisible): Deleted.
+        (setMenuBarIsVisible): Deleted.
+        (statusBarIsVisible): Deleted.
+        (setStatusBarIsVisible): Deleted.
+        (isResizable): Deleted.
+        (setIsResizable): Deleted.
+        (getWindowFrame): Deleted.
+        (setWindowFrame): Deleted.
+        (mouseDidMoveOverElement): Deleted.
+        (printFrame): Deleted.
+        (runOpenPanel): Deleted.
+        (decidePolicyForGeolocationPermissionRequest): Deleted.
+        (runModal): Deleted.
+        * UIProcess/API/gtk/WebKitWebView.cpp:
+        (webkitWebViewCreate): Add WebKitNavigationAction parameter.
+        (webkit_web_view_class_init): Add WebKitNavigationAction paramter
+        to CREATE signal.
+        (webkitWebViewCreateNewPage): Add WebKitNavigationAction parameter
+        and pass it to the signal callbacks.
+        (webkitWebViewMouseTargetChanged): Use a WebHitTestResult::Data
+        const reference.
+        (webkitWebViewPopulateContextMenu): Ditto.
+        * UIProcess/API/gtk/WebKitWebView.h:
+        * UIProcess/API/gtk/WebKitWebViewPrivate.h:
+        * UIProcess/API/gtk/WebKitWindowProperties.cpp:
+        (webkitWindowPropertiesUpdateFromWebWindowFeatures): Use a
+        WebCore::WindowFeatures const reference.
+        * UIProcess/API/gtk/WebKitWindowPropertiesPrivate.h:
+        * UIProcess/API/gtk/docs/webkit2gtk-docs.sgml: Add new section.
+        * UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add new symbols.
+        * UIProcess/API/gtk/webkit2.h: Include WebKitNavigationAction.h.
+
 2014-07-01  KwangHyuk Kim  <hyuki.kim@samsung.com>
 
         [EFL] Fix occurrence of two cursors on WK2 EFL.
index 7649f14..a4ba9aa 100644 (file)
@@ -162,6 +162,9 @@ list(APPEND WebKit2_SOURCES
     UIProcess/API/gtk/WebKitMimeInfo.cpp
     UIProcess/API/gtk/WebKitMimeInfo.h
     UIProcess/API/gtk/WebKitMimeInfoPrivate.h
+    UIProcess/API/gtk/WebKitNavigationAction.cpp
+    UIProcess/API/gtk/WebKitNavigationAction.h
+    UIProcess/API/gtk/WebKitNavigationActionPrivate.h
     UIProcess/API/gtk/WebKitNavigationPolicyDecision.cpp
     UIProcess/API/gtk/WebKitNavigationPolicyDecision.h
     UIProcess/API/gtk/WebKitNavigationPolicyDecisionPrivate.h
@@ -337,6 +340,7 @@ set(WebKit2GTK_INSTALLED_HEADERS
     ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitHitTestResult.h
     ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitJavascriptResult.h
     ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitMimeInfo.h
+    ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitNavigationAction.h
     ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitNavigationPolicyDecision.h
     ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitPermissionRequest.h
     ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitPlugin.h
index 918d316..1982aa0 100644 (file)
@@ -221,39 +221,33 @@ static void webkit_hit_test_result_class_init(WebKitHitTestResultClass* hitTestR
                                                         paramFlags));
 }
 
-WebKitHitTestResult* webkitHitTestResultCreate(WebHitTestResult* hitTestResult)
+WebKitHitTestResult* webkitHitTestResultCreate(const WebHitTestResult::Data& hitTestResult)
 {
     unsigned context = WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT;
 
-    const String& linkURL = hitTestResult->absoluteLinkURL();
-    if (!linkURL.isEmpty())
+    if (!hitTestResult.absoluteLinkURL.isEmpty())
         context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK;
 
-    const String& imageURL = hitTestResult->absoluteImageURL();
-    if (!imageURL.isEmpty())
+    if (!hitTestResult.absoluteImageURL.isEmpty())
         context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE;
 
-    const String& mediaURL = hitTestResult->absoluteMediaURL();
-    if (!mediaURL.isEmpty())
+    if (!hitTestResult.absoluteMediaURL.isEmpty())
         context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_MEDIA;
 
-    if (hitTestResult->isContentEditable())
+    if (hitTestResult.isContentEditable)
         context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE;
 
-    if (hitTestResult->isScrollbar())
+    if (hitTestResult.isScrollbar)
         context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_SCROLLBAR;
 
-    const String& linkTitle = hitTestResult->linkTitle();
-    const String& linkLabel = hitTestResult->linkLabel();
-
     return WEBKIT_HIT_TEST_RESULT(g_object_new(WEBKIT_TYPE_HIT_TEST_RESULT,
-                                               "context", context,
-                                               "link-uri", !linkURL.isEmpty() ? linkURL.utf8().data() : 0,
-                                               "image-uri", !imageURL.isEmpty() ? imageURL.utf8().data() : 0,
-                                               "media-uri", !mediaURL.isEmpty() ? mediaURL.utf8().data() : 0,
-                                               "link-title", !linkTitle.isEmpty() ? linkTitle.utf8().data() : 0,
-                                               "link-label", !linkLabel.isEmpty() ? linkLabel.utf8().data() : 0,
-                                               NULL));
+        "context", context,
+        "link-uri", context & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK ? hitTestResult.absoluteLinkURL.utf8().data() : nullptr,
+        "image-uri", context & WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE ? hitTestResult.absoluteImageURL.utf8().data() : nullptr,
+        "media-uri", context & WEBKIT_HIT_TEST_RESULT_CONTEXT_MEDIA ? hitTestResult.absoluteMediaURL.utf8().data() : nullptr,
+        "link-title", !hitTestResult.linkTitle.isEmpty() ? hitTestResult.linkTitle.utf8().data() : nullptr,
+        "link-label", !hitTestResult.linkLabel.isEmpty() ? hitTestResult.linkLabel.utf8().data() : nullptr,
+        nullptr));
 }
 
 static bool stringIsEqualToCString(const String& string, const CString& cString)
@@ -261,16 +255,16 @@ static bool stringIsEqualToCString(const String& string, const CString& cString)
     return ((string.isEmpty() && cString.isNull()) || (string.utf8() == cString));
 }
 
-bool webkitHitTestResultCompare(WebKitHitTestResult* hitTestResult, WebHitTestResult* webHitTestResult)
+bool webkitHitTestResultCompare(WebKitHitTestResult* hitTestResult, const WebHitTestResult::Data& webHitTestResult)
 {
     WebKitHitTestResultPrivate* priv = hitTestResult->priv;
-    return webHitTestResult->isContentEditable() == webkit_hit_test_result_context_is_editable(hitTestResult)
-        && webHitTestResult->isScrollbar() == webkit_hit_test_result_context_is_scrollbar(hitTestResult)
-        && stringIsEqualToCString(webHitTestResult->absoluteLinkURL(), priv->linkURI)
-        && stringIsEqualToCString(webHitTestResult->linkTitle(), priv->linkTitle)
-        && stringIsEqualToCString(webHitTestResult->linkLabel(), priv->linkLabel)
-        && stringIsEqualToCString(webHitTestResult->absoluteImageURL(), priv->imageURI)
-        && stringIsEqualToCString(webHitTestResult->absoluteMediaURL(), priv->mediaURI);
+    return webHitTestResult.isContentEditable == webkit_hit_test_result_context_is_editable(hitTestResult)
+        && webHitTestResult.isScrollbar == webkit_hit_test_result_context_is_scrollbar(hitTestResult)
+        && stringIsEqualToCString(webHitTestResult.absoluteLinkURL, priv->linkURI)
+        && stringIsEqualToCString(webHitTestResult.linkTitle, priv->linkTitle)
+        && stringIsEqualToCString(webHitTestResult.linkLabel, priv->linkLabel)
+        && stringIsEqualToCString(webHitTestResult.absoluteImageURL, priv->imageURI)
+        && stringIsEqualToCString(webHitTestResult.absoluteMediaURL, priv->mediaURI);
 }
 
 /**
index 7ba2c38..a69b24b 100644 (file)
@@ -23,7 +23,7 @@
 #include "WebKitHitTestResult.h"
 #include "WebKitPrivate.h"
 
-WebKitHitTestResult* webkitHitTestResultCreate(WebKit::WebHitTestResult*);
-bool webkitHitTestResultCompare(WebKitHitTestResult*, WebKit::WebHitTestResult*);
+WebKitHitTestResult* webkitHitTestResultCreate(const WebKit::WebHitTestResult::Data&);
+bool webkitHitTestResultCompare(WebKitHitTestResult*, const WebKit::WebHitTestResult::Data&);
 
 #endif // WebKitHitTestResultPrivate_h
diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitNavigationAction.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitNavigationAction.cpp
new file mode 100644 (file)
index 0000000..249a0e3
--- /dev/null
@@ -0,0 +1,153 @@
+/*
+ * Copyright (C) 2014 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "WebKitNavigationAction.h"
+
+#include "WebKitNavigationActionPrivate.h"
+#include <gdk/gdk.h>
+#include <wtf/gobject/GRefPtr.h>
+
+using namespace WebKit;
+
+G_DEFINE_BOXED_TYPE(WebKitNavigationAction, webkit_navigation_action, webkit_navigation_action_copy, webkit_navigation_action_free)
+
+WebKitNavigationAction* webkitNavigationActionCreate(WebKitURIRequest* request, const NavigationActionData& navigationActionData)
+{
+    WebKitNavigationAction* navigation = g_slice_new0(WebKitNavigationAction);
+    new (navigation) WebKitNavigationAction(request, navigationActionData);
+    return navigation;
+}
+
+/**
+ * webkit_navigation_action_copy:
+ * @navigation: a #WebKitNavigationAction
+ *
+ * Make a copy of @navigation.
+ *
+ * Returns: (transfer full): A copy of passed in #WebKitNavigationAction
+ *
+ * Since: 2.6
+ */
+WebKitNavigationAction* webkit_navigation_action_copy(WebKitNavigationAction* navigation)
+{
+    g_return_val_if_fail(navigation, nullptr);
+
+    WebKitNavigationAction* copy = g_slice_new0(WebKitNavigationAction);
+    new (copy) WebKitNavigationAction(navigation);
+    return copy;
+}
+
+/**
+ * webkit_navigation_action_free:
+ * @navigation: a #WebKitNavigationAction
+ *
+ * Free the #WebKitNavigationAction
+ *
+ * Since: 2.6
+ */
+void webkit_navigation_action_free(WebKitNavigationAction* navigation)
+{
+    g_return_if_fail(navigation);
+
+    navigation->~WebKitNavigationAction();
+    g_slice_free(WebKitNavigationAction, navigation);
+}
+
+/**
+ * webkit_navigation_action_get_navigation_type:
+ * @navigation: a #WebKitNavigationAction
+ *
+ * Rtuen the type of action that triggered the navigation.
+ *
+ * Returns: a #WebKitNavigationType
+ *
+ * Since: 2.6
+ */
+WebKitNavigationType webkit_navigation_action_get_navigation_type(WebKitNavigationAction* navigation)
+{
+    g_return_val_if_fail(navigation, WEBKIT_NAVIGATION_TYPE_OTHER);
+    return navigation->type;
+}
+
+/**
+ * webkit_navigation_action_get_mouse_button:
+ * @navigation: a #WebKitNavigationAction
+ *
+ * Return the number of the mouse button that triggered the navigation, or 0 if
+ * the navigation was not started by a mouse event.
+ *
+ * Returns: the mouse button number or 0
+ *
+ * Since: 2.6
+ */
+unsigned webkit_navigation_action_get_mouse_button(WebKitNavigationAction* navigation)
+{
+    g_return_val_if_fail(navigation, 0);
+    return navigation->mouseButton;
+}
+
+/**
+ * webkit_navigation_action_get_modifiers:
+ * @navigation: a #WebKitNavigationAction
+ *
+ * Return a bitmask of #GdkModifierType values describing the modifier keys that were in effect
+ * when the navigation was requested
+ *
+ * Returns: the modifier keys
+ *
+ * Since: 2.6
+ */
+unsigned webkit_navigation_action_get_modifiers(WebKitNavigationAction* navigation)
+{
+    g_return_val_if_fail(navigation, 0);
+    return navigation->modifiers;
+}
+
+/**
+ * webkit_navigation_action_get_request:
+ * @navigation: a #WebKitNavigationAction
+ *
+ * Return the navigation #WebKitURIRequest
+ *
+ * Returns: (transfer none): a #WebKitURIRequest
+ *
+ * Since: 2.6
+ */
+WebKitURIRequest* webkit_navigation_action_get_request(WebKitNavigationAction* navigation)
+{
+    g_return_val_if_fail(navigation, nullptr);
+    return navigation->request.get();
+}
+
+/**
+ * webkit_navigation_action_is_user_gesture:
+ * @navigation: a #WebKitNavigationAction
+ *
+ * Return whether the navigation was triggered by a user gesture like a mouse click.
+ *
+ * Returns: whether navigation action is a user gesture
+ *
+ * Since: 2.6
+ */
+gboolean webkit_navigation_action_is_user_gesture(WebKitNavigationAction* navigation)
+{
+    g_return_val_if_fail(navigation, FALSE);
+    return navigation->isUserGesture;
+}
diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitNavigationAction.h b/Source/WebKit2/UIProcess/API/gtk/WebKitNavigationAction.h
new file mode 100644 (file)
index 0000000..ae95586
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2014 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION)
+#error "Only <webkit2/webkit2.h> can be included directly."
+#endif
+
+#ifndef WebKitNavigationAction_h
+#define WebKitNavigationAction_h
+
+#include <glib-object.h>
+#include <webkit2/WebKitDefines.h>
+#include <webkit2/WebKitURIRequest.h>
+
+G_BEGIN_DECLS
+
+#define WEBKIT_TYPE_NAVIGATION_ACTION (webkit_navigation_action_get_type())
+
+/**
+ * WebKitNavigationType:
+ * @WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: The navigation was triggered by clicking a link.
+ * @WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: The navigation was triggered by submitting a form.
+ * @WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: The navigation was triggered by navigating forward or backward.
+ * @WEBKIT_NAVIGATION_TYPE_RELOAD: The navigation was triggered by reloading.
+ * @WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED: The navigation was triggered by resubmitting a form.
+ * @WEBKIT_NAVIGATION_TYPE_OTHER: The navigation was triggered by some other action.
+ *
+ * Enum values used to denote the various navigation types.
+ */
+typedef enum {
+    WEBKIT_NAVIGATION_TYPE_LINK_CLICKED,
+    WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED,
+    WEBKIT_NAVIGATION_TYPE_BACK_FORWARD,
+    WEBKIT_NAVIGATION_TYPE_RELOAD,
+    WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED,
+    WEBKIT_NAVIGATION_TYPE_OTHER
+} WebKitNavigationType;
+
+typedef struct _WebKitNavigationAction WebKitNavigationAction;
+
+
+WEBKIT_API GType
+webkit_navigation_action_get_type            (void);
+
+WEBKIT_API WebKitNavigationAction *
+webkit_navigation_action_copy                (WebKitNavigationAction *navigation);
+
+WEBKIT_API void
+webkit_navigation_action_free                (WebKitNavigationAction *navigation);
+
+WEBKIT_API WebKitNavigationType
+webkit_navigation_action_get_navigation_type (WebKitNavigationAction *navigation);
+
+WEBKIT_API guint
+webkit_navigation_action_get_mouse_button    (WebKitNavigationAction *navigation);
+
+WEBKIT_API guint
+webkit_navigation_action_get_modifiers       (WebKitNavigationAction *navigation);
+
+WEBKIT_API WebKitURIRequest *
+webkit_navigation_action_get_request         (WebKitNavigationAction *navigation);
+
+WEBKIT_API gboolean
+webkit_navigation_action_is_user_gesture     (WebKitNavigationAction *navigation);
+
+G_END_DECLS
+
+#endif
diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitNavigationActionPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitNavigationActionPrivate.h
new file mode 100644 (file)
index 0000000..97fc8b3
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2014 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef WebKitNavigationActionPrivate_h
+#define WebKitNavigationActionPrivate_h
+
+#include "NavigationActionData.h"
+#include "WebKitNavigationAction.h"
+#include "WebKitPrivate.h"
+
+struct _WebKitNavigationAction {
+    _WebKitNavigationAction(WebKitURIRequest* uriRequest, const WebKit::NavigationActionData& navigationActionData)
+        : type(toWebKitNavigationType(navigationActionData.navigationType))
+        , mouseButton(toWebKitMouseButton(navigationActionData.mouseButton))
+        , modifiers(toGdkModifiers(navigationActionData.modifiers))
+        , isUserGesture(navigationActionData.isProcessingUserGesture)
+        , request(uriRequest)
+    {
+    }
+
+    _WebKitNavigationAction(WebKitNavigationAction* navigation)
+        : type(navigation->type)
+        , mouseButton(navigation->mouseButton)
+        , modifiers(navigation->modifiers)
+        , isUserGesture(navigation->isUserGesture)
+        , request(navigation->request)
+    {
+    }
+
+    WebKitNavigationType type;
+    unsigned mouseButton;
+    unsigned modifiers;
+    bool isUserGesture : 1;
+    GRefPtr<WebKitURIRequest> request;
+};
+
+WebKitNavigationAction* webkitNavigationActionCreate(WebKitURIRequest*, const WebKit::NavigationActionData&);
+
+#endif // WebKitNavigationActionPrivate_h
index 7513977..e852461 100644 (file)
 
 #include <glib-object.h>
 #include <webkit2/WebKitDefines.h>
+#include <webkit2/WebKitNavigationAction.h>
 #include <webkit2/WebKitPolicyDecision.h>
 #include <webkit2/WebKitURIRequest.h>
 
 G_BEGIN_DECLS
 
-/**
- * WebKitNavigationType:
- * @WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: The navigation was triggered by clicking a link.
- * @WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: The navigation was triggered by submitting a form.
- * @WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: The navigation was triggered by navigating forward or backward.
- * @WEBKIT_NAVIGATION_TYPE_RELOAD: The navigation was triggered by reloading.
- * @WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED: The navigation was triggered by resubmitting a form.
- * @WEBKIT_NAVIGATION_TYPE_OTHER: The navigation was triggered by some other action.
- *
- * Enum values used to denote the various navigation types.
- */
-typedef enum {
-    WEBKIT_NAVIGATION_TYPE_LINK_CLICKED,
-    WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED,
-    WEBKIT_NAVIGATION_TYPE_BACK_FORWARD,
-    WEBKIT_NAVIGATION_TYPE_RELOAD,
-    WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED,
-    WEBKIT_NAVIGATION_TYPE_OTHER,
-} WebKitNavigationType;
-
 #define WEBKIT_TYPE_NAVIGATION_POLICY_DECISION            (webkit_navigation_policy_decision_get_type())
 #define WEBKIT_NAVIGATION_POLICY_DECISION(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_NAVIGATION_POLICY_DECISION, WebKitNavigationPolicyDecision))
 #define WEBKIT_NAVIGATION_POLICY_DECISION_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),  WEBKIT_TYPE_NAVIGATION_POLICY_DECISION, WebKitNavigationPolicyDecisionClass))
index 5e8f9c5..206cbcc 100644 (file)
@@ -21,6 +21,7 @@
 #include "WebKitPrivate.h"
 
 #include "ErrorsGtk.h"
+#include "WebEvent.h"
 #include "WebKitError.h"
 #include <gdk/gdk.h>
 
@@ -38,6 +39,57 @@ unsigned wkEventModifiersToGdkModifiers(WKEventModifiers wkModifiers)
     return modifiers;
 }
 
+unsigned toGdkModifiers(WebKit::WebEvent::Modifiers wkModifiers)
+{
+    unsigned modifiers = 0;
+    if (wkModifiers & WebKit::WebEvent::Modifiers::ShiftKey)
+        modifiers |= GDK_SHIFT_MASK;
+    if (wkModifiers & WebKit::WebEvent::Modifiers::ControlKey)
+        modifiers |= GDK_CONTROL_MASK;
+    if (wkModifiers & WebKit::WebEvent::Modifiers::AltKey)
+        modifiers |= GDK_MOD1_MASK;
+    if (wkModifiers & WebKit::WebEvent::Modifiers::MetaKey)
+        modifiers |= GDK_META_MASK;
+    return modifiers;
+}
+
+WebKitNavigationType toWebKitNavigationType(WebCore::NavigationType type)
+{
+    switch (type) {
+    case WebCore::NavigationType::NavigationTypeLinkClicked:
+        return WEBKIT_NAVIGATION_TYPE_LINK_CLICKED;
+    case WebCore::NavigationType::NavigationTypeFormSubmitted:
+        return WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED;
+    case WebCore::NavigationType::NavigationTypeBackForward:
+        return WEBKIT_NAVIGATION_TYPE_BACK_FORWARD;
+    case WebCore::NavigationType::NavigationTypeReload:
+        return WEBKIT_NAVIGATION_TYPE_RELOAD;
+    case WebCore::NavigationType::NavigationTypeFormResubmitted:
+        return WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED;
+    case WebCore::NavigationType::NavigationTypeOther:
+        return WEBKIT_NAVIGATION_TYPE_OTHER;
+    default:
+        ASSERT_NOT_REACHED();
+        return WEBKIT_NAVIGATION_TYPE_OTHER;
+    }
+}
+
+unsigned toWebKitMouseButton(WebKit::WebMouseEvent::Button button)
+{
+    switch (button) {
+    case WebKit::WebMouseEvent::Button::NoButton:
+        return 0;
+    case WebKit::WebMouseEvent::Button::LeftButton:
+        return 1;
+    case WebKit::WebMouseEvent::Button::MiddleButton:
+        return 2;
+    case WebKit::WebMouseEvent::Button::RightButton:
+        return 3;
+    }
+    ASSERT_NOT_REACHED();
+    return 0;
+}
+
 unsigned wkEventMouseButtonToWebKitMouseButton(WKEventMouseButton wkButton)
 {
     switch (wkButton) {
index fab0865..a54e14e 100644 (file)
@@ -26,6 +26,7 @@
 #ifndef WebKitPrivate_h
 #define WebKitPrivate_h
 
+#include "WebKitNavigationAction.h"
 #include <WebKit/WKAPICast.h>
 #include <WebKit/WKDownload.h>
 #include <WebKit/WKFindOptions.h>
@@ -115,6 +116,9 @@ GType type_name##_get_type(void) \
 
 unsigned wkEventModifiersToGdkModifiers(WKEventModifiers);
 unsigned wkEventMouseButtonToWebKitMouseButton(WKEventMouseButton);
+unsigned toGdkModifiers(WebKit::WebEvent::Modifiers);
+WebKitNavigationType toWebKitNavigationType(WebCore::NavigationType);
+unsigned toWebKitMouseButton(WebKit::WebMouseEvent::Button);
 unsigned toWebKitError(unsigned webCoreError);
 unsigned toWebCoreError(unsigned webKitError);
 
index 9e0ef68..9d6a8ec 100644 (file)
 #include "config.h"
 #include "WebKitUIClient.h"
 
+#include "APIUIClient.h"
 #include "WebKitFileChooserRequestPrivate.h"
 #include "WebKitGeolocationPermissionRequestPrivate.h"
+#include "WebKitNavigationActionPrivate.h"
 #include "WebKitPrivate.h"
+#include "WebKitURIRequestPrivate.h"
 #include "WebKitWebViewBasePrivate.h"
 #include "WebKitWebViewPrivate.h"
 #include "WebKitWindowPropertiesPrivate.h"
 
 using namespace WebKit;
 
-static WKPageRef createNewPage(WKPageRef, WKURLRequestRef, WKDictionaryRef wkWindowFeatures, WKEventModifiers, WKEventMouseButton, const void* clientInfo)
-{
-    return static_cast<WKPageRef>(toAPI(webkitWebViewCreateNewPage(WEBKIT_WEB_VIEW(clientInfo), toImpl(wkWindowFeatures))));
-}
+class UIClient : public API::UIClient {
+public:
+    explicit UIClient(WebKitWebView* webView)
+        : m_webView(webView)
+    {
+    }
 
-static void showPage(WKPageRef, const void* clientInfo)
-{
-    webkitWebViewReadyToShowPage(WEBKIT_WEB_VIEW(clientInfo));
-}
+private:
+    virtual PassRefPtr<WebPageProxy> createNewPage(WebPageProxy*, WebFrameProxy*, const WebCore::ResourceRequest& resourceRequest, const WebCore::WindowFeatures& windowFeatures, const NavigationActionData& navigationActionData) override
+    {
+        GRefPtr<WebKitURIRequest> request = adoptGRef(webkitURIRequestCreateForResourceRequest(resourceRequest));
+        WebKitNavigationAction navigationAction(request.get(), navigationActionData);
+        return webkitWebViewCreateNewPage(m_webView, windowFeatures, &navigationAction);
+    }
 
-static void closePage(WKPageRef, const void* clientInfo)
-{
-    webkitWebViewClosePage(WEBKIT_WEB_VIEW(clientInfo));
-}
+    virtual void showPage(WebPageProxy*) override
+    {
+        webkitWebViewReadyToShowPage(m_webView);
+    }
 
-static void runJavaScriptAlert(WKPageRef, WKStringRef message, WKFrameRef, const void* clientInfo)
-{
-    webkitWebViewRunJavaScriptAlert(WEBKIT_WEB_VIEW(clientInfo), toImpl(message)->string().utf8());
-}
+    virtual void close(WebPageProxy*) override
+    {
+        webkitWebViewClosePage(m_webView);
+    }
 
-static bool runJavaScriptConfirm(WKPageRef, WKStringRef message, WKFrameRef, const void* clientInfo)
-{
-    return webkitWebViewRunJavaScriptConfirm(WEBKIT_WEB_VIEW(clientInfo), toImpl(message)->string().utf8());
-}
+    virtual void runJavaScriptAlert(WebPageProxy*, const String& message, WebFrameProxy*, std::function<void ()> completionHandler) override
+    {
+        webkitWebViewRunJavaScriptAlert(m_webView, message.utf8());
+        completionHandler();
+    }
 
-static WKStringRef runJavaScriptPrompt(WKPageRef, WKStringRef message, WKStringRef defaultValue, WKFrameRef, const void* clientInfo)
-{
-    CString result = webkitWebViewRunJavaScriptPrompt(WEBKIT_WEB_VIEW(clientInfo), toImpl(message)->string().utf8(),
-                                                      toImpl(defaultValue)->string().utf8());
-    return WKStringCreateWithUTF8CString(result.data());
-}
+    virtual void runJavaScriptConfirm(WebPageProxy*, const String& message, WebFrameProxy*, std::function<void (bool)> completionHandler) override
+    {
+        completionHandler(webkitWebViewRunJavaScriptConfirm(m_webView, message.utf8()));
+    }
 
-static bool toolbarsAreVisible(WKPageRef, const void* clientInfo)
-{
-    WebKitWindowProperties* windowProperties = webkit_web_view_get_window_properties(WEBKIT_WEB_VIEW(clientInfo));
-    return webkit_window_properties_get_toolbar_visible(windowProperties);
-}
+    virtual void runJavaScriptPrompt(WebPageProxy*, const String& message, const String& defaultValue, WebFrameProxy*, std::function<void (const String&)> completionHandler) override
+    {
+        CString result = webkitWebViewRunJavaScriptPrompt(m_webView, message.utf8(), defaultValue.utf8());
+        if (result.isNull()) {
+            completionHandler(String());
+            return;
+        }
 
-static void setToolbarsAreVisible(WKPageRef, bool toolbarsVisible, const void* clientInfo)
-{
-    WebKitWindowProperties* windowProperties = webkit_web_view_get_window_properties(WEBKIT_WEB_VIEW(clientInfo));
-    webkitWindowPropertiesSetToolbarVisible(windowProperties, toolbarsVisible);
-}
+        completionHandler(String::fromUTF8(result.data()));
+    }
 
-static bool menuBarIsVisible(WKPageRef, const void* clientInfo)
-{
-    WebKitWindowProperties* windowProperties = webkit_web_view_get_window_properties(WEBKIT_WEB_VIEW(clientInfo));
-    return webkit_window_properties_get_menubar_visible(windowProperties);
-}
+    virtual void mouseDidMoveOverElement(WebPageProxy*, const WebHitTestResult::Data& data, WebEvent::Modifiers modifiers, API::Object*) override
+    {
+        webkitWebViewMouseTargetChanged(m_webView, data, toGdkModifiers(modifiers));
+    }
 
-static void setMenuBarIsVisible(WKPageRef, bool menuBarVisible, const void* clientInfo)
-{
-    WebKitWindowProperties* windowProperties = webkit_web_view_get_window_properties(WEBKIT_WEB_VIEW(clientInfo));
-    webkitWindowPropertiesSetMenubarVisible(windowProperties, menuBarVisible);
-}
+    virtual bool toolbarsAreVisible(WebPageProxy*) override
+    {
+        return webkit_window_properties_get_toolbar_visible(webkit_web_view_get_window_properties(m_webView));
+    }
 
-static bool statusBarIsVisible(WKPageRef, const void* clientInfo)
-{
-    WebKitWindowProperties* windowProperties = webkit_web_view_get_window_properties(WEBKIT_WEB_VIEW(clientInfo));
-    return webkit_window_properties_get_statusbar_visible(windowProperties);
-}
+    virtual void setToolbarsAreVisible(WebPageProxy*, bool visible) override
+    {
+        webkitWindowPropertiesSetToolbarVisible(webkit_web_view_get_window_properties(m_webView), visible);
+    }
 
-static void setStatusBarIsVisible(WKPageRef, bool statusBarVisible, const void* clientInfo)
-{
-    WebKitWindowProperties* windowProperties = webkit_web_view_get_window_properties(WEBKIT_WEB_VIEW(clientInfo));
-    webkitWindowPropertiesSetStatusbarVisible(windowProperties, statusBarVisible);
-}
+    virtual bool menuBarIsVisible(WebPageProxy*) override
+    {
+        return webkit_window_properties_get_menubar_visible(webkit_web_view_get_window_properties(m_webView));
+    }
 
-static bool isResizable(WKPageRef, const void* clientInfo)
-{
-    WebKitWindowProperties* windowProperties = webkit_web_view_get_window_properties(WEBKIT_WEB_VIEW(clientInfo));
-    return webkit_window_properties_get_resizable(windowProperties);
-}
+    virtual void setMenuBarIsVisible(WebPageProxy*, bool visible) override
+    {
+        webkitWindowPropertiesSetToolbarVisible(webkit_web_view_get_window_properties(m_webView), visible);
+    }
 
-static void setIsResizable(WKPageRef, bool resizable, const void* clientInfo)
-{
-    WebKitWindowProperties* windowProperties = webkit_web_view_get_window_properties(WEBKIT_WEB_VIEW(clientInfo));
-    webkitWindowPropertiesSetResizable(windowProperties, resizable);
-}
+    virtual bool statusBarIsVisible(WebPageProxy*) override
+    {
+        return webkit_window_properties_get_statusbar_visible(webkit_web_view_get_window_properties(m_webView));
+    }
 
-static WKRect getWindowFrame(WKPageRef, const void* clientInfo)
-{
-    GdkRectangle geometry = { 0, 0, 0, 0 };
-    GtkWidget* window = gtk_widget_get_toplevel(GTK_WIDGET(clientInfo));
-    if (WebCore::widgetIsOnscreenToplevelWindow(window) && gtk_widget_get_visible(window)) {
-        gtk_window_get_position(GTK_WINDOW(window), &geometry.x, &geometry.y);
-        gtk_window_get_size(GTK_WINDOW(window), &geometry.width, &geometry.height);
+    virtual void setStatusBarIsVisible(WebPageProxy*, bool visible) override
+    {
+        webkitWindowPropertiesSetStatusbarVisible(webkit_web_view_get_window_properties(m_webView), visible);
     }
-    return WKRectMake(geometry.x, geometry.y, geometry.width, geometry.height);
-}
 
-static void setWindowFrame(WKPageRef, WKRect frame, const void* clientInfo)
-{
-    WebKitWindowProperties* windowProperties = webkit_web_view_get_window_properties(WEBKIT_WEB_VIEW(clientInfo));
-    GdkRectangle geometry = { static_cast<int>(frame.origin.x), static_cast<int>(frame.origin.y),
-        static_cast<int>(frame.size.width), static_cast<int>(frame.size.height) };
-    webkitWindowPropertiesSetGeometry(windowProperties, &geometry);
-}
+    virtual bool isResizable(WebPageProxy*) override
+    {
+        return webkit_window_properties_get_resizable(webkit_web_view_get_window_properties(m_webView));
+    }
 
-static void mouseDidMoveOverElement(WKPageRef, WKHitTestResultRef hitTestResult, WKEventModifiers modifiers, WKTypeRef /* userData */, const void* clientInfo)
-{
-    webkitWebViewMouseTargetChanged(WEBKIT_WEB_VIEW(clientInfo), toImpl(hitTestResult), wkEventModifiersToGdkModifiers(modifiers));
-}
+    virtual void setIsResizable(WebPageProxy*, bool resizable) override
+    {
+        webkitWindowPropertiesSetResizable(webkit_web_view_get_window_properties(m_webView), resizable);
+    }
 
-static void printFrame(WKPageRef page, WKFrameRef frame, const void*)
-{
-    webkitWebViewPrintFrame(WEBKIT_WEB_VIEW(toImpl(page)->viewWidget()), toImpl(frame));
-}
+    virtual void setWindowFrame(WebPageProxy*, const WebCore::FloatRect& frame) override
+    {
+        GdkRectangle geometry = WebCore::IntRect(frame);
+        webkitWindowPropertiesSetGeometry(webkit_web_view_get_window_properties(m_webView), &geometry);
+    }
 
-static void runOpenPanel(WKPageRef, WKFrameRef, WKOpenPanelParametersRef parameters, WKOpenPanelResultListenerRef listener, const void *clientInfo)
-{
-    GRefPtr<WebKitFileChooserRequest> request = adoptGRef(webkitFileChooserRequestCreate(toImpl(parameters), toImpl(listener)));
-    webkitWebViewRunFileChooserRequest(WEBKIT_WEB_VIEW(clientInfo), request.get());
-}
+    virtual WebCore::FloatRect windowFrame(WebPageProxy*) override
+    {
+        GdkRectangle geometry = { 0, 0, 0, 0 };
+        GtkWidget* window = gtk_widget_get_toplevel(GTK_WIDGET(m_webView));
+        if (WebCore::widgetIsOnscreenToplevelWindow(window) && gtk_widget_get_visible(window)) {
+            gtk_window_get_position(GTK_WINDOW(window), &geometry.x, &geometry.y);
+            gtk_window_get_size(GTK_WINDOW(window), &geometry.width, &geometry.height);
+        }
+        return WebCore::FloatRect(geometry);
+    }
 
-static void decidePolicyForGeolocationPermissionRequest(WKPageRef, WKFrameRef, WKSecurityOriginRef, WKGeolocationPermissionRequestRef request, const void* clientInfo)
-{
-    GRefPtr<WebKitGeolocationPermissionRequest> geolocationPermissionRequest = adoptGRef(webkitGeolocationPermissionRequestCreate(toImpl(request)));
-    webkitWebViewMakePermissionRequest(WEBKIT_WEB_VIEW(clientInfo), WEBKIT_PERMISSION_REQUEST(geolocationPermissionRequest.get()));
-}
+    virtual bool runOpenPanel(WebPageProxy*, WebFrameProxy*, WebOpenPanelParameters* parameters, WebOpenPanelResultListenerProxy* listener) override
+    {
+        GRefPtr<WebKitFileChooserRequest> request = adoptGRef(webkitFileChooserRequestCreate(parameters, listener));
+        webkitWebViewRunFileChooserRequest(m_webView, request.get());
+        return true;
+    }
 
-static void runModal(WKPageRef, const void* clientInfo)
-{
-    webkitWebViewRunAsModal(WEBKIT_WEB_VIEW(clientInfo));
-}
+    virtual bool decidePolicyForGeolocationPermissionRequest(WebPageProxy*, WebFrameProxy*, WebSecurityOrigin*, GeolocationPermissionRequestProxy* permissionRequest) override
+    {
+        GRefPtr<WebKitGeolocationPermissionRequest> geolocationPermissionRequest = adoptGRef(webkitGeolocationPermissionRequestCreate(permissionRequest));
+        webkitWebViewMakePermissionRequest(m_webView, WEBKIT_PERMISSION_REQUEST(geolocationPermissionRequest.get()));
+        return true;
+    }
+
+    virtual void printFrame(WebPageProxy*, WebFrameProxy* frame) override
+    {
+        webkitWebViewPrintFrame(m_webView, frame);
+    }
+
+    virtual bool canRunModal() const override { return true; }
+
+    virtual void runModal(WebPageProxy*) override
+    {
+        webkitWebViewRunAsModal(m_webView);
+    }
+
+    WebKitWebView* m_webView;
+};
 
 void attachUIClientToView(WebKitWebView* webView)
 {
-    WKPageUIClientV2 wkUIClient = {
-        {
-            2, // version
-            webView, // clientInfo
-        },
-        0, // createNewPage_deprecatedForUseWithV0
-        showPage,
-        closePage,
-        0, // takeFocus
-        0, // focus
-        0, // unfocus
-        runJavaScriptAlert,
-        runJavaScriptConfirm,
-        runJavaScriptPrompt,
-        0, // setStatusText
-        0, // mouseDidMoveOverElement_deprecatedForUseWithV0
-        0, // missingPluginButtonClicked
-        0, // didNotHandleKeyEvent
-        0, // didNotHandleWheelEvent
-        toolbarsAreVisible,
-        setToolbarsAreVisible,
-        menuBarIsVisible,
-        setMenuBarIsVisible,
-        statusBarIsVisible,
-        setStatusBarIsVisible,
-        isResizable,
-        setIsResizable,
-        getWindowFrame,
-        setWindowFrame,
-        0, // runBeforeUnloadConfirmPanel
-        0, // didDraw
-        0, // pageDidScroll
-        0, // exceededDatabaseQuota
-        runOpenPanel,
-        decidePolicyForGeolocationPermissionRequest,
-        0, // headerHeight
-        0, // footerHeight
-        0, // drawHeader
-        0, // drawFooter
-        printFrame,
-        runModal,
-        0, // didCompleteRubberBandForMainFrame
-        0, // saveDataToFileInDownloadsFolder
-        0, // shouldInterruptJavaScript
-        createNewPage,
-        mouseDidMoveOverElement,
-        0, // decidePolicyForNotificationPermissionRequest
-        0, // unavailablePluginButtonClicked
-        0, // showColorPicker
-        0, // hideColorPicker
-        0, // pluginLoadPolicy
-    };
-    WKPageRef wkPage = toAPI(webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView)));
-    WKPageSetPageUIClient(wkPage, &wkUIClient.base);
+    WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView));
+    page->setUIClient(std::make_unique<UIClient>(webView));
 }
 
index 4f88a0b..0f855e5 100644 (file)
@@ -217,9 +217,9 @@ static gboolean webkitWebViewLoadFail(WebKitWebView* webView, WebKitLoadEvent, c
     return TRUE;
 }
 
-static GtkWidget* webkitWebViewCreate(WebKitWebView*)
+static GtkWidget* webkitWebViewCreate(WebKitWebView*, WebKitNavigationAction*)
 {
-    return 0;
+    return nullptr;
 }
 
 static GtkWidget* webkitWebViewCreateJavaScriptDialog(WebKitWebView* webView, GtkMessageType type, GtkButtonsType buttons, int defaultResponse, const char* message)
@@ -889,14 +889,18 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass)
     /**
      * WebKitWebView::create:
      * @web_view: the #WebKitWebView on which the signal is emitted
+     * @navigation_action: a #WebKitNavigationAction
      *
      * Emitted when the creation of a new #WebKitWebView is requested.
      * If this signal is handled the signal handler should return the
      * newly created #WebKitWebView.
      *
+     * The #WebKitNavigationAction parameter contains information about the
+     * navigation action that triggered this signal.
+     *
      * When using %WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES
      * process model, the new #WebKitWebView should be related to
-     * @web_view to share the same web process, see webkit_web_view_new_with_related_view
+     * @web_view to share the same web process, see webkit_web_view_new_with_related_view()
      * for more details.
      *
      * The new #WebKitWebView should not be displayed to the user
@@ -905,14 +909,15 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass)
      * Returns: (transfer full): a newly allocated #WebKitWebView widget
      *    or %NULL to propagate the event further.
      */
-    signals[CREATE] =
-        g_signal_new("create",
-                     G_TYPE_FROM_CLASS(webViewClass),
-                     G_SIGNAL_RUN_LAST,
-                     G_STRUCT_OFFSET(WebKitWebViewClass, create),
-                     webkitWebViewAccumulatorObjectHandled, 0,
-                     webkit_marshal_OBJECT__VOID,
-                     GTK_TYPE_WIDGET, 0);
+    signals[CREATE] = g_signal_new(
+        "create",
+        G_TYPE_FROM_CLASS(webViewClass),
+        G_SIGNAL_RUN_LAST,
+        G_STRUCT_OFFSET(WebKitWebViewClass, create),
+        webkitWebViewAccumulatorObjectHandled, 0,
+        g_cclosure_marshal_generic,
+        GTK_TYPE_WIDGET, 1,
+        WEBKIT_TYPE_NAVIGATION_ACTION | G_SIGNAL_TYPE_STATIC_SCOPE);
 
     /**
      * WebKitWebView::ready-to-show:
@@ -1601,10 +1606,10 @@ void webkitWebViewUpdateURI(WebKitWebView* webView)
     g_object_notify(G_OBJECT(webView), "uri");
 }
 
-WebPageProxy* webkitWebViewCreateNewPage(WebKitWebView* webView, ImmutableDictionary* windowFeatures)
+WebPageProxy* webkitWebViewCreateNewPage(WebKitWebView* webView, const WindowFeatures& windowFeatures, WebKitNavigationAction* navigationAction)
 {
     WebKitWebView* newWebView;
-    g_signal_emit(webView, signals[CREATE], 0, &newWebView);
+    g_signal_emit(webView, signals[CREATE], 0, navigationAction, &newWebView);
     if (!newWebView)
         return 0;
 
@@ -1674,9 +1679,9 @@ void webkitWebViewMakePermissionRequest(WebKitWebView* webView, WebKitPermission
     g_signal_emit(webView, signals[PERMISSION_REQUEST], 0, request, &returnValue);
 }
 
-void webkitWebViewMouseTargetChanged(WebKitWebView* webView, WebHitTestResult* hitTestResult, unsigned modifiers)
+void webkitWebViewMouseTargetChanged(WebKitWebView* webView, const WebHitTestResult::Data& hitTestResult, unsigned modifiers)
 {
-    webkitWebViewBaseSetTooltipArea(WEBKIT_WEB_VIEW_BASE(webView), hitTestResult->elementBoundingBox());
+    webkitWebViewBaseSetTooltipArea(WEBKIT_WEB_VIEW_BASE(webView), hitTestResult.elementBoundingBox);
 
     WebKitWebViewPrivate* priv = webView->priv;
     if (priv->mouseTargetHitTestResult
@@ -1828,7 +1833,19 @@ void webkitWebViewPopulateContextMenu(WebKitWebView* webView, API::Array* propos
     if (webHitTestResult->isContentEditable())
         webkitWebViewCreateAndAppendInputMethodsMenuItem(webView, contextMenu.get());
 
-    GRefPtr<WebKitHitTestResult> hitTestResult = adoptGRef(webkitHitTestResultCreate(webHitTestResult));
+    // FIXME: we should use a custom ContextMenuClient at some point, that will receive a
+    // const WebHitTestResult::Data& that we can use directly here.
+    WebHitTestResult::Data data;
+    data.absoluteImageURL = webHitTestResult->absoluteImageURL();
+    data.absoluteLinkURL = webHitTestResult->absoluteLinkURL();
+    data.absoluteMediaURL = webHitTestResult->absoluteMediaURL();
+    data.linkLabel = webHitTestResult->linkLabel();
+    data.linkTitle = webHitTestResult->linkTitle();
+    data.isContentEditable = webHitTestResult->isContentEditable();
+    data.elementBoundingBox = webHitTestResult->elementBoundingBox();
+    data.isScrollbar = webHitTestResult->isScrollbar();
+
+    GRefPtr<WebKitHitTestResult> hitTestResult = adoptGRef(webkitHitTestResultCreate(data));
     GUniquePtr<GdkEvent> contextMenuEvent(webkitWebViewBaseTakeContextMenuEvent(webViewBase));
 
     gboolean returnValue;
index 980f458..549d254 100644 (file)
@@ -38,6 +38,7 @@
 #include <webkit2/WebKitForwardDeclarations.h>
 #include <webkit2/WebKitHitTestResult.h>
 #include <webkit2/WebKitJavascriptResult.h>
+#include <webkit2/WebKitNavigationAction.h>
 #include <webkit2/WebKitPermissionRequest.h>
 #include <webkit2/WebKitPolicyDecision.h>
 #include <webkit2/WebKitScriptDialog.h>
@@ -194,7 +195,8 @@ struct _WebKitWebViewClass {
                                                 const gchar                 *failing_uri,
                                                 GError                      *error);
 
-    GtkWidget *(* create)                      (WebKitWebView               *web_view);
+    GtkWidget *(* create)                      (WebKitWebView               *web_view,
+                                                WebKitNavigationAction      *navigation_action);
     void       (* ready_to_show)               (WebKitWebView               *web_view);
     void       (* run_as_modal)                (WebKitWebView               *web_view);
     void       (* close)                       (WebKitWebView               *web_view);
index 11591ff..5f6941c 100644 (file)
@@ -27,6 +27,7 @@
 #ifndef WebKitWebViewPrivate_h
 #define WebKitWebViewPrivate_h
 
+#include "WebHitTestResult.h"
 #include "WebImage.h"
 #include "WebKitWebView.h"
 #include <wtf/text/CString.h>
@@ -37,7 +38,7 @@ void webkitWebViewLoadFailedWithTLSErrors(WebKitWebView*, const char* failingURI
 void webkitWebViewSetEstimatedLoadProgress(WebKitWebView*, double estimatedLoadProgress);
 void webkitWebViewSetTitle(WebKitWebView*, const CString&);
 void webkitWebViewUpdateURI(WebKitWebView*);
-WebKit::WebPageProxy* webkitWebViewCreateNewPage(WebKitWebView*, WebKit::ImmutableDictionary* windowFeatures);
+WebKit::WebPageProxy* webkitWebViewCreateNewPage(WebKitWebView*, const WebCore::WindowFeatures&, WebKitNavigationAction*);
 void webkitWebViewReadyToShowPage(WebKitWebView*);
 void webkitWebViewRunAsModal(WebKitWebView*);
 void webkitWebViewClosePage(WebKitWebView*);
@@ -46,7 +47,7 @@ bool webkitWebViewRunJavaScriptConfirm(WebKitWebView*, const CString& message);
 CString webkitWebViewRunJavaScriptPrompt(WebKitWebView*, const CString& message, const CString& defaultText);
 void webkitWebViewMakePermissionRequest(WebKitWebView*, WebKitPermissionRequest*);
 void webkitWebViewMakePolicyDecision(WebKitWebView*, WebKitPolicyDecisionType, WebKitPolicyDecision*);
-void webkitWebViewMouseTargetChanged(WebKitWebView*, WebKit::WebHitTestResult*, unsigned modifiers);
+void webkitWebViewMouseTargetChanged(WebKitWebView*, const WebKit::WebHitTestResult::Data&, unsigned modifiers);
 void webkitWebViewPrintFrame(WebKitWebView*, WebKit::WebFrameProxy*);
 void webkitWebViewResourceLoadStarted(WebKitWebView*, WebKit::WebFrameProxy*, uint64_t resourceIdentifier, WebKitURIRequest*);
 void webkitWebViewRunFileChooserRequest(WebKitWebView*, WebKitFileChooserRequest*);
index a40e6db..bac88b5 100644 (file)
@@ -26,6 +26,7 @@
 #include "WebKitPrivate.h"
 #include "WebKitWindowPropertiesPrivate.h"
 #include <WebCore/IntRect.h>
+#include <WebCore/WindowFeatures.h>
 #include <glib/gi18n-lib.h>
 
 using namespace WebKit;
@@ -374,54 +375,26 @@ void webkitWindowPropertiesSetFullscreen(WebKitWindowProperties* windowPropertie
     g_object_notify(G_OBJECT(windowProperties), "fullscreen");
 }
 
-void webkitWindowPropertiesUpdateFromWebWindowFeatures(WebKitWindowProperties* windowProperties, ImmutableDictionary* features)
+void webkitWindowPropertiesUpdateFromWebWindowFeatures(WebKitWindowProperties* windowProperties, const WindowFeatures& windowFeatures)
 {
     GdkRectangle geometry = windowProperties->priv->geometry;
-
-    API::Double* doubleValue = static_cast<API::Double*>(features->get("x"));
-    if (doubleValue)
-        geometry.x = doubleValue->value();
-
-    doubleValue = static_cast<API::Double*>(features->get("y"));
-    if (doubleValue)
-        geometry.y = doubleValue->value();
-
-    doubleValue = static_cast<API::Double*>(features->get("width"));
-    if (doubleValue)
-        geometry.width = doubleValue->value();
-
-    doubleValue = static_cast<API::Double*>(features->get("height"));
-    if (doubleValue)
-        geometry.height = doubleValue->value();
+    if (windowFeatures.xSet)
+        geometry.x = windowFeatures.x;
+    if (windowFeatures.ySet)
+        geometry.y = windowFeatures.y;
+    if (windowFeatures.widthSet)
+        geometry.width = windowFeatures.width;
+    if (windowFeatures.heightSet)
+        geometry.height = windowFeatures.height;
     webkitWindowPropertiesSetGeometry(windowProperties, &geometry);
 
-    API::Boolean* booleanValue = static_cast<API::Boolean*>(features->get("menuBarVisible"));
-    if (booleanValue)
-        webkitWindowPropertiesSetMenubarVisible(windowProperties, booleanValue->value());
-
-    booleanValue = static_cast<API::Boolean*>(features->get("statusBarVisible"));
-    if (booleanValue)
-        webkitWindowPropertiesSetStatusbarVisible(windowProperties, booleanValue->value());
-
-    booleanValue = static_cast<API::Boolean*>(features->get("toolBarVisible"));
-    if (booleanValue)
-        webkitWindowPropertiesSetToolbarVisible(windowProperties, booleanValue->value());
-
-    booleanValue = static_cast<API::Boolean*>(features->get("locationBarVisible"));
-    if (booleanValue)
-        webkitWindowPropertiesSetLocationbarVisible(windowProperties, booleanValue->value());
-
-    booleanValue = static_cast<API::Boolean*>(features->get("scrollbarsVisible"));
-    if (booleanValue)
-        webkitWindowPropertiesSetScrollbarsVisible(windowProperties, booleanValue->value());
-
-    booleanValue = static_cast<API::Boolean*>(features->get("resizable"));
-    if (booleanValue)
-        webkitWindowPropertiesSetResizable(windowProperties, booleanValue->value());
-
-    booleanValue = static_cast<API::Boolean*>(features->get("fullscreen"));
-    if (booleanValue)
-        webkitWindowPropertiesSetFullscreen(windowProperties, booleanValue->value());
+    webkitWindowPropertiesSetMenubarVisible(windowProperties, windowFeatures.menuBarVisible);
+    webkitWindowPropertiesSetStatusbarVisible(windowProperties, windowFeatures.statusBarVisible);
+    webkitWindowPropertiesSetToolbarVisible(windowProperties, windowFeatures.toolBarVisible);
+    webkitWindowPropertiesSetLocationbarVisible(windowProperties, windowFeatures.locationBarVisible);
+    webkitWindowPropertiesSetScrollbarsVisible(windowProperties, windowFeatures.scrollbarsVisible);
+    webkitWindowPropertiesSetResizable(windowProperties, windowFeatures.resizable);
+    webkitWindowPropertiesSetFullscreen(windowProperties, windowFeatures.fullscreen);
 }
 
 /**
index 8ec17b4..05e4b9b 100644 (file)
@@ -31,7 +31,7 @@
 #include "WebKitWindowProperties.h"
 
 WebKitWindowProperties* webkitWindowPropertiesCreate();
-void webkitWindowPropertiesUpdateFromWebWindowFeatures(WebKitWindowProperties*, WebKit::ImmutableDictionary* features);
+void webkitWindowPropertiesUpdateFromWebWindowFeatures(WebKitWindowProperties*, const WebCore::WindowFeatures&);
 void webkitWindowPropertiesSetGeometry(WebKitWindowProperties*, GdkRectangle*);
 void webkitWindowPropertiesSetToolbarVisible(WebKitWindowProperties*, bool toolbarsVisible);
 void webkitWindowPropertiesSetMenubarVisible(WebKitWindowProperties*, bool menuBarVisible);
index e3cf9a6..1b71565 100644 (file)
@@ -23,6 +23,7 @@
     <xi:include href="xml/WebKitDownload.xml"/>
     <xi:include href="xml/WebKitPermissionRequest.xml"/>
     <xi:include href="xml/WebKitGeolocationPermissionRequest.xml"/>
+    <xi:include href="xml/WebKitNavigationAction.xml"/>
     <xi:include href="xml/WebKitPolicyDecision.xml"/>
     <xi:include href="xml/WebKitNavigationPolicyDecision.xml"/>
     <xi:include href="xml/WebKitResponsePolicyDecision.xml"/>
index 47b864e..54813c9 100644 (file)
@@ -521,6 +521,24 @@ webkit_geolocation_permission_request_get_type
 </SECTION>
 
 <SECTION>
+<FILE>WebKitNavigationAction</FILE>
+WebKitNavigationAction
+webkit_navigation_action_copy
+webkit_navigation_action_free
+webkit_navigation_action_get_navigation_type
+webkit_navigation_action_get_mouse_button
+webkit_navigation_action_get_modifiers
+webkit_navigation_action_get_request
+webkit_navigation_action_is_user_gesture
+
+<SUBSECTION Standard>
+WEBKIT_TYPE_NAVIGATION_ACTION
+
+<SUBSECTION Private>
+webkit_navigation_action_get_type
+</SECTION>
+
+<SECTION>
 <FILE>WebKitPolicyDecision</FILE>
 WebKitPolicyDecision
 webkit_policy_decision_download
index c18538a..46490a2 100644 (file)
@@ -49,6 +49,7 @@
 #include <webkit2/WebKitHitTestResult.h>
 #include <webkit2/WebKitJavascriptResult.h>
 #include <webkit2/WebKitMimeInfo.h>
+#include <webkit2/WebKitNavigationAction.h>
 #include <webkit2/WebKitNavigationPolicyDecision.h>
 #include <webkit2/WebKitPermissionRequest.h>
 #include <webkit2/WebKitPlugin.h>
index ce53dfe..3658db7 100644 (file)
@@ -1,5 +1,25 @@
 2014-07-02  Carlos Garcia Campos  <cgarcia@igalia.com>
 
+        [GTK] WebKitWebView::create should receive information about the navigation action
+        https://bugs.webkit.org/show_bug.cgi?id=133680
+
+        Reviewed by Martin Robinson.
+
+        Add unit test to check the WebKitNavigationAction passed to
+        WebKitWebView::create callback.
+
+        * MiniBrowser/gtk/BrowserWindow.c:
+        (webViewCreate): Add WebKitNavigationAction parameter.
+        * TestWebKitAPI/Tests/WebKit2Gtk/TestMultiprocess.cpp:
+        * TestWebKitAPI/Tests/WebKit2Gtk/TestPrinting.cpp:
+        * TestWebKitAPI/Tests/WebKit2Gtk/TestUIClient.cpp:
+        (testWebViewCreateNavigationData):
+        (beforeAll):
+        * TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitPolicyClient.cpp:
+        (createCallback):
+
+2014-07-02  Carlos Garcia Campos  <cgarcia@igalia.com>
+
         [GTK] Do not add forward declaration of class struct for interfaces
         https://bugs.webkit.org/show_bug.cgi?id=134297
 
index 4374773..65b096c 100644 (file)
@@ -348,7 +348,7 @@ static gboolean webViewLeaveFullScreen(WebKitWebView *webView, BrowserWindow *wi
     return FALSE;
 }
 
-static GtkWidget *webViewCreate(WebKitWebView *webView, BrowserWindow *window)
+static GtkWidget *webViewCreate(WebKitWebView *webView, WebKitNavigationAction *navigation, BrowserWindow *window)
 {
     WebKitWebView *newWebView = WEBKIT_WEB_VIEW(webkit_web_view_new_with_related_view(webView));
     webkit_web_view_set_settings(newWebView, webkit_web_view_get_settings(webView));
index 765e542..f8380d2 100644 (file)
@@ -138,7 +138,7 @@ public:
         Close
     };
 
-    static GtkWidget* viewCreateCallback(WebKitWebView* webView, UIClientMultiprocessTest* test)
+    static GtkWidget* viewCreateCallback(WebKitWebView* webView, WebKitNavigationAction*, UIClientMultiprocessTest* test)
     {
         return test->viewCreate(webView);
     }
index 99efa7c..cfa1656 100644 (file)
@@ -194,7 +194,7 @@ class CloseAfterPrintTest: public WebViewTest {
 public:
     MAKE_GLIB_TEST_FIXTURE(CloseAfterPrintTest);
 
-    static GtkWidget* webViewCreate(WebKitWebView* webView, CloseAfterPrintTest* test)
+    static GtkWidget* webViewCreate(WebKitWebView* webView, WebKitNavigationAction*, CloseAfterPrintTest* test)
     {
         return test->createWebView();
     }
index d24edc6..1c9d278 100644 (file)
@@ -117,9 +117,9 @@ public:
         test->m_windowPropertiesChanged.add(g_param_spec_get_name(paramSpec));
     }
 
-    static GtkWidget* viewCreateCallback(WebKitWebView* webView, UIClientTest* test)
+    static GtkWidget* viewCreateCallback(WebKitWebView* webView, WebKitNavigationAction* navigation, UIClientTest* test)
     {
-        return test->viewCreate(webView);
+        return test->viewCreate(webView, navigation);
     }
 
     static void viewReadyToShowCallback(WebKitWebView* webView, UIClientTest* test)
@@ -240,9 +240,10 @@ public:
         return m_mouseTargetHitTestResult.get();
     }
 
-    virtual GtkWidget* viewCreate(WebKitWebView* webView)
+    virtual GtkWidget* viewCreate(WebKitWebView* webView, WebKitNavigationAction* navigation)
     {
         g_assert(webView == m_webView);
+        g_assert(navigation);
 
         GtkWidget* newWebView = webkit_web_view_new_with_context(webkit_web_view_get_context(webView));
         g_object_ref_sink(newWebView);
@@ -305,6 +306,91 @@ static void testWebViewCreateReadyClose(UIClientTest* test, gconstpointer)
     g_assert_cmpint(events[2], ==, UIClientTest::Close);
 }
 
+class CreateNavigationDataTest: public UIClientTest {
+public:
+    MAKE_GLIB_TEST_FIXTURE(CreateNavigationDataTest);
+
+    CreateNavigationDataTest()
+        : m_navigation(nullptr)
+    {
+    }
+
+    ~CreateNavigationDataTest()
+    {
+        clearNavigation();
+    }
+
+    void clearNavigation()
+    {
+        if (m_navigation)
+            webkit_navigation_action_free(m_navigation);
+        m_navigation = nullptr;
+    }
+
+    GtkWidget* viewCreate(WebKitWebView* webView, WebKitNavigationAction* navigation)
+    {
+        g_assert(navigation);
+        g_assert(!m_navigation);
+        m_navigation = webkit_navigation_action_copy(navigation);
+        g_main_loop_quit(m_mainLoop);
+        return nullptr;
+    }
+
+    void loadHTML(const char* html)
+    {
+        clearNavigation();
+        WebViewTest::loadHtml(html, nullptr);
+    }
+
+    void clickAndWaitUntilMainLoopFinishes(int x, int y)
+    {
+        clearNavigation();
+        clickMouseButton(x, y, 1);
+        g_main_loop_run(m_mainLoop);
+    }
+
+    WebKitNavigationAction* m_navigation;
+};
+
+static void testWebViewCreateNavigationData(CreateNavigationDataTest* test, gconstpointer)
+{
+    test->showInWindowAndWaitUntilMapped();
+
+    test->loadHTML(
+        "<html><body>"
+        "<input style=\"position:absolute; left:0; top:0; margin:0; padding:0\" type=\"button\" value=\"click to show a popup\" onclick=\"window.open('data:foo');\"/>"
+        "<a style=\"position:absolute; left:20; top:20;\" href=\"data:bar\" target=\"_blank\">popup link</a>"
+        "</body></html>");
+    test->waitUntilLoadFinished();
+
+    // Click on a button.
+    test->clickAndWaitUntilMainLoopFinishes(5, 5);
+    g_assert_cmpstr(webkit_uri_request_get_uri(webkit_navigation_action_get_request(test->m_navigation)), ==, "data:foo");
+    g_assert_cmpuint(webkit_navigation_action_get_navigation_type(test->m_navigation), ==, WEBKIT_NAVIGATION_TYPE_OTHER);
+    // FIXME: This should be button 1.
+    g_assert_cmpuint(webkit_navigation_action_get_mouse_button(test->m_navigation), ==, 0);
+    g_assert_cmpuint(webkit_navigation_action_get_modifiers(test->m_navigation), ==, 0);
+    g_assert(webkit_navigation_action_is_user_gesture(test->m_navigation));
+
+    // Click on a link.
+    test->clickAndWaitUntilMainLoopFinishes(21, 21);
+    g_assert_cmpstr(webkit_uri_request_get_uri(webkit_navigation_action_get_request(test->m_navigation)), ==, "data:bar");
+    g_assert_cmpuint(webkit_navigation_action_get_navigation_type(test->m_navigation), ==, WEBKIT_NAVIGATION_TYPE_LINK_CLICKED);
+    g_assert_cmpuint(webkit_navigation_action_get_mouse_button(test->m_navigation), ==, 1);
+    g_assert_cmpuint(webkit_navigation_action_get_modifiers(test->m_navigation), ==, 0);
+    g_assert(webkit_navigation_action_is_user_gesture(test->m_navigation));
+
+    // No user interaction.
+    test->loadHTML("<html><body onLoad=\"window.open();\"></html>");
+    test->waitUntilMainLoopFinishes();
+
+    g_assert_cmpstr(webkit_uri_request_get_uri(webkit_navigation_action_get_request(test->m_navigation)), ==, "");
+    g_assert_cmpuint(webkit_navigation_action_get_navigation_type(test->m_navigation), ==, WEBKIT_NAVIGATION_TYPE_OTHER);
+    g_assert_cmpuint(webkit_navigation_action_get_mouse_button(test->m_navigation), ==, 0);
+    g_assert_cmpuint(webkit_navigation_action_get_modifiers(test->m_navigation), ==, 0);
+    g_assert(!webkit_navigation_action_is_user_gesture(test->m_navigation));
+}
+
 static gboolean checkMimeTypeForFilter(GtkFileFilter* filter, const gchar* mimeType)
 {
     GtkFileFilterInfo filterInfo;
@@ -323,11 +409,11 @@ public:
         test->m_webViewEvents.append(RunAsModal);
     }
 
-    GtkWidget* viewCreate(WebKitWebView* webView)
+    GtkWidget* viewCreate(WebKitWebView* webView, WebKitNavigationAction* navigation)
     {
         g_assert(webView == m_webView);
 
-        GtkWidget* newWebView = UIClientTest::viewCreate(webView);
+        GtkWidget* newWebView = UIClientTest::viewCreate(webView, navigation);
         g_signal_connect(newWebView, "run-as-modal", G_CALLBACK(dialogRunAsModalCallback), this);
         return newWebView;
     }
@@ -665,6 +751,7 @@ static void testWebViewFileChooserRequest(FileChooserTest* test, gconstpointer)
 void beforeAll()
 {
     UIClientTest::add("WebKitWebView", "create-ready-close", testWebViewCreateReadyClose);
+    CreateNavigationDataTest::add("WebKitWebView", "create-navigation-data", testWebViewCreateNavigationData);
     ModalDialogsTest::add("WebKitWebView", "allow-modal-dialogs", testWebViewAllowModalDialogs);
     ModalDialogsTest::add("WebKitWebView", "disallow-modal-dialogs", testWebViewDisallowModalDialogs);
     UIClientTest::add("WebKitWebView", "javascript-dialogs", testWebViewJavaScriptDialogs);
index 209ea04..fa91257 100644 (file)
@@ -191,7 +191,7 @@ struct CreateCallbackData {
     GMainLoop* mainLoop;
 };
 
-static WebKitWebView* createCallback(WebKitWebView* webView, CreateCallbackData* data)
+static WebKitWebView* createCallback(WebKitWebView* webView, WebKitNavigationAction*, CreateCallbackData* data)
 {
     data->triedToOpenWindow = true;
     g_main_loop_quit(data->mainLoop);