diff options
Diffstat (limited to 'embed')
-rw-r--r-- | embed/ephy-embed-single.c | 29 | ||||
-rw-r--r-- | embed/ephy-embed-single.h | 19 | ||||
-rw-r--r-- | embed/mozilla/EphyContentPolicy.cpp | 125 | ||||
-rw-r--r-- | embed/mozilla/EphyContentPolicy.h | 2 |
4 files changed, 139 insertions, 36 deletions
diff --git a/embed/ephy-embed-single.c b/embed/ephy-embed-single.c index 012b11795..6f0d06321 100644 --- a/embed/ephy-embed-single.c +++ b/embed/ephy-embed-single.c @@ -21,6 +21,7 @@ #include "config.h" #include "ephy-embed-single.h" +#include "ephy-embed-type-builtins.h" #include "ephy-marshal.h" static void ephy_embed_single_iface_init (gpointer g_class); @@ -116,6 +117,34 @@ ephy_embed_single_iface_init (gpointer g_class) G_TYPE_STRING, G_TYPE_STRING); +/** + * EphyEmbedSingle::check_content: + * @single: + * @type: the type of content + * @address: the address of the content + * @requesting_address: the address of the requesting content (may be empty) + * @mime_type_guess: a guess of the mime type of the content (may be empty) + * @mime_type: the MIME type of the content + * + * The ::check-content signal is emitted when Epiphany loads any content from + * anywhere. + * + * If a connected callback returns %TRUE, the + * signal emission will stop, and the load be aborted. + **/ + g_signal_new ("check_content", + EPHY_TYPE_EMBED_SINGLE, + G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (EphyEmbedSingleIface, check_content), + g_signal_accumulator_true_handled, NULL, + ephy_marshal_BOOLEAN__ENUM_STRING_STRING_STRING, + G_TYPE_BOOLEAN, + 4, + EPHY_TYPE_CONTENT_CHECK_TYPE, + G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE, + G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE, + G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE); + initialised = TRUE; } } diff --git a/embed/ephy-embed-single.h b/embed/ephy-embed-single.h index 7c3850b82..ceb2dcb19 100644 --- a/embed/ephy-embed-single.h +++ b/embed/ephy-embed-single.h @@ -35,6 +35,18 @@ G_BEGIN_DECLS typedef struct _EphyEmbedSingle EphyEmbedSingle; typedef struct _EphyEmbedSingleIface EphyEmbedSingleIface; +typedef enum +{ + EPHY_CONTENT_CHECK_TYPE_OTHER = 1U, + EPHY_CONTENT_CHECK_TYPE_SCRIPT = 2U, /* Indicates an executable script (such as JavaScript) */ + EPHY_CONTENT_CHECK_TYPE_IMAGE = 3U, /* Indicates an image (e.g., IMG elements) */ + EPHY_CONTENT_CHECK_TYPE_STYLESHEET = 4U, /* Indicates a stylesheet (e.g., STYLE elements) */ + EPHY_CONTENT_CHECK_TYPE_OBJECT = 5U, /* Indicates a generic object (plugin-handled content typically falls under this category) */ + EPHY_CONTENT_CHECK_TYPE_DOCUMENT = 6U, /* Indicates a document at the top-level (i.e., in a browser) */ + EPHY_CONTENT_CHECK_TYPE_SUBDOCUMENT = 7U, /* Indicates a document contained within another document (e.g., IFRAMEs, FRAMES, and OBJECTs) */ + EPHY_CONTENT_CHECK_TYPE_REFRESH = 8U /* Indicates a timed refresh */ +} EphyContentCheckType; + struct _EphyEmbedSingleIface { GTypeInterface base_iface; @@ -49,10 +61,15 @@ struct _EphyEmbedSingleIface gboolean offline); - gboolean (* add_sidebar) (EphyEmbedSingle *single, + gboolean (* add_sidebar) (EphyEmbedSingle *single, const char * url, const char * title); + gboolean (* check_content) (EphyEmbedSingle *single, + EphyContentCheckType type, + const char *address, + const char *requesting_address, + const char *mime_type_guess); /* Methods */ GtkWidget * (* open_window) (EphyEmbedSingle *single, diff --git a/embed/mozilla/EphyContentPolicy.cpp b/embed/mozilla/EphyContentPolicy.cpp index 5eb2e5404..98f5f3afd 100644 --- a/embed/mozilla/EphyContentPolicy.cpp +++ b/embed/mozilla/EphyContentPolicy.cpp @@ -25,6 +25,8 @@ #include "EphyContentPolicy.h" +#include "ephy-embed-shell.h" +#include "ephy-embed-single.h" #include "eel-gconf-extensions.h" #include "ephy-debug.h" @@ -49,6 +51,8 @@ EphyContentPolicy::EphyContentPolicy() mSafeProtocols = g_slist_prepend (mSafeProtocols, g_strdup ("https")); mSafeProtocols = g_slist_prepend (mSafeProtocols, g_strdup ("http")); + mEmbedSingle = ephy_embed_shell_get_embed_single (embed_shell); + g_return_if_fail (mEmbedSingle); } EphyContentPolicy::~EphyContentPolicy() @@ -69,33 +73,46 @@ EphyContentPolicy::ShouldLoad(PRUint32 aContentType, nsISupports *aExtra, PRInt16 *aDecision) { - if (!mLocked) - { - *aDecision = nsIContentPolicy::ACCEPT; - return NS_OK; - } + NS_ENSURE_ARG (aContentLocation); - NS_ENSURE_TRUE (aContentLocation, NS_ERROR_FAILURE); + nsEmbedCString contentScheme; + aContentLocation->GetScheme (contentScheme); - nsEmbedCString scheme; - aContentLocation->GetScheme (scheme); + nsEmbedCString contentSpec; + aContentLocation->GetSpec (contentSpec); - nsEmbedCString spec; - aContentLocation->GetSpec (spec); + /* first general lockdown check */ + if (mLocked && + !g_slist_find_custom (mSafeProtocols, contentScheme.get(), (GCompareFunc) strcmp) && + strcmp (contentSpec.get(), "about:blank") != 0) + { + *aDecision = nsIContentPolicy::REJECT_REQUEST; + return NS_OK; + } - LOG ("ShouldLoad type=%d location=%s (scheme %s)", aContentType, spec.get(), scheme.get()) + nsEmbedCString requestingSpec; + if (aRequestingLocation) + { + aRequestingLocation->GetSpec (requestingSpec); + } - *aDecision = nsIContentPolicy::REJECT_REQUEST; + gboolean result = FALSE; + g_signal_emit_by_name (mEmbedSingle, "check-content", + (EphyContentCheckType) aContentType, + contentSpec.get(), + requestingSpec.get(), + nsEmbedCString(aMimeTypeGuess).get(), + &result); - /* Allow the load if the protocol is in safe list, or it's about:blank */ - if (g_slist_find_custom (mSafeProtocols, scheme.get(), (GCompareFunc) strcmp) - || strcmp (spec.get(), "about:blank") == 0) + if (result) + { + *aDecision = nsIContentPolicy::REJECT_REQUEST; + } + else { *aDecision = nsIContentPolicy::ACCEPT; } - LOG ("Decision: %sallowing load", *aDecision >= 0 ? "" : "DIS") - return NS_OK; } @@ -115,33 +132,71 @@ EphyContentPolicy::ShouldProcess(PRUint32 aContentType, #else /* boolean shouldLoad (in PRInt32 contentType, in nsIURI contentLocation, in nsISupports ctxt, in nsIDOMWindow window); */ -NS_IMETHODIMP EphyContentPolicy::ShouldLoad(PRInt32 contentType, - nsIURI *contentLocation, - nsISupports *ctxt, - nsIDOMWindow *window, +NS_IMETHODIMP EphyContentPolicy::ShouldLoad(PRInt32 aContentType, + nsIURI *aContentLocation, + nsISupports *aContext, + nsIDOMWindow *aWindow, PRBool *_retval) { - if (!mLocked) - { - *_retval = PR_TRUE; - return NS_OK; - } + NS_ENSURE_ARG (aContentLocation); - nsEmbedCString scheme; - contentLocation->GetScheme (scheme); + nsEmbedCString contentScheme; + aContentLocation->GetScheme (contentScheme); - nsEmbedCString spec; - contentLocation->GetSpec (spec); + nsEmbedCString contentSpec; + aContentLocation->GetSpec (contentSpec); - *_retval = PR_FALSE; + /* first general lockdown check */ + if (mLocked && + !g_slist_find_custom (mSafeProtocols, contentScheme.get(), (GCompareFunc) strcmp) && + strcmp (contentSpec.get(), "about:blank") != 0) + { + *_retval = PR_FALSE; + return NS_OK; + } - /* Allow the load if the protocol is in safe list, or it's about:blank */ - if (g_slist_find_custom (mSafeProtocols, scheme.get(), (GCompareFunc) strcmp) - || strcmp (spec.get(), "about:blank") == 0) + /* translate to variant-2 types */ + EphyContentCheckType type; + switch (aContentType) { - *_retval = PR_TRUE; + case nsIContentPolicy::SCRIPT: + type = EPHY_CONTENT_CHECK_TYPE_SCRIPT; + break; + case nsIContentPolicy::IMAGE: + type = EPHY_CONTENT_CHECK_TYPE_IMAGE; + break; + case nsIContentPolicy::STYLESHEET: + type = EPHY_CONTENT_CHECK_TYPE_STYLESHEET; + break; + case nsIContentPolicy::OBJECT: + type = EPHY_CONTENT_CHECK_TYPE_OBJECT; + break; + case nsIContentPolicy::SUBDOCUMENT: + type = EPHY_CONTENT_CHECK_TYPE_SUBDOCUMENT; + break; + case nsIContentPolicy::CONTROL_TAG: + type = EPHY_CONTENT_CHECK_TYPE_REFRESH; + break; + case nsIContentPolicy::DOCUMENT: + type = EPHY_CONTENT_CHECK_TYPE_DOCUMENT; + break; + case nsIContentPolicy::OTHER: + case nsIContentPolicy::RAW_URL: + default: + type = EPHY_CONTENT_CHECK_TYPE_OTHER; + break; } + gboolean result = FALSE; + g_signal_emit_by_name (mEmbedSingle, "check-content", + type, + contentSpec.get(), + "", + "", + &result); + + *_retval = !result; + return NS_OK; } diff --git a/embed/mozilla/EphyContentPolicy.h b/embed/mozilla/EphyContentPolicy.h index 5742f84f8..11e0ce9bd 100644 --- a/embed/mozilla/EphyContentPolicy.h +++ b/embed/mozilla/EphyContentPolicy.h @@ -23,6 +23,7 @@ #define EPHY_CONTENT_POLICY_H #include <glib.h> +#include <glib-object.h> #include <nsISupports.h> #include <nsIContentPolicy.h> @@ -47,6 +48,7 @@ public: EphyContentPolicy(); virtual ~EphyContentPolicy(); private: + GObject *mEmbedSingle; gboolean mLocked; GSList *mSafeProtocols; }; |