2010-07-16 14:15:07 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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 16:39:58 +00:00
|
|
|
|
2012-11-20 14:15:32 +00:00
|
|
|
#include "DocManager.h"
|
2010-06-08 16:39:58 +00:00
|
|
|
|
2012-04-25 11:29:40 +00:00
|
|
|
#include "ApplicationAccessible.h"
|
2013-04-25 03:48:26 +00:00
|
|
|
#include "ARIAMap.h"
|
2012-06-01 18:39:47 +00:00
|
|
|
#include "DocAccessible-inl.h"
|
2014-03-07 21:35:19 +00:00
|
|
|
#include "DocAccessibleChild.h"
|
2014-12-11 22:36:59 +00:00
|
|
|
#include "DocAccessibleParent.h"
|
2010-06-08 16:39:58 +00:00
|
|
|
#include "nsAccessibilityService.h"
|
2014-12-11 22:36:59 +00:00
|
|
|
#include "Platform.h"
|
2012-05-04 06:09:22 +00:00
|
|
|
#include "RootAccessibleWrap.h"
|
2014-10-22 00:49:28 +00:00
|
|
|
#include "xpcAccessibleDocument.h"
|
2010-06-08 16:39:58 +00:00
|
|
|
|
2012-10-04 09:57:09 +00:00
|
|
|
#ifdef A11Y_LOG
|
2012-05-23 09:21:40 +00:00
|
|
|
#include "Logging.h"
|
|
|
|
#endif
|
|
|
|
|
2014-03-17 06:56:53 +00:00
|
|
|
#include "mozilla/EventListenerManager.h"
|
2014-03-05 00:37:43 +00:00
|
|
|
#include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent()
|
2010-06-08 16:39:58 +00:00
|
|
|
#include "nsCURILoader.h"
|
|
|
|
#include "nsDocShellLoadTypes.h"
|
|
|
|
#include "nsIChannel.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMWindow.h"
|
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
|
|
|
#include "nsIWebNavigation.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
2013-09-10 22:18:59 +00:00
|
|
|
#include "nsIWebProgress.h"
|
|
|
|
#include "nsCoreUtils.h"
|
2014-03-07 21:35:19 +00:00
|
|
|
#include "nsXULAppAPI.h"
|
2015-05-21 17:04:58 +00:00
|
|
|
#include "mozilla/dom/TabChild.h"
|
2010-06-08 16:39:58 +00:00
|
|
|
|
2012-12-16 01:26:05 +00:00
|
|
|
using namespace mozilla;
|
2011-07-27 12:43:01 +00:00
|
|
|
using namespace mozilla::a11y;
|
2013-04-19 22:18:33 +00:00
|
|
|
using namespace mozilla::dom;
|
2011-07-27 12:43:01 +00:00
|
|
|
|
2014-12-09 01:08:15 +00:00
|
|
|
StaticAutoPtr<nsTArray<DocAccessibleParent*>> DocManager::sRemoteDocuments;
|
|
|
|
|
2010-06-08 16:39:58 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-11-20 14:15:32 +00:00
|
|
|
// DocManager
|
2010-06-08 16:39:58 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-09-02 08:41:57 +00:00
|
|
|
DocManager::DocManager()
|
2014-10-22 00:49:28 +00:00
|
|
|
: mDocAccessibleCache(2), mXPCDocumentCache(0)
|
2013-09-02 08:41:57 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-06-08 16:39:58 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-11-20 14:15:32 +00:00
|
|
|
// DocManager public
|
2010-06-08 16:39:58 +00:00
|
|
|
|
2012-05-27 09:01:40 +00:00
|
|
|
DocAccessible*
|
2012-11-20 14:15:32 +00:00
|
|
|
DocManager::GetDocAccessible(nsIDocument* aDocument)
|
2010-06-08 16:39:58 +00:00
|
|
|
{
|
|
|
|
if (!aDocument)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-06-08 16:39:58 +00:00
|
|
|
|
2010-08-06 07:03:32 +00:00
|
|
|
// Ensure CacheChildren is called before we query cache.
|
2012-09-10 13:20:26 +00:00
|
|
|
ApplicationAcc()->EnsureChildren();
|
2010-08-06 07:03:32 +00:00
|
|
|
|
2012-11-02 23:57:58 +00:00
|
|
|
DocAccessible* docAcc = GetExistingDocAccessible(aDocument);
|
2010-06-08 16:39:58 +00:00
|
|
|
if (docAcc)
|
|
|
|
return docAcc;
|
|
|
|
|
|
|
|
return CreateDocOrRootAccessible(aDocument);
|
|
|
|
}
|
|
|
|
|
2012-05-29 01:18:45 +00:00
|
|
|
Accessible*
|
2012-11-20 14:15:32 +00:00
|
|
|
DocManager::FindAccessibleInCache(nsINode* aNode) const
|
2010-06-08 16:39:58 +00:00
|
|
|
{
|
|
|
|
nsSearchAccessibleInCacheArg arg;
|
2010-10-21 04:16:10 +00:00
|
|
|
arg.mNode = aNode;
|
2010-06-08 16:39:58 +00:00
|
|
|
|
|
|
|
mDocAccessibleCache.EnumerateRead(SearchAccessibleInDocCache,
|
|
|
|
static_cast<void*>(&arg));
|
|
|
|
|
|
|
|
return arg.mAccessible;
|
|
|
|
}
|
|
|
|
|
2014-10-22 00:49:28 +00:00
|
|
|
void
|
|
|
|
DocManager::NotifyOfDocumentShutdown(DocAccessible* aDocument,
|
|
|
|
nsIDocument* aDOMDocument)
|
|
|
|
{
|
|
|
|
xpcAccessibleDocument* xpcDoc = mXPCDocumentCache.GetWeak(aDocument);
|
|
|
|
if (xpcDoc) {
|
|
|
|
xpcDoc->Shutdown();
|
|
|
|
mXPCDocumentCache.Remove(aDocument);
|
|
|
|
}
|
|
|
|
|
|
|
|
mDocAccessibleCache.Remove(aDOMDocument);
|
|
|
|
RemoveListeners(aDOMDocument);
|
|
|
|
}
|
|
|
|
|
|
|
|
xpcAccessibleDocument*
|
|
|
|
DocManager::GetXPCDocument(DocAccessible* aDocument)
|
|
|
|
{
|
|
|
|
if (!aDocument)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
xpcAccessibleDocument* xpcDoc = mXPCDocumentCache.GetWeak(aDocument);
|
|
|
|
if (!xpcDoc) {
|
|
|
|
xpcDoc = new xpcAccessibleDocument(aDocument);
|
|
|
|
mXPCDocumentCache.Put(aDocument, xpcDoc);
|
|
|
|
}
|
|
|
|
return xpcDoc;
|
|
|
|
}
|
|
|
|
|
2011-10-06 02:10:30 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool
|
2012-11-20 14:15:32 +00:00
|
|
|
DocManager::IsProcessingRefreshDriverNotification() const
|
2011-10-06 02:10:30 +00:00
|
|
|
{
|
|
|
|
bool isDocRefreshing = false;
|
|
|
|
mDocAccessibleCache.EnumerateRead(SearchIfDocIsRefreshing,
|
|
|
|
static_cast<void*>(&isDocRefreshing));
|
|
|
|
|
|
|
|
return isDocRefreshing;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-06-18 02:44:09 +00:00
|
|
|
|
2010-06-08 16:39:58 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-11-20 14:15:32 +00:00
|
|
|
// DocManager protected
|
2010-06-08 16:39:58 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2012-11-20 14:15:32 +00:00
|
|
|
DocManager::Init()
|
2010-06-08 16:39:58 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIWebProgress> progress =
|
|
|
|
do_GetService(NS_DOCUMENTLOADER_SERVICE_CONTRACTID);
|
|
|
|
|
|
|
|
if (!progress)
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-06-08 16:39:58 +00:00
|
|
|
|
|
|
|
progress->AddProgressListener(static_cast<nsIWebProgressListener*>(this),
|
|
|
|
nsIWebProgress::NOTIFY_STATE_DOCUMENT);
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2010-06-08 16:39:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-11-20 14:15:32 +00:00
|
|
|
DocManager::Shutdown()
|
2010-06-08 16:39:58 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIWebProgress> progress =
|
|
|
|
do_GetService(NS_DOCUMENTLOADER_SERVICE_CONTRACTID);
|
|
|
|
|
|
|
|
if (progress)
|
|
|
|
progress->RemoveProgressListener(static_cast<nsIWebProgressListener*>(this));
|
|
|
|
|
|
|
|
ClearDocCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsISupports
|
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(DocManager,
|
|
|
|
nsIWebProgressListener,
|
|
|
|
nsIDOMEventListener,
|
|
|
|
nsISupportsWeakReference)
|
2010-06-08 16:39:58 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIWebProgressListener
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-11-20 14:15:32 +00:00
|
|
|
DocManager::OnStateChange(nsIWebProgress* aWebProgress,
|
|
|
|
nsIRequest* aRequest, uint32_t aStateFlags,
|
|
|
|
nsresult aStatus)
|
2010-06-08 16:39:58 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aStateFlags & STATE_IS_DOCUMENT, "Other notifications excluded");
|
|
|
|
|
|
|
|
if (nsAccessibilityService::IsShutdown() || !aWebProgress ||
|
|
|
|
(aStateFlags & (STATE_START | STATE_STOP)) == 0)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMWindow> DOMWindow;
|
|
|
|
aWebProgress->GetDOMWindow(getter_AddRefs(DOMWindow));
|
|
|
|
NS_ENSURE_STATE(DOMWindow);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> DOMDocument;
|
|
|
|
DOMWindow->GetDocument(getter_AddRefs(DOMDocument));
|
|
|
|
NS_ENSURE_STATE(DOMDocument);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> document(do_QueryInterface(DOMDocument));
|
|
|
|
|
|
|
|
// Document was loaded.
|
|
|
|
if (aStateFlags & STATE_STOP) {
|
2012-10-04 09:57:09 +00:00
|
|
|
#ifdef A11Y_LOG
|
2012-05-23 09:21:40 +00:00
|
|
|
if (logging::IsEnabled(logging::eDocLoad))
|
|
|
|
logging::DocLoad("document loaded", aWebProgress, aRequest, aStateFlags);
|
|
|
|
#endif
|
2010-06-08 16:39:58 +00:00
|
|
|
|
|
|
|
// Figure out an event type to notify the document has been loaded.
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t eventType = nsIAccessibleEvent::EVENT_DOCUMENT_LOAD_STOPPED;
|
2010-06-08 16:39:58 +00:00
|
|
|
|
|
|
|
// Some XUL documents get start state and then stop state with failure
|
|
|
|
// status when everything is ok. Fire document load complete event in this
|
|
|
|
// case.
|
|
|
|
if (NS_SUCCEEDED(aStatus) || !nsCoreUtils::IsContentDocument(document))
|
|
|
|
eventType = nsIAccessibleEvent::EVENT_DOCUMENT_LOAD_COMPLETE;
|
|
|
|
|
|
|
|
// If end consumer has been retargeted for loaded content then do not fire
|
|
|
|
// any event because it means no new document has been loaded, for example,
|
|
|
|
// it happens when user clicks on file link.
|
|
|
|
if (aRequest) {
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t loadFlags = 0;
|
2010-06-08 16:39:58 +00:00
|
|
|
aRequest->GetLoadFlags(&loadFlags);
|
|
|
|
if (loadFlags & nsIChannel::LOAD_RETARGETED_DOCUMENT_URI)
|
|
|
|
eventType = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
HandleDOMDocumentLoad(document, eventType);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Document loading was started.
|
2012-10-04 09:57:09 +00:00
|
|
|
#ifdef A11Y_LOG
|
2012-05-23 09:21:40 +00:00
|
|
|
if (logging::IsEnabled(logging::eDocLoad))
|
|
|
|
logging::DocLoad("start document loading", aWebProgress, aRequest, aStateFlags);
|
|
|
|
#endif
|
2010-06-08 16:39:58 +00:00
|
|
|
|
2012-11-02 23:57:58 +00:00
|
|
|
DocAccessible* docAcc = GetExistingDocAccessible(document);
|
2010-06-08 16:39:58 +00:00
|
|
|
if (!docAcc)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWebNavigation> webNav(do_GetInterface(DOMWindow));
|
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(webNav));
|
|
|
|
NS_ENSURE_STATE(docShell);
|
|
|
|
|
2011-08-08 07:55:36 +00:00
|
|
|
bool isReloading = false;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t loadType;
|
2010-06-08 16:39:58 +00:00
|
|
|
docShell->GetLoadType(&loadType);
|
|
|
|
if (loadType == LOAD_RELOAD_NORMAL ||
|
|
|
|
loadType == LOAD_RELOAD_BYPASS_CACHE ||
|
|
|
|
loadType == LOAD_RELOAD_BYPASS_PROXY ||
|
2013-01-30 08:04:34 +00:00
|
|
|
loadType == LOAD_RELOAD_BYPASS_PROXY_AND_CACHE ||
|
|
|
|
loadType == LOAD_RELOAD_ALLOW_MIXED_CONTENT) {
|
2011-08-08 07:55:36 +00:00
|
|
|
isReloading = true;
|
2010-06-08 16:39:58 +00:00
|
|
|
}
|
|
|
|
|
2011-08-08 07:55:36 +00:00
|
|
|
docAcc->NotifyOfLoading(isReloading);
|
2010-06-08 16:39:58 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-11-20 14:15:32 +00:00
|
|
|
DocManager::OnProgressChange(nsIWebProgress* aWebProgress,
|
|
|
|
nsIRequest* aRequest,
|
|
|
|
int32_t aCurSelfProgress,
|
|
|
|
int32_t aMaxSelfProgress,
|
|
|
|
int32_t aCurTotalProgress,
|
|
|
|
int32_t aMaxTotalProgress)
|
2010-06-08 16:39:58 +00:00
|
|
|
{
|
|
|
|
NS_NOTREACHED("notification excluded in AddProgressListener(...)");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-11-20 14:15:32 +00:00
|
|
|
DocManager::OnLocationChange(nsIWebProgress* aWebProgress,
|
|
|
|
nsIRequest* aRequest, nsIURI* aLocation,
|
|
|
|
uint32_t aFlags)
|
2010-06-08 16:39:58 +00:00
|
|
|
{
|
|
|
|
NS_NOTREACHED("notification excluded in AddProgressListener(...)");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-11-20 14:15:32 +00:00
|
|
|
DocManager::OnStatusChange(nsIWebProgress* aWebProgress,
|
|
|
|
nsIRequest* aRequest, nsresult aStatus,
|
2014-01-04 15:02:17 +00:00
|
|
|
const char16_t* aMessage)
|
2010-06-08 16:39:58 +00:00
|
|
|
{
|
|
|
|
NS_NOTREACHED("notification excluded in AddProgressListener(...)");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-11-20 14:15:32 +00:00
|
|
|
DocManager::OnSecurityChange(nsIWebProgress* aWebProgress,
|
|
|
|
nsIRequest* aRequest,
|
|
|
|
uint32_t aState)
|
2010-06-08 16:39:58 +00:00
|
|
|
{
|
|
|
|
NS_NOTREACHED("notification excluded in AddProgressListener(...)");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIDOMEventListener
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-11-20 14:15:32 +00:00
|
|
|
DocManager::HandleEvent(nsIDOMEvent* aEvent)
|
2010-06-08 16:39:58 +00:00
|
|
|
{
|
|
|
|
nsAutoString type;
|
|
|
|
aEvent->GetType(type);
|
|
|
|
|
2013-04-19 22:18:32 +00:00
|
|
|
nsCOMPtr<nsIDocument> document =
|
|
|
|
do_QueryInterface(aEvent->InternalDOMEvent()->GetTarget());
|
2010-06-08 16:39:58 +00:00
|
|
|
NS_ASSERTION(document, "pagehide or DOMContentLoaded for non document!");
|
|
|
|
if (!document)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
if (type.EqualsLiteral("pagehide")) {
|
|
|
|
// 'pagehide' event is registered on every DOM document we create an
|
|
|
|
// accessible for, process the event for the target. This document
|
|
|
|
// accessible and all its sub document accessible are shutdown as result of
|
|
|
|
// processing.
|
|
|
|
|
2012-10-04 09:57:09 +00:00
|
|
|
#ifdef A11Y_LOG
|
2012-05-23 09:21:40 +00:00
|
|
|
if (logging::IsEnabled(logging::eDocDestroy))
|
|
|
|
logging::DocDestroy("received 'pagehide' event", document);
|
|
|
|
#endif
|
2010-06-08 16:39:58 +00:00
|
|
|
|
|
|
|
// Shutdown this one and sub document accessibles.
|
2010-10-28 09:34:26 +00:00
|
|
|
|
|
|
|
// We're allowed to not remove listeners when accessible document is
|
|
|
|
// shutdown since we don't keep strong reference on chrome event target and
|
|
|
|
// listeners are removed automatically when chrome event target goes away.
|
2012-11-02 23:57:58 +00:00
|
|
|
DocAccessible* docAccessible = GetExistingDocAccessible(document);
|
2010-10-28 09:34:26 +00:00
|
|
|
if (docAccessible)
|
|
|
|
docAccessible->Shutdown();
|
|
|
|
|
2010-06-08 16:39:58 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX: handle error pages loading separately since they get neither
|
|
|
|
// webprogress notifications nor 'pageshow' event.
|
|
|
|
if (type.EqualsLiteral("DOMContentLoaded") &&
|
|
|
|
nsCoreUtils::IsErrorPage(document)) {
|
2012-10-04 09:57:09 +00:00
|
|
|
#ifdef A11Y_LOG
|
2012-05-23 09:21:40 +00:00
|
|
|
if (logging::IsEnabled(logging::eDocLoad))
|
|
|
|
logging::DocLoad("handled 'DOMContentLoaded' event", document);
|
|
|
|
#endif
|
|
|
|
|
2010-06-08 16:39:58 +00:00
|
|
|
HandleDOMDocumentLoad(document,
|
2010-11-22 08:22:04 +00:00
|
|
|
nsIAccessibleEvent::EVENT_DOCUMENT_LOAD_COMPLETE);
|
2010-06-08 16:39:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-11-20 14:15:32 +00:00
|
|
|
// DocManager private
|
2010-06-08 16:39:58 +00:00
|
|
|
|
|
|
|
void
|
2012-11-20 14:15:32 +00:00
|
|
|
DocManager::HandleDOMDocumentLoad(nsIDocument* aDocument,
|
|
|
|
uint32_t aLoadEventType)
|
2010-06-08 16:39:58 +00:00
|
|
|
{
|
|
|
|
// Document accessible can be created before we were notified the DOM document
|
|
|
|
// was loaded completely. However if it's not created yet then create it.
|
2012-11-02 23:57:58 +00:00
|
|
|
DocAccessible* docAcc = GetExistingDocAccessible(aDocument);
|
2010-06-08 16:39:58 +00:00
|
|
|
if (!docAcc) {
|
|
|
|
docAcc = CreateDocOrRootAccessible(aDocument);
|
|
|
|
if (!docAcc)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-08 07:55:36 +00:00
|
|
|
docAcc->NotifyOfLoad(aLoadEventType);
|
2010-06-08 16:39:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-11-20 14:15:32 +00:00
|
|
|
DocManager::AddListeners(nsIDocument* aDocument,
|
|
|
|
bool aAddDOMContentLoadedListener)
|
2010-06-08 16:39:58 +00:00
|
|
|
{
|
2013-04-19 22:18:33 +00:00
|
|
|
nsPIDOMWindow* window = aDocument->GetWindow();
|
|
|
|
EventTarget* target = window->GetChromeEventHandler();
|
2014-03-17 06:56:53 +00:00
|
|
|
EventListenerManager* elm = target->GetOrCreateListenerManager();
|
2010-06-08 16:39:58 +00:00
|
|
|
elm->AddEventListenerByType(this, NS_LITERAL_STRING("pagehide"),
|
2014-03-17 06:56:52 +00:00
|
|
|
TrustedEventsAtCapture());
|
2010-06-08 16:39:58 +00:00
|
|
|
|
2012-10-04 09:57:09 +00:00
|
|
|
#ifdef A11Y_LOG
|
2012-05-23 09:21:40 +00:00
|
|
|
if (logging::IsEnabled(logging::eDocCreate))
|
|
|
|
logging::Text("added 'pagehide' listener");
|
|
|
|
#endif
|
2010-06-08 16:39:58 +00:00
|
|
|
|
|
|
|
if (aAddDOMContentLoadedListener) {
|
|
|
|
elm->AddEventListenerByType(this, NS_LITERAL_STRING("DOMContentLoaded"),
|
2014-03-17 06:56:52 +00:00
|
|
|
TrustedEventsAtCapture());
|
2012-10-04 09:57:09 +00:00
|
|
|
#ifdef A11Y_LOG
|
2012-05-23 09:21:40 +00:00
|
|
|
if (logging::IsEnabled(logging::eDocCreate))
|
|
|
|
logging::Text("added 'DOMContentLoaded' listener");
|
|
|
|
#endif
|
2010-06-08 16:39:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-05 14:56:34 +00:00
|
|
|
void
|
|
|
|
DocManager::RemoveListeners(nsIDocument* aDocument)
|
|
|
|
{
|
|
|
|
nsPIDOMWindow* window = aDocument->GetWindow();
|
2013-03-13 06:23:28 +00:00
|
|
|
if (!window)
|
|
|
|
return;
|
|
|
|
|
2013-04-19 22:18:33 +00:00
|
|
|
EventTarget* target = window->GetChromeEventHandler();
|
2013-06-25 06:22:00 +00:00
|
|
|
if (!target)
|
|
|
|
return;
|
|
|
|
|
2014-03-17 06:56:53 +00:00
|
|
|
EventListenerManager* elm = target->GetOrCreateListenerManager();
|
2013-03-05 14:56:34 +00:00
|
|
|
elm->RemoveEventListenerByType(this, NS_LITERAL_STRING("pagehide"),
|
2014-03-17 06:56:52 +00:00
|
|
|
TrustedEventsAtCapture());
|
2013-03-05 14:56:34 +00:00
|
|
|
|
|
|
|
elm->RemoveEventListenerByType(this, NS_LITERAL_STRING("DOMContentLoaded"),
|
2014-03-17 06:56:52 +00:00
|
|
|
TrustedEventsAtCapture());
|
2013-03-05 14:56:34 +00:00
|
|
|
}
|
|
|
|
|
2012-05-27 09:01:40 +00:00
|
|
|
DocAccessible*
|
2012-11-20 14:15:32 +00:00
|
|
|
DocManager::CreateDocOrRootAccessible(nsIDocument* aDocument)
|
2010-06-08 16:39:58 +00:00
|
|
|
{
|
2014-04-02 19:36:48 +00:00
|
|
|
// Ignore hiding, resource documents and documents without docshell.
|
|
|
|
if (!aDocument->IsVisibleConsideringAncestors() ||
|
2010-10-15 02:44:22 +00:00
|
|
|
aDocument->IsResourceDoc() || !aDocument->IsActive())
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-06-08 16:39:58 +00:00
|
|
|
|
2012-02-27 11:33:55 +00:00
|
|
|
// Ignore documents without presshell and not having root frame.
|
|
|
|
nsIPresShell* presShell = aDocument->GetShell();
|
2012-12-27 04:25:27 +00:00
|
|
|
if (!presShell || presShell->IsDestroying())
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-06-08 16:39:58 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isRootDoc = nsCoreUtils::IsRootDocument(aDocument);
|
2010-06-08 16:39:58 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
DocAccessible* parentDocAcc = nullptr;
|
2011-01-26 06:35:51 +00:00
|
|
|
if (!isRootDoc) {
|
2010-06-08 16:39:58 +00:00
|
|
|
// XXXaaronl: ideally we would traverse the presshell chain. Since there's
|
|
|
|
// no easy way to do that, we cheat and use the document hierarchy.
|
2011-01-26 06:35:51 +00:00
|
|
|
parentDocAcc = GetDocAccessible(aDocument->GetParentDocument());
|
|
|
|
NS_ASSERTION(parentDocAcc,
|
|
|
|
"Can't create an accessible for the document!");
|
|
|
|
if (!parentDocAcc)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-06-08 16:39:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// We only create root accessibles for the true root, otherwise create a
|
|
|
|
// doc accessible.
|
2012-10-31 02:25:17 +00:00
|
|
|
nsIContent *rootElm = nsCoreUtils::GetRoleContent(aDocument);
|
2012-05-27 09:01:40 +00:00
|
|
|
nsRefPtr<DocAccessible> docAcc = isRootDoc ?
|
2012-05-04 06:09:22 +00:00
|
|
|
new RootAccessibleWrap(aDocument, rootElm, presShell) :
|
2012-05-27 09:01:40 +00:00
|
|
|
new DocAccessibleWrap(aDocument, rootElm, presShell);
|
2010-06-08 16:39:58 +00:00
|
|
|
|
2010-11-12 19:00:55 +00:00
|
|
|
// Cache the document accessible into document cache.
|
2012-05-18 17:30:49 +00:00
|
|
|
mDocAccessibleCache.Put(aDocument, docAcc);
|
2010-06-08 16:39:58 +00:00
|
|
|
|
2012-11-20 03:54:41 +00:00
|
|
|
// Initialize the document accessible.
|
|
|
|
docAcc->Init();
|
2012-04-16 09:24:23 +00:00
|
|
|
docAcc->SetRoleMapEntry(aria::GetRoleMap(aDocument));
|
2010-06-08 16:39:58 +00:00
|
|
|
|
2011-01-26 06:35:51 +00:00
|
|
|
// Bind the document to the tree.
|
|
|
|
if (isRootDoc) {
|
2012-09-10 13:20:26 +00:00
|
|
|
if (!ApplicationAcc()->AppendChild(docAcc)) {
|
2011-01-26 06:35:51 +00:00
|
|
|
docAcc->Shutdown();
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2011-01-26 06:35:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fire reorder event to notify new accessible document has been attached to
|
2011-07-19 08:30:32 +00:00
|
|
|
// the tree. The reorder event is delivered after the document tree is
|
|
|
|
// constructed because event processing and tree construction are done by
|
|
|
|
// the same document.
|
2012-11-13 06:29:22 +00:00
|
|
|
// Note: don't use AccReorderEvent to avoid coalsecense and special reorder
|
|
|
|
// events processing.
|
2012-11-20 04:53:38 +00:00
|
|
|
docAcc->FireDelayedEvent(nsIAccessibleEvent::EVENT_REORDER,
|
|
|
|
ApplicationAcc());
|
2011-01-26 06:35:51 +00:00
|
|
|
|
2014-03-07 21:35:19 +00:00
|
|
|
if (IPCAccessibilityActive()) {
|
2015-07-06 12:15:37 +00:00
|
|
|
nsIDocShell* docShell = aDocument->GetDocShell();
|
|
|
|
if (docShell) {
|
|
|
|
nsCOMPtr<nsITabChild> tabChild = do_GetInterface(docShell);
|
2015-07-10 19:43:51 +00:00
|
|
|
|
|
|
|
// XXX We may need to handle the case that we don't have a tab child
|
|
|
|
// differently. It may be that this will cause us to fail to notify
|
|
|
|
// the parent process about important accessible documents.
|
|
|
|
if (tabChild) {
|
2015-07-30 23:03:16 +00:00
|
|
|
DocAccessibleChild* ipcDoc = new DocAccessibleChild(docAcc);
|
|
|
|
docAcc->SetIPCDoc(ipcDoc);
|
2015-07-10 19:43:51 +00:00
|
|
|
static_cast<TabChild*>(tabChild.get())->
|
|
|
|
SendPDocAccessibleConstructor(ipcDoc, nullptr, 0);
|
|
|
|
}
|
2015-07-06 12:15:37 +00:00
|
|
|
}
|
2014-03-07 21:35:19 +00:00
|
|
|
}
|
2011-01-26 06:35:51 +00:00
|
|
|
} else {
|
|
|
|
parentDocAcc->BindChildDocument(docAcc);
|
|
|
|
}
|
|
|
|
|
2012-10-04 09:57:09 +00:00
|
|
|
#ifdef A11Y_LOG
|
2012-05-23 09:21:40 +00:00
|
|
|
if (logging::IsEnabled(logging::eDocCreate)) {
|
|
|
|
logging::DocCreate("document creation finished", aDocument);
|
|
|
|
logging::Stack();
|
|
|
|
}
|
|
|
|
#endif
|
2010-06-08 16:39:58 +00:00
|
|
|
|
|
|
|
AddListeners(aDocument, isRootDoc);
|
|
|
|
return docAcc;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-11-20 14:15:32 +00:00
|
|
|
// DocManager static
|
2010-06-08 16:39:58 +00:00
|
|
|
|
|
|
|
PLDHashOperator
|
2012-11-20 14:15:32 +00:00
|
|
|
DocManager::GetFirstEntryInDocCache(const nsIDocument* aKey,
|
|
|
|
DocAccessible* aDocAccessible,
|
|
|
|
void* aUserArg)
|
2010-06-08 16:39:58 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aDocAccessible,
|
2010-12-02 16:07:14 +00:00
|
|
|
"No doc accessible for the object in doc accessible cache!");
|
2012-05-27 09:01:40 +00:00
|
|
|
*reinterpret_cast<DocAccessible**>(aUserArg) = aDocAccessible;
|
2010-06-08 16:39:58 +00:00
|
|
|
|
2010-12-02 16:07:14 +00:00
|
|
|
return PL_DHASH_STOP;
|
|
|
|
}
|
2010-06-08 16:39:58 +00:00
|
|
|
|
2010-12-02 16:07:14 +00:00
|
|
|
void
|
2012-11-20 14:15:32 +00:00
|
|
|
DocManager::ClearDocCache()
|
2010-12-02 16:07:14 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
DocAccessible* docAcc = nullptr;
|
2010-12-02 16:07:14 +00:00
|
|
|
while (mDocAccessibleCache.EnumerateRead(GetFirstEntryInDocCache, static_cast<void*>(&docAcc))) {
|
|
|
|
if (docAcc)
|
|
|
|
docAcc->Shutdown();
|
|
|
|
}
|
2010-06-08 16:39:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PLDHashOperator
|
2012-11-20 14:15:32 +00:00
|
|
|
DocManager::SearchAccessibleInDocCache(const nsIDocument* aKey,
|
|
|
|
DocAccessible* aDocAccessible,
|
|
|
|
void* aUserArg)
|
2010-06-08 16:39:58 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aDocAccessible,
|
|
|
|
"No doc accessible for the object in doc accessible cache!");
|
|
|
|
|
|
|
|
if (aDocAccessible) {
|
|
|
|
nsSearchAccessibleInCacheArg* arg =
|
|
|
|
static_cast<nsSearchAccessibleInCacheArg*>(aUserArg);
|
2011-01-28 04:37:08 +00:00
|
|
|
arg->mAccessible = aDocAccessible->GetAccessible(arg->mNode);
|
2010-06-12 04:04:35 +00:00
|
|
|
if (arg->mAccessible)
|
2010-06-08 16:39:58 +00:00
|
|
|
return PL_DHASH_STOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
2011-10-06 02:10:30 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
PLDHashOperator
|
2012-11-20 14:15:32 +00:00
|
|
|
DocManager::SearchIfDocIsRefreshing(const nsIDocument* aKey,
|
|
|
|
DocAccessible* aDocAccessible,
|
|
|
|
void* aUserArg)
|
2011-10-06 02:10:30 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aDocAccessible,
|
|
|
|
"No doc accessible for the object in doc accessible cache!");
|
|
|
|
|
|
|
|
if (aDocAccessible && aDocAccessible->mNotificationController &&
|
|
|
|
aDocAccessible->mNotificationController->IsUpdating()) {
|
|
|
|
*(static_cast<bool*>(aUserArg)) = true;
|
|
|
|
return PL_DHASH_STOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
#endif
|
2014-12-11 22:36:59 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
DocManager::RemoteDocAdded(DocAccessibleParent* aDoc)
|
|
|
|
{
|
|
|
|
if (!sRemoteDocuments) {
|
|
|
|
sRemoteDocuments = new nsTArray<DocAccessibleParent*>;
|
|
|
|
ClearOnShutdown(&sRemoteDocuments);
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(!sRemoteDocuments->Contains(aDoc),
|
|
|
|
"How did we already have the doc!");
|
|
|
|
sRemoteDocuments->AppendElement(aDoc);
|
2015-09-03 05:55:39 +00:00
|
|
|
ProxyCreated(aDoc, Interfaces::DOCUMENT | Interfaces::HYPERTEXT);
|
2014-12-11 22:36:59 +00:00
|
|
|
}
|