aboutsummaryrefslogtreecommitdiffstats
path: root/embed
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@src.gnome.org>2004-01-19 08:11:35 +0800
committerMarco Pesenti Gritti <marco@src.gnome.org>2004-01-19 08:11:35 +0800
commitbc344d71c648e9985122fad66b6cab941b32f188 (patch)
tree1ceb0dfd2e6cc725894e03502dfea5282388dbb0 /embed
parent5532d7831fe768cbf8100c84668291dc707ef1fb (diff)
downloadgsoc2013-epiphany-bc344d71c648e9985122fad66b6cab941b32f188.tar
gsoc2013-epiphany-bc344d71c648e9985122fad66b6cab941b32f188.tar.gz
gsoc2013-epiphany-bc344d71c648e9985122fad66b6cab941b32f188.tar.bz2
gsoc2013-epiphany-bc344d71c648e9985122fad66b6cab941b32f188.tar.lz
gsoc2013-epiphany-bc344d71c648e9985122fad66b6cab941b32f188.tar.xz
gsoc2013-epiphany-bc344d71c648e9985122fad66b6cab941b32f188.tar.zst
gsoc2013-epiphany-bc344d71c648e9985122fad66b6cab941b32f188.zip
*** empty log message ***
Diffstat (limited to 'embed')
-rw-r--r--embed/mozilla/ContentHandler.cpp247
-rw-r--r--embed/mozilla/ContentHandler.h29
-rw-r--r--embed/mozilla/MozDownload.cpp29
3 files changed, 152 insertions, 153 deletions
diff --git a/embed/mozilla/ContentHandler.cpp b/embed/mozilla/ContentHandler.cpp
index 2b654a509..02f346bd2 100644
--- a/embed/mozilla/ContentHandler.cpp
+++ b/embed/mozilla/ContentHandler.cpp
@@ -42,6 +42,7 @@
#include "eel-gconf-extensions.h"
#include "ephy-embed-single.h"
#include "ephy-embed-shell.h"
+#include "ephy-file-chooser.h"
#include "ephy-debug.h"
#include <gtk/gtkimage.h>
@@ -76,98 +77,6 @@ GContentHandler::~GContentHandler()
// begin nsIHelperAppLauncher impl
////////////////////////////////////////////////////////////////////////////////
-/* This is copied verbatim from nsDocShell.h in Mozilla, we should keep it synced */
-/* http://lxr.mozilla.org/mozilla/source/docshell/base/nsDocShell.h */
-
-#define MAKE_LOAD_TYPE(type, flags) ((type) | (flags << 16))
-
-enum LoadType {
- LOAD_NORMAL = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_NONE),
- LOAD_NORMAL_REPLACE = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_REPLACE_HISTORY),
- LOAD_HISTORY = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_HISTORY, nsIWebNavigation::LOAD_FLAGS_NONE),
- LOAD_RELOAD_NORMAL = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_RELOAD, nsIWebNavigation::LOAD_FLAGS_NONE),
- LOAD_RELOAD_BYPASS_CACHE = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_RELOAD, nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE),
- LOAD_RELOAD_BYPASS_PROXY = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_RELOAD, nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY),
- LOAD_RELOAD_BYPASS_PROXY_AND_CACHE = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_RELOAD, nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE | nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY),
- LOAD_LINK = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_IS_LINK),
- LOAD_REFRESH = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_IS_REFRESH),
- LOAD_RELOAD_CHARSET_CHANGE = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_RELOAD, nsIWebNavigation::LOAD_FLAGS_CHARSET_CHANGE),
- LOAD_BYPASS_HISTORY = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_BYPASS_HISTORY)
-};
-
-static GtkWidget*
-ch_unrequested_dialog_construct (GtkWindow *parent, const char *title)
-{
- GtkWidget *dialog;
- GtkWidget *hbox, *vbox, *label, *image;
- char *str, *tmp_str, *tmp_title;
-
- dialog = gtk_dialog_new_with_buttons ("",
- GTK_WINDOW (parent),
- GTK_DIALOG_NO_SEPARATOR,
- GTK_STOCK_CANCEL,
- GTK_RESPONSE_CANCEL,
- GTK_STOCK_OK,
- GTK_RESPONSE_OK,
- NULL);
-
- gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
- gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
- gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 14);
-
- hbox = gtk_hbox_new (FALSE, 6);
- gtk_widget_show (hbox);
- gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox,
- TRUE, TRUE, 0);
-
- image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING,
- GTK_ICON_SIZE_DIALOG);
- gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0);
- gtk_widget_show (image);
- gtk_box_pack_start (GTK_BOX (hbox), image, TRUE, TRUE, 0);
-
- vbox = gtk_vbox_new (FALSE, 6);
- gtk_widget_show (vbox);
- gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
-
- label = gtk_label_new (NULL);
- gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
- gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
- tmp_title = g_strconcat ("<b>", title, "</b>", NULL);
- tmp_str = g_strdup_printf (_("An unrequested download (%s) has been started.\n Would you like to continue it and open the file?"),
- tmp_title);
- str = g_strconcat ("<big>", tmp_str, "</big>", NULL);
- gtk_label_set_markup (GTK_LABEL (label), str);
- g_free (tmp_title);
- g_free (tmp_str);
- g_free (str);
- gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
- gtk_widget_show (label);
-
- return dialog;
-}
-
-static void
-ch_unrequested_dialog_cb (GtkWidget *dialog,
- int response_id,
- gpointer user_data)
-{
- switch (response_id)
- {
- case GTK_RESPONSE_OK:
- ((GContentHandler*)user_data)->MIMEAskAction ();
- break;
- case GTK_RESPONSE_CANCEL:
- nsCOMPtr<nsIHelperAppLauncher> launcher;
-
- ((GContentHandler*)user_data)->GetLauncher (getter_AddRefs(launcher));
- launcher->Cancel ();
- break;
- }
-
- gtk_widget_destroy (GTK_WIDGET (dialog));
-}
-
#if MOZILLA_SNAPSHOT > 9
/* void show (in nsIHelperAppLauncher aLauncher, in nsISupports aContext); */
NS_IMETHODIMP GContentHandler::Show(nsIHelperAppLauncher *aLauncher,
@@ -194,21 +103,9 @@ NS_IMETHODIMP GContentHandler::Show(nsIHelperAppLauncher *aLauncher,
PRUint32 eLoadType;
eDocShell->GetLoadType (&eLoadType);
- /* We ask the user what to do if he has not explicitely started the download
- * (LoadType == LOAD_LINK) */
-
- if (eLoadType != LOAD_LINK) {
- GtkWidget *dialog;
- dialog = ch_unrequested_dialog_construct (NULL, mUrl.get());
- g_signal_connect (G_OBJECT (dialog),
- "response",
- G_CALLBACK (ch_unrequested_dialog_cb),
- this);
- gtk_widget_show (dialog);
- }
- else if (!handled)
+ if (!handled)
{
- MIMEAskAction ();
+ MIMEDoAction ();
}
else
{
@@ -228,8 +125,35 @@ NS_IMETHODIMP GContentHandler::PromptForSaveToFile(
const PRUnichar *aSuggestedFileExtension,
nsILocalFile **_retval)
{
- return BuildDownloadPath (NS_ConvertUCS2toUTF8 (aDefaultFile).get(),
- _retval);
+ EphyFileChooser *dialog;
+ gint response;
+ char *filename;
+
+ if (mAction != CONTENT_ACTION_SAVEAS)
+ {
+ return BuildDownloadPath (NS_ConvertUCS2toUTF8 (aDefaultFile).get(),
+ _retval);
+ }
+
+ dialog = ephy_file_chooser_new (_("Save"), NULL,
+ GTK_FILE_CHOOSER_ACTION_SAVE,
+ CONF_STATE_DOWNLOAD_DIR);
+ gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog),
+ NS_ConvertUCS2toUTF8 (aDefaultFile).get());
+ response = gtk_dialog_run (GTK_DIALOG (dialog));
+
+ if (response == EPHY_RESPONSE_SAVE)
+ {
+ filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+ BuildDownloadPath (filename, _retval);
+ g_free (filename);
+
+ return NS_OK;
+ }
+ else
+ {
+ return NS_ERROR_FAILURE;
+ }
}
#if MOZILLA_SNAPSHOT < 10
@@ -432,32 +356,117 @@ NS_METHOD GContentHandler::ProcessMimeInfo (void)
return NS_OK;
}
-NS_METHOD GContentHandler::MIMEAskAction (void)
+NS_METHOD GContentHandler::MIMEConfirmAction ()
+{
+ GtkWidget *dialog;
+ GtkWidget *hbox, *vbox, *label, *image;
+ char *text;
+ int response;
+
+ dialog = gtk_dialog_new_with_buttons
+ ("", NULL, GTK_DIALOG_NO_SEPARATOR,
+ _("Save As..."), CONTENT_ACTION_SAVEAS,
+ GTK_STOCK_CANCEL, CONTENT_ACTION_NONE,
+ _("Open"), CONTENT_ACTION_OPEN,
+ NULL);
+
+ gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
+ gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
+ gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 14);
+
+ hbox = gtk_hbox_new (FALSE, 6);
+ gtk_widget_show (hbox);
+ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox,
+ TRUE, TRUE, 0);
+
+ if (mPermission != EPHY_MIME_PERMISSION_SAFE)
+ {
+ text = g_strdup_printf ("<span weight=\"bold\" size=\"larger\">%s</span>\n\n%s",
+ _("Do you really want to download the file?"),
+ _("This type of file could potentially damage your documents"
+ "or invade your privacy."
+ "It's not safe to open it directly. You"
+ "can save it instead."));
+ }
+ if (mAction == CONTENT_ACTION_OPEN)
+ {
+ text = g_strdup_printf ("<span weight=\"bold\" size=\"larger\">%s</span>\n\n%s",
+ _("Open the file in another application?"),
+ _("It's not possible to view this file type directly "
+ "in the browser. You can open it with another "
+ "application or save it."));
+ }
+ else
+ {
+ text = g_strdup_printf ("<span weight=\"bold\" size=\"larger\">%s</span>\n\n%s",
+ _("Download the file?"),
+ _("It's not possible to view this file because there is no"
+ "application installed that can open it."
+ "You can save it instead."));
+ }
+
+ image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING,
+ GTK_ICON_SIZE_DIALOG);
+ gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0);
+ gtk_widget_show (image);
+ gtk_box_pack_start (GTK_BOX (hbox), image, TRUE, TRUE, 0);
+
+ vbox = gtk_vbox_new (FALSE, 6);
+ gtk_widget_show (vbox);
+ gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
+
+ label = gtk_label_new (NULL);
+ gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
+ gtk_label_set_markup (GTK_LABEL (label), text);
+ g_free (text);
+
+ gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
+ gtk_widget_show (label);
+
+ mAction = (ContentAction) gtk_dialog_run (GTK_DIALOG (dialog));
+
+ gtk_widget_destroy (dialog);
+
+ return NS_OK;
+}
+
+NS_METHOD GContentHandler::MIMEDoAction (void)
{
nsresult rv;
- gboolean auto_open;
+ gboolean auto_downloads;
+
+ if (eel_gconf_get_boolean (CONF_LOCKDOWN_DISABLE_SAVE_TO_DISK)) return NS_OK;
- auto_open = eel_gconf_get_boolean (CONF_AUTO_OPEN_DOWNLOADS);
+ auto_downloads = eel_gconf_get_boolean (CONF_AUTO_DOWNLOADS);
GnomeVFSMimeApplication *DefaultApp = gnome_vfs_mime_get_default_application(mMimeType);
- EphyMimePermission permission;
- permission = ephy_embed_shell_check_mime (embed_shell, mMimeType);
-
- if (!auto_open || !DefaultApp || permission != EPHY_MIME_PERMISSION_SAFE)
+ mPermission = ephy_embed_shell_check_mime (embed_shell, mMimeType);
+
+ mAction = CONTENT_ACTION_OPEN;
+
+ if (mPermission != EPHY_MIME_PERMISSION_SAFE)
{
- if (eel_gconf_get_boolean (CONF_LOCKDOWN_DISABLE_SAVE_TO_DISK)) return NS_OK;
+ mAction = CONTENT_ACTION_DOWNLOAD;
+ }
+ if (!auto_downloads)
+ {
+ MIMEConfirmAction ();
+ }
+
+ if (mAction == CONTENT_ACTION_DOWNLOAD ||
+ mAction == CONTENT_ACTION_SAVEAS)
+ {
nsCOMPtr<nsIHelperAppLauncher> launcher;
GetLauncher (getter_AddRefs(launcher));
NS_ENSURE_TRUE (launcher, NS_ERROR_FAILURE);
-
launcher->SaveToDisk (nsnull,PR_FALSE);
}
- else
+ else if (mAction == CONTENT_ACTION_OPEN)
{
rv = SetHelperApp (DefaultApp, FALSE);
NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE);
-
rv = FindHelperApp ();
NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE);
}
diff --git a/embed/mozilla/ContentHandler.h b/embed/mozilla/ContentHandler.h
index 6234ca584..d07bea0f7 100644
--- a/embed/mozilla/ContentHandler.h
+++ b/embed/mozilla/ContentHandler.h
@@ -40,6 +40,14 @@
#include "nsISupports.h"
#include "nsError.h"
+typedef enum
+{
+ CONTENT_ACTION_OPEN,
+ CONTENT_ACTION_DOWNLOAD,
+ CONTENT_ACTION_SAVEAS,
+ CONTENT_ACTION_NONE
+} ContentAction;
+
#define G_CONTENTHANDLER_CID \
{ /* 16072c4a-23a6-4996-9beb-9335c06bbeae */ \
0x16072c4a, \
@@ -59,18 +67,19 @@ class GContentHandler : public nsIHelperAppLauncherDialog
GContentHandler();
virtual ~GContentHandler();
- NS_METHOD FindHelperApp (void);
- NS_METHOD LaunchHelperApp (void);
+ private:
+
+ NS_METHOD Init ();
+ NS_METHOD ProcessMimeInfo ();
+ NS_METHOD FindHelperApp ();
+ NS_METHOD LaunchHelperApp ();
NS_METHOD GetLauncher (nsIHelperAppLauncher * *_retval);
NS_METHOD SetHelperApp(GnomeVFSMimeApplication *mHelperApp,
PRBool alwaysUse);
- NS_METHOD SynchroniseMIMEInfo (void);
- NS_METHOD MIMEAskAction (void);
- private:
- /* additional members */
- NS_METHOD Init (void);
- NS_METHOD ProcessMimeInfo (void);
+ NS_METHOD SynchroniseMIMEInfo ();
+ NS_METHOD MIMEConfirmAction ();
+ NS_METHOD MIMEDoAction ();
nsCOMPtr<nsIHelperAppLauncher> mLauncher;
@@ -80,7 +89,9 @@ class GContentHandler : public nsIHelperAppLauncherDialog
char *mMimeType;
PRBool mUrlHelper;
GnomeVFSMimeApplication *mHelperApp;
-
+ ContentAction mAction;
+ EphyMimePermission mPermission;
+
nsCString mUrl;
nsCString mScheme;
};
diff --git a/embed/mozilla/MozDownload.cpp b/embed/mozilla/MozDownload.cpp
index 31847a3e1..53205702a 100644
--- a/embed/mozilla/MozDownload.cpp
+++ b/embed/mozilla/MozDownload.cpp
@@ -491,7 +491,7 @@ nsresult InitiateMozillaDownload (nsIDOMDocument *domDocument, nsIURI *sourceURI
static char*
GetFilePath (const char *filename)
{
- char *path, *download_dir;
+ char *path, *download_dir, *expanded;
download_dir = eel_gconf_get_string (CONF_STATE_DOWNLOAD_DIR);
if (!download_dir)
@@ -500,31 +500,10 @@ GetFilePath (const char *filename)
download_dir = g_strdup (g_get_home_dir ());
}
- if (!strcmp (download_dir, "Desktop"))
- {
- if (eel_gconf_get_boolean (CONF_DESKTOP_IS_HOME_DIR))
- {
- path = g_build_filename
- (g_get_home_dir (),
- filename,
- NULL);
- }
- else
- {
- path = g_build_filename
- (g_get_home_dir (), "Desktop",
- filename,
- NULL);
- }
- }
- else
- {
- char *expanded;
+ expanded = gnome_vfs_expand_initial_tilde (download_dir);
+ path = g_build_filename (expanded, filename, NULL);
+ g_free (expanded);
- expanded = gnome_vfs_expand_initial_tilde (download_dir);
- path = g_build_filename (expanded, filename, NULL);
- g_free (expanded);
- }
g_free (download_dir);
return path;