| 1 | /* |
| 2 | * Copyright (C) 2014 Igalia S.L. |
| 3 | * |
| 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. |
| 8 | * |
| 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. |
| 13 | * |
| 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. |
| 18 | */ |
| 19 | |
| 20 | #include "config.h" |
| 21 | #include "WebKitNavigationAction.h" |
| 22 | |
| 23 | #include "WebKitNavigationActionPrivate.h" |
| 24 | #include "WebKitPrivate.h" |
| 25 | #include "WebKitURIRequestPrivate.h" |
| 26 | |
| 27 | using namespace WebKit; |
| 28 | |
| 29 | G_DEFINE_BOXED_TYPE(WebKitNavigationAction, webkit_navigation_action, webkit_navigation_action_copy, webkit_navigation_action_free) |
| 30 | |
| 31 | WebKitNavigationAction* webkitNavigationActionCreate(Ref<API::NavigationAction>&& action) |
| 32 | { |
| 33 | WebKitNavigationAction* navigation = static_cast<WebKitNavigationAction*>(fastZeroedMalloc(sizeof(WebKitNavigationAction))); |
| 34 | new (navigation) WebKitNavigationAction(WTFMove(action)); |
| 35 | return navigation; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * webkit_navigation_action_copy: |
| 40 | * @navigation: a #WebKitNavigationAction |
| 41 | * |
| 42 | * Make a copy of @navigation. |
| 43 | * |
| 44 | * Returns: (transfer full): A copy of passed in #WebKitNavigationAction |
| 45 | * |
| 46 | * Since: 2.6 |
| 47 | */ |
| 48 | WebKitNavigationAction* webkit_navigation_action_copy(WebKitNavigationAction* navigation) |
| 49 | { |
| 50 | g_return_val_if_fail(navigation, nullptr); |
| 51 | |
| 52 | WebKitNavigationAction* copy = static_cast<WebKitNavigationAction*>(fastZeroedMalloc(sizeof(WebKitNavigationAction))); |
| 53 | new (copy) WebKitNavigationAction(navigation); |
| 54 | return copy; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * webkit_navigation_action_free: |
| 59 | * @navigation: a #WebKitNavigationAction |
| 60 | * |
| 61 | * Free the #WebKitNavigationAction |
| 62 | * |
| 63 | * Since: 2.6 |
| 64 | */ |
| 65 | void webkit_navigation_action_free(WebKitNavigationAction* navigation) |
| 66 | { |
| 67 | g_return_if_fail(navigation); |
| 68 | |
| 69 | navigation->~WebKitNavigationAction(); |
| 70 | fastFree(navigation); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * webkit_navigation_action_get_navigation_type: |
| 75 | * @navigation: a #WebKitNavigationAction |
| 76 | * |
| 77 | * Return the type of action that triggered the navigation. |
| 78 | * |
| 79 | * Returns: a #WebKitNavigationType |
| 80 | * |
| 81 | * Since: 2.6 |
| 82 | */ |
| 83 | WebKitNavigationType webkit_navigation_action_get_navigation_type(WebKitNavigationAction* navigation) |
| 84 | { |
| 85 | g_return_val_if_fail(navigation, WEBKIT_NAVIGATION_TYPE_OTHER); |
| 86 | return toWebKitNavigationType(navigation->action->navigationType()); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * webkit_navigation_action_get_mouse_button: |
| 91 | * @navigation: a #WebKitNavigationAction |
| 92 | * |
| 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. |
| 95 | * |
| 96 | * Returns: the mouse button number or 0 |
| 97 | * |
| 98 | * Since: 2.6 |
| 99 | */ |
| 100 | unsigned webkit_navigation_action_get_mouse_button(WebKitNavigationAction* navigation) |
| 101 | { |
| 102 | g_return_val_if_fail(navigation, 0); |
| 103 | return toWebKitMouseButton(navigation->action->mouseButton()); |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * webkit_navigation_action_get_modifiers: |
| 108 | * @navigation: a #WebKitNavigationAction |
| 109 | * |
| 110 | * Return a bitmask of #GdkModifierType values describing the modifier keys that were in effect |
| 111 | * when the navigation was requested |
| 112 | * |
| 113 | * Returns: the modifier keys |
| 114 | * |
| 115 | * Since: 2.6 |
| 116 | */ |
| 117 | unsigned webkit_navigation_action_get_modifiers(WebKitNavigationAction* navigation) |
| 118 | { |
| 119 | g_return_val_if_fail(navigation, 0); |
| 120 | return toPlatformModifiers(navigation->action->modifiers()); |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * webkit_navigation_action_get_request: |
| 125 | * @navigation: a #WebKitNavigationAction |
| 126 | * |
| 127 | * Return the #WebKitURIRequest associated with the navigation action. |
| 128 | * Modifications to the returned object are <emphasis>not</emphasis> taken |
| 129 | * into account when the request is sent over the network, and is intended |
| 130 | * only to aid in evaluating whether a navigation action should be taken or |
| 131 | * not. To modify requests before they are sent over the network the |
| 132 | * #WebKitPage::send-request signal can be used instead. |
| 133 | * |
| 134 | * Returns: (transfer none): a #WebKitURIRequest |
| 135 | * |
| 136 | * Since: 2.6 |
| 137 | */ |
| 138 | WebKitURIRequest* webkit_navigation_action_get_request(WebKitNavigationAction* navigation) |
| 139 | { |
| 140 | g_return_val_if_fail(navigation, nullptr); |
| 141 | if (!navigation->request) |
| 142 | navigation->request = adoptGRef(webkitURIRequestCreateForResourceRequest(navigation->action->request())); |
| 143 | return navigation->request.get(); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * webkit_navigation_action_is_user_gesture: |
| 148 | * @navigation: a #WebKitNavigationAction |
| 149 | * |
| 150 | * Return whether the navigation was triggered by a user gesture like a mouse click. |
| 151 | * |
| 152 | * Returns: whether navigation action is a user gesture |
| 153 | * |
| 154 | * Since: 2.6 |
| 155 | */ |
| 156 | gboolean webkit_navigation_action_is_user_gesture(WebKitNavigationAction* navigation) |
| 157 | { |
| 158 | g_return_val_if_fail(navigation, FALSE); |
| 159 | return navigation->action->isProcessingUserGesture(); |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * webkit_navigation_action_is_redirect: |
| 164 | * @navigation: a #WebKitNavigationAction |
| 165 | * |
| 166 | * Returns whether the @navigation was redirected. |
| 167 | * |
| 168 | * Returns: %TRUE if the original navigation was redirected, %FALSE otherwise. |
| 169 | * |
| 170 | * Since: 2.20 |
| 171 | */ |
| 172 | gboolean webkit_navigation_action_is_redirect(WebKitNavigationAction* navigation) |
| 173 | { |
| 174 | g_return_val_if_fail(navigation, FALSE); |
| 175 | return navigation->action->isRedirect(); |
| 176 | } |
| 177 | |