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-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
|
|
|
/*
|
2018-01-21 20:07:31 +03:00
|
|
|
* Implementation of DOM Core's Attr node.
|
2006-03-30 12:03:04 +04:00
|
|
|
*/
|
|
|
|
|
2013-04-09 19:29:44 +04:00
|
|
|
#include "mozilla/dom/Attr.h"
|
2013-04-09 19:29:47 +04:00
|
|
|
#include "mozilla/dom/AttrBinding.h"
|
2010-08-24 11:05:56 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2014-03-18 08:48:21 +04:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2014-02-27 14:51:15 +04:00
|
|
|
#include "mozilla/InternalMutationEvent.h"
|
2006-07-19 08:36:36 +04:00
|
|
|
#include "nsContentCreatorFunctions.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2002-05-14 05:28:17 +04:00
|
|
|
#include "nsUnicharUtils.h"
|
2004-04-01 23:44:17 +04:00
|
|
|
#include "nsDOMString.h"
|
2013-10-02 15:40:07 +04:00
|
|
|
#include "nsIContentInlines.h"
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2006-04-07 00:54:53 +04:00
|
|
|
#include "nsGkAtoms.h"
|
2006-06-02 16:33:17 +04:00
|
|
|
#include "nsCOMArray.h"
|
2014-02-28 03:04:46 +04:00
|
|
|
#include "nsNameSpaceManager.h"
|
2008-10-15 13:40:28 +04:00
|
|
|
#include "nsTextNode.h"
|
|
|
|
#include "mozAutoDocUpdate.h"
|
2011-05-26 23:58:35 +04:00
|
|
|
#include "nsWrapperCacheInlines.h"
|
2018-07-07 02:52:42 +03:00
|
|
|
#include "NodeUbiReporting.h"
|
1999-01-12 11:45:23 +03:00
|
|
|
|
2013-04-09 19:29:44 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2010-08-24 11:05:56 +04:00
|
|
|
|
1999-01-12 11:45:23 +03:00
|
|
|
//----------------------------------------------------------------------
|
2013-04-09 19:29:44 +04:00
|
|
|
bool Attr::sInitialized;
|
1999-01-12 11:45:23 +03:00
|
|
|
|
2013-04-09 19:29:44 +04:00
|
|
|
Attr::Attr(nsDOMAttributeMap* aAttrMap,
|
2018-08-09 02:58:44 +03:00
|
|
|
already_AddRefed<dom::NodeInfo>&& aNodeInfo, const nsAString& aValue)
|
2018-09-21 23:45:49 +03:00
|
|
|
: nsINode(std::move(aNodeInfo)), mAttrMap(aAttrMap), mValue(aValue) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mNodeInfo, "We must get a nodeinfo here!");
|
2018-01-30 07:10:53 +03:00
|
|
|
MOZ_ASSERT(mNodeInfo->NodeType() == ATTRIBUTE_NODE, "Wrong nodeType");
|
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
|
|
|
|
1999-01-12 11:45:23 +03:00
|
|
|
// We don't add a reference to our content. It will tell us
|
|
|
|
// to drop our reference when it goes away.
|
2008-07-12 00:42:19 +04:00
|
|
|
}
|
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(Attr)
|
|
|
|
|
2013-04-09 19:29:44 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Attr)
|
2011-08-28 18:07:24 +04:00
|
|
|
if (!nsINode::Traverse(tmp, cb)) {
|
|
|
|
return NS_SUCCESS_INTERRUPTED_TRAVERSE;
|
|
|
|
}
|
2013-05-07 03:37:47 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAttrMap)
|
2007-01-05 01:31:26 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2013-05-29 03:58:29 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(Attr)
|
2009-05-13 00:20:42 +04:00
|
|
|
|
2013-04-09 19:29:44 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Attr)
|
2011-08-28 18:07:24 +04:00
|
|
|
nsINode::Unlink(tmp);
|
2013-05-07 03:37:47 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mAttrMap)
|
2007-01-05 01:31:26 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2010-01-12 16:08:43 +03:00
|
|
|
|
2013-05-07 03:37:47 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(Attr)
|
2014-04-10 20:09:50 +04:00
|
|
|
Element* ownerElement = tmp->GetElement();
|
2017-01-25 04:38:58 +03:00
|
|
|
if (tmp->HasKnownLiveWrapper()) {
|
2013-05-07 03:37:47 +04:00
|
|
|
if (ownerElement) {
|
|
|
|
// The attribute owns the element via attribute map so we can
|
|
|
|
// mark it when the attribute is certainly alive.
|
|
|
|
mozilla::dom::FragmentOrElement::MarkNodeChildren(ownerElement);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (ownerElement &&
|
|
|
|
mozilla::dom::FragmentOrElement::CanSkip(ownerElement, true)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_BEGIN(Attr)
|
2018-07-13 01:51:52 +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(Attr)
|
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
|
|
|
|
|
2013-04-09 19:29:44 +04:00
|
|
|
// QueryInterface implementation for Attr
|
|
|
|
NS_INTERFACE_TABLE_HEAD(Attr)
|
2014-08-26 03:21:35 +04:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_TABLE_ENTRY
|
2018-07-13 01:51:52 +03:00
|
|
|
NS_INTERFACE_TABLE(Attr, nsINode, EventTarget)
|
2013-05-21 23:59:27 +04:00
|
|
|
NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(Attr)
|
2006-11-11 03:36:03 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY_TEAROFF(nsISupportsWeakReference,
|
|
|
|
new nsNodeSupportsWeakRefTearoff(this))
|
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
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2013-04-09 19:29:44 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(Attr)
|
2019-11-05 17:06:13 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_LAST_RELEASE(Attr, LastRelease())
|
2005-12-03 10:42:40 +03:00
|
|
|
|
2013-04-09 19:29:44 +04:00
|
|
|
void Attr::SetMap(nsDOMAttributeMap* aMap) {
|
2005-08-20 03:40:42 +04:00
|
|
|
if (mAttrMap && !aMap && sInitialized) {
|
2005-06-01 17:46:20 +04:00
|
|
|
// We're breaking a relationship with content and not getting a new one,
|
|
|
|
// need to locally cache value. GetValue() does that.
|
2006-01-25 23:49:56 +03:00
|
|
|
GetValue(mValue);
|
2005-06-01 17:46:20 +04:00
|
|
|
}
|
2010-05-27 23:10:33 +04:00
|
|
|
|
2005-06-01 17:46:20 +04:00
|
|
|
mAttrMap = aMap;
|
|
|
|
}
|
|
|
|
|
2014-04-10 20:09:50 +04:00
|
|
|
Element* Attr::GetElement() const {
|
|
|
|
if (!mAttrMap) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
nsIContent* content = mAttrMap->GetContent();
|
|
|
|
return content ? content->AsElement() : nullptr;
|
2014-03-22 00:02:21 +04:00
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
nsresult Attr::SetOwnerDocument(Document* aDocument) {
|
2005-12-29 06:01:58 +03:00
|
|
|
NS_ASSERTION(aDocument, "Missing document");
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* doc = OwnerDoc();
|
2013-04-09 19:29:44 +04:00
|
|
|
NS_ASSERTION(doc != aDocument, "bad call to Attr::SetOwnerDocument");
|
2011-10-18 15:19:44 +04:00
|
|
|
doc->DeleteAllPropertiesFor(this);
|
2005-12-29 06:01:58 +03:00
|
|
|
|
2018-08-09 02:58:44 +03:00
|
|
|
RefPtr<dom::NodeInfo> newNodeInfo = aDocument->NodeInfoManager()->GetNodeInfo(
|
|
|
|
mNodeInfo->NameAtom(), mNodeInfo->GetPrefixAtom(),
|
|
|
|
mNodeInfo->NamespaceID(), ATTRIBUTE_NODE);
|
2005-12-29 06:01:58 +03:00
|
|
|
NS_ASSERTION(newNodeInfo, "GetNodeInfo lies");
|
|
|
|
mNodeInfo.swap(newNodeInfo);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-04-09 19:29:44 +04:00
|
|
|
void Attr::GetName(nsAString& aName) { aName = NodeName(); }
|
1999-01-12 11:45:23 +03:00
|
|
|
|
2013-04-09 19:29:44 +04:00
|
|
|
void Attr::GetValue(nsAString& aValue) {
|
2014-04-10 20:09:50 +04:00
|
|
|
Element* element = GetElement();
|
|
|
|
if (element) {
|
2017-10-03 01:05:19 +03:00
|
|
|
RefPtr<nsAtom> nameAtom = mNodeInfo->NameAtom();
|
2014-04-10 20:09:50 +04:00
|
|
|
element->GetAttr(mNodeInfo->NamespaceID(), nameAtom, aValue);
|
2006-01-25 23:49:56 +03:00
|
|
|
} else {
|
|
|
|
aValue = mValue;
|
1999-01-12 11:45:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-10 00:33:38 +03:00
|
|
|
void Attr::SetValue(const nsAString& aValue, nsIPrincipal* aTriggeringPrincipal,
|
|
|
|
ErrorResult& aRv) {
|
2014-04-10 20:09:50 +04:00
|
|
|
Element* element = GetElement();
|
|
|
|
if (!element) {
|
2012-04-03 11:25:39 +04:00
|
|
|
mValue = aValue;
|
2013-04-09 19:29:47 +04:00
|
|
|
return;
|
2012-04-03 11:25:39 +04:00
|
|
|
}
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
RefPtr<nsAtom> nameAtom = mNodeInfo->NameAtom();
|
2014-04-10 20:09:50 +04:00
|
|
|
aRv = element->SetAttr(mNodeInfo->NamespaceID(), nameAtom,
|
2013-04-09 19:29:47 +04:00
|
|
|
mNodeInfo->GetPrefixAtom(), aValue,
|
2017-10-10 00:33:38 +03:00
|
|
|
aTriggeringPrincipal, true);
|
2013-04-09 19:29:47 +04:00
|
|
|
}
|
|
|
|
|
2018-01-21 20:07:31 +03:00
|
|
|
void Attr::SetValue(const nsAString& aValue, ErrorResult& aRv) {
|
|
|
|
SetValue(aValue, nullptr, aRv);
|
1999-01-12 11:45:23 +03:00
|
|
|
}
|
|
|
|
|
2013-04-09 19:29:47 +04:00
|
|
|
bool Attr::Specified() const { return true; }
|
2011-06-23 12:30:48 +04:00
|
|
|
|
2014-03-22 00:04:09 +04:00
|
|
|
Element* Attr::GetOwnerElement(ErrorResult& aRv) { return GetElement(); }
|
|
|
|
|
2013-04-09 19:29:44 +04:00
|
|
|
void Attr::GetNodeValueInternal(nsAString& aNodeValue) { GetValue(aNodeValue); }
|
1999-01-12 11:45:23 +03:00
|
|
|
|
2013-04-09 19:29:44 +04:00
|
|
|
void Attr::SetNodeValueInternal(const nsAString& aNodeValue,
|
|
|
|
ErrorResult& aError) {
|
2018-01-21 20:07:31 +03:00
|
|
|
SetValue(aNodeValue, nullptr, aError);
|
1999-01-12 11:45:23 +03:00
|
|
|
}
|
|
|
|
|
2018-08-09 02:58:44 +03:00
|
|
|
nsresult Attr::Clone(dom::NodeInfo* aNodeInfo, nsINode** aResult) const {
|
2005-06-01 17:46:20 +04:00
|
|
|
nsAutoString value;
|
2013-04-09 19:29:44 +04:00
|
|
|
const_cast<Attr*>(this)->GetValue(value);
|
1999-01-12 11:45:23 +03:00
|
|
|
|
2018-08-09 02:58:44 +03:00
|
|
|
*aResult = new Attr(nullptr, do_AddRef(aNodeInfo), value);
|
2006-09-05 14:22:54 +04:00
|
|
|
NS_ADDREF(*aResult);
|
2005-10-27 18:09:23 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
1999-01-12 11:45:23 +03:00
|
|
|
}
|
|
|
|
|
2019-07-15 20:22:30 +03:00
|
|
|
nsIURI* Attr::GetBaseURI(bool aTryUseXHRDocBaseURI) const {
|
2014-04-10 20:09:50 +04:00
|
|
|
Element* parent = GetElement();
|
2010-04-19 19:40:15 +04:00
|
|
|
|
2020-02-04 10:11:26 +03:00
|
|
|
return parent ? parent->GetBaseURI(aTryUseXHRDocBaseURI)
|
|
|
|
: OwnerDoc()->GetBaseURI(aTryUseXHRDocBaseURI);
|
2010-04-19 19:40:15 +04:00
|
|
|
}
|
|
|
|
|
2014-08-05 14:10:00 +04:00
|
|
|
void Attr::GetTextContentInternal(nsAString& aTextContent,
|
2017-01-18 07:52:29 +03:00
|
|
|
OOMReporter& aError) {
|
2012-10-09 16:31:24 +04:00
|
|
|
GetValue(aTextContent);
|
2003-06-25 01:39:39 +04:00
|
|
|
}
|
|
|
|
|
2013-04-09 19:29:44 +04:00
|
|
|
void Attr::SetTextContentInternal(const nsAString& aTextContent,
|
2017-11-08 01:01:21 +03:00
|
|
|
nsIPrincipal* aSubjectPrincipal,
|
2013-04-09 19:29:44 +04:00
|
|
|
ErrorResult& aError) {
|
2012-10-09 16:31:24 +04:00
|
|
|
SetNodeValueInternal(aTextContent, aError);
|
2011-06-14 11:56:48 +04:00
|
|
|
}
|
2003-06-25 01:39:39 +04:00
|
|
|
|
2013-04-09 19:29:44 +04:00
|
|
|
bool Attr::IsNodeOfType(uint32_t aFlags) const { return false; }
|
2006-05-05 10:52:21 +04:00
|
|
|
|
2016-10-21 05:11:07 +03:00
|
|
|
void Attr::GetEventTargetParent(EventChainPreVisitor& aVisitor) {
|
2011-10-17 18:59:28 +04:00
|
|
|
aVisitor.mCanHandle = true;
|
2006-03-07 20:08:51 +03:00
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
void Attr::Initialize() { sInitialized = true; }
|
2005-08-20 03:40:42 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
void Attr::Shutdown() { sInitialized = false; }
|
2013-04-09 19:29:44 +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
|
|
|
JSObject* Attr::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return Attr_Binding::Wrap(aCx, this, aGivenProto);
|
2013-04-09 19:29:47 +04:00
|
|
|
}
|
|
|
|
|
2018-07-07 02:52:42 +03:00
|
|
|
void Attr::ConstructUbiNode(void* storage) {
|
|
|
|
JS::ubi::Concrete<Attr>::construct(storage, this);
|
|
|
|
}
|
|
|
|
|
2013-04-09 19:29:44 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|