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