From e464015f47f6d575f5db02d851d7ea4b88278e34 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Thu, 20 Nov 2003 19:12:19 +0000 Subject: Implement an handle_content signal to allow to write plugins to support 2003-11-20 Marco Pesenti Gritti * embed/ephy-embed-single.c: (ephy_embed_single_class_init): * embed/ephy-embed-single.h: * embed/mozilla/ContentHandler.cpp: * embed/mozilla/EphyHeaderSniffer.cpp: * embed/mozilla/EphyHeaderSniffer.h: * lib/ephy-marshal.list: Implement an handle_content signal to allow to write plugins to support external download managers. --- ChangeLog | 12 ++++++++++++ embed/ephy-embed-single.c | 11 +++++++++++ embed/ephy-embed-single.h | 8 ++++++++ embed/mozilla/ContentHandler.cpp | 21 +++++++++++++++------ embed/mozilla/EphyHeaderSniffer.cpp | 20 ++++++++++++++++++++ embed/mozilla/EphyHeaderSniffer.h | 1 + lib/ephy-marshal.list | 1 + 7 files changed, 68 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 77842f7b9..c0a6c13d2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2003-11-20 Marco Pesenti Gritti + + * embed/ephy-embed-single.c: (ephy_embed_single_class_init): + * embed/ephy-embed-single.h: + * embed/mozilla/ContentHandler.cpp: + * embed/mozilla/EphyHeaderSniffer.cpp: + * embed/mozilla/EphyHeaderSniffer.h: + * lib/ephy-marshal.list: + + Implement an handle_content signal to allow to write + plugins to support external download managers. + 2003-11-20 Marco Pesenti Gritti * embed/ephy-command-manager.c: (ephy_command_manager_base_init): diff --git a/embed/ephy-embed-single.c b/embed/ephy-embed-single.c index 359b33069..e5bfd0f65 100644 --- a/embed/ephy-embed-single.c +++ b/embed/ephy-embed-single.c @@ -82,6 +82,17 @@ ephy_embed_single_class_init (EphyEmbedSingleClass *klass) parent_class = (GObjectClass *) g_type_class_peek_parent (klass); + g_signal_new ("handle_content", + EPHY_TYPE_EMBED_SINGLE, + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (EphyEmbedSingleClass, handle_content), + g_signal_accumulator_true_handled, NULL, + ephy_marshal_BOOLEAN__STRING_STRING, + G_TYPE_BOOLEAN, + 2, + G_TYPE_STRING, + G_TYPE_STRING); + g_type_class_add_private (object_class, sizeof(EphyEmbedSinglePrivate)); } diff --git a/embed/ephy-embed-single.h b/embed/ephy-embed-single.h index 0228032af..a30eb4194 100644 --- a/embed/ephy-embed-single.h +++ b/embed/ephy-embed-single.h @@ -90,6 +90,14 @@ struct EphyEmbedSingleClass { GObjectClass parent_class; + /* Signals */ + + gboolean (* handle_content) (EphyEmbedSingle *shell, + char *mime_type, + char *uri); + + /* Methods */ + void (* clear_cache) (EphyEmbedSingle *shell); void (* set_offline_mode) (EphyEmbedSingle *shell, gboolean offline); diff --git a/embed/mozilla/ContentHandler.cpp b/embed/mozilla/ContentHandler.cpp index 8f0267d33..dc4382943 100644 --- a/embed/mozilla/ContentHandler.cpp +++ b/embed/mozilla/ContentHandler.cpp @@ -73,17 +73,26 @@ NS_IMETHODIMP GContentHandler::Show(nsIHelperAppLauncher *aLauncher, nsISupports *aContext) #endif { - /* aForced reflects if the content being sent is normally viewable - * in mozilla or not. That fact doesn't affect us, so ignore it - */ - nsresult rv; + EphyEmbedSingle *single; + gboolean handled = FALSE; mLauncher = aLauncher; rv = Init (); if (NS_FAILED (rv)) return rv; - - MIMEAskAction (); + + single = ephy_embed_shell_get_embed_single (embed_shell); + g_signal_emit_by_name (single, "handle_content", mMimeType, + mUrl.get(), &handled); + + if (!handled) + { + MIMEAskAction (); + } + else + { + mLauncher->Cancel (); + } return NS_OK; } diff --git a/embed/mozilla/EphyHeaderSniffer.cpp b/embed/mozilla/EphyHeaderSniffer.cpp index 0b353112b..a1e621fad 100644 --- a/embed/mozilla/EphyHeaderSniffer.cpp +++ b/embed/mozilla/EphyHeaderSniffer.cpp @@ -91,6 +91,23 @@ EphyHeaderSniffer::~EphyHeaderSniffer() NS_IMPL_ISUPPORTS2(EphyHeaderSniffer, nsIWebProgressListener, nsIAuthPrompt) +NS_IMETHODIMP +EphyHeaderSniffer::HandleContent () +{ + EphyEmbedSingle *single; + gboolean handled = FALSE; + nsCString uriSpec; + + if (mPostData) return NS_ERROR_FAILURE; + + mURL->GetSpec (uriSpec); + single = ephy_embed_shell_get_embed_single (embed_shell); + g_signal_emit_by_name (single, "handle_content", mContentType.get(), + uriSpec.get(), &handled); + + return handled ? NS_OK : NS_ERROR_FAILURE; +} + NS_IMETHODIMP EphyHeaderSniffer::OnStateChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 aStateFlags, PRUint32 aStatus) @@ -126,6 +143,9 @@ EphyHeaderSniffer::OnStateChange (nsIWebProgress *aWebProgress, nsIRequest *aReq mTmpFile->Remove(PR_FALSE); } + rv = HandleContent (); + if (NS_SUCCEEDED (rv)) return NS_OK; + rv = PerformSave(origURI); if (NS_FAILED(rv)) { diff --git a/embed/mozilla/EphyHeaderSniffer.h b/embed/mozilla/EphyHeaderSniffer.h index 8d5d6f0d3..45a3b0f91 100644 --- a/embed/mozilla/EphyHeaderSniffer.h +++ b/embed/mozilla/EphyHeaderSniffer.h @@ -65,6 +65,7 @@ public: protected: nsresult PerformSave (nsIURI* inOriginalURI); + nsresult HandleContent (); private: nsIWebBrowserPersist* mPersist; /* Weak. It owns us as a listener. */ diff --git a/lib/ephy-marshal.list b/lib/ephy-marshal.list index 3c5ffae41..28007f3c7 100644 --- a/lib/ephy-marshal.list +++ b/lib/ephy-marshal.list @@ -1,5 +1,6 @@ INT:STRING BOOLEAN:OBJECT +BOOLEAN:STRING, STRING VOID:INT,INT VOID:POINTER,INT VOID:POINTER,POINTER -- cgit v1.2.3