aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Persch <chpe@cvs.gnome.org>2003-11-25 06:43:10 +0800
committerChristian Persch <chpe@src.gnome.org>2003-11-25 06:43:10 +0800
commit7200cd97ba96357d050ba7015e54a16d421b63d0 (patch)
tree1b9ed45739e627483dcbe080daf1c19a3058d5c5
parentc34c1e3df618940b2b139444bf2906d5e627d166 (diff)
downloadgsoc2013-epiphany-7200cd97ba96357d050ba7015e54a16d421b63d0.tar
gsoc2013-epiphany-7200cd97ba96357d050ba7015e54a16d421b63d0.tar.gz
gsoc2013-epiphany-7200cd97ba96357d050ba7015e54a16d421b63d0.tar.bz2
gsoc2013-epiphany-7200cd97ba96357d050ba7015e54a16d421b63d0.tar.lz
gsoc2013-epiphany-7200cd97ba96357d050ba7015e54a16d421b63d0.tar.xz
gsoc2013-epiphany-7200cd97ba96357d050ba7015e54a16d421b63d0.tar.zst
gsoc2013-epiphany-7200cd97ba96357d050ba7015e54a16d421b63d0.zip
Implemented cookie and permissions observer used to actually send
2003-11-24 Christian Persch <chpe@cvs.gnome.org> * embed/ephy-permission-manager.h: * embed/mozilla/EphyBrowser.cpp: * embed/mozilla/EphySingle.cpp: * embed/mozilla/EphySingle.h: * embed/mozilla/Makefile.am: * embed/mozilla/mozilla-embed-single.cpp: * src/ephy-encoding-dialog.c: (sync_embed_encoding), (automatic_toggled_cb), (ephy_encoding_dialog_init): Implemented cookie and permissions observer used to actually send notifications on EphyCookieManager and EphyPermissionManager signals.
-rw-r--r--ChangeLog15
-rw-r--r--embed/ephy-permission-manager.h2
-rw-r--r--embed/mozilla/EphyBrowser.cpp1
-rw-r--r--embed/mozilla/EphySingle.cpp317
-rw-r--r--embed/mozilla/EphySingle.h60
-rw-r--r--embed/mozilla/Makefile.am2
-rw-r--r--embed/mozilla/mozilla-embed-single.cpp97
7 files changed, 417 insertions, 77 deletions
diff --git a/ChangeLog b/ChangeLog
index 153e12e99..905de61bb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
2003-11-24 Christian Persch <chpe@cvs.gnome.org>
+ * embed/ephy-permission-manager.h:
+ * embed/mozilla/EphyBrowser.cpp:
+ * embed/mozilla/EphySingle.cpp:
+ * embed/mozilla/EphySingle.h:
+ * embed/mozilla/Makefile.am:
+ * embed/mozilla/mozilla-embed-single.cpp:
+ * src/ephy-encoding-dialog.c: (sync_embed_encoding),
+ (automatic_toggled_cb), (ephy_encoding_dialog_init):
+
+ Implemented cookie and permissions observer used to actually
+ send notifications on EphyCookieManager and EphyPermissionManager
+ signals.
+
+2003-11-24 Christian Persch <chpe@cvs.gnome.org>
+
* embed/mozilla/nsUnicharUtils.cpp:
* embed/mozilla/nsUnicharUtils.h:
diff --git a/embed/ephy-permission-manager.h b/embed/ephy-permission-manager.h
index e8e2a5fb2..1afa829ea 100644
--- a/embed/ephy-permission-manager.h
+++ b/embed/ephy-permission-manager.h
@@ -43,7 +43,7 @@ typedef enum
{
EPT_COOKIE,
EPT_IMAGE,
- EPT_PASSWORD
+ EPT_POPUP
} EphyPermissionType;
typedef struct
diff --git a/embed/mozilla/EphyBrowser.cpp b/embed/mozilla/EphyBrowser.cpp
index 2f1b19d7e..08b81190a 100644
--- a/embed/mozilla/EphyBrowser.cpp
+++ b/embed/mozilla/EphyBrowser.cpp
@@ -64,7 +64,6 @@
#include "nsIDocumentObserver.h"
#include "nsCWebBrowser.h"
#include "nsReadableUtils.h"
-#include "nsUnicharUtils.h"
#include "nsIDOMNSHTMLDocument.h"
#include "nsIDOMHTMLDocument.h"
#include "nsIDOMHTMLCollection.h"
diff --git a/embed/mozilla/EphySingle.cpp b/embed/mozilla/EphySingle.cpp
new file mode 100644
index 000000000..0963551de
--- /dev/null
+++ b/embed/mozilla/EphySingle.cpp
@@ -0,0 +1,317 @@
+/*
+ * Copyright (C) 2003 Christian Persch
+ * Copyright (C) 2003 Marco Pesenti Gritti
+ *
+ * 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.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "EphySingle.h"
+
+#include "ephy-debug.h"
+
+#include <nsString.h>
+#include <nsICookie2.h>
+#include <nsIURI.h>
+#include <nsIPermissionManager.h>
+#include <nsICookieManager.h>
+#include <nsIServiceManager.h>
+
+NS_IMPL_ISUPPORTS1(EphySingle, nsIObserver)
+
+EphySingle::EphySingle()
+{
+ LOG ("EphySingle constructor")
+
+ mOwner = nsnull;
+}
+
+nsresult
+EphySingle::Init (EphyEmbedSingle *aOwner)
+{
+ LOG ("EphySingle::Init")
+
+ mOwner = aOwner;
+
+ nsresult rv;
+ mObserverService = do_GetService ("@mozilla.org/observer-service;1", &rv);
+ if (NS_FAILED (rv) || !mObserverService) return NS_ERROR_FAILURE;
+
+ mObserverService->AddObserver (this, "cookie-changed", PR_FALSE);
+ mObserverService->AddObserver (this, "cookie-rejected", PR_FALSE);
+ mObserverService->AddObserver (this, "perm-changed", PR_FALSE);
+
+ return NS_OK;
+}
+
+nsresult
+EphySingle::Detach ()
+{
+ if (mObserverService)
+ {
+ mObserverService->RemoveObserver (this, "cookie-changed");
+ mObserverService->RemoveObserver (this, "cookie-rejected");
+ mObserverService->RemoveObserver (this, "perm-changed");
+ }
+
+ return NS_OK;
+}
+
+EphySingle::~EphySingle()
+{
+ LOG ("EphySingle destructor")
+
+ Detach();
+ mOwner = nsnull;
+}
+
+nsresult
+EphySingle::EmitCookieNotification (const char *name, nsISupports *aSubject)
+{
+ LOG ("EmitCookieNotification %s", name)
+
+ nsCOMPtr<nsICookie> cookie = do_QueryInterface (aSubject);
+ if (!cookie) return NS_ERROR_FAILURE;
+
+ EphyCookie *info = mozilla_cookie_to_ephy_cookie (cookie);
+
+ g_signal_emit_by_name (EPHY_COOKIE_MANAGER (mOwner), name, info);
+
+ ephy_cookie_free (info);
+
+ return NS_OK;
+}
+
+nsresult
+EphySingle::EmitPermissionNotification (const char *name, nsISupports *aSubject)
+{
+ LOG ("EmitPermissionNotification %s", name)
+
+ nsCOMPtr<nsIPermission> perm = do_QueryInterface (aSubject);
+ if (!perm) return NS_ERROR_FAILURE;
+
+ EphyPermissionInfo *info =
+ mozilla_permission_to_ephy_permission (perm);
+
+
+ g_signal_emit_by_name (EPHY_PERMISSION_MANAGER (mOwner), name, info);
+
+ ephy_permission_info_free (info);
+
+ return NS_OK;
+}
+
+/* void observe (in nsISupports aSubject, in string aTopic, in wstring aData); */
+NS_IMETHODIMP EphySingle::Observe(nsISupports *aSubject,
+ const char *aTopic,
+ const PRUnichar *aData)
+{
+ nsresult rv = NS_OK;
+
+ if (strcmp (aTopic, "cookie-changed") == 0)
+ {
+ /* "added" */
+ if (aData[0] == 'a')
+ {
+ rv = EmitCookieNotification ("added", aSubject);
+ }
+ /* "deleted" */
+ else if (aData[0] == 'd')
+ {
+ rv = EmitCookieNotification ("deleted", aSubject);
+ }
+ /* "changed" */
+ else if (aData[0] == 'c' && aData[1] == 'h')
+ {
+ rv = EmitCookieNotification ("changed", aSubject);
+ }
+ /* "cleared" */
+ else if (aData[0] == 'c' && aData[2] == 'l')
+ {
+ LOG ("EphySingle::cookie-changed::cleared")
+
+ g_signal_emit_by_name (EPHY_COOKIE_MANAGER (mOwner), "cleared");
+ }
+ else
+ {
+ g_warning ("EphySingle unexpected data!\n");
+ rv = NS_ERROR_FAILURE;
+ }
+ }
+ else if (strcmp (aTopic, "cookie-rejected") == 0)
+ {
+ LOG ("EphySingle::cookie-rejected")
+
+ nsCOMPtr<nsIURI> uri = do_QueryInterface (aSubject);
+ if (uri)
+ {
+ nsCAutoString spec;
+ uri->GetSpec (spec);
+
+ g_signal_emit_by_name (EPHY_COOKIE_MANAGER (mOwner), "rejected", spec.get());
+ }
+ else
+ {
+ rv = NS_ERROR_FAILURE;
+ }
+ }
+ else if (strcmp (aTopic, "perm-changed") == 0)
+ {
+ /* "added" */
+ if (aData[0] == 'a')
+ {
+ rv = EmitPermissionNotification ("added", aSubject);
+ }
+ /* "deleted" */
+ else if (aData[0] == 'd')
+ {
+ rv = EmitPermissionNotification ("deleted", aSubject);
+ }
+ /* "changed" */
+ else if (aData[0] == 'c' && aData[1] == 'h')
+ {
+ rv = EmitPermissionNotification ("changed", aSubject);
+ }
+ /* "cleared" */
+ else if (aData[0] == 'c' && aData[1] == 'l')
+ {
+ LOG ("EphySingle::perm-changed::cleared")
+
+ g_signal_emit_by_name (EPHY_PERMISSION_MANAGER (mOwner), "cleared");
+ }
+ else
+ {
+ g_warning ("EphySingle unexpected data!\n");
+ rv = NS_ERROR_FAILURE;
+ }
+ }
+ else
+ {
+ g_warning ("EphySingle observed unknown topic!\n");
+ rv = NS_ERROR_FAILURE;
+ }
+
+ return rv;
+}
+
+EphyCookie *
+mozilla_cookie_to_ephy_cookie (nsICookie *cookie)
+{
+ EphyCookie *info = ephy_cookie_new ();
+
+ nsCAutoString transfer;
+
+ cookie->GetHost (transfer);
+ info->domain = g_strdup (transfer.get());
+ cookie->GetName (transfer);
+ info->name = g_strdup (transfer.get());
+ cookie->GetValue (transfer);
+ info->value = g_strdup (transfer.get());
+ cookie->GetPath (transfer);
+ info->path = g_strdup (transfer.get());
+
+ PRBool isSecure;
+ cookie->GetIsSecure (&isSecure);
+ info->is_secure = isSecure != PR_FALSE;
+
+ nsCookieStatus status;
+ cookie->GetStatus (&status);
+ info->p3p_state = status;
+
+ nsCookiePolicy policy;
+ cookie->GetPolicy (&policy);
+ info->p3p_policy = policy;
+
+ PRUint64 dateTime;
+ cookie->GetExpires (&dateTime);
+ info->expires = dateTime;
+
+#if MOZILLA_SNAPSHOT > 9
+ nsCOMPtr<nsICookie2> cookie2 = do_QueryInterface (cookie);
+ if (cookie2)
+ {
+
+ PRBool isSession;
+ cookie2->GetIsSession (&isSession);
+ info->is_session = isSession != PR_FALSE;
+
+ if (!isSession)
+ {
+ PRInt64 expiry;
+ cookie2->GetExpiry (&expiry);
+ info->real_expires = expiry;
+ }
+ }
+#endif
+
+ return info;
+}
+
+EphyPermissionInfo *
+mozilla_permission_to_ephy_permission (nsIPermission *perm)
+{
+ EphyPermissionType type = (EphyPermissionType) 0;
+
+ nsresult result;
+#if MOZILLA_SNAPSHOT >= 10
+ nsCAutoString str;
+ result = perm->GetType(str);
+ if (NS_FAILED (result)) return NULL;
+
+ if (str.Equals ("cookie"))
+ {
+ type = EPT_COOKIE;
+ }
+ else if (str.Equals ("image"))
+ {
+ type = EPT_IMAGE;
+ }
+ else if (str.Equals ("popup"))
+ {
+ type = EPT_POPUP;
+ }
+#else
+ PRUint32 num;
+ result = perm->GetType(&num);
+ if (NS_FAILED (result)) return NULL;
+
+ type = (EphyPermissionType) num;
+#endif
+
+ PRUint32 cap;
+ perm->GetCapability(&cap);
+ gboolean allowed;
+ switch (cap)
+ {
+ case nsIPermissionManager::ALLOW_ACTION:
+ allowed = TRUE;
+ break;
+ case nsIPermissionManager::DENY_ACTION:
+ case nsIPermissionManager::UNKNOWN_ACTION:
+ default :
+ allowed = FALSE;
+ break;
+ }
+
+ nsCString host;
+ perm->GetHost(host);
+
+ return ephy_permission_info_new (host.get(), type, allowed);
+}
diff --git a/embed/mozilla/EphySingle.h b/embed/mozilla/EphySingle.h
new file mode 100644
index 000000000..ac884ffc0
--- /dev/null
+++ b/embed/mozilla/EphySingle.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2003 Christian Persch
+ * Copyright (C) 2003 Marco Pesenti Gritti
+ *
+ * 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.
+ *
+ * $Id$
+ */
+
+#ifndef EPHY_SINGLE_H
+#define EPHY_SINGLE_H
+
+#include "ephy-embed-single.h"
+#include "ephy-cookie-manager.h"
+#include "ephy-permission-manager.h"
+
+#include <nsCOMPtr.h>
+#include <nsIObserver.h>
+#include <nsIObserverService.h>
+#include <nsICookie.h>
+#include <nsIPermission.h>
+
+class EphySingle : public nsIObserver
+{
+public:
+ NS_DECL_ISUPPORTS
+ NS_DECL_NSIOBSERVER
+
+ EphySingle();
+ virtual ~EphySingle();
+
+ nsresult Init (EphyEmbedSingle *aOwner);
+ nsresult Detach ();
+
+protected:
+ nsresult EmitCookieNotification (const char *name, nsISupports *aSubject);
+ nsresult EmitPermissionNotification (const char *name, nsISupports *aSubject);
+
+private:
+ nsCOMPtr<nsIObserverService> mObserverService;
+ EphyEmbedSingle *mOwner;
+};
+
+EphyCookie *mozilla_cookie_to_ephy_cookie (nsICookie *cookie);
+
+EphyPermissionInfo *mozilla_permission_to_ephy_permission (nsIPermission *perm);
+
+#endif
diff --git a/embed/mozilla/Makefile.am b/embed/mozilla/Makefile.am
index b066f5efd..ba3b78439 100644
--- a/embed/mozilla/Makefile.am
+++ b/embed/mozilla/Makefile.am
@@ -57,6 +57,8 @@ libephymozillaembed_la_SOURCES = \
EphyHeaderSniffer.h \
EphyBrowser.cpp \
EphyBrowser.h \
+ EphySingle.cpp \
+ EphySingle.h \
EventContext.cpp \
EventContext.h \
ExternalProtocolHandlers.cpp \
diff --git a/embed/mozilla/mozilla-embed-single.cpp b/embed/mozilla/mozilla-embed-single.cpp
index 7d9fe5070..55bac6535 100644
--- a/embed/mozilla/mozilla-embed-single.cpp
+++ b/embed/mozilla/mozilla-embed-single.cpp
@@ -39,6 +39,7 @@
#include "eel-gconf-extensions.h"
#include "ephy-embed-prefs.h"
#include "MozRegisterComponents.h"
+#include "EphySingle.h"
#include <glib/gi18n.h>
#include <libgnomevfs/gnome-vfs-utils.h>
@@ -92,6 +93,8 @@ struct MozillaEmbedSinglePrivate
/* monitor this widget for theme changes*/
GtkWidget *theme_window;
+
+ EphySingle *mSingleObserver;
};
static void mozilla_embed_single_class_init (MozillaEmbedSingleClass *klass);
@@ -428,6 +431,17 @@ mozilla_init_chrome (void)
return NS_OK;
}
+static void
+mozilla_init_observer (MozillaEmbedSingle *single)
+{
+ single->priv->mSingleObserver = new EphySingle ();
+
+ if (single->priv->mSingleObserver)
+ {
+ single->priv->mSingleObserver->Init (EPHY_EMBED_SINGLE (single));
+ }
+}
+
static gboolean
init_services (MozillaEmbedSingle *single)
{
@@ -461,6 +475,8 @@ init_services (MozillaEmbedSingle *single)
mozilla_register_external_protocols ();
+ mozilla_init_observer (single);
+
return TRUE;
}
@@ -477,6 +493,8 @@ mozilla_embed_single_init (MozillaEmbedSingle *mes)
MOZILLA_PROFILE_FILE,
NULL);
+ mes->priv->mSingleObserver = nsnull;
+
if (!init_services (mes))
{
GtkWidget *dialog;
@@ -589,61 +607,6 @@ impl_get_font_list (EphyEmbedSingle *shell,
return g_list_reverse (l);
}
-static EphyCookie *
-mozilla_cookie_to_ephy_cookie (nsICookie *keks)
-{
- EphyCookie *cookie;
-
- cookie = ephy_cookie_new ();
-
- nsCAutoString transfer;
-
- keks->GetHost (transfer);
- cookie->domain = g_strdup (transfer.get());
- keks->GetName (transfer);
- cookie->name = g_strdup (transfer.get());
- keks->GetValue (transfer);
- cookie->value = g_strdup (transfer.get());
- keks->GetPath (transfer);
- cookie->path = g_strdup (transfer.get());
-
- PRBool isSecure;
- keks->GetIsSecure (&isSecure);
- cookie->is_secure = isSecure != PR_FALSE;
-
- nsCookieStatus status;
- keks->GetStatus (&status);
- cookie->p3p_state = status;
-
- nsCookiePolicy policy;
- keks->GetPolicy (&policy);
- cookie->p3p_policy = policy;
-
- PRUint64 dateTime;
- keks->GetExpires (&dateTime);
- cookie->expires = dateTime;
-
-#if MOZILLA_SNAPSHOT > 9
- nsCOMPtr<nsICookie2> keks2 = do_QueryInterface (keks);
- if (keks2)
- {
-
- PRBool isSession;
- keks2->GetIsSession (&isSession);
- cookie->is_session = isSession != PR_FALSE;
-
- if (!isSession)
- {
- PRInt64 expiry;
- keks2->GetExpiry (&expiry);
- cookie->real_expires = expiry;
- }
- }
-#endif
-
- return cookie;
-}
-
static GList *
impl_list_cookies (EphyCookieManager *manager)
{
@@ -892,29 +855,13 @@ impl_permission_manager_list (EphyPermissionManager *manager,
if ((PRUint32) num == (PRUint32) type)
#endif
{
- EphyPermissionInfo *info = g_new0 (EphyPermissionInfo, 1);
+ EphyPermissionInfo *info =
+ mozilla_permission_to_ephy_permission (perm);
- info->type = type;
-
- nsCString host;
- perm->GetHost(host);
- info->host = g_strdup (host.get());
-
- PRUint32 cap;
- perm->GetCapability(&cap);
- switch (cap)
+ if (info != NULL)
{
- case nsIPermissionManager::ALLOW_ACTION :
- info->allowed = TRUE;
- break;
- case nsIPermissionManager::DENY_ACTION :
- /* fallthrough */
- default :
- info->allowed = FALSE;
- break;
+ list = g_list_prepend (list, info);
}
-
- list = g_list_prepend (list, info);
}
}