2015-10-20 03:52:43 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04: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 20:39:58 +04:00
|
|
|
|
2012-11-20 18:15:32 +04:00
|
|
|
#include "DocManager.h"
|
2010-06-08 20:39:58 +04:00
|
|
|
|
2012-04-25 15:29:40 +04:00
|
|
|
#include "ApplicationAccessible.h"
|
2013-04-25 07:48:26 +04:00
|
|
|
#include "ARIAMap.h"
|
2012-06-01 22:39:47 +04:00
|
|
|
#include "DocAccessible-inl.h"
|
2014-03-08 01:35:19 +04:00
|
|
|
#include "DocAccessibleChild.h"
|
2014-12-12 01:36:59 +03:00
|
|
|
#include "DocAccessibleParent.h"
|
2010-06-08 20:39:58 +04:00
|
|
|
#include "nsAccessibilityService.h"
|
2014-12-12 01:36:59 +03:00
|
|
|
#include "Platform.h"
|
2012-05-04 10:09:22 +04:00
|
|
|
#include "RootAccessibleWrap.h"
|
2014-10-22 04:49:28 +04:00
|
|
|
#include "xpcAccessibleDocument.h"
|
2010-06-08 20:39:58 +04:00
|
|
|
|
2012-10-04 13:57:09 +04:00
|
|
|
#ifdef A11Y_LOG
|
2012-05-23 13:21:40 +04:00
|
|
|
# include "Logging.h"
|
|
|
|
#endif
|
|
|
|
|
2018-12-17 04:27:58 +03:00
|
|
|
#include "mozilla/Components.h"
|
2014-03-17 10:56:53 +04:00
|
|
|
#include "mozilla/EventListenerManager.h"
|
2019-03-29 18:12:47 +03:00
|
|
|
#include "mozilla/PresShell.h"
|
2018-04-20 07:49:29 +03:00
|
|
|
#include "mozilla/dom/Event.h" // for Event
|
2018-05-07 17:19:00 +03:00
|
|
|
#include "nsContentUtils.h"
|
2010-06-08 20:39:58 +04:00
|
|
|
#include "nsDocShellLoadTypes.h"
|
|
|
|
#include "nsIChannel.h"
|
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
|
|
|
#include "nsIWebNavigation.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
2013-09-11 02:18:59 +04:00
|
|
|
#include "nsIWebProgress.h"
|
|
|
|
#include "nsCoreUtils.h"
|
2014-03-08 01:35:19 +04:00
|
|
|
#include "nsXULAppAPI.h"
|
2015-05-21 20:04:58 +03:00
|
|
|
#include "mozilla/dom/TabChild.h"
|
2010-06-08 20:39:58 +04:00
|
|
|
|
2012-12-16 05:26:05 +04:00
|
|
|
using namespace mozilla;
|
2011-07-27 16:43:01 +04:00
|
|
|
using namespace mozilla::a11y;
|
2013-04-20 02:18:33 +04:00
|
|
|
using namespace mozilla::dom;
|
2011-07-27 16:43:01 +04:00
|
|
|
|
2014-12-09 04:08:15 +03:00
|
|
|
StaticAutoPtr<nsTArray<DocAccessibleParent*>> DocManager::sRemoteDocuments;
|
2016-01-19 19:19:58 +03:00
|
|
|
nsRefPtrHashtable<nsPtrHashKey<const DocAccessibleParent>,
|
|
|
|
xpcAccessibleDocument>* DocManager::sRemoteXPCDocumentCache =
|
|
|
|
nullptr;
|
2014-12-09 04:08:15 +03:00
|
|
|
|
2010-06-08 20:39:58 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-11-20 18:15:32 +04:00
|
|
|
// DocManager
|
2010-06-08 20:39:58 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-10-22 04:49:28 +04:00
|
|
|
DocManager::DocManager() : mDocAccessibleCache(2), mXPCDocumentCache(0) {}
|
2013-09-02 12:41:57 +04:00
|
|
|
|
2010-06-08 20:39:58 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-11-20 18:15:32 +04:00
|
|
|
// DocManager public
|
2010-06-08 20:39:58 +04:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
DocAccessible* DocManager::GetDocAccessible(Document* aDocument) {
|
2010-06-08 20:39:58 +04:00
|
|
|
if (!aDocument) return nullptr;
|
|
|
|
|
2012-11-03 03:57:58 +04:00
|
|
|
DocAccessible* docAcc = GetExistingDocAccessible(aDocument);
|
2010-06-08 20:39:58 +04:00
|
|
|
if (docAcc) return docAcc;
|
|
|
|
|
|
|
|
return CreateDocOrRootAccessible(aDocument);
|
|
|
|
}
|
|
|
|
|
2012-11-20 18:15:32 +04:00
|
|
|
Accessible* DocManager::FindAccessibleInCache(nsINode* aNode) const {
|
2015-10-20 03:52:43 +03:00
|
|
|
for (auto iter = mDocAccessibleCache.ConstIter(); !iter.Done(); iter.Next()) {
|
|
|
|
DocAccessible* docAccessible = iter.UserData();
|
|
|
|
NS_ASSERTION(docAccessible,
|
|
|
|
"No doc accessible for the object in doc accessible cache!");
|
|
|
|
|
|
|
|
if (docAccessible) {
|
|
|
|
Accessible* accessible = docAccessible->GetAccessible(aNode);
|
|
|
|
if (accessible) {
|
|
|
|
return accessible;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
2010-06-08 20:39:58 +04:00
|
|
|
}
|
|
|
|
|
2016-11-19 07:29:10 +03:00
|
|
|
void DocManager::RemoveFromXPCDocumentCache(DocAccessible* aDocument) {
|
|
|
|
xpcAccessibleDocument* xpcDoc = mXPCDocumentCache.GetWeak(aDocument);
|
|
|
|
if (xpcDoc) {
|
|
|
|
xpcDoc->Shutdown();
|
|
|
|
mXPCDocumentCache.Remove(aDocument);
|
|
|
|
|
2017-06-21 22:55:40 +03:00
|
|
|
if (!HasXPCDocuments()) {
|
|
|
|
MaybeShutdownAccService(nsAccessibilityService::eXPCOM);
|
|
|
|
}
|
2016-11-19 07:29:10 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-22 04:49:28 +04:00
|
|
|
void DocManager::NotifyOfDocumentShutdown(DocAccessible* aDocument,
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* aDOMDocument) {
|
2016-08-08 18:35:56 +03:00
|
|
|
// We need to remove listeners in both cases, when document is being shutdown
|
|
|
|
// or when accessibility service is being shut down as well.
|
|
|
|
RemoveListeners(aDOMDocument);
|
|
|
|
|
|
|
|
// Document will already be removed when accessibility service is shutting
|
|
|
|
// down so we do not need to remove it twice.
|
|
|
|
if (nsAccessibilityService::IsShutdown()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-19 07:29:10 +03:00
|
|
|
RemoveFromXPCDocumentCache(aDocument);
|
2014-10-22 04:49:28 +04:00
|
|
|
mDocAccessibleCache.Remove(aDOMDocument);
|
|
|
|
}
|
|
|
|
|
2016-11-19 07:29:10 +03:00
|
|
|
void DocManager::RemoveFromRemoteXPCDocumentCache(DocAccessibleParent* aDoc) {
|
2016-01-19 19:19:58 +03:00
|
|
|
xpcAccessibleDocument* doc = GetCachedXPCDocument(aDoc);
|
|
|
|
if (doc) {
|
|
|
|
doc->Shutdown();
|
|
|
|
sRemoteXPCDocumentCache->Remove(aDoc);
|
|
|
|
}
|
2016-11-19 07:29:10 +03:00
|
|
|
|
|
|
|
if (sRemoteXPCDocumentCache && sRemoteXPCDocumentCache->Count() == 0) {
|
|
|
|
MaybeShutdownAccService(nsAccessibilityService::eXPCOM);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DocManager::NotifyOfRemoteDocShutdown(DocAccessibleParent* aDoc) {
|
|
|
|
RemoveFromRemoteXPCDocumentCache(aDoc);
|
2016-01-19 19:19:58 +03:00
|
|
|
}
|
|
|
|
|
2014-10-22 04:49:28 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-01-19 19:19:58 +03:00
|
|
|
xpcAccessibleDocument* DocManager::GetXPCDocument(DocAccessibleParent* aDoc) {
|
|
|
|
xpcAccessibleDocument* doc = GetCachedXPCDocument(aDoc);
|
|
|
|
if (doc) {
|
|
|
|
return doc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!sRemoteXPCDocumentCache) {
|
|
|
|
sRemoteXPCDocumentCache =
|
|
|
|
new nsRefPtrHashtable<nsPtrHashKey<const DocAccessibleParent>,
|
|
|
|
xpcAccessibleDocument>;
|
|
|
|
}
|
|
|
|
|
|
|
|
doc = new xpcAccessibleDocument(aDoc,
|
|
|
|
Interfaces::DOCUMENT | Interfaces::HYPERTEXT);
|
|
|
|
sRemoteXPCDocumentCache->Put(aDoc, doc);
|
|
|
|
|
|
|
|
return doc;
|
|
|
|
}
|
|
|
|
|
2011-10-06 06:10:30 +04:00
|
|
|
#ifdef DEBUG
|
2012-11-20 18:15:32 +04:00
|
|
|
bool DocManager::IsProcessingRefreshDriverNotification() const {
|
2015-10-20 03:52:43 +03:00
|
|
|
for (auto iter = mDocAccessibleCache.ConstIter(); !iter.Done(); iter.Next()) {
|
|
|
|
DocAccessible* docAccessible = iter.UserData();
|
|
|
|
NS_ASSERTION(docAccessible,
|
|
|
|
"No doc accessible for the object in doc accessible cache!");
|
|
|
|
|
|
|
|
if (docAccessible && docAccessible->mNotificationController &&
|
|
|
|
docAccessible->mNotificationController->IsUpdating()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2011-10-06 06:10:30 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-06-08 20:39:58 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-11-20 18:15:32 +04:00
|
|
|
// DocManager protected
|
2010-06-08 20:39:58 +04:00
|
|
|
|
2012-11-20 18:15:32 +04:00
|
|
|
bool DocManager::Init() {
|
2018-12-17 04:27:58 +03:00
|
|
|
nsCOMPtr<nsIWebProgress> progress = components::DocLoader::Service();
|
2010-06-08 20:39:58 +04:00
|
|
|
|
|
|
|
if (!progress) return false;
|
|
|
|
|
|
|
|
progress->AddProgressListener(static_cast<nsIWebProgressListener*>(this),
|
|
|
|
nsIWebProgress::NOTIFY_STATE_DOCUMENT);
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-06-08 20:39:58 +04:00
|
|
|
}
|
|
|
|
|
2012-11-20 18:15:32 +04:00
|
|
|
void DocManager::Shutdown() {
|
2018-12-17 04:27:58 +03:00
|
|
|
nsCOMPtr<nsIWebProgress> progress = components::DocLoader::Service();
|
2010-06-08 20:39:58 +04:00
|
|
|
|
|
|
|
if (progress)
|
|
|
|
progress->RemoveProgressListener(
|
|
|
|
static_cast<nsIWebProgressListener*>(this));
|
|
|
|
|
|
|
|
ClearDocCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsISupports
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(DocManager, nsIWebProgressListener, nsIDOMEventListener,
|
|
|
|
nsISupportsWeakReference)
|
2010-06-08 20:39:58 +04:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIWebProgressListener
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-11-20 18:15:32 +04:00
|
|
|
DocManager::OnStateChange(nsIWebProgress* aWebProgress, nsIRequest* aRequest,
|
|
|
|
uint32_t aStateFlags, nsresult aStatus) {
|
2010-06-08 20:39:58 +04:00
|
|
|
NS_ASSERTION(aStateFlags & STATE_IS_DOCUMENT, "Other notifications excluded");
|
|
|
|
|
|
|
|
if (nsAccessibilityService::IsShutdown() || !aWebProgress ||
|
|
|
|
(aStateFlags & (STATE_START | STATE_STOP)) == 0)
|
|
|
|
return NS_OK;
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<mozIDOMWindowProxy> DOMWindow;
|
2010-06-08 20:39:58 +04:00
|
|
|
aWebProgress->GetDOMWindow(getter_AddRefs(DOMWindow));
|
|
|
|
NS_ENSURE_STATE(DOMWindow);
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowOuter* piWindow = nsPIDOMWindowOuter::From(DOMWindow);
|
2015-10-27 00:37:32 +03:00
|
|
|
MOZ_ASSERT(piWindow);
|
2010-06-08 20:39:58 +04:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
nsCOMPtr<Document> document = piWindow->GetDoc();
|
2015-10-27 00:37:32 +03:00
|
|
|
NS_ENSURE_STATE(document);
|
2010-06-08 20:39:58 +04:00
|
|
|
|
|
|
|
// Document was loaded.
|
|
|
|
if (aStateFlags & STATE_STOP) {
|
2012-10-04 13:57:09 +04:00
|
|
|
#ifdef A11Y_LOG
|
2012-05-23 13:21:40 +04:00
|
|
|
if (logging::IsEnabled(logging::eDocLoad))
|
|
|
|
logging::DocLoad("document loaded", aWebProgress, aRequest, aStateFlags);
|
|
|
|
#endif
|
2010-06-08 20:39:58 +04:00
|
|
|
|
|
|
|
// Figure out an event type to notify the document has been loaded.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t eventType = nsIAccessibleEvent::EVENT_DOCUMENT_LOAD_STOPPED;
|
2010-06-08 20:39:58 +04: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 19:56:38 +04:00
|
|
|
uint32_t loadFlags = 0;
|
2010-06-08 20:39:58 +04: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 13:57:09 +04:00
|
|
|
#ifdef A11Y_LOG
|
2012-05-23 13:21:40 +04:00
|
|
|
if (logging::IsEnabled(logging::eDocLoad))
|
|
|
|
logging::DocLoad("start document loading", aWebProgress, aRequest,
|
|
|
|
aStateFlags);
|
|
|
|
#endif
|
2010-06-08 20:39:58 +04:00
|
|
|
|
2012-11-03 03:57:58 +04:00
|
|
|
DocAccessible* docAcc = GetExistingDocAccessible(document);
|
2010-06-08 20:39:58 +04: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 11:55:36 +04:00
|
|
|
bool isReloading = false;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t loadType;
|
2010-06-08 20:39:58 +04:00
|
|
|
docShell->GetLoadType(&loadType);
|
|
|
|
if (loadType == LOAD_RELOAD_NORMAL || loadType == LOAD_RELOAD_BYPASS_CACHE ||
|
|
|
|
loadType == LOAD_RELOAD_BYPASS_PROXY ||
|
2013-01-30 12:04:34 +04:00
|
|
|
loadType == LOAD_RELOAD_BYPASS_PROXY_AND_CACHE ||
|
|
|
|
loadType == LOAD_RELOAD_ALLOW_MIXED_CONTENT) {
|
2011-08-08 11:55:36 +04:00
|
|
|
isReloading = true;
|
2010-06-08 20:39:58 +04:00
|
|
|
}
|
|
|
|
|
2011-08-08 11:55:36 +04:00
|
|
|
docAcc->NotifyOfLoading(isReloading);
|
2010-06-08 20:39:58 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-11-20 18:15:32 +04:00
|
|
|
DocManager::OnProgressChange(nsIWebProgress* aWebProgress, nsIRequest* aRequest,
|
|
|
|
int32_t aCurSelfProgress, int32_t aMaxSelfProgress,
|
|
|
|
int32_t aCurTotalProgress,
|
|
|
|
int32_t aMaxTotalProgress) {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("notification excluded in AddProgressListener(...)");
|
2010-06-08 20:39:58 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-11-20 18:15:32 +04:00
|
|
|
DocManager::OnLocationChange(nsIWebProgress* aWebProgress, nsIRequest* aRequest,
|
|
|
|
nsIURI* aLocation, uint32_t aFlags) {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("notification excluded in AddProgressListener(...)");
|
2010-06-08 20:39:58 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-11-20 18:15:32 +04:00
|
|
|
DocManager::OnStatusChange(nsIWebProgress* aWebProgress, nsIRequest* aRequest,
|
2014-01-04 19:02:17 +04:00
|
|
|
nsresult aStatus, const char16_t* aMessage) {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("notification excluded in AddProgressListener(...)");
|
2010-06-08 20:39:58 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-11-20 18:15:32 +04:00
|
|
|
DocManager::OnSecurityChange(nsIWebProgress* aWebProgress, nsIRequest* aRequest,
|
2018-11-29 18:46:08 +03:00
|
|
|
uint32_t aState) {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("notification excluded in AddProgressListener(...)");
|
2010-06-08 20:39:58 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-01-07 01:45:57 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DocManager::OnContentBlockingEvent(nsIWebProgress* aWebProgress,
|
|
|
|
nsIRequest* aRequest, uint32_t aEvent) {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("notification excluded in AddProgressListener(...)");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-06-08 20:39:58 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIDOMEventListener
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-04-20 07:49:29 +03:00
|
|
|
DocManager::HandleEvent(Event* aEvent) {
|
2010-06-08 20:39:58 +04:00
|
|
|
nsAutoString type;
|
|
|
|
aEvent->GetType(type);
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
nsCOMPtr<Document> document = do_QueryInterface(aEvent->GetTarget());
|
2010-06-08 20:39:58 +04: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 13:57:09 +04:00
|
|
|
#ifdef A11Y_LOG
|
2012-05-23 13:21:40 +04:00
|
|
|
if (logging::IsEnabled(logging::eDocDestroy))
|
|
|
|
logging::DocDestroy("received 'pagehide' event", document);
|
|
|
|
#endif
|
2010-06-08 20:39:58 +04:00
|
|
|
|
|
|
|
// Shutdown this one and sub document accessibles.
|
2010-10-28 13:34:26 +04: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-03 03:57:58 +04:00
|
|
|
DocAccessible* docAccessible = GetExistingDocAccessible(document);
|
2010-10-28 13:34:26 +04:00
|
|
|
if (docAccessible) docAccessible->Shutdown();
|
|
|
|
|
2010-06-08 20:39:58 +04: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 13:57:09 +04:00
|
|
|
#ifdef A11Y_LOG
|
2012-05-23 13:21:40 +04:00
|
|
|
if (logging::IsEnabled(logging::eDocLoad))
|
|
|
|
logging::DocLoad("handled 'DOMContentLoaded' event", document);
|
|
|
|
#endif
|
|
|
|
|
2010-06-08 20:39:58 +04:00
|
|
|
HandleDOMDocumentLoad(document,
|
2010-11-22 11:22:04 +03:00
|
|
|
nsIAccessibleEvent::EVENT_DOCUMENT_LOAD_COMPLETE);
|
2010-06-08 20:39:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-11-20 18:15:32 +04:00
|
|
|
// DocManager private
|
2010-06-08 20:39:58 +04:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
void DocManager::HandleDOMDocumentLoad(Document* aDocument,
|
2012-11-20 18:15:32 +04:00
|
|
|
uint32_t aLoadEventType) {
|
2010-06-08 20:39:58 +04: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-03 03:57:58 +04:00
|
|
|
DocAccessible* docAcc = GetExistingDocAccessible(aDocument);
|
2010-06-08 20:39:58 +04:00
|
|
|
if (!docAcc) {
|
|
|
|
docAcc = CreateDocOrRootAccessible(aDocument);
|
|
|
|
if (!docAcc) return;
|
|
|
|
}
|
|
|
|
|
2011-08-08 11:55:36 +04:00
|
|
|
docAcc->NotifyOfLoad(aLoadEventType);
|
2010-06-08 20:39:58 +04:00
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
void DocManager::AddListeners(Document* aDocument,
|
2012-11-20 18:15:32 +04:00
|
|
|
bool aAddDOMContentLoadedListener) {
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowOuter* window = aDocument->GetWindow();
|
2013-04-20 02:18:33 +04:00
|
|
|
EventTarget* target = window->GetChromeEventHandler();
|
2014-03-17 10:56:53 +04:00
|
|
|
EventListenerManager* elm = target->GetOrCreateListenerManager();
|
2010-06-08 20:39:58 +04:00
|
|
|
elm->AddEventListenerByType(this, NS_LITERAL_STRING("pagehide"),
|
2014-03-17 10:56:52 +04:00
|
|
|
TrustedEventsAtCapture());
|
2010-06-08 20:39:58 +04:00
|
|
|
|
2012-10-04 13:57:09 +04:00
|
|
|
#ifdef A11Y_LOG
|
2012-05-23 13:21:40 +04:00
|
|
|
if (logging::IsEnabled(logging::eDocCreate))
|
|
|
|
logging::Text("added 'pagehide' listener");
|
|
|
|
#endif
|
2010-06-08 20:39:58 +04:00
|
|
|
|
|
|
|
if (aAddDOMContentLoadedListener) {
|
|
|
|
elm->AddEventListenerByType(this, NS_LITERAL_STRING("DOMContentLoaded"),
|
2014-03-17 10:56:52 +04:00
|
|
|
TrustedEventsAtCapture());
|
2012-10-04 13:57:09 +04:00
|
|
|
#ifdef A11Y_LOG
|
2012-05-23 13:21:40 +04:00
|
|
|
if (logging::IsEnabled(logging::eDocCreate))
|
|
|
|
logging::Text("added 'DOMContentLoaded' listener");
|
|
|
|
#endif
|
2010-06-08 20:39:58 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
void DocManager::RemoveListeners(Document* aDocument) {
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowOuter* window = aDocument->GetWindow();
|
2013-03-13 10:23:28 +04:00
|
|
|
if (!window) return;
|
|
|
|
|
2013-04-20 02:18:33 +04:00
|
|
|
EventTarget* target = window->GetChromeEventHandler();
|
2013-06-25 10:22:00 +04:00
|
|
|
if (!target) return;
|
|
|
|
|
2014-03-17 10:56:53 +04:00
|
|
|
EventListenerManager* elm = target->GetOrCreateListenerManager();
|
2013-03-05 18:56:34 +04:00
|
|
|
elm->RemoveEventListenerByType(this, NS_LITERAL_STRING("pagehide"),
|
2014-03-17 10:56:52 +04:00
|
|
|
TrustedEventsAtCapture());
|
2013-03-05 18:56:34 +04:00
|
|
|
|
|
|
|
elm->RemoveEventListenerByType(this, NS_LITERAL_STRING("DOMContentLoaded"),
|
2014-03-17 10:56:52 +04:00
|
|
|
TrustedEventsAtCapture());
|
2013-03-05 18:56:34 +04:00
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
DocAccessible* DocManager::CreateDocOrRootAccessible(Document* aDocument) {
|
2018-01-24 23:02:15 +03:00
|
|
|
// Ignore hidden documents, resource documents, static clone
|
|
|
|
// (printing) documents and documents without a docshell.
|
2014-04-02 23:36:48 +04:00
|
|
|
if (!aDocument->IsVisibleConsideringAncestors() ||
|
2018-01-24 23:02:15 +03:00
|
|
|
aDocument->IsResourceDoc() || aDocument->IsStaticDocument() ||
|
|
|
|
!aDocument->IsActive()) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2018-01-24 23:02:15 +03:00
|
|
|
}
|
2010-06-08 20:39:58 +04:00
|
|
|
|
2018-05-07 17:19:00 +03:00
|
|
|
nsIDocShell* docShell = aDocument->GetDocShell();
|
|
|
|
if (!docShell || docShell->IsInvisible()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIWidget* widget = nsContentUtils::WidgetForDocument(aDocument);
|
|
|
|
if (!widget || widget->WindowType() == eWindowType_invisible) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-02-27 15:33:55 +04:00
|
|
|
// Ignore documents without presshell and not having root frame.
|
2019-03-29 18:12:47 +03:00
|
|
|
PresShell* presShell = aDocument->GetPresShell();
|
|
|
|
if (!presShell || presShell->IsDestroying()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2010-06-08 20:39:58 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isRootDoc = nsCoreUtils::IsRootDocument(aDocument);
|
2010-06-08 20:39:58 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
DocAccessible* parentDocAcc = nullptr;
|
2011-01-26 09:35:51 +03:00
|
|
|
if (!isRootDoc) {
|
2010-06-08 20:39:58 +04: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 09:35:51 +03:00
|
|
|
parentDocAcc = GetDocAccessible(aDocument->GetParentDocument());
|
|
|
|
NS_ASSERTION(parentDocAcc, "Can't create an accessible for the document!");
|
|
|
|
if (!parentDocAcc) return nullptr;
|
2010-06-08 20:39:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// We only create root accessibles for the true root, otherwise create a
|
|
|
|
// doc accessible.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DocAccessible> docAcc =
|
2016-03-02 17:39:06 +03:00
|
|
|
isRootDoc ? new RootAccessibleWrap(aDocument, presShell)
|
|
|
|
: new DocAccessibleWrap(aDocument, presShell);
|
2010-06-08 20:39:58 +04:00
|
|
|
|
2010-11-12 22:00:55 +03:00
|
|
|
// Cache the document accessible into document cache.
|
2012-05-18 21:30:49 +04:00
|
|
|
mDocAccessibleCache.Put(aDocument, docAcc);
|
2010-06-08 20:39:58 +04:00
|
|
|
|
2012-11-20 07:54:41 +04:00
|
|
|
// Initialize the document accessible.
|
|
|
|
docAcc->Init();
|
2010-06-08 20:39:58 +04:00
|
|
|
|
2011-01-26 09:35:51 +03:00
|
|
|
// Bind the document to the tree.
|
|
|
|
if (isRootDoc) {
|
2012-09-10 17:20:26 +04:00
|
|
|
if (!ApplicationAcc()->AppendChild(docAcc)) {
|
2011-01-26 09:35:51 +03:00
|
|
|
docAcc->Shutdown();
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-01-26 09:35:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fire reorder event to notify new accessible document has been attached to
|
2011-07-19 12:30:32 +04: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 10:29:22 +04:00
|
|
|
// Note: don't use AccReorderEvent to avoid coalsecense and special reorder
|
|
|
|
// events processing.
|
2012-11-20 08:53:38 +04:00
|
|
|
docAcc->FireDelayedEvent(nsIAccessibleEvent::EVENT_REORDER,
|
|
|
|
ApplicationAcc());
|
2011-01-26 09:35:51 +03:00
|
|
|
|
|
|
|
} else {
|
|
|
|
parentDocAcc->BindChildDocument(docAcc);
|
|
|
|
}
|
|
|
|
|
2012-10-04 13:57:09 +04:00
|
|
|
#ifdef A11Y_LOG
|
2012-05-23 13:21:40 +04:00
|
|
|
if (logging::IsEnabled(logging::eDocCreate)) {
|
|
|
|
logging::DocCreate("document creation finished", aDocument);
|
|
|
|
logging::Stack();
|
|
|
|
}
|
|
|
|
#endif
|
2010-06-08 20:39:58 +04:00
|
|
|
|
|
|
|
AddListeners(aDocument, isRootDoc);
|
|
|
|
return docAcc;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-11-20 18:15:32 +04:00
|
|
|
// DocManager static
|
2010-06-08 20:39:58 +04:00
|
|
|
|
2012-11-20 18:15:32 +04:00
|
|
|
void DocManager::ClearDocCache() {
|
2015-10-20 03:52:43 +03:00
|
|
|
while (mDocAccessibleCache.Count() > 0) {
|
|
|
|
auto iter = mDocAccessibleCache.Iter();
|
|
|
|
MOZ_ASSERT(!iter.Done());
|
|
|
|
DocAccessible* docAcc = iter.UserData();
|
|
|
|
NS_ASSERTION(docAcc,
|
|
|
|
"No doc accessible for the object in doc accessible cache!");
|
|
|
|
if (docAcc) {
|
2010-12-02 19:07:14 +03:00
|
|
|
docAcc->Shutdown();
|
2015-10-20 03:52:43 +03:00
|
|
|
}
|
2016-08-08 18:35:56 +03:00
|
|
|
|
|
|
|
iter.Remove();
|
2010-12-02 19:07:14 +03:00
|
|
|
}
|
2016-08-08 18:35:56 +03:00
|
|
|
|
|
|
|
// Ensure that all xpcom accessible documents are shut down as well.
|
|
|
|
while (mXPCDocumentCache.Count() > 0) {
|
|
|
|
auto iter = mXPCDocumentCache.Iter();
|
|
|
|
MOZ_ASSERT(!iter.Done());
|
|
|
|
xpcAccessibleDocument* xpcDoc = iter.UserData();
|
|
|
|
NS_ASSERTION(xpcDoc, "No xpc doc for the object in xpc doc cache!");
|
|
|
|
|
|
|
|
if (xpcDoc) {
|
|
|
|
xpcDoc->Shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
iter.Remove();
|
|
|
|
}
|
2010-06-08 20:39:58 +04:00
|
|
|
}
|
|
|
|
|
2014-12-12 01:36:59 +03: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 08:55:39 +03:00
|
|
|
ProxyCreated(aDoc, Interfaces::DOCUMENT | Interfaces::HYPERTEXT);
|
2014-12-12 01:36:59 +03:00
|
|
|
}
|