diff options
author | Marco Pesenti Gritti <marco@src.gnome.org> | 2003-10-17 01:28:46 +0800 |
---|---|---|
committer | Marco Pesenti Gritti <marco@src.gnome.org> | 2003-10-17 01:28:46 +0800 |
commit | 24fc218c90c70a06011a851df6991bf34b72d6c3 (patch) | |
tree | 6bb9ee7e434a3b10e636634cbaaa997e6ccebf1f /embed/mozilla | |
parent | b7a8e995fde6c3cf6ac82ea2390c3c4b510024c5 (diff) | |
download | gsoc2013-epiphany-24fc218c90c70a06011a851df6991bf34b72d6c3.tar gsoc2013-epiphany-24fc218c90c70a06011a851df6991bf34b72d6c3.tar.gz gsoc2013-epiphany-24fc218c90c70a06011a851df6991bf34b72d6c3.tar.bz2 gsoc2013-epiphany-24fc218c90c70a06011a851df6991bf34b72d6c3.tar.lz gsoc2013-epiphany-24fc218c90c70a06011a851df6991bf34b72d6c3.tar.xz gsoc2013-epiphany-24fc218c90c70a06011a851df6991bf34b72d6c3.tar.zst gsoc2013-epiphany-24fc218c90c70a06011a851df6991bf34b72d6c3.zip |
Merge new-downloader branch. We reworked the backend, the user
interface is still incomplete.
Diffstat (limited to 'embed/mozilla')
-rw-r--r-- | embed/mozilla/ContentHandler.cpp | 11 | ||||
-rw-r--r-- | embed/mozilla/EphyDownload.cpp | 470 | ||||
-rw-r--r-- | embed/mozilla/EphyHeaderSniffer.cpp | 261 | ||||
-rw-r--r-- | embed/mozilla/EphyHeaderSniffer.h | 23 | ||||
-rw-r--r-- | embed/mozilla/EphyWrapper.cpp | 2 | ||||
-rw-r--r-- | embed/mozilla/EphyWrapper.h | 2 | ||||
-rw-r--r-- | embed/mozilla/GlobalHistory.h | 1 | ||||
-rw-r--r-- | embed/mozilla/Makefile.am | 9 | ||||
-rw-r--r-- | embed/mozilla/MozDownload.cpp | 377 | ||||
-rw-r--r-- | embed/mozilla/MozDownload.h (renamed from embed/mozilla/EphyDownload.h) | 128 | ||||
-rw-r--r-- | embed/mozilla/MozRegisterComponents.cpp | 16 | ||||
-rw-r--r-- | embed/mozilla/ProgressListener.cpp | 648 | ||||
-rw-r--r-- | embed/mozilla/ProgressListener.h | 131 | ||||
-rw-r--r-- | embed/mozilla/mozilla-download.cpp | 203 | ||||
-rw-r--r-- | embed/mozilla/mozilla-download.h | 57 | ||||
-rw-r--r-- | embed/mozilla/mozilla-embed-persist.cpp | 153 |
16 files changed, 786 insertions, 1706 deletions
diff --git a/embed/mozilla/ContentHandler.cpp b/embed/mozilla/ContentHandler.cpp index 48809a099..519bff738 100644 --- a/embed/mozilla/ContentHandler.cpp +++ b/embed/mozilla/ContentHandler.cpp @@ -159,7 +159,6 @@ extern "C" { #include "ephy-gui.h" #include "ephy-embed-utils.h" #include "ephy-file-helpers.h" -#include "ProgressListener.h" #include "ContentHandler.h" #include <gtk/gtkentry.h> @@ -189,9 +188,10 @@ extern "C" { #include "nsIPrefService.h" #include "nsIDOMWindow.h" #include "nsIDOMWindowInternal.h" +#include "nsIMIMEInfo.h" class GContentHandler; -class GDownloadProgressListener; +//class GDownloadProgressListener; struct MimeAskActionDialog; struct HelperAppChooserDialog; @@ -454,15 +454,20 @@ NS_METHOD GContentHandler::SetHelperApp(GnomeVFSMimeApplication *aHelperApp, NS_METHOD GContentHandler::SynchroniseMIMEInfo (void) { nsresult rv; + char *command_with_path; + nsCOMPtr<nsIMIMEInfo> mimeInfo; rv = mLauncher->GetMIMEInfo(getter_AddRefs(mimeInfo)); if(NS_FAILED(rv)) return 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; - rv = NS_NewNativeLocalFile(nsDependentCString(mHelperApp->command), + rv = NS_NewNativeLocalFile(nsDependentCString(command_with_path), PR_TRUE, getter_AddRefs(helperFile)); if(NS_FAILED(rv)) return NS_ERROR_FAILURE; + g_free (command_with_path); rv = mimeInfo->SetPreferredApplicationHandler(helperFile); if(NS_FAILED(rv)) return NS_ERROR_FAILURE; diff --git a/embed/mozilla/EphyDownload.cpp b/embed/mozilla/EphyDownload.cpp deleted file mode 100644 index 062abc983..000000000 --- a/embed/mozilla/EphyDownload.cpp +++ /dev/null @@ -1,470 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Conrad Carlen <ccarlen@netscape.com> - * - * 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 - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#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), - mUserCanceled(false), - mStatus(NS_OK) -{ -} - -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, - nsIMIMEInfo *aMIMEInfo, PRInt64 startTime, nsIWebBrowserPersist *aPersist) -{ - try { - mSource = aSource; - mDestination = aTarget; - mStartTime = startTime; - mPercentComplete = 0; - mInterval = 400000; // ms - mPriorKRate = 0; - mRateChanges = 0; - mRateChangeLimit = 2; - mIsPaused = PR_FALSE; - mStartTime = PR_Now(); - mLastUpdate = mStartTime; - if (aPersist) { - mWebPersist = aPersist; - // We have to break this circular ref when the download is done - - // until nsIWebBrowserPersist supports weak refs - bug #163889. - aPersist->SetProgressListener(this); - } - // UI Rumba - 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; - } - return NS_OK; -} - -/* readonly attribute nsIURI source; */ -NS_IMETHODIMP -EphyDownload::GetSource(nsIURI * *aSource) -{ - NS_ENSURE_ARG_POINTER(aSource); - NS_IF_ADDREF(*aSource = mSource); - return NS_OK; -} - -/* readonly attribute nsILocalFile target; */ -NS_IMETHODIMP -EphyDownload::GetTarget(nsILocalFile * *aTarget) -{ - NS_ENSURE_ARG_POINTER(aTarget); - NS_IF_ADDREF(*aTarget = mDestination); - return NS_OK; -} - -/* readonly attribute nsIWebBrowserPersist persist; */ -NS_IMETHODIMP -EphyDownload::GetPersist(nsIWebBrowserPersist * *aPersist) -{ - NS_ENSURE_ARG_POINTER(aPersist); - NS_IF_ADDREF(*aPersist = mWebPersist); - return NS_OK; -} - -/* readonly attribute PRInt32 percentComplete; */ -NS_IMETHODIMP -EphyDownload::GetPercentComplete(PRInt32 *aPercentComplete) -{ - NS_ENSURE_ARG_POINTER(aPercentComplete); - *aPercentComplete = mPercentComplete; - return NS_OK; -} - -/* attribute wstring displayName; */ -NS_IMETHODIMP -EphyDownload::GetDisplayName(PRUnichar * *aDisplayName) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -EphyDownload::SetDisplayName(const PRUnichar * aDisplayName) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* readonly attribute long long startTime; */ -NS_IMETHODIMP -EphyDownload::GetStartTime(PRInt64 *aStartTime) -{ - NS_ENSURE_ARG_POINTER(aStartTime); - *aStartTime = mStartTime; - return NS_OK; -} - -/* readonly attribute nsIMIMEInfo MIMEInfo; */ -NS_IMETHODIMP -EphyDownload::GetMIMEInfo(nsIMIMEInfo * *aMIMEInfo) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* attribute nsIWebProgressListener listener; */ -NS_IMETHODIMP -EphyDownload::GetListener(nsIWebProgressListener * *aListener) -{ - NS_ENSURE_ARG_POINTER(aListener); - NS_IF_ADDREF(*aListener = (nsIWebProgressListener *)this); - return NS_OK; -} - -NS_IMETHODIMP -EphyDownload::SetListener(nsIWebProgressListener * aListener) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* attribute nsIObserver observer; */ -NS_IMETHODIMP -EphyDownload::GetObserver(nsIObserver * *aObserver) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -EphyDownload::SetObserver(nsIObserver * aObserver) -{ - if (aObserver) - aObserver->QueryInterface(NS_GET_IID(nsIHelperAppLauncher), getter_AddRefs(mHelperAppLauncher)); - 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, - 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; - //BroadcastMessage(msg_OnDLStart, this); - } - - 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))) { - if (mWebPersist) { - mWebPersist->SetProgressListener(nsnull); - mWebPersist = nsnull; - } - mHelperAppLauncher = nsnull; - //BroadcastMessage(msg_OnDLComplete, this); - } - - 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 -EphyDownload::OnProgressChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, - PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, - PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress) -{ - 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); - - //MsgOnDLProgressChangeInfo info(this, aCurTotalProgress, aMaxTotalProgress); - // From ProgressListener - PRInt64 now = PR_Now(); - mElapsed = now - mStartTime; - - if ((now - mLastUpdate < mInterval) && - (aMaxTotalProgress != -1) && - (aCurTotalProgress < aMaxTotalProgress)) - { - return NS_OK; - } - mLastUpdate = now; - - - 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); - } - - //BroadcastMessage(msg_OnDLProgressChange, &info); - // UI Rumba - downloader_view_set_download_progress (mDownloaderView, - mElapsed / 1000000, - remaining, - speed, - aMaxTotalProgress / 1024.0 + 0.5, - aCurTotalProgress / 1024.0 + 0.5, - progress, - (gpointer)this); - - return NS_OK; -} - -/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */ -NS_IMETHODIMP -EphyDownload::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 -EphyDownload::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 -EphyDownload::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 state) -{ - return NS_OK; -} - -#pragma mark - -#pragma mark [EphyDownload Internal Methods] - -void -EphyDownload::Cancel() -{ - mUserCanceled = true; - // 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; -} - -void -EphyDownload::Pause() -{ -} - -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/EphyHeaderSniffer.cpp b/embed/mozilla/EphyHeaderSniffer.cpp index ea5df90a0..fe0e6ac4a 100644 --- a/embed/mozilla/EphyHeaderSniffer.cpp +++ b/embed/mozilla/EphyHeaderSniffer.cpp @@ -36,11 +36,8 @@ * * ***** END LICENSE BLOCK ***** */ +#include "MozDownload.h" #include "EphyHeaderSniffer.h" -//#include "UMacUnicode.h" - -//#include "UCustomNavServicesDialogs.h" - #include "netCore.h" #include "nsIChannel.h" @@ -52,21 +49,20 @@ #include "nsIMIMEInfo.h" #include "nsIDOMHTMLDocument.h" #include "nsIDownload.h" -//#include "nsILocalFileMac.h" const char* const persistContractID = "@mozilla.org/embedding/browser/nsWebBrowserPersist;1"; -EphyHeaderSniffer::EphyHeaderSniffer(nsIWebBrowserPersist* aPersist, nsIFile* aFile, nsIURI* aURL, - nsIDOMDocument* aDocument, nsIInputStream* aPostData, - const nsAString& aSuggestedFilename, PRBool aBypassCache, ESaveFormat aSaveFormat) +EphyHeaderSniffer::EphyHeaderSniffer(nsIWebBrowserPersist* aPersist, MozillaEmbedPersist *aEmbedPersist, + nsIFile* aFile, nsIURI* aURL, nsIDOMDocument* aDocument, nsIInputStream* aPostData, + const nsAString& aSuggestedFilename, PRBool aBypassCache) : mPersist(aPersist) +, mEmbedPersist(aEmbedPersist) , mTmpFile(aFile) , mURL(aURL) , mDocument(aDocument) , mPostData(aPostData) , mDefaultFilename(aSuggestedFilename) , mBypassCache(aBypassCache) -, mSaveFormat(aSaveFormat) { } @@ -76,8 +72,6 @@ EphyHeaderSniffer::~EphyHeaderSniffer() NS_IMPL_ISUPPORTS1(EphyHeaderSniffer, nsIWebProgressListener) -#pragma mark - - // Implementation of nsIWebProgressListener /* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aStateFlags, in unsigned long aStatus); */ NS_IMETHODIMP @@ -109,7 +103,7 @@ EphyHeaderSniffer::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequ if (exists) mTmpFile->Remove(PR_FALSE); - rv = PerformSave(origURI, mSaveFormat); + rv = PerformSave(origURI); if (NS_FAILED(rv)) { // put up some UI @@ -147,7 +141,7 @@ EphyHeaderSniffer::OnStatusChange(nsIWebProgress *aWebProgress, nsresult aStatus, const PRUnichar *aMessage) { - return NS_OK; + return NS_OK; } /* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long state); */ @@ -157,225 +151,25 @@ EphyHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aR return NS_OK; } -#pragma mark - - -static ESaveFormat SaveFormatFromPrefValue(PRInt32 inPrefValue) -{ - switch (inPrefValue) - { - case 0: return eSaveFormatHTMLComplete; - default: // fall through - case 1: return eSaveFormatHTML; - case 2: return eSaveFormatPlainText; - } -} - -static PRInt32 PrefValueFromSaveFormat(ESaveFormat inSaveFormat) -{ - switch (inSaveFormat) - { - case eSaveFormatPlainText: return 2; - default: // fall through - case eSaveFormatHTML: return 1; - case eSaveFormatHTMLComplete: return 0; - } -} - -nsresult EphyHeaderSniffer::PerformSave(nsIURI* inOriginalURI, const ESaveFormat inSaveFormat) +nsresult EphyHeaderSniffer::PerformSave(nsIURI* inOriginalURI) { - nsresult rv; - // Are we an HTML document? If so, we will want to append an accessory view to - // the save dialog to provide the user with the option of doing a complete - // save vs. a single file save. - PRBool isHTML = (mDocument && mContentType.Equals("text/html") || - mContentType.Equals("text/xml") || - mContentType.Equals("application/xhtml+xml")); - - // Next find out the directory that we should start in. - nsCOMPtr<nsIPrefService> prefs(do_GetService("@mozilla.org/preferences-service;1", &rv)); - if (!prefs) - return rv; - nsCOMPtr<nsIPrefBranch> dirBranch; - prefs->GetBranch("browser.download.", getter_AddRefs(dirBranch)); - PRInt32 filterIndex = 0; - if (inSaveFormat != eSaveFormatUnspecified) { - filterIndex = PrefValueFromSaveFormat(inSaveFormat); - } - else if (dirBranch) { - nsresult rv = dirBranch->GetIntPref("save_converter_index", &filterIndex); - if (NS_FAILED(rv)) - filterIndex = 0; - } - - // We need to figure out what file name to use. -/* nsAutoString defaultFileName; - if (!mContentDisposition.IsEmpty()) { - // (1) Use the HTTP header suggestion. - PRInt32 index = mContentDisposition.Find("filename="); - if (index >= 0) { - // Take the substring following the prefix. - index += 9; - nsCAutoString filename; - mContentDisposition.Right(filename, mContentDisposition.Length() - index); - defaultFileName = NS_ConvertUTF8toUCS2(filename); - } - } - - if (defaultFileName.IsEmpty()) { - nsCOMPtr<nsIURL> url(do_QueryInterface(mURL)); - if (url) { - nsCAutoString fileNameCString; - url->GetFileName(fileNameCString); // (2) For file URLs, use the file name. - defaultFileName = NS_ConvertUTF8toUCS2(fileNameCString); - } - } - - if (defaultFileName.IsEmpty() && mDocument && isHTML) { - nsCOMPtr<nsIDOMHTMLDocument> htmlDoc(do_QueryInterface(mDocument)); - if (htmlDoc) - htmlDoc->GetTitle(defaultFileName); // (3) Use the title of the document. - } - - if (defaultFileName.IsEmpty()) { - // (4) Use the caller provided name. - defaultFileName = mDefaultFilename; - } - - if (defaultFileName.IsEmpty() && mURL) { - // (5) Use the host. - nsCAutoString hostName; - mURL->GetHost(hostName); - defaultFileName = NS_ConvertUTF8toUCS2(hostName); - } - - // One last case to handle about:blank and other fruity untitled pages. - if (defaultFileName.IsEmpty()) - defaultFileName.AssignWithConversion("untitled"); - - // Validate the file name to ensure legality. - for (PRUint32 i = 0; i < defaultFileName.Length(); i++) - if (defaultFileName[i] == ':' || defaultFileName[i] == '/') - defaultFileName.SetCharAt(i, PRUnichar(' ')); - - // Make sure the appropriate extension is appended to the suggested file name. - nsCOMPtr<nsIURI> fileURI(do_CreateInstance("@mozilla.org/network/standard-url;1")); - nsCOMPtr<nsIURL> fileURL(do_QueryInterface(fileURI, &rv)); - if (!fileURL) - return rv; - - fileURL->SetFilePath(NS_ConvertUCS2toUTF8(defaultFileName)); - - nsCAutoString fileExtension; - fileURL->GetFileExtension(fileExtension); - - PRBool setExtension = PR_FALSE; - if (mContentType.Equals("text/html")) { - if (fileExtension.IsEmpty() || (!fileExtension.Equals("htm") && !fileExtension.Equals("html"))) { - defaultFileName.AppendWithConversion(".html"); - setExtension = PR_TRUE; - } - } - - if (!setExtension && fileExtension.IsEmpty()) { - nsCOMPtr<nsIMIMEService> mimeService(do_GetService("@mozilla.org/mime;1", &rv)); - if (!mimeService) - return rv; - nsCOMPtr<nsIMIMEInfo> mimeInfo; - rv = mimeService->GetFromTypeAndExtension(mContentType.get(), nsnull, getter_AddRefs(mimeInfo)); - if (!mimeInfo) - return rv; - - nsCOMPtr<nsIUTF8StringEnumerator> extensions; - mimeInfo->GetFileExtensions(getter_AddRefs(extensions)); - - PRBool hasMore; - extensions->HasMore(&hasMore); - if (hasMore) { - nsCAutoString ext; - extensions->GetNext(ext); - defaultFileName.Append(PRUnichar('.')); - defaultFileName.Append(NS_ConvertUTF8toUCS2(ext)); - } - } - - // Now it's time to pose the save dialog. - FSSpec destFileSpec; - bool isReplacing = false; - - { - Str255 defaultName; - bool result; - - CPlatformUCSConversion::GetInstance()->UCSToPlatform(defaultFileName, defaultName); -#ifndef XP_MACOSX - char tempBuf1[256], tempBuf2[64]; - ::CopyPascalStringToC(defaultName, tempBuf1); - ::CopyCStringToPascal(NS_TruncNodeName(tempBuf1, tempBuf2), defaultName); -#endif - if (isHTML) { - ESaveFormat saveFormat = SaveFormatFromPrefValue(filterIndex); - UNavServicesDialogs::LCustomFileDesignator customDesignator; - result = customDesignator.AskDesignateFile(defaultName, saveFormat); - if (!result) - return NS_OK; // user canceled - filterIndex = PrefValueFromSaveFormat(saveFormat); - customDesignator.GetFileSpec(destFileSpec); - isReplacing = customDesignator.IsReplacing(); - } - else { - UNavServicesDialogs::LFileDesignator stdDesignator; - result = stdDesignator.AskDesignateFile(defaultName); - if (!result) - return NS_OK; // user canceled - stdDesignator.GetFileSpec(destFileSpec); - isReplacing = stdDesignator.IsReplacing(); - } - - // 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); - } - } - - // only save the pref if the frontend didn't specify a format - if (inSaveFormat == eSaveFormatUnspecified && isHTML) - dirBranch->SetIntPref("save_converter_index", filterIndex); - - nsCOMPtr<nsILocalFile> destFile; - - rv = NS_NewLocalFileWithFSSpec(&destFileSpec, PR_TRUE, getter_AddRefs(destFile)); - if (NS_FAILED(rv)) - return rv; - - if (isReplacing) { - PRBool exists; - rv = destFile->Exists(&exists); - if (NS_SUCCEEDED(rv) && exists) - rv = destFile->Remove(PR_TRUE); - if (NS_FAILED(rv)) - return rv; - } - - // if the user chose plain text, set the content type - if (isHTML && filterIndex == 2) - mContentType = "text/plain"; - - nsCOMPtr<nsISupports> sourceData; - if (isHTML && filterIndex != 1) - sourceData = do_QueryInterface(mDocument); // HTML complete - else - sourceData = do_QueryInterface(mURL); // HTML or text only + nsresult rv; + + PRBool isHTML = (mDocument && mContentType.Equals("text/html") || + mContentType.Equals("text/xml") || + mContentType.Equals("application/xhtml+xml")); + + nsCOMPtr<nsILocalFile> file; + rv = NS_NewLocalFile(mDefaultFilename, PR_TRUE, getter_AddRefs(file)); + if (NS_FAILED(rv) || !file) return G_FAILED; + + nsCOMPtr<nsISupports> sourceData; + if (isHTML) + sourceData = do_QueryInterface(mDocument); + else + sourceData = do_QueryInterface(mURL); - return InitiateDownload(sourceData, destFile, inOriginalURI);*/ + return InitiateDownload(sourceData, file, inOriginalURI); } // inOriginalURI is always a URI. inSourceData can be an nsIURI or an nsIDOMDocument, depending @@ -394,11 +188,12 @@ nsresult EphyHeaderSniffer::InitiateDownload(nsISupports* inSourceData, nsILocal nsAutoString fileDisplayName; inDestFile->GetLeafName(fileDisplayName); - nsCOMPtr<nsIDownload> downloader = do_CreateInstance(NS_DOWNLOAD_CONTRACTID); + MozDownload *downloader = new MozDownload (); // dlListener attaches to its progress dialog here, which gains ownership - rv = downloader->Init(inOriginalURI, inDestFile, fileDisplayName.get(), nsnull, timeNow, webPersist); + rv = downloader->InitForEmbed (inOriginalURI, inDestFile, fileDisplayName.get(), + nsnull, timeNow, webPersist, mEmbedPersist); if (NS_FAILED(rv)) return rv; - + PRInt32 flags = nsIWebBrowserPersist::PERSIST_FLAGS_NO_CONVERSION | nsIWebBrowserPersist::PERSIST_FLAGS_REPLACE_EXISTING_FILES; if (mBypassCache) diff --git a/embed/mozilla/EphyHeaderSniffer.h b/embed/mozilla/EphyHeaderSniffer.h index 8ef6afa01..9124cfa16 100644 --- a/embed/mozilla/EphyHeaderSniffer.h +++ b/embed/mozilla/EphyHeaderSniffer.h @@ -36,7 +36,7 @@ * * ***** END LICENSE BLOCK ***** */ - #pragma once +#include "mozilla-embed-persist.h" #include "nsString.h" #include "nsIWebProgressListener.h" @@ -46,23 +46,14 @@ #include "nsIInputStream.h" #include "nsIDOMDocument.h" - -typedef enum -{ - eSaveFormatUnspecified = 0, - eSaveFormatPlainText, // items should match the MENU in resources - eSaveFormatHTML, - eSaveFormatHTMLComplete -} ESaveFormat; - // Implementation of a header sniffer class that is used when saving Web pages and images. class EphyHeaderSniffer : public nsIWebProgressListener { public: - EphyHeaderSniffer(nsIWebBrowserPersist* aPersist, nsIFile* aFile, nsIURI* aURL, - nsIDOMDocument* aDocument, nsIInputStream* aPostData, - const nsAString& aSuggestedFilename, PRBool aBypassCache, - ESaveFormat aSaveFormat = eSaveFormatUnspecified); + EphyHeaderSniffer(nsIWebBrowserPersist* aPersist, MozillaEmbedPersist *aEmbedPersist, + nsIFile* aFile, nsIURI* aURL, + nsIDOMDocument* aDocument, nsIInputStream* aPostData, + const nsAString& aSuggestedFilename, PRBool aBypassCache); virtual ~EphyHeaderSniffer(); NS_DECL_ISUPPORTS @@ -70,19 +61,19 @@ public: protected: - nsresult PerformSave(nsIURI* inOriginalURI, const ESaveFormat inSaveFormat); + nsresult PerformSave(nsIURI* inOriginalURI); nsresult InitiateDownload(nsISupports* inSourceData, nsILocalFile* inDestFile, nsIURI* inOriginalURI); private: nsIWebBrowserPersist* mPersist; // Weak. It owns us as a listener. + MozillaEmbedPersist *mEmbedPersist; nsCOMPtr<nsIFile> mTmpFile; nsCOMPtr<nsIURI> mURL; nsCOMPtr<nsIDOMDocument> mDocument; nsCOMPtr<nsIInputStream> mPostData; nsString mDefaultFilename; PRBool mBypassCache; - ESaveFormat mSaveFormat; nsCString mContentType; nsCString mContentDisposition; }; diff --git a/embed/mozilla/EphyWrapper.cpp b/embed/mozilla/EphyWrapper.cpp index a8492d055..71194438f 100644 --- a/embed/mozilla/EphyWrapper.cpp +++ b/embed/mozilla/EphyWrapper.cpp @@ -24,7 +24,7 @@ #include "EphyWrapper.h" #include "GlobalHistory.h" -#include "ProgressListener.h" +//#include "ProgressListener.h" #include "ephy-embed.h" #include "ephy-string.h" diff --git a/embed/mozilla/EphyWrapper.h b/embed/mozilla/EphyWrapper.h index 32cfe5efd..cfedf6ccc 100644 --- a/embed/mozilla/EphyWrapper.h +++ b/embed/mozilla/EphyWrapper.h @@ -22,7 +22,7 @@ #define EPHY_WRAPPER_H #include "nsIDocShell.h" -#include "ProgressListener.h" +//#include "ProgressListener.h" #include "nsIWebNavigation.h" #include "nsIWebPageDescriptor.h" #include "nsISHistory.h" diff --git a/embed/mozilla/GlobalHistory.h b/embed/mozilla/GlobalHistory.h index f1d810f6a..4315509af 100644 --- a/embed/mozilla/GlobalHistory.h +++ b/embed/mozilla/GlobalHistory.h @@ -22,6 +22,7 @@ #include "nsError.h" #include "nsIGlobalHistory.h" #include "nsIBrowserHistory.h" +#include "ephy-history.h" #define EPHY_GLOBALHISTORY_CLASSNAME \ "Epiphany's Global History Implementation" diff --git a/embed/mozilla/Makefile.am b/embed/mozilla/Makefile.am index b07ffedef..22ef72829 100644 --- a/embed/mozilla/Makefile.am +++ b/embed/mozilla/Makefile.am @@ -37,7 +37,6 @@ INCLUDES = \ $(EPIPHANY_DEPENDENCY_CFLAGS) \ -DG_DISABLE_DEPRECATED \ -DGDK_DISABLE_DEPRECATED \ - -DGTK_DISABLE_DEPRECATED \ -DGDK_PIXBUF_DISABLE_DEPRECATED \ -DGNOME_DISABLE_DEPRECATED \ -DSHARE_DIR=\"$(pkgdatadir)\" \ @@ -56,6 +55,8 @@ libephymozillaembed_la_SOURCES = \ EphyAboutRedirector.h \ EphyEventListener.cpp \ EphyEventListener.h \ + EphyHeaderSniffer.cpp \ + EphyHeaderSniffer.h \ EphyWrapper.cpp \ EphyWrapper.h \ EventContext.cpp \ @@ -70,14 +71,16 @@ libephymozillaembed_la_SOURCES = \ GlobalHistory.h \ GtkNSSDialogs.cpp \ GtkNSSDialogs.h \ + MozDownload.cpp \ + MozDownload.h \ MozillaPrivate.cpp \ MozillaPrivate.h \ MozRegisterComponents.cpp \ MozRegisterComponents.h \ PrintingPromptService.cpp \ PrintingPromptService.h \ - ProgressListener.cpp \ - ProgressListener.h \ + mozilla-download.cpp \ + mozilla-download.h \ mozilla-embed.cpp \ mozilla-embed.h \ mozilla-embed-persist.cpp \ diff --git a/embed/mozilla/MozDownload.cpp b/embed/mozilla/MozDownload.cpp new file mode 100644 index 000000000..ce8a2254d --- /dev/null +++ b/embed/mozilla/MozDownload.cpp @@ -0,0 +1,377 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 2002 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Conrad Carlen <ccarlen@netscape.com> + * + * 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 + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "MozDownload.h" +#include "mozilla-download.h" + +#include "nsIExternalHelperAppService.h" +#include "nsDirectoryServiceDefs.h" +#include "nsDirectoryServiceUtils.h" +#include "nsIRequest.h" +#include "netCore.h" +#include "nsIObserver.h" + +//***************************************************************************** +// MozDownload +//***************************************************************************** + +MozDownload::MozDownload() : + mGotFirstStateChange(false), mIsNetworkTransfer(false), + mUserCanceled(false), + mStatus(NS_OK), + mEmbedPersist(nsnull), + mDownloadState(EPHY_DOWNLOAD_DOWNLOADING) +{ +} + +MozDownload::~MozDownload() +{ +} + +NS_IMPL_ISUPPORTS2(MozDownload, nsIDownload, nsIWebProgressListener) + +NS_IMETHODIMP +MozDownload::InitForEmbed (nsIURI *aSource, nsILocalFile *aTarget, const PRUnichar *aDisplayName, + nsIMIMEInfo *aMIMEInfo, PRInt64 startTime, nsIWebBrowserPersist *aPersist, + MozillaEmbedPersist *aEmbedPersist) +{ + mEmbedPersist = aEmbedPersist; + return Init (aSource, aTarget, aDisplayName, aMIMEInfo, startTime, aPersist); +} + +/* void init (in nsIURI aSource, in nsILocalFile aTarget, in wstring aDisplayName, in nsIMIMEInfo aMIMEInfo, in long long startTime, in nsIWebBrowserPersist aPersist); */ +NS_IMETHODIMP +MozDownload::Init(nsIURI *aSource, nsILocalFile *aTarget, const PRUnichar *aDisplayName, + nsIMIMEInfo *aMIMEInfo, PRInt64 startTime, nsIWebBrowserPersist *aPersist) +{ + PRBool addToView = PR_TRUE; + + if (mEmbedPersist) + { + EmbedPersistFlags flags; + + ephy_embed_persist_get_flags (EPHY_EMBED_PERSIST (mEmbedPersist), &flags); + + addToView = !(flags & EMBED_PERSIST_NO_VIEW); + } + + mSource = aSource; + mDestination = aTarget; + mStartTime = startTime; + mPercentComplete = 0; + mInterval = 4000; // in ms + mLastUpdate = mStartTime; + + if (aPersist) + { + mWebPersist = aPersist; + aPersist->SetProgressListener(this); + } + + if (addToView) + { + DownloaderView *dview; + 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); + } + else + { + mEphyDownload = nsnull; + } + + return NS_OK; +} + +/* readonly attribute nsIURI source; */ +NS_IMETHODIMP +MozDownload::GetSource(nsIURI * *aSource) +{ + NS_ENSURE_ARG_POINTER(aSource); + NS_IF_ADDREF(*aSource = mSource); + return NS_OK; +} + +/* readonly attribute nsILocalFile target; */ +NS_IMETHODIMP +MozDownload::GetTarget(nsILocalFile * *aTarget) +{ + NS_ENSURE_ARG_POINTER(aTarget); + NS_IF_ADDREF(*aTarget = mDestination); + return NS_OK; +} + +/* readonly attribute nsIWebBrowserPersist persist; */ +NS_IMETHODIMP +MozDownload::GetPersist(nsIWebBrowserPersist * *aPersist) +{ + 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_IMETHODIMP +MozDownload::GetTotalProgress(PRInt32 *aTotalProgress) +{ + 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_IMETHODIMP +MozDownload::GetState(EphyDownloadState *aDownloadState) +{ + NS_ENSURE_ARG_POINTER(aDownloadState); + *aDownloadState = mDownloadState; + return NS_OK; +} + +/* attribute wstring displayName; */ +NS_IMETHODIMP +MozDownload::GetDisplayName(PRUnichar * *aDisplayName) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +MozDownload::SetDisplayName(const PRUnichar * aDisplayName) +{ + 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_IMETHODIMP +MozDownload::GetElapsedTime(PRInt64 *aElapsedTime) +{ + NS_ENSURE_ARG_POINTER(aElapsedTime); + *aElapsedTime = PR_Now() - mStartTime; + return NS_OK; +} + +/* readonly attribute nsIMIMEInfo MIMEInfo; */ +NS_IMETHODIMP +MozDownload::GetMIMEInfo(nsIMIMEInfo * *aMIMEInfo) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* attribute nsIWebProgressListener listener; */ +NS_IMETHODIMP +MozDownload::GetListener(nsIWebProgressListener * *aListener) +{ + NS_ENSURE_ARG_POINTER(aListener); + NS_IF_ADDREF(*aListener = (nsIWebProgressListener *)this); + return NS_OK; +} + +NS_IMETHODIMP +MozDownload::SetListener(nsIWebProgressListener * aListener) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* attribute nsIObserver observer; */ +NS_IMETHODIMP +MozDownload::GetObserver(nsIObserver * *aObserver) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +MozDownload::SetObserver(nsIObserver * aObserver) +{ + if (aObserver) + aObserver->QueryInterface(NS_GET_IID(nsIHelperAppLauncher), getter_AddRefs(mHelperAppLauncher)); + return NS_OK; +} + +/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long aStateFlags, in nsresult aStatus); */ +NS_IMETHODIMP +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) + { + g_signal_emit_by_name (mEphyDownload, "changed"); + } + + if (mWebPersist) + { + mWebPersist->SetProgressListener(nsnull); + mWebPersist = nsnull; + } + mHelperAppLauncher = nsnull; + + if (mEmbedPersist) + { + if (NS_SUCCEEDED (aStatus)) + { + mozilla_embed_persist_completed (mEmbedPersist); + } + else + { + mozilla_embed_persist_cancelled (mEmbedPersist); + } + } + } + + 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) +{ + PRInt64 now = PR_Now (); + + if ((now - mLastUpdate < mInterval) && + (aMaxTotalProgress != -1) && + (aCurTotalProgress < aMaxTotalProgress)) + return NS_OK; + + 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; +} + +/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */ +NS_IMETHODIMP +MozDownload::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 +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) +{ + 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. + if (!mWebPersist) + mStatus = NS_ERROR_ABORT; +} + +void +MozDownload::Pause() +{ +} + +void +MozDownload::Resume() +{ +} diff --git a/embed/mozilla/EphyDownload.h b/embed/mozilla/MozDownload.h index a3abc7067..f2fc8fe4b 100644 --- a/embed/mozilla/EphyDownload.h +++ b/embed/mozilla/MozDownload.h @@ -36,10 +36,10 @@ * * ***** END LICENSE BLOCK ***** */ -#ifndef EphyDownload_h__ -#define EphyDownload_h__ -//#pragma once +#ifndef MozDownload_h__ +#define MozDownload_h__ +#include "mozilla-embed-persist.h" #include "nsIDownload.h" #include "nsIWebProgressListener.h" #include "nsIHelperAppLauncherDialog.h" @@ -50,12 +50,11 @@ #include "nsIWebBrowserPersist.h" #include "downloader-view.h" +#include "ephy-download.h" #include "ephy-embed-shell.h" -//class ADownloadProgressView; - //***************************************************************************** -// EphyDownload +// MozDownload // // Holds information used to display a single download in the UI. This object is // created in one of two ways: @@ -67,7 +66,7 @@ // nsIDownload are controlled by the implementation of nsIWebBrowserPersist. //***************************************************************************** -#define EPHY_DOWNLOAD_CID \ +#define MOZ_DOWNLOAD_CID \ { /* d2a2f743-f126-4f1f-1234-d4e50490f112 */ \ 0xd2a2f743, \ 0xf126, \ @@ -75,122 +74,55 @@ {0x12, 0x34, 0xd4, 0xe5, 0x04, 0x90, 0xf1, 0x12} \ } -#define EPHY_DOWNLOAD_CLASSNAME "Ephy's Download Progress Dialog" -//#define EPHY_DOWNLOAD_CONTRACTID "@mozilla.org/progressdialog;1" +#define MOZ_DOWNLOAD_CLASSNAME "Ephy's Download Progress Dialog" -class EphyDownload : public nsIDownload, +class MozDownload : public nsIDownload, public nsIWebProgressListener -// public LBroadcaster { public: - - // Messages we broadcast to listeners. - enum { - msg_OnDLStart = 57723, // param is EphyDownload* - msg_OnDLComplete, // param is EphyDownload* - 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(); + MozDownload(); + virtual ~MozDownload(); NS_DECL_ISUPPORTS NS_DECL_NSIDOWNLOAD NS_DECL_NSIWEBPROGRESSLISTENER - + virtual void Cancel(); virtual void Pause(); virtual void Resume(); - 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. - + 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; + bool mGotFirstStateChange, mIsNetworkTransfer; bool mUserCanceled; - bool mIsPaused; nsresult mStatus; // These two are mutually exclusive. nsCOMPtr<nsIWebBrowserPersist> mWebPersist; nsCOMPtr<nsIHelperAppLauncher> mHelperAppLauncher; - - PRFloat64 mPriorKRate; - PRInt32 mRateChanges; - PRInt32 mRateChangeLimit; - PRInt64 mLastUpdate; - PRInt32 mInterval; + + EphyDownload *mEphyDownload; DownloaderView *mDownloaderView; - // static ADownloadProgressView *sProgressView; + MozillaEmbedPersist *mEmbedPersist; + EphyDownloadState mDownloadState; }; -//***************************************************************************** -// 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__ +#endif // MozDownload_h__ diff --git a/embed/mozilla/MozRegisterComponents.cpp b/embed/mozilla/MozRegisterComponents.cpp index 29079aff2..ee2ac999b 100644 --- a/embed/mozilla/MozRegisterComponents.cpp +++ b/embed/mozilla/MozRegisterComponents.cpp @@ -25,7 +25,7 @@ #include "GlobalHistory.h" #include "ExternalProtocolHandlers.h" #include "PrintingPromptService.h" -#include "ProgressListener.h" +#include "MozDownload.h" #include "ExternalProtocolService.h" #include "EphyAboutRedirector.h" @@ -41,7 +41,7 @@ #include <glib.h> NS_GENERIC_FACTORY_CONSTRUCTOR(EphyAboutRedirector) -NS_GENERIC_FACTORY_CONSTRUCTOR(GProgressListener) +NS_GENERIC_FACTORY_CONSTRUCTOR(MozDownload) NS_GENERIC_FACTORY_CONSTRUCTOR(GFilePicker) NS_GENERIC_FACTORY_CONSTRUCTOR(GContentHandler) NS_GENERIC_FACTORY_CONSTRUCTOR(MozGlobalHistory) @@ -63,16 +63,10 @@ static const nsModuleComponentInfo sAppComps[] = { GExternalProtocolServiceConstructor }, { - G_PROGRESSDIALOG_CLASSNAME, - G_PROGRESSDIALOG_CID, - G_PROGRESSDIALOG_CONTRACTID, - GProgressListenerConstructor - }, - { - G_PROGRESSDIALOG_CLASSNAME, - G_PROGRESSDIALOG_CID, + MOZ_DOWNLOAD_CLASSNAME, + MOZ_DOWNLOAD_CID, NS_DOWNLOAD_CONTRACTID, - GProgressListenerConstructor + MozDownloadConstructor }, { G_FILEPICKER_CLASSNAME, diff --git a/embed/mozilla/ProgressListener.cpp b/embed/mozilla/ProgressListener.cpp deleted file mode 100644 index 433b2234c..000000000 --- a/embed/mozilla/ProgressListener.cpp +++ /dev/null @@ -1,648 +0,0 @@ -/* - * 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 deleted file mode 100644 index 1c6cf6689..000000000 --- a/embed/mozilla/ProgressListener.h +++ /dev/null @@ -1,131 +0,0 @@ -/* - * 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-download.cpp b/embed/mozilla/mozilla-download.cpp new file mode 100644 index 000000000..bb60cd0e6 --- /dev/null +++ b/embed/mozilla/mozilla-download.cpp @@ -0,0 +1,203 @@ +/* + * Copyright (C) 2003 Xan Lopez + * + * 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$ + */ + +#include "mozilla-download.h" + +#include "nsString.h" + +static void +mozilla_download_class_init (MozillaDownloadClass *klass); +static void +mozilla_download_init (MozillaDownload *ges); +static void +mozilla_download_finalize (GObject *object); + +static GObjectClass *parent_class = NULL; + +GType +mozilla_download_get_type (void) +{ + static GType mozilla_download_type = 0; + + if (mozilla_download_type == 0) + { + static const GTypeInfo our_info = + { + sizeof (MozillaDownloadClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) mozilla_download_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (MozillaDownload), + 0, /* n_preallocs */ + (GInstanceInitFunc) mozilla_download_init + }; + + mozilla_download_type = + g_type_register_static (EPHY_TYPE_DOWNLOAD, + "MozillaDownload", + &our_info, (GTypeFlags)0); + } + + return mozilla_download_type; +} + +static char * +impl_get_source (EphyDownload *download) +{ + nsCOMPtr<nsILocalFile> targetFile; + MozDownload *mozDownload; + + mozDownload = MOZILLA_DOWNLOAD (download)->moz_download; + + mozDownload->GetTarget (getter_AddRefs (targetFile)); + + nsCAutoString tempPathStr; + targetFile->GetNativePath (tempPathStr); + + return g_strdup (tempPathStr.get ()); +} + +static char * +impl_get_target (EphyDownload *download) +{ + nsCOMPtr<nsIURI> uri; + MozDownload *mozDownload; + nsCString spec; + + mozDownload = MOZILLA_DOWNLOAD (download)->moz_download; + + mozDownload->GetSource (getter_AddRefs (uri)); + uri->GetSpec (spec); + + return g_strdup (spec.get()); +} + +static long +impl_get_current_progress (EphyDownload *download) +{ + MozDownload *mozDownload; + PRInt32 progress; + + mozDownload = MOZILLA_DOWNLOAD (download)->moz_download; + + mozDownload->GetCurrentProgress (&progress); + + return progress; +} + +static EphyDownloadState +impl_get_state (EphyDownload *download) +{ + MozDownload *mozDownload; + EphyDownloadState state; + + mozDownload = MOZILLA_DOWNLOAD (download)->moz_download; + + mozDownload->GetState (&state); + + return state; +} + +static long +impl_get_total_progress (EphyDownload *download) +{ + MozDownload *mozDownload; + PRInt32 progress; + + mozDownload = MOZILLA_DOWNLOAD (download)->moz_download; + + mozDownload->GetTotalProgress (&progress); + + return progress; +} + +static int +impl_get_percent (EphyDownload *download) +{ + MozDownload *mozDownload; + PRInt32 percent; + + mozDownload = MOZILLA_DOWNLOAD (download)->moz_download; + + mozDownload->GetPercentComplete (&percent); + + return percent; +} + +static long +impl_get_elapsed_time (EphyDownload *download) +{ + MozDownload *mozDownload; + PRInt64 elapsed; + + mozDownload = MOZILLA_DOWNLOAD (download)->moz_download; + + mozDownload->GetElapsedTime (&elapsed); + + return elapsed / 1000000; +} + +static void +impl_cancel (EphyDownload *download) +{ + MOZILLA_DOWNLOAD (download)->moz_download->Cancel (); +} + +static void +impl_pause (EphyDownload *download) +{ +} + +static void +impl_resume (EphyDownload *download) +{ +} + +static void +mozilla_download_class_init (MozillaDownloadClass *klass) +{ + EphyDownloadClass *download_class = EPHY_DOWNLOAD_CLASS (klass); + + parent_class = (GObjectClass *) g_type_class_peek_parent (klass); + + download_class->get_elapsed_time = impl_get_elapsed_time; + download_class->get_current_progress = impl_get_current_progress; + download_class->get_total_progress = impl_get_total_progress; + download_class->get_percent = impl_get_percent; + download_class->get_target = impl_get_target; + download_class->get_source = impl_get_source; + download_class->get_state = impl_get_state; + download_class->cancel = impl_cancel; + download_class->pause = impl_pause; + download_class->resume = impl_resume; +} + +static void +mozilla_download_init (MozillaDownload *view) +{ +} + +EphyDownload * +mozilla_download_new (void) +{ + return EPHY_DOWNLOAD (g_object_new (MOZILLA_TYPE_DOWNLOAD, NULL)); +} diff --git a/embed/mozilla/mozilla-download.h b/embed/mozilla/mozilla-download.h new file mode 100644 index 000000000..3d92cc24d --- /dev/null +++ b/embed/mozilla/mozilla-download.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2000, 2001, 2002 Marco Pesenti Gritti + * + * 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 MOZILLA_DOWNLOAD_H +#define MOZILLA_DOWNLOAD_H + +#include "MozDownload.h" + +#include <glib-object.h> +#include <glib.h> + +G_BEGIN_DECLS + +#define MOZILLA_TYPE_DOWNLOAD (mozilla_download_get_type ()) +#define MOZILLA_DOWNLOAD(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MOZILLA_TYPE_DOWNLOAD, MozillaDownload)) +#define MOZILLA_DOWNLOAD_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MOZILLA_TYPE_DOWNLOAD, MozillaDownloadClass)) +#define MOZILLA_IS_DOWNLOAD(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MOZILLA_TYPE_DOWNLOAD)) +#define MOZILLA_IS_DOWNLOAD_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MOZILLA_TYPE_DOWNLOAD)) +#define MOZILLA_DOWNLOAD_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MOZILLA_TYPE_DOWNLOAD, MozillaDownloadClass)) + +typedef struct MozillaDownloadClass MozillaDownloadClass; +typedef struct MozillaDownload MozillaDownload; +typedef struct MozillaDownloadPrivate MozillaDownloadPrivate; + +struct MozillaDownload +{ + EphyDownload parent; + MozDownload *moz_download; +}; + +struct MozillaDownloadClass +{ + EphyDownloadClass parent_class; +}; + +GType mozilla_download_get_type (void); + +EphyDownload *mozilla_download_new (void); + +G_END_DECLS + +#endif diff --git a/embed/mozilla/mozilla-embed-persist.cpp b/embed/mozilla/mozilla-embed-persist.cpp index 7e120935b..8906a68f1 100644 --- a/embed/mozilla/mozilla-embed-persist.cpp +++ b/embed/mozilla/mozilla-embed-persist.cpp @@ -18,8 +18,8 @@ * $Id$ */ -#include "ProgressListener.h" #include "EphyWrapper.h" +#include "EphyHeaderSniffer.h" #include "mozilla-embed.h" #include "mozilla-embed-persist.h" @@ -28,6 +28,8 @@ #include <nsString.h> #include <nsCWebBrowserPersist.h> #include <nsNetUtil.h> +#include <nsIHistoryEntry.h> +#include <nsISHEntry.h> static void mozilla_embed_persist_class_init (MozillaEmbedPersistClass *klass); @@ -46,7 +48,7 @@ impl_cancel (EphyEmbedPersist *persist); struct MozillaEmbedPersistPrivate { nsCOMPtr<nsIWebBrowserPersist> mPersist; - GProgressListener *mProgress; +// GProgressListener *mProgress; }; static GObjectClass *parent_class = NULL; @@ -109,7 +111,6 @@ mozilla_embed_persist_finalize (GObject *object) { MozillaEmbedPersist *persist = MOZILLA_EMBED_PERSIST (object); - persist->priv->mPersist->SetProgressListener (nsnull); persist->priv->mPersist = nsnull; G_OBJECT_CLASS (parent_class)->finalize (object); @@ -152,9 +153,10 @@ impl_save (EphyEmbedPersist *persist) int max_size; EphyEmbed *embed; EmbedPersistFlags flags; - EphyWrapper *wrapper = NULL; PRUint32 persistFlags = 0; + /* FIXME implement max size */ + g_object_ref (persist); g_object_get (persist, @@ -167,76 +169,48 @@ impl_save (EphyEmbedPersist *persist) g_return_val_if_fail (filename != NULL, G_FAILED); - nsCOMPtr<nsIWebBrowserPersist> bpersist = + nsCOMPtr<nsIWebBrowserPersist> webPersist = MOZILLA_EMBED_PERSIST (persist)->priv->mPersist; - if (!bpersist) return G_FAILED; - - nsCOMPtr<nsIURI> linkURI; - linkURI = nsnull; + if (!webPersist) return G_FAILED; + + /* Get a temp filename to save to */ + nsCOMPtr<nsIProperties> dirService(do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv)); + if (!dirService) return G_FAILED; + nsCOMPtr<nsIFile> tmpFile; + dirService->Get("TmpD", NS_GET_IID(nsIFile), getter_AddRefs(tmpFile)); + static short unsigned int tmpRandom = 0; + nsAutoString tmpNo; + tmpNo.AppendInt(tmpRandom++); + nsAutoString saveFile(NS_LITERAL_STRING("-sav")); + saveFile += tmpNo; + saveFile += NS_LITERAL_STRING("tmp"); + tmpFile->Append(saveFile); + + /* Get the uri to save to */ + nsCOMPtr<nsIURI> inURI; if (uri) { + nsAutoString s; s.AssignWithConversion(uri); - rv = NS_NewURI(getter_AddRefs(linkURI), s); - if (NS_FAILED(rv) || !linkURI) return G_FAILED; - } - - nsCOMPtr<nsILocalFile> file; - rv = NS_NewLocalFile(NS_ConvertUTF8toUCS2(filename), PR_TRUE, getter_AddRefs(file)); - if (NS_FAILED(rv) || !file) return G_FAILED; - - nsCOMPtr<nsILocalFile> path; - if (flags & EMBED_PERSIST_SAVE_CONTENT) - { - char *datapath; - datapath = g_strconcat (filename, ".content", NULL); - NS_NewLocalFile(NS_ConvertUTF8toUCS2(datapath), PR_TRUE, getter_AddRefs(path)); - g_free (datapath); - } - else - { - path = nsnull; - } - - nsCOMPtr<nsIDOMWindow> parent; - parent = nsnull; - - if (embed) - { - wrapper = (EphyWrapper *) mozilla_embed_get_ephy_wrapper (MOZILLA_EMBED(embed)); - g_return_val_if_fail (wrapper != NULL, G_FAILED); - wrapper->GetDOMWindow (getter_AddRefs (parent)); - } - - persistFlags = nsIWebBrowserPersist::PERSIST_FLAGS_REPLACE_EXISTING_FILES; - - size_t len = strlen(filename); - if((filename[len-1] == 'z' && filename[len-2] == 'g') || - (filename[len-1] == 'Z' && filename[len-2] == 'G')) - { - persistFlags |= nsIWebBrowserPersist::PERSIST_FLAGS_NO_CONVERSION; + rv = NS_NewURI(getter_AddRefs(inURI), s); + if (NS_FAILED(rv) || !inURI) return G_FAILED; } - if (flags & EMBED_PERSIST_BYPASSCACHE) - { - persistFlags |= nsIWebBrowserPersist::PERSIST_FLAGS_BYPASS_CACHE; - } + /* Filename to save to */ + nsAutoString inFilename; + inFilename.AssignWithConversion (filename); - if (flags & EMBED_PERSIST_FROMCACHE) + nsCOMPtr<nsIDOMDocument> DOMDocument; + nsCOMPtr<nsIInputStream> postData; + if (!uri) { - persistFlags |= nsIWebBrowserPersist::PERSIST_FLAGS_FROM_CACHE; - } - - bpersist->SetPersistFlags (persistFlags); + EphyWrapper *wrapper; - GProgressListener *aProgress = new GProgressListener (); - MOZILLA_EMBED_PERSIST (persist)->priv->mProgress = aProgress; - - if (uri == NULL) - { + g_return_val_if_fail (embed != NULL, G_FAILED); + wrapper = (EphyWrapper *) mozilla_embed_get_ephy_wrapper (MOZILLA_EMBED(embed)); g_return_val_if_fail (wrapper != NULL, G_FAILED); - nsCOMPtr<nsIDOMDocument> DOMDocument; - + /* Get the DOM document */ if (flags & EMBED_PERSIST_MAINDOC) { rv = wrapper->GetMainDOMDocument (getter_AddRefs(DOMDocument)); @@ -247,35 +221,32 @@ impl_save (EphyEmbedPersist *persist) } if (NS_FAILED(rv) || !DOMDocument) return G_FAILED; - nsCOMPtr<nsIDocument> document = - do_QueryInterface (DOMDocument, &rv); - if (NS_FAILED(rv) || !document) return G_FAILED; - - nsCOMPtr<nsIURI> uri; - rv = document->GetDocumentURL (getter_AddRefs(uri)); - if (NS_FAILED(rv) || !uri) return G_FAILED; + nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(wrapper->mWebBrowser)); + nsCOMPtr<nsISHistory> sessionHistory; + webNav->GetSessionHistory(getter_AddRefs(sessionHistory)); + nsCOMPtr<nsIHistoryEntry> entry; + + /* Get post data */ + PRInt32 sindex; + sessionHistory->GetIndex(&sindex); + sessionHistory->GetEntryAtIndex(sindex, PR_FALSE, getter_AddRefs(entry)); + nsCOMPtr<nsISHEntry> shEntry(do_QueryInterface(entry)); + if (shEntry) + { + shEntry->GetPostData(getter_AddRefs(postData)); + } + } - aProgress->InitForPersist (bpersist, parent, - uri, file, - ACTION_OBJECT_NOTIFY, - persist, - (flags & EMBED_PERSIST_SHOW_PROGRESS)); + EphyHeaderSniffer* sniffer = new EphyHeaderSniffer + (webPersist, MOZILLA_EMBED_PERSIST (persist), + tmpFile, inURI, DOMDocument, postData, + inFilename, flags & EMBED_PERSIST_BYPASSCACHE); + if (!sniffer) return G_FAILED; + + webPersist->SetProgressListener(sniffer); + + rv = webPersist->SaveURI(inURI, nsnull, nsnull, nsnull, nsnull, tmpFile); + if (NS_FAILED (rv)) return G_FAILED; - rv = bpersist->SaveDocument (DOMDocument, file, path, nsnull, 0, 0); - if (NS_FAILED(rv)) return G_FAILED; - } - else - { - aProgress->InitForPersist (bpersist, parent, - linkURI, file, - ACTION_OBJECT_NOTIFY, - persist, - (flags & EMBED_PERSIST_SHOW_PROGRESS)); - - rv = bpersist->SaveURI (linkURI, nsnull, nsnull, nsnull, nsnull, file); - if (NS_FAILED(rv)) return G_FAILED; - } - return G_OK; } - |