aboutsummaryrefslogtreecommitdiffstats
path: root/embed/mozilla/EphyBrowser.cpp
diff options
context:
space:
mode:
authorAdam Hooper <adamh@densi.com>2003-12-10 06:23:07 +0800
committerMarco Pesenti Gritti <marco@src.gnome.org>2003-12-10 06:23:07 +0800
commit1a30aad2cd97319b1b66b14d7c9c2f3b20b05d80 (patch)
treea1de8c874fadd7e2ef3478de1f8a114554fa90e1 /embed/mozilla/EphyBrowser.cpp
parent8a7cfd5a9a6a2fe10c78199dd1a81c6a13118835 (diff)
downloadgsoc2013-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/mozilla/EphyBrowser.cpp')
-rw-r--r--embed/mozilla/EphyBrowser.cpp148
1 files changed, 140 insertions, 8 deletions
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)