aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Persch <chpe@cvs.gnome.org>2005-01-01 00:09:40 +0800
committerChristian Persch <chpe@src.gnome.org>2005-01-01 00:09:40 +0800
commit9b8959a4de1dc5eacdf807ae6d311defce4fad51 (patch)
tree88ac3f23c1b1024b3b6d7101bbc6712ebd943e74
parentddf12994065314b103f57969640845d7344974f2 (diff)
downloadgsoc2013-epiphany-9b8959a4de1dc5eacdf807ae6d311defce4fad51.tar.gz
gsoc2013-epiphany-9b8959a4de1dc5eacdf807ae6d311defce4fad51.tar.zst
gsoc2013-epiphany-9b8959a4de1dc5eacdf807ae6d311defce4fad51.zip
Move mime permission checks to ephy-file-helpers.
2004-12-31 Christian Persch <chpe@cvs.gnome.org> * embed/ephy-embed-shell.c: (ephy_embed_shell_finalize), (ephy_embed_shell_get_encodings): * embed/ephy-embed-shell.h: * embed/mozilla/ContentHandler.cpp: * embed/mozilla/ContentHandler.h: * lib/ephy-file-helpers.c: (ephy_file_helpers_shutdown), (ephy_file_delete_on_exit), (load_mime_from_xml), (ephy_file_check_mime): * lib/ephy-file-helpers.h: Move mime permission checks to ephy-file-helpers. * src/popup-commands.c: (image_open_uri), (save_source_completed_cb), (popup_cmd_open_image): Only open the image if its mime type is 'safe'.
-rw-r--r--ChangeLog19
-rw-r--r--embed/ephy-embed-shell.c94
-rw-r--r--embed/ephy-embed-shell.h22
-rw-r--r--embed/mozilla/ContentHandler.cpp5
-rw-r--r--embed/mozilla/ContentHandler.h2
-rw-r--r--lib/ephy-file-helpers.c97
-rw-r--r--lib/ephy-file-helpers.h11
-rw-r--r--src/popup-commands.c20
8 files changed, 152 insertions, 118 deletions
diff --git a/ChangeLog b/ChangeLog
index 17fe517f4..cf6123cc1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,24 @@
2004-12-31 Christian Persch <chpe@cvs.gnome.org>
+ * embed/ephy-embed-shell.c: (ephy_embed_shell_finalize),
+ (ephy_embed_shell_get_encodings):
+ * embed/ephy-embed-shell.h:
+ * embed/mozilla/ContentHandler.cpp:
+ * embed/mozilla/ContentHandler.h:
+ * lib/ephy-file-helpers.c: (ephy_file_helpers_shutdown),
+ (ephy_file_delete_on_exit), (load_mime_from_xml),
+ (ephy_file_check_mime):
+ * lib/ephy-file-helpers.h:
+
+ Move mime permission checks to ephy-file-helpers.
+
+ * src/popup-commands.c: (image_open_uri),
+ (save_source_completed_cb), (popup_cmd_open_image):
+
+ Only open the image if its mime type is 'safe'.
+
+2004-12-31 Christian Persch <chpe@cvs.gnome.org>
+
* src/popup-commands.c: (image_open_uri),
(save_source_completed_cb), (save_temp_source),
(popup_cmd_open_image):
diff --git a/embed/ephy-embed-shell.c b/embed/ephy-embed-shell.c
index 0051be195..4802438a0 100644
--- a/embed/ephy-embed-shell.c
+++ b/embed/ephy-embed-shell.c
@@ -32,19 +32,15 @@
#include "ephy-encodings.h"
#include "ephy-debug.h"
-#include <libxml/xmlreader.h>
-#include <string.h>
-
#define EPHY_EMBED_SHELL_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_EMBED_SHELL, EphyEmbedShellPrivate))
-struct EphyEmbedShellPrivate
+struct _EphyEmbedShellPrivate
{
EphyHistory *global_history;
DownloaderView *downloader_view;
EphyFaviconCache *favicon_cache;
EphyEmbedSingle *embed_single;
EphyEncodings *encodings;
- GHashTable *mime_table;
};
static void ephy_embed_shell_class_init (EphyEmbedShellClass *klass);
@@ -120,12 +116,6 @@ ephy_embed_shell_finalize (GObject *object)
g_object_unref (G_OBJECT (shell->priv->embed_single));
}
- LOG ("Destroying mime type hashtable")
- if (shell->priv->mime_table)
- {
- g_hash_table_destroy (shell->priv->mime_table);
- }
-
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@@ -207,88 +197,6 @@ ephy_embed_shell_get_encodings (EphyEmbedShell *shell)
}
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");
- if (xml_file == NULL)
- {
- g_warning ("MIME types permissions file not found!\n");
- return;
- }
-
- reader = xmlNewTextReaderFilename (xml_file);
- if (reader == NULL)
- {
- g_warning ("Could not load MIME types permissions file!\n");
- return;
- }
-
- ret = xmlTextReaderRead (reader);
- while (ret == 1)
- {
- const xmlChar *tag;
- xmlReaderTypes type;
-
- tag = xmlTextReaderConstName (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));
- }
-
- ret = xmlTextReaderRead (reader);
- }
-
- xmlFreeTextReader (reader);
-}
-
-EphyMimePermission
-ephy_embed_shell_check_mime (EphyEmbedShell *shell, const char *mime_type)
-{
- EphyMimePermission permission;
- gpointer tmp;
-
- g_return_val_if_fail (EPHY_IS_EMBED_SHELL (shell), EPHY_MIME_PERMISSION_UNKNOWN);
-
- 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;
-}
-
-static void
ephy_embed_shell_init (EphyEmbedShell *shell)
{
shell->priv = EPHY_EMBED_SHELL_GET_PRIVATE (shell);
diff --git a/embed/ephy-embed-shell.h b/embed/ephy-embed-shell.h
index cc2febf60..4eb3234a9 100644
--- a/embed/ephy-embed-shell.h
+++ b/embed/ephy-embed-shell.h
@@ -33,20 +33,13 @@ G_BEGIN_DECLS
#define EPHY_IS_EMBED_SHELL_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EPHY_TYPE_EMBED_SHELL))
#define EPHY_EMBED_SHELL_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EPHY_TYPE_EMBED_SHELL, EphyEmbedShellClass))
-typedef struct EphyEmbedShellClass EphyEmbedShellClass;
-typedef struct EphyEmbedShell EphyEmbedShell;
-typedef struct EphyEmbedShellPrivate EphyEmbedShellPrivate;
+typedef struct _EphyEmbedShellClass EphyEmbedShellClass;
+typedef struct _EphyEmbedShell EphyEmbedShell;
+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
+struct _EphyEmbedShell
{
GObject parent;
@@ -54,7 +47,7 @@ struct EphyEmbedShell
EphyEmbedShellPrivate *priv;
};
-struct EphyEmbedShellClass
+struct _EphyEmbedShellClass
{
GObjectClass parent_class;
};
@@ -71,9 +64,6 @@ GObject *ephy_embed_shell_get_encodings (EphyEmbedShell *shell);
GObject *ephy_embed_shell_get_embed_single (EphyEmbedShell *shell);
-EphyMimePermission ephy_embed_shell_check_mime (EphyEmbedShell *shell,
- const char *mime_type);
-
G_END_DECLS
-#endif
+#endif /* !EPHY_EMBED_SHELL_H */
diff --git a/embed/mozilla/ContentHandler.cpp b/embed/mozilla/ContentHandler.cpp
index 14a3438ec..0b7f2f653 100644
--- a/embed/mozilla/ContentHandler.cpp
+++ b/embed/mozilla/ContentHandler.cpp
@@ -49,6 +49,7 @@
#include "ephy-embed-single.h"
#include "ephy-embed-shell.h"
#include "ephy-file-chooser.h"
+#include "ephy-file-helpers.h"
#include "ephy-stock-icons.h"
#include "ephy-gui.h"
#include "ephy-debug.h"
@@ -326,10 +327,10 @@ NS_METHOD GContentHandler::MIMEInitiateAction (void)
#ifdef MOZ_NSIMIMEINFO_NSACSTRING_
mHelperApp = gnome_vfs_mime_get_default_application (mMimeType.get());
- mPermission = ephy_embed_shell_check_mime (embed_shell, mMimeType.get());
+ mPermission = ephy_file_check_mime (mMimeType.get());
#else
mHelperApp = gnome_vfs_mime_get_default_application (mMimeType);
- mPermission = ephy_embed_shell_check_mime (embed_shell, mMimeType);
+ mPermission = ephy_file_check_mime (mMimeType);
#endif
if (auto_downloads)
diff --git a/embed/mozilla/ContentHandler.h b/embed/mozilla/ContentHandler.h
index 9f11bb67a..3401a68cb 100644
--- a/embed/mozilla/ContentHandler.h
+++ b/embed/mozilla/ContentHandler.h
@@ -24,7 +24,7 @@
#include "config.h"
-#include "ephy-embed-shell.h"
+#include "ephy-file-helpers.h"
#include <libgnomevfs/gnome-vfs-mime-handlers.h>
diff --git a/lib/ephy-file-helpers.c b/lib/ephy-file-helpers.c
index fb6e3ac1f..bc11f8e27 100644
--- a/lib/ephy-file-helpers.c
+++ b/lib/ephy-file-helpers.c
@@ -1,5 +1,7 @@
/*
* Copyright (C) 2002 Jorn Baayen
+ * Copyright (C) 2003, 2004 Marco Pesenti Gritti
+ * Copyright (C) 2004 Christian Persch
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -27,12 +29,15 @@
#include <glib.h>
#include <glib/gi18n.h>
#include <libgnome/gnome-init.h>
+#include <libxml/xmlreader.h>
#include "ephy-file-helpers.h"
#include "ephy-prefs.h"
#include "eel-gconf-extensions.h"
+#include "ephy-debug.h"
static GHashTable *files = NULL;
+static GHashTable *mime_table = NULL;
static char *dot_dir = NULL;
static char *tmp_dir = NULL;
@@ -222,6 +227,13 @@ ephy_file_helpers_shutdown (void)
g_list_free (del_on_exit);
del_on_exit = NULL;
+ if (mime_table != NULL)
+ {
+ LOG ("Destroying mime type hashtable")
+ g_hash_table_destroy (mime_table);
+ mime_table = NULL;
+ }
+
if (tmp_dir != NULL)
{
rmdir (tmp_dir);
@@ -349,3 +361,88 @@ ephy_file_delete_on_exit (const char *path)
del_on_exit = g_list_prepend (del_on_exit,
g_strdup (path));
}
+
+static void
+load_mime_from_xml (void)
+{
+ xmlTextReaderPtr reader;
+ const char *xml_file;
+ int ret;
+ EphyMimePermission permission = EPHY_MIME_PERMISSION_UNKNOWN;
+
+ g_return_if_fail (mime_table == NULL);
+
+ mime_table = g_hash_table_new_full (g_str_hash, g_str_equal,
+ xmlFree, NULL);
+
+ xml_file = ephy_file ("mime-types-permissions.xml");
+ if (xml_file == NULL)
+ {
+ g_warning ("MIME types permissions file not found!\n");
+ return;
+ }
+
+ reader = xmlNewTextReaderFilename (xml_file);
+ if (reader == NULL)
+ {
+ g_warning ("Could not load MIME types permissions file!\n");
+ return;
+ }
+
+ ret = xmlTextReaderRead (reader);
+ while (ret == 1)
+ {
+ const xmlChar *tag;
+ xmlReaderTypes type;
+
+ tag = xmlTextReaderConstName (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 (mime_table, type,
+ GINT_TO_POINTER (permission));
+ }
+
+ ret = xmlTextReaderRead (reader);
+ }
+
+ xmlFreeTextReader (reader);
+}
+
+EphyMimePermission
+ephy_file_check_mime (const char *mime_type)
+{
+ EphyMimePermission permission;
+ gpointer tmp;
+
+ g_return_val_if_fail (mime_type != NULL, EPHY_MIME_PERMISSION_UNKNOWN);
+
+ if (mime_table == NULL)
+ {
+ load_mime_from_xml ();
+ }
+
+ tmp = g_hash_table_lookup (mime_table, mime_type);
+ if (tmp == NULL)
+ {
+ permission = EPHY_MIME_PERMISSION_UNKNOWN;
+ }
+ else
+ {
+ permission = GPOINTER_TO_INT (tmp);
+ }
+
+ return permission;
+}
diff --git a/lib/ephy-file-helpers.h b/lib/ephy-file-helpers.h
index 6beb2951a..8b9a99c13 100644
--- a/lib/ephy-file-helpers.h
+++ b/lib/ephy-file-helpers.h
@@ -1,5 +1,7 @@
/*
* Copyright (C) 2002 Jorn Baayen
+ * Copyright (C) 2003, 2004 Marco Pesenti Gritti
+ * Copyright (C) 2004 Christian Persch
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -25,6 +27,13 @@
G_BEGIN_DECLS
+typedef enum
+{
+ EPHY_MIME_PERMISSION_SAFE = 1,
+ EPHY_MIME_PERMISSION_UNSAFE = 2,
+ EPHY_MIME_PERMISSION_UNKNOWN = 3
+} EphyMimePermission;
+
const char *ephy_file (const char *filename);
const char *ephy_dot_dir (void);
@@ -53,6 +62,8 @@ gboolean ephy_file_switch_temp_file (const char *filename,
void ephy_file_delete_on_exit (const char *path);
+EphyMimePermission ephy_file_check_mime (const char *mime_type);
+
G_END_DECLS
#endif /* EPHY_FILE_HELPERS_H */
diff --git a/src/popup-commands.c b/src/popup-commands.c
index fd7805034..4804b3316 100644
--- a/src/popup-commands.c
+++ b/src/popup-commands.c
@@ -365,7 +365,8 @@ popup_cmd_open_frame (GtkAction *action,
}
static void
-image_open_uri (const char *address)
+image_open_uri (const char *address,
+ gboolean delete)
{
GList *uris = NULL;
char *canonical;
@@ -380,7 +381,8 @@ image_open_uri (const char *address)
GNOME_VFS_FILE_INFO_FORCE_SLOW_MIME_TYPE) == GNOME_VFS_OK &&
(info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE) &&
info->mime_type != NULL &&
- info->mime_type[0] != '\0')
+ info->mime_type[0] != '\0' &&
+ ephy_file_check_mime (info->mime_type) == EPHY_MIME_PERMISSION_SAFE)
{
app = gnome_vfs_mime_get_default_application (info->mime_type);
}
@@ -392,12 +394,20 @@ image_open_uri (const char *address)
gnome_vfs_mime_application_launch (app, uris);
gnome_vfs_mime_application_free (app);
g_list_free (uris);
+ if (delete)
+ {
+ ephy_file_delete_on_exit (address);
+ }
}
else
{
/* FIXME We should really warn the user here */
g_warning ("Cannot find an application to open %s with.", address);
+ if (delete)
+ {
+ gnome_vfs_unlink (address);
+ }
}
g_free (canonical);
@@ -412,9 +422,7 @@ save_source_completed_cb (EphyEmbedPersist *persist)
dest = ephy_embed_persist_get_dest (persist);
g_return_if_fail (dest != NULL);
- ephy_file_delete_on_exit (dest);
-
- image_open_uri (dest);
+ image_open_uri (dest, TRUE);
}
static void
@@ -475,7 +483,7 @@ popup_cmd_open_image (GtkAction *action,
if (strcmp (scheme, "file") == 0)
{
- image_open_uri (address);
+ image_open_uri (address, FALSE);
}
else
{