parser/html/nsHtml5AtomTable.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #ifndef nsHtml5AtomTable_h
michael@0 6 #define nsHtml5AtomTable_h
michael@0 7
michael@0 8 #include "nsHashKeys.h"
michael@0 9 #include "nsTHashtable.h"
michael@0 10 #include "nsAutoPtr.h"
michael@0 11 #include "nsIAtom.h"
michael@0 12 #include "nsIThread.h"
michael@0 13
michael@0 14 class nsHtml5Atom;
michael@0 15
michael@0 16 class nsHtml5AtomEntry : public nsStringHashKey
michael@0 17 {
michael@0 18 public:
michael@0 19 nsHtml5AtomEntry(KeyTypePointer aStr);
michael@0 20 nsHtml5AtomEntry(const nsHtml5AtomEntry& aOther);
michael@0 21 ~nsHtml5AtomEntry();
michael@0 22 inline nsHtml5Atom* GetAtom()
michael@0 23 {
michael@0 24 return mAtom;
michael@0 25 }
michael@0 26 private:
michael@0 27 nsAutoPtr<nsHtml5Atom> mAtom;
michael@0 28 };
michael@0 29
michael@0 30 /**
michael@0 31 * nsHtml5AtomTable provides non-locking lookup and creation of atoms for
michael@0 32 * nsHtml5Parser or nsHtml5StreamParser.
michael@0 33 *
michael@0 34 * The hashtable holds dynamically allocated atoms that are private to an
michael@0 35 * instance of nsHtml5Parser or nsHtml5StreamParser. (Static atoms are used on
michael@0 36 * interned nsHtml5ElementNames and interned nsHtml5AttributeNames. Also, when
michael@0 37 * the doctype name is 'html', that identifier needs to be represented as a
michael@0 38 * static atom.)
michael@0 39 *
michael@0 40 * Each instance of nsHtml5Parser has a single instance of nsHtml5AtomTable,
michael@0 41 * and each instance of nsHtml5StreamParser has a single instance of
michael@0 42 * nsHtml5AtomTable. Dynamic atoms obtained from an nsHtml5AtomTable are valid
michael@0 43 * for == comparison with each other or with atoms declared in nsHtml5Atoms
michael@0 44 * within the nsHtml5Tokenizer and the nsHtml5TreeBuilder instances owned by
michael@0 45 * the same nsHtml5Parser/nsHtml5StreamParser instance that owns the
michael@0 46 * nsHtml5AtomTable instance.
michael@0 47 *
michael@0 48 * Dynamic atoms (atoms whose IsStaticAtom() returns false) obtained from
michael@0 49 * nsHtml5AtomTable must be re-obtained from another atom table when there's a
michael@0 50 * need to migrate atoms from an nsHtml5Parser to its nsHtml5StreamParser
michael@0 51 * (re-obtain from the other nsHtml5AtomTable), from an nsHtml5Parser to its
michael@0 52 * owner nsHtml5Parser (re-obtain from the other nsHtml5AtomTable) or from the
michael@0 53 * parser to the DOM (re-obtain from the application-wide atom table). To
michael@0 54 * re-obtain an atom from another atom table, obtain a string from the atom
michael@0 55 * using ToString(nsAString&) and look up an atom in the other table using that
michael@0 56 * string.
michael@0 57 *
michael@0 58 * An instance of nsHtml5AtomTable that belongs to an nsHtml5Parser is only
michael@0 59 * accessed from the main thread. An instance of nsHtml5AtomTable that belongs
michael@0 60 * to an nsHtml5StreamParser is accessed both from the main thread and from the
michael@0 61 * thread that executes the runnables of the nsHtml5StreamParser instance.
michael@0 62 * However, the threads never access the nsHtml5AtomTable instance concurrently
michael@0 63 * in the nsHtml5StreamParser case.
michael@0 64 *
michael@0 65 * Methods on the atoms obtained from nsHtml5AtomTable may be called on any
michael@0 66 * thread, although they only need to be called on the main thread or on the
michael@0 67 * thread working for the nsHtml5StreamParser when nsHtml5AtomTable belongs to
michael@0 68 * an nsHtml5StreamParser.
michael@0 69 *
michael@0 70 * Dynamic atoms obtained from nsHtml5AtomTable are deleted when the
michael@0 71 * nsHtml5AtomTable itself is destructed, which happens when the owner
michael@0 72 * nsHtml5Parser or nsHtml5StreamParser is destructed.
michael@0 73 */
michael@0 74 class nsHtml5AtomTable
michael@0 75 {
michael@0 76 public:
michael@0 77 nsHtml5AtomTable();
michael@0 78 ~nsHtml5AtomTable();
michael@0 79
michael@0 80 /**
michael@0 81 * Obtains the atom for the given string in the scope of this atom table.
michael@0 82 */
michael@0 83 nsIAtom* GetAtom(const nsAString& aKey);
michael@0 84
michael@0 85 /**
michael@0 86 * Empties the table.
michael@0 87 */
michael@0 88 void Clear()
michael@0 89 {
michael@0 90 mTable.Clear();
michael@0 91 }
michael@0 92
michael@0 93 #ifdef DEBUG
michael@0 94 void SetPermittedLookupThread(nsIThread* aThread)
michael@0 95 {
michael@0 96 mPermittedLookupThread = aThread;
michael@0 97 }
michael@0 98 #endif
michael@0 99
michael@0 100 private:
michael@0 101 nsTHashtable<nsHtml5AtomEntry> mTable;
michael@0 102 #ifdef DEBUG
michael@0 103 nsCOMPtr<nsIThread> mPermittedLookupThread;
michael@0 104 #endif
michael@0 105 };
michael@0 106
michael@0 107 #endif // nsHtml5AtomTable_h

mercurial