2015-05-03 19:32:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1998-12-11 02:30:59 +00:00
|
|
|
|
2014-02-27 23:04:46 +00:00
|
|
|
#ifndef nsNameSpaceManager_h___
|
|
|
|
#define nsNameSpaceManager_h___
|
1998-12-11 02:30:59 +00:00
|
|
|
|
2014-02-27 23:04:46 +00:00
|
|
|
#include "nsDataHashtable.h"
|
2016-05-13 00:24:07 +00:00
|
|
|
#include "nsHashKeys.h"
|
|
|
|
#include "nsIAtom.h"
|
2016-06-28 14:24:48 +00:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIObserver.h"
|
2014-02-27 23:04:46 +00:00
|
|
|
#include "nsTArray.h"
|
|
|
|
|
|
|
|
#include "mozilla/StaticPtr.h"
|
1998-12-11 02:30:59 +00:00
|
|
|
|
2013-10-21 21:23:33 +00:00
|
|
|
class nsAString;
|
1998-12-11 02:30:59 +00:00
|
|
|
|
|
|
|
/**
|
2010-05-13 12:19:51 +00:00
|
|
|
* The Name Space Manager tracks the association between a NameSpace
|
2012-08-22 15:56:38 +00:00
|
|
|
* URI and the int32_t runtime id. Mappings between NameSpaces and
|
2002-11-29 23:44:07 +00:00
|
|
|
* NameSpace prefixes are managed by nsINameSpaces.
|
1998-12-11 02:30:59 +00:00
|
|
|
*
|
|
|
|
* All NameSpace URIs are stored in a global table so that IDs are
|
|
|
|
* consistent accross the app. NameSpace IDs are only consistent at runtime
|
|
|
|
* ie: they are not guaranteed to be consistent accross app sessions.
|
|
|
|
*
|
2014-02-27 23:04:46 +00:00
|
|
|
* The nsNameSpaceManager needs to have a live reference for as long as
|
2002-11-29 23:44:07 +00:00
|
|
|
* the NameSpace IDs are needed.
|
1998-12-11 02:30:59 +00:00
|
|
|
*
|
|
|
|
*/
|
2001-09-05 04:20:54 +00:00
|
|
|
|
2016-06-28 14:24:48 +00:00
|
|
|
class nsNameSpaceManager final : public nsIObserver
|
2001-09-05 04:20:54 +00:00
|
|
|
{
|
1998-12-11 02:30:59 +00:00
|
|
|
public:
|
2016-06-28 14:24:48 +00:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
virtual nsresult RegisterNameSpace(const nsAString& aURI,
|
|
|
|
int32_t& aNameSpaceID);
|
1999-06-30 19:28:16 +00:00
|
|
|
|
2016-06-28 14:24:48 +00:00
|
|
|
virtual nsresult GetNameSpaceURI(int32_t aNameSpaceID, nsAString& aURI);
|
2016-05-13 00:24:07 +00:00
|
|
|
|
2016-08-05 21:21:54 +00:00
|
|
|
// Returns the atom for the namespace URI associated with the given ID. The
|
|
|
|
// ID must be within range and not be kNameSpaceID_None (i.e. zero);
|
2016-05-13 00:24:07 +00:00
|
|
|
nsIAtom* NameSpaceURIAtom(int32_t aNameSpaceID) {
|
2016-08-05 21:21:54 +00:00
|
|
|
MOZ_ASSERT(aNameSpaceID > 0);
|
|
|
|
return NameSpaceURIAtomForServo(aNameSpaceID);
|
|
|
|
}
|
|
|
|
|
|
|
|
// NB: This function should only be called by Servo code (and the above
|
|
|
|
// accessor), which uses the empty atom to represent kNameSpaceID_None.
|
|
|
|
nsIAtom* NameSpaceURIAtomForServo(int32_t aNameSpaceID) {
|
|
|
|
MOZ_ASSERT(aNameSpaceID >= 0);
|
|
|
|
MOZ_ASSERT((int64_t) aNameSpaceID < (int64_t) mURIArray.Length());
|
|
|
|
return mURIArray.ElementAt(aNameSpaceID);
|
2016-05-13 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
2016-06-28 14:24:48 +00:00
|
|
|
int32_t GetNameSpaceID(const nsAString& aURI,
|
|
|
|
bool aInChromeDoc);
|
|
|
|
int32_t GetNameSpaceID(nsIAtom* aURI,
|
|
|
|
bool aInChromeDoc);
|
2001-09-05 04:20:54 +00:00
|
|
|
|
2016-06-30 18:13:54 +00:00
|
|
|
bool HasElementCreator(int32_t aNameSpaceID);
|
2005-11-11 14:36:26 +00:00
|
|
|
|
2014-02-27 23:04:46 +00:00
|
|
|
static nsNameSpaceManager* GetInstance();
|
2016-06-28 14:24:48 +00:00
|
|
|
bool mMathMLDisabled;
|
|
|
|
|
2014-02-27 23:04:46 +00:00
|
|
|
private:
|
|
|
|
bool Init();
|
2016-05-13 00:24:07 +00:00
|
|
|
nsresult AddNameSpace(already_AddRefed<nsIAtom> aURI, const int32_t aNameSpaceID);
|
2016-06-28 14:24:48 +00:00
|
|
|
nsresult AddDisabledNameSpace(already_AddRefed<nsIAtom> aURI, const int32_t aNameSpaceID);
|
|
|
|
~nsNameSpaceManager() {};
|
1998-12-11 02:30:59 +00:00
|
|
|
|
2016-05-13 00:24:07 +00:00
|
|
|
nsDataHashtable<nsISupportsHashKey, int32_t> mURIToIDTable;
|
2016-06-28 14:24:48 +00:00
|
|
|
nsDataHashtable<nsISupportsHashKey, int32_t> mDisabledURIToIDTable;
|
2016-05-13 00:24:07 +00:00
|
|
|
nsTArray<nsCOMPtr<nsIAtom>> mURIArray;
|
2001-09-06 06:18:31 +00:00
|
|
|
|
2016-06-28 14:24:48 +00:00
|
|
|
static mozilla::StaticRefPtr<nsNameSpaceManager> sInstance;
|
2014-02-27 23:04:46 +00:00
|
|
|
};
|
|
|
|
|
2014-02-27 23:04:46 +00:00
|
|
|
#endif // nsNameSpaceManager_h___
|