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/. */
|
1998-07-23 03:32:19 +04:00
|
|
|
|
2006-03-30 12:03:04 +04:00
|
|
|
/*
|
|
|
|
* nsBaseContentList is a basic list of content nodes; nsContentList
|
|
|
|
* is a commonly used NodeList implementation (used for
|
2006-03-31 12:41:49 +04:00
|
|
|
* getElementsByTagName, some properties on nsIDOMHTMLDocument, etc).
|
2006-03-30 12:03:04 +04:00
|
|
|
*/
|
|
|
|
|
1998-07-23 03:32:19 +04:00
|
|
|
#include "nsContentList.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsIDocument.h"
|
2012-11-15 02:10:08 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2011-12-30 01:21:33 +04:00
|
|
|
#include "nsWrapperCacheInlines.h"
|
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
|
|
|
#include "nsContentUtils.h"
|
2011-12-30 01:21:33 +04:00
|
|
|
#include "nsCCUncollectableMarker.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2012-06-13 19:18:30 +04:00
|
|
|
#include "mozilla/dom/HTMLCollectionBinding.h"
|
|
|
|
#include "mozilla/dom/NodeListBinding.h"
|
2012-10-26 17:32:10 +04:00
|
|
|
#include "mozilla/Likely.h"
|
2012-11-05 20:58:03 +04:00
|
|
|
#include "nsGenericHTMLElement.h"
|
2014-04-16 06:58:44 +04:00
|
|
|
#include "jsfriendapi.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2014-06-20 06:01:40 +04:00
|
|
|
#include "mozilla/dom/NodeInfoInlines.h"
|
2011-05-23 19:39:52 +04:00
|
|
|
|
2001-03-22 11:51:52 +03:00
|
|
|
// Form related includes
|
|
|
|
#include "nsIDOMHTMLFormElement.h"
|
|
|
|
|
2002-05-09 00:48:19 +04:00
|
|
|
#include "pldhash.h"
|
|
|
|
|
2006-08-10 22:58:37 +04:00
|
|
|
#ifdef DEBUG_CONTENT_LIST
|
|
|
|
#include "nsIContentIterator.h"
|
|
|
|
#define ASSERT_IN_SYNC AssertInSync()
|
|
|
|
#else
|
2006-08-19 03:25:35 +04:00
|
|
|
#define ASSERT_IN_SYNC PR_BEGIN_MACRO PR_END_MACRO
|
2006-08-10 22:58:37 +04:00
|
|
|
#endif
|
|
|
|
|
2013-11-11 11:55:41 +04:00
|
|
|
using namespace mozilla;
|
2010-04-30 17:12:05 +04:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2001-03-22 11:51:52 +03:00
|
|
|
nsBaseContentList::~nsBaseContentList()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-09-25 06:56:18 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsBaseContentList)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsBaseContentList)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mElements)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
|
|
|
tmp->RemoveFromCaches();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsBaseContentList)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mElements)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(nsBaseContentList)
|
2001-03-22 11:51:52 +03:00
|
|
|
|
2012-02-11 00:47:29 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(nsBaseContentList)
|
|
|
|
if (nsCCUncollectableMarker::sGeneration && tmp->IsBlack()) {
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < tmp->mElements.Length(); ++i) {
|
2012-02-11 00:47:29 +04:00
|
|
|
nsIContent* c = tmp->mElements[i];
|
|
|
|
if (c->IsPurple()) {
|
|
|
|
c->RemovePurple();
|
|
|
|
}
|
2012-11-15 02:10:08 +04:00
|
|
|
Element::MarkNodeChildren(c);
|
2012-02-11 00:47:29 +04:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_BEGIN(nsBaseContentList)
|
|
|
|
return nsCCUncollectableMarker::sGeneration && tmp->IsBlack();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_BEGIN(nsBaseContentList)
|
|
|
|
return nsCCUncollectableMarker::sGeneration && tmp->IsBlack();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_END
|
|
|
|
|
2008-11-03 13:31:47 +03:00
|
|
|
#define NS_CONTENT_LIST_INTERFACES(_class) \
|
|
|
|
NS_INTERFACE_TABLE_ENTRY(_class, nsINodeList) \
|
|
|
|
NS_INTERFACE_TABLE_ENTRY(_class, nsIDOMNodeList)
|
|
|
|
|
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 nsBaseContentList
|
2008-11-03 13:31:47 +03:00
|
|
|
NS_INTERFACE_TABLE_HEAD(nsBaseContentList)
|
2014-08-26 03:21:35 +04:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_TABLE_ENTRY
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_INTERFACE_TABLE(nsBaseContentList, nsINodeList, nsIDOMNodeList)
|
2013-01-10 13:54:46 +04:00
|
|
|
NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(nsBaseContentList)
|
2001-03-22 11:51:52 +03:00
|
|
|
NS_INTERFACE_MAP_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
|
|
|
|
2007-03-08 14:17:16 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsBaseContentList)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsBaseContentList)
|
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
|
|
|
|
|
|
|
|
2001-03-22 11:51:52 +03:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsBaseContentList::GetLength(uint32_t* aLength)
|
2001-03-22 11:51:52 +03:00
|
|
|
{
|
2011-11-01 06:48:59 +04:00
|
|
|
*aLength = mElements.Length();
|
2001-03-22 11:51:52 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsBaseContentList::Item(uint32_t aIndex, nsIDOMNode** aReturn)
|
2001-03-22 11:51:52 +03:00
|
|
|
{
|
2012-10-13 16:50:24 +04:00
|
|
|
nsISupports *tmp = Item(aIndex);
|
2006-08-25 21:45:25 +04:00
|
|
|
|
2001-03-22 11:51:52 +03:00
|
|
|
if (!tmp) {
|
2012-07-30 18:20:58 +04:00
|
|
|
*aReturn = nullptr;
|
2001-03-22 11:51:52 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CallQueryInterface(tmp, aReturn);
|
|
|
|
}
|
|
|
|
|
2009-01-29 22:46:18 +03:00
|
|
|
nsIContent*
|
2012-10-13 16:50:24 +04:00
|
|
|
nsBaseContentList::Item(uint32_t aIndex)
|
2008-09-11 07:15:29 +04:00
|
|
|
{
|
2011-11-01 06:48:59 +04:00
|
|
|
return mElements.SafeElementAt(aIndex);
|
2008-09-11 07:15:29 +04:00
|
|
|
}
|
|
|
|
|
2001-03-22 11:51:52 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
2011-09-29 10:19:26 +04:00
|
|
|
nsBaseContentList::IndexOf(nsIContent *aContent, bool aDoFlush)
|
2001-03-22 11:51:52 +03:00
|
|
|
{
|
2003-09-27 08:18:26 +04:00
|
|
|
return mElements.IndexOf(aContent);
|
2001-03-22 11:51:52 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
2009-01-29 22:46:18 +03:00
|
|
|
nsBaseContentList::IndexOf(nsIContent* aContent)
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return IndexOf(aContent, true);
|
2009-01-29 22:46:18 +03:00
|
|
|
}
|
|
|
|
|
2014-04-25 20:49:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(nsSimpleContentList, nsBaseContentList,
|
|
|
|
mRoot)
|
2009-06-16 10:32:10 +04:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsSimpleContentList)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsBaseContentList)
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(nsSimpleContentList, nsBaseContentList)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsSimpleContentList, nsBaseContentList)
|
|
|
|
|
2011-06-01 01:47:17 +04:00
|
|
|
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
|
|
|
nsSimpleContentList::WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto)
|
2011-06-01 01:47:17 +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);
|
2011-06-01 01:47:17 +04:00
|
|
|
}
|
|
|
|
|
2002-05-09 00:48:19 +04:00
|
|
|
// Hashtable for storing nsContentLists
|
2015-05-20 02:46:17 +03:00
|
|
|
static PLDHashTable* gContentListHashTable;
|
2002-05-09 00:48:19 +04:00
|
|
|
|
2013-11-05 23:40:09 +04:00
|
|
|
#define RECENTLY_USED_CONTENT_LIST_CACHE_SIZE 31
|
|
|
|
static nsContentList*
|
|
|
|
sRecentlyUsedContentLists[RECENTLY_USED_CONTENT_LIST_CACHE_SIZE] = {};
|
|
|
|
|
|
|
|
static MOZ_ALWAYS_INLINE uint32_t
|
|
|
|
RecentlyUsedCacheIndex(const nsContentListKey& aKey)
|
|
|
|
{
|
|
|
|
return aKey.GetHash() % RECENTLY_USED_CONTENT_LIST_CACHE_SIZE;
|
|
|
|
}
|
|
|
|
|
2002-05-09 00:48:19 +04:00
|
|
|
struct ContentListHashEntry : public PLDHashEntryHdr
|
|
|
|
{
|
|
|
|
nsContentList* mContentList;
|
|
|
|
};
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static PLDHashNumber
|
2002-05-09 00:48:19 +04:00
|
|
|
ContentListHashtableHashKey(PLDHashTable *table, const void *key)
|
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
const nsContentListKey* list = static_cast<const nsContentListKey *>(key);
|
2002-05-09 00:48:19 +04:00
|
|
|
return list->GetHash();
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2002-05-09 00:48:19 +04:00
|
|
|
ContentListHashtableMatchEntry(PLDHashTable *table,
|
|
|
|
const PLDHashEntryHdr *entry,
|
|
|
|
const void *key)
|
|
|
|
{
|
|
|
|
const ContentListHashEntry *e =
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<const ContentListHashEntry *>(entry);
|
2010-11-23 22:10:56 +03:00
|
|
|
const nsContentList* list = e->mContentList;
|
|
|
|
const nsContentListKey* ourKey = static_cast<const nsContentListKey *>(key);
|
2002-05-09 00:48:19 +04:00
|
|
|
|
2010-11-23 22:10:56 +03:00
|
|
|
return list->MatchesKey(*ourKey);
|
2002-05-09 00:48:19 +04:00
|
|
|
}
|
|
|
|
|
2005-02-03 02:16:02 +03:00
|
|
|
already_AddRefed<nsContentList>
|
2010-09-01 06:47:00 +04:00
|
|
|
NS_GetContentList(nsINode* aRootNode,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aMatchNameSpaceId,
|
2010-11-23 22:10:56 +03:00
|
|
|
const nsAString& aTagname)
|
2002-05-09 00:48:19 +04:00
|
|
|
{
|
2006-07-02 11:23:10 +04:00
|
|
|
NS_ASSERTION(aRootNode, "content list has to have a root");
|
|
|
|
|
2013-04-22 15:15:59 +04:00
|
|
|
nsRefPtr<nsContentList> list;
|
2013-11-05 23:40:09 +04:00
|
|
|
nsContentListKey hashKey(aRootNode, aMatchNameSpaceId, aTagname);
|
|
|
|
uint32_t recentlyUsedCacheIndex = RecentlyUsedCacheIndex(hashKey);
|
|
|
|
nsContentList* cachedList = sRecentlyUsedContentLists[recentlyUsedCacheIndex];
|
|
|
|
if (cachedList && cachedList->MatchesKey(hashKey)) {
|
|
|
|
list = cachedList;
|
|
|
|
return list.forget();
|
|
|
|
}
|
2002-05-09 00:48:19 +04:00
|
|
|
|
2013-11-19 06:52:15 +04:00
|
|
|
static const PLDHashTableOps hash_table_ops =
|
2002-05-09 00:48:19 +04:00
|
|
|
{
|
|
|
|
ContentListHashtableHashKey,
|
|
|
|
ContentListHashtableMatchEntry,
|
|
|
|
PL_DHashMoveEntryStub,
|
2015-01-14 06:02:35 +03:00
|
|
|
PL_DHashClearEntryStub
|
2002-05-09 00:48:19 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
// Initialize the hashtable if needed.
|
2015-05-18 10:52:07 +03:00
|
|
|
if (!gContentListHashTable) {
|
|
|
|
gContentListHashTable =
|
2015-05-20 02:46:17 +03:00
|
|
|
new PLDHashTable(&hash_table_ops, sizeof(ContentListHashEntry));
|
2002-05-09 00:48:19 +04:00
|
|
|
}
|
2014-02-27 22:04:09 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
ContentListHashEntry *entry = nullptr;
|
2002-05-09 00:48:19 +04:00
|
|
|
// First we look in our hashtable. Then we create a content list if needed
|
2015-05-18 10:52:07 +03:00
|
|
|
entry = static_cast<ContentListHashEntry *>
|
|
|
|
(PL_DHashTableAdd(gContentListHashTable, &hashKey, fallible));
|
|
|
|
if (entry)
|
|
|
|
list = entry->mContentList;
|
2002-05-09 00:48:19 +04:00
|
|
|
|
|
|
|
if (!list) {
|
|
|
|
// We need to create a ContentList and add it to our new entry, if
|
|
|
|
// we have an entry
|
2010-11-23 22:10:56 +03:00
|
|
|
nsCOMPtr<nsIAtom> xmlAtom = do_GetAtom(aTagname);
|
|
|
|
nsCOMPtr<nsIAtom> htmlAtom;
|
|
|
|
if (aMatchNameSpaceId == kNameSpaceID_Unknown) {
|
|
|
|
nsAutoString lowercaseName;
|
|
|
|
nsContentUtils::ASCIIToLower(aTagname, lowercaseName);
|
|
|
|
htmlAtom = do_GetAtom(lowercaseName);
|
|
|
|
} else {
|
|
|
|
htmlAtom = xmlAtom;
|
|
|
|
}
|
2015-01-27 02:13:56 +03:00
|
|
|
list = new nsContentList(aRootNode, aMatchNameSpaceId, htmlAtom, xmlAtom);
|
2002-05-09 00:48:19 +04:00
|
|
|
if (entry) {
|
2010-09-01 06:47:00 +04:00
|
|
|
entry->mContentList = list;
|
2002-05-09 00:48:19 +04:00
|
|
|
}
|
2003-07-01 22:41:39 +04:00
|
|
|
}
|
2002-05-09 00:48:19 +04:00
|
|
|
|
2013-11-05 23:40:09 +04:00
|
|
|
sRecentlyUsedContentLists[recentlyUsedCacheIndex] = list;
|
2013-04-22 15:15:59 +04:00
|
|
|
return list.forget();
|
2002-05-09 00:48:19 +04:00
|
|
|
}
|
|
|
|
|
2012-09-06 00:49:53 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
const nsCacheableFuncStringContentList::ContentListType
|
|
|
|
nsCacheableFuncStringNodeList::sType = nsCacheableFuncStringContentList::eNodeList;
|
|
|
|
const nsCacheableFuncStringContentList::ContentListType
|
|
|
|
nsCacheableFuncStringHTMLCollection::sType = nsCacheableFuncStringContentList::eHTMLCollection;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
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
|
|
|
nsCacheableFuncStringNodeList::WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto)
|
2012-09-06 00:49:53 +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-09-06 00:49:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
nsCacheableFuncStringHTMLCollection::WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto)
|
2012-09-06 00:49:53 +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 HTMLCollectionBinding::Wrap(cx, this, aGivenProto);
|
2012-09-06 00:49:53 +04:00
|
|
|
}
|
|
|
|
|
2010-02-09 20:09:06 +03:00
|
|
|
// Hashtable for storing nsCacheableFuncStringContentList
|
2015-05-20 02:46:17 +03:00
|
|
|
static PLDHashTable* gFuncStringContentListHashTable;
|
2010-02-09 20:09:06 +03:00
|
|
|
|
|
|
|
struct FuncStringContentListHashEntry : public PLDHashEntryHdr
|
|
|
|
{
|
|
|
|
nsCacheableFuncStringContentList* mContentList;
|
|
|
|
};
|
|
|
|
|
|
|
|
static PLDHashNumber
|
|
|
|
FuncStringContentListHashtableHashKey(PLDHashTable *table, const void *key)
|
|
|
|
{
|
|
|
|
const nsFuncStringCacheKey* funcStringKey =
|
|
|
|
static_cast<const nsFuncStringCacheKey *>(key);
|
|
|
|
return funcStringKey->GetHash();
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2010-02-09 20:09:06 +03:00
|
|
|
FuncStringContentListHashtableMatchEntry(PLDHashTable *table,
|
|
|
|
const PLDHashEntryHdr *entry,
|
|
|
|
const void *key)
|
|
|
|
{
|
|
|
|
const FuncStringContentListHashEntry *e =
|
|
|
|
static_cast<const FuncStringContentListHashEntry *>(entry);
|
|
|
|
const nsFuncStringCacheKey* ourKey =
|
|
|
|
static_cast<const nsFuncStringCacheKey *>(key);
|
|
|
|
|
|
|
|
return e->mContentList->Equals(ourKey);
|
|
|
|
}
|
|
|
|
|
2012-09-06 00:49:53 +04:00
|
|
|
template<class ListType>
|
2010-02-09 20:09:06 +03:00
|
|
|
already_AddRefed<nsContentList>
|
2012-09-06 00:49:53 +04:00
|
|
|
GetFuncStringContentList(nsINode* aRootNode,
|
|
|
|
nsContentListMatchFunc aFunc,
|
|
|
|
nsContentListDestroyFunc aDestroyFunc,
|
|
|
|
nsFuncStringContentListDataAllocator aDataAllocator,
|
|
|
|
const nsAString& aString)
|
2010-02-09 20:09:06 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aRootNode, "content list has to have a root");
|
|
|
|
|
2013-04-22 15:15:59 +04:00
|
|
|
nsRefPtr<nsCacheableFuncStringContentList> list;
|
2010-02-09 20:09:06 +03:00
|
|
|
|
2013-11-19 06:52:15 +04:00
|
|
|
static const PLDHashTableOps hash_table_ops =
|
2010-02-09 20:09:06 +03:00
|
|
|
{
|
|
|
|
FuncStringContentListHashtableHashKey,
|
|
|
|
FuncStringContentListHashtableMatchEntry,
|
|
|
|
PL_DHashMoveEntryStub,
|
2015-01-14 06:02:35 +03:00
|
|
|
PL_DHashClearEntryStub
|
2010-02-09 20:09:06 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// Initialize the hashtable if needed.
|
2015-05-18 10:52:07 +03:00
|
|
|
if (!gFuncStringContentListHashTable) {
|
|
|
|
gFuncStringContentListHashTable =
|
2015-05-20 02:46:17 +03:00
|
|
|
new PLDHashTable(&hash_table_ops, sizeof(FuncStringContentListHashEntry));
|
2010-02-09 20:09:06 +03:00
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
FuncStringContentListHashEntry *entry = nullptr;
|
2010-02-09 20:09:06 +03:00
|
|
|
// First we look in our hashtable. Then we create a content list if needed
|
2015-05-18 10:52:07 +03:00
|
|
|
if (gFuncStringContentListHashTable) {
|
2010-02-09 20:09:06 +03:00
|
|
|
nsFuncStringCacheKey hashKey(aRootNode, aFunc, aString);
|
|
|
|
|
|
|
|
entry = static_cast<FuncStringContentListHashEntry *>
|
2015-05-18 10:52:07 +03:00
|
|
|
(PL_DHashTableAdd(gFuncStringContentListHashTable, &hashKey, fallible));
|
2012-09-06 00:49:53 +04:00
|
|
|
if (entry) {
|
2010-02-09 20:09:06 +03:00
|
|
|
list = entry->mContentList;
|
2012-09-06 00:49:53 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
MOZ_ASSERT_IF(list, list->mType == ListType::sType);
|
|
|
|
#endif
|
|
|
|
}
|
2010-02-09 20:09:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!list) {
|
|
|
|
// We need to create a ContentList and add it to our new entry, if
|
|
|
|
// we have an entry
|
2012-09-06 00:49:53 +04:00
|
|
|
list = new ListType(aRootNode, aFunc, aDestroyFunc, aDataAllocator,
|
|
|
|
aString);
|
2010-02-09 20:09:06 +03:00
|
|
|
if (entry) {
|
2012-09-26 18:17:47 +04:00
|
|
|
entry->mContentList = list;
|
2010-02-09 20:09:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't cache these lists globally
|
|
|
|
|
2013-04-22 15:15:59 +04:00
|
|
|
return list.forget();
|
2010-02-09 20:09:06 +03:00
|
|
|
}
|
2001-03-22 11:51:52 +03:00
|
|
|
|
2012-09-06 00:49:53 +04:00
|
|
|
already_AddRefed<nsContentList>
|
|
|
|
NS_GetFuncStringNodeList(nsINode* aRootNode,
|
|
|
|
nsContentListMatchFunc aFunc,
|
|
|
|
nsContentListDestroyFunc aDestroyFunc,
|
|
|
|
nsFuncStringContentListDataAllocator aDataAllocator,
|
|
|
|
const nsAString& aString)
|
|
|
|
{
|
|
|
|
return GetFuncStringContentList<nsCacheableFuncStringNodeList>(aRootNode,
|
|
|
|
aFunc,
|
|
|
|
aDestroyFunc,
|
|
|
|
aDataAllocator,
|
|
|
|
aString);
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsContentList>
|
|
|
|
NS_GetFuncStringHTMLCollection(nsINode* aRootNode,
|
|
|
|
nsContentListMatchFunc aFunc,
|
|
|
|
nsContentListDestroyFunc aDestroyFunc,
|
|
|
|
nsFuncStringContentListDataAllocator aDataAllocator,
|
|
|
|
const nsAString& aString)
|
|
|
|
{
|
|
|
|
return GetFuncStringContentList<nsCacheableFuncStringHTMLCollection>(aRootNode,
|
|
|
|
aFunc,
|
|
|
|
aDestroyFunc,
|
|
|
|
aDataAllocator,
|
|
|
|
aString);
|
|
|
|
}
|
|
|
|
|
2001-03-22 11:51:52 +03:00
|
|
|
// nsContentList implementation
|
|
|
|
|
2006-07-02 11:23:10 +04:00
|
|
|
nsContentList::nsContentList(nsINode* aRootNode,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aMatchNameSpaceId,
|
2010-09-01 06:47:00 +04:00
|
|
|
nsIAtom* aHTMLMatchAtom,
|
|
|
|
nsIAtom* aXMLMatchAtom,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aDeep)
|
2004-04-14 08:26:00 +04:00
|
|
|
: nsBaseContentList(),
|
2010-11-23 22:10:56 +03:00
|
|
|
mRootNode(aRootNode),
|
|
|
|
mMatchNameSpaceId(aMatchNameSpaceId),
|
|
|
|
mHTMLMatchAtom(aHTMLMatchAtom),
|
|
|
|
mXMLMatchAtom(aXMLMatchAtom),
|
2012-07-30 18:20:58 +04:00
|
|
|
mFunc(nullptr),
|
|
|
|
mDestroyFunc(nullptr),
|
|
|
|
mData(nullptr),
|
2004-04-14 08:26:00 +04:00
|
|
|
mState(LIST_DIRTY),
|
2005-08-16 05:43:53 +04:00
|
|
|
mDeep(aDeep),
|
2011-10-17 18:59:28 +04:00
|
|
|
mFuncMayDependOnAttr(false)
|
2004-04-14 08:26:00 +04:00
|
|
|
{
|
2006-07-02 11:23:10 +04:00
|
|
|
NS_ASSERTION(mRootNode, "Must have root");
|
2015-04-17 04:09:58 +03:00
|
|
|
if (nsGkAtoms::_asterisk == mHTMLMatchAtom) {
|
|
|
|
NS_ASSERTION(mXMLMatchAtom == nsGkAtoms::_asterisk, "HTML atom and XML atom are not both asterisk?");
|
2011-10-17 18:59:28 +04:00
|
|
|
mMatchAll = true;
|
1999-01-15 22:18:30 +03:00
|
|
|
}
|
|
|
|
else {
|
2011-10-17 18:59:28 +04:00
|
|
|
mMatchAll = false;
|
1999-01-15 22:18:30 +03:00
|
|
|
}
|
2006-07-02 11:23:10 +04:00
|
|
|
mRootNode->AddMutationObserver(this);
|
2010-09-28 21:46:08 +04:00
|
|
|
|
|
|
|
// We only need to flush if we're in an non-HTML document, since the
|
|
|
|
// HTML5 parser doesn't need flushing. Further, if we're not in a
|
2014-10-02 22:45:44 +04:00
|
|
|
// document at all right now (in the GetUncomposedDoc() sense), we're
|
2010-09-28 21:46:08 +04:00
|
|
|
// not parser-created and don't need to be flushing stuff under us
|
|
|
|
// to get our kids right.
|
2014-10-02 22:45:44 +04:00
|
|
|
nsIDocument* doc = mRootNode->GetUncomposedDoc();
|
2015-03-03 14:08:59 +03:00
|
|
|
mFlushesNeeded = doc && !doc->IsHTMLDocument();
|
1998-07-23 03:32:19 +04:00
|
|
|
}
|
|
|
|
|
2006-07-02 11:23:10 +04:00
|
|
|
nsContentList::nsContentList(nsINode* aRootNode,
|
1999-01-15 22:18:30 +03:00
|
|
|
nsContentListMatchFunc aFunc,
|
2007-02-01 18:14:00 +03:00
|
|
|
nsContentListDestroyFunc aDestroyFunc,
|
|
|
|
void* aData,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aDeep,
|
2004-04-15 05:51:32 +04:00
|
|
|
nsIAtom* aMatchAtom,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aMatchNameSpaceId,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aFuncMayDependOnAttr)
|
2004-04-14 08:26:00 +04:00
|
|
|
: nsBaseContentList(),
|
2010-11-23 22:10:56 +03:00
|
|
|
mRootNode(aRootNode),
|
|
|
|
mMatchNameSpaceId(aMatchNameSpaceId),
|
|
|
|
mHTMLMatchAtom(aMatchAtom),
|
|
|
|
mXMLMatchAtom(aMatchAtom),
|
2004-04-14 08:26:00 +04:00
|
|
|
mFunc(aFunc),
|
2007-02-01 18:14:00 +03:00
|
|
|
mDestroyFunc(aDestroyFunc),
|
|
|
|
mData(aData),
|
2004-04-14 08:26:00 +04:00
|
|
|
mState(LIST_DIRTY),
|
2011-10-17 18:59:28 +04:00
|
|
|
mMatchAll(false),
|
2005-08-16 05:43:53 +04:00
|
|
|
mDeep(aDeep),
|
|
|
|
mFuncMayDependOnAttr(aFuncMayDependOnAttr)
|
2004-04-14 08:26:00 +04:00
|
|
|
{
|
2006-07-02 11:23:10 +04:00
|
|
|
NS_ASSERTION(mRootNode, "Must have root");
|
|
|
|
mRootNode->AddMutationObserver(this);
|
2011-03-29 08:41:01 +04:00
|
|
|
|
|
|
|
// We only need to flush if we're in an non-HTML document, since the
|
|
|
|
// HTML5 parser doesn't need flushing. Further, if we're not in a
|
2014-10-02 22:45:44 +04:00
|
|
|
// document at all right now (in the GetUncomposedDoc() sense), we're
|
2011-03-29 08:41:01 +04:00
|
|
|
// not parser-created and don't need to be flushing stuff under us
|
|
|
|
// to get our kids right.
|
2014-10-02 22:45:44 +04:00
|
|
|
nsIDocument* doc = mRootNode->GetUncomposedDoc();
|
2015-03-03 14:08:59 +03:00
|
|
|
mFlushesNeeded = doc && !doc->IsHTMLDocument();
|
1998-07-23 03:32:19 +04:00
|
|
|
}
|
2001-03-22 11:51:52 +03:00
|
|
|
|
1998-07-23 03:32:19 +04:00
|
|
|
nsContentList::~nsContentList()
|
|
|
|
{
|
2002-05-09 00:48:19 +04:00
|
|
|
RemoveFromHashtable();
|
2006-07-02 11:23:10 +04:00
|
|
|
if (mRootNode) {
|
|
|
|
mRootNode->RemoveMutationObserver(this);
|
1998-07-23 03:32:19 +04:00
|
|
|
}
|
2007-02-01 18:14:00 +03:00
|
|
|
|
|
|
|
if (mDestroyFunc) {
|
|
|
|
// Clean up mData
|
|
|
|
(*mDestroyFunc)(mData);
|
2004-04-15 05:51:32 +04:00
|
|
|
}
|
1998-07-23 03:32:19 +04:00
|
|
|
}
|
|
|
|
|
2011-05-23 19:39:52 +04:00
|
|
|
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
|
|
|
nsContentList::WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto)
|
2011-05-23 19:39:52 +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 HTMLCollectionBinding::Wrap(cx, this, aGivenProto);
|
2011-05-23 19:39:52 +04:00
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(nsContentList, nsBaseContentList,
|
|
|
|
nsIHTMLCollection, nsIDOMHTMLCollection,
|
|
|
|
nsIMutationObserver)
|
1998-07-23 03:32:19 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t
|
2011-09-29 10:19:26 +04:00
|
|
|
nsContentList::Length(bool aDoFlush)
|
1999-01-18 06:43:43 +03:00
|
|
|
{
|
2003-07-29 01:09:56 +04:00
|
|
|
BringSelfUpToDate(aDoFlush);
|
2002-06-28 05:30:09 +04:00
|
|
|
|
2011-11-01 06:48:59 +04:00
|
|
|
return mElements.Length();
|
1999-01-18 06:43:43 +03:00
|
|
|
}
|
|
|
|
|
2004-01-24 03:46:17 +03:00
|
|
|
nsIContent *
|
2012-08-22 19:56:38 +04:00
|
|
|
nsContentList::Item(uint32_t aIndex, bool aDoFlush)
|
1999-01-18 06:43:43 +03:00
|
|
|
{
|
2010-09-28 21:46:08 +04:00
|
|
|
if (mRootNode && aDoFlush && mFlushesNeeded) {
|
2006-07-02 11:23:10 +04:00
|
|
|
// XXX sXBL/XBL2 issue
|
2014-10-02 22:45:44 +04:00
|
|
|
nsIDocument* doc = mRootNode->GetUncomposedDoc();
|
2006-07-02 11:23:10 +04:00
|
|
|
if (doc) {
|
|
|
|
// Flush pending content changes Bug 4891.
|
|
|
|
doc->FlushPendingNotifications(Flush_ContentAndNotify);
|
|
|
|
}
|
2003-07-29 01:09:56 +04:00
|
|
|
}
|
2002-06-28 05:30:09 +04:00
|
|
|
|
2003-07-29 01:09:56 +04:00
|
|
|
if (mState != LIST_UP_TO_DATE)
|
2014-06-26 09:21:13 +04:00
|
|
|
PopulateSelf(std::min(aIndex, UINT32_MAX - 1) + 1);
|
2002-06-28 05:30:09 +04:00
|
|
|
|
2006-08-10 22:58:37 +04:00
|
|
|
ASSERT_IN_SYNC;
|
2006-07-02 11:23:10 +04:00
|
|
|
NS_ASSERTION(!mRootNode || mState != LIST_DIRTY,
|
2003-07-29 01:09:56 +04:00
|
|
|
"PopulateSelf left the list in a dirty (useless) state!");
|
|
|
|
|
2011-11-01 06:48:59 +04:00
|
|
|
return mElements.SafeElementAt(aIndex);
|
1999-01-18 06:43:43 +03:00
|
|
|
}
|
|
|
|
|
2013-11-11 11:55:41 +04:00
|
|
|
Element*
|
2011-09-29 10:19:26 +04:00
|
|
|
nsContentList::NamedItem(const nsAString& aName, bool aDoFlush)
|
1999-01-18 06:43:43 +03:00
|
|
|
{
|
2014-05-22 08:23:51 +04:00
|
|
|
if (aName.IsEmpty()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2003-07-29 01:09:56 +04:00
|
|
|
BringSelfUpToDate(aDoFlush);
|
2013-05-02 13:12:45 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t i, count = mElements.Length();
|
2003-07-29 01:09:56 +04:00
|
|
|
|
2005-11-16 05:55:29 +03:00
|
|
|
// Typically IDs and names are atomized
|
2005-09-11 23:20:08 +04:00
|
|
|
nsCOMPtr<nsIAtom> name = do_GetAtom(aName);
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ENSURE_TRUE(name, nullptr);
|
2005-09-11 23:20:08 +04:00
|
|
|
|
2003-07-29 01:09:56 +04:00
|
|
|
for (i = 0; i < count; i++) {
|
2006-08-25 21:45:25 +04:00
|
|
|
nsIContent *content = mElements[i];
|
2005-09-11 23:20:08 +04:00
|
|
|
// XXX Should this pass eIgnoreCase?
|
|
|
|
if (content &&
|
2006-12-26 20:47:52 +03:00
|
|
|
(content->AttrValueIs(kNameSpaceID_None, nsGkAtoms::name,
|
2005-11-16 05:55:29 +03:00
|
|
|
name, eCaseMatters) ||
|
2006-12-26 20:47:52 +03:00
|
|
|
content->AttrValueIs(kNameSpaceID_None, nsGkAtoms::id,
|
2005-09-11 23:20:08 +04:00
|
|
|
name, eCaseMatters))) {
|
2013-11-11 11:55:41 +04:00
|
|
|
return content->AsElement();
|
1999-01-18 06:43:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
1999-01-18 06:43:43 +03:00
|
|
|
}
|
|
|
|
|
2012-11-05 20:58:03 +04:00
|
|
|
void
|
2014-04-16 06:58:44 +04:00
|
|
|
nsContentList::GetSupportedNames(unsigned aFlags, nsTArray<nsString>& aNames)
|
2012-11-05 20:58:03 +04:00
|
|
|
{
|
2014-04-16 06:58:44 +04:00
|
|
|
if (!(aFlags & JSITER_HIDDEN)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-05 20:58:03 +04:00
|
|
|
BringSelfUpToDate(true);
|
|
|
|
|
|
|
|
nsAutoTArray<nsIAtom*, 8> atoms;
|
|
|
|
for (uint32_t i = 0; i < mElements.Length(); ++i) {
|
|
|
|
nsIContent *content = mElements.ElementAt(i);
|
2014-05-22 08:23:51 +04:00
|
|
|
if (content->HasID()) {
|
|
|
|
nsIAtom* id = content->GetID();
|
|
|
|
MOZ_ASSERT(id != nsGkAtoms::_empty,
|
|
|
|
"Empty ids don't get atomized");
|
|
|
|
if (!atoms.Contains(id)) {
|
|
|
|
atoms.AppendElement(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-05 20:58:03 +04:00
|
|
|
nsGenericHTMLElement* el = nsGenericHTMLElement::FromContent(content);
|
|
|
|
if (el) {
|
|
|
|
// XXXbz should we be checking for particular tags here? How
|
|
|
|
// stable is this part of the spec?
|
|
|
|
// Note: nsINode::HasName means the name is exposed on the document,
|
|
|
|
// which is false for options, so we don't check it here.
|
|
|
|
const nsAttrValue* val = el->GetParsedAttr(nsGkAtoms::name);
|
|
|
|
if (val && val->Type() == nsAttrValue::eAtom) {
|
|
|
|
nsIAtom* name = val->GetAtomValue();
|
2014-05-22 08:23:51 +04:00
|
|
|
MOZ_ASSERT(name != nsGkAtoms::_empty,
|
|
|
|
"Empty names don't get atomized");
|
2012-11-05 20:58:03 +04:00
|
|
|
if (!atoms.Contains(name)) {
|
|
|
|
atoms.AppendElement(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aNames.SetCapacity(atoms.Length());
|
|
|
|
for (uint32_t i = 0; i < atoms.Length(); ++i) {
|
|
|
|
aNames.AppendElement(nsDependentAtomString(atoms[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
2011-09-29 10:19:26 +04:00
|
|
|
nsContentList::IndexOf(nsIContent *aContent, bool aDoFlush)
|
2001-05-30 15:26:21 +04:00
|
|
|
{
|
2003-07-29 01:09:56 +04:00
|
|
|
BringSelfUpToDate(aDoFlush);
|
2002-06-28 05:30:09 +04:00
|
|
|
|
2003-09-27 08:18:26 +04:00
|
|
|
return mElements.IndexOf(aContent);
|
2001-05-30 15:26:21 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
2009-01-29 22:46:18 +03:00
|
|
|
nsContentList::IndexOf(nsIContent* aContent)
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return IndexOf(aContent, true);
|
2009-01-29 22:46:18 +03:00
|
|
|
}
|
|
|
|
|
2004-04-14 08:26:00 +04:00
|
|
|
void
|
2006-07-02 11:23:10 +04:00
|
|
|
nsContentList::NodeWillBeDestroyed(const nsINode* aNode)
|
2004-04-14 08:26:00 +04:00
|
|
|
{
|
|
|
|
// We shouldn't do anything useful from now on
|
2006-07-02 11:23:10 +04:00
|
|
|
|
2010-02-09 20:09:06 +03:00
|
|
|
RemoveFromCaches();
|
2012-07-30 18:20:58 +04:00
|
|
|
mRootNode = nullptr;
|
2006-07-02 11:23:10 +04:00
|
|
|
|
|
|
|
// We will get no more updates, so we can never know we're up to
|
|
|
|
// date
|
2006-09-30 19:12:47 +04:00
|
|
|
SetDirty();
|
2004-04-14 08:26:00 +04:00
|
|
|
}
|
|
|
|
|
2001-05-30 15:26:21 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsContentList::GetLength(uint32_t* aLength)
|
2001-05-30 15:26:21 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
*aLength = Length(true);
|
2003-09-27 08:18:26 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
2001-05-30 15:26:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsContentList::Item(uint32_t aIndex, nsIDOMNode** aReturn)
|
2001-05-30 15:26:21 +04:00
|
|
|
{
|
2012-10-13 16:50:24 +04:00
|
|
|
nsINode* node = Item(aIndex);
|
2004-01-24 03:46:17 +03:00
|
|
|
|
2008-09-11 07:15:29 +04:00
|
|
|
if (node) {
|
|
|
|
return CallQueryInterface(node, aReturn);
|
2004-01-24 03:46:17 +03:00
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
*aReturn = nullptr;
|
2004-01-24 03:46:17 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2001-05-30 15:26:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 02:54:46 +03:00
|
|
|
nsContentList::NamedItem(const nsAString& aName, nsIDOMNode** aReturn)
|
2001-05-30 15:26:21 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
nsIContent *content = NamedItem(aName, true);
|
2004-01-24 03:46:17 +03:00
|
|
|
|
|
|
|
if (content) {
|
|
|
|
return CallQueryInterface(content, aReturn);
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
*aReturn = nullptr;
|
2004-01-24 03:46:17 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2001-05-30 15:26:21 +04:00
|
|
|
}
|
|
|
|
|
2012-11-15 02:10:08 +04:00
|
|
|
Element*
|
2012-09-05 19:42:58 +04:00
|
|
|
nsContentList::GetElementAt(uint32_t aIndex)
|
|
|
|
{
|
2012-11-15 02:10:08 +04:00
|
|
|
return static_cast<Element*>(Item(aIndex, true));
|
2012-09-05 19:42:58 +04:00
|
|
|
}
|
|
|
|
|
2009-01-29 22:46:18 +03:00
|
|
|
nsIContent*
|
2012-10-13 16:50:24 +04:00
|
|
|
nsContentList::Item(uint32_t aIndex)
|
2008-09-11 07:15:29 +04:00
|
|
|
{
|
2012-09-05 19:42:58 +04:00
|
|
|
return GetElementAt(aIndex);
|
2008-09-11 07:15:29 +04:00
|
|
|
}
|
|
|
|
|
2004-04-15 05:51:32 +04:00
|
|
|
void
|
2010-08-24 11:05:56 +04:00
|
|
|
nsContentList::AttributeChanged(nsIDocument *aDocument, Element* aElement,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aNameSpaceID, nsIAtom* aAttribute,
|
|
|
|
int32_t aModType)
|
2004-04-15 05:51:32 +04:00
|
|
|
{
|
2010-08-24 11:05:56 +04:00
|
|
|
NS_PRECONDITION(aElement, "Must have a content node to work with");
|
2004-04-30 01:07:44 +04:00
|
|
|
|
2005-08-16 05:43:53 +04:00
|
|
|
if (!mFunc || !mFuncMayDependOnAttr || mState == LIST_DIRTY ||
|
2012-10-09 16:31:24 +04:00
|
|
|
!MayContainRelevantNodes(aElement->GetParentNode()) ||
|
2010-08-24 11:05:56 +04:00
|
|
|
!nsContentUtils::IsInSameAnonymousTree(mRootNode, aElement)) {
|
2004-04-15 05:51:32 +04:00
|
|
|
// Either we're already dirty or this notification doesn't affect
|
2010-08-24 11:05:56 +04:00
|
|
|
// whether we might match aElement.
|
2004-04-15 05:51:32 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-24 11:05:56 +04:00
|
|
|
if (Match(aElement)) {
|
2011-11-01 06:48:59 +04:00
|
|
|
if (mElements.IndexOf(aElement) == mElements.NoIndex) {
|
2010-08-24 11:05:56 +04:00
|
|
|
// We match aElement now, and it's not in our list already. Just dirty
|
2006-07-02 11:23:10 +04:00
|
|
|
// ourselves; this is simpler than trying to figure out where to insert
|
2010-08-24 11:05:56 +04:00
|
|
|
// aElement.
|
2006-09-30 19:12:47 +04:00
|
|
|
SetDirty();
|
2004-04-15 05:51:32 +04:00
|
|
|
}
|
2006-07-02 11:23:10 +04:00
|
|
|
} else {
|
2010-08-24 11:05:56 +04:00
|
|
|
// We no longer match aElement. Remove it from our list. If it's
|
2006-08-25 21:45:25 +04:00
|
|
|
// already not there, this is a no-op (though a potentially
|
|
|
|
// expensive one). Either way, no change of mState is required
|
|
|
|
// here.
|
2011-11-01 06:48:59 +04:00
|
|
|
mElements.RemoveElement(aElement);
|
2004-04-15 05:51:32 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-24 03:46:17 +03:00
|
|
|
void
|
2010-08-24 11:05:56 +04:00
|
|
|
nsContentList::ContentAppended(nsIDocument* aDocument, nsIContent* aContainer,
|
2010-05-11 05:12:34 +04:00
|
|
|
nsIContent* aFirstNewContent,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aNewIndexInContainer)
|
1999-01-18 06:43:43 +03:00
|
|
|
{
|
2002-09-09 23:44:29 +04:00
|
|
|
NS_PRECONDITION(aContainer, "Can't get at the new content if no container!");
|
|
|
|
|
2002-06-28 05:30:09 +04:00
|
|
|
/*
|
2004-04-30 01:07:44 +04:00
|
|
|
* If the state is LIST_DIRTY then we have no useful information in our list
|
2013-11-28 16:10:39 +04:00
|
|
|
* and we want to put off doing work as much as possible.
|
|
|
|
*
|
|
|
|
* Also, if aContainer is anonymous from our point of view, we know that we
|
|
|
|
* can't possibly be matching any of the kids.
|
|
|
|
*
|
|
|
|
* Optimize out also the common case when just one new node is appended and
|
|
|
|
* it doesn't match us.
|
2002-06-28 05:30:09 +04:00
|
|
|
*/
|
2007-01-30 08:48:22 +03:00
|
|
|
if (mState == LIST_DIRTY ||
|
|
|
|
!nsContentUtils::IsInSameAnonymousTree(mRootNode, aContainer) ||
|
2013-11-28 16:10:39 +04:00
|
|
|
!MayContainRelevantNodes(aContainer) ||
|
|
|
|
(!aFirstNewContent->HasChildren() &&
|
|
|
|
!aFirstNewContent->GetNextSibling() &&
|
|
|
|
!MatchSelf(aFirstNewContent))) {
|
2004-01-24 03:46:17 +03:00
|
|
|
return;
|
2013-11-28 16:10:39 +04:00
|
|
|
}
|
2001-03-22 11:51:52 +03:00
|
|
|
|
2002-06-28 05:30:09 +04:00
|
|
|
/*
|
|
|
|
* We want to handle the case of ContentAppended by sometimes
|
|
|
|
* appending the content to our list, not just setting state to
|
|
|
|
* LIST_DIRTY, since most of our ContentAppended notifications
|
|
|
|
* should come during pageload and be at the end of the document.
|
|
|
|
* Do a bit of work to see whether we could just append to what we
|
|
|
|
* already have.
|
|
|
|
*/
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t count = aContainer->GetChildCount();
|
2004-04-14 08:26:00 +04:00
|
|
|
|
2006-07-02 11:23:10 +04:00
|
|
|
if (count > 0) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t ourCount = mElements.Length();
|
2011-09-29 10:19:26 +04:00
|
|
|
bool appendToList = false;
|
2002-06-28 05:30:09 +04:00
|
|
|
if (ourCount == 0) {
|
2011-10-17 18:59:28 +04:00
|
|
|
appendToList = true;
|
2002-06-28 05:30:09 +04:00
|
|
|
} else {
|
2006-08-25 21:45:25 +04:00
|
|
|
nsIContent* ourLastContent = mElements[ourCount - 1];
|
2002-06-28 05:30:09 +04:00
|
|
|
/*
|
2002-09-09 23:44:29 +04:00
|
|
|
* We want to append instead of invalidating if the first thing
|
|
|
|
* that got appended comes after ourLastContent.
|
2002-06-28 05:30:09 +04:00
|
|
|
*/
|
2010-05-11 05:12:34 +04:00
|
|
|
if (nsContentUtils::PositionIsBefore(ourLastContent, aFirstNewContent)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
appendToList = true;
|
2002-06-28 05:30:09 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-18 22:02:24 +04:00
|
|
|
|
2002-06-28 05:30:09 +04:00
|
|
|
if (!appendToList) {
|
|
|
|
// The new stuff is somewhere in the middle of our list; check
|
|
|
|
// whether we need to invalidate
|
2010-05-11 05:12:34 +04:00
|
|
|
for (nsIContent* cur = aFirstNewContent; cur; cur = cur->GetNextSibling()) {
|
2010-05-11 05:12:34 +04:00
|
|
|
if (MatchSelf(cur)) {
|
2002-06-28 05:30:09 +04:00
|
|
|
// Uh-oh. We're gonna have to add elements into the middle
|
|
|
|
// of our list. That's not worth the effort.
|
2006-09-30 19:12:47 +04:00
|
|
|
SetDirty();
|
2002-06-28 05:30:09 +04:00
|
|
|
break;
|
|
|
|
}
|
1999-01-18 06:43:43 +03:00
|
|
|
}
|
2009-04-18 22:02:24 +04:00
|
|
|
|
2006-08-10 22:58:37 +04:00
|
|
|
ASSERT_IN_SYNC;
|
2004-01-24 03:46:17 +03:00
|
|
|
return;
|
1999-01-18 06:43:43 +03:00
|
|
|
}
|
2002-06-28 05:30:09 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* At this point we know we could append. If we're not up to
|
|
|
|
* date, however, that would be a bad idea -- it could miss some
|
|
|
|
* content that we never picked up due to being lazy. Further, we
|
|
|
|
* may never get asked for this content... so don't grab it yet.
|
|
|
|
*/
|
|
|
|
if (mState == LIST_LAZY) // be lazy
|
2004-01-24 03:46:17 +03:00
|
|
|
return;
|
2002-06-28 05:30:09 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We're up to date. That means someone's actively using us; we
|
|
|
|
* may as well grab this content....
|
|
|
|
*/
|
2010-05-11 05:12:34 +04:00
|
|
|
if (mDeep) {
|
2010-05-11 05:12:34 +04:00
|
|
|
for (nsIContent* cur = aFirstNewContent;
|
|
|
|
cur;
|
|
|
|
cur = cur->GetNextNode(aContainer)) {
|
2010-05-11 05:12:34 +04:00
|
|
|
if (cur->IsElement() && Match(cur->AsElement())) {
|
2011-11-01 06:48:59 +04:00
|
|
|
mElements.AppendElement(cur);
|
2010-05-11 05:12:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2010-05-11 05:12:34 +04:00
|
|
|
for (nsIContent* cur = aFirstNewContent; cur; cur = cur->GetNextSibling()) {
|
2010-05-11 05:12:34 +04:00
|
|
|
if (cur->IsElement() && Match(cur->AsElement())) {
|
2011-11-01 06:48:59 +04:00
|
|
|
mElements.AppendElement(cur);
|
2010-05-11 05:12:34 +04:00
|
|
|
}
|
2008-09-13 02:35:15 +04:00
|
|
|
}
|
1999-01-18 06:43:43 +03:00
|
|
|
}
|
2006-08-10 22:58:37 +04:00
|
|
|
|
|
|
|
ASSERT_IN_SYNC;
|
1999-01-18 06:43:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-24 03:46:17 +03:00
|
|
|
void
|
1999-01-18 06:43:43 +03:00
|
|
|
nsContentList::ContentInserted(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aIndexInContainer)
|
1999-01-18 06:43:43 +03:00
|
|
|
{
|
2002-07-02 05:25:23 +04:00
|
|
|
// Note that aContainer can be null here if we are inserting into
|
|
|
|
// the document itself; any attempted optimizations to this method
|
|
|
|
// should deal with that.
|
2006-07-02 11:23:10 +04:00
|
|
|
if (mState != LIST_DIRTY &&
|
|
|
|
MayContainRelevantNodes(NODE_FROM(aContainer, aDocument)) &&
|
2007-01-30 08:48:22 +03:00
|
|
|
nsContentUtils::IsInSameAnonymousTree(mRootNode, aChild) &&
|
2006-07-02 11:23:10 +04:00
|
|
|
MatchSelf(aChild)) {
|
2006-09-30 19:12:47 +04:00
|
|
|
SetDirty();
|
2006-07-02 11:23:10 +04:00
|
|
|
}
|
2006-08-10 22:58:37 +04:00
|
|
|
|
|
|
|
ASSERT_IN_SYNC;
|
1999-01-18 06:43:43 +03:00
|
|
|
}
|
|
|
|
|
2004-01-24 03:46:17 +03:00
|
|
|
void
|
1999-01-18 06:43:43 +03:00
|
|
|
nsContentList::ContentRemoved(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aIndexInContainer,
|
2010-07-22 02:05:17 +04:00
|
|
|
nsIContent* aPreviousSibling)
|
1999-01-18 06:43:43 +03:00
|
|
|
{
|
2004-04-30 01:07:44 +04:00
|
|
|
// Note that aContainer can be null here if we are removing from
|
2002-07-02 05:25:23 +04:00
|
|
|
// the document itself; any attempted optimizations to this method
|
|
|
|
// should deal with that.
|
2006-07-02 11:23:10 +04:00
|
|
|
if (mState != LIST_DIRTY &&
|
|
|
|
MayContainRelevantNodes(NODE_FROM(aContainer, aDocument)) &&
|
2007-01-30 08:48:22 +03:00
|
|
|
nsContentUtils::IsInSameAnonymousTree(mRootNode, aChild) &&
|
2006-07-02 11:23:10 +04:00
|
|
|
MatchSelf(aChild)) {
|
2006-09-30 19:12:47 +04:00
|
|
|
SetDirty();
|
1999-01-18 06:43:43 +03:00
|
|
|
}
|
2006-08-10 22:58:37 +04:00
|
|
|
|
|
|
|
ASSERT_IN_SYNC;
|
1999-01-18 06:43:43 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-04-30 17:12:05 +04:00
|
|
|
nsContentList::Match(Element *aElement)
|
1998-07-23 03:32:19 +04:00
|
|
|
{
|
2004-04-15 05:51:32 +04:00
|
|
|
if (mFunc) {
|
2010-09-01 06:47:00 +04:00
|
|
|
return (*mFunc)(aElement, mMatchNameSpaceId, mXMLMatchAtom, mData);
|
2004-04-15 05:51:32 +04:00
|
|
|
}
|
|
|
|
|
2010-09-01 06:47:00 +04:00
|
|
|
if (!mXMLMatchAtom)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2006-07-20 07:25:39 +04:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
mozilla::dom::NodeInfo *ni = aElement->NodeInfo();
|
2010-09-01 06:47:00 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool unknown = mMatchNameSpaceId == kNameSpaceID_Unknown;
|
|
|
|
bool wildcard = mMatchNameSpaceId == kNameSpaceID_Wildcard;
|
|
|
|
bool toReturn = mMatchAll;
|
2010-09-01 06:47:00 +04:00
|
|
|
if (!unknown && !wildcard)
|
|
|
|
toReturn &= ni->NamespaceEquals(mMatchNameSpaceId);
|
|
|
|
|
|
|
|
if (toReturn)
|
|
|
|
return toReturn;
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool matchHTML = aElement->GetNameSpaceID() == kNameSpaceID_XHTML &&
|
2015-03-03 14:08:59 +03:00
|
|
|
aElement->OwnerDoc()->IsHTMLDocument();
|
2010-09-01 06:47:00 +04:00
|
|
|
|
|
|
|
if (unknown) {
|
|
|
|
return matchHTML ? ni->QualifiedNameEquals(mHTMLMatchAtom) :
|
|
|
|
ni->QualifiedNameEquals(mXMLMatchAtom);
|
1998-07-23 03:32:19 +04:00
|
|
|
}
|
2010-09-01 06:47:00 +04:00
|
|
|
|
|
|
|
if (wildcard) {
|
|
|
|
return matchHTML ? ni->Equals(mHTMLMatchAtom) :
|
|
|
|
ni->Equals(mXMLMatchAtom);
|
|
|
|
}
|
|
|
|
|
|
|
|
return matchHTML ? ni->Equals(mHTMLMatchAtom, mMatchNameSpaceId) :
|
|
|
|
ni->Equals(mXMLMatchAtom, mMatchNameSpaceId);
|
1998-07-23 03:32:19 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
1999-01-18 06:43:43 +03:00
|
|
|
nsContentList::MatchSelf(nsIContent *aContent)
|
1998-07-23 03:32:19 +04:00
|
|
|
{
|
2002-09-09 23:44:29 +04:00
|
|
|
NS_PRECONDITION(aContent, "Can't match null stuff, you know");
|
2012-10-09 16:31:24 +04:00
|
|
|
NS_PRECONDITION(mDeep || aContent->GetParentNode() == mRootNode,
|
2004-04-14 08:26:00 +04:00
|
|
|
"MatchSelf called on a node that we can't possibly match");
|
2008-09-13 02:35:15 +04:00
|
|
|
|
2010-04-30 17:12:05 +04:00
|
|
|
if (!aContent->IsElement()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2008-09-13 02:35:15 +04:00
|
|
|
}
|
2002-09-09 23:44:29 +04:00
|
|
|
|
2010-04-30 17:12:05 +04:00
|
|
|
if (Match(aContent->AsElement()))
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-06-28 05:30:09 +04:00
|
|
|
|
2004-04-14 08:26:00 +04:00
|
|
|
if (!mDeep)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2004-04-14 08:26:00 +04:00
|
|
|
|
2010-05-11 05:12:34 +04:00
|
|
|
for (nsIContent* cur = aContent->GetFirstChild();
|
|
|
|
cur;
|
|
|
|
cur = cur->GetNextNode(aContent)) {
|
|
|
|
if (cur->IsElement() && Match(cur->AsElement())) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
1998-07-23 03:32:19 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
1998-07-23 03:32:19 +04:00
|
|
|
}
|
|
|
|
|
1999-01-18 06:43:43 +03:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
nsContentList::PopulateSelf(uint32_t aNeededLength)
|
1998-07-23 03:32:19 +04:00
|
|
|
{
|
2006-07-02 11:23:10 +04:00
|
|
|
if (!mRootNode) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-08-10 22:58:37 +04:00
|
|
|
ASSERT_IN_SYNC;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t count = mElements.Length();
|
2006-09-30 19:12:47 +04:00
|
|
|
NS_ASSERTION(mState != LIST_DIRTY || count == 0,
|
|
|
|
"Reset() not called when setting state to LIST_DIRTY?");
|
2002-06-28 05:30:09 +04:00
|
|
|
|
|
|
|
if (count >= aNeededLength) // We're all set
|
|
|
|
return;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t elementsToAppend = aNeededLength - count;
|
2002-06-28 05:30:09 +04:00
|
|
|
#ifdef DEBUG
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t invariant = elementsToAppend + mElements.Length();
|
2002-06-28 05:30:09 +04:00
|
|
|
#endif
|
|
|
|
|
2010-05-11 05:12:34 +04:00
|
|
|
if (mDeep) {
|
|
|
|
// If we already have nodes start searching at the last one, otherwise
|
|
|
|
// start searching at the root.
|
|
|
|
nsINode* cur = count ? mElements[count - 1] : mRootNode;
|
|
|
|
do {
|
|
|
|
cur = cur->GetNextNode(mRootNode);
|
|
|
|
if (!cur) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (cur->IsElement() && Match(cur->AsElement())) {
|
2011-11-01 06:48:59 +04:00
|
|
|
// Append AsElement() to get nsIContent instead of nsINode
|
|
|
|
mElements.AppendElement(cur->AsElement());
|
2010-05-11 05:12:34 +04:00
|
|
|
--elementsToAppend;
|
|
|
|
}
|
|
|
|
} while (elementsToAppend);
|
|
|
|
} else {
|
|
|
|
nsIContent* cur =
|
|
|
|
count ? mElements[count-1]->GetNextSibling() : mRootNode->GetFirstChild();
|
|
|
|
for ( ; cur && elementsToAppend; cur = cur->GetNextSibling()) {
|
|
|
|
if (cur->IsElement() && Match(cur->AsElement())) {
|
2011-11-01 06:48:59 +04:00
|
|
|
mElements.AppendElement(cur);
|
2010-05-11 05:12:34 +04:00
|
|
|
--elementsToAppend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-01-18 06:43:43 +03:00
|
|
|
|
2011-11-01 06:48:59 +04:00
|
|
|
NS_ASSERTION(elementsToAppend + mElements.Length() == invariant,
|
2010-05-11 05:12:34 +04:00
|
|
|
"Something is awry!");
|
1998-07-23 03:32:19 +04:00
|
|
|
|
2006-07-02 11:23:10 +04:00
|
|
|
if (elementsToAppend != 0)
|
|
|
|
mState = LIST_UP_TO_DATE;
|
|
|
|
else
|
|
|
|
mState = LIST_LAZY;
|
2006-08-10 22:58:37 +04:00
|
|
|
|
|
|
|
ASSERT_IN_SYNC;
|
1998-07-23 03:32:19 +04:00
|
|
|
}
|
2002-05-09 00:48:19 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
nsContentList::RemoveFromHashtable()
|
|
|
|
{
|
2004-04-15 05:51:32 +04:00
|
|
|
if (mFunc) {
|
|
|
|
// This can't be in the table anyway
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-05 23:40:09 +04:00
|
|
|
nsDependentAtomString str(mXMLMatchAtom);
|
|
|
|
nsContentListKey key(mRootNode, mMatchNameSpaceId, str);
|
|
|
|
uint32_t recentlyUsedCacheIndex = RecentlyUsedCacheIndex(key);
|
|
|
|
if (sRecentlyUsedContentLists[recentlyUsedCacheIndex] == this) {
|
|
|
|
sRecentlyUsedContentLists[recentlyUsedCacheIndex] = nullptr;
|
|
|
|
}
|
|
|
|
|
2015-05-18 10:52:07 +03:00
|
|
|
if (!gContentListHashTable)
|
2002-05-09 00:48:19 +04:00
|
|
|
return;
|
2002-08-13 04:50:50 +04:00
|
|
|
|
2015-05-18 10:52:07 +03:00
|
|
|
PL_DHashTableRemove(gContentListHashTable, &key);
|
2002-05-09 00:48:19 +04:00
|
|
|
|
2015-05-18 10:52:07 +03:00
|
|
|
if (gContentListHashTable->EntryCount() == 0) {
|
|
|
|
delete gContentListHashTable;
|
|
|
|
gContentListHashTable = nullptr;
|
2002-05-09 00:48:19 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-28 05:30:09 +04:00
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsContentList::BringSelfUpToDate(bool aDoFlush)
|
2002-06-28 05:30:09 +04:00
|
|
|
{
|
2010-09-28 21:46:08 +04:00
|
|
|
if (mRootNode && aDoFlush && mFlushesNeeded) {
|
2006-07-02 11:23:10 +04:00
|
|
|
// XXX sXBL/XBL2 issue
|
2014-10-02 22:45:44 +04:00
|
|
|
nsIDocument* doc = mRootNode->GetUncomposedDoc();
|
2006-07-02 11:23:10 +04:00
|
|
|
if (doc) {
|
|
|
|
// Flush pending content changes Bug 4891.
|
|
|
|
doc->FlushPendingNotifications(Flush_ContentAndNotify);
|
|
|
|
}
|
2002-06-28 05:30:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mState != LIST_UP_TO_DATE)
|
2012-08-22 19:56:38 +04:00
|
|
|
PopulateSelf(uint32_t(-1));
|
2002-06-28 05:30:09 +04:00
|
|
|
|
2006-08-10 22:58:37 +04:00
|
|
|
ASSERT_IN_SYNC;
|
2006-07-02 11:23:10 +04:00
|
|
|
NS_ASSERTION(!mRootNode || mState == LIST_UP_TO_DATE,
|
2002-06-28 05:30:09 +04:00
|
|
|
"PopulateSelf dod not bring content list up to date!");
|
|
|
|
}
|
2004-04-30 01:07:44 +04:00
|
|
|
|
2010-02-09 20:09:06 +03:00
|
|
|
nsCacheableFuncStringContentList::~nsCacheableFuncStringContentList()
|
|
|
|
{
|
|
|
|
RemoveFromFuncStringHashtable();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCacheableFuncStringContentList::RemoveFromFuncStringHashtable()
|
|
|
|
{
|
2015-05-18 10:52:07 +03:00
|
|
|
if (!gFuncStringContentListHashTable) {
|
2010-02-09 20:09:06 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsFuncStringCacheKey key(mRootNode, mFunc, mString);
|
2015-05-18 10:52:07 +03:00
|
|
|
PL_DHashTableRemove(gFuncStringContentListHashTable, &key);
|
2010-02-09 20:09:06 +03:00
|
|
|
|
2015-05-18 10:52:07 +03:00
|
|
|
if (gFuncStringContentListHashTable->EntryCount() == 0) {
|
|
|
|
delete gFuncStringContentListHashTable;
|
|
|
|
gFuncStringContentListHashTable = nullptr;
|
2010-02-09 20:09:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-10 22:58:37 +04:00
|
|
|
#ifdef DEBUG_CONTENT_LIST
|
|
|
|
void
|
|
|
|
nsContentList::AssertInSync()
|
|
|
|
{
|
|
|
|
if (mState == LIST_DIRTY) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mRootNode) {
|
2011-11-01 06:48:59 +04:00
|
|
|
NS_ASSERTION(mElements.Length() == 0 && mState == LIST_DIRTY,
|
2006-08-10 22:58:37 +04:00
|
|
|
"Empty iterator isn't quite empty?");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX This code will need to change if nsContentLists can ever match
|
|
|
|
// elements that are outside of the document element.
|
|
|
|
nsIContent *root;
|
|
|
|
if (mRootNode->IsNodeOfType(nsINode::eDOCUMENT)) {
|
2010-04-30 17:12:05 +04:00
|
|
|
root = static_cast<nsIDocument*>(mRootNode)->GetRootElement();
|
2006-08-10 22:58:37 +04:00
|
|
|
}
|
|
|
|
else {
|
2007-07-08 11:08:04 +04:00
|
|
|
root = static_cast<nsIContent*>(mRootNode);
|
2006-08-10 22:58:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContentIterator> iter;
|
|
|
|
if (mDeep) {
|
2012-06-11 03:44:50 +04:00
|
|
|
iter = NS_NewPreContentIterator();
|
2006-08-10 22:58:37 +04:00
|
|
|
iter->Init(root);
|
|
|
|
iter->First();
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t cnt = 0, index = 0;
|
2011-10-17 18:59:28 +04:00
|
|
|
while (true) {
|
2011-11-01 06:48:59 +04:00
|
|
|
if (cnt == mElements.Length() && mState == LIST_LAZY) {
|
2006-08-10 22:58:37 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent *cur = mDeep ? iter->GetCurrentNode() :
|
|
|
|
mRootNode->GetChildAt(index++);
|
|
|
|
if (!cur) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-04-30 17:12:05 +04:00
|
|
|
if (cur->IsElement() && Match(cur->AsElement())) {
|
2011-11-01 06:48:59 +04:00
|
|
|
NS_ASSERTION(cnt < mElements.Length() && mElements[cnt] == cur,
|
2006-08-10 22:58:37 +04:00
|
|
|
"Elements is out of sync");
|
|
|
|
++cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mDeep) {
|
|
|
|
iter->Next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-01 06:48:59 +04:00
|
|
|
NS_ASSERTION(cnt == mElements.Length(), "Too few elements");
|
2006-08-10 22:58:37 +04:00
|
|
|
}
|
|
|
|
#endif
|