diff options
author | Adam Hooper <adamh@densi.com> | 2003-12-10 06:23:07 +0800 |
---|---|---|
committer | Marco Pesenti Gritti <marco@src.gnome.org> | 2003-12-10 06:23:07 +0800 |
commit | 1a30aad2cd97319b1b66b14d7c9c2f3b20b05d80 (patch) | |
tree | a1de8c874fadd7e2ef3478de1f8a114554fa90e1 /embed | |
parent | 8a7cfd5a9a6a2fe10c78199dd1a81c6a13118835 (diff) | |
download | gsoc2013-epiphany-1a30aad2cd97319b1b66b14d7c9c2f3b20b05d80.tar gsoc2013-epiphany-1a30aad2cd97319b1b66b14d7c9c2f3b20b05d80.tar.gz gsoc2013-epiphany-1a30aad2cd97319b1b66b14d7c9c2f3b20b05d80.tar.bz2 gsoc2013-epiphany-1a30aad2cd97319b1b66b14d7c9c2f3b20b05d80.tar.lz gsoc2013-epiphany-1a30aad2cd97319b1b66b14d7c9c2f3b20b05d80.tar.xz gsoc2013-epiphany-1a30aad2cd97319b1b66b14d7c9c2f3b20b05d80.tar.zst gsoc2013-epiphany-1a30aad2cd97319b1b66b14d7c9c2f3b20b05d80.zip |
Move events code inside EphyBrowser.cpp and add an event for blocked
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
Diffstat (limited to 'embed')
-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 |
8 files changed, 187 insertions, 182 deletions
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 \ |