зеркало из https://github.com/mozilla/pjs.git
add chardet
This commit is contained in:
Родитель
82b33a9377
Коммит
524e1ec08d
|
@ -0,0 +1,21 @@
|
|||
#!nmake
|
||||
#
|
||||
# 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=..\..
|
||||
IGNORE_MANIFEST=1
|
||||
|
||||
DIRS= public src
|
||||
include <$(DEPTH)\config\rules.mak>
|
|
@ -0,0 +1,27 @@
|
|||
#!nmake
|
||||
#
|
||||
# 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=..\..\..
|
||||
IGNORE_MANIFEST=1
|
||||
|
||||
EXPORTS = \
|
||||
nsMetaCharsetCID.h \
|
||||
$(NULL)
|
||||
|
||||
MODULE=chardet
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
|
@ -0,0 +1,30 @@
|
|||
/* -*- 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) 1999 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsMetaCharsetCID_h__
|
||||
#define nsMetaCharsetCID_h__
|
||||
|
||||
#include "nscore.h"
|
||||
|
||||
#define NS_META_CHARSET_PROGID "component://netscape/intl/metacharset"
|
||||
|
||||
// {218F2AC0-0A48-11d3-B3BA-00805F8A6670}
|
||||
#define NS_META_CHARSET_CID \
|
||||
{ 0x218f2ac0, 0xa48, 0x11d3, { 0xb3, 0xba, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
|
||||
|
||||
#endif // nsMetaCharsetCID_h__
|
|
@ -0,0 +1,67 @@
|
|||
#!nmake
|
||||
#
|
||||
# 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=..\..\..
|
||||
IGNORE_MANIFEST=1
|
||||
|
||||
LCFLAGS= $(LCFLAGS) -D__STDC__
|
||||
|
||||
DEFINES= -DWIN32_LEAN_AND_MEAN
|
||||
LIBRARY_NAME= chardet
|
||||
|
||||
OBJS= \
|
||||
$(NULL)
|
||||
|
||||
CSRCS= \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS= \
|
||||
nsCharDetDll.cpp \
|
||||
nsMetaCharsetObserver.cpp \
|
||||
$(NULL)
|
||||
|
||||
CPP_OBJS= \
|
||||
.\$(OBJDIR)\nsCharDetDll.obj \
|
||||
.\$(OBJDIR)\nsMetaCharsetObserver.obj \
|
||||
$(NULL)
|
||||
|
||||
MODULE=chardet
|
||||
|
||||
REQUIRES=xpcom
|
||||
|
||||
INCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\chardet -I$(PUBLIC)\raptor \
|
||||
-I$(PUBLIC)\netlib -I$(PUBLIC)\uconv
|
||||
|
||||
MAKE_OBJ_TYPE=DLL
|
||||
DLLNAME=chardet
|
||||
DLL=.\$(OBJDIR)\$(DLLNAME).dll
|
||||
|
||||
|
||||
LLIBS= \
|
||||
$(DIST)\lib\xpcom32.lib \
|
||||
$(DIST)\lib\plc3.lib \
|
||||
$(DIST)\lib\raptorbase.lib \
|
||||
$(LIBNSPR)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
libs:: $(DLL)
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\components
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib
|
||||
|
||||
clobber::
|
||||
rm -f $(DIST)\bin\components\$(DLLNAME).dll
|
||||
rm -f $(DIST)\bin\$(DLLNAME).lib
|
|
@ -0,0 +1,104 @@
|
|||
/* -*- 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 "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 "pratom.h"
|
||||
#include "nsCharDetDll.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIFactory.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsMetaCharsetObserver.h"
|
||||
|
||||
#include "nsMetaCharsetCID.h"
|
||||
|
||||
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
|
||||
|
||||
NS_DEFINE_IID(kFactoryIID, NS_IFACTORY_IID);
|
||||
NS_DEFINE_CID(kMetaCharsetCID, NS_META_CHARSET_CID);
|
||||
|
||||
PRInt32 g_InstanceCount = 0;
|
||||
PRInt32 g_LockCount = 0;
|
||||
|
||||
|
||||
extern "C" NS_EXPORT nsresult NSGetFactory(nsISupports* aServMgr,
|
||||
const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
nsIFactory **aFactory)
|
||||
{
|
||||
if (aFactory == NULL) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (aClass.Equals(kMetaCharsetCID)) {
|
||||
nsIFactory *factory = NEW_META_CHARSET_OBSERVER_FACTORY();
|
||||
nsresult res = factory->QueryInterface(kFactoryIID, (void **) aFactory);
|
||||
if (NS_FAILED(res)) {
|
||||
*aFactory = NULL;
|
||||
delete factory;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
extern "C" NS_EXPORT PRBool NSCanUnload(nsISupports* aServMgr) {
|
||||
return PRBool(g_InstanceCount == 0 && g_LockCount == 0);
|
||||
}
|
||||
extern "C" NS_EXPORT nsresult NSRegisterSelf(nsISupports* aServMgr, const char *path)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsIComponentManager* compMgr;
|
||||
rv = servMgr->GetService(kComponentManagerCID,
|
||||
nsIComponentManager::GetIID(),
|
||||
(nsISupports**)&compMgr);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = compMgr->RegisterComponent(kMetaCharsetCID,
|
||||
"Meta Charset",
|
||||
NS_META_CHARSET_PROGID,
|
||||
path,
|
||||
PR_TRUE, PR_TRUE);
|
||||
|
||||
(void)servMgr->ReleaseService(kComponentManagerCID, compMgr);
|
||||
return rv;
|
||||
}
|
||||
|
||||
extern "C" NS_EXPORT nsresult NSUnregisterSelf(nsISupports* aServMgr, const char *path)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsIComponentManager* compMgr;
|
||||
rv = servMgr->GetService(kComponentManagerCID,
|
||||
nsIComponentManager::GetIID(),
|
||||
(nsISupports**)&compMgr);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = compMgr->UnregisterComponent(kMetaCharsetCID, path);
|
||||
|
||||
(void)servMgr->ReleaseService(kComponentManagerCID, compMgr);
|
||||
return rv;
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
/* -*- 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.
|
||||
*/
|
||||
|
||||
#ifndef nsCharDetDll_h__
|
||||
#define nsCharDetDll_h__
|
||||
|
||||
#include "prtypes.h"
|
||||
|
||||
extern "C" PRInt32 g_InstanceCount;
|
||||
extern "C" PRInt32 g_LockCount;
|
||||
|
||||
#endif /* nsCharDetDll_h__ */
|
|
@ -0,0 +1,293 @@
|
|||
/* -*- 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.
|
||||
*/
|
||||
|
||||
#define NS_IMPL_IDS
|
||||
#include "nsICharsetAlias.h"
|
||||
#undef NS_IMPL_IDS
|
||||
|
||||
#include "nsMetaCharsetObserver.h"
|
||||
#include "nsIElementObserver.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsIParser.h"
|
||||
#include "pratom.h"
|
||||
#include "nsCharDetDll.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
static NS_DEFINE_IID(kIElementObserverIID, NS_IELEMENTOBSERVER_IID);
|
||||
static NS_DEFINE_IID(kIObserverIID, NS_IOBSERVER_IID);
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Class declaration for the class
|
||||
//
|
||||
//==========================================================================
|
||||
class nsMetaCharsetObserver: public nsIElementObserver, public nsIObserver {
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
public:
|
||||
|
||||
nsMetaCharsetObserver();
|
||||
virtual ~nsMetaCharsetObserver();
|
||||
|
||||
/*
|
||||
* This method return the tag which the observer care about
|
||||
*/
|
||||
NS_IMETHOD_(const char*) GetTagName();
|
||||
|
||||
/*
|
||||
* Subject call observer when the parser hit the tag
|
||||
* @param aDocumentID- ID of the document
|
||||
* @param aTag- the tag
|
||||
* @param numOfAttributes - number of attributes
|
||||
* @param nameArray - array of name.
|
||||
* @param valueArray - array of value
|
||||
*/
|
||||
NS_IMETHOD Notify(PRUint32 aDocumentID, eHTMLTags aTag, PRUint32 numOfAttributes,
|
||||
const PRUnichar* nameArray[], const PRUnichar* valueArray[]);
|
||||
|
||||
NS_IMETHOD Notify(nsISupports** result);
|
||||
|
||||
};
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
nsMetaCharsetObserver::nsMetaCharsetObserver()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
PR_AtomicIncrement(& g_InstanceCount);
|
||||
}
|
||||
//-------------------------------------------------------------------------
|
||||
nsMetaCharsetObserver::~nsMetaCharsetObserver()
|
||||
{
|
||||
PR_AtomicDecrement(& g_InstanceCount);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMPL_ADDREF ( nsMetaCharsetObserver );
|
||||
NS_IMPL_RELEASE ( nsMetaCharsetObserver );
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsMetaCharsetObserver::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
|
||||
if( NULL == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
*aInstancePtr = NULL;
|
||||
|
||||
if( aIID.Equals ( kIElementObserverIID )) {
|
||||
*aInstancePtr = (void*) ((nsIElementObserver*) this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if( aIID.Equals ( kIObserverIID )) {
|
||||
*aInstancePtr = (void*) ((nsIObserver*) this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if( aIID.Equals ( kISupportsIID )) {
|
||||
*aInstancePtr = (void*) (this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP_(const char*) nsMetaCharsetObserver::GetTagName()
|
||||
{
|
||||
return "META";
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsMetaCharsetObserver::Notify(
|
||||
PRUint32 aDocumentID,
|
||||
eHTMLTags aTag,
|
||||
PRUint32 numOfAttributes,
|
||||
const PRUnichar* nameArray[],
|
||||
const PRUnichar* valueArray[])
|
||||
{
|
||||
if(eHTMLTag_meta != aTag)
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
|
||||
nsresult res = NS_OK;
|
||||
|
||||
// Only process if we get the HTTP-EQUIV=Content-Type in meta
|
||||
// We totaly need 4 attributes
|
||||
// HTTP-EQUIV
|
||||
// CONTENT
|
||||
// currentCharset - pseudo attribute fake by parser
|
||||
// currentCharsetSource - pseudo attribute fake by parser
|
||||
|
||||
if((numOfAttributes >= 4) &&
|
||||
(0 == nsCRT::strcasecmp(nameArray[0], "HTTP-EQUIV")) &&
|
||||
(0 == nsCRT::strcasecmp(valueArray[0], "Content-Type")))
|
||||
{
|
||||
nsAutoString currentCharset("unknown");
|
||||
nsAutoString charsetSourceStr("unknown");
|
||||
|
||||
for(PRUint32 i=0; i < numOfAttributes; i++)
|
||||
{
|
||||
nsAutoString charset("charset");
|
||||
nsAutoString charsetSource("charsetSource");
|
||||
if(0==nsCRT::strcmp(nameArray[i], "charset"))
|
||||
{
|
||||
currentCharset = valueArray[i];
|
||||
} else if(0==nsCRT::strcmp(nameArray[i], "charsetSource")) {
|
||||
charsetSourceStr = valueArray[i];
|
||||
}
|
||||
}
|
||||
|
||||
// if we cannot find currentCharset or currentCharsetSource
|
||||
// return error.
|
||||
if( currentCharset.Equals("unknown") ||
|
||||
charsetSourceStr.Equals("unknown") )
|
||||
{
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
|
||||
PRInt32 err;
|
||||
PRInt32 charsetSourceInt = charsetSourceStr.ToInteger(&err);
|
||||
|
||||
// if we cannot convert the string into nsCharsetSource, return error
|
||||
if(NS_FAILED(err))
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
|
||||
nsCharsetSource currentCharsetSource = (nsCharsetSource)charsetSourceInt;
|
||||
|
||||
if (0==nsCRT::strcasecmp(nameArray[1],"CONTENT"))
|
||||
{
|
||||
nsAutoString content(valueArray[2]);
|
||||
nsAutoString type;
|
||||
content.Left(type, 9); // length of "text/html" == 9
|
||||
if(type.EqualsIgnoreCase("text/html"))
|
||||
{
|
||||
PRInt32 charsetValueStart = content.RFind("charset=", PR_TRUE ) ;
|
||||
if(kNotFound != charsetValueStart) {
|
||||
charsetValueStart += 8; // 8 = "charset=".length
|
||||
PRInt32 charsetValueEnd = content.FindCharInSet("\'\";", charsetValueStart );
|
||||
if(kNotFound == charsetValueEnd )
|
||||
charsetValueEnd = content.Length();
|
||||
nsAutoString theCharset;
|
||||
content.Mid(theCharset, charsetValueStart, charsetValueEnd - charsetValueStart);
|
||||
|
||||
if(kCharsetFromMetaTag > currentCharsetSource)
|
||||
{
|
||||
nsICharsetAlias* calias = nsnull;
|
||||
res = nsServiceManager::GetService(
|
||||
kCharsetAliasCID,
|
||||
kICharsetAliasIID,
|
||||
(nsISupports**) &calias);
|
||||
if(NS_SUCCEEDED(res) && (nsnull != calias) ) {
|
||||
PRBool same = PR_FALSE;
|
||||
res = calias->Equals( theCharset, currentCharset, &same);
|
||||
if(NS_SUCCEEDED(res) && (! same))
|
||||
{
|
||||
nsAutoString preferred;
|
||||
res = calias->GetPreferred(theCharset, preferred);
|
||||
if(NS_SUCCEEDED(res))
|
||||
{
|
||||
// XXX
|
||||
// ask nsWebShellProxy to load docuement
|
||||
// where the docuemtn ID is euqal to aDocuemntID
|
||||
// Charset equal to preferred
|
||||
// and charsetSource is kCharetFromMetaTag
|
||||
}
|
||||
}
|
||||
nsServiceManager::ReleaseService(kCharsetAliasCID, calias);
|
||||
}
|
||||
}
|
||||
|
||||
} // if
|
||||
|
||||
} // if
|
||||
} // if
|
||||
} // if
|
||||
return res;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsMetaCharsetObserver::Notify(nsISupports** result)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
//==========================================================================
|
||||
|
||||
class nsMetaCharsetObserverFactory : public nsIFactory {
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
public:
|
||||
nsMetaCharsetObserverFactory() {
|
||||
NS_INIT_REFCNT();
|
||||
PR_AtomicIncrement(&g_InstanceCount);
|
||||
}
|
||||
virtual ~nsMetaCharsetObserverFactory() {
|
||||
PR_AtomicDecrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
NS_IMETHOD CreateInstance(nsISupports* aDelegate, const nsIID& aIID, void** aResult);
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------
|
||||
NS_DEFINE_IID( kIFactoryIID, NS_IFACTORY_IID);
|
||||
NS_IMPL_ISUPPORTS( nsMetaCharsetObserverFactory , kIFactoryIID);
|
||||
|
||||
NS_IMETHODIMP nsMetaCharsetObserverFactory::CreateInstance(
|
||||
nsISupports* aDelegate, const nsIID &aIID, void** aResult)
|
||||
{
|
||||
if(NULL == aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if(NULL != aDelegate)
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
*aResult = NULL;
|
||||
|
||||
nsMetaCharsetObserver *inst = new nsMetaCharsetObserver();
|
||||
|
||||
|
||||
if(NULL == inst) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
nsresult res =inst->QueryInterface(aIID, aResult);
|
||||
if(NS_FAILED(res)) {
|
||||
delete inst;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
//--------------------------------------------------------------
|
||||
NS_IMETHODIMP nsMetaCharsetObserverFactory::LockFactory(PRBool aLock)
|
||||
{
|
||||
if(aLock)
|
||||
PR_AtomicIncrement( &g_LockCount );
|
||||
else
|
||||
PR_AtomicDecrement( &g_LockCount );
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//==============================================================
|
||||
nsIFactory* NEW_META_CHARSET_OBSERVER_FACTORY()
|
||||
{
|
||||
return new nsMetaCharsetObserverFactory();
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
/* -*- 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 nsMetaCharsetObserverFactory_h__
|
||||
#define nsMetaCharsetObserverFactory_h__
|
||||
|
||||
#include "nsIFactory.h"
|
||||
nsIFactory* NEW_META_CHARSET_OBSERVER_FACTORY();
|
||||
|
||||
#endif // nsMetaCharsetObserverFactory_h__
|
Загрузка…
Ссылка в новой задаче