|
1 /* |
|
2 * Copyright (C) 2008 Collabora Ltd. |
|
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 |
|
22 #include "webkitwebpolicydecision.h" |
|
23 |
|
24 #include "FrameLoaderTypes.h" |
|
25 #include "webkitprivate.h" |
|
26 |
|
27 using namespace WebKit; |
|
28 using namespace WebCore; |
|
29 |
|
30 /** |
|
31 * SECTION:webkitwebpolicydecision |
|
32 * @short_description: Liason between WebKit and the application regarding asynchronous policy decisions |
|
33 * |
|
34 * #WebKitWebPolicyDecision objects are given to the application on |
|
35 * signal emissions that deal with policy decisions, such as if a new |
|
36 * window should be opened, or if a given navigation should be |
|
37 * allowed. The application uses it to tell the engine what to do. |
|
38 */ |
|
39 |
|
40 G_DEFINE_TYPE(WebKitWebPolicyDecision, webkit_web_policy_decision, G_TYPE_OBJECT); |
|
41 |
|
42 struct _WebKitWebPolicyDecisionPrivate { |
|
43 WebKitWebFrame* frame; |
|
44 FramePolicyFunction framePolicyFunction; |
|
45 gboolean isCancelled; |
|
46 }; |
|
47 |
|
48 #define WEBKIT_WEB_POLICY_DECISION_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), WEBKIT_TYPE_WEB_POLICY_DECISION, WebKitWebPolicyDecisionPrivate)) |
|
49 |
|
50 static void webkit_web_policy_decision_class_init(WebKitWebPolicyDecisionClass* decisionClass) |
|
51 { |
|
52 g_type_class_add_private(decisionClass, sizeof(WebKitWebPolicyDecisionPrivate)); |
|
53 } |
|
54 |
|
55 static void webkit_web_policy_decision_init(WebKitWebPolicyDecision* decision) |
|
56 { |
|
57 decision->priv = WEBKIT_WEB_POLICY_DECISION_GET_PRIVATE(decision); |
|
58 } |
|
59 |
|
60 WebKitWebPolicyDecision* webkit_web_policy_decision_new(WebKitWebFrame* frame, WebCore::FramePolicyFunction function) |
|
61 { |
|
62 g_return_val_if_fail(frame, NULL); |
|
63 |
|
64 WebKitWebPolicyDecision* decision = WEBKIT_WEB_POLICY_DECISION(g_object_new(WEBKIT_TYPE_WEB_POLICY_DECISION, NULL)); |
|
65 WebKitWebPolicyDecisionPrivate* priv = decision->priv; |
|
66 |
|
67 priv->frame = frame; |
|
68 priv->framePolicyFunction = function; |
|
69 priv->isCancelled = FALSE; |
|
70 |
|
71 return decision; |
|
72 } |
|
73 |
|
74 /** |
|
75 * webkit_web_policy_decision_use |
|
76 * @decision: a #WebKitWebPolicyDecision |
|
77 * |
|
78 * Will send the USE decision to the policy implementer. |
|
79 * |
|
80 * Since: 1.0.3 |
|
81 */ |
|
82 void webkit_web_policy_decision_use(WebKitWebPolicyDecision* decision) |
|
83 { |
|
84 g_return_if_fail(WEBKIT_IS_WEB_POLICY_DECISION(decision)); |
|
85 |
|
86 WebKitWebPolicyDecisionPrivate* priv = decision->priv; |
|
87 |
|
88 if (!priv->isCancelled) |
|
89 (core(priv->frame)->loader()->policyChecker()->*(priv->framePolicyFunction))(WebCore::PolicyUse); |
|
90 } |
|
91 |
|
92 /** |
|
93 * webkit_web_policy_decision_ignore |
|
94 * @decision: a #WebKitWebPolicyDecision |
|
95 * |
|
96 * Will send the IGNORE decision to the policy implementer. |
|
97 * |
|
98 * Since: 1.0.3 |
|
99 */ |
|
100 void webkit_web_policy_decision_ignore(WebKitWebPolicyDecision* decision) |
|
101 { |
|
102 g_return_if_fail(WEBKIT_IS_WEB_POLICY_DECISION(decision)); |
|
103 |
|
104 WebKitWebPolicyDecisionPrivate* priv = decision->priv; |
|
105 |
|
106 if (!priv->isCancelled) |
|
107 (core(priv->frame)->loader()->policyChecker()->*(priv->framePolicyFunction))(WebCore::PolicyIgnore); |
|
108 } |
|
109 |
|
110 /** |
|
111 * webkit_web_policy_decision_download |
|
112 * @decision: a #WebKitWebPolicyDecision |
|
113 * |
|
114 * Will send the DOWNLOAD decision to the policy implementer. |
|
115 * |
|
116 * Since: 1.0.3 |
|
117 */ |
|
118 void webkit_web_policy_decision_download(WebKitWebPolicyDecision* decision) |
|
119 { |
|
120 g_return_if_fail(WEBKIT_IS_WEB_POLICY_DECISION(decision)); |
|
121 |
|
122 WebKitWebPolicyDecisionPrivate* priv = decision->priv; |
|
123 |
|
124 if (!priv->isCancelled) |
|
125 (core(priv->frame)->loader()->policyChecker()->*(priv->framePolicyFunction))(WebCore::PolicyDownload); |
|
126 } |
|
127 |
|
128 void webkit_web_policy_decision_cancel(WebKitWebPolicyDecision* decision) |
|
129 { |
|
130 g_return_if_fail(WEBKIT_IS_WEB_POLICY_DECISION(decision)); |
|
131 |
|
132 WebKitWebPolicyDecisionPrivate* priv = decision->priv; |
|
133 |
|
134 priv->isCancelled = TRUE; |
|
135 } |