diff options
author | Marco Pesenti Gritti <marco@gnome.org> | 2003-10-19 17:53:50 +0800 |
---|---|---|
committer | Marco Pesenti Gritti <marco@src.gnome.org> | 2003-10-19 17:53:50 +0800 |
commit | ffba6a5ae788b7c8ad83809a944907caa7a8fe84 (patch) | |
tree | db6f0f070124b950f7ed6109b2ff0ba477e6eafd /embed/mozilla/EphyHeaderSniffer.cpp | |
parent | 80f66913e794ce851a9e38145fd2f0cf0ca7dd31 (diff) | |
download | gsoc2013-epiphany-ffba6a5ae788b7c8ad83809a944907caa7a8fe84.tar gsoc2013-epiphany-ffba6a5ae788b7c8ad83809a944907caa7a8fe84.tar.gz gsoc2013-epiphany-ffba6a5ae788b7c8ad83809a944907caa7a8fe84.tar.bz2 gsoc2013-epiphany-ffba6a5ae788b7c8ad83809a944907caa7a8fe84.tar.lz gsoc2013-epiphany-ffba6a5ae788b7c8ad83809a944907caa7a8fe84.tar.xz gsoc2013-epiphany-ffba6a5ae788b7c8ad83809a944907caa7a8fe84.tar.zst gsoc2013-epiphany-ffba6a5ae788b7c8ad83809a944907caa7a8fe84.zip |
Update remaning time every two seconds
2003-10-19 Marco Pesenti Gritti <marco@gnome.org>
* TODO:
* embed/ephy-download.c: (ephy_download_class_init),
(ephy_download_init), (update_remaining_time),
(ephy_download_get_remaining_time):
* embed/ephy-download.h:
Update remaning time every two seconds
* embed/mozilla/mozilla-download.cpp:
Source/target was swapped
* embed/mozilla/EphyHeaderSniffer.cpp:
* embed/mozilla/EphyHeaderSniffer.h:
Fix style
Diffstat (limited to 'embed/mozilla/EphyHeaderSniffer.cpp')
-rw-r--r-- | embed/mozilla/EphyHeaderSniffer.cpp | 260 |
1 files changed, 138 insertions, 122 deletions
diff --git a/embed/mozilla/EphyHeaderSniffer.cpp b/embed/mozilla/EphyHeaderSniffer.cpp index 407967b87..efeb90e4a 100644 --- a/embed/mozilla/EphyHeaderSniffer.cpp +++ b/embed/mozilla/EphyHeaderSniffer.cpp @@ -53,7 +53,7 @@ const char* const persistContractID = "@mozilla.org/embedding/browser/nsWebBrowserPersist;1"; -EphyHeaderSniffer::EphyHeaderSniffer(nsIWebBrowserPersist* aPersist, MozillaEmbedPersist *aEmbedPersist, +EphyHeaderSniffer::EphyHeaderSniffer (nsIWebBrowserPersist* aPersist, MozillaEmbedPersist *aEmbedPersist, nsIFile* aFile, nsIURI* aURL, nsIDOMDocument* aDocument, nsIInputStream* aPostData, const nsAString& aSuggestedFilename, PRBool aBypassCache) : mPersist(aPersist) @@ -74,86 +74,87 @@ EphyHeaderSniffer::~EphyHeaderSniffer() NS_IMPL_ISUPPORTS2(EphyHeaderSniffer, nsIWebProgressListener, nsIAuthPrompt) -// Implementation of nsIWebProgressListener -/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aStateFlags, in unsigned long aStatus); */ NS_IMETHODIMP -EphyHeaderSniffer::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 aStateFlags, - PRUint32 aStatus) +EphyHeaderSniffer::OnStateChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 aStateFlags, + PRUint32 aStatus) { - if (aStateFlags & nsIWebProgressListener::STATE_START) - { - nsCOMPtr<nsIWebBrowserPersist> kungFuDeathGrip(mPersist); // be sure to keep it alive while we save - // since it owns us as a listener - nsCOMPtr<nsIWebProgressListener> kungFuSuicideGrip(this); // and keep ourselves alive + if (aStateFlags & nsIWebProgressListener::STATE_START) + { + /* be sure to keep it alive while we save since it owns + us as a listener and keep ourselves alive */ + nsCOMPtr<nsIWebBrowserPersist> kungFuDeathGrip(mPersist); + nsCOMPtr<nsIWebProgressListener> kungFuSuicideGrip(this); - nsresult rv; - nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest, &rv); - if (!channel) return rv; - channel->GetContentType(mContentType); + nsresult rv; + nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest, &rv); + if (!channel) return rv; + channel->GetContentType(mContentType); - nsCOMPtr<nsIURI> origURI; - channel->GetOriginalURI(getter_AddRefs(origURI)); + nsCOMPtr<nsIURI> origURI; + channel->GetOriginalURI(getter_AddRefs(origURI)); - // Get the content-disposition if we're an HTTP channel. - nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel)); - if (httpChannel) - httpChannel->GetResponseHeader(nsCAutoString("content-disposition"), mContentDisposition); + nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel)); + if (httpChannel) + { + httpChannel->GetResponseHeader(nsCAutoString("content-disposition"), + mContentDisposition); + } - mPersist->CancelSave(); - PRBool exists; - mTmpFile->Exists(&exists); - if (exists) - mTmpFile->Remove(PR_FALSE); - - rv = PerformSave(origURI); - if (NS_FAILED(rv)) - { - // put up some UI + mPersist->CancelSave(); + + PRBool exists; + mTmpFile->Exists(&exists); + if (exists) + { + mTmpFile->Remove(PR_FALSE); + } + + rv = PerformSave(origURI); + if (NS_FAILED(rv)) + { + /* FIXME put up some UI */ - } - } - 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 -EphyHeaderSniffer::OnProgressChange(nsIWebProgress *aWebProgress, - nsIRequest *aRequest, - PRInt32 aCurSelfProgress, - PRInt32 aMaxSelfProgress, - PRInt32 aCurTotalProgress, - PRInt32 aMaxTotalProgress) +EphyHeaderSniffer::OnProgressChange (nsIWebProgress *aWebProgress, + nsIRequest *aRequest, + PRInt32 aCurSelfProgress, + PRInt32 aMaxSelfProgress, + PRInt32 aCurTotalProgress, + PRInt32 aMaxTotalProgress) { - return NS_OK; + return NS_OK; } -/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */ NS_IMETHODIMP -EphyHeaderSniffer::OnLocationChange(nsIWebProgress *aWebProgress, - nsIRequest *aRequest, - nsIURI *location) +EphyHeaderSniffer::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 -EphyHeaderSniffer::OnStatusChange(nsIWebProgress *aWebProgress, - nsIRequest *aRequest, - nsresult aStatus, - const PRUnichar *aMessage) +EphyHeaderSniffer::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 -EphyHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 state) +EphyHeaderSniffer::OnSecurityChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 state) { - return NS_OK; + return NS_OK; } -nsresult EphyHeaderSniffer::PerformSave(nsIURI* inOriginalURI) +nsresult EphyHeaderSniffer::PerformSave (nsIURI* inOriginalURI) { nsresult rv; @@ -167,90 +168,105 @@ nsresult EphyHeaderSniffer::PerformSave(nsIURI* inOriginalURI) nsCOMPtr<nsISupports> sourceData; if (isHTML) + { sourceData = do_QueryInterface(mDocument); + } else + { sourceData = do_QueryInterface(mURL); + } return InitiateDownload(sourceData, file, inOriginalURI); } -// inOriginalURI is always a URI. inSourceData can be an nsIURI or an nsIDOMDocument, depending -// on what we're saving. It's that way for nsIWebBrowserPersist. -nsresult EphyHeaderSniffer::InitiateDownload(nsISupports* inSourceData, nsILocalFile* inDestFile, nsIURI* inOriginalURI) +nsresult EphyHeaderSniffer::InitiateDownload (nsISupports* inSourceData, nsILocalFile* inDestFile, + nsIURI* inOriginalURI) { - nsresult rv = NS_OK; + nsresult rv = NS_OK; - nsCOMPtr<nsIWebBrowserPersist> webPersist = do_CreateInstance(persistContractID, &rv); - if (NS_FAILED(rv)) return rv; + nsCOMPtr<nsIWebBrowserPersist> webPersist = do_CreateInstance(persistContractID, &rv); + if (NS_FAILED(rv)) return rv; - nsCOMPtr<nsIURI> sourceURI = do_QueryInterface(inSourceData); + nsCOMPtr<nsIURI> sourceURI = do_QueryInterface(inSourceData); - PRInt64 timeNow = PR_Now(); - - nsAutoString fileDisplayName; - inDestFile->GetLeafName(fileDisplayName); + PRInt64 timeNow = PR_Now(); - MozDownload *downloader = new MozDownload (); - // dlListener attaches to its progress dialog here, which gains ownership - 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) - flags |= nsIWebBrowserPersist::PERSIST_FLAGS_BYPASS_CACHE; - else - flags |= nsIWebBrowserPersist::PERSIST_FLAGS_FROM_CACHE; - - webPersist->SetPersistFlags(flags); + nsAutoString fileDisplayName; + inDestFile->GetLeafName(fileDisplayName); + + MozDownload *downloader = new MozDownload (); + /* dlListener attaches to its progress dialog here, which gains ownership */ + 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) + { + flags |= nsIWebBrowserPersist::PERSIST_FLAGS_BYPASS_CACHE; + } + else + { + flags |= nsIWebBrowserPersist::PERSIST_FLAGS_FROM_CACHE; + } + + webPersist->SetPersistFlags(flags); - if (sourceURI) - { - rv = webPersist->SaveURI(sourceURI, nsnull, nsnull, mPostData, nsnull, inDestFile); - } - else - { - nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(inSourceData, &rv); - if (!domDoc) return rv; // should never happen + if (sourceURI) + { + rv = webPersist->SaveURI (sourceURI, nsnull, nsnull, + mPostData, nsnull, inDestFile); + } + else + { + nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(inSourceData, &rv); + if (!domDoc) return rv; /* should never happen */ - PRInt32 encodingFlags = 0; - nsCOMPtr<nsILocalFile> filesFolder; + PRInt32 encodingFlags = 0; + nsCOMPtr<nsILocalFile> filesFolder; - if (!mContentType.Equals("text/plain")) { - // Create a local directory in the same dir as our file. It - // will hold our associated files. - filesFolder = do_CreateInstance("@mozilla.org/file/local;1"); - nsAutoString unicodePath; - inDestFile->GetPath(unicodePath); - filesFolder->InitWithPath(unicodePath); + if (!mContentType.Equals("text/plain")) + { + /* Create a local directory in the same dir as our file. It + will hold our associated files. */ + + filesFolder = do_CreateInstance("@mozilla.org/file/local;1"); + nsAutoString unicodePath; + inDestFile->GetPath(unicodePath); + filesFolder->InitWithPath(unicodePath); - nsAutoString leafName; - filesFolder->GetLeafName(leafName); - nsAutoString nameMinusExt(leafName); - PRInt32 index = nameMinusExt.RFind("."); - if (index >= 0) - nameMinusExt.Left(nameMinusExt, index); - nameMinusExt += NS_LITERAL_STRING(" Files"); // XXXdwh needs to be localizable! - filesFolder->SetLeafName(nameMinusExt); - PRBool exists = PR_FALSE; - filesFolder->Exists(&exists); - if (!exists) { - rv = filesFolder->Create(nsILocalFile::DIRECTORY_TYPE, 0755); - if (NS_FAILED(rv)) - return rv; - } - } - else - { - encodingFlags |= nsIWebBrowserPersist::ENCODE_FLAGS_FORMATTED | - nsIWebBrowserPersist::ENCODE_FLAGS_ABSOLUTE_LINKS | - nsIWebBrowserPersist::ENCODE_FLAGS_NOFRAMES_CONTENT; - } - rv = webPersist->SaveDocument(domDoc, inDestFile, filesFolder, mContentType.get(), encodingFlags, 80); - } + nsAutoString leafName; + filesFolder->GetLeafName(leafName); + nsAutoString nameMinusExt(leafName); + PRInt32 index = nameMinusExt.RFind("."); + if (index >= 0) + { + nameMinusExt.Left(nameMinusExt, index); + } + + nameMinusExt += NS_LITERAL_STRING(" Files"); + filesFolder->SetLeafName(nameMinusExt); + PRBool exists = PR_FALSE; + filesFolder->Exists(&exists); + if (!exists) + { + rv = filesFolder->Create(nsILocalFile::DIRECTORY_TYPE, 0755); + if (NS_FAILED(rv)) return rv; + } + } + else + { + encodingFlags |= nsIWebBrowserPersist::ENCODE_FLAGS_FORMATTED | + nsIWebBrowserPersist::ENCODE_FLAGS_ABSOLUTE_LINKS | + nsIWebBrowserPersist::ENCODE_FLAGS_NOFRAMES_CONTENT; + } + + rv = webPersist->SaveDocument (domDoc, inDestFile, filesFolder, + mContentType.get(), encodingFlags, 80); + } - return rv; + return rv; } NS_IMETHODIMP EphyHeaderSniffer::Prompt (const PRUnichar *dialogTitle, const PRUnichar *text, |