Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef mozilla_a11_DocManager_h_
6 #define mozilla_a11_DocManager_h_
8 #include "nsIDocument.h"
9 #include "nsIDOMEventListener.h"
10 #include "nsRefPtrHashtable.h"
11 #include "nsIWebProgressListener.h"
12 #include "nsWeakReference.h"
13 #include "nsIPresShell.h"
15 namespace mozilla {
16 namespace a11y {
18 class Accessible;
19 class DocAccessible;
21 /**
22 * Manage the document accessible life cycle.
23 */
24 class DocManager : public nsIWebProgressListener,
25 public nsIDOMEventListener,
26 public nsSupportsWeakReference
27 {
28 public:
29 virtual ~DocManager() { }
31 NS_DECL_THREADSAFE_ISUPPORTS
32 NS_DECL_NSIWEBPROGRESSLISTENER
33 NS_DECL_NSIDOMEVENTLISTENER
35 /**
36 * Return document accessible for the given DOM node.
37 */
38 DocAccessible* GetDocAccessible(nsIDocument* aDocument);
40 /**
41 * Return document accessible for the given presshell.
42 */
43 DocAccessible* GetDocAccessible(const nsIPresShell* aPresShell)
44 {
45 if (!aPresShell)
46 return nullptr;
48 DocAccessible* doc = aPresShell->GetDocAccessible();
49 if (doc)
50 return doc;
52 return GetDocAccessible(aPresShell->GetDocument());
53 }
55 /**
56 * Search through all document accessibles for an accessible with the given
57 * unique id.
58 */
59 Accessible* FindAccessibleInCache(nsINode* aNode) const;
61 /**
62 * Called by document accessible when it gets shutdown.
63 */
64 inline void NotifyOfDocumentShutdown(nsIDocument* aDocument)
65 {
66 mDocAccessibleCache.Remove(aDocument);
67 RemoveListeners(aDocument);
68 }
70 #ifdef DEBUG
71 bool IsProcessingRefreshDriverNotification() const;
72 #endif
74 protected:
75 DocManager();
77 /**
78 * Initialize the manager.
79 */
80 bool Init();
82 /**
83 * Shutdown the manager.
84 */
85 void Shutdown();
87 private:
88 DocManager(const DocManager&);
89 DocManager& operator =(const DocManager&);
91 private:
92 /**
93 * Create an accessible document if it was't created and fire accessibility
94 * events if needed.
95 *
96 * @param aDocument [in] loaded DOM document
97 * @param aLoadEventType [in] specifies the event type to fire load event,
98 * if 0 then no event is fired
99 */
100 void HandleDOMDocumentLoad(nsIDocument* aDocument,
101 uint32_t aLoadEventType);
103 /**
104 * Add/remove 'pagehide' and 'DOMContentLoaded' event listeners.
105 */
106 void AddListeners(nsIDocument *aDocument, bool aAddPageShowListener);
107 void RemoveListeners(nsIDocument* aDocument);
109 /**
110 * Create document or root accessible.
111 */
112 DocAccessible* CreateDocOrRootAccessible(nsIDocument* aDocument);
114 typedef nsRefPtrHashtable<nsPtrHashKey<const nsIDocument>, DocAccessible>
115 DocAccessibleHashtable;
117 /**
118 * Get first entry of the document accessible from cache.
119 */
120 static PLDHashOperator
121 GetFirstEntryInDocCache(const nsIDocument* aKey,
122 DocAccessible* aDocAccessible,
123 void* aUserArg);
125 /**
126 * Clear the cache and shutdown the document accessibles.
127 */
128 void ClearDocCache();
130 struct nsSearchAccessibleInCacheArg
131 {
132 Accessible* mAccessible;
133 nsINode* mNode;
134 };
136 static PLDHashOperator
137 SearchAccessibleInDocCache(const nsIDocument* aKey,
138 DocAccessible* aDocAccessible,
139 void* aUserArg);
141 #ifdef DEBUG
142 static PLDHashOperator
143 SearchIfDocIsRefreshing(const nsIDocument* aKey,
144 DocAccessible* aDocAccessible, void* aUserArg);
145 #endif
147 DocAccessibleHashtable mDocAccessibleCache;
148 };
150 /**
151 * Return the existing document accessible for the document if any.
152 * Note this returns the doc accessible for the primary pres shell if there is
153 * more than one.
154 */
155 inline DocAccessible*
156 GetExistingDocAccessible(const nsIDocument* aDocument)
157 {
158 nsIPresShell* ps = aDocument->GetShell();
159 return ps ? ps->GetDocAccessible() : nullptr;
160 }
162 } // namespace a11y
163 } // namespace mozilla
165 #endif // mozilla_a11_DocManager_h_