2014-08-27 09:46:24 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-01-12 11:45:23 +03:00
|
|
|
|
2006-03-30 12:03:04 +04:00
|
|
|
/*
|
2013-03-10 12:00:33 +04:00
|
|
|
* Implementation of the |attributes| property of DOM Core's Element object.
|
2006-03-30 12:03:04 +04:00
|
|
|
*/
|
|
|
|
|
1999-01-12 11:45:23 +03:00
|
|
|
#include "nsDOMAttributeMap.h"
|
2013-04-26 10:48:23 +04:00
|
|
|
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2013-04-09 19:29:44 +04:00
|
|
|
#include "mozilla/dom/Attr.h"
|
2012-11-15 02:10:08 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2014-08-25 13:25:34 +04:00
|
|
|
#include "mozilla/dom/NamedNodeMapBinding.h"
|
2015-02-04 08:46:23 +03:00
|
|
|
#include "mozilla/dom/NodeInfoInlines.h"
|
2013-04-26 10:48:23 +04:00
|
|
|
#include "nsAttrName.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsError.h"
|
2013-10-02 15:40:07 +04:00
|
|
|
#include "nsIContentInlines.h"
|
2008-02-22 05:18:43 +03:00
|
|
|
#include "nsIDocument.h"
|
2014-02-28 03:04:46 +04:00
|
|
|
#include "nsNameSpaceManager.h"
|
2004-06-25 16:26:02 +04:00
|
|
|
#include "nsNodeInfoManager.h"
|
2009-12-28 17:35:06 +03:00
|
|
|
#include "nsUnicharUtils.h"
|
2013-05-07 03:37:47 +04:00
|
|
|
#include "nsWrapperCacheInlines.h"
|
1999-01-12 11:45:23 +03:00
|
|
|
|
2012-10-16 15:51:00 +04:00
|
|
|
using namespace mozilla;
|
2013-04-09 19:29:44 +04:00
|
|
|
using namespace mozilla::dom;
|
2012-10-16 15:51:00 +04:00
|
|
|
|
1999-01-12 11:45:23 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2010-07-30 17:42:11 +04:00
|
|
|
nsDOMAttributeMap::nsDOMAttributeMap(Element* aContent)
|
1999-01-12 11:45:23 +03:00
|
|
|
: mContent(aContent)
|
|
|
|
{
|
|
|
|
// We don't add a reference to our content. If it goes away,
|
|
|
|
// we'll be told to drop our reference
|
2005-06-01 17:46:20 +04:00
|
|
|
}
|
|
|
|
|
1999-01-12 11:45:23 +03:00
|
|
|
nsDOMAttributeMap::~nsDOMAttributeMap()
|
|
|
|
{
|
2016-01-29 01:44:46 +03:00
|
|
|
DropReference();
|
1999-01-12 11:45:23 +03:00
|
|
|
}
|
|
|
|
|
2000-04-14 03:42:52 +04:00
|
|
|
void
|
1999-01-12 11:45:23 +03:00
|
|
|
nsDOMAttributeMap::DropReference()
|
|
|
|
{
|
2016-01-29 01:44:46 +03:00
|
|
|
for (auto iter = mAttributeCache.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
iter.Data()->SetMap(nullptr);
|
|
|
|
iter.Remove();
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
mContent = nullptr;
|
1999-01-12 11:45:23 +03:00
|
|
|
}
|
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsDOMAttributeMap)
|
|
|
|
|
2007-02-18 17:38:04 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDOMAttributeMap)
|
2007-01-05 01:31:26 +03:00
|
|
|
tmp->DropReference();
|
2013-04-26 10:48:27 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
2013-05-07 03:37:47 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mContent)
|
2007-01-05 01:31:26 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
|
2007-02-18 17:38:04 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDOMAttributeMap)
|
2016-01-29 01:44:46 +03:00
|
|
|
for (auto iter = tmp->mAttributeCache.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
cb.NoteXPCOMChild(static_cast<nsINode*>(iter.Data().get()));
|
|
|
|
}
|
2013-05-07 03:37:47 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mContent)
|
2007-01-05 01:31:26 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2013-04-26 10:48:27 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(nsDOMAttributeMap)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
|
2013-05-07 03:37:47 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(nsDOMAttributeMap)
|
2017-01-25 04:38:58 +03:00
|
|
|
if (tmp->HasKnownLiveWrapper()) {
|
2013-05-07 03:37:47 +04:00
|
|
|
if (tmp->mContent) {
|
|
|
|
// The map owns the element so we can mark it when the
|
|
|
|
// map itself is certainly alive.
|
|
|
|
mozilla::dom::FragmentOrElement::MarkNodeChildren(tmp->mContent);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (tmp->mContent &&
|
|
|
|
mozilla::dom::FragmentOrElement::CanSkip(tmp->mContent, true)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_BEGIN(nsDOMAttributeMap)
|
2017-01-25 04:39:37 +03:00
|
|
|
return tmp->HasKnownLiveWrapperAndDoesNotNeedTracing(tmp);
|
2013-05-07 03:37:47 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_BEGIN(nsDOMAttributeMap)
|
2017-01-25 04:38:58 +03:00
|
|
|
return tmp->HasKnownLiveWrapper();
|
2013-05-07 03:37:47 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_END
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
// QueryInterface implementation for nsDOMAttributeMap
|
2018-01-21 04:57:26 +03:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsDOMAttributeMap)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2008-11-03 13:31:47 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(nsDOMAttributeMap)
|
2018-01-21 04:57:26 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2000-04-14 03:42:52 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
1999-01-12 11:45:23 +03:00
|
|
|
|
2007-01-05 01:31:26 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMAttributeMap)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMAttributeMap)
|
1999-01-12 11:45:23 +03:00
|
|
|
|
2005-12-29 06:01:58 +03:00
|
|
|
nsresult
|
|
|
|
nsDOMAttributeMap::SetOwnerDocument(nsIDocument* aDocument)
|
|
|
|
{
|
2015-11-04 03:00:38 +03:00
|
|
|
for (auto iter = mAttributeCache.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
nsresult rv = iter.Data()->SetOwnerDocument(aDocument);
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
|
|
|
}
|
2005-12-29 06:01:58 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2005-06-01 17:46:20 +04:00
|
|
|
|
|
|
|
void
|
2017-10-03 01:05:19 +03:00
|
|
|
nsDOMAttributeMap::DropAttribute(int32_t aNamespaceID, nsAtom* aLocalName)
|
2005-06-01 17:46:20 +04:00
|
|
|
{
|
2005-06-10 00:17:40 +04:00
|
|
|
nsAttrKey attr(aNamespaceID, aLocalName);
|
2017-06-18 18:07:54 +03:00
|
|
|
if (auto entry = mAttributeCache.Lookup(attr)) {
|
|
|
|
entry.Data()->SetMap(nullptr); // break link to map
|
|
|
|
entry.Remove();
|
|
|
|
}
|
2005-06-01 17:46:20 +04:00
|
|
|
}
|
|
|
|
|
2013-04-09 19:29:44 +04:00
|
|
|
Attr*
|
2016-01-11 21:01:33 +03:00
|
|
|
nsDOMAttributeMap::GetAttribute(mozilla::dom::NodeInfo* aNodeInfo)
|
2008-10-22 18:31:14 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ASSERTION(aNodeInfo, "GetAttribute() called with aNodeInfo == nullptr!");
|
2008-10-22 18:31:14 +04:00
|
|
|
|
|
|
|
nsAttrKey attr(aNodeInfo->NamespaceID(), aNodeInfo->NameAtom());
|
|
|
|
|
2017-06-07 21:03:19 +03:00
|
|
|
RefPtr<Attr>& entryValue = mAttributeCache.GetOrInsert(attr);
|
|
|
|
Attr* node = entryValue;
|
2008-10-22 18:31:14 +04:00
|
|
|
if (!node) {
|
2017-06-07 21:03:19 +03:00
|
|
|
// Newly inserted entry!
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> ni = aNodeInfo;
|
2017-06-07 21:03:19 +03:00
|
|
|
entryValue = new Attr(this, ni.forget(), EmptyString());
|
|
|
|
node = entryValue;
|
2008-10-22 18:31:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2013-04-09 19:29:44 +04:00
|
|
|
Attr*
|
2013-04-26 10:48:23 +04:00
|
|
|
nsDOMAttributeMap::NamedGetter(const nsAString& aAttrName, bool& aFound)
|
1999-01-12 11:45:23 +03:00
|
|
|
{
|
2013-04-26 10:48:23 +04:00
|
|
|
aFound = false;
|
2013-04-26 10:48:15 +04:00
|
|
|
NS_ENSURE_TRUE(mContent, nullptr);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> ni = mContent->GetExistingAttrNameFromQName(aAttrName);
|
2013-04-26 10:48:15 +04:00
|
|
|
if (!ni) {
|
|
|
|
return nullptr;
|
1999-01-12 11:45:23 +03:00
|
|
|
}
|
|
|
|
|
2013-04-26 10:48:23 +04:00
|
|
|
aFound = true;
|
2016-01-11 21:01:33 +03:00
|
|
|
return GetAttribute(ni);
|
2008-11-01 00:40:35 +03:00
|
|
|
}
|
|
|
|
|
2015-12-08 02:42:36 +03:00
|
|
|
void
|
2016-05-10 05:25:40 +03:00
|
|
|
nsDOMAttributeMap::GetSupportedNames(nsTArray<nsString>& aNames)
|
2015-12-08 02:42:36 +03:00
|
|
|
{
|
2016-01-15 21:29:58 +03:00
|
|
|
// For HTML elements in HTML documents, only include names that are still the
|
|
|
|
// same after ASCII-lowercasing, since our named getter will end up
|
|
|
|
// ASCII-lowercasing the given string.
|
|
|
|
bool lowercaseNamesOnly =
|
|
|
|
mContent->IsHTMLElement() && mContent->IsInHTMLDocument();
|
|
|
|
|
2015-12-08 02:42:36 +03:00
|
|
|
const uint32_t count = mContent->GetAttrCount();
|
|
|
|
bool seenNonAtomName = false;
|
|
|
|
for (uint32_t i = 0; i < count; i++) {
|
|
|
|
const nsAttrName* name = mContent->GetAttrNameAt(i);
|
|
|
|
seenNonAtomName = seenNonAtomName || !name->IsAtom();
|
|
|
|
nsString qualifiedName;
|
|
|
|
name->GetQualifiedName(qualifiedName);
|
|
|
|
|
2016-01-15 21:29:58 +03:00
|
|
|
if (lowercaseNamesOnly &&
|
|
|
|
nsContentUtils::StringContainsASCIIUpper(qualifiedName)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Omit duplicates. We only need to do this check if we've seen a non-atom
|
|
|
|
// name, because that's the only way we can have two identical qualified
|
|
|
|
// names.
|
2015-12-08 02:42:36 +03:00
|
|
|
if (seenNonAtomName && aNames.Contains(qualifiedName)) {
|
|
|
|
continue;
|
|
|
|
}
|
2016-01-15 21:29:58 +03:00
|
|
|
|
2015-12-08 02:42:36 +03:00
|
|
|
aNames.AppendElement(qualifiedName);
|
|
|
|
}
|
2014-04-16 06:58:44 +04:00
|
|
|
}
|
|
|
|
|
2013-04-26 10:48:23 +04:00
|
|
|
Attr*
|
|
|
|
nsDOMAttributeMap::GetNamedItem(const nsAString& aAttrName)
|
|
|
|
{
|
|
|
|
bool dummy;
|
|
|
|
return NamedGetter(aAttrName, dummy);
|
|
|
|
}
|
|
|
|
|
2013-04-09 19:29:44 +04:00
|
|
|
already_AddRefed<Attr>
|
2015-12-04 17:51:04 +03:00
|
|
|
nsDOMAttributeMap::SetNamedItemNS(Attr& aAttr, ErrorResult& aError)
|
2005-06-01 17:46:20 +04:00
|
|
|
{
|
2013-04-26 10:48:15 +04:00
|
|
|
NS_ENSURE_TRUE(mContent, nullptr);
|
|
|
|
|
|
|
|
// XXX should check same-origin between mContent and aAttr however
|
|
|
|
// nsContentUtils::CheckSameOrigin can't deal with attributenodes yet
|
2005-12-29 06:01:58 +03:00
|
|
|
|
2013-04-26 10:48:15 +04:00
|
|
|
// Check that attribute is not owned by somebody else
|
2013-04-26 10:48:23 +04:00
|
|
|
nsDOMAttributeMap* owner = aAttr.GetMap();
|
2013-04-26 10:48:15 +04:00
|
|
|
if (owner) {
|
|
|
|
if (owner != this) {
|
|
|
|
aError.Throw(NS_ERROR_DOM_INUSE_ATTRIBUTE_ERR);
|
|
|
|
return nullptr;
|
2003-09-23 17:46:20 +04:00
|
|
|
}
|
|
|
|
|
2013-04-26 10:48:15 +04:00
|
|
|
// setting a preexisting attribute is a no-op, just return the same
|
|
|
|
// node.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Attr> attribute = &aAttr;
|
2013-04-26 10:48:23 +04:00
|
|
|
return attribute.forget();
|
2013-04-26 10:48:15 +04:00
|
|
|
}
|
2008-02-22 05:18:43 +03:00
|
|
|
|
2013-04-26 10:48:15 +04:00
|
|
|
nsresult rv;
|
2013-08-02 14:24:41 +04:00
|
|
|
if (mContent->OwnerDoc() != aAttr.OwnerDoc()) {
|
2016-08-30 17:44:52 +03:00
|
|
|
DebugOnly<void*> adoptedNode =
|
2013-04-26 10:48:23 +04:00
|
|
|
mContent->OwnerDoc()->AdoptNode(aAttr, aError);
|
|
|
|
if (aError.Failed()) {
|
2013-04-26 10:48:15 +04:00
|
|
|
return nullptr;
|
2005-12-29 06:01:58 +03:00
|
|
|
}
|
|
|
|
|
2013-04-26 10:48:23 +04:00
|
|
|
NS_ASSERTION(adoptedNode == &aAttr, "Uh, adopt node changed nodes?");
|
2013-04-26 10:48:15 +04:00
|
|
|
}
|
2000-04-14 03:42:52 +04:00
|
|
|
|
2013-04-26 10:48:15 +04:00
|
|
|
// Get nodeinfo and preexisting attribute (if it exists)
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<NodeInfo> oldNi;
|
2015-09-22 20:13:26 +03:00
|
|
|
|
2015-12-04 17:51:04 +03:00
|
|
|
uint32_t i, count = mContent->GetAttrCount();
|
|
|
|
for (i = 0; i < count; ++i) {
|
|
|
|
const nsAttrName* name = mContent->GetAttrNameAt(i);
|
|
|
|
int32_t attrNS = name->NamespaceID();
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* nameAtom = name->LocalName();
|
2015-12-04 17:51:04 +03:00
|
|
|
|
|
|
|
// we're purposefully ignoring the prefix.
|
|
|
|
if (aAttr.NodeInfo()->Equals(nameAtom, attrNS)) {
|
|
|
|
oldNi = mContent->NodeInfo()->NodeInfoManager()->
|
|
|
|
GetNodeInfo(nameAtom, name->GetPrefix(), aAttr.NodeInfo()->NamespaceID(),
|
2018-01-30 07:10:53 +03:00
|
|
|
nsINode::ATTRIBUTE_NODE);
|
2015-12-04 17:51:04 +03:00
|
|
|
break;
|
2015-09-22 20:13:26 +03:00
|
|
|
}
|
|
|
|
}
|
2000-04-14 03:42:52 +04:00
|
|
|
|
2016-01-11 21:01:35 +03:00
|
|
|
RefPtr<Attr> oldAttr;
|
2013-04-26 10:48:15 +04:00
|
|
|
|
2015-09-22 20:13:26 +03:00
|
|
|
if (oldNi) {
|
2016-01-11 21:01:35 +03:00
|
|
|
oldAttr = GetAttribute(oldNi);
|
2005-12-29 06:01:58 +03:00
|
|
|
|
2015-09-22 20:13:26 +03:00
|
|
|
if (oldAttr == &aAttr) {
|
|
|
|
return oldAttr.forget();
|
2013-04-26 10:48:15 +04:00
|
|
|
}
|
|
|
|
|
2015-09-22 20:13:26 +03:00
|
|
|
if (oldAttr) {
|
2016-01-11 21:01:35 +03:00
|
|
|
// Just remove it from our hashtable. This has no side-effects, so we
|
|
|
|
// don't have to recheck anything after we do it. Then we'll add our new
|
|
|
|
// Attr to the hashtable and do the actual attr set on the element. This
|
|
|
|
// will make the whole thing look like a single attribute mutation (with
|
|
|
|
// the new attr node in place) as opposed to a removal and addition.
|
|
|
|
DropAttribute(oldNi->NamespaceID(), oldNi->NameAtom());
|
2005-06-01 17:46:20 +04:00
|
|
|
}
|
2013-04-26 10:48:15 +04:00
|
|
|
}
|
2006-12-20 23:55:08 +03:00
|
|
|
|
2013-04-26 10:48:15 +04:00
|
|
|
nsAutoString value;
|
2013-04-26 10:48:23 +04:00
|
|
|
aAttr.GetValue(value);
|
2006-12-20 23:55:08 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<NodeInfo> ni = aAttr.NodeInfo();
|
2015-09-22 20:13:26 +03:00
|
|
|
|
2013-04-26 10:48:15 +04:00
|
|
|
// Add the new attribute to the attribute map before updating
|
|
|
|
// its value in the element. @see bug 364413.
|
|
|
|
nsAttrKey attrkey(ni->NamespaceID(), ni->NameAtom());
|
2015-02-03 11:03:28 +03:00
|
|
|
mAttributeCache.Put(attrkey, &aAttr);
|
2013-04-26 10:48:23 +04:00
|
|
|
aAttr.SetMap(this);
|
2000-04-14 03:42:52 +04:00
|
|
|
|
2013-04-26 10:48:15 +04:00
|
|
|
rv = mContent->SetAttr(ni->NamespaceID(), ni->NameAtom(),
|
|
|
|
ni->GetPrefixAtom(), value, true);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
DropAttribute(ni->NamespaceID(), ni->NameAtom());
|
2017-02-28 22:50:35 +03:00
|
|
|
aError.Throw(rv);
|
|
|
|
return nullptr;
|
2012-10-16 15:51:00 +04:00
|
|
|
}
|
2005-06-01 17:46:20 +04:00
|
|
|
|
2016-01-11 21:01:35 +03:00
|
|
|
return oldAttr.forget();
|
1999-01-12 11:45:23 +03:00
|
|
|
}
|
|
|
|
|
2015-09-22 20:13:26 +03:00
|
|
|
already_AddRefed<Attr>
|
|
|
|
nsDOMAttributeMap::RemoveNamedItem(NodeInfo* aNodeInfo, ErrorResult& aError)
|
|
|
|
{
|
2016-01-11 21:01:33 +03:00
|
|
|
RefPtr<Attr> attribute = GetAttribute(aNodeInfo);
|
2015-09-22 20:13:26 +03:00
|
|
|
// This removes the attribute node from the attribute map.
|
|
|
|
aError = mContent->UnsetAttr(aNodeInfo->NamespaceID(), aNodeInfo->NameAtom(), true);
|
|
|
|
return attribute.forget();
|
|
|
|
}
|
|
|
|
|
2013-04-26 10:48:23 +04:00
|
|
|
already_AddRefed<Attr>
|
|
|
|
nsDOMAttributeMap::RemoveNamedItem(const nsAString& aName, ErrorResult& aError)
|
|
|
|
{
|
2013-05-07 03:37:47 +04:00
|
|
|
if (!mContent) {
|
|
|
|
aError.Throw(NS_ERROR_DOM_NOT_FOUND_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2000-04-14 03:42:52 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> ni = mContent->GetExistingAttrNameFromQName(aName);
|
2013-04-26 10:48:15 +04:00
|
|
|
if (!ni) {
|
2013-04-26 10:48:23 +04:00
|
|
|
aError.Throw(NS_ERROR_DOM_NOT_FOUND_ERR);
|
|
|
|
return nullptr;
|
1999-01-12 11:45:23 +03:00
|
|
|
}
|
|
|
|
|
2015-09-22 20:13:26 +03:00
|
|
|
return RemoveNamedItem(ni, aError);
|
1999-01-12 11:45:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-09 19:29:44 +04:00
|
|
|
Attr*
|
2013-04-26 10:48:23 +04:00
|
|
|
nsDOMAttributeMap::IndexedGetter(uint32_t aIndex, bool& aFound)
|
1999-01-12 11:45:23 +03:00
|
|
|
{
|
2013-04-26 10:48:23 +04:00
|
|
|
aFound = false;
|
2013-04-26 10:48:15 +04:00
|
|
|
NS_ENSURE_TRUE(mContent, nullptr);
|
2000-04-14 03:42:52 +04:00
|
|
|
|
2013-04-26 10:48:15 +04:00
|
|
|
const nsAttrName* name = mContent->GetAttrNameAt(aIndex);
|
|
|
|
NS_ENSURE_TRUE(name, nullptr);
|
|
|
|
|
2013-04-26 10:48:23 +04:00
|
|
|
aFound = true;
|
|
|
|
// Don't use the nodeinfo even if one exists since it can have the wrong
|
|
|
|
// owner document.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> ni = mContent->NodeInfo()->NodeInfoManager()->
|
2013-04-26 10:48:15 +04:00
|
|
|
GetNodeInfo(name->LocalName(), name->GetPrefix(), name->NamespaceID(),
|
2018-01-30 07:10:53 +03:00
|
|
|
nsINode::ATTRIBUTE_NODE);
|
2016-01-11 21:01:33 +03:00
|
|
|
return GetAttribute(ni);
|
2008-10-22 18:31:14 +04:00
|
|
|
}
|
2005-12-29 00:52:39 +03:00
|
|
|
|
2013-04-26 10:48:23 +04:00
|
|
|
Attr*
|
|
|
|
nsDOMAttributeMap::Item(uint32_t aIndex)
|
|
|
|
{
|
|
|
|
bool dummy;
|
|
|
|
return IndexedGetter(aIndex, dummy);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
nsDOMAttributeMap::Length() const
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mContent, 0);
|
|
|
|
|
|
|
|
return mContent->GetAttrCount();
|
|
|
|
}
|
|
|
|
|
2013-04-09 19:29:44 +04:00
|
|
|
Attr*
|
2012-10-16 15:51:00 +04:00
|
|
|
nsDOMAttributeMap::GetNamedItemNS(const nsAString& aNamespaceURI,
|
2013-04-04 16:01:11 +04:00
|
|
|
const nsAString& aLocalName)
|
2000-04-14 01:21:02 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> ni = GetAttrNodeInfo(aNamespaceURI, aLocalName);
|
2012-10-16 15:51:00 +04:00
|
|
|
if (!ni) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-01-11 21:01:33 +03:00
|
|
|
return GetAttribute(ni);
|
2012-10-16 15:51:00 +04:00
|
|
|
}
|
2000-06-23 04:21:32 +04:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>
|
2012-10-16 15:51:00 +04:00
|
|
|
nsDOMAttributeMap::GetAttrNodeInfo(const nsAString& aNamespaceURI,
|
2013-04-04 16:01:11 +04:00
|
|
|
const nsAString& aLocalName)
|
2012-10-16 15:51:00 +04:00
|
|
|
{
|
2004-01-15 20:07:27 +03:00
|
|
|
if (!mContent) {
|
2012-10-16 15:51:00 +04:00
|
|
|
return nullptr;
|
2004-01-15 20:07:27 +03:00
|
|
|
}
|
2000-06-23 04:21:32 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t nameSpaceID = kNameSpaceID_None;
|
2000-06-23 04:21:32 +04:00
|
|
|
|
2004-01-15 20:07:27 +03:00
|
|
|
if (!aNamespaceURI.IsEmpty()) {
|
2005-09-11 15:24:16 +04:00
|
|
|
nameSpaceID =
|
2016-06-28 17:24:48 +03:00
|
|
|
nsContentUtils::NameSpaceManager()->GetNameSpaceID(aNamespaceURI,
|
|
|
|
nsContentUtils::IsChromeDoc(mContent->OwnerDoc()));
|
2000-06-23 04:21:32 +04:00
|
|
|
|
2004-01-15 20:07:27 +03:00
|
|
|
if (nameSpaceID == kNameSpaceID_Unknown) {
|
2012-10-16 15:51:00 +04:00
|
|
|
return nullptr;
|
2000-06-23 04:21:32 +04:00
|
|
|
}
|
2004-01-15 20:07:27 +03:00
|
|
|
}
|
2000-06-23 04:21:32 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t i, count = mContent->GetAttrCount();
|
2004-01-15 20:07:27 +03:00
|
|
|
for (i = 0; i < count; ++i) {
|
2005-12-29 00:52:39 +03:00
|
|
|
const nsAttrName* name = mContent->GetAttrNameAt(i);
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t attrNS = name->NamespaceID();
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* nameAtom = name->LocalName();
|
2005-12-29 00:52:39 +03:00
|
|
|
|
2015-09-22 20:13:26 +03:00
|
|
|
// we're purposefully ignoring the prefix.
|
2004-01-15 20:07:27 +03:00
|
|
|
if (nameSpaceID == attrNS &&
|
2010-03-08 18:45:00 +03:00
|
|
|
nameAtom->Equals(aLocalName)) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> ni;
|
2008-09-13 02:32:18 +04:00
|
|
|
ni = mContent->NodeInfo()->NodeInfoManager()->
|
2011-06-14 11:56:49 +04:00
|
|
|
GetNodeInfo(nameAtom, name->GetPrefix(), nameSpaceID,
|
2018-01-30 07:10:53 +03:00
|
|
|
nsINode::ATTRIBUTE_NODE);
|
2010-04-19 19:41:39 +04:00
|
|
|
|
2012-10-16 15:51:00 +04:00
|
|
|
return ni.forget();
|
2000-06-23 04:21:32 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-16 15:51:00 +04:00
|
|
|
return nullptr;
|
2000-04-14 01:21:02 +04:00
|
|
|
}
|
|
|
|
|
2013-04-26 10:48:23 +04:00
|
|
|
already_AddRefed<Attr>
|
|
|
|
nsDOMAttributeMap::RemoveNamedItemNS(const nsAString& aNamespaceURI,
|
|
|
|
const nsAString& aLocalName,
|
|
|
|
ErrorResult& aError)
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> ni = GetAttrNodeInfo(aNamespaceURI, aLocalName);
|
2012-10-16 15:51:00 +04:00
|
|
|
if (!ni) {
|
2013-04-26 10:48:23 +04:00
|
|
|
aError.Throw(NS_ERROR_DOM_NOT_FOUND_ERR);
|
|
|
|
return nullptr;
|
2004-01-15 20:07:27 +03:00
|
|
|
}
|
2000-06-23 04:21:32 +04:00
|
|
|
|
2015-09-22 20:13:26 +03:00
|
|
|
return RemoveNamedItem(ni, aError);
|
2000-04-14 01:21:02 +04:00
|
|
|
}
|
2006-07-29 20:02:11 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t
|
2006-07-29 20:02:11 +04:00
|
|
|
nsDOMAttributeMap::Count() const
|
|
|
|
{
|
2015-02-03 11:03:28 +03:00
|
|
|
return mAttributeCache.Count();
|
2006-07-29 20:02:11 +04:00
|
|
|
}
|
|
|
|
|
2012-09-30 20:43:47 +04:00
|
|
|
size_t
|
2013-06-23 16:03:39 +04:00
|
|
|
nsDOMAttributeMap::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
|
2012-09-30 20:43:47 +04:00
|
|
|
{
|
|
|
|
size_t n = aMallocSizeOf(this);
|
2015-07-31 07:19:57 +03:00
|
|
|
|
|
|
|
n += mAttributeCache.ShallowSizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
for (auto iter = mAttributeCache.ConstIter(); !iter.Done(); iter.Next()) {
|
|
|
|
n += aMallocSizeOf(iter.Data().get());
|
|
|
|
}
|
2012-09-30 20:43:47 +04:00
|
|
|
|
|
|
|
// NB: mContent is non-owning and thus not counted.
|
|
|
|
return n;
|
|
|
|
}
|
2013-04-26 10:48:27 +04:00
|
|
|
|
|
|
|
/* virtual */ JSObject*
|
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
|
|
|
nsDOMAttributeMap::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-04-26 10:48:27 +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 NamedNodeMapBinding::Wrap(aCx, this, aGivenProto);
|
2013-04-26 10:48:27 +04:00
|
|
|
}
|
2017-11-27 11:10:27 +03:00
|
|
|
|
|
|
|
DocGroup*
|
|
|
|
nsDOMAttributeMap::GetDocGroup() const
|
|
|
|
{
|
|
|
|
return mContent ? mContent->OwnerDoc()->GetDocGroup() : nullptr;
|
|
|
|
}
|