Added new browsing profile stuff.

git-svn-id: svn://10.0.0.236/trunk@24740 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
warren%netscape.com
1999-03-22 23:51:38 +00:00
parent 4a40515c9e
commit 504afff9b3
9 changed files with 805 additions and 0 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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>

View File

@@ -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>

View File

@@ -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__

View File

@@ -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

View File

@@ -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;
}
////////////////////////////////////////////////////////////////////////////////