diff options
-rw-r--r-- | ChangeLog | 21 | ||||
-rw-r--r-- | embed/ephy-embed.c | 8 | ||||
-rw-r--r-- | embed/ephy-embed.h | 1 | ||||
-rw-r--r-- | embed/ephy-permission-manager.c | 3 | ||||
-rw-r--r-- | embed/mozilla/EphyBrowser.cpp | 148 | ||||
-rw-r--r-- | embed/mozilla/EphyBrowser.h | 38 | ||||
-rw-r--r-- | embed/mozilla/EphyEventListener.cpp | 123 | ||||
-rw-r--r-- | embed/mozilla/EphyEventListener.h | 46 | ||||
-rw-r--r-- | embed/mozilla/Makefile.am | 2 | ||||
-rw-r--r-- | src/Makefile.am | 4 | ||||
-rw-r--r-- | src/ephy-window.c | 8 | ||||
-rw-r--r-- | src/ephy-window.h | 2 |
12 files changed, 220 insertions, 184 deletions
@@ -1,3 +1,24 @@ +2003-12-09 Adam Hooper <adamh@densi.com> + + * embed/ephy-embed.c: (ephy_embed_base_init): + * embed/ephy-embed.h: + * embed/mozilla/EphyBrowser.cpp: + * embed/mozilla/EphyBrowser.h: + * embed/mozilla/Makefile.am: + + Move events code inside EphyBrowser.cpp and + add an event for blocked popup. + + * embed/ephy-permission-manager.c: + + Some more docs + + * src/Makefile.am: + * src/ephy-window.c: (ephy_window_get_statusbar): + * src/ephy-window.h: + + Add a way to access the statusbar for plugins + 2003-12-09 Jorn Baayen <jorn@nl.linux.org> * lib/egg/egg-editable-toolbar.c: (set_item_drag_source): diff --git a/embed/ephy-embed.c b/embed/ephy-embed.c index f6acc50e6..9bf7ef1d2 100644 --- a/embed/ephy-embed.c +++ b/embed/ephy-embed.c @@ -125,6 +125,14 @@ ephy_embed_base_init (gpointer g_class) G_TYPE_BOOLEAN, 1, G_TYPE_POINTER); + g_signal_new ("ge_popup_blocked", + EPHY_TYPE_EMBED, + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (EphyEmbedClass, popup_blocked), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 0); g_signal_new ("ge_security_change", EPHY_TYPE_EMBED, G_SIGNAL_RUN_LAST, diff --git a/embed/ephy-embed.h b/embed/ephy-embed.h index 4cd7a5371..0dc4a655b 100644 --- a/embed/ephy-embed.h +++ b/embed/ephy-embed.h @@ -170,6 +170,7 @@ struct EphyEmbedClass EphyEmbedEvent *event); gboolean (* dom_mouse_down) (EphyEmbed *embed, EphyEmbedEvent *event); + void (* popup_blocked) (EphyEmbed *embed); void (* security_change) (EphyEmbed *embed, EmbedSecurityLevel level); void (* zoom_change) (EphyEmbed *embed, diff --git a/embed/ephy-permission-manager.c b/embed/ephy-permission-manager.c index 9ef7512a9..b4b60ab78 100644 --- a/embed/ephy-permission-manager.c +++ b/embed/ephy-permission-manager.c @@ -283,7 +283,8 @@ ephy_permission_manager_test (EphyPermissionManager *manager, * @manager: the #EphyPermissionManager * @type: a #EphyPermissionType * - * Lists all permission entries of type @type in the permissions database. + * Lists all permission entries of type @type in the permissions database, each + * as its own #EphyPermissionInfo * * Return value: the list of permission entries **/ diff --git a/embed/mozilla/EphyBrowser.cpp b/embed/mozilla/EphyBrowser.cpp index a105987b3..c8c82c62c 100644 --- a/embed/mozilla/EphyBrowser.cpp +++ b/embed/mozilla/EphyBrowser.cpp @@ -52,7 +52,13 @@ #include "nsCWebBrowserPersist.h" #include "nsNetUtil.h" #include "nsIChromeEventHandler.h" +#include "nsIDOMDocument.h" #include "nsIDOMDocumentStyle.h" +#include "nsIDOMEvent.h" +#include "nsIDOMEventTarget.h" +#include "nsIDOMNode.h" +#include "nsIDOMElement.h" +#include "nsIDOMPopupBlockedEvent.h" #include "nsIDocShellTreeItem.h" #include "nsIDocShellTreeNode.h" #include "nsIDocShellTreeOwner.h" @@ -73,12 +79,122 @@ #include "nsIAtom.h" #include "nsIDocumentCharsetInfo.h" #include "nsPromiseFlatString.h" +#include "nsString.h" +#include "nsUnicharUtils.h" #include "ContentHandler.h" -#include "EphyEventListener.h" + +EphyEventListener::EphyEventListener(void) +{ + mOwner = nsnull; +} + +EphyEventListener::~EphyEventListener() +{ +} + +NS_IMPL_ISUPPORTS1(EphyEventListener, nsIDOMEventListener) + +nsresult +EphyEventListener::Init(EphyEmbed *aOwner) +{ + mOwner = aOwner; + return NS_OK; +} + +nsresult +EphyFaviconEventListener::HandleFaviconLink (nsIDOMNode *node) +{ + nsresult result; + + nsCOMPtr<nsIDOMElement> linkElement; + linkElement = do_QueryInterface (node); + if (!linkElement) return NS_ERROR_FAILURE; + + NS_NAMED_LITERAL_STRING(attr_rel, "rel"); + nsAutoString value; + result = linkElement->GetAttribute (attr_rel, value); + if (NS_FAILED(result)) return NS_ERROR_FAILURE; + + if (value.Equals(NS_LITERAL_STRING("SHORTCUT ICON"), + nsCaseInsensitiveStringComparator()) || + value.Equals(NS_LITERAL_STRING("ICON"), + nsCaseInsensitiveStringComparator())) + { + NS_NAMED_LITERAL_STRING(attr_href, "href"); + nsAutoString value; + result = linkElement->GetAttribute (attr_href, value); + if (NS_FAILED (result) || value.IsEmpty()) + return NS_ERROR_FAILURE; + + nsCOMPtr<nsIDOMDocument> domDoc; + result = node->GetOwnerDocument(getter_AddRefs(domDoc)); + if (NS_FAILED(result) || !domDoc) return NS_ERROR_FAILURE; + + nsCOMPtr<nsIDocument> doc = do_QueryInterface (domDoc); + if(!doc) return NS_ERROR_FAILURE; + +#if MOZILLA_SNAPSHOT > 11 + nsIURI *uri; + uri = doc->GetDocumentURL (); + if (uri == NULL) return NS_ERROR_FAILURE; +#else + nsCOMPtr<nsIURI> uri; + result = doc->GetDocumentURL(getter_AddRefs(uri)); + if (NS_FAILED (result)) return NS_ERROR_FAILURE; +#endif + + const nsACString &link = NS_ConvertUCS2toUTF8(value); + nsCAutoString favicon_url; + result = uri->Resolve (link, favicon_url); + if (NS_FAILED (result)) return NS_ERROR_FAILURE; + + char *url = g_strdup (favicon_url.get()); + g_signal_emit_by_name (mOwner, "ge_favicon", url); + g_free (url); + } + + return NS_OK; +} + +NS_IMETHODIMP +EphyFaviconEventListener::HandleEvent(nsIDOMEvent* aDOMEvent) +{ + nsCOMPtr<nsIDOMEventTarget> eventTarget; + + aDOMEvent->GetTarget(getter_AddRefs(eventTarget)); + + nsresult result; + nsCOMPtr<nsIDOMNode> node = do_QueryInterface(eventTarget, &result); + if (NS_FAILED(result) || !node) return NS_ERROR_FAILURE; + + HandleFaviconLink (node); + + return NS_OK; +} + +NS_IMETHODIMP +EphyPopupEventListener::HandleEvent(nsIDOMEvent* aDOMEvent) +{ + nsresult rv; + + nsCOMPtr<nsIDOMPopupBlockedEvent> popupEvent = + do_QueryInterface(aDOMEvent, &rv); + + if (NS_FAILED(rv)) return NS_ERROR_FAILURE; + + if (popupEvent) + { + g_signal_emit_by_name (mOwner, "ge_popup_blocked"); + } + + return NS_OK; +} + EphyBrowser::EphyBrowser () { - mEventListener = nsnull; + mFaviconEventListener = nsnull; + mPopupEventListener = nsnull; mEventReceiver = nsnull; } @@ -101,9 +217,13 @@ nsresult EphyBrowser::Init (GtkMozEmbed *mozembed) rv = mDOMWindow->GetDocument (getter_AddRefs (domDocument)); if (NS_FAILED (rv)) return NS_ERROR_FAILURE; - mEventListener = new EphyEventListener(); + mFaviconEventListener = new EphyFaviconEventListener(); + mPopupEventListener = new EphyPopupEventListener(); + + rv = mFaviconEventListener->Init (EPHY_EMBED (mozembed)); + if (NS_FAILED (rv)) return NS_ERROR_FAILURE; - rv = mEventListener->Init (EPHY_EMBED (mozembed)); + rv = mPopupEventListener->Init (EPHY_EMBED (mozembed)); if (NS_FAILED (rv)) return NS_ERROR_FAILURE; rv = GetListener(); @@ -138,25 +258,37 @@ EphyBrowser::GetListener (void) nsresult EphyBrowser::AttachListeners(void) { + nsresult rv; + if (!mEventReceiver) return NS_ERROR_FAILURE; nsCOMPtr<nsIDOMEventTarget> target; target = do_QueryInterface (mEventReceiver); - return target->AddEventListener(NS_LITERAL_STRING("DOMLinkAdded"), - mEventListener, PR_FALSE); + rv = target->AddEventListener(NS_LITERAL_STRING("DOMLinkAdded"), + mFaviconEventListener, PR_FALSE); + if (NS_FAILED (rv)) return NS_ERROR_FAILURE; + + return target->AddEventListener(NS_LITERAL_STRING("DOMPopupBlocked"), + mPopupEventListener, PR_FALSE); } nsresult EphyBrowser::DetachListeners(void) { + nsresult rv; + if (!mEventReceiver) return NS_ERROR_FAILURE; nsCOMPtr<nsIDOMEventTarget> target; target = do_QueryInterface (mEventReceiver); - return target->RemoveEventListener(NS_LITERAL_STRING("DOMLinkAdded"), - mEventListener, PR_FALSE); + rv = target->RemoveEventListener(NS_LITERAL_STRING("DOMLinkAdded"), + mFaviconEventListener, PR_FALSE); + if (NS_FAILED (rv)) return NS_ERROR_FAILURE; + + return target->RemoveEventListener(NS_LITERAL_STRING("DOMPopupBlocked"), + mPopupEventListener, PR_FALSE); } nsresult EphyBrowser::Print (nsIPrintSettings *options, PRBool preview) diff --git a/embed/mozilla/EphyBrowser.h b/embed/mozilla/EphyBrowser.h index b2de36ff2..e5ed2e5f5 100644 --- a/embed/mozilla/EphyBrowser.h +++ b/embed/mozilla/EphyBrowser.h @@ -22,7 +22,9 @@ #define EPHY_BROWSER_H #include "ephy-encodings.h" +#include "ephy-embed.h" +#include "nsIDOMEventListener.h" #include "nsIDocShell.h" #include "nsIWebNavigation.h" #include "nsIWebPageDescriptor.h" @@ -38,7 +40,38 @@ #include "nsIPrintSettings.h" -class EphyEventListener; +class EphyEventListener : public nsIDOMEventListener +{ +public: + EphyEventListener(); + virtual ~EphyEventListener(); + + nsresult Init(EphyEmbed *aOwner); + + NS_DECL_ISUPPORTS + + // nsIDOMEventListener + + NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) = 0; + +protected: + EphyEmbed *mOwner; +}; + +class EphyFaviconEventListener : public EphyEventListener +{ +public: + NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent); + +private: + nsresult HandleFaviconLink (nsIDOMNode *node); +}; + +class EphyPopupEventListener : public EphyEventListener +{ +public: + NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent); +}; class EphyBrowser { @@ -93,7 +126,8 @@ private: nsCOMPtr<nsIWebProgressListener> mProgress; nsCOMPtr<nsIDOMEventReceiver> mEventReceiver; nsCOMPtr<nsIDOMWindow> mDOMWindow; - EphyEventListener *mEventListener; + EphyFaviconEventListener *mFaviconEventListener; + EphyPopupEventListener *mPopupEventListener; nsresult GetListener (void); nsresult AttachListeners (void); diff --git a/embed/mozilla/EphyEventListener.cpp b/embed/mozilla/EphyEventListener.cpp deleted file mode 100644 index aab2988fe..000000000 --- a/embed/mozilla/EphyEventListener.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (C) 2000 Marco Pesenti Gritti - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, 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 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. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <nsCOMPtr.h> - -#include "EphyEventListener.h" -#include "nsIDOMNode.h" -#include "nsIDOMElement.h" -#include "nsString.h" -#include "nsUnicharUtils.h" -#include "nsIDOMDocument.h" -#include "nsIURI.h" -#include "nsIDocument.h" -#include "nsIDOMEventTarget.h" -#include "nsIDOMEvent.h" - -EphyEventListener::EphyEventListener(void) -{ - mOwner = nsnull; -} - -EphyEventListener::~EphyEventListener() -{ -} - -NS_IMPL_ISUPPORTS1(EphyEventListener, nsIDOMEventListener) - -nsresult -EphyEventListener::Init(EphyEmbed *aOwner) -{ - mOwner = aOwner; - return NS_OK; -} - -nsresult -EphyEventListener::HandleFaviconLink (nsIDOMNode *node) -{ - nsresult result; - - nsCOMPtr<nsIDOMElement> linkElement; - linkElement = do_QueryInterface (node); - if (!linkElement) return NS_ERROR_FAILURE; - - NS_NAMED_LITERAL_STRING(attr_rel, "rel"); - nsAutoString value; - result = linkElement->GetAttribute (attr_rel, value); - if (NS_FAILED(result)) return NS_ERROR_FAILURE; - - if (value.Equals(NS_LITERAL_STRING("SHORTCUT ICON"), - nsCaseInsensitiveStringComparator()) || - value.Equals(NS_LITERAL_STRING("ICON"), - nsCaseInsensitiveStringComparator())) - { - NS_NAMED_LITERAL_STRING(attr_href, "href"); - nsAutoString value; - result = linkElement->GetAttribute (attr_href, value); - if (NS_FAILED (result) || value.IsEmpty()) - return NS_ERROR_FAILURE; - - nsCOMPtr<nsIDOMDocument> domDoc; - result = node->GetOwnerDocument(getter_AddRefs(domDoc)); - if (NS_FAILED(result) || !domDoc) return NS_ERROR_FAILURE; - - nsCOMPtr<nsIDocument> doc = do_QueryInterface (domDoc); - if(!doc) return NS_ERROR_FAILURE; - -#if MOZILLA_SNAPSHOT > 11 - nsIURI *uri; - uri = doc->GetDocumentURL (); - if (uri == NULL) return NS_ERROR_FAILURE; -#else - nsCOMPtr<nsIURI> uri; - result = doc->GetDocumentURL(getter_AddRefs(uri)); - if (NS_FAILED (result)) return NS_ERROR_FAILURE; -#endif - - const nsACString &link = NS_ConvertUCS2toUTF8(value); - nsCAutoString favicon_url; - result = uri->Resolve (link, favicon_url); - if (NS_FAILED (result)) return NS_ERROR_FAILURE; - - char *url = g_strdup (favicon_url.get()); - g_signal_emit_by_name (mOwner, "ge_favicon", url); - g_free (url); - } - - return NS_OK; -} - -NS_IMETHODIMP -EphyEventListener::HandleEvent(nsIDOMEvent* aDOMEvent) -{ - nsCOMPtr<nsIDOMEventTarget> eventTarget; - - aDOMEvent->GetTarget(getter_AddRefs(eventTarget)); - - nsresult result; - nsCOMPtr<nsIDOMNode> node = do_QueryInterface(eventTarget, &result); - if (NS_FAILED(result) || !node) return NS_ERROR_FAILURE; - - HandleFaviconLink (node); - - return NS_OK; -} diff --git a/embed/mozilla/EphyEventListener.h b/embed/mozilla/EphyEventListener.h deleted file mode 100644 index 32f84e904..000000000 --- a/embed/mozilla/EphyEventListener.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2000 Marco Pesenti Gritti - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, 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 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. - */ - -#ifndef EPHY_EVENT_LISTENER_H -#define EPHY_EVENT_LISTENER_H - -#include "ephy-embed.h" - -#include <nsIDOMEventListener.h> - -class EphyEventListener : public nsIDOMEventListener -{ -public: - EphyEventListener(); - virtual ~EphyEventListener(); - - nsresult Init(EphyEmbed *aOwner); - - NS_DECL_ISUPPORTS - - // nsIDOMEventListener - - NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent); - -private: - EphyEmbed *mOwner; - - nsresult HandleFaviconLink (nsIDOMNode *node); -}; - -#endif diff --git a/embed/mozilla/Makefile.am b/embed/mozilla/Makefile.am index b7646a05d..25d63176d 100644 --- a/embed/mozilla/Makefile.am +++ b/embed/mozilla/Makefile.am @@ -53,8 +53,6 @@ libephymozillaembed_la_SOURCES = \ EphyAboutRedirector.h \ EphyContentPolicy.cpp \ EphyContentPolicy.h \ - EphyEventListener.cpp \ - EphyEventListener.h \ EphyHeaderSniffer.cpp \ EphyHeaderSniffer.h \ EphyBrowser.cpp \ diff --git a/src/Makefile.am b/src/Makefile.am index 92558f383..38c4a7c68 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -68,7 +68,6 @@ NOINST_H_FILES = \ popup-commands.h \ prefs-dialog.h \ ppview-toolbar.h \ - statusbar.h \ toolbar.h \ window-commands.h @@ -78,7 +77,8 @@ INST_H_FILES = \ ephy-session.h \ ephy-shell.h \ ephy-tab.h \ - ephy-window.h + ephy-window.h \ + statusbar.h libephymain_la_SOURCES = \ $(CORBA_SOURCE) \ diff --git a/src/ephy-window.c b/src/ephy-window.c index 5ab1177f0..4bbd59014 100644 --- a/src/ephy-window.c +++ b/src/ephy-window.c @@ -1719,6 +1719,14 @@ ephy_window_get_notebook (EphyWindow *window) return GTK_WIDGET (window->priv->notebook); } +GtkWidget * +ephy_window_get_statusbar (EphyWindow *window) +{ + g_return_val_if_fail (EPHY_IS_WINDOW (window), NULL); + + return GTK_WIDGET (window->priv->statusbar); +} + void ephy_window_add_tab (EphyWindow *window, EphyTab *tab, diff --git a/src/ephy-window.h b/src/ephy-window.h index e7fbf1ca5..6c0245aab 100644 --- a/src/ephy-window.h +++ b/src/ephy-window.h @@ -80,6 +80,8 @@ void ephy_window_set_print_preview (EphyWindow *window, GtkWidget *ephy_window_get_notebook (EphyWindow *window); +GtkWidget *ephy_window_get_statusbar (EphyWindow *window); + void ephy_window_add_tab (EphyWindow *window, EphyTab *tab, gint position, |