~noskcaj/ubuntu/wily/epiphany-browser/merge2

« back to all changes in this revision

Viewing changes to embed/mozilla/GeckoFormSigningDialog.cpp

Tags: upstream-2.28.0
Import upstream version 2.28.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  Copyright © 2006 Christian Persch
3
 
 *
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)
7
 
 *  any later version.
8
 
 *
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.
13
 
 *
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.
17
 
 *
18
 
 *  $Id$
19
 
 */
20
 
 
21
 
#include "mozilla-config.h"
22
 
#include "config.h"
23
 
 
24
 
#include <glib.h>
25
 
#include <glib/gi18n.h>
26
 
#include <gtk/gtk.h>
27
 
#include <glade/glade-xml.h>
28
 
 
29
 
#include <nsStringAPI.h>
30
 
 
31
 
#include <nsCOMPtr.h>
32
 
#include <nsIDOMWindow.h>
33
 
#include <nsIInterfaceRequestor.h>
34
 
#include <nsIInterfaceRequestorUtils.h>
35
 
 
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"
41
 
 
42
 
#include "AutoModalDialog.h"
43
 
#include "EphyUtils.h"
44
 
 
45
 
#include "GeckoFormSigningDialog.h"
46
 
 
47
 
#define LITERAL(s) reinterpret_cast<const nsAString::char_type*>(NS_L(s))
48
 
 
49
 
NS_IMPL_ISUPPORTS1 (GeckoFormSigningDialog,
50
 
                    nsIFormSigningDialog)
51
 
 
52
 
GeckoFormSigningDialog::GeckoFormSigningDialog()
53
 
{
54
 
  LOG ("GeckoFormSigningDialog ctor [%p]", this);
55
 
}
56
 
 
57
 
GeckoFormSigningDialog::~GeckoFormSigningDialog()
58
 
{
59
 
  LOG ("GeckoFormSigningDialog dtor [%p]", this);
60
 
}
61
 
 
62
 
/* nsIFormSigningDialog implementation */
63
 
 
64
 
/* boolean confirmSignText (in nsIInterfaceRequestor ctxt,
65
 
                            in AString host,
66
 
                            in AString signText,
67
 
                            [array, size_is (count)] in wstring certNickList,
68
 
                            [array, size_is (count)] in wstring certDetailsList,
69
 
                            in PRUint32 count,
70
 
                            out PRInt32 selectedIndex,
71
 
                            out AString password); */
72
 
NS_IMETHODIMP
73
 
GeckoFormSigningDialog::ConfirmSignText (nsIInterfaceRequestor *ctx,
74
 
                                         const nsAString & host,
75
 
                                         const nsAString & signText,
76
 
                                         const PRUnichar **certNickList,
77
 
                                         const PRUnichar **certDetailsList,
78
 
                                         PRUint32 count,
79
 
                                         PRInt32 *selectedIndex,
80
 
                                         nsAString &_password,
81
 
                                         PRBool *_cancelled)
82
 
{
83
 
  /* FIXME: limit |signText| to a sensitlbe length (maybe 100k)? */
84
 
 
85
 
  nsCOMPtr<nsIDOMWindow> parent (do_GetInterface (ctx));
86
 
  if (!parent) {
87
 
    parent = EphyJSUtils::GetDOMWindowFromCallContext ();
88
 
    g_print ("Fallback window %p\n", (void*)parent.get());
89
 
  }
90
 
  GtkWidget *gparent = EphyUtils::FindGtkParent (parent);
91
 
 
92
 
  AutoModalDialog modalDialog (parent, PR_TRUE);
93
 
  if (!modalDialog.ShouldShow ()) {
94
 
    *_cancelled = PR_TRUE;
95
 
    return NS_OK;
96
 
  }
97
 
 
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);
101
 
 
102
 
  GtkWidget *dialog = glade_xml_get_widget (gxml, "form_signing_dialog");
103
 
  gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (gparent));
104
 
 
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);
109
 
  g_free (primary);
110
 
 
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 ());
115
 
 
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 ());
120
 
  }
121
 
 
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));
126
 
 
127
 
  /* FIXME: Add "View Certificate" button */
128
 
 
129
 
  GtkEntry *password_entry = GTK_ENTRY (glade_xml_get_widget (gxml, "password_entry"));
130
 
 
131
 
  GtkWidget *button = gtk_dialog_add_button (GTK_DIALOG (dialog),
132
 
                                             GTK_STOCK_CANCEL,
133
 
                                             GTK_RESPONSE_CANCEL);
134
 
  gtk_dialog_add_button (GTK_DIALOG (dialog),
135
 
                         _("_Sign text"),
136
 
                         GTK_RESPONSE_ACCEPT);
137
 
  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_REJECT);
138
 
  gtk_widget_grab_focus (button);
139
 
 
140
 
  /* FIXME: make Sign insensitive for some time (proportional to text length, with maximum?) */
141
 
 
142
 
  g_object_unref (gxml);
143
 
 
144
 
  int response = modalDialog.Run (GTK_DIALOG (dialog));
145
 
 
146
 
  *_cancelled = response != GTK_RESPONSE_ACCEPT;
147
 
 
148
 
  if (response == GTK_RESPONSE_ACCEPT) {
149
 
    _password = NS_ConvertUTF8toUTF16 (gtk_entry_get_text (password_entry));
150
 
    *selectedIndex = gtk_combo_box_get_active (combo);
151
 
  }
152
 
 
153
 
  gtk_widget_destroy (dialog);
154
 
 
155
 
  return NS_OK;
156
 
}