aboutsummaryrefslogtreecommitdiffstats
path: root/embed/ephy-embed-shell.c
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@gnome.org>2003-11-06 18:36:39 +0800
committerMarco Pesenti Gritti <marco@src.gnome.org>2003-11-06 18:36:39 +0800
commit510dc2f81c7d5da00ae321c4f87fe74bc7873e0d (patch)
treedc55cc4838c34ad069a5464271a3cd17621bf3f3 /embed/ephy-embed-shell.c
parent665035daca3b08898e1d838d38c65fbe5f36ff95 (diff)
downloadgsoc2013-epiphany-510dc2f81c7d5da00ae321c4f87fe74bc7873e0d.tar
gsoc2013-epiphany-510dc2f81c7d5da00ae321c4f87fe74bc7873e0d.tar.gz
gsoc2013-epiphany-510dc2f81c7d5da00ae321c4f87fe74bc7873e0d.tar.bz2
gsoc2013-epiphany-510dc2f81c7d5da00ae321c4f87fe74bc7873e0d.tar.lz
gsoc2013-epiphany-510dc2f81c7d5da00ae321c4f87fe74bc7873e0d.tar.xz
gsoc2013-epiphany-510dc2f81c7d5da00ae321c4f87fe74bc7873e0d.tar.zst
gsoc2013-epiphany-510dc2f81c7d5da00ae321c4f87fe74bc7873e0d.zip
Correct download dir default.
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.
Diffstat (limited to 'embed/ephy-embed-shell.c')
-rw-r--r--embed/ephy-embed-shell.c83
1 files changed, 83 insertions, 0 deletions
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;
+}