2 * Copyright (C) 2014 Igalia S.L.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 #include "WebKitNavigationAction.h"
23 #include "WebKitNavigationActionPrivate.h"
24 #include "WebKitPrivate.h"
25 #include "WebKitURIRequestPrivate.h"
27 using namespace WebKit;
29 G_DEFINE_BOXED_TYPE(WebKitNavigationAction, webkit_navigation_action, webkit_navigation_action_copy, webkit_navigation_action_free)
31 WebKitNavigationAction* webkitNavigationActionCreate(Ref<API::NavigationAction>&& action)
33 WebKitNavigationAction* navigation = static_cast<WebKitNavigationAction*>(fastZeroedMalloc(sizeof(WebKitNavigationAction)));
34 new (navigation) WebKitNavigationAction(WTFMove(action));
39 * webkit_navigation_action_copy:
40 * @navigation: a #WebKitNavigationAction
42 * Make a copy of @navigation.
44 * Returns: (transfer full): A copy of passed in #WebKitNavigationAction
48 WebKitNavigationAction* webkit_navigation_action_copy(WebKitNavigationAction* navigation)
50 g_return_val_if_fail(navigation, nullptr);
52 WebKitNavigationAction* copy = static_cast<WebKitNavigationAction*>(fastZeroedMalloc(sizeof(WebKitNavigationAction)));
53 new (copy) WebKitNavigationAction(navigation);
58 * webkit_navigation_action_free:
59 * @navigation: a #WebKitNavigationAction
61 * Free the #WebKitNavigationAction
65 void webkit_navigation_action_free(WebKitNavigationAction* navigation)
67 g_return_if_fail(navigation);
69 navigation->~WebKitNavigationAction();
74 * webkit_navigation_action_get_navigation_type:
75 * @navigation: a #WebKitNavigationAction
77 * Return the type of action that triggered the navigation.
79 * Returns: a #WebKitNavigationType
83 WebKitNavigationType webkit_navigation_action_get_navigation_type(WebKitNavigationAction* navigation)
85 g_return_val_if_fail(navigation, WEBKIT_NAVIGATION_TYPE_OTHER);
86 return toWebKitNavigationType(navigation->action->navigationType());
90 * webkit_navigation_action_get_mouse_button:
91 * @navigation: a #WebKitNavigationAction
93 * Return the number of the mouse button that triggered the navigation, or 0 if
94 * the navigation was not started by a mouse event.
96 * Returns: the mouse button number or 0
100 unsigned webkit_navigation_action_get_mouse_button(WebKitNavigationAction* navigation)
102 g_return_val_if_fail(navigation, 0);
103 return toWebKitMouseButton(navigation->action->mouseButton());
107 * webkit_navigation_action_get_modifiers:
108 * @navigation: a #WebKitNavigationAction
110 * Return a bitmask of #GdkModifierType values describing the modifier keys that were in effect
111 * when the navigation was requested
113 * Returns: the modifier keys
117 unsigned webkit_navigation_action_get_modifiers(WebKitNavigationAction* navigation)
119 g_return_val_if_fail(navigation, 0);
120 return toPlatformModifiers(navigation->action->modifiers());
124 * webkit_navigation_action_get_request:
125 * @navigation: a #WebKitNavigationAction
127 * Return the navigation #WebKitURIRequest
129 * Returns: (transfer none): a #WebKitURIRequest
133 WebKitURIRequest* webkit_navigation_action_get_request(WebKitNavigationAction* navigation)
135 g_return_val_if_fail(navigation, nullptr);
136 if (!navigation->request)
137 navigation->request = adoptGRef(webkitURIRequestCreateForResourceRequest(navigation->action->request()));
138 return navigation->request.get();
142 * webkit_navigation_action_is_user_gesture:
143 * @navigation: a #WebKitNavigationAction
145 * Return whether the navigation was triggered by a user gesture like a mouse click.
147 * Returns: whether navigation action is a user gesture
151 gboolean webkit_navigation_action_is_user_gesture(WebKitNavigationAction* navigation)
153 g_return_val_if_fail(navigation, FALSE);
154 return navigation->action->isProcessingUserGesture();
158 * webkit_navigation_action_is_redirect:
159 * @navigation: a #WebKitNavigationAction
161 * Returns whether the @navigation was redirected.
163 * Returns: %TRUE if the original navigation was redirected, %FALSE otherwise.
167 gboolean webkit_navigation_action_is_redirect(WebKitNavigationAction* navigation)
169 g_return_val_if_fail(navigation, FALSE);
170 return navigation->action->isRedirect();