1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870
|
/*
* Copyright (C) 2005, 2006 Christian Persch
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#include "config.h"
#include "EphyPromptService.h"
#include "AutoJSContextStack.h"
#include <nsCOMPtr.h>
#include <nsIDOMWindow.h>
#define MOZILLA_STRICT_API
#include <nsEmbedString.h>
#undef MOZILLA_STRICT_API
#if 0
#include <nsIPrincipal.h>
#include <nsIScriptSecurityManager.h>
#include <nsIServiceManager.h>
#endif
#if 0
#include "AutoEventQueue.h"
#endif
#include "GaleonUtils.h"
#include <glib.h>
#include <glib-object.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include "src/galeon-shell.h"
#include "galeon-debug.h"
#define TIMEOUT 1000 /* ms */
#define TIMEOUT_DATA_KEY "timeout"
#define MAX_MESSAGE_LENGTH 512
#define MAX_TITLE_LENGTH 256
#define MAX_BUTTON_TEXT_LENGTH 128
enum
{
RESPONSE_ABORT_SCRIPT = 42
};
#define RETVAL(r) (r = NS_OK)
class Prompter
{
public:
Prompter (const char*, nsIDOMWindow*, const PRUnichar*, const PRUnichar*);
~Prompter();
void AddStockButton (const char*, int);
void AddButtonWithFlags (PRInt32, PRUint32, const PRUnichar*, PRUint32);
void AddButtonsWithFlags (PRUint32, const PRUnichar*, const PRUnichar*, const PRUnichar*);
void AddCheckbox (const PRUnichar*, PRBool*);
void GetCheckboxState (PRBool *);
void AddEntry (const char *, const PRUnichar *, PRBool);
void GetText (PRUint32, PRUnichar **);
void AddSelect (PRUint32, const PRUnichar **, PRInt32);
void GetSelected (PRInt32*);
PRInt32 Run (PRBool * = nsnull);
void Show ();
PRBool IsCalledFromScript ();
void PerformScriptAbortion ();
char *ConvertAndTruncateString (const PRUnichar *, PRInt32 = -1);
char* ConvertAndEscapeButtonText (const PRUnichar *, PRInt32 = -1);
private:
GtkDialog *mDialog;
GtkWidget *mVBox;
GtkWidget *mCheck;
GtkSizeGroup *mSizeGroup;
GtkWidget *mEntries[2];
GtkWidget *mCombo;
PRInt32 mNumButtons;
PRInt32 mNumEntries;
PRInt32 mDefaultResponse;
PRInt32 mUnaffirmativeResponse;
PRInt32 mResponse;
PRBool mSuccess;
PRBool mDelay;
};
Prompter::Prompter (const char *aStock,
nsIDOMWindow *aParent,
const PRUnichar *aTitle,
const PRUnichar *aText)
: mDialog(nsnull)
, mVBox(nsnull)
, mCheck(nsnull)
, mSizeGroup(nsnull)
, mCombo(nsnull)
, mNumButtons(0)
, mNumEntries(0)
, mDefaultResponse(GTK_RESPONSE_ACCEPT)
, mUnaffirmativeResponse(0)
, mResponse(GTK_RESPONSE_CANCEL)
, mSuccess(PR_FALSE)
, mDelay(PR_FALSE)
{
GtkWidget *parent, *hbox, *label, *image;
g_object_ref (embed_shell);
mEntries[0] = mEntries[1] = nsnull;
mDialog = GTK_DIALOG (gtk_dialog_new ());
g_object_ref (mDialog);
gtk_object_sink (GTK_OBJECT (mDialog));
char *title = NULL;
if (aTitle)
{
title = ConvertAndTruncateString (aTitle, MAX_TITLE_LENGTH);
}
gtk_window_set_title (GTK_WINDOW (mDialog), title ? title : "");
g_free (title);
gtk_window_set_modal (GTK_WINDOW (mDialog), TRUE);
parent = GaleonUtils::FindGtkParent (aParent);
if (GTK_IS_WINDOW (parent))
{
gtk_window_set_transient_for (GTK_WINDOW (mDialog),
GTK_WINDOW (parent));
}
gtk_dialog_set_has_separator (mDialog, FALSE);
gtk_window_set_resizable (GTK_WINDOW (mDialog), FALSE);
gtk_container_set_border_width (GTK_CONTAINER (mDialog), 5);
gtk_box_set_spacing (GTK_BOX (mDialog->vbox), 14); /* 2 * 5 + 14 = 24 */
hbox = gtk_hbox_new (FALSE, 12);
gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (mDialog)->vbox), hbox);
image = gtk_image_new_from_stock (aStock, GTK_ICON_SIZE_DIALOG);
gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0);
gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
mVBox = gtk_vbox_new (FALSE, 12);
gtk_box_pack_start (GTK_BOX (hbox), mVBox, TRUE, TRUE, 0);
char *text = NULL;
if (aText)
{
text = ConvertAndTruncateString (aText, MAX_MESSAGE_LENGTH);
}
label = gtk_label_new (text);
g_free (text);
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
gtk_label_set_selectable (GTK_LABEL (label), TRUE);
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
gtk_box_pack_start (GTK_BOX (mVBox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
if (IsCalledFromScript ())
{
gtk_dialog_add_button (GTK_DIALOG (mDialog),
_("_Abort Script"),
RESPONSE_ABORT_SCRIPT);
}
gtk_widget_show (image);
gtk_widget_show (mVBox);
gtk_widget_show (hbox);
}
Prompter::~Prompter ()
{
if (mSizeGroup)
{
g_object_unref (mSizeGroup);
}
gtk_widget_destroy (GTK_WIDGET (mDialog));
g_object_unref (mDialog);
g_object_unref (embed_shell);
}
void
Prompter::AddStockButton (const char *aStock,
int aResponse)
{
gtk_dialog_add_button (GTK_DIALOG (mDialog),
aStock, aResponse);
++mNumButtons;
}
void
Prompter::AddButtonWithFlags (PRInt32 aNum,
PRUint32 aFlags,
const PRUnichar *aText,
PRUint32 aDefault)
{
if (aFlags == 0) return;
const char *label = NULL;
char *freeme = NULL;
gboolean isAffirmative = FALSE;
switch (aFlags)
{
case nsIPromptService::BUTTON_TITLE_OK:
label = GTK_STOCK_OK;
isAffirmative = TRUE;
break;
case nsIPromptService::BUTTON_TITLE_CANCEL:
label = GTK_STOCK_CANCEL;
break;
case nsIPromptService::BUTTON_TITLE_YES:
label = GTK_STOCK_YES;
isAffirmative = TRUE;
break;
case nsIPromptService::BUTTON_TITLE_NO:
label = GTK_STOCK_NO;
break;
case nsIPromptService::BUTTON_TITLE_SAVE:
label = GTK_STOCK_SAVE;
isAffirmative = TRUE;
break;
case nsIPromptService::BUTTON_TITLE_DONT_SAVE:
label = _("Don't Save");
break;
case nsIPromptService::BUTTON_TITLE_REVERT:
label = GTK_STOCK_REVERT_TO_SAVED;
break;
case nsIPromptService::BUTTON_TITLE_IS_STRING:
default:
label = freeme = ConvertAndEscapeButtonText (aText, MAX_BUTTON_TEXT_LENGTH);
/* We can't tell, so assume it's affirmative */
isAffirmative = TRUE;
break;
}
if (label == NULL) return;
gtk_dialog_add_button (mDialog, label, aNum);
++mNumButtons;
if (isAffirmative && mDelay)
{
gtk_dialog_set_response_sensitive (mDialog, aNum, FALSE);
}
if (!isAffirmative)
{
mUnaffirmativeResponse = aNum;
}
if (aDefault)
{
mDefaultResponse = aNum;
}
g_free (freeme);
}
void
Prompter::AddButtonsWithFlags (PRUint32 aFlags,
const PRUnichar *aText0,
const PRUnichar *aText1,
const PRUnichar *aText2)
{
mDelay = (aFlags & nsIPromptService::BUTTON_DELAY_ENABLE) != 0;
mDefaultResponse = -1;
/* Reverse the order, on the assumption that what we passed is the
* 'windows' button order, and we want HIG order.
*/
AddButtonWithFlags (2, ((aFlags / nsIPromptService::BUTTON_POS_2) & 0xff), aText2,
aFlags & nsIPromptService::BUTTON_POS_2_DEFAULT);
AddButtonWithFlags (1, ((aFlags / nsIPromptService::BUTTON_POS_1) & 0xff), aText1,
aFlags & nsIPromptService::BUTTON_POS_1_DEFAULT);
AddButtonWithFlags (0, ((aFlags / nsIPromptService::BUTTON_POS_0) & 0xff), aText0,
aFlags & nsIPromptService::BUTTON_POS_0_DEFAULT);
/* If no default was set, use the 'rightmost' unaffirmative response.
* This happens with the suite's password manager prompt.
*/
if (mDefaultResponse == -1)
{
mDefaultResponse = mUnaffirmativeResponse;
}
}
void
Prompter::AddCheckbox (const PRUnichar *aText,
PRBool *aState)
{
if (!aState || !aText) return;
char *label = ConvertAndEscapeButtonText (aText, 2 * MAX_BUTTON_TEXT_LENGTH);
mCheck = gtk_check_button_new_with_mnemonic (label);
g_free (label);
gtk_label_set_line_wrap (GTK_LABEL (GTK_BIN (mCheck)->child), TRUE);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (mCheck), *aState);
gtk_box_pack_start (GTK_BOX (mVBox), mCheck, FALSE, FALSE, 0);
gtk_widget_show (mCheck);
}
void
Prompter::GetCheckboxState (PRBool *aState)
{
if (!aState || !mCheck) return;
*aState = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (mCheck));
}
void
Prompter::AddEntry (const char *aLabel,
const PRUnichar *aValue,
PRBool aIsPassword)
{
if (!mSizeGroup)
{
mSizeGroup = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
}
GtkWidget *hbox = gtk_hbox_new (FALSE, 12);
gtk_box_pack_start (GTK_BOX (mVBox), hbox, FALSE, FALSE, 0);
GtkWidget *label = nsnull;
if (aLabel)
{
label = gtk_label_new_with_mnemonic (aLabel);
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_size_group_add_widget (mSizeGroup, label);
}
GtkWidget *entry = mEntries[mNumEntries++] = gtk_entry_new ();
gtk_entry_set_visibility (GTK_ENTRY (entry), !aIsPassword);
gtk_entry_set_activates_default(GTK_ENTRY (entry), TRUE);
if (aValue)
{
nsEmbedCString cValue;
NS_UTF16ToCString (nsDependentString(aValue),
NS_CSTRING_ENCODING_UTF8, cValue);
gtk_entry_set_text (GTK_ENTRY (entry), cValue.get());
}
if (label)
{
gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
}
gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
gtk_widget_show_all (hbox);
}
void
Prompter::GetText (PRUint32 aNum,
PRUnichar **aValue)
{
if (!aValue || !mEntries[aNum]) return;
const char *text = gtk_entry_get_text (GTK_ENTRY (mEntries[aNum]));
if (!text) return;
nsEmbedString value;
NS_CStringToUTF16 (nsDependentCString (text),
NS_CSTRING_ENCODING_UTF8, value);
*aValue = NS_StringCloneData (value);
}
void
Prompter::AddSelect (PRUint32 aCount,
const PRUnichar **aList,
PRInt32 aDefault)
{
mCombo = gtk_combo_box_new_text ();
for (PRUint32 i = 0; i < aCount; i++)
{
/* FIXME: use "" instead in this case? */
if (!aList[i] || !aList[i][0]) continue;
nsEmbedCString cData;
NS_UTF16ToCString (nsDependentString(aList[i]), NS_CSTRING_ENCODING_UTF8, cData);
gtk_combo_box_append_text (GTK_COMBO_BOX (mCombo), cData.get());
}
gtk_combo_box_set_active (GTK_COMBO_BOX (mCombo), aDefault);
gtk_box_pack_start (GTK_BOX (mVBox), mCombo, FALSE, FALSE, 0);
gtk_widget_show (mCombo);
}
void
Prompter::GetSelected (PRInt32 *aSelected)
{
if (!aSelected || !mCombo) return;
*aSelected = gtk_combo_box_get_active (GTK_COMBO_BOX (mCombo));
}
static gboolean
EnableResponse (GtkDialog *aDialog)
{
g_object_steal_data (G_OBJECT (aDialog), TIMEOUT_DATA_KEY);
gtk_dialog_set_response_sensitive (aDialog, 0, TRUE);
gtk_dialog_set_response_sensitive (aDialog, 1, TRUE);
gtk_dialog_set_response_sensitive (aDialog, 2, TRUE);
return FALSE;
}
static void
RemoveTimeout (GObject *aDialog)
{
guint timeout;
timeout = GPOINTER_TO_UINT (g_object_get_data (aDialog, TIMEOUT_DATA_KEY));
g_return_if_fail (timeout != 0);
g_source_remove (timeout);
}
PRInt32
Prompter::Run (PRBool *aSuccess)
{
#if 0
AutoEventQueue queue;
if (NS_FAILED (queue.Init()))
{
if (aSuccess)
{
*aSuccess = PR_FALSE;
}
mSuccess = PR_FALSE;
return GTK_RESPONSE_CANCEL;
}
#endif
nsresult rv;
AutoJSContextStack stack;
rv = stack.Init ();
if (NS_FAILED (rv)) return rv;
if (mDelay)
{
guint timeout = g_timeout_add (TIMEOUT,
(GSourceFunc) EnableResponse,
mDialog);
g_object_set_data_full (G_OBJECT (mDialog), TIMEOUT_DATA_KEY,
GUINT_TO_POINTER (timeout),
(GDestroyNotify) RemoveTimeout);
}
gtk_dialog_set_default_response (GTK_DIALOG (mDialog), mDefaultResponse);
GtkWidget *widget = GTK_WIDGET (mDialog);
gtk_widget_show (widget);
mResponse = gtk_dialog_run (mDialog);
gtk_widget_hide (widget);
g_object_set_data (G_OBJECT (mDialog), TIMEOUT_DATA_KEY, NULL);
mSuccess = (GTK_RESPONSE_ACCEPT == mResponse);
if (aSuccess)
{
*aSuccess = mSuccess;
}
if (mResponse == RESPONSE_ABORT_SCRIPT)
{
PerformScriptAbortion ();
}
return mResponse;
}
static void
DeletePrompter (gpointer aPromptPtr,
GObject *aZombie)
{
Prompter *prompt = static_cast<Prompter*>(aPromptPtr);
delete prompt;
}
void
Prompter::Show ()
{
gtk_window_set_modal (GTK_WINDOW (mDialog), FALSE);
g_signal_connect (mDialog, "response",
G_CALLBACK (gtk_widget_destroy), NULL);
g_object_weak_ref (G_OBJECT (mDialog),
(GWeakNotify) DeletePrompter,
static_cast<gpointer>(this));
gtk_widget_show (GTK_WIDGET (mDialog));
}
PRBool
Prompter::IsCalledFromScript()
{
/* FIXME: implement me! */
#if 0
nsresult rv;
nsCOMPtr<nsIScriptSecurityManager> securityManager =
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS (rv, PR_FALSE);
nsCOMPtr<nsIPrincipal> principal;
rv = securityManager->GetSubjectPrincipal (getter_AddRefs (principal));
g_print ("rv=%x mPrincipal=%p\n", rv, (void*)principal.get());
return NS_SUCCEEDED (rv) && principal.get();
#endif
return PR_FALSE;
}
void
Prompter::PerformScriptAbortion()
{
/* FIXME: implement me! */
#if 0
nsresult rv;
nsCOMPtr<nsIScriptSecurityManager> securityManager =
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS (rv, );
securityManager->DisableCapability ("javascript.enabled");
#endif
}
char *
Prompter::ConvertAndTruncateString (const PRUnichar *aText,
PRInt32 aMaxLength)
{
if (aText == nsnull) return NULL;
/* This depends on the assumption that
* typeof(PRUnichar) == typeof (gunichar2) == uint16,
* which should be pretty safe.
*/
glong n_read = 0, n_written = 0;
char *converted = g_utf16_to_utf8 ((gunichar2*) aText, aMaxLength,
&n_read, &n_written, NULL);
/* FIXME loop from the end while !g_unichar_isspace (char)? */
return converted;
}
char *
Prompter::ConvertAndEscapeButtonText(const PRUnichar *aText,
PRInt32 aMaxLength)
{
char *converted = ConvertAndTruncateString (aText, aMaxLength);
if (converted == NULL) return NULL;
char *escaped = (char*) g_malloc (strlen (converted) + 1);
char *q = escaped;
for (const char *p = converted; *p; ++p, ++q)
{
if (*p == '&')
{
if (*(p+1) == '&')
{
*q = '&';
++p;
}
else
{
*q = '_';
}
}
else
{
*q = *p;
}
}
/* Null termination */
*q = '\0';
g_free (converted);
return escaped;
}
/* FIXME: needs THREADSAFE? */
#if HAVE_NSINONBLOCKINGALERTSERVICE_H
NS_IMPL_ISUPPORTS2 (EphyPromptService,
nsIPromptService,
nsINonBlockingAlertService)
#else
NS_IMPL_ISUPPORTS1 (EphyPromptService,
nsIPromptService)
#endif
EphyPromptService::EphyPromptService()
{
LOG ("EphyPromptService ctor (%p)", this);
}
EphyPromptService::~EphyPromptService()
{
LOG ("EphyPromptService dtor (%p)", this);
}
/* nsIPromptService implementation */
/* void alert (in nsIDOMWindow aParent, in wstring aDialogTitle, in wstring aText); */
NS_IMETHODIMP
EphyPromptService::Alert (nsIDOMWindow *aParent,
const PRUnichar *aDialogTitle,
const PRUnichar *aText)
{
Prompter prompt (GTK_STOCK_DIALOG_INFO, aParent, aDialogTitle, aText);
prompt.AddStockButton (GTK_STOCK_OK, GTK_RESPONSE_ACCEPT);
PRInt32 response = prompt.Run ();
return RETVAL(response);
}
/* void alertCheck (in nsIDOMWindow aParent, in wstring aDialogTitle, in wstring aText, in wstring aCheckMsg, inout boolean aCheckState); */
NS_IMETHODIMP
EphyPromptService::AlertCheck (nsIDOMWindow *aParent,
const PRUnichar *aDialogTitle,
const PRUnichar *aText,
const PRUnichar *aCheckMsg,
PRBool *aCheckState)
{
Prompter prompt (GTK_STOCK_DIALOG_INFO, aParent, aDialogTitle, aText);
prompt.AddStockButton (GTK_STOCK_OK, GTK_RESPONSE_ACCEPT);
prompt.AddCheckbox (aCheckMsg, aCheckState);
PRInt32 response = prompt.Run ();
prompt.GetCheckboxState (aCheckState);
return RETVAL(response);
}
/* boolean confirm (in nsIDOMWindow aParent, in wstring aDialogTitle, in wstring aText); */
NS_IMETHODIMP
EphyPromptService::Confirm (nsIDOMWindow *aParent,
const PRUnichar *aDialogTitle,
const PRUnichar *aText,
PRBool *_retval)
{
NS_ENSURE_ARG_POINTER (_retval);
Prompter prompt (GTK_STOCK_DIALOG_QUESTION, aParent, aDialogTitle, aText);
prompt.AddStockButton (GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
prompt.AddStockButton (GTK_STOCK_OK, GTK_RESPONSE_ACCEPT);
PRInt32 response = prompt.Run (_retval);
return RETVAL(response);
}
/* boolean confirmCheck (in nsIDOMWindow aParent, in wstring aDialogTitle, in wstring aText, in wstring aCheckMsg, inout boolean aCheckState); */
NS_IMETHODIMP
EphyPromptService::ConfirmCheck (nsIDOMWindow *aParent,
const PRUnichar *aDialogTitle,
const PRUnichar *aText,
const PRUnichar *aCheckMsg,
PRBool *aCheckState,
PRBool *_retval)
{
NS_ENSURE_ARG_POINTER (_retval);
Prompter prompt (GTK_STOCK_DIALOG_QUESTION, aParent, aDialogTitle, aText);
prompt.AddStockButton (GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
prompt.AddStockButton (GTK_STOCK_OK, GTK_RESPONSE_ACCEPT);
prompt.AddCheckbox (aCheckMsg, aCheckState);
PRInt32 response = prompt.Run (_retval);
prompt.GetCheckboxState (aCheckState);
return RETVAL(response);
}
/* 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); */
NS_IMETHODIMP
EphyPromptService::ConfirmEx (nsIDOMWindow *aParent,
const PRUnichar *aDialogTitle,
const PRUnichar *aText,
PRUint32 aButtonFlags,
const PRUnichar *aButton0Title,
const PRUnichar *aButton1Title,
const PRUnichar *aButton2Title,
const PRUnichar *aCheckMsg,
PRBool *aCheckState,
PRInt32 *_retval)
{
NS_ENSURE_ARG_POINTER (_retval);
Prompter prompt (GTK_STOCK_DIALOG_QUESTION, aParent, aDialogTitle, aText);
prompt.AddButtonsWithFlags (aButtonFlags, aButton0Title,
aButton1Title, aButton2Title);
prompt.AddCheckbox (aCheckMsg, aCheckState);
PRInt32 response = prompt.Run (nsnull);
*_retval = response;
prompt.GetCheckboxState (aCheckState);
return RETVAL(response);
}
/* boolean prompt (in nsIDOMWindow aParent, in wstring aDialogTitle, in wstring aText, inout wstring aValue, in wstring aCheckMsg, inout boolean aCheckState); */
NS_IMETHODIMP
EphyPromptService::Prompt (nsIDOMWindow *aParent,
const PRUnichar *aDialogTitle,
const PRUnichar *aText,
PRUnichar **aValue,
const PRUnichar *aCheckMsg,
PRBool *aCheckState,
PRBool *_retval)
{
NS_ENSURE_ARG_POINTER (_retval);
NS_ENSURE_ARG_POINTER (aValue);
Prompter prompt (GTK_STOCK_DIALOG_QUESTION, aParent, aDialogTitle, aText);
prompt.AddStockButton (GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
prompt.AddStockButton (GTK_STOCK_OK, GTK_RESPONSE_ACCEPT);
prompt.AddEntry (nsnull, *aValue, PR_FALSE);
prompt.AddCheckbox (aCheckMsg, aCheckState);
PRInt32 response = prompt.Run (_retval);
prompt.GetText (0, aValue);
prompt.GetCheckboxState (aCheckState);
return RETVAL(response);
}
/* boolean promptUsernameAndPassword (in nsIDOMWindow aParent, in wstring aDialogTitle, in wstring aText, inout wstring aUsername, inout wstring aPassword, in wstring aCheckMsg, inout boolean aCheckState); */
NS_IMETHODIMP
EphyPromptService::PromptUsernameAndPassword (nsIDOMWindow *aParent,
const PRUnichar *aDialogTitle,
const PRUnichar *aText,
PRUnichar **aUsername,
PRUnichar **aPassword,
const PRUnichar *aCheckMsg,
PRBool *aCheckState,
PRBool *_retval)
{
NS_ENSURE_ARG_POINTER (_retval);
NS_ENSURE_ARG_POINTER (aUsername);
NS_ENSURE_ARG_POINTER (aPassword);
Prompter prompt (GTK_STOCK_DIALOG_AUTHENTICATION, aParent, aDialogTitle, aText);
prompt.AddStockButton (GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
prompt.AddStockButton (GTK_STOCK_OK, GTK_RESPONSE_ACCEPT);
prompt.AddEntry (_("_Username:"), *aUsername, PR_FALSE);
prompt.AddEntry (_("_Password:"), *aPassword, PR_TRUE);
prompt.AddCheckbox (aCheckMsg, aCheckState);
PRInt32 response = prompt.Run (_retval);
prompt.GetText (0, aUsername);
prompt.GetText (1, aPassword);
prompt.GetCheckboxState (aCheckState);
return RETVAL(response);
}
/* boolean promptPassword (in nsIDOMWindow aParent, in wstring aDialogTitle, in wstring aText, inout wstring aPassword, in wstring aCheckMsg, inout boolean aCheckState); */
NS_IMETHODIMP
EphyPromptService::PromptPassword (nsIDOMWindow *aParent,
const PRUnichar *aDialogTitle,
const PRUnichar *aText,
PRUnichar **aPassword,
const PRUnichar *aCheckMsg,
PRBool *aCheckState,
PRBool *_retval)
{
NS_ENSURE_ARG_POINTER (_retval);
NS_ENSURE_ARG_POINTER (aPassword);
Prompter prompt (GTK_STOCK_DIALOG_AUTHENTICATION, aParent, aDialogTitle, aText);
prompt.AddStockButton (GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
prompt.AddStockButton (GTK_STOCK_OK, GTK_RESPONSE_ACCEPT);
prompt.AddEntry (_("_Password:"), *aPassword, PR_TRUE);
prompt.AddCheckbox (aCheckMsg, aCheckState);
// FIXME: Add a CAPSLOCK indicator?
PRInt32 response = prompt.Run (_retval);
prompt.GetText (0, aPassword);
prompt.GetCheckboxState (aCheckState);
return RETVAL(response);
}
/* boolean select (in nsIDOMWindow aParent, in wstring aDialogTitle, in wstring aText, in PRUint32 aCount, [array, size_is (aCount)] in wstring aSelectList, out long aOutSelection); */
NS_IMETHODIMP
EphyPromptService::Select (nsIDOMWindow *aParent,
const PRUnichar *aDialogTitle,
const PRUnichar *aText,
PRUint32 aCount,
const PRUnichar **aSelectList,
PRInt32 *aOutSelection,
PRBool *_retval)
{
NS_ENSURE_ARG_POINTER (_retval);
NS_ENSURE_ARG_POINTER (aOutSelection);
Prompter prompt (GTK_STOCK_DIALOG_QUESTION, aParent, aDialogTitle, aText);
prompt.AddStockButton (GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
prompt.AddStockButton (GTK_STOCK_OK, GTK_RESPONSE_ACCEPT);
prompt.AddSelect (aCount, aSelectList, *aOutSelection);
PRInt32 response = prompt.Run (_retval);
prompt.GetSelected (aOutSelection);
return RETVAL(response);
}
#if HAVE_NSINONBLOCKINGALERTSERVICE_H
/* showNonBlockingAlert (in nsIDOMWindow aParent, in wstring aDialogTitle, in wstring aText); */
NS_IMETHODIMP
EphyPromptService::ShowNonBlockingAlert (nsIDOMWindow *aParent,
const PRUnichar *aDialogTitle,
const PRUnichar *aText)
{
Prompter *prompt = new Prompter (GTK_STOCK_DIALOG_INFO, aParent, aDialogTitle, aText);
if (!prompt) return NS_ERROR_OUT_OF_MEMORY;
prompt->AddStockButton (GTK_STOCK_OK, GTK_RESPONSE_ACCEPT);
prompt->Show ();
return NS_OK;
}
#endif /* HAVE_NSINONBLOCKINGALERTSERVICE_H */
|