зеркало из https://github.com/mozilla/pjs.git
Move webbrowserpersist code to components/ directory. b=106554 r=brade@netscape.com sr=sfraser@netscape.com
This commit is contained in:
Родитель
f842bce88a
Коммит
242c80e2b2
|
@ -0,0 +1,50 @@
|
|||
#
|
||||
# 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 mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications, Inc. Portions created by Netscape are
|
||||
# Copyright (C) 2001, Mozilla. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = embedcomponents
|
||||
LIBRARY_NAME = webbrowserpersist_s
|
||||
REQUIRES = xpcom \
|
||||
string \
|
||||
dom \
|
||||
content \
|
||||
necko \
|
||||
widget \
|
||||
exthandler \
|
||||
uriloader \
|
||||
mimetype \
|
||||
webbrowserpersist \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = nsWebBrowserPersist.cpp \
|
||||
nsDOMWalker.cpp
|
||||
$(NULL)
|
||||
|
||||
# we don't want the shared lib, but we want to force the creation of a
|
||||
# static lib.
|
||||
FORCE_STATIC_LIB = 1
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
#!nmake
|
||||
#
|
||||
# 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 mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications, Inc. Portions created by Netscape are
|
||||
# Copyright (C) 2001, Mozilla. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
|
||||
DEPTH=..\..\..\..
|
||||
|
||||
MODULE=webbrowserpersist
|
||||
REQUIRES = xpcom \
|
||||
string \
|
||||
dom \
|
||||
content \
|
||||
necko \
|
||||
widget \
|
||||
exthandler \
|
||||
uriloader \
|
||||
mimetype \
|
||||
$(NULL)
|
||||
|
||||
LIBRARY_NAME=webbrowserpersist_s
|
||||
|
||||
CPP_OBJS= \
|
||||
.\$(OBJDIR)\nsWebBrowserPersist.obj \
|
||||
.\$(OBJDIR)\nsDOMWalker.obj \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
install:: $(LIBRARY)
|
||||
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
|
||||
|
||||
clobber::
|
||||
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib
|
|
@ -0,0 +1,140 @@
|
|||
/* -*- 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 "nsVoidArray.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);
|
||||
|
||||
nsAutoVoidArray stack;
|
||||
PRInt32 stackSize = 0;
|
||||
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.AppendElement(rootPos);
|
||||
stackSize++;
|
||||
|
||||
while (stackSize > 0)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> current;
|
||||
nsCOMPtr<nsIDOMNode> next;
|
||||
|
||||
// Pop the last position off the stack
|
||||
stackSize--;
|
||||
DOMTreePos *currentPos = NS_STATIC_CAST(DOMTreePos *, stack[stackSize]);
|
||||
current = do_QueryInterface(currentPos->current);
|
||||
|
||||
// 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)
|
||||
{
|
||||
if (stackSize < stack.Count())
|
||||
{
|
||||
DOMTreePos *nextPos = NS_STATIC_CAST(DOMTreePos *, stack[stackSize]);
|
||||
nextPos->current = next;
|
||||
}
|
||||
else
|
||||
{
|
||||
DOMTreePos *nextPos = new DOMTreePos;
|
||||
if (nextPos == nsnull)
|
||||
{
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
goto cleanup;
|
||||
}
|
||||
nextPos->current = next;
|
||||
stack.AppendElement(nextPos);
|
||||
}
|
||||
stackSize++;
|
||||
}
|
||||
|
||||
// Push the first child onto the stack
|
||||
if (stackSize < stack.Count())
|
||||
{
|
||||
DOMTreePos *childPos = NS_STATIC_CAST(DOMTreePos *, stack[stackSize]);
|
||||
current->GetFirstChild(getter_AddRefs(childPos->current));
|
||||
}
|
||||
else
|
||||
{
|
||||
DOMTreePos *childPos = new DOMTreePos;
|
||||
if (childPos == nsnull)
|
||||
{
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
goto cleanup;
|
||||
}
|
||||
current->GetFirstChild(getter_AddRefs(childPos->current));
|
||||
stack.AppendElement(childPos);
|
||||
}
|
||||
stackSize++;
|
||||
|
||||
break;
|
||||
}
|
||||
current = next;
|
||||
}
|
||||
}
|
||||
|
||||
cleanup:
|
||||
// Clean the tree in case we came out early
|
||||
PRInt32 i;
|
||||
for (i = 0; i < stack.Count(); i++)
|
||||
{
|
||||
DOMTreePos *pos = NS_STATIC_CAST(DOMTreePos *, stack.ElementAt(i));
|
||||
delete pos;
|
||||
}
|
||||
stack.Clear();
|
||||
|
||||
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
|
|
@ -117,8 +117,8 @@ nsWebBrowserPersist::nsWebBrowserPersist() :
|
|||
mCancel(PR_FALSE),
|
||||
mJustStartedLoading(PR_TRUE),
|
||||
mCompleted(PR_FALSE),
|
||||
mPersistResult(NS_OK),
|
||||
mPersistFlags(PERSIST_FLAGS_NONE)
|
||||
mPersistFlags(PERSIST_FLAGS_NONE),
|
||||
mPersistResult(NS_OK)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
@ -972,7 +972,7 @@ nsWebBrowserPersist::EnumPersistURIs(nsHashKey *aKey, void *aData, void* closure
|
|||
rv = data->mDataPath->Clone(getter_AddRefs(fileAsFile));
|
||||
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
||||
nsCOMPtr<nsILocalFile> file = do_QueryInterface(fileAsFile);
|
||||
file->AppendRelativePath(filename);
|
||||
file->AppendRelativePath(filename.get());
|
||||
|
||||
rv = pthis->SaveURIInternal(uri, nsnull, file, PR_TRUE);
|
||||
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
||||
|
@ -1207,7 +1207,7 @@ nsWebBrowserPersist::StoreURIAttribute(
|
|||
attrNode->GetNodeValue(oldValue);
|
||||
nsCString oldCValue; oldCValue.AssignWithConversion(oldValue);
|
||||
URIData *data = nsnull;
|
||||
MakeAndStoreLocalFilenameInURIMap(oldCValue, aNeedsPersisting, &data);
|
||||
MakeAndStoreLocalFilenameInURIMap(oldCValue.get(), aNeedsPersisting, &data);
|
||||
if (aData)
|
||||
{
|
||||
*aData = data;
|
||||
|
@ -1270,7 +1270,7 @@ nsWebBrowserPersist::FixupNodeAttribute(nsIDOMNode *aNode, char *aAttribute)
|
|||
nsCAutoString rawPathURL;
|
||||
rawPathURL.Assign(data->mRelativePathToData);
|
||||
rawPathURL.Append(filename.get());
|
||||
newValue.AssignWithConversion(nsEscape(rawPathURL, url_Path));
|
||||
newValue.AssignWithConversion(nsEscape(rawPathURL.get(), url_Path));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1407,7 +1407,7 @@ nsWebBrowserPersist::SaveDocumentToFileWithFixup(
|
|||
nsCAutoString contractID(NS_DOC_ENCODER_CONTRACTID_BASE);
|
||||
contractID.AppendWithConversion(aFormatType);
|
||||
|
||||
nsCOMPtr<nsIDocumentEncoder> encoder = do_CreateInstance(contractID, &rv);
|
||||
nsCOMPtr<nsIDocumentEncoder> encoder = do_CreateInstance(contractID.get(), &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
|
|
|
@ -0,0 +1,167 @@
|
|||
/* -*- 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 "nsWeakReference.h"
|
||||
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsIMIMEService.h"
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsIOutputStream.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIChannel.h"
|
||||
#include "nsIStyleSheet.h"
|
||||
#include "nsIDocumentEncoder.h"
|
||||
#include "nsITransport.h"
|
||||
#include "nsIProgressEventSink.h"
|
||||
#include "nsILocalFile.h"
|
||||
#include "nsIWebProgressListener.h"
|
||||
|
||||
#include "nsHashtable.h"
|
||||
#include "nsVoidArray.h"
|
||||
|
||||
#include "nsCWebBrowserPersist.h"
|
||||
#include "nsDOMWalker.h"
|
||||
|
||||
class nsEncoderNodeFixup;
|
||||
struct URIData;
|
||||
|
||||
class nsWebBrowserPersist : public nsIInterfaceRequestor,
|
||||
public nsIWebBrowserPersist,
|
||||
public nsIStreamListener,
|
||||
public nsDOMWalkerCallback,
|
||||
public nsIProgressEventSink,
|
||||
public nsSupportsWeakReference
|
||||
{
|
||||
friend class nsEncoderNodeFixup;
|
||||
|
||||
// Public members
|
||||
public:
|
||||
nsWebBrowserPersist();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIINTERFACEREQUESTOR
|
||||
NS_DECL_NSIWEBBROWSERPERSIST
|
||||
NS_DECL_NSIREQUESTOBSERVER
|
||||
NS_DECL_NSISTREAMLISTENER
|
||||
NS_DECL_NSIPROGRESSEVENTSINK
|
||||
|
||||
// Protected members
|
||||
protected:
|
||||
virtual ~nsWebBrowserPersist();
|
||||
nsresult CloneNodeWithFixedUpURIAttributes(
|
||||
nsIDOMNode *aNodeIn, nsIDOMNode **aNodeOut);
|
||||
nsresult SaveURIInternal(
|
||||
nsIURI *aURI, nsIInputStream *aPostData, nsILocalFile *aFile,
|
||||
PRBool aCalcFileExt);
|
||||
nsresult SaveDocumentInternal(nsIDOMDocument *aDocument,
|
||||
nsILocalFile *aFile, nsILocalFile *aDataPath);
|
||||
nsresult SaveDocuments();
|
||||
|
||||
// Private members
|
||||
private:
|
||||
void CleanUp();
|
||||
nsresult MakeAndStoreLocalFilenameInURIMap(
|
||||
const char *aURI, PRBool aNeedsPersisting, URIData **aData);
|
||||
nsresult MakeOutputStream(
|
||||
nsILocalFile *aFile, PRBool aCalcFileExt,
|
||||
nsIChannel *aChannel, nsIOutputStream **aOutputStream);
|
||||
nsresult MakeFilenameFromURI(
|
||||
nsIURI *aURI, nsString &aFilename);
|
||||
nsresult StoreURIAttribute(
|
||||
nsIDOMNode *aNode, char *aAttribute, PRBool aNeedsPersisting = PR_TRUE,
|
||||
URIData **aData = nsnull);
|
||||
nsresult FixupNodeAttribute(nsIDOMNode *aNode, char *aAttribute);
|
||||
nsresult FixupAnchor(nsIDOMNode *aNode);
|
||||
nsresult StoreAndFixupStyleSheet(nsIStyleSheet *aStyleSheet);
|
||||
nsresult SaveDocumentToFileWithFixup(
|
||||
nsIDocument *pDocument, nsIDocumentEncoderNodeFixup *pFixup,
|
||||
nsIFile *aFile, PRBool aReplaceExisting, PRBool aSaveCopy,
|
||||
const nsString &aFormatType, const nsString &aSaveCharset,
|
||||
PRUint32 aFlags);
|
||||
nsresult SaveSubframeContent(
|
||||
nsIDOMDocument *aFrameContent, URIData *aData);
|
||||
nsresult SetDocumentBase(nsIDOMDocument *aDocument, nsIURI *aBaseURI);
|
||||
|
||||
nsresult FixRedirectedChannelEntry(nsIChannel *aNewChannel);
|
||||
|
||||
void EndDownload(nsresult aResult = NS_OK);
|
||||
void CalcTotalProgress();
|
||||
|
||||
// nsDOMWalkerCallback method
|
||||
nsresult OnWalkDOMNode(nsIDOMNode *aNode, PRBool *aAbort);
|
||||
|
||||
// Hash table enumerators
|
||||
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 EnumCalcProgress(
|
||||
nsHashKey *aKey, void *aData, void* closure);
|
||||
static PRBool PR_CALLBACK EnumFixRedirect(
|
||||
nsHashKey *aKey, void *aData, void* closure);
|
||||
|
||||
nsCOMPtr<nsILocalFile> mCurrentDataPath;
|
||||
PRBool mCurrentDataPathIsRelative;
|
||||
nsCString mCurrentRelativePathToData;
|
||||
nsCOMPtr<nsIURI> mCurrentBaseURI;
|
||||
|
||||
nsCOMPtr<nsIMIMEService> mMIMEService;
|
||||
nsCOMPtr<nsIURI> mURI;
|
||||
nsCOMPtr<nsIWebProgressListener> mProgressListener;
|
||||
nsHashtable mOutputMap;
|
||||
nsHashtable mURIMap;
|
||||
nsVoidArray mDocList;
|
||||
PRUint32 mFileCounter;
|
||||
PRUint32 mFrameCounter;
|
||||
PRBool mFirstAndOnlyUse;
|
||||
PRBool mCancel;
|
||||
PRBool mJustStartedLoading;
|
||||
PRBool mCompleted;
|
||||
PRUint32 mPersistFlags;
|
||||
PRUint32 mPersistResult;
|
||||
PRInt32 mTotalCurrentProgress;
|
||||
PRInt32 mTotalMaxProgress;
|
||||
|
||||
};
|
||||
|
||||
// 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
|
Загрузка…
Ссылка в новой задаче