зеркало из https://github.com/mozilla/gecko-dev.git
Global history introduced as a service and appropriate changes to
Appshell service and Factory
This commit is contained in:
Родитель
6b99d39f50
Коммит
d399658918
|
@ -37,6 +37,7 @@ CPPSRCS= \
|
|||
nsJSXPConnectFactory.cpp \
|
||||
nsAppShellNameSet.cpp \
|
||||
nsFileLocations.cpp \
|
||||
nsGlobalHistory.cpp \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
|
|
@ -31,6 +31,7 @@ CPPSRCS= \
|
|||
nsJSXPConnectFactory.cpp \
|
||||
nsAppShellNameSet.cpp \
|
||||
nsFileLocations.cpp \
|
||||
nsGlobalHistory.cpp \
|
||||
$(NULL)
|
||||
|
||||
CPP_OBJS= \
|
||||
|
@ -43,6 +44,8 @@ CPP_OBJS= \
|
|||
.\$(OBJDIR)\nsJSXPConnectFactory.obj \
|
||||
.\$(OBJDIR)\nsAppShellNameSet.obj \
|
||||
.\$(OBJDIR)\nsFileLocations.obj \
|
||||
.\$(OBJDIR)\nsGlobalHistory.obj \
|
||||
|
||||
$(NULL)
|
||||
|
||||
LINCS=-I$(PUBLIC)\raptor \
|
||||
|
@ -52,7 +55,8 @@ LINCS=-I$(PUBLIC)\raptor \
|
|||
-I$(PUBLIC)\js \
|
||||
-I$(PUBLIC)\pref \
|
||||
-I$(PUBLIC)\appcores \
|
||||
-I$(PUBLIC)\netlib
|
||||
-I$(PUBLIC)\netlib \
|
||||
-I$(PUBLIC)\rdf
|
||||
|
||||
MAKE_OBJ_TYPE = DLL
|
||||
DLLNAME = nsappshell
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "nsIComponentManager.h"
|
||||
#include "nsAppShellCIDs.h"
|
||||
#include "nsICmdLineService.h"
|
||||
#include "nsIGlobalHistory.h"
|
||||
|
||||
/* extern the factory entry points for each component... */
|
||||
nsresult NS_NewAppShellServiceFactory(nsIFactory** aFactory);
|
||||
|
@ -35,6 +36,7 @@ static NS_DEFINE_IID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID);
|
|||
static NS_DEFINE_IID(kCmdLineServiceCID, NS_COMMANDLINE_SERVICE_CID);
|
||||
static NS_DEFINE_IID(kProtocolHelperCID, NS_PROTOCOL_HELPER_CID);
|
||||
static NS_DEFINE_IID(kXPConnectFactoryCID, NS_XPCONNECTFACTORY_CID);
|
||||
static NS_DEFINE_IID(kGlobalHistoryCID, NS_GLOBALHISTORY_CID);
|
||||
|
||||
/*
|
||||
* Global entry point to register all components in the registry...
|
||||
|
@ -46,6 +48,7 @@ NSRegisterSelf(nsISupports* serviceMgr, const char *path)
|
|||
nsComponentManager::RegisterComponent(kCmdLineServiceCID, NULL, NULL, path, PR_TRUE, PR_TRUE);
|
||||
nsComponentManager::RegisterComponent(kProtocolHelperCID, NULL, NULL, path, PR_TRUE, PR_TRUE);
|
||||
nsComponentManager::RegisterComponent(kXPConnectFactoryCID, NULL, NULL, path, PR_TRUE, PR_TRUE);
|
||||
nsComponentManager::RegisterComponent(kGlobalHistoryCID, NULL, NULL, path, PR_TRUE, PR_TRUE);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -59,6 +62,7 @@ NSUnregisterSelf(nsISupports* serviceMgr, const char *path)
|
|||
nsComponentManager::UnregisterFactory(kCmdLineServiceCID, path);
|
||||
nsComponentManager::UnregisterFactory(kProtocolHelperCID, path);
|
||||
nsComponentManager::UnregisterFactory(kXPConnectFactoryCID, path);
|
||||
nsComponentManager::UnregisterFactory(kGlobalHistoryCID, path);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -99,6 +103,9 @@ NSGetFactory(nsISupports* serviceMgr,
|
|||
else if (aClass.Equals(kXPConnectFactoryCID)) {
|
||||
rv = NS_NewXPConnectFactoryFactory(aFactory);
|
||||
}
|
||||
else if (aClass.Equals(kGlobalHistoryCID)) {
|
||||
rv = NS_NewGlobalHistoryFactory(aFactory);
|
||||
}
|
||||
|
||||
#if 0
|
||||
else if (aClass.Equals(kProtocolHelperCID)) {
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include "nsIWidget.h"
|
||||
#include "nsIWebShellWindow.h"
|
||||
#include "nsWebShellWindow.h"
|
||||
#include "nsIGlobalHistory.h"
|
||||
|
||||
/* For Javascript Namespace Access */
|
||||
#include "nsDOMCID.h"
|
||||
|
@ -48,6 +49,7 @@
|
|||
static NS_DEFINE_IID(kAppShellCID, NS_APPSHELL_CID);
|
||||
static NS_DEFINE_IID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
||||
static NS_DEFINE_IID(kCScriptNameSetRegistryCID, NS_SCRIPT_NAMESET_REGISTRY_CID);
|
||||
static NS_DEFINE_IID(kCGlobalHistoryCID, NS_GLOBALHISTORY_CID);
|
||||
|
||||
/* Define Interface IDs */
|
||||
|
||||
|
@ -57,7 +59,7 @@ static NS_DEFINE_IID(kIAppShellServiceIID, NS_IAPPSHELL_SERVICE_IID);
|
|||
static NS_DEFINE_IID(kIAppShellIID, NS_IAPPSHELL_IID);
|
||||
static NS_DEFINE_IID(kIWebShellWindowIID, NS_IWEBSHELL_WINDOW_IID);
|
||||
static NS_DEFINE_IID(kIScriptNameSetRegistryIID, NS_ISCRIPTNAMESETREGISTRY_IID);
|
||||
|
||||
static NS_DEFINE_IID(kIGlobalHistoryIID, NS_IGLOBALHISTORY_IID);
|
||||
|
||||
|
||||
class nsAppShellService : public nsIAppShellService
|
||||
|
@ -154,6 +156,16 @@ nsAppShellService::Initialize(void)
|
|||
goto done;
|
||||
}
|
||||
|
||||
// Initialise the global History
|
||||
nsIGlobalHistory * gHistory;
|
||||
rv = nsServiceManager::GetService(kCGlobalHistoryCID,
|
||||
kIGlobalHistoryIID,
|
||||
(nsISupports **)&gHistory);
|
||||
if (NS_FAILED(rv)) {
|
||||
goto done;
|
||||
}
|
||||
gHistory->Init();
|
||||
|
||||
// Create widget application shell
|
||||
rv = nsComponentManager::CreateInstance(kAppShellCID, nsnull, kIAppShellIID,
|
||||
(void**)&mAppShell);
|
||||
|
|
|
@ -0,0 +1,271 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (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/NPL/
|
||||
*
|
||||
* 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 Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
/** Wrapper class for Global History implementation. This class
|
||||
* primarily passes on the data to the nsIHistoryDataSource interface
|
||||
*/
|
||||
|
||||
#include "nsIGlobalHistory.h"
|
||||
#include "nsIRDFDataSource.h"
|
||||
#include "nsIRDFService.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIHistoryDataSource.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsRDFCID.h"
|
||||
#include "nsString.h"
|
||||
#include "plstr.h"
|
||||
|
||||
|
||||
|
||||
/* Define Class IDs */
|
||||
static NS_DEFINE_CID(kGlobalHistoryCID, NS_GLOBALHISTORY_CID);
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
|
||||
/* Define Interface IDs */
|
||||
|
||||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
static NS_DEFINE_IID(kIGlobalHistoryIID, NS_IGLOBALHISTORY_IID);
|
||||
static NS_DEFINE_IID(kIRDFDataSourceIID, NS_IRDFDATASOURCE_IID);
|
||||
static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
|
||||
|
||||
|
||||
class nsGlobalHistory : public nsIGlobalHistory
|
||||
{
|
||||
public:
|
||||
nsGlobalHistory(void);
|
||||
|
||||
// nsISupports methods
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIGlobalHistory
|
||||
NS_IMETHOD AddPage (const char* aURI, const char* aRefererURI, PRTime aDate);
|
||||
NS_IMETHOD SetPageTitle (const char* aURI, const PRUnichar* aTitle);
|
||||
NS_IMETHOD RemovePage (const char* aURI);
|
||||
NS_IMETHOD GetLastVisitDate (const char* aURI, uint32 *aDate);
|
||||
NS_IMETHOD CompleteURL (const char* aPrefix, char** aPreferredCompletions);
|
||||
NS_IMETHOD Init(void);
|
||||
|
||||
private:
|
||||
virtual ~nsGlobalHistory();
|
||||
nsIHistoryDataSource * mGHistory;
|
||||
|
||||
};
|
||||
|
||||
|
||||
nsGlobalHistory::nsGlobalHistory()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mGHistory = nsnull;
|
||||
}
|
||||
|
||||
nsGlobalHistory::~nsGlobalHistory()
|
||||
{
|
||||
mGHistory = nsnull;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Implement the nsISupports methods...
|
||||
*/
|
||||
NS_IMPL_ISUPPORTS(nsGlobalHistory, kIGlobalHistoryIID);
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGlobalHistory::Init(void)
|
||||
{
|
||||
|
||||
/* Create a RDF Data source for history */
|
||||
nsIRDFService* rdf;
|
||||
if (NS_SUCCEEDED(nsServiceManager::GetService(kRDFServiceCID,
|
||||
nsIRDFService::GetIID(),
|
||||
(nsISupports**) &rdf))) {
|
||||
nsCOMPtr<nsIRDFDataSource> ds;
|
||||
static const char* kHistoryDataSourceURI = "rdf:history";
|
||||
if (NS_SUCCEEDED(rdf->GetDataSource(kHistoryDataSourceURI,
|
||||
getter_AddRefs(ds)))) {
|
||||
ds->QueryInterface(nsIHistoryDataSource::GetIID(), (void**) &mGHistory);
|
||||
}
|
||||
nsServiceManager::ReleaseService(kRDFServiceCID, rdf);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGlobalHistory::AddPage(const char * aURI, const char * aRefererURI, PRTime aDate)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
if (NS_FAILED(rv = mGHistory->AddPage(aURI, /* XXX referrer? */ (char *) nsnull, PR_Now()))) {
|
||||
NS_ERROR("unable to add page to history");
|
||||
return rv;
|
||||
}
|
||||
else
|
||||
printf("Added page %s to the rdf:history datasource\n", aURI);
|
||||
return rv;
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGlobalHistory::SetPageTitle (const char* aURI, const PRUnichar* aTitle)
|
||||
{
|
||||
nsresult rv=nsnull;
|
||||
if (NS_FAILED(rv = mGHistory->SetPageTitle(aURI, aTitle))) {
|
||||
NS_ERROR("unable to set doc title");
|
||||
return rv;
|
||||
}
|
||||
return rv;
|
||||
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGlobalHistory::RemovePage (const char* aURI)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
mGHistory->RemovePage(aURI);
|
||||
return rv;
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGlobalHistory::GetLastVisitDate (const char* aURI, uint32 *aResult)
|
||||
{
|
||||
|
||||
if (nsnull == aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
mGHistory->GetLastVisitDate(aURI, aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGlobalHistory::CompleteURL (const char* aPrefix, char** aResult)
|
||||
{
|
||||
if (nsnull == aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
mGHistory->CompleteURL(aPrefix, aResult);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_EXPORT nsresult NS_NewGlobalHistory(nsIGlobalHistory** aResult)
|
||||
{
|
||||
if (nsnull == aResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
*aResult = new nsGlobalHistory();
|
||||
if (nsnull == *aResult) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
NS_ADDREF(*aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
// Factory code for creating nsGlobalHistory
|
||||
|
||||
class nsGlobalHistoryFactory : public nsIFactory
|
||||
{
|
||||
public:
|
||||
nsGlobalHistoryFactory();
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIFactory methods
|
||||
NS_IMETHOD CreateInstance(nsISupports *aOuter,
|
||||
const nsIID &aIID,
|
||||
void **aResult);
|
||||
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
protected:
|
||||
virtual ~nsGlobalHistoryFactory();
|
||||
};
|
||||
|
||||
|
||||
nsGlobalHistoryFactory::nsGlobalHistoryFactory()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGlobalHistoryFactory::LockFactory(PRBool lock)
|
||||
{
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsGlobalHistoryFactory::~nsGlobalHistoryFactory()
|
||||
{
|
||||
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsGlobalHistoryFactory, kIFactoryIID);
|
||||
|
||||
|
||||
nsresult
|
||||
nsGlobalHistoryFactory::CreateInstance(nsISupports *aOuter,
|
||||
const nsIID &aIID,
|
||||
void **aResult)
|
||||
{
|
||||
nsresult rv;
|
||||
nsGlobalHistory* inst;
|
||||
|
||||
if (aResult == NULL) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
*aResult = NULL;
|
||||
if (nsnull != aOuter) {
|
||||
rv = NS_ERROR_NO_AGGREGATION;
|
||||
goto done;
|
||||
}
|
||||
|
||||
NS_NEWXPCOM(inst, nsGlobalHistory);
|
||||
if (inst == NULL) {
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
goto done;
|
||||
}
|
||||
|
||||
NS_ADDREF(inst);
|
||||
rv = inst->QueryInterface(aIID, aResult);
|
||||
NS_RELEASE(inst);
|
||||
|
||||
done:
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
NS_NewGlobalHistoryFactory(nsIFactory** aFactory)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsIFactory* inst = new nsGlobalHistoryFactory();
|
||||
if (nsnull == inst) {
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
else {
|
||||
NS_ADDREF(inst);
|
||||
}
|
||||
*aFactory = inst;
|
||||
return rv;
|
||||
}
|
Загрузка…
Ссылка в новой задаче