2015-05-03 22:32:37 +03: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 15:12:37 +04: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 05:30:59 +03:00
|
|
|
|
2014-02-28 03:04:46 +04:00
|
|
|
#ifndef nsNameSpaceManager_h___
|
|
|
|
#define nsNameSpaceManager_h___
|
1998-12-11 05:30:59 +03:00
|
|
|
|
2014-02-28 03:04:46 +04:00
|
|
|
#include "nsDataHashtable.h"
|
2016-05-13 03:24:07 +03:00
|
|
|
#include "nsHashKeys.h"
|
2017-10-03 01:05:19 +03:00
|
|
|
#include "nsAtom.h"
|
2016-06-28 17:24:48 +03:00
|
|
|
#include "nsIDocument.h"
|
2017-08-17 02:48:52 +03:00
|
|
|
#include "nsStringFwd.h"
|
2014-02-28 03:04:46 +04:00
|
|
|
#include "nsTArray.h"
|
|
|
|
|
|
|
|
#include "mozilla/StaticPtr.h"
|
1998-12-11 05:30:59 +03:00
|
|
|
|
|
|
|
/**
|
2010-05-13 16:19:51 +04:00
|
|
|
* The Name Space Manager tracks the association between a NameSpace
|
2017-07-06 15:00:35 +03:00
|
|
|
* URI and the int32_t runtime id. Mappings between NameSpaces and
|
2002-11-30 02:44:07 +03:00
|
|
|
* NameSpace prefixes are managed by nsINameSpaces.
|
1998-12-11 05:30:59 +03: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-28 03:04:46 +04:00
|
|
|
* The nsNameSpaceManager needs to have a live reference for as long as
|
2002-11-30 02:44:07 +03:00
|
|
|
* the NameSpace IDs are needed.
|
1998-12-11 05:30:59 +03:00
|
|
|
*
|
|
|
|
*/
|
2001-09-05 08:20:54 +04:00
|
|
|
|
2018-07-25 19:12:50 +03:00
|
|
|
class nsNameSpaceManager final
|
2001-09-05 08:20:54 +04:00
|
|
|
{
|
1998-12-11 05:30:59 +03:00
|
|
|
public:
|
2018-07-25 19:12:50 +03:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(nsNameSpaceManager)
|
|
|
|
|
2016-06-28 17:24:48 +03:00
|
|
|
virtual nsresult RegisterNameSpace(const nsAString& aURI,
|
|
|
|
int32_t& aNameSpaceID);
|
2018-04-04 03:59:03 +03:00
|
|
|
nsresult RegisterNameSpace(already_AddRefed<nsAtom> aURI,
|
|
|
|
int32_t& aNameSpaceID);
|
1999-06-30 23:28:16 +04:00
|
|
|
|
2016-06-28 17:24:48 +03:00
|
|
|
virtual nsresult GetNameSpaceURI(int32_t aNameSpaceID, nsAString& aURI);
|
2016-05-13 03:24:07 +03:00
|
|
|
|
2016-08-06 00:21:54 +03: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);
|
2017-12-04 02:19:44 +03:00
|
|
|
//
|
|
|
|
// NB: The requirement of mapping from the first entry to the empty atom is
|
|
|
|
// necessary for Servo, though it can be removed if needed adding a branch in
|
|
|
|
// GeckoElement::get_namespace().
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* NameSpaceURIAtom(int32_t aNameSpaceID) {
|
2016-08-06 00:21:54 +03:00
|
|
|
MOZ_ASSERT(aNameSpaceID > 0);
|
|
|
|
MOZ_ASSERT((int64_t) aNameSpaceID < (int64_t) mURIArray.Length());
|
|
|
|
return mURIArray.ElementAt(aNameSpaceID);
|
2016-05-13 03:24:07 +03:00
|
|
|
}
|
|
|
|
|
2016-06-28 17:24:48 +03:00
|
|
|
int32_t GetNameSpaceID(const nsAString& aURI,
|
|
|
|
bool aInChromeDoc);
|
2017-10-03 01:05:19 +03:00
|
|
|
int32_t GetNameSpaceID(nsAtom* aURI,
|
2016-06-28 17:24:48 +03:00
|
|
|
bool aInChromeDoc);
|
2001-09-05 08:20:54 +04:00
|
|
|
|
2016-06-30 21:13:54 +03:00
|
|
|
bool HasElementCreator(int32_t aNameSpaceID);
|
2005-11-11 17:36:26 +03:00
|
|
|
|
2014-02-28 03:04:46 +04:00
|
|
|
static nsNameSpaceManager* GetInstance();
|
2016-06-28 17:24:48 +03:00
|
|
|
bool mMathMLDisabled;
|
2016-12-01 10:41:22 +03:00
|
|
|
bool mSVGDisabled;
|
2016-06-28 17:24:48 +03:00
|
|
|
|
2014-02-28 03:04:46 +04:00
|
|
|
private:
|
2018-07-06 01:07:12 +03:00
|
|
|
void PrefChanged(const char* aPref);
|
|
|
|
|
2014-02-28 03:04:46 +04:00
|
|
|
bool Init();
|
2017-10-03 01:05:19 +03:00
|
|
|
nsresult AddNameSpace(already_AddRefed<nsAtom> aURI, const int32_t aNameSpaceID);
|
|
|
|
nsresult AddDisabledNameSpace(already_AddRefed<nsAtom> aURI, const int32_t aNameSpaceID);
|
2016-06-28 17:24:48 +03:00
|
|
|
~nsNameSpaceManager() {};
|
1998-12-11 05:30:59 +03:00
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
nsDataHashtable<nsRefPtrHashKey<nsAtom>, int32_t> mURIToIDTable;
|
|
|
|
nsDataHashtable<nsRefPtrHashKey<nsAtom>, int32_t> mDisabledURIToIDTable;
|
|
|
|
nsTArray<RefPtr<nsAtom>> mURIArray;
|
2001-09-06 10:18:31 +04:00
|
|
|
|
2016-06-28 17:24:48 +03:00
|
|
|
static mozilla::StaticRefPtr<nsNameSpaceManager> sInstance;
|
2014-02-28 03:04:46 +04:00
|
|
|
};
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2014-02-28 03:04:46 +04:00
|
|
|
#endif // nsNameSpaceManager_h___
|