зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1272537 - Atomize the namespace manager. r=bz
This commit is contained in:
Родитель
744f2efb4a
Коммит
e4d70db3b1
|
@ -2433,3 +2433,15 @@ GK_ATOM(vr_state, "vr-state")
|
|||
|
||||
// Contextual Identity / Containers
|
||||
GK_ATOM(usercontextid, "usercontextid")
|
||||
|
||||
// Namespaces
|
||||
GK_ATOM(nsuri_xmlns, "http://www.w3.org/2000/xmlns/")
|
||||
GK_ATOM(nsuri_xml, "http://www.w3.org/XML/1998/namespace")
|
||||
GK_ATOM(nsuri_xhtml, "http://www.w3.org/1999/xhtml")
|
||||
GK_ATOM(nsuri_xlink, "http://www.w3.org/1999/xlink")
|
||||
GK_ATOM(nsuri_xslt, "http://www.w3.org/1999/XSL/Transform")
|
||||
GK_ATOM(nsuri_xbl, "http://www.mozilla.org/xbl")
|
||||
GK_ATOM(nsuri_mathml, "http://www.w3.org/1998/Math/MathML")
|
||||
GK_ATOM(nsuri_rdf, "http://www.w3.org/1999/02/22-rdf-syntax-ns#")
|
||||
GK_ATOM(nsuri_xul, "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul")
|
||||
GK_ATOM(nsuri_svg, "http://www.w3.org/2000/svg")
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "mozilla/dom/NodeInfo.h"
|
||||
#include "nsCOMArray.h"
|
||||
#include "nsContentCreatorFunctions.h"
|
||||
#include "nsGkAtoms.h"
|
||||
#include "nsString.h"
|
||||
#include "mozilla/dom/NodeInfo.h"
|
||||
#include "mozilla/ClearOnShutdown.h"
|
||||
|
@ -25,17 +26,6 @@
|
|||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
|
||||
#define kXMLNSNameSpaceURI "http://www.w3.org/2000/xmlns/"
|
||||
#define kXMLNameSpaceURI "http://www.w3.org/XML/1998/namespace"
|
||||
#define kXHTMLNameSpaceURI "http://www.w3.org/1999/xhtml"
|
||||
#define kXLinkNameSpaceURI "http://www.w3.org/1999/xlink"
|
||||
#define kXSLTNameSpaceURI "http://www.w3.org/1999/XSL/Transform"
|
||||
#define kXBLNameSpaceURI "http://www.mozilla.org/xbl"
|
||||
#define kMathMLNameSpaceURI "http://www.w3.org/1998/Math/MathML"
|
||||
#define kRDFNameSpaceURI "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
#define kXULNameSpaceURI "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
#define kSVGNameSpaceURI "http://www.w3.org/2000/svg"
|
||||
|
||||
StaticAutoPtr<nsNameSpaceManager> nsNameSpaceManager::sInstance;
|
||||
|
||||
/* static */ nsNameSpaceManager*
|
||||
|
@ -57,20 +47,20 @@ bool nsNameSpaceManager::Init()
|
|||
{
|
||||
nsresult rv;
|
||||
#define REGISTER_NAMESPACE(uri, id) \
|
||||
rv = AddNameSpace(NS_LITERAL_STRING(uri), id); \
|
||||
rv = AddNameSpace(dont_AddRef(uri), id); \
|
||||
NS_ENSURE_SUCCESS(rv, false)
|
||||
|
||||
// Need to be ordered according to ID.
|
||||
REGISTER_NAMESPACE(kXMLNSNameSpaceURI, kNameSpaceID_XMLNS);
|
||||
REGISTER_NAMESPACE(kXMLNameSpaceURI, kNameSpaceID_XML);
|
||||
REGISTER_NAMESPACE(kXHTMLNameSpaceURI, kNameSpaceID_XHTML);
|
||||
REGISTER_NAMESPACE(kXLinkNameSpaceURI, kNameSpaceID_XLink);
|
||||
REGISTER_NAMESPACE(kXSLTNameSpaceURI, kNameSpaceID_XSLT);
|
||||
REGISTER_NAMESPACE(kXBLNameSpaceURI, kNameSpaceID_XBL);
|
||||
REGISTER_NAMESPACE(kMathMLNameSpaceURI, kNameSpaceID_MathML);
|
||||
REGISTER_NAMESPACE(kRDFNameSpaceURI, kNameSpaceID_RDF);
|
||||
REGISTER_NAMESPACE(kXULNameSpaceURI, kNameSpaceID_XUL);
|
||||
REGISTER_NAMESPACE(kSVGNameSpaceURI, kNameSpaceID_SVG);
|
||||
REGISTER_NAMESPACE(nsGkAtoms::nsuri_xmlns, kNameSpaceID_XMLNS);
|
||||
REGISTER_NAMESPACE(nsGkAtoms::nsuri_xml, kNameSpaceID_XML);
|
||||
REGISTER_NAMESPACE(nsGkAtoms::nsuri_xhtml, kNameSpaceID_XHTML);
|
||||
REGISTER_NAMESPACE(nsGkAtoms::nsuri_xlink, kNameSpaceID_XLink);
|
||||
REGISTER_NAMESPACE(nsGkAtoms::nsuri_xslt, kNameSpaceID_XSLT);
|
||||
REGISTER_NAMESPACE(nsGkAtoms::nsuri_xbl, kNameSpaceID_XBL);
|
||||
REGISTER_NAMESPACE(nsGkAtoms::nsuri_mathml, kNameSpaceID_MathML);
|
||||
REGISTER_NAMESPACE(nsGkAtoms::nsuri_rdf, kNameSpaceID_RDF);
|
||||
REGISTER_NAMESPACE(nsGkAtoms::nsuri_xul, kNameSpaceID_XUL);
|
||||
REGISTER_NAMESPACE(nsGkAtoms::nsuri_svg, kNameSpaceID_SVG);
|
||||
|
||||
#undef REGISTER_NAMESPACE
|
||||
|
||||
|
@ -87,11 +77,12 @@ nsNameSpaceManager::RegisterNameSpace(const nsAString& aURI,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIAtom> atom = NS_Atomize(aURI);
|
||||
nsresult rv = NS_OK;
|
||||
if (!mURIToIDTable.Get(&aURI, &aNameSpaceID)) {
|
||||
if (!mURIToIDTable.Get(atom, &aNameSpaceID)) {
|
||||
aNameSpaceID = mURIArray.Length() + 1; // id is index + 1
|
||||
|
||||
rv = AddNameSpace(aURI, aNameSpaceID);
|
||||
rv = AddNameSpace(atom.forget(), aNameSpaceID);
|
||||
if (NS_FAILED(rv)) {
|
||||
aNameSpaceID = kNameSpaceID_Unknown;
|
||||
}
|
||||
|
@ -114,7 +105,7 @@ nsNameSpaceManager::GetNameSpaceURI(int32_t aNameSpaceID, nsAString& aURI)
|
|||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
|
||||
aURI = *mURIArray.ElementAt(index);
|
||||
mURIArray.ElementAt(index)->ToString(aURI);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -128,7 +119,8 @@ nsNameSpaceManager::GetNameSpaceID(const nsAString& aURI)
|
|||
|
||||
int32_t nameSpaceID;
|
||||
|
||||
if (mURIToIDTable.Get(&aURI, &nameSpaceID)) {
|
||||
nsCOMPtr<nsIAtom> atom = NS_Atomize(aURI);
|
||||
if (mURIToIDTable.Get(atom, &nameSpaceID)) {
|
||||
NS_POSTCONDITION(nameSpaceID >= 0, "Bogus namespace ID");
|
||||
return nameSpaceID;
|
||||
}
|
||||
|
@ -177,9 +169,10 @@ nsNameSpaceManager::HasElementCreator(int32_t aNameSpaceID)
|
|||
false;
|
||||
}
|
||||
|
||||
nsresult nsNameSpaceManager::AddNameSpace(const nsAString& aURI,
|
||||
nsresult nsNameSpaceManager::AddNameSpace(already_AddRefed<nsIAtom> aURI,
|
||||
const int32_t aNameSpaceID)
|
||||
{
|
||||
nsCOMPtr<nsIAtom> uri = aURI;
|
||||
if (aNameSpaceID < 0) {
|
||||
// We've wrapped... Can't do anything else here; just bail.
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
@ -188,13 +181,8 @@ nsresult nsNameSpaceManager::AddNameSpace(const nsAString& aURI,
|
|||
NS_ASSERTION(aNameSpaceID - 1 == (int32_t) mURIArray.Length(),
|
||||
"BAD! AddNameSpace not called in right order!");
|
||||
|
||||
nsString* uri = new nsString(aURI);
|
||||
if (!mURIArray.AppendElement(uri)) {
|
||||
delete uri;
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
mURIToIDTable.Put(uri, aNameSpaceID);
|
||||
mURIArray.AppendElement(uri.forget());
|
||||
mURIToIDTable.Put(mURIArray.LastElement(), aNameSpaceID);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -8,50 +8,14 @@
|
|||
#define nsNameSpaceManager_h___
|
||||
|
||||
#include "nsDataHashtable.h"
|
||||
#include "nsHashKeys.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsTArray.h"
|
||||
|
||||
#include "mozilla/StaticPtr.h"
|
||||
|
||||
class nsAString;
|
||||
|
||||
class nsNameSpaceKey : public PLDHashEntryHdr
|
||||
{
|
||||
public:
|
||||
typedef const nsAString* KeyType;
|
||||
typedef const nsAString* KeyTypePointer;
|
||||
|
||||
explicit nsNameSpaceKey(KeyTypePointer aKey) : mKey(aKey)
|
||||
{
|
||||
}
|
||||
nsNameSpaceKey(const nsNameSpaceKey& toCopy) : mKey(toCopy.mKey)
|
||||
{
|
||||
}
|
||||
|
||||
KeyType GetKey() const
|
||||
{
|
||||
return mKey;
|
||||
}
|
||||
bool KeyEquals(KeyType aKey) const
|
||||
{
|
||||
return mKey->Equals(*aKey);
|
||||
}
|
||||
|
||||
static KeyTypePointer KeyToPointer(KeyType aKey)
|
||||
{
|
||||
return aKey;
|
||||
}
|
||||
static PLDHashNumber HashKey(KeyTypePointer aKey) {
|
||||
return mozilla::HashString(*aKey);
|
||||
}
|
||||
|
||||
enum {
|
||||
ALLOW_MEMMOVE = true
|
||||
};
|
||||
|
||||
private:
|
||||
const nsAString* mKey;
|
||||
};
|
||||
|
||||
/**
|
||||
* The Name Space Manager tracks the association between a NameSpace
|
||||
* URI and the int32_t runtime id. Mappings between NameSpaces and
|
||||
|
@ -75,6 +39,12 @@ public:
|
|||
int32_t& aNameSpaceID);
|
||||
|
||||
virtual nsresult GetNameSpaceURI(int32_t aNameSpaceID, nsAString& aURI);
|
||||
|
||||
nsIAtom* NameSpaceURIAtom(int32_t aNameSpaceID) {
|
||||
MOZ_ASSERT(aNameSpaceID > 0 && (int64_t) aNameSpaceID <= (int64_t) mURIArray.Length());
|
||||
return mURIArray.ElementAt(aNameSpaceID - 1); // id is index + 1
|
||||
}
|
||||
|
||||
virtual int32_t GetNameSpaceID(const nsAString& aURI);
|
||||
|
||||
virtual bool HasElementCreator(int32_t aNameSpaceID);
|
||||
|
@ -82,10 +52,10 @@ public:
|
|||
static nsNameSpaceManager* GetInstance();
|
||||
private:
|
||||
bool Init();
|
||||
nsresult AddNameSpace(const nsAString& aURI, const int32_t aNameSpaceID);
|
||||
nsresult AddNameSpace(already_AddRefed<nsIAtom> aURI, const int32_t aNameSpaceID);
|
||||
|
||||
nsDataHashtable<nsNameSpaceKey,int32_t> mURIToIDTable;
|
||||
nsTArray< nsAutoPtr<nsString> > mURIArray;
|
||||
nsDataHashtable<nsISupportsHashKey, int32_t> mURIToIDTable;
|
||||
nsTArray<nsCOMPtr<nsIAtom>> mURIArray;
|
||||
|
||||
static mozilla::StaticAutoPtr<nsNameSpaceManager> sInstance;
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче