void DocManager::RemoveListeners(nsIDocument* aDocument) { nsPIDOMWindow* window = aDocument->GetWindow(); if (!window) return; EventTarget* target = window->GetChromeEventHandler(); nsEventListenerManager* elm = target->GetListenerManager(true); elm->RemoveEventListenerByType(this, NS_LITERAL_STRING("pagehide"), dom::TrustedEventsAtCapture()); elm->RemoveEventListenerByType(this, NS_LITERAL_STRING("DOMContentLoaded"), dom::TrustedEventsAtCapture()); }
void DocManager::AddListeners(nsIDocument* aDocument, bool aAddDOMContentLoadedListener) { nsPIDOMWindow* window = aDocument->GetWindow(); EventTarget* target = window->GetChromeEventHandler(); nsEventListenerManager* elm = target->GetListenerManager(true); elm->AddEventListenerByType(this, NS_LITERAL_STRING("pagehide"), dom::TrustedEventsAtCapture()); #ifdef A11Y_LOG if (logging::IsEnabled(logging::eDocCreate)) logging::Text("added 'pagehide' listener"); #endif if (aAddDOMContentLoadedListener) { elm->AddEventListenerByType(this, NS_LITERAL_STRING("DOMContentLoaded"), dom::TrustedEventsAtCapture()); #ifdef A11Y_LOG if (logging::IsEnabled(logging::eDocCreate)) logging::Text("added 'DOMContentLoaded' listener"); #endif } }
static void MarkMessageManagers() { nsCOMPtr<nsIMessageBroadcaster> strongGlobalMM = do_GetService("@mozilla.org/globalmessagemanager;1"); if (!strongGlobalMM) { return; } nsIMessageBroadcaster* globalMM = strongGlobalMM; strongGlobalMM = nullptr; globalMM->MarkForCC(); uint32_t childCount = 0; globalMM->GetChildCount(&childCount); for (uint32_t i = 0; i < childCount; ++i) { nsCOMPtr<nsIMessageListenerManager> childMM; globalMM->GetChildAt(i, getter_AddRefs(childMM)); if (!childMM) { continue; } nsCOMPtr<nsIMessageBroadcaster> strongWindowMM = do_QueryInterface(childMM); nsIMessageBroadcaster* windowMM = strongWindowMM; childMM = nullptr; strongWindowMM = nullptr; windowMM->MarkForCC(); uint32_t tabChildCount = 0; windowMM->GetChildCount(&tabChildCount); for (uint32_t j = 0; j < tabChildCount; ++j) { nsCOMPtr<nsIMessageListenerManager> childMM; windowMM->GetChildAt(j, getter_AddRefs(childMM)); if (!childMM) { continue; } nsCOMPtr<nsIMessageSender> strongTabMM = do_QueryInterface(childMM); nsIMessageSender* tabMM = strongTabMM; childMM = nullptr; strongTabMM = nullptr; tabMM->MarkForCC(); //XXX hack warning, but works, since we know that // callback is frameloader. mozilla::dom::ipc::MessageManagerCallback* cb = static_cast<nsFrameMessageManager*>(tabMM)->GetCallback(); if (cb) { nsFrameLoader* fl = static_cast<nsFrameLoader*>(cb); EventTarget* et = fl->GetTabChildGlobalAsEventTarget(); if (!et) { continue; } static_cast<nsInProcessTabChildGlobal*>(et)->MarkForCC(); nsEventListenerManager* elm = et->GetListenerManager(false); if (elm) { elm->MarkForCC(); } } } } if (nsFrameMessageManager::sParentProcessManager) { nsFrameMessageManager::sParentProcessManager->MarkForCC(); uint32_t childCount = 0; nsFrameMessageManager::sParentProcessManager->GetChildCount(&childCount); for (uint32_t i = 0; i < childCount; ++i) { nsCOMPtr<nsIMessageListenerManager> childMM; nsFrameMessageManager::sParentProcessManager-> GetChildAt(i, getter_AddRefs(childMM)); if (!childMM) { continue; } nsIMessageListenerManager* child = childMM; childMM = nullptr; child->MarkForCC(); } } if (nsFrameMessageManager::sSameProcessParentManager) { nsFrameMessageManager::sSameProcessParentManager->MarkForCC(); } if (nsFrameMessageManager::sChildProcessManager) { nsFrameMessageManager::sChildProcessManager->MarkForCC(); } }