2 * Copyright © 2005, 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.
18 * $Id: EphyPromptService.cpp 6952 2007-03-11 19:42:02Z chpe $
21 #include "mozilla-config.h"
25 #include <glib-object.h>
26 #include <glib/gi18n.h>
29 #include <nsStringAPI.h>
32 #include <nsIDOMWindow.h>
33 #include <nsServiceManagerUtils.h>
35 #include "ephy-embed-shell.h"
37 #include "ephy-debug.h"
39 #include "AutoJSContextStack.h"
40 #include "AutoWindowModalState.h"
41 #include "EphyUtils.h"
43 #include "EphyPromptService.h"
45 #define TIMEOUT 1000 /* ms */
46 #define TIMEOUT_DATA_KEY "timeout"
48 #define MAX_MESSAGE_LENGTH 512
49 #define MAX_TITLE_LENGTH 256
50 #define MAX_BUTTON_TEXT_LENGTH 128
54 RESPONSE_ABORT_SCRIPT
= 42
60 Prompter (const char*, nsIDOMWindow
*, const PRUnichar
*, const PRUnichar
*);
63 void AddStockButton (const char*, int);
64 void AddButtonWithFlags (PRInt32
, PRUint32
, const PRUnichar
*, PRUint32
);
65 void AddButtonsWithFlags (PRUint32
, const PRUnichar
*, const PRUnichar
*, const PRUnichar
*);
66 void AddCheckbox (const PRUnichar
*, PRBool
*);
67 void GetCheckboxState (PRBool
*);
68 void AddEntry (const char *, const PRUnichar
*, PRBool
);
69 void GetText (PRUint32
, PRUnichar
**);
70 void AddSelect (PRUint32
, const PRUnichar
**, PRInt32
);
71 void GetSelected (PRInt32
*);
73 PRInt32
Run (PRBool
* = nsnull
);
76 PRBool
IsCalledFromScript ();
77 void PerformScriptAbortion ();
79 char *ConvertAndTruncateString (const PRUnichar
*, PRInt32
= -1);
80 char* ConvertAndEscapeButtonText (const PRUnichar
*, PRInt32
= -1);
83 nsCOMPtr
<nsIDOMWindow
> mWindow
;
87 GtkSizeGroup
*mSizeGroup
;
88 GtkWidget
*mEntries
[2];
92 PRInt32 mDefaultResponse
;
93 PRInt32 mUnaffirmativeResponse
;
99 Prompter::Prompter (const char *aStock
,
100 nsIDOMWindow
*aParent
,
101 const PRUnichar
*aTitle
,
102 const PRUnichar
*aText
)
111 , mDefaultResponse(GTK_RESPONSE_ACCEPT
)
112 , mUnaffirmativeResponse(0)
113 , mResponse(GTK_RESPONSE_CANCEL
)
117 GtkWidget
*parent
, *hbox
, *label
, *image
;
119 g_object_ref (ephy_embed_shell_get_default ());
121 mEntries
[0] = mEntries
[1] = nsnull
;
123 mDialog
= GTK_DIALOG (gtk_dialog_new ());
124 g_object_ref_sink (mDialog
);
129 title
= ConvertAndTruncateString (aTitle
, MAX_TITLE_LENGTH
);
132 gtk_window_set_title (GTK_WINDOW (mDialog
), title
? title
: "");
135 gtk_window_set_modal (GTK_WINDOW (mDialog
), TRUE
);
137 parent
= EphyUtils::FindGtkParent (aParent
);
138 if (GTK_IS_WINDOW (parent
))
140 gtk_window_set_transient_for (GTK_WINDOW (mDialog
),
141 GTK_WINDOW (parent
));
143 gtk_window_group_add_window (ephy_gui_ensure_window_group (GTK_WINDOW (parent
)),
144 GTK_WINDOW (mDialog
));
147 gtk_dialog_set_has_separator (mDialog
, FALSE
);
148 gtk_window_set_resizable (GTK_WINDOW (mDialog
), FALSE
);
149 gtk_container_set_border_width (GTK_CONTAINER (mDialog
), 5);
150 gtk_box_set_spacing (GTK_BOX (mDialog
->vbox
), 14); /* 2 * 5 + 14 = 24 */
152 hbox
= gtk_hbox_new (FALSE
, 12);
153 gtk_container_set_border_width (GTK_CONTAINER (hbox
), 5);
154 gtk_container_add (GTK_CONTAINER (GTK_DIALOG (mDialog
)->vbox
), hbox
);
156 image
= gtk_image_new_from_stock (aStock
, GTK_ICON_SIZE_DIALOG
);
157 gtk_misc_set_alignment (GTK_MISC (image
), 0.5, 0.0);
158 gtk_box_pack_start (GTK_BOX (hbox
), image
, FALSE
, FALSE
, 0);
160 mVBox
= gtk_vbox_new (FALSE
, 12);
161 gtk_box_pack_start (GTK_BOX (hbox
), mVBox
, TRUE
, TRUE
, 0);
166 text
= ConvertAndTruncateString (aText
, MAX_MESSAGE_LENGTH
);
169 label
= gtk_label_new (text
);
172 gtk_label_set_line_wrap (GTK_LABEL (label
), TRUE
);
173 /* Guard against overlong nonbreakable text (exploit) */
174 gtk_label_set_line_wrap_mode (GTK_LABEL (label
), PANGO_WRAP_WORD_CHAR
);
175 gtk_label_set_selectable (GTK_LABEL (label
), TRUE
);
176 gtk_misc_set_alignment (GTK_MISC (label
), 0.0, 0.0);
178 gtk_box_pack_start (GTK_BOX (mVBox
), label
, FALSE
, FALSE
, 0);
179 gtk_widget_show (label
);
181 if (IsCalledFromScript ())
183 gtk_dialog_add_button (GTK_DIALOG (mDialog
),
185 RESPONSE_ABORT_SCRIPT
);
188 gtk_widget_show (image
);
189 gtk_widget_show (mVBox
);
190 gtk_widget_show (hbox
);
193 Prompter::~Prompter ()
197 g_object_unref (mSizeGroup
);
200 gtk_widget_destroy (GTK_WIDGET (mDialog
));
201 g_object_unref (mDialog
);
203 g_object_unref (ephy_embed_shell_get_default ());
207 Prompter::AddStockButton (const char *aStock
,
210 gtk_dialog_add_button (GTK_DIALOG (mDialog
),
216 Prompter::AddButtonWithFlags (PRInt32 aNum
,
218 const PRUnichar
*aText
,
221 if (aFlags
== 0) return;
223 const char *label
= NULL
;
225 gboolean isAffirmative
= FALSE
;
228 case nsIPromptService::BUTTON_TITLE_OK
:
229 label
= GTK_STOCK_OK
;
230 isAffirmative
= TRUE
;
233 case nsIPromptService::BUTTON_TITLE_CANCEL
:
234 label
= GTK_STOCK_CANCEL
;
237 case nsIPromptService::BUTTON_TITLE_YES
:
238 label
= GTK_STOCK_YES
;
239 isAffirmative
= TRUE
;
242 case nsIPromptService::BUTTON_TITLE_NO
:
243 label
= GTK_STOCK_NO
;
246 case nsIPromptService::BUTTON_TITLE_SAVE
:
247 label
= GTK_STOCK_SAVE
;
248 isAffirmative
= TRUE
;
251 case nsIPromptService::BUTTON_TITLE_DONT_SAVE
:
252 label
= _("Don't Save");
255 case nsIPromptService::BUTTON_TITLE_REVERT
:
256 label
= GTK_STOCK_REVERT_TO_SAVED
;
259 case nsIPromptService::BUTTON_TITLE_IS_STRING
:
261 label
= freeme
= ConvertAndEscapeButtonText (aText
, MAX_BUTTON_TEXT_LENGTH
);
262 /* We can't tell, so assume it's affirmative */
263 isAffirmative
= TRUE
;
267 if (label
== NULL
) return;
269 gtk_dialog_add_button (mDialog
, label
, aNum
);
272 if (isAffirmative
&& mDelay
)
274 gtk_dialog_set_response_sensitive (mDialog
, aNum
, FALSE
);
279 mUnaffirmativeResponse
= aNum
;
284 mDefaultResponse
= aNum
;
291 Prompter::AddButtonsWithFlags (PRUint32 aFlags
,
292 const PRUnichar
*aText0
,
293 const PRUnichar
*aText1
,
294 const PRUnichar
*aText2
)
296 mDelay
= (aFlags
& nsIPromptService::BUTTON_DELAY_ENABLE
) != 0;
297 mDefaultResponse
= -1;
299 /* Reverse the order, on the assumption that what we passed is the
300 * 'windows' button order, and we want HIG order.
302 AddButtonWithFlags (2, ((aFlags
/ nsIPromptService::BUTTON_POS_2
) & 0xff), aText2
,
303 aFlags
& nsIPromptService::BUTTON_POS_2_DEFAULT
);
304 AddButtonWithFlags (1, ((aFlags
/ nsIPromptService::BUTTON_POS_1
) & 0xff), aText1
,
305 aFlags
& nsIPromptService::BUTTON_POS_1_DEFAULT
);
306 AddButtonWithFlags (0, ((aFlags
/ nsIPromptService::BUTTON_POS_0
) & 0xff), aText0
,
307 aFlags
& nsIPromptService::BUTTON_POS_0_DEFAULT
);
309 /* If no default was set, use the 'rightmost' unaffirmative response.
310 * This happens with the suite's password manager prompt.
312 if (mDefaultResponse
== -1)
314 mDefaultResponse
= mUnaffirmativeResponse
;
319 Prompter::AddCheckbox (const PRUnichar
*aText
,
322 if (!aState
|| !aText
) return;
324 char *label
= ConvertAndEscapeButtonText (aText
, 2 * MAX_BUTTON_TEXT_LENGTH
);
325 mCheck
= gtk_check_button_new_with_mnemonic (label
);
328 gtk_label_set_line_wrap (GTK_LABEL (GTK_BIN (mCheck
)->child
), TRUE
);
329 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (mCheck
), *aState
);
330 gtk_box_pack_start (GTK_BOX (mVBox
), mCheck
, FALSE
, FALSE
, 0);
331 gtk_widget_show (mCheck
);
335 Prompter::GetCheckboxState (PRBool
*aState
)
337 if (!aState
|| !mCheck
) return;
339 *aState
= gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (mCheck
));
343 Prompter::AddEntry (const char *aLabel
,
344 const PRUnichar
*aValue
,
349 mSizeGroup
= gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL
);
352 GtkWidget
*hbox
= gtk_hbox_new (FALSE
, 12);
353 gtk_box_pack_start (GTK_BOX (mVBox
), hbox
, FALSE
, FALSE
, 0);
355 GtkWidget
*label
= nsnull
;
358 label
= gtk_label_new_with_mnemonic (aLabel
);
359 gtk_misc_set_alignment (GTK_MISC (label
), 0.0, 0.5);
360 gtk_box_pack_start (GTK_BOX (hbox
), label
, FALSE
, FALSE
, 0);
361 gtk_size_group_add_widget (mSizeGroup
, label
);
364 GtkWidget
*entry
= mEntries
[mNumEntries
++] = gtk_entry_new ();
365 gtk_entry_set_visibility (GTK_ENTRY (entry
), !aIsPassword
);
366 gtk_entry_set_activates_default(GTK_ENTRY (entry
), TRUE
);
371 NS_UTF16ToCString (nsDependentString(aValue
),
372 NS_CSTRING_ENCODING_UTF8
, cValue
);
374 gtk_entry_set_text (GTK_ENTRY (entry
), cValue
.get());
379 gtk_label_set_mnemonic_widget (GTK_LABEL (label
), entry
);
382 gtk_box_pack_start (GTK_BOX (hbox
), entry
, TRUE
, TRUE
, 0);
383 gtk_widget_show_all (hbox
);
387 Prompter::GetText (PRUint32 aNum
,
390 if (!aValue
|| !mEntries
[aNum
]) return;
392 const char *text
= gtk_entry_get_text (GTK_ENTRY (mEntries
[aNum
]));
396 NS_CStringToUTF16 (nsDependentCString (text
),
397 NS_CSTRING_ENCODING_UTF8
, value
);
399 *aValue
= NS_StringCloneData (value
);
403 Prompter::AddSelect (PRUint32 aCount
,
404 const PRUnichar
**aList
,
407 mCombo
= gtk_combo_box_new_text ();
409 for (PRUint32 i
= 0; i
< aCount
; i
++)
411 /* FIXME: use "" instead in this case? */
412 if (!aList
[i
] || !aList
[i
][0]) continue;
415 NS_UTF16ToCString (nsDependentString(aList
[i
]), NS_CSTRING_ENCODING_UTF8
, cData
);
417 gtk_combo_box_append_text (GTK_COMBO_BOX (mCombo
), cData
.get());
420 gtk_combo_box_set_active (GTK_COMBO_BOX (mCombo
), aDefault
);
422 gtk_box_pack_start (GTK_BOX (mVBox
), mCombo
, FALSE
, FALSE
, 0);
423 gtk_widget_show (mCombo
);
427 Prompter::GetSelected (PRInt32
*aSelected
)
429 if (!aSelected
|| !mCombo
) return;
431 *aSelected
= gtk_combo_box_get_active (GTK_COMBO_BOX (mCombo
));
435 EnableResponse (GtkDialog
*aDialog
)
437 g_object_steal_data (G_OBJECT (aDialog
), TIMEOUT_DATA_KEY
);
439 gtk_dialog_set_response_sensitive (aDialog
, 0, TRUE
);
440 gtk_dialog_set_response_sensitive (aDialog
, 1, TRUE
);
441 gtk_dialog_set_response_sensitive (aDialog
, 2, TRUE
);
447 RemoveTimeout (gpointer idptr
)
449 guint timeout
= GPOINTER_TO_UINT (idptr
);
451 g_return_if_fail (timeout
!= 0);
453 g_source_remove (timeout
);
457 Prompter::Run (PRBool
*aSuccess
)
460 AutoEventQueue queue
;
461 if (NS_FAILED (queue
.Init()))
465 *aSuccess
= PR_FALSE
;
469 return GTK_RESPONSE_CANCEL
;
474 AutoJSContextStack stack
;
476 if (NS_FAILED (rv
)) return rv
;
478 AutoWindowModalState
modalState (mWindow
);
482 guint timeout
= g_timeout_add (TIMEOUT
,
483 (GSourceFunc
) EnableResponse
,
485 g_object_set_data_full (G_OBJECT (mDialog
), TIMEOUT_DATA_KEY
,
486 GUINT_TO_POINTER (timeout
),
487 (GDestroyNotify
) RemoveTimeout
);
490 gtk_dialog_set_default_response (GTK_DIALOG (mDialog
), mDefaultResponse
);
492 GtkWidget
*widget
= GTK_WIDGET (mDialog
);
493 gtk_widget_show (widget
);
494 mResponse
= gtk_dialog_run (mDialog
);
495 gtk_widget_hide (widget
);
497 g_object_set_data (G_OBJECT (mDialog
), TIMEOUT_DATA_KEY
, NULL
);
499 mSuccess
= (GTK_RESPONSE_ACCEPT
== mResponse
);
502 *aSuccess
= mSuccess
;
505 if (mResponse
== RESPONSE_ABORT_SCRIPT
)
507 PerformScriptAbortion ();
514 DeletePrompter (gpointer aPromptPtr
,
517 Prompter
*prompt
= NS_STATIC_CAST (Prompter
*, aPromptPtr
);
525 /* We don't need it anymore */
528 gtk_window_set_modal (GTK_WINDOW (mDialog
), FALSE
);
530 g_signal_connect (mDialog
, "response",
531 G_CALLBACK (gtk_widget_destroy
), NULL
);
532 g_object_weak_ref (G_OBJECT (mDialog
),
533 (GWeakNotify
) DeletePrompter
,
534 NS_STATIC_CAST (gpointer
, this));
536 gtk_widget_show (GTK_WIDGET (mDialog
));
540 Prompter::IsCalledFromScript()
543 nsCOMPtr
<nsIXPConnect
> xpconnect (do_GetService (nsIXPConnect::GetCID()));
544 NS_ENSURE_TRUE (xpconnect
, PR_FALSE
);
547 nsCOMPtr
<nsIXPCNativeCallContext
> ncc
;
548 rv
= xpconnect
->GetCurrentNativeCallContext (getter_AddRefs (ncc
));
549 NS_ENSURE_SUCCESS (rv
, PR_FALSE
);
551 if (!ncc
) return PR_FALSE
;
553 JSContext
*cx
= nsnull
;
554 rv
= ncc
->GetJSContext (&cx
);
555 g_print ("GetJSContext rv=%x, cx=%p\n", rv
, cx
);
557 NS_ENSURE_SUCCESS (rv
, PR_FALSE
);
565 Prompter::PerformScriptAbortion()
568 /* FIXME: can we only stop the calling script, not all scripts in the context? */
570 nsCOMPtr
<nsIXPConnect
> xpconnect (do_GetService (nsIXPConnect::GetCID()));
571 NS_ENSURE_TRUE (xpconnect
, );
574 nsCOMPtr
<nsIXPCNativeCallContext
> ncc
;
575 rv
= xpconnect
->GetCurrentNativeCallContext (getter_AddRefs (ncc
));
576 NS_ENSURE_SUCCESS (rv
, );
577 NS_ENSURE_TRUE (ncc
, );
579 JSContext
*cx
= nsnull
;
580 rv
= ncc
->GetJSContext (&cx
);
581 g_print ("GetJSContext rv=%x, cx=%p\n", rv
, cx
);
582 NS_ENSURE_SUCCESS (rv
, );
583 NS_ENSURE_TRUE (cx
, );
585 g_print ("Would now disable scripts\n");
586 // MozillaPrivate::SetScriptsEnabled (cx, PR_FALSE, PR_FALSE);
591 Prompter::ConvertAndTruncateString (const PRUnichar
*aText
,
594 if (aText
== nsnull
) return NULL
;
596 /* This depends on the assumption that
597 * typeof(PRUnichar) == typeof (gunichar2) == uint16,
598 * which should be pretty safe.
600 glong n_read
= 0, n_written
= 0;
601 char *converted
= g_utf16_to_utf8 ((gunichar2
*) aText
, aMaxLength
,
602 &n_read
, &n_written
, NULL
);
603 /* FIXME loop from the end while !g_unichar_isspace (char)? */
609 Prompter::ConvertAndEscapeButtonText(const PRUnichar
*aText
,
612 char *converted
= ConvertAndTruncateString (aText
, aMaxLength
);
613 if (converted
== NULL
) return NULL
;
615 char *escaped
= (char*) g_malloc (strlen (converted
) + 1);
617 for (const char *p
= converted
; *p
; ++p
, ++q
)
637 /* Null termination */
645 /* FIXME: needs THREADSAFE? */
646 #if HAVE_NSINONBLOCKINGALERTSERVICE_H
647 NS_IMPL_ISUPPORTS2 (EphyPromptService
,
649 nsINonBlockingAlertService
)
651 NS_IMPL_ISUPPORTS1 (EphyPromptService
,
655 EphyPromptService::EphyPromptService()
657 LOG ("EphyPromptService ctor (%p)", this);
660 EphyPromptService::~EphyPromptService()
662 LOG ("EphyPromptService dtor (%p)", this);
665 /* nsIPromptService implementation */
667 /* void alert (in nsIDOMWindow aParent, in wstring aDialogTitle, in wstring aText); */
669 EphyPromptService::Alert (nsIDOMWindow
*aParent
,
670 const PRUnichar
*aDialogTitle
,
671 const PRUnichar
*aText
)
673 Prompter
prompt (GTK_STOCK_DIALOG_INFO
, aParent
, aDialogTitle
, aText
);
674 prompt
.AddStockButton (GTK_STOCK_OK
, GTK_RESPONSE_ACCEPT
);
680 /* void alertCheck (in nsIDOMWindow aParent, in wstring aDialogTitle, in wstring aText, in wstring aCheckMsg, inout boolean aCheckState); */
682 EphyPromptService::AlertCheck (nsIDOMWindow
*aParent
,
683 const PRUnichar
*aDialogTitle
,
684 const PRUnichar
*aText
,
685 const PRUnichar
*aCheckMsg
,
688 Prompter
prompt (GTK_STOCK_DIALOG_INFO
, aParent
, aDialogTitle
, aText
);
689 prompt
.AddStockButton (GTK_STOCK_OK
, GTK_RESPONSE_ACCEPT
);
690 prompt
.AddCheckbox (aCheckMsg
, aCheckState
);
693 prompt
.GetCheckboxState (aCheckState
);
698 /* boolean confirm (in nsIDOMWindow aParent, in wstring aDialogTitle, in wstring aText); */
700 EphyPromptService::Confirm (nsIDOMWindow
*aParent
,
701 const PRUnichar
*aDialogTitle
,
702 const PRUnichar
*aText
,
705 NS_ENSURE_ARG_POINTER (_retval
);
707 Prompter
prompt (GTK_STOCK_DIALOG_QUESTION
, aParent
, aDialogTitle
, aText
);
708 prompt
.AddStockButton (GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
);
709 prompt
.AddStockButton (GTK_STOCK_OK
, GTK_RESPONSE_ACCEPT
);
710 prompt
.Run (_retval
);
715 /* boolean confirmCheck (in nsIDOMWindow aParent, in wstring aDialogTitle, in wstring aText, in wstring aCheckMsg, inout boolean aCheckState); */
717 EphyPromptService::ConfirmCheck (nsIDOMWindow
*aParent
,
718 const PRUnichar
*aDialogTitle
,
719 const PRUnichar
*aText
,
720 const PRUnichar
*aCheckMsg
,
724 NS_ENSURE_ARG_POINTER (_retval
);
726 Prompter
prompt (GTK_STOCK_DIALOG_QUESTION
, aParent
, aDialogTitle
, aText
);
727 prompt
.AddStockButton (GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
);
728 prompt
.AddStockButton (GTK_STOCK_OK
, GTK_RESPONSE_ACCEPT
);
729 prompt
.AddCheckbox (aCheckMsg
, aCheckState
);
731 prompt
.Run (_retval
);
732 prompt
.GetCheckboxState (aCheckState
);
737 /* PRInt32 confirmEx (in nsIDOMWindow aParent, in wstring aDialogTitle, in wstring aText, in unsigned long aButtonFlags, in wstring aButton0Title, in wstring aButton1Title, in wstring aButton2Title, in wstring aCheckMsg, inout boolean aCheckState); */
739 EphyPromptService::ConfirmEx (nsIDOMWindow
*aParent
,
740 const PRUnichar
*aDialogTitle
,
741 const PRUnichar
*aText
,
742 PRUint32 aButtonFlags
,
743 const PRUnichar
*aButton0Title
,
744 const PRUnichar
*aButton1Title
,
745 const PRUnichar
*aButton2Title
,
746 const PRUnichar
*aCheckMsg
,
750 NS_ENSURE_ARG_POINTER (_retval
);
752 Prompter
prompt (GTK_STOCK_DIALOG_QUESTION
, aParent
, aDialogTitle
, aText
);
753 prompt
.AddButtonsWithFlags (aButtonFlags
, aButton0Title
,
754 aButton1Title
, aButton2Title
);
755 prompt
.AddCheckbox (aCheckMsg
, aCheckState
);
757 *_retval
= prompt
.Run (nsnull
);
758 prompt
.GetCheckboxState (aCheckState
);
763 /* boolean prompt (in nsIDOMWindow aParent, in wstring aDialogTitle, in wstring aText, inout wstring aValue, in wstring aCheckMsg, inout boolean aCheckState); */
765 EphyPromptService::Prompt (nsIDOMWindow
*aParent
,
766 const PRUnichar
*aDialogTitle
,
767 const PRUnichar
*aText
,
769 const PRUnichar
*aCheckMsg
,
773 NS_ENSURE_ARG_POINTER (_retval
);
774 NS_ENSURE_ARG_POINTER (aValue
);
776 Prompter
prompt (GTK_STOCK_DIALOG_QUESTION
, aParent
, aDialogTitle
, aText
);
777 prompt
.AddStockButton (GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
);
778 prompt
.AddStockButton (GTK_STOCK_OK
, GTK_RESPONSE_ACCEPT
);
779 prompt
.AddEntry (nsnull
, *aValue
, PR_FALSE
);
780 prompt
.AddCheckbox (aCheckMsg
, aCheckState
);
782 prompt
.Run (_retval
);
783 prompt
.GetText (0, aValue
);
784 prompt
.GetCheckboxState (aCheckState
);
789 /* boolean promptUsernameAndPassword (in nsIDOMWindow aParent, in wstring aDialogTitle, in wstring aText, inout wstring aUsername, inout wstring aPassword, in wstring aCheckMsg, inout boolean aCheckState); */
791 EphyPromptService::PromptUsernameAndPassword (nsIDOMWindow
*aParent
,
792 const PRUnichar
*aDialogTitle
,
793 const PRUnichar
*aText
,
794 PRUnichar
**aUsername
,
795 PRUnichar
**aPassword
,
796 const PRUnichar
*aCheckMsg
,
800 NS_ENSURE_ARG_POINTER (_retval
);
801 NS_ENSURE_ARG_POINTER (aUsername
);
802 NS_ENSURE_ARG_POINTER (aPassword
);
804 Prompter
prompt (GTK_STOCK_DIALOG_AUTHENTICATION
, aParent
, aDialogTitle
, aText
);
805 prompt
.AddStockButton (GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
);
806 prompt
.AddStockButton (GTK_STOCK_OK
, GTK_RESPONSE_ACCEPT
);
807 prompt
.AddEntry (_("_Username:"), *aUsername
, PR_FALSE
);
808 prompt
.AddEntry (_("_Password:"), *aPassword
, PR_TRUE
);
809 prompt
.AddCheckbox (aCheckMsg
, aCheckState
);
811 prompt
.Run (_retval
);
812 prompt
.GetText (0, aUsername
);
813 prompt
.GetText (1, aPassword
);
814 prompt
.GetCheckboxState (aCheckState
);
819 /* boolean promptPassword (in nsIDOMWindow aParent, in wstring aDialogTitle, in wstring aText, inout wstring aPassword, in wstring aCheckMsg, inout boolean aCheckState); */
821 EphyPromptService::PromptPassword (nsIDOMWindow
*aParent
,
822 const PRUnichar
*aDialogTitle
,
823 const PRUnichar
*aText
,
824 PRUnichar
**aPassword
,
825 const PRUnichar
*aCheckMsg
,
829 NS_ENSURE_ARG_POINTER (_retval
);
830 NS_ENSURE_ARG_POINTER (aPassword
);
832 Prompter
prompt (GTK_STOCK_DIALOG_AUTHENTICATION
, aParent
, aDialogTitle
, aText
);
833 prompt
.AddStockButton (GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
);
834 prompt
.AddStockButton (GTK_STOCK_OK
, GTK_RESPONSE_ACCEPT
);
835 prompt
.AddEntry (_("_Password:"), *aPassword
, PR_TRUE
);
836 prompt
.AddCheckbox (aCheckMsg
, aCheckState
);
838 // FIXME: Add a CAPSLOCK indicator?
840 prompt
.Run (_retval
);
841 prompt
.GetText (0, aPassword
);
842 prompt
.GetCheckboxState (aCheckState
);
847 /* boolean select (in nsIDOMWindow aParent, in wstring aDialogTitle, in wstring aText, in PRUint32 aCount, [array, size_is (aCount)] in wstring aSelectList, out long aOutSelection); */
849 EphyPromptService::Select (nsIDOMWindow
*aParent
,
850 const PRUnichar
*aDialogTitle
,
851 const PRUnichar
*aText
,
853 const PRUnichar
**aSelectList
,
854 PRInt32
*aOutSelection
,
857 NS_ENSURE_ARG_POINTER (_retval
);
858 NS_ENSURE_ARG_POINTER (aOutSelection
);
860 Prompter
prompt (GTK_STOCK_DIALOG_QUESTION
, aParent
, aDialogTitle
, aText
);
861 prompt
.AddStockButton (GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
);
862 prompt
.AddStockButton (GTK_STOCK_OK
, GTK_RESPONSE_ACCEPT
);
863 prompt
.AddSelect (aCount
, aSelectList
, *aOutSelection
);
865 prompt
.Run (_retval
);
866 prompt
.GetSelected (aOutSelection
);
871 #if HAVE_NSINONBLOCKINGALERTSERVICE_H
873 /* showNonBlockingAlert (in nsIDOMWindow aParent, in wstring aDialogTitle, in wstring aText); */
875 EphyPromptService::ShowNonBlockingAlert (nsIDOMWindow
*aParent
,
876 const PRUnichar
*aDialogTitle
,
877 const PRUnichar
*aText
)
879 Prompter
*prompt
= new Prompter (GTK_STOCK_DIALOG_INFO
, aParent
, aDialogTitle
, aText
);
880 if (!prompt
) return NS_ERROR_OUT_OF_MEMORY
;
882 prompt
->AddStockButton (GTK_STOCK_OK
, GTK_RESPONSE_ACCEPT
);
888 #endif /* HAVE_NSINONBLOCKINGALERTSERVICE_H */