2012-06-04 23:49:57 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set tw=80 expandtab softtabstop=2 ts=2 sw=2: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "HTMLPropertiesCollection.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsGenericHTMLElement.h"
|
|
|
|
#include "nsVariant.h"
|
|
|
|
#include "nsDOMSettableTokenList.h"
|
|
|
|
#include "nsAttrValue.h"
|
2012-09-05 20:49:53 +00:00
|
|
|
#include "nsWrapperCacheInlines.h"
|
2012-06-13 15:18:30 +00:00
|
|
|
#include "mozilla/dom/HTMLPropertiesCollectionBinding.h"
|
2013-09-03 05:01:18 +00:00
|
|
|
#include "jsapi.h"
|
2014-12-17 06:26:15 +00:00
|
|
|
#include "MainThreadUtils.h"
|
|
|
|
#include "mozilla/Assertions.h"
|
2012-06-04 23:49:57 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2013-08-02 01:29:05 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLPropertiesCollection)
|
|
|
|
|
2012-06-04 23:49:57 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(HTMLPropertiesCollection)
|
2012-07-30 14:20:58 +00:00
|
|
|
// SetDocument(nullptr) ensures that we remove ourselves as a mutation observer
|
|
|
|
tmp->SetDocument(nullptr);
|
2012-11-15 07:32:40 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mRoot)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mNames)
|
2013-04-03 16:49:17 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mNamedItemEntries)
|
2012-11-15 07:32:40 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mProperties)
|
2012-06-04 23:49:57 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(HTMLPropertiesCollection)
|
2012-11-15 07:32:40 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDoc)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRoot)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mNames)
|
2013-04-03 16:49:17 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mNamedItemEntries);
|
2012-11-15 07:32:40 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mProperties)
|
2012-06-04 23:49:57 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(HTMLPropertiesCollection)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
|
|
|
HTMLPropertiesCollection::HTMLPropertiesCollection(nsGenericHTMLElement* aRoot)
|
|
|
|
: mRoot(aRoot)
|
2014-10-02 19:07:24 +00:00
|
|
|
, mDoc(aRoot->GetUncomposedDoc())
|
2012-06-04 23:49:57 +00:00
|
|
|
, mIsDirty(true)
|
|
|
|
{
|
|
|
|
mNames = new PropertyStringList(this);
|
|
|
|
if (mDoc) {
|
|
|
|
mDoc->AddMutationObserver(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HTMLPropertiesCollection::~HTMLPropertiesCollection()
|
|
|
|
{
|
|
|
|
if (mDoc) {
|
|
|
|
mDoc->RemoveMutationObserver(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_INTERFACE_TABLE_HEAD(HTMLPropertiesCollection)
|
2014-08-25 23:21:35 +00:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_TABLE_ENTRY
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_INTERFACE_TABLE(HTMLPropertiesCollection,
|
|
|
|
nsIDOMHTMLCollection,
|
|
|
|
nsIHTMLCollection,
|
|
|
|
nsIMutationObserver)
|
2012-06-04 23:49:57 +00:00
|
|
|
NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(HTMLPropertiesCollection)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(HTMLPropertiesCollection)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(HTMLPropertiesCollection)
|
|
|
|
|
|
|
|
|
|
|
|
static PLDHashOperator
|
|
|
|
SetPropertyListDocument(const nsAString& aKey, PropertyNodeList* aEntry, void* aData)
|
|
|
|
{
|
|
|
|
aEntry->SetDocument(static_cast<nsIDocument*>(aData));
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLPropertiesCollection::SetDocument(nsIDocument* aDocument) {
|
|
|
|
if (mDoc) {
|
|
|
|
mDoc->RemoveMutationObserver(this);
|
|
|
|
}
|
|
|
|
mDoc = aDocument;
|
|
|
|
if (mDoc) {
|
|
|
|
mDoc->AddMutationObserver(this);
|
|
|
|
}
|
|
|
|
mNamedItemEntries.EnumerateRead(SetPropertyListDocument, aDocument);
|
|
|
|
mIsDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 14:13:33 +00:00
|
|
|
HTMLPropertiesCollection::WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto)
|
2012-06-04 23:49:57 +00: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 14:13:33 +00:00
|
|
|
return HTMLPropertiesCollectionBinding::Wrap(cx, this, aGivenProto);
|
2012-06-04 23:49:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
HTMLPropertiesCollection::GetLength(uint32_t* aLength)
|
2012-06-04 23:49:57 +00:00
|
|
|
{
|
|
|
|
EnsureFresh();
|
|
|
|
*aLength = mProperties.Length();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
HTMLPropertiesCollection::Item(uint32_t aIndex, nsIDOMNode** aResult)
|
2012-06-04 23:49:57 +00:00
|
|
|
{
|
2012-09-05 20:49:53 +00:00
|
|
|
nsINode* result = nsIHTMLCollection::Item(aIndex);
|
|
|
|
if (result) {
|
|
|
|
NS_ADDREF(*aResult = result->AsDOMNode());
|
|
|
|
} else {
|
|
|
|
*aResult = nullptr;
|
|
|
|
}
|
2012-06-04 23:49:57 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLPropertiesCollection::NamedItem(const nsAString& aName,
|
|
|
|
nsIDOMNode** aResult)
|
|
|
|
{
|
2013-04-03 01:14:24 +00:00
|
|
|
*aResult = nullptr;
|
2012-06-04 23:49:57 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-11-14 22:10:08 +00:00
|
|
|
Element*
|
2012-09-05 15:42:58 +00:00
|
|
|
HTMLPropertiesCollection::GetElementAt(uint32_t aIndex)
|
2012-06-04 23:49:57 +00:00
|
|
|
{
|
|
|
|
EnsureFresh();
|
|
|
|
return mProperties.SafeElementAt(aIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsINode*
|
|
|
|
HTMLPropertiesCollection::GetParentObject()
|
|
|
|
{
|
|
|
|
return mRoot;
|
|
|
|
}
|
|
|
|
|
2012-09-05 20:49:53 +00:00
|
|
|
PropertyNodeList*
|
|
|
|
HTMLPropertiesCollection::NamedItem(const nsAString& aName)
|
|
|
|
{
|
|
|
|
EnsureFresh();
|
|
|
|
|
|
|
|
PropertyNodeList* propertyList = mNamedItemEntries.GetWeak(aName);
|
|
|
|
if (!propertyList) {
|
|
|
|
nsRefPtr<PropertyNodeList> newPropertyList =
|
|
|
|
new PropertyNodeList(this, mRoot, aName);
|
|
|
|
mNamedItemEntries.Put(aName, newPropertyList);
|
|
|
|
propertyList = newPropertyList;
|
|
|
|
}
|
|
|
|
return propertyList;
|
|
|
|
}
|
|
|
|
|
2012-06-04 23:49:57 +00:00
|
|
|
void
|
|
|
|
HTMLPropertiesCollection::AttributeChanged(nsIDocument *aDocument, Element* aElement,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aNameSpaceID, nsIAtom* aAttribute,
|
|
|
|
int32_t aModType)
|
2012-06-04 23:49:57 +00:00
|
|
|
{
|
|
|
|
mIsDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLPropertiesCollection::ContentAppended(nsIDocument* aDocument, nsIContent* aContainer,
|
|
|
|
nsIContent* aFirstNewContent,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aNewIndexInContainer)
|
2012-06-04 23:49:57 +00:00
|
|
|
{
|
|
|
|
mIsDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLPropertiesCollection::ContentInserted(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aIndexInContainer)
|
2012-06-04 23:49:57 +00:00
|
|
|
{
|
|
|
|
mIsDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLPropertiesCollection::ContentRemoved(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aIndexInContainer,
|
2012-06-04 23:49:57 +00:00
|
|
|
nsIContent* aPreviousSibling)
|
|
|
|
{
|
|
|
|
mIsDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PLDHashOperator
|
|
|
|
MarkDirty(const nsAString& aKey, PropertyNodeList* aEntry, void* aData)
|
|
|
|
{
|
|
|
|
aEntry->SetDirty();
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLPropertiesCollection::EnsureFresh()
|
|
|
|
{
|
|
|
|
if (mDoc && !mIsDirty) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mIsDirty = false;
|
|
|
|
|
|
|
|
mProperties.Clear();
|
|
|
|
mNames->Clear();
|
|
|
|
// We don't clear NamedItemEntries because the PropertyNodeLists must be live.
|
2013-04-03 01:14:24 +00:00
|
|
|
mNamedItemEntries.EnumerateRead(MarkDirty, nullptr);
|
2012-06-04 23:49:57 +00:00
|
|
|
if (!mRoot->HasAttr(kNameSpaceID_None, nsGkAtoms::itemscope)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CrawlProperties();
|
|
|
|
TreeOrderComparator comparator;
|
|
|
|
mProperties.Sort(comparator);
|
|
|
|
|
|
|
|
// Create the names DOMStringList
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t count = mProperties.Length();
|
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
2012-06-04 23:49:57 +00:00
|
|
|
const nsAttrValue* attr = mProperties.ElementAt(i)->GetParsedAttr(nsGkAtoms::itemprop);
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < attr->GetAtomCount(); i++) {
|
2012-06-04 23:49:57 +00:00
|
|
|
nsDependentAtomString propName(attr->AtomAt(i));
|
|
|
|
bool contains = mNames->ContainsInternal(propName);
|
|
|
|
if (!contains) {
|
|
|
|
mNames->Add(propName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-12-08 22:06:42 +00:00
|
|
|
|
2012-06-04 23:49:57 +00:00
|
|
|
static Element*
|
|
|
|
GetElementByIdForConnectedSubtree(nsIContent* aContent, const nsIAtom* aId)
|
|
|
|
{
|
|
|
|
aContent = static_cast<nsIContent*>(aContent->SubtreeRoot());
|
|
|
|
do {
|
|
|
|
if (aContent->GetID() == aId) {
|
|
|
|
return aContent->AsElement();
|
|
|
|
}
|
|
|
|
aContent = aContent->GetNextNode();
|
|
|
|
} while(aContent);
|
2012-12-08 22:06:42 +00:00
|
|
|
|
2013-04-03 01:14:24 +00:00
|
|
|
return nullptr;
|
2012-06-04 23:49:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLPropertiesCollection::CrawlProperties()
|
|
|
|
{
|
2014-10-02 19:07:24 +00:00
|
|
|
nsIDocument* doc = mRoot->GetUncomposedDoc();
|
2012-12-08 22:06:42 +00:00
|
|
|
|
2012-06-04 23:49:57 +00:00
|
|
|
const nsAttrValue* attr = mRoot->GetParsedAttr(nsGkAtoms::itemref);
|
|
|
|
if (attr) {
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < attr->GetAtomCount(); i++) {
|
2012-06-04 23:49:57 +00:00
|
|
|
nsIAtom* ref = attr->AtomAt(i);
|
|
|
|
Element* element;
|
|
|
|
if (doc) {
|
|
|
|
element = doc->GetElementById(nsDependentAtomString(ref));
|
|
|
|
} else {
|
|
|
|
element = GetElementByIdForConnectedSubtree(mRoot, ref);
|
|
|
|
}
|
|
|
|
if (element && element != mRoot) {
|
|
|
|
CrawlSubtree(element);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-12-08 22:06:42 +00:00
|
|
|
|
2012-06-04 23:49:57 +00:00
|
|
|
CrawlSubtree(mRoot);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLPropertiesCollection::CrawlSubtree(Element* aElement)
|
|
|
|
{
|
|
|
|
nsIContent* aContent = aElement;
|
|
|
|
while (aContent) {
|
|
|
|
// We must check aContent against mRoot because
|
|
|
|
// an element must not be its own property
|
2015-03-03 11:08:59 +00:00
|
|
|
if (aContent == mRoot || !aContent->IsHTMLElement()) {
|
2012-06-04 23:49:57 +00:00
|
|
|
// Move on to the next node in the tree
|
|
|
|
aContent = aContent->GetNextNode(aElement);
|
|
|
|
} else {
|
2015-03-03 11:08:59 +00:00
|
|
|
MOZ_ASSERT(aContent->IsElement(), "IsHTMLElement() returned true!");
|
2012-06-04 23:49:57 +00:00
|
|
|
Element* element = aContent->AsElement();
|
|
|
|
if (element->HasAttr(kNameSpaceID_None, nsGkAtoms::itemprop) &&
|
|
|
|
!mProperties.Contains(element)) {
|
|
|
|
mProperties.AppendElement(static_cast<nsGenericHTMLElement*>(element));
|
2012-12-08 22:06:42 +00:00
|
|
|
}
|
|
|
|
|
2012-06-04 23:49:57 +00:00
|
|
|
if (element->HasAttr(kNameSpaceID_None, nsGkAtoms::itemscope)) {
|
|
|
|
aContent = element->GetNextNonChildNode(aElement);
|
2012-12-08 22:06:42 +00:00
|
|
|
} else {
|
2012-06-04 23:49:57 +00:00
|
|
|
aContent = element->GetNextNode(aElement);
|
2012-12-08 22:06:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-06-04 23:49:57 +00:00
|
|
|
}
|
|
|
|
|
2012-11-05 16:58:03 +00:00
|
|
|
void
|
2014-04-16 02:58:44 +00:00
|
|
|
HTMLPropertiesCollection::GetSupportedNames(unsigned, nsTArray<nsString>& aNames)
|
2012-11-05 16:58:03 +00:00
|
|
|
{
|
|
|
|
EnsureFresh();
|
|
|
|
mNames->CopyList(aNames);
|
|
|
|
}
|
|
|
|
|
2012-06-04 23:49:57 +00:00
|
|
|
PropertyNodeList::PropertyNodeList(HTMLPropertiesCollection* aCollection,
|
|
|
|
nsIContent* aParent, const nsAString& aName)
|
|
|
|
: mName(aName),
|
2014-10-02 19:07:24 +00:00
|
|
|
mDoc(aParent->GetUncomposedDoc()),
|
2012-06-04 23:49:57 +00:00
|
|
|
mCollection(aCollection),
|
|
|
|
mParent(aParent),
|
|
|
|
mIsDirty(true)
|
|
|
|
{
|
|
|
|
if (mDoc) {
|
|
|
|
mDoc->AddMutationObserver(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PropertyNodeList::~PropertyNodeList()
|
|
|
|
{
|
|
|
|
if (mDoc) {
|
|
|
|
mDoc->RemoveMutationObserver(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PropertyNodeList::SetDocument(nsIDocument* aDoc)
|
|
|
|
{
|
|
|
|
if (mDoc) {
|
|
|
|
mDoc->RemoveMutationObserver(this);
|
|
|
|
}
|
|
|
|
mDoc = aDoc;
|
|
|
|
if (mDoc) {
|
|
|
|
mDoc->AddMutationObserver(this);
|
|
|
|
}
|
|
|
|
mIsDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
PropertyNodeList::GetLength(uint32_t* aLength)
|
2012-06-04 23:49:57 +00:00
|
|
|
{
|
|
|
|
EnsureFresh();
|
|
|
|
*aLength = mElements.Length();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
PropertyNodeList::Item(uint32_t aIndex, nsIDOMNode** aReturn)
|
2012-06-04 23:49:57 +00:00
|
|
|
{
|
|
|
|
EnsureFresh();
|
|
|
|
nsINode* element = mElements.SafeElementAt(aIndex);
|
|
|
|
if (!element) {
|
2013-04-03 01:14:24 +00:00
|
|
|
*aReturn = nullptr;
|
2012-06-04 23:49:57 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return CallQueryInterface(element, aReturn);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent*
|
2012-10-13 12:50:24 +00:00
|
|
|
PropertyNodeList::Item(uint32_t aIndex)
|
2012-06-04 23:49:57 +00:00
|
|
|
{
|
|
|
|
EnsureFresh();
|
|
|
|
return mElements.SafeElementAt(aIndex);
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t
|
2012-06-04 23:49:57 +00:00
|
|
|
PropertyNodeList::IndexOf(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
EnsureFresh();
|
|
|
|
return mElements.IndexOf(aContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsINode*
|
|
|
|
PropertyNodeList::GetParentObject()
|
|
|
|
{
|
|
|
|
return mParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 14:13:33 +00:00
|
|
|
PropertyNodeList::WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto)
|
2012-06-04 23:49:57 +00: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 14:13:33 +00:00
|
|
|
return PropertyNodeListBinding::Wrap(cx, this, aGivenProto);
|
2012-06-04 23:49:57 +00:00
|
|
|
}
|
|
|
|
|
2013-08-02 01:29:05 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(PropertyNodeList)
|
|
|
|
|
2012-06-04 23:49:57 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(PropertyNodeList)
|
2012-07-30 14:20:58 +00:00
|
|
|
// SetDocument(nullptr) ensures that we remove ourselves as a mutation observer
|
|
|
|
tmp->SetDocument(nullptr);
|
2012-11-15 07:32:40 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mParent)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCollection)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mElements)
|
2012-06-04 23:49:57 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(PropertyNodeList)
|
2012-11-15 07:32:40 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDoc)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mParent)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCollection)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mElements)
|
2012-06-04 23:49:57 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(PropertyNodeList)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(PropertyNodeList)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(PropertyNodeList)
|
|
|
|
|
|
|
|
NS_INTERFACE_TABLE_HEAD(PropertyNodeList)
|
2014-08-25 23:21:35 +00:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_TABLE_ENTRY
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_INTERFACE_TABLE(PropertyNodeList,
|
|
|
|
nsIDOMNodeList,
|
|
|
|
nsINodeList,
|
|
|
|
nsIMutationObserver)
|
2012-06-04 23:49:57 +00:00
|
|
|
NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(PropertyNodeList)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2012-09-05 20:49:53 +00:00
|
|
|
void
|
|
|
|
PropertyNodeList::GetValues(JSContext* aCx, nsTArray<JS::Value >& aResult,
|
|
|
|
ErrorResult& aError)
|
|
|
|
{
|
|
|
|
EnsureFresh();
|
|
|
|
|
2013-11-11 08:04:41 +00:00
|
|
|
JS::Rooted<JSObject*> wrapper(aCx, GetWrapper());
|
2012-09-05 20:49:53 +00:00
|
|
|
JSAutoCompartment ac(aCx, wrapper);
|
|
|
|
uint32_t length = mElements.Length();
|
|
|
|
for (uint32_t i = 0; i < length; ++i) {
|
2014-06-11 20:26:52 +00:00
|
|
|
JS::Rooted<JS::Value> v(aCx);
|
|
|
|
mElements.ElementAt(i)->GetItemValue(aCx, wrapper, &v, aError);
|
2012-09-05 20:49:53 +00:00
|
|
|
if (aError.Failed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
aResult.AppendElement(v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-04 23:49:57 +00:00
|
|
|
void
|
|
|
|
PropertyNodeList::AttributeChanged(nsIDocument* aDocument, Element* aElement,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aNameSpaceID, nsIAtom* aAttribute,
|
|
|
|
int32_t aModType)
|
2012-06-04 23:49:57 +00:00
|
|
|
{
|
|
|
|
mIsDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PropertyNodeList::ContentAppended(nsIDocument* aDocument, nsIContent* aContainer,
|
|
|
|
nsIContent* aFirstNewContent,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aNewIndexInContainer)
|
2012-06-04 23:49:57 +00:00
|
|
|
{
|
|
|
|
mIsDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PropertyNodeList::ContentInserted(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aIndexInContainer)
|
2012-06-04 23:49:57 +00:00
|
|
|
{
|
|
|
|
mIsDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PropertyNodeList::ContentRemoved(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aIndexInContainer,
|
2012-06-04 23:49:57 +00:00
|
|
|
nsIContent* aPreviousSibling)
|
|
|
|
{
|
|
|
|
mIsDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PropertyNodeList::EnsureFresh()
|
|
|
|
{
|
|
|
|
if (mDoc && !mIsDirty) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mIsDirty = false;
|
|
|
|
|
|
|
|
mCollection->EnsureFresh();
|
|
|
|
Clear();
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t count = mCollection->mProperties.Length();
|
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
2012-06-04 23:49:57 +00:00
|
|
|
nsGenericHTMLElement* element = mCollection->mProperties.ElementAt(i);
|
|
|
|
const nsAttrValue* attr = element->GetParsedAttr(nsGkAtoms::itemprop);
|
|
|
|
if (attr->Contains(mName)) {
|
|
|
|
AppendElement(element);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PropertyStringList::PropertyStringList(HTMLPropertiesCollection* aCollection)
|
2013-07-09 17:51:03 +00:00
|
|
|
: DOMStringList()
|
2012-06-04 23:49:57 +00:00
|
|
|
, mCollection(aCollection)
|
|
|
|
{ }
|
|
|
|
|
2014-07-08 21:23:16 +00:00
|
|
|
PropertyStringList::~PropertyStringList()
|
|
|
|
{ }
|
|
|
|
|
2014-04-25 16:49:00 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(PropertyStringList, DOMStringList,
|
|
|
|
mCollection)
|
2012-06-04 23:49:57 +00:00
|
|
|
|
2013-07-09 17:54:21 +00:00
|
|
|
NS_IMPL_ADDREF_INHERITED(PropertyStringList, DOMStringList)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(PropertyStringList, DOMStringList)
|
2012-06-04 23:49:57 +00:00
|
|
|
|
2013-07-09 17:54:21 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(PropertyStringList)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMStringList)
|
2012-06-04 23:49:57 +00:00
|
|
|
|
2013-07-09 17:54:21 +00:00
|
|
|
void
|
|
|
|
PropertyStringList::EnsureFresh()
|
2012-06-04 23:49:57 +00:00
|
|
|
{
|
2014-12-17 06:26:15 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2012-06-04 23:49:57 +00:00
|
|
|
mCollection->EnsureFresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PropertyStringList::ContainsInternal(const nsAString& aString)
|
|
|
|
{
|
|
|
|
// This method should not call EnsureFresh, otherwise we may become stuck in an infinite loop.
|
2013-07-09 17:54:21 +00:00
|
|
|
return mNames.Contains(aString);
|
2012-06-04 23:49:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|