2
* Copyright © 2006 Christian Persch
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License as published by
6
* the Free Software Foundation; either version 2.1, or (at your option)
9
* This program 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
12
* GNU Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
#include "mozilla-config.h"
25
#include <glib/gi18n.h>
27
#include <glade/glade-xml.h>
29
#include <nsStringAPI.h>
32
#include <nsIDOMWindow.h>
33
#include <nsIInterfaceRequestor.h>
34
#include <nsIInterfaceRequestorUtils.h>
36
#include "eel-gconf-extensions.h"
37
#include "ephy-debug.h"
38
#include "ephy-embed-shell.h"
39
#include "ephy-file-helpers.h"
40
#include "ephy-prefs.h"
42
#include "AutoModalDialog.h"
43
#include "EphyUtils.h"
45
#include "GeckoFormSigningDialog.h"
47
#define LITERAL(s) reinterpret_cast<const nsAString::char_type*>(NS_L(s))
49
NS_IMPL_ISUPPORTS1 (GeckoFormSigningDialog,
52
GeckoFormSigningDialog::GeckoFormSigningDialog()
54
LOG ("GeckoFormSigningDialog ctor [%p]", this);
57
GeckoFormSigningDialog::~GeckoFormSigningDialog()
59
LOG ("GeckoFormSigningDialog dtor [%p]", this);
62
/* nsIFormSigningDialog implementation */
64
/* boolean confirmSignText (in nsIInterfaceRequestor ctxt,
67
[array, size_is (count)] in wstring certNickList,
68
[array, size_is (count)] in wstring certDetailsList,
70
out PRInt32 selectedIndex,
71
out AString password); */
73
GeckoFormSigningDialog::ConfirmSignText (nsIInterfaceRequestor *ctx,
74
const nsAString & host,
75
const nsAString & signText,
76
const PRUnichar **certNickList,
77
const PRUnichar **certDetailsList,
79
PRInt32 *selectedIndex,
83
/* FIXME: limit |signText| to a sensitlbe length (maybe 100k)? */
85
nsCOMPtr<nsIDOMWindow> parent (do_GetInterface (ctx));
87
parent = EphyJSUtils::GetDOMWindowFromCallContext ();
88
g_print ("Fallback window %p\n", (void*)parent.get());
90
GtkWidget *gparent = EphyUtils::FindGtkParent (parent);
92
AutoModalDialog modalDialog (parent, PR_TRUE);
93
if (!modalDialog.ShouldShow ()) {
94
*_cancelled = PR_TRUE;
98
GladeXML *gxml = glade_xml_new (ephy_file ("form-signing-dialog.glade"),
99
"form_signing_dialog", NULL);
100
g_return_val_if_fail (gxml, NS_ERROR_FAILURE);
102
GtkWidget *dialog = glade_xml_get_widget (gxml, "form_signing_dialog");
103
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (gparent));
105
GtkLabel *primary_label = GTK_LABEL (glade_xml_get_widget (gxml, "primary_label"));
106
char *primary = g_strdup_printf (_("The web site “%s” requests that you sign the following text:"),
107
NS_ConvertUTF16toUTF8 (host).get ());
108
gtk_label_set_text (primary_label, primary);
111
GtkTextView *textview = GTK_TEXT_VIEW (glade_xml_get_widget (gxml, "textview"));
112
NS_ConvertUTF16toUTF8 text (signText);
113
gtk_text_buffer_set_text (gtk_text_view_get_buffer (textview),
114
text.get (), text.Length ());
116
GtkTable *table = GTK_TABLE (glade_xml_get_widget (gxml, "table"));
117
GtkComboBox *combo = GTK_COMBO_BOX (gtk_combo_box_new_text ());
118
for (PRUint32 i = 0; i < count; ++i) {
119
gtk_combo_box_append_text (combo, NS_ConvertUTF16toUTF8 (certNickList[i]).get ());
122
gtk_combo_box_set_active (combo, 0);
123
gtk_table_attach (table, GTK_WIDGET (combo), 1, 2, 0, 1,
124
GtkAttachOptions (0), GtkAttachOptions (0), 0, 0);
125
gtk_widget_show (GTK_WIDGET (combo));
127
/* FIXME: Add "View Certificate" button */
129
GtkEntry *password_entry = GTK_ENTRY (glade_xml_get_widget (gxml, "password_entry"));
131
GtkWidget *button = gtk_dialog_add_button (GTK_DIALOG (dialog),
133
GTK_RESPONSE_CANCEL);
134
gtk_dialog_add_button (GTK_DIALOG (dialog),
136
GTK_RESPONSE_ACCEPT);
137
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_REJECT);
138
gtk_widget_grab_focus (button);
140
/* FIXME: make Sign insensitive for some time (proportional to text length, with maximum?) */
142
g_object_unref (gxml);
144
int response = modalDialog.Run (GTK_DIALOG (dialog));
146
*_cancelled = response != GTK_RESPONSE_ACCEPT;
148
if (response == GTK_RESPONSE_ACCEPT) {
149
_password = NS_ConvertUTF8toUTF16 (gtk_entry_get_text (password_entry));
150
*selectedIndex = gtk_combo_box_get_active (combo);
153
gtk_widget_destroy (dialog);