From 504afff9b32bbc9566e8d293bcd2bb75e09f5f9a Mon Sep 17 00:00:00 2001 From: "warren%netscape.com" Date: Mon, 22 Mar 1999 23:51:38 +0000 Subject: [PATCH] Added new browsing profile stuff. git-svn-id: svn://10.0.0.236/trunk@24740 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/rdf/brprof/Makefile.in | 29 ++ mozilla/rdf/brprof/build/Makefile.in | 86 +++++ mozilla/rdf/brprof/build/makefile.win | 55 +++ .../brprof/build/nsBrowsingProfileFactory.cpp | 100 +++++ mozilla/rdf/brprof/makefile.win | 24 ++ mozilla/rdf/brprof/public/makefile.win | 28 ++ .../rdf/brprof/public/nsIBrowsingProfile.h | 96 +++++ mozilla/rdf/brprof/src/makefile.win | 42 +++ mozilla/rdf/brprof/src/nsBrowsingProfile.cpp | 345 ++++++++++++++++++ 9 files changed, 805 insertions(+) create mode 100644 mozilla/rdf/brprof/Makefile.in create mode 100644 mozilla/rdf/brprof/build/Makefile.in create mode 100644 mozilla/rdf/brprof/build/makefile.win create mode 100644 mozilla/rdf/brprof/build/nsBrowsingProfileFactory.cpp create mode 100644 mozilla/rdf/brprof/makefile.win create mode 100644 mozilla/rdf/brprof/public/makefile.win create mode 100644 mozilla/rdf/brprof/public/nsIBrowsingProfile.h create mode 100644 mozilla/rdf/brprof/src/makefile.win create mode 100644 mozilla/rdf/brprof/src/nsBrowsingProfile.cpp diff --git a/mozilla/rdf/brprof/Makefile.in b/mozilla/rdf/brprof/Makefile.in new file mode 100644 index 00000000000..002b9fb5180 --- /dev/null +++ b/mozilla/rdf/brprof/Makefile.in @@ -0,0 +1,29 @@ +#!gmake +# +# The contents of this file are subject to the Netscape Public License +# Version 1.0 (the "NPL"); you may not use this file except in +# compliance with the NPL. You may obtain a copy of the NPL at +# http://www.mozilla.org/NPL/ +# +# Software distributed under the NPL is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL +# for the specific language governing rights and limitations under the +# NPL. +# +# The Initial Developer of this code under the NPL is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All Rights +# Reserved. + +DEPTH = ../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +DIRS = public src build + +include $(topsrcdir)/config/config.mk + +include $(topsrcdir)/config/rules.mk diff --git a/mozilla/rdf/brprof/build/Makefile.in b/mozilla/rdf/brprof/build/Makefile.in new file mode 100644 index 00000000000..3c2e1e8a738 --- /dev/null +++ b/mozilla/rdf/brprof/build/Makefile.in @@ -0,0 +1,86 @@ +#!gmake +# +# The contents of this file are subject to the Netscape Public License +# Version 1.0 (the "NPL"); you may not use this file except in +# compliance with the NPL. You may obtain a copy of the NPL at +# http://www.mozilla.org/NPL/ +# +# Software distributed under the NPL is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL +# for the specific language governing rights and limitations under the +# NPL. +# +# The Initial Developer of this code under the NPL is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All Rights +# Reserved. + +DEPTH=../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +include $(topsrcdir)/config/config.mk + +LIBRARY_NAME = rdf +IS_COMPONENT = 1 + +CPPSRCS = \ + dlldeps.cpp \ + nsRDFFactory.cpp \ + $(NULL) + +EXPORTS = \ + nsRDFCID.h \ + $(NULL) + +EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS)) + +MODULE = rdf + +REQUIRES = dom js netlib rdf raptor xpcom + +# XXX Note dependencies on implementation headers for factory functions + +INCLUDES += -I$(srcdir)/../base/src \ + -I$(srcdir)/../content/src \ + -I$(srcdir)/../datasource/src \ + $(NULL) + +SHARED_LIBRARY_LIBS = \ + $(DIST)/lib/librdfbase_s.a \ + $(DIST)/lib/librdfcontent_s.a \ + $(DIST)/lib/librdfdatasource_s.a \ + $(DIST)/lib/librdfutil_s.a \ + $(NULL) + +EXTRA_DSO_LDOPTS = \ + $(MKSHLIB_FORCE_ALL) \ + $(SHARED_LIBRARY_LIBS) \ + $(MKSHLIB_UNFORCE_ALL) \ + -L$(DIST)/bin \ + $(NULL) + +include $(topsrcdir)/config/rules.mk + +$(SHARED_LIBRARY): $(SHARED_LIBRARY_LIBS) Makefile + +install:: $(TARGETS) + $(INSTALL) $(srcdir)/../resources/sidebar.xul $(DIST)/bin/res/rdf + $(INSTALL) $(srcdir)/../resources/sidebar.css $(DIST)/bin/res/rdf + $(INSTALL) $(srcdir)/../resources/bookmarks.xul $(DIST)/bin/res/rdf + $(INSTALL) $(srcdir)/../resources/bookmarks.css $(DIST)/bin/res/rdf + $(INSTALL) $(srcdir)/../resources/bookmarks.html $(DIST)/bin/res/rdf + $(INSTALL) $(srcdir)/../resources/bookmark-item.gif $(DIST)/bin/res/rdf + $(INSTALL) $(srcdir)/../resources/bookmark-folder-closed.gif $(DIST)/bin/res/rdf + $(INSTALL) $(srcdir)/../resources/bookmark-folder-open.gif $(DIST)/bin/res/rdf + $(INSTALL) $(srcdir)/../resources/personal-folder-closed.gif $(DIST)/bin/res/rdf + $(INSTALL) $(srcdir)/../resources/personal-folder-open.gif $(DIST)/bin/res/rdf + $(INSTALL) $(srcdir)/../resources/folder-open.gif $(DIST)/bin/res/rdf + $(INSTALL) $(srcdir)/../resources/folder-closed.gif $(DIST)/bin/res/rdf + $(INSTALL) $(srcdir)/../resources/History/h1.hst $(DIST)/bin/res/rdf/History + $(INSTALL) $(srcdir)/../resources/dom-test-1.xul $(DIST)/bin/res/rdf + $(INSTALL) $(srcdir)/../resources/dom-test-1.css $(DIST)/bin/res/rdf + diff --git a/mozilla/rdf/brprof/build/makefile.win b/mozilla/rdf/brprof/build/makefile.win new file mode 100644 index 00000000000..fa054a3cc84 --- /dev/null +++ b/mozilla/rdf/brprof/build/makefile.win @@ -0,0 +1,55 @@ +#!gmake +# +# The contents of this file are subject to the Netscape Public License +# Version 1.0 (the "NPL"); you may not use this file except in +# compliance with the NPL. You may obtain a copy of the NPL at +# http://www.mozilla.org/NPL/ +# +# Software distributed under the NPL is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL +# for the specific language governing rights and limitations under the +# NPL. +# +# The Initial Developer of this code under the NPL is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All Rights +# Reserved. + +DEPTH=..\..\.. +MODULE=brprof + +MAKE_OBJ_TYPE=DLL +DLLNAME=brprof +DLL=.\$(OBJDIR)\$(DLLNAME).dll + +CPP_OBJS=\ + .\$(OBJDIR)\nsBrowsingProfileFactory.obj \ + $(NULL) + +# XXX linking in raptor is a heinous crime that will go away once we +# have a more DOM-based mechanism for constructing elements and +# hooking in to their changes. + +LLIBS=\ + $(DIST)\lib\xpcom32.lib \ + $(DIST)\lib\raptorbase.lib \ + $(DIST)\lib\rdf.lib \ + $(DIST)\lib\brprof_s.lib \ + $(LIBNSPR) + +MISCDEP=$(LLIBS) + +# XXX Note dependencies on implementation dirs for factory methods. + +LINCS= -I$(PUBLIC)\rdf \ + -I$(PUBLIC)\xpcom \ + -I$(PUBLIC)\raptor \ + -I$(PUBLIC)\brprof \ + $(NULL) + +include <$(DEPTH)\config\rules.mak> + +install:: $(DLL) + $(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\components + $(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib + diff --git a/mozilla/rdf/brprof/build/nsBrowsingProfileFactory.cpp b/mozilla/rdf/brprof/build/nsBrowsingProfileFactory.cpp new file mode 100644 index 00000000000..d2ab9473cb1 --- /dev/null +++ b/mozilla/rdf/brprof/build/nsBrowsingProfileFactory.cpp @@ -0,0 +1,100 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "nsIServiceManager.h" +#include "nsIComponentManager.h" +#include "nsIGenericFactory.h" +#include "nsIBrowsingProfile.h" +#include "nscore.h" + +static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID); +static NS_DEFINE_CID(kGenericFactoryCID, NS_GENERICFACTORY_CID); +static NS_DEFINE_CID(kBrowsingProfileCID, NS_BROWSINGPROFILE_CID); + +static NS_IMETHODIMP +nsConstructBrowsingProfile(nsISupports *aOuter, REFNSIID aIID, void **aResult) +{ + nsresult rv; + NS_ASSERTION(aOuter == nsnull, "no aggregation"); + nsIBrowsingProfile* brprof; + rv = NS_NewBrowsingProfile(nsnull, &brprof); + if (NS_FAILED(rv)) return rv; + rv = brprof->QueryInterface(aIID, aResult); + NS_RELEASE(brprof); + return rv; +} + +extern "C" PR_IMPLEMENT(nsresult) +NSGetFactory(nsISupports* aServMgr, + const nsCID &aClass, + const char *aClassName, + const char *aProgID, + nsIFactory **aFactory) +{ + nsresult rv; + NS_ASSERTION(aFactory != nsnull, "bad factory pointer"); + NS_ASSERTION(aClass.Equals(kBrowsingProfileCID), "incorrectly registered"); + + NS_WITH_SERVICE1(nsIComponentManager, compMgr, + aServMgr, kComponentManagerCID, &rv); + if (NS_FAILED(rv)) return rv; + + nsIGenericFactory* factory; + rv = compMgr->CreateInstance(kGenericFactoryCID, nsnull, nsIGenericFactory::GetIID(), + (void**)&factory); + if (NS_FAILED(rv)) return rv; + + rv = factory->SetConstructor(nsConstructBrowsingProfile); + if (NS_FAILED(rv)) { + delete factory; + return rv; + } + NS_ADDREF(factory); + *aFactory = factory; + return NS_OK; +} + +extern "C" PR_IMPLEMENT(nsresult) +NSRegisterSelf(nsISupports* aServMgr , const char* aPath) +{ + nsresult rv; + + NS_WITH_SERVICE1(nsIComponentManager, compMgr, + aServMgr, kComponentManagerCID, &rv); + if (NS_FAILED(rv)) return rv; + + rv = compMgr->RegisterComponent(kBrowsingProfileCID, + "Browsing Profile", nsnull, aPath, + PR_TRUE, PR_TRUE); + + return rv; +} + +extern "C" PR_IMPLEMENT(nsresult) +NSUnregisterSelf(nsISupports* aServMgr, const char* aPath) +{ + nsresult rv; + NS_WITH_SERVICE1(nsIComponentManager, compMgr, + aServMgr, kComponentManagerCID, &rv); + if (NS_FAILED(rv)) return rv; + + rv = compMgr->UnregisterComponent(kBrowsingProfileCID, aPath); + + return rv; +} + diff --git a/mozilla/rdf/brprof/makefile.win b/mozilla/rdf/brprof/makefile.win new file mode 100644 index 00000000000..8080b6eac9b --- /dev/null +++ b/mozilla/rdf/brprof/makefile.win @@ -0,0 +1,24 @@ +#!gmake +# +# The contents of this file are subject to the Netscape Public License +# Version 1.0 (the "NPL"); you may not use this file except in +# compliance with the NPL. You may obtain a copy of the NPL at +# http://www.mozilla.org/NPL/ +# +# Software distributed under the NPL is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL +# for the specific language governing rights and limitations under the +# NPL. +# +# The Initial Developer of this code under the NPL is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All Rights +# Reserved. + +DEPTH=..\.. + +MODULE = rdf + +DIRS= public src build + +include <$(DEPTH)\config\rules.mak> diff --git a/mozilla/rdf/brprof/public/makefile.win b/mozilla/rdf/brprof/public/makefile.win new file mode 100644 index 00000000000..a49315d7e42 --- /dev/null +++ b/mozilla/rdf/brprof/public/makefile.win @@ -0,0 +1,28 @@ +#!gmake +# +# The contents of this file are subject to the Netscape Public License +# Version 1.0 (the "NPL"); you may not use this file except in +# compliance with the NPL. You may obtain a copy of the NPL at +# http://www.mozilla.org/NPL/ +# +# Software distributed under the NPL is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL +# for the specific language governing rights and limitations under the +# NPL. +# +# The Initial Developer of this code under the NPL is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All Rights +# Reserved. + +DEPTH=..\..\.. +MODULE=brprof + +EXPORTS = \ + nsIBrowsingProfile.h \ + $(NULL) + +include <$(DEPTH)\config\rules.mak> + + + diff --git a/mozilla/rdf/brprof/public/nsIBrowsingProfile.h b/mozilla/rdf/brprof/public/nsIBrowsingProfile.h new file mode 100644 index 00000000000..b0e3c96e17b --- /dev/null +++ b/mozilla/rdf/brprof/public/nsIBrowsingProfile.h @@ -0,0 +1,96 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef nsIBrowsingProfile_h__ +#define nsIBrowsingProfile_h__ + +#include "nsISupports.h" + +#define nsBrowsingProfile_Check 0xbaadf00d +#define nsBrowsingProfile_CurrentMajorVersion 1 +#define nsBrowsingProfile_CurrentMinorVersion 0 + +struct nsBrowsingProfileVector { + union { + PRUint8 mPadding[32]; + struct { + PRUint32 mCheck; // should always == nsBrowsingProfile_Check + PRUint16 mMajorVersion; // denotes a non-backward compatible change (e.g. structural change to this vector) + PRUint16 mMinorVersion; // denotes a backward compatible change to the meaning of this vector + } mInfo; + } mHeader; + struct { + PRUint16 mID; + PRUint8 mVisitCount; + PRUint8 mFlags; + } mCategory[56]; +}; + +enum nsBrowsingProfileFlag { + nsBrowsingProfileFlag_ThisSession = (1 << 0), + nsBrowsingProfileFlag_Recent = (1 << 1) +}; + +//////////////////////////////////////////////////////////////////////////////// + +// size of hex encoding: +const PRUint32 kBrowsingProfileCookieSize = sizeof(nsBrowsingProfileVector) * 2; + +#define NS_IBROWSINGPROFILE_IID \ +{ /* 4aef9ba2-e0af-11d2-8cca-0060b0fc14a3 */ \ + 0x4aef9ba2, \ + 0xe0af, \ + 0x11d2, \ + {0x8c, 0xca, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \ +} + +class nsIBrowsingProfile : public nsISupports { +public: + static const nsIID& GetIID() { static nsIID iid = NS_IBROWSINGPROFILE_IID; return iid; } + + NS_IMETHOD Init(const char* userProfileName) = 0; + + NS_IMETHOD GetVector(nsBrowsingProfileVector& result) = 0; + + NS_IMETHOD SetVector(nsBrowsingProfileVector& value) = 0; + + NS_IMETHOD GetCookieString(char buf[kBrowsingProfileCookieSize]) = 0; + + NS_IMETHOD SetCookieString(char buf[kBrowsingProfileCookieSize]) = 0; + + NS_IMETHOD GetDescription(char* *htmlResult) = 0; + + NS_IMETHOD CountPageVisit(const char* url) = 0; +}; + +// for component registration +#define NS_BROWSINGPROFILE_CID \ +{ /* 7ef80dd0-e0af-11d2-8cca-0060b0fc14a3 */ \ + 0x7ef80dd0, \ + 0xe0af, \ + 0x11d2, \ + {0x8c, 0xca, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +extern nsresult +NS_NewBrowsingProfile(const char* userProfileName, + nsIBrowsingProfile* *result); + +#endif // nsIBrowsingProfile_h__ diff --git a/mozilla/rdf/brprof/src/makefile.win b/mozilla/rdf/brprof/src/makefile.win new file mode 100644 index 00000000000..35a08ece3be --- /dev/null +++ b/mozilla/rdf/brprof/src/makefile.win @@ -0,0 +1,42 @@ +#!gmake +# +# The contents of this file are subject to the Netscape Public License +# Version 1.0 (the "NPL"); you may not use this file except in +# compliance with the NPL. You may obtain a copy of the NPL at +# http://www.mozilla.org/NPL/ +# +# Software distributed under the NPL is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL +# for the specific language governing rights and limitations under the +# NPL. +# +# The Initial Developer of this code under the NPL is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All Rights +# Reserved. + +DEPTH=..\..\.. +MODULE=brprof +LIBRARY_NAME=brprof_s + +CPP_OBJS=\ + .\$(OBJDIR)\nsBrowsingProfile.obj \ + $(NULL) + +LINCS= -I$(PUBLIC)\rdf \ + -I$(PUBLIC)\xpcom \ + -I$(PUBLIC)\brprof \ + -I$(PUBLIC)\raptor \ + $(NULL) + +include <$(DEPTH)\config\rules.mak> + +libs:: $(LIBRARY) + $(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib + +clobber:: + rm -f $(DIST)\lib\$(LIBRARY_NAME).lib + + + + diff --git a/mozilla/rdf/brprof/src/nsBrowsingProfile.cpp b/mozilla/rdf/brprof/src/nsBrowsingProfile.cpp new file mode 100644 index 00000000000..31fb1a98649 --- /dev/null +++ b/mozilla/rdf/brprof/src/nsBrowsingProfile.cpp @@ -0,0 +1,345 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "nsIBrowsingProfile.h" +#include "nsIRDFObserver.h" +#include "nsCRT.h" +#include "rdf.h" +#include "nsIServiceManager.h" +#include "nsIRDFService.h" +#include "nsRDFCID.h" +#include "nsIRDFResource.h" +#include "nsIRDFDataSource.h" +#include "nsIRDFCursor.h" + +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); +static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); + +DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Page); +DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, child); +DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, CategoryID); + +#if 0 +static PRBool +peq(nsIRDFResource* r1, nsIRDFResource* r2) +{ + PRBool eq; + return NS_SUCCEEDED(r1->EqualsResource(r2, &eq)) && eq; +} +#else +#define peq(r1, r2) ((r1) == (r2)) +#endif + +//////////////////////////////////////////////////////////////////////////////// + +class nsBrowsingProfile : public nsIBrowsingProfile, public nsIRDFObserver { +public: + NS_DECL_ISUPPORTS + + // nsIBrowsingProfile methods: + NS_IMETHOD Init(const char* userProfileName); + NS_IMETHOD GetVector(nsBrowsingProfileVector& result); + NS_IMETHOD SetVector(nsBrowsingProfileVector& value); + NS_IMETHOD GetCookieString(char buf[kBrowsingProfileCookieSize]); + NS_IMETHOD SetCookieString(char buf[kBrowsingProfileCookieSize]); + NS_IMETHOD GetDescription(char* *htmlResult); + NS_IMETHOD CountPageVisit(const char* url); + + // nsIRDFObserver methods: + NS_IMETHOD OnAssert(nsIRDFResource* subject, + nsIRDFResource* predicate, + nsIRDFNode* object); + NS_IMETHOD OnUnassert(nsIRDFResource* subject, + nsIRDFResource* predicate, + nsIRDFNode* object); + + // nsBrowsingProfile methods: + nsBrowsingProfile(); + virtual ~nsBrowsingProfile(); + + nsresult RecordHit(const char* categoryURL, PRInt32 id); + + static PRUint32 gRefCnt; + static nsIRDFService* gRDFService; + static nsIRDFDataSource* gCategoryDB; + static nsIRDFResource* gPageProperty; + static nsIRDFResource* gChildProperty; + static nsIRDFResource* gCategoryIDProperty; + +protected: + const char* mUserProfileName; + nsBrowsingProfileVector mVector; +}; + +PRUint32 nsBrowsingProfile::gRefCnt = 0; +nsIRDFService* nsBrowsingProfile::gRDFService = nsnull; +nsIRDFDataSource* nsBrowsingProfile::gCategoryDB = nsnull; +nsIRDFResource* nsBrowsingProfile::gPageProperty = nsnull; +nsIRDFResource* nsBrowsingProfile::gChildProperty = nsnull; +nsIRDFResource* nsBrowsingProfile::gCategoryIDProperty = nsnull; + +//////////////////////////////////////////////////////////////////////////////// + +nsBrowsingProfile::nsBrowsingProfile() +{ + nsCRT::zero(&mVector, sizeof(nsBrowsingProfileVector)); + gRefCnt++; +} + +NS_IMETHODIMP +nsBrowsingProfile::Init(const char* userProfileName) +{ + nsresult rv = NS_OK; + + mUserProfileName = userProfileName; + + if (gRefCnt == 1) { + NS_ASSERTION(gPageProperty == nsnull, "out of sync"); + + rv = nsServiceManager::GetService(kRDFServiceCID, + nsIRDFService::GetIID(), + (nsISupports**)&gRDFService); + if (NS_FAILED(rv)) return rv; + + rv = gRDFService->GetDataSource("rdf:categoryDB", &gCategoryDB); + if (NS_FAILED(rv)) return rv; + + // get all the properties we'll need: + rv = gRDFService->GetResource(kURINC_Page, &gPageProperty); + if (NS_FAILED(rv)) return rv; + rv = gRDFService->GetResource(kURINC_Page, &gChildProperty); + if (NS_FAILED(rv)) return rv; + rv = gRDFService->GetResource(kURINC_Page, &gCategoryIDProperty); + if (NS_FAILED(rv)) return rv; + } + return rv; +} + +nsBrowsingProfile::~nsBrowsingProfile() +{ + --gRefCnt; + if (gRefCnt == 0) { + nsresult rv; + + // release all the properties: + if (gCategoryIDProperty) { + rv = gRDFService->UnregisterResource(gCategoryIDProperty); + NS_ASSERTION(NS_SUCCEEDED(rv), "UnregisterResource failed"); + gCategoryIDProperty = nsnull; + } + if (gChildProperty) { + rv = gRDFService->UnregisterResource(gChildProperty); + NS_ASSERTION(NS_SUCCEEDED(rv), "UnregisterResource failed"); + gChildProperty = nsnull; + } + if (gPageProperty) { + rv = gRDFService->UnregisterResource(gPageProperty); + NS_ASSERTION(NS_SUCCEEDED(rv), "UnregisterResource failed"); + gPageProperty = nsnull; + } + + if (gCategoryDB) { + NS_RELEASE(gCategoryDB); + gCategoryDB = nsnull; + } + + if (gRDFService) { + nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService); + gRDFService = nsnull; + } + } +} + +NS_IMPL_ADDREF(nsBrowsingProfile) +NS_IMPL_RELEASE(nsBrowsingProfile) + +NS_IMETHODIMP +nsBrowsingProfile::QueryInterface(REFNSIID aIID, void** aResult) +{ + NS_PRECONDITION(aResult != nsnull, "null ptr"); + if (! aResult) + return NS_ERROR_NULL_POINTER; + + if (aIID.Equals(nsIBrowsingProfile::GetIID()) || + aIID.Equals(kISupportsIID)) { + *aResult = NS_STATIC_CAST(nsIBrowsingProfile*, this); + NS_ADDREF(this); + return NS_OK; + } + if (aIID.Equals(nsIRDFObserver::GetIID())) { + *aResult = NS_STATIC_CAST(nsIRDFObserver*, this); + NS_ADDREF(this); + return NS_OK; + } + return NS_NOINTERFACE; +} + +//////////////////////////////////////////////////////////////////////////////// +// nsIBrowsingProfile methods: + +NS_IMETHODIMP +nsBrowsingProfile::GetVector(nsBrowsingProfileVector& result) +{ + result = mVector; // copy + return NS_OK; +} + +NS_IMETHODIMP +nsBrowsingProfile::SetVector(nsBrowsingProfileVector& value) +{ + mVector = value; // copy + return NS_OK; +} + +NS_IMETHODIMP +nsBrowsingProfile::GetCookieString(char buf[kBrowsingProfileCookieSize]) +{ + // XXX translate mVector to hex + return NS_OK; +} + +NS_IMETHODIMP +nsBrowsingProfile::SetCookieString(char buf[kBrowsingProfileCookieSize]) +{ + // XXX translate hex to mVector + return NS_OK; +} + +NS_IMETHODIMP +nsBrowsingProfile::GetDescription(char* *htmlResult) +{ + // XXX generate some nice html + return NS_OK; +} + +NS_IMETHODIMP +nsBrowsingProfile::CountPageVisit(const char* url) +{ + // Here's where the real work is: + // Find the url in the directory, and get the category ID. + // Then increment the count (and set the flags) for that category ID + // in the vector. + + nsresult rv = NS_OK; + PRBool found = PR_FALSE; + do { + nsIRDFResource* urlRes; + rv = gRDFService->GetResource(url, &urlRes); + if (NS_FAILED(rv)) return rv; + + nsIRDFAssertionCursor* cursor; + rv = gCategoryDB->GetSources(gChildProperty, urlRes, PR_TRUE, &cursor); + if (NS_SUCCEEDED(rv)) { + while (cursor->Advance()) { + nsIRDFResource* category; + rv = cursor->GetSubject(&category); + if (NS_SUCCEEDED(rv)) { + // found this page in a category -- count it + nsIRDFNode* catID; + rv = gCategoryDB->GetTarget(category, gCategoryIDProperty, PR_TRUE, &catID); + if (NS_SUCCEEDED(rv)) { + const char* catURI; + rv = category->GetValue(&catURI); + if (NS_SUCCEEDED(rv)) { + nsIRDFInt* catIDInt; + rv = catID->QueryInterface(nsIRDFInt::GetIID(), (void**)&catIDInt); + if (NS_SUCCEEDED(rv)) { + int32 id; + rv = catIDInt->GetValue(&id); + if (NS_SUCCEEDED(rv)) { + rv = RecordHit(catURI, id); + found = PR_TRUE; + } + NS_RELEASE(catIDInt); + } + } + } + NS_RELEASE(category); + } + } + NS_RELEASE(cursor); + } + NS_RELEASE(urlRes); + + // we didn't find this page exactly, but see if some ancestor is there + if (!found) { + + } + } while (found); + + return rv; +} + +nsresult +nsBrowsingProfile::RecordHit(const char* categoryURL, PRInt32 id) +{ + return NS_OK; +} + +//////////////////////////////////////////////////////////////////////////////// +// nsIRDFObserver methods: + +NS_IMETHODIMP +nsBrowsingProfile::OnAssert(nsIRDFResource* subject, + nsIRDFResource* predicate, + nsIRDFNode* object) +{ + nsresult rv = NS_OK; + if (peq(predicate, gPageProperty)) { + nsIRDFResource* objRes; + rv = object->QueryInterface(nsIRDFResource::GetIID(), (void**)&objRes); + if (NS_FAILED(rv)) return rv; + const char* url; + rv = objRes->GetValue(&url); + if (NS_SUCCEEDED(rv)) { + rv = CountPageVisit(url); + } + NS_RELEASE(objRes); + } + return rv; +} + +NS_IMETHODIMP +nsBrowsingProfile::OnUnassert(nsIRDFResource* subject, + nsIRDFResource* predicate, + nsIRDFNode* object) +{ + // we don't care about history entries going away + return NS_OK; +} + +//////////////////////////////////////////////////////////////////////////////// + +nsresult +NS_NewBrowsingProfile(const char* userProfileName, + nsIBrowsingProfile* *result) +{ + nsresult rv; + nsBrowsingProfile* profile = new nsBrowsingProfile(); + if (profile == nsnull) + return NS_ERROR_OUT_OF_MEMORY; + rv = profile->Init(userProfileName); + if (NS_FAILED(rv)) { + delete profile; + } + NS_ADDREF(profile); + *result = profile; + return rv; +} + +////////////////////////////////////////////////////////////////////////////////