diff options
author | Christian Persch <chpe@gnome.org> | 2007-03-12 20:47:10 +0800 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2007-03-12 20:47:10 +0800 |
commit | 44bce1ab7d508b27cb8471bfbda15733752f81f8 (patch) | |
tree | 6b7bbc63dc807da574162b8bb9b42fae907e08a5 /embed | |
parent | 5754e9de9cbbf108eb28b28b609bfe95092afbc3 (diff) | |
download | gsoc2013-epiphany-44bce1ab7d508b27cb8471bfbda15733752f81f8.tar gsoc2013-epiphany-44bce1ab7d508b27cb8471bfbda15733752f81f8.tar.gz gsoc2013-epiphany-44bce1ab7d508b27cb8471bfbda15733752f81f8.tar.bz2 gsoc2013-epiphany-44bce1ab7d508b27cb8471bfbda15733752f81f8.tar.lz gsoc2013-epiphany-44bce1ab7d508b27cb8471bfbda15733752f81f8.tar.xz gsoc2013-epiphany-44bce1ab7d508b27cb8471bfbda15733752f81f8.tar.zst gsoc2013-epiphany-44bce1ab7d508b27cb8471bfbda15733752f81f8.zip |
Implement nsICookiePromptService. Bug #337826.
2007-03-12 Christian Persch <chpe@gnome.org>
* embed/mozilla/GeckoCookiePromptService.cpp:
* embed/mozilla/GeckoCookiePromptService.h:
* embed/mozilla/Makefile.am:
* embed/mozilla/MozRegisterComponents.cpp:
Implement nsICookiePromptService. Bug #337826.
svn path=/trunk/; revision=6961
Diffstat (limited to 'embed')
-rw-r--r-- | embed/mozilla/GeckoCookiePromptService.cpp | 160 | ||||
-rw-r--r-- | embed/mozilla/GeckoCookiePromptService.h | 43 | ||||
-rw-r--r-- | embed/mozilla/Makefile.am | 2 | ||||
-rw-r--r-- | embed/mozilla/MozRegisterComponents.cpp | 10 |
4 files changed, 214 insertions, 1 deletions
diff --git a/embed/mozilla/GeckoCookiePromptService.cpp b/embed/mozilla/GeckoCookiePromptService.cpp new file mode 100644 index 000000000..843546c2d --- /dev/null +++ b/embed/mozilla/GeckoCookiePromptService.cpp @@ -0,0 +1,160 @@ +/* + * Copyright © 2003 Tommi Komulainen <tommi.komulainen@iki.fi> + * Copyright © 2004, 2007 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 "mozilla-config.h" +#include "config.h" + +#include <glib/gi18n.h> + +#include <gtk/gtkbox.h> +#include <gtk/gtkcheckbutton.h> +#include <gtk/gtkdialog.h> +#include <gtk/gtkmessagedialog.h> +#include <gtk/gtkstock.h> +#include <gtk/gtkwindow.h> + +#include <nsStringAPI.h> + +#include "ephy-debug.h" +#include "ephy-gui.h" + +#include "AutoJSContextStack.h" +#include "AutoWindowModalState.h" +#include "EphyUtils.h" + +#include "GeckoCookiePromptService.h" + +NS_IMPL_ISUPPORTS1 (GeckoCookiePromptService, nsICookiePromptService) + +GeckoCookiePromptService::GeckoCookiePromptService() +{ + LOG ("GeckoCookiePromptService ctor [%p]", this); +} + +GeckoCookiePromptService::~GeckoCookiePromptService() +{ + LOG ("GeckoCookiePromptService 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 +GeckoCookiePromptService::CookieDialog (nsIDOMWindow *aParent, + nsICookie *aCookie, + const nsACString &aHostname, + PRInt32 aCookiesFromHost, + PRBool aChangingCookie, + PRBool *_checkValue, + PRBool *_retval) +{ + NS_ENSURE_ARG (aParent); + 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 *parent = EphyUtils::FindGtkParent (aParent); + NS_ENSURE_TRUE(parent, NS_ERROR_INVALID_POINTER); + + nsresult rv; + AutoJSContextStack stack; + rv = stack.Init (); + if (NS_FAILED (rv)) { + return rv; + } + + AutoWindowModalState modalState (aParent); + + nsCString host(aHostname); + + GtkWidget *dialog = gtk_message_dialog_new + (GTK_WINDOW (parent), + GTK_DIALOG_MODAL /* FIXME mozilla sucks! */, + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_NONE, + _("Accept cookie from %s?"), + host.get()); + GtkWindow *window = GTK_WINDOW (dialog); + GtkDialog *gdialog = GTK_DIALOG (dialog); + GtkMessageDialog *message_dialog = GTK_MESSAGE_DIALOG (dialog); + + gtk_window_set_icon_name (window, "web-browser"); + gtk_window_set_title (window, _("Accept Cookie?")); + + if (aChangingCookie) { + gtk_message_dialog_format_secondary_text + (message_dialog, + _("The site wants to modify an existing cookie.")); + } else if (aCookiesFromHost == 0) { + gtk_message_dialog_format_secondary_text + (message_dialog, + _("The site wants to set a cookie.")); + } else if (aCookiesFromHost == 1) { + gtk_message_dialog_format_secondary_text + (message_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 + (message_dialog, + "The site %s wants to set another cookie. %s", + host.get(), 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 (ephy_gui_message_dialog_get_content_box (dialog)), + checkbutton, FALSE, FALSE, 0); + + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbutton), *_checkValue); + + gtk_dialog_add_button (gdialog, + _("_Reject"), GTK_RESPONSE_REJECT); + gtk_dialog_add_button (gdialog, + _("_Accept"), GTK_RESPONSE_ACCEPT); + gtk_dialog_set_default_response (gdialog, GTK_RESPONSE_ACCEPT); + + int response = gtk_dialog_run (gdialog); + + if (response == 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; +} diff --git a/embed/mozilla/GeckoCookiePromptService.h b/embed/mozilla/GeckoCookiePromptService.h new file mode 100644 index 000000000..7092a2982 --- /dev/null +++ b/embed/mozilla/GeckoCookiePromptService.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2003 Tommi Komulainen <tommi.komulainen@iki.fi> + * + * 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$ + */ + +#ifndef COOKIEPROMPTSERVICE_H +#define COOKIEPROMPTSERVICE_H + +#include <nsICookiePromptService.h> + +/* 50766a18-0b34-41d9-8f6c-4612200e6556 */ +#define EPHY_COOKIEPROMPTSERVICE_CID \ + { 0x50766a18, 0x0b34, 0x41d9, { 0x8f, 0x6c, 0x46, 0x12, 0x20, 0x0e, 0x65, 0x56 } } + +#define EPHY_COOKIEPROMPTSERVICE_CLASSNAME "Epiphany Cookie Prompt Service" +#define EPHY_COOKIEPROMPTSERVICE_CONTRACTID "@mozilla.org/embedcomp/cookieprompt-service;1" + +class GeckoCookiePromptService : public nsICookiePromptService { + public: + NS_DECL_ISUPPORTS + NS_DECL_NSICOOKIEPROMPTSERVICE + + GeckoCookiePromptService(); + + private: + ~GeckoCookiePromptService(); +}; + +#endif /* COOKIEPROMPTSERVICE_H */ diff --git a/embed/mozilla/Makefile.am b/embed/mozilla/Makefile.am index 418c7c702..e63cf43a8 100644 --- a/embed/mozilla/Makefile.am +++ b/embed/mozilla/Makefile.am @@ -35,6 +35,8 @@ libephymozillaembed_la_SOURCES = \ EphyUtils.h \ EventContext.cpp \ EventContext.h \ + GeckoCookiePromptService.cpp \ + GeckoCookiePromptService.h \ GeckoFormSigningDialog.cpp \ GeckoFormSigningDialog.h \ GeckoPrintService.cpp \ diff --git a/embed/mozilla/MozRegisterComponents.cpp b/embed/mozilla/MozRegisterComponents.cpp index 05b2d1a6a..e712bbc5d 100644 --- a/embed/mozilla/MozRegisterComponents.cpp +++ b/embed/mozilla/MozRegisterComponents.cpp @@ -55,6 +55,7 @@ #include "EphyContentPolicy.h" #include "EphyPromptService.h" #include "EphySidebar.h" +#include "GeckoCookiePromptService.h" #include "GeckoPrintService.h" #include "GeckoPrintSession.h" #include "GlobalHistory.h" @@ -81,6 +82,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(EphyContentPolicy) NS_GENERIC_FACTORY_CONSTRUCTOR(EphyPromptService) NS_GENERIC_FACTORY_CONSTRUCTOR(EphySidebar) NS_GENERIC_FACTORY_CONSTRUCTOR(GContentHandler) +NS_GENERIC_FACTORY_CONSTRUCTOR(GeckoCookiePromptService) NS_GENERIC_FACTORY_CONSTRUCTOR(GeckoPrintService) NS_GENERIC_FACTORY_CONSTRUCTOR(GeckoPrintSession) NS_GENERIC_FACTORY_CONSTRUCTOR(MozDownload) @@ -267,8 +269,14 @@ static const nsModuleComponentInfo sAppComps[] = { GECKO_SPELL_CHECK_ENGINE_IID, GECKO_SPELL_CHECK_ENGINE_CONTRACTID, GeckoSpellCheckEngineConstructor - } + }, #endif /* ENABLE_SPELLCHECK */ + { + EPHY_COOKIEPROMPTSERVICE_CLASSNAME, + EPHY_COOKIEPROMPTSERVICE_CID, + EPHY_COOKIEPROMPTSERVICE_CONTRACTID, + GeckoCookiePromptServiceConstructor + } }; gboolean |