mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:18:48 +00:00
69d1f32ff7
- Bug 1268085 - Remove unused post barrier callbacks r=terrence (0ab13411c9) - Bug 1267699 - Move some public types to the right namespace; r=sfink (3d5008e610) - Bug 1267550 (part 1) - Rename MOZ_MUST_USE as MOZ_MUST_USE_TYPE. r=ehsan. (6f47375796) - Bug 1259021 - Rename Vector::extractRawBuffer to extractOrCopyRawBuffer r=Waldo (97ca94495b) - Bug 1259021 - Add Vector::extractRawBuffer method that doesn't copy the buffer r=Waldo (e58deec48f) - Bug 1265892 - Change Vector to use Impl::new_ consistently. r=Waldo (7a52d21b29) - Bug 1267912 - Rename nsNetUtil.inl as nsNetUtilInlines.h. r=valentin. (548a41b293) - Bug 1265690 part 1 - Mark StringBuffer methods WARN_UNUSED_RESULT, fix OOM issues. r=jonco (0d7e6837e3) - Bug 1265690 part 2 - Fix some more OOM issues in TypedObject code. r=jonco (b60902453e) - Bug 1263490 - Part 2: Add GetFirstDollarIndex intrinsic and use it inRegExpReplace. r=till (4ba19db8c4) - Bug 1263490 - Part 3: Inline GetFirstDollarIndex intrinsic. r=h4writer (e7d9b5d1cc) - Bug 1263490 - Part 4: Fold GetFirstDollarIndex into a integer constant. r=h4writer (3479c7d1af) - Bug 1267269 - Make MIRType an enum class. r=bbouvier (d580ef372a) - Bug 1259295 - BaldrMonkey: Postorder (r=luke) (6ef7a77663) - Bug 1254142: BaldrMonkey: make br_table yield (r=luke) (80e7635e58) - Bug 1263202 - BaldrMonkey: switch to arities on branches, calls and return (r=bbouvier) (f5a0358634) - Bug 1236358 - Improper reading of string16 in Pickle::ReadString16. r=jld (8370ba6a0b) - Bug 1263205 - BaldrMonkey: Update section headers for proposed spec changes (r=luke) (0def2e6bc2) - Bug 1263205 - BaldrMonkey: Update for proposed new section names (r=luke) (e57f0e3367) - Bug 1263205 - BaldrMonkey: Add 'form' field to types section (r=bbouvier) (794edc890f) - Bug 1259021 - Use in-place storage in AutoStableStringChars to avoid allocation for short strings r=jandem r=Waldo (ffb53cbcf4) - Bug 1267550 (part 2) - Rename MOZ_WARN_UNUSED_RESULT as MOZ_MUST_USE. r=froydnj. (47bc674b86) - Bug 1268518: Baldr: implement int32/int64 rotations; r=luke (0d5eedccce) - Bug 1255008: IonMonkey - Add a by default disabled flow sensitive alias analysis pass, r=jandem (521c585d75) - Bug 1266781: Baldr: implement proper checked truncations to integer types; r=sunfish (46078fb3d3) - Bug 1266781: Rename MTruncateToInt64 into MWasmTruncateInt64; r=sunfish (c7d7d1ac11) - Bug 1266781: Add new traps; r=luke (b7ed3d44e6) - Bug 1268024: Pass the atomic attribute down to EmitHeapAccess; r=luke (6195f7d7a3) - Bug 1268024: A few cleanups related to loads/stores; r=luke (88141e3a01) - Bug 1258312 - Make Pickle::Resize infallible r=jld (241ee9b60d) - Bug 1162772, part 1 - Allow CompartmentCreationOptions to store Secure Context state. r=jorendorff (ff666384cf) - Bug 1162772, part 2 - Expose whether SEC_FORCE_INHERIT_PRINCIPAL was dropped from an nsILoadInfo. r=bz (ada46f86bf) - Bug 1162772, part 3 - Add a getChannelResultPrincipalIfNotSandboxed method to nsIScriptSecurityManager. r=bz (5b1d9f6807) - Bug 1162772, part 4 - Implement nsGlobalWindow::IsSecureContext. r=bz (f392f439c9) - Bug 1162772, part 5 - Expose Window.isSecureContext to content. r=bz (e7296e2cf1) - Bug 1267509 - Make nsContentSecurityManager::IsURIPotentiallyTrustworthy act on an nsIPrincipal. r=bz (83de80350a) - Bug 1219098 - Use UniquePtr in UncompressedSourceCache, for it is good (r=jandem) (b68769c729) - Bug 1244279 - Part 1: Take a bit in ObjectElements::Flags to indicate whether the object is in the whole cell store buffer. r=terrence (968cf373f9) - Bug 1244279 - Part 0: Add a GC ubench for large arrays with both elements and properties. r=terrence (ec76b48323) - Bug 1255925 - Give a name to getters/setters and integer-named methods. r=efaust (f978cc6916) - Bug 888969 - Make the getPrototypeOf/setPrototypeOf traps scriptable. r=efaust, r=bholley (eb2325a9ea) - Bug 1267557 part 0 - Move JS poison constants to jsutil.h. r=jonco (65afc690d2) - Bug 1267557 part 1 - Also poison bytes allocated before the actual jitcode. r=nbp (70f0b327d3) - Bug 1267557 part 2 - Use different jitcode poison values. r=nbp (08008ab9dc) - Bug 1267557 part 3 - Define JS_SWEPT_CODE_PATTERN for mips. r=nbp (17e894d59d) - Bug 1267449 - Do not infinite loop in js_fputs; r=jimb (67f961b6cd) - Bug 1219098 - Reenable compression on large sources, but revert to uncompressed if decompression happens (r=jandem) (b44ee8d77d) - Bug 1267551 (part 1) - Use MOZ_MUST_USE more in jsnum.h. r=jonco. (d2476bf8f4) - Bug 1267551 (part 2) - Use MOZ_MUST_USE more in js/src/ds/. r=jonco. (4ff5d9aa88) - Bug 1267412 - Use MutableHandleValue instead of pointer-to-AutoValueVector; r=sfink (3f6dd284bb) - Bug 1266406 - Use EnumSet<AllocKind> to simplify GC sweeping phase information r=terrence (64811500e7) - Bug 1266457 - Update pointers in GC things in two phases when compacting r=terrence (f6f5bc4e4d) - Bug 1266457 - Simplify typed object trace hook r=terence (3b06c8d1e5) - Bug 1268541 - Compact arenas containing base shapes r=terrence (b458b92eea) - Bug 1268805 - Implement PrivateGCThingValue. (r=terrence) (deec9a83ae) - Bug 1268415: Initialize members in UpdatePointerTasks; r=jonco (6cb219005a) - Bug 1268501 - Release the GC lock periodically when releasing arenas on the backgound thread r=terrence (37f0997682) - Bug 1263572 - Wait for background sweeping to finish before checking base shapes r=terrence (354801a411) - Bug 1266887 - Store Rooted heads on the Zone; r=sfink (91c0101ee3) - Bug 1266402 - Add iteration to EnumSet<T> so that it can be used in range-based for loops r=Waldo (e9507a2524) - Bug 1266404 - Allow construction of an EnumSet<T> using an initializer list r=Waldo (1b6d340e99) - Bug 1254020 - Always compute theme scaling factor when per-monitor dpi aware, even if only a single display is currently present. r=emk (a00cda21f4) - Bug 1263525 - Add dedicated function for std_Array self-hosted intrinsic. r=efaust (449d8bb7eb) - Bug 1255925 - Change JSFunction::name to return a JSAtom. r=efaust (5ab396ce83) - Bug 888969 - Make our tree's sole implementation of nsIRemoteTagService.getRemoteObjectTag not depend upon the infallibility of [[GetPrototypeOf]] on the object provided to it. r=bz (f388f4bf1f) - Bug 1264896 - Kill off nsIRemoteTagService and do what it does, in its sole caller, in far-faster C++. r=billm (5ed3fb103d) - Bug 1268246 - Add a simple Poison class lifetime checker. r=froydnj (7b237bc70e) - Bug 1249496 - Don't apply dpi-based scaling for window titlebar dimensions when on a secondary display, because windows doesn't scale it. r=emk (64dd706dbc) - Bug 1164518 - Avoid unnecessary DB updates when caching Safe Browsing results. r=gcp (3cafd9a4df) - Bug 1264472 - Use nsRunnables in FIDO U2F. r=keeler (3aa9570132) - Bug 1236060 - Dispatch error should advance queue. r=smaug (74155b75dd) - Bug 1251697 part 1. Thread an ErrorResult reference through the worker XHR WorkerThreadProxySyncRunnable implementations. r=khuey (77804cbb7c) - Bug 1251697 part 2. Have WorkerThreadProxySyncRunnable hand the ErrorResult reference it holds to its ResponseRunnable so it can report exceptions on there instead of on a JSContext. r=khuey (355c9ee313) - Bug 1251697 part 3. Remove the JSContext argument of StopSyncLoopRunnable::MaybeSetException. r=khuey (010f5b1058) - Bug 1155328. r=smaug (e1f8dac304) - Bug 1265927: Move nsRunnable to mozilla::Runnable, CancelableRunnable to mozilla::CancelableRunnable. r=froydnj (f83bfcae02) - Bug 1239946 - Change test to return error on Speak. r=eeejay (1d402beb02) - Bug 1254378 - Update synth tests and introduce no voiceschanged test. r=smaug (f5823bb70e) - Bug 1251627. Fix XMLHttpRequest.send() to follow the spec better in terms of the exceptions it throws. r=khuey (cd0e321948) - Bug 1268868: [MSE] P1. Re-enable gap detection within a media segment. r=gerald (b8b8df4bc2) - Bug 1268868: [MSE] P2. Reset longest duration after keyframe is seen. r=gerald (2b1401465c) - Bug 1268868: [MSE] P3. Prevent crash should gap be detected in content. r=gerald (063d9376fc) - Bug 1254378 - Implement nsISynthVoiceRegistry.notifyVoicesChanged. r=smaug (4b63b1c360) - Bug 1266804 - Un-inline js::Unbox(); r=jorendorff (0f288b6173) - Bug 1268863 - Report ScriptSources that are only reachable via AsmJSModule (r=njn) (5ba40acb64) - bump version to 45.1b1 (1414db0ca8) - Bug 1262062 - remove old futex names. r=bbouvier (62662bdd2e) - memory: build fix after renaming MOZ_WARN_UNUSED_RESULT (7254dc8d53) - import from mozilla: - Bug 1268725 - BaldrMonkey: Refactor away the internal storage from ExprIter. r=luke (1931bd636f17) - Bug 1268725 - BaldrMonkey: Convert default arguments into explicit arguments. r=luke (c8a11b8b6bbd) (867ec715d6)
1165 lines
36 KiB
C++
1165 lines
36 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
/* 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/. */
|
|
|
|
#include "nsDOMMutationObserver.h"
|
|
|
|
#include "mozilla/OwningNonNull.h"
|
|
|
|
#include "mozilla/dom/Animation.h"
|
|
#include "mozilla/dom/KeyframeEffect.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
#include "nsError.h"
|
|
#include "nsIDOMMutationEvent.h"
|
|
#include "nsIScriptGlobalObject.h"
|
|
#include "nsServiceManagerUtils.h"
|
|
#include "nsTextFragment.h"
|
|
#include "nsThreadUtils.h"
|
|
|
|
using mozilla::dom::TreeOrderComparator;
|
|
using mozilla::dom::Animation;
|
|
|
|
AutoTArray<RefPtr<nsDOMMutationObserver>, 4>*
|
|
nsDOMMutationObserver::sScheduledMutationObservers = nullptr;
|
|
|
|
nsDOMMutationObserver* nsDOMMutationObserver::sCurrentObserver = nullptr;
|
|
|
|
uint32_t nsDOMMutationObserver::sMutationLevel = 0;
|
|
uint64_t nsDOMMutationObserver::sCount = 0;
|
|
|
|
AutoTArray<AutoTArray<RefPtr<nsDOMMutationObserver>, 4>, 4>*
|
|
nsDOMMutationObserver::sCurrentlyHandlingObservers = nullptr;
|
|
|
|
nsINodeList*
|
|
nsDOMMutationRecord::AddedNodes()
|
|
{
|
|
if (!mAddedNodes) {
|
|
mAddedNodes = new nsSimpleContentList(mTarget);
|
|
}
|
|
return mAddedNodes;
|
|
}
|
|
|
|
nsINodeList*
|
|
nsDOMMutationRecord::RemovedNodes()
|
|
{
|
|
if (!mRemovedNodes) {
|
|
mRemovedNodes = new nsSimpleContentList(mTarget);
|
|
}
|
|
return mRemovedNodes;
|
|
}
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMMutationRecord)
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
NS_INTERFACE_MAP_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMMutationRecord)
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMMutationRecord)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(nsDOMMutationRecord,
|
|
mTarget,
|
|
mPreviousSibling, mNextSibling,
|
|
mAddedNodes, mRemovedNodes,
|
|
mAddedAnimations, mRemovedAnimations,
|
|
mChangedAnimations,
|
|
mNext, mOwner)
|
|
|
|
// Observer
|
|
|
|
bool
|
|
nsMutationReceiverBase::IsObservable(nsIContent* aContent)
|
|
{
|
|
return !aContent->ChromeOnlyAccess() &&
|
|
(Observer()->IsChrome() || !aContent->IsInAnonymousSubtree());
|
|
}
|
|
|
|
NS_IMPL_ADDREF(nsMutationReceiver)
|
|
NS_IMPL_RELEASE(nsMutationReceiver)
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsMutationReceiver)
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
NS_INTERFACE_MAP_ENTRY(nsIMutationObserver)
|
|
NS_INTERFACE_MAP_END
|
|
|
|
nsMutationReceiver::nsMutationReceiver(nsINode* aTarget,
|
|
nsDOMMutationObserver* aObserver)
|
|
: nsMutationReceiverBase(aTarget, aObserver)
|
|
{
|
|
mTarget->BindObject(aObserver);
|
|
}
|
|
|
|
void
|
|
nsMutationReceiver::Disconnect(bool aRemoveFromObserver)
|
|
{
|
|
if (mRegisterTarget) {
|
|
mRegisterTarget->RemoveMutationObserver(this);
|
|
mRegisterTarget = nullptr;
|
|
}
|
|
|
|
mParent = nullptr;
|
|
nsINode* target = mTarget;
|
|
mTarget = nullptr;
|
|
nsDOMMutationObserver* observer = mObserver;
|
|
mObserver = nullptr;
|
|
RemoveClones();
|
|
|
|
if (target && observer) {
|
|
if (aRemoveFromObserver) {
|
|
static_cast<nsDOMMutationObserver*>(observer)->RemoveReceiver(this);
|
|
}
|
|
// UnbindObject may delete 'this'!
|
|
target->UnbindObject(observer);
|
|
}
|
|
}
|
|
|
|
void
|
|
nsMutationReceiver::NativeAnonymousChildListChange(nsIDocument* aDocument,
|
|
nsIContent* aContent,
|
|
bool aIsRemove) {
|
|
if (!NativeAnonymousChildList()) {
|
|
return;
|
|
}
|
|
|
|
nsINode* parent = aContent->GetParentNode();
|
|
if (!parent ||
|
|
(!Subtree() && Target() != parent) ||
|
|
(Subtree() && RegisterTarget()->SubtreeRoot() != parent->SubtreeRoot())) {
|
|
return;
|
|
}
|
|
|
|
nsDOMMutationRecord* m =
|
|
Observer()->CurrentRecord(nsGkAtoms::nativeAnonymousChildList);
|
|
|
|
if (m->mTarget) {
|
|
return;
|
|
}
|
|
m->mTarget = parent;
|
|
|
|
if (aIsRemove) {
|
|
m->mRemovedNodes = new nsSimpleContentList(parent);
|
|
m->mRemovedNodes->AppendElement(aContent);
|
|
} else {
|
|
m->mAddedNodes = new nsSimpleContentList(parent);
|
|
m->mAddedNodes->AppendElement(aContent);
|
|
}
|
|
}
|
|
|
|
void
|
|
nsMutationReceiver::AttributeWillChange(nsIDocument* aDocument,
|
|
mozilla::dom::Element* aElement,
|
|
int32_t aNameSpaceID,
|
|
nsIAtom* aAttribute,
|
|
int32_t aModType,
|
|
const nsAttrValue* aNewValue)
|
|
{
|
|
if (nsAutoMutationBatch::IsBatching() ||
|
|
!ObservesAttr(RegisterTarget(), aElement, aNameSpaceID, aAttribute)) {
|
|
return;
|
|
}
|
|
|
|
nsDOMMutationRecord* m =
|
|
Observer()->CurrentRecord(nsGkAtoms::attributes);
|
|
|
|
NS_ASSERTION(!m->mTarget || m->mTarget == aElement,
|
|
"Wrong target!");
|
|
NS_ASSERTION(!m->mAttrName || m->mAttrName == aAttribute,
|
|
"Wrong attribute!");
|
|
if (!m->mTarget) {
|
|
m->mTarget = aElement;
|
|
m->mAttrName = aAttribute;
|
|
if (aNameSpaceID == kNameSpaceID_None) {
|
|
m->mAttrNamespace.SetIsVoid(true);
|
|
} else {
|
|
nsContentUtils::NameSpaceManager()->GetNameSpaceURI(aNameSpaceID,
|
|
m->mAttrNamespace);
|
|
}
|
|
}
|
|
|
|
if (AttributeOldValue() && m->mPrevValue.IsVoid()) {
|
|
if (!aElement->GetAttr(aNameSpaceID, aAttribute, m->mPrevValue)) {
|
|
m->mPrevValue.SetIsVoid(true);
|
|
}
|
|
}
|
|
}
|
|
|
|
void
|
|
nsMutationReceiver::CharacterDataWillChange(nsIDocument *aDocument,
|
|
nsIContent* aContent,
|
|
CharacterDataChangeInfo* aInfo)
|
|
{
|
|
if (nsAutoMutationBatch::IsBatching() ||
|
|
!CharacterData() ||
|
|
(!Subtree() && aContent != Target()) ||
|
|
(Subtree() && RegisterTarget()->SubtreeRoot() != aContent->SubtreeRoot()) ||
|
|
!IsObservable(aContent)) {
|
|
return;
|
|
}
|
|
|
|
nsDOMMutationRecord* m =
|
|
Observer()->CurrentRecord(nsGkAtoms::characterData);
|
|
|
|
NS_ASSERTION(!m->mTarget || m->mTarget == aContent,
|
|
"Wrong target!");
|
|
|
|
if (!m->mTarget) {
|
|
m->mTarget = aContent;
|
|
}
|
|
if (CharacterDataOldValue() && m->mPrevValue.IsVoid()) {
|
|
aContent->GetText()->AppendTo(m->mPrevValue);
|
|
}
|
|
}
|
|
|
|
void
|
|
nsMutationReceiver::ContentAppended(nsIDocument* aDocument,
|
|
nsIContent* aContainer,
|
|
nsIContent* aFirstNewContent,
|
|
int32_t aNewIndexInContainer)
|
|
{
|
|
nsINode* parent = NODE_FROM(aContainer, aDocument);
|
|
bool wantsChildList =
|
|
ChildList() &&
|
|
((Subtree() && RegisterTarget()->SubtreeRoot() == parent->SubtreeRoot()) ||
|
|
parent == Target());
|
|
if (!wantsChildList || !IsObservable(aFirstNewContent)) {
|
|
return;
|
|
}
|
|
|
|
if (nsAutoMutationBatch::IsBatching()) {
|
|
if (parent == nsAutoMutationBatch::GetBatchTarget()) {
|
|
nsAutoMutationBatch::UpdateObserver(Observer(), wantsChildList);
|
|
}
|
|
return;
|
|
}
|
|
|
|
nsDOMMutationRecord* m =
|
|
Observer()->CurrentRecord(nsGkAtoms::childList);
|
|
NS_ASSERTION(!m->mTarget || m->mTarget == parent,
|
|
"Wrong target!");
|
|
if (m->mTarget) {
|
|
// Already handled case.
|
|
return;
|
|
}
|
|
m->mTarget = parent;
|
|
m->mAddedNodes = new nsSimpleContentList(parent);
|
|
|
|
nsINode* n = aFirstNewContent;
|
|
while (n) {
|
|
m->mAddedNodes->AppendElement(static_cast<nsIContent*>(n));
|
|
n = n->GetNextSibling();
|
|
}
|
|
m->mPreviousSibling = aFirstNewContent->GetPreviousSibling();
|
|
}
|
|
|
|
void
|
|
nsMutationReceiver::ContentInserted(nsIDocument* aDocument,
|
|
nsIContent* aContainer,
|
|
nsIContent* aChild,
|
|
int32_t aIndexInContainer)
|
|
{
|
|
nsINode* parent = NODE_FROM(aContainer, aDocument);
|
|
bool wantsChildList =
|
|
ChildList() &&
|
|
((Subtree() && RegisterTarget()->SubtreeRoot() == parent->SubtreeRoot()) ||
|
|
parent == Target());
|
|
if (!wantsChildList || !IsObservable(aChild)) {
|
|
return;
|
|
}
|
|
|
|
if (nsAutoMutationBatch::IsBatching()) {
|
|
if (parent == nsAutoMutationBatch::GetBatchTarget()) {
|
|
nsAutoMutationBatch::UpdateObserver(Observer(), wantsChildList);
|
|
}
|
|
return;
|
|
}
|
|
|
|
nsDOMMutationRecord* m =
|
|
Observer()->CurrentRecord(nsGkAtoms::childList);
|
|
if (m->mTarget) {
|
|
// Already handled case.
|
|
return;
|
|
}
|
|
m->mTarget = parent;
|
|
m->mAddedNodes = new nsSimpleContentList(parent);
|
|
m->mAddedNodes->AppendElement(aChild);
|
|
m->mPreviousSibling = aChild->GetPreviousSibling();
|
|
m->mNextSibling = aChild->GetNextSibling();
|
|
}
|
|
|
|
void
|
|
nsMutationReceiver::ContentRemoved(nsIDocument* aDocument,
|
|
nsIContent* aContainer,
|
|
nsIContent* aChild,
|
|
int32_t aIndexInContainer,
|
|
nsIContent* aPreviousSibling)
|
|
{
|
|
if (!IsObservable(aChild)) {
|
|
return;
|
|
}
|
|
|
|
nsINode* parent = NODE_FROM(aContainer, aDocument);
|
|
if (Subtree() && parent->SubtreeRoot() != RegisterTarget()->SubtreeRoot()) {
|
|
return;
|
|
}
|
|
if (nsAutoMutationBatch::IsBatching()) {
|
|
if (nsAutoMutationBatch::IsRemovalDone()) {
|
|
// This can happen for example if HTML parser parses to
|
|
// context node, but needs to move elements around.
|
|
return;
|
|
}
|
|
if (nsAutoMutationBatch::GetBatchTarget() != parent) {
|
|
return;
|
|
}
|
|
|
|
bool wantsChildList = ChildList() && (Subtree() || parent == Target());
|
|
if (wantsChildList || Subtree()) {
|
|
nsAutoMutationBatch::NodeRemoved(aChild);
|
|
nsAutoMutationBatch::UpdateObserver(Observer(), wantsChildList);
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
if (Subtree()) {
|
|
// Try to avoid creating transient observer if the node
|
|
// already has an observer observing the same set of nodes.
|
|
nsMutationReceiver* orig = GetParent() ? GetParent() : this;
|
|
if (Observer()->GetReceiverFor(aChild, false, false) != orig) {
|
|
bool transientExists = false;
|
|
nsCOMArray<nsMutationReceiver>* transientReceivers = nullptr;
|
|
Observer()->mTransientReceivers.Get(aChild, &transientReceivers);
|
|
if (!transientReceivers) {
|
|
transientReceivers = new nsCOMArray<nsMutationReceiver>();
|
|
Observer()->mTransientReceivers.Put(aChild, transientReceivers);
|
|
} else {
|
|
for (int32_t i = 0; i < transientReceivers->Count(); ++i) {
|
|
nsMutationReceiver* r = transientReceivers->ObjectAt(i);
|
|
if (r->GetParent() == orig) {
|
|
transientExists = true;
|
|
}
|
|
}
|
|
}
|
|
if (!transientExists) {
|
|
// Make sure the elements which are removed from the
|
|
// subtree are kept in the same observation set.
|
|
nsMutationReceiver* tr;
|
|
if (orig->Animations()) {
|
|
tr = nsAnimationReceiver::Create(aChild, orig);
|
|
} else {
|
|
tr = nsMutationReceiver::Create(aChild, orig);
|
|
}
|
|
transientReceivers->AppendObject(tr);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (ChildList() && (Subtree() || parent == Target())) {
|
|
nsDOMMutationRecord* m =
|
|
Observer()->CurrentRecord(nsGkAtoms::childList);
|
|
if (m->mTarget) {
|
|
// Already handled case.
|
|
return;
|
|
}
|
|
m->mTarget = parent;
|
|
m->mRemovedNodes = new nsSimpleContentList(parent);
|
|
m->mRemovedNodes->AppendElement(aChild);
|
|
m->mPreviousSibling = aPreviousSibling;
|
|
m->mNextSibling = parent->GetChildAt(aIndexInContainer);
|
|
}
|
|
// We need to schedule always, so that after microtask mTransientReceivers
|
|
// can be cleared correctly.
|
|
Observer()->ScheduleForRun();
|
|
}
|
|
|
|
void nsMutationReceiver::NodeWillBeDestroyed(const nsINode *aNode)
|
|
{
|
|
NS_ASSERTION(!mParent, "Shouldn't have mParent here!");
|
|
Disconnect(true);
|
|
}
|
|
|
|
void
|
|
nsAnimationReceiver::RecordAnimationMutation(Animation* aAnimation,
|
|
AnimationMutation aMutationType)
|
|
{
|
|
mozilla::dom::KeyframeEffectReadOnly* effect = aAnimation->GetEffect();
|
|
if (!effect) {
|
|
return;
|
|
}
|
|
|
|
Maybe<NonOwningAnimationTarget> animationTarget = effect->GetTarget();
|
|
if (!animationTarget) {
|
|
return;
|
|
}
|
|
|
|
dom::Element* elem = animationTarget->mElement;
|
|
if (!Animations() || !(Subtree() || elem == Target()) ||
|
|
elem->ChromeOnlyAccess()) {
|
|
return;
|
|
}
|
|
|
|
// Record animations targeting to a pseudo element only when subtree is true.
|
|
if (animationTarget->mPseudoType != CSSPseudoElementType::NotPseudo &&
|
|
!Subtree()) {
|
|
return;
|
|
}
|
|
|
|
if (nsAutoAnimationMutationBatch::IsBatching()) {
|
|
switch (aMutationType) {
|
|
case eAnimationMutation_Added:
|
|
nsAutoAnimationMutationBatch::AnimationAdded(aAnimation, elem);
|
|
break;
|
|
case eAnimationMutation_Changed:
|
|
nsAutoAnimationMutationBatch::AnimationChanged(aAnimation, elem);
|
|
break;
|
|
case eAnimationMutation_Removed:
|
|
nsAutoAnimationMutationBatch::AnimationRemoved(aAnimation, elem);
|
|
break;
|
|
}
|
|
|
|
nsAutoAnimationMutationBatch::AddObserver(Observer());
|
|
return;
|
|
}
|
|
|
|
nsDOMMutationRecord* m =
|
|
Observer()->CurrentRecord(nsGkAtoms::animations);
|
|
|
|
NS_ASSERTION(!m->mTarget, "Wrong target!");
|
|
|
|
m->mTarget = elem;
|
|
|
|
switch (aMutationType) {
|
|
case eAnimationMutation_Added:
|
|
m->mAddedAnimations.AppendElement(aAnimation);
|
|
break;
|
|
case eAnimationMutation_Changed:
|
|
m->mChangedAnimations.AppendElement(aAnimation);
|
|
break;
|
|
case eAnimationMutation_Removed:
|
|
m->mRemovedAnimations.AppendElement(aAnimation);
|
|
break;
|
|
}
|
|
}
|
|
|
|
void
|
|
nsAnimationReceiver::AnimationAdded(Animation* aAnimation)
|
|
{
|
|
RecordAnimationMutation(aAnimation, eAnimationMutation_Added);
|
|
}
|
|
|
|
void
|
|
nsAnimationReceiver::AnimationChanged(Animation* aAnimation)
|
|
{
|
|
RecordAnimationMutation(aAnimation, eAnimationMutation_Changed);
|
|
}
|
|
|
|
void
|
|
nsAnimationReceiver::AnimationRemoved(Animation* aAnimation)
|
|
{
|
|
RecordAnimationMutation(aAnimation, eAnimationMutation_Removed);
|
|
}
|
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(nsAnimationReceiver, nsMutationReceiver,
|
|
nsIAnimationObserver)
|
|
|
|
// Observer
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMMutationObserver)
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
NS_INTERFACE_MAP_ENTRY(nsDOMMutationObserver)
|
|
NS_INTERFACE_MAP_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMMutationObserver)
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMMutationObserver)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsDOMMutationObserver)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsDOMMutationObserver)
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDOMMutationObserver)
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mOwner)
|
|
for (int32_t i = 0; i < tmp->mReceivers.Count(); ++i) {
|
|
tmp->mReceivers[i]->Disconnect(false);
|
|
}
|
|
tmp->mReceivers.Clear();
|
|
tmp->ClearPendingRecords();
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCallback)
|
|
// No need to handle mTransientReceivers
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDOMMutationObserver)
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOwner)
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mReceivers)
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFirstPendingMutation)
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCallback)
|
|
// No need to handle mTransientReceivers
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
nsMutationReceiver*
|
|
nsDOMMutationObserver::GetReceiverFor(nsINode* aNode, bool aMayCreate,
|
|
bool aWantsAnimations)
|
|
{
|
|
MOZ_ASSERT(aMayCreate || !aWantsAnimations,
|
|
"the value of aWantsAnimations doesn't matter when aMayCreate is "
|
|
"false, so just pass in false for it");
|
|
|
|
if (!aMayCreate && !aNode->MayHaveDOMMutationObserver()) {
|
|
return nullptr;
|
|
}
|
|
|
|
for (int32_t i = 0; i < mReceivers.Count(); ++i) {
|
|
if (mReceivers[i]->Target() == aNode) {
|
|
return mReceivers[i];
|
|
}
|
|
}
|
|
if (!aMayCreate) {
|
|
return nullptr;
|
|
}
|
|
|
|
nsMutationReceiver* r;
|
|
if (aWantsAnimations) {
|
|
r = nsAnimationReceiver::Create(aNode, this);
|
|
} else {
|
|
r = nsMutationReceiver::Create(aNode, this);
|
|
}
|
|
mReceivers.AppendObject(r);
|
|
return r;
|
|
}
|
|
|
|
void
|
|
nsDOMMutationObserver::RemoveReceiver(nsMutationReceiver* aReceiver)
|
|
{
|
|
mReceivers.RemoveObject(aReceiver);
|
|
}
|
|
|
|
void
|
|
nsDOMMutationObserver::GetAllSubtreeObserversFor(nsINode* aNode,
|
|
nsTArray<nsMutationReceiver*>&
|
|
aReceivers)
|
|
{
|
|
nsINode* n = aNode;
|
|
while (n) {
|
|
if (n->MayHaveDOMMutationObserver()) {
|
|
nsMutationReceiver* r = GetReceiverFor(n, false, false);
|
|
if (r && r->Subtree() && !aReceivers.Contains(r)) {
|
|
aReceivers.AppendElement(r);
|
|
// If we've found all the receivers the observer has,
|
|
// no need to search for more.
|
|
if (mReceivers.Count() == int32_t(aReceivers.Length())) {
|
|
return;
|
|
}
|
|
}
|
|
nsCOMArray<nsMutationReceiver>* transientReceivers = nullptr;
|
|
if (mTransientReceivers.Get(n, &transientReceivers) && transientReceivers) {
|
|
for (int32_t i = 0; i < transientReceivers->Count(); ++i) {
|
|
nsMutationReceiver* r = transientReceivers->ObjectAt(i);
|
|
nsMutationReceiver* parent = r->GetParent();
|
|
if (r->Subtree() && parent && !aReceivers.Contains(parent)) {
|
|
aReceivers.AppendElement(parent);
|
|
}
|
|
}
|
|
if (mReceivers.Count() == int32_t(aReceivers.Length())) {
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
n = n->GetParentNode();
|
|
}
|
|
}
|
|
|
|
void
|
|
nsDOMMutationObserver::ScheduleForRun()
|
|
{
|
|
nsDOMMutationObserver::AddCurrentlyHandlingObserver(this, sMutationLevel);
|
|
|
|
if (mWaitingForRun) {
|
|
return;
|
|
}
|
|
mWaitingForRun = true;
|
|
RescheduleForRun();
|
|
}
|
|
|
|
void
|
|
nsDOMMutationObserver::RescheduleForRun()
|
|
{
|
|
if (!sScheduledMutationObservers) {
|
|
sScheduledMutationObservers = new AutoTArray<RefPtr<nsDOMMutationObserver>, 4>;
|
|
}
|
|
|
|
bool didInsert = false;
|
|
for (uint32_t i = 0; i < sScheduledMutationObservers->Length(); ++i) {
|
|
if (static_cast<nsDOMMutationObserver*>((*sScheduledMutationObservers)[i])
|
|
->mId > mId) {
|
|
sScheduledMutationObservers->InsertElementAt(i, this);
|
|
didInsert = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!didInsert) {
|
|
sScheduledMutationObservers->AppendElement(this);
|
|
}
|
|
}
|
|
|
|
void
|
|
nsDOMMutationObserver::Observe(nsINode& aTarget,
|
|
const mozilla::dom::MutationObserverInit& aOptions,
|
|
mozilla::ErrorResult& aRv)
|
|
{
|
|
|
|
bool childList = aOptions.mChildList;
|
|
bool attributes =
|
|
aOptions.mAttributes.WasPassed() &&
|
|
aOptions.mAttributes.Value();
|
|
bool characterData =
|
|
aOptions.mCharacterData.WasPassed() &&
|
|
aOptions.mCharacterData.Value();
|
|
bool subtree = aOptions.mSubtree;
|
|
bool attributeOldValue =
|
|
aOptions.mAttributeOldValue.WasPassed() &&
|
|
aOptions.mAttributeOldValue.Value();
|
|
bool nativeAnonymousChildList = aOptions.mNativeAnonymousChildList &&
|
|
nsContentUtils::ThreadsafeIsCallerChrome();
|
|
bool characterDataOldValue =
|
|
aOptions.mCharacterDataOldValue.WasPassed() &&
|
|
aOptions.mCharacterDataOldValue.Value();
|
|
bool animations =
|
|
aOptions.mAnimations.WasPassed() &&
|
|
aOptions.mAnimations.Value() &&
|
|
nsContentUtils::ThreadsafeIsCallerChrome();
|
|
|
|
if (!aOptions.mAttributes.WasPassed() &&
|
|
(aOptions.mAttributeOldValue.WasPassed() ||
|
|
aOptions.mAttributeFilter.WasPassed())) {
|
|
attributes = true;
|
|
}
|
|
|
|
if (!aOptions.mCharacterData.WasPassed() &&
|
|
aOptions.mCharacterDataOldValue.WasPassed()) {
|
|
characterData = true;
|
|
}
|
|
|
|
if (!(childList || attributes || characterData || animations ||
|
|
nativeAnonymousChildList)) {
|
|
aRv.Throw(NS_ERROR_DOM_TYPE_ERR);
|
|
return;
|
|
}
|
|
|
|
if (aOptions.mAttributeOldValue.WasPassed() &&
|
|
aOptions.mAttributeOldValue.Value() &&
|
|
aOptions.mAttributes.WasPassed() &&
|
|
!aOptions.mAttributes.Value()) {
|
|
aRv.Throw(NS_ERROR_DOM_TYPE_ERR);
|
|
return;
|
|
}
|
|
|
|
if (aOptions.mAttributeFilter.WasPassed() &&
|
|
aOptions.mAttributes.WasPassed() &&
|
|
!aOptions.mAttributes.Value()) {
|
|
aRv.Throw(NS_ERROR_DOM_TYPE_ERR);
|
|
return;
|
|
}
|
|
|
|
if (aOptions.mCharacterDataOldValue.WasPassed() &&
|
|
aOptions.mCharacterDataOldValue.Value() &&
|
|
aOptions.mCharacterData.WasPassed() &&
|
|
!aOptions.mCharacterData.Value()) {
|
|
aRv.Throw(NS_ERROR_DOM_TYPE_ERR);
|
|
return;
|
|
}
|
|
|
|
nsCOMArray<nsIAtom> filters;
|
|
bool allAttrs = true;
|
|
if (aOptions.mAttributeFilter.WasPassed()) {
|
|
allAttrs = false;
|
|
const mozilla::dom::Sequence<nsString>& filtersAsString =
|
|
aOptions.mAttributeFilter.Value();
|
|
uint32_t len = filtersAsString.Length();
|
|
filters.SetCapacity(len);
|
|
|
|
for (uint32_t i = 0; i < len; ++i) {
|
|
nsCOMPtr<nsIAtom> a = NS_Atomize(filtersAsString[i]);
|
|
filters.AppendObject(a);
|
|
}
|
|
}
|
|
|
|
nsMutationReceiver* r = GetReceiverFor(&aTarget, true, animations);
|
|
r->SetChildList(childList);
|
|
r->SetAttributes(attributes);
|
|
r->SetCharacterData(characterData);
|
|
r->SetSubtree(subtree);
|
|
r->SetAttributeOldValue(attributeOldValue);
|
|
r->SetCharacterDataOldValue(characterDataOldValue);
|
|
r->SetNativeAnonymousChildList(nativeAnonymousChildList);
|
|
r->SetAttributeFilter(filters);
|
|
r->SetAllAttributes(allAttrs);
|
|
r->SetAnimations(animations);
|
|
r->RemoveClones();
|
|
|
|
#ifdef DEBUG
|
|
for (int32_t i = 0; i < mReceivers.Count(); ++i) {
|
|
NS_WARN_IF_FALSE(mReceivers[i]->Target(),
|
|
"All the receivers should have a target!");
|
|
}
|
|
#endif
|
|
}
|
|
|
|
void
|
|
nsDOMMutationObserver::Disconnect()
|
|
{
|
|
for (int32_t i = 0; i < mReceivers.Count(); ++i) {
|
|
mReceivers[i]->Disconnect(false);
|
|
}
|
|
mReceivers.Clear();
|
|
mCurrentMutations.Clear();
|
|
ClearPendingRecords();
|
|
}
|
|
|
|
void
|
|
nsDOMMutationObserver::TakeRecords(
|
|
nsTArray<RefPtr<nsDOMMutationRecord> >& aRetVal)
|
|
{
|
|
aRetVal.Clear();
|
|
aRetVal.SetCapacity(mPendingMutationCount);
|
|
RefPtr<nsDOMMutationRecord> current;
|
|
current.swap(mFirstPendingMutation);
|
|
for (uint32_t i = 0; i < mPendingMutationCount; ++i) {
|
|
RefPtr<nsDOMMutationRecord> next;
|
|
current->mNext.swap(next);
|
|
if (!mMergeAttributeRecords ||
|
|
!MergeableAttributeRecord(aRetVal.SafeLastElement(nullptr),
|
|
current)) {
|
|
*aRetVal.AppendElement() = current.forget();
|
|
}
|
|
current.swap(next);
|
|
}
|
|
ClearPendingRecords();
|
|
}
|
|
|
|
void
|
|
nsDOMMutationObserver::GetObservingInfo(
|
|
nsTArray<Nullable<MutationObservingInfo>>& aResult,
|
|
mozilla::ErrorResult& aRv)
|
|
{
|
|
aResult.SetCapacity(mReceivers.Count());
|
|
for (int32_t i = 0; i < mReceivers.Count(); ++i) {
|
|
MutationObservingInfo& info = aResult.AppendElement()->SetValue();
|
|
nsMutationReceiver* mr = mReceivers[i];
|
|
info.mChildList = mr->ChildList();
|
|
info.mAttributes.Construct(mr->Attributes());
|
|
info.mCharacterData.Construct(mr->CharacterData());
|
|
info.mSubtree = mr->Subtree();
|
|
info.mAttributeOldValue.Construct(mr->AttributeOldValue());
|
|
info.mCharacterDataOldValue.Construct(mr->CharacterDataOldValue());
|
|
info.mNativeAnonymousChildList = mr->NativeAnonymousChildList();
|
|
info.mAnimations.Construct(mr->Animations());
|
|
nsCOMArray<nsIAtom>& filters = mr->AttributeFilter();
|
|
if (filters.Count()) {
|
|
info.mAttributeFilter.Construct();
|
|
mozilla::dom::Sequence<nsString>& filtersAsStrings =
|
|
info.mAttributeFilter.Value();
|
|
nsString* strings = filtersAsStrings.AppendElements(filters.Count(),
|
|
mozilla::fallible);
|
|
if (!strings) {
|
|
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
return;
|
|
}
|
|
for (int32_t j = 0; j < filters.Count(); ++j) {
|
|
filters[j]->ToString(strings[j]);
|
|
}
|
|
}
|
|
info.mObservedNode = mr->Target();
|
|
}
|
|
}
|
|
|
|
// static
|
|
already_AddRefed<nsDOMMutationObserver>
|
|
nsDOMMutationObserver::Constructor(const mozilla::dom::GlobalObject& aGlobal,
|
|
mozilla::dom::MutationCallback& aCb,
|
|
mozilla::ErrorResult& aRv)
|
|
{
|
|
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal.GetAsSupports());
|
|
if (!window) {
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
return nullptr;
|
|
}
|
|
MOZ_ASSERT(window->IsInnerWindow());
|
|
bool isChrome = nsContentUtils::IsChromeDoc(window->GetExtantDoc());
|
|
RefPtr<nsDOMMutationObserver> observer =
|
|
new nsDOMMutationObserver(window.forget(), aCb, isChrome);
|
|
return observer.forget();
|
|
}
|
|
|
|
|
|
bool
|
|
nsDOMMutationObserver::MergeableAttributeRecord(nsDOMMutationRecord* aOldRecord,
|
|
nsDOMMutationRecord* aRecord)
|
|
{
|
|
MOZ_ASSERT(mMergeAttributeRecords);
|
|
return
|
|
aOldRecord &&
|
|
aOldRecord->mType == nsGkAtoms::attributes &&
|
|
aOldRecord->mType == aRecord->mType &&
|
|
aOldRecord->mTarget == aRecord->mTarget &&
|
|
aOldRecord->mAttrName == aRecord->mAttrName &&
|
|
aOldRecord->mAttrNamespace.Equals(aRecord->mAttrNamespace);
|
|
}
|
|
|
|
void
|
|
nsDOMMutationObserver::HandleMutation()
|
|
{
|
|
NS_ASSERTION(nsContentUtils::IsSafeToRunScript(), "Whaat!");
|
|
NS_ASSERTION(mCurrentMutations.IsEmpty(),
|
|
"Still generating MutationRecords?");
|
|
|
|
mWaitingForRun = false;
|
|
|
|
for (int32_t i = 0; i < mReceivers.Count(); ++i) {
|
|
mReceivers[i]->RemoveClones();
|
|
}
|
|
mTransientReceivers.Clear();
|
|
|
|
nsPIDOMWindow* outer = mOwner->GetOuterWindow();
|
|
if (!mPendingMutationCount || !outer ||
|
|
outer->GetCurrentInnerWindow() != mOwner) {
|
|
ClearPendingRecords();
|
|
return;
|
|
}
|
|
|
|
mozilla::dom::Sequence<mozilla::OwningNonNull<nsDOMMutationRecord> >
|
|
mutations;
|
|
if (mutations.SetCapacity(mPendingMutationCount, mozilla::fallible)) {
|
|
// We can't use TakeRecords easily here, because it deals with a
|
|
// different type of array, and we want to optimize out any extra copying.
|
|
RefPtr<nsDOMMutationRecord> current;
|
|
current.swap(mFirstPendingMutation);
|
|
for (uint32_t i = 0; i < mPendingMutationCount; ++i) {
|
|
RefPtr<nsDOMMutationRecord> next;
|
|
current->mNext.swap(next);
|
|
if (!mMergeAttributeRecords ||
|
|
!MergeableAttributeRecord(mutations.Length() ?
|
|
mutations.LastElement().get() : nullptr,
|
|
current)) {
|
|
*mutations.AppendElement(mozilla::fallible) = current;
|
|
}
|
|
current.swap(next);
|
|
}
|
|
}
|
|
ClearPendingRecords();
|
|
|
|
mCallback->Call(this, mutations, *this);
|
|
}
|
|
|
|
class AsyncMutationHandler : public mozilla::Runnable
|
|
{
|
|
public:
|
|
NS_IMETHOD Run()
|
|
{
|
|
nsDOMMutationObserver::HandleMutations();
|
|
return NS_OK;
|
|
}
|
|
};
|
|
|
|
void
|
|
nsDOMMutationObserver::HandleMutationsInternal()
|
|
{
|
|
if (!nsContentUtils::IsSafeToRunScript()) {
|
|
nsContentUtils::AddScriptRunner(new AsyncMutationHandler());
|
|
return;
|
|
}
|
|
static RefPtr<nsDOMMutationObserver> sCurrentObserver;
|
|
if (sCurrentObserver && !sCurrentObserver->Suppressed()) {
|
|
// In normal cases sScheduledMutationObservers will be handled
|
|
// after previous mutations are handled. But in case some
|
|
// callback calls a sync API, which spins the eventloop, we need to still
|
|
// process other mutations happening during that sync call.
|
|
// This does *not* catch all cases, but should work for stuff running
|
|
// in separate tabs.
|
|
return;
|
|
}
|
|
|
|
nsTArray<RefPtr<nsDOMMutationObserver> >* suppressedObservers = nullptr;
|
|
|
|
while (sScheduledMutationObservers) {
|
|
AutoTArray<RefPtr<nsDOMMutationObserver>, 4>* observers =
|
|
sScheduledMutationObservers;
|
|
sScheduledMutationObservers = nullptr;
|
|
for (uint32_t i = 0; i < observers->Length(); ++i) {
|
|
sCurrentObserver = static_cast<nsDOMMutationObserver*>((*observers)[i]);
|
|
if (!sCurrentObserver->Suppressed()) {
|
|
sCurrentObserver->HandleMutation();
|
|
} else {
|
|
if (!suppressedObservers) {
|
|
suppressedObservers = new nsTArray<RefPtr<nsDOMMutationObserver> >;
|
|
}
|
|
if (!suppressedObservers->Contains(sCurrentObserver)) {
|
|
suppressedObservers->AppendElement(sCurrentObserver);
|
|
}
|
|
}
|
|
}
|
|
delete observers;
|
|
}
|
|
|
|
if (suppressedObservers) {
|
|
for (uint32_t i = 0; i < suppressedObservers->Length(); ++i) {
|
|
static_cast<nsDOMMutationObserver*>(suppressedObservers->ElementAt(i))->
|
|
RescheduleForRun();
|
|
}
|
|
delete suppressedObservers;
|
|
suppressedObservers = nullptr;
|
|
}
|
|
sCurrentObserver = nullptr;
|
|
}
|
|
|
|
nsDOMMutationRecord*
|
|
nsDOMMutationObserver::CurrentRecord(nsIAtom* aType)
|
|
{
|
|
NS_ASSERTION(sMutationLevel > 0, "Unexpected mutation level!");
|
|
|
|
while (mCurrentMutations.Length() < sMutationLevel) {
|
|
mCurrentMutations.AppendElement(static_cast<nsDOMMutationRecord*>(nullptr));
|
|
}
|
|
|
|
uint32_t last = sMutationLevel - 1;
|
|
if (!mCurrentMutations[last]) {
|
|
RefPtr<nsDOMMutationRecord> r = new nsDOMMutationRecord(aType, GetParentObject());
|
|
mCurrentMutations[last] = r;
|
|
AppendMutationRecord(r.forget());
|
|
ScheduleForRun();
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
MOZ_ASSERT(sCurrentlyHandlingObservers->Length() == sMutationLevel);
|
|
for (size_t i = 0; i < sCurrentlyHandlingObservers->Length(); ++i) {
|
|
MOZ_ASSERT(sCurrentlyHandlingObservers->ElementAt(i).Contains(this),
|
|
"MutationObserver should be added as an observer of all the "
|
|
"nested mutations!");
|
|
}
|
|
#endif
|
|
|
|
NS_ASSERTION(mCurrentMutations[last]->mType == aType,
|
|
"Unexpected MutationRecord type!");
|
|
|
|
return mCurrentMutations[last];
|
|
}
|
|
|
|
nsDOMMutationObserver::~nsDOMMutationObserver()
|
|
{
|
|
for (int32_t i = 0; i < mReceivers.Count(); ++i) {
|
|
mReceivers[i]->RemoveClones();
|
|
}
|
|
}
|
|
|
|
void
|
|
nsDOMMutationObserver::EnterMutationHandling()
|
|
{
|
|
++sMutationLevel;
|
|
}
|
|
|
|
// Leave the current mutation level (there can be several levels if in case
|
|
// of nested calls to the nsIMutationObserver methods).
|
|
// The most recent mutation record is removed from mCurrentMutations, so
|
|
// that is doesn't get modified anymore by receivers.
|
|
void
|
|
nsDOMMutationObserver::LeaveMutationHandling()
|
|
{
|
|
if (sCurrentlyHandlingObservers &&
|
|
sCurrentlyHandlingObservers->Length() == sMutationLevel) {
|
|
nsTArray<RefPtr<nsDOMMutationObserver> >& obs =
|
|
sCurrentlyHandlingObservers->ElementAt(sMutationLevel - 1);
|
|
for (uint32_t i = 0; i < obs.Length(); ++i) {
|
|
nsDOMMutationObserver* o =
|
|
static_cast<nsDOMMutationObserver*>(obs[i]);
|
|
if (o->mCurrentMutations.Length() == sMutationLevel) {
|
|
// It is already in pending mutations.
|
|
o->mCurrentMutations.RemoveElementAt(sMutationLevel - 1);
|
|
}
|
|
}
|
|
sCurrentlyHandlingObservers->RemoveElementAt(sMutationLevel - 1);
|
|
}
|
|
--sMutationLevel;
|
|
}
|
|
|
|
void
|
|
nsDOMMutationObserver::AddCurrentlyHandlingObserver(nsDOMMutationObserver* aObserver,
|
|
uint32_t aMutationLevel)
|
|
{
|
|
NS_ASSERTION(aMutationLevel > 0, "Unexpected mutation level!");
|
|
|
|
if (aMutationLevel > 1) {
|
|
// MutationObserver must be in the currently handling observer list
|
|
// in all the nested levels.
|
|
AddCurrentlyHandlingObserver(aObserver, aMutationLevel - 1);
|
|
}
|
|
|
|
if (!sCurrentlyHandlingObservers) {
|
|
sCurrentlyHandlingObservers =
|
|
new AutoTArray<AutoTArray<RefPtr<nsDOMMutationObserver>, 4>, 4>;
|
|
}
|
|
|
|
while (sCurrentlyHandlingObservers->Length() < aMutationLevel) {
|
|
sCurrentlyHandlingObservers->InsertElementAt(
|
|
sCurrentlyHandlingObservers->Length());
|
|
}
|
|
|
|
uint32_t index = aMutationLevel - 1;
|
|
if (!sCurrentlyHandlingObservers->ElementAt(index).Contains(aObserver)) {
|
|
sCurrentlyHandlingObservers->ElementAt(index).AppendElement(aObserver);
|
|
}
|
|
}
|
|
|
|
void
|
|
nsDOMMutationObserver::Shutdown()
|
|
{
|
|
delete sCurrentlyHandlingObservers;
|
|
sCurrentlyHandlingObservers = nullptr;
|
|
delete sScheduledMutationObservers;
|
|
sScheduledMutationObservers = nullptr;
|
|
}
|
|
|
|
nsAutoMutationBatch*
|
|
nsAutoMutationBatch::sCurrentBatch = nullptr;
|
|
|
|
void
|
|
nsAutoMutationBatch::Done()
|
|
{
|
|
if (sCurrentBatch != this) {
|
|
return;
|
|
}
|
|
|
|
sCurrentBatch = mPreviousBatch;
|
|
if (mObservers.IsEmpty()) {
|
|
nsDOMMutationObserver::LeaveMutationHandling();
|
|
// Nothing to do.
|
|
return;
|
|
}
|
|
|
|
uint32_t len = mObservers.Length();
|
|
for (uint32_t i = 0; i < len; ++i) {
|
|
nsDOMMutationObserver* ob = mObservers[i].mObserver;
|
|
bool wantsChildList = mObservers[i].mWantsChildList;
|
|
|
|
RefPtr<nsSimpleContentList> removedList;
|
|
if (wantsChildList) {
|
|
removedList = new nsSimpleContentList(mBatchTarget);
|
|
}
|
|
|
|
nsTArray<nsMutationReceiver*> allObservers;
|
|
ob->GetAllSubtreeObserversFor(mBatchTarget, allObservers);
|
|
|
|
int32_t j = mFromFirstToLast ? 0 : mRemovedNodes.Length() - 1;
|
|
int32_t end = mFromFirstToLast ? mRemovedNodes.Length() : -1;
|
|
for (; j != end; mFromFirstToLast ? ++j : --j) {
|
|
nsCOMPtr<nsIContent> removed = mRemovedNodes[j];
|
|
if (removedList) {
|
|
removedList->AppendElement(removed);
|
|
}
|
|
|
|
if (allObservers.Length()) {
|
|
nsCOMArray<nsMutationReceiver>* transientReceivers = nullptr;
|
|
ob->mTransientReceivers.Get(removed, &transientReceivers);
|
|
if (!transientReceivers) {
|
|
transientReceivers = new nsCOMArray<nsMutationReceiver>();
|
|
ob->mTransientReceivers.Put(removed, transientReceivers);
|
|
}
|
|
for (uint32_t k = 0; k < allObservers.Length(); ++k) {
|
|
nsMutationReceiver* r = allObservers[k];
|
|
nsMutationReceiver* orig = r->GetParent() ? r->GetParent() : r;
|
|
if (ob->GetReceiverFor(removed, false, false) != orig) {
|
|
// Make sure the elements which are removed from the
|
|
// subtree are kept in the same observation set.
|
|
nsMutationReceiver* tr;
|
|
if (orig->Animations()) {
|
|
tr = nsAnimationReceiver::Create(removed, orig);
|
|
} else {
|
|
tr = nsMutationReceiver::Create(removed, orig);
|
|
}
|
|
transientReceivers->AppendObject(tr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (wantsChildList && (mRemovedNodes.Length() || mAddedNodes.Length())) {
|
|
RefPtr<nsSimpleContentList> addedList =
|
|
new nsSimpleContentList(mBatchTarget);
|
|
for (uint32_t i = 0; i < mAddedNodes.Length(); ++i) {
|
|
addedList->AppendElement(mAddedNodes[i]);
|
|
}
|
|
RefPtr<nsDOMMutationRecord> m =
|
|
new nsDOMMutationRecord(nsGkAtoms::childList,
|
|
ob->GetParentObject());
|
|
m->mTarget = mBatchTarget;
|
|
m->mRemovedNodes = removedList;
|
|
m->mAddedNodes = addedList;
|
|
m->mPreviousSibling = mPrevSibling;
|
|
m->mNextSibling = mNextSibling;
|
|
ob->AppendMutationRecord(m.forget());
|
|
}
|
|
// Always schedule the observer so that transient receivers are
|
|
// removed correctly.
|
|
ob->ScheduleForRun();
|
|
}
|
|
nsDOMMutationObserver::LeaveMutationHandling();
|
|
}
|
|
|
|
nsAutoAnimationMutationBatch*
|
|
nsAutoAnimationMutationBatch::sCurrentBatch = nullptr;
|
|
|
|
void
|
|
nsAutoAnimationMutationBatch::Done()
|
|
{
|
|
if (sCurrentBatch != this) {
|
|
return;
|
|
}
|
|
|
|
sCurrentBatch = nullptr;
|
|
if (mObservers.IsEmpty()) {
|
|
nsDOMMutationObserver::LeaveMutationHandling();
|
|
// Nothing to do.
|
|
return;
|
|
}
|
|
|
|
mBatchTargets.Sort(TreeOrderComparator());
|
|
|
|
for (nsDOMMutationObserver* ob : mObservers) {
|
|
bool didAddRecords = false;
|
|
|
|
for (nsINode* target : mBatchTargets) {
|
|
EntryArray* entries = mEntryTable.Get(target);
|
|
MOZ_ASSERT(entries,
|
|
"Targets in entry table and targets list should match");
|
|
|
|
RefPtr<nsDOMMutationRecord> m =
|
|
new nsDOMMutationRecord(nsGkAtoms::animations, ob->GetParentObject());
|
|
m->mTarget = target;
|
|
|
|
for (const Entry& e : *entries) {
|
|
if (e.mState == eState_Added) {
|
|
m->mAddedAnimations.AppendElement(e.mAnimation);
|
|
} else if (e.mState == eState_Removed) {
|
|
m->mRemovedAnimations.AppendElement(e.mAnimation);
|
|
} else if (e.mState == eState_RemainedPresent && e.mChanged) {
|
|
m->mChangedAnimations.AppendElement(e.mAnimation);
|
|
}
|
|
}
|
|
|
|
if (!m->mAddedAnimations.IsEmpty() ||
|
|
!m->mChangedAnimations.IsEmpty() ||
|
|
!m->mRemovedAnimations.IsEmpty()) {
|
|
ob->AppendMutationRecord(m.forget());
|
|
didAddRecords = true;
|
|
}
|
|
}
|
|
|
|
if (didAddRecords) {
|
|
ob->ScheduleForRun();
|
|
}
|
|
}
|
|
nsDOMMutationObserver::LeaveMutationHandling();
|
|
}
|