2012-05-21 04:12:37 -07: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/. */
|
2010-06-08 09:39:58 -07:00
|
|
|
|
2012-11-20 06:15:32 -08:00
|
|
|
#ifndef mozilla_a11_DocManager_h_
|
|
|
|
#define mozilla_a11_DocManager_h_
|
2010-06-08 09:39:58 -07:00
|
|
|
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDOMEventListener.h"
|
2011-01-27 20:38:14 -08:00
|
|
|
#include "nsRefPtrHashtable.h"
|
2010-06-08 09:39:58 -07:00
|
|
|
#include "nsIWebProgressListener.h"
|
|
|
|
#include "nsWeakReference.h"
|
2012-04-16 22:29:47 -07:00
|
|
|
#include "nsIPresShell.h"
|
2010-06-08 09:39:58 -07:00
|
|
|
|
2012-11-17 18:01:44 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace a11y {
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
class Accessible;
|
2012-05-27 02:01:40 -07:00
|
|
|
class DocAccessible;
|
2014-10-21 17:49:28 -07:00
|
|
|
class xpcAccessibleDocument;
|
2014-03-07 13:35:19 -08:00
|
|
|
class DocAccessibleParent;
|
2010-06-08 09:39:58 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Manage the document accessible life cycle.
|
|
|
|
*/
|
2012-11-20 06:15:32 -08:00
|
|
|
class DocManager : public nsIWebProgressListener,
|
|
|
|
public nsIDOMEventListener,
|
|
|
|
public nsSupportsWeakReference
|
2010-06-08 09:39:58 -07:00
|
|
|
{
|
|
|
|
public:
|
2013-07-14 09:34:46 -07:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2010-06-08 09:39:58 -07:00
|
|
|
NS_DECL_NSIWEBPROGRESSLISTENER
|
|
|
|
NS_DECL_NSIDOMEVENTLISTENER
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return document accessible for the given DOM node.
|
|
|
|
*/
|
2012-05-27 02:01:40 -07:00
|
|
|
DocAccessible* GetDocAccessible(nsIDocument* aDocument);
|
2010-06-08 09:39:58 -07:00
|
|
|
|
2012-04-16 22:29:47 -07:00
|
|
|
/**
|
|
|
|
* Return document accessible for the given presshell.
|
|
|
|
*/
|
2012-05-27 02:01:40 -07:00
|
|
|
DocAccessible* GetDocAccessible(const nsIPresShell* aPresShell)
|
2012-04-16 22:29:47 -07:00
|
|
|
{
|
2012-10-15 07:58:42 -07:00
|
|
|
if (!aPresShell)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
DocAccessible* doc = aPresShell->GetDocAccessible();
|
|
|
|
if (doc)
|
|
|
|
return doc;
|
|
|
|
|
|
|
|
return GetDocAccessible(aPresShell->GetDocument());
|
2012-04-16 22:29:47 -07:00
|
|
|
}
|
|
|
|
|
2010-06-08 09:39:58 -07:00
|
|
|
/**
|
|
|
|
* Search through all document accessibles for an accessible with the given
|
|
|
|
* unique id.
|
|
|
|
*/
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* FindAccessibleInCache(nsINode* aNode) const;
|
2010-06-08 09:39:58 -07:00
|
|
|
|
2010-10-28 02:34:26 -07:00
|
|
|
/**
|
|
|
|
* Called by document accessible when it gets shutdown.
|
|
|
|
*/
|
2014-10-21 17:49:28 -07:00
|
|
|
void NotifyOfDocumentShutdown(DocAccessible* aDocument,
|
|
|
|
nsIDocument* aDOMDocument);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return XPCOM accessible document.
|
|
|
|
*/
|
|
|
|
xpcAccessibleDocument* GetXPCDocument(DocAccessible* aDocument);
|
|
|
|
xpcAccessibleDocument* GetCachedXPCDocument(DocAccessible* aDocument) const
|
|
|
|
{ return mXPCDocumentCache.GetWeak(aDocument); }
|
2010-10-28 02:34:26 -07:00
|
|
|
|
2014-03-07 13:35:19 -08:00
|
|
|
/*
|
|
|
|
* Notification that a top level document in a content process has gone away.
|
|
|
|
*/
|
|
|
|
void RemoteDocShutdown(DocAccessibleParent* aDoc)
|
|
|
|
{
|
|
|
|
DebugOnly<bool> result = mRemoteDocuments.RemoveElement(aDoc);
|
|
|
|
MOZ_ASSERT(result, "Why didn't we find the document!");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Notify of a new top level document in a content process.
|
|
|
|
*/
|
|
|
|
void RemoteDocAdded(DocAccessibleParent* aDoc)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mRemoteDocuments.Contains(aDoc),
|
|
|
|
"How did we already have the doc!");
|
|
|
|
mRemoteDocuments.AppendElement(aDoc);
|
|
|
|
}
|
|
|
|
|
2011-10-05 19:10:30 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool IsProcessingRefreshDriverNotification() const;
|
|
|
|
#endif
|
|
|
|
|
2010-06-08 09:39:58 -07:00
|
|
|
protected:
|
2013-09-02 01:41:57 -07:00
|
|
|
DocManager();
|
2014-06-23 12:56:09 -07:00
|
|
|
virtual ~DocManager() { }
|
2010-06-08 09:39:58 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the manager.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool Init();
|
2010-06-08 09:39:58 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Shutdown the manager.
|
|
|
|
*/
|
|
|
|
void Shutdown();
|
|
|
|
|
|
|
|
private:
|
2012-11-20 06:15:32 -08:00
|
|
|
DocManager(const DocManager&);
|
|
|
|
DocManager& operator =(const DocManager&);
|
2010-06-08 09:39:58 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* Create an accessible document if it was't created and fire accessibility
|
|
|
|
* events if needed.
|
|
|
|
*
|
|
|
|
* @param aDocument [in] loaded DOM document
|
|
|
|
* @param aLoadEventType [in] specifies the event type to fire load event,
|
|
|
|
* if 0 then no event is fired
|
|
|
|
*/
|
2012-05-27 02:01:40 -07:00
|
|
|
void HandleDOMDocumentLoad(nsIDocument* aDocument,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aLoadEventType);
|
2010-06-08 09:39:58 -07:00
|
|
|
|
|
|
|
/**
|
2013-03-05 06:56:34 -08:00
|
|
|
* Add/remove 'pagehide' and 'DOMContentLoaded' event listeners.
|
2010-06-08 09:39:58 -07:00
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
void AddListeners(nsIDocument *aDocument, bool aAddPageShowListener);
|
2013-03-05 06:56:34 -08:00
|
|
|
void RemoveListeners(nsIDocument* aDocument);
|
2010-06-08 09:39:58 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create document or root accessible.
|
|
|
|
*/
|
2012-05-27 02:01:40 -07:00
|
|
|
DocAccessible* CreateDocOrRootAccessible(nsIDocument* aDocument);
|
2010-06-08 09:39:58 -07:00
|
|
|
|
|
|
|
/**
|
2010-12-02 08:07:14 -08:00
|
|
|
* Get first entry of the document accessible from cache.
|
2010-06-08 09:39:58 -07:00
|
|
|
*/
|
|
|
|
static PLDHashOperator
|
2010-12-02 08:07:14 -08:00
|
|
|
GetFirstEntryInDocCache(const nsIDocument* aKey,
|
2012-05-27 02:01:40 -07:00
|
|
|
DocAccessible* aDocAccessible,
|
2010-12-02 08:07:14 -08:00
|
|
|
void* aUserArg);
|
2010-06-08 09:39:58 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear the cache and shutdown the document accessibles.
|
|
|
|
*/
|
2010-12-02 08:07:14 -08:00
|
|
|
void ClearDocCache();
|
2010-06-08 09:39:58 -07:00
|
|
|
|
|
|
|
struct nsSearchAccessibleInCacheArg
|
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* mAccessible;
|
2010-10-20 21:16:10 -07:00
|
|
|
nsINode* mNode;
|
2010-06-08 09:39:58 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static PLDHashOperator
|
2010-10-20 21:16:10 -07:00
|
|
|
SearchAccessibleInDocCache(const nsIDocument* aKey,
|
2012-05-27 02:01:40 -07:00
|
|
|
DocAccessible* aDocAccessible,
|
2010-06-08 09:39:58 -07:00
|
|
|
void* aUserArg);
|
|
|
|
|
2011-10-05 19:10:30 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
static PLDHashOperator
|
|
|
|
SearchIfDocIsRefreshing(const nsIDocument* aKey,
|
2012-05-27 02:01:40 -07:00
|
|
|
DocAccessible* aDocAccessible, void* aUserArg);
|
2011-10-05 19:10:30 -07:00
|
|
|
#endif
|
|
|
|
|
2014-10-21 17:49:28 -07:00
|
|
|
typedef nsRefPtrHashtable<nsPtrHashKey<const nsIDocument>, DocAccessible>
|
|
|
|
DocAccessibleHashtable;
|
2012-05-27 02:01:40 -07:00
|
|
|
DocAccessibleHashtable mDocAccessibleCache;
|
2014-03-07 13:35:19 -08:00
|
|
|
|
2014-10-21 17:49:28 -07:00
|
|
|
typedef nsRefPtrHashtable<nsPtrHashKey<const DocAccessible>, xpcAccessibleDocument>
|
|
|
|
XPCDocumentHashtable;
|
|
|
|
XPCDocumentHashtable mXPCDocumentCache;
|
|
|
|
|
2014-03-07 13:35:19 -08:00
|
|
|
/*
|
|
|
|
* The list of remote top level documents.
|
|
|
|
*/
|
|
|
|
nsTArray<DocAccessibleParent*> mRemoteDocuments;
|
2010-06-08 09:39:58 -07:00
|
|
|
};
|
|
|
|
|
2012-11-02 16:57:58 -07:00
|
|
|
/**
|
|
|
|
* Return the existing document accessible for the document if any.
|
|
|
|
* Note this returns the doc accessible for the primary pres shell if there is
|
|
|
|
* more than one.
|
|
|
|
*/
|
|
|
|
inline DocAccessible*
|
|
|
|
GetExistingDocAccessible(const nsIDocument* aDocument)
|
|
|
|
{
|
|
|
|
nsIPresShell* ps = aDocument->GetShell();
|
|
|
|
return ps ? ps->GetDocAccessible() : nullptr;
|
|
|
|
}
|
|
|
|
|
2012-11-20 06:15:32 -08:00
|
|
|
} // namespace a11y
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_a11_DocManager_h_
|