aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog17
-rw-r--r--data/epiphany.schemas.in2
-rw-r--r--embed/ephy-embed-shell.c83
-rw-r--r--embed/ephy-embed-shell.h26
-rw-r--r--embed/mozilla/ContentHandler.cpp8
5 files changed, 126 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index d0451288b..2f666708f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,22 @@
2003-11-06 Marco Pesenti Gritti <marco@gnome.org>
+ * data/epiphany.schemas.in:
+
+ Correct download dir default.
+
+ * embed/ephy-embed-shell.h:
+ * embed/ephy-embed-shell.c: (ephy_embed_shell_init),
+ (ephy_embed_shell_finalize), (ephy_embed_shell_get_encodings),
+ (load_mime_from_xml), (ephy_embed_shell_check_mime):
+
+ Add check_mime api for permissions.
+
+ * embed/mozilla/ContentHandler.cpp:
+
+ First incomplete try at using it.
+
+2003-11-06 Marco Pesenti Gritti <marco@gnome.org>
+
* data/Makefile.am:
* data/check-mime.py:
* data/mime-types-permissions.xml:
diff --git a/data/epiphany.schemas.in b/data/epiphany.schemas.in
index 21b248bf0..1073289d0 100644
--- a/data/epiphany.schemas.in
+++ b/data/epiphany.schemas.in
@@ -404,7 +404,7 @@
<applyto>/apps/epiphany/directories/download</applyto>
<owner>epiphany</owner>
<type>string</type>
- <default>~</default>
+ <default>Desktop</default>
<locale name="C">
</locale>
</schema>
diff --git a/embed/ephy-embed-shell.c b/embed/ephy-embed-shell.c
index 0a0dbeb04..e338a0c35 100644
--- a/embed/ephy-embed-shell.c
+++ b/embed/ephy-embed-shell.c
@@ -22,6 +22,7 @@
#include "ephy-embed-shell.h"
#include "ephy-marshal.h"
+#include "ephy-file-helpers.h"
#include "ephy-favicon-cache.h"
#include "mozilla-embed-single.h"
#include "downloader-view.h"
@@ -29,6 +30,7 @@
#include "ephy-debug.h"
#include <string.h>
+#include <libxml/xmlreader.h>
#define EPHY_EMBED_SHELL_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_EMBED_SHELL, EphyEmbedShellPrivate))
@@ -39,6 +41,7 @@ struct EphyEmbedShellPrivate
EphyFaviconCache *favicon_cache;
EphyEmbedSingle *embed_single;
EphyEncodings *encodings;
+ GHashTable *mime_table;
};
static void
@@ -112,6 +115,7 @@ ephy_embed_shell_init (EphyEmbedShell *ges)
ges->priv->downloader_view = NULL;
ges->priv->favicon_cache = NULL;
ges->priv->encodings = NULL;
+ ges->priv->mime_table = NULL;
}
static void
@@ -152,6 +156,11 @@ ephy_embed_shell_finalize (GObject *object)
g_object_unref (G_OBJECT (ges->priv->embed_single));
}
+ if (ges->priv->mime_table)
+ {
+ g_hash_table_destroy (ges->priv->mime_table);
+ }
+
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@@ -255,3 +264,77 @@ ephy_embed_shell_get_encodings (EphyEmbedShell *shell)
return G_OBJECT (shell->priv->encodings);
}
+
+static void
+load_mime_from_xml (EphyEmbedShell *shell)
+{
+ xmlTextReaderPtr reader;
+ const char *xml_file;
+ int ret;
+ EphyMimePermission permission = EPHY_MIME_PERMISSION_UNKNOWN;
+
+ xml_file = ephy_file ("mime-types-permissions.xml");
+ g_return_if_fail (xml_file != NULL);
+
+ reader = xmlNewTextReaderFilename (xml_file);
+ g_return_if_fail (reader != NULL);
+
+ ret = xmlTextReaderRead (reader);
+ while (ret == 1)
+ {
+ xmlChar *tag;
+ xmlReaderTypes type;
+
+ tag = xmlTextReaderName (reader);
+ type = xmlTextReaderNodeType (reader);
+
+ if (xmlStrEqual (tag, "safe") && type == XML_READER_TYPE_ELEMENT)
+ {
+ permission = EPHY_MIME_PERMISSION_SAFE;
+ }
+ else if (xmlStrEqual (tag, "unsafe") && type == XML_READER_TYPE_ELEMENT)
+ {
+ permission = EPHY_MIME_PERMISSION_UNSAFE;
+ }
+ else if (xmlStrEqual (tag, "mime-type"))
+ {
+ xmlChar *type;
+
+ type = xmlTextReaderGetAttribute (reader, "type");
+ g_hash_table_insert (shell->priv->mime_table,
+ type, GINT_TO_POINTER (permission));
+ }
+
+ xmlFree (tag);
+
+ ret = xmlTextReaderRead (reader);
+ }
+
+ xmlFreeTextReader (reader);
+}
+
+EphyMimePermission
+ephy_embed_shell_check_mime (EphyEmbedShell *shell, const char *mime_type)
+{
+ EphyMimePermission permission;
+ gpointer tmp;
+
+ if (shell->priv->mime_table == NULL)
+ {
+ shell->priv->mime_table = g_hash_table_new_full
+ (g_str_hash, g_str_equal, xmlFree, NULL);
+ load_mime_from_xml (shell);
+ }
+
+ tmp = g_hash_table_lookup (shell->priv->mime_table, mime_type);
+ if (tmp == NULL)
+ {
+ permission = EPHY_MIME_PERMISSION_UNKNOWN;
+ }
+ else
+ {
+ permission = GPOINTER_TO_INT (tmp);
+ }
+
+ return permission;
+}
diff --git a/embed/ephy-embed-shell.h b/embed/ephy-embed-shell.h
index 610123eb0..6cafdc63c 100644
--- a/embed/ephy-embed-shell.h
+++ b/embed/ephy-embed-shell.h
@@ -42,6 +42,13 @@ typedef struct EphyEmbedShellPrivate EphyEmbedShellPrivate;
extern EphyEmbedShell *embed_shell;
+typedef enum
+{
+ EPHY_MIME_PERMISSION_SAFE = 1,
+ EPHY_MIME_PERMISSION_UNSAFE = 2,
+ EPHY_MIME_PERMISSION_UNKNOWN = 3
+} EphyMimePermission;
+
struct EphyEmbedShell
{
GObject parent;
@@ -57,21 +64,24 @@ struct EphyEmbedShellClass
GObject * (* get_downloader_view) (EphyEmbedShell *shell);
};
-GType ephy_embed_shell_get_type (void);
+GType ephy_embed_shell_get_type (void);
+
+GType ephy_embed_shell_get_impl (void);
-GType ephy_embed_shell_get_impl (void);
+EphyEmbedShell *ephy_embed_shell_new (const char *type);
-EphyEmbedShell *ephy_embed_shell_new (const char *type);
+GObject *ephy_embed_shell_get_favicon_cache (EphyEmbedShell *ges);
-GObject *ephy_embed_shell_get_favicon_cache (EphyEmbedShell *ges);
+EphyHistory *ephy_embed_shell_get_global_history (EphyEmbedShell *shell);
-EphyHistory *ephy_embed_shell_get_global_history (EphyEmbedShell *shell);
+GObject *ephy_embed_shell_get_downloader_view (EphyEmbedShell *shell);
-GObject *ephy_embed_shell_get_downloader_view (EphyEmbedShell *shell);
+GObject *ephy_embed_shell_get_encodings (EphyEmbedShell *shell);
-GObject *ephy_embed_shell_get_encodings (EphyEmbedShell *shell);
+EphyEmbedSingle *ephy_embed_shell_get_embed_single (EphyEmbedShell *shell);
-EphyEmbedSingle *ephy_embed_shell_get_embed_single (EphyEmbedShell *shell);
+EphyMimePermission ephy_embed_shell_check_mime (EphyEmbedShell *shell,
+ const char *mime_type);
G_END_DECLS
diff --git a/embed/mozilla/ContentHandler.cpp b/embed/mozilla/ContentHandler.cpp
index 17c6685c3..742db0319 100644
--- a/embed/mozilla/ContentHandler.cpp
+++ b/embed/mozilla/ContentHandler.cpp
@@ -35,6 +35,7 @@
#include "ephy-prefs.h"
#include "eel-gconf-extensions.h"
+#include "ephy-embed-shell.h"
#include <libgnomevfs/gnome-vfs-mime.h>
#include <libgnomevfs/gnome-vfs-utils.h>
@@ -342,11 +343,16 @@ NS_METHOD GContentHandler::MIMEAskAction (void)
nsresult rv;
gboolean auto_open;
+ /* FIXME can we assume mime is not NULL ? */
+
auto_open = eel_gconf_get_boolean (CONF_AUTO_OPEN_DOWNLOADS);
GContentHandler *mContentHandler = this;
GnomeVFSMimeApplication *DefaultApp = gnome_vfs_mime_get_default_application(mMimeType);
+
+ EphyMimePermission permission;
+ permission = ephy_embed_shell_check_mime (embed_shell, mMimeType);
- if (!auto_open || !DefaultApp)
+ if (!auto_open || !DefaultApp || permission != EPHY_MIME_PERMISSION_SAFE)
{
nsCOMPtr<nsIHelperAppLauncher> launcher;