2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2010-07-19 13:50:20 -07:00
|
|
|
/* vim: set ts=2 sw=2 et tw=79: */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
2012-05-23 11:46:04 -07:00
|
|
|
#include "nsXBLService.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIInputStream.h"
|
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsIURL.h"
|
|
|
|
#include "nsIChannel.h"
|
|
|
|
#include "nsXPIDLString.h"
|
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "plstr.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIXMLContentSink.h"
|
|
|
|
#include "nsContentCID.h"
|
|
|
|
#include "nsXMLDocument.h"
|
|
|
|
#include "nsIStreamListener.h"
|
|
|
|
|
|
|
|
#include "nsXBLBinding.h"
|
|
|
|
#include "nsXBLPrototypeBinding.h"
|
2010-07-14 18:53:11 -07:00
|
|
|
#include "nsXBLDocumentInfo.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsXBLInsertionPoint.h"
|
|
|
|
|
|
|
|
#include "nsIStyleRuleProcessor.h"
|
2009-08-01 08:53:40 -07:00
|
|
|
#include "nsRuleProcessorData.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIWeakReference.h"
|
|
|
|
|
|
|
|
#include "jsapi.h"
|
|
|
|
#include "nsIXPConnect.h"
|
|
|
|
#include "nsDOMCID.h"
|
|
|
|
#include "nsIDOMScriptObjectFactory.h"
|
|
|
|
#include "nsIScriptGlobalObject.h"
|
2008-07-26 09:14:49 -07:00
|
|
|
#include "nsTHashtable.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsIScriptContext.h"
|
|
|
|
#include "nsBindingManager.h"
|
|
|
|
|
|
|
|
#include "nsThreadUtils.h"
|
2012-06-13 08:18:30 -07:00
|
|
|
#include "mozilla/dom/NodeListBinding.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// ==================================================================
|
|
|
|
// = nsAnonymousContentList
|
|
|
|
// ==================================================================
|
|
|
|
|
2007-10-12 04:07:29 -07:00
|
|
|
#define NS_ANONYMOUS_CONTENT_LIST_IID \
|
2011-05-23 08:39:52 -07:00
|
|
|
{ 0xbfb5d8e7, 0xf718, 0x4a46, \
|
|
|
|
{ 0xb2, 0x2b, 0x22, 0x4a, 0x44, 0x4c, 0xb9, 0x77 } }
|
2007-10-12 04:07:29 -07:00
|
|
|
|
2008-10-22 07:31:14 -07:00
|
|
|
class nsAnonymousContentList : public nsINodeList
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
2009-06-15 23:32:10 -07:00
|
|
|
nsAnonymousContentList(nsIContent *aContent, nsInsertionPointList* aElements);
|
2007-03-22 10:30:00 -07:00
|
|
|
virtual ~nsAnonymousContentList();
|
|
|
|
|
2007-05-24 07:10:02 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2011-05-31 14:47:17 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsAnonymousContentList)
|
2007-03-22 10:30:00 -07:00
|
|
|
// nsIDOMNodeList interface
|
|
|
|
NS_DECL_NSIDOMNODELIST
|
|
|
|
|
2008-09-10 20:15:29 -07:00
|
|
|
// nsINodeList interface
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual int32_t IndexOf(nsIContent* aContent);
|
2009-06-15 23:32:10 -07:00
|
|
|
virtual nsINode *GetParentObject()
|
|
|
|
{
|
|
|
|
return mContent;
|
|
|
|
}
|
2012-10-13 05:50:24 -07:00
|
|
|
virtual nsIContent* Item(uint32_t aIndex);
|
2008-09-10 20:15:29 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t GetInsertionPointCount() { return mElements->Length(); }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXBLInsertionPoint* GetInsertionPointAt(int32_t i) { return static_cast<nsXBLInsertionPoint*>(mElements->ElementAt(i)); }
|
|
|
|
void RemoveInsertionPointAt(int32_t i) { mElements->RemoveElementAt(i); }
|
2011-05-31 14:47:17 -07:00
|
|
|
|
2012-03-14 08:25:40 -07:00
|
|
|
virtual JSObject* WrapObject(JSContext *cx, JSObject *scope,
|
2011-06-29 10:17:37 -07:00
|
|
|
bool *triedToWrap)
|
2011-05-31 14:47:17 -07:00
|
|
|
{
|
2012-10-13 05:50:24 -07:00
|
|
|
return mozilla::dom::NodeListBinding::Wrap(cx, scope, this, triedToWrap);
|
2011-05-31 14:47:17 -07:00
|
|
|
}
|
|
|
|
|
2007-10-12 04:07:29 -07:00
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(NS_ANONYMOUS_CONTENT_LIST_IID)
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
2009-06-15 23:32:10 -07:00
|
|
|
nsCOMPtr<nsIContent> mContent;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsInsertionPointList* mElements;
|
|
|
|
};
|
|
|
|
|
2007-10-12 04:07:29 -07:00
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(nsAnonymousContentList,
|
|
|
|
NS_ANONYMOUS_CONTENT_LIST_IID)
|
|
|
|
|
2009-06-15 23:32:10 -07:00
|
|
|
nsAnonymousContentList::nsAnonymousContentList(nsIContent *aContent,
|
|
|
|
nsInsertionPointList* aElements)
|
|
|
|
: mContent(aContent),
|
|
|
|
mElements(aElements)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsAnonymousContentList);
|
|
|
|
|
|
|
|
// We don't reference count our Anonymous reference (to avoid circular
|
|
|
|
// references). We'll be told when the Anonymous goes away.
|
2012-03-16 08:44:09 -07:00
|
|
|
SetIsDOMBinding();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAnonymousContentList::~nsAnonymousContentList()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsAnonymousContentList);
|
|
|
|
delete mElements;
|
|
|
|
}
|
|
|
|
|
2007-05-24 07:10:02 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsAnonymousContentList)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsAnonymousContentList)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsAnonymousContentList)
|
|
|
|
|
2008-11-03 02:31:47 -08:00
|
|
|
NS_INTERFACE_TABLE_HEAD(nsAnonymousContentList)
|
2011-05-31 14:47:17 -07:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2008-11-03 02:31:47 -08:00
|
|
|
NS_NODELIST_OFFSET_AND_INTERFACE_TABLE_BEGIN(nsAnonymousContentList)
|
|
|
|
NS_INTERFACE_TABLE_ENTRY(nsAnonymousContentList, nsINodeList)
|
|
|
|
NS_INTERFACE_TABLE_ENTRY(nsAnonymousContentList, nsIDOMNodeList)
|
|
|
|
NS_INTERFACE_TABLE_ENTRY(nsAnonymousContentList, nsAnonymousContentList)
|
|
|
|
NS_OFFSET_AND_INTERFACE_TABLE_END
|
|
|
|
NS_OFFSET_AND_INTERFACE_TABLE_TO_MAP_SEGUE
|
2010-03-17 08:09:05 -07:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(NodeList)
|
2007-05-24 07:10:02 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(nsAnonymousContentList)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2010-04-30 04:09:05 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsAnonymousContentList)
|
2009-06-15 23:32:10 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mContent)
|
2010-04-30 04:09:05 -07:00
|
|
|
tmp->mElements->Clear();
|
2011-05-31 14:47:17 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
2010-04-30 04:09:05 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2007-05-24 07:10:02 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsAnonymousContentList)
|
2009-06-15 23:32:10 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mContent)
|
2007-05-24 07:10:02 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t i, count = tmp->mElements->Length();
|
2007-05-24 07:10:02 -07:00
|
|
|
for (i = 0; i < count; ++i) {
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_MEMBER(mElements->ElementAt(i),
|
|
|
|
nsXBLInsertionPoint);
|
|
|
|
}
|
|
|
|
}
|
2011-05-31 14:47:17 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
2007-05-24 07:10:02 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2011-05-31 14:47:17 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsAnonymousContentList)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
2007-05-24 07:10:02 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsAnonymousContentList::GetLength(uint32_t* aLength)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ASSERTION(aLength != nullptr, "null ptr");
|
2007-03-22 10:30:00 -07:00
|
|
|
if (! aLength)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t cnt = mElements->Length();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
*aLength = 0;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = 0; i < cnt; i++)
|
2007-07-08 00:08:04 -07:00
|
|
|
*aLength += static_cast<nsXBLInsertionPoint*>(mElements->ElementAt(i))->ChildCount();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsAnonymousContentList::Item(uint32_t aIndex, nsIDOMNode** aReturn)
|
2008-09-10 20:15:29 -07:00
|
|
|
{
|
2012-10-13 05:50:24 -07:00
|
|
|
nsINode* item = Item(aIndex);
|
2008-09-10 20:15:29 -07:00
|
|
|
if (!item)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return CallQueryInterface(item, aReturn);
|
|
|
|
}
|
|
|
|
|
2009-01-29 11:46:18 -08:00
|
|
|
nsIContent*
|
2012-10-13 05:50:24 -07:00
|
|
|
nsAnonymousContentList::Item(uint32_t aIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t cnt = mElements->Length();
|
|
|
|
uint32_t pointCount = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = 0; i < cnt; i++) {
|
2007-03-22 10:30:00 -07:00
|
|
|
aIndex -= pointCount;
|
|
|
|
|
2007-07-08 00:08:04 -07:00
|
|
|
nsXBLInsertionPoint* point = static_cast<nsXBLInsertionPoint*>(mElements->ElementAt(i));
|
2007-03-22 10:30:00 -07:00
|
|
|
pointCount = point->ChildCount();
|
|
|
|
|
|
|
|
if (aIndex < pointCount) {
|
2008-09-10 20:15:29 -07:00
|
|
|
return point->ChildAt(aIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t
|
2009-01-29 11:46:18 -08:00
|
|
|
nsAnonymousContentList::IndexOf(nsIContent* aContent)
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t cnt = mElements->Length();
|
|
|
|
int32_t lengthSoFar = 0;
|
2009-01-29 11:46:18 -08:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = 0; i < cnt; ++i) {
|
2009-01-29 11:46:18 -08:00
|
|
|
nsXBLInsertionPoint* point =
|
|
|
|
static_cast<nsXBLInsertionPoint*>(mElements->ElementAt(i));
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t idx = point->IndexOf(aContent);
|
2009-01-29 11:46:18 -08:00
|
|
|
if (idx != -1) {
|
|
|
|
return idx + lengthSoFar;
|
|
|
|
}
|
|
|
|
|
|
|
|
lengthSoFar += point->ChildCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Didn't find it anywhere
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//
|
|
|
|
// Generic pldhash table stuff for mapping one nsISupports to another
|
|
|
|
//
|
|
|
|
// These values are never null - a null value implies that this
|
|
|
|
// whole key should be removed (See SetOrRemoveObject)
|
|
|
|
class ObjectEntry : public PLDHashEntryHdr
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
// note that these are allocated within the PLDHashTable, but we
|
|
|
|
// want to keep track of them anyway
|
|
|
|
ObjectEntry() { MOZ_COUNT_CTOR(ObjectEntry); }
|
|
|
|
~ObjectEntry() { MOZ_COUNT_DTOR(ObjectEntry); }
|
|
|
|
|
|
|
|
nsISupports* GetValue() { return mValue; }
|
|
|
|
nsISupports* GetKey() { return mKey; }
|
|
|
|
void SetValue(nsISupports* aValue) { mValue = aValue; }
|
|
|
|
void SetKey(nsISupports* aKey) { mKey = aKey; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsISupports> mKey;
|
|
|
|
nsCOMPtr<nsISupports> mValue;
|
|
|
|
};
|
|
|
|
|
2008-10-10 08:04:34 -07:00
|
|
|
static void
|
2007-03-22 10:30:00 -07:00
|
|
|
ClearObjectEntry(PLDHashTable* table, PLDHashEntryHdr *entry)
|
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
ObjectEntry* objEntry = static_cast<ObjectEntry*>(entry);
|
2007-03-22 10:30:00 -07:00
|
|
|
objEntry->~ObjectEntry();
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2007-03-22 10:30:00 -07:00
|
|
|
InitObjectEntry(PLDHashTable* table, PLDHashEntryHdr* entry, const void* key)
|
|
|
|
{
|
|
|
|
new (entry) ObjectEntry;
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static PLDHashTableOps ObjectTableOps = {
|
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
PL_DHashVoidPtrKeyStub,
|
|
|
|
PL_DHashMatchEntryStub,
|
|
|
|
PL_DHashMoveEntryStub,
|
|
|
|
ClearObjectEntry,
|
|
|
|
PL_DHashFinalizeStub,
|
|
|
|
InitObjectEntry
|
|
|
|
};
|
|
|
|
|
|
|
|
// helper routine for adding a new entry
|
|
|
|
static nsresult
|
|
|
|
AddObjectEntry(PLDHashTable& table, nsISupports* aKey, nsISupports* aValue)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aKey, "key must be non-null");
|
|
|
|
if (!aKey) return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
ObjectEntry *entry =
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<ObjectEntry*>
|
|
|
|
(PL_DHashTableOperate(&table, aKey, PL_DHASH_ADD));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (!entry)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
// only add the key if the entry is new
|
|
|
|
if (!entry->GetKey())
|
|
|
|
entry->SetKey(aKey);
|
|
|
|
|
|
|
|
// now attach the new entry - note that entry->mValue could possibly
|
|
|
|
// have a value already, this will release that.
|
|
|
|
entry->SetValue(aValue);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// helper routine for looking up an existing entry. Note that the
|
|
|
|
// return result is NOT addreffed
|
|
|
|
static nsISupports*
|
2007-08-21 23:48:47 -07:00
|
|
|
LookupObject(PLDHashTable& table, nsIContent* aKey)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-08-21 23:48:47 -07:00
|
|
|
if (aKey && aKey->HasFlag(NODE_MAY_BE_IN_BINDING_MNGR)) {
|
|
|
|
ObjectEntry *entry =
|
|
|
|
static_cast<ObjectEntry*>
|
|
|
|
(PL_DHashTableOperate(&table, aKey, PL_DHASH_LOOKUP));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-08-21 23:48:47 -07:00
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(entry))
|
|
|
|
return entry->GetValue();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
RemoveObjectEntry(PLDHashTable& table, nsISupports* aKey)
|
|
|
|
{
|
|
|
|
PL_DHashTableOperate(&table, aKey, PL_DHASH_REMOVE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsresult
|
2007-05-11 11:34:12 -07:00
|
|
|
SetOrRemoveObject(PLDHashTable& table, nsIContent* aKey, nsISupports* aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aValue) {
|
|
|
|
// lazily create the table, but only when adding elements
|
|
|
|
if (!table.ops &&
|
2012-07-30 07:20:58 -07:00
|
|
|
!PL_DHashTableInit(&table, &ObjectTableOps, nullptr,
|
2007-03-22 10:30:00 -07:00
|
|
|
sizeof(ObjectEntry), 16)) {
|
2012-07-30 07:20:58 -07:00
|
|
|
table.ops = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2007-05-11 11:34:12 -07:00
|
|
|
aKey->SetFlags(NODE_MAY_BE_IN_BINDING_MNGR);
|
2007-03-22 10:30:00 -07:00
|
|
|
return AddObjectEntry(table, aKey, aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
// no value, so remove the key from the table
|
2007-10-12 04:07:29 -07:00
|
|
|
if (table.ops) {
|
|
|
|
ObjectEntry* entry =
|
|
|
|
static_cast<ObjectEntry*>
|
|
|
|
(PL_DHashTableOperate(&table, aKey, PL_DHASH_LOOKUP));
|
|
|
|
if (entry && PL_DHASH_ENTRY_IS_BUSY(entry)) {
|
|
|
|
// Keep key and value alive while removing the entry.
|
|
|
|
nsCOMPtr<nsISupports> key = entry->GetKey();
|
|
|
|
nsCOMPtr<nsISupports> value = entry->GetValue();
|
|
|
|
RemoveObjectEntry(table, aKey);
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Implementation /////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// Static member variable initialization
|
|
|
|
|
|
|
|
// Implement our nsISupports methods
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsBindingManager)
|
2011-10-17 07:59:28 -07:00
|
|
|
tmp->mDestroyed = true;
|
2007-12-04 10:53:53 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (tmp->mBindingTable.IsInitialized())
|
|
|
|
tmp->mBindingTable.Clear();
|
|
|
|
|
|
|
|
if (tmp->mDocumentTable.IsInitialized())
|
|
|
|
tmp->mDocumentTable.Clear();
|
|
|
|
|
|
|
|
if (tmp->mLoadingDocTable.IsInitialized())
|
|
|
|
tmp->mLoadingDocTable.Clear();
|
|
|
|
|
|
|
|
if (tmp->mContentListTable.ops)
|
|
|
|
PL_DHashTableFinish(&(tmp->mContentListTable));
|
2012-07-30 07:20:58 -07:00
|
|
|
tmp->mContentListTable.ops = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (tmp->mAnonymousNodesTable.ops)
|
|
|
|
PL_DHashTableFinish(&(tmp->mAnonymousNodesTable));
|
2012-07-30 07:20:58 -07:00
|
|
|
tmp->mAnonymousNodesTable.ops = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (tmp->mInsertionParentTable.ops)
|
|
|
|
PL_DHashTableFinish(&(tmp->mInsertionParentTable));
|
2012-07-30 07:20:58 -07:00
|
|
|
tmp->mInsertionParentTable.ops = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (tmp->mWrapperTable.ops)
|
|
|
|
PL_DHashTableFinish(&(tmp->mWrapperTable));
|
2012-07-30 07:20:58 -07:00
|
|
|
tmp->mWrapperTable.ops = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-05-24 07:10:02 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSTARRAY(mAttachedStack)
|
2011-06-22 05:56:44 -07:00
|
|
|
|
|
|
|
if (tmp->mProcessAttachedQueueEvent) {
|
|
|
|
tmp->mProcessAttachedQueueEvent->Revoke();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
|
|
|
|
static PLDHashOperator
|
|
|
|
DocumentInfoHashtableTraverser(nsIURI* key,
|
2010-07-14 18:53:11 -07:00
|
|
|
nsXBLDocumentInfo* di,
|
2007-03-22 10:30:00 -07:00
|
|
|
void* userArg)
|
|
|
|
{
|
|
|
|
nsCycleCollectionTraversalCallback *cb =
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsCycleCollectionTraversalCallback*>(userArg);
|
2009-07-02 05:05:32 -07:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*cb, "mDocumentTable value");
|
2010-11-11 14:52:30 -08:00
|
|
|
cb->NoteXPCOMChild(static_cast<nsIScriptGlobalObjectOwner*>(di));
|
2007-03-22 10:30:00 -07:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PLDHashOperator
|
|
|
|
LoadingDocHashtableTraverser(nsIURI* key,
|
|
|
|
nsIStreamListener* sl,
|
|
|
|
void* userArg)
|
|
|
|
{
|
|
|
|
nsCycleCollectionTraversalCallback *cb =
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsCycleCollectionTraversalCallback*>(userArg);
|
2009-07-02 05:05:32 -07:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*cb, "mLoadingDocTable value");
|
2007-03-22 10:30:00 -07:00
|
|
|
cb->NoteXPCOMChild(sl);
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsBindingManager)
|
|
|
|
// The hashes keyed on nsIContent are traversed from the nsIContent itself.
|
|
|
|
if (tmp->mDocumentTable.IsInitialized())
|
|
|
|
tmp->mDocumentTable.EnumerateRead(&DocumentInfoHashtableTraverser, &cb);
|
|
|
|
if (tmp->mLoadingDocTable.IsInitialized())
|
|
|
|
tmp->mLoadingDocTable.EnumerateRead(&LoadingDocHashtableTraverser, &cb);
|
2007-05-24 07:10:02 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSTARRAY_MEMBER(mAttachedStack,
|
|
|
|
nsXBLBinding)
|
2007-03-22 10:30:00 -07:00
|
|
|
// No need to traverse mProcessAttachedQueueEvent, since it'll just
|
2009-02-03 18:58:21 -08:00
|
|
|
// fire at some point or become revoke and drop its ref to us.
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsBindingManager)
|
|
|
|
|
2007-04-25 09:35:27 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsBindingManager)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIMutationObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsBindingManager)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsBindingManager)
|
|
|
|
|
|
|
|
// Constructors/Destructors
|
2007-10-03 16:38:32 -07:00
|
|
|
nsBindingManager::nsBindingManager(nsIDocument* aDocument)
|
2011-10-17 07:59:28 -07:00
|
|
|
: mProcessingAttachedStack(false),
|
|
|
|
mDestroyed(false),
|
2007-10-31 16:35:51 -07:00
|
|
|
mAttachedStackSizeOnOutermost(0),
|
2007-10-03 16:38:32 -07:00
|
|
|
mDocument(aDocument)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
mContentListTable.ops = nullptr;
|
|
|
|
mAnonymousNodesTable.ops = nullptr;
|
|
|
|
mInsertionParentTable.ops = nullptr;
|
|
|
|
mWrapperTable.ops = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsBindingManager::~nsBindingManager(void)
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
mDestroyed = true;
|
2007-12-04 10:53:53 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mContentListTable.ops)
|
|
|
|
PL_DHashTableFinish(&mContentListTable);
|
|
|
|
if (mAnonymousNodesTable.ops)
|
|
|
|
PL_DHashTableFinish(&mAnonymousNodesTable);
|
2007-10-12 04:07:29 -07:00
|
|
|
NS_ASSERTION(!mInsertionParentTable.ops || !mInsertionParentTable.entryCount,
|
|
|
|
"Insertion parent table isn't empty!");
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mInsertionParentTable.ops)
|
|
|
|
PL_DHashTableFinish(&mInsertionParentTable);
|
|
|
|
if (mWrapperTable.ops)
|
|
|
|
PL_DHashTableFinish(&mWrapperTable);
|
|
|
|
}
|
|
|
|
|
2007-10-12 04:07:29 -07:00
|
|
|
PLDHashOperator
|
2008-10-10 08:04:34 -07:00
|
|
|
RemoveInsertionParentCB(PLDHashTable* aTable, PLDHashEntryHdr* aEntry,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aNumber, void* aArg)
|
2007-10-12 04:07:29 -07:00
|
|
|
{
|
|
|
|
return (static_cast<ObjectEntry*>(aEntry)->GetValue() ==
|
|
|
|
static_cast<nsISupports*>(aArg)) ? PL_DHASH_REMOVE : PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
RemoveInsertionParentForNodeList(nsIDOMNodeList* aList, nsIContent* aParent)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
nsAnonymousContentList* list = nullptr;
|
2008-09-10 20:15:29 -07:00
|
|
|
if (aList) {
|
|
|
|
CallQueryInterface(aList, &list);
|
|
|
|
}
|
2007-10-12 04:07:29 -07:00
|
|
|
if (list) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t count = list->GetInsertionPointCount();
|
|
|
|
for (int32_t i = 0; i < count; ++i) {
|
2007-10-12 04:07:29 -07:00
|
|
|
nsRefPtr<nsXBLInsertionPoint> currPoint = list->GetInsertionPointAt(i);
|
2008-01-28 15:34:28 -08:00
|
|
|
currPoint->UnbindDefaultContent();
|
2007-10-12 04:07:29 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsCOMPtr<nsIContent> parent = currPoint->GetInsertionParent();
|
|
|
|
NS_ASSERTION(!parent || parent == aParent, "Wrong insertion parent!");
|
|
|
|
#endif
|
|
|
|
currPoint->ClearInsertionParent();
|
|
|
|
}
|
2008-09-10 20:15:29 -07:00
|
|
|
NS_RELEASE(list);
|
2007-10-12 04:07:29 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBindingManager::RemoveInsertionParent(nsIContent* aParent)
|
|
|
|
{
|
2010-05-14 10:04:51 -07:00
|
|
|
RemoveInsertionParentForNodeList(GetContentListFor(aParent), aParent);
|
2007-10-12 04:07:29 -07:00
|
|
|
|
2010-05-14 10:04:51 -07:00
|
|
|
RemoveInsertionParentForNodeList(GetAnonymousNodesFor(aParent), aParent);
|
2007-10-12 04:07:29 -07:00
|
|
|
|
|
|
|
if (mInsertionParentTable.ops) {
|
|
|
|
PL_DHashTableEnumerate(&mInsertionParentTable, RemoveInsertionParentCB,
|
|
|
|
static_cast<nsISupports*>(aParent));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXBLBinding*
|
|
|
|
nsBindingManager::GetBinding(nsIContent* aContent)
|
|
|
|
{
|
2007-05-11 11:34:12 -07:00
|
|
|
if (aContent && aContent->HasFlag(NODE_MAY_BE_IN_BINDING_MNGR) &&
|
|
|
|
mBindingTable.IsInitialized()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return mBindingTable.GetWeak(aContent);
|
2007-05-11 11:34:12 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsBindingManager::SetBinding(nsIContent* aContent, nsXBLBinding* aBinding)
|
|
|
|
{
|
|
|
|
if (!mBindingTable.IsInitialized()) {
|
2012-05-18 10:30:49 -07:00
|
|
|
mBindingTable.Init();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// After this point, aBinding will be the most-derived binding for aContent.
|
|
|
|
// If we already have a binding for aContent in our table, make sure to
|
|
|
|
// remove it from the attached stack. Otherwise we might end up firing its
|
|
|
|
// constructor twice (if aBinding inherits from it) or firing its constructor
|
|
|
|
// after aContent has been deleted (if aBinding is null and the content node
|
|
|
|
// dies before we process mAttachedStack).
|
2007-10-12 04:07:29 -07:00
|
|
|
nsRefPtr<nsXBLBinding> oldBinding = GetBinding(aContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (oldBinding) {
|
2007-10-12 04:07:29 -07:00
|
|
|
if (aContent->HasFlag(NODE_IS_INSERTION_PARENT)) {
|
|
|
|
nsRefPtr<nsXBLBinding> parentBinding =
|
|
|
|
GetBinding(aContent->GetBindingParent());
|
|
|
|
// Clear insertion parent only if we don't have a parent binding which
|
|
|
|
// marked content to be an insertion parent. See also ChangeDocumentFor().
|
|
|
|
if (!parentBinding || !parentBinding->HasInsertionParent(aContent)) {
|
|
|
|
RemoveInsertionParent(aContent);
|
|
|
|
aContent->UnsetFlags(NODE_IS_INSERTION_PARENT);
|
|
|
|
}
|
|
|
|
}
|
2007-10-31 16:35:51 -07:00
|
|
|
// Don't remove items here as that could mess up an executing
|
|
|
|
// ProcessAttachedQueue
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t index = mAttachedStack.IndexOf(oldBinding);
|
2007-10-31 16:35:51 -07:00
|
|
|
if (index != mAttachedStack.NoIndex) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mAttachedStack[index] = nullptr;
|
2007-10-31 16:35:51 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aBinding) {
|
2007-05-11 11:34:12 -07:00
|
|
|
aContent->SetFlags(NODE_MAY_BE_IN_BINDING_MNGR);
|
2012-05-18 10:30:49 -07:00
|
|
|
mBindingTable.Put(aContent, aBinding);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
|
|
|
mBindingTable.Remove(aContent);
|
|
|
|
|
|
|
|
// The death of the bindings means the death of the JS wrapper,
|
|
|
|
// and the flushing of our explicit and anonymous insertion point
|
|
|
|
// lists.
|
2012-07-30 07:20:58 -07:00
|
|
|
SetWrappedJS(aContent, nullptr);
|
|
|
|
SetContentListFor(aContent, nullptr);
|
|
|
|
SetAnonymousNodesFor(aContent, nullptr);
|
2011-06-11 13:43:33 -07:00
|
|
|
if (oldBinding) {
|
2012-07-30 07:20:58 -07:00
|
|
|
oldBinding->SetBoundElement(nullptr);
|
2011-06-11 13:43:33 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-05-18 10:30:49 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent*
|
|
|
|
nsBindingManager::GetInsertionParent(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
if (mInsertionParentTable.ops) {
|
2007-07-08 00:08:04 -07:00
|
|
|
return static_cast<nsIContent*>
|
|
|
|
(LookupObject(mInsertionParentTable, aContent));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsBindingManager::SetInsertionParent(nsIContent* aContent, nsIContent* aParent)
|
|
|
|
{
|
2007-10-12 04:07:29 -07:00
|
|
|
NS_ASSERTION(!aParent || aParent->HasFlag(NODE_IS_INSERTION_PARENT),
|
|
|
|
"Insertion parent should have NODE_IS_INSERTION_PARENT flag!");
|
2007-12-04 10:53:53 -08:00
|
|
|
|
|
|
|
if (mDestroyed) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return SetOrRemoveObject(mInsertionParentTable, aContent, aParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIXPConnectWrappedJS*
|
|
|
|
nsBindingManager::GetWrappedJS(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
if (mWrapperTable.ops) {
|
2007-07-08 00:08:04 -07:00
|
|
|
return static_cast<nsIXPConnectWrappedJS*>(LookupObject(mWrapperTable, aContent));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsBindingManager::SetWrappedJS(nsIContent* aContent, nsIXPConnectWrappedJS* aWrappedJS)
|
|
|
|
{
|
2007-12-04 10:53:53 -08:00
|
|
|
if (mDestroyed) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return SetOrRemoveObject(mWrapperTable, aContent, aWrappedJS);
|
|
|
|
}
|
|
|
|
|
2010-06-03 18:09:08 -07:00
|
|
|
void
|
|
|
|
nsBindingManager::RemovedFromDocumentInternal(nsIContent* aContent,
|
2012-06-11 15:22:26 -07:00
|
|
|
nsIDocument* aOldDocument,
|
|
|
|
nsIContent* aContentBindingParent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_PRECONDITION(aOldDocument != nullptr, "no old document");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-19 13:50:20 -07:00
|
|
|
if (mDestroyed)
|
|
|
|
return;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Hold a ref to the binding so it won't die when we remove it from our
|
|
|
|
// table.
|
|
|
|
nsRefPtr<nsXBLBinding> binding = GetBinding(aContent);
|
2007-10-12 04:07:29 -07:00
|
|
|
if (aContent->HasFlag(NODE_IS_INSERTION_PARENT)) {
|
2012-06-11 15:22:26 -07:00
|
|
|
nsRefPtr<nsXBLBinding> parentBinding = GetBinding(aContentBindingParent);
|
2007-10-12 04:07:29 -07:00
|
|
|
if (parentBinding) {
|
|
|
|
parentBinding->RemoveInsertionParent(aContent);
|
|
|
|
// Clear insertion parent only if we don't have a binding which
|
|
|
|
// marked content to be an insertion parent. See also SetBinding().
|
|
|
|
if (!binding || !binding->HasInsertionParent(aContent)) {
|
|
|
|
RemoveInsertionParent(aContent);
|
|
|
|
aContent->UnsetFlags(NODE_IS_INSERTION_PARENT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (binding) {
|
2010-10-22 12:29:21 -07:00
|
|
|
binding->PrototypeBinding()->BindingDetached(binding->GetBoundElement());
|
2012-07-30 07:20:58 -07:00
|
|
|
binding->ChangeDocument(aOldDocument, nullptr);
|
|
|
|
SetBinding(aContent, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Clear out insertion parents and content lists.
|
2012-07-30 07:20:58 -07:00
|
|
|
SetInsertionParent(aContent, nullptr);
|
|
|
|
SetContentListFor(aContent, nullptr);
|
|
|
|
SetAnonymousNodesFor(aContent, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom*
|
2012-08-22 08:56:38 -07:00
|
|
|
nsBindingManager::ResolveTag(nsIContent* aContent, int32_t* aNameSpaceID)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsXBLBinding *binding = GetBinding(aContent);
|
|
|
|
|
|
|
|
if (binding) {
|
|
|
|
nsIAtom* base = binding->GetBaseTag(aNameSpaceID);
|
|
|
|
|
|
|
|
if (base) {
|
|
|
|
return base;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*aNameSpaceID = aContent->GetNameSpaceID();
|
|
|
|
return aContent->Tag();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsBindingManager::GetContentListFor(nsIContent* aContent, nsIDOMNodeList** aResult)
|
2010-02-11 09:34:01 -08:00
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aResult = GetContentListFor(aContent));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsINodeList*
|
|
|
|
nsBindingManager::GetContentListFor(nsIContent* aContent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
nsINodeList* result = nullptr;
|
2010-02-11 09:34:01 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mContentListTable.ops) {
|
2010-02-11 09:34:01 -08:00
|
|
|
result = static_cast<nsAnonymousContentList*>
|
|
|
|
(LookupObject(mContentListTable, aContent));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-02-11 09:34:01 -08:00
|
|
|
|
|
|
|
if (!result) {
|
2012-10-09 05:31:24 -07:00
|
|
|
result = aContent->ChildNodes();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-02-11 09:34:01 -08:00
|
|
|
return result;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsBindingManager::SetContentListFor(nsIContent* aContent,
|
|
|
|
nsInsertionPointList* aList)
|
|
|
|
{
|
2007-12-04 10:53:53 -08:00
|
|
|
if (mDestroyed) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
nsAnonymousContentList* contentList = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aList) {
|
2009-06-15 23:32:10 -07:00
|
|
|
contentList = new nsAnonymousContentList(aContent, aList);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!contentList) {
|
|
|
|
delete aList;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return SetOrRemoveObject(mContentListTable, aContent, contentList);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsBindingManager::HasContentListFor(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
return mContentListTable.ops && LookupObject(mContentListTable, aContent);
|
|
|
|
}
|
|
|
|
|
2009-01-29 11:46:18 -08:00
|
|
|
nsINodeList*
|
2007-03-22 10:30:00 -07:00
|
|
|
nsBindingManager::GetAnonymousNodesInternal(nsIContent* aContent,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* aIsAnonymousContentList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
nsINodeList* result = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mAnonymousNodesTable.ops) {
|
2009-01-29 11:46:18 -08:00
|
|
|
result = static_cast<nsAnonymousContentList*>
|
|
|
|
(LookupObject(mAnonymousNodesTable, aContent));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-01-29 11:46:18 -08:00
|
|
|
if (!result) {
|
2011-10-17 07:59:28 -07:00
|
|
|
*aIsAnonymousContentList = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXBLBinding *binding = GetBinding(aContent);
|
|
|
|
if (binding) {
|
2009-01-29 11:46:18 -08:00
|
|
|
result = binding->GetAnonymousNodes();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
} else
|
2011-10-17 07:59:28 -07:00
|
|
|
*aIsAnonymousContentList = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-01-29 11:46:18 -08:00
|
|
|
return result;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsBindingManager::GetAnonymousNodesFor(nsIContent* aContent,
|
|
|
|
nsIDOMNodeList** aResult)
|
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool dummy;
|
2009-01-29 11:46:18 -08:00
|
|
|
NS_IF_ADDREF(*aResult = GetAnonymousNodesInternal(aContent, &dummy));
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-05-14 10:04:51 -07:00
|
|
|
nsINodeList*
|
|
|
|
nsBindingManager::GetAnonymousNodesFor(nsIContent* aContent)
|
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool dummy;
|
2010-05-14 10:04:51 -07:00
|
|
|
return GetAnonymousNodesInternal(aContent, &dummy);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
|
|
|
nsBindingManager::SetAnonymousNodesFor(nsIContent* aContent,
|
|
|
|
nsInsertionPointList* aList)
|
|
|
|
{
|
2007-12-04 10:53:53 -08:00
|
|
|
if (mDestroyed) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
nsAnonymousContentList* contentList = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aList) {
|
2009-06-15 23:32:10 -07:00
|
|
|
contentList = new nsAnonymousContentList(aContent, aList);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!contentList) {
|
|
|
|
delete aList;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return SetOrRemoveObject(mAnonymousNodesTable, aContent, contentList);
|
|
|
|
}
|
|
|
|
|
2009-01-29 11:46:18 -08:00
|
|
|
nsINodeList*
|
2007-03-22 10:30:00 -07:00
|
|
|
nsBindingManager::GetXBLChildNodesInternal(nsIContent* aContent,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* aIsAnonymousContentList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t length;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Retrieve the anonymous content that we should build.
|
2009-01-29 11:46:18 -08:00
|
|
|
nsINodeList* result = GetAnonymousNodesInternal(aContent,
|
|
|
|
aIsAnonymousContentList);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (result) {
|
|
|
|
result->GetLength(&length);
|
|
|
|
if (length == 0)
|
2012-07-30 07:20:58 -07:00
|
|
|
result = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// We may have an altered list of children from XBL insertion points.
|
|
|
|
// If we don't have any anonymous kids, we next check to see if we have
|
|
|
|
// insertion points.
|
|
|
|
if (!result) {
|
|
|
|
if (mContentListTable.ops) {
|
2009-01-29 11:46:18 -08:00
|
|
|
result = static_cast<nsAnonymousContentList*>
|
2007-07-08 00:08:04 -07:00
|
|
|
(LookupObject(mContentListTable, aContent));
|
2011-10-17 07:59:28 -07:00
|
|
|
*aIsAnonymousContentList = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-29 11:46:18 -08:00
|
|
|
return result;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsBindingManager::GetXBLChildNodesFor(nsIContent* aContent, nsIDOMNodeList** aResult)
|
2009-01-29 11:46:18 -08:00
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aResult = GetXBLChildNodesFor(aContent));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsINodeList*
|
|
|
|
nsBindingManager::GetXBLChildNodesFor(nsIContent* aContent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool dummy;
|
2009-01-29 11:46:18 -08:00
|
|
|
return GetXBLChildNodesInternal(aContent, &dummy);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent*
|
2010-04-16 11:15:28 -07:00
|
|
|
nsBindingManager::GetInsertionPoint(nsIContent* aParent,
|
|
|
|
const nsIContent* aChild,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t* aIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsXBLBinding *binding = GetBinding(aParent);
|
2012-07-30 07:20:58 -07:00
|
|
|
return binding ? binding->GetInsertionPoint(aChild, aIndex) : nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent*
|
|
|
|
nsBindingManager::GetSingleInsertionPoint(nsIContent* aParent,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t* aIndex,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* aMultipleInsertionPoints)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsXBLBinding *binding = GetBinding(aParent);
|
|
|
|
if (binding)
|
|
|
|
return binding->GetSingleInsertionPoint(aIndex, aMultipleInsertionPoints);
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
*aMultipleInsertionPoints = false;
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2007-07-18 14:56:57 -07:00
|
|
|
nsBindingManager::AddLayeredBinding(nsIContent* aContent, nsIURI* aURL,
|
|
|
|
nsIPrincipal* aOriginPrincipal)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// First we need to load our binding.
|
2012-05-23 11:46:04 -07:00
|
|
|
nsXBLService* xblService = nsXBLService::GetInstance();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!xblService)
|
2012-05-23 11:46:04 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Load the bindings.
|
|
|
|
nsRefPtr<nsXBLBinding> binding;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool dummy;
|
2011-10-17 07:59:28 -07:00
|
|
|
xblService->LoadBindings(aContent, aURL, aOriginPrincipal, true,
|
2007-07-18 14:56:57 -07:00
|
|
|
getter_AddRefs(binding), &dummy);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (binding) {
|
|
|
|
AddToAttachedQueue(binding);
|
|
|
|
ProcessAttachedQueue();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsBindingManager::RemoveLayeredBinding(nsIContent* aContent, nsIURI* aURL)
|
|
|
|
{
|
|
|
|
// Hold a ref to the binding so it won't die when we remove it from our table
|
|
|
|
nsRefPtr<nsXBLBinding> binding = GetBinding(aContent);
|
|
|
|
|
|
|
|
if (!binding) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For now we can only handle removing a binding if it's the only one
|
|
|
|
NS_ENSURE_FALSE(binding->GetBaseBinding(), NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
// Make sure that the binding has the URI that is requested to be removed
|
2009-11-03 13:45:10 -08:00
|
|
|
if (!binding->PrototypeBinding()->CompareBindingURI(aURL)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure it isn't a style binding
|
|
|
|
if (binding->IsStyleBinding()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hold strong ref in case removing the binding tries to close the
|
|
|
|
// window or something.
|
|
|
|
// XXXbz should that be ownerdoc? Wouldn't we need a ref to the
|
|
|
|
// currentdoc too? What's the one that should be passed to
|
|
|
|
// ChangeDocument?
|
2011-10-18 03:53:36 -07:00
|
|
|
nsCOMPtr<nsIDocument> doc = aContent->OwnerDoc();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Finally remove the binding...
|
2007-11-15 14:29:08 -08:00
|
|
|
// XXXbz this doesn't remove the implementation! Should fix! Until
|
|
|
|
// then we need the explicit UnhookEventHandlers here.
|
2007-03-22 10:30:00 -07:00
|
|
|
binding->UnhookEventHandlers();
|
2012-07-30 07:20:58 -07:00
|
|
|
binding->ChangeDocument(doc, nullptr);
|
|
|
|
SetBinding(aContent, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
binding->MarkForDeath();
|
|
|
|
|
2009-01-23 01:02:09 -08:00
|
|
|
// ...and recreate its frames. We need to do this since the frames may have
|
2007-03-22 10:30:00 -07:00
|
|
|
// been removed and style may have changed due to the removal of the
|
|
|
|
// anonymous children.
|
|
|
|
// XXXbz this should be using the current doc (if any), not the owner doc.
|
2010-06-25 06:59:57 -07:00
|
|
|
nsIPresShell *presShell = doc->GetShell();
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
return presShell->RecreateFramesFor(aContent);;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsBindingManager::LoadBindingDocument(nsIDocument* aBoundDoc,
|
2007-07-18 14:56:57 -07:00
|
|
|
nsIURI* aURL,
|
|
|
|
nsIPrincipal* aOriginPrincipal)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aURL, "Must have a URI to load!");
|
|
|
|
|
|
|
|
// First we need to load our binding.
|
2012-05-23 11:46:04 -07:00
|
|
|
nsXBLService* xblService = nsXBLService::GetInstance();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!xblService)
|
2012-05-23 11:46:04 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Load the binding doc.
|
2010-07-14 18:53:11 -07:00
|
|
|
nsRefPtr<nsXBLDocumentInfo> info;
|
2012-07-30 07:20:58 -07:00
|
|
|
xblService->LoadBindingDocumentInfo(nullptr, aBoundDoc, aURL,
|
2011-10-17 07:59:28 -07:00
|
|
|
aOriginPrincipal, true,
|
2007-07-18 14:56:57 -07:00
|
|
|
getter_AddRefs(info));
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!info)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsBindingManager::AddToAttachedQueue(nsXBLBinding* aBinding)
|
|
|
|
{
|
|
|
|
if (!mAttachedStack.AppendElement(aBinding))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
// If we're in the middle of processing our queue already, don't
|
|
|
|
// bother posting the event.
|
|
|
|
if (!mProcessingAttachedStack && !mProcessAttachedQueueEvent) {
|
2007-12-04 08:56:44 -08:00
|
|
|
PostProcessAttachedQueueEvent();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-12-14 20:42:15 -08:00
|
|
|
// Make sure that flushes will flush out the new items as needed.
|
|
|
|
mDocument->SetNeedStyleFlush();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
2007-12-04 08:56:44 -08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBindingManager::PostProcessAttachedQueueEvent()
|
|
|
|
{
|
|
|
|
mProcessAttachedQueueEvent =
|
2010-04-20 16:21:35 -07:00
|
|
|
NS_NewRunnableMethod(this, &nsBindingManager::DoProcessAttachedQueue);
|
2007-12-04 08:56:44 -08:00
|
|
|
nsresult rv = NS_DispatchToCurrentThread(mProcessAttachedQueueEvent);
|
|
|
|
if (NS_SUCCEEDED(rv) && mDocument) {
|
|
|
|
mDocument->BlockOnload();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBindingManager::DoProcessAttachedQueue()
|
|
|
|
{
|
2007-12-04 08:56:44 -08:00
|
|
|
if (!mProcessingAttachedStack) {
|
|
|
|
ProcessAttachedQueue();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-12-04 08:56:44 -08:00
|
|
|
NS_ASSERTION(mAttachedStack.Length() == 0,
|
2007-03-22 10:30:00 -07:00
|
|
|
"Shouldn't have pending bindings!");
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
mProcessAttachedQueueEvent = nullptr;
|
2007-12-04 08:56:44 -08:00
|
|
|
} else {
|
|
|
|
// Someone's doing event processing from inside a constructor.
|
|
|
|
// They're evil, but we'll fight back! Just poll on them being
|
|
|
|
// done and repost the attached queue event.
|
|
|
|
PostProcessAttachedQueueEvent();
|
|
|
|
}
|
2007-10-03 16:38:32 -07:00
|
|
|
|
2007-12-04 08:56:44 -08:00
|
|
|
// No matter what, unblock onload for the event that's fired.
|
2007-10-03 16:38:32 -07:00
|
|
|
if (mDocument) {
|
2007-10-29 19:14:52 -07:00
|
|
|
// Hold a strong reference while calling UnblockOnload since that might
|
|
|
|
// run script.
|
|
|
|
nsCOMPtr<nsIDocument> doc = mDocument;
|
2011-10-17 07:59:28 -07:00
|
|
|
doc->UnblockOnload(true);
|
2007-10-03 16:38:32 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsBindingManager::ProcessAttachedQueue(uint32_t aSkipSize)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-10-31 16:35:51 -07:00
|
|
|
if (mProcessingAttachedStack || mAttachedStack.Length() <= aSkipSize)
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mProcessingAttachedStack = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-03-14 16:08:57 -07:00
|
|
|
// Excute constructors. Do this from high index to low
|
2007-10-31 16:35:51 -07:00
|
|
|
while (mAttachedStack.Length() > aSkipSize) {
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t lastItem = mAttachedStack.Length() - 1;
|
2008-03-14 16:08:57 -07:00
|
|
|
nsRefPtr<nsXBLBinding> binding = mAttachedStack.ElementAt(lastItem);
|
|
|
|
mAttachedStack.RemoveElementAt(lastItem);
|
|
|
|
if (binding) {
|
|
|
|
binding->ExecuteAttachedHandler();
|
2007-10-31 16:35:51 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-10-31 16:35:51 -07:00
|
|
|
// If NodeWillBeDestroyed has run we don't want to clobber
|
|
|
|
// mProcessingAttachedStack set there.
|
|
|
|
if (mDocument) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mProcessingAttachedStack = false;
|
2007-10-31 16:35:51 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-10-31 16:35:51 -07:00
|
|
|
NS_ASSERTION(mAttachedStack.Length() == aSkipSize, "How did we get here?");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mAttachedStack.Compact();
|
|
|
|
}
|
|
|
|
|
2007-08-21 14:45:00 -07:00
|
|
|
// Keep bindings and bound elements alive while executing detached handlers.
|
|
|
|
struct BindingTableReadClosure
|
|
|
|
{
|
|
|
|
nsCOMArray<nsIContent> mBoundElements;
|
|
|
|
nsBindingList mBindings;
|
|
|
|
};
|
|
|
|
|
2008-10-10 08:04:34 -07:00
|
|
|
static PLDHashOperator
|
2007-03-22 10:30:00 -07:00
|
|
|
AccumulateBindingsToDetach(nsISupports *aKey, nsXBLBinding *aBinding,
|
2007-08-21 14:45:00 -07:00
|
|
|
void* aClosure)
|
|
|
|
{
|
|
|
|
BindingTableReadClosure* closure =
|
|
|
|
static_cast<BindingTableReadClosure*>(aClosure);
|
|
|
|
if (aBinding && closure->mBindings.AppendElement(aBinding)) {
|
|
|
|
if (!closure->mBoundElements.AppendObject(aBinding->GetBoundElement())) {
|
|
|
|
closure->mBindings.RemoveElementAt(closure->mBindings.Length() - 1);
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBindingManager::ExecuteDetachedHandlers()
|
|
|
|
{
|
|
|
|
// Walk our hashtable of bindings.
|
|
|
|
if (mBindingTable.IsInitialized()) {
|
2007-08-21 14:45:00 -07:00
|
|
|
BindingTableReadClosure closure;
|
|
|
|
mBindingTable.EnumerateRead(AccumulateBindingsToDetach, &closure);
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t i, count = closure.mBindings.Length();
|
2007-08-21 14:45:00 -07:00
|
|
|
for (i = 0; i < count; ++i) {
|
|
|
|
closure.mBindings[i]->ExecuteDetachedHandler();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2010-07-14 18:53:11 -07:00
|
|
|
nsBindingManager::PutXBLDocumentInfo(nsXBLDocumentInfo* aDocumentInfo)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aDocumentInfo, "Must have a non-null documentinfo!");
|
|
|
|
|
2012-05-18 10:30:49 -07:00
|
|
|
if (!mDocumentTable.IsInitialized())
|
|
|
|
mDocumentTable.Init(16);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-05-18 10:30:49 -07:00
|
|
|
mDocumentTable.Put(aDocumentInfo->DocumentURI(),
|
|
|
|
aDocumentInfo);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-07-14 18:53:11 -07:00
|
|
|
nsBindingManager::RemoveXBLDocumentInfo(nsXBLDocumentInfo* aDocumentInfo)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mDocumentTable.IsInitialized()) {
|
|
|
|
mDocumentTable.Remove(aDocumentInfo->DocumentURI());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-14 18:53:11 -07:00
|
|
|
nsXBLDocumentInfo*
|
2007-03-22 10:30:00 -07:00
|
|
|
nsBindingManager::GetXBLDocumentInfo(nsIURI* aURL)
|
|
|
|
{
|
|
|
|
if (!mDocumentTable.IsInitialized())
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return mDocumentTable.GetWeak(aURL);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsBindingManager::PutLoadingDocListener(nsIURI* aURL, nsIStreamListener* aListener)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aListener, "Must have a non-null listener!");
|
|
|
|
|
2012-05-18 10:30:49 -07:00
|
|
|
if (!mLoadingDocTable.IsInitialized())
|
|
|
|
mLoadingDocTable.Init(16);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-05-18 10:30:49 -07:00
|
|
|
mLoadingDocTable.Put(aURL, aListener);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIStreamListener*
|
|
|
|
nsBindingManager::GetLoadingDocListener(nsIURI* aURL)
|
|
|
|
{
|
|
|
|
if (!mLoadingDocTable.IsInitialized())
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return mLoadingDocTable.GetWeak(aURL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBindingManager::RemoveLoadingDocListener(nsIURI* aURL)
|
|
|
|
{
|
|
|
|
if (mLoadingDocTable.IsInitialized()) {
|
|
|
|
mLoadingDocTable.Remove(aURL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-10 08:04:34 -07:00
|
|
|
static PLDHashOperator
|
2007-03-22 10:30:00 -07:00
|
|
|
MarkForDeath(nsISupports *aKey, nsXBLBinding *aBinding, void* aClosure)
|
|
|
|
{
|
|
|
|
if (aBinding->MarkedForDeath())
|
|
|
|
return PL_DHASH_NEXT; // Already marked for death.
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString path;
|
2007-03-22 10:30:00 -07:00
|
|
|
aBinding->PrototypeBinding()->DocURI()->GetPath(path);
|
|
|
|
|
|
|
|
if (!strncmp(path.get(), "/skin", 5))
|
|
|
|
aBinding->MarkForDeath();
|
|
|
|
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBindingManager::FlushSkinBindings()
|
|
|
|
{
|
|
|
|
if (mBindingTable.IsInitialized())
|
2012-07-30 07:20:58 -07:00
|
|
|
mBindingTable.EnumerateRead(MarkForDeath, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Used below to protect from recurring in QI calls through XPConnect.
|
|
|
|
struct AntiRecursionData {
|
|
|
|
nsIContent* element;
|
|
|
|
REFNSIID iid;
|
|
|
|
AntiRecursionData* next;
|
|
|
|
|
|
|
|
AntiRecursionData(nsIContent* aElement,
|
|
|
|
REFNSIID aIID,
|
|
|
|
AntiRecursionData* aNext)
|
|
|
|
: element(aElement), iid(aIID), next(aNext) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsBindingManager::GetBindingImplementation(nsIContent* aContent, REFNSIID aIID,
|
|
|
|
void** aResult)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*aResult = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXBLBinding *binding = GetBinding(aContent);
|
|
|
|
if (binding) {
|
|
|
|
// The binding should not be asked for nsISupports
|
|
|
|
NS_ASSERTION(!aIID.Equals(NS_GET_IID(nsISupports)), "Asking a binding for nsISupports");
|
|
|
|
if (binding->ImplementsInterface(aIID)) {
|
|
|
|
nsCOMPtr<nsIXPConnectWrappedJS> wrappedJS = GetWrappedJS(aContent);
|
|
|
|
|
|
|
|
if (wrappedJS) {
|
|
|
|
// Protect from recurring in QI calls through XPConnect.
|
|
|
|
// This can happen when a second binding is being resolved.
|
|
|
|
// At that point a wrappedJS exists, but it doesn't yet know about
|
|
|
|
// the iid we are asking for. So, without this protection,
|
|
|
|
// AggregatedQueryInterface would end up recurring back into itself
|
|
|
|
// through this code.
|
|
|
|
//
|
|
|
|
// With this protection, when we detect the recursion we return
|
|
|
|
// NS_NOINTERFACE in the inner call. The outer call will then fall
|
|
|
|
// through (see below) and build a new chained wrappedJS for the iid.
|
|
|
|
//
|
|
|
|
// We're careful to not assume that only one direct nesting can occur
|
|
|
|
// because there is a call into JS in the middle and we can't assume
|
|
|
|
// that this code won't be reached by some more complex nesting path.
|
|
|
|
//
|
|
|
|
// NOTE: We *assume* this is single threaded, so we can use a
|
|
|
|
// static linked list to do the check.
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
static AntiRecursionData* list = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
for (AntiRecursionData* p = list; p; p = p->next) {
|
|
|
|
if (p->element == aContent && p->iid.Equals(aIID)) {
|
2012-07-30 07:20:58 -07:00
|
|
|
*aResult = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AntiRecursionData item(aContent, aIID, list);
|
|
|
|
list = &item;
|
|
|
|
|
|
|
|
nsresult rv = wrappedJS->AggregatedQueryInterface(aIID, aResult);
|
|
|
|
|
|
|
|
list = item.next;
|
|
|
|
|
|
|
|
if (*aResult)
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
// No result was found, so this must be another XBL interface.
|
|
|
|
// Fall through to create a new wrapper.
|
|
|
|
}
|
|
|
|
|
|
|
|
// We have never made a wrapper for this implementation.
|
|
|
|
// Create an XPC wrapper for the script object and hand it back.
|
|
|
|
|
2011-10-18 03:53:36 -07:00
|
|
|
nsIDocument* doc = aContent->OwnerDoc();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsIScriptGlobalObject *global = doc->GetScriptGlobalObject();
|
|
|
|
if (!global)
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
|
|
|
|
nsIScriptContext *context = global->GetContext();
|
|
|
|
if (!context)
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
|
2011-09-18 02:22:17 -07:00
|
|
|
JSContext* jscontext = context->GetNativeContext();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!jscontext)
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
|
|
|
|
nsIXPConnect *xpConnect = nsContentUtils::XPConnect();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
|
|
|
|
xpConnect->GetWrappedNativeOfNativeObject(jscontext,
|
|
|
|
global->GetGlobalJSObject(),
|
|
|
|
aContent,
|
|
|
|
NS_GET_IID(nsISupports),
|
|
|
|
getter_AddRefs(wrapper));
|
|
|
|
NS_ENSURE_TRUE(wrapper, NS_NOINTERFACE);
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
JSObject* jsobj = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
wrapper->GetJSObject(&jsobj);
|
|
|
|
NS_ENSURE_TRUE(jsobj, NS_NOINTERFACE);
|
|
|
|
|
|
|
|
nsresult rv = xpConnect->WrapJSAggregatedToNative(aContent, jscontext,
|
|
|
|
jsobj, aIID, aResult);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
// We successfully created a wrapper. We will own this wrapper for as long as the binding remains
|
|
|
|
// alive. At the time the binding is cleared out of the bindingManager, we will remove the wrapper
|
|
|
|
// from the bindingManager as well.
|
2007-07-08 00:08:04 -07:00
|
|
|
nsISupports* supp = static_cast<nsISupports*>(*aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
wrappedJS = do_QueryInterface(supp);
|
|
|
|
SetWrappedJS(aContent, wrappedJS);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
*aResult = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2008-07-26 09:14:49 -07:00
|
|
|
nsBindingManager::WalkRules(nsIStyleRuleProcessor::EnumFunc aFunc,
|
2007-03-22 10:30:00 -07:00
|
|
|
RuleProcessorData* aData,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* aCutOffInheritance)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
*aCutOffInheritance = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-04-30 06:12:06 -07:00
|
|
|
NS_ASSERTION(aData->mElement, "How did that happen?");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Walk the binding scope chain, starting with the binding attached to our
|
|
|
|
// content, up till we run out of scopes or we get cut off.
|
2010-04-30 06:12:06 -07:00
|
|
|
nsIContent *content = aData->mElement;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
do {
|
|
|
|
nsXBLBinding *binding = GetBinding(content);
|
|
|
|
if (binding) {
|
2011-03-29 10:29:21 -07:00
|
|
|
aData->mTreeMatchContext.mScopedRoot = content;
|
2007-03-22 10:30:00 -07:00
|
|
|
binding->WalkRules(aFunc, aData);
|
|
|
|
// If we're not looking at our original content, allow the binding to cut
|
|
|
|
// off style inheritance
|
2010-04-30 06:12:06 -07:00
|
|
|
if (content != aData->mElement) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!binding->InheritsStyle()) {
|
|
|
|
// Go no further; we're not inheriting style from anything above here
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-22 21:50:20 -07:00
|
|
|
if (content->IsRootOfNativeAnonymousSubtree()) {
|
|
|
|
break; // Deliberately cut off style inheritance here.
|
2007-05-04 23:47:09 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-07-22 21:50:20 -07:00
|
|
|
content = content->GetBindingParent();
|
2007-03-22 10:30:00 -07:00
|
|
|
} while (content);
|
|
|
|
|
|
|
|
// If "content" is non-null that means we cut off inheritance at some point
|
|
|
|
// in the loop.
|
2012-07-30 07:20:58 -07:00
|
|
|
*aCutOffInheritance = (content != nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Null out the scoped root that we set repeatedly
|
2012-07-30 07:20:58 -07:00
|
|
|
aData->mTreeMatchContext.mScopedRoot = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-21 11:07:31 -07:00
|
|
|
typedef nsTHashtable<nsPtrHashKey<nsIStyleRuleProcessor> > RuleProcessorSet;
|
2008-07-26 09:14:49 -07:00
|
|
|
|
2008-10-10 08:04:34 -07:00
|
|
|
static PLDHashOperator
|
2008-07-26 09:14:49 -07:00
|
|
|
EnumRuleProcessors(nsISupports *aKey, nsXBLBinding *aBinding, void* aClosure)
|
|
|
|
{
|
|
|
|
RuleProcessorSet *set = static_cast<RuleProcessorSet*>(aClosure);
|
|
|
|
for (nsXBLBinding *binding = aBinding; binding;
|
|
|
|
binding = binding->GetBaseBinding()) {
|
|
|
|
nsIStyleRuleProcessor *ruleProc =
|
|
|
|
binding->PrototypeBinding()->GetRuleProcessor();
|
|
|
|
if (ruleProc) {
|
2012-05-18 10:30:49 -07:00
|
|
|
if (!set->IsInitialized()) {
|
|
|
|
set->Init(16);
|
|
|
|
}
|
2008-07-26 09:14:49 -07:00
|
|
|
set->PutEntry(ruleProc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
2010-03-25 02:22:58 -07:00
|
|
|
struct WalkAllRulesData {
|
|
|
|
nsIStyleRuleProcessor::EnumFunc mFunc;
|
|
|
|
RuleProcessorData* mData;
|
|
|
|
};
|
|
|
|
|
|
|
|
static PLDHashOperator
|
2012-03-21 11:07:31 -07:00
|
|
|
EnumWalkAllRules(nsPtrHashKey<nsIStyleRuleProcessor> *aKey, void* aClosure)
|
2010-03-25 02:22:58 -07:00
|
|
|
{
|
2012-03-21 11:07:31 -07:00
|
|
|
nsIStyleRuleProcessor *ruleProcessor = aKey->GetKey();
|
|
|
|
|
2010-03-25 02:22:58 -07:00
|
|
|
WalkAllRulesData *data = static_cast<WalkAllRulesData*>(aClosure);
|
|
|
|
|
|
|
|
(*(data->mFunc))(ruleProcessor, data->mData);
|
|
|
|
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBindingManager::WalkAllRules(nsIStyleRuleProcessor::EnumFunc aFunc,
|
|
|
|
RuleProcessorData* aData)
|
|
|
|
{
|
|
|
|
if (!mBindingTable.IsInitialized())
|
|
|
|
return;
|
|
|
|
|
|
|
|
RuleProcessorSet set;
|
|
|
|
mBindingTable.EnumerateRead(EnumRuleProcessors, &set);
|
|
|
|
if (!set.IsInitialized())
|
|
|
|
return;
|
|
|
|
|
|
|
|
WalkAllRulesData data = { aFunc, aData };
|
|
|
|
set.EnumerateEntries(EnumWalkAllRules, &data);
|
|
|
|
}
|
|
|
|
|
2008-07-26 09:14:49 -07:00
|
|
|
struct MediumFeaturesChangedData {
|
|
|
|
nsPresContext *mPresContext;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool *mRulesChanged;
|
2008-07-26 09:14:49 -07:00
|
|
|
};
|
|
|
|
|
2008-10-10 08:04:34 -07:00
|
|
|
static PLDHashOperator
|
2012-03-21 11:07:31 -07:00
|
|
|
EnumMediumFeaturesChanged(nsPtrHashKey<nsIStyleRuleProcessor> *aKey, void* aClosure)
|
2008-07-26 09:14:49 -07:00
|
|
|
{
|
2012-03-21 11:07:31 -07:00
|
|
|
nsIStyleRuleProcessor *ruleProcessor = aKey->GetKey();
|
|
|
|
|
2008-07-26 09:14:49 -07:00
|
|
|
MediumFeaturesChangedData *data =
|
|
|
|
static_cast<MediumFeaturesChangedData*>(aClosure);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool thisChanged = ruleProcessor->MediumFeaturesChanged(data->mPresContext);
|
2008-07-26 09:14:49 -07:00
|
|
|
*data->mRulesChanged = *data->mRulesChanged || thisChanged;
|
|
|
|
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsBindingManager::MediumFeaturesChanged(nsPresContext* aPresContext,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* aRulesChanged)
|
2008-07-26 09:14:49 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
*aRulesChanged = false;
|
2008-07-26 09:14:49 -07:00
|
|
|
if (!mBindingTable.IsInitialized())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
RuleProcessorSet set;
|
|
|
|
mBindingTable.EnumerateRead(EnumRuleProcessors, &set);
|
|
|
|
if (!set.IsInitialized())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
MediumFeaturesChangedData data = { aPresContext, aRulesChanged };
|
|
|
|
set.EnumerateEntries(EnumMediumFeaturesChanged, &data);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-07-16 22:36:34 -07:00
|
|
|
static PLDHashOperator
|
|
|
|
EnumAppendAllSheets(nsISupports *aKey, nsXBLBinding *aBinding, void* aClosure)
|
|
|
|
{
|
|
|
|
nsTArray<nsCSSStyleSheet*>* array =
|
|
|
|
static_cast<nsTArray<nsCSSStyleSheet*>*>(aClosure);
|
|
|
|
for (nsXBLBinding *binding = aBinding; binding;
|
|
|
|
binding = binding->GetBaseBinding()) {
|
|
|
|
nsXBLPrototypeResources::sheet_array_type* sheets =
|
|
|
|
binding->PrototypeBinding()->GetStyleSheets();
|
|
|
|
if (sheets) {
|
|
|
|
// Copy from nsTArray<nsRefPtr<nsCSSStyleSheet> > to
|
|
|
|
// nsTArray<nsCSSStyleSheet*>.
|
|
|
|
array->AppendElements(*sheets);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBindingManager::AppendAllSheets(nsTArray<nsCSSStyleSheet*>& aArray)
|
|
|
|
{
|
|
|
|
if (!mBindingTable.IsInitialized())
|
|
|
|
return;
|
|
|
|
|
|
|
|
mBindingTable.EnumerateRead(EnumAppendAllSheets, &aArray);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIContent*
|
2010-04-16 11:15:28 -07:00
|
|
|
nsBindingManager::GetNestedInsertionPoint(nsIContent* aParent,
|
|
|
|
const nsIContent* aChild)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Check to see if the content is anonymous.
|
|
|
|
if (aChild->GetBindingParent() == aParent)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr; // It is anonymous. Don't use the insertion point, since that's only
|
2007-03-22 10:30:00 -07:00
|
|
|
// for the explicit kids.
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t index;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIContent *insertionElement = GetInsertionPoint(aParent, aChild, &index);
|
2007-11-19 20:18:59 -08:00
|
|
|
if (insertionElement && insertionElement != aParent) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// See if we nest even further in.
|
|
|
|
nsIContent* nestedPoint = GetNestedInsertionPoint(insertionElement, aChild);
|
|
|
|
if (nestedPoint)
|
|
|
|
insertionElement = nestedPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
return insertionElement;
|
|
|
|
}
|
|
|
|
|
2007-11-19 20:18:59 -08:00
|
|
|
nsIContent*
|
|
|
|
nsBindingManager::GetNestedSingleInsertionPoint(nsIContent* aParent,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* aMultipleInsertionPoints)
|
2007-11-19 20:18:59 -08:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
*aMultipleInsertionPoints = false;
|
2007-11-19 20:18:59 -08:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t index;
|
2007-11-19 20:18:59 -08:00
|
|
|
nsIContent *insertionElement =
|
|
|
|
GetSingleInsertionPoint(aParent, &index, aMultipleInsertionPoints);
|
|
|
|
if (*aMultipleInsertionPoints) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-11-19 20:18:59 -08:00
|
|
|
}
|
|
|
|
if (insertionElement && insertionElement != aParent) {
|
|
|
|
// See if we nest even further in.
|
|
|
|
nsIContent* nestedPoint =
|
|
|
|
GetNestedSingleInsertionPoint(insertionElement,
|
|
|
|
aMultipleInsertionPoints);
|
|
|
|
if (nestedPoint)
|
|
|
|
insertionElement = nestedPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
return insertionElement;
|
|
|
|
}
|
|
|
|
|
2009-04-08 11:37:15 -07:00
|
|
|
nsXBLInsertionPoint*
|
|
|
|
nsBindingManager::FindInsertionPointAndIndex(nsIContent* aContainer,
|
|
|
|
nsIContent* aInsertionParent,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aIndexInContainer,
|
|
|
|
int32_t aAppend,
|
|
|
|
int32_t* aInsertionIndex)
|
2009-04-08 11:37:15 -07:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isAnonymousContentList;
|
2009-04-08 11:37:15 -07:00
|
|
|
nsINodeList* nodeList =
|
|
|
|
GetXBLChildNodesInternal(aInsertionParent, &isAnonymousContentList);
|
|
|
|
if (!nodeList || !isAnonymousContentList) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2009-04-08 11:37:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Find a non-pseudo-insertion point and just jam ourselves in. This is
|
|
|
|
// not 100% correct, since there might be multiple insertion points under
|
|
|
|
// this insertion parent, and we should really be using the one that
|
|
|
|
// matches our content... Hack city, baby.
|
|
|
|
nsAnonymousContentList* contentList =
|
|
|
|
static_cast<nsAnonymousContentList*>(nodeList);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t count = contentList->GetInsertionPointCount();
|
|
|
|
for (int32_t i = 0; i < count; i++) {
|
2009-04-08 11:37:15 -07:00
|
|
|
nsXBLInsertionPoint* point = contentList->GetInsertionPointAt(i);
|
|
|
|
if (point->GetInsertionIndex() != -1) {
|
|
|
|
// We're real. Jam the kid in.
|
|
|
|
|
|
|
|
// Find the right insertion spot. Can't just insert in the insertion
|
|
|
|
// point at aIndexInContainer since the point may contain anonymous
|
|
|
|
// content, not all of aContainer's kids, etc. So find the last
|
|
|
|
// child of aContainer that comes before aIndexInContainer and is in
|
|
|
|
// the insertion point and insert right after it.
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t pointSize = point->ChildCount();
|
|
|
|
for (int32_t parentIndex = aIndexInContainer - 1; parentIndex >= 0;
|
2009-04-08 11:37:15 -07:00
|
|
|
--parentIndex) {
|
|
|
|
nsIContent* currentSibling = aContainer->GetChildAt(parentIndex);
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t pointIndex = pointSize - 1; pointIndex >= 0;
|
2009-04-08 11:37:15 -07:00
|
|
|
--pointIndex) {
|
|
|
|
if (point->ChildAt(pointIndex) == currentSibling) {
|
|
|
|
*aInsertionIndex = pointIndex + 1;
|
|
|
|
return point;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// None of our previous siblings are in here... just stick
|
|
|
|
// ourselves in at the end of the insertion point if we're
|
|
|
|
// appending, and at the beginning otherwise.
|
|
|
|
// XXXbz if we ever start doing the filter thing right, this may be no
|
|
|
|
// good, since we may _still_ have anonymous kids in there and may need
|
|
|
|
// to get the ordering with those right. In fact, this is even wrong
|
|
|
|
// without the filter thing for nested insertion points, since they might
|
|
|
|
// contain anonymous content that needs to come after all explicit
|
|
|
|
// kids... but we have no way to know that here easily.
|
|
|
|
if (aAppend) {
|
|
|
|
*aInsertionIndex = pointSize;
|
|
|
|
} else {
|
|
|
|
*aInsertionIndex = 0;
|
|
|
|
}
|
|
|
|
return point;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2009-04-08 11:37:15 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsBindingManager::ContentAppended(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
2010-05-10 18:12:34 -07:00
|
|
|
nsIContent* aFirstNewContent,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aNewIndexInContainer)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-04-26 21:06:45 -07:00
|
|
|
if (aNewIndexInContainer != -1 &&
|
|
|
|
(mContentListTable.ops || mAnonymousNodesTable.ops)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// It's not anonymous.
|
2009-04-08 11:37:15 -07:00
|
|
|
NS_ASSERTION(aNewIndexInContainer >= 0, "Bogus index");
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool multiple;
|
2007-11-19 20:18:59 -08:00
|
|
|
nsIContent* ins = GetNestedSingleInsertionPoint(aContainer, &multiple);
|
2007-11-15 09:17:46 -08:00
|
|
|
|
|
|
|
if (multiple) {
|
|
|
|
// Do each kid individually
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t childCount = aContainer->GetChildCount();
|
|
|
|
for (int32_t idx = aNewIndexInContainer; idx < childCount; ++idx) {
|
2007-11-15 09:17:46 -08:00
|
|
|
HandleChildInsertion(aContainer, aContainer->GetChildAt(idx),
|
2011-10-17 07:59:28 -07:00
|
|
|
idx, true);
|
2007-11-15 09:17:46 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ins) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t insertionIndex;
|
2009-04-08 11:37:15 -07:00
|
|
|
nsXBLInsertionPoint* point =
|
|
|
|
FindInsertionPointAndIndex(aContainer, ins, aNewIndexInContainer,
|
2011-10-17 07:59:28 -07:00
|
|
|
true, &insertionIndex);
|
2009-04-08 11:37:15 -07:00
|
|
|
if (point) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t childCount = aContainer->GetChildCount();
|
|
|
|
for (int32_t j = aNewIndexInContainer; j < childCount;
|
2009-04-08 11:37:15 -07:00
|
|
|
j++, insertionIndex++) {
|
|
|
|
nsIContent* child = aContainer->GetChildAt(j);
|
|
|
|
point->InsertChildAt(insertionIndex, child);
|
|
|
|
SetInsertionParent(child, ins);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBindingManager::ContentInserted(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aIndexInContainer)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-04-26 21:06:45 -07:00
|
|
|
if (aIndexInContainer != -1 &&
|
|
|
|
(mContentListTable.ops || mAnonymousNodesTable.ops)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// It's not anonymous.
|
2007-11-15 09:17:46 -08:00
|
|
|
NS_ASSERTION(aIndexInContainer >= 0, "Bogus index");
|
2011-10-17 07:59:28 -07:00
|
|
|
HandleChildInsertion(aContainer, aChild, aIndexInContainer, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-27 21:31:20 -08:00
|
|
|
static void
|
|
|
|
RemoveChildFromInsertionPoint(nsAnonymousContentList* aInsertionPointList,
|
|
|
|
nsIContent* aChild,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aRemoveFromPseudoPoints)
|
2008-01-27 21:31:20 -08:00
|
|
|
{
|
|
|
|
// We need to find the insertion point that contains aChild and remove it
|
|
|
|
// from that insertion point. Sadly, we don't know which point it is, or
|
|
|
|
// when we've hit it, but just trying to remove from all the pseudo or
|
|
|
|
// non-pseudo insertion points, depending on the value of
|
|
|
|
// aRemoveFromPseudoPoints, should work.
|
2010-01-13 08:30:11 -08:00
|
|
|
|
|
|
|
// XXXbz nsXBLInsertionPoint::RemoveChild could return whether it
|
|
|
|
// removed something. Wouldn't that let us short-circuit the walk?
|
|
|
|
// Or can a child be in multiple insertion points? I wouldn't think
|
|
|
|
// so...
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t count = aInsertionPointList->GetInsertionPointCount();
|
|
|
|
for (int32_t i = 0; i < count; i++) {
|
2008-01-27 21:31:20 -08:00
|
|
|
nsXBLInsertionPoint* point =
|
|
|
|
aInsertionPointList->GetInsertionPointAt(i);
|
|
|
|
if ((point->GetInsertionIndex() == -1) == aRemoveFromPseudoPoints) {
|
|
|
|
point->RemoveChild(aChild);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsBindingManager::ContentRemoved(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aIndexInContainer,
|
2010-07-21 15:05:17 -07:00
|
|
|
nsIContent* aPreviousSibling)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-01-27 21:31:20 -08:00
|
|
|
if (aContainer && aIndexInContainer != -1 &&
|
2007-06-26 21:51:37 -07:00
|
|
|
(mContentListTable.ops || mAnonymousNodesTable.ops)) {
|
|
|
|
// It's not anonymous
|
|
|
|
nsCOMPtr<nsIContent> point = GetNestedInsertionPoint(aContainer, aChild);
|
|
|
|
|
|
|
|
if (point) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isAnonymousContentList;
|
2009-01-29 11:46:18 -08:00
|
|
|
nsCOMPtr<nsIDOMNodeList> nodeList =
|
|
|
|
GetXBLChildNodesInternal(point, &isAnonymousContentList);
|
2007-06-26 21:51:37 -07:00
|
|
|
|
|
|
|
if (nodeList && isAnonymousContentList) {
|
|
|
|
// Find a non-pseudo-insertion point and remove ourselves.
|
2008-01-27 21:31:20 -08:00
|
|
|
RemoveChildFromInsertionPoint(static_cast<nsAnonymousContentList*>
|
|
|
|
(static_cast<nsIDOMNodeList*>
|
|
|
|
(nodeList)),
|
|
|
|
aChild,
|
2011-10-17 07:59:28 -07:00
|
|
|
false);
|
2012-07-30 07:20:58 -07:00
|
|
|
SetInsertionParent(aChild, nullptr);
|
2007-06-26 21:51:37 -07:00
|
|
|
}
|
2010-01-13 08:30:11 -08:00
|
|
|
|
|
|
|
// Also remove from the list in mContentListTable, if any.
|
|
|
|
if (mContentListTable.ops) {
|
|
|
|
nsCOMPtr<nsIDOMNodeList> otherNodeList =
|
|
|
|
static_cast<nsAnonymousContentList*>
|
|
|
|
(LookupObject(mContentListTable, point));
|
|
|
|
if (otherNodeList && otherNodeList != nodeList) {
|
|
|
|
// otherNodeList is always anonymous
|
|
|
|
RemoveChildFromInsertionPoint(static_cast<nsAnonymousContentList*>
|
|
|
|
(static_cast<nsIDOMNodeList*>
|
|
|
|
(otherNodeList)),
|
|
|
|
aChild,
|
2011-10-17 07:59:28 -07:00
|
|
|
false);
|
2010-01-13 08:30:11 -08:00
|
|
|
}
|
|
|
|
}
|
2008-01-27 21:31:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Whether the child has a nested insertion point or not, aContainer might
|
|
|
|
// have insertion points under it. If that's the case, we need to remove
|
|
|
|
// aChild from the pseudo insertion point it's in.
|
|
|
|
if (mContentListTable.ops) {
|
|
|
|
nsAnonymousContentList* insertionPointList =
|
2009-01-29 11:46:18 -08:00
|
|
|
static_cast<nsAnonymousContentList*>(LookupObject(mContentListTable,
|
|
|
|
aContainer));
|
2008-01-27 21:31:20 -08:00
|
|
|
if (insertionPointList) {
|
2011-10-17 07:59:28 -07:00
|
|
|
RemoveChildFromInsertionPoint(insertionPointList, aChild, true);
|
2008-01-27 21:31:20 -08:00
|
|
|
}
|
|
|
|
}
|
2007-06-26 21:51:37 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-12-04 10:37:54 -08:00
|
|
|
nsBindingManager::DropDocumentReference()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
mDestroyed = true;
|
2010-07-19 13:50:20 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Make sure to not run any more XBL constructors
|
2011-10-17 07:59:28 -07:00
|
|
|
mProcessingAttachedStack = true;
|
2009-02-03 18:58:21 -08:00
|
|
|
if (mProcessAttachedQueueEvent) {
|
|
|
|
mProcessAttachedQueueEvent->Revoke();
|
|
|
|
}
|
2009-07-02 05:05:32 -07:00
|
|
|
|
|
|
|
if (mContentListTable.ops)
|
|
|
|
PL_DHashTableFinish(&(mContentListTable));
|
2012-07-30 07:20:58 -07:00
|
|
|
mContentListTable.ops = nullptr;
|
2009-07-02 05:05:32 -07:00
|
|
|
|
|
|
|
if (mAnonymousNodesTable.ops)
|
|
|
|
PL_DHashTableFinish(&(mAnonymousNodesTable));
|
2012-07-30 07:20:58 -07:00
|
|
|
mAnonymousNodesTable.ops = nullptr;
|
2009-07-02 05:05:32 -07:00
|
|
|
|
|
|
|
if (mInsertionParentTable.ops)
|
|
|
|
PL_DHashTableFinish(&(mInsertionParentTable));
|
2012-07-30 07:20:58 -07:00
|
|
|
mInsertionParentTable.ops = nullptr;
|
2009-07-02 05:05:32 -07:00
|
|
|
|
2010-07-19 13:50:20 -07:00
|
|
|
if (mBindingTable.IsInitialized())
|
|
|
|
mBindingTable.Clear();
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
mDocument = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBindingManager::Traverse(nsIContent *aContent,
|
|
|
|
nsCycleCollectionTraversalCallback &cb)
|
|
|
|
{
|
2007-05-11 11:34:12 -07:00
|
|
|
if (!aContent->HasFlag(NODE_MAY_BE_IN_BINDING_MNGR)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-03-28 07:09:00 -07:00
|
|
|
nsISupports *value;
|
|
|
|
if (mInsertionParentTable.ops &&
|
|
|
|
(value = LookupObject(mInsertionParentTable, aContent))) {
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "[via binding manager] mInsertionParentTable key");
|
|
|
|
cb.NoteXPCOMChild(aContent);
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "[via binding manager] mInsertionParentTable value");
|
|
|
|
cb.NoteXPCOMChild(value);
|
|
|
|
}
|
|
|
|
|
2010-04-30 06:12:06 -07:00
|
|
|
// XXXbz how exactly would NODE_MAY_BE_IN_BINDING_MNGR end up on non-elements?
|
|
|
|
if (!aContent->IsElement()) {
|
2008-03-28 07:09:00 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXBLBinding *binding = GetBinding(aContent);
|
|
|
|
if (binding) {
|
2008-03-17 16:11:08 -07:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "[via binding manager] mBindingTable key");
|
2007-03-22 10:30:00 -07:00
|
|
|
cb.NoteXPCOMChild(aContent);
|
2008-03-17 16:11:08 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_PTR(binding, nsXBLBinding,
|
|
|
|
"[via binding manager] mBindingTable value")
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (mContentListTable.ops &&
|
|
|
|
(value = LookupObject(mContentListTable, aContent))) {
|
2008-03-17 16:11:08 -07:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "[via binding manager] mContentListTable key");
|
2007-03-22 10:30:00 -07:00
|
|
|
cb.NoteXPCOMChild(aContent);
|
2008-03-17 16:11:08 -07:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "[via binding manager] mContentListTable value");
|
2007-03-22 10:30:00 -07:00
|
|
|
cb.NoteXPCOMChild(value);
|
|
|
|
}
|
|
|
|
if (mAnonymousNodesTable.ops &&
|
|
|
|
(value = LookupObject(mAnonymousNodesTable, aContent))) {
|
2008-03-17 16:11:08 -07:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "[via binding manager] mAnonymousNodesTable key");
|
2007-03-22 10:30:00 -07:00
|
|
|
cb.NoteXPCOMChild(aContent);
|
2008-03-17 16:11:08 -07:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "[via binding manager] mAnonymousNodesTable value");
|
2007-03-22 10:30:00 -07:00
|
|
|
cb.NoteXPCOMChild(value);
|
|
|
|
}
|
|
|
|
if (mWrapperTable.ops &&
|
|
|
|
(value = LookupObject(mWrapperTable, aContent))) {
|
2008-03-17 16:11:08 -07:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "[via binding manager] mWrapperTable key");
|
2007-03-22 10:30:00 -07:00
|
|
|
cb.NoteXPCOMChild(aContent);
|
2008-03-17 16:11:08 -07:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "[via binding manager] mWrapperTable value");
|
2007-03-22 10:30:00 -07:00
|
|
|
cb.NoteXPCOMChild(value);
|
|
|
|
}
|
|
|
|
}
|
2007-05-30 18:36:06 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
nsBindingManager::BeginOutermostUpdate()
|
|
|
|
{
|
2007-10-31 16:35:51 -07:00
|
|
|
mAttachedStackSizeOnOutermost = mAttachedStack.Length();
|
2007-05-30 18:36:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBindingManager::EndOutermostUpdate()
|
|
|
|
{
|
2007-10-31 16:35:51 -07:00
|
|
|
if (!mProcessingAttachedStack) {
|
|
|
|
ProcessAttachedQueue(mAttachedStackSizeOnOutermost);
|
|
|
|
mAttachedStackSizeOnOutermost = 0;
|
|
|
|
}
|
2007-05-30 18:36:06 -07:00
|
|
|
}
|
2007-11-15 09:17:46 -08:00
|
|
|
|
|
|
|
void
|
|
|
|
nsBindingManager::HandleChildInsertion(nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aIndexInContainer,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aAppend)
|
2007-11-15 09:17:46 -08:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aChild, "Must have child");
|
|
|
|
NS_PRECONDITION(!aContainer ||
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t(aContainer->IndexOf(aChild)) == aIndexInContainer,
|
2007-11-15 09:17:46 -08:00
|
|
|
"Child not at the right index?");
|
|
|
|
|
|
|
|
nsIContent* ins = GetNestedInsertionPoint(aContainer, aChild);
|
|
|
|
|
|
|
|
if (ins) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t insertionIndex;
|
2009-04-08 11:37:15 -07:00
|
|
|
nsXBLInsertionPoint* point =
|
|
|
|
FindInsertionPointAndIndex(aContainer, ins, aIndexInContainer, aAppend,
|
|
|
|
&insertionIndex);
|
|
|
|
if (point) {
|
|
|
|
point->InsertChildAt(insertionIndex, aChild);
|
|
|
|
SetInsertionParent(aChild, ins);
|
2007-11-15 09:17:46 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|