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
|
|
|
|
|
2014-03-17 10:56:53 +04:00
|
|
|
#include "mozilla/EventListenerManager.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 "nsCURILoader.h"
|
|
|
|
#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
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-09-02 12:41:57 +04:00
|
|
|
DocManager::DocManager()
|
2014-10-22 04:49:28 +04:00
|
|
|
: 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
|
|
|
|
2012-05-27 13:01:40 +04:00
|
|
|
DocAccessible*
|
2012-11-20 18:15:32 +04:00
|
|
|
DocManager::GetDocAccessible(nsIDocument* aDocument)
|
2010-06-08 20:39:58 +04:00
|
|
|
{
|
|
|
|
if (!aDocument)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-06-08 20:39:58 +04:00
|
|
|
|
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-05-29 05:18:45 +04:00
|
|
|
Accessible*
|
2012-11-20 18:15:32 +04:00
|
|
|
DocManager::FindAccessibleInCache(nsINode* aNode) const
|
2010-06-08 20:39:58 +04:00
|
|
|
{
|
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,
|
|
|
|
nsIDocument* 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-01-19 19:19:58 +03:00
|
|
|
void
|
2016-11-19 07:29:10 +03:00
|
|
|
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
|
|
|
|
bool
|
2012-11-20 18:15:32 +04:00
|
|
|
DocManager::IsProcessingRefreshDriverNotification() const
|
2011-10-06 06:10:30 +04:00
|
|
|
{
|
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-18 06:44:09 +04:00
|
|
|
|
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
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-11-20 18:15:32 +04:00
|
|
|
DocManager::Init()
|
2010-06-08 20:39:58 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIWebProgress> progress =
|
|
|
|
do_GetService(NS_DOCUMENTLOADER_SERVICE_CONTRACTID);
|
|
|
|
|
|
|
|
if (!progress)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-06-08 20:39:58 +04:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-11-20 18:15:32 +04:00
|
|
|
DocManager::Shutdown()
|
2010-06-08 20:39:58 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIWebProgress> progress =
|
|
|
|
do_GetService(NS_DOCUMENTLOADER_SERVICE_CONTRACTID);
|
|
|
|
|
|
|
|
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
|
|
|
|
2015-10-27 00:37:32 +03:00
|
|
|
nsCOMPtr<nsIDocument> document = piWindow->GetDoc();
|
|
|
|
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)
|
2010-06-08 20:39:58 +04:00
|
|
|
{
|
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)
|
2010-06-08 20:39:58 +04:00
|
|
|
{
|
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, nsresult aStatus,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* aMessage)
|
2010-06-08 20:39:58 +04:00
|
|
|
{
|
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,
|
|
|
|
uint32_t aState)
|
2010-06-08 20:39:58 +04:00
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// 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);
|
|
|
|
|
2018-04-20 07:49:29 +03:00
|
|
|
nsCOMPtr<nsIDocument> 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
|
|
|
|
|
|
|
void
|
2012-11-20 18:15:32 +04:00
|
|
|
DocManager::HandleDOMDocumentLoad(nsIDocument* aDocument,
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-11-20 18:15:32 +04:00
|
|
|
DocManager::AddListeners(nsIDocument* aDocument,
|
|
|
|
bool aAddDOMContentLoadedListener)
|
2010-06-08 20:39:58 +04:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-05 18:56:34 +04:00
|
|
|
void
|
|
|
|
DocManager::RemoveListeners(nsIDocument* 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
|
|
|
}
|
|
|
|
|
2012-05-27 13:01:40 +04:00
|
|
|
DocAccessible*
|
2012-11-20 18:15:32 +04:00
|
|
|
DocManager::CreateDocOrRootAccessible(nsIDocument* aDocument)
|
2010-06-08 20:39:58 +04:00
|
|
|
{
|
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.
|
|
|
|
nsIPresShell* presShell = aDocument->GetShell();
|
2012-12-27 08:25:27 +04:00
|
|
|
if (!presShell || presShell->IsDestroying())
|
2012-07-30 18:20:58 +04:00
|
|
|
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)
|
2012-07-30 18:20:58 +04:00
|
|
|
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 = isRootDoc ?
|
2016-03-02 17:39:06 +03:00
|
|
|
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
|
|
|
|
2010-12-02 19:07:14 +03:00
|
|
|
void
|
2012-11-20 18:15:32 +04:00
|
|
|
DocManager::ClearDocCache()
|
2010-12-02 19:07:14 +03:00
|
|
|
{
|
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
|
|
|
}
|