aboutsummaryrefslogtreecommitdiffstats
path: root/embed
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@gnome.org>2004-01-19 22:06:41 +0800
committerMarco Pesenti Gritti <marco@src.gnome.org>2004-01-19 22:06:41 +0800
commitdd0b02c40b5d202794d03299f2d190833b63bb22 (patch)
tree4e8dc109ed36ca01584e1a7d39d5649cc6adbd6e /embed
parenteaba78e8dfd1cdad90bed57cc536cbfe40a9509e (diff)
downloadgsoc2013-epiphany-dd0b02c40b5d202794d03299f2d190833b63bb22.tar
gsoc2013-epiphany-dd0b02c40b5d202794d03299f2d190833b63bb22.tar.gz
gsoc2013-epiphany-dd0b02c40b5d202794d03299f2d190833b63bb22.tar.bz2
gsoc2013-epiphany-dd0b02c40b5d202794d03299f2d190833b63bb22.tar.lz
gsoc2013-epiphany-dd0b02c40b5d202794d03299f2d190833b63bb22.tar.xz
gsoc2013-epiphany-dd0b02c40b5d202794d03299f2d190833b63bb22.tar.zst
gsoc2013-epiphany-dd0b02c40b5d202794d03299f2d190833b63bb22.zip
Add a way to store paths.
2004-01-19 Marco Pesenti Gritti <marco@gnome.org> * lib/eel-gconf-extensions.c: (tilde_compress), (eel_gconf_set_path): * lib/eel-gconf-extensions.h: Add a way to store paths. * embed/mozilla/ContentHandler.cpp: * embed/mozilla/ContentHandler.h: * embed/mozilla/MozDownload.cpp: * embed/mozilla/MozDownload.h: Actually save the file in downloads dir and then open it. It doesnt seem to open it but it's prolly a gnome-vfs bug. * src/prefs-dialog.c: (get_download_button_label), (download_path_response_cb): Simplify the label logic using ~.
Diffstat (limited to 'embed')
-rw-r--r--embed/mozilla/ContentHandler.cpp225
-rw-r--r--embed/mozilla/ContentHandler.h11
-rw-r--r--embed/mozilla/MozDownload.cpp40
-rw-r--r--embed/mozilla/MozDownload.h2
4 files changed, 104 insertions, 174 deletions
diff --git a/embed/mozilla/ContentHandler.cpp b/embed/mozilla/ContentHandler.cpp
index 02f346bd2..d4c1dc4f9 100644
--- a/embed/mozilla/ContentHandler.cpp
+++ b/embed/mozilla/ContentHandler.cpp
@@ -35,7 +35,6 @@
#include "nsILocalFile.h"
#include "nsIMIMEInfo.h"
-#include "nsIDocShell.h"
#include "nsIWebNavigation.h" // Needed to create the LoadType flag
#include "ephy-prefs.h"
@@ -59,8 +58,7 @@ class GContentHandler;
NS_IMPL_ISUPPORTS1(GContentHandler, nsIHelperAppLauncherDialog)
-GContentHandler::GContentHandler() : mMimeType(nsnull),
- mUrlHelper(PR_FALSE)
+GContentHandler::GContentHandler() : mMimeType(nsnull)
{
LOG ("GContentHandler ctor")
}
@@ -98,10 +96,6 @@ NS_IMETHODIMP GContentHandler::Show(nsIHelperAppLauncher *aLauncher,
single = EPHY_EMBED_SINGLE (ephy_embed_shell_get_embed_single (embed_shell));
g_signal_emit_by_name (single, "handle_content", mMimeType,
mUrl.get(), &handled);
-
- nsCOMPtr<nsIDocShell> eDocShell = do_QueryInterface(aContext);
- PRUint32 eLoadType;
- eDocShell->GetLoadType (&eLoadType);
if (!handled)
{
@@ -165,136 +159,51 @@ NS_METHOD GContentHandler::ShowProgressDialog(nsIHelperAppLauncher *aLauncher,
}
#endif
-NS_METHOD GContentHandler::FindHelperApp (void)
-{
- if (mUrlHelper)
- {
- return LaunchHelperApp ();
- }
-
- nsresult rv;
- rv = SynchroniseMIMEInfo();
- if (NS_FAILED (rv)) return NS_ERROR_FAILURE;
-
- return mLauncher->LaunchWithApplication (nsnull, PR_FALSE);
-}
-
NS_METHOD GContentHandler::LaunchHelperApp (void)
{
- if (mMimeType)
- {
- nsresult rv;
- nsCOMPtr<nsIExternalHelperAppService> helperService =
- do_GetService (NS_EXTERNALHELPERAPPSERVICE_CONTRACTID);
- NS_ENSURE_TRUE (helperService, NS_ERROR_FAILURE);
-
- nsCOMPtr<nsPIExternalAppLauncher> appLauncher =
- do_QueryInterface (helperService);
- if (appLauncher)
- {
- appLauncher->DeleteTemporaryFileOnExit(mTempFile);
- }
+ nsresult rv;
+ nsCOMPtr<nsIExternalHelperAppService> helperService;
- nsString uFileName;
- mTempFile->GetPath(uFileName);
- const nsCString &aFileName = NS_ConvertUCS2toUTF8(uFileName);
+ helperService = do_GetService (NS_EXTERNALHELPERAPPSERVICE_CONTRACTID);
+ NS_ENSURE_TRUE (helperService, NS_ERROR_FAILURE);
- const nsCString &document = (mUrlHelper) ? mUrl : aFileName;
+ nsCOMPtr<nsPIExternalAppLauncher> appLauncher = do_QueryInterface (helperService);
+ NS_ENSURE_TRUE (appLauncher, NS_ERROR_FAILURE);
+ appLauncher->DeleteTemporaryFileOnExit(mTempFile);
- char *param = g_strdup (document.get());
- GList *params = NULL;
- params = g_list_append (params, param);
- gnome_vfs_mime_application_launch (mHelperApp, params);
- g_free (param);
- g_list_free (params);
+ char *param = g_strdup (mUrl.get());
+ GList *params = NULL;
+ params = g_list_append (params, param);
+ gnome_vfs_mime_application_launch (mHelperApp, params);
+ g_free (param);
+ g_list_free (params);
- if (mUrlHelper)
- {
- mLauncher->Cancel();
- }
- }
- else
- {
- mLauncher->Cancel ();
- }
+ mLauncher->Cancel();
return NS_OK;
}
-NS_METHOD GContentHandler::GetLauncher (nsIHelperAppLauncher * *_retval)
-{
- NS_IF_ADDREF (*_retval = mLauncher);
- return NS_OK;
-}
-
-static gboolean
-application_support_scheme (GnomeVFSMimeApplication *app, const nsCString &aScheme)
+NS_METHOD GContentHandler::CheckAppSupportScheme (void)
{
GList *l;
- g_return_val_if_fail (app != NULL, FALSE);
- g_return_val_if_fail (!aScheme.IsEmpty(), FALSE);
-
- if (app->expects_uris != GNOME_VFS_MIME_APPLICATION_ARGUMENT_TYPE_URIS)
- return FALSE;
+ mAppSupportScheme = PR_FALSE;
+
+ if (!mHelperApp) return NS_OK;
+
+ if (mHelperApp->expects_uris != GNOME_VFS_MIME_APPLICATION_ARGUMENT_TYPE_URIS)
+ return NS_OK;
- for (l = app->supported_uri_schemes; l != NULL; l = l->next)
+ for (l = mHelperApp->supported_uri_schemes; l != NULL; l = l->next)
{
char *uri_scheme = (char *)l->data;
- g_return_val_if_fail (uri_scheme != NULL, FALSE);
- if (aScheme.Equals (uri_scheme)) return TRUE;
- }
-
- return FALSE;
-}
-
-NS_METHOD GContentHandler::SetHelperApp(GnomeVFSMimeApplication *aHelperApp,
- PRBool alwaysUse)
-{
- mHelperApp = aHelperApp;
- mUrlHelper = application_support_scheme (aHelperApp, mScheme);
-
- return NS_OK;
-}
-
-NS_METHOD GContentHandler::SynchroniseMIMEInfo (void)
-{
- nsresult rv;
- char *command_with_path;
-
- NS_ENSURE_TRUE (mLauncher, NS_ERROR_FAILURE);
- nsCOMPtr<nsIMIMEInfo> mimeInfo;
- mLauncher->GetMIMEInfo(getter_AddRefs(mimeInfo));
- NS_ENSURE_TRUE (mimeInfo, NS_ERROR_FAILURE);
-
- command_with_path = g_find_program_in_path (mHelperApp->command);
- if (command_with_path == NULL) return NS_ERROR_FAILURE;
-
- nsCOMPtr<nsILocalFile> helperFile;
- NS_NewNativeLocalFile (nsDependentCString(command_with_path),
- PR_TRUE,
- getter_AddRefs(helperFile));
- NS_ENSURE_TRUE (helperFile, NS_ERROR_FAILURE);
-
- g_free (command_with_path);
-
- rv = mimeInfo->SetPreferredApplicationHandler(helperFile);
- NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE);
-
- nsMIMEInfoHandleAction mimeInfoAction;
- mimeInfoAction = nsIMIMEInfo::useHelperApp;
-
- if(mHelperApp->requires_terminal) //Information passing kludge!
- {
- rv = mimeInfo->SetApplicationDescription
- (NS_LITERAL_STRING("runInTerminal").get());
- NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE);
+ if (mScheme.Equals (uri_scheme))
+ {
+ mAppSupportScheme = PR_TRUE;
+ }
}
- rv = mimeInfo->SetPreferredAction(mimeInfoAction);
- NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE);
-
return NS_OK;
}
@@ -325,34 +234,6 @@ NS_METHOD GContentHandler::Init (void)
rv = mUri->GetSpec (mUrl);
rv = mUri->GetScheme (mScheme);
- ProcessMimeInfo ();
-
- return NS_OK;
-}
-
-NS_METHOD GContentHandler::ProcessMimeInfo (void)
-{
- if (mMimeType == NULL ||
- !nsCRT::strcmp(mMimeType, "application/octet-stream"))
- {
- /* FIXME: we leak the old value of mMimeType */
-
- nsresult rv;
- nsCOMPtr<nsIURL> url = do_QueryInterface(mUri, &rv);
- if (NS_SUCCEEDED(rv) && url)
- {
- nsCAutoString uriFileName;
- url->GetFileName(uriFileName);
- mMimeType = g_strdup
- (gnome_vfs_mime_type_from_name
- (uriFileName.get()));
- }
- else
- {
- mMimeType = g_strdup ("application/octet-stream");
- }
- }
-
return NS_OK;
}
@@ -367,7 +248,8 @@ NS_METHOD GContentHandler::MIMEConfirmAction ()
("", NULL, GTK_DIALOG_NO_SEPARATOR,
_("Save As..."), CONTENT_ACTION_SAVEAS,
GTK_STOCK_CANCEL, CONTENT_ACTION_NONE,
- _("Open"), CONTENT_ACTION_OPEN,
+ mAction == CONTENT_ACTION_OPEN ?
+ _("Open") : _("Download"), mAction,
NULL);
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
@@ -382,13 +264,13 @@ NS_METHOD GContentHandler::MIMEConfirmAction ()
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"
+ _("Download the unsafe 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)
+ else 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?"),
@@ -400,7 +282,7 @@ NS_METHOD GContentHandler::MIMEConfirmAction ()
{
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"
+ _("It's not possible to view this file because there is no "
"application installed that can open it."
"You can save it instead."));
}
@@ -439,8 +321,9 @@ NS_METHOD GContentHandler::MIMEDoAction (void)
if (eel_gconf_get_boolean (CONF_LOCKDOWN_DISABLE_SAVE_TO_DISK)) return NS_OK;
auto_downloads = eel_gconf_get_boolean (CONF_AUTO_DOWNLOADS);
- GnomeVFSMimeApplication *DefaultApp = gnome_vfs_mime_get_default_application(mMimeType);
+ mHelperApp = gnome_vfs_mime_get_default_application (mMimeType);
+ CheckAppSupportScheme ();
mPermission = ephy_embed_shell_check_mime (embed_shell, mMimeType);
mAction = CONTENT_ACTION_OPEN;
@@ -454,21 +337,31 @@ NS_METHOD GContentHandler::MIMEDoAction (void)
{
MIMEConfirmAction ();
}
-
- if (mAction == CONTENT_ACTION_DOWNLOAD ||
- mAction == CONTENT_ACTION_SAVEAS)
+
+ nsCOMPtr<nsIMIMEInfo> mimeInfo;
+ mLauncher->GetMIMEInfo(getter_AddRefs(mimeInfo));
+ NS_ENSURE_TRUE (mimeInfo, NS_ERROR_FAILURE);
+
+ if (mAction == CONTENT_ACTION_OPEN)
{
- nsCOMPtr<nsIHelperAppLauncher> launcher;
- GetLauncher (getter_AddRefs(launcher));
- NS_ENSURE_TRUE (launcher, NS_ERROR_FAILURE);
- launcher->SaveToDisk (nsnull,PR_FALSE);
+ /* HACK we use the application description to ask
+ MozDownload to open the file when download
+ is finished */
+ mimeInfo->SetApplicationDescription
+ (NS_LITERAL_STRING ("gnome-default").get());
}
- else if (mAction == CONTENT_ACTION_OPEN)
+ else
+ {
+ mimeInfo->SetApplicationDescription (nsnull);
+ }
+
+ if (mAction == CONTENT_ACTION_OPEN && mAppSupportScheme)
+ {
+ LaunchHelperApp ();
+ }
+ else if (mAction != CONTENT_ACTION_NONE)
{
- rv = SetHelperApp (DefaultApp, FALSE);
- NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE);
- rv = FindHelperApp ();
- NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE);
+ mLauncher->SaveToDisk (nsnull,PR_FALSE);
}
return NS_OK;
diff --git a/embed/mozilla/ContentHandler.h b/embed/mozilla/ContentHandler.h
index d07bea0f7..b692675f5 100644
--- a/embed/mozilla/ContentHandler.h
+++ b/embed/mozilla/ContentHandler.h
@@ -70,24 +70,19 @@ class GContentHandler : public nsIHelperAppLauncherDialog
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 ();
NS_METHOD MIMEConfirmAction ();
NS_METHOD MIMEDoAction ();
-
+ NS_METHOD CheckAppSupportScheme ();
+
nsCOMPtr<nsIHelperAppLauncher> mLauncher;
nsCOMPtr<nsIURI> mUri;
nsCOMPtr<nsIFile> mTempFile;
char *mMimeType;
- PRBool mUrlHelper;
+ PRBool mAppSupportScheme;
GnomeVFSMimeApplication *mHelperApp;
ContentAction mAction;
EphyMimePermission mPermission;
diff --git a/embed/mozilla/MozDownload.cpp b/embed/mozilla/MozDownload.cpp
index 53205702a..003573402 100644
--- a/embed/mozilla/MozDownload.cpp
+++ b/embed/mozilla/MozDownload.cpp
@@ -55,6 +55,7 @@
#include "nsDirectoryServiceDefs.h"
#include "nsDirectoryServiceUtils.h"
#include "nsIRequest.h"
+#include "nsIMIMEInfo.h"
#include "netCore.h"
const char* const persistContractID = "@mozilla.org/embedding/browser/nsWebBrowserPersist;1";
@@ -88,6 +89,7 @@ MozDownload::Init(nsIURI *aSource, nsILocalFile *aTarget, const PRUnichar *aDisp
nsIMIMEInfo *aMIMEInfo, PRInt64 startTime, nsIWebBrowserPersist *aPersist)
{
PRBool addToView = PR_TRUE;
+ nsresult rv;
if (mEmbedPersist)
{
@@ -106,6 +108,7 @@ MozDownload::Init(nsIURI *aSource, nsILocalFile *aTarget, const PRUnichar *aDisp
mPercentComplete = 0;
mInterval = 4000; /* in ms */
mLastUpdate = mStartTime;
+ mMIMEInfo = aMIMEInfo;
if (aPersist)
{
@@ -262,6 +265,8 @@ NS_IMETHODIMP
MozDownload::OnStateChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest,
PRUint32 aStateFlags, nsresult aStatus)
{
+ nsresult rv;
+
/* For a file download via the external helper app service, we will never get a start
notification. The helper app service has gotten that notification before it created us. */
if (!mGotFirstStateChange)
@@ -302,6 +307,41 @@ MozDownload::OnStateChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest,
mozilla_embed_persist_cancelled (mEmbedPersist);
}
}
+ else if (NS_SUCCEEDED (aStatus))
+ {
+ GnomeVFSMimeApplication *helperApp;
+ char *mimeType;
+
+ rv = mMIMEInfo->GetMIMEType (&mimeType);
+ NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE);
+
+ helperApp = gnome_vfs_mime_get_default_application (mimeType);
+
+ PRUnichar *description;
+ mMIMEInfo->GetApplicationDescription (&description);
+
+ /* HACK we use the application description to decide
+ if we have to open the saved file */
+ if ((strcmp (NS_ConvertUCS2toUTF8 (description).get(), "gnome-default") == 0) &&
+ helperApp)
+ {
+ GList *params = NULL;
+ char *param;
+ nsCAutoString aDest;
+
+ mDestination->GetNativePath (aDest);
+
+ param = g_strdup (aDest.get ());
+ params = g_list_append (params, param);
+ gnome_vfs_mime_application_launch (helperApp, params);
+ g_free (param);
+
+ g_list_free (params);
+ }
+
+ nsMemory::Free (mimeType);
+ gnome_vfs_mime_application_free (helperApp);
+ }
}
return NS_OK;
diff --git a/embed/mozilla/MozDownload.h b/embed/mozilla/MozDownload.h
index 9a2a94d53..084a90f8b 100644
--- a/embed/mozilla/MozDownload.h
+++ b/embed/mozilla/MozDownload.h
@@ -56,6 +56,7 @@
#include "downloader-view.h"
#include "ephy-download.h"
#include "ephy-embed-shell.h"
+#include <libgnomevfs/gnome-vfs-mime-handlers.h>
/* MozDownload
Holds information used to display a single download in the UI. This object is
@@ -111,6 +112,7 @@ public:
protected:
nsCOMPtr<nsIURI> mSource;
nsCOMPtr<nsILocalFile> mDestination;
+ nsCOMPtr<nsIMIMEInfo> mMIMEInfo;
PRInt64 mLastUpdate;
PRInt64 mStartTime;
PRInt64 mElapsed;