aboutsummaryrefslogtreecommitdiffstats
path: root/embed/mozilla
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@gnome.org>2003-10-19 17:53:50 +0800
committerMarco Pesenti Gritti <marco@src.gnome.org>2003-10-19 17:53:50 +0800
commitffba6a5ae788b7c8ad83809a944907caa7a8fe84 (patch)
treedb6f0f070124b950f7ed6109b2ff0ba477e6eafd /embed/mozilla
parent80f66913e794ce851a9e38145fd2f0cf0ca7dd31 (diff)
downloadgsoc2013-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')
-rw-r--r--embed/mozilla/EphyHeaderSniffer.cpp260
-rw-r--r--embed/mozilla/EphyHeaderSniffer.h45
-rw-r--r--embed/mozilla/mozilla-download.cpp4
3 files changed, 161 insertions, 148 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,
diff --git a/embed/mozilla/EphyHeaderSniffer.h b/embed/mozilla/EphyHeaderSniffer.h
index 01f5b7bd8..b8d56281d 100644
--- a/embed/mozilla/EphyHeaderSniffer.h
+++ b/embed/mozilla/EphyHeaderSniffer.h
@@ -48,38 +48,35 @@
#include "nsIAuthPrompt.h"
#include "nsIPromptService.h"
-// Implementation of a header sniffer class that is used when saving Web pages and images.
class EphyHeaderSniffer : public nsIWebProgressListener,
public nsIAuthPrompt
{
public:
- EphyHeaderSniffer(nsIWebBrowserPersist* aPersist, MozillaEmbedPersist *aEmbedPersist,
- nsIFile* aFile, nsIURI* aURL,
- nsIDOMDocument* aDocument, nsIInputStream* aPostData,
- const nsAString& aSuggestedFilename, PRBool aBypassCache);
- virtual ~EphyHeaderSniffer();
+ EphyHeaderSniffer (nsIWebBrowserPersist* aPersist, MozillaEmbedPersist *aEmbedPersist,
+ nsIFile* aFile, nsIURI* aURL,
+ nsIDOMDocument* aDocument, nsIInputStream* aPostData,
+ const nsAString& aSuggestedFilename, PRBool aBypassCache);
+ virtual ~EphyHeaderSniffer ();
- NS_DECL_ISUPPORTS
- NS_DECL_NSIWEBPROGRESSLISTENER
- NS_DECL_NSIAUTHPROMPT
+ NS_DECL_ISUPPORTS
+ NS_DECL_NSIWEBPROGRESSLISTENER
+ NS_DECL_NSIAUTHPROMPT
protected:
-
- nsresult PerformSave(nsIURI* inOriginalURI);
- nsresult InitiateDownload(nsISupports* inSourceData, nsILocalFile* inDestFile, nsIURI* inOriginalURI);
+ 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;
- nsCString mContentType;
- nsCString mContentDisposition;
- nsCOMPtr<nsIPromptService> mPrompt;
+ 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;
+ nsCString mContentType;
+ nsCString mContentDisposition;
+ nsCOMPtr<nsIPromptService> mPrompt;
};
diff --git a/embed/mozilla/mozilla-download.cpp b/embed/mozilla/mozilla-download.cpp
index bb60cd0e6..d970264fe 100644
--- a/embed/mozilla/mozilla-download.cpp
+++ b/embed/mozilla/mozilla-download.cpp
@@ -61,7 +61,7 @@ mozilla_download_get_type (void)
}
static char *
-impl_get_source (EphyDownload *download)
+impl_get_target (EphyDownload *download)
{
nsCOMPtr<nsILocalFile> targetFile;
MozDownload *mozDownload;
@@ -77,7 +77,7 @@ impl_get_source (EphyDownload *download)
}
static char *
-impl_get_target (EphyDownload *download)
+impl_get_source (EphyDownload *download)
{
nsCOMPtr<nsIURI> uri;
MozDownload *mozDownload;