diff options
author | Xan Lopez <xan@src.gnome.org> | 2003-10-06 19:26:44 +0000 |
---|---|---|
committer | Xan Lopez <xan@src.gnome.org> | 2003-10-06 19:26:44 +0000 |
commit | 1977289f786570f810b54c769085ff8cac6d0c72 (patch) | |
tree | aa9a117e353c88b3d08359769650eb612bc3c99f | |
parent | 4a2e6b22abf86d3e28d3476efc7ff49803430fe0 (diff) | |
download | epiphany-1977289f786570f810b54c769085ff8cac6d0c72.tar.gz |
Cleanups.
* embed/mozilla/EphyDownload.cpp:
* embed/mozilla/EphyDownload.h:
* embed/mozilla/EphyHeaderSniffer.cpp:
* embed/mozilla/EphyHeaderSniffer.h:
* embed/mozilla/MozRegisterComponents.cpp:
* embed/mozilla/ProgressListener.cpp:
* embed/mozilla/ProgressListener.h:
* embed/mozilla/mozilla-embed-persist.cpp:
Cleanups.
-rw-r--r-- | ChangeLog | 13 | ||||
-rw-r--r-- | embed/mozilla/EphyDownload.cpp | 118 | ||||
-rw-r--r-- | embed/mozilla/EphyDownload.h | 69 | ||||
-rw-r--r-- | embed/mozilla/EphyHeaderSniffer.cpp | 5 | ||||
-rw-r--r-- | embed/mozilla/EphyHeaderSniffer.h | 2 | ||||
-rw-r--r-- | embed/mozilla/MozRegisterComponents.cpp | 20 | ||||
-rw-r--r-- | embed/mozilla/ProgressListener.cpp | 648 | ||||
-rw-r--r-- | embed/mozilla/ProgressListener.h | 131 | ||||
-rw-r--r-- | embed/mozilla/mozilla-embed-persist.cpp | 1 |
9 files changed, 793 insertions, 214 deletions
@@ -1,5 +1,18 @@ 2003-10-06 Xan Lopez <xan@masilla.org> + * embed/mozilla/EphyDownload.cpp: + * embed/mozilla/EphyDownload.h: + * embed/mozilla/EphyHeaderSniffer.cpp: + * embed/mozilla/EphyHeaderSniffer.h: + * embed/mozilla/MozRegisterComponents.cpp: + * embed/mozilla/ProgressListener.cpp: + * embed/mozilla/ProgressListener.h: + * embed/mozilla/mozilla-embed-persist.cpp: + + Cleanups. + +2003-10-06 Xan Lopez <xan@masilla.org> + * embed/mozilla/Makefile.am: * embed/mozilla/MozRegisterComponents.cpp: * embed/mozilla/mozilla-embed-persist.cpp: diff --git a/embed/mozilla/EphyDownload.cpp b/embed/mozilla/EphyDownload.cpp index 062abc983..814f65ee7 100644 --- a/embed/mozilla/EphyDownload.cpp +++ b/embed/mozilla/EphyDownload.cpp @@ -39,25 +39,15 @@ #include "EphyDownload.h" #include "nsIExternalHelperAppService.h" -//#include "nsILocalFIleMac.h" #include "nsDirectoryServiceDefs.h" #include "nsDirectoryServiceUtils.h" #include "nsIRequest.h" #include "netCore.h" #include "nsIObserver.h" -//#include "UDownloadDisplay.h" -//#include "UMacUnicode.h" - -//#include "UNavServicesDialogs.h" - - //***************************************************************************** // EphyDownload //***************************************************************************** -#pragma mark [EphyDownload] - -//ADownloadProgressView *EphyDownload::sProgressView; EphyDownload::EphyDownload() : mGotFirstStateChange(false), mIsNetworkTransfer(false), @@ -72,9 +62,6 @@ EphyDownload::~EphyDownload() NS_IMPL_ISUPPORTS2(EphyDownload, nsIDownload, nsIWebProgressListener) -#pragma mark - -#pragma mark [EphyDownload::nsIDownload] - /* void init (in nsIURI aSource, in nsILocalFile aTarget, in wstring aDisplayName, in nsIMIMEInfo aMIMEInfo, in long long startTime, in nsIWebBrowserPersist aPersist); */ NS_IMETHODIMP EphyDownload::Init(nsIURI *aSource, nsILocalFile *aTarget, const PRUnichar *aDisplayName, @@ -98,12 +85,10 @@ EphyDownload::Init(nsIURI *aSource, nsILocalFile *aTarget, const PRUnichar *aDis // until nsIWebBrowserPersist supports weak refs - bug #163889. aPersist->SetProgressListener(this); } - // UI Rumba + // FIXME, get source, dest and filename mDownloaderView = EPHY_DOWNLOADER_VIEW (ephy_embed_shell_get_downloader_view (embed_shell)); downloader_view_add_download (mDownloaderView, "A", "B", "C", (gpointer)this); - // EnsureProgressView(); - // sProgressView->AddDownloadItem(this); } catch (...) { return NS_ERROR_FAILURE; @@ -206,9 +191,6 @@ EphyDownload::SetObserver(nsIObserver * aObserver) return NS_OK; } -#pragma mark - -#pragma mark [EphyDownload::nsIWebProgressListener] - /* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long aStateFlags, in nsresult aStatus); */ NS_IMETHODIMP EphyDownload::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, @@ -219,7 +201,6 @@ EphyDownload::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, if (!mGotFirstStateChange) { mIsNetworkTransfer = ((aStateFlags & STATE_IS_NETWORK) != 0); mGotFirstStateChange = PR_TRUE; - //BroadcastMessage(msg_OnDLStart, this); } if (NS_FAILED(aStatus) && NS_SUCCEEDED(mStatus)) @@ -232,7 +213,6 @@ EphyDownload::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, mWebPersist = nsnull; } mHelperAppLauncher = nsnull; - //BroadcastMessage(msg_OnDLComplete, this); } return NS_OK; @@ -256,7 +236,6 @@ EphyDownload::OnProgressChange(nsIWebProgress *aWebProgress, nsIRequest *aReques else mPercentComplete = (PRInt32)(((float)aCurTotalProgress / (float)aMaxTotalProgress) * 100.0 + 0.5); - //MsgOnDLProgressChangeInfo info(this, aCurTotalProgress, aMaxTotalProgress); // From ProgressListener PRInt64 now = PR_Now(); mElapsed = now - mStartTime; @@ -320,8 +299,6 @@ EphyDownload::OnProgressChange(nsIWebProgress *aWebProgress, nsIRequest *aReques /currentRate + 0.5); } - //BroadcastMessage(msg_OnDLProgressChange, &info); - // UI Rumba downloader_view_set_download_progress (mDownloaderView, mElapsed / 1000000, remaining, @@ -356,9 +333,6 @@ EphyDownload::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aReques return NS_OK; } -#pragma mark - -#pragma mark [EphyDownload Internal Methods] - void EphyDownload::Cancel() { @@ -378,93 +352,3 @@ void EphyDownload::Resume() { } - -/*void -EphyDownload::CreateProgressView() -{ - sProgressView = new CMultiDownloadProgress; - ThrowIfNil_(sProgressView); -}*/ - - -//***************************************************************************** -// CHelperAppLauncherDialog -//***************************************************************************** -/*#pragma mark - -#pragma mark [CHelperAppLauncherDialog] - -CHelperAppLauncherDialog::CHelperAppLauncherDialog() -{ -} - -CHelperAppLauncherDialog::~CHelperAppLauncherDialog() -{ -} - -NS_IMPL_ISUPPORTS1(CHelperAppLauncherDialog, nsIHelperAppLauncherDialog)*/ - -/* void show (in nsIHelperAppLauncher aLauncher, in nsISupports aContext, in boolean aForced); */ -/*NS_IMETHODIMP CHelperAppLauncherDialog::Show(nsIHelperAppLauncher *aLauncher, nsISupports *aContext, PRBool aForced) -{ - return aLauncher->SaveToDisk(nsnull, PR_FALSE); -}*/ - -/* nsILocalFile promptForSaveToFile (in nsIHelperAppLauncher aLauncher, in nsISupports aWindowContext, in wstring aDefaultFile, in wstring aSuggestedFileExtension); */ -/*NS_IMETHODIMP CHelperAppLauncherDialog::PromptForSaveToFile(nsIHelperAppLauncher* aLauncher, - nsISupports *aWindowContext, - const PRUnichar *aDefaultFile, - const PRUnichar *aSuggestedFileExtension, - nsILocalFile **_retval) -{ - NS_ENSURE_ARG_POINTER(_retval); - *_retval = nsnull; - - static bool sFirstTime = true; - UNavServicesDialogs::LFileDesignator designator; - - if (sFirstTime) { - // Get the default download folder and point Nav Sevices to it. - nsCOMPtr<nsIFile> defaultDownloadDir; - NS_GetSpecialDirectory(NS_MAC_DEFAULT_DOWNLOAD_DIR, getter_AddRefs(defaultDownloadDir)); - if (defaultDownloadDir) { - nsCOMPtr<nsILocalFileMac> macDir(do_QueryInterface(defaultDownloadDir)); - FSSpec defaultDownloadSpec; - if (NS_SUCCEEDED(macDir->GetFSSpec(&defaultDownloadSpec))) - designator.SetDefaultLocation(defaultDownloadSpec, true); - } - sFirstTime = false; - } - - Str255 defaultName; - CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(aDefaultFile), defaultName); - bool result = designator.AskDesignateFile(defaultName); - - // After the dialog is dismissed, process all activation an update events right away. - // The save dialog code calls UDesktop::Activate after dismissing the dialog. All that - // does is activate the now frontmost LWindow which was behind the dialog. It does not - // remove the activate event from the queue. If that event is not processed and removed - // before we show the progress window, bad things happen. Specifically, the progress - // dialog will show in front and then, shortly thereafter, the window which was behind this save - // dialog will be moved to the front. - - if (LEventDispatcher::GetCurrentEventDispatcher()) { // Can this ever be NULL? - EventRecord theEvent; - while (::WaitNextEvent(updateMask | activMask, &theEvent, 0, nil)) - LEventDispatcher::GetCurrentEventDispatcher()->DispatchEvent(theEvent); - } - - if (result) { - FSSpec destSpec; - designator.GetFileSpec(destSpec); - nsCOMPtr<nsILocalFileMac> destFile; - NS_NewLocalFileWithFSSpec(&destSpec, PR_TRUE, getter_AddRefs(destFile)); - if (!destFile) - return NS_ERROR_FAILURE; - *_retval = destFile; - NS_ADDREF(*_retval); - return NS_OK; - } - else - return NS_ERROR_ABORT; -}*/ - diff --git a/embed/mozilla/EphyDownload.h b/embed/mozilla/EphyDownload.h index a3abc7067..abc6af436 100644 --- a/embed/mozilla/EphyDownload.h +++ b/embed/mozilla/EphyDownload.h @@ -38,7 +38,6 @@ #ifndef EphyDownload_h__ #define EphyDownload_h__ -//#pragma once #include "nsIDownload.h" #include "nsIWebProgressListener.h" @@ -52,8 +51,6 @@ #include "downloader-view.h" #include "ephy-embed-shell.h" -//class ADownloadProgressView; - //***************************************************************************** // EphyDownload // @@ -76,7 +73,6 @@ } #define EPHY_DOWNLOAD_CLASSNAME "Ephy's Download Progress Dialog" -//#define EPHY_DOWNLOAD_CONTRACTID "@mozilla.org/progressdialog;1" class EphyDownload : public nsIDownload, public nsIWebProgressListener @@ -91,16 +87,6 @@ public: msg_OnDLProgressChange // param is MsgOnDLProgressChangeInfo* }; -/* struct MsgOnDLProgressChangeInfo - { - MsgOnDLProgressChangeInfo(EphyDownload* broadcaster, PRInt32 curProgress, PRInt32 maxProgress) : - mBroadcaster(broadcaster), mCurProgress(curProgress), mMaxProgress(maxProgress) - { } - - EphyDownload *mBroadcaster; - PRInt32 mCurProgress, mMaxProgress; - };*/ - EphyDownload(); virtual ~EphyDownload(); @@ -114,15 +100,6 @@ public: virtual void GetStatus(nsresult& aStatus) { aStatus = mStatus; } -//protected: - // void EnsureProgressView() - // { - // if (!sProgressView) - // CreateProgressView(); - // } - // virtual void CreateProgressView(); - // sProgressView is a singleton. This will only be called once. - protected: nsCOMPtr<nsIURI> mSource; nsCOMPtr<nsILocalFile> mDestination; @@ -145,52 +122,6 @@ protected: PRInt64 mLastUpdate; PRInt32 mInterval; DownloaderView *mDownloaderView; - // static ADownloadProgressView *sProgressView; }; -//***************************************************************************** -// CHelperAppLauncherDialog -// -// The implementation of nsIExternalHelperAppService in Gecko creates one of -// these at the beginning of the download and calls its Show() method. Typically, -// this will create a non-modal dialog in which the user can decide whether to -// save the file to disk or open it with an application. This implementation -// just saves the file to disk unconditionally. The user can decide what they -// wish to do with the download from the progress dialog. -//***************************************************************************** - -/*class CHelperAppLauncherDialog : public nsIHelperAppLauncherDialog -{ -public: - CHelperAppLauncherDialog(); - virtual ~CHelperAppLauncherDialog(); - - NS_DECL_ISUPPORTS - NS_DECL_NSIHELPERAPPLAUNCHERDIALOG - -protected: - -};*/ - - -//***************************************************************************** -// ADownloadProgressView -// -// An abstract class which handles the display and interaction with a download. -// Typically, it presents a progress dialog. -//***************************************************************************** - -/*class ADownloadProgressView -{ - friend class EphyDownload; - - virtual void AddDownloadItem(EphyDownload *aDownloadItem) = 0; - // A download is beginning. Initialize the UI for this download. - // Throughout the download process, the EphyDownload will broadcast - // status messages. The UI needs to call LBroadcaster::AddListener() - // on the EphyDownload at this point in order to get the messages. - -};*/ - - #endif // EphyDownload_h__ diff --git a/embed/mozilla/EphyHeaderSniffer.cpp b/embed/mozilla/EphyHeaderSniffer.cpp index ea5df90a0..3a1731d16 100644 --- a/embed/mozilla/EphyHeaderSniffer.cpp +++ b/embed/mozilla/EphyHeaderSniffer.cpp @@ -37,10 +37,6 @@ * ***** END LICENSE BLOCK ***** */ #include "EphyHeaderSniffer.h" -//#include "UMacUnicode.h" - -//#include "UCustomNavServicesDialogs.h" - #include "netCore.h" #include "nsIChannel.h" @@ -52,7 +48,6 @@ #include "nsIMIMEInfo.h" #include "nsIDOMHTMLDocument.h" #include "nsIDownload.h" -//#include "nsILocalFileMac.h" const char* const persistContractID = "@mozilla.org/embedding/browser/nsWebBrowserPersist;1"; diff --git a/embed/mozilla/EphyHeaderSniffer.h b/embed/mozilla/EphyHeaderSniffer.h index 8ef6afa01..11d3c9e6b 100644 --- a/embed/mozilla/EphyHeaderSniffer.h +++ b/embed/mozilla/EphyHeaderSniffer.h @@ -36,8 +36,6 @@ * * ***** END LICENSE BLOCK ***** */ - #pragma once - #include "nsString.h" #include "nsIWebProgressListener.h" #include "nsIWebBrowserPersist.h" diff --git a/embed/mozilla/MozRegisterComponents.cpp b/embed/mozilla/MozRegisterComponents.cpp index aebc8802d..b595e06be 100644 --- a/embed/mozilla/MozRegisterComponents.cpp +++ b/embed/mozilla/MozRegisterComponents.cpp @@ -25,7 +25,6 @@ #include "GlobalHistory.h" #include "ExternalProtocolHandlers.h" #include "PrintingPromptService.h" -//#include "ProgressListener.h" #include "EphyDownload.h" #include "ExternalProtocolService.h" #include "EphyAboutRedirector.h" @@ -43,7 +42,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(EphyAboutRedirector) NS_GENERIC_FACTORY_CONSTRUCTOR(EphyDownload) -//NS_GENERIC_FACTORY_CONSTRUCTOR(GProgressListener) NS_GENERIC_FACTORY_CONSTRUCTOR(GFilePicker) NS_GENERIC_FACTORY_CONSTRUCTOR(GContentHandler) NS_GENERIC_FACTORY_CONSTRUCTOR(MozGlobalHistory) @@ -64,30 +62,12 @@ static const nsModuleComponentInfo sAppComps[] = { NS_EXTERNALPROTOCOLSERVICE_CONTRACTID, GExternalProtocolServiceConstructor }, - /*{ - EPHY_DOWNLOAD_CLASSNAME, - EPHY_DOWNLOAD_CID, - EPHY_DOWNLOAD_CONTRACTID, - EphyDownloadConstructor - },*/ { EPHY_DOWNLOAD_CLASSNAME, EPHY_DOWNLOAD_CID, NS_DOWNLOAD_CONTRACTID, EphyDownloadConstructor }, -/* { - G_PROGRESSDIALOG_CLASSNAME, - G_PROGRESSDIALOG_CID, - G_PROGRESSDIALOG_CONTRACTID, - GProgressListenerConstructor - }, - { - G_PROGRESSDIALOG_CLASSNAME, - G_PROGRESSDIALOG_CID, - NS_DOWNLOAD_CONTRACTID, - GProgressListenerConstructor - },*/ { G_FILEPICKER_CLASSNAME, G_FILEPICKER_CID, diff --git a/embed/mozilla/ProgressListener.cpp b/embed/mozilla/ProgressListener.cpp new file mode 100644 index 000000000..433b2234c --- /dev/null +++ b/embed/mozilla/ProgressListener.cpp @@ -0,0 +1,648 @@ +/* + * Copyright (C) 2001 Philip Langdale, Matthew Aubury + * + * 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 + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include "ProgressListener.h" +#include "ephy-file-helpers.h" +#include "downloader-view.h" +#include "mozilla-embed-persist.h" +#include "nsXPIDLString.h" +#include "nsCOMPtr.h" + +static void +download_remove_cb (DownloaderView *dv, GProgressListener *Changed, GProgressListener *Progress); +static void +download_resume_cb (DownloaderView *dv, GProgressListener *Changed, GProgressListener *Progress); +static void +download_pause_cb (DownloaderView *dv, GProgressListener *Changed, GProgressListener *Progress); + +NS_IMPL_ISUPPORTS4 (GProgressListener, nsIDownload, nsIWebProgressListener, + nsIProgressDialog, nsISupportsWeakReference) + +//--------------------------------------------------------------------------- + +//--------------------------------------------------------------------------- + +GProgressListener::GProgressListener () : mLauncher(nsnull), + mPersist(nsnull), + mHandler(nsnull), + mObserver(nsnull), + mMIMEInfo(nsnull), + mPercentComplete(0) +{ + NS_INIT_ISUPPORTS (); +} + +GProgressListener::~GProgressListener () +{ + /* destructor code */ +} + +NS_METHOD GProgressListener::InitForPersist (nsIWebBrowserPersist *aPersist, + nsIDOMWindow *aParent, + nsIURI *aURI, + nsIFile *aFile, + DownloadAction aAction, + EphyEmbedPersist *ephyPersist, + PRBool Dialog, + PRInt64 aTimeDownloadStarted) +{ + nsresult rv; + /* fill in download details */ + mAction = aAction; + mParent = aParent; + mDialog = Dialog; + mUri = aURI; + mFile = aFile; + mPersist = aPersist; + mTimeDownloadStarted = aTimeDownloadStarted; + mEphyPersist = ephyPersist; + + /* do remaining init */ + rv = PrivateInit (); + + /* pick up progress messages */ + mPersist->SetProgressListener (this); + + return rv; +} + +NS_METHOD GProgressListener::PrivateInit (void) +{ + mInterval = 500000; /* in microsecs, 0.5s */ + mPriorKRate = 0; + mRateChanges = 0; + mRateChangeLimit = 2; /* only update rate every second */ + mIsPaused = PR_FALSE; + mAbort = PR_FALSE; + mStartTime = PR_Now (); + mLastUpdate = mStartTime; + mElapsed = 0; + + if (mDialog) + { + gchar *filename, *source, *dest; + nsAutoString uTmp; + nsCAutoString cTmp; + nsresult rv; + + rv = mFile->GetLeafName (uTmp); + if (NS_FAILED (rv)) return NS_ERROR_FAILURE; + filename = g_strdup (NS_ConvertUCS2toUTF8(uTmp).get()); + + rv = mFile->GetPath (uTmp); + if (NS_FAILED (rv)) return NS_ERROR_FAILURE; + dest = g_strdup (NS_ConvertUCS2toUTF8(uTmp).get()); + + rv = mUri->GetSpec (cTmp); + if (NS_FAILED (rv)) return NS_ERROR_FAILURE; + source = g_strdup (cTmp.get()); + + mDownloaderView = EPHY_DOWNLOADER_VIEW + (ephy_embed_shell_get_downloader_view (embed_shell)); + downloader_view_add_download (mDownloaderView, filename, source, + dest, (gpointer)this); + g_free (source); + g_free (dest); + g_free (filename); + + g_signal_connect (G_OBJECT (mDownloaderView), + "download_remove", + G_CALLBACK (download_remove_cb), + this); + g_signal_connect (G_OBJECT (mDownloaderView), + "download_pause", + G_CALLBACK (download_pause_cb), + this); + g_signal_connect (G_OBJECT (mDownloaderView), + "download_resume", + G_CALLBACK (download_resume_cb), + this); + } + + return NS_OK; +} + +NS_IMETHODIMP GProgressListener::Init(nsIURI *aSource, + nsILocalFile *aTarget, + const PRUnichar *aDisplayName, + nsIMIMEInfo *aMIMEInfo, + PRInt64 aStartTime, + nsIWebBrowserPersist *aPersist) +{ + mUri = aSource; + mFile = aTarget; + mTimeDownloadStarted = aStartTime; + mStartTime = aStartTime; + mPersist = aPersist; + mMIMEInfo = aMIMEInfo; + mAction = ACTION_NONE; + if(mMIMEInfo) + { + nsMIMEInfoHandleAction mimeAction; + if(NS_SUCCEEDED(mMIMEInfo->GetPreferredAction(&mimeAction))) + { + mAction = (mimeAction == nsIMIMEInfo::useHelperApp) ? + ACTION_SAVEFORHELPER : ACTION_NONE; + } + } + mDialog = TRUE; + + return PrivateInit(); +} + +NS_IMETHODIMP GProgressListener::Open(nsIDOMWindow *aParent) +{ + mParent = aParent; + mDialog = TRUE; + + return NS_OK; +} + +/* attribute long long startTime; */ +NS_IMETHODIMP GProgressListener::GetStartTime(PRInt64 *aStartTime) +{ + *aStartTime = mStartTime; + return NS_OK; +} + +/* attribute nsIURI source; */ +NS_IMETHODIMP GProgressListener::GetSource(nsIURI * *aSource) +{ + NS_IF_ADDREF(*aSource = mUri); + return NS_OK; +} + +/* attribute nsILocalFile target; */ +NS_IMETHODIMP GProgressListener::GetTarget(nsILocalFile * *aTarget) +{ + nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(mFile); + NS_IF_ADDREF(*aTarget = localFile); + return NS_OK; +} + +NS_IMETHODIMP GProgressListener::GetMIMEInfo(nsIMIMEInfo * *aMIMEInfo) +{ + NS_IF_ADDREF(*aMIMEInfo = mMIMEInfo); + return NS_OK; +} + +/* attribute nsIObserver observer; */ +NS_IMETHODIMP GProgressListener::GetObserver(nsIObserver * *aObserver) +{ + NS_IF_ADDREF(*aObserver = mObserver); + return NS_OK; +} +NS_IMETHODIMP GProgressListener::SetObserver(nsIObserver * aObserver) +{ + mObserver = aObserver; + return NS_OK; +} + +/* attribute nsIWebProgressListener listener; */ +NS_IMETHODIMP GProgressListener::GetListener(nsIWebProgressListener * *aListener) +{ + *aListener = nsnull; + return NS_OK; +} +NS_IMETHODIMP GProgressListener::SetListener(nsIWebProgressListener * aListener) +{ + return NS_OK; +} + +/* readonly attribute PRInt32 percentComplete; */ +NS_IMETHODIMP GProgressListener::GetPercentComplete(PRInt32 *aPercentComplete) +{ + return *aPercentComplete = mPercentComplete; +} + +/* attribute wstring displayName; */ +NS_IMETHODIMP GProgressListener::GetDisplayName(PRUnichar * *aDisplayName) +{ + *aDisplayName = nsnull; + return NS_OK; +} +NS_IMETHODIMP GProgressListener::SetDisplayName(const PRUnichar * aDisplayName) +{ + return NS_OK; +} + +NS_IMETHODIMP GProgressListener::GetPersist(nsIWebBrowserPersist * *aPersist) +{ + NS_IF_ADDREF(*aPersist = mPersist); + return NS_OK; +} + +NS_IMETHODIMP GProgressListener::SetDialog(nsIDOMWindow *aDialog) +{ + return NS_OK; +} + +NS_IMETHODIMP GProgressListener::GetDialog(nsIDOMWindow * *aDialog) +{ + *aDialog = nsnull; + return NS_OK; +} + +/* attribute PRBool cancelDownloadOnClose; */ +NS_IMETHODIMP GProgressListener::GetCancelDownloadOnClose(PRBool *aCancelDownloadOnClose) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP GProgressListener::SetCancelDownloadOnClose(PRBool aCancelDownloadOnClose) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP GProgressListener::LaunchHandler (PersistHandlerInfo *handler) +{ + nsresult rv; + nsCOMPtr<nsIExternalHelperAppService> helperService = + do_GetService (NS_EXTERNALHELPERAPPSERVICE_CONTRACTID); + + nsCOMPtr<nsPIExternalAppLauncher> appLauncher = + do_QueryInterface (helperService, &rv); + if (NS_SUCCEEDED(rv)) + { + appLauncher->DeleteTemporaryFileOnExit(mFile); + } + + nsAutoString uFileName; + + mFile->GetPath(uFileName); + const nsACString &cFileName = NS_ConvertUCS2toUTF8(uFileName); + + char *fname = g_strdup(PromiseFlatCString(cFileName).get()); + ephy_file_launch_application (handler->command, + fname, + handler->need_terminal); + g_free (fname); + + return NS_OK; +} + +/* + * void onStateChange (in nsIWebProgress aWebProgress, + * in nsIRequest aRequest, + * in long aStateFlags, + * in unsigned long aStatus); + */ +NS_IMETHODIMP GProgressListener::OnStateChange (nsIWebProgress *aWebProgress, + nsIRequest *aRequest, + PRUint32 aStateFlags, + PRUint32 aStatus) +{ + if (mAbort) return NS_ERROR_FAILURE; + + if (aStateFlags & nsIWebProgressListener::STATE_STOP) + { + + if (mDialog) + { + downloader_view_set_download_status (mDownloaderView, + DOWNLOAD_STATUS_COMPLETED, + (gpointer)this); + } + + switch (mAction) + { + case ACTION_SAVEFORHELPER: + LaunchHelperApp(); + break; + + case ACTION_NONE: + if (mLauncher) + { + mLauncher->CloseProgressWindow (); + } + break; + case ACTION_OBJECT_NOTIFY: + + g_return_val_if_fail (EPHY_IS_EMBED_PERSIST (mEphyPersist), + NS_ERROR_FAILURE); + + PersistHandlerInfo *handler; + + g_object_get (mEphyPersist, + "handler", &handler, + NULL); + + if (handler) + { + LaunchHandler (handler); + } + + mozilla_embed_persist_completed + (MOZILLA_EMBED_PERSIST (mEphyPersist)); + } + } + + return NS_OK; +} + +/* + * void onProgressChange (in nsIWebProgress aWebProgress, + * in nsIRequest aRequest, + * in long aCurSelfProgress, + * in long aMaxSelfProgress, + * in long aCurTotalProgress, + * in long aMaxTotalProgress); + */ +NS_IMETHODIMP GProgressListener:: + OnProgressChange (nsIWebProgress *aWebProgress, + nsIRequest *aRequest, + PRInt32 aCurSelfProgress, + PRInt32 aMaxSelfProgress, + PRInt32 aCurTotalProgress, + PRInt32 aMaxTotalProgress) +{ + if (mAbort) return NS_ERROR_FAILURE; + + /* FIXME maxsize check here */ + + if (!mDialog) return NS_OK; + + mRequest = aRequest; + + PRInt64 now = PR_Now (); + + /* get out if we're updating too quickly */ + if ((now - mLastUpdate < mInterval) && + (aMaxTotalProgress != -1) && + (aCurTotalProgress < aMaxTotalProgress)) + { + return NS_OK; + } + mLastUpdate = now; + + /* compute elapsed time */ + mElapsed = now - mStartTime; + + /* compute size done */ + PRInt32 currentKBytes = (PRInt32)(aCurTotalProgress / 1024.0 + 0.5); + + /* compute total size */ + PRInt32 totalKBytes = (PRInt32)(aMaxTotalProgress / 1024.0 + 0.5); + + /* compute progress value */ + gfloat progress = -1; + if (aMaxTotalProgress > 0) + { + progress = (gfloat)aCurTotalProgress / + (gfloat)aMaxTotalProgress; + } + + /* compute download rate */ + gfloat speed = -1; + PRInt64 currentRate; + if (mElapsed) + { + currentRate = ((PRInt64)(aCurTotalProgress)) * 1000000 / mElapsed; + } + else + { + currentRate = 0; + } + + if (!mIsPaused && currentRate) + { + PRFloat64 currentKRate = ((PRFloat64)currentRate)/1024; + if (currentKRate != mPriorKRate) + { + if (mRateChanges++ == mRateChangeLimit) + { + mPriorKRate = currentKRate; + mRateChanges = 0; + } + else + { + currentKRate = mPriorKRate; + } + } + else + { + mRateChanges = 0; + } + + speed = currentKRate; + } + + /* compute time remaining */ + gint remaining = -1; + if (currentRate && (aMaxTotalProgress > 0)) + { + remaining = (gint)((aMaxTotalProgress - aCurTotalProgress) + /currentRate + 0.5); + } + + downloader_view_set_download_progress (mDownloaderView, + mElapsed / 1000000, + remaining, + speed, + totalKBytes, + currentKBytes, + progress, + (gpointer)this); + + return NS_OK; +} + +/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */ +NS_IMETHODIMP GProgressListener:: + OnLocationChange(nsIWebProgress *aWebProgress, + nsIRequest *aRequest, nsIURI *location) +{ + return NS_OK; +} + +/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */ +NS_IMETHODIMP GProgressListener:: + OnStatusChange(nsIWebProgress *aWebProgress, + nsIRequest *aRequest, nsresult aStatus, + const PRUnichar *aMessage) +{ + return NS_OK; +} + +/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long state); */ +NS_IMETHODIMP GProgressListener:: + OnSecurityChange(nsIWebProgress *aWebProgress, + nsIRequest *aRequest, + PRUint32 state) +{ + return NS_OK; +} + +//--------------------------------------------------------------------------- + +NS_METHOD GProgressListener::LaunchHelperApp (void) +{ + if (!mMIMEInfo) + return NS_ERROR_FAILURE; + + nsresult rv; + + nsCOMPtr<nsIFile> helperFile; + rv = mMIMEInfo->GetPreferredApplicationHandler(getter_AddRefs(helperFile)); + if(NS_FAILED(rv)) return NS_ERROR_FAILURE; + + nsCAutoString helperFileName; + rv = helperFile->GetNativePath(helperFileName); + if(NS_FAILED(rv)) return NS_ERROR_FAILURE; + + nsMIMEInfoHandleAction mimeAction; + rv = mMIMEInfo->GetPreferredAction(&mimeAction); + if(NS_FAILED(rv)) return NS_ERROR_FAILURE; + + nsCOMPtr<nsIExternalHelperAppService> helperService = + do_GetService (NS_EXTERNALHELPERAPPSERVICE_CONTRACTID, &rv); + if (NS_SUCCEEDED(rv)) + { + nsCOMPtr<nsPIExternalAppLauncher> appLauncher = + do_QueryInterface (helperService, &rv); + if (NS_SUCCEEDED(rv)) + { + appLauncher->DeleteTemporaryFileOnExit(mFile); + } + } + + nsCAutoString cFileName; + mFile->GetNativePath(cFileName); + if(NS_FAILED(rv)) return NS_ERROR_FAILURE; + + nsXPIDLString helperDesc; + rv = mMIMEInfo->GetApplicationDescription(getter_Copies(helperDesc)); + if(NS_FAILED(rv)) return NS_ERROR_FAILURE; + + gboolean terminalHelper = + helperDesc.Equals(NS_LITERAL_STRING("runInTerminal")) ? + TRUE : FALSE; + + ephy_file_launch_application (helperFileName.get(), + cFileName.get(), + terminalHelper); + + return NS_OK; +} + +nsresult GProgressListener::Pause (void) +{ + nsresult rv; + + if (!mIsPaused) + { + rv = mRequest->Suspend (); + if (NS_SUCCEEDED (rv)) + { + mIsPaused = PR_TRUE; + } + } + else + { + rv = NS_ERROR_FAILURE; + } + + return rv; +} + +nsresult GProgressListener::Resume (void) +{ + nsresult rv; + + if (mIsPaused) + { + rv = mRequest->Resume (); + if (NS_SUCCEEDED (rv)) + { + mIsPaused = PR_FALSE; + } + } + else + { + rv = NS_ERROR_FAILURE; + } + + return rv; +} + +nsresult GProgressListener::Abort (void) +{ + PRBool notify; + notify = (mAction == ACTION_OBJECT_NOTIFY); + mAction = ACTION_NONE; + mAbort = PR_TRUE; + + if (mObserver) + { + mObserver->Observe(NS_ISUPPORTS_CAST(nsIProgressDialog*, this), + "oncancel", nsnull); + OnStateChange(nsnull, nsnull, + nsIWebProgressListener::STATE_STOP, 0); + } + + if (mPersist) + { + mPersist->CancelSave (); + } + else if (mLauncher) + { + mLauncher->Cancel (); + } + else + { + return NS_ERROR_FAILURE; + } + + if (notify) + { + mozilla_embed_persist_cancelled + (MOZILLA_EMBED_PERSIST (mEphyPersist)); + } + + return NS_OK; +} + +static void +download_remove_cb (DownloaderView *dv, GProgressListener *Changed, GProgressListener *Progress) +{ + if (Changed == Progress){ + Progress->Abort(); + } +} + +static void +download_resume_cb (DownloaderView *dv, GProgressListener *Changed, GProgressListener *Progress) +{ + if (Changed == Progress) { + Progress->Resume(); + } +} + +static void +download_pause_cb (DownloaderView *dv, GProgressListener *Changed, GProgressListener *Progress) +{ + if (Changed == Progress) { + Progress->Pause(); + } +} diff --git a/embed/mozilla/ProgressListener.h b/embed/mozilla/ProgressListener.h new file mode 100644 index 000000000..1c6cf6689 --- /dev/null +++ b/embed/mozilla/ProgressListener.h @@ -0,0 +1,131 @@ +/* + * Copyright (C) 2001 Philip Langdale, Matthew Aubury + * + * 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 + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef PROGRESSLISTENER2_H__ +#define PROGRESSLISTENER2_H__ + +#include "downloader-view.h" +#include "ephy-embed-persist.h" +#include "ephy-embed-shell.h" + +#include <gtk/gtkwidget.h> +#include "nsIWebProgressListener.h" +#include "nsIHelperAppLauncherDialog.h" +#include "nsIExternalHelperAppService.h" +#include "nsCExternalHandlerService.h" +#include "nsIWebBrowserPersist.h" +#include "nsWeakReference.h" +#include "nsIURI.h" +#include "nsILocalFile.h" +#include "nsIDOMWindow.h" +#include "nsIRequest.h" +#include "nsIDownload.h" +#include "nsIObserver.h" +#include "nsIProgressDialog.h" +#include "nsIMIMEInfo.h" + +#include "ContentHandler.h" + +#define G_PROGRESSDIALOG_CID \ +{ /* d2a2f743-f126-4f1f-1234-d4e50490f112 */ \ + 0xd2a2f743, \ + 0xf126, \ + 0x4f1f, \ + {0x12, 0x34, 0xd4, 0xe5, 0x04, 0x90, 0xf1, 0x12} \ +} + +#define G_PROGRESSDIALOG_CLASSNAME "Ephy's Download Progress Dialog" +#define G_PROGRESSDIALOG_CONTRACTID "@mozilla.org/progressdialog;1" + +class GProgressListener : public nsIProgressDialog, + public nsIWebProgressListener, + public nsSupportsWeakReference +{ + public: + NS_DECL_ISUPPORTS + NS_DECL_NSIWEBPROGRESSLISTENER + NS_DECL_NSIPROGRESSDIALOG + NS_DECL_NSIDOWNLOAD + + GProgressListener (); + virtual ~GProgressListener (); + + NS_METHOD InitForPersist (nsIWebBrowserPersist *aPersist, + nsIDOMWindow *aParent, nsIURI *aURI, + nsIFile *aFile, + DownloadAction aAction, + EphyEmbedPersist *ephyPersist, + PRBool Dialog, + PRInt64 aTimeDownloadStarted = 0); + nsresult Pause (void); + nsresult Resume (void); + nsresult Abort (void); + + GTimer *mTimer; + + private: + NS_METHOD PrivateInit (void); + NS_METHOD LaunchHelperApp (void); + + NS_METHOD LaunchHandler (PersistHandlerInfo *handler); + + nsCOMPtr<nsIHelperAppLauncher> mLauncher; + nsCOMPtr<nsIWebBrowserPersist> mPersist; + nsCOMPtr<GContentHandler> mHandler; + nsCOMPtr<nsIDOMWindow> mParent; + nsCOMPtr<nsIRequest> mRequest; + + EphyEmbedPersist *mEphyPersist; + + nsCOMPtr<nsIURI> mUri; + PRInt64 mTimeDownloadStarted; + nsCOMPtr<nsIFile> mFile; + + PRInt64 mStartTime; + PRInt64 mElapsed; + + PRInt64 mLastUpdate; + PRInt32 mInterval; + + PRFloat64 mPriorKRate; + PRInt32 mRateChanges; + PRInt32 mRateChangeLimit; + + PRBool mIsPaused; + PRBool mAbort; + gboolean mDialog; + + DownloadAction mAction; + + DownloaderView *mDownloaderView; + + EphyEmbedShell *ephy_shell; + + guint mTimeoutFunc; + + nsCOMPtr<nsIObserver> mObserver; + + nsCOMPtr<nsIMIMEInfo> mMIMEInfo; + + PRInt32 mPercentComplete; +}; + +extern nsresult NS_NewProgressListenerFactory(nsIFactory** aFactory); + +#endif // PROGRESSLISTENER2_H__ + diff --git a/embed/mozilla/mozilla-embed-persist.cpp b/embed/mozilla/mozilla-embed-persist.cpp index 56888f69c..6a0099506 100644 --- a/embed/mozilla/mozilla-embed-persist.cpp +++ b/embed/mozilla/mozilla-embed-persist.cpp @@ -18,7 +18,6 @@ * $Id$ */ -//#include "ProgressListener.h" #include "EphyDownload.h" #include "EphyWrapper.h" #include "mozilla-embed.h" |