2
* Copyright (C) 2012 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 "WebKitNavigationPolicyDecision.h"
24
#include "WebKitEnumTypes.h"
25
#include "WebKitPolicyDecisionPrivate.h"
26
#include "WebKitURIRequestPrivate.h"
27
#include "WebURLRequest.h"
28
#include <glib/gi18n-lib.h>
29
#include <wtf/gobject/GRefPtr.h>
30
#include <wtf/text/CString.h>
32
using namespace WebKit;
33
using namespace WebCore;
36
* SECTION: WebKitNavigationPolicyDecision
37
* @Short_description: A policy decision for navigation actions
38
* @Title: WebKitNavigationPolicyDecision
39
* @See_also: #WebKitPolicyDecision, #WebKitWebView
41
* WebKitNavigationPolicyDecision represents a policy decision for events associated with
42
* navigations. If the value of #WebKitNavigationPolicyDecision:mouse-button is not 0, then
43
* the navigation was triggered by a mouse event.
46
struct _WebKitNavigationPolicyDecisionPrivate {
47
WebKitNavigationType navigationType;
50
GRefPtr<WebKitURIRequest> request;
54
WEBKIT_DEFINE_TYPE(WebKitNavigationPolicyDecision, webkit_navigation_policy_decision, WEBKIT_TYPE_POLICY_DECISION)
65
static void webkitNavigationPolicyDecisionGetProperty(GObject* object, guint propId, GValue* value, GParamSpec* paramSpec)
67
WebKitNavigationPolicyDecision* decision = WEBKIT_NAVIGATION_POLICY_DECISION(object);
69
case PROP_NAVIGATION_TYPE:
70
g_value_set_enum(value, webkit_navigation_policy_decision_get_navigation_type(decision));
72
case PROP_MOUSE_BUTTON:
73
g_value_set_enum(value, webkit_navigation_policy_decision_get_mouse_button(decision));
76
g_value_set_uint(value, webkit_navigation_policy_decision_get_modifiers(decision));
79
g_value_set_object(value, webkit_navigation_policy_decision_get_request(decision));
82
g_value_set_string(value, webkit_navigation_policy_decision_get_frame_name(decision));
85
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
90
static void webkit_navigation_policy_decision_class_init(WebKitNavigationPolicyDecisionClass* decisionClass)
92
GObjectClass* objectClass = G_OBJECT_CLASS(decisionClass);
93
objectClass->get_property = webkitNavigationPolicyDecisionGetProperty;
96
* WebKitNavigationPolicyDecision:navigation-type:
98
* The type of navigation that triggered this policy decision. This is
99
* useful for enacting different policies depending on what type of user
100
* action caused the navigation.
102
g_object_class_install_property(objectClass,
103
PROP_NAVIGATION_TYPE,
104
g_param_spec_enum("navigation-type",
105
_("Navigation type"),
106
_("The type of navigation triggering this decision"),
107
WEBKIT_TYPE_NAVIGATION_TYPE,
108
WEBKIT_NAVIGATION_TYPE_LINK_CLICKED,
109
WEBKIT_PARAM_READABLE));
112
* WebKitNavigationPolicyDecision:mouse-button:
114
* If the navigation associated with this policy decision was originally
115
* triggered by a mouse event, this property contains non-zero button number
116
* of the button triggering that event. The button numbers match those from GDK.
117
* If the navigation was not triggered by a mouse event, the value of this
118
* property will be 0.
120
g_object_class_install_property(objectClass,
122
g_param_spec_uint("mouse-button",
124
_("The mouse button used if this decision was triggered by a mouse event"),
126
WEBKIT_PARAM_READABLE));
129
* WebKitNavigationPolicyDecision:modifiers:
131
* If the navigation associated with this policy decision was originally
132
* triggered by a mouse event, this property contains a bitmask of various
133
* #GdkModifierType values describing the modifiers used for that click.
134
* If the navigation was not triggered by a mouse event or no modifiers
135
* were active, the value of this property will be zero.
137
g_object_class_install_property(objectClass,
139
g_param_spec_uint("modifiers",
140
_("Mouse event modifiers"),
141
_("The modifiers active if this decision was triggered by a mouse event"),
143
WEBKIT_PARAM_READABLE));
146
* WebKitNavigationPolicyDecision:request:
148
* This property contains the #WebKitURIRequest associated with this
151
g_object_class_install_property(objectClass,
153
g_param_spec_object("request",
154
_("Navigation URI request"),
155
_("The URI request that is associated with this navigation"),
156
WEBKIT_TYPE_URI_REQUEST,
157
WEBKIT_PARAM_READABLE));
160
* WebKitNavigationPolicyDecision:frame-name:
162
* If this navigation request targets a new frame, this property contains
163
* the name of that frame. For example if the decision was triggered by clicking a
164
* link with a target attribute equal to "_blank", this property will contain the
165
* value of that attribute. In all other cases, this value will be %NULL.
167
g_object_class_install_property(objectClass,
169
g_param_spec_string("frame-name",
171
_("The name of the new frame this navigation action targets"),
173
WEBKIT_PARAM_READABLE));
177
* webkit_navigation_policy_decision_get_navigation_type:
178
* @decision: a #WebKitNavigationPolicyDecision
180
* Gets the value of the #WebKitNavigationPolicyDecision:navigation-type property.
182
* Returns: The type of navigation triggering this policy decision.
184
WebKitNavigationType webkit_navigation_policy_decision_get_navigation_type(WebKitNavigationPolicyDecision* decision)
186
g_return_val_if_fail(WEBKIT_IS_NAVIGATION_POLICY_DECISION(decision), WEBKIT_NAVIGATION_TYPE_OTHER);
187
return decision->priv->navigationType;
191
* webkit_navigation_policy_decision_get_mouse_button:
192
* @decision: a #WebKitNavigationPolicyDecision
194
* Gets the value of the #WebKitNavigationPolicyDecision:mouse-button property.
196
* Returns: The mouse button used if this decision was triggered by a mouse event or 0 otherwise
198
guint webkit_navigation_policy_decision_get_mouse_button(WebKitNavigationPolicyDecision* decision)
200
g_return_val_if_fail(WEBKIT_IS_NAVIGATION_POLICY_DECISION(decision), 0);
201
return decision->priv->mouseButton;
205
* webkit_navigation_policy_decision_get_modifiers:
206
* @decision: a #WebKitNavigationPolicyDecision
208
* Gets the value of the #WebKitNavigationPolicyDecision:modifiers property.
210
* Returns: The modifiers active if this decision was triggered by a mouse event
212
unsigned webkit_navigation_policy_decision_get_modifiers(WebKitNavigationPolicyDecision* decision)
214
g_return_val_if_fail(WEBKIT_IS_NAVIGATION_POLICY_DECISION(decision), 0);
215
return decision->priv->modifiers;
219
* webkit_navigation_policy_decision_get_request:
220
* @decision: a #WebKitNavigationPolicyDecision
222
* Gets the value of the #WebKitNavigationPolicyDecision:request property.
224
* Returns: (transfer none): The URI request that is associated with this navigation
226
WebKitURIRequest* webkit_navigation_policy_decision_get_request(WebKitNavigationPolicyDecision* decision)
228
g_return_val_if_fail(WEBKIT_IS_NAVIGATION_POLICY_DECISION(decision), 0);
229
return decision->priv->request.get();
233
* webkit_navigation_policy_decision_get_frame_name:
234
* @decision: a #WebKitNavigationPolicyDecision
236
* Gets the value of the #WebKitNavigationPolicyDecision:frame-name property.
238
* Returns: The name of the new frame this navigation action targets or %NULL
240
const char* webkit_navigation_policy_decision_get_frame_name(WebKitNavigationPolicyDecision* decision)
242
g_return_val_if_fail(WEBKIT_IS_NAVIGATION_POLICY_DECISION(decision), 0);
243
return decision->priv->frameName.data();
246
COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_NAVIGATION_TYPE_LINK_CLICKED, NavigationTypeLinkClicked);
247
COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED, NavigationTypeFormSubmitted);
248
COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_NAVIGATION_TYPE_BACK_FORWARD, NavigationTypeBackForward);
249
COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_NAVIGATION_TYPE_RELOAD, NavigationTypeReload);
250
COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED, NavigationTypeFormResubmitted);
251
COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_NAVIGATION_TYPE_OTHER, NavigationTypeOther);
253
WebKitNavigationPolicyDecision* webkitNavigationPolicyDecisionCreate(WebKitNavigationType navigationType, unsigned mouseButton, unsigned modifiers, WebURLRequest* request, const char* frameName, WebFramePolicyListenerProxy* listener)
255
WebKitNavigationPolicyDecision* decision = WEBKIT_NAVIGATION_POLICY_DECISION(g_object_new(WEBKIT_TYPE_NAVIGATION_POLICY_DECISION, NULL));
256
decision->priv->navigationType = navigationType;
257
decision->priv->mouseButton = mouseButton;
258
decision->priv->modifiers = modifiers;
259
decision->priv->request = adoptGRef(webkitURIRequestCreateForResourceRequest(request->resourceRequest()));
260
decision->priv->frameName = frameName;
261
webkitPolicyDecisionSetListener(WEBKIT_POLICY_DECISION(decision), listener);