1/* 2 * Copyright (C) 2012 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 "WebKitScriptDialog.h" 22 23#include "WebKitScriptDialogPrivate.h" 24 25static WebKitScriptDialog* webkitScriptDialogCopy(WebKitScriptDialog* dialog) 26{ 27 WebKitScriptDialog* copy = g_slice_new0(WebKitScriptDialog); 28 new (copy) WebKitScriptDialog(dialog); 29 return copy; 30} 31 32static void webkitScriptDialogFree(WebKitScriptDialog* dialog) 33{ 34 dialog->~WebKitScriptDialog(); 35 g_slice_free(WebKitScriptDialog, dialog); 36} 37 38G_DEFINE_BOXED_TYPE(WebKitScriptDialog, webkit_script_dialog, webkitScriptDialogCopy, webkitScriptDialogFree) 39 40/** 41 * webkit_script_dialog_get_dialog_type: 42 * @dialog: a #WebKitScriptDialog 43 * 44 * Get the dialog type of a #WebKitScriptDialog. 45 * 46 * Returns: the #WebKitScriptDialogType of @dialog 47 */ 48WebKitScriptDialogType webkit_script_dialog_get_dialog_type(WebKitScriptDialog* dialog) 49{ 50 g_return_val_if_fail(dialog, WEBKIT_SCRIPT_DIALOG_ALERT); 51 52 return static_cast<WebKitScriptDialogType>(dialog->type); 53} 54 55/** 56 * webkit_script_dialog_get_message: 57 * @dialog: a #WebKitScriptDialog 58 * 59 * Get the message of a #WebKitScriptDialog. 60 * 61 * Returns: the message of @dialog. 62 */ 63const char* webkit_script_dialog_get_message(WebKitScriptDialog* dialog) 64{ 65 g_return_val_if_fail(dialog, 0); 66 67 return dialog->message.data(); 68} 69 70/** 71 * webkit_script_dialog_confirm_set_confirmed: 72 * @dialog: a #WebKitScriptDialog 73 * @confirmed: whether user confirmed the dialog 74 * 75 * This method is used for %WEBKIT_SCRIPT_DIALOG_CONFIRM dialogs when 76 * #WebKitWebView::script-dialog signal is emitted to set whether the user 77 * confirmed the dialog or not. The default implementation of #WebKitWebView::script-dialog 78 * signal sets %TRUE when the OK button is clicked and %FALSE otherwise. 79 * It's an error to use this method with a #WebKitScriptDialog that is not of type 80 * %WEBKIT_SCRIPT_DIALOG_CONFIRM. 81 */ 82void webkit_script_dialog_confirm_set_confirmed(WebKitScriptDialog* dialog, gboolean confirmed) 83{ 84 g_return_if_fail(dialog); 85 g_return_if_fail(dialog->type == WEBKIT_SCRIPT_DIALOG_CONFIRM); 86 87 dialog->confirmed = confirmed; 88} 89 90/** 91 * webkit_script_dialog_prompt_get_default_text: 92 * @dialog: a #WebKitScriptDialog 93 * 94 * Get the default text of a #WebKitScriptDialog of type %WEBKIT_SCRIPT_DIALOG_PROMPT. 95 * It's an error to use this method with a #WebKitScriptDialog that is not of type 96 * %WEBKIT_SCRIPT_DIALOG_PROMPT. 97 * 98 * Returns: the default text of @dialog 99 */ 100const char* webkit_script_dialog_prompt_get_default_text(WebKitScriptDialog* dialog) 101{ 102 g_return_val_if_fail(dialog, 0); 103 g_return_val_if_fail(dialog->type == WEBKIT_SCRIPT_DIALOG_PROMPT, 0); 104 105 return dialog->defaultText.data(); 106} 107 108/** 109 * webkit_script_dialog_prompt_set_text: 110 * @dialog: a #WebKitScriptDialog 111 * @text: the text to set 112 * 113 * This method is used for %WEBKIT_SCRIPT_DIALOG_PROMPT dialogs when 114 * #WebKitWebView::script-dialog signal is emitted to set the text 115 * entered by the user. The default implementation of #WebKitWebView::script-dialog 116 * signal sets the text of the entry form when OK button is clicked, otherwise %NULL is set. 117 * It's an error to use this method with a #WebKitScriptDialog that is not of type 118 * %WEBKIT_SCRIPT_DIALOG_PROMPT. 119 */ 120void webkit_script_dialog_prompt_set_text(WebKitScriptDialog* dialog, const char* text) 121{ 122 g_return_if_fail(dialog); 123 g_return_if_fail(dialog->type == WEBKIT_SCRIPT_DIALOG_PROMPT); 124 125 dialog->text = text; 126} 127