/* * Copyright (C) 2003 Tommi Komulainen * Copyright (C) 2004 Christian Persch * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * 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 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. * * $Id$ */ #include "config.h" #include "CookiePromptService.h" #define MOZILLA_STRICT_API #include #undef MOZILLA_STRICT_API #include #include #include #include #include #include "EphyUtils.h" #include "ephy-debug.h" #include #define CONF_REMEMBER_DECISION "/apps/epiphany/extensions/galeon/cookie_remember_decision" NS_IMPL_ISUPPORTS1 (EphyCookiePromptService, nsICookiePromptService) EphyCookiePromptService::EphyCookiePromptService() { LOG ("EphyCookiePromptService ctor %p", this) } EphyCookiePromptService::~EphyCookiePromptService() { LOG ("EphyCookiePromptService dtor %p", this) } /* boolean cookieDialog (in nsIDOMWindow parent, in nsICookie cookie, in ACString hostname, in long cookiesFromHost, in boolean changingCookie, inout boolean checkValue); */ NS_IMETHODIMP EphyCookiePromptService::CookieDialog (nsIDOMWindow *aParent, nsICookie *aCookie, const nsACString &aHostname, PRInt32 aCookiesFromHost, PRBool aChangingCookie, PRBool *_checkValue, PRBool *_retval) { NS_ENSURE_ARG (aCookie); NS_ENSURE_ARG_POINTER (_checkValue); NS_ENSURE_ARG_POINTER (_retval); // TODO short-circuit and accept session cookies as per preference // TODO until mozilla starts supporting it natively? GtkWidget *pwin = EphyUtils::FindGtkParent (aParent); nsEmbedCString cHost(aHostname); GtkWidget *dialog; dialog = gtk_message_dialog_new (GTK_WINDOW (pwin), GTK_DIALOG_MODAL /* FIXME mozilla sucks! */, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, _("Accept cookie from %s?"), cHost.get()); gtk_window_set_icon_name (GTK_WINDOW (dialog), "web-browser"); gtk_window_set_title (GTK_WINDOW (dialog), _("Accept cookie?")); if (aChangingCookie) { gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), _("The site wants to modify an existing cookie.")); } else if (aCookiesFromHost == 0) { gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), _("The site wants to set a cookie.")); } else if (aCookiesFromHost == 1) { gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), _("The site wants to set a second cookie.")); } else { char *num_text = g_strdup_printf (dngettext(GETTEXT_PACKAGE, "You already have %d cookie from this site.", "You already have %d cookies from this site.", aCookiesFromHost), aCookiesFromHost); gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "The site %s wants to set another cookie. %s", num_text); g_free (num_text); } GtkWidget *checkbutton; checkbutton = gtk_check_button_new_with_mnemonic (_("Apply this _decision to all cookies from this site")); gtk_widget_show (checkbutton); gtk_box_pack_start (GTK_BOX (dialog->vbox), checkbutton); gtk_check_button_set_is_active (GTK_CHECK_BUTTON (checkbutton), *_checkValue); // gtk_widget_set_sensitive (checkbutton, eel_gconf_key_is_writable (CONF_REMEMBED_DECISION)); gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT, GTK_STOCK_ACCEPT); gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_RESPONSE_REJECT, GTK_STOCK_REJECT); int response; response = ephy_dialog_run (dialog); if (resonse == GTK_RESPONSE_ACCEPT || response == GTK_RESPONSE_REJECT) { *_retval = (response == GTK_RESPONSE_ACCEPT); *_checkValue = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton)); } else { /* if the dialog was closed, but no button was pressed, * consider it as 'Reject' but ignore the checkbutton */ *_retval = PR_FALSE; *_checkValue = PR_FALSE; } gtk_widget_destroy (dialog); return NS_OK; }