New persistence object and helper classes. b=46574, sr=blizzard@mozilla.org

This commit is contained in:
locka%iol.ie 2000-11-29 23:41:54 +00:00
Родитель 2dbc59dbed
Коммит 88a8521783
5 изменённых файлов: 1383 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,118 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications, Inc. Portions created by Netscape are
* Copyright (C) 1999, Mozilla. All Rights Reserved.
*
* Contributor(s):
* Adam Lock <adamlock@netscape.com>
*/
#include "nsVector.h"
#include "nsCOMPtr.h"
#include "nsDOMWalker.h"
struct DOMTreePos
{
nsCOMPtr<nsIDOMNode> current;
};
nsresult nsDOMWalker::WalkDOM(nsIDOMNode *aRootNode, nsDOMWalkerCallback *aCallback)
{
NS_ENSURE_ARG_POINTER(aRootNode);
NS_ENSURE_ARG_POINTER(aCallback);
nsVector stack;
nsresult rv = NS_OK;
// Push the top most node onto the stack
DOMTreePos *rootPos = new DOMTreePos;
if (rootPos == nsnull)
{
return NS_ERROR_OUT_OF_MEMORY;
}
rootPos->current = aRootNode;
stack.Add(rootPos);
while (stack.size > 0)
{
nsCOMPtr<nsIDOMNode> current;
nsCOMPtr<nsIDOMNode> next;
// Pop the last position off the stack
DOMTreePos *pos = (DOMTreePos *) stack.Get(stack.size - 1);
stack.Remove(stack.size - 1);
current = do_QueryInterface(pos->current);
delete pos;
// Iterate through each sibling
while (current)
{
PRBool hasChildNodes = PR_FALSE;
current->GetNextSibling(getter_AddRefs(next));
current->HasChildNodes(&hasChildNodes);
// Call the callback to let them do what they want to do
if (aCallback)
{
PRBool abort = PR_FALSE;
aCallback->OnWalkDOMNode(current, &abort);
if (abort)
{
goto cleanup;
}
}
if (hasChildNodes)
{
// Push the current node back onto the stack
if (next)
{
DOMTreePos *nextPos = new DOMTreePos;
if (nextPos == nsnull)
{
rv = NS_ERROR_OUT_OF_MEMORY;
goto cleanup;
}
nextPos->current = next;
stack.Add(nextPos);
}
// Push the first child onto the stack
DOMTreePos *childPos = new DOMTreePos;
if (childPos == nsnull)
{
rv = NS_ERROR_OUT_OF_MEMORY;
goto cleanup;
}
current->GetFirstChild(getter_AddRefs(childPos->current));
stack.Add(childPos);
break;
}
current = next;
}
}
cleanup:
// Clean the tree in case we came out early
while (stack.size > 0)
{
DOMTreePos *pos = (DOMTreePos *) stack.Get(stack.size - 1);
stack.Remove(stack.size - 1);
delete pos;
}
return rv;
}

Просмотреть файл

@ -0,0 +1,40 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications, Inc. Portions created by Netscape are
* Copyright (C) 1999, Mozilla. All Rights Reserved.
*
* Contributor(s):
* Adam Lock <adamlock@netscape.com>
*/
#ifndef NSDOMWALKER_H
#define NSDOMWALKER_H
#include <nsIDOMNode.h>
class nsDOMWalkerCallback
{
public:
virtual nsresult OnWalkDOMNode(nsIDOMNode *aNode, PRBool *aAbort) = 0;
};
class nsDOMWalker
{
public:
nsresult WalkDOM(nsIDOMNode *aRootNode, nsDOMWalkerCallback *aCallback = nsnull);
};
#endif

Просмотреть файл

