Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef _nsAccCache_H_
7 #define _nsAccCache_H_
9 #include "nsIAccessible.h"
10 #include "nsRefPtrHashtable.h"
11 #include "nsCycleCollectionParticipant.h"
13 ////////////////////////////////////////////////////////////////////////////////
14 // Accessible cache utils
15 ////////////////////////////////////////////////////////////////////////////////
17 /**
18 * Shutdown and removes the accessible from cache.
19 */
20 template <class T>
21 static PLDHashOperator
22 ClearCacheEntry(const void* aKey, nsRefPtr<T>& aAccessible, void* aUserArg)
23 {
24 NS_ASSERTION(aAccessible, "Calling ClearCacheEntry with a nullptr pointer!");
25 if (aAccessible)
26 aAccessible->Shutdown();
28 return PL_DHASH_REMOVE;
29 }
31 /**
32 * Clear the cache and shutdown the accessibles.
33 */
35 static void
36 ClearCache(mozilla::a11y::AccessibleHashtable& aCache)
37 {
38 aCache.Enumerate(ClearCacheEntry<mozilla::a11y::Accessible>, nullptr);
39 }
41 /**
42 * Traverse the accessible cache entry for cycle collector.
43 */
44 template <class T>
45 static PLDHashOperator
46 CycleCollectorTraverseCacheEntry(const void *aKey, T *aAccessible,
47 void *aUserArg)
48 {
49 nsCycleCollectionTraversalCallback *cb =
50 static_cast<nsCycleCollectionTraversalCallback*>(aUserArg);
52 NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*cb, "accessible cache entry");
54 nsISupports *supports = static_cast<nsIAccessible*>(aAccessible);
55 cb->NoteXPCOMChild(supports);
56 return PL_DHASH_NEXT;
57 }
59 /**
60 * Unlink the accessible cache for the cycle collector.
61 */
62 inline void
63 ImplCycleCollectionUnlink(mozilla::a11y::AccessibleHashtable& aCache)
64 {
65 ClearCache(aCache);
66 }
68 /**
69 * Traverse the accessible cache for cycle collector.
70 */
71 inline void
72 ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
73 mozilla::a11y::AccessibleHashtable& aCache,
74 const char* aName,
75 uint32_t aFlags = 0)
76 {
77 aCache.EnumerateRead(CycleCollectorTraverseCacheEntry<mozilla::a11y::Accessible>,
78 &aCallback);
79 }
81 #endif