2015-05-03 22:32:37 +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-06-27 17:01:55 +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/. */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Base class for all element classes; this provides an implementation
|
|
|
|
|
* of DOM Core's nsIDOMElement, implements nsIContent, provides
|
|
|
|
|
* utility methods for subclasses, and so forth.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-12-09 06:52:54 +04:00
|
|
|
|
#include "mozilla/ArrayUtils.h"
|
2013-12-06 22:17:19 +04:00
|
|
|
|
#include "mozilla/Likely.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
|
#include "mozilla/MemoryReporting.h"
|
2013-12-06 22:17:19 +04:00
|
|
|
|
#include "mozilla/StaticPtr.h"
|
2012-06-27 17:01:55 +04:00
|
|
|
|
|
|
|
|
|
#include "mozilla/dom/FragmentOrElement.h"
|
|
|
|
|
|
2014-03-17 10:56:54 +04:00
|
|
|
|
#include "mozilla/AsyncEventDispatcher.h"
|
2016-11-03 06:41:02 +03:00
|
|
|
|
#include "mozilla/DeclarationBlockInlines.h"
|
2015-11-26 10:53:54 +03:00
|
|
|
|
#include "mozilla/EffectSet.h"
|
2014-03-18 08:48:21 +04:00
|
|
|
|
#include "mozilla/EventDispatcher.h"
|
2014-03-17 10:56:53 +04:00
|
|
|
|
#include "mozilla/EventListenerManager.h"
|
2014-04-03 08:18:36 +04:00
|
|
|
|
#include "mozilla/EventStates.h"
|
2017-08-07 10:33:59 +03:00
|
|
|
|
#include "mozilla/HTMLEditor.h"
|
2016-12-14 06:11:28 +03:00
|
|
|
|
#include "mozilla/ServoRestyleManager.h"
|
2017-06-22 09:21:31 +03:00
|
|
|
|
#include "mozilla/TextEditor.h"
|
2017-04-06 09:51:29 +03:00
|
|
|
|
#include "mozilla/URLExtraData.h"
|
2013-04-09 19:29:44 +04:00
|
|
|
|
#include "mozilla/dom/Attr.h"
|
2012-06-27 17:01:55 +04:00
|
|
|
|
#include "nsDOMAttributeMap.h"
|
2017-10-03 01:05:19 +03:00
|
|
|
|
#include "nsAtom.h"
|
2014-06-20 06:01:40 +04:00
|
|
|
|
#include "mozilla/dom/NodeInfo.h"
|
2014-08-27 07:19:56 +04:00
|
|
|
|
#include "mozilla/dom/Event.h"
|
2013-01-13 01:53:01 +04:00
|
|
|
|
#include "nsIDocumentInlines.h"
|
2013-12-02 14:26:12 +04:00
|
|
|
|
#include "nsIDocumentEncoder.h"
|
2012-06-27 17:01:55 +04:00
|
|
|
|
#include "nsIDOMNodeList.h"
|
|
|
|
|
#include "nsIContentIterator.h"
|
|
|
|
|
#include "nsFocusManager.h"
|
|
|
|
|
#include "nsILinkHandler.h"
|
|
|
|
|
#include "nsIScriptGlobalObject.h"
|
|
|
|
|
#include "nsIURL.h"
|
|
|
|
|
#include "nsNetUtil.h"
|
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
|
#include "nsIAnonymousContentCreator.h"
|
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
|
#include "nsString.h"
|
|
|
|
|
#include "nsUnicharUtils.h"
|
|
|
|
|
#include "nsIDOMEvent.h"
|
|
|
|
|
#include "nsDOMCID.h"
|
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
|
#include "nsDOMCSSAttrDeclaration.h"
|
2014-02-28 03:04:46 +04:00
|
|
|
|
#include "nsNameSpaceManager.h"
|
2012-06-27 17:01:55 +04:00
|
|
|
|
#include "nsContentList.h"
|
|
|
|
|
#include "nsDOMTokenList.h"
|
|
|
|
|
#include "nsXBLPrototypeBinding.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
|
#include "nsError.h"
|
2012-06-27 17:01:55 +04:00
|
|
|
|
#include "nsDOMString.h"
|
|
|
|
|
#include "nsIScriptSecurityManager.h"
|
2014-02-27 14:51:15 +04:00
|
|
|
|
#include "mozilla/InternalMutationEvent.h"
|
2013-09-25 15:21:18 +04:00
|
|
|
|
#include "mozilla/MouseEvents.h"
|
2012-06-27 17:01:55 +04:00
|
|
|
|
#include "nsNodeUtils.h"
|
|
|
|
|
#include "nsDocument.h"
|
|
|
|
|
#include "nsAttrValueOrString.h"
|
|
|
|
|
#ifdef MOZ_XUL
|
|
|
|
|
#include "nsXULElement.h"
|
|
|
|
|
#endif /* MOZ_XUL */
|
|
|
|
|
#include "nsFrameSelection.h"
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
#include "nsRange.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "nsBindingManager.h"
|
|
|
|
|
#include "nsXBLBinding.h"
|
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
|
#include "nsPIBoxObject.h"
|
|
|
|
|
#include "nsSVGUtils.h"
|
|
|
|
|
#include "nsLayoutUtils.h"
|
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
|
#include "nsContentUtils.h"
|
2013-12-02 14:26:12 +04:00
|
|
|
|
#include "nsTextFragment.h"
|
|
|
|
|
#include "nsContentCID.h"
|
2012-06-27 17:01:55 +04:00
|
|
|
|
|
|
|
|
|
#include "nsIDOMEventListener.h"
|
|
|
|
|
#include "nsIWebNavigation.h"
|
|
|
|
|
#include "nsIBaseWindow.h"
|
|
|
|
|
#include "nsIWidget.h"
|
|
|
|
|
|
|
|
|
|
#include "nsNodeInfoManager.h"
|
|
|
|
|
#include "nsICategoryManager.h"
|
|
|
|
|
#include "nsGenericHTMLElement.h"
|
|
|
|
|
#include "nsContentCreatorFunctions.h"
|
|
|
|
|
#include "nsIControllers.h"
|
2013-01-03 17:23:11 +04:00
|
|
|
|
#include "nsView.h"
|
2013-01-05 07:12:24 +04:00
|
|
|
|
#include "nsViewManager.h"
|
2012-06-27 17:01:55 +04:00
|
|
|
|
#include "nsIScrollableFrame.h"
|
2013-05-02 02:50:08 +04:00
|
|
|
|
#include "ChildIterator.h"
|
2018-02-01 07:04:04 +03:00
|
|
|
|
#ifdef MOZ_OLD_STYLE
|
2012-06-27 17:01:55 +04:00
|
|
|
|
#include "mozilla/css/StyleRule.h" /* For nsCSSSelectorList */
|
|
|
|
|
#include "nsRuleProcessorData.h"
|
2018-02-01 07:04:04 +03:00
|
|
|
|
#endif
|
2012-06-27 17:01:55 +04:00
|
|
|
|
#include "nsTextNode.h"
|
2012-06-13 19:18:30 +04:00
|
|
|
|
#include "mozilla/dom/NodeListBinding.h"
|
2012-06-27 17:01:55 +04:00
|
|
|
|
|
|
|
|
|
#include "nsCCUncollectableMarker.h"
|
|
|
|
|
|
|
|
|
|
#include "mozAutoDocUpdate.h"
|
|
|
|
|
|
2016-08-15 09:43:21 +03:00
|
|
|
|
#include "mozilla/Sprintf.h"
|
2012-06-27 17:01:55 +04:00
|
|
|
|
#include "nsDOMMutationObserver.h"
|
|
|
|
|
#include "nsWrapperCacheInlines.h"
|
|
|
|
|
#include "nsCycleCollector.h"
|
|
|
|
|
#include "xpcpublic.h"
|
|
|
|
|
#include "nsIScriptError.h"
|
|
|
|
|
#include "mozilla/Telemetry.h"
|
|
|
|
|
|
|
|
|
|
#include "mozilla/CORSMode.h"
|
|
|
|
|
|
2013-12-02 14:26:11 +04:00
|
|
|
|
#include "mozilla/dom/ShadowRoot.h"
|
2017-10-19 09:31:36 +03:00
|
|
|
|
#include "mozilla/dom/HTMLSlotElement.h"
|
2013-12-02 14:26:12 +04:00
|
|
|
|
#include "mozilla/dom/HTMLTemplateElement.h"
|
2017-02-16 10:14:46 +03:00
|
|
|
|
#include "mozilla/dom/SVGUseElement.h"
|
2013-12-02 14:26:11 +04:00
|
|
|
|
|
2012-06-27 17:01:55 +04:00
|
|
|
|
#include "nsStyledElement.h"
|
2013-12-03 02:33:15 +04:00
|
|
|
|
#include "nsIContentInlines.h"
|
2015-05-19 13:33:00 +03:00
|
|
|
|
#include "nsChildContentList.h"
|
2018-02-01 07:04:04 +03:00
|
|
|
|
#include "mozilla/BloomFilter.h"
|
2012-06-27 17:01:55 +04:00
|
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
|
int32_t nsIContent::sTabFocusModel = eTabFocus_any;
|
2012-06-27 17:01:55 +04:00
|
|
|
|
bool nsIContent::sTabFocusModelAppliesToXUL = false;
|
2014-08-02 00:30:58 +04:00
|
|
|
|
uint64_t nsMutationGuard::sGeneration = 0;
|
2012-06-27 17:01:55 +04:00
|
|
|
|
|
|
|
|
|
nsIContent*
|
2012-10-10 23:04:42 +04:00
|
|
|
|
nsIContent::FindFirstNonChromeOnlyAccessContent() const
|
2012-06-27 17:01:55 +04:00
|
|
|
|
{
|
|
|
|
|
// This handles also nested native anonymous content.
|
|
|
|
|
for (const nsIContent *content = this; content;
|
|
|
|
|
content = content->GetBindingParent()) {
|
2012-10-10 23:04:42 +04:00
|
|
|
|
if (!content->ChromeOnlyAccess()) {
|
2012-06-27 17:01:55 +04:00
|
|
|
|
// Oops, this function signature allows casting const to
|
2018-01-03 15:59:54 +03:00
|
|
|
|
// non-const. (Then again, so does GetChildAt_Deprecated(0)->GetParent().)
|
2012-06-27 17:01:55 +04:00
|
|
|
|
return const_cast<nsIContent*>(content);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-02 11:53:44 +03:00
|
|
|
|
// https://dom.spec.whatwg.org/#dom-slotable-assignedslot
|
|
|
|
|
HTMLSlotElement*
|
|
|
|
|
nsIContent::GetAssignedSlotByMode() const
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Get slotable's assigned slot for the result of
|
|
|
|
|
* find a slot with open flag UNSET [1].
|
|
|
|
|
*
|
|
|
|
|
* [1] https://dom.spec.whatwg.org/#assign-a-slot
|
|
|
|
|
*/
|
|
|
|
|
HTMLSlotElement* slot = GetAssignedSlot();
|
|
|
|
|
if (!slot) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MOZ_ASSERT(GetParent());
|
|
|
|
|
MOZ_ASSERT(GetParent()->GetShadowRoot());
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Additional check for open flag SET:
|
|
|
|
|
* If slotable’s parent’s shadow root's mode is not "open",
|
|
|
|
|
* then return null.
|
|
|
|
|
*/
|
|
|
|
|
if (GetParent()->GetShadowRoot()->IsClosed()) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return slot;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-04 11:06:37 +03:00
|
|
|
|
nsINode*
|
2017-12-31 22:57:32 +03:00
|
|
|
|
nsIContent::GetFlattenedTreeParentForDocumentElementNAC() const
|
2017-12-04 11:06:37 +03:00
|
|
|
|
{
|
2017-12-31 22:57:32 +03:00
|
|
|
|
MOZ_ASSERT(IsRootOfNativeAnonymousSubtree());
|
|
|
|
|
MOZ_ASSERT(GetParent());
|
|
|
|
|
MOZ_ASSERT(GetParent() == OwnerDoc()->GetRootElement());
|
|
|
|
|
MOZ_ASSERT(!IsGeneratedContentContainerForAfter());
|
|
|
|
|
MOZ_ASSERT(!IsGeneratedContentContainerForBefore());
|
2017-04-22 23:36:15 +03:00
|
|
|
|
|
2017-12-31 22:57:32 +03:00
|
|
|
|
nsIContent* parent = GetParent();
|
|
|
|
|
AutoTArray<nsIContent*, 8> rootElementNAC;
|
|
|
|
|
nsContentUtils::AppendNativeAnonymousChildren(
|
|
|
|
|
parent, rootElementNAC, nsIContent::eSkipDocumentLevelNativeAnonymousContent);
|
|
|
|
|
const bool isDocLevelNAC = !rootElementNAC.Contains(this);
|
2017-09-29 22:06:21 +03:00
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2017-12-31 22:57:32 +03:00
|
|
|
|
{
|
|
|
|
|
// The code below would be slightly more direct, but it gets the wrong
|
|
|
|
|
// answer when the root scrollframe is being bootstrapped and we're
|
|
|
|
|
// trying to style the scrollbars (since GetRootScrollFrame() still returns
|
|
|
|
|
// null at that point). Verify that the results match otherwise.
|
|
|
|
|
AutoTArray<nsIContent*, 8> docLevelNAC;
|
|
|
|
|
nsContentUtils::AppendDocumentLevelNativeAnonymousContentTo(OwnerDoc(), docLevelNAC);
|
|
|
|
|
nsIPresShell* shell = OwnerDoc()->GetShell();
|
|
|
|
|
MOZ_ASSERT_IF(shell && shell->GetRootScrollFrame(),
|
|
|
|
|
isDocLevelNAC == docLevelNAC.Contains(this));
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
2017-12-31 22:57:32 +03:00
|
|
|
|
#endif
|
2013-05-02 02:50:08 +04:00
|
|
|
|
|
2017-12-31 22:57:32 +03:00
|
|
|
|
return isDocLevelNAC ? OwnerDocAsNode() : parent;
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsIContent::IMEState
|
|
|
|
|
nsIContent::GetDesiredIMEState()
|
|
|
|
|
{
|
|
|
|
|
if (!IsEditableInternal()) {
|
|
|
|
|
// Check for the special case where we're dealing with elements which don't
|
|
|
|
|
// have the editable flag set, but are readwrite (such as text controls).
|
|
|
|
|
if (!IsElement() ||
|
|
|
|
|
!AsElement()->State().HasState(NS_EVENT_STATE_MOZ_READWRITE)) {
|
|
|
|
|
return IMEState(IMEState::DISABLED);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// NOTE: The content for independent editors (e.g., input[type=text],
|
|
|
|
|
// textarea) must override this method, so, we don't need to worry about
|
|
|
|
|
// that here.
|
|
|
|
|
nsIContent *editableAncestor = GetEditingHost();
|
|
|
|
|
|
|
|
|
|
// This is in another editable content, use the result of it.
|
|
|
|
|
if (editableAncestor && editableAncestor != this) {
|
|
|
|
|
return editableAncestor->GetDesiredIMEState();
|
|
|
|
|
}
|
2014-10-02 22:45:44 +04:00
|
|
|
|
nsIDocument* doc = GetComposedDoc();
|
2012-06-27 17:01:55 +04:00
|
|
|
|
if (!doc) {
|
|
|
|
|
return IMEState(IMEState::DISABLED);
|
|
|
|
|
}
|
|
|
|
|
nsIPresShell* ps = doc->GetShell();
|
|
|
|
|
if (!ps) {
|
|
|
|
|
return IMEState(IMEState::DISABLED);
|
|
|
|
|
}
|
|
|
|
|
nsPresContext* pc = ps->GetPresContext();
|
|
|
|
|
if (!pc) {
|
|
|
|
|
return IMEState(IMEState::DISABLED);
|
|
|
|
|
}
|
2017-08-07 10:33:59 +03:00
|
|
|
|
HTMLEditor* htmlEditor = nsContentUtils::GetHTMLEditor(pc);
|
|
|
|
|
if (!htmlEditor) {
|
2012-06-27 17:01:55 +04:00
|
|
|
|
return IMEState(IMEState::DISABLED);
|
|
|
|
|
}
|
|
|
|
|
IMEState state;
|
2017-08-07 10:33:59 +03:00
|
|
|
|
htmlEditor->GetPreferredIMEState(&state);
|
2012-06-27 17:01:55 +04:00
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
nsIContent::HasIndependentSelection()
|
|
|
|
|
{
|
|
|
|
|
nsIFrame* frame = GetPrimaryFrame();
|
|
|
|
|
return (frame && frame->GetStateBits() & NS_FRAME_INDEPENDENT_SELECTION);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dom::Element*
|
|
|
|
|
nsIContent::GetEditingHost()
|
|
|
|
|
{
|
2013-04-03 05:14:24 +04:00
|
|
|
|
// If this isn't editable, return nullptr.
|
2016-01-22 09:18:47 +03:00
|
|
|
|
if (!IsEditableInternal()) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2012-06-27 17:01:55 +04:00
|
|
|
|
|
2014-10-02 22:45:44 +04:00
|
|
|
|
nsIDocument* doc = GetComposedDoc();
|
2016-01-22 09:18:47 +03:00
|
|
|
|
if (!doc) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-27 17:01:55 +04:00
|
|
|
|
// If this is in designMode, we should return <body>
|
2014-10-02 22:45:44 +04:00
|
|
|
|
if (doc->HasFlag(NODE_IS_EDITABLE) && !IsInShadowTree()) {
|
2012-06-27 17:01:55 +04:00
|
|
|
|
return doc->GetBodyElement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsIContent* content = this;
|
2013-01-11 12:43:01 +04:00
|
|
|
|
for (dom::Element* parent = GetParentElement();
|
2012-06-27 17:01:55 +04:00
|
|
|
|
parent && parent->HasFlag(NODE_IS_EDITABLE);
|
2013-01-11 12:43:01 +04:00
|
|
|
|
parent = content->GetParentElement()) {
|
2012-06-27 17:01:55 +04:00
|
|
|
|
content = parent;
|
|
|
|
|
}
|
|
|
|
|
return content->AsElement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
|
nsIContent::LookupNamespaceURIInternal(const nsAString& aNamespacePrefix,
|
|
|
|
|
nsAString& aNamespaceURI) const
|
|
|
|
|
{
|
|
|
|
|
if (aNamespacePrefix.EqualsLiteral("xml")) {
|
|
|
|
|
// Special-case for xml prefix
|
|
|
|
|
aNamespaceURI.AssignLiteral("http://www.w3.org/XML/1998/namespace");
|
|
|
|
|
return NS_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (aNamespacePrefix.EqualsLiteral("xmlns")) {
|
|
|
|
|
// Special-case for xmlns prefix
|
|
|
|
|
aNamespaceURI.AssignLiteral("http://www.w3.org/2000/xmlns/");
|
|
|
|
|
return NS_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
|
RefPtr<nsAtom> name;
|
2012-06-27 17:01:55 +04:00
|
|
|
|
if (!aNamespacePrefix.IsEmpty()) {
|
2016-03-29 02:09:43 +03:00
|
|
|
|
name = NS_Atomize(aNamespacePrefix);
|
2012-06-27 17:01:55 +04:00
|
|
|
|
NS_ENSURE_TRUE(name, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
name = nsGkAtoms::xmlns;
|
|
|
|
|
}
|
|
|
|
|
// Trace up the content parent chain looking for the namespace
|
|
|
|
|
// declaration that declares aNamespacePrefix.
|
|
|
|
|
const nsIContent* content = this;
|
|
|
|
|
do {
|
2017-12-05 20:05:51 +03:00
|
|
|
|
if (content->IsElement() &&
|
|
|
|
|
content->AsElement()->GetAttr(kNameSpaceID_XMLNS, name, aNamespaceURI))
|
2012-06-27 17:01:55 +04:00
|
|
|
|
return NS_OK;
|
|
|
|
|
} while ((content = content->GetParent()));
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
|
nsAtom*
|
2017-06-15 22:48:26 +03:00
|
|
|
|
nsIContent::GetLang() const
|
|
|
|
|
{
|
|
|
|
|
for (const auto* content = this; content; content = content->GetParent()) {
|
2017-12-05 20:05:51 +03:00
|
|
|
|
if (!content->IsElement()) {
|
2017-06-15 22:48:26 +03:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto* element = content->AsElement();
|
2017-12-05 20:05:51 +03:00
|
|
|
|
if (!element->GetAttrCount()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2017-06-15 22:48:26 +03:00
|
|
|
|
|
|
|
|
|
// xml:lang has precedence over lang on HTML elements (see
|
|
|
|
|
// XHTML1 section C.7).
|
|
|
|
|
const nsAttrValue* attr =
|
|
|
|
|
element->GetParsedAttr(nsGkAtoms::lang, kNameSpaceID_XML);
|
|
|
|
|
if (!attr && element->SupportsLangAttr()) {
|
|
|
|
|
attr = element->GetParsedAttr(nsGkAtoms::lang);
|
|
|
|
|
}
|
|
|
|
|
if (attr) {
|
|
|
|
|
MOZ_ASSERT(attr->Type() == nsAttrValue::eAtom);
|
|
|
|
|
MOZ_ASSERT(attr->GetAtomValue());
|
|
|
|
|
return attr->GetAtomValue();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-27 17:01:55 +04:00
|
|
|
|
already_AddRefed<nsIURI>
|
2013-09-25 01:56:52 +04:00
|
|
|
|
nsIContent::GetBaseURI(bool aTryUseXHRDocBaseURI) const
|
2012-06-27 17:01:55 +04:00
|
|
|
|
{
|
2017-02-16 10:14:46 +03:00
|
|
|
|
if (IsInAnonymousSubtree() && IsAnonymousContentInSVGUseSubtree()) {
|
|
|
|
|
nsIContent* bindingParent = GetBindingParent();
|
|
|
|
|
MOZ_ASSERT(bindingParent);
|
|
|
|
|
SVGUseElement* useElement = static_cast<SVGUseElement*>(bindingParent);
|
|
|
|
|
// XXX Ignore xml:base as we are removing it.
|
2017-08-02 05:07:58 +03:00
|
|
|
|
if (URLExtraData* data = useElement->GetContentURLData()) {
|
|
|
|
|
return do_AddRef(data->BaseURI());
|
|
|
|
|
}
|
2017-02-16 10:14:46 +03:00
|
|
|
|
}
|
|
|
|
|
|
2012-06-27 17:01:55 +04:00
|
|
|
|
nsIDocument* doc = OwnerDoc();
|
|
|
|
|
// Start with document base
|
2013-09-25 01:56:52 +04:00
|
|
|
|
nsCOMPtr<nsIURI> base = doc->GetBaseURI(aTryUseXHRDocBaseURI);
|
2012-06-27 17:01:55 +04:00
|
|
|
|
|
|
|
|
|
// Collect array of xml:base attribute values up the parent chain. This
|
|
|
|
|
// is slightly slower for the case when there are xml:base attributes, but
|
|
|
|
|
// faster for the far more common case of there not being any such
|
|
|
|
|
// attributes.
|
|
|
|
|
// Also check for SVG elements which require special handling
|
2016-02-02 18:36:30 +03:00
|
|
|
|
AutoTArray<nsString, 5> baseAttrs;
|
2012-06-27 17:01:55 +04:00
|
|
|
|
nsString attr;
|
|
|
|
|
const nsIContent *elem = this;
|
|
|
|
|
do {
|
|
|
|
|
// First check for SVG specialness (why is this SVG specific?)
|
2015-03-03 14:08:59 +03:00
|
|
|
|
if (elem->IsSVGElement()) {
|
2012-06-27 17:01:55 +04:00
|
|
|
|
nsIContent* bindingParent = elem->GetBindingParent();
|
|
|
|
|
if (bindingParent) {
|
2013-07-17 20:05:03 +04:00
|
|
|
|
nsXBLBinding* binding = bindingParent->GetXBLBinding();
|
2012-06-27 17:01:55 +04:00
|
|
|
|
if (binding) {
|
|
|
|
|
// XXX sXBL/XBL2 issue
|
|
|
|
|
// If this is an anonymous XBL element use the binding
|
2015-05-04 16:56:00 +03:00
|
|
|
|
// document for the base URI.
|
2012-06-27 17:01:55 +04:00
|
|
|
|
// XXX Will fail with xml:base
|
|
|
|
|
base = binding->PrototypeBinding()->DocURI();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Otherwise check for xml:base attribute
|
2017-12-07 21:13:50 +03:00
|
|
|
|
if (elem->IsElement()) {
|
|
|
|
|
elem->AsElement()->GetAttr(kNameSpaceID_XML, nsGkAtoms::base, attr);
|
|
|
|
|
if (!attr.IsEmpty()) {
|
|
|
|
|
baseAttrs.AppendElement(attr);
|
|
|
|
|
}
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
elem = elem->GetParent();
|
|
|
|
|
} while(elem);
|
2015-05-04 16:56:00 +03:00
|
|
|
|
|
2017-02-20 04:41:11 +03:00
|
|
|
|
if (!baseAttrs.IsEmpty()) {
|
|
|
|
|
doc->WarnOnceAbout(nsIDocument::eXMLBaseAttribute);
|
|
|
|
|
// Now resolve against all xml:base attrs
|
|
|
|
|
for (uint32_t i = baseAttrs.Length() - 1; i != uint32_t(-1); --i) {
|
|
|
|
|
nsCOMPtr<nsIURI> newBase;
|
|
|
|
|
nsresult rv = NS_NewURI(getter_AddRefs(newBase), baseAttrs[i],
|
2017-06-18 14:37:50 +03:00
|
|
|
|
doc->GetDocumentCharacterSet(), base);
|
2017-02-20 04:41:11 +03:00
|
|
|
|
// Do a security check, almost the same as nsDocument::SetBaseURL()
|
|
|
|
|
// Only need to do this on the final uri
|
|
|
|
|
if (NS_SUCCEEDED(rv) && i == 0) {
|
|
|
|
|
rv = nsContentUtils::GetSecurityManager()->
|
|
|
|
|
CheckLoadURIWithPrincipal(NodePrincipal(), newBase,
|
|
|
|
|
nsIScriptSecurityManager::STANDARD);
|
|
|
|
|
}
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
|
base.swap(newBase);
|
|
|
|
|
}
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.forget();
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-21 03:32:19 +03:00
|
|
|
|
nsIURI*
|
2017-10-06 07:45:33 +03:00
|
|
|
|
nsIContent::GetBaseURIForStyleAttr() const
|
2017-03-10 10:04:34 +03:00
|
|
|
|
{
|
|
|
|
|
if (IsInAnonymousSubtree() && IsAnonymousContentInSVGUseSubtree()) {
|
|
|
|
|
nsIContent* bindingParent = GetBindingParent();
|
|
|
|
|
MOZ_ASSERT(bindingParent);
|
|
|
|
|
SVGUseElement* useElement = static_cast<SVGUseElement*>(bindingParent);
|
2017-08-02 05:07:58 +03:00
|
|
|
|
if (URLExtraData* data = useElement->GetContentURLData()) {
|
|
|
|
|
return data->BaseURI();
|
|
|
|
|
}
|
2017-03-10 10:04:34 +03:00
|
|
|
|
}
|
|
|
|
|
// This also ignores the case that SVG inside XBL binding.
|
|
|
|
|
// But it is probably fine.
|
2017-03-21 03:32:19 +03:00
|
|
|
|
return OwnerDoc()->GetDocBaseURI();
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-06 00:23:49 +03:00
|
|
|
|
already_AddRefed<URLExtraData>
|
|
|
|
|
nsIContent::GetURLDataForStyleAttr(nsIPrincipal* aSubjectPrincipal) const
|
2017-04-06 09:51:29 +03:00
|
|
|
|
{
|
|
|
|
|
if (IsInAnonymousSubtree() && IsAnonymousContentInSVGUseSubtree()) {
|
|
|
|
|
nsIContent* bindingParent = GetBindingParent();
|
|
|
|
|
MOZ_ASSERT(bindingParent);
|
|
|
|
|
SVGUseElement* useElement = static_cast<SVGUseElement*>(bindingParent);
|
2017-08-02 05:07:58 +03:00
|
|
|
|
if (URLExtraData* data = useElement->GetContentURLData()) {
|
2017-11-06 00:23:49 +03:00
|
|
|
|
return do_AddRef(data);
|
2017-08-02 05:07:58 +03:00
|
|
|
|
}
|
2017-04-06 09:51:29 +03:00
|
|
|
|
}
|
2017-11-06 00:23:49 +03:00
|
|
|
|
if (aSubjectPrincipal && aSubjectPrincipal != NodePrincipal()) {
|
|
|
|
|
// TODO: Cache this?
|
|
|
|
|
return MakeAndAddRef<URLExtraData>(OwnerDoc()->GetDocBaseURI(),
|
|
|
|
|
OwnerDoc()->GetDocumentURI(),
|
|
|
|
|
aSubjectPrincipal);
|
|
|
|
|
}
|
2017-04-06 09:51:29 +03:00
|
|
|
|
// This also ignores the case that SVG inside XBL binding.
|
|
|
|
|
// But it is probably fine.
|
2017-11-06 00:23:49 +03:00
|
|
|
|
return do_AddRef(OwnerDoc()->DefaultStyleAttrURLData());
|
2017-04-06 09:51:29 +03:00
|
|
|
|
}
|
|
|
|
|
|
2012-06-27 17:01:55 +04:00
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
static inline JSObject*
|
|
|
|
|
GetJSObjectChild(nsWrapperCache* aCache)
|
|
|
|
|
{
|
2013-04-03 05:14:24 +04:00
|
|
|
|
return aCache->PreservingWrapper() ? aCache->GetWrapperPreserveColor() : nullptr;
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
2013-07-22 21:47:20 +04:00
|
|
|
|
NeedsScriptTraverse(nsINode* aNode)
|
2012-06-27 17:01:55 +04:00
|
|
|
|
{
|
2013-07-22 21:47:20 +04:00
|
|
|
|
return aNode->PreservingWrapper() && aNode->GetWrapperPreserveColor() &&
|
2017-01-25 04:39:37 +03:00
|
|
|
|
!aNode->HasKnownLiveWrapperAndDoesNotNeedTracing(aNode);
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
2017-08-11 05:12:17 +03:00
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsAttrChildContentList)
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsAttrChildContentList)
|
2012-06-27 17:01:55 +04:00
|
|
|
|
|
2017-08-11 05:12:17 +03:00
|
|
|
|
// If nsAttrChildContentList is changed so that any additional fields are
|
2012-06-27 17:01:55 +04:00
|
|
|
|
// traversed by the cycle collector, then CAN_SKIP must be updated to
|
|
|
|
|
// check that the additional fields are null.
|
2017-08-11 05:12:17 +03:00
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(nsAttrChildContentList)
|
2012-06-27 17:01:55 +04:00
|
|
|
|
|
2017-08-11 05:12:17 +03:00
|
|
|
|
// nsAttrChildContentList only ever has a single child, its wrapper, so if
|
2017-01-25 04:38:58 +03:00
|
|
|
|
// the wrapper is known-live, the list can't be part of a garbage cycle.
|
2017-08-11 05:12:17 +03:00
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(nsAttrChildContentList)
|
2017-01-25 04:38:58 +03:00
|
|
|
|
return tmp->HasKnownLiveWrapper();
|
2012-06-27 17:01:55 +04:00
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_END
|
|
|
|
|
|
2017-08-11 05:12:17 +03:00
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_BEGIN(nsAttrChildContentList)
|
2017-01-25 04:39:37 +03:00
|
|
|
|
return tmp->HasKnownLiveWrapperAndDoesNotNeedTracing(tmp);
|
2012-06-27 17:01:55 +04:00
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_END
|
|
|
|
|
|
|
|
|
|
// CanSkipThis returns false to avoid problems with incomplete unlinking.
|
2017-08-11 05:12:17 +03:00
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_BEGIN(nsAttrChildContentList)
|
2012-06-27 17:01:55 +04:00
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_END
|
|
|
|
|
|
2017-08-11 05:12:17 +03:00
|
|
|
|
NS_INTERFACE_TABLE_HEAD(nsAttrChildContentList)
|
2014-08-26 03:21:35 +04:00
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_TABLE_ENTRY
|
2017-08-11 05:12:17 +03:00
|
|
|
|
NS_INTERFACE_TABLE(nsAttrChildContentList, nsINodeList, nsIDOMNodeList)
|
|
|
|
|
NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(nsAttrChildContentList)
|
2012-06-27 17:01:55 +04:00
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
|
|
JSObject*
|
2017-08-11 05:12:17 +03:00
|
|
|
|
nsAttrChildContentList::WrapObject(JSContext *cx,
|
|
|
|
|
JS::Handle<JSObject*> aGivenProto)
|
2012-06-27 17:01:55 +04:00
|
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
|
return NodeListBinding::Wrap(cx, this, aGivenProto);
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2017-08-11 05:12:17 +03:00
|
|
|
|
nsAttrChildContentList::GetLength(uint32_t* aLength)
|
2012-06-27 17:01:55 +04:00
|
|
|
|
{
|
|
|
|
|
*aLength = mNode ? mNode->GetChildCount() : 0;
|
|
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2017-08-11 05:12:17 +03:00
|
|
|
|
nsAttrChildContentList::Item(uint32_t aIndex, nsIDOMNode** aReturn)
|
2012-06-27 17:01:55 +04:00
|
|
|
|
{
|
2012-10-13 16:50:24 +04:00
|
|
|
|
nsINode* node = Item(aIndex);
|
2012-06-27 17:01:55 +04:00
|
|
|
|
if (!node) {
|
|
|
|
|
*aReturn = nullptr;
|
|
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return CallQueryInterface(node, aReturn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsIContent*
|
2017-08-11 05:12:17 +03:00
|
|
|
|
nsAttrChildContentList::Item(uint32_t aIndex)
|
2012-06-27 17:01:55 +04:00
|
|
|
|
{
|
|
|
|
|
if (mNode) {
|
2018-01-03 15:59:54 +03:00
|
|
|
|
return mNode->GetChildAt_Deprecated(aIndex);
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
|
int32_t
|
2017-08-11 05:12:17 +03:00
|
|
|
|
nsAttrChildContentList::IndexOf(nsIContent* aContent)
|
2012-06-27 17:01:55 +04:00
|
|
|
|
{
|
|
|
|
|
if (mNode) {
|
2018-01-23 16:30:18 +03:00
|
|
|
|
return mNode->ComputeIndexOf(aContent);
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-21 11:11:56 +03:00
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
|
nsParentNodeChildContentList::GetLength(uint32_t* aLength)
|
|
|
|
|
{
|
|
|
|
|
if (!mIsCacheValid && !ValidateCache()) {
|
|
|
|
|
*aLength = 0;
|
|
|
|
|
return NS_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MOZ_ASSERT(mIsCacheValid);
|
|
|
|
|
|
|
|
|
|
*aLength = mCachedChildArray.Length();
|
|
|
|
|
return NS_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
|
nsParentNodeChildContentList::Item(uint32_t aIndex, nsIDOMNode** aReturn)
|
|
|
|
|
{
|
|
|
|
|
nsINode* node = Item(aIndex);
|
|
|
|
|
if (!node) {
|
|
|
|
|
*aReturn = nullptr;
|
|
|
|
|
return NS_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return CallQueryInterface(node, aReturn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsIContent*
|
|
|
|
|
nsParentNodeChildContentList::Item(uint32_t aIndex)
|
|
|
|
|
{
|
|
|
|
|
if (!mIsCacheValid && !ValidateCache()) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MOZ_ASSERT(mIsCacheValid);
|
|
|
|
|
|
|
|
|
|
return mCachedChildArray.SafeElementAt(aIndex, nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
|
nsParentNodeChildContentList::IndexOf(nsIContent* aContent)
|
|
|
|
|
{
|
|
|
|
|
if (!mIsCacheValid && !ValidateCache()) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MOZ_ASSERT(mIsCacheValid);
|
|
|
|
|
|
|
|
|
|
return mCachedChildArray.IndexOf(aContent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
nsParentNodeChildContentList::ValidateCache()
|
|
|
|
|
{
|
|
|
|
|
MOZ_ASSERT(!mIsCacheValid);
|
|
|
|
|
MOZ_ASSERT(mCachedChildArray.IsEmpty());
|
|
|
|
|
|
|
|
|
|
nsINode* parent = GetParentObject();
|
|
|
|
|
if (!parent) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (nsIContent* node = parent->GetFirstChild(); node;
|
|
|
|
|
node = node->GetNextSibling()) {
|
|
|
|
|
mCachedChildArray.AppendElement(node);
|
|
|
|
|
}
|
|
|
|
|
mIsCacheValid = true;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-27 17:01:55 +04:00
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
2012-10-16 15:51:00 +04:00
|
|
|
|
nsIHTMLCollection*
|
|
|
|
|
FragmentOrElement::Children()
|
2012-06-27 17:01:55 +04:00
|
|
|
|
{
|
2017-12-23 11:23:42 +03:00
|
|
|
|
nsDOMSlots* slots = DOMSlots();
|
2012-06-27 17:01:55 +04:00
|
|
|
|
|
2012-07-31 19:36:21 +04:00
|
|
|
|
if (!slots->mChildrenList) {
|
2015-05-04 16:56:00 +03:00
|
|
|
|
slots->mChildrenList = new nsContentList(this, kNameSpaceID_Wildcard,
|
2015-04-17 04:09:58 +03:00
|
|
|
|
nsGkAtoms::_asterisk, nsGkAtoms::_asterisk,
|
2012-07-31 19:36:21 +04:00
|
|
|
|
false);
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
2012-07-31 19:36:21 +04:00
|
|
|
|
|
|
|
|
|
return slots->mChildrenList;
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-07-31 19:36:21 +04:00
|
|
|
|
//----------------------------------------------------------------------
|
2012-06-27 17:01:55 +04:00
|
|
|
|
|
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
|
NS_IMPL_ISUPPORTS(nsNodeWeakReference,
|
|
|
|
|
nsIWeakReference)
|
2012-06-27 17:01:55 +04:00
|
|
|
|
|
2012-07-31 19:36:21 +04:00
|
|
|
|
nsNodeWeakReference::~nsNodeWeakReference()
|
2012-06-27 17:01:55 +04:00
|
|
|
|
{
|
2017-08-25 20:48:29 +03:00
|
|
|
|
nsINode* node = static_cast<nsINode*>(mObject);
|
|
|
|
|
|
|
|
|
|
if (node) {
|
|
|
|
|
NS_ASSERTION(node->Slots()->mWeakReference == this,
|
2012-07-31 19:36:21 +04:00
|
|
|
|
"Weak reference has wrong value");
|
2017-08-25 20:48:29 +03:00
|
|
|
|
node->Slots()->mWeakReference = nullptr;
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2017-08-25 20:48:29 +03:00
|
|
|
|
nsNodeWeakReference::QueryReferentFromScript(const nsIID& aIID, void** aInstancePtr)
|
2012-06-27 17:01:55 +04:00
|
|
|
|
{
|
2017-08-25 20:48:29 +03:00
|
|
|
|
return QueryReferent(aIID, aInstancePtr);
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-23 02:02:59 +04:00
|
|
|
|
size_t
|
|
|
|
|
nsNodeWeakReference::SizeOfOnlyThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
|
|
|
|
{
|
|
|
|
|
return aMallocSizeOf(this);
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-27 17:01:55 +04:00
|
|
|
|
|
2014-04-25 20:49:00 +04:00
|
|
|
|
NS_IMPL_CYCLE_COLLECTION(nsNodeSupportsWeakRefTearoff, mNode)
|
2012-06-27 17:01:55 +04:00
|
|
|
|
|
2012-07-31 19:36:21 +04:00
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsNodeSupportsWeakRefTearoff)
|
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
|
|
|
|
NS_INTERFACE_MAP_END_AGGREGATED(mNode)
|
2012-06-27 17:01:55 +04:00
|
|
|
|
|
2012-07-31 19:36:21 +04:00
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsNodeSupportsWeakRefTearoff)
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsNodeSupportsWeakRefTearoff)
|
2012-06-27 17:01:55 +04:00
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-07-31 19:36:21 +04:00
|
|
|
|
nsNodeSupportsWeakRefTearoff::GetWeakReference(nsIWeakReference** aInstancePtr)
|
2012-06-27 17:01:55 +04:00
|
|
|
|
{
|
2012-08-11 02:27:28 +04:00
|
|
|
|
nsINode::nsSlots* slots = mNode->Slots();
|
2012-07-31 19:36:21 +04:00
|
|
|
|
if (!slots->mWeakReference) {
|
|
|
|
|
slots->mWeakReference = new nsNodeWeakReference(mNode);
|
|
|
|
|
}
|
2012-06-27 17:01:55 +04:00
|
|
|
|
|
2012-07-31 19:36:21 +04:00
|
|
|
|
NS_ADDREF(*aInstancePtr = slots->mWeakReference);
|
|
|
|
|
|
|
|
|
|
return NS_OK;
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-31 19:36:21 +04:00
|
|
|
|
//----------------------------------------------------------------------
|
2017-07-22 08:29:07 +03:00
|
|
|
|
|
|
|
|
|
static const size_t MaxDOMSlotSizeAllowed =
|
|
|
|
|
#ifdef HAVE_64BIT_BUILD
|
|
|
|
|
128;
|
|
|
|
|
#else
|
|
|
|
|
64;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
static_assert(sizeof(nsINode::nsSlots) <= MaxDOMSlotSizeAllowed,
|
|
|
|
|
"DOM slots cannot be grown without consideration");
|
|
|
|
|
static_assert(sizeof(FragmentOrElement::nsDOMSlots) <= MaxDOMSlotSizeAllowed,
|
|
|
|
|
"DOM slots cannot be grown without consideration");
|
|
|
|
|
|
2017-12-23 11:23:42 +03:00
|
|
|
|
void
|
|
|
|
|
nsIContent::nsExtendedContentSlots::Unlink()
|
|
|
|
|
{
|
|
|
|
|
mXBLInsertionPoint = nullptr;
|
|
|
|
|
mContainingShadow = nullptr;
|
|
|
|
|
mAssignedSlot = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nsIContent::nsExtendedContentSlots::Traverse(nsCycleCollectionTraversalCallback& aCb)
|
|
|
|
|
{
|
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(aCb, "mExtendedSlots->mContainingShadow");
|
|
|
|
|
aCb.NoteXPCOMChild(NS_ISUPPORTS_CAST(nsIContent*, mContainingShadow));
|
|
|
|
|
|
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(aCb, "mExtendedSlots->mAssignedSlot");
|
|
|
|
|
aCb.NoteXPCOMChild(NS_ISUPPORTS_CAST(nsIContent*, mAssignedSlot.get()));
|
|
|
|
|
|
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(aCb, "mExtendedSlots->mXBLInsertionPoint");
|
|
|
|
|
aCb.NoteXPCOMChild(mXBLInsertionPoint.get());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsIContent::nsExtendedContentSlots::nsExtendedContentSlots()
|
|
|
|
|
: mBindingParent(nullptr)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsIContent::nsExtendedContentSlots::~nsExtendedContentSlots() = default;
|
|
|
|
|
|
2012-07-31 19:36:21 +04:00
|
|
|
|
FragmentOrElement::nsDOMSlots::nsDOMSlots()
|
2017-12-23 11:23:42 +03:00
|
|
|
|
: nsIContent::nsContentSlots(),
|
2017-07-18 01:25:49 +03:00
|
|
|
|
mDataset(nullptr)
|
2012-06-27 17:01:55 +04:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-31 19:36:21 +04:00
|
|
|
|
FragmentOrElement::nsDOMSlots::~nsDOMSlots()
|
2012-06-27 17:01:55 +04:00
|
|
|
|
{
|
2012-07-31 19:36:21 +04:00
|
|
|
|
if (mAttributeMap) {
|
|
|
|
|
mAttributeMap->DropReference();
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2017-12-23 11:23:42 +03:00
|
|
|
|
FragmentOrElement::nsDOMSlots::Traverse(nsCycleCollectionTraversalCallback& aCb)
|
2012-06-27 17:01:55 +04:00
|
|
|
|
{
|
2017-12-23 11:23:42 +03:00
|
|
|
|
nsIContent::nsContentSlots::Traverse(aCb);
|
2012-06-27 17:01:55 +04:00
|
|
|
|
|
2017-12-23 11:23:42 +03:00
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(aCb, "mSlots->mStyle");
|
|
|
|
|
aCb.NoteXPCOMChild(mStyle.get());
|
2017-06-16 03:04:00 +03:00
|
|
|
|
|
2017-12-23 11:23:42 +03:00
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(aCb, "mSlots->mAttributeMap");
|
|
|
|
|
aCb.NoteXPCOMChild(mAttributeMap.get());
|
2014-02-24 01:01:26 +04:00
|
|
|
|
|
2017-12-23 11:23:42 +03:00
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(aCb, "mSlots->mChildrenList");
|
|
|
|
|
aCb.NoteXPCOMChild(NS_ISUPPORTS_CAST(nsIDOMNodeList*, mChildrenList));
|
2017-02-22 21:45:13 +03:00
|
|
|
|
|
2017-12-23 11:23:42 +03:00
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(aCb, "mSlots->mClassList");
|
|
|
|
|
aCb.NoteXPCOMChild(mClassList.get());
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-31 19:36:21 +04:00
|
|
|
|
void
|
2017-07-18 01:25:49 +03:00
|
|
|
|
FragmentOrElement::nsDOMSlots::Unlink()
|
2012-06-27 17:01:55 +04:00
|
|
|
|
{
|
2017-12-23 11:23:42 +03:00
|
|
|
|
nsIContent::nsContentSlots::Unlink();
|
2012-07-31 19:36:21 +04:00
|
|
|
|
mStyle = nullptr;
|
|
|
|
|
if (mAttributeMap) {
|
|
|
|
|
mAttributeMap->DropReference();
|
|
|
|
|
mAttributeMap = nullptr;
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
2012-07-31 19:36:21 +04:00
|
|
|
|
mChildrenList = nullptr;
|
2014-03-28 18:36:47 +04:00
|
|
|
|
mClassList = nullptr;
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-30 20:43:47 +04:00
|
|
|
|
size_t
|
2013-06-23 16:03:39 +04:00
|
|
|
|
FragmentOrElement::nsDOMSlots::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
|
2012-09-30 20:43:47 +04:00
|
|
|
|
{
|
|
|
|
|
size_t n = aMallocSizeOf(this);
|
2017-07-18 01:25:49 +03:00
|
|
|
|
if (mExtendedSlots) {
|
|
|
|
|
n += aMallocSizeOf(mExtendedSlots.get());
|
|
|
|
|
}
|
2012-09-30 20:43:47 +04:00
|
|
|
|
|
|
|
|
|
if (mAttributeMap) {
|
|
|
|
|
n += mAttributeMap->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Measurement of the following members may be added later if DMD finds it is
|
|
|
|
|
// worthwhile:
|
|
|
|
|
// - Superclass members (nsINode::nsSlots)
|
|
|
|
|
// - mStyle
|
|
|
|
|
// - mDataSet
|
|
|
|
|
// - mSMILOverrideStyle
|
2015-11-09 10:57:16 +03:00
|
|
|
|
// - mSMILOverrideStyleDeclaration
|
2012-09-30 20:43:47 +04:00
|
|
|
|
// - mChildrenList
|
|
|
|
|
// - mClassList
|
|
|
|
|
|
|
|
|
|
// The following members are not measured:
|
|
|
|
|
// - mBindingParent / mControllers: because they're non-owning
|
|
|
|
|
return n;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-23 11:23:42 +03:00
|
|
|
|
FragmentOrElement::nsExtendedDOMSlots::nsExtendedDOMSlots() = default;
|
2017-07-18 01:25:49 +03:00
|
|
|
|
|
|
|
|
|
FragmentOrElement::nsExtendedDOMSlots::~nsExtendedDOMSlots()
|
|
|
|
|
{
|
|
|
|
|
nsCOMPtr<nsIFrameLoader> frameLoader = do_QueryInterface(mFrameLoaderOrOpener);
|
|
|
|
|
if (frameLoader) {
|
|
|
|
|
static_cast<nsFrameLoader*>(frameLoader.get())->Destroy();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-23 11:23:42 +03:00
|
|
|
|
void
|
|
|
|
|
FragmentOrElement::nsExtendedDOMSlots::Unlink()
|
|
|
|
|
{
|
|
|
|
|
nsIContent::nsExtendedContentSlots::Unlink();
|
|
|
|
|
|
|
|
|
|
// Don't clear mXBLBinding, it'll be done in
|
|
|
|
|
// BindingManager::RemovedFromDocument from FragmentOrElement::Unlink.
|
|
|
|
|
mSMILOverrideStyle = nullptr;
|
|
|
|
|
mControllers = nullptr;
|
|
|
|
|
mLabelsList = nullptr;
|
|
|
|
|
mShadowRoot = nullptr;
|
|
|
|
|
if (mCustomElementData) {
|
|
|
|
|
mCustomElementData->Unlink();
|
|
|
|
|
mCustomElementData = nullptr;
|
|
|
|
|
}
|
|
|
|
|
nsCOMPtr<nsIFrameLoader> frameLoader =
|
|
|
|
|
do_QueryInterface(mFrameLoaderOrOpener);
|
|
|
|
|
if (frameLoader) {
|
|
|
|
|
static_cast<nsFrameLoader*>(frameLoader.get())->Destroy();
|
|
|
|
|
}
|
|
|
|
|
mFrameLoaderOrOpener = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FragmentOrElement::nsExtendedDOMSlots::Traverse(nsCycleCollectionTraversalCallback& aCb)
|
|
|
|
|
{
|
|
|
|
|
nsIContent::nsExtendedContentSlots::Traverse(aCb);
|
|
|
|
|
|
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(aCb, "mExtendedSlots->mSMILOverrideStyle");
|
|
|
|
|
aCb.NoteXPCOMChild(mSMILOverrideStyle.get());
|
|
|
|
|
|
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(aCb, "mExtendedSlots->mControllers");
|
|
|
|
|
aCb.NoteXPCOMChild(mControllers);
|
|
|
|
|
|
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(aCb, "mExtendedSlots->mLabelsList");
|
|
|
|
|
aCb.NoteXPCOMChild(NS_ISUPPORTS_CAST(nsIDOMNodeList*, mLabelsList));
|
|
|
|
|
|
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(aCb, "mExtendedSlots->mShadowRoot");
|
|
|
|
|
aCb.NoteXPCOMChild(NS_ISUPPORTS_CAST(nsIContent*, mShadowRoot));
|
|
|
|
|
|
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(aCb, "mExtendedSlots->mXBLBinding");
|
|
|
|
|
aCb.NoteNativeChild(mXBLBinding,
|
|
|
|
|
NS_CYCLE_COLLECTION_PARTICIPANT(nsXBLBinding));
|
|
|
|
|
|
|
|
|
|
if (mCustomElementData) {
|
|
|
|
|
mCustomElementData->Traverse(aCb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(aCb, "mExtendedSlots->mFrameLoaderOrOpener");
|
|
|
|
|
aCb.NoteXPCOMChild(mFrameLoaderOrOpener);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
|
FragmentOrElement::FragmentOrElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2014-03-15 23:00:17 +04:00
|
|
|
|
: nsIContent(aNodeInfo)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
|
FragmentOrElement::FragmentOrElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
|
2012-07-31 19:36:21 +04:00
|
|
|
|
: nsIContent(aNodeInfo)
|
2012-06-27 17:01:55 +04:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-31 19:36:21 +04:00
|
|
|
|
FragmentOrElement::~FragmentOrElement()
|
2012-06-27 17:01:55 +04:00
|
|
|
|
{
|
2016-03-31 13:58:25 +03:00
|
|
|
|
NS_PRECONDITION(!IsInUncomposedDoc(),
|
2012-07-31 19:36:21 +04:00
|
|
|
|
"Please remove this from the document properly");
|
|
|
|
|
if (GetParent()) {
|
|
|
|
|
NS_RELEASE(mParent);
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
already_AddRefed<nsINodeList>
|
2012-08-22 19:56:38 +04:00
|
|
|
|
FragmentOrElement::GetChildren(uint32_t aFilter)
|
2012-06-27 17:01:55 +04:00
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
|
RefPtr<nsSimpleContentList> list = new nsSimpleContentList(this);
|
2014-07-16 22:41:57 +04:00
|
|
|
|
AllChildrenIterator iter(this, aFilter);
|
|
|
|
|
while (nsIContent* kid = iter.GetNextChild()) {
|
|
|
|
|
list->AppendElement(kid);
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-22 15:15:59 +04:00
|
|
|
|
return list.forget();
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static nsIContent*
|
2012-10-10 23:04:42 +04:00
|
|
|
|
FindChromeAccessOnlySubtreeOwner(nsIContent* aContent)
|
2012-06-27 17:01:55 +04:00
|
|
|
|
{
|
2012-10-10 23:04:42 +04:00
|
|
|
|
if (aContent->ChromeOnlyAccess()) {
|
|
|
|
|
bool chromeAccessOnly = false;
|
|
|
|
|
while (aContent && !chromeAccessOnly) {
|
|
|
|
|
chromeAccessOnly = aContent->IsRootOfChromeAccessOnlySubtree();
|
2012-06-27 17:01:55 +04:00
|
|
|
|
aContent = aContent->GetParent();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return aContent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsresult
|
2016-10-21 05:11:07 +03:00
|
|
|
|
nsIContent::GetEventTargetParent(EventChainPreVisitor& aVisitor)
|
2012-06-27 17:01:55 +04:00
|
|
|
|
{
|
|
|
|
|
//FIXME! Document how this event retargeting works, Bug 329124.
|
|
|
|
|
aVisitor.mCanHandle = true;
|
|
|
|
|
aVisitor.mMayHaveListenerManager = HasListenerManager();
|
|
|
|
|
|
|
|
|
|
// Don't propagate mouseover and mouseout events when mouse is moving
|
2012-10-10 23:04:42 +04:00
|
|
|
|
// inside chrome access only content.
|
|
|
|
|
bool isAnonForEvents = IsRootOfChromeAccessOnlySubtree();
|
2017-12-18 19:07:36 +03:00
|
|
|
|
aVisitor.mRootOfClosedTree = isAnonForEvents;
|
2015-08-29 02:58:32 +03:00
|
|
|
|
if ((aVisitor.mEvent->mMessage == eMouseOver ||
|
2015-08-29 02:58:32 +03:00
|
|
|
|
aVisitor.mEvent->mMessage == eMouseOut ||
|
2015-08-31 18:20:05 +03:00
|
|
|
|
aVisitor.mEvent->mMessage == ePointerOver ||
|
2015-08-31 18:20:05 +03:00
|
|
|
|
aVisitor.mEvent->mMessage == ePointerOut) &&
|
2012-06-27 17:01:55 +04:00
|
|
|
|
// Check if we should stop event propagation when event has just been
|
|
|
|
|
// dispatched or when we're about to propagate from
|
2014-08-27 07:19:56 +04:00
|
|
|
|
// chrome access only subtree or if we are about to propagate out of
|
|
|
|
|
// a shadow root to a shadow root host.
|
2016-04-18 19:33:23 +03:00
|
|
|
|
((this == aVisitor.mEvent->mOriginalTarget &&
|
2014-08-27 07:19:56 +04:00
|
|
|
|
!ChromeOnlyAccess()) || isAnonForEvents || GetShadowRoot())) {
|
2012-06-27 17:01:55 +04:00
|
|
|
|
nsCOMPtr<nsIContent> relatedTarget =
|
2017-12-18 20:08:11 +03:00
|
|
|
|
do_QueryInterface(aVisitor.mEvent->AsMouseEvent()->mRelatedTarget);
|
2012-06-27 17:01:55 +04:00
|
|
|
|
if (relatedTarget &&
|
|
|
|
|
relatedTarget->OwnerDoc() == OwnerDoc()) {
|
|
|
|
|
|
2014-08-27 07:19:56 +04:00
|
|
|
|
// In the web components case, we may need to stop propagation of events
|
|
|
|
|
// at shadow root host.
|
|
|
|
|
if (GetShadowRoot()) {
|
|
|
|
|
nsIContent* adjustedTarget =
|
|
|
|
|
Event::GetShadowRelatedTarget(this, relatedTarget);
|
|
|
|
|
if (this == adjustedTarget) {
|
2017-12-18 19:07:36 +03:00
|
|
|
|
aVisitor.SetParentTarget(nullptr, false);
|
2014-08-27 07:19:56 +04:00
|
|
|
|
aVisitor.mCanHandle = false;
|
|
|
|
|
return NS_OK;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-27 17:01:55 +04:00
|
|
|
|
// If current target is anonymous for events or we know that related
|
|
|
|
|
// target is descendant of an element which is anonymous for events,
|
|
|
|
|
// we may want to stop event propagation.
|
|
|
|
|
// If this is the original target, aVisitor.mRelatedTargetIsInAnon
|
|
|
|
|
// must be updated.
|
|
|
|
|
if (isAnonForEvents || aVisitor.mRelatedTargetIsInAnon ||
|
2016-04-18 19:33:23 +03:00
|
|
|
|
(aVisitor.mEvent->mOriginalTarget == this &&
|
2012-06-27 17:01:55 +04:00
|
|
|
|
(aVisitor.mRelatedTargetIsInAnon =
|
2012-10-10 23:04:42 +04:00
|
|
|
|
relatedTarget->ChromeOnlyAccess()))) {
|
|
|
|
|
nsIContent* anonOwner = FindChromeAccessOnlySubtreeOwner(this);
|
2012-06-27 17:01:55 +04:00
|
|
|
|
if (anonOwner) {
|
|
|
|
|
nsIContent* anonOwnerRelated =
|
2012-10-10 23:04:42 +04:00
|
|
|
|
FindChromeAccessOnlySubtreeOwner(relatedTarget);
|
2012-06-27 17:01:55 +04:00
|
|
|
|
if (anonOwnerRelated) {
|
|
|
|
|
// Note, anonOwnerRelated may still be inside some other
|
|
|
|
|
// native anonymous subtree. The case where anonOwner is still
|
|
|
|
|
// inside native anonymous subtree will be handled when event
|
|
|
|
|
// propagates up in the DOM tree.
|
|
|
|
|
while (anonOwner != anonOwnerRelated &&
|
2012-10-10 23:04:42 +04:00
|
|
|
|
anonOwnerRelated->ChromeOnlyAccess()) {
|
|
|
|
|
anonOwnerRelated = FindChromeAccessOnlySubtreeOwner(anonOwnerRelated);
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
if (anonOwner == anonOwnerRelated) {
|
|
|
|
|
#ifdef DEBUG_smaug
|
|
|
|
|
nsCOMPtr<nsIContent> originalTarget =
|
2016-04-18 19:33:23 +03:00
|
|
|
|
do_QueryInterface(aVisitor.mEvent->mOriginalTarget);
|
2012-06-27 17:01:55 +04:00
|
|
|
|
nsAutoString ot, ct, rt;
|
|
|
|
|
if (originalTarget) {
|
2015-03-03 17:13:48 +03:00
|
|
|
|
originalTarget->NodeInfo()->NameAtom()->ToString(ot);
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
2015-03-03 14:09:00 +03:00
|
|
|
|
NodeInfo()->NameAtom()->ToString(ct);
|
|
|
|
|
relatedTarget->NodeInfo()->NameAtom()->ToString(rt);
|
2012-06-27 17:01:55 +04:00
|
|
|
|
printf("Stopping %s propagation:"
|
|
|
|
|
"\n\toriginalTarget=%s \n\tcurrentTarget=%s %s"
|
|
|
|
|
"\n\trelatedTarget=%s %s \n%s",
|
2015-08-29 02:58:32 +03:00
|
|
|
|
(aVisitor.mEvent->mMessage == eMouseOver)
|
2012-06-27 17:01:55 +04:00
|
|
|
|
? "mouseover" : "mouseout",
|
|
|
|
|
NS_ConvertUTF16toUTF8(ot).get(),
|
|
|
|
|
NS_ConvertUTF16toUTF8(ct).get(),
|
|
|
|
|
isAnonForEvents
|
|
|
|
|
? "(is native anonymous)"
|
2012-10-10 23:04:42 +04:00
|
|
|
|
: (ChromeOnlyAccess()
|
2012-06-27 17:01:55 +04:00
|
|
|
|
? "(is in native anonymous subtree)" : ""),
|
|
|
|
|
NS_ConvertUTF16toUTF8(rt).get(),
|
2012-10-10 23:04:42 +04:00
|
|
|
|
relatedTarget->ChromeOnlyAccess()
|
2012-06-27 17:01:55 +04:00
|
|
|
|
? "(is in native anonymous subtree)" : "",
|
2012-10-10 23:04:42 +04:00
|
|
|
|
(originalTarget &&
|
|
|
|
|
relatedTarget->FindFirstNonChromeOnlyAccessContent() ==
|
|
|
|
|
originalTarget->FindFirstNonChromeOnlyAccessContent())
|
2012-06-27 17:01:55 +04:00
|
|
|
|
? "" : "Wrong event propagation!?!\n");
|
|
|
|
|
#endif
|
2017-12-18 19:07:36 +03:00
|
|
|
|
aVisitor.SetParentTarget(nullptr, false);
|
2012-06-27 17:01:55 +04:00
|
|
|
|
// Event should not propagate to non-anon content.
|
|
|
|
|
aVisitor.mCanHandle = isAnonForEvents;
|
|
|
|
|
return NS_OK;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-04 11:06:40 +03:00
|
|
|
|
// Event parent is the assigned slot, if node is assigned, or node's parent
|
|
|
|
|
// otherwise.
|
|
|
|
|
HTMLSlotElement* slot = GetAssignedSlot();
|
|
|
|
|
nsIContent* parent = slot ? slot : GetParent();
|
2014-08-27 07:19:56 +04:00
|
|
|
|
|
2012-06-27 17:01:55 +04:00
|
|
|
|
// Event may need to be retargeted if this is the root of a native
|
|
|
|
|
// anonymous content subtree or event is dispatched somewhere inside XBL.
|
|
|
|
|
if (isAnonForEvents) {
|
2012-10-19 04:22:35 +04:00
|
|
|
|
#ifdef DEBUG
|
2012-06-27 17:01:55 +04:00
|
|
|
|
// If a DOM event is explicitly dispatched using node.dispatchEvent(), then
|
|
|
|
|
// all the events are allowed even in the native anonymous content..
|
2016-04-18 19:33:23 +03:00
|
|
|
|
nsCOMPtr<nsIContent> t =
|
|
|
|
|
do_QueryInterface(aVisitor.mEvent->mOriginalTarget);
|
2012-10-19 04:22:35 +04:00
|
|
|
|
NS_ASSERTION(!t || !t->ChromeOnlyAccess() ||
|
2014-08-04 09:28:57 +04:00
|
|
|
|
aVisitor.mEvent->mClass != eMutationEventClass ||
|
2012-06-27 17:01:55 +04:00
|
|
|
|
aVisitor.mDOMEvent,
|
|
|
|
|
"Mutation event dispatched in native anonymous content!?!");
|
2012-10-19 04:22:35 +04:00
|
|
|
|
#endif
|
2012-06-27 17:01:55 +04:00
|
|
|
|
aVisitor.mEventTargetAtParent = parent;
|
|
|
|
|
} else if (parent && aVisitor.mOriginalTargetIsInAnon) {
|
2016-04-18 18:46:00 +03:00
|
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(aVisitor.mEvent->mTarget));
|
2012-06-27 17:01:55 +04:00
|
|
|
|
if (content && content->GetBindingParent() == parent) {
|
|
|
|
|
aVisitor.mEventTargetAtParent = parent;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// check for an anonymous parent
|
|
|
|
|
// XXX XBL2/sXBL issue
|
|
|
|
|
if (HasFlag(NODE_MAY_BE_IN_BINDING_MNGR)) {
|
2013-07-17 20:05:06 +04:00
|
|
|
|
nsIContent* insertionParent = GetXBLInsertionParent();
|
2012-06-27 17:01:55 +04:00
|
|
|
|
NS_ASSERTION(!(aVisitor.mEventTargetAtParent && insertionParent &&
|
|
|
|
|
aVisitor.mEventTargetAtParent != insertionParent),
|
|
|
|
|
"Retargeting and having insertion parent!");
|
|
|
|
|
if (insertionParent) {
|
|
|
|
|
parent = insertionParent;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-12 13:15:16 +03:00
|
|
|
|
if (!aVisitor.mEvent->mFlags.mComposedInNativeAnonymousContent &&
|
|
|
|
|
IsRootOfNativeAnonymousSubtree() && OwnerDoc() &&
|
|
|
|
|
OwnerDoc()->GetWindow()) {
|
2017-12-18 19:07:36 +03:00
|
|
|
|
aVisitor.SetParentTarget(OwnerDoc()->GetWindow()->GetParentTarget(), true);
|
2016-09-12 13:15:16 +03:00
|
|
|
|
} else if (parent) {
|
2017-12-18 19:07:36 +03:00
|
|
|
|
aVisitor.SetParentTarget(parent, false);
|
|
|
|
|
if (slot) {
|
|
|
|
|
ShadowRoot* root = slot->GetContainingShadow();
|
|
|
|
|
if (root && root->IsClosed()) {
|
|
|
|
|
aVisitor.mParentIsSlotInClosedTree = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-06-27 17:01:55 +04:00
|
|
|
|
} else {
|
2017-12-18 19:07:36 +03:00
|
|
|
|
aVisitor.SetParentTarget(GetComposedDoc(), false);
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
return NS_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-20 02:21:16 +04:00
|
|
|
|
bool
|
|
|
|
|
nsIContent::IsFocusable(int32_t* aTabIndex, bool aWithMouse)
|
|
|
|
|
{
|
|
|
|
|
bool focusable = IsFocusableInternal(aTabIndex, aWithMouse);
|
|
|
|
|
// Ensure that the return value and aTabIndex are consistent in the case
|
|
|
|
|
// we're in userfocusignored context.
|
|
|
|
|
if (focusable || (aTabIndex && *aTabIndex != -1)) {
|
|
|
|
|
if (nsContentUtils::IsUserFocusIgnored(this)) {
|
|
|
|
|
if (aTabIndex) {
|
|
|
|
|
*aTabIndex = -1;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return focusable;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
nsIContent::IsFocusableInternal(int32_t* aTabIndex, bool aWithMouse)
|
|
|
|
|
{
|
|
|
|
|
if (aTabIndex) {
|
|
|
|
|
*aTabIndex = -1; // Default, not tabbable
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-27 17:01:55 +04:00
|
|
|
|
bool
|
|
|
|
|
FragmentOrElement::IsLink(nsIURI** aURI) const
|
|
|
|
|
{
|
|
|
|
|
*aURI = nullptr;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-17 20:05:03 +04:00
|
|
|
|
nsXBLBinding*
|
2017-11-21 12:27:49 +03:00
|
|
|
|
FragmentOrElement::DoGetXBLBinding() const
|
2013-07-17 20:05:03 +04:00
|
|
|
|
{
|
2017-11-21 12:27:49 +03:00
|
|
|
|
MOZ_ASSERT(HasFlag(NODE_MAY_BE_IN_BINDING_MNGR));
|
2017-12-23 11:23:42 +03:00
|
|
|
|
const nsExtendedDOMSlots* slots = GetExistingExtendedDOMSlots();
|
|
|
|
|
return slots ? slots->mXBLBinding.get() : nullptr;
|
2013-07-17 20:05:03 +04:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-15 09:42:47 +03:00
|
|
|
|
nsIContent*
|
|
|
|
|
nsIContent::GetContainingShadowHost() const
|
|
|
|
|
{
|
|
|
|
|
if (mozilla::dom::ShadowRoot* shadow = GetContainingShadow()) {
|
|
|
|
|
return shadow->GetHost();
|
|
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-19 09:31:36 +03:00
|
|
|
|
void
|
2017-12-23 11:23:42 +03:00
|
|
|
|
nsIContent::SetAssignedSlot(HTMLSlotElement* aSlot)
|
2017-10-19 09:31:36 +03:00
|
|
|
|
{
|
2017-12-23 11:23:42 +03:00
|
|
|
|
ExtendedContentSlots()->mAssignedSlot = aSlot;
|
2017-10-19 09:31:36 +03:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-17 20:05:06 +04:00
|
|
|
|
void
|
2017-12-23 11:23:42 +03:00
|
|
|
|
nsIContent::SetXBLInsertionPoint(nsIContent* aContent)
|
2013-07-17 20:05:06 +04:00
|
|
|
|
{
|
2017-10-23 16:52:08 +03:00
|
|
|
|
nsCOMPtr<nsIContent> oldInsertionPoint = nullptr;
|
2013-07-17 20:05:06 +04:00
|
|
|
|
if (aContent) {
|
2017-12-23 11:23:42 +03:00
|
|
|
|
nsExtendedContentSlots* slots = ExtendedContentSlots();
|
2013-07-17 20:05:06 +04:00
|
|
|
|
SetFlags(NODE_MAY_BE_IN_BINDING_MNGR);
|
2017-10-23 16:52:08 +03:00
|
|
|
|
oldInsertionPoint = slots->mXBLInsertionPoint.forget();
|
|
|
|
|
slots->mXBLInsertionPoint = aContent;
|
2014-04-28 17:15:08 +04:00
|
|
|
|
} else {
|
2017-12-23 11:23:42 +03:00
|
|
|
|
if (nsExtendedContentSlots* slots = GetExistingExtendedContentSlots()) {
|
2017-10-23 16:52:08 +03:00
|
|
|
|
oldInsertionPoint = slots->mXBLInsertionPoint.forget();
|
|
|
|
|
slots->mXBLInsertionPoint = nullptr;
|
2014-04-28 17:15:08 +04:00
|
|
|
|
}
|
2013-07-17 20:05:06 +04:00
|
|
|
|
}
|
2016-12-14 06:11:28 +03:00
|
|
|
|
|
|
|
|
|
// We just changed the flattened tree, so any Servo style data is now invalid.
|
|
|
|
|
// We rely on nsXBLService::LoadBindings to re-traverse the subtree afterwards.
|
2017-10-23 16:52:08 +03:00
|
|
|
|
if (oldInsertionPoint != aContent &&
|
2017-09-23 01:02:59 +03:00
|
|
|
|
IsStyledByServo() && IsElement() && AsElement()->HasServoData()) {
|
2016-12-14 06:11:28 +03:00
|
|
|
|
ServoRestyleManager::ClearServoDataFromSubtree(AsElement());
|
|
|
|
|
}
|
2013-07-17 20:05:06 +04:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-25 17:59:42 +03:00
|
|
|
|
nsresult
|
|
|
|
|
FragmentOrElement::InsertChildBefore(nsIContent* aKid,
|
|
|
|
|
nsIContent* aBeforeThis,
|
|
|
|
|
bool aNotify)
|
|
|
|
|
{
|
|
|
|
|
NS_PRECONDITION(aKid, "null ptr");
|
|
|
|
|
|
|
|
|
|
int32_t index = aBeforeThis ? ComputeIndexOf(aBeforeThis) : GetChildCount();
|
|
|
|
|
MOZ_ASSERT(index >= 0);
|
|
|
|
|
|
|
|
|
|
return doInsertChildAt(aKid, index, aNotify, mAttrsAndChildren);
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-27 17:01:55 +04:00
|
|
|
|
nsresult
|
2018-01-23 16:30:18 +03:00
|
|
|
|
FragmentOrElement::InsertChildAt_Deprecated(nsIContent* aKid,
|
|
|
|
|
uint32_t aIndex,
|
|
|
|
|
bool aNotify)
|
2012-06-27 17:01:55 +04:00
|
|
|
|
{
|
|
|
|
|
NS_PRECONDITION(aKid, "null ptr");
|
|
|
|
|
|
|
|
|
|
return doInsertChildAt(aKid, aIndex, aNotify, mAttrsAndChildren);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2018-01-03 16:01:03 +03:00
|
|
|
|
FragmentOrElement::RemoveChildAt_Deprecated(uint32_t aIndex, bool aNotify)
|
2012-06-27 17:01:55 +04:00
|
|
|
|
{
|
|
|
|
|
nsCOMPtr<nsIContent> oldKid = mAttrsAndChildren.GetSafeChildAt(aIndex);
|
2018-01-03 16:01:03 +03:00
|
|
|
|
NS_ASSERTION(oldKid == GetChildAt_Deprecated(aIndex), "Unexpected child in RemoveChildAt_Deprecated");
|
2012-06-27 17:01:55 +04:00
|
|
|
|
|
|
|
|
|
if (oldKid) {
|
|
|
|
|
doRemoveChildAt(aIndex, aNotify, oldKid, mAttrsAndChildren);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-15 19:18:38 +03:00
|
|
|
|
void
|
|
|
|
|
FragmentOrElement::RemoveChildNode(nsIContent* aKid, bool aNotify)
|
|
|
|
|
{
|
2018-01-16 16:17:11 +03:00
|
|
|
|
// Let's keep the node alive.
|
|
|
|
|
nsCOMPtr<nsIContent> kungFuDeathGrip = aKid;
|
2018-01-23 16:30:18 +03:00
|
|
|
|
doRemoveChildAt(ComputeIndexOf(aKid), aNotify, aKid, mAttrsAndChildren);
|
2018-01-15 19:18:38 +03:00
|
|
|
|
}
|
|
|
|
|
|
2012-10-09 16:31:24 +04:00
|
|
|
|
void
|
2014-08-05 14:10:00 +04:00
|
|
|
|
FragmentOrElement::GetTextContentInternal(nsAString& aTextContent,
|
2017-01-18 07:52:29 +03:00
|
|
|
|
OOMReporter& aError)
|
2012-06-27 17:01:55 +04:00
|
|
|
|
{
|
2015-10-30 08:37:03 +03:00
|
|
|
|
if (!nsContentUtils::GetNodeTextContent(this, true, aTextContent, fallible)) {
|
2017-01-18 07:52:29 +03:00
|
|
|
|
aError.ReportOOM();
|
2014-08-05 14:10:00 +04:00
|
|
|
|
}
|
2012-07-31 19:36:21 +04:00
|
|
|
|
}
|
2012-06-27 17:01:55 +04:00
|
|
|
|
|
2012-10-09 16:31:24 +04:00
|
|
|
|
void
|
|
|
|
|
FragmentOrElement::SetTextContentInternal(const nsAString& aTextContent,
|
2017-11-08 01:01:21 +03:00
|
|
|
|
nsIPrincipal* aSubjectPrincipal,
|
2012-10-09 16:31:24 +04:00
|
|
|
|
ErrorResult& aError)
|
2012-07-31 19:36:21 +04:00
|
|
|
|
{
|
2012-10-09 16:31:24 +04:00
|
|
|
|
aError = nsContentUtils::SetNodeTextContent(this, aTextContent, false);
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FragmentOrElement::DestroyContent()
|
|
|
|
|
{
|
2017-07-11 22:57:38 +03:00
|
|
|
|
// Drop any servo data. We do this before the RemovedFromDocument call below
|
|
|
|
|
// so that it doesn't need to try to keep the style state sane when shuffling
|
|
|
|
|
// around the flattened tree.
|
|
|
|
|
if (IsElement() && AsElement()->HasServoData()) {
|
|
|
|
|
AsElement()->ClearServoData();
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-27 17:01:55 +04:00
|
|
|
|
nsIDocument *document = OwnerDoc();
|
2016-02-19 22:13:42 +03:00
|
|
|
|
document->BindingManager()->RemovedFromDocument(this, document,
|
|
|
|
|
nsBindingManager::eRunDtor);
|
2012-06-27 17:01:55 +04:00
|
|
|
|
document->ClearBoxObjectFor(this);
|
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint32_t i, count = mAttrsAndChildren.ChildCount();
|
2012-06-27 17:01:55 +04:00
|
|
|
|
for (i = 0; i < count; ++i) {
|
|
|
|
|
// The child can remove itself from the parent in BindToTree.
|
|
|
|
|
mAttrsAndChildren.ChildAt(i)->DestroyContent();
|
|
|
|
|
}
|
2015-02-24 17:41:43 +03:00
|
|
|
|
ShadowRoot* shadowRoot = GetShadowRoot();
|
|
|
|
|
if (shadowRoot) {
|
|
|
|
|
shadowRoot->DestroyContent();
|
|
|
|
|
}
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FragmentOrElement::SaveSubtreeState()
|
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint32_t i, count = mAttrsAndChildren.ChildCount();
|
2012-06-27 17:01:55 +04:00
|
|
|
|
for (i = 0; i < count; ++i) {
|
|
|
|
|
mAttrsAndChildren.ChildAt(i)->SaveSubtreeState();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
// Generic DOMNode implementations
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FragmentOrElement::FireNodeInserted(nsIDocument* aDoc,
|
|
|
|
|
nsINode* aParent,
|
|
|
|
|
nsTArray<nsCOMPtr<nsIContent> >& aNodes)
|
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint32_t count = aNodes.Length();
|
|
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
2012-06-27 17:01:55 +04:00
|
|
|
|
nsIContent* childContent = aNodes[i];
|
|
|
|
|
|
|
|
|
|
if (nsContentUtils::HasMutationListeners(childContent,
|
|
|
|
|
NS_EVENT_BITS_MUTATION_NODEINSERTED, aParent)) {
|
2015-09-07 17:55:51 +03:00
|
|
|
|
InternalMutationEvent mutation(true, eLegacyNodeInserted);
|
2012-06-27 17:01:55 +04:00
|
|
|
|
mutation.mRelatedNode = do_QueryInterface(aParent);
|
|
|
|
|
|
|
|
|
|
mozAutoSubtreeModified subtree(aDoc, aParent);
|
2014-03-17 10:56:54 +04:00
|
|
|
|
(new AsyncEventDispatcher(childContent, mutation))->RunDOMEventWhenSafe();
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
2015-07-02 13:34:00 +03:00
|
|
|
|
// nsISupports implementation
|
|
|
|
|
|
|
|
|
|
#define SUBTREE_UNBINDINGS_PER_RUNNABLE 500
|
|
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
|
class ContentUnbinder : public Runnable
|
2012-06-27 17:01:55 +04:00
|
|
|
|
{
|
2015-07-02 13:34:00 +03:00
|
|
|
|
public:
|
|
|
|
|
ContentUnbinder()
|
2017-02-11 09:11:48 +03:00
|
|
|
|
: Runnable("ContentUnbinder")
|
2015-07-02 13:34:00 +03:00
|
|
|
|
{
|
|
|
|
|
mLast = this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~ContentUnbinder()
|
|
|
|
|
{
|
|
|
|
|
Run();
|
|
|
|
|
}
|
2012-06-27 17:01:55 +04:00
|
|
|
|
|
2015-07-02 13:34:00 +03:00
|
|
|
|
void UnbindSubtree(nsIContent* aNode)
|
2012-06-27 17:01:55 +04:00
|
|
|
|
{
|
2018-01-30 07:10:53 +03:00
|
|
|
|
if (aNode->NodeType() != nsINode::ELEMENT_NODE &&
|
|
|
|
|
aNode->NodeType() != nsINode::DOCUMENT_FRAGMENT_NODE) {
|
2013-08-28 02:39:02 +04:00
|
|
|
|
return;
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
FragmentOrElement* container = static_cast<FragmentOrElement*>(aNode);
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint32_t childCount = container->mAttrsAndChildren.ChildCount();
|
2012-06-27 17:01:55 +04:00
|
|
|
|
if (childCount) {
|
2017-10-23 10:04:14 +03:00
|
|
|
|
// Invalidate cached array of child nodes
|
|
|
|
|
container->InvalidateChildNodes();
|
|
|
|
|
|
2012-06-27 17:01:55 +04:00
|
|
|
|
while (childCount-- > 0) {
|
|
|
|
|
// Hold a strong ref to the node when we remove it, because we may be
|
|
|
|
|
// the last reference to it. We need to call TakeChildAt() and
|
|
|
|
|
// update mFirstChild before calling UnbindFromTree, since this last
|
|
|
|
|
// can notify various observers and they should really see consistent
|
|
|
|
|
// tree state.
|
2017-04-19 03:56:45 +03:00
|
|
|
|
// If this code changes, change the corresponding code in
|
|
|
|
|
// FragmentOrElement's and nsDocument's unlink impls.
|
2012-06-27 17:01:55 +04:00
|
|
|
|
nsCOMPtr<nsIContent> child =
|
|
|
|
|
container->mAttrsAndChildren.TakeChildAt(childCount);
|
|
|
|
|
if (childCount == 0) {
|
|
|
|
|
container->mFirstChild = nullptr;
|
|
|
|
|
}
|
|
|
|
|
UnbindSubtree(child);
|
|
|
|
|
child->UnbindFromTree();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-08 05:18:10 +03:00
|
|
|
|
NS_IMETHOD Run() override
|
2012-06-27 17:01:55 +04:00
|
|
|
|
{
|
2015-07-02 13:34:00 +03:00
|
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
|
|
|
|
uint32_t len = mSubtreeRoots.Length();
|
|
|
|
|
if (len) {
|
|
|
|
|
for (uint32_t i = 0; i < len; ++i) {
|
|
|
|
|
UnbindSubtree(mSubtreeRoots[i]);
|
|
|
|
|
}
|
|
|
|
|
mSubtreeRoots.Clear();
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
2015-07-02 13:34:00 +03:00
|
|
|
|
nsCycleCollector_dispatchDeferredDeletion();
|
|
|
|
|
if (this == sContentUnbinder) {
|
|
|
|
|
sContentUnbinder = nullptr;
|
|
|
|
|
if (mNext) {
|
2015-10-18 08:24:48 +03:00
|
|
|
|
RefPtr<ContentUnbinder> next;
|
2015-07-02 13:34:00 +03:00
|
|
|
|
next.swap(mNext);
|
|
|
|
|
sContentUnbinder = next;
|
|
|
|
|
next->mLast = mLast;
|
|
|
|
|
mLast = nullptr;
|
2017-05-25 01:06:32 +03:00
|
|
|
|
NS_IdleDispatchToCurrentThread(next.forget());
|
2015-07-02 13:34:00 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return NS_OK;
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-02 13:34:00 +03:00
|
|
|
|
static void UnbindAll()
|
2012-06-27 17:01:55 +04:00
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
|
RefPtr<ContentUnbinder> ub = sContentUnbinder;
|
2015-07-02 13:34:00 +03:00
|
|
|
|
sContentUnbinder = nullptr;
|
|
|
|
|
while (ub) {
|
|
|
|
|
ub->Run();
|
|
|
|
|
ub = ub->mNext;
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
2015-07-02 13:34:00 +03:00
|
|
|
|
}
|
2012-06-27 17:01:55 +04:00
|
|
|
|
|
2015-07-02 13:34:00 +03:00
|
|
|
|
static void Append(nsIContent* aSubtreeRoot)
|
|
|
|
|
{
|
|
|
|
|
if (!sContentUnbinder) {
|
|
|
|
|
sContentUnbinder = new ContentUnbinder();
|
|
|
|
|
nsCOMPtr<nsIRunnable> e = sContentUnbinder;
|
2017-05-25 01:06:32 +03:00
|
|
|
|
NS_IdleDispatchToCurrentThread(e.forget());
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-02 13:34:00 +03:00
|
|
|
|
if (sContentUnbinder->mLast->mSubtreeRoots.Length() >=
|
|
|
|
|
SUBTREE_UNBINDINGS_PER_RUNNABLE) {
|
|
|
|
|
sContentUnbinder->mLast->mNext = new ContentUnbinder();
|
|
|
|
|
sContentUnbinder->mLast = sContentUnbinder->mLast->mNext;
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
2015-07-02 13:34:00 +03:00
|
|
|
|
sContentUnbinder->mLast->mSubtreeRoots.AppendElement(aSubtreeRoot);
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-02 13:34:00 +03:00
|
|
|
|
private:
|
2016-02-02 18:36:30 +03:00
|
|
|
|
AutoTArray<nsCOMPtr<nsIContent>,
|
2015-07-02 13:34:00 +03:00
|
|
|
|
SUBTREE_UNBINDINGS_PER_RUNNABLE> mSubtreeRoots;
|
2015-10-18 08:24:48 +03:00
|
|
|
|
RefPtr<ContentUnbinder> mNext;
|
2015-07-02 13:34:00 +03:00
|
|
|
|
ContentUnbinder* mLast;
|
|
|
|
|
static ContentUnbinder* sContentUnbinder;
|
2012-06-27 17:01:55 +04:00
|
|
|
|
};
|
|
|
|
|
|
2015-07-02 13:34:00 +03:00
|
|
|
|
ContentUnbinder* ContentUnbinder::sContentUnbinder = nullptr;
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FragmentOrElement::ClearContentUnbinder()
|
|
|
|
|
{
|
|
|
|
|
ContentUnbinder::UnbindAll();
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(FragmentOrElement)
|
|
|
|
|
|
2012-06-27 17:01:55 +04:00
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(FragmentOrElement)
|
|
|
|
|
nsINode::Unlink(tmp);
|
|
|
|
|
|
2014-04-29 22:37:02 +04:00
|
|
|
|
// The XBL binding is removed by RemoveFromBindingManagerRunnable
|
|
|
|
|
// which is dispatched in UnbindFromTree.
|
|
|
|
|
|
2012-06-27 17:01:55 +04:00
|
|
|
|
if (tmp->HasProperties()) {
|
2017-10-06 06:42:55 +03:00
|
|
|
|
if (tmp->IsElement()) {
|
|
|
|
|
Element* elem = tmp->AsElement();
|
|
|
|
|
elem->UnlinkIntersectionObservers();
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-03 14:08:59 +03:00
|
|
|
|
if (tmp->IsHTMLElement() || tmp->IsSVGElement()) {
|
2017-10-27 02:31:13 +03:00
|
|
|
|
nsStaticAtom*** props = Element::HTMLSVGPropertiesToTraverseAndUnlink();
|
2014-03-28 18:36:47 +04:00
|
|
|
|
for (uint32_t i = 0; props[i]; ++i) {
|
|
|
|
|
tmp->DeleteProperty(*props[i]);
|
|
|
|
|
}
|
2016-01-18 07:40:12 +03:00
|
|
|
|
if (tmp->MayHaveAnimations()) {
|
2017-10-03 01:05:19 +03:00
|
|
|
|
nsAtom** effectProps = EffectSet::GetEffectSetPropertyAtoms();
|
2016-01-18 07:40:12 +03:00
|
|
|
|
for (uint32_t i = 0; effectProps[i]; ++i) {
|
|
|
|
|
tmp->DeleteProperty(effectProps[i]);
|
|
|
|
|
}
|
2015-11-26 10:53:54 +03:00
|
|
|
|
}
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Unlink child content (and unbind our subtree).
|
|
|
|
|
if (tmp->UnoptimizableCCNode() || !nsCCUncollectableMarker::sGeneration) {
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint32_t childCount = tmp->mAttrsAndChildren.ChildCount();
|
2012-06-27 17:01:55 +04:00
|
|
|
|
if (childCount) {
|
|
|
|
|
// Don't allow script to run while we're unbinding everything.
|
|
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
|
|
|
|
while (childCount-- > 0) {
|
|
|
|
|
// Hold a strong ref to the node when we remove it, because we may be
|
|
|
|
|
// the last reference to it. We need to call TakeChildAt() and
|
|
|
|
|
// update mFirstChild before calling UnbindFromTree, since this last
|
|
|
|
|
// can notify various observers and they should really see consistent
|
|
|
|
|
// tree state.
|
2017-04-19 03:56:45 +03:00
|
|
|
|
// If this code changes, change the corresponding code in nsDocument's
|
|
|
|
|
// unlink impl and ContentUnbinder::UnbindSubtree.
|
2012-06-27 17:01:55 +04:00
|
|
|
|
nsCOMPtr<nsIContent> child = tmp->mAttrsAndChildren.TakeChildAt(childCount);
|
|
|
|
|
if (childCount == 0) {
|
|
|
|
|
tmp->mFirstChild = nullptr;
|
|
|
|
|
}
|
|
|
|
|
child->UnbindFromTree();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (!tmp->GetParent() && tmp->mAttrsAndChildren.ChildCount()) {
|
|
|
|
|
ContentUnbinder::Append(tmp);
|
|
|
|
|
} /* else {
|
|
|
|
|
The subtree root will end up to a ContentUnbinder, and that will
|
|
|
|
|
unbind the child nodes.
|
|
|
|
|
} */
|
|
|
|
|
|
2014-09-27 02:07:40 +04:00
|
|
|
|
// Clear flag here because unlinking slots will clear the
|
|
|
|
|
// containing shadow root pointer.
|
|
|
|
|
tmp->UnsetFlags(NODE_IS_IN_SHADOW_TREE);
|
|
|
|
|
|
2016-02-19 22:13:42 +03:00
|
|
|
|
nsIDocument* doc = tmp->OwnerDoc();
|
|
|
|
|
doc->BindingManager()->RemovedFromDocument(tmp, doc,
|
|
|
|
|
nsBindingManager::eDoNotRunDtor);
|
2012-06-27 17:01:55 +04:00
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
2013-05-29 03:58:29 +04:00
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(FragmentOrElement)
|
2012-06-27 17:01:55 +04:00
|
|
|
|
|
|
|
|
|
void
|
2017-10-03 01:05:19 +03:00
|
|
|
|
FragmentOrElement::MarkUserData(void* aObject, nsAtom* aKey, void* aChild,
|
2012-06-27 17:01:55 +04:00
|
|
|
|
void* aData)
|
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint32_t* gen = static_cast<uint32_t*>(aData);
|
2012-06-27 17:01:55 +04:00
|
|
|
|
xpc_MarkInCCGeneration(static_cast<nsISupports*>(aChild), *gen);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FragmentOrElement::MarkNodeChildren(nsINode* aNode)
|
|
|
|
|
{
|
|
|
|
|
JSObject* o = GetJSObjectChild(aNode);
|
2013-09-09 07:28:48 +04:00
|
|
|
|
if (o) {
|
|
|
|
|
JS::ExposeObjectToActiveJS(o);
|
|
|
|
|
}
|
2012-06-27 17:01:55 +04:00
|
|
|
|
|
2014-03-17 10:56:53 +04:00
|
|
|
|
EventListenerManager* elm = aNode->GetExistingListenerManager();
|
2012-06-27 17:01:55 +04:00
|
|
|
|
if (elm) {
|
2012-10-17 05:22:02 +04:00
|
|
|
|
elm->MarkForCC();
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (aNode->HasProperties()) {
|
|
|
|
|
nsIDocument* ownerDoc = aNode->OwnerDoc();
|
|
|
|
|
ownerDoc->PropertyTable(DOM_USER_DATA)->
|
|
|
|
|
Enumerate(aNode, FragmentOrElement::MarkUserData,
|
|
|
|
|
&nsCCUncollectableMarker::sGeneration);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsINode*
|
|
|
|
|
FindOptimizableSubtreeRoot(nsINode* aNode)
|
|
|
|
|
{
|
|
|
|
|
nsINode* p;
|
2012-10-09 16:31:24 +04:00
|
|
|
|
while ((p = aNode->GetParentNode())) {
|
2012-06-27 17:01:55 +04:00
|
|
|
|
if (aNode->UnoptimizableCCNode()) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
aNode = p;
|
|
|
|
|
}
|
2013-12-06 22:17:19 +04:00
|
|
|
|
|
2012-06-27 17:01:55 +04:00
|
|
|
|
if (aNode->UnoptimizableCCNode()) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
return aNode;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-06 22:17:19 +04:00
|
|
|
|
StaticAutoPtr<nsTHashtable<nsPtrHashKey<nsINode>>> gCCBlackMarkedNodes;
|
2012-06-27 17:01:55 +04:00
|
|
|
|
|
2013-12-06 22:17:19 +04:00
|
|
|
|
static void
|
2012-06-27 17:01:55 +04:00
|
|
|
|
ClearBlackMarkedNodes()
|
|
|
|
|
{
|
|
|
|
|
if (!gCCBlackMarkedNodes) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-07-22 19:42:01 +03:00
|
|
|
|
for (auto iter = gCCBlackMarkedNodes->ConstIter(); !iter.Done();
|
|
|
|
|
iter.Next()) {
|
|
|
|
|
nsINode* n = iter.Get()->GetKey();
|
|
|
|
|
n->SetCCMarkedRoot(false);
|
|
|
|
|
n->SetInCCBlackTree(false);
|
|
|
|
|
}
|
2012-06-27 17:01:55 +04:00
|
|
|
|
gCCBlackMarkedNodes = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-06 22:17:19 +04:00
|
|
|
|
// static
|
|
|
|
|
void
|
|
|
|
|
FragmentOrElement::RemoveBlackMarkedNode(nsINode* aNode)
|
|
|
|
|
{
|
|
|
|
|
if (!gCCBlackMarkedNodes) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
gCCBlackMarkedNodes->RemoveEntry(aNode);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-18 22:50:45 +03:00
|
|
|
|
static bool
|
|
|
|
|
IsCertainlyAliveNode(nsINode* aNode, nsIDocument* aDoc)
|
|
|
|
|
{
|
|
|
|
|
MOZ_ASSERT(aNode->GetUncomposedDoc() == aDoc);
|
|
|
|
|
|
|
|
|
|
// Marked to be in-CC-generation or if the document is an svg image that's
|
|
|
|
|
// being kept alive by the image cache. (Note that an svg image's internal
|
|
|
|
|
// SVG document will receive an OnPageHide() call when it gets purged from
|
|
|
|
|
// the image cache; hence, we use IsVisible() as a hint that the document is
|
|
|
|
|
// actively being kept alive by the cache.)
|
|
|
|
|
return nsCCUncollectableMarker::InGeneration(aDoc->GetMarkedCCGeneration()) ||
|
|
|
|
|
(nsCCUncollectableMarker::sGeneration &&
|
|
|
|
|
aDoc->IsBeingUsedAsImage() &&
|
|
|
|
|
aDoc->IsVisible());
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-27 17:01:55 +04:00
|
|
|
|
// static
|
|
|
|
|
bool
|
|
|
|
|
FragmentOrElement::CanSkipInCC(nsINode* aNode)
|
|
|
|
|
{
|
|
|
|
|
// Don't try to optimize anything during shutdown.
|
|
|
|
|
if (nsCCUncollectableMarker::sGeneration == 0) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-02 22:45:44 +04:00
|
|
|
|
//XXXsmaug Need to figure out in which cases Shadow DOM can be optimized out
|
|
|
|
|
// from the CC graph.
|
|
|
|
|
nsIDocument* currentDoc = aNode->GetUncomposedDoc();
|
2016-06-18 22:50:45 +03:00
|
|
|
|
if (currentDoc && IsCertainlyAliveNode(aNode, currentDoc)) {
|
2012-06-27 17:01:55 +04:00
|
|
|
|
return !NeedsScriptTraverse(aNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Bail out early if aNode is somewhere in anonymous content,
|
|
|
|
|
// or otherwise unusual.
|
|
|
|
|
if (aNode->UnoptimizableCCNode()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsINode* root =
|
|
|
|
|
currentDoc ? static_cast<nsINode*>(currentDoc) :
|
|
|
|
|
FindOptimizableSubtreeRoot(aNode);
|
|
|
|
|
if (!root) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2013-12-06 22:17:19 +04:00
|
|
|
|
|
2012-06-27 17:01:55 +04:00
|
|
|
|
// Subtree has been traversed already.
|
|
|
|
|
if (root->CCMarkedRoot()) {
|
|
|
|
|
return root->InCCBlackTree() && !NeedsScriptTraverse(aNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!gCCBlackMarkedNodes) {
|
2013-12-06 22:17:19 +04:00
|
|
|
|
gCCBlackMarkedNodes = new nsTHashtable<nsPtrHashKey<nsINode> >(1020);
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// nodesToUnpurple contains nodes which will be removed
|
2017-01-25 04:38:58 +03:00
|
|
|
|
// from the purple buffer if the DOM tree is known-live.
|
2016-02-02 18:36:30 +03:00
|
|
|
|
AutoTArray<nsIContent*, 1020> nodesToUnpurple;
|
2012-06-27 17:01:55 +04:00
|
|
|
|
// grayNodes need script traverse, so they aren't removed from
|
2017-01-25 04:38:58 +03:00
|
|
|
|
// the purple buffer, but are marked to be in known-live subtree so that
|
2012-06-27 17:01:55 +04:00
|
|
|
|
// traverse is faster.
|
2016-02-02 18:36:30 +03:00
|
|
|
|
AutoTArray<nsINode*, 1020> grayNodes;
|
2012-06-27 17:01:55 +04:00
|
|
|
|
|
2017-01-25 04:38:58 +03:00
|
|
|
|
bool foundLiveWrapper = root->HasKnownLiveWrapper();
|
2012-06-27 17:01:55 +04:00
|
|
|
|
if (root != currentDoc) {
|
|
|
|
|
currentDoc = nullptr;
|
|
|
|
|
if (NeedsScriptTraverse(root)) {
|
|
|
|
|
grayNodes.AppendElement(root);
|
|
|
|
|
} else if (static_cast<nsIContent*>(root)->IsPurple()) {
|
|
|
|
|
nodesToUnpurple.AppendElement(static_cast<nsIContent*>(root));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Traverse the subtree and check if we could know without CC
|
2017-01-25 04:38:58 +03:00
|
|
|
|
// that it is known-live.
|
2012-06-27 17:01:55 +04:00
|
|
|
|
// Note, this traverse is non-virtual and inline, so it should be a lot faster
|
|
|
|
|
// than CC's generic traverse.
|
|
|
|
|
for (nsIContent* node = root->GetFirstChild(); node;
|
|
|
|
|
node = node->GetNextNode(root)) {
|
2017-01-25 04:38:58 +03:00
|
|
|
|
foundLiveWrapper = foundLiveWrapper || node->HasKnownLiveWrapper();
|
|
|
|
|
if (foundLiveWrapper && currentDoc) {
|
|
|
|
|
// If we can mark the whole document known-live, no need to optimize
|
2012-06-27 17:01:55 +04:00
|
|
|
|
// so much, since when the next purple node in the document will be
|
|
|
|
|
// handled, it is fast to check that currentDoc is in CCGeneration.
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (NeedsScriptTraverse(node)) {
|
|
|
|
|
// Gray nodes need real CC traverse.
|
|
|
|
|
grayNodes.AppendElement(node);
|
|
|
|
|
} else if (node->IsPurple()) {
|
|
|
|
|
nodesToUnpurple.AppendElement(node);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
root->SetCCMarkedRoot(true);
|
2017-01-25 04:38:58 +03:00
|
|
|
|
root->SetInCCBlackTree(foundLiveWrapper);
|
2013-12-06 22:17:19 +04:00
|
|
|
|
gCCBlackMarkedNodes->PutEntry(root);
|
2012-06-27 17:01:55 +04:00
|
|
|
|
|
2017-01-25 04:38:58 +03:00
|
|
|
|
if (!foundLiveWrapper) {
|
2012-06-27 17:01:55 +04:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (currentDoc) {
|
2017-01-25 04:38:58 +03:00
|
|
|
|
// Special case documents. If we know the document is known-live,
|
2012-06-27 17:01:55 +04:00
|
|
|
|
// we can mark the document to be in CCGeneration.
|
|
|
|
|
currentDoc->
|
|
|
|
|
MarkUncollectableForCCGeneration(nsCCUncollectableMarker::sGeneration);
|
|
|
|
|
} else {
|
2012-08-22 19:56:38 +04:00
|
|
|
|
for (uint32_t i = 0; i < grayNodes.Length(); ++i) {
|
2012-06-27 17:01:55 +04:00
|
|
|
|
nsINode* node = grayNodes[i];
|
|
|
|
|
node->SetInCCBlackTree(true);
|
2013-12-06 22:17:19 +04:00
|
|
|
|
gCCBlackMarkedNodes->PutEntry(node);
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-25 04:38:58 +03:00
|
|
|
|
// Subtree is known-live, we can remove non-gray purple nodes from
|
2012-06-27 17:01:55 +04:00
|
|
|
|
// purple buffer.
|
2012-08-22 19:56:38 +04:00
|
|
|
|
for (uint32_t i = 0; i < nodesToUnpurple.Length(); ++i) {
|
2012-06-27 17:01:55 +04:00
|
|
|
|
nsIContent* purple = nodesToUnpurple[i];
|
|
|
|
|
// Can't remove currently handled purple node.
|
|
|
|
|
if (purple != aNode) {
|
|
|
|
|
purple->RemovePurple();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return !NeedsScriptTraverse(aNode);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-02 18:36:30 +03:00
|
|
|
|
AutoTArray<nsINode*, 1020>* gPurpleRoots = nullptr;
|
|
|
|
|
AutoTArray<nsIContent*, 1020>* gNodesToUnbind = nullptr;
|
2012-06-27 17:01:55 +04:00
|
|
|
|
|
|
|
|
|
void ClearCycleCollectorCleanupData()
|
|
|
|
|
{
|
|
|
|
|
if (gPurpleRoots) {
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint32_t len = gPurpleRoots->Length();
|
|
|
|
|
for (uint32_t i = 0; i < len; ++i) {
|
2012-06-27 17:01:55 +04:00
|
|
|
|
nsINode* n = gPurpleRoots->ElementAt(i);
|
|
|
|
|
n->SetIsPurpleRoot(false);
|
|
|
|
|
}
|
|
|
|
|
delete gPurpleRoots;
|
|
|
|
|
gPurpleRoots = nullptr;
|
|
|
|
|
}
|
|
|
|
|
if (gNodesToUnbind) {
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint32_t len = gNodesToUnbind->Length();
|
|
|
|
|
for (uint32_t i = 0; i < len; ++i) {
|
2012-06-27 17:01:55 +04:00
|
|
|
|
nsIContent* c = gNodesToUnbind->ElementAt(i);
|
|
|
|
|
c->SetIsPurpleRoot(false);
|
|
|
|
|
ContentUnbinder::Append(c);
|
|
|
|
|
}
|
|
|
|
|
delete gNodesToUnbind;
|
|
|
|
|
gNodesToUnbind = nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
ShouldClearPurple(nsIContent* aContent)
|
|
|
|
|
{
|
2016-08-30 07:48:30 +03:00
|
|
|
|
MOZ_ASSERT(aContent);
|
2016-08-30 07:23:08 +03:00
|
|
|
|
if (aContent->IsPurple()) {
|
2012-06-27 17:01:55 +04:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JSObject* o = GetJSObjectChild(aContent);
|
2014-12-05 20:38:34 +03:00
|
|
|
|
if (o && JS::ObjectIsMarkedGray(o)) {
|
2012-06-27 17:01:55 +04:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (aContent->HasListenerManager()) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return aContent->HasProperties();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If aNode is not optimizable, but is an element
|
|
|
|
|
// with a frame in a document which has currently active presshell,
|
|
|
|
|
// we can act as if it was optimizable. When the primary frame dies, aNode
|
|
|
|
|
// will end up to the purple buffer because of the refcount change.
|
|
|
|
|
bool
|
|
|
|
|
NodeHasActiveFrame(nsIDocument* aCurrentDoc, nsINode* aNode)
|
|
|
|
|
{
|
|
|
|
|
return aCurrentDoc->GetShell() && aNode->IsElement() &&
|
|
|
|
|
aNode->AsElement()->GetPrimaryFrame();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
OwnedByBindingManager(nsIDocument* aCurrentDoc, nsINode* aNode)
|
|
|
|
|
{
|
2013-07-17 20:05:03 +04:00
|
|
|
|
return aNode->IsElement() && aNode->AsElement()->GetXBLBinding();
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-25 04:38:58 +03:00
|
|
|
|
// CanSkip checks if aNode is known-live, and if it is, returns true. If aNode
|
|
|
|
|
// is in a known-live DOM tree, CanSkip may also remove other objects from
|
|
|
|
|
// purple buffer and unmark event listeners and user data. If the root of the
|
|
|
|
|
// DOM tree is a document, less optimizations are done since checking the
|
|
|
|
|
// liveness of the current document is usually fast and we don't want slow down
|
|
|
|
|
// such common cases.
|
2012-06-27 17:01:55 +04:00
|
|
|
|
bool
|
|
|
|
|
FragmentOrElement::CanSkip(nsINode* aNode, bool aRemovingAllowed)
|
|
|
|
|
{
|
|
|
|
|
// Don't try to optimize anything during shutdown.
|
|
|
|
|
if (nsCCUncollectableMarker::sGeneration == 0) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool unoptimizable = aNode->UnoptimizableCCNode();
|
2014-10-02 22:45:44 +04:00
|
|
|
|
nsIDocument* currentDoc = aNode->GetUncomposedDoc();
|
2016-06-18 22:50:45 +03:00
|
|
|
|
if (currentDoc && IsCertainlyAliveNode(aNode, currentDoc) &&
|
2012-06-27 17:01:55 +04:00
|
|
|
|
(!unoptimizable || NodeHasActiveFrame(currentDoc, aNode) ||
|
|
|
|
|
OwnedByBindingManager(currentDoc, aNode))) {
|
|
|
|
|
MarkNodeChildren(aNode);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (unoptimizable) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsINode* root = currentDoc ? static_cast<nsINode*>(currentDoc) :
|
|
|
|
|
FindOptimizableSubtreeRoot(aNode);
|
|
|
|
|
if (!root) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2015-05-04 16:56:00 +03:00
|
|
|
|
|
2012-06-27 17:01:55 +04:00
|
|
|
|
// Subtree has been traversed already, and aNode has
|
|
|
|
|
// been handled in a way that doesn't require revisiting it.
|
|
|
|
|
if (root->IsPurpleRoot()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// nodesToClear contains nodes which are either purple or
|
|
|
|
|
// gray.
|
2016-02-02 18:36:30 +03:00
|
|
|
|
AutoTArray<nsIContent*, 1020> nodesToClear;
|
2012-06-27 17:01:55 +04:00
|
|
|
|
|
2017-01-25 04:38:58 +03:00
|
|
|
|
bool foundLiveWrapper = root->HasKnownLiveWrapper();
|
2012-06-27 17:01:55 +04:00
|
|
|
|
bool domOnlyCycle = false;
|
|
|
|
|
if (root != currentDoc) {
|
|
|
|
|
currentDoc = nullptr;
|
2017-01-25 04:38:58 +03:00
|
|
|
|
if (!foundLiveWrapper) {
|
2012-06-27 17:01:55 +04:00
|
|
|
|
domOnlyCycle = static_cast<nsIContent*>(root)->OwnedOnlyByTheDOMTree();
|
|
|
|
|
}
|
|
|
|
|
if (ShouldClearPurple(static_cast<nsIContent*>(root))) {
|
|
|
|
|
nodesToClear.AppendElement(static_cast<nsIContent*>(root));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Traverse the subtree and check if we could know without CC
|
2017-01-25 04:38:58 +03:00
|
|
|
|
// that it is known-live.
|
2012-06-27 17:01:55 +04:00
|
|
|
|
// Note, this traverse is non-virtual and inline, so it should be a lot faster
|
|
|
|
|
// than CC's generic traverse.
|
|
|
|
|
for (nsIContent* node = root->GetFirstChild(); node;
|
|
|
|
|
node = node->GetNextNode(root)) {
|
2017-01-25 04:38:58 +03:00
|
|
|
|
foundLiveWrapper = foundLiveWrapper || node->HasKnownLiveWrapper();
|
|
|
|
|
if (foundLiveWrapper) {
|
2012-06-27 17:01:55 +04:00
|
|
|
|
domOnlyCycle = false;
|
|
|
|
|
if (currentDoc) {
|
2017-01-25 04:38:58 +03:00
|
|
|
|
// If we can mark the whole document live, no need to optimize
|
2012-06-27 17:01:55 +04:00
|
|
|
|
// so much, since when the next purple node in the document will be
|
|
|
|
|
// handled, it is fast to check that the currentDoc is in CCGeneration.
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// No need to put stuff to the nodesToClear array, if we can clear it
|
|
|
|
|
// already here.
|
|
|
|
|
if (node->IsPurple() && (node != aNode || aRemovingAllowed)) {
|
|
|
|
|
node->RemovePurple();
|
|
|
|
|
}
|
|
|
|
|
MarkNodeChildren(node);
|
|
|
|
|
} else {
|
|
|
|
|
domOnlyCycle = domOnlyCycle && node->OwnedOnlyByTheDOMTree();
|
|
|
|
|
if (ShouldClearPurple(node)) {
|
|
|
|
|
// Collect interesting nodes which we can clear if we find that
|
2017-01-25 04:38:58 +03:00
|
|
|
|
// they are kept alive in a known-live tree or are in a DOM-only cycle.
|
2012-06-27 17:01:55 +04:00
|
|
|
|
nodesToClear.AppendElement(node);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-25 04:38:58 +03:00
|
|
|
|
if (!currentDoc || !foundLiveWrapper) {
|
2012-06-27 17:01:55 +04:00
|
|
|
|
root->SetIsPurpleRoot(true);
|
|
|
|
|
if (domOnlyCycle) {
|
|
|
|
|
if (!gNodesToUnbind) {
|
2016-02-02 18:36:30 +03:00
|
|
|
|
gNodesToUnbind = new AutoTArray<nsIContent*, 1020>();
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
gNodesToUnbind->AppendElement(static_cast<nsIContent*>(root));
|
2012-08-22 19:56:38 +04:00
|
|
|
|
for (uint32_t i = 0; i < nodesToClear.Length(); ++i) {
|
2012-06-27 17:01:55 +04:00
|
|
|
|
nsIContent* n = nodesToClear[i];
|
|
|
|
|
if ((n != aNode || aRemovingAllowed) && n->IsPurple()) {
|
|
|
|
|
n->RemovePurple();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
if (!gPurpleRoots) {
|
2016-02-02 18:36:30 +03:00
|
|
|
|
gPurpleRoots = new AutoTArray<nsINode*, 1020>();
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
gPurpleRoots->AppendElement(root);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-25 04:38:58 +03:00
|
|
|
|
if (!foundLiveWrapper) {
|
2012-06-27 17:01:55 +04:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (currentDoc) {
|
2017-01-25 04:38:58 +03:00
|
|
|
|
// Special case documents. If we know the document is known-live,
|
2012-06-27 17:01:55 +04:00
|
|
|
|
// we can mark the document to be in CCGeneration.
|
|
|
|
|
currentDoc->
|
|
|
|
|
MarkUncollectableForCCGeneration(nsCCUncollectableMarker::sGeneration);
|
|
|
|
|
MarkNodeChildren(currentDoc);
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-25 04:38:58 +03:00
|
|
|
|
// Subtree is known-live, so we can remove purple nodes from
|
2012-06-27 17:01:55 +04:00
|
|
|
|
// purple buffer and mark stuff that to be certainly alive.
|
2012-08-22 19:56:38 +04:00
|
|
|
|
for (uint32_t i = 0; i < nodesToClear.Length(); ++i) {
|
2012-06-27 17:01:55 +04:00
|
|
|
|
nsIContent* n = nodesToClear[i];
|
|
|
|
|
MarkNodeChildren(n);
|
|
|
|
|
// Can't remove currently handled purple node,
|
2015-05-04 16:56:00 +03:00
|
|
|
|
// unless aRemovingAllowed is true.
|
2012-06-27 17:01:55 +04:00
|
|
|
|
if ((n != aNode || aRemovingAllowed) && n->IsPurple()) {
|
|
|
|
|
n->RemovePurple();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
FragmentOrElement::CanSkipThis(nsINode* aNode)
|
|
|
|
|
{
|
|
|
|
|
if (nsCCUncollectableMarker::sGeneration == 0) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2017-01-25 04:38:58 +03:00
|
|
|
|
if (aNode->HasKnownLiveWrapper()) {
|
2012-06-27 17:01:55 +04:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-10-02 22:45:44 +04:00
|
|
|
|
nsIDocument* c = aNode->GetUncomposedDoc();
|
2015-05-04 16:56:00 +03:00
|
|
|
|
return
|
2016-06-18 22:50:45 +03:00
|
|
|
|
((c && IsCertainlyAliveNode(aNode, c)) || aNode->InCCBlackTree()) &&
|
|
|
|
|
!NeedsScriptTraverse(aNode);
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FragmentOrElement::InitCCCallbacks()
|
|
|
|
|
{
|
|
|
|
|
nsCycleCollector_setForgetSkippableCallback(ClearCycleCollectorCleanupData);
|
|
|
|
|
nsCycleCollector_setBeforeUnlinkCallback(ClearBlackMarkedNodes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(FragmentOrElement)
|
|
|
|
|
return FragmentOrElement::CanSkip(tmp, aRemovingAllowed);
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_END
|
|
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_BEGIN(FragmentOrElement)
|
|
|
|
|
return FragmentOrElement::CanSkipInCC(tmp);
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_END
|
|
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_BEGIN(FragmentOrElement)
|
|
|
|
|
return FragmentOrElement::CanSkipThis(tmp);
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_END
|
|
|
|
|
|
|
|
|
|
static const char* kNSURIs[] = {
|
|
|
|
|
" ([none])",
|
|
|
|
|
" (xmlns)",
|
|
|
|
|
" (xml)",
|
|
|
|
|
" (xhtml)",
|
|
|
|
|
" (XLink)",
|
|
|
|
|
" (XSLT)",
|
|
|
|
|
" (XBL)",
|
|
|
|
|
" (MathML)",
|
|
|
|
|
" (RDF)",
|
|
|
|
|
" (XUL)",
|
|
|
|
|
" (SVG)",
|
|
|
|
|
" (XML Events)"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(FragmentOrElement)
|
2012-10-26 17:32:10 +04:00
|
|
|
|
if (MOZ_UNLIKELY(cb.WantDebugInfo())) {
|
2012-06-27 17:01:55 +04:00
|
|
|
|
char name[512];
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint32_t nsid = tmp->GetNameSpaceID();
|
2012-06-27 17:01:55 +04:00
|
|
|
|
nsAtomCString localName(tmp->NodeInfo()->NameAtom());
|
2012-09-02 06:35:17 +04:00
|
|
|
|
nsAutoCString uri;
|
2012-06-27 17:01:55 +04:00
|
|
|
|
if (tmp->OwnerDoc()->GetDocumentURI()) {
|
2016-09-08 07:17:58 +03:00
|
|
|
|
uri = tmp->OwnerDoc()->GetDocumentURI()->GetSpecOrDefault();
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsAutoString id;
|
2017-10-03 01:05:19 +03:00
|
|
|
|
nsAtom* idAtom = tmp->GetID();
|
2012-06-27 17:01:55 +04:00
|
|
|
|
if (idAtom) {
|
|
|
|
|
id.AppendLiteral(" id='");
|
|
|
|
|
id.Append(nsDependentAtomString(idAtom));
|
2014-05-22 07:48:51 +04:00
|
|
|
|
id.Append('\'');
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsAutoString classes;
|
2017-02-14 00:06:45 +03:00
|
|
|
|
const nsAttrValue* classAttrValue = tmp->IsElement() ?
|
|
|
|
|
tmp->AsElement()->GetClasses() : nullptr;
|
2012-06-27 17:01:55 +04:00
|
|
|
|
if (classAttrValue) {
|
|
|
|
|
classes.AppendLiteral(" class='");
|
|
|
|
|
nsAutoString classString;
|
|
|
|
|
classAttrValue->ToString(classString);
|
2014-01-04 19:02:17 +04:00
|
|
|
|
classString.ReplaceChar(char16_t('\n'), char16_t(' '));
|
2012-06-27 17:01:55 +04:00
|
|
|
|
classes.Append(classString);
|
2014-05-22 07:48:51 +04:00
|
|
|
|
classes.Append('\'');
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-04-01 07:33:28 +04:00
|
|
|
|
nsAutoCString orphan;
|
2016-03-31 13:58:25 +03:00
|
|
|
|
if (!tmp->IsInUncomposedDoc() &&
|
2014-04-01 07:33:28 +04:00
|
|
|
|
// Ignore xbl:content, which is never in the document and hence always
|
|
|
|
|
// appears to be orphaned.
|
|
|
|
|
!tmp->NodeInfo()->Equals(nsGkAtoms::content, kNameSpaceID_XBL)) {
|
|
|
|
|
orphan.AppendLiteral(" (orphan)");
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-27 17:01:55 +04:00
|
|
|
|
const char* nsuri = nsid < ArrayLength(kNSURIs) ? kNSURIs[nsid] : "";
|
2016-08-15 09:44:00 +03:00
|
|
|
|
SprintfLiteral(name, "FragmentOrElement%s %s%s%s%s %s",
|
|
|
|
|
nsuri,
|
|
|
|
|
localName.get(),
|
|
|
|
|
NS_ConvertUTF16toUTF8(id).get(),
|
|
|
|
|
NS_ConvertUTF16toUTF8(classes).get(),
|
|
|
|
|
orphan.get(),
|
|
|
|
|
uri.get());
|
2012-08-27 21:41:04 +04:00
|
|
|
|
cb.DescribeRefCountedNode(tmp->mRefCnt.get(), name);
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_DESCRIBE(FragmentOrElement, tmp->mRefCnt.get())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!nsINode::Traverse(tmp, cb)) {
|
|
|
|
|
return NS_SUCCESS_INTERRUPTED_TRAVERSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tmp->OwnerDoc()->BindingManager()->Traverse(tmp, cb);
|
|
|
|
|
|
2016-01-18 07:40:12 +03:00
|
|
|
|
// Check that whenever we have effect properties, MayHaveAnimations is set.
|
|
|
|
|
#ifdef DEBUG
|
2017-10-03 01:05:19 +03:00
|
|
|
|
nsAtom** effectProps = EffectSet::GetEffectSetPropertyAtoms();
|
2016-01-18 07:40:12 +03:00
|
|
|
|
for (uint32_t i = 0; effectProps[i]; ++i) {
|
|
|
|
|
MOZ_ASSERT_IF(tmp->GetProperty(effectProps[i]), tmp->MayHaveAnimations());
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-06-27 17:01:55 +04:00
|
|
|
|
if (tmp->HasProperties()) {
|
2017-10-06 06:42:55 +03:00
|
|
|
|
if (tmp->IsElement()) {
|
|
|
|
|
Element* elem = tmp->AsElement();
|
|
|
|
|
IntersectionObserverList* observers =
|
|
|
|
|
static_cast<IntersectionObserverList*>(
|
|
|
|
|
elem->GetProperty(nsGkAtoms::intersectionobserverlist)
|
|
|
|
|
);
|
|
|
|
|
if (observers) {
|
|
|
|
|
for (auto iter = observers->Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
|
DOMIntersectionObserver* observer = iter.Key();
|
|
|
|
|
cb.NoteXPCOMChild(observer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-03-03 14:08:59 +03:00
|
|
|
|
if (tmp->IsHTMLElement() || tmp->IsSVGElement()) {
|
2017-10-27 02:31:13 +03:00
|
|
|
|
nsStaticAtom*** props = Element::HTMLSVGPropertiesToTraverseAndUnlink();
|
2014-03-28 18:36:47 +04:00
|
|
|
|
for (uint32_t i = 0; props[i]; ++i) {
|
|
|
|
|
nsISupports* property =
|
|
|
|
|
static_cast<nsISupports*>(tmp->GetProperty(*props[i]));
|
|
|
|
|
cb.NoteXPCOMChild(property);
|
|
|
|
|
}
|
2016-01-18 07:40:12 +03:00
|
|
|
|
if (tmp->MayHaveAnimations()) {
|
2017-10-03 01:05:19 +03:00
|
|
|
|
nsAtom** effectProps = EffectSet::GetEffectSetPropertyAtoms();
|
2016-01-18 07:40:12 +03:00
|
|
|
|
for (uint32_t i = 0; effectProps[i]; ++i) {
|
|
|
|
|
EffectSet* effectSet =
|
|
|
|
|
static_cast<EffectSet*>(tmp->GetProperty(effectProps[i]));
|
|
|
|
|
if (effectSet) {
|
|
|
|
|
effectSet->Traverse(cb);
|
|
|
|
|
}
|
2015-11-26 10:53:54 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Traverse attribute names and child content.
|
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint32_t i;
|
|
|
|
|
uint32_t attrs = tmp->mAttrsAndChildren.AttrCount();
|
2012-06-27 17:01:55 +04:00
|
|
|
|
for (i = 0; i < attrs; i++) {
|
|
|
|
|
const nsAttrName* name = tmp->mAttrsAndChildren.AttrNameAt(i);
|
|
|
|
|
if (!name->IsAtom()) {
|
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb,
|
|
|
|
|
"mAttrsAndChildren[i]->NodeInfo()");
|
2014-06-20 06:01:40 +04:00
|
|
|
|
cb.NoteNativeChild(name->NodeInfo(),
|
|
|
|
|
NS_CYCLE_COLLECTION_PARTICIPANT(NodeInfo));
|
2012-07-31 19:36:21 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-06-27 17:01:55 +04:00
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint32_t kids = tmp->mAttrsAndChildren.ChildCount();
|
2012-07-31 19:36:21 +04:00
|
|
|
|
for (i = 0; i < kids; i++) {
|
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mAttrsAndChildren[i]");
|
|
|
|
|
cb.NoteXPCOMChild(tmp->mAttrsAndChildren.GetSafeChildAt(i));
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-07-31 19:36:21 +04:00
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2012-06-27 17:01:55 +04:00
|
|
|
|
|
|
|
|
|
|
2012-07-31 19:36:21 +04:00
|
|
|
|
NS_INTERFACE_MAP_BEGIN(FragmentOrElement)
|
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
|
NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(FragmentOrElement)
|
|
|
|
|
NS_INTERFACE_MAP_ENTRY(Element)
|
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIContent)
|
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsINode)
|
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMEventTarget)
|
2013-01-29 17:44:01 +04:00
|
|
|
|
NS_INTERFACE_MAP_ENTRY(mozilla::dom::EventTarget)
|
2012-07-31 19:36:21 +04:00
|
|
|
|
NS_INTERFACE_MAP_ENTRY_TEAROFF(nsISupportsWeakReference,
|
|
|
|
|
new nsNodeSupportsWeakRefTearoff(this))
|
2013-06-26 18:59:45 +04:00
|
|
|
|
// DOM bindings depend on the identity pointer being the
|
|
|
|
|
// same as nsINode (which nsIContent inherits).
|
2012-07-31 19:36:21 +04:00
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContent)
|
|
|
|
|
NS_INTERFACE_MAP_END
|
2012-06-27 17:01:55 +04:00
|
|
|
|
|
2017-08-22 00:01:47 +03:00
|
|
|
|
NS_IMPL_MAIN_THREAD_ONLY_CYCLE_COLLECTING_ADDREF(FragmentOrElement)
|
|
|
|
|
NS_IMPL_MAIN_THREAD_ONLY_CYCLE_COLLECTING_RELEASE_WITH_LAST_RELEASE(FragmentOrElement,
|
|
|
|
|
nsNodeUtils::LastRelease(this))
|
2012-06-27 17:01:55 +04:00
|
|
|
|
|
2012-07-31 19:36:21 +04:00
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
nsresult
|
2017-04-20 22:57:48 +03:00
|
|
|
|
FragmentOrElement::CopyInnerTo(FragmentOrElement* aDst,
|
|
|
|
|
bool aPreallocateChildren)
|
2012-06-27 17:01:55 +04:00
|
|
|
|
{
|
2017-04-20 22:57:48 +03:00
|
|
|
|
nsresult rv = aDst->mAttrsAndChildren.EnsureCapacityToClone(mAttrsAndChildren,
|
|
|
|
|
aPreallocateChildren);
|
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint32_t i, count = mAttrsAndChildren.AttrCount();
|
2012-07-31 19:36:21 +04:00
|
|
|
|
for (i = 0; i < count; ++i) {
|
|
|
|
|
const nsAttrName* name = mAttrsAndChildren.AttrNameAt(i);
|
|
|
|
|
const nsAttrValue* value = mAttrsAndChildren.AttrAt(i);
|
|
|
|
|
nsAutoString valStr;
|
|
|
|
|
value->ToString(valStr);
|
2017-12-05 20:05:51 +03:00
|
|
|
|
rv = aDst->AsElement()->SetAttr(name->NamespaceID(), name->LocalName(),
|
|
|
|
|
name->GetPrefix(), valStr, false);
|
2012-07-31 19:36:21 +04:00
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NS_OK;
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const nsTextFragment*
|
|
|
|
|
FragmentOrElement::GetText()
|
|
|
|
|
{
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint32_t
|
2012-06-27 17:01:55 +04:00
|
|
|
|
FragmentOrElement::TextLength() const
|
|
|
|
|
{
|
|
|
|
|
// We can remove this assertion if it turns out to be useful to be able
|
|
|
|
|
// to depend on this returning 0
|
|
|
|
|
NS_NOTREACHED("called FragmentOrElement::TextLength");
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsresult
|
2014-01-04 19:02:17 +04:00
|
|
|
|
FragmentOrElement::SetText(const char16_t* aBuffer, uint32_t aLength,
|
2012-06-27 17:01:55 +04:00
|
|
|
|
bool aNotify)
|
|
|
|
|
{
|
|
|
|
|
NS_ERROR("called FragmentOrElement::SetText");
|
|
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsresult
|
2014-01-04 19:02:17 +04:00
|
|
|
|
FragmentOrElement::AppendText(const char16_t* aBuffer, uint32_t aLength,
|
2012-06-27 17:01:55 +04:00
|
|
|
|
bool aNotify)
|
|
|
|
|
{
|
|
|
|
|
NS_ERROR("called FragmentOrElement::AppendText");
|
|
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
FragmentOrElement::TextIsOnlyWhitespace()
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-17 00:10:22 +03:00
|
|
|
|
bool
|
|
|
|
|
FragmentOrElement::ThreadSafeTextIsOnlyWhitespace() const
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-05 07:21:08 +04:00
|
|
|
|
bool
|
|
|
|
|
FragmentOrElement::HasTextForTranslation()
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-27 17:01:55 +04:00
|
|
|
|
void
|
|
|
|
|
FragmentOrElement::AppendTextTo(nsAString& aResult)
|
|
|
|
|
{
|
|
|
|
|
// We can remove this assertion if it turns out to be useful to be able
|
|
|
|
|
// to depend on this appending nothing.
|
|
|
|
|
NS_NOTREACHED("called FragmentOrElement::TextLength");
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-19 21:05:02 +04:00
|
|
|
|
bool
|
|
|
|
|
FragmentOrElement::AppendTextTo(nsAString& aResult, const mozilla::fallible_t&)
|
|
|
|
|
{
|
|
|
|
|
// We can remove this assertion if it turns out to be useful to be able
|
|
|
|
|
// to depend on this appending nothing.
|
|
|
|
|
NS_NOTREACHED("called FragmentOrElement::TextLength");
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint32_t
|
2012-06-27 17:01:55 +04:00
|
|
|
|
FragmentOrElement::GetChildCount() const
|
|
|
|
|
{
|
|
|
|
|
return mAttrsAndChildren.ChildCount();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsIContent *
|
2018-01-03 15:59:54 +03:00
|
|
|
|
FragmentOrElement::GetChildAt_Deprecated(uint32_t aIndex) const
|
2012-06-27 17:01:55 +04:00
|
|
|
|
{
|
|
|
|
|
return mAttrsAndChildren.GetSafeChildAt(aIndex);
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
|
int32_t
|
2018-01-23 16:30:18 +03:00
|
|
|
|
FragmentOrElement::ComputeIndexOf(const nsINode* aPossibleChild) const
|
2012-06-27 17:01:55 +04:00
|
|
|
|
{
|
|
|
|
|
return mAttrsAndChildren.IndexOfChild(aPossibleChild);
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-02 14:26:12 +04:00
|
|
|
|
static inline bool
|
2017-10-03 01:05:19 +03:00
|
|
|
|
IsVoidTag(nsAtom* aTag)
|
2013-12-02 14:26:12 +04:00
|
|
|
|
{
|
2017-10-03 01:05:19 +03:00
|
|
|
|
static const nsAtom* voidElements[] = {
|
2013-12-02 14:26:12 +04:00
|
|
|
|
nsGkAtoms::area, nsGkAtoms::base, nsGkAtoms::basefont,
|
|
|
|
|
nsGkAtoms::bgsound, nsGkAtoms::br, nsGkAtoms::col,
|
2015-01-23 06:36:21 +03:00
|
|
|
|
nsGkAtoms::embed, nsGkAtoms::frame,
|
2013-12-02 14:26:12 +04:00
|
|
|
|
nsGkAtoms::hr, nsGkAtoms::img, nsGkAtoms::input,
|
|
|
|
|
nsGkAtoms::keygen, nsGkAtoms::link, nsGkAtoms::meta,
|
|
|
|
|
nsGkAtoms::param, nsGkAtoms::source, nsGkAtoms::track,
|
|
|
|
|
nsGkAtoms::wbr
|
|
|
|
|
};
|
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
|
static mozilla::BloomFilter<12, nsAtom> sFilter;
|
2013-12-02 14:26:12 +04:00
|
|
|
|
static bool sInitialized = false;
|
|
|
|
|
if (!sInitialized) {
|
|
|
|
|
sInitialized = true;
|
|
|
|
|
for (uint32_t i = 0; i < ArrayLength(voidElements); ++i) {
|
|
|
|
|
sFilter.add(voidElements[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-01-19 14:17:22 +03:00
|
|
|
|
|
|
|
|
|
if (sFilter.mightContain(aTag)) {
|
2013-12-02 14:26:12 +04:00
|
|
|
|
for (uint32_t i = 0; i < ArrayLength(voidElements); ++i) {
|
2015-01-19 14:17:22 +03:00
|
|
|
|
if (aTag == voidElements[i]) {
|
2013-12-02 14:26:12 +04:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-19 14:17:22 +03:00
|
|
|
|
/* static */
|
|
|
|
|
bool
|
2017-10-03 01:05:19 +03:00
|
|
|
|
FragmentOrElement::IsHTMLVoid(nsAtom* aLocalName)
|
2015-01-19 14:17:22 +03:00
|
|
|
|
{
|
|
|
|
|
return aLocalName && IsVoidTag(aLocalName);
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-02 14:26:12 +04:00
|
|
|
|
void
|
|
|
|
|
FragmentOrElement::GetMarkup(bool aIncludeSelf, nsAString& aMarkup)
|
|
|
|
|
{
|
|
|
|
|
aMarkup.Truncate();
|
|
|
|
|
|
|
|
|
|
nsIDocument* doc = OwnerDoc();
|
|
|
|
|
if (IsInHTMLDocument()) {
|
2015-10-08 19:57:40 +03:00
|
|
|
|
nsContentUtils::SerializeNodeToMarkup(this, !aIncludeSelf, aMarkup);
|
2013-12-02 14:26:12 +04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsAutoString contentType;
|
|
|
|
|
doc->GetContentType(contentType);
|
|
|
|
|
bool tryToCacheEncoder = !aIncludeSelf;
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocumentEncoder> docEncoder = doc->GetCachedEncoder();
|
|
|
|
|
if (!docEncoder) {
|
|
|
|
|
docEncoder =
|
|
|
|
|
do_CreateInstance(PromiseFlatCString(
|
|
|
|
|
nsDependentCString(NS_DOC_ENCODER_CONTRACTID_BASE) +
|
|
|
|
|
NS_ConvertUTF16toUTF8(contentType)
|
|
|
|
|
).get());
|
|
|
|
|
}
|
|
|
|
|
if (!docEncoder) {
|
|
|
|
|
// This could be some type for which we create a synthetic document. Try
|
|
|
|
|
// again as XML
|
|
|
|
|
contentType.AssignLiteral("application/xml");
|
|
|
|
|
docEncoder = do_CreateInstance(NS_DOC_ENCODER_CONTRACTID_BASE "application/xml");
|
|
|
|
|
// Don't try to cache the encoder since it would point to a different
|
|
|
|
|
// contentType once it has been reinitialized.
|
|
|
|
|
tryToCacheEncoder = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NS_ENSURE_TRUE_VOID(docEncoder);
|
|
|
|
|
|
|
|
|
|
uint32_t flags = nsIDocumentEncoder::OutputEncodeBasicEntities |
|
|
|
|
|
// Output DOM-standard newlines
|
|
|
|
|
nsIDocumentEncoder::OutputLFLineBreak |
|
|
|
|
|
// Don't do linebreaking that's not present in
|
|
|
|
|
// the source
|
|
|
|
|
nsIDocumentEncoder::OutputRaw |
|
|
|
|
|
// Only check for mozdirty when necessary (bug 599983)
|
|
|
|
|
nsIDocumentEncoder::OutputIgnoreMozDirty;
|
|
|
|
|
|
|
|
|
|
if (IsEditable()) {
|
|
|
|
|
nsCOMPtr<Element> elem = do_QueryInterface(this);
|
2017-06-22 09:21:31 +03:00
|
|
|
|
TextEditor* textEditor = elem ? elem->GetTextEditorInternal() : nullptr;
|
|
|
|
|
if (textEditor && textEditor->OutputsMozDirty()) {
|
2013-12-02 14:26:12 +04:00
|
|
|
|
flags &= ~nsIDocumentEncoder::OutputIgnoreMozDirty;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DebugOnly<nsresult> rv = docEncoder->NativeInit(doc, contentType, flags);
|
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
|
|
|
|
|
|
|
|
|
if (aIncludeSelf) {
|
|
|
|
|
docEncoder->SetNativeNode(this);
|
|
|
|
|
} else {
|
|
|
|
|
docEncoder->SetNativeContainerNode(this);
|
|
|
|
|
}
|
|
|
|
|
rv = docEncoder->EncodeToString(aMarkup);
|
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
|
|
|
|
if (tryToCacheEncoder) {
|
|
|
|
|
doc->SetCachedEncoder(docEncoder.forget());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-17 17:58:32 +04:00
|
|
|
|
static bool
|
|
|
|
|
ContainsMarkup(const nsAString& aStr)
|
|
|
|
|
{
|
|
|
|
|
// Note: we can't use FindCharInSet because null is one of the characters we
|
|
|
|
|
// want to search for.
|
2014-01-04 19:02:17 +04:00
|
|
|
|
const char16_t* start = aStr.BeginReading();
|
|
|
|
|
const char16_t* end = aStr.EndReading();
|
2013-12-17 17:58:32 +04:00
|
|
|
|
|
|
|
|
|
while (start != end) {
|
2014-01-04 19:02:17 +04:00
|
|
|
|
char16_t c = *start;
|
|
|
|
|
if (c == char16_t('<') ||
|
|
|
|
|
c == char16_t('&') ||
|
|
|
|
|
c == char16_t('\r') ||
|
|
|
|
|
c == char16_t('\0')) {
|
2013-12-17 17:58:32 +04:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
++start;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-02 14:26:12 +04:00
|
|
|
|
void
|
2018-01-25 01:56:48 +03:00
|
|
|
|
FragmentOrElement::SetInnerHTMLInternal(const nsAString& aInnerHTML, ErrorResult& aError,
|
|
|
|
|
bool aNeverSanitize)
|
2013-12-02 14:26:12 +04:00
|
|
|
|
{
|
|
|
|
|
FragmentOrElement* target = this;
|
|
|
|
|
// Handle template case.
|
|
|
|
|
if (nsNodeUtils::IsTemplateElement(target)) {
|
|
|
|
|
DocumentFragment* frag =
|
|
|
|
|
static_cast<HTMLTemplateElement*>(target)->Content();
|
|
|
|
|
MOZ_ASSERT(frag);
|
|
|
|
|
target = frag;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-17 17:58:32 +04:00
|
|
|
|
// Fast-path for strings with no markup. Limit this to short strings, to
|
|
|
|
|
// avoid ContainsMarkup taking too long. The choice for 100 is based on
|
|
|
|
|
// gut feeling.
|
|
|
|
|
//
|
|
|
|
|
// Don't do this for elements with a weird parser insertion mode, for
|
|
|
|
|
// instance setting innerHTML = "" on a <html> element should add the
|
|
|
|
|
// optional <head> and <body> elements.
|
|
|
|
|
if (!target->HasWeirdParserInsertionMode() &&
|
|
|
|
|
aInnerHTML.Length() < 100 && !ContainsMarkup(aInnerHTML)) {
|
|
|
|
|
aError = nsContentUtils::SetNodeTextContent(target, aInnerHTML, false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-02 14:26:12 +04:00
|
|
|
|
nsIDocument* doc = target->OwnerDoc();
|
|
|
|
|
|
|
|
|
|
// Batch possible DOMSubtreeModified events.
|
|
|
|
|
mozAutoSubtreeModified subtree(doc, nullptr);
|
|
|
|
|
|
|
|
|
|
target->FireNodeRemovedForChildren();
|
|
|
|
|
|
|
|
|
|
// Needed when innerHTML is used in combination with contenteditable
|
|
|
|
|
mozAutoDocUpdate updateBatch(doc, UPDATE_CONTENT_MODEL, true);
|
|
|
|
|
|
|
|
|
|
// Remove childnodes.
|
|
|
|
|
nsAutoMutationBatch mb(target, true, false);
|
2018-01-16 16:17:11 +03:00
|
|
|
|
while (target->HasChildren()) {
|
|
|
|
|
target->RemoveChildNode(target->GetFirstChild(), true);
|
2013-12-02 14:26:12 +04:00
|
|
|
|
}
|
|
|
|
|
mb.RemovalDone();
|
|
|
|
|
|
|
|
|
|
nsAutoScriptLoaderDisabler sld(doc);
|
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
|
nsAtom* contextLocalName = NodeInfo()->NameAtom();
|
2013-12-02 14:26:12 +04:00
|
|
|
|
int32_t contextNameSpaceID = GetNameSpaceID();
|
|
|
|
|
|
2017-12-31 22:57:32 +03:00
|
|
|
|
if (ShadowRoot* shadowRoot = ShadowRoot::FromNode(this)) {
|
2013-12-02 14:26:12 +04:00
|
|
|
|
// Fix up the context to be the host of the ShadowRoot.
|
2015-03-03 14:09:00 +03:00
|
|
|
|
contextLocalName = shadowRoot->GetHost()->NodeInfo()->NameAtom();
|
2013-12-02 14:26:12 +04:00
|
|
|
|
contextNameSpaceID = shadowRoot->GetHost()->GetNameSpaceID();
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-25 01:56:48 +03:00
|
|
|
|
auto sanitize = (aNeverSanitize ? nsContentUtils::NeverSanitize
|
|
|
|
|
: nsContentUtils::SanitizeSystemPrivileged);
|
|
|
|
|
|
2015-03-03 14:08:59 +03:00
|
|
|
|
if (doc->IsHTMLDocument()) {
|
2013-12-02 14:26:12 +04:00
|
|
|
|
int32_t oldChildCount = target->GetChildCount();
|
|
|
|
|
aError = nsContentUtils::ParseFragmentHTML(aInnerHTML,
|
|
|
|
|
target,
|
|
|
|
|
contextLocalName,
|
|
|
|
|
contextNameSpaceID,
|
|
|
|
|
doc->GetCompatibilityMode() ==
|
|
|
|
|
eCompatibility_NavQuirks,
|
2018-01-25 01:56:48 +03:00
|
|
|
|
true,
|
|
|
|
|
sanitize);
|
2013-12-02 14:26:12 +04:00
|
|
|
|
mb.NodesAdded();
|
|
|
|
|
// HTML5 parser has notified, but not fired mutation events.
|
|
|
|
|
nsContentUtils::FireMutationEventsForDirectParsing(doc, target,
|
|
|
|
|
oldChildCount);
|
|
|
|
|
} else {
|
2015-10-18 08:24:48 +03:00
|
|
|
|
RefPtr<DocumentFragment> df =
|
2018-01-25 01:56:48 +03:00
|
|
|
|
nsContentUtils::CreateContextualFragment(target, aInnerHTML, true,
|
|
|
|
|
sanitize, aError);
|
2013-12-02 14:26:12 +04:00
|
|
|
|
if (!aError.Failed()) {
|
|
|
|
|
// Suppress assertion about node removal mutation events that can't have
|
|
|
|
|
// listeners anyway, because no one has had the chance to register mutation
|
|
|
|
|
// listeners on the fragment that comes from the parser.
|
|
|
|
|
nsAutoScriptBlockerSuppressNodeRemoved scriptBlocker;
|
|
|
|
|
|
2014-01-15 18:26:51 +04:00
|
|
|
|
static_cast<nsINode*>(target)->AppendChild(*df, aError);
|
2013-12-02 14:26:12 +04:00
|
|
|
|
mb.NodesAdded();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-27 17:01:55 +04:00
|
|
|
|
void
|
|
|
|
|
FragmentOrElement::FireNodeRemovedForChildren()
|
|
|
|
|
{
|
|
|
|
|
nsIDocument* doc = OwnerDoc();
|
|
|
|
|
// Optimize the common case
|
|
|
|
|
if (!nsContentUtils::
|
|
|
|
|
HasMutationListeners(doc, NS_EVENT_BITS_MUTATION_NODEREMOVED)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> owningDoc = doc;
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsINode> child;
|
|
|
|
|
for (child = GetFirstChild();
|
2012-10-09 16:31:24 +04:00
|
|
|
|
child && child->GetParentNode() == this;
|
2012-06-27 17:01:55 +04:00
|
|
|
|
child = child->GetNextSibling()) {
|
|
|
|
|
nsContentUtils::MaybeFireNodeRemoved(child, this, doc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Bug 1387956 - Overhaul ComputedValues measurement, and add style structs measurement. r=bholley.
This patch moves measurement of ComputedValues objects from Rust to C++.
Measurement now happens (a) via DOM elements and (b) remaining elements via
the frame tree. Likewise for the style structs hanging off ComputedValues
objects.
Here is an example of the output.
> ├──27,600,448 B (26.49%) -- active/window(https://en.wikipedia.org/wiki/Barack_Obama)
> │ ├──12,772,544 B (12.26%) -- layout
> │ │ ├───4,483,744 B (04.30%) -- frames
> │ │ │ ├──1,653,552 B (01.59%) ── nsInlineFrame
> │ │ │ ├──1,415,760 B (01.36%) ── nsTextFrame
> │ │ │ ├────431,376 B (00.41%) ── nsBlockFrame
> │ │ │ ├────340,560 B (00.33%) ── nsHTMLScrollFrame
> │ │ │ ├────302,544 B (00.29%) ── nsContinuingTextFrame
> │ │ │ ├────156,408 B (00.15%) ── nsBulletFrame
> │ │ │ ├─────73,024 B (00.07%) ── nsPlaceholderFrame
> │ │ │ ├─────27,656 B (00.03%) ── sundries
> │ │ │ ├─────23,520 B (00.02%) ── nsTableCellFrame
> │ │ │ ├─────16,704 B (00.02%) ── nsImageFrame
> │ │ │ ├─────15,488 B (00.01%) ── nsTableRowFrame
> │ │ │ ├─────13,776 B (00.01%) ── nsTableColFrame
> │ │ │ └─────13,376 B (00.01%) ── nsTableFrame
> │ │ ├───3,412,192 B (03.28%) -- servo-style-structs
> │ │ │ ├──1,288,224 B (01.24%) ── Display
> │ │ │ ├────742,400 B (00.71%) ── Position
> │ │ │ ├────308,736 B (00.30%) ── Font
> │ │ │ ├────226,512 B (00.22%) ── Background
> │ │ │ ├────218,304 B (00.21%) ── TextReset
> │ │ │ ├────214,896 B (00.21%) ── Text
> │ │ │ ├────130,560 B (00.13%) ── Border
> │ │ │ ├─────81,408 B (00.08%) ── UIReset
> │ │ │ ├─────61,440 B (00.06%) ── Padding
> │ │ │ ├─────38,176 B (00.04%) ── UserInterface
> │ │ │ ├─────29,232 B (00.03%) ── Margin
> │ │ │ ├─────21,824 B (00.02%) ── sundries
> │ │ │ ├─────20,080 B (00.02%) ── Color
> │ │ │ ├─────20,080 B (00.02%) ── Column
> │ │ │ └─────10,320 B (00.01%) ── Effects
> │ │ ├───2,227,680 B (02.14%) -- computed-values
> │ │ │ ├──1,182,928 B (01.14%) ── non-dom
> │ │ │ └──1,044,752 B (01.00%) ── dom
> │ │ ├───1,500,016 B (01.44%) ── text-runs
> │ │ ├─────492,640 B (00.47%) ── line-boxes
> │ │ ├─────326,688 B (00.31%) ── frame-properties
> │ │ ├─────301,760 B (00.29%) ── pres-shell
> │ │ ├──────27,648 B (00.03%) ── pres-contexts
> │ │ └─────────176 B (00.00%) ── style-sets
The 'servo-style-structs' and 'computed-values' sub-trees are new. (Prior to
this patch, ComputedValues under DOM elements were tallied under the the
'dom/element-nodes' sub-tree, and ComputedValues not under DOM element were
ignored.) 'servo-style-structs/sundries' aggregates all the style structs that
are smaller than 8 KiB.
Other notable things done by the patch are as follows.
- It significantly changes the signatures of the methods measuring nsINode and
its subclasses, in order to handle the tallying of style structs separately
from element-nodes. Likewise for nsIFrame.
- It renames the 'layout/style-structs' sub-tree as
'layout/gecko-style-structs', to clearly distinguish it from the new
'layout/servo-style-structs' sub-tree.
- It adds some FFI functions to access various Rust-side data structures from
C++ code.
- There is a nasty hack used twice to measure Arcs, by stepping backwards from
an interior pointer to a base pointer. It works, but I want to replace it
with something better eventually. The "XXX WARNING" comments have details.
- It makes DMD print a line to the console if it sees a pointer it doesn't
recognise. This is useful for detecting when we are measuring an interior
pointer instead of a base pointer, which is bad but easy to do when Arcs are
involved.
- It removes the Rust code for measuring CVs, because it's now all done on the
C++ side.
MozReview-Commit-ID: BKebACLKtCi
--HG--
extra : rebase_source : 4d9a8c6b198a0ff025b811759a6bfa9f33a260ba
2017-08-11 09:37:33 +03:00
|
|
|
|
void
|
2017-08-25 07:47:54 +03:00
|
|
|
|
FragmentOrElement::AddSizeOfExcludingThis(nsWindowSizes& aSizes,
|
Bug 1387956 - Overhaul ComputedValues measurement, and add style structs measurement. r=bholley.
This patch moves measurement of ComputedValues objects from Rust to C++.
Measurement now happens (a) via DOM elements and (b) remaining elements via
the frame tree. Likewise for the style structs hanging off ComputedValues
objects.
Here is an example of the output.
> ├──27,600,448 B (26.49%) -- active/window(https://en.wikipedia.org/wiki/Barack_Obama)
> │ ├──12,772,544 B (12.26%) -- layout
> │ │ ├───4,483,744 B (04.30%) -- frames
> │ │ │ ├──1,653,552 B (01.59%) ── nsInlineFrame
> │ │ │ ├──1,415,760 B (01.36%) ── nsTextFrame
> │ │ │ ├────431,376 B (00.41%) ── nsBlockFrame
> │ │ │ ├────340,560 B (00.33%) ── nsHTMLScrollFrame
> │ │ │ ├────302,544 B (00.29%) ── nsContinuingTextFrame
> │ │ │ ├────156,408 B (00.15%) ── nsBulletFrame
> │ │ │ ├─────73,024 B (00.07%) ── nsPlaceholderFrame
> │ │ │ ├─────27,656 B (00.03%) ── sundries
> │ │ │ ├─────23,520 B (00.02%) ── nsTableCellFrame
> │ │ │ ├─────16,704 B (00.02%) ── nsImageFrame
> │ │ │ ├─────15,488 B (00.01%) ── nsTableRowFrame
> │ │ │ ├─────13,776 B (00.01%) ── nsTableColFrame
> │ │ │ └─────13,376 B (00.01%) ── nsTableFrame
> │ │ ├───3,412,192 B (03.28%) -- servo-style-structs
> │ │ │ ├──1,288,224 B (01.24%) ── Display
> │ │ │ ├────742,400 B (00.71%) ── Position
> │ │ │ ├────308,736 B (00.30%) ── Font
> │ │ │ ├────226,512 B (00.22%) ── Background
> │ │ │ ├────218,304 B (00.21%) ── TextReset
> │ │ │ ├────214,896 B (00.21%) ── Text
> │ │ │ ├────130,560 B (00.13%) ── Border
> │ │ │ ├─────81,408 B (00.08%) ── UIReset
> │ │ │ ├─────61,440 B (00.06%) ── Padding
> │ │ │ ├─────38,176 B (00.04%) ── UserInterface
> │ │ │ ├─────29,232 B (00.03%) ── Margin
> │ │ │ ├─────21,824 B (00.02%) ── sundries
> │ │ │ ├─────20,080 B (00.02%) ── Color
> │ │ │ ├─────20,080 B (00.02%) ── Column
> │ │ │ └─────10,320 B (00.01%) ── Effects
> │ │ ├───2,227,680 B (02.14%) -- computed-values
> │ │ │ ├──1,182,928 B (01.14%) ── non-dom
> │ │ │ └──1,044,752 B (01.00%) ── dom
> │ │ ├───1,500,016 B (01.44%) ── text-runs
> │ │ ├─────492,640 B (00.47%) ── line-boxes
> │ │ ├─────326,688 B (00.31%) ── frame-properties
> │ │ ├─────301,760 B (00.29%) ── pres-shell
> │ │ ├──────27,648 B (00.03%) ── pres-contexts
> │ │ └─────────176 B (00.00%) ── style-sets
The 'servo-style-structs' and 'computed-values' sub-trees are new. (Prior to
this patch, ComputedValues under DOM elements were tallied under the the
'dom/element-nodes' sub-tree, and ComputedValues not under DOM element were
ignored.) 'servo-style-structs/sundries' aggregates all the style structs that
are smaller than 8 KiB.
Other notable things done by the patch are as follows.
- It significantly changes the signatures of the methods measuring nsINode and
its subclasses, in order to handle the tallying of style structs separately
from element-nodes. Likewise for nsIFrame.
- It renames the 'layout/style-structs' sub-tree as
'layout/gecko-style-structs', to clearly distinguish it from the new
'layout/servo-style-structs' sub-tree.
- It adds some FFI functions to access various Rust-side data structures from
C++ code.
- There is a nasty hack used twice to measure Arcs, by stepping backwards from
an interior pointer to a base pointer. It works, but I want to replace it
with something better eventually. The "XXX WARNING" comments have details.
- It makes DMD print a line to the console if it sees a pointer it doesn't
recognise. This is useful for detecting when we are measuring an interior
pointer instead of a base pointer, which is bad but easy to do when Arcs are
involved.
- It removes the Rust code for measuring CVs, because it's now all done on the
C++ side.
MozReview-Commit-ID: BKebACLKtCi
--HG--
extra : rebase_source : 4d9a8c6b198a0ff025b811759a6bfa9f33a260ba
2017-08-11 09:37:33 +03:00
|
|
|
|
size_t* aNodeSize) const
|
2012-06-27 17:01:55 +04:00
|
|
|
|
{
|
2017-08-25 07:47:54 +03:00
|
|
|
|
nsIContent::AddSizeOfExcludingThis(aSizes, aNodeSize);
|
|
|
|
|
*aNodeSize +=
|
|
|
|
|
mAttrsAndChildren.SizeOfExcludingThis(aSizes.mState.mMallocSizeOf);
|
2012-09-30 20:43:47 +04:00
|
|
|
|
|
|
|
|
|
nsDOMSlots* slots = GetExistingDOMSlots();
|
|
|
|
|
if (slots) {
|
2017-08-25 07:47:54 +03:00
|
|
|
|
*aNodeSize += slots->SizeOfIncludingThis(aSizes.mState.mMallocSizeOf);
|
2012-09-30 20:43:47 +04:00
|
|
|
|
}
|
2012-06-27 17:01:55 +04:00
|
|
|
|
}
|
2014-06-06 09:23:40 +04:00
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FragmentOrElement::SetIsElementInStyleScopeFlagOnSubtree(bool aInStyleScope)
|
|
|
|
|
{
|
|
|
|
|
if (aInStyleScope && IsElementInStyleScope()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (IsElement()) {
|
|
|
|
|
SetIsElementInStyleScope(aInStyleScope);
|
|
|
|
|
SetIsElementInStyleScopeFlagOnShadowTree(aInStyleScope);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsIContent* n = GetNextNode(this);
|
|
|
|
|
while (n) {
|
|
|
|
|
if (n->IsElementInStyleScope()) {
|
|
|
|
|
n = n->GetNextNonChildNode(this);
|
|
|
|
|
} else {
|
|
|
|
|
if (n->IsElement()) {
|
|
|
|
|
n->SetIsElementInStyleScope(aInStyleScope);
|
|
|
|
|
n->AsElement()->SetIsElementInStyleScopeFlagOnShadowTree(aInStyleScope);
|
|
|
|
|
}
|
|
|
|
|
n = n->GetNextNode(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FragmentOrElement::SetIsElementInStyleScopeFlagOnShadowTree(bool aInStyleScope)
|
|
|
|
|
{
|
|
|
|
|
NS_ASSERTION(IsElement(), "calling SetIsElementInStyleScopeFlagOnShadowTree "
|
|
|
|
|
"on a non-Element is useless");
|
|
|
|
|
ShadowRoot* shadowRoot = GetShadowRoot();
|
2017-09-25 18:09:26 +03:00
|
|
|
|
if (shadowRoot) {
|
2014-06-06 09:23:40 +04:00
|
|
|
|
shadowRoot->SetIsElementInStyleScopeFlagOnSubtree(aInStyleScope);
|
|
|
|
|
}
|
|
|
|
|
}
|