diff options
author | Marco Pesenti Gritti <marco@gnome.org> | 2003-10-18 22:16:24 +0800 |
---|---|---|
committer | Marco Pesenti Gritti <marco@src.gnome.org> | 2003-10-18 22:16:24 +0800 |
commit | 4a10053f4fa6380a4400b2c28ccf31c76a86497a (patch) | |
tree | 3a6ca3df7892ada56a34544a3a8b66e5f6793a10 /embed/mozilla | |
parent | 850649e3b65a15efa73d5c34b5c14d9b9cf5ef09 (diff) | |
download | gsoc2013-epiphany-4a10053f4fa6380a4400b2c28ccf31c76a86497a.tar gsoc2013-epiphany-4a10053f4fa6380a4400b2c28ccf31c76a86497a.tar.gz gsoc2013-epiphany-4a10053f4fa6380a4400b2c28ccf31c76a86497a.tar.bz2 gsoc2013-epiphany-4a10053f4fa6380a4400b2c28ccf31c76a86497a.tar.lz gsoc2013-epiphany-4a10053f4fa6380a4400b2c28ccf31c76a86497a.tar.xz gsoc2013-epiphany-4a10053f4fa6380a4400b2c28ccf31c76a86497a.tar.zst gsoc2013-epiphany-4a10053f4fa6380a4400b2c28ccf31c76a86497a.zip |
fixup style
2003-10-18 Marco Pesenti Gritti <marco@gnome.org>
* TODO:
* embed/mozilla/MozDownload.cpp:
* embed/mozilla/MozDownload.h:
fixup style
Diffstat (limited to 'embed/mozilla')
-rw-r--r-- | embed/mozilla/MozDownload.cpp | 279 | ||||
-rw-r--r-- | embed/mozilla/MozDownload.h | 103 |
2 files changed, 188 insertions, 194 deletions
diff --git a/embed/mozilla/MozDownload.cpp b/embed/mozilla/MozDownload.cpp index ce8a2254d..96f5ac38b 100644 --- a/embed/mozilla/MozDownload.cpp +++ b/embed/mozilla/MozDownload.cpp @@ -21,6 +21,8 @@ * * Contributor(s): * Conrad Carlen <ccarlen@netscape.com> + * + * Adapted for epiphany by Marco Pesenti Gritti <marco@gnome.org> * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -46,16 +48,12 @@ #include "netCore.h" #include "nsIObserver.h" -//***************************************************************************** -// MozDownload -//***************************************************************************** - MozDownload::MozDownload() : - mGotFirstStateChange(false), mIsNetworkTransfer(false), - mUserCanceled(false), - mStatus(NS_OK), - mEmbedPersist(nsnull), - mDownloadState(EPHY_DOWNLOAD_DOWNLOADING) + mGotFirstStateChange(false), mIsNetworkTransfer(false), + mUserCanceled(false), + mStatus(NS_OK), + mEmbedPersist(nsnull), + mDownloadState(EPHY_DOWNLOAD_DOWNLOADING) { } @@ -94,7 +92,7 @@ MozDownload::Init(nsIURI *aSource, nsILocalFile *aTarget, const PRUnichar *aDisp mDestination = aTarget; mStartTime = startTime; mPercentComplete = 0; - mInterval = 4000; // in ms + mInterval = 4000; /* in ms */ mLastUpdate = mStartTime; if (aPersist) @@ -106,8 +104,8 @@ MozDownload::Init(nsIURI *aSource, nsILocalFile *aTarget, const PRUnichar *aDisp if (addToView) { DownloaderView *dview; - dview = EPHY_DOWNLOADER_VIEW (ephy_embed_shell_get_downloader_view - (embed_shell)); + dview = EPHY_DOWNLOADER_VIEW + (ephy_embed_shell_get_downloader_view (embed_shell)); mEphyDownload = mozilla_download_new (); MOZILLA_DOWNLOAD (mEphyDownload)->moz_download = this; downloader_view_add_download (dview, mEphyDownload); @@ -120,248 +118,249 @@ MozDownload::Init(nsIURI *aSource, nsILocalFile *aTarget, const PRUnichar *aDisp return NS_OK; } -/* readonly attribute nsIURI source; */ NS_IMETHODIMP -MozDownload::GetSource(nsIURI * *aSource) +MozDownload::GetSource(nsIURI **aSource) { - NS_ENSURE_ARG_POINTER(aSource); - NS_IF_ADDREF(*aSource = mSource); - return NS_OK; + NS_ENSURE_ARG_POINTER(aSource); + NS_IF_ADDREF(*aSource = mSource); + + return NS_OK; } -/* readonly attribute nsILocalFile target; */ NS_IMETHODIMP -MozDownload::GetTarget(nsILocalFile * *aTarget) +MozDownload::GetTarget(nsILocalFile **aTarget) { - NS_ENSURE_ARG_POINTER(aTarget); - NS_IF_ADDREF(*aTarget = mDestination); - return NS_OK; + NS_ENSURE_ARG_POINTER(aTarget); + NS_IF_ADDREF(*aTarget = mDestination); + + return NS_OK; } -/* readonly attribute nsIWebBrowserPersist persist; */ NS_IMETHODIMP -MozDownload::GetPersist(nsIWebBrowserPersist * *aPersist) +MozDownload::GetPersist(nsIWebBrowserPersist **aPersist) { - NS_ENSURE_ARG_POINTER(aPersist); - NS_IF_ADDREF(*aPersist = mWebPersist); - return NS_OK; + NS_ENSURE_ARG_POINTER(aPersist); + NS_IF_ADDREF(*aPersist = mWebPersist); + + return NS_OK; } -/* readonly attribute PRInt32 percentComplete; */ NS_IMETHODIMP MozDownload::GetPercentComplete(PRInt32 *aPercentComplete) { - NS_ENSURE_ARG_POINTER(aPercentComplete); - *aPercentComplete = mPercentComplete; - return NS_OK; + NS_ENSURE_ARG_POINTER(aPercentComplete); + *aPercentComplete = mPercentComplete; + + return NS_OK; } NS_IMETHODIMP MozDownload::GetTotalProgress(PRInt32 *aTotalProgress) { - NS_ENSURE_ARG_POINTER(aTotalProgress); - *aTotalProgress = mTotalProgress; - return NS_OK; + NS_ENSURE_ARG_POINTER(aTotalProgress); + *aTotalProgress = mTotalProgress; + + return NS_OK; } NS_IMETHODIMP MozDownload::GetCurrentProgress(PRInt32 *aCurrentProgress) { - NS_ENSURE_ARG_POINTER(aCurrentProgress); - *aCurrentProgress = mCurrentProgress; - return NS_OK; + NS_ENSURE_ARG_POINTER(aCurrentProgress); + *aCurrentProgress = mCurrentProgress; + + return NS_OK; } NS_IMETHODIMP MozDownload::GetState(EphyDownloadState *aDownloadState) { - NS_ENSURE_ARG_POINTER(aDownloadState); - *aDownloadState = mDownloadState; - return NS_OK; + NS_ENSURE_ARG_POINTER(aDownloadState); + *aDownloadState = mDownloadState; + + return NS_OK; } -/* attribute wstring displayName; */ NS_IMETHODIMP MozDownload::GetDisplayName(PRUnichar * *aDisplayName) { - return NS_ERROR_NOT_IMPLEMENTED; + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP MozDownload::SetDisplayName(const PRUnichar * aDisplayName) { - return NS_ERROR_NOT_IMPLEMENTED; + return NS_ERROR_NOT_IMPLEMENTED; } -/* readonly attribute long long startTime; */ NS_IMETHODIMP MozDownload::GetStartTime(PRInt64 *aStartTime) { - NS_ENSURE_ARG_POINTER(aStartTime); - *aStartTime = mStartTime; - return NS_OK; + NS_ENSURE_ARG_POINTER(aStartTime); + *aStartTime = mStartTime; + + return NS_OK; } NS_IMETHODIMP MozDownload::GetElapsedTime(PRInt64 *aElapsedTime) { - NS_ENSURE_ARG_POINTER(aElapsedTime); - *aElapsedTime = PR_Now() - mStartTime; - return NS_OK; + NS_ENSURE_ARG_POINTER(aElapsedTime); + *aElapsedTime = PR_Now() - mStartTime; + + return NS_OK; } -/* readonly attribute nsIMIMEInfo MIMEInfo; */ NS_IMETHODIMP -MozDownload::GetMIMEInfo(nsIMIMEInfo * *aMIMEInfo) +MozDownload::GetMIMEInfo(nsIMIMEInfo **aMIMEInfo) { - return NS_ERROR_NOT_IMPLEMENTED; + return NS_ERROR_NOT_IMPLEMENTED; } -/* attribute nsIWebProgressListener listener; */ NS_IMETHODIMP -MozDownload::GetListener(nsIWebProgressListener * *aListener) +MozDownload::GetListener(nsIWebProgressListener **aListener) { - NS_ENSURE_ARG_POINTER(aListener); - NS_IF_ADDREF(*aListener = (nsIWebProgressListener *)this); - return NS_OK; + NS_ENSURE_ARG_POINTER(aListener); + NS_IF_ADDREF(*aListener = (nsIWebProgressListener *)this); + + return NS_OK; } NS_IMETHODIMP -MozDownload::SetListener(nsIWebProgressListener * aListener) +MozDownload::SetListener(nsIWebProgressListener *aListener) { - return NS_ERROR_NOT_IMPLEMENTED; + return NS_ERROR_NOT_IMPLEMENTED; } -/* attribute nsIObserver observer; */ NS_IMETHODIMP -MozDownload::GetObserver(nsIObserver * *aObserver) +MozDownload::GetObserver(nsIObserver **aObserver) { - return NS_ERROR_NOT_IMPLEMENTED; + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP -MozDownload::SetObserver(nsIObserver * aObserver) +MozDownload::SetObserver(nsIObserver *aObserver) { - if (aObserver) - aObserver->QueryInterface(NS_GET_IID(nsIHelperAppLauncher), getter_AddRefs(mHelperAppLauncher)); - return NS_OK; + return NS_ERROR_NOT_IMPLEMENTED; } -/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long aStateFlags, in nsresult aStatus); */ NS_IMETHODIMP -MozDownload::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, +MozDownload::OnStateChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 aStateFlags, nsresult aStatus) { - // 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) { - mIsNetworkTransfer = ((aStateFlags & STATE_IS_NETWORK) != 0); - mGotFirstStateChange = PR_TRUE; - } - - if (NS_FAILED(aStatus) && NS_SUCCEEDED(mStatus)) - mStatus = aStatus; - - // We will get this even in the event of a cancel, - if ((aStateFlags & STATE_STOP) && (!mIsNetworkTransfer || (aStateFlags & STATE_IS_NETWORK))) { - /* Keep us alive */ - nsCOMPtr<nsIDownload> kungFuDeathGrip(this); - - mDownloadState = NS_SUCCEEDED (aStatus) ? EPHY_DOWNLOAD_COMPLETED : EPHY_DOWNLOAD_FAILED; - if (mEphyDownload) + /* 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) { - g_signal_emit_by_name (mEphyDownload, "changed"); + mIsNetworkTransfer = ((aStateFlags & STATE_IS_NETWORK) != 0); + mGotFirstStateChange = PR_TRUE; } - if (mWebPersist) + if (NS_FAILED(aStatus) && NS_SUCCEEDED(mStatus)) + mStatus = aStatus; + + /* We will get this even in the event of a cancel */ + if ((aStateFlags & STATE_STOP) && (!mIsNetworkTransfer || (aStateFlags & STATE_IS_NETWORK))) { - mWebPersist->SetProgressListener(nsnull); - mWebPersist = nsnull; - } - mHelperAppLauncher = nsnull; + /* Keep us alive */ + nsCOMPtr<nsIDownload> kungFuDeathGrip(this); - if (mEmbedPersist) - { - if (NS_SUCCEEDED (aStatus)) + mDownloadState = NS_SUCCEEDED (aStatus) ? EPHY_DOWNLOAD_COMPLETED : EPHY_DOWNLOAD_FAILED; + if (mEphyDownload) { - mozilla_embed_persist_completed (mEmbedPersist); + g_signal_emit_by_name (mEphyDownload, "changed"); } - else + + if (mWebPersist) { - mozilla_embed_persist_cancelled (mEmbedPersist); + mWebPersist->SetProgressListener(nsnull); + mWebPersist = nsnull; + } + + if (mEmbedPersist) + { + if (NS_SUCCEEDED (aStatus)) + { + mozilla_embed_persist_completed (mEmbedPersist); + } + else + { + mozilla_embed_persist_cancelled (mEmbedPersist); + } } } - } - return NS_OK; + 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 MozDownload::OnProgressChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, - PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, - PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress) + PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, + PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress) { - PRInt64 now = PR_Now (); + PRInt64 now = PR_Now (); - if ((now - mLastUpdate < mInterval) && - (aMaxTotalProgress != -1) && - (aCurTotalProgress < aMaxTotalProgress)) - return NS_OK; + if ((now - mLastUpdate < mInterval) && + (aMaxTotalProgress != -1) && + (aCurTotalProgress < aMaxTotalProgress)) + return NS_OK; - mLastUpdate = now; + mLastUpdate = now; - if (mUserCanceled) { - if (mHelperAppLauncher) - mHelperAppLauncher->Cancel(); - else if (aRequest) - aRequest->Cancel(NS_BINDING_ABORTED); - mUserCanceled = false; - } - if (aMaxTotalProgress == -1) - mPercentComplete = -1; - else - mPercentComplete = (PRInt32)(((float)aCurTotalProgress / (float)aMaxTotalProgress) * 100.0 + 0.5); - - mTotalProgress = aMaxTotalProgress; - mCurrentProgress = aCurTotalProgress; - - if (mEphyDownload) - { - g_signal_emit_by_name (mEphyDownload, "changed"); - } - - return NS_OK; + if (mUserCanceled) + { + if (aRequest) + { + aRequest->Cancel(NS_BINDING_ABORTED); + } + mUserCanceled = false; + } + + if (aMaxTotalProgress == -1) + { + mPercentComplete = -1; + } + else + { + mPercentComplete = (PRInt32)(((float)aCurTotalProgress / (float)aMaxTotalProgress) * 100.0 + 0.5); + } + + mTotalProgress = aMaxTotalProgress; + mCurrentProgress = aCurTotalProgress; + + if (mEphyDownload) + { + g_signal_emit_by_name (mEphyDownload, "changed"); + } + + return NS_OK; } -/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */ NS_IMETHODIMP -MozDownload::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location) +MozDownload::OnLocationChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location) { - return NS_OK; + return NS_OK; } -/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */ NS_IMETHODIMP -MozDownload::OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, +MozDownload::OnStatusChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsresult aStatus, const PRUnichar *aMessage) { return NS_OK; } -/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long state); */ NS_IMETHODIMP -MozDownload::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 state) +MozDownload::OnSecurityChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 state) { - return NS_OK; + return NS_OK; } void MozDownload::Cancel() { mUserCanceled = true; - // nsWebBrowserPersist does the right thing: After canceling, next time through - // OnStateChange(), aStatus != NS_OK. This isn't the case with nsExternalHelperAppService. + /* nsWebBrowserPersist does the right thing: After canceling, next time through + OnStateChange(), aStatus != NS_OK. This isn't the case with nsExternalHelperAppService.*/ if (!mWebPersist) mStatus = NS_ERROR_ABORT; } diff --git a/embed/mozilla/MozDownload.h b/embed/mozilla/MozDownload.h index f2fc8fe4b..56b8e16e1 100644 --- a/embed/mozilla/MozDownload.h +++ b/embed/mozilla/MozDownload.h @@ -53,76 +53,71 @@ #include "ephy-download.h" #include "ephy-embed-shell.h" -//***************************************************************************** -// MozDownload -// -// Holds information used to display a single download in the UI. This object is -// created in one of two ways: -// (1) By nsExternalHelperAppHandler when Gecko encounters a MIME type which -// it doesn't itself handle. In this case, the notifications sent to -// nsIDownload are controlled by nsExternalHelperAppHandler. -// (2) By the embedding app's file saving code when saving a web page or a link -// target. See CHeaderSniffer.cpp. In this case, the notifications sent to -// nsIDownload are controlled by the implementation of nsIWebBrowserPersist. -//***************************************************************************** +/* MozDownload + Holds information used to display a single download in the UI. This object is + created in one of two ways: + (1) By nsExternalHelperAppHandler when Gecko encounters a MIME type which + it doesn't itself handle. In this case, the notifications sent to + nsIDownload are controlled by nsExternalHelperAppHandler. + (2) By the embedding app's file saving code when saving a web page or a link + target. See CHeaderSniffer.cpp. In this case, the notifications sent to + nsIDownload are controlled by the implementation of nsIWebBrowserPersist. +*/ #define MOZ_DOWNLOAD_CID \ { /* d2a2f743-f126-4f1f-1234-d4e50490f112 */ \ - 0xd2a2f743, \ - 0xf126, \ - 0x4f1f, \ - {0x12, 0x34, 0xd4, 0xe5, 0x04, 0x90, 0xf1, 0x12} \ + 0xd2a2f743, \ + 0xf126, \ + 0x4f1f, \ + {0x12, 0x34, 0xd4, 0xe5, 0x04, 0x90, 0xf1, 0x12} \ } #define MOZ_DOWNLOAD_CLASSNAME "Ephy's Download Progress Dialog" class MozDownload : public nsIDownload, - public nsIWebProgressListener + public nsIWebProgressListener { public: - MozDownload(); - virtual ~MozDownload(); + MozDownload(); + virtual ~MozDownload(); - NS_DECL_ISUPPORTS - NS_DECL_NSIDOWNLOAD - NS_DECL_NSIWEBPROGRESSLISTENER + NS_DECL_ISUPPORTS + NS_DECL_NSIDOWNLOAD + NS_DECL_NSIWEBPROGRESSLISTENER - virtual void Cancel(); - virtual void Pause(); - virtual void Resume(); + virtual void Cancel(); + virtual void Pause(); + virtual void Resume(); - nsresult GetState (EphyDownloadState *aDownloadState); - nsresult GetCurrentProgress (PRInt32 *aCurrentProgress); - nsresult GetTotalProgress (PRInt32 *aTProgress); - nsresult GetElapsedTime (PRInt64 *aTProgress); - nsresult InitForEmbed (nsIURI *aSource, nsILocalFile *aTarget, - const PRUnichar *aDisplayName, nsIMIMEInfo *aMIMEInfo, - PRInt64 startTime, nsIWebBrowserPersist *aPersist, - MozillaEmbedPersist *aEmbedPersist); + nsresult GetState (EphyDownloadState *aDownloadState); + nsresult GetCurrentProgress (PRInt32 *aCurrentProgress); + nsresult GetTotalProgress (PRInt32 *aTProgress); + nsresult GetElapsedTime (PRInt64 *aTProgress); + nsresult InitForEmbed (nsIURI *aSource, nsILocalFile *aTarget, + const PRUnichar *aDisplayName, nsIMIMEInfo *aMIMEInfo, + PRInt64 startTime, nsIWebBrowserPersist *aPersist, + MozillaEmbedPersist *aEmbedPersist); protected: - nsCOMPtr<nsIURI> mSource; - nsCOMPtr<nsILocalFile> mDestination; - PRInt64 mLastUpdate; - PRInt64 mStartTime; - PRInt64 mElapsed; - PRInt32 mInterval; - PRInt32 mPercentComplete; - PRInt32 mTotalProgress; - PRInt32 mCurrentProgress; + nsCOMPtr<nsIURI> mSource; + nsCOMPtr<nsILocalFile> mDestination; + PRInt64 mLastUpdate; + PRInt64 mStartTime; + PRInt64 mElapsed; + PRInt32 mInterval; + PRInt32 mPercentComplete; + PRInt32 mTotalProgress; + PRInt32 mCurrentProgress; - bool mGotFirstStateChange, mIsNetworkTransfer; - bool mUserCanceled; - nsresult mStatus; - - // These two are mutually exclusive. - nsCOMPtr<nsIWebBrowserPersist> mWebPersist; - nsCOMPtr<nsIHelperAppLauncher> mHelperAppLauncher; - - EphyDownload *mEphyDownload; - DownloaderView *mDownloaderView; - MozillaEmbedPersist *mEmbedPersist; - EphyDownloadState mDownloadState; + bool mGotFirstStateChange, mIsNetworkTransfer; + bool mUserCanceled; + nsresult mStatus; + + nsCOMPtr<nsIWebBrowserPersist> mWebPersist; + EphyDownload *mEphyDownload; + DownloaderView *mDownloaderView; + MozillaEmbedPersist *mEmbedPersist; + EphyDownloadState mDownloadState; }; #endif // MozDownload_h__ |