@ -0,0 +1,96 @@
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications, Inc. Portions created by Netscape are
* Copyright (C) 1999, Mozilla. All Rights Reserved.
*
* Contributor(s):
* Adam Lock <adamlock@netscape.com>
*/
#include "nsISupports.idl"
interface nsIURI;
interface nsIInputStream;
interface nsIDOMDocument;
[scriptable, uuid(F823C5B0-AF6C-11d4-9597-0020183BF181)]
interface nsIWebBrowserPersistProgress : nsISupports
{
/**
* Flags that indicate the beginning and end of ALL downloading.
* Every operation with begin with a call to the listener with a
* PROGRESS_STARTED flag and finish with a PROGRESS_FINISHED flag.
*/
const unsigned long PROGRESS_STARTED = 1;
const unsigned long PROGRESS_FINISHED = 2;
/**
* Flags that indicate the progress of a particular URI
*/
const unsigned long PROGRESS_START_URI = 4;
const unsigned long PROGRESS_END_URI = 8;
/**
* Called as the downloading progresses.
*
* aStatus - Status flags indicating the state of progress.
* aURI - URI to which the progress refers or nsnull when it refers
* to everything.
* aAbort -
*/
void OnProgress(in unsigned long aStatus, in nsIURI aURI, out boolean aAbort);
};
/**
* The nsIWebBrowserPersist
*/
[scriptable, uuid(814ba433-a816-4785-9f95-ad3ba0a43dab)]
interface nsIWebBrowserPersist : nsISupports
{
/**
* Callback listener for progress notifications.
*/
attribute nsIWebBrowserPersistProgress progressListener;
/**
* Save the specified URI to file.
*
* aURI - The URI to save to file.
* aPostData - Data to pass with in an HTTP request or nsnull.
* aFileName - Target local filename.
*/
void saveURI(in nsIURI aURI, in nsIInputStream aPostData, in string aFileName);
/*
* Save the current URI (in the browser) to file. Internal implementation
* calls saveURI passing in the current URI and postdata.
*
* aFileName - Target local filename.
*/
void saveCurrentURI(in string aFileName);
/**
* Save the specified DOM document to file and optionally all linked files
* including images, CSS, JS & frames.
*
* aDocument - Document to save.
* aFileName - Target local filename.
* aDataPath - Path to folder (which must exist) to save linked files to,
* or nsnull.
*/
void saveDocument(in nsIDOMDocument aDocument, in string aFileName, in string aDataPath);
};

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,126 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications, Inc. Portions created by Netscape are
* Copyright (C) 1999, Mozilla. All Rights Reserved.
*
* Contributor(s):
* Adam Lock <adamlock@netscape.com>
*/
#ifndef nsWebBrowserPersist_h__
#define nsWebBrowserPersist_h__
#include <nsCOMPtr.h>
#include <nsIMIMEService.h>
#include <nsIStreamListener.h>
#include <nsIOutputStream.h>
#include <nsIInputStream.h>
#include <nsIFileStream.h>
#include <nsIChannel.h>
#include <nsIStyleSheet.h>
#include <nsIDocumentEncoder.h>
#include <nsHashtable.h>
#include "nsIWebBrowserPersist.h"
#include "nsDOMWalker.h"
class nsEncoderNodeFixup;
class nsWebBrowserPersist : public nsIWebBrowserPersist,
public nsIWebBrowserPersistProgress,
public nsIStreamListener,
public nsDOMWalkerCallback
{
friend nsEncoderNodeFixup;
// Public members
public:
nsWebBrowserPersist();
NS_DECL_ISUPPORTS
NS_DECL_NSIWEBBROWSERPERSIST
NS_DECL_NSIWEBBROWSERPERSISTPROGRESS
NS_DECL_NSISTREAMOBSERVER
NS_DECL_NSISTREAMLISTENER
// Protected members
protected:
virtual ~nsWebBrowserPersist();
nsresult CloneNodeWithFixedUpURIAttributes(nsIDOMNode *aNodeIn, nsIDOMNode **aNodeOut);
// Private members
private:
void CleanUp();
nsresult MakeAndStoreLocalFilenameInURIMap(const char *aURI, nsString &aFilename, PRBool aNeedsPersisting);
nsresult MakeFilenameFromURI(nsIURI *aURI, nsIChannel *aChannel, nsString &aFilename);
nsresult StoreURIAttribute(nsIDOMNode *aNode, char *aAttribute, PRBool aNeedsPersisting = PR_TRUE, nsString *aFilename = nsnull);
nsresult FixupNodeAttribute(nsIDOMNode *aNode, char *aAttribute);
nsresult StoreAndFixupStyleSheet(nsIStyleSheet *aStyleSheet);
nsresult SaveDocumentToFileWithFixup(
nsIDocument *pDocument,
nsIDocumentEncoderNodeFixup *pFixup,
nsFileSpec* aFileSpec,
PRBool aReplaceExisting,
PRBool aSaveCopy,
const nsString& aFormatType,
const nsString& aSaveCharset,
PRUint32 aFlags);
nsresult SaveSubframeContent(nsIDOMDocument *aFrameContent, const nsString &aFilename);
void OnBeginDownload();
void OnEndDownload();
// nsDOMWalkerCallback method
nsresult OnWalkDOMNode(nsIDOMNode *aNode, PRBool *aAbort);
// Hash table enumerators
static PRBool PR_CALLBACK PersistURIs(nsHashKey *aKey, void *aData, void* closure);
static PRBool PR_CALLBACK CleanupURIMap(nsHashKey *aKey, void *aData, void* closure);
nsCOMPtr<nsIMIMEService> mMIMEService;
nsCOMPtr<nsIChannel> mInputChannel;
nsCOMPtr<nsIInputStream> mInputStream;
nsCOMPtr<nsIChannel> mOutputChannel;
nsCOMPtr<nsIOutputStream> mOutputStream;
nsCOMPtr<nsIURI> mBaseURI;
nsCOMPtr<nsIURI> mURI;
nsCOMPtr<nsIWebBrowserPersistProgress> mProgressListener;
PRUint32 mFileCounter;
PRUint32 mFrameCounter;
PRUint32 mTaskCounter;
nsCString mDataPath;
nsHashtable mURIMap;
PRBool mFirstAndOnlyUse;
};
// Helper class does node fixup during persistence
class nsEncoderNodeFixup : public nsIDocumentEncoderNodeFixup
{
public:
nsEncoderNodeFixup();
NS_DECL_ISUPPORTS
NS_IMETHOD FixupNode(nsIDOMNode *aNode, nsIDOMNode **aOutNode);
nsWebBrowserPersist *mWebBrowserPersist;
protected:
virtual ~nsEncoderNodeFixup();
};
#endif