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"
|
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"
|
2019-04-10 01:39:01 +03:00
|
|
|
#include "mozilla/dom/BrowserChild.h"
|
2020-05-01 07:28:35 +03:00
|
|
|
#include "xpcAccessibleDocument.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;
|
2020-06-17 21:42:30 +03:00
|
|
|
StaticAutoPtr<nsRefPtrHashtable<nsPtrHashKey<const DocAccessibleParent>,
|
|
|
|
xpcAccessibleDocument>>
|
|
|
|
DocManager::sRemoteXPCDocumentCache;
|
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);
|
|
|
|
}
|
|
|
|
|
2020-11-23 19:08:23 +03:00
|
|
|
DocAccessible* DocManager::GetDocAccessible(const PresShell* aPresShell) {
|
|
|
|
if (!aPresShell) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
DocAccessible* doc = aPresShell->GetDocAccessible();
|
|
|
|
if (doc) {
|
|
|
|
return doc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetDocAccessible(aPresShell->GetDocument());
|
|
|
|
}
|
|
|
|
|
2021-02-20 02:14:32 +03:00
|
|
|
LocalAccessible* DocManager::FindAccessibleInCache(nsINode* aNode) const {
|
2021-03-24 20:56:49 +03:00
|
|
|
for (const auto& docAccessible : mDocAccessibleCache.Values()) {
|
2015-10-20 03:52:43 +03:00
|
|
|
NS_ASSERTION(docAccessible,
|
|
|
|
"No doc accessible for the object in doc accessible cache!");
|
|
|
|
|
|
|
|
if (docAccessible) {
|
2021-02-20 02:14:32 +03:00
|
|
|
LocalAccessible* accessible = docAccessible->GetAccessible(aNode);
|
2015-10-20 03:52:43 +03:00
|
|
|
if (accessible) {
|
|
|
|
return accessible;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
2010-06-08 20:39:58 +04:00
|
|
|
}
|
|
|
|
|
2021-02-04 04:10:52 +03:00
|
|
|
void DocManager::RemoveFromXPCDocumentCache(DocAccessible* aDocument,
|
|
|
|
bool aAllowServiceShutdown) {
|
2016-11-19 07:29:10 +03:00
|
|
|
xpcAccessibleDocument* xpcDoc = mXPCDocumentCache.GetWeak(aDocument);
|
|
|
|
if (xpcDoc) {
|
|
|
|
xpcDoc->Shutdown();
|
|
|
|
mXPCDocumentCache.Remove(aDocument);
|
|
|
|
|
2021-02-04 04:10:52 +03:00
|
|
|
if (aAllowServiceShutdown && !HasXPCDocuments()) {
|
2017-06-21 22:55:40 +03:00
|
|
|
MaybeShutdownAccService(nsAccessibilityService::eXPCOM);
|
|
|
|
}
|
2016-11-19 07:29:10 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-22 04:49:28 +04:00
|
|
|
void DocManager::NotifyOfDocumentShutdown(DocAccessible* aDocument,
|
2021-02-04 04:10:52 +03:00
|
|
|
Document* aDOMDocument,
|
|
|
|
bool aAllowServiceShutdown) {
|
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;
|
|
|
|
}
|
|
|
|
|
2021-02-04 04:10:52 +03:00
|
|
|
RemoveFromXPCDocumentCache(aDocument, aAllowServiceShutdown);
|
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;
|
|
|
|
|
2021-03-03 11:58:52 +03:00
|
|
|
return mXPCDocumentCache.GetOrInsertNew(aDocument, aDocument);
|
2014-10-22 04:49:28 +04:00
|
|
|
}
|
|
|
|
|
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>;
|
2020-06-17 21:42:30 +03:00
|
|
|
ClearOnShutdown(&sRemoteXPCDocumentCache);
|
2016-01-19 19:19:58 +03:00
|
|
|
}
|
|
|
|
|
2020-06-17 21:37:58 +03:00
|
|
|
MOZ_ASSERT(!aDoc->IsShutdown(), "Adding a shutdown doc to remote XPC cache");
|
2021-03-22 23:39:54 +03:00
|
|
|
doc = new xpcAccessibleDocument(aDoc);
|
2021-02-26 12:11:46 +03:00
|
|
|
sRemoteXPCDocumentCache->InsertOrUpdate(aDoc, RefPtr{doc});
|
2016-01-19 19:19:58 +03:00
|
|
|
|
|
|
|
return doc;
|
|
|
|
}
|
|
|
|
|
2011-10-06 06:10:30 +04:00
|
|
|
#ifdef DEBUG
|
2012-11-20 18:15:32 +04:00
|
|
|
bool DocManager::IsProcessingRefreshDriverNotification() const {
|
2021-03-12 19:14:58 +03:00
|
|
|
for (const auto& entry : mDocAccessibleCache) {
|
|
|
|
DocAccessible* docAccessible = entry.GetWeak();
|
2015-10-20 03:52:43 +03:00
|
|
|
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
|
|
|
|
2021-02-20 02:14:32 +03:00
|
|
|
if (progress) {
|
2010-06-08 20:39:58 +04:00
|
|
|
progress->RemoveProgressListener(
|
|
|
|
static_cast<nsIWebProgressListener*>(this));
|
2021-02-20 02:14:32 +03:00
|
|
|
}
|
2010-06-08 20:39:58 +04:00
|
|
|
|
|
|
|
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 ||
|
2021-02-20 02:14:32 +03:00
|
|
|
(aStateFlags & (STATE_START | STATE_STOP)) == 0) {
|
2010-06-08 20:39:58 +04:00
|
|
|
return NS_OK;
|
2021-02-20 02:14:32 +03:00
|
|
|
}
|
2010-06-08 20:39:58 +04:00
|
|
|
|
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
|
2021-02-20 02:14:32 +03:00
|
|
|
if (logging::IsEnabled(logging::eDocLoad)) {
|
2012-05-23 13:21:40 +04:00
|
|
|
logging::DocLoad("document loaded", aWebProgress, aRequest, aStateFlags);
|
2021-02-20 02:14:32 +03:00
|
|
|
}
|
2012-05-23 13:21:40 +04:00
|
|
|
#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.
|
2021-02-20 02:14:32 +03:00
|
|
|
if (NS_SUCCEEDED(aStatus) || !nsCoreUtils::IsContentDocument(document)) {
|
2010-06-08 20:39:58 +04:00
|
|
|
eventType = nsIAccessibleEvent::EVENT_DOCUMENT_LOAD_COMPLETE;
|
2021-02-20 02:14:32 +03:00
|
|
|
}
|
2010-06-08 20:39:58 +04:00
|
|
|
|
|
|
|
// 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
|
2021-02-20 02:14:32 +03:00
|
|
|
if (logging::IsEnabled(logging::eDocLoad)) {
|
2012-05-23 13:21:40 +04:00
|
|
|
logging::DocLoad("start document loading", aWebProgress, aRequest,
|
|
|
|
aStateFlags);
|
2021-02-20 02:14:32 +03:00
|
|
|
}
|
2012-05-23 13:21:40 +04:00
|
|
|
#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 ||
|
2021-04-12 21:04:12 +03:00
|
|
|
loadType == LOAD_RELOAD_BYPASS_PROXY_AND_CACHE) {
|
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
|
2021-02-20 02:14:32 +03:00
|
|
|
if (logging::IsEnabled(logging::eDocDestroy)) {
|
2012-05-23 13:21:40 +04:00
|
|
|
logging::DocDestroy("received 'pagehide' event", document);
|
2021-02-20 02:14:32 +03:00
|
|
|
}
|
2012-05-23 13:21:40 +04:00
|
|
|
#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
|
2021-02-20 02:14:32 +03:00
|
|
|
if (logging::IsEnabled(logging::eDocLoad)) {
|
2012-05-23 13:21:40 +04:00
|
|
|
logging::DocLoad("handled 'DOMContentLoaded' event", document);
|
2021-02-20 02:14:32 +03:00
|
|
|
}
|
2012-05-23 13:21:40 +04:00
|
|
|
#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, u"pagehide"_ns, TrustedEventsAtCapture());
|
|
|
|
|
2012-10-04 13:57:09 +04:00
|
|
|
#ifdef A11Y_LOG
|
2021-02-20 02:14:32 +03:00
|
|
|
if (logging::IsEnabled(logging::eDocCreate)) {
|
2012-05-23 13:21:40 +04:00
|
|
|
logging::Text("added 'pagehide' listener");
|
2021-02-20 02:14:32 +03:00
|
|
|
}
|
2012-05-23 13:21:40 +04:00
|
|
|
#endif
|
2010-06-08 20:39:58 +04:00
|
|
|
|
|
|
|
if (aAddDOMContentLoadedListener) {
|
|
|
|
elm->AddEventListenerByType(this, u"DOMContentLoaded"_ns,
|
2014-03-17 10:56:52 +04:00
|
|
|
TrustedEventsAtCapture());
|
2012-10-04 13:57:09 +04:00
|
|
|
#ifdef A11Y_LOG
|
2021-02-20 02:14:32 +03:00
|
|
|
if (logging::IsEnabled(logging::eDocCreate)) {
|
2012-05-23 13:21:40 +04:00
|
|
|
logging::Text("added 'DOMContentLoaded' listener");
|
2021-02-20 02:14:32 +03:00
|
|
|
}
|
2012-05-23 13:21:40 +04:00
|
|
|
#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, u"pagehide"_ns,
|
2014-03-17 10:56:52 +04:00
|
|
|
TrustedEventsAtCapture());
|
2013-03-05 18:56:34 +04:00
|
|
|
|
|
|
|
elm->RemoveEventListenerByType(this, u"DOMContentLoaded"_ns,
|
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.
|
2021-02-09 03:44:21 +03:00
|
|
|
if (!nsCoreUtils::IsDocumentVisibleConsideringInProcessAncestors(aDocument) ||
|
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.
|
2019-07-26 19:48:31 +03:00
|
|
|
parentDocAcc = GetDocAccessible(aDocument->GetInProcessParentDocument());
|
2011-01-26 09:35:51 +03:00
|
|
|
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.
|
2021-02-26 12:11:46 +03:00
|
|
|
mDocAccessibleCache.InsertOrUpdate(aDocument, RefPtr{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);
|
2021-03-02 19:32:24 +03:00
|
|
|
ProxyCreated(aDoc);
|
2014-12-12 01:36:59 +03:00
|
|
|
}
|
2020-11-23 19:07:43 +03:00
|
|
|
|
|
|
|
DocAccessible* mozilla::a11y::GetExistingDocAccessible(
|
|
|
|
const dom::Document* aDocument) {
|
|
|
|
PresShell* presShell = aDocument->GetPresShell();
|
|
|
|
return presShell ? presShell->GetDocAccessible() : nullptr;
|
|
|
|
}
|