Initial checkin for new SessionHistory component

git-svn-id: svn://10.0.0.236/trunk@54192 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
radha%netscape.com 1999-11-22 22:49:01 +00:00
parent 32e419cc84
commit 5c61905f0e
6 changed files with 678 additions and 1 deletions

View File

@ -30,7 +30,10 @@ MODULE = history
LIBRARY_NAME = history
IS_COMPONENT = 1
CPPSRCS = nsGlobalHistory.cpp
CPPSRCS = nsGlobalHistory.cpp \
nsSHEntry.cpp \
nsSHTransaction.cpp \
$(NULL)
EXTRA_DSO_LDOPTS = \
-L$(DIST)/bin \

View File

@ -24,10 +24,14 @@ MODULE=history
CPPSRCS= \
nsGlobalHistory.obj \
nsSHEntry.obj \
nsSHTrasaction.obj \
$(NULL)
CPP_OBJS= \
.\$(OBJDIR)\nsGlobalHistory.obj \
.\$(OBJDIR)\nsSHEntry.obj \
.\$(OBJDIR)\nsSHTransaction.obj \
$(NULL)
MAKE_OBJ_TYPE=DLL

View File

@ -0,0 +1,405 @@
/* -*- 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):
* Radha Kulkarni <radha@netscape.com>
*/
#include "nsISupportsUtils.h"
//#include "nsCOMPtr.h"
#include "nsIDOMDocument.h"
#include "nsSHEntry.h"
#ifdef XXX_NS_DEBUG // XXX: we'll need a logging facility for debugging
#define WEB_TRACE(_bit,_args) \
PR_BEGIN_MACRO \
if (WEB_LOG_TEST(gLogModule,_bit)) { \
PR_LogPrint _args; \
} \
PR_END_MACRO
#else
#define WEB_TRACE(_bit,_args)
#endif
//*****************************************************************************
//*** nsSHEnumerator: Object Management
//*****************************************************************************
class nsSHEnumerator : public nsIEnumerator
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIENUMERATOR
NS_IMETHOD CurrentItem(nsISHEntry ** aItem);
private:
friend class nsSHEntry;
nsSHEnumerator(nsSHEntry * aEntry);
virtual ~nsSHEnumerator();
PRInt32 mIndex;
nsSHEntry * mSHEntry;
};
//*****************************************************************************
//*** nsSHEntry: Object Management
//*****************************************************************************
nsSHEntry::nsSHEntry()
{
NS_INIT_REFCNT();
mURI = (nsnull);
mPostData = (nsnull);
mDocument= (nsnull);
mLayoutHistoryState= (nsnull);
}
NS_IMETHODIMP
nsSHEntry::Create(nsIURI * aURI, const PRUnichar * aTitle, nsIDOMDocument * aDOMDocument,
nsIInputStream * aInputStream, nsISupports * aHistoryLayoutState)
{
SetUri(aURI);
SetTitle(aTitle);
SetDocument(aDOMDocument);
SetPostData(aInputStream);
SetLayoutHistoryState(aHistoryLayoutState);
return NS_OK;
}
nsSHEntry::~nsSHEntry()
{
NS_IF_RELEASE(mURI);
NS_IF_RELEASE(mPostData);
NS_IF_RELEASE(mDocument);
NS_IF_RELEASE(mLayoutHistoryState);
if (mTitle)
delete mTitle;
DestroyChildren();
}
void
nsSHEntry::DestroyChildren() {
PRInt32 i, n;
n = GetChildCount(&n);
for (i = 0; i < n; i++) {
nsISHEntry* child = (nsISHEntry *) mChildren.ElementAt(i);
child->SetParent(nsnull); // Weak reference to parent
delete child;
}
mChildren.Clear();
}
// nsSHEntry::nsISupports
NS_IMPL_ISUPPORTS2(nsSHEntry, nsISHEntry, nsISHContainer)
NS_IMETHODIMP
nsSHEntry::GetUri(nsIURI **aUri)
{
NS_ENSURE_ARG_POINTER(aUri);
*aUri = mURI;
NS_IF_ADDREF(mURI);
return NS_OK;
}
NS_IMETHODIMP
nsSHEntry::SetUri(nsIURI * aUri)
{
NS_IF_RELEASE(mURI);
mURI = aUri;
NS_IF_ADDREF(mURI);
return NS_OK;
}
NS_IMETHODIMP
nsSHEntry::SetDocument(nsIDOMDocument * aDocument)
{
NS_IF_RELEASE(mDocument);
mDocument = aDocument;
NS_IF_ADDREF(mDocument);
return NS_OK;
}
NS_IMETHODIMP
nsSHEntry::GetDocument(nsIDOMDocument ** aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = mDocument;
NS_IF_ADDREF(mDocument);
return NS_OK;
}
NS_IMETHODIMP
nsSHEntry::GetTitle(PRUnichar** aTitle)
{
NS_ENSURE_ARG_POINTER(aTitle);
if (mTitle)
*aTitle = mTitle->ToNewUnicode();
return NS_OK;
}
NS_IMETHODIMP
nsSHEntry::SetTitle(const PRUnichar* aTitle)
{
if (mTitle)
delete mTitle;
if (aTitle)
mTitle = new nsString(aTitle);
return NS_OK;
}
NS_IMETHODIMP
nsSHEntry::GetPostData(nsIInputStream ** aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = mPostData;
NS_IF_ADDREF(mPostData);
return NS_OK;
}
NS_IMETHODIMP
nsSHEntry::SetPostData(nsIInputStream * aPostData)
{
NS_IF_RELEASE(mPostData);
mPostData = aPostData;
NS_IF_ADDREF(aPostData);
return NS_OK;
}
NS_IMETHODIMP
nsSHEntry::GetLayoutHistoryState(nsISupports ** aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = mLayoutHistoryState;
NS_IF_ADDREF(mLayoutHistoryState);
return NS_OK;
}
NS_IMETHODIMP
nsSHEntry::SetLayoutHistoryState(nsISupports * aState)
{
NS_IF_RELEASE(mLayoutHistoryState);
mLayoutHistoryState = aState;
NS_IF_ADDREF(aState);
return NS_OK;
}
NS_IMETHODIMP
nsSHEntry::GetParent(nsISHEntry ** aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = mParent;
NS_IF_ADDREF(*aResult);
return NS_OK;
}
NS_IMETHODIMP
nsSHEntry::SetParent(nsISHEntry * aParent)
{
/* parent not Addrefed on purpose to avoid cyclic reference
* Null parent is OK
*/
mParent = aParent;
return NS_OK;
}
NS_IMETHODIMP
nsSHEntry::GetChildCount(PRInt32 * aCount)
{
NS_ENSURE_ARG_POINTER(aCount);
*aCount = mChildren.Count();
return NS_OK;
}
NS_IMETHODIMP
nsSHEntry::AddChild(nsISHEntry * aChild)
{
NS_ENSURE_ARG_POINTER(aChild);
NS_ENSURE_SUCCESS(aChild->SetParent(this), NS_ERROR_FAILURE);
mChildren.AppendElement((void *)aChild);
NS_ADDREF(aChild);
return NS_OK;
}
NS_IMETHODIMP
nsSHEntry::RemoveChild(nsISHEntry * aChild)
{
NS_ENSURE_ARG_POINTER(aChild);
PRBool childRemoved = mChildren.RemoveElement((void *)aChild);
if (childRemoved) {
aChild->SetParent(nsnull);
NS_RELEASE(aChild);
}
return NS_OK;
}
NS_IMETHODIMP
nsSHEntry::GetChildEnumerator(nsIEnumerator** aChildEnumerator)
{
nsresult status = NS_OK;
NS_ENSURE_ARG_POINTER(aChildEnumerator);
nsSHEnumerator * iterator = new nsSHEnumerator(this);
if (iterator && !!NS_SUCCEEDED(status = CallQueryInterface(iterator, aChildEnumerator)))
delete iterator;
return status;
}
//*****************************************************************************
//*** nsSHEnumerator: Object Management
//*****************************************************************************
nsSHEnumerator::nsSHEnumerator(nsSHEntry * aEntry):mIndex(0)
{
NS_INIT_REFCNT();
mSHEntry = aEntry;
}
nsSHEnumerator::~nsSHEnumerator()
{
}
NS_IMETHODIMP
nsSHEnumerator::Next()
{
mIndex++;
PRUint32 cnt=0;
cnt = mSHEntry->mChildren.Count();
if (mIndex < (PRInt32)cnt)
return NS_OK;
return NS_ERROR_FAILURE;
}
#if 0
NS_IMETHODIMP
nsSHEnumerator::Prev()
{
mIndex--;
if (mIndex >= 0 )
return NS_OK;
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsSHEnumerator::Last()
{
PRUint32 cnt;
nsresult rv = mSHEntry->mChildren.Count(&cnt);
if (NS_FAILED(rv)) return rv;
mIndex = (PRInt32)cnt-1;
return NS_OK;
}
#endif /* 0 */
NS_IMETHODIMP
nsSHEnumerator::First()
{
mIndex = 0;
return NS_OK;
}
NS_IMETHODIMP
nsSHEnumerator::CurrentItem(nsISupports **aItem)
{
if (!aItem)
return NS_ERROR_NULL_POINTER;
PRUint32 cnt= mSHEntry->mChildren.Count();
if (mIndex >=0 && mIndex < (PRInt32)cnt){
*aItem = (nsISupports *)mSHEntry->mChildren.ElementAt(mIndex);
NS_IF_ADDREF(*aItem);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
NS_IMPL_ISUPPORTS1(nsSHEnumerator, nsIEnumerator)
NS_IMETHODIMP
nsSHEnumerator::CurrentItem(nsISHEntry **aItem)
{
if (!aItem)
return NS_ERROR_NULL_POINTER;
PRUint32 cnt = mSHEntry->mChildren.Count();
if (mIndex >=0 && mIndex < (PRInt32)cnt){
nsCOMPtr<nsISupports> indexIsupports = (nsISHEntry *) mSHEntry->mChildren.ElementAt(mIndex);
return indexIsupports->QueryInterface(nsISHEntry::GetIID(),(void **)aItem);
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsSHEnumerator::IsDone()
{
PRUint32 cnt;
cnt = mSHEntry->mChildren.Count();
if (mIndex >= 0 && mIndex < (PRInt32)cnt ) {
return NS_ENUMERATOR_FALSE;
}
return NS_OK;
}
#if 0
NS_IMETHODIMP
nsRangeListIterator::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (nsnull == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(nsIEnumerator::GetIID())) {
*aInstancePtr = NS_STATIC_CAST(nsIEnumerator*, this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsIBidirectionalEnumerator::GetIID())) {
*aInstancePtr = NS_STATIC_CAST(nsIBidirectionalEnumerator*, this);
NS_ADDREF_THIS();
return NS_OK;
}
return mDomSelection->QueryInterface(aIID, aInstancePtr);
}
#endif
////////////END nsSHEnumerator methods

View File

@ -0,0 +1,59 @@
/* -*- 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):
* Radha Kulkarni <radha@netscape.com>
*/
#ifndef nsSHEntry_h
#define nsSHEntry_h
#include "nsCOMPtr.h"
#include "nsISHEntry.h"
#include "nsISHContainer.h"
#include "nsVoidArray.h"
#include "nsString.h"
class nsSHEnumerator;
class nsSHEntry : public nsISHEntry,
public nsISHContainer
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSISHENTRY
NS_DECL_NSISHCONTAINER
protected:
nsSHEntry();
virtual ~nsSHEntry();
void DestroyChildren();
private:
friend class nsSHEnumerator;
nsIURI * mURI;
nsIDOMDocument * mDocument;
nsString * mTitle;
nsIInputStream * mPostData;
nsISupports * mLayoutHistoryState;
nsVoidArray mChildren;
nsISHEntry * mParent; // weak reference to parent
};
#endif /* nsSHEntry_h */

View File

@ -0,0 +1,151 @@
/* -*- 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):
* Radha Kulkarni <radha@netscape.com>
*/
#include "nsISupportsUtils.h"
#include "nsCOMPtr.h"
#include "nsIDOMDocument.h"
#include "nsSHTransaction.h"
#ifdef XXX_NS_DEBUG // XXX: we'll need a logging facility for debugging
#define WEB_TRACE(_bit,_args) \
PR_BEGIN_MACRO \
if (WEB_LOG_TEST(gLogModule,_bit)) { \
PR_LogPrint _args; \
} \
PR_END_MACRO
#else
#define WEB_TRACE(_bit,_args)
#endif
NS_IMPL_ISUPPORTS1(nsSHTransaction, nsISHTransaction)
nsSHTransaction::nsSHTransaction() : mSHEntry(nsnull), mParent(nsnull),
mChild(nsnull), mLRVList(nsnull)
{
NS_INIT_REFCNT();
}
nsSHTransaction::~nsSHTransaction()
{
NS_IF_RELEASE(mSHEntry);
mParent = nsnull; //Weak reference to parent transaction
NS_IF_RELEASE(mChild);
NS_IF_RELEASE(mLRVList);
}
NS_IMETHODIMP
nsSHTransaction::Create(nsISHEntry * aSHEntry, nsISHTransaction * aParent)
{
SetCurrentSHistoryEntry(aSHEntry);
if (aParent) {
// This will correctly set the parent child pointers
((nsSHTransaction *)aParent)->SetChild(this);
}
else
SetParent(aParent);
return NS_OK;
}
NS_IMETHODIMP
nsSHTransaction::GetCurrentSHistoryEntry(nsISHEntry ** aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = mSHEntry;
NS_IF_ADDREF(mSHEntry);
return NS_OK;
}
nsresult
nsSHTransaction::SetCurrentSHistoryEntry(nsISHEntry * aSHEntry)
{
NS_IF_RELEASE(mSHEntry);
mSHEntry = aSHEntry;
NS_IF_ADDREF(mSHEntry);
return NS_OK;
}
NS_IMETHODIMP
nsSHTransaction::GetChild(nsISHTransaction * * aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = mChild;
NS_IF_ADDREF(mChild);
return NS_OK;
}
nsresult
nsSHTransaction::SetChild(nsISHTransaction * aChild)
{
if (mChild) {
// There is already a child. Move the child to the LRV list
if (mLRVList) {
//Delete any old LRV item that was there.
}
// Make the child the LRV item
}
NS_ENSURE_SUCCESS(((nsSHTransaction *)aChild)->SetParent(this), NS_ERROR_FAILURE);
mChild = aChild;
NS_IF_ADDREF(aChild);
return NS_OK;
}
nsresult
nsSHTransaction::SetParent(nsISHTransaction * aParent)
{
/* This is weak reference to parent. Do not Addref it */
mParent = aParent;
return NS_OK;
}
nsresult
nsSHTransaction::GetParent(nsISHTransaction ** aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = mParent;
NS_IF_ADDREF(*aResult);
return NS_OK;
}
NS_IMETHODIMP
nsSHTransaction::GetLrvList(nsISHTransaction ** aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = mLRVList;
NS_IF_ADDREF(mLRVList);
return NS_OK;
}

View File

@ -0,0 +1,55 @@
/* -*- 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):
* Radha Kulkarni <radha@netscape.com>
*/
#ifndef nsSHTransaction_h
#define nsSHTransaction_h
#include "nsISHTransaction.h"
#include "nsISHEntry.h"
class nsSHTransaction: public nsISHTransaction
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSISHTRANSACTION
nsSHTransaction();
protected:
virtual ~nsSHTransaction();
private:
nsresult SetChild(nsISHTransaction * aChild);
nsresult SetParent(nsISHTransaction * aParent);
nsresult SetCurrentSHistoryEntry(nsISHEntry * aSHEntry);
nsISHEntry * mSHEntry;
/* Weak reference to parent */
nsISHTransaction * mParent;
nsISHTransaction * mChild;
nsISHTransaction * mLRVList;
};
#endif /* nsSHTransaction_h */