Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Protected Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Friends
nsWebBrowserPersist Class Reference

#include <nsWebBrowserPersist.h>

Inheritance diagram for nsWebBrowserPersist:
Inheritance graph
[legend]
Collaboration diagram for nsWebBrowserPersist:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsWebBrowserPersist ()
void getInterface (in nsIIDRef uuid,[iid_is(uuid), retval] out nsQIResult result)
 Retrieves the specified interface pointer.
void saveURI (in nsIURI aURI, in nsISupports aCacheKey, in nsIURI aReferrer, in nsIInputStream aPostData, in string aExtraHeaders, in nsISupports aFile)
 Save the specified URI to file.
void saveChannel (in nsIChannel aChannel, in nsISupports aFile)
 Save a channel to a file.
void saveDocument (in nsIDOMDocument aDocument, in nsISupports aFile, in nsISupports aDataPath, in string aOutputContentType, in unsigned long aEncodingFlags, in unsigned long aWrapColumn)
 Save the specified DOM document to file and optionally all linked files (e.g.
void cancelSave ()
 Cancels the current operation.
void cancel (in nsresult aReason)
 Call this method to request that this object abort whatever operation it may be performing.
void onDataAvailable (in nsIRequest aRequest, in nsISupports aContext, in nsIInputStream aInputStream, in unsigned long aOffset, in unsigned long aCount)
 Called when the next chunk of data (corresponding to the request) may be read without blocking the calling thread.
void onStartRequest (in nsIRequest aRequest, in nsISupports aContext)
 Called to signify the beginning of an asynchronous request.
void onStopRequest (in nsIRequest aRequest, in nsISupports aContext, in nsresult aStatusCode)
 Called to signify the end of an asynchronous request.
void onProgress (in nsIRequest aRequest, in nsISupports aContext, in unsigned long long aProgress, in unsigned long long aProgressMax)
 Called to notify the event sink that progress has occurred for the given request.
void onStatus (in nsIRequest aRequest, in nsISupports aContext, in nsresult aStatus, in wstring aStatusArg)
 Called to notify the event sink with a status message for the given request.

Public Attributes

const unsigned long PERSIST_FLAGS_NONE = 0
 No special persistence behaviour.
const unsigned long PERSIST_FLAGS_FROM_CACHE = 1
 Only use cached data (could result in failure if data is not cached).
const unsigned long PERSIST_FLAGS_BYPASS_CACHE = 2
 Bypass the cached data.
const unsigned long PERSIST_FLAGS_IGNORE_REDIRECTED_DATA = 4
 Ignore any redirected data (usually adverts).
const unsigned long PERSIST_FLAGS_IGNORE_IFRAMES = 8
 Ignore IFRAME content (usually adverts).
const unsigned long PERSIST_FLAGS_NO_CONVERSION = 16
 Do not run the incoming data through a content converter e.g.
const unsigned long PERSIST_FLAGS_REPLACE_EXISTING_FILES = 32
 Replace existing files on the disk (use with due diligence!)
const unsigned long PERSIST_FLAGS_NO_BASE_TAG_MODIFICATIONS = 64
 Don't modify or add base tags.
const unsigned long PERSIST_FLAGS_FIXUP_ORIGINAL_DOM = 128
 Make changes to original dom rather than cloning nodes.
const unsigned long PERSIST_FLAGS_FIXUP_LINKS_TO_DESTINATION = 256
 Fix links relative to destination location (not origin)
const unsigned long PERSIST_FLAGS_DONT_FIXUP_LINKS = 512
 Don't make any adjustments to links.
const unsigned long PERSIST_FLAGS_SERIALIZE_OUTPUT = 1024
 Force serialization of output (one file at a time; not concurrent)
const unsigned long PERSIST_FLAGS_DONT_CHANGE_FILENAMES = 2048
 Don't make any adjustments to filenames.
const unsigned long PERSIST_FLAGS_FAIL_ON_BROKEN_LINKS = 4096
 Fail on broken inline links.
const unsigned long PERSIST_FLAGS_CLEANUP_ON_FAILURE = 8192
 Automatically cleanup after a failed or cancelled operation, deleting all created files and directories.
const unsigned long PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION = 16384
 Let the WebBrowserPersist decide whether the incoming data is encoded and whether it needs to go through a content converter e.g.
attribute unsigned long persistFlags
 Flags governing how data is fetched and saved from the network.
const unsigned long PERSIST_STATE_READY = 1
 Persister is ready to save data.
const unsigned long PERSIST_STATE_SAVING = 2
 Persister is saving data.
const unsigned long PERSIST_STATE_FINISHED = 3
 Persister has finished saving data.
readonly attribute unsigned long currentState
 Current state of the persister object.
readonly attribute unsigned long result
 Value indicating the success or failure of the persist operation.
attribute nsIWebProgressListener progressListener
 Callback listener for progress notifications.
const unsigned long ENCODE_FLAGS_SELECTION_ONLY = 1
 Output only the current selection as opposed to the whole document.
const unsigned long ENCODE_FLAGS_FORMATTED = 2
 For plaintext output.
const unsigned long ENCODE_FLAGS_RAW = 4
 Output without formatting or wrapping the content.
const unsigned long ENCODE_FLAGS_BODY_ONLY = 8
 Output only the body section, no HTML tags.
const unsigned long ENCODE_FLAGS_PREFORMATTED = 16
 Wrap even if when not doing formatted output (e.g.
const unsigned long ENCODE_FLAGS_WRAP = 32
 Wrap documents at the specified column.
const unsigned long ENCODE_FLAGS_FORMAT_FLOWED = 64
 For plaintext output.
const unsigned long ENCODE_FLAGS_ABSOLUTE_LINKS = 128
 Convert links to absolute links where possible.
const unsigned long ENCODE_FLAGS_ENCODE_W3C_ENTITIES = 256
 Attempt to encode entities standardized at W3C (HTML, MathML, etc).
const unsigned long ENCODE_FLAGS_CR_LINEBREAKS = 512
 Output with carriage return line breaks.
const unsigned long ENCODE_FLAGS_LF_LINEBREAKS = 1024
 Output with linefeed line breaks.
const unsigned long ENCODE_FLAGS_NOSCRIPT_CONTENT = 2048
 For plaintext output.
const unsigned long ENCODE_FLAGS_NOFRAMES_CONTENT = 4096
 For plaintext output.
const unsigned long ENCODE_FLAGS_ENCODE_BASIC_ENTITIES = 8192
 Encode basic entities, e.g.
const unsigned long ENCODE_FLAGS_ENCODE_LATIN1_ENTITIES = 16384
 Encode Latin1 entities.
const unsigned long ENCODE_FLAGS_ENCODE_HTML_ENTITIES = 32768
 Encode HTML4 entities.

Protected Member Functions

virtual ~nsWebBrowserPersist ()
nsresult CloneNodeWithFixedUpURIAttributes (nsIDOMNode *aNodeIn, nsIDOMNode **aNodeOut)
nsresult SaveURIInternal (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 ()
nsresult GetDocEncoderContentType (nsIDOMDocument *aDocument, const PRUnichar *aContentType, PRUnichar **aRealContentType)
nsresult GetExtensionForContentType (const PRUnichar *aContentType, PRUnichar **aExt)
nsresult GetDocumentExtension (nsIDOMDocument *aDocument, PRUnichar **aExt)

Private Member Functions

void Cleanup ()
void CleanupLocalFiles ()
nsresult GetValidURIFromObject (nsISupports *aObject, nsIURI **aURI) const
nsresult GetLocalFileFromURI (nsIURI *aURI, nsILocalFile **aLocalFile) const
nsresult AppendPathToURI (nsIURI *aURI, const nsAString &aPath) const
nsresult MakeAndStoreLocalFilenameInURIMap (const char *aURI, PRBool aNeedsPersisting, URIData **aData)
nsresult MakeOutputStream (nsIURI *aFile, nsIOutputStream **aOutputStream)
nsresult MakeOutputStreamFromFile (nsILocalFile *aFile, nsIOutputStream **aOutputStream)
nsresult MakeOutputStreamFromURI (nsIURI *aURI, nsIOutputStream **aOutStream)
nsresult CreateChannelFromURI (nsIURI *aURI, nsIChannel **aChannel)
nsresult StartUpload (nsIStorageStream *aOutStream, nsIURI *aDestinationURI, const nsACString &aContentType)
nsresult CalculateAndAppendFileExt (nsIURI *aURI, nsIChannel *aChannel, nsIURI *aOriginalURIWithExtension)
nsresult CalculateUniqueFilename (nsIURI *aURI)
nsresult MakeFilenameFromURI (nsIURI *aURI, nsString &aFilename)
nsresult StoreURI (const char *aURI, PRBool aNeedsPersisting=PR_TRUE, URIData **aData=nsnull)
nsresult StoreURIAttribute (nsIDOMNode *aNode, const char *aAttribute, PRBool aNeedsPersisting=PR_TRUE, URIData **aData=nsnull)
PRBool GetQuotedAttributeValue (const nsAString &aSource, const nsAString &aAttribute, nsAString &aValue)
nsresult GetNodeToFixup (nsIDOMNode *aNodeIn, nsIDOMNode **aNodeOut)
nsresult FixupURI (nsAString &aURI)
nsresult FixupNodeAttribute (nsIDOMNode *aNode, const char *aAttribute)
nsresult FixupAnchor (nsIDOMNode *aNode)
nsresult FixupXMLStyleSheetLink (nsIDOMProcessingInstruction *aPI, const nsAString &aHref)
nsresult GetXMLStyleSheetLink (nsIDOMProcessingInstruction *aPI, nsAString &aHref)
nsresult StoreAndFixupStyleSheet (nsIStyleSheet *aStyleSheet)
nsresult SaveDocumentWithFixup (nsIDocument *pDocument, nsIDocumentEncoderNodeFixup *pFixup, nsIURI *aFile, PRBool aReplaceExisting, const nsACString &aFormatType, const nsCString &aSaveCharset, PRUint32 aFlags)
nsresult SaveSubframeContent (nsIDOMDocument *aFrameContent, URIData *aData)
nsresult SetDocumentBase (nsIDOMDocument *aDocument, nsIURI *aBaseURI)
nsresult SendErrorStatusChange (PRBool aIsReadError, nsresult aResult, nsIRequest *aRequest, nsIURI *aURI)
nsresult OnWalkDOMNode (nsIDOMNode *aNode)
nsresult FixRedirectedChannelEntry (nsIChannel *aNewChannel)
void EndDownload (nsresult aResult=NS_OK)
nsresult SaveGatheredURIs (nsIURI *aFileAsURI)
PRBool SerializeNextFile ()
void CalcTotalProgress ()
void SetApplyConversionIfNeeded (nsIChannel *aChannel)

Static Private Member Functions

static PRBool PR_CALLBACK EnumPersistURIs (nsHashKey *aKey, void *aData, void *closure)
static PRBool PR_CALLBACK EnumCleanupURIMap (nsHashKey *aKey, void *aData, void *closure)
static PRBool PR_CALLBACK EnumCleanupOutputMap (nsHashKey *aKey, void *aData, void *closure)
static PRBool PR_CALLBACK EnumCleanupUploadList (nsHashKey *aKey, void *aData, void *closure)
static PRBool PR_CALLBACK EnumCalcProgress (nsHashKey *aKey, void *aData, void *closure)
static PRBool PR_CALLBACK EnumCalcUploadProgress (nsHashKey *aKey, void *aData, void *closure)
static PRBool PR_CALLBACK EnumFixRedirect (nsHashKey *aKey, void *aData, void *closure)
static PRBool PR_CALLBACK EnumCountURIsToPersist (nsHashKey *aKey, void *aData, void *closure)

Private Attributes

nsCOMPtr< nsIURImCurrentDataPath
PRBool mCurrentDataPathIsRelative
nsCString mCurrentRelativePathToData
nsCOMPtr< nsIURImCurrentBaseURI
nsCString mCurrentCharset
nsCOMPtr< nsIURImTargetBaseURI
PRUint32 mCurrentThingsToPersist
nsCOMPtr< nsIMIMEServicemMIMEService
nsCOMPtr< nsIURImURI
nsCOMPtr< nsIWebProgressListenermProgressListener
nsCOMPtr< nsIWebProgressListener2mProgressListener2
 Progress listener for 64-bit values; this is the same object as mProgressListener, but is a member to avoid having to qi it for each progress notification.
nsHashtable mOutputMap
nsHashtable mUploadList
nsHashtable mURIMap
nsVoidArray mDocList
nsVoidArray mCleanupList
nsCStringArray mFilenameList
PRPackedBool mFirstAndOnlyUse
PRPackedBool mCancel
PRPackedBool mJustStartedLoading
PRPackedBool mCompleted
PRPackedBool mStartSaving
PRPackedBool mReplaceExisting
PRPackedBool mSerializingOutput
PRUint32 mPersistFlags
PRUint32 mPersistResult
nsInt64 mTotalCurrentProgress
nsInt64 mTotalMaxProgress
PRInt16 mWrapColumn
PRUint32 mEncodingFlags
nsString mContentType

Friends

class nsEncoderNodeFixup

Detailed Description

Definition at line 70 of file nsWebBrowserPersist.h.


Constructor & Destructor Documentation

Definition at line 251 of file nsWebBrowserPersist.cpp.

{
    Cleanup();
}

Here is the call graph for this function:


Member Function Documentation

nsresult nsWebBrowserPersist::AppendPathToURI ( nsIURI aURI,
const nsAString &  aPath 
) const [private]

Definition at line 1162 of file nsWebBrowserPersist.cpp.

{
    NS_ENSURE_ARG_POINTER(aURI);

    nsCAutoString newPath;
    nsresult rv = aURI->GetPath(newPath);
    NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);

    // Append a forward slash if necessary
    PRInt32 len = newPath.Length();
    if (len > 0 && newPath.CharAt(len - 1) != '/')
    {
        newPath.Append('/');
    }

    // Store the path back on the URI
    AppendUTF16toUTF8(aPath, newPath);
    aURI->SetPath(newPath);

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2418 of file nsWebBrowserPersist.cpp.

{
    mTotalCurrentProgress = 0;
    mTotalMaxProgress = 0;

    if (mOutputMap.Count() > 0)
    {
        // Total up the progress of each output stream
        mOutputMap.Enumerate(EnumCalcProgress, this);
    }

    if (mUploadList.Count() > 0)
    {
        // Total up the progress of each upload
        mUploadList.Enumerate(EnumCalcUploadProgress, this);
    }

    // XXX this code seems pretty bogus and pointless
    if (mTotalCurrentProgress == LL_ZERO && mTotalMaxProgress == LL_ZERO)
    {
        // No output streams so we must be complete
        mTotalCurrentProgress = 10000;
        mTotalMaxProgress = 10000;
    }
}

Here is the call graph for this function:

nsresult nsWebBrowserPersist::CalculateAndAppendFileExt ( nsIURI aURI,
nsIChannel aChannel,
nsIURI aOriginalURIWithExtension 
) [private]

Definition at line 2144 of file nsWebBrowserPersist.cpp.

{
    nsresult rv;

    if (!mMIMEService)
    {
        mMIMEService = do_GetService(NS_MIMESERVICE_CONTRACTID, &rv);
        NS_ENSURE_TRUE(mMIMEService, NS_ERROR_FAILURE);
    }

    nsCAutoString contentType;

    // Get the content type from the channel
    aChannel->GetContentType(contentType);

    // Get the content type from the MIME service
    if (contentType.IsEmpty())
    {
        nsCOMPtr<nsIURI> uri;
        aChannel->GetOriginalURI(getter_AddRefs(uri));
        mMIMEService->GetTypeFromURI(uri, contentType);
    }

    // Append the extension onto the file
    if (!contentType.IsEmpty())
    {
        nsCOMPtr<nsIMIMEInfo> mimeInfo;
        mMIMEService->GetFromTypeAndExtension(
            contentType, EmptyCString(), getter_AddRefs(mimeInfo));

        nsCOMPtr<nsILocalFile> localFile;
        GetLocalFileFromURI(aURI, getter_AddRefs(localFile));

        if (mimeInfo)
        {
            nsCOMPtr<nsIURL> url(do_QueryInterface(aURI));
            NS_ENSURE_TRUE(url, NS_ERROR_FAILURE);

            nsCAutoString newFileName;
            url->GetFileName(newFileName);

            // Test if the current extension is current for the mime type
            PRBool hasExtension = PR_FALSE;
            PRInt32 ext = newFileName.RFind(".");
            if (ext != -1)
            {
                mimeInfo->ExtensionExists(Substring(newFileName, ext + 1), &hasExtension);
            }

            // Append the mime file extension
            nsCAutoString fileExt;
            if (!hasExtension)
            {
                // Test if previous extension is acceptable
                nsCOMPtr<nsIURL> oldurl(do_QueryInterface(aOriginalURIWithExtension));
                NS_ENSURE_TRUE(oldurl, NS_ERROR_FAILURE);
                oldurl->GetFileExtension(fileExt);
                PRBool useOldExt = PR_FALSE;
                if (!fileExt.IsEmpty())
                {
                    mimeInfo->ExtensionExists(fileExt, &useOldExt);
                }

                // can't use old extension so use primary extension
                if (!useOldExt)
                {
                    mimeInfo->GetPrimaryExtension(fileExt);
                } 

                if (!fileExt.IsEmpty())
                {
                    PRUint32 newLength = newFileName.Length() + fileExt.Length() + 1;
                    if (newLength > kDefaultMaxFilenameLength)
                    {
                        newFileName.Truncate(newFileName.Length() - (newLength - kDefaultMaxFilenameLength));
                    }
                    newFileName.Append(".");
                    newFileName.Append(fileExt);
                }

                if (localFile)
                {
                    localFile->SetLeafName(NS_ConvertUTF8toUTF16(newFileName));

                    // Resync the URI with the file after the extension has been appended
                    nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(aURI, &rv);
                    NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
                    fileURL->SetFile(localFile);  // this should recalculate uri
                }
                else
                {
                    url->SetFileName(newFileName);
                }
            }

        }

#ifdef  XP_MAC
        // Set appropriate Mac file type/creator for this mime type
        nsCOMPtr<nsILocalFileMac> macFile(do_QueryInterface(localFile));
        if (macFile)
        {
            macFile->SetFileTypeAndCreatorFromMIMEType(contentType.get());
        }
#endif            
    }

    return NS_OK;
}

Here is the call graph for this function:

Definition at line 1919 of file nsWebBrowserPersist.cpp.

{
    nsCOMPtr<nsIURL> url(do_QueryInterface(aURI));
    NS_ENSURE_TRUE(url, NS_ERROR_FAILURE);

    PRBool nameHasChanged = PR_FALSE;
    nsresult rv;

    // Get the old filename
    nsCAutoString filename;
    rv = url->GetFileName(filename);
    NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
    nsCAutoString directory;
    rv = url->GetDirectory(directory);
    NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);

    // Split the filename into a base and an extension.
    // e.g. "foo.html" becomes "foo" & ".html"
    //
    // The nsIURL methods GetFileBaseName & GetFileExtension don't
    // preserve the dot whereas this code does to save some effort
    // later when everything is put back together.
    PRInt32 lastDot = filename.RFind(".");
    nsCAutoString base;
    nsCAutoString ext;
    if (lastDot >= 0)
    {
        filename.Mid(base, 0, lastDot);
        filename.Mid(ext, lastDot, filename.Length() - lastDot); // includes dot
    }
    else
    {
        // filename contains no dot
        base = filename;
    }

    // Test if the filename is longer than allowed by the OS
    PRInt32 needToChop = filename.Length() - kDefaultMaxFilenameLength;
    if (needToChop > 0)
    {
        // Truncate the base first and then the ext if necessary
        if (base.Length() > (PRUint32) needToChop)
        {
            base.Truncate(base.Length() - needToChop);
        }
        else
        {
            needToChop -= base.Length() - 1;
            base.Truncate(1);
            if (ext.Length() > (PRUint32) needToChop)
            {
                ext.Truncate(ext.Length() - needToChop);
            }
            else
            {
                ext.Truncate(0);
            }
            // If kDefaultMaxFilenameLength were 1 we'd be in trouble here,
            // but that won't happen because it will be set to a sensible
            // value.
        }

        filename.Assign(base);
        filename.Append(ext);
        nameHasChanged = PR_TRUE;
    }

    // Ensure the filename is unique
    // Create a filename if it's empty, or if the filename / datapath is
    // already taken by another URI and create an alternate name.

    if (base.IsEmpty() || mFilenameList.Count() > 0)
    {
        nsCAutoString tmpPath;
        nsCAutoString tmpBase;
        PRUint32 duplicateCounter = 1;
        while (1)
        {
            // Make a file name,
            // Foo become foo_001, foo_002, etc.
            // Empty files become _001, _002 etc.

            if (base.IsEmpty() || duplicateCounter > 1)
            {
                char * tmp = PR_smprintf("_%03d", duplicateCounter);
                NS_ENSURE_TRUE(tmp, NS_ERROR_OUT_OF_MEMORY);
                if (filename.Length() < kDefaultMaxFilenameLength - 4)
                {
                    tmpBase = base;
                }
                else
                {
                    base.Mid(tmpBase, 0, base.Length() - 4);
                }
                tmpBase.Append(tmp);
                PR_smprintf_free(tmp);
            }
            else
            {
                tmpBase = base;
            }
        
            tmpPath.Assign(directory);
            tmpPath.Append(tmpBase);
            tmpPath.Append(ext);

            // Test if the name is a duplicate
            if (mFilenameList.IndexOf(tmpPath) < 0)
            {
                if (!base.Equals(tmpBase))
                {
                    filename.Assign(tmpBase);
                    filename.Append(ext);
                    nameHasChanged = PR_TRUE;
                }
                break;
            }
            duplicateCounter++;
        }
    }

    // Add name to list of those already used
    nsCAutoString newFilepath(directory);
    newFilepath.Append(filename);
    mFilenameList.AppendCString(newFilepath);

    // Update the uri accordingly if the filename actually changed
    if (nameHasChanged)
    {
        // Final sanity test
        if (filename.Length() > kDefaultMaxFilenameLength)
        {
            NS_WARNING("Filename wasn't truncated less than the max file length - how can that be?");
            return NS_ERROR_FAILURE;
        }

        nsCOMPtr<nsILocalFile> localFile;
        GetLocalFileFromURI(aURI, getter_AddRefs(localFile));

        if (localFile)
        {
            nsAutoString filenameAsUnichar;
            filenameAsUnichar.AssignWithConversion(filename.get());
            localFile->SetLeafName(filenameAsUnichar);

            // Resync the URI with the file after the extension has been appended
            nsresult rv;
            nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(aURI, &rv);
            NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
            fileURL->SetFile(localFile);  // this should recalculate uri
        }
        else
        {
            url->SetFileName(filename);
        }
    }

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsICancelable::cancel ( in nsresult  aReason) [inherited]

Call this method to request that this object abort whatever operation it may be performing.

Parameters:
aReasonPass a failure code to indicate the reason why this operation is being canceled. It is an error to pass a success code.

Cancels the current operation.

The caller is responsible for cleaning up partially written files or directories. This has the same effect as calling cancel with an argument of NS_BINDING_ABORTED.

Definition at line 1785 of file nsWebBrowserPersist.cpp.

{
    mURIMap.Enumerate(EnumCleanupURIMap, this);
    mURIMap.Reset();
    mOutputMap.Enumerate(EnumCleanupOutputMap, this);
    mOutputMap.Reset();
    mUploadList.Enumerate(EnumCleanupUploadList, this);
    mUploadList.Reset();
    PRInt32 i;
    for (i = 0; i < mDocList.Count(); i++)
    {
        DocData *docData = (DocData *) mDocList.ElementAt(i);
        delete docData;
    }
    mDocList.Clear();
    for (i = 0; i < mCleanupList.Count(); i++)
    {
        CleanupData *cleanupData = (CleanupData *) mCleanupList.ElementAt(i);
        delete cleanupData;
    }
    mCleanupList.Clear();
    mFilenameList.Clear();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1809 of file nsWebBrowserPersist.cpp.

{
    // Two passes, the first pass cleans up files, the second pass tests
    // for and then deletes empty directories. Directories that are not
    // empty after the first pass must contain files from something else
    // and are not deleted.
    int pass;
    for (pass = 0; pass < 2; pass++)
    {
        PRInt32 i;
        for (i = 0; i < mCleanupList.Count(); i++)
        {
            CleanupData *cleanupData = (CleanupData *) mCleanupList.ElementAt(i);
            nsCOMPtr<nsILocalFile> file = cleanupData->mFile;

            // Test if the dir / file exists (something in an earlier loop
            // may have already removed it)
            PRBool exists = PR_FALSE;
            file->Exists(&exists);
            if (!exists)
                continue;

            // Test if the file has changed in between creation and deletion
            // in some way that means it should be ignored
            PRBool isDirectory = PR_FALSE;
            file->IsDirectory(&isDirectory);
            if (isDirectory != cleanupData->mIsDirectory)
                continue; // A file has become a dir or vice versa !

            if (pass == 0 && !isDirectory)
            {
                file->Remove(PR_FALSE);
            }
            else if (pass == 1 && isDirectory) // Directory
            {
                // Directories are more complicated. Enumerate through
                // children looking for files. Any files created by the
                // persist object would have been deleted by the first
                // pass so if there are any there at this stage, the dir
                // cannot be deleted because it has someone else's files
                // in it. Empty child dirs are deleted but they must be
                // recursed through to ensure they are actually empty.

                PRBool isEmptyDirectory = PR_TRUE;
                nsSupportsArray dirStack;
                PRUint32 stackSize = 0;

                // Push the top level enum onto the stack
                nsCOMPtr<nsISimpleEnumerator> pos;
                if (NS_SUCCEEDED(file->GetDirectoryEntries(getter_AddRefs(pos))))
                    dirStack.AppendElement(pos);

                while (isEmptyDirectory &&
                    NS_SUCCEEDED(dirStack.Count(&stackSize)) && stackSize > 0)
                {
                    // Pop the last element
                    nsCOMPtr<nsISimpleEnumerator> curPos;
                    dirStack.GetElementAt(stackSize - 1, getter_AddRefs(curPos));
                    dirStack.RemoveElementAt(stackSize - 1);
                    
                    // Test if the enumerator has any more files in it
                    PRBool hasMoreElements = PR_FALSE;
                    curPos->HasMoreElements(&hasMoreElements);
                    if (!hasMoreElements)
                    {
                        continue;
                    }

                    // Child files automatically make this code drop out,
                    // while child dirs keep the loop going.
                    nsCOMPtr<nsISupports> child;
                    curPos->GetNext(getter_AddRefs(child));
                    NS_ASSERTION(child, "No child element, but hasMoreElements says otherwise");
                    if (!child)
                        continue;
                    nsCOMPtr<nsILocalFile> childAsFile = do_QueryInterface(child);
                    NS_ASSERTION(childAsFile, "This should be a file but isn't");

                    PRBool childIsSymlink = PR_FALSE;
                    childAsFile->IsSymlink(&childIsSymlink);
                    PRBool childIsDir = PR_FALSE;
                    childAsFile->IsDirectory(&childIsDir);                           
                    if (!childIsDir || childIsSymlink)
                    {
                        // Some kind of file or symlink which means dir
                        // is not empty so just drop out.
                        isEmptyDirectory = PR_FALSE;
                        break;
                    }
                    // Push parent enumerator followed by child enumerator
                    nsCOMPtr<nsISimpleEnumerator> childPos;
                    childAsFile->GetDirectoryEntries(getter_AddRefs(childPos));
                    dirStack.AppendElement(curPos);
                    if (childPos)
                        dirStack.AppendElement(childPos);

                }
                dirStack.Clear();

                // If after all that walking the dir is deemed empty, delete it
                if (isEmptyDirectory)
                {
                    file->Remove(PR_TRUE);
                }
            }
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2947 of file nsWebBrowserPersist.cpp.

{
    nsresult rv;
    *aNodeOut = nsnull;

    // Fixup xml-stylesheet processing instructions
    nsCOMPtr<nsIDOMProcessingInstruction> nodeAsPI = do_QueryInterface(aNodeIn);
    if (nodeAsPI)
    {
        nsAutoString target;
        nodeAsPI->GetTarget(target);
        if (target.EqualsLiteral("xml-stylesheet"))
        {
            rv = GetNodeToFixup(aNodeIn, aNodeOut);
            if (NS_SUCCEEDED(rv) && *aNodeOut)
            {
                nsCOMPtr<nsIDOMProcessingInstruction> outNode = do_QueryInterface(*aNodeOut);
                nsAutoString href;
                GetXMLStyleSheetLink(nodeAsPI, href);
                if (!href.IsEmpty())
                {
                    FixupURI(href);
                    FixupXMLStyleSheetLink(outNode, href);
                }
            }
        }
    }

    // BASE elements are replaced by a comment so relative links are not hosed.

    if (!(mPersistFlags & PERSIST_FLAGS_NO_BASE_TAG_MODIFICATIONS))
    {
        nsCOMPtr<nsIDOMHTMLBaseElement> nodeAsBase = do_QueryInterface(aNodeIn);
        if (nodeAsBase)
        {
            nsCOMPtr<nsIDOMDocument> ownerDocument;
            nodeAsBase->GetOwnerDocument(getter_AddRefs(ownerDocument));
            if (ownerDocument)
            {
                nsAutoString href;
                nodeAsBase->GetHref(href); // Doesn't matter if this fails
                nsCOMPtr<nsIDOMComment> comment;
                nsAutoString commentText; commentText.AssignLiteral(" base ");
                if (!href.IsEmpty())
                {
                    commentText += NS_LITERAL_STRING("href=\"") + href + NS_LITERAL_STRING("\" ");
                }
                rv = ownerDocument->CreateComment(commentText, getter_AddRefs(comment));
                if (comment)
                {
                    return CallQueryInterface(comment, aNodeOut);
                }
            }
        }
    }

    // Fix up href and file links in the elements

    nsCOMPtr<nsIDOMHTMLAnchorElement> nodeAsAnchor = do_QueryInterface(aNodeIn);
    if (nodeAsAnchor)
    {
        rv = GetNodeToFixup(aNodeIn, aNodeOut);
        if (NS_SUCCEEDED(rv) && *aNodeOut)
        {
            FixupAnchor(*aNodeOut);
        }
        return rv;
    }

    nsCOMPtr<nsIDOMHTMLAreaElement> nodeAsArea = do_QueryInterface(aNodeIn);
    if (nodeAsArea)
    {
        rv = GetNodeToFixup(aNodeIn, aNodeOut);
        if (NS_SUCCEEDED(rv) && *aNodeOut)
        {
            FixupAnchor(*aNodeOut);
        }
        return rv;
    }

    nsCOMPtr<nsIDOMHTMLBodyElement> nodeAsBody = do_QueryInterface(aNodeIn);
    if (nodeAsBody)
    {
        rv = GetNodeToFixup(aNodeIn, aNodeOut);
        if (NS_SUCCEEDED(rv) && *aNodeOut)
        {
            FixupNodeAttribute(*aNodeOut, "background");
        }
        return rv;
    }

    nsCOMPtr<nsIDOMHTMLTableElement> nodeAsTable = do_QueryInterface(aNodeIn);
    if (nodeAsTable)
    {
        rv = GetNodeToFixup(aNodeIn, aNodeOut);
        if (NS_SUCCEEDED(rv) && *aNodeOut)
        {
            FixupNodeAttribute(*aNodeOut, "background");
        }
        return rv;
    }

    nsCOMPtr<nsIDOMHTMLTableRowElement> nodeAsTableRow = do_QueryInterface(aNodeIn);
    if (nodeAsTableRow)
    {
        rv = GetNodeToFixup(aNodeIn, aNodeOut);
        if (NS_SUCCEEDED(rv) && *aNodeOut)
        {
            FixupNodeAttribute(*aNodeOut, "background");
        }
        return rv;
    }

    nsCOMPtr<nsIDOMHTMLTableCellElement> nodeAsTableCell = do_QueryInterface(aNodeIn);
    if (nodeAsTableCell)
    {
        rv = GetNodeToFixup(aNodeIn, aNodeOut);
        if (NS_SUCCEEDED(rv) && *aNodeOut)
        {
            FixupNodeAttribute(*aNodeOut, "background");
        }
        return rv;
    }

    nsCOMPtr<nsIDOMHTMLImageElement> nodeAsImage = do_QueryInterface(aNodeIn);
    if (nodeAsImage)
    {
        rv = GetNodeToFixup(aNodeIn, aNodeOut);
        if (NS_SUCCEEDED(rv) && *aNodeOut)
        {
            // Disable image loads
            nsCOMPtr<nsIImageLoadingContent> imgCon =
                do_QueryInterface(*aNodeOut);
            if (imgCon)
                imgCon->SetLoadingEnabled(PR_FALSE);

            FixupAnchor(*aNodeOut);
            FixupNodeAttribute(*aNodeOut, "src");
        }
        return rv;
    }
    
    nsCOMPtr<nsIDOMHTMLScriptElement> nodeAsScript = do_QueryInterface(aNodeIn);
    if (nodeAsScript)
    {
        rv = GetNodeToFixup(aNodeIn, aNodeOut);
        if (NS_SUCCEEDED(rv) && *aNodeOut)
        {
            FixupNodeAttribute(*aNodeOut, "src");
        }
        return rv;
    }
    
    nsCOMPtr<nsIDOMHTMLEmbedElement> nodeAsEmbed = do_QueryInterface(aNodeIn);
    if (nodeAsEmbed)
    {
        rv = GetNodeToFixup(aNodeIn, aNodeOut);
        if (NS_SUCCEEDED(rv) && *aNodeOut)
        {
            FixupNodeAttribute(*aNodeOut, "src");
        }
        return rv;
    }
    
    nsCOMPtr<nsIDOMHTMLObjectElement> nodeAsObject = do_QueryInterface(aNodeIn);
    if (nodeAsObject)
    {
        rv = GetNodeToFixup(aNodeIn, aNodeOut);
        if (NS_SUCCEEDED(rv) && *aNodeOut)
        {
            FixupNodeAttribute(*aNodeOut, "data");
        }
        return rv;
    }

    nsCOMPtr<nsIDOMHTMLAppletElement> nodeAsApplet = do_QueryInterface(aNodeIn);
    if (nodeAsApplet)
    {
        rv = GetNodeToFixup(aNodeIn, aNodeOut);
        if (NS_SUCCEEDED(rv) && *aNodeOut)
        {
            nsCOMPtr<nsIDOMHTMLAppletElement> newApplet =
                do_QueryInterface(*aNodeOut);
            // For an applet, relative URIs are resolved relative to the
            // codebase (which is resolved relative to the base URI).
            nsCOMPtr<nsIURI> oldBase = mCurrentBaseURI;
            nsAutoString codebase;
            nodeAsApplet->GetCodeBase(codebase);
            if (!codebase.IsEmpty()) {
                nsCOMPtr<nsIURI> baseURI;
                NS_NewURI(getter_AddRefs(baseURI), codebase,
                          mCurrentCharset.get(), mCurrentBaseURI);
                if (baseURI) {
                    mCurrentBaseURI = baseURI;
                }
            }
            // Unset the codebase too, since we'll correctly relativize the
            // code and archive paths.
            newApplet->RemoveAttribute(NS_LITERAL_STRING("codebase"));
            FixupNodeAttribute(*aNodeOut, "code");
            FixupNodeAttribute(*aNodeOut, "archive");
            // restore the base URI we really want to have
            mCurrentBaseURI = oldBase;
        }
        return rv;
    }
    
    nsCOMPtr<nsIDOMHTMLLinkElement> nodeAsLink = do_QueryInterface(aNodeIn);
    if (nodeAsLink)
    {
        rv = GetNodeToFixup(aNodeIn, aNodeOut);
        if (NS_SUCCEEDED(rv) && *aNodeOut)
        {
            // First see if the link represents linked content
            rv = FixupNodeAttribute(*aNodeOut, "href");
            if (NS_FAILED(rv))
            {
                // Perhaps this link is actually an anchor to related content
                FixupAnchor(*aNodeOut);
            }
            // TODO if "type" attribute == "text/css"
            //        fixup stylesheet
        }
        return rv;
    }

    nsCOMPtr<nsIDOMHTMLFrameElement> nodeAsFrame = do_QueryInterface(aNodeIn);
    if (nodeAsFrame)
    {
        rv = GetNodeToFixup(aNodeIn, aNodeOut);
        if (NS_SUCCEEDED(rv) && *aNodeOut)
        {
            FixupNodeAttribute(*aNodeOut, "src");
        }
        return rv;
    }

    nsCOMPtr<nsIDOMHTMLIFrameElement> nodeAsIFrame = do_QueryInterface(aNodeIn);
    if (nodeAsIFrame)
    {
        rv = GetNodeToFixup(aNodeIn, aNodeOut);
        if (NS_SUCCEEDED(rv) && *aNodeOut)
        {
            FixupNodeAttribute(*aNodeOut, "src");
        }
        return rv;
    }

    nsCOMPtr<nsIDOMHTMLInputElement> nodeAsInput = do_QueryInterface(aNodeIn);
    if (nodeAsInput)
    {
        rv = GetNodeToFixup(aNodeIn, aNodeOut);
        if (NS_SUCCEEDED(rv) && *aNodeOut)
        {
            // Disable image loads
            nsCOMPtr<nsIImageLoadingContent> imgCon =
                do_QueryInterface(*aNodeOut);
            if (imgCon)
                imgCon->SetLoadingEnabled(PR_FALSE);

            FixupNodeAttribute(*aNodeOut, "src");
        }
        return rv;
    }

    return NS_OK;
}

Here is the call graph for this function:

nsresult nsWebBrowserPersist::CreateChannelFromURI ( nsIURI aURI,
nsIChannel **  aChannel 
) [private]

Definition at line 3499 of file nsWebBrowserPersist.cpp.

{
    nsresult rv = NS_OK;
    *aChannel = nsnull;

    nsCOMPtr<nsIIOService> ioserv;
    ioserv = do_GetIOService(&rv);
    NS_ENSURE_SUCCESS(rv, rv);

    rv = ioserv->NewChannelFromURI(aURI, aChannel);
    NS_ENSURE_SUCCESS(rv, rv);
    NS_ENSURE_ARG_POINTER(*aChannel);

    rv = (*aChannel)->SetNotificationCallbacks(NS_STATIC_CAST(nsIInterfaceRequestor *, this));
    NS_ENSURE_SUCCESS(rv, rv);
    return NS_OK;
} 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2314 of file nsWebBrowserPersist.cpp.

{
    // Store the error code in the result if it is an error
    if (NS_SUCCEEDED(mPersistResult) && NS_FAILED(aResult))
    {
        mPersistResult = aResult;
    }

    // Do file cleanup if required
    if (NS_FAILED(aResult) && (mPersistFlags & PERSIST_FLAGS_CLEANUP_ON_FAILURE))
    {
        CleanupLocalFiles();
    }

    // Cleanup the channels
    mCompleted = PR_TRUE;
    Cleanup();
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool PR_CALLBACK nsWebBrowserPersist::EnumCalcProgress ( nsHashKey *  aKey,
void aData,
void closure 
) [static, private]

Definition at line 2445 of file nsWebBrowserPersist.cpp.

{
    nsWebBrowserPersist *pthis = (nsWebBrowserPersist *) closure;
    OutputData *data = (OutputData *) aData;

    // only count toward total progress if destination file is local
    nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(data->mFile);
    if (fileURL)
    {
        pthis->mTotalCurrentProgress += data->mSelfProgress;
        pthis->mTotalMaxProgress += data->mSelfProgressMax;
    }
    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool PR_CALLBACK nsWebBrowserPersist::EnumCalcUploadProgress ( nsHashKey *  aKey,
void aData,
void closure 
) [static, private]

Definition at line 2461 of file nsWebBrowserPersist.cpp.

Here is the caller graph for this function:

PRBool PR_CALLBACK nsWebBrowserPersist::EnumCleanupOutputMap ( nsHashKey *  aKey,
void aData,
void closure 
) [static, private]

Definition at line 2537 of file nsWebBrowserPersist.cpp.

{
    nsCOMPtr<nsISupports> keyPtr;
    ((nsMyISupportsKey *) aKey)->GetISupports(getter_AddRefs(keyPtr));
    nsCOMPtr<nsIChannel> channel = do_QueryInterface(keyPtr);
    if (channel)
    {
        channel->Cancel(NS_BINDING_ABORTED);
    }
    OutputData *data = (OutputData *) aData;
    if (data)
    {
        delete data;
    }
    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool PR_CALLBACK nsWebBrowserPersist::EnumCleanupUploadList ( nsHashKey *  aKey,
void aData,
void closure 
) [static, private]

Definition at line 2568 of file nsWebBrowserPersist.cpp.

{
    nsCOMPtr<nsISupports> keyPtr;
    ((nsMyISupportsKey *) aKey)->GetISupports(getter_AddRefs(keyPtr));
    nsCOMPtr<nsIChannel> channel = do_QueryInterface(keyPtr);
    if (channel)
    {
        channel->Cancel(NS_BINDING_ABORTED);
    }
    UploadData *data = (UploadData *) aData;
    if (data)
    {
        delete data; // Delete data associated with key
    }
    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool PR_CALLBACK nsWebBrowserPersist::EnumCleanupURIMap ( nsHashKey *  aKey,
void aData,
void closure 
) [static, private]

Definition at line 2556 of file nsWebBrowserPersist.cpp.

{
    URIData *data = (URIData *) aData;
    if (data)
    {
        delete data; // Delete data associated with key
    }
    return PR_TRUE;
}

Here is the caller graph for this function:

PRBool PR_CALLBACK nsWebBrowserPersist::EnumCountURIsToPersist ( nsHashKey *  aKey,
void aData,
void closure 
) [static, private]

Definition at line 2474 of file nsWebBrowserPersist.cpp.

{
    URIData *data = (URIData *) aData;
    PRUint32 *count = (PRUint32 *) closure;
    if (data->mNeedsPersisting && !data->mSaved)
    {
        (*count)++;
    }
    return PR_TRUE;
}

Here is the caller graph for this function:

PRBool PR_CALLBACK nsWebBrowserPersist::EnumFixRedirect ( nsHashKey *  aKey,
void aData,
void closure 
) [static, private]

Definition at line 2393 of file nsWebBrowserPersist.cpp.

{
    FixRedirectData *data = (FixRedirectData *) closure;

    nsCOMPtr<nsISupports> keyPtr;
    ((nsMyISupportsKey *) aKey)->GetISupports(getter_AddRefs(keyPtr));

    nsCOMPtr<nsIChannel> thisChannel = do_QueryInterface(keyPtr);
    nsCOMPtr<nsIURI> thisURI;

    thisChannel->GetOriginalURI(getter_AddRefs(thisURI));

    // Compare this channel's URI to the one passed in.
    PRBool matchingURI = PR_FALSE;
    thisURI->Equals(data->mOriginalURI, &matchingURI);
    if (matchingURI)
    {
        data->mMatchingKey = (nsISupportsKey *) aKey;
        return PR_FALSE; // Stop enumerating
    }

    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool PR_CALLBACK nsWebBrowserPersist::EnumPersistURIs ( nsHashKey *  aKey,
void aData,
void closure 
) [static, private]

Definition at line 2486 of file nsWebBrowserPersist.cpp.

{
    URIData *data = (URIData *) aData;
    if (!data->mNeedsPersisting || data->mSaved)
    {
        return PR_TRUE;
    }

    nsWebBrowserPersist *pthis = (nsWebBrowserPersist *) closure;
    nsresult rv;

    // Create a URI from the key
    nsCOMPtr<nsIURI> uri;
    rv = NS_NewURI(getter_AddRefs(uri), 
                   nsDependentCString(((nsCStringKey *) aKey)->GetString(),
                                      ((nsCStringKey *) aKey)->GetStringLength()),
                   data->mCharset.get());
    NS_ENSURE_SUCCESS(rv, PR_FALSE);

    // Make a URI to save the data to
    nsCOMPtr<nsIURI> fileAsURI;
    rv = data->mDataPath->Clone(getter_AddRefs(fileAsURI));
    NS_ENSURE_SUCCESS(rv, PR_FALSE);
    rv = pthis->AppendPathToURI(fileAsURI, data->mFilename);
    NS_ENSURE_SUCCESS(rv, PR_FALSE);

    rv = pthis->SaveURIInternal(uri, nsnull, nsnull, nsnull, nsnull, fileAsURI, PR_TRUE);
    // if SaveURIInternal fails, then it will have called EndDownload,
    // which means that |aData| is no longer valid memory.  we MUST bail.
    NS_ENSURE_SUCCESS(rv, PR_FALSE);

    if (rv == NS_OK)
    {
        // Store the actual object because once it's persisted this
        // will be fixed up with the right file extension.

        data->mFile = fileAsURI;
        data->mSaved = PR_TRUE;
    }
    else
    {
        data->mNeedsFixup = PR_FALSE;
    }

    if (pthis->mSerializingOutput)
        return PR_FALSE;

    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2357 of file nsWebBrowserPersist.cpp.

{
    NS_ENSURE_ARG_POINTER(aNewChannel);
    nsCOMPtr<nsIURI> originalURI;

    // Enumerate through existing open channels looking for one with
    // a URI matching the one specified.

    FixRedirectData data;
    data.mMatchingKey = nsnull;
    data.mNewChannel = aNewChannel;
    data.mNewChannel->GetOriginalURI(getter_AddRefs(data.mOriginalURI));
    mOutputMap.Enumerate(EnumFixRedirect, (void *) &data);

    // If a match is found, remove the data entry with the old channel key
    // and re-add it with the new channel key.

    if (data.mMatchingKey)
    {
        OutputData *outputData = (OutputData *) mOutputMap.Get(data.mMatchingKey);
        NS_ENSURE_TRUE(outputData, NS_ERROR_FAILURE);
        mOutputMap.Remove(data.mMatchingKey);

        // Store data again with new channel unless told to ignore redirects
        if (!(mPersistFlags & PERSIST_FLAGS_IGNORE_REDIRECTED_DATA))
        {
            nsCOMPtr<nsISupports> keyPtr = do_QueryInterface(aNewChannel);
            nsISupportsKey key(keyPtr);
            mOutputMap.Put(&key, outputData);
        }
    }

    return NS_OK;
}

Here is the call graph for this function:

Definition at line 3390 of file nsWebBrowserPersist.cpp.

{
    NS_ENSURE_ARG_POINTER(aNode);

    nsCOMPtr<nsIDOMNamedNodeMap> attrMap;
    nsCOMPtr<nsIDOMNode> attrNode;
    nsresult rv = aNode->GetAttributes(getter_AddRefs(attrMap));
    NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);

    if (mPersistFlags & PERSIST_FLAGS_DONT_FIXUP_LINKS)
    {
        return NS_OK;
    }

    // Make all anchor links absolute so they point off onto the Internet
    nsString attribute(NS_LITERAL_STRING("href"));
    rv = attrMap->GetNamedItem(attribute, getter_AddRefs(attrNode));
    if (attrNode)
    {
        nsString oldValue;
        attrNode->GetNodeValue(oldValue);
        NS_ConvertUCS2toUTF8 oldCValue(oldValue);

        // Skip empty values and self-referencing bookmarks
        if (oldCValue.IsEmpty() || oldCValue.CharAt(0) == '#')
        {
            return NS_OK;
        }

        // if saving file to same location, we don't need to do any fixup
        PRBool isEqual = PR_FALSE;
        if (NS_SUCCEEDED(mCurrentBaseURI->Equals(mTargetBaseURI, &isEqual))
            && isEqual)
        {
            return NS_OK;
        }

        nsCOMPtr<nsIURI> relativeURI;
        relativeURI = (mPersistFlags & PERSIST_FLAGS_FIXUP_LINKS_TO_DESTINATION)
                      ? mTargetBaseURI : mCurrentBaseURI;
        // Make a new URI to replace the current one
        nsCOMPtr<nsIURI> newURI;
        rv = NS_NewURI(getter_AddRefs(newURI), oldCValue, 
                       mCurrentCharset.get(), relativeURI);
        if (NS_SUCCEEDED(rv) && newURI)
        {
            newURI->SetUserPass(EmptyCString());
            nsCAutoString uriSpec;
            newURI->GetSpec(uriSpec);
            attrNode->SetNodeValue(NS_ConvertUTF8toUCS2(uriSpec));
        }
    }

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsWebBrowserPersist::FixupNodeAttribute ( nsIDOMNode aNode,
const char *  aAttribute 
) [private]

Definition at line 3357 of file nsWebBrowserPersist.cpp.

{
    NS_ENSURE_ARG_POINTER(aNode);
    NS_ENSURE_ARG_POINTER(aAttribute);

    nsresult rv = NS_OK;

    // Find the named URI attribute on the (element) node and change it to reference
    // a local file.

    nsCOMPtr<nsIDOMNamedNodeMap> attrMap;
    nsCOMPtr<nsIDOMNode> attrNode;
    rv = aNode->GetAttributes(getter_AddRefs(attrMap));
    NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);

    NS_ConvertASCIItoUTF16 attribute(aAttribute);
    rv = attrMap->GetNamedItem(attribute, getter_AddRefs(attrNode));
    if (attrNode)
    {
        nsString uri;
        attrNode->GetNodeValue(uri);
        rv = FixupURI(uri);
        if (NS_SUCCEEDED(rv))
        {
            attrNode->SetNodeValue(uri);
        }
    }

    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsWebBrowserPersist::FixupURI ( nsAString &  aURI) [private]

Definition at line 3283 of file nsWebBrowserPersist.cpp.

{
    // get the current location of the file (absolutized)
    nsCOMPtr<nsIURI> uri;
    nsresult rv = NS_NewURI(getter_AddRefs(uri), aURI, 
                            mCurrentCharset.get(), mCurrentBaseURI);
    NS_ENSURE_SUCCESS(rv, rv);
    nsCAutoString spec;
    rv = uri->GetSpec(spec);
    NS_ENSURE_SUCCESS(rv, rv);

    // Search for the URI in the map and replace it with the local file
    nsCStringKey key(spec.get());
    if (!mURIMap.Exists(&key))
    {
        return NS_ERROR_FAILURE;
    }
    URIData *data = (URIData *) mURIMap.Get(&key);
    if (!data->mNeedsFixup)
    {
        return NS_OK;
    }
    nsCOMPtr<nsIURI> fileAsURI;
    if (data->mFile)
    {
        rv = data->mFile->Clone(getter_AddRefs(fileAsURI)); 
        NS_ENSURE_SUCCESS(rv, rv);
    }
    else
    {
        rv = data->mDataPath->Clone(getter_AddRefs(fileAsURI));
        NS_ENSURE_SUCCESS(rv, rv);
        rv = AppendPathToURI(fileAsURI, data->mFilename);
        NS_ENSURE_SUCCESS(rv, rv);
    }
    nsAutoString newValue;

    // remove username/password if present
    fileAsURI->SetUserPass(EmptyCString());

    // reset node attribute 
    // Use relative or absolute links
    if (data->mDataPathIsRelative)
    {
        nsCOMPtr<nsIURL> url(do_QueryInterface(fileAsURI));
        if (!url)
          return NS_ERROR_FAILURE;
          
        nsCAutoString filename;
        url->GetFileName(filename);

        nsCAutoString rawPathURL(data->mRelativePathToData);
        rawPathURL.Append(filename);

        nsCAutoString buf;
        AppendUTF8toUTF16(NS_EscapeURL(rawPathURL, esc_FilePath, buf),
                          newValue);
    }
    else
    {
        nsCAutoString fileurl;
        fileAsURI->GetSpec(fileurl);
        AppendUTF8toUTF16(fileurl, newValue);
    }
    if (data->mIsSubFrame)
    {
        newValue.Append(data->mSubFrameExt);
    }

    aURI = newValue;
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2651 of file nsWebBrowserPersist.cpp.

{
    NS_ENSURE_ARG_POINTER(aPI);
    nsresult rv = NS_OK;

    nsAutoString data;
    rv = aPI->GetData(data);
    NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);

    nsAutoString href;
    GetQuotedAttributeValue(data, NS_LITERAL_STRING("href"), href);

    // Construct and set a new data value for the xml-stylesheet
    if (!aHref.IsEmpty() && !href.IsEmpty())
    {
        nsAutoString alternate;
        nsAutoString charset;
        nsAutoString title;
        nsAutoString type;
        nsAutoString media;

        GetQuotedAttributeValue(data, NS_LITERAL_STRING("alternate"), alternate);
        GetQuotedAttributeValue(data, NS_LITERAL_STRING("charset"), charset);
        GetQuotedAttributeValue(data, NS_LITERAL_STRING("title"), title);
        GetQuotedAttributeValue(data, NS_LITERAL_STRING("type"), type);
        GetQuotedAttributeValue(data, NS_LITERAL_STRING("media"), media);

        NS_NAMED_LITERAL_STRING(kCloseAttr, "\" ");
        nsAutoString newData;
        newData += NS_LITERAL_STRING("href=\"") + aHref + kCloseAttr;
        if (!title.IsEmpty())
        {
            newData += NS_LITERAL_STRING("title=\"") + title + kCloseAttr;
        }
        if (!media.IsEmpty())
        {
            newData += NS_LITERAL_STRING("media=\"") + media + kCloseAttr;
        }
        if (!type.IsEmpty())
        {
            newData += NS_LITERAL_STRING("type=\"") + type + kCloseAttr;
        }
        if (!charset.IsEmpty())
        {
            newData += NS_LITERAL_STRING("charset=\"") + charset + kCloseAttr;
        }
        if (!alternate.IsEmpty())
        {
            newData += NS_LITERAL_STRING("alternate=\"") + alternate + kCloseAttr;
        }
        newData.Truncate(newData.Length() - 1);  // Remove the extra space on the end.
        aPI->SetData(newData);
    }

    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsWebBrowserPersist::GetDocEncoderContentType ( nsIDOMDocument aDocument,
const PRUnichar aContentType,
PRUnichar **  aRealContentType 
) [protected]

Definition at line 1404 of file nsWebBrowserPersist.cpp.

{
    NS_ENSURE_ARG_POINTER(aDocument);
    NS_ENSURE_ARG_POINTER(aRealContentType);

    *aRealContentType = nsnull;

    nsAutoString defaultContentType(NS_LITERAL_STRING("text/html"));

    // Get the desired content type for the document, either by using the one
    // supplied or from the document itself.

    nsAutoString contentType;
    if (aContentType)
    {
        contentType.Assign(aContentType);
    }
    else
    {
        // Get the content type from the document
        nsCOMPtr<nsIDOMNSDocument> nsDoc = do_QueryInterface(aDocument);
        if (nsDoc)
        {
            nsAutoString type;
            if (NS_SUCCEEDED(nsDoc->GetContentType(type)) && !type.IsEmpty())
            {
                contentType.Assign(type);
            }
        }
    }

    // Check that an encoder actually exists for the desired output type. The
    // following content types will usually yield an encoder.
    //
    //   text/xml
    //   application/xml
    //   application/xhtml+xml
    //   image/svg+xml
    //   text/html
    //   text/plain

    if (!contentType.IsEmpty() &&
        !contentType.Equals(defaultContentType, nsCaseInsensitiveStringComparator()))
    {
        // Check if there is an encoder for the desired content type
        nsCAutoString contractID(NS_DOC_ENCODER_CONTRACTID_BASE);
        contractID.AppendWithConversion(contentType);

        nsCOMPtr<nsIComponentRegistrar> registrar;
        NS_GetComponentRegistrar(getter_AddRefs(registrar));
        if (registrar)
        {
            PRBool result;
            nsresult rv = registrar->IsContractIDRegistered(contractID.get(), &result);
            if (NS_SUCCEEDED(rv) && result)
            {
                *aRealContentType = ToNewUnicode(contentType);
            }
        }
    }

    // Use the default if no encoder exists for the desired one
    if (!*aRealContentType)
    {
        *aRealContentType = ToNewUnicode(defaultContentType);
    }
    
    NS_ENSURE_TRUE(*aRealContentType, NS_ERROR_OUT_OF_MEMORY);

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsWebBrowserPersist::GetDocumentExtension ( nsIDOMDocument aDocument,
PRUnichar **  aExt 
) [protected]

Definition at line 1392 of file nsWebBrowserPersist.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsWebBrowserPersist::GetExtensionForContentType ( const PRUnichar aContentType,
PRUnichar **  aExt 
) [protected]

Definition at line 1362 of file nsWebBrowserPersist.cpp.

{
    NS_ENSURE_ARG_POINTER(aContentType);
    NS_ENSURE_ARG_POINTER(aExt);

    *aExt = nsnull;

    nsresult rv;
    if (!mMIMEService)
    {
        mMIMEService = do_GetService(NS_MIMESERVICE_CONTRACTID, &rv);
        NS_ENSURE_TRUE(mMIMEService, NS_ERROR_FAILURE);
    }

    nsCOMPtr<nsIMIMEInfo> mimeInfo;
    nsCAutoString contentType;
    contentType.AssignWithConversion(aContentType);
    nsCAutoString ext;
    rv = mMIMEService->GetPrimaryExtension(contentType, EmptyCString(), ext);
    if (NS_SUCCEEDED(rv))
    {
        *aExt = UTF8ToNewUnicode(ext);
        NS_ENSURE_TRUE(*aExt, NS_ERROR_OUT_OF_MEMORY);
        return NS_OK;
    }

    return NS_ERROR_FAILURE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIInterfaceRequestor::getInterface ( in nsIIDRef  uuid,
[iid_is(uuid), retval] out nsQIResult  result 
) [inherited]

Retrieves the specified interface pointer.

Parameters:
uuidThe IID of the interface being requested.
result[out] The interface pointer to be filled in if the interface is accessible.
Returns:
NS_OK - interface was successfully returned. NS_NOINTERFACE - interface not accessible. NS_ERROR* - method failure.
nsresult nsWebBrowserPersist::GetLocalFileFromURI ( nsIURI aURI,
nsILocalFile **  aLocalFile 
) const [private]

Definition at line 1146 of file nsWebBrowserPersist.cpp.

{
    nsresult rv;

    nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(aURI, &rv);
    if (NS_FAILED(rv))
        return rv;

    nsCOMPtr<nsIFile> file;
    rv = fileURL->GetFile(getter_AddRefs(file));
    if (NS_SUCCEEDED(rv))
        rv = CallQueryInterface(file, aLocalFile);

    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsWebBrowserPersist::GetNodeToFixup ( nsIDOMNode aNodeIn,
nsIDOMNode **  aNodeOut 
) [private]

Definition at line 2919 of file nsWebBrowserPersist.cpp.

{
    if (!(mPersistFlags & PERSIST_FLAGS_FIXUP_ORIGINAL_DOM))
    {
        nsresult rv = aNodeIn->CloneNode(PR_FALSE, aNodeOut);
        NS_ENSURE_SUCCESS(rv, rv);
    }
    else
    {
        NS_ADDREF(*aNodeOut = aNodeIn);
    }
    nsCOMPtr<nsIDOMHTMLElement> element(do_QueryInterface(*aNodeOut));
    if (element) {
        // Make sure this is not XHTML
        nsAutoString namespaceURI;
        element->GetNamespaceURI(namespaceURI);
        if (namespaceURI.IsEmpty()) {
            // This is a tag-soup node.  It may have a _base_href attribute
            // stuck on it by the parser, but since we're fixing up all URIs
            // relative to the overall document base that will screw us up.
            // Just remove the _base_href.
            element->RemoveAttribute(NS_LITERAL_STRING("_base_href"));
        }
    }
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsWebBrowserPersist::GetQuotedAttributeValue ( const nsAString &  aSource,
const nsAString &  aAttribute,
nsAString &  aValue 
) [private]

Definition at line 2587 of file nsWebBrowserPersist.cpp.

{  
    // NOTE: This code was lifted verbatim from nsParserUtils.cpp
    aValue.Truncate();
    nsAString::const_iterator start, end;
    aSource.BeginReading(start);
    aSource.EndReading(end);
    nsAString::const_iterator iter(end);

    while (start != end) {
        if (FindInReadable(aAttribute, start, iter))
        {
            // walk past any whitespace
            while (iter != end && nsCRT::IsAsciiSpace(*iter))
            {
                ++iter;
            }

            if (iter == end)
                break;
            
            // valid name="value" pair?
            if (*iter != '=')
            {
                start = iter;
                iter = end;
                continue;
            }
            // move past the =
            ++iter;

            while (iter != end && nsCRT::IsAsciiSpace(*iter))
            {
                ++iter;
            }

            if (iter == end)
                break;

            PRUnichar q = *iter;
            if (q != '"' && q != '\'')
            {
                start = iter;
                iter = end;
                continue;
            }

            // point to the first char of the value
            ++iter;
            start = iter;
            if (FindCharInReadable(q, iter, end))
            {
                aValue = Substring(start, iter);
                return PR_TRUE;
            }

            // we've run out of string.  Just return...
            break;
         }
    }
    return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsWebBrowserPersist::GetValidURIFromObject ( nsISupports *  aObject,
nsIURI **  aURI 
) const [private]

Definition at line 1125 of file nsWebBrowserPersist.cpp.

{
    NS_ENSURE_ARG_POINTER(aObject);
    NS_ENSURE_ARG_POINTER(aURI);
    
    nsCOMPtr<nsIFile> objAsFile = do_QueryInterface(aObject);
    if (objAsFile)
    {
        return NS_NewFileURI(aURI, objAsFile);
    }
    nsCOMPtr<nsIURI> objAsURI = do_QueryInterface(aObject);
    if (objAsURI)
    {
        *aURI = objAsURI;
        NS_ADDREF(*aURI);
        return NS_OK;
    }

    return NS_ERROR_FAILURE;
}

Here is the call graph for this function:

Definition at line 2708 of file nsWebBrowserPersist.cpp.

{
    NS_ENSURE_ARG_POINTER(aPI);

    nsresult rv = NS_OK;
    nsAutoString data;
    rv = aPI->GetData(data);
    NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);

    GetQuotedAttributeValue(data, NS_LITERAL_STRING("href"), aHref);

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsWebBrowserPersist::MakeAndStoreLocalFilenameInURIMap ( const char *  aURI,
PRBool  aNeedsPersisting,
URIData **  aData 
) [private]

Definition at line 3609 of file nsWebBrowserPersist.cpp.

{
    NS_ENSURE_ARG_POINTER(aURI);

    nsresult rv;

    // Make a URI
    nsCOMPtr<nsIURI> uri;
    rv = NS_NewURI(getter_AddRefs(uri), nsDependentCString(aURI), 
                   mCurrentCharset.get(), mCurrentBaseURI);
    NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
    nsCAutoString spec;
    rv = uri->GetSpec(spec);
    NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);

    // Create a sensibly named filename for the URI and store in the URI map
    nsCStringKey key(spec.get());
    if (mURIMap.Exists(&key))
    {
        if (aData)
        {
            *aData = (URIData *) mURIMap.Get(&key);
        }
        return NS_OK;
    }

    // Create a unique file name for the uri
    nsString filename;
    rv = MakeFilenameFromURI(uri, filename);
    NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);

    // Store the file name
    URIData *data = new URIData;
    NS_ENSURE_TRUE(data, NS_ERROR_OUT_OF_MEMORY);

    data->mNeedsPersisting = aNeedsPersisting;
    data->mNeedsFixup = PR_TRUE;
    data->mFilename = filename;
    data->mSaved = PR_FALSE;
    data->mIsSubFrame = PR_FALSE;
    data->mDataPath = mCurrentDataPath;
    data->mDataPathIsRelative = mCurrentDataPathIsRelative;
    data->mRelativePathToData = mCurrentRelativePathToData;
    data->mCharset = mCurrentCharset;

    if (aNeedsPersisting)
        mCurrentThingsToPersist++;

    mURIMap.Put(&key, data);
    if (aData)
    {
        *aData = data;
    }

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsWebBrowserPersist::MakeFilenameFromURI ( nsIURI aURI,
nsString aFilename 
) [private]

Definition at line 2081 of file nsWebBrowserPersist.cpp.

{
    // Try to get filename from the URI.
    nsAutoString fileName;

    // Get a suggested file name from the URL but strip it of characters
    // likely to cause the name to be illegal.

    nsCOMPtr<nsIURL> url(do_QueryInterface(aURI));
    if (url)
    {
        nsCAutoString nameFromURL;
        url->GetFileName(nameFromURL);
        if (mPersistFlags & PERSIST_FLAGS_DONT_CHANGE_FILENAMES)
        {
            fileName.AssignWithConversion(NS_UnescapeURL(nameFromURL).get());
            goto end;
        }
        if (!nameFromURL.IsEmpty())
        {
            // Unescape the file name (GetFileName escapes it)
            NS_UnescapeURL(nameFromURL);
            PRUint32 nameLength = 0;
            const char *p = nameFromURL.get();
            for (;*p && *p != ';' && *p != '?' && *p != '#' && *p != '.'
                 ;p++)
            {
                if (nsCRT::IsAsciiAlpha(*p) || nsCRT::IsAsciiDigit(*p)
                    || *p == '.' || *p == '-' ||  *p == '_' || (*p == ' '))
                {
                    fileName.Append(PRUnichar(*p));
                    if (++nameLength == kDefaultMaxFilenameLength)
                    {
                        // Note:
                        // There is no point going any further since it will be
                        // truncated in CalculateUniqueFilename anyway.
                        // More importantly, certain implementations of
                        // nsILocalFile (e.g. the Mac impl) might truncate
                        // names in undesirable ways, such as truncating from
                        // the middle, inserting ellipsis and so on.
                        break;
                    }
                }
            }
        }
    }

    // Empty filenames can confuse the local file object later 
    // when it attempts to set the leaf name in CalculateUniqueFilename
    // for duplicates and ends up replacing the parent dir. To avoid
    // the problem, all filenames are made at least one character long.
    if (fileName.IsEmpty())
    {
        fileName.Append(PRUnichar('a')); // 'a' is for arbitrary
    }
 
end:
    aFilename = fileName;
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsWebBrowserPersist::MakeOutputStream ( nsIURI aFile,
nsIOutputStream **  aOutputStream 
) [private]

Definition at line 2255 of file nsWebBrowserPersist.cpp.

{
    nsresult rv;

    nsCOMPtr<nsILocalFile> localFile;
    GetLocalFileFromURI(aURI, getter_AddRefs(localFile));
    if (localFile)
        rv = MakeOutputStreamFromFile(localFile, aOutputStream);
    else
        rv = MakeOutputStreamFromURI(aURI, aOutputStream);

    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2271 of file nsWebBrowserPersist.cpp.

{
    nsresult rv = NS_OK;

    nsCOMPtr<nsIFileOutputStream> fileOutputStream =
        do_CreateInstance(NS_LOCALFILEOUTPUTSTREAM_CONTRACTID, &rv);
    NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);

    // XXX brade:  get the right flags here!
    rv = fileOutputStream->Init(aFile, -1, -1, 0);
    NS_ENSURE_SUCCESS(rv, rv);

    NS_ENSURE_SUCCESS(CallQueryInterface(fileOutputStream, aOutputStream), NS_ERROR_FAILURE);

    if (mPersistFlags & PERSIST_FLAGS_CLEANUP_ON_FAILURE)
    {
        // Add to cleanup list in event of failure
        CleanupData *cleanupData = new CleanupData;
        NS_ENSURE_TRUE(cleanupData, NS_ERROR_OUT_OF_MEMORY);
        cleanupData->mFile = aFile;
        cleanupData->mIsDirectory = PR_FALSE;
        mCleanupList.AppendElement(cleanupData);
    }

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2300 of file nsWebBrowserPersist.cpp.

{
    PRUint32 segsize = 8192;
    PRUint32 maxsize = PRUint32(-1);
    nsCOMPtr<nsIStorageStream> storStream;
    nsresult rv = NS_NewStorageStream(segsize, maxsize, getter_AddRefs(storStream));
    NS_ENSURE_SUCCESS(rv, rv);
    
    NS_ENSURE_SUCCESS(CallQueryInterface(storStream, aOutputStream), NS_ERROR_FAILURE);
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIStreamListener::onDataAvailable ( in nsIRequest  aRequest,
in nsISupports  aContext,
in nsIInputStream  aInputStream,
in unsigned long  aOffset,
in unsigned long  aCount 
) [inherited]

Called when the next chunk of data (corresponding to the request) may be read without blocking the calling thread.

The onDataAvailable impl must read exactly |aCount| bytes of data before returning.

Parameters:
aRequestrequest corresponding to the source of the data
aContextuser defined context
aInputStreaminput stream containing the data chunk
aOffsetNumber of bytes that were sent in previous onDataAvailable calls for this request. In other words, the sum of all previous count parameters. If that number is greater than or equal to 2^32, this parameter will be PR_UINT32_MAX (2^32 - 1).
aCountnumber of bytes available in the stream

NOTE: The aInputStream parameter must implement readSegments.

An exception thrown from onDataAvailable has the side-effect of causing the request to be canceled.

void nsIProgressEventSink::onProgress ( in nsIRequest  aRequest,
in nsISupports  aContext,
in unsigned long long  aProgress,
in unsigned long long  aProgressMax 
) [inherited]

Called to notify the event sink that progress has occurred for the given request.

Parameters:
aRequestthe request being observed (may QI to nsIChannel).
aContextif aRequest is a channel, then this parameter is the listener context passed to nsIChannel::asyncOpen.
aProgressnumeric value in the range 0 to aProgressMax indicating the number of bytes transfered thus far.
aProgressMaxnumeric value indicating maximum number of bytes that will be transfered (or 0xFFFFFFFFFFFFFFFF if total is unknown).
void nsIRequestObserver::onStartRequest ( in nsIRequest  aRequest,
in nsISupports  aContext 
) [inherited]

Called to signify the beginning of an asynchronous request.

Parameters:
aRequestrequest being observed
aContextuser defined context

An exception thrown from onStartRequest has the side-effect of causing the request to be canceled.

Here is the caller graph for this function:

void nsIProgressEventSink::onStatus ( in nsIRequest  aRequest,
in nsISupports  aContext,
in nsresult  aStatus,
in wstring  aStatusArg 
) [inherited]

Called to notify the event sink with a status message for the given request.

Parameters:
aRequestthe request being observed (may QI to nsIChannel).
aContextif aRequest is a channel, then this parameter is the listener context passed to nsIChannel::asyncOpen.
aStatusstatus code (not necessarily an error code) indicating the state of the channel (usually the state of the underlying transport). see nsISocketTransport for socket specific status codes.
aStatusArgstatus code argument to be used with the string bundle service to convert the status message into localized, human readable text. the meaning of this parameter is specific to the value of the status code. for socket status codes, this parameter indicates the host:port associated with the status code.
void nsIRequestObserver::onStopRequest ( in nsIRequest  aRequest,
in nsISupports  aContext,
in nsresult  aStatusCode 
) [inherited]

Called to signify the end of an asynchronous request.

This call is always preceded by a call to onStartRequest.

Parameters:
aRequestrequest being observed
aContextuser defined context
aStatusCodereason for stopping (NS_OK if completed successfully)

An exception thrown from onStopRequest is generally ignored.

Here is the caller graph for this function:

Definition at line 2722 of file nsWebBrowserPersist.cpp.

{
    // Fixup xml-stylesheet processing instructions
    nsCOMPtr<nsIDOMProcessingInstruction> nodeAsPI = do_QueryInterface(aNode);
    if (nodeAsPI)
    {
        nsAutoString target;
        nodeAsPI->GetTarget(target);
        if (target.EqualsLiteral("xml-stylesheet"))
        {
            nsAutoString href;
            GetXMLStyleSheetLink(nodeAsPI, href);
            if (!href.IsEmpty())
            {
                StoreURI(NS_ConvertUCS2toUTF8(href).get());
            }
        }
    }

    // Test the node to see if it's an image, frame, iframe, css, js
    nsCOMPtr<nsIDOMHTMLImageElement> nodeAsImage = do_QueryInterface(aNode);
    if (nodeAsImage)
    {
        StoreURIAttribute(aNode, "src");
        return NS_OK;
    }

    nsCOMPtr<nsIDOMHTMLBodyElement> nodeAsBody = do_QueryInterface(aNode);
    if (nodeAsBody)
    {
        StoreURIAttribute(aNode, "background");
        return NS_OK;
    }

    nsCOMPtr<nsIDOMHTMLTableElement> nodeAsTable = do_QueryInterface(aNode);
    if (nodeAsTable)
    {
        StoreURIAttribute(aNode, "background");
        return NS_OK;
    }

    nsCOMPtr<nsIDOMHTMLTableRowElement> nodeAsTableRow = do_QueryInterface(aNode);
    if (nodeAsTableRow)
    {
        StoreURIAttribute(aNode, "background");
        return NS_OK;
    }

    nsCOMPtr<nsIDOMHTMLTableCellElement> nodeAsTableCell = do_QueryInterface(aNode);
    if (nodeAsTableCell)
    {
        StoreURIAttribute(aNode, "background");
        return NS_OK;
    }

    nsCOMPtr<nsIDOMHTMLScriptElement> nodeAsScript = do_QueryInterface(aNode);
    if (nodeAsScript)
    {
        StoreURIAttribute(aNode, "src");
        return NS_OK;
    }
    
    nsCOMPtr<nsIDOMHTMLEmbedElement> nodeAsEmbed = do_QueryInterface(aNode);
    if (nodeAsEmbed)
    {
        StoreURIAttribute(aNode, "src");
        return NS_OK;
    }
    
    nsCOMPtr<nsIDOMHTMLObjectElement> nodeAsObject = do_QueryInterface(aNode);
    if (nodeAsObject)
    {
        StoreURIAttribute(aNode, "data");
        return NS_OK;
    }

    nsCOMPtr<nsIDOMHTMLAppletElement> nodeAsApplet = do_QueryInterface(aNode);
    if (nodeAsApplet)
    {
        // For an applet, relative URIs are resolved relative to the
        // codebase (which is resolved relative to the base URI).
        nsCOMPtr<nsIURI> oldBase = mCurrentBaseURI;
        nsAutoString codebase;
        nodeAsApplet->GetCodeBase(codebase);
        if (!codebase.IsEmpty()) {
            nsCOMPtr<nsIURI> baseURI;
            NS_NewURI(getter_AddRefs(baseURI), codebase,
                      mCurrentCharset.get(), mCurrentBaseURI);
            if (baseURI) {
                mCurrentBaseURI = baseURI;
            }
        }
        StoreURIAttribute(aNode, "code");
        StoreURIAttribute(aNode, "archive");
        // restore the base URI we really want to have
        mCurrentBaseURI = oldBase;
        return NS_OK;
    }
    
    nsCOMPtr<nsIDOMHTMLLinkElement> nodeAsLink = do_QueryInterface(aNode);
    if (nodeAsLink)
    {
        // Test if the link has a rel value indicating it to be a stylesheet
        nsAutoString linkRel;
        if (NS_SUCCEEDED(nodeAsLink->GetRel(linkRel)) && !linkRel.IsEmpty())
        {
            nsReadingIterator<PRUnichar> start;
            nsReadingIterator<PRUnichar> end;
            nsReadingIterator<PRUnichar> current;

            linkRel.BeginReading(start);
            linkRel.EndReading(end);

            // Walk through space delimited string looking for "stylesheet"
            for (current = start; current != end; ++current)
            {
                // Ignore whitespace
                if (nsCRT::IsAsciiSpace(*current))
                    continue;

                // Grab the next space delimited word
                nsReadingIterator<PRUnichar> startWord = current;
                do {
                    ++current;
                } while (current != end && !nsCRT::IsAsciiSpace(*current));

                // Store the link for fix up if it says "stylesheet"
                if (Substring(startWord, current)
                        .LowerCaseEqualsLiteral("stylesheet"))
                {
                    StoreURIAttribute(aNode, "href");
                    return NS_OK;
                }
                if (current == end)
                    break;
            }
        }
        return NS_OK;
    }

    nsCOMPtr<nsIDOMHTMLFrameElement> nodeAsFrame = do_QueryInterface(aNode);
    if (nodeAsFrame)
    {
        URIData *data = nsnull;
        StoreURIAttribute(aNode, "src", PR_FALSE, &data);
        if (data)
        {
            data->mIsSubFrame = PR_TRUE;
            // Save the frame content
            nsCOMPtr<nsIDOMDocument> content;
            nodeAsFrame->GetContentDocument(getter_AddRefs(content));
            if (content)
            {
                nsXPIDLString ext;
                GetDocumentExtension(content, getter_Copies(ext));
                data->mSubFrameExt.AssignLiteral(".");
                data->mSubFrameExt.Append(ext);
                SaveSubframeContent(content, data);
            }
        }
        return NS_OK;
    }

    nsCOMPtr<nsIDOMHTMLIFrameElement> nodeAsIFrame = do_QueryInterface(aNode);
    if (nodeAsIFrame && !(mPersistFlags & PERSIST_FLAGS_IGNORE_IFRAMES))
    {
        URIData *data = nsnull;
        StoreURIAttribute(aNode, "src", PR_FALSE, &data);
        if (data)
        {
            data->mIsSubFrame = PR_TRUE;
            // Save the frame content
            nsCOMPtr<nsIDOMDocument> content;
            nodeAsIFrame->GetContentDocument(getter_AddRefs(content));
            if (content)
            {
                nsXPIDLString ext;
                GetDocumentExtension(content, getter_Copies(ext));
                data->mSubFrameExt.AssignLiteral(".");
                data->mSubFrameExt.Append(ext);
                SaveSubframeContent(content, data);
            }
        }
        return NS_OK;
    }

    nsCOMPtr<nsIDOMHTMLInputElement> nodeAsInput = do_QueryInterface(aNode);
    if (nodeAsInput)
    {
        StoreURIAttribute(aNode, "src");
        return NS_OK;
    }

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIWebBrowserPersist::saveChannel ( in nsIChannel  aChannel,
in nsISupports  aFile 
) [inherited]

Save a channel to a file.

It must not be opened yet.

See also:
saveURI
nsresult nsWebBrowserPersist::SaveChannelInternal ( nsIChannel aChannel,
nsIURI aFile,
PRBool  aCalcFileExt 
) [protected]

Definition at line 1326 of file nsWebBrowserPersist.cpp.

{
    NS_ENSURE_ARG_POINTER(aChannel);
    NS_ENSURE_ARG_POINTER(aFile);

    // Read from the input channel
    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
        // data and just ignore it.
        return NS_SUCCESS_DONT_FIXUP;
    }
    else if (NS_FAILED(rv))
    {
        // Opening failed, but do we care?
        if (mPersistFlags & PERSIST_FLAGS_FAIL_ON_BROKEN_LINKS)
        {
            EndDownload(NS_ERROR_FAILURE);
            return NS_ERROR_FAILURE;
        }
        return NS_SUCCESS_DONT_FIXUP;
    }
    else
    {
        // Add the output transport to the output map with the channel as the key
        nsCOMPtr<nsISupports> keyPtr = do_QueryInterface(aChannel);
        nsISupportsKey key(keyPtr);
        mOutputMap.Put(&key, new OutputData(aFile, mURI, aCalcFileExt));
    }

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIWebBrowserPersist::saveDocument ( in nsIDOMDocument  aDocument,
in nsISupports  aFile,
in nsISupports  aDataPath,
in string  aOutputContentType,
in unsigned long  aEncodingFlags,
in unsigned long  aWrapColumn 
) [inherited]

Save the specified DOM document to file and optionally all linked files (e.g.

images, CSS, JS & subframes). Do not call this method until the document has finished loading!

Parameters:
aDocumentDocument to save to file. Some implementations of this interface may also support nsnull to imply the currently loaded document.
aFileTarget local file. This may be a nsILocalFile object or an nsIURI object with a file scheme or a scheme that supports uploading (e.g. ftp).
aDataPathPath to directory where URIs linked to the document are saved or nsnull if no linked URIs should be saved. This may be a nsILocalFile object or an nsIURI object with a file scheme.
aOutputContentTypeThe desired MIME type format to save the document and all subdocuments into or nsnull to use the default behaviour.
aEncodingFlagsFlags to pass to the encoder.
aWrapColumnFor text documents, indicates the desired width to wrap text at. Parameter is ignored if wrapping is not specified by the encoding flags.
See also:
nsILocalFile
nsIURI
Returns:
NS_OK Operation has been started.
NS_ERROR_INVALID_ARG One or more arguments was invalid.
nsresult nsWebBrowserPersist::SaveDocumentInternal ( nsIDOMDocument aDocument,
nsIURI aFile,
nsIURI aDataPath 
) [protected]

Definition at line 1476 of file nsWebBrowserPersist.cpp.

{
    NS_ENSURE_ARG_POINTER(aDocument);
    NS_ENSURE_ARG_POINTER(aFile);

    // See if we can get the local file representation of this URI
    nsCOMPtr<nsILocalFile> localFile;
    nsresult rv = GetLocalFileFromURI(aFile, getter_AddRefs(localFile));

    nsCOMPtr<nsILocalFile> localDataPath;
    if (NS_SUCCEEDED(rv) && aDataPath)
    {
        // See if we can get the local file representation of this URI
        rv = GetLocalFileFromURI(aDataPath, getter_AddRefs(localDataPath));
        NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
    }

    nsCOMPtr<nsIDOMNode> docAsNode = do_QueryInterface(aDocument);

    // Persist the main document
    nsCOMPtr<nsIDocument> doc(do_QueryInterface(aDocument));
    mURI = doc->GetDocumentURI();

    nsCOMPtr<nsIURI> oldBaseURI = mCurrentBaseURI;
    nsCAutoString oldCharset(mCurrentCharset);

    // Store the base URI and the charset
    mCurrentBaseURI = doc->GetBaseURI();
    mCurrentCharset = doc->GetDocumentCharacterSet();

    // Does the caller want to fixup the referenced URIs and save those too?
    if (aDataPath)
    {
        // Basic steps are these.
        //
        // 1. Iterate through the document (and subdocuments) building a list
        //    of unique URIs.
        // 2. For each URI create an OutputData entry and open a channel to save
        //    it. As each URI is saved, discover the mime type and fix up the
        //    local filename with the correct extension.
        // 3. Store the document in a list and wait for URI persistence to finish
        // 4. After URI persistence completes save the list of documents,
        //    fixing it up as it goes out to file.

        nsCOMPtr<nsIURI> oldDataPath = mCurrentDataPath;
        PRBool oldDataPathIsRelative = mCurrentDataPathIsRelative;
        nsCString oldCurrentRelativePathToData = mCurrentRelativePathToData;
        PRUint32 oldThingsToPersist = mCurrentThingsToPersist;

        mCurrentDataPathIsRelative = PR_FALSE;
        mCurrentDataPath = aDataPath;
        mCurrentRelativePathToData = "";
        mCurrentThingsToPersist = 0;

        // Determine if the specified data path is relative to the
        // specified file, (e.g. c:\docs\htmldata is relative to
        // c:\docs\myfile.htm, but not to d:\foo\data.

        // Starting with the data dir work back through its parents
        // checking if one of them matches the base directory.

        if (localDataPath && localFile)
        {
            nsCOMPtr<nsIFile> baseDir;
            localFile->GetParent(getter_AddRefs(baseDir));

            nsCAutoString relativePathToData;
            nsCOMPtr<nsIFile> dataDirParent;
            dataDirParent = localDataPath;
            while (dataDirParent)
            {
                PRBool sameDir = PR_FALSE;
                dataDirParent->Equals(baseDir, &sameDir);
                if (sameDir)
                {
                    mCurrentRelativePathToData = relativePathToData;
                    mCurrentDataPathIsRelative = PR_TRUE;
                    break;
                }

                nsAutoString dirName;
                dataDirParent->GetLeafName(dirName);

                nsCAutoString newRelativePathToData;
                newRelativePathToData = NS_ConvertUTF16toUTF8(dirName)
                                      + NS_LITERAL_CSTRING("/")
                                      + relativePathToData;
                relativePathToData = newRelativePathToData;

                nsCOMPtr<nsIFile> newDataDirParent;
                rv = dataDirParent->GetParent(getter_AddRefs(newDataDirParent));
                dataDirParent = newDataDirParent;
            }
        }
        else
        {
            // generate a relative path if possible
            nsCOMPtr<nsIURL> pathToBaseURL(do_QueryInterface(aFile));
            if (pathToBaseURL)
            {
                nsCAutoString relativePath;  // nsACString
                if (NS_SUCCEEDED(pathToBaseURL->GetRelativeSpec(aDataPath, relativePath)))
                {
                    mCurrentDataPathIsRelative = PR_TRUE;
                    mCurrentRelativePathToData = relativePath;
                }
            }
        }

        // Store the document in a list so when URI persistence is done and the
        // filenames of saved URIs are known, the documents can be fixed up and
        // saved

        DocData *docData = new DocData;
        docData->mBaseURI = mCurrentBaseURI;
        docData->mCharset = mCurrentCharset;
        docData->mDocument = aDocument;
        docData->mFile = aFile;
        docData->mRelativePathToData = mCurrentRelativePathToData;
        docData->mDataPath = mCurrentDataPath;
        docData->mDataPathIsRelative = mCurrentDataPathIsRelative;
        mDocList.AppendElement(docData);

        // Walk the DOM gathering a list of externally referenced URIs in the uri map
        nsCOMPtr<nsIDOMDocumentTraversal> trav = do_QueryInterface(docData->mDocument, &rv);
        NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
        nsCOMPtr<nsIDOMTreeWalker> walker;
        rv = trav->CreateTreeWalker(docAsNode, 
            nsIDOMNodeFilter::SHOW_ELEMENT |
                nsIDOMNodeFilter::SHOW_DOCUMENT |
                nsIDOMNodeFilter::SHOW_PROCESSING_INSTRUCTION,
            nsnull, PR_TRUE, getter_AddRefs(walker));
        NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);

        nsCOMPtr<nsIDOMNode> currentNode;
        walker->GetCurrentNode(getter_AddRefs(currentNode));
        while (currentNode)
        {
            OnWalkDOMNode(currentNode);
            walker->NextNode(getter_AddRefs(currentNode));
        }

        // If there are things to persist, create a directory to hold them
        if (mCurrentThingsToPersist > 0)
        {
            if (localDataPath)
            {
                PRBool exists = PR_FALSE;
                PRBool haveDir = PR_FALSE;

                localDataPath->Exists(&exists);
                if (exists)
                {
                    localDataPath->IsDirectory(&haveDir);
                }
                if (!haveDir)
                {
                    rv = localDataPath->Create(nsILocalFile::DIRECTORY_TYPE, 0755);
                    if (NS_SUCCEEDED(rv))
                        haveDir = PR_TRUE;
                    else
                        SendErrorStatusChange(PR_FALSE, rv, nsnull, aFile);
                }
                if (!haveDir)
                {
                    EndDownload(NS_ERROR_FAILURE);
                    mCurrentBaseURI = oldBaseURI;
                    mCurrentCharset = oldCharset;
                    return NS_ERROR_FAILURE;
                }
                if (mPersistFlags & PERSIST_FLAGS_CLEANUP_ON_FAILURE)
                {
                    // Add to list of things to delete later if all goes wrong
                    CleanupData *cleanupData = new CleanupData;
                    NS_ENSURE_TRUE(cleanupData, NS_ERROR_OUT_OF_MEMORY);
                    cleanupData->mFile = localDataPath;
                    cleanupData->mIsDirectory = PR_TRUE;
                    mCleanupList.AppendElement(cleanupData);
                }
#if defined(XP_OS2)
                // tag the directory with the URI that originated its contents
                nsCOMPtr<nsILocalFileOS2> localFileOS2 = do_QueryInterface(localDataPath);
                if (localFileOS2)
                {
                    nsCAutoString url;
                    mCurrentBaseURI->GetSpec(url);
                    localFileOS2->SetFileSource(url);
                }
#endif
            }
        }

        mCurrentThingsToPersist = oldThingsToPersist;
        mCurrentDataPath = oldDataPath;
        mCurrentDataPathIsRelative = oldDataPathIsRelative;
        mCurrentRelativePathToData = oldCurrentRelativePathToData;
    }
    else
    {
        // Set the document base to ensure relative links still work
        SetDocumentBase(aDocument, mCurrentBaseURI);

        // Get the content type to save with
        nsXPIDLString realContentType;
        GetDocEncoderContentType(aDocument,
            !mContentType.IsEmpty() ? mContentType.get() : nsnull,
            getter_Copies(realContentType));

        nsCAutoString contentType; contentType.AssignWithConversion(realContentType);
        nsCAutoString charType; // Empty

        // Save the document
        nsCOMPtr<nsIDocument> docAsDoc = do_QueryInterface(aDocument);
        rv = SaveDocumentWithFixup(
            docAsDoc,
            nsnull,  // no dom fixup
            aFile,
            mReplaceExisting,
            contentType,
            charType,
            mEncodingFlags);
        NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
    }

    mCurrentBaseURI = oldBaseURI;
    mCurrentCharset = oldCharset;

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1707 of file nsWebBrowserPersist.cpp.

{
    nsresult rv = NS_OK;

    mStartSaving = PR_TRUE;

    // Iterate through all queued documents, saving them to file and fixing
    // them up on the way.

    PRInt32 i;
    for (i = 0; i < mDocList.Count(); i++)
    {
        DocData *docData = (DocData *) mDocList.ElementAt(i);
        if (!docData)
        {
            rv = NS_ERROR_FAILURE;
            break;
        }

        mCurrentBaseURI = docData->mBaseURI;
        mCurrentCharset = docData->mCharset;

        // Save the document, fixing it up with the new URIs as we do
        
        nsEncoderNodeFixup *nodeFixup;
        nodeFixup = new nsEncoderNodeFixup;
        if (nodeFixup)
            nodeFixup->mWebBrowserPersist = this;

        nsCOMPtr<nsIDocument> docAsDoc = do_QueryInterface(docData->mDocument);

        // Get the content type
        nsXPIDLString realContentType;
        GetDocEncoderContentType(docData->mDocument,
            !mContentType.IsEmpty() ? mContentType.get() : nsnull,
            getter_Copies(realContentType));

        nsCAutoString contentType; contentType.AssignWithConversion(realContentType.get());
        nsCAutoString charType; // Empty

        // Save the document, fixing up the links as it goes out
        rv = SaveDocumentWithFixup(
            docAsDoc,
            nodeFixup,
            docData->mFile,
            mReplaceExisting,
            contentType,
            charType,
            mEncodingFlags);

        if (NS_FAILED(rv))
            break;

        // if we're serializing, bail after first iteration of loop
        if (mSerializingOutput)
            break;
    }

    // delete, cleanup regardless of errors (bug 132417)
    for (i = 0; i < mDocList.Count(); i++)
    {
        DocData *docData = (DocData *) mDocList.ElementAt(i);
        delete docData;
        if (mSerializingOutput)
        {
            mDocList.RemoveElementAt(i);
            break;
        }
    }

    if (!mSerializingOutput)
    {
        mDocList.Clear();
    }

    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsWebBrowserPersist::SaveDocumentWithFixup ( nsIDocument pDocument,
nsIDocumentEncoderNodeFixup pFixup,
nsIURI aFile,
PRBool  aReplaceExisting,
const nsACString &  aFormatType,
const nsCString aSaveCharset,
PRUint32  aFlags 
) [private]

Definition at line 3518 of file nsWebBrowserPersist.cpp.

{
    NS_ENSURE_ARG_POINTER(aFile);
    
    nsresult  rv = NS_OK;
    nsCOMPtr<nsILocalFile> localFile;
    GetLocalFileFromURI(aFile, getter_AddRefs(localFile));
    if (localFile)
    {
        // if we're not replacing an existing file but the file
        // exists, something is wrong
        PRBool fileExists = PR_FALSE;
        rv = localFile->Exists(&fileExists);
        NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);

        if (!aReplaceExisting && fileExists)
            return NS_ERROR_FAILURE;                // where are the file I/O errors?
    }
    
    nsCOMPtr<nsIOutputStream> outputStream;
    rv = MakeOutputStream(aFile, getter_AddRefs(outputStream));
    if (NS_FAILED(rv))
    {
        SendErrorStatusChange(PR_FALSE, rv, nsnull, aFile);
        return NS_ERROR_FAILURE;
    }
    NS_ENSURE_TRUE(outputStream, NS_ERROR_FAILURE);

    // Get a document encoder instance
    nsCAutoString contractID(NS_DOC_ENCODER_CONTRACTID_BASE);
    contractID.Append(aFormatType);
    
    nsCOMPtr<nsIDocumentEncoder> encoder = do_CreateInstance(contractID.get(), &rv);
    NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);

    NS_ConvertASCIItoUCS2 newContentType(aFormatType);
    rv = encoder->Init(aDocument, newContentType, aFlags);
    NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);

    mTargetBaseURI = aFile;

    // Set the node fixup callback
    encoder->SetNodeFixup(aNodeFixup);

    if (mWrapColumn && (aFlags & ENCODE_FLAGS_WRAP))
        encoder->SetWrapColumn(mWrapColumn);

    nsCAutoString charsetStr(aSaveCharset);
    if (charsetStr.IsEmpty())
        charsetStr = aDocument->GetDocumentCharacterSet();

    rv = encoder->SetCharset(charsetStr);
    NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);

    rv = encoder->EncodeToStream(outputStream);
    NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
    
    if (!localFile)
    {
        nsCOMPtr<nsIStorageStream> storStream(do_QueryInterface(outputStream));
        if (storStream)
        {
            outputStream->Close();
            rv = StartUpload(storStream, aFile, aFormatType);
            NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
        }
    }
#if defined(XP_OS2)
    else
    {
        // close the stream, then tag the file it created with its source URI
        outputStream->Close();
        nsCOMPtr<nsILocalFileOS2> localFileOS2 = do_QueryInterface(localFile);
        if (localFileOS2)
        {
            nsCAutoString url;
            mCurrentBaseURI->GetSpec(url);
            localFileOS2->SetFileSource(url);
        }
    }
#endif

    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 548 of file nsWebBrowserPersist.cpp.

{
    nsresult rv = NS_OK;

    // Count how many URIs in the URI map require persisting
    PRUint32 urisToPersist = 0;
    if (mURIMap.Count() > 0)
    {
        mURIMap.Enumerate(EnumCountURIsToPersist, &urisToPersist);
    }

    if (urisToPersist > 0)
    {
        // Persist each file in the uri map. The document(s)
        // will be saved after the last one of these is saved.
        mURIMap.Enumerate(EnumPersistURIs, this);
    }

    // if we don't have anything in mOutputMap (added from above enumeration)
    // then we build the doc list (SaveDocuments)
    if (mOutputMap.Count() == 0)
    {
        // There are no URIs to save, so just save the document(s)

        // State start notification
        PRUint32 addToStateFlags = 0;
        if (mProgressListener)
        {
            if (mJustStartedLoading)
            {
                addToStateFlags |= nsIWebProgressListener::STATE_IS_NETWORK;
            }
            mProgressListener->OnStateChange(nsnull, nsnull,
                nsIWebProgressListener::STATE_START | addToStateFlags, NS_OK);
        }

        rv = SaveDocuments();
        if (NS_FAILED(rv))
            EndDownload(rv);
        else if (aFileAsURI)
        {
            // local files won't trigger OnStopRequest so we call EndDownload here
            PRBool isFile = PR_FALSE;
            aFileAsURI->SchemeIs("file", &isFile);
            if (isFile)
                EndDownload(NS_OK);
        }

        // State stop notification
        if (mProgressListener)
        {
            mProgressListener->OnStateChange(nsnull, nsnull,
                nsIWebProgressListener::STATE_STOP | addToStateFlags, rv);
        }
    }

    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsWebBrowserPersist::SaveSubframeContent ( nsIDOMDocument aFrameContent,
URIData aData 
) [private]

Definition at line 3454 of file nsWebBrowserPersist.cpp.

{
    NS_ENSURE_ARG_POINTER(aData);
    nsresult rv;

    nsString filenameWithExt = aData->mFilename;
    filenameWithExt.Append(aData->mSubFrameExt);

    // Work out the path for the subframe
    nsCOMPtr<nsIURI> frameURI;
    rv = mCurrentDataPath->Clone(getter_AddRefs(frameURI));
    NS_ENSURE_SUCCESS(rv, rv);
    rv = AppendPathToURI(frameURI, filenameWithExt);
    NS_ENSURE_SUCCESS(rv, rv);

    // Work out the path for the subframe data
    nsCOMPtr<nsIURI> frameDataURI;
    rv = mCurrentDataPath->Clone(getter_AddRefs(frameDataURI));
    NS_ENSURE_SUCCESS(rv, rv);
    nsAutoString newFrameDataPath(aData->mFilename);

    // Append _data
    newFrameDataPath.AppendLiteral("_data");
    rv = AppendPathToURI(frameDataURI, newFrameDataPath);
    NS_ENSURE_SUCCESS(rv, rv);

    // Make frame document & data path conformant and unique
    rv = CalculateUniqueFilename(frameURI);
    NS_ENSURE_SUCCESS(rv, rv);
    rv = CalculateUniqueFilename(frameDataURI);
    NS_ENSURE_SUCCESS(rv, rv);

    mCurrentThingsToPersist++;
    rv = SaveDocumentInternal(aFrameContent, frameURI, frameDataURI);
    NS_ENSURE_SUCCESS(rv, rv);

    // Store the updated uri to the frame
    aData->mFile = frameURI;
    aData->mSubFrameExt.Truncate(); // we already put this in frameURI

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIWebBrowserPersist::saveURI ( in nsIURI  aURI,
in nsISupports  aCacheKey,
in nsIURI  aReferrer,
in nsIInputStream  aPostData,
in string  aExtraHeaders,
in nsISupports  aFile 
) [inherited]

Save the specified URI to file.

Parameters:
aURIURI to save to file. Some implementations of this interface may also support nsnull to imply the currently loaded URI.
aCacheKeyAn object representing the URI in the cache or nsnull.
aReferrerThe referrer URI to pass with an HTTP request or nsnull.
aPostDataPost data to pass with an HTTP request or nsnull.
aExtraHeadersAdditional headers to supply with an HTTP request or nsnull.
aFileTarget file. This may be a nsILocalFile object or an nsIURI object with a file scheme or a scheme that supports uploading (e.g. ftp).
See also:
nsILocalFile
nsIURI
nsIInputStream
Returns:
NS_OK Operation has been started.
NS_ERROR_INVALID_ARG One or more arguments was invalid.
nsresult nsWebBrowserPersist::SaveURIInternal ( nsIURI aURI,
nsISupports *  aCacheKey,
nsIURI aReferrer,
nsIInputStream aPostData,
const char *  aExtraHeaders,
nsIURI aFile,
PRBool  aCalcFileExt 
) [protected]

Definition at line 1184 of file nsWebBrowserPersist.cpp.

{
    NS_ENSURE_ARG_POINTER(aURI);
    NS_ENSURE_ARG_POINTER(aFile);

    nsresult rv = NS_OK;
    
    mURI = aURI;

    nsLoadFlags loadFlags = nsIRequest::LOAD_NORMAL;
    if (mPersistFlags & PERSIST_FLAGS_BYPASS_CACHE)
    {
        loadFlags |= nsIRequest::LOAD_BYPASS_CACHE;
    }
    else if (mPersistFlags & PERSIST_FLAGS_FROM_CACHE)
    {
        loadFlags |= nsIRequest::LOAD_FROM_CACHE;
    }

    // Extract the cache key
    nsCOMPtr<nsISupports> cacheKey;
    if (aCacheKey)
    {
        // Test if the cache key is actually a web page descriptor (docshell)
        nsCOMPtr<nsIWebPageDescriptor> webPageDescriptor = do_QueryInterface(aCacheKey);
        if (webPageDescriptor)
        {
            nsCOMPtr<nsISupports> currentDescriptor;
            webPageDescriptor->GetCurrentDescriptor(getter_AddRefs(currentDescriptor));
            if (currentDescriptor)
            {
                // Descriptor is actually a session history entry
                nsCOMPtr<nsISHEntry> shEntry = do_QueryInterface(currentDescriptor);
                NS_ASSERTION(shEntry, "The descriptor is meant to be a session history entry");
                if (shEntry)
                {
                    shEntry->GetCacheKey(getter_AddRefs(cacheKey));
                }
            }
        }
        else
        {
            // Assume a plain cache key
            cacheKey = aCacheKey;
        }
    }

    // Open a channel to the URI
    nsCOMPtr<nsIChannel> inputChannel;
    rv = NS_NewChannel(getter_AddRefs(inputChannel), aURI,
            nsnull, nsnull, NS_STATIC_CAST(nsIInterfaceRequestor *, this),
            loadFlags);
    
    if (NS_FAILED(rv) || inputChannel == nsnull)
    {
        EndDownload(NS_ERROR_FAILURE);
        return NS_ERROR_FAILURE;
    }
    
    // Disable content conversion
    if (mPersistFlags & PERSIST_FLAGS_NO_CONVERSION)
    {
        nsCOMPtr<nsIEncodedChannel> encodedChannel(do_QueryInterface(inputChannel));
        if (encodedChannel)
        {
            encodedChannel->SetApplyConversion(PR_FALSE);
        }
    }

    // Set the referrer, post data and headers if any
    nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(inputChannel));
    if (httpChannel)
    {
        // Referrer
        if (aReferrer)
        {
            httpChannel->SetReferrer(aReferrer);
        }

        // Post data
        if (aPostData)
        {
            nsCOMPtr<nsISeekableStream> stream(do_QueryInterface(aPostData));
            if (stream)
            {
                // Rewind the postdata stream
                stream->Seek(nsISeekableStream::NS_SEEK_SET, 0);
                nsCOMPtr<nsIUploadChannel> uploadChannel(do_QueryInterface(httpChannel));
                NS_ASSERTION(uploadChannel, "http must support nsIUploadChannel");
                // Attach the postdata to the http channel
                uploadChannel->SetUploadStream(aPostData, EmptyCString(), -1);
            }
        }

        // Cache key
        nsCOMPtr<nsICachingChannel> cacheChannel(do_QueryInterface(httpChannel));
        if (cacheChannel && cacheKey)
        {
            cacheChannel->SetCacheKey(cacheKey);
        }

        // Headers
        if (aExtraHeaders)
        {
            nsCAutoString oneHeader;
            nsCAutoString headerName;
            nsCAutoString headerValue;
            PRInt32 crlf = 0;
            PRInt32 colon = 0;
            const char *kWhitespace = "\b\t\r\n ";
            nsCAutoString extraHeaders(aExtraHeaders);
            while (PR_TRUE)
            {
                crlf = extraHeaders.Find("\r\n", PR_TRUE);
                if (crlf == -1)
                    break;
                extraHeaders.Mid(oneHeader, 0, crlf);
                extraHeaders.Cut(0, crlf + 2);
                colon = oneHeader.Find(":");
                if (colon == -1)
                    break; // Should have a colon
                oneHeader.Left(headerName, colon);
                colon++;
                oneHeader.Mid(headerValue, colon, oneHeader.Length() - colon);
                headerName.Trim(kWhitespace);
                headerValue.Trim(kWhitespace);
                // Add the header (merging if required)
                rv = httpChannel->SetRequestHeader(headerName, headerValue, PR_TRUE);
                if (NS_FAILED(rv))
                {
                    EndDownload(NS_ERROR_FAILURE);
                    return NS_ERROR_FAILURE;
                }
            }
        }
    }
    return SaveChannelInternal(inputChannel, aFile, aCalcFileExt);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsWebBrowserPersist::SendErrorStatusChange ( PRBool  aIsReadError,
nsresult  aResult,
nsIRequest aRequest,
nsIURI aURI 
) [private]

Definition at line 1044 of file nsWebBrowserPersist.cpp.

{
    NS_ENSURE_ARG_POINTER(aURI);

    if (!mProgressListener)
    {
        // Do nothing
        return NS_OK;
    }

    // Get the file path or spec from the supplied URI
    nsCOMPtr<nsILocalFile> file;
    GetLocalFileFromURI(aURI, getter_AddRefs(file));
    nsAutoString path;
    if (file)
    {
        file->GetPath(path);
    }
    else
    {
        nsCAutoString fileurl;
        aURI->GetSpec(fileurl);
        AppendUTF8toUTF16(fileurl, path);
    }
    
    nsAutoString msgId;
    switch(aResult)
    {
    case NS_ERROR_FILE_NAME_TOO_LONG:
        // File name too long.
        msgId.AssignLiteral("fileNameTooLongError");
        break;
    case NS_ERROR_FILE_ALREADY_EXISTS:
        // File exists with same name as directory.
        msgId.AssignLiteral("fileAlreadyExistsError");
        break;
    case NS_ERROR_FILE_DISK_FULL:
    case NS_ERROR_FILE_NO_DEVICE_SPACE:
        // Out of space on target volume.
        msgId.AssignLiteral("diskFull");
        break;

    case NS_ERROR_FILE_READ_ONLY:
        // Attempt to write to read/only file.
        msgId.AssignLiteral("readOnly");
        break;

    case NS_ERROR_FILE_ACCESS_DENIED:
        // Attempt to write without sufficient permissions.
        msgId.AssignLiteral("accessError");
        break;

    default:
        // Generic read/write error message.
        if (aIsReadError)
            msgId.AssignLiteral("readError");
        else
            msgId.AssignLiteral("writeError");
        break;
    }
    // Get properties file bundle and extract status string.
    nsresult rv;
    nsCOMPtr<nsIStringBundleService> s = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
    NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && s, NS_ERROR_FAILURE);

    nsCOMPtr<nsIStringBundle> bundle;
    rv = s->CreateBundle(kWebBrowserPersistStringBundle, getter_AddRefs(bundle));
    NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && bundle, NS_ERROR_FAILURE);
    
    nsXPIDLString msgText;
    const PRUnichar *strings[1];
    strings[0] = path.get();
    rv = bundle->FormatStringFromName(msgId.get(), strings, 1, getter_Copies(msgText));
    NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);

    mProgressListener->OnStatusChange(nsnull, aRequest, aResult, msgText);

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 609 of file nsWebBrowserPersist.cpp.

{
    if (!mSerializingOutput)
    {
        return PR_FALSE;
    }

    nsresult rv = SaveGatheredURIs(nsnull);
    if (NS_FAILED(rv))
    {
        return PR_FALSE;
    }

    return (mURIMap.Count() 
        || mUploadList.Count()
        || mDocList.Count()
        || mOutputMap.Count());
}

Here is the call graph for this function:

Definition at line 3893 of file nsWebBrowserPersist.cpp.

{
    nsresult rv = NS_OK;
    nsCOMPtr<nsIEncodedChannel> encChannel = do_QueryInterface(aChannel, &rv);
    if (NS_FAILED(rv))
        return;

    // Set the default conversion preference:
    encChannel->SetApplyConversion(PR_FALSE);

    nsCOMPtr<nsIURI> thisURI;
    aChannel->GetURI(getter_AddRefs(thisURI));
    nsCOMPtr<nsIURL> sourceURL(do_QueryInterface(thisURI));
    if (!sourceURL)
        return;
    nsCAutoString extension;
    sourceURL->GetFileExtension(extension);

    nsCOMPtr<nsIUTF8StringEnumerator> encEnum;
    encChannel->GetContentEncodings(getter_AddRefs(encEnum));
    if (!encEnum)
        return;
    nsCOMPtr<nsIExternalHelperAppService> helperAppService =
        do_GetService(NS_EXTERNALHELPERAPPSERVICE_CONTRACTID, &rv);
    if (NS_FAILED(rv))
        return;
    PRBool hasMore;
    rv = encEnum->HasMore(&hasMore);
    if (NS_SUCCEEDED(rv) && hasMore)
    {
        nsCAutoString encType;
        rv = encEnum->GetNext(encType);
        if (NS_SUCCEEDED(rv))
        {
            PRBool applyConversion = PR_FALSE;
            rv = helperAppService->ApplyDecodingForExtension(extension, encType,
                                                             &applyConversion);
            if (NS_SUCCEEDED(rv))
                encChannel->SetApplyConversion(applyConversion);
        }
    }
}

Here is the call graph for this function:

nsresult nsWebBrowserPersist::SetDocumentBase ( nsIDOMDocument aDocument,
nsIURI aBaseURI 
) [private]

Definition at line 3760 of file nsWebBrowserPersist.cpp.

{
    if (mPersistFlags & PERSIST_FLAGS_NO_BASE_TAG_MODIFICATIONS)
    {
        return NS_OK;
    }

    NS_ENSURE_ARG_POINTER(aBaseURI);

    nsCOMPtr<nsIDOMXMLDocument> xmlDoc;
    nsCOMPtr<nsIDOMHTMLDocument> htmlDoc = do_QueryInterface(aDocument);
    if (!htmlDoc)
    {
        xmlDoc = do_QueryInterface(aDocument);
        if (!xmlDoc)
        {
            return NS_ERROR_FAILURE;
        }
    }

    NS_NAMED_LITERAL_STRING(kXHTMLNS, "http://www.w3.org/1999/xhtml");
    NS_NAMED_LITERAL_STRING(kHead, "head");

    // Find the head element
    nsCOMPtr<nsIDOMElement> headElement;
    nsCOMPtr<nsIDOMNodeList> headList;
    if (xmlDoc)
    {
        // First see if there is XHTML content that needs base 
        // tags.
        if (!NeedXHTMLBaseTag(aDocument))
            return NS_OK;

        aDocument->GetElementsByTagNameNS(
            kXHTMLNS,
            kHead, getter_AddRefs(headList));
    }
    else
    {
        aDocument->GetElementsByTagName(
            kHead, getter_AddRefs(headList));
    }
    if (headList)
    {
        nsCOMPtr<nsIDOMNode> headNode;
        headList->Item(0, getter_AddRefs(headNode));
        headElement = do_QueryInterface(headNode);
    }
    if (!headElement)
    {
        // Create head and insert as first element
        nsCOMPtr<nsIDOMNode> firstChildNode;
        nsCOMPtr<nsIDOMNode> newNode;
        if (xmlDoc)
        {
            aDocument->CreateElementNS(
                kXHTMLNS,
                kHead, getter_AddRefs(headElement));
        }
        else
        {
            aDocument->CreateElement(
                kHead, getter_AddRefs(headElement));
        }
        nsCOMPtr<nsIDOMElement> documentElement;
        aDocument->GetDocumentElement(getter_AddRefs(documentElement));
        if (documentElement)
        {
            documentElement->GetFirstChild(getter_AddRefs(firstChildNode));
            documentElement->InsertBefore(headElement, firstChildNode, getter_AddRefs(newNode));
        }
    }
    if (!headElement)
    {
        return NS_ERROR_FAILURE;
    }

    // Find or create the BASE element
    NS_NAMED_LITERAL_STRING(kBase, "base");
    nsCOMPtr<nsIDOMElement> baseElement;
    nsCOMPtr<nsIDOMNodeList> baseList;
    if (xmlDoc)
    {
        headElement->GetElementsByTagNameNS(
            kXHTMLNS,
            kBase, getter_AddRefs(baseList));
    }
    else
    {
        headElement->GetElementsByTagName(
            kBase, getter_AddRefs(baseList));
    }
    if (baseList)
    {
        nsCOMPtr<nsIDOMNode> baseNode;
        baseList->Item(0, getter_AddRefs(baseNode));
        baseElement = do_QueryInterface(baseNode);
    }

    // Add the BASE element
    if (!baseElement)
    {
        if (!baseElement)
        {
            nsCOMPtr<nsIDOMNode> newNode;
            if (xmlDoc)
            {
                aDocument->CreateElementNS(
                    kXHTMLNS,
                    kBase, getter_AddRefs(baseElement));
            }
            else
            {
                aDocument->CreateElement(
                    kBase, getter_AddRefs(baseElement));
            }
            headElement->AppendChild(baseElement, getter_AddRefs(newNode));
        }
    }
    if (!baseElement)
    {
        return NS_ERROR_FAILURE;
    }
    nsCAutoString uriSpec;
    aBaseURI->GetSpec(uriSpec);
    NS_ConvertUTF8toUCS2 href(uriSpec);
    baseElement->SetAttribute(NS_LITERAL_STRING("href"), href);

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsWebBrowserPersist::StartUpload ( nsIStorageStream aOutStream,
nsIURI aDestinationURI,
const nsACString &  aContentType 
) [private]

Definition at line 518 of file nsWebBrowserPersist.cpp.

{
     // setup the upload channel if the destination is not local
    nsCOMPtr<nsIInputStream> inputstream;
    nsresult rv = storStream->NewInputStream(0, getter_AddRefs(inputstream));
    NS_ENSURE_TRUE(inputstream, NS_ERROR_FAILURE);
    NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);

    nsCOMPtr<nsIChannel> destChannel;
    rv = CreateChannelFromURI(aDestinationURI, getter_AddRefs(destChannel));
    nsCOMPtr<nsIUploadChannel> uploadChannel(do_QueryInterface(destChannel));
    NS_ENSURE_TRUE(uploadChannel, NS_ERROR_FAILURE);

    // Set the upload stream
    // NOTE: ALL data must be available in "inputstream"
    rv = uploadChannel->SetUploadStream(inputstream, aContentType, -1);
    NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
    rv = destChannel->AsyncOpen(this, nsnull);
    NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);

    // add this to the upload list
    nsCOMPtr<nsISupports> keyPtr = do_QueryInterface(destChannel);
    nsISupportsKey key(keyPtr);
    mUploadList.Put(&key, new UploadData(aDestinationURI));

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 3447 of file nsWebBrowserPersist.cpp.

{
    // TODO go through the style sheet fixing up all links
    return NS_OK;
}
nsresult nsWebBrowserPersist::StoreURI ( const char *  aURI,
PRBool  aNeedsPersisting = PR_TRUE,
URIData **  aData = nsnull 
) [private]

Definition at line 3217 of file nsWebBrowserPersist.cpp.

{
    NS_ENSURE_ARG_POINTER(aURI);
    if (aData)
        *aData = nsnull;
    
    // Test whether this URL should be persisted
    PRBool shouldPersistURI = PR_TRUE;
    for (PRUint32 i = 0; i < kNonpersistableSchemesSize; i++)
    {
        PRUint32 schemeLen = strlen(kNonpersistableSchemes[i]);
        if (nsCRT::strncasecmp(aURI, kNonpersistableSchemes[i], schemeLen) == 0)
        {
            shouldPersistURI = PR_FALSE;
            break;
        }
    }
    if (shouldPersistURI)
    {
        URIData *data = nsnull;
        MakeAndStoreLocalFilenameInURIMap(aURI, aNeedsPersisting, &data);
        if (aData)
        {
            *aData = data;
        }
    }

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsWebBrowserPersist::StoreURIAttribute ( nsIDOMNode aNode,
const char *  aAttribute,
PRBool  aNeedsPersisting = PR_TRUE,
URIData **  aData = nsnull 
) [private]

Definition at line 3249 of file nsWebBrowserPersist.cpp.

{
    NS_ENSURE_ARG_POINTER(aNode);
    NS_ENSURE_ARG_POINTER(aAttribute);

    nsresult rv = NS_OK;

    // Find the named URI attribute on the (element) node and store
    // a reference to the URI that maps onto a local file name

    nsCOMPtr<nsIDOMNamedNodeMap> attrMap;
    nsCOMPtr<nsIDOMNode> attrNode;
    rv = aNode->GetAttributes(getter_AddRefs(attrMap));
    NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);

    NS_ConvertASCIItoUTF16 attribute(aAttribute);
    rv = attrMap->GetNamedItem(attribute, getter_AddRefs(attrNode));
    if (attrNode)
    {
        nsAutoString oldValue;
        attrNode->GetNodeValue(oldValue);
        if (!oldValue.IsEmpty())
        {
            NS_ConvertUCS2toUTF8 oldCValue(oldValue);
            return StoreURI(oldCValue.get(), aNeedsPersisting, aData);
        }
    }

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class nsEncoderNodeFixup [friend]

Definition at line 76 of file nsWebBrowserPersist.h.


Member Data Documentation

readonly attribute unsigned long nsIWebBrowserPersist::currentState [inherited]

Current state of the persister object.

Definition at line 116 of file nsIWebBrowserPersist.idl.

Convert links to absolute links where possible.

Definition at line 201 of file nsIWebBrowserPersist.idl.

Output only the body section, no HTML tags.

Definition at line 188 of file nsIWebBrowserPersist.idl.

Output with carriage return line breaks.

May also be combined with ENCODE_FLAGS_LF_LINEBREAKS and if neither is specified, the platform default format is used.

Definition at line 216 of file nsIWebBrowserPersist.idl.

Encode basic entities, e.g.

output   instead of character code 0xa0. The basic set is just   & < > " for interoperability with older products that don't support and friends.

Definition at line 233 of file nsIWebBrowserPersist.idl.

Encode HTML4 entities.

This includes the basic set, accented letters, greek letters and certain special markup symbols.

Definition at line 243 of file nsIWebBrowserPersist.idl.

Encode Latin1 entities.

This includes the basic set and accented letters between 128 and 255.

Definition at line 238 of file nsIWebBrowserPersist.idl.

Attempt to encode entities standardized at W3C (HTML, MathML, etc).

This is a catch-all flag for documents with mixed contents. Beware of interoperability issues. See below for other flags which might likely do what you want.

Definition at line 209 of file nsIWebBrowserPersist.idl.

For plaintext output.

Output for format flowed (RFC 2646). This is used when converting to text for mail sending. This differs just slightly but in an important way from normal formatted, and that is that lines are space stuffed. This can't (correctly) be done later.

Definition at line 199 of file nsIWebBrowserPersist.idl.

For plaintext output.

Convert html to plaintext that looks like the html. Implies wrap (except inside <pre>), since html wraps. HTML output: always do prettyprinting, ignoring existing formatting.

Definition at line 181 of file nsIWebBrowserPersist.idl.

Output with linefeed line breaks.

May also be combined with ENCODE_FLAGS_CR_LINEBREAKS and if neither is specified, the platform default format is used.

Definition at line 222 of file nsIWebBrowserPersist.idl.

For plaintext output.

Output the content of noframes elements.

Definition at line 226 of file nsIWebBrowserPersist.idl.

For plaintext output.

Output the content of noscript elements.

Definition at line 224 of file nsIWebBrowserPersist.idl.

Wrap even if when not doing formatted output (e.g.

for text fields).

Definition at line 190 of file nsIWebBrowserPersist.idl.

Output without formatting or wrapping the content.

This flag may be used to preserve the original formatting as much as possible.

Definition at line 186 of file nsIWebBrowserPersist.idl.

Output only the current selection as opposed to the whole document.

Definition at line 175 of file nsIWebBrowserPersist.idl.

Wrap documents at the specified column.

Definition at line 192 of file nsIWebBrowserPersist.idl.

Definition at line 214 of file nsWebBrowserPersist.h.

Definition at line 211 of file nsWebBrowserPersist.h.

Definition at line 216 of file nsWebBrowserPersist.h.

Definition at line 226 of file nsWebBrowserPersist.h.

Definition at line 193 of file nsWebBrowserPersist.h.

Definition at line 194 of file nsWebBrowserPersist.h.

Definition at line 190 of file nsWebBrowserPersist.h.

Definition at line 191 of file nsWebBrowserPersist.h.

Definition at line 192 of file nsWebBrowserPersist.h.

Definition at line 196 of file nsWebBrowserPersist.h.

Definition at line 210 of file nsWebBrowserPersist.h.

Definition at line 225 of file nsWebBrowserPersist.h.

nsCStringArray nsWebBrowserPersist::mFilenameList [private]

Definition at line 212 of file nsWebBrowserPersist.h.

Definition at line 213 of file nsWebBrowserPersist.h.

Definition at line 215 of file nsWebBrowserPersist.h.

Definition at line 198 of file nsWebBrowserPersist.h.

nsHashtable nsWebBrowserPersist::mOutputMap [private]

Definition at line 207 of file nsWebBrowserPersist.h.

Definition at line 220 of file nsWebBrowserPersist.h.

Definition at line 221 of file nsWebBrowserPersist.h.

Definition at line 200 of file nsWebBrowserPersist.h.

Progress listener for 64-bit values; this is the same object as mProgressListener, but is a member to avoid having to qi it for each progress notification.

Definition at line 206 of file nsWebBrowserPersist.h.

Definition at line 218 of file nsWebBrowserPersist.h.

Definition at line 219 of file nsWebBrowserPersist.h.

Definition at line 217 of file nsWebBrowserPersist.h.

Definition at line 195 of file nsWebBrowserPersist.h.

Definition at line 222 of file nsWebBrowserPersist.h.

Definition at line 223 of file nsWebBrowserPersist.h.

nsHashtable nsWebBrowserPersist::mUploadList [private]

Definition at line 208 of file nsWebBrowserPersist.h.

Definition at line 199 of file nsWebBrowserPersist.h.

nsHashtable nsWebBrowserPersist::mURIMap [private]

Definition at line 209 of file nsWebBrowserPersist.h.

Definition at line 224 of file nsWebBrowserPersist.h.

Let the WebBrowserPersist decide whether the incoming data is encoded and whether it needs to go through a content converter e.g.

to decompress it.

Definition at line 96 of file nsIWebBrowserPersist.idl.

Bypass the cached data.

Definition at line 62 of file nsIWebBrowserPersist.idl.

Automatically cleanup after a failed or cancelled operation, deleting all created files and directories.

This flag does nothing for failed upload operations to remote servers.

Definition at line 90 of file nsIWebBrowserPersist.idl.

Don't make any adjustments to filenames.

Definition at line 82 of file nsIWebBrowserPersist.idl.

Don't make any adjustments to links.

Definition at line 78 of file nsIWebBrowserPersist.idl.

Fail on broken inline links.

Definition at line 84 of file nsIWebBrowserPersist.idl.

Fix links relative to destination location (not origin)

Definition at line 76 of file nsIWebBrowserPersist.idl.

Make changes to original dom rather than cloning nodes.

Definition at line 74 of file nsIWebBrowserPersist.idl.

Only use cached data (could result in failure if data is not cached).

Definition at line 60 of file nsIWebBrowserPersist.idl.

Ignore IFRAME content (usually adverts).

Definition at line 66 of file nsIWebBrowserPersist.idl.

Ignore any redirected data (usually adverts).

Definition at line 64 of file nsIWebBrowserPersist.idl.

Don't modify or add base tags.

Definition at line 72 of file nsIWebBrowserPersist.idl.

Do not run the incoming data through a content converter e.g.

to decompress it

Definition at line 68 of file nsIWebBrowserPersist.idl.

No special persistence behaviour.

Definition at line 58 of file nsIWebBrowserPersist.idl.

Replace existing files on the disk (use with due diligence!)

Definition at line 70 of file nsIWebBrowserPersist.idl.

Force serialization of output (one file at a time; not concurrent)

Definition at line 80 of file nsIWebBrowserPersist.idl.

Persister has finished saving data.

Definition at line 111 of file nsIWebBrowserPersist.idl.

Persister is ready to save data.

Definition at line 107 of file nsIWebBrowserPersist.idl.

Persister is saving data.

Definition at line 109 of file nsIWebBrowserPersist.idl.

Flags governing how data is fetched and saved from the network.

It is best to set this value explicitly unless you are prepared to accept the default values.

Definition at line 104 of file nsIWebBrowserPersist.idl.

Callback listener for progress notifications.

The object that the embbedder supplies may also implement nsIInterfaceRequestor and be prepared to return nsIAuthPrompt or other interfaces that may be required to download data.

See also:
nsIAuthPrompt
nsIInterfaceRequestor

Definition at line 137 of file nsIWebBrowserPersist.idl.

readonly attribute unsigned long nsIWebBrowserPersist::result [inherited]

Value indicating the success or failure of the persist operation.

Returns:
NS_OK Operation was successful or is still ongoing.
NS_BINDING_ABORTED Operation cancelled.
NS_ERROR_FAILURE Non-specific failure.

Definition at line 126 of file nsIWebBrowserPersist.idl.


The documentation for this class was generated from the following files: