Bug 228603 nsIWebBrowserPersist should have a saveChannel method
r=adamlock sr=darin
This commit is contained in:
Родитель
1d4bf35781
Коммит
9b90f640dd
|
@ -1009,6 +1009,40 @@ NS_IMETHODIMP nsWebBrowser::SaveURI(
|
|||
return rv;
|
||||
}
|
||||
|
||||
/* void saveChannel (in nsIChannel aChannel, in nsISupports aFile); */
|
||||
NS_IMETHODIMP nsWebBrowser::SaveChannel(
|
||||
nsIChannel* aChannel, nsISupports *aFile)
|
||||
{
|
||||
if (mPersist)
|
||||
{
|
||||
PRUint32 currentState;
|
||||
mPersist->GetCurrentState(¤tState);
|
||||
if (currentState == PERSIST_STATE_FINISHED)
|
||||
{
|
||||
mPersist = nsnull;
|
||||
}
|
||||
else
|
||||
{
|
||||
// You can't save again until the last save has completed
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
// Create a throwaway persistence object to do the work
|
||||
nsresult rv;
|
||||
mPersist = do_CreateInstance(NS_WEBBROWSERPERSIST_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
mPersist->SetProgressListener(this);
|
||||
mPersist->SetPersistFlags(mPersistFlags);
|
||||
mPersist->GetCurrentState(&mPersistCurrentState);
|
||||
rv = mPersist->SaveChannel(aChannel, aFile);
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
mPersist = nsnull;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* void saveDocument (in nsIDOMDocument document, in nsISupports aFile, in nsISupports aDataPath); */
|
||||
NS_IMETHODIMP nsWebBrowser::SaveDocument(
|
||||
nsIDOMDocument *aDocument, nsISupports *aFile, nsISupports *aDataPath,
|
||||
|
|
|
@ -44,6 +44,7 @@ interface nsIInputStream;
|
|||
interface nsIDOMDocument;
|
||||
interface nsIWebProgressListener;
|
||||
interface nsILocalFile;
|
||||
interface nsIChannel;
|
||||
|
||||
/**
|
||||
* @status UNDER_REVIEW
|
||||
|
@ -52,7 +53,7 @@ interface nsILocalFile;
|
|||
/**
|
||||
* Interface for persisting DOM documents and URIs to local or remote storage.
|
||||
*/
|
||||
[scriptable, uuid(814ba433-a816-4785-9f95-ad3ba0a43dab)]
|
||||
[scriptable, uuid(1c2a6fac-c100-4c67-95d3-281736038700)]
|
||||
interface nsIWebBrowserPersist : nsISupports
|
||||
{
|
||||
/** No special persistence behaviour. */
|
||||
|
@ -160,6 +161,12 @@ interface nsIWebBrowserPersist : nsISupports
|
|||
in nsIURI aReferrer, in nsIInputStream aPostData,
|
||||
in string aExtraHeaders, in nsISupports aFile);
|
||||
|
||||
/**
|
||||
* Save a channel to a file. It must not be opened yet.
|
||||
* @see saveURI
|
||||
*/
|
||||
void saveChannel(in nsIChannel aChannel, in nsISupports aFile);
|
||||
|
||||
/** Output only the current selection as opposed to the whole document. */
|
||||
const unsigned long ENCODE_FLAGS_SELECTION_ONLY = 1;
|
||||
/**
|
||||
|
|
|
@ -388,6 +388,28 @@ NS_IMETHODIMP nsWebBrowserPersist::SaveURI(
|
|||
return NS_FAILED(rv) ? rv : NS_OK;
|
||||
}
|
||||
|
||||
/* void saveChannel (in nsIChannel aChannel, in nsISupports aFile); */
|
||||
NS_IMETHODIMP nsWebBrowserPersist::SaveChannel(
|
||||
nsIChannel *aChannel, nsISupports *aFile)
|
||||
{
|
||||
NS_ENSURE_TRUE(mFirstAndOnlyUse, NS_ERROR_FAILURE);
|
||||
mFirstAndOnlyUse = PR_FALSE; // Stop people from reusing this object!
|
||||
|
||||
nsCOMPtr<nsIURI> fileAsURI;
|
||||
nsresult rv;
|
||||
rv = GetValidURIFromObject(aFile, getter_AddRefs(fileAsURI));
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_INVALID_ARG);
|
||||
|
||||
rv = aChannel->GetURI(getter_AddRefs(mURI));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// SaveURI doesn't like broken uris.
|
||||
mPersistFlags |= PERSIST_FLAGS_FAIL_ON_BROKEN_LINKS;
|
||||
rv = SaveChannelInternal(aChannel, fileAsURI, PR_FALSE);
|
||||
return NS_FAILED(rv) ? rv : NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/* void saveDocument (in nsIDOMDocument aDocument, in nsIURI aFileURI,
|
||||
in nsIURI aDataPathURI, in string aOutputContentType,
|
||||
in unsigned long aEncodingFlags, in unsigned long aWrapColumn); */
|
||||
|
@ -1238,9 +1260,17 @@ nsresult nsWebBrowserPersist::SaveURIInternal(
|
|||
}
|
||||
}
|
||||
}
|
||||
return SaveChannelInternal(inputChannel, aFile, aCalcFileExt);
|
||||
}
|
||||
|
||||
nsresult nsWebBrowserPersist::SaveChannelInternal(
|
||||
nsIChannel *aChannel, nsIURI *aFile, PRBool aCalcFileExt)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aChannel);
|
||||
NS_ENSURE_ARG_POINTER(aFile);
|
||||
|
||||
// Read from the input channel
|
||||
rv = inputChannel->AsyncOpen(this, nsnull);
|
||||
nsresult rv = aChannel->AsyncOpen(this, nsnull);
|
||||
if (rv == NS_ERROR_NO_CONTENT)
|
||||
{
|
||||
// Assume this is a protocol such as mailto: which does not feed out
|
||||
|
@ -1260,9 +1290,9 @@ nsresult nsWebBrowserPersist::SaveURIInternal(
|
|||
else
|
||||
{
|
||||
// Add the output transport to the output map with the channel as the key
|
||||
nsCOMPtr<nsISupports> keyPtr = do_QueryInterface(inputChannel);
|
||||
nsCOMPtr<nsISupports> keyPtr = do_QueryInterface(aChannel);
|
||||
nsISupportsKey key(keyPtr);
|
||||
mOutputMap.Put(&key, new OutputData(aFile, aURI, aCalcFileExt));
|
||||
mOutputMap.Put(&key, new OutputData(aFile, mURI, aCalcFileExt));
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
|
|
@ -94,6 +94,8 @@ protected:
|
|||
nsIURI *aURI, nsISupports *aCacheKey, nsIURI *aReferrer,
|
||||
nsIInputStream *aPostData, const char *aExtraHeaders, nsIURI *aFile,
|
||||
PRBool aCalcFileExt);
|
||||
nsresult SaveChannelInternal(
|
||||
nsIChannel *aChannel, nsIURI *aFile, PRBool aCalcFileExt);
|
||||
nsresult SaveDocumentInternal(
|
||||
nsIDOMDocument *aDocument, nsIURI *aFile, nsIURI *aDataPath);
|
||||
nsresult SaveDocuments();
|
||||
|
|
Загрузка…
Ссылка в новой задаче