From 973d0ef356592ef84f7d643560b07638b5c83a9d Mon Sep 17 00:00:00 2001 From: Trevor Saunders Date: Tue, 19 Jan 2016 11:19:58 -0500 Subject: [PATCH] bug 1241453 - allow caching xpc documents for remote documents r=davidb --- accessible/base/DocManager.cpp | 32 ++++++++++++++++++++++++++ accessible/base/DocManager.h | 17 ++++++++++++++ accessible/ipc/DocAccessibleParent.cpp | 2 ++ 3 files changed, 51 insertions(+) diff --git a/accessible/base/DocManager.cpp b/accessible/base/DocManager.cpp index 6fa97d62972..6318ce961b1 100644 --- a/accessible/base/DocManager.cpp +++ b/accessible/base/DocManager.cpp @@ -40,6 +40,8 @@ using namespace mozilla::a11y; using namespace mozilla::dom; StaticAutoPtr> DocManager::sRemoteDocuments; +nsRefPtrHashtable, xpcAccessibleDocument>* +DocManager::sRemoteXPCDocumentCache = nullptr; //////////////////////////////////////////////////////////////////////////////// // DocManager @@ -101,6 +103,16 @@ DocManager::NotifyOfDocumentShutdown(DocAccessible* aDocument, RemoveListeners(aDOMDocument); } +void +DocManager::NotifyOfRemoteDocShutdown(DocAccessibleParent* aDoc) +{ + xpcAccessibleDocument* doc = GetCachedXPCDocument(aDoc); + if (doc) { + doc->Shutdown(); + sRemoteXPCDocumentCache->Remove(aDoc); + } +} + xpcAccessibleDocument* DocManager::GetXPCDocument(DocAccessible* aDocument) { @@ -115,6 +127,26 @@ DocManager::GetXPCDocument(DocAccessible* aDocument) return xpcDoc; } +xpcAccessibleDocument* +DocManager::GetXPCDocument(DocAccessibleParent* aDoc) +{ + xpcAccessibleDocument* doc = GetCachedXPCDocument(aDoc); + if (doc) { + return doc; + } + + if (!sRemoteXPCDocumentCache) { + sRemoteXPCDocumentCache = + new nsRefPtrHashtable, xpcAccessibleDocument>; + } + + doc = + new xpcAccessibleDocument(aDoc, Interfaces::DOCUMENT | Interfaces::HYPERTEXT); + sRemoteXPCDocumentCache->Put(aDoc, doc); + + return doc; +} + #ifdef DEBUG bool DocManager::IsProcessingRefreshDriverNotification() const diff --git a/accessible/base/DocManager.h b/accessible/base/DocManager.h index 1251f3df2e9..b07b6eb0136 100644 --- a/accessible/base/DocManager.h +++ b/accessible/base/DocManager.h @@ -90,6 +90,21 @@ public: static const nsTArray* TopLevelRemoteDocs() { return sRemoteDocuments; } + /** + * Remove the xpc document for a remote document if there is one. + */ + static void NotifyOfRemoteDocShutdown(DocAccessibleParent* adoc); + + /** + * Get a XPC document for a remote document. + */ + static xpcAccessibleDocument* GetXPCDocument(DocAccessibleParent* aDoc); + static xpcAccessibleDocument* GetCachedXPCDocument(const DocAccessibleParent* aDoc) + { + return sRemoteXPCDocumentCache ? sRemoteXPCDocumentCache->GetWeak(aDoc) + : nullptr; + } + #ifdef DEBUG bool IsProcessingRefreshDriverNotification() const; #endif @@ -147,6 +162,8 @@ private: typedef nsRefPtrHashtable, xpcAccessibleDocument> XPCDocumentHashtable; XPCDocumentHashtable mXPCDocumentCache; + static nsRefPtrHashtable, xpcAccessibleDocument>* + sRemoteXPCDocumentCache; /* * The list of remote top level documents. diff --git a/accessible/ipc/DocAccessibleParent.cpp b/accessible/ipc/DocAccessibleParent.cpp index dc0831d344d..2b0c12dffbf 100644 --- a/accessible/ipc/DocAccessibleParent.cpp +++ b/accessible/ipc/DocAccessibleParent.cpp @@ -267,6 +267,8 @@ DocAccessibleParent::Destroy() ProxyDestroyed(iter.Get()->mProxy); iter.Remove(); } + + DocManager::NotifyOfRemoteDocShutdown(this); ProxyDestroyed(this); if (mParentDoc) mParentDoc->RemoveChildDoc(this);