2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
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
|
|
|
|
2013-12-08 18:52:54 -08:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2011-10-10 22:50:08 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsIInputStream.h"
|
|
|
|
#include "nsINameSpaceManager.h"
|
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsIURL.h"
|
|
|
|
#include "nsIChannel.h"
|
|
|
|
#include "nsXPIDLString.h"
|
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "plstr.h"
|
|
|
|
#include "nsContentCreatorFunctions.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIXMLContentSink.h"
|
|
|
|
#include "nsContentCID.h"
|
2013-03-20 09:22:26 -07:00
|
|
|
#include "mozilla/dom/XMLDocument.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsXBLService.h"
|
|
|
|
#include "nsXBLBinding.h"
|
|
|
|
#include "nsXBLPrototypeBinding.h"
|
2011-11-03 13:39:08 -07:00
|
|
|
#include "nsXBLContentSink.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "xptinfo.h"
|
|
|
|
#include "nsIInterfaceInfoManager.h"
|
|
|
|
#include "nsIDocumentObserver.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsXBLProtoImpl.h"
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsContentUtils.h"
|
2012-07-01 16:45:59 -07:00
|
|
|
#include "nsTextFragment.h"
|
2013-04-04 05:01:08 -07:00
|
|
|
#include "nsTextNode.h"
|
2013-09-23 10:29:27 -07:00
|
|
|
#include "nsIInterfaceInfo.h"
|
2011-11-03 13:39:07 -07:00
|
|
|
#include "nsIScriptError.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsIStyleRuleProcessor.h"
|
|
|
|
#include "nsXBLResourceLoader.h"
|
2013-04-04 05:01:11 -07:00
|
|
|
#include "mozilla/dom/CDATASection.h"
|
2013-04-04 05:02:22 -07:00
|
|
|
#include "mozilla/dom/Comment.h"
|
2011-07-20 12:18:54 -07:00
|
|
|
#include "mozilla/dom/Element.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-11-03 13:39:08 -07:00
|
|
|
#ifdef MOZ_XUL
|
|
|
|
#include "nsXULElement.h"
|
|
|
|
#endif
|
|
|
|
|
2011-11-15 23:50:19 -08:00
|
|
|
using namespace mozilla;
|
2011-11-03 13:39:08 -07:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Helper Classes =====================================================================
|
|
|
|
|
|
|
|
// nsXBLAttributeEntry and helpers. This class is used to efficiently handle
|
|
|
|
// attribute changes in anonymous content.
|
|
|
|
|
|
|
|
class nsXBLAttributeEntry {
|
|
|
|
public:
|
2013-03-05 05:12:16 -08:00
|
|
|
nsXBLAttributeEntry(nsIAtom* aSrcAtom, nsIAtom* aDstAtom,
|
|
|
|
int32_t aDstNameSpace, nsIContent* aContent)
|
|
|
|
: mElement(aContent),
|
|
|
|
mSrcAttribute(aSrcAtom),
|
|
|
|
mDstAttribute(aDstAtom),
|
|
|
|
mDstNameSpace(aDstNameSpace),
|
|
|
|
mNext(nullptr) { }
|
|
|
|
|
|
|
|
~nsXBLAttributeEntry() {
|
|
|
|
NS_CONTENT_DELETE_LIST_MEMBER(nsXBLAttributeEntry, this, mNext);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom* GetSrcAttribute() { return mSrcAttribute; }
|
|
|
|
nsIAtom* GetDstAttribute() { return mDstAttribute; }
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t GetDstNameSpace() { return mDstNameSpace; }
|
2013-03-05 05:12:16 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIContent* GetElement() { return mElement; }
|
|
|
|
|
|
|
|
nsXBLAttributeEntry* GetNext() { return mNext; }
|
|
|
|
void SetNext(nsXBLAttributeEntry* aEntry) { mNext = aEntry; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsIContent* mElement;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> mSrcAttribute;
|
|
|
|
nsCOMPtr<nsIAtom> mDstAttribute;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mDstNameSpace;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXBLAttributeEntry* mNext;
|
|
|
|
};
|
|
|
|
|
|
|
|
// =============================================================================
|
|
|
|
|
|
|
|
// Implementation /////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// Constructors/Destructors
|
|
|
|
nsXBLPrototypeBinding::nsXBLPrototypeBinding()
|
2012-07-30 07:20:58 -07:00
|
|
|
: mImplementation(nullptr),
|
|
|
|
mBaseBinding(nullptr),
|
2013-03-05 05:12:16 -08:00
|
|
|
mInheritStyle(true),
|
2011-11-03 13:39:07 -07:00
|
|
|
mCheckedBaseProto(false),
|
2011-10-17 07:59:28 -07:00
|
|
|
mKeyHandlersRegistered(false),
|
2012-10-10 12:04:42 -07:00
|
|
|
mChromeOnlyContent(false),
|
2012-07-30 07:20:58 -07:00
|
|
|
mResources(nullptr),
|
|
|
|
mAttributeTable(nullptr),
|
2011-11-03 13:39:08 -07:00
|
|
|
mBaseNameSpaceID(kNameSpaceID_None)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsXBLPrototypeBinding);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXBLPrototypeBinding::Init(const nsACString& aID,
|
2010-07-14 18:53:11 -07:00
|
|
|
nsXBLDocumentInfo* aInfo,
|
2009-11-03 13:45:10 -08:00
|
|
|
nsIContent* aElement,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aFirstBinding)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult rv = aInfo->DocumentURI()->Clone(getter_AddRefs(mBindingURI));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-05-21 18:12:46 -07:00
|
|
|
// The binding URI might be an immutable URI (e.g. for about: URIs). In that case,
|
|
|
|
// we'll fail in SetRef below, but that doesn't matter much for now.
|
|
|
|
if (aFirstBinding) {
|
|
|
|
rv = mBindingURI->Clone(getter_AddRefs(mAlternateBindingURI));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-11-03 13:45:10 -08:00
|
|
|
}
|
2011-05-21 18:12:46 -07:00
|
|
|
mBindingURI->SetRef(aID);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mXBLDocInfoWeak = aInfo;
|
|
|
|
|
2011-11-03 13:39:08 -07:00
|
|
|
// aElement will be null when reading from the cache, but the element will
|
|
|
|
// still be set later.
|
|
|
|
if (aElement) {
|
|
|
|
SetBindingElement(aElement);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsXBLPrototypeBinding::CompareBindingURI(nsIURI* aURI) const
|
2009-11-03 13:45:10 -08:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool equal = false;
|
2009-11-03 13:45:10 -08:00
|
|
|
mBindingURI->Equals(aURI, &equal);
|
|
|
|
if (!equal && mAlternateBindingURI) {
|
|
|
|
mAlternateBindingURI->Equals(aURI, &equal);
|
|
|
|
}
|
|
|
|
return equal;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsXBLPrototypeBinding::Traverse(nsCycleCollectionTraversalCallback &cb) const
|
|
|
|
{
|
2012-01-23 15:25:53 -08:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "proto mBinding");
|
2007-03-22 10:30:00 -07:00
|
|
|
cb.NoteXPCOMChild(mBinding);
|
2012-01-23 15:25:53 -08:00
|
|
|
if (mResources) {
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "proto mResources mLoader");
|
2007-03-22 10:30:00 -07:00
|
|
|
cb.NoteXPCOMChild(mResources->mLoader);
|
2012-01-23 15:25:53 -08:00
|
|
|
}
|
2013-07-24 00:39:56 -07:00
|
|
|
ImplCycleCollectionTraverse(cb, mInterfaceTable, "proto mInterfaceTable");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-09-28 06:45:01 -07:00
|
|
|
void
|
2008-01-29 18:05:43 -08:00
|
|
|
nsXBLPrototypeBinding::UnlinkJSObjects()
|
2007-09-28 06:45:01 -07:00
|
|
|
{
|
|
|
|
if (mImplementation)
|
2008-01-29 18:05:43 -08:00
|
|
|
mImplementation->UnlinkJSObjects();
|
2007-09-28 06:45:01 -07:00
|
|
|
}
|
|
|
|
|
2007-10-29 06:45:07 -07:00
|
|
|
void
|
2013-05-27 04:50:49 -07:00
|
|
|
nsXBLPrototypeBinding::Trace(const TraceCallbacks& aCallbacks, void *aClosure) const
|
2007-10-29 06:45:07 -07:00
|
|
|
{
|
|
|
|
if (mImplementation)
|
2013-05-27 04:50:49 -07:00
|
|
|
mImplementation->Trace(aCallbacks, aClosure);
|
2007-10-29 06:45:07 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsXBLPrototypeBinding::Initialize()
|
|
|
|
{
|
|
|
|
nsIContent* content = GetImmediateChild(nsGkAtoms::content);
|
|
|
|
if (content) {
|
|
|
|
ConstructAttributeTable(content);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsXBLPrototypeBinding::~nsXBLPrototypeBinding(void)
|
|
|
|
{
|
|
|
|
delete mResources;
|
|
|
|
delete mAttributeTable;
|
|
|
|
delete mImplementation;
|
|
|
|
MOZ_COUNT_DTOR(nsXBLPrototypeBinding);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXBLPrototypeBinding::SetBasePrototype(nsXBLPrototypeBinding* aBinding)
|
|
|
|
{
|
|
|
|
if (mBaseBinding == aBinding)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (mBaseBinding) {
|
|
|
|
NS_ERROR("Base XBL prototype binding is already defined!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mBaseBinding = aBinding;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXBLPrototypeBinding::SetBindingElement(nsIContent* aElement)
|
|
|
|
{
|
|
|
|
mBinding = aElement;
|
|
|
|
if (mBinding->AttrValueIs(kNameSpaceID_None, nsGkAtoms::inheritstyle,
|
|
|
|
nsGkAtoms::_false, eCaseMatters))
|
2011-10-17 07:59:28 -07:00
|
|
|
mInheritStyle = false;
|
2012-10-10 12:04:42 -07:00
|
|
|
|
2013-10-04 04:29:35 -07:00
|
|
|
mChromeOnlyContent = mBinding->AttrValueIs(kNameSpaceID_None,
|
2012-10-10 12:04:42 -07:00
|
|
|
nsGkAtoms::chromeOnlyContent,
|
|
|
|
nsGkAtoms::_true, eCaseMatters);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2013-12-13 08:54:04 -08:00
|
|
|
nsXBLPrototypeBinding::GetAllowScripts() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-07-14 18:55:54 -07:00
|
|
|
return mXBLDocInfoWeak->GetScriptAccess();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXBLPrototypeBinding::LoadResources()
|
|
|
|
{
|
|
|
|
if (mResources) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool result;
|
2007-03-22 10:30:00 -07:00
|
|
|
mResources->LoadResources(&result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXBLPrototypeBinding::AddResource(nsIAtom* aResourceType, const nsAString& aSrc)
|
|
|
|
{
|
|
|
|
if (!mResources) {
|
|
|
|
mResources = new nsXBLPrototypeResources(this);
|
|
|
|
if (!mResources)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
mResources->AddResource(aResourceType, aSrc);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXBLPrototypeBinding::FlushSkinSheets()
|
|
|
|
{
|
|
|
|
if (mResources)
|
|
|
|
return mResources->FlushSkinSheets();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXBLPrototypeBinding::BindingAttached(nsIContent* aBoundElement)
|
|
|
|
{
|
2007-10-05 18:23:09 -07:00
|
|
|
if (mImplementation && mImplementation->CompiledMembers() &&
|
|
|
|
mImplementation->mConstructor)
|
2007-03-22 10:30:00 -07:00
|
|
|
return mImplementation->mConstructor->Execute(aBoundElement);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXBLPrototypeBinding::BindingDetached(nsIContent* aBoundElement)
|
|
|
|
{
|
2007-10-05 18:23:09 -07:00
|
|
|
if (mImplementation && mImplementation->CompiledMembers() &&
|
|
|
|
mImplementation->mDestructor)
|
2007-03-22 10:30:00 -07:00
|
|
|
return mImplementation->mDestructor->Execute(aBoundElement);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsXBLProtoImplAnonymousMethod*
|
|
|
|
nsXBLPrototypeBinding::GetConstructor()
|
|
|
|
{
|
|
|
|
if (mImplementation)
|
|
|
|
return mImplementation->mConstructor;
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsXBLProtoImplAnonymousMethod*
|
|
|
|
nsXBLPrototypeBinding::GetDestructor()
|
|
|
|
{
|
|
|
|
if (mImplementation)
|
|
|
|
return mImplementation->mDestructor;
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXBLPrototypeBinding::SetConstructor(nsXBLProtoImplAnonymousMethod* aMethod)
|
|
|
|
{
|
|
|
|
if (!mImplementation)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
mImplementation->mConstructor = aMethod;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXBLPrototypeBinding::SetDestructor(nsXBLProtoImplAnonymousMethod* aMethod)
|
|
|
|
{
|
|
|
|
if (!mImplementation)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
mImplementation->mDestructor = aMethod;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2013-02-08 06:24:20 -08:00
|
|
|
nsXBLPrototypeBinding::InstallImplementation(nsXBLBinding* aBinding)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mImplementation)
|
2013-02-08 06:24:20 -08:00
|
|
|
return mImplementation->InstallImplementation(this, aBinding);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXXbz this duplicates lots of SetAttrs
|
|
|
|
void
|
|
|
|
nsXBLPrototypeBinding::AttributeChanged(nsIAtom* aAttribute,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aNameSpaceID,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aRemoveFlag,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIContent* aChangedElement,
|
|
|
|
nsIContent* aAnonymousContent,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aNotify)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!mAttributeTable)
|
|
|
|
return;
|
|
|
|
nsPRUint32Key nskey(aNameSpaceID);
|
2007-07-08 00:08:04 -07:00
|
|
|
nsObjectHashtable *attributesNS = static_cast<nsObjectHashtable*>(mAttributeTable->Get(&nskey));
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!attributesNS)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsISupportsKey key(aAttribute);
|
2007-07-08 00:08:04 -07:00
|
|
|
nsXBLAttributeEntry* xblAttr = static_cast<nsXBLAttributeEntry*>
|
|
|
|
(attributesNS->Get(&key));
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!xblAttr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Iterate over the elements in the array.
|
2007-06-18 08:43:40 -07:00
|
|
|
nsCOMPtr<nsIContent> content = GetImmediateChild(nsGkAtoms::content);
|
2007-03-22 10:30:00 -07:00
|
|
|
while (xblAttr) {
|
|
|
|
nsIContent* element = xblAttr->GetElement();
|
|
|
|
|
2007-06-18 08:43:40 -07:00
|
|
|
nsCOMPtr<nsIContent> realElement = LocateInstance(aChangedElement, content,
|
|
|
|
aAnonymousContent,
|
|
|
|
element);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (realElement) {
|
2008-03-19 12:44:08 -07:00
|
|
|
// Hold a strong reference here so that the atom doesn't go away during
|
|
|
|
// UnsetAttr.
|
|
|
|
nsCOMPtr<nsIAtom> dstAttr = xblAttr->GetDstAttribute();
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t dstNs = xblAttr->GetDstNameSpace();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (aRemoveFlag)
|
|
|
|
realElement->UnsetAttr(dstNs, dstAttr, aNotify);
|
|
|
|
else {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool attrPresent = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAutoString value;
|
|
|
|
// Check to see if the src attribute is xbl:text. If so, then we need to obtain the
|
|
|
|
// children of the real element and get the text nodes' values.
|
|
|
|
if (aAttribute == nsGkAtoms::text && aNameSpaceID == kNameSpaceID_XBL) {
|
2011-10-17 07:59:28 -07:00
|
|
|
nsContentUtils::GetNodeTextContent(aChangedElement, false, value);
|
2014-01-04 07:02:17 -08:00
|
|
|
value.StripChar(char16_t('\n'));
|
|
|
|
value.StripChar(char16_t('\r'));
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAutoString stripVal(value);
|
|
|
|
stripVal.StripWhitespace();
|
|
|
|
if (stripVal.IsEmpty())
|
2011-10-17 07:59:28 -07:00
|
|
|
attrPresent = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
attrPresent = aChangedElement->GetAttr(aNameSpaceID, aAttribute, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attrPresent)
|
|
|
|
realElement->SetAttr(dstNs, dstAttr, value, aNotify);
|
|
|
|
}
|
|
|
|
|
|
|
|
// See if we're the <html> tag in XUL, and see if value is being
|
|
|
|
// set or unset on us. We may also be a tag that is having
|
|
|
|
// xbl:text set on us.
|
|
|
|
|
|
|
|
if ((dstAttr == nsGkAtoms::text && dstNs == kNameSpaceID_XBL) ||
|
2011-12-17 22:00:47 -08:00
|
|
|
(realElement->NodeInfo()->Equals(nsGkAtoms::html,
|
|
|
|
kNameSpaceID_XUL) &&
|
|
|
|
dstAttr == nsGkAtoms::value)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Flush out all our kids.
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t childCount = realElement->GetChildCount();
|
|
|
|
for (uint32_t i = 0; i < childCount; i++)
|
2007-03-22 10:30:00 -07:00
|
|
|
realElement->RemoveChildAt(0, aNotify);
|
|
|
|
|
|
|
|
if (!aRemoveFlag) {
|
|
|
|
// Construct a new text node and insert it.
|
|
|
|
nsAutoString value;
|
|
|
|
aChangedElement->GetAttr(aNameSpaceID, aAttribute, value);
|
|
|
|
if (!value.IsEmpty()) {
|
2013-04-04 05:01:08 -07:00
|
|
|
nsRefPtr<nsTextNode> textContent =
|
|
|
|
new nsTextNode(realElement->NodeInfo()->NodeInfoManager());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
textContent->SetText(value, true);
|
|
|
|
realElement->AppendChildTo(textContent, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
xblAttr = xblAttr->GetNext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXBLPrototypeBinding::SetBaseTag(int32_t aNamespaceID, nsIAtom* aTag)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
mBaseNameSpaceID = aNamespaceID;
|
|
|
|
mBaseTag = aTag;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom*
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXBLPrototypeBinding::GetBaseTag(int32_t* aNamespaceID)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mBaseTag) {
|
|
|
|
*aNamespaceID = mBaseNameSpaceID;
|
|
|
|
return mBaseTag;
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXBLPrototypeBinding::ImplementsInterface(REFNSIID aIID) const
|
|
|
|
{
|
|
|
|
// Check our IID table.
|
2013-07-24 00:39:56 -07:00
|
|
|
return !!mInterfaceTable.GetWeak(aIID);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Internal helpers ///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
nsIContent*
|
|
|
|
nsXBLPrototypeBinding::GetImmediateChild(nsIAtom* aTag)
|
|
|
|
{
|
2011-09-27 00:54:58 -07:00
|
|
|
for (nsIContent* child = mBinding->GetFirstChild();
|
|
|
|
child;
|
|
|
|
child = child->GetNextSibling()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (child->NodeInfo()->Equals(aTag, kNameSpaceID_XBL)) {
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXBLPrototypeBinding::InitClass(const nsCString& aClassName,
|
2013-04-05 06:21:01 -07:00
|
|
|
JSContext * aContext,
|
|
|
|
JS::Handle<JSObject*> aGlobal,
|
|
|
|
JS::Handle<JSObject*> aScriptObject,
|
|
|
|
JS::MutableHandle<JSObject*> aClassObject,
|
2013-02-08 06:24:20 -08:00
|
|
|
bool* aNew)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return nsXBLBinding::DoInitJSClass(aContext, aGlobal, aScriptObject,
|
2013-02-08 06:24:20 -08:00
|
|
|
aClassName, this, aClassObject, aNew);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent*
|
|
|
|
nsXBLPrototypeBinding::LocateInstance(nsIContent* aBoundElement,
|
|
|
|
nsIContent* aTemplRoot,
|
|
|
|
nsIContent* aCopyRoot,
|
|
|
|
nsIContent* aTemplChild)
|
|
|
|
{
|
|
|
|
// XXX We will get in trouble if the binding instantiation deviates from the template
|
|
|
|
// in the prototype.
|
|
|
|
if (aTemplChild == aTemplRoot || !aTemplChild)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-05-01 15:50:08 -07:00
|
|
|
nsIContent* templParent = aTemplChild->GetParent();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// We may be disconnected from our parent during cycle collection.
|
|
|
|
if (!templParent)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-05-01 15:50:08 -07:00
|
|
|
nsIContent *copyParent =
|
|
|
|
templParent == aTemplRoot ? aCopyRoot :
|
|
|
|
LocateInstance(aBoundElement, aTemplRoot, aCopyRoot, templParent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-05-01 15:50:08 -07:00
|
|
|
if (!copyParent)
|
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-05-01 15:50:08 -07:00
|
|
|
return copyParent->GetChildAt(templParent->IndexOf(aTemplChild));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
struct nsXBLAttrChangeData
|
|
|
|
{
|
|
|
|
nsXBLPrototypeBinding* mProto;
|
|
|
|
nsIContent* mBoundElement;
|
|
|
|
nsIContent* mContent;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mSrcNamespace;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsXBLAttrChangeData(nsXBLPrototypeBinding* aProto,
|
|
|
|
nsIContent* aElt, nsIContent* aContent)
|
2007-04-23 07:21:53 -07:00
|
|
|
:mProto(aProto), mBoundElement(aElt), mContent(aContent) {}
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// XXXbz this duplicates lots of AttributeChanged
|
2011-09-28 23:19:26 -07:00
|
|
|
bool SetAttrs(nsHashKey* aKey, void* aData, void* aClosure)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
nsXBLAttributeEntry* entry = static_cast<nsXBLAttributeEntry*>(aData);
|
|
|
|
nsXBLAttrChangeData* changeData = static_cast<nsXBLAttrChangeData*>(aClosure);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsIAtom* src = entry->GetSrcAttribute();
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t srcNs = changeData->mSrcNamespace;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAutoString value;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool attrPresent = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (src == nsGkAtoms::text && srcNs == kNameSpaceID_XBL) {
|
2011-10-17 07:59:28 -07:00
|
|
|
nsContentUtils::GetNodeTextContent(changeData->mBoundElement, false,
|
2007-03-22 10:30:00 -07:00
|
|
|
value);
|
2014-01-04 07:02:17 -08:00
|
|
|
value.StripChar(char16_t('\n'));
|
|
|
|
value.StripChar(char16_t('\r'));
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAutoString stripVal(value);
|
|
|
|
stripVal.StripWhitespace();
|
|
|
|
|
|
|
|
if (stripVal.IsEmpty())
|
2011-10-17 07:59:28 -07:00
|
|
|
attrPresent = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
attrPresent = changeData->mBoundElement->GetAttr(srcNs, src, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attrPresent) {
|
|
|
|
nsIContent* content =
|
|
|
|
changeData->mProto->GetImmediateChild(nsGkAtoms::content);
|
|
|
|
|
|
|
|
nsXBLAttributeEntry* curr = entry;
|
|
|
|
while (curr) {
|
|
|
|
nsIAtom* dst = curr->GetDstAttribute();
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t dstNs = curr->GetDstNameSpace();
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIContent* element = curr->GetElement();
|
|
|
|
|
|
|
|
nsIContent *realElement =
|
|
|
|
changeData->mProto->LocateInstance(changeData->mBoundElement, content,
|
|
|
|
changeData->mContent, element);
|
|
|
|
|
|
|
|
if (realElement) {
|
2011-10-17 07:59:28 -07:00
|
|
|
realElement->SetAttr(dstNs, dst, value, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-11-03 13:39:08 -07:00
|
|
|
// XXXndeakin shouldn't this be done in lieu of SetAttr?
|
2007-03-22 10:30:00 -07:00
|
|
|
if ((dst == nsGkAtoms::text && dstNs == kNameSpaceID_XBL) ||
|
|
|
|
(realElement->NodeInfo()->Equals(nsGkAtoms::html,
|
|
|
|
kNameSpaceID_XUL) &&
|
|
|
|
dst == nsGkAtoms::value && !value.IsEmpty())) {
|
|
|
|
|
2013-04-04 05:01:08 -07:00
|
|
|
nsRefPtr<nsTextNode> textContent =
|
|
|
|
new nsTextNode(realElement->NodeInfo()->NodeInfoManager());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
textContent->SetText(value, false);
|
|
|
|
realElement->AppendChildTo(textContent, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
curr = curr->GetNext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool SetAttrsNS(nsHashKey* aKey, void* aData, void* aClosure)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aData && aClosure) {
|
2007-07-08 00:08:04 -07:00
|
|
|
nsPRUint32Key * key = static_cast<nsPRUint32Key*>(aKey);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsObjectHashtable* xblAttributes =
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsObjectHashtable*>(aData);
|
|
|
|
nsXBLAttrChangeData * changeData = static_cast<nsXBLAttrChangeData *>
|
|
|
|
(aClosure);
|
2007-03-22 10:30:00 -07:00
|
|
|
changeData->mSrcNamespace = key->GetValue();
|
|
|
|
xblAttributes->Enumerate(SetAttrs, (void*)changeData);
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXBLPrototypeBinding::SetInitialAttributes(nsIContent* aBoundElement, nsIContent* aAnonymousContent)
|
|
|
|
{
|
|
|
|
if (mAttributeTable) {
|
|
|
|
nsXBLAttrChangeData data(this, aBoundElement, aAnonymousContent);
|
|
|
|
mAttributeTable->Enumerate(SetAttrsNS, (void*)&data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIStyleRuleProcessor*
|
|
|
|
nsXBLPrototypeBinding::GetRuleProcessor()
|
|
|
|
{
|
|
|
|
if (mResources) {
|
|
|
|
return mResources->mRuleProcessor;
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-12-02 02:26:12 -08:00
|
|
|
nsXBLPrototypeResources::sheet_array_type*
|
|
|
|
nsXBLPrototypeBinding::GetOrCreateStyleSheets()
|
|
|
|
{
|
|
|
|
if (!mResources) {
|
|
|
|
mResources = new nsXBLPrototypeResources(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
return &mResources->mStyleSheetList;
|
|
|
|
}
|
|
|
|
|
2010-05-11 13:41:47 -07:00
|
|
|
nsXBLPrototypeResources::sheet_array_type*
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXBLPrototypeBinding::GetStyleSheets()
|
|
|
|
{
|
|
|
|
if (mResources) {
|
|
|
|
return &mResources->mStyleSheetList;
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2007-03-22 10:30:00 -07:00
|
|
|
DeleteAttributeEntry(nsHashKey* aKey, void* aData, void* aClosure)
|
|
|
|
{
|
2013-03-05 05:12:16 -08:00
|
|
|
delete static_cast<nsXBLAttributeEntry*>(aData);
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2007-03-22 10:30:00 -07:00
|
|
|
DeleteAttributeTable(nsHashKey* aKey, void* aData, void* aClosure)
|
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
delete static_cast<nsObjectHashtable*>(aData);
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-11-03 13:39:08 -07:00
|
|
|
void
|
|
|
|
nsXBLPrototypeBinding::EnsureAttributeTable()
|
|
|
|
{
|
|
|
|
if (!mAttributeTable) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mAttributeTable = new nsObjectHashtable(nullptr, nullptr,
|
2011-11-03 13:39:08 -07:00
|
|
|
DeleteAttributeTable,
|
2012-07-30 07:20:58 -07:00
|
|
|
nullptr, 4);
|
2011-11-03 13:39:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXBLPrototypeBinding::AddToAttributeTable(int32_t aSourceNamespaceID, nsIAtom* aSourceTag,
|
|
|
|
int32_t aDestNamespaceID, nsIAtom* aDestTag,
|
2011-11-03 13:39:08 -07:00
|
|
|
nsIContent* aContent)
|
|
|
|
{
|
|
|
|
nsPRUint32Key nskey(aSourceNamespaceID);
|
|
|
|
nsObjectHashtable* attributesNS =
|
|
|
|
static_cast<nsObjectHashtable*>(mAttributeTable->Get(&nskey));
|
|
|
|
if (!attributesNS) {
|
2012-07-30 07:20:58 -07:00
|
|
|
attributesNS = new nsObjectHashtable(nullptr, nullptr,
|
2011-11-03 13:39:08 -07:00
|
|
|
DeleteAttributeEntry,
|
2012-07-30 07:20:58 -07:00
|
|
|
nullptr, 4);
|
2011-11-03 13:39:08 -07:00
|
|
|
mAttributeTable->Put(&nskey, attributesNS);
|
|
|
|
}
|
2013-03-05 05:12:16 -08:00
|
|
|
|
2011-11-03 13:39:08 -07:00
|
|
|
nsXBLAttributeEntry* xblAttr =
|
2013-03-05 05:12:16 -08:00
|
|
|
new nsXBLAttributeEntry(aSourceTag, aDestTag, aDestNamespaceID, aContent);
|
2011-11-03 13:39:08 -07:00
|
|
|
|
|
|
|
nsISupportsKey key(aSourceTag);
|
|
|
|
nsXBLAttributeEntry* entry = static_cast<nsXBLAttributeEntry*>
|
|
|
|
(attributesNS->Get(&key));
|
|
|
|
if (!entry) {
|
|
|
|
attributesNS->Put(&key, xblAttr);
|
|
|
|
} else {
|
|
|
|
while (entry->GetNext())
|
|
|
|
entry = entry->GetNext();
|
|
|
|
entry->SetNext(xblAttr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsXBLPrototypeBinding::ConstructAttributeTable(nsIContent* aElement)
|
|
|
|
{
|
|
|
|
// Don't add entries for <children> elements, since those will get
|
|
|
|
// removed from the DOM when we construct the insertion point table.
|
|
|
|
if (!aElement->NodeInfo()->Equals(nsGkAtoms::children, kNameSpaceID_XBL)) {
|
|
|
|
nsAutoString inherits;
|
|
|
|
aElement->GetAttr(kNameSpaceID_XBL, nsGkAtoms::inherits, inherits);
|
|
|
|
|
|
|
|
if (!inherits.IsEmpty()) {
|
2011-11-03 13:39:08 -07:00
|
|
|
EnsureAttributeTable();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// The user specified at least one attribute.
|
|
|
|
char* str = ToNewCString(inherits);
|
|
|
|
char* newStr;
|
|
|
|
// XXX We should use a strtok function that tokenizes PRUnichars
|
|
|
|
// so that we don't have to convert from Unicode to ASCII and then back
|
|
|
|
|
|
|
|
char* token = nsCRT::strtok( str, ", ", &newStr );
|
2013-04-02 18:14:24 -07:00
|
|
|
while( token != nullptr ) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Build an atom out of this attribute.
|
|
|
|
nsCOMPtr<nsIAtom> atom;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t atomNsID = kNameSpaceID_None;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIAtom> attribute;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t attributeNsID = kNameSpaceID_None;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Figure out if this token contains a :.
|
|
|
|
nsAutoString attrTok; attrTok.AssignWithConversion(token);
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t index = attrTok.Find("=", true);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult rv;
|
|
|
|
if (index != -1) {
|
|
|
|
// This attribute maps to something different.
|
|
|
|
nsAutoString left, right;
|
|
|
|
attrTok.Left(left, index);
|
|
|
|
attrTok.Right(right, attrTok.Length()-index-1);
|
|
|
|
|
|
|
|
rv = nsContentUtils::SplitQName(aElement, left, &attributeNsID,
|
|
|
|
getter_AddRefs(attribute));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return;
|
|
|
|
|
|
|
|
rv = nsContentUtils::SplitQName(aElement, right, &atomNsID,
|
|
|
|
getter_AddRefs(atom));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsAutoString tok;
|
|
|
|
tok.AssignWithConversion(token);
|
|
|
|
rv = nsContentUtils::SplitQName(aElement, tok, &atomNsID,
|
|
|
|
getter_AddRefs(atom));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return;
|
|
|
|
attribute = atom;
|
|
|
|
attributeNsID = atomNsID;
|
|
|
|
}
|
|
|
|
|
2011-11-03 13:39:08 -07:00
|
|
|
AddToAttributeTable(atomNsID, atom, attributeNsID, attribute, aElement);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Now remove the inherits attribute from the element so that it doesn't
|
|
|
|
// show up on clones of the element. It is used
|
|
|
|
// by the template only, and we don't need it anymore.
|
|
|
|
// XXXdwh Don't do this for XUL elements, since it faults them into heavyweight
|
|
|
|
// elements. Should nuke from the prototype instead.
|
2011-10-17 07:59:28 -07:00
|
|
|
// aElement->UnsetAttr(kNameSpaceID_XBL, nsGkAtoms::inherits, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
token = nsCRT::strtok( newStr, ", ", &newStr );
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMemory::Free(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Recur into our children.
|
2011-09-27 00:54:58 -07:00
|
|
|
for (nsIContent* child = aElement->GetFirstChild();
|
|
|
|
child;
|
|
|
|
child = child->GetNextSibling()) {
|
|
|
|
ConstructAttributeTable(child);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXBLPrototypeBinding::ConstructInterfaceTable(const nsAString& aImpls)
|
|
|
|
{
|
|
|
|
if (!aImpls.IsEmpty()) {
|
|
|
|
// Obtain the interface info manager that can tell us the IID
|
|
|
|
// for a given interface name.
|
|
|
|
nsCOMPtr<nsIInterfaceInfoManager>
|
|
|
|
infoManager(do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID));
|
|
|
|
if (!infoManager)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// The user specified at least one attribute.
|
|
|
|
NS_ConvertUTF16toUTF8 utf8impl(aImpls);
|
|
|
|
char* str = utf8impl.BeginWriting();
|
|
|
|
char* newStr;
|
|
|
|
// XXX We should use a strtok function that tokenizes PRUnichars
|
|
|
|
// so that we don't have to convert from Unicode to ASCII and then back
|
|
|
|
|
|
|
|
char* token = nsCRT::strtok( str, ", ", &newStr );
|
2013-04-02 18:14:24 -07:00
|
|
|
while( token != nullptr ) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// get the InterfaceInfo for the name
|
|
|
|
nsCOMPtr<nsIInterfaceInfo> iinfo;
|
|
|
|
infoManager->GetInfoForName(token, getter_AddRefs(iinfo));
|
|
|
|
|
|
|
|
if (iinfo) {
|
|
|
|
// obtain an IID.
|
2012-07-30 07:20:58 -07:00
|
|
|
const nsIID* iid = nullptr;
|
2008-01-11 20:30:42 -08:00
|
|
|
iinfo->GetIIDShared(&iid);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (iid) {
|
|
|
|
// We found a valid iid. Add it to our table.
|
2013-07-24 00:39:56 -07:00
|
|
|
mInterfaceTable.Put(*iid, mBinding);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// this block adds the parent interfaces of each interface
|
|
|
|
// defined in the xbl definition (implements="nsI...")
|
|
|
|
nsCOMPtr<nsIInterfaceInfo> parentInfo;
|
|
|
|
// if it has a parent, add it to the table
|
|
|
|
while (NS_SUCCEEDED(iinfo->GetParent(getter_AddRefs(parentInfo))) && parentInfo) {
|
|
|
|
// get the iid
|
2008-01-11 20:30:42 -08:00
|
|
|
parentInfo->GetIIDShared(&iid);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// don't add nsISupports to the table
|
|
|
|
if (!iid || iid->Equals(NS_GET_IID(nsISupports)))
|
|
|
|
break;
|
|
|
|
|
|
|
|
// add the iid to the table
|
2013-07-24 00:39:56 -07:00
|
|
|
mInterfaceTable.Put(*iid, mBinding);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// look for the next parent
|
|
|
|
iinfo = parentInfo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
token = nsCRT::strtok( newStr, ", ", &newStr );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXBLPrototypeBinding::AddResourceListener(nsIContent* aBoundElement)
|
|
|
|
{
|
|
|
|
if (!mResources)
|
|
|
|
return NS_ERROR_FAILURE; // Makes no sense to add a listener when the binding
|
|
|
|
// has no resources.
|
|
|
|
|
|
|
|
mResources->AddResourceListener(aBoundElement);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXBLPrototypeBinding::CreateKeyHandlers()
|
|
|
|
{
|
|
|
|
nsXBLPrototypeHandler* curr = mPrototypeHandler;
|
|
|
|
while (curr) {
|
|
|
|
nsCOMPtr<nsIAtom> eventAtom = curr->GetEventName();
|
|
|
|
if (eventAtom == nsGkAtoms::keyup ||
|
|
|
|
eventAtom == nsGkAtoms::keydown ||
|
|
|
|
eventAtom == nsGkAtoms::keypress) {
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t phase = curr->GetPhase();
|
|
|
|
uint8_t type = curr->GetType();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t count = mKeyHandlers.Count();
|
|
|
|
int32_t i;
|
2012-07-30 07:20:58 -07:00
|
|
|
nsXBLKeyEventHandler* handler = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
for (i = 0; i < count; ++i) {
|
|
|
|
handler = mKeyHandlers[i];
|
|
|
|
if (handler->Matches(eventAtom, phase, type))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == count) {
|
|
|
|
nsRefPtr<nsXBLKeyEventHandler> newHandler;
|
|
|
|
NS_NewXBLKeyEventHandler(eventAtom, phase, type,
|
|
|
|
getter_AddRefs(newHandler));
|
|
|
|
if (newHandler)
|
|
|
|
mKeyHandlers.AppendObject(newHandler);
|
|
|
|
handler = newHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (handler)
|
|
|
|
handler->AddProtoHandler(curr);
|
|
|
|
}
|
|
|
|
|
|
|
|
curr = curr->GetNextHandler();
|
|
|
|
}
|
|
|
|
}
|
2011-11-03 13:39:07 -07:00
|
|
|
|
2012-02-07 00:35:58 -08:00
|
|
|
class XBLPrototypeSetupCleanup
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
XBLPrototypeSetupCleanup(nsXBLDocumentInfo* aDocInfo, const nsACString& aID)
|
|
|
|
: mDocInfo(aDocInfo), mID(aID) {}
|
|
|
|
|
|
|
|
~XBLPrototypeSetupCleanup()
|
|
|
|
{
|
|
|
|
if (mDocInfo) {
|
|
|
|
mDocInfo->RemovePrototypeBinding(mID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Disconnect()
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
mDocInfo = nullptr;
|
2012-02-07 00:35:58 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsXBLDocumentInfo* mDocInfo;
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString mID;
|
2012-02-07 00:35:58 -08:00
|
|
|
};
|
|
|
|
|
2011-11-03 13:39:08 -07:00
|
|
|
nsresult
|
|
|
|
nsXBLPrototypeBinding::Read(nsIObjectInputStream* aStream,
|
|
|
|
nsXBLDocumentInfo* aDocInfo,
|
|
|
|
nsIDocument* aDocument,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t aFlags)
|
2011-11-03 13:39:08 -07:00
|
|
|
{
|
|
|
|
mInheritStyle = (aFlags & XBLBinding_Serialize_InheritStyle) ? true : false;
|
2012-10-10 12:04:42 -07:00
|
|
|
mChromeOnlyContent =
|
|
|
|
(aFlags & XBLBinding_Serialize_ChromeOnlyContent) ? true : false;
|
2011-11-03 13:39:08 -07:00
|
|
|
|
|
|
|
// nsXBLContentSink::ConstructBinding doesn't create a binding with an empty
|
|
|
|
// id, so we don't here either.
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString id;
|
2011-11-03 13:39:08 -07:00
|
|
|
nsresult rv = aStream->ReadCString(id);
|
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_TRUE(!id.IsEmpty(), NS_ERROR_FAILURE);
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString baseBindingURI;
|
2011-11-03 13:39:08 -07:00
|
|
|
rv = aStream->ReadCString(baseBindingURI);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
mCheckedBaseProto = true;
|
|
|
|
|
|
|
|
if (!baseBindingURI.IsEmpty()) {
|
|
|
|
rv = NS_NewURI(getter_AddRefs(mBaseBindingURI), baseBindingURI);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = ReadNamespace(aStream, mBaseNameSpaceID);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsAutoString baseTag;
|
|
|
|
rv = aStream->ReadString(baseTag);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!baseTag.IsEmpty()) {
|
|
|
|
mBaseTag = do_GetAtom(baseTag);
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
aDocument->CreateElem(NS_LITERAL_STRING("binding"), nullptr, kNameSpaceID_XBL,
|
2011-11-03 13:39:08 -07:00
|
|
|
getter_AddRefs(mBinding));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> child;
|
|
|
|
rv = ReadContentNode(aStream, aDocument, aDocument->NodeInfoManager(), getter_AddRefs(child));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
Element* rootElement = aDocument->GetRootElement();
|
|
|
|
if (rootElement)
|
|
|
|
rootElement->AppendChildTo(mBinding, false);
|
|
|
|
|
|
|
|
if (child) {
|
|
|
|
mBinding->AppendChildTo(child, false);
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t interfaceCount;
|
2011-11-03 13:39:08 -07:00
|
|
|
rv = aStream->Read32(&interfaceCount);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-07-24 00:39:56 -07:00
|
|
|
for (; interfaceCount > 0; interfaceCount--) {
|
|
|
|
nsIID iid;
|
|
|
|
aStream->ReadID(&iid);
|
|
|
|
mInterfaceTable.Put(iid, mBinding);
|
2011-11-03 13:39:08 -07:00
|
|
|
}
|
|
|
|
|
2013-08-09 09:25:13 -07:00
|
|
|
AutoSafeJSContext cx;
|
2013-08-09 09:25:14 -07:00
|
|
|
JS::Rooted<JSObject*> compilationGlobal(cx, aDocInfo->GetCompilationGlobal());
|
2013-08-09 09:25:13 -07:00
|
|
|
NS_ENSURE_TRUE(compilationGlobal, NS_ERROR_UNEXPECTED);
|
|
|
|
JSAutoCompartment ac(cx, compilationGlobal);
|
2011-11-03 13:39:08 -07:00
|
|
|
|
|
|
|
bool isFirstBinding = aFlags & XBLBinding_Serialize_IsFirstBinding;
|
2012-07-30 07:20:58 -07:00
|
|
|
rv = Init(id, aDocInfo, nullptr, isFirstBinding);
|
2011-11-03 13:39:08 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// We need to set the prototype binding before reading the nsXBLProtoImpl,
|
|
|
|
// as it may be retrieved within.
|
|
|
|
rv = aDocInfo->SetPrototypeBinding(id, this);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-02-07 00:35:58 -08:00
|
|
|
XBLPrototypeSetupCleanup cleanup(aDocInfo, id);
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString className;
|
2011-11-03 13:39:08 -07:00
|
|
|
rv = aStream->ReadCString(className);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!className.IsEmpty()) {
|
|
|
|
nsXBLProtoImpl* impl; // NS_NewXBLProtoImpl will set mImplementation for us
|
|
|
|
NS_NewXBLProtoImpl(this, NS_ConvertUTF8toUTF16(className).get(), &impl);
|
|
|
|
|
|
|
|
// This needs to happen after SetPrototypeBinding as calls are made to
|
|
|
|
// retrieve the mapped bindings from within here. However, if an error
|
|
|
|
// occurs, the mapping should be removed again so that we don't keep an
|
|
|
|
// invalid binding around.
|
2013-08-09 09:25:14 -07:00
|
|
|
rv = mImplementation->Read(aStream, this);
|
2012-02-07 00:35:58 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-11-03 13:39:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Next read in the handlers.
|
2012-07-30 07:20:58 -07:00
|
|
|
nsXBLPrototypeHandler* previousHandler = nullptr;
|
2011-11-03 13:39:08 -07:00
|
|
|
|
|
|
|
do {
|
|
|
|
XBLBindingSerializeDetails type;
|
|
|
|
rv = aStream->Read8(&type);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (type == XBLBinding_Serialize_NoMoreItems)
|
|
|
|
break;
|
|
|
|
|
|
|
|
NS_ASSERTION((type & XBLBinding_Serialize_Mask) == XBLBinding_Serialize_Handler,
|
|
|
|
"invalid handler type");
|
|
|
|
|
|
|
|
nsXBLPrototypeHandler* handler = new nsXBLPrototypeHandler(this);
|
2013-08-09 09:25:13 -07:00
|
|
|
rv = handler->Read(aStream);
|
2011-11-03 13:39:08 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
delete handler;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (previousHandler) {
|
|
|
|
previousHandler->SetNextHandler(handler);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
SetPrototypeHandlers(handler);
|
|
|
|
}
|
|
|
|
previousHandler = handler;
|
|
|
|
} while (1);
|
|
|
|
|
2013-09-25 13:32:05 -07:00
|
|
|
if (mBinding) {
|
|
|
|
while (true) {
|
|
|
|
XBLBindingSerializeDetails type;
|
|
|
|
rv = aStream->Read8(&type);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (type != XBLBinding_Serialize_Attribute) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t attrNamespace;
|
|
|
|
rv = ReadNamespace(aStream, attrNamespace);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsAutoString attrPrefix, attrName, attrValue;
|
|
|
|
rv = aStream->ReadString(attrPrefix);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = aStream->ReadString(attrName);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = aStream->ReadString(attrValue);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> atomPrefix = do_GetAtom(attrPrefix);
|
|
|
|
nsCOMPtr<nsIAtom> atomName = do_GetAtom(attrName);
|
|
|
|
mBinding->SetAttr(attrNamespace, atomName, atomPrefix, attrValue, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-03 13:39:08 -07:00
|
|
|
// Finally, read in the resources.
|
2013-09-25 13:32:05 -07:00
|
|
|
while (true) {
|
2011-11-03 13:39:08 -07:00
|
|
|
XBLBindingSerializeDetails type;
|
|
|
|
rv = aStream->Read8(&type);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (type == XBLBinding_Serialize_NoMoreItems)
|
|
|
|
break;
|
|
|
|
|
|
|
|
NS_ASSERTION((type & XBLBinding_Serialize_Mask) == XBLBinding_Serialize_Stylesheet ||
|
|
|
|
(type & XBLBinding_Serialize_Mask) == XBLBinding_Serialize_Image, "invalid resource type");
|
|
|
|
|
|
|
|
nsAutoString src;
|
|
|
|
rv = aStream->ReadString(src);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
AddResource(type == XBLBinding_Serialize_Stylesheet ? nsGkAtoms::stylesheet :
|
|
|
|
nsGkAtoms::image, src);
|
2013-09-25 13:32:05 -07:00
|
|
|
}
|
2011-11-03 13:39:08 -07:00
|
|
|
|
|
|
|
if (isFirstBinding) {
|
|
|
|
aDocInfo->SetFirstPrototypeBinding(this);
|
|
|
|
}
|
|
|
|
|
2012-02-07 00:35:58 -08:00
|
|
|
cleanup.Disconnect();
|
2011-11-03 13:39:08 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-07-24 00:39:56 -07:00
|
|
|
static PLDHashOperator
|
|
|
|
WriteInterfaceID(const nsIID& aKey, nsIContent* aData, void* aClosure)
|
2011-11-03 13:39:08 -07:00
|
|
|
{
|
|
|
|
// We can just write out the ids. The cache will be invalidated when a
|
|
|
|
// different build is used, so we don't need to worry about ids changing.
|
2013-07-24 00:39:56 -07:00
|
|
|
static_cast<nsIObjectOutputStream *>(aClosure)->WriteID(aKey);
|
|
|
|
return PL_DHASH_NEXT;
|
2011-11-03 13:39:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXBLPrototypeBinding::Write(nsIObjectOutputStream* aStream)
|
|
|
|
{
|
|
|
|
// This writes out the binding. Note that mCheckedBaseProto,
|
|
|
|
// mKeyHandlersRegistered and mKeyHandlers are not serialized as they are
|
|
|
|
// computed on demand.
|
|
|
|
|
2013-08-09 09:25:13 -07:00
|
|
|
AutoSafeJSContext cx;
|
2013-08-09 09:25:14 -07:00
|
|
|
JS::Rooted<JSObject*> compilationGlobal(cx, mXBLDocInfoWeak->GetCompilationGlobal());
|
2013-08-09 09:25:13 -07:00
|
|
|
NS_ENSURE_TRUE(compilationGlobal, NS_ERROR_UNEXPECTED);
|
|
|
|
JSAutoCompartment ac(cx, compilationGlobal);
|
2011-11-03 13:39:08 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t flags = mInheritStyle ? XBLBinding_Serialize_InheritStyle : 0;
|
2011-11-03 13:39:08 -07:00
|
|
|
|
|
|
|
// mAlternateBindingURI is only set on the first binding.
|
|
|
|
if (mAlternateBindingURI) {
|
|
|
|
flags |= XBLBinding_Serialize_IsFirstBinding;
|
|
|
|
}
|
|
|
|
|
2012-10-10 12:04:42 -07:00
|
|
|
if (mChromeOnlyContent) {
|
|
|
|
flags |= XBLBinding_Serialize_ChromeOnlyContent;
|
|
|
|
}
|
|
|
|
|
2011-11-03 13:39:08 -07:00
|
|
|
nsresult rv = aStream->Write8(flags);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString id;
|
2011-11-03 13:39:08 -07:00
|
|
|
mBindingURI->GetRef(id);
|
|
|
|
rv = aStream->WriteStringZ(id.get());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// write out the extends and display attribute values
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString extends;
|
2011-11-03 13:39:08 -07:00
|
|
|
ResolveBaseBinding();
|
|
|
|
if (mBaseBindingURI)
|
|
|
|
mBaseBindingURI->GetSpec(extends);
|
|
|
|
|
|
|
|
rv = aStream->WriteStringZ(extends.get());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = WriteNamespace(aStream, mBaseNameSpaceID);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsAutoString baseTag;
|
|
|
|
if (mBaseTag) {
|
|
|
|
mBaseTag->ToString(baseTag);
|
|
|
|
}
|
|
|
|
rv = aStream->WriteWStringZ(baseTag.get());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsIContent* content = GetImmediateChild(nsGkAtoms::content);
|
|
|
|
if (content) {
|
2013-05-01 15:50:08 -07:00
|
|
|
rv = WriteContentNode(aStream, content);
|
2011-11-03 13:39:08 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Write a marker to indicate that there is no content.
|
|
|
|
rv = aStream->Write8(XBLBinding_Serialize_NoContent);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enumerate and write out the implemented interfaces.
|
2013-07-24 00:39:56 -07:00
|
|
|
rv = aStream->Write32(mInterfaceTable.Count());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-11-03 13:39:08 -07:00
|
|
|
|
2013-07-24 00:39:56 -07:00
|
|
|
mInterfaceTable.EnumerateRead(WriteInterfaceID, aStream);
|
2011-11-03 13:39:08 -07:00
|
|
|
|
|
|
|
// Write out the implementation details.
|
|
|
|
if (mImplementation) {
|
2013-08-09 09:25:13 -07:00
|
|
|
rv = mImplementation->Write(aStream, this);
|
2011-11-03 13:39:08 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Write out an empty classname. This indicates that the binding does not
|
|
|
|
// define an implementation.
|
|
|
|
rv = aStream->WriteWStringZ(EmptyString().get());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write out the handlers.
|
|
|
|
nsXBLPrototypeHandler* handler = mPrototypeHandler;
|
|
|
|
while (handler) {
|
2013-08-09 09:25:13 -07:00
|
|
|
rv = handler->Write(aStream);
|
2011-11-03 13:39:08 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
handler = handler->GetNextHandler();
|
|
|
|
}
|
|
|
|
|
|
|
|
aStream->Write8(XBLBinding_Serialize_NoMoreItems);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-09-25 13:32:05 -07:00
|
|
|
if (mBinding) {
|
|
|
|
uint32_t attributes = mBinding->GetAttrCount();
|
|
|
|
nsAutoString attrValue;
|
|
|
|
for (uint32_t i = 0; i < attributes; ++i) {
|
|
|
|
const nsAttrName* attr = mBinding->GetAttrNameAt(i);
|
|
|
|
nsDependentAtomString attrName = attr->LocalName();
|
|
|
|
mBinding->GetAttr(attr->NamespaceID(), attr->LocalName(), attrValue);
|
|
|
|
rv = aStream->Write8(XBLBinding_Serialize_Attribute);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = WriteNamespace(aStream, attr->NamespaceID());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsIAtom* prefix = attr->GetPrefix();
|
|
|
|
nsAutoString prefixString;
|
|
|
|
if (prefix) {
|
|
|
|
prefix->ToString(prefixString);
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = aStream->WriteWStringZ(prefixString.get());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = aStream->WriteWStringZ(attrName.get());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = aStream->WriteWStringZ(attrValue.get());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aStream->Write8(XBLBinding_Serialize_NoMoreItems);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-11-03 13:39:08 -07:00
|
|
|
// Write out the resources
|
|
|
|
if (mResources) {
|
|
|
|
rv = mResources->Write(aStream);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write out an end mark at the end.
|
|
|
|
return aStream->Write8(XBLBinding_Serialize_NoMoreItems);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXBLPrototypeBinding::ReadContentNode(nsIObjectInputStream* aStream,
|
|
|
|
nsIDocument* aDocument,
|
|
|
|
nsNodeInfoManager* aNim,
|
|
|
|
nsIContent** aContent)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*aContent = nullptr;
|
2011-11-03 13:39:08 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t namespaceID;
|
2011-11-03 13:39:08 -07:00
|
|
|
nsresult rv = ReadNamespace(aStream, namespaceID);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// There is no content to read so just return.
|
|
|
|
if (namespaceID == XBLBinding_Serialize_NoContent)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
|
|
|
|
// If this is a text type, just read the string and return.
|
|
|
|
if (namespaceID == XBLBinding_Serialize_TextNode ||
|
|
|
|
namespaceID == XBLBinding_Serialize_CDATANode ||
|
|
|
|
namespaceID == XBLBinding_Serialize_CommentNode) {
|
|
|
|
switch (namespaceID) {
|
|
|
|
case XBLBinding_Serialize_TextNode:
|
2013-04-04 05:01:08 -07:00
|
|
|
content = new nsTextNode(aNim);
|
2011-11-03 13:39:08 -07:00
|
|
|
break;
|
|
|
|
case XBLBinding_Serialize_CDATANode:
|
2013-04-04 05:01:11 -07:00
|
|
|
content = new CDATASection(aNim);
|
2011-11-03 13:39:08 -07:00
|
|
|
break;
|
|
|
|
case XBLBinding_Serialize_CommentNode:
|
2013-04-04 05:02:22 -07:00
|
|
|
content = new Comment(aNim);
|
2011-11-03 13:39:08 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString text;
|
|
|
|
rv = aStream->ReadString(text);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
content->SetText(text, false);
|
|
|
|
content.swap(*aContent);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, it's an element, so read its tag, attributes and children.
|
|
|
|
nsAutoString prefix, tag;
|
|
|
|
rv = aStream->ReadString(prefix);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> prefixAtom;
|
|
|
|
if (!prefix.IsEmpty())
|
|
|
|
prefixAtom = do_GetAtom(prefix);
|
|
|
|
|
|
|
|
rv = aStream->ReadString(tag);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> tagAtom = do_GetAtom(tag);
|
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo =
|
|
|
|
aNim->GetNodeInfo(tagAtom, prefixAtom, namespaceID, nsIDOMNode::ELEMENT_NODE);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t attrCount;
|
2011-11-03 13:39:08 -07:00
|
|
|
rv = aStream->Read32(&attrCount);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Create XUL prototype elements, or regular elements for other namespaces.
|
|
|
|
// This needs to match the code in nsXBLContentSink::CreateElement.
|
|
|
|
#ifdef MOZ_XUL
|
|
|
|
if (namespaceID == kNameSpaceID_XUL) {
|
|
|
|
nsIURI* documentURI = aDocument->GetDocumentURI();
|
|
|
|
|
|
|
|
nsRefPtr<nsXULPrototypeElement> prototype = new nsXULPrototypeElement();
|
|
|
|
NS_ENSURE_TRUE(prototype, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
prototype->mNodeInfo = nodeInfo;
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
nsXULPrototypeAttribute* attrs = nullptr;
|
2011-11-03 13:39:08 -07:00
|
|
|
if (attrCount > 0) {
|
|
|
|
attrs = new nsXULPrototypeAttribute[attrCount];
|
|
|
|
}
|
|
|
|
|
|
|
|
prototype->mAttributes = attrs;
|
|
|
|
prototype->mNumAttributes = attrCount;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < attrCount; i++) {
|
2011-11-03 13:39:08 -07:00
|
|
|
rv = ReadNamespace(aStream, namespaceID);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsAutoString prefix, name, val;
|
|
|
|
rv = aStream->ReadString(prefix);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = aStream->ReadString(name);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = aStream->ReadString(val);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> nameAtom = do_GetAtom(name);
|
|
|
|
if (namespaceID == kNameSpaceID_None) {
|
|
|
|
attrs[i].mName.SetTo(nameAtom);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsCOMPtr<nsIAtom> prefixAtom;
|
|
|
|
if (!prefix.IsEmpty())
|
|
|
|
prefixAtom = do_GetAtom(prefix);
|
|
|
|
|
|
|
|
nsCOMPtr<nsINodeInfo> ni =
|
|
|
|
aNim->GetNodeInfo(nameAtom, prefixAtom,
|
|
|
|
namespaceID, nsIDOMNode::ATTRIBUTE_NODE);
|
|
|
|
attrs[i].mName.SetTo(ni);
|
|
|
|
}
|
2013-03-05 05:12:16 -08:00
|
|
|
|
2011-11-03 13:39:08 -07:00
|
|
|
rv = prototype->SetAttrAt(i, val, documentURI);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2012-07-13 14:25:01 -07:00
|
|
|
|
|
|
|
nsCOMPtr<Element> result;
|
|
|
|
nsresult rv =
|
2013-02-04 15:22:51 -08:00
|
|
|
nsXULElement::Create(prototype, aDocument, false, false, getter_AddRefs(result));
|
2012-07-13 14:25:01 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
content = result;
|
2011-11-03 13:39:08 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
#endif
|
2013-12-03 06:40:11 -08:00
|
|
|
nsCOMPtr<Element> element;
|
|
|
|
NS_NewElement(getter_AddRefs(element), nodeInfo.forget(), NOT_FROM_PARSER);
|
|
|
|
content = element;
|
2011-11-03 13:39:08 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < attrCount; i++) {
|
2011-11-03 13:39:08 -07:00
|
|
|
rv = ReadNamespace(aStream, namespaceID);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsAutoString prefix, name, val;
|
|
|
|
rv = aStream->ReadString(prefix);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = aStream->ReadString(name);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = aStream->ReadString(val);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> prefixAtom;
|
|
|
|
if (!prefix.IsEmpty())
|
|
|
|
prefixAtom = do_GetAtom(prefix);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> nameAtom = do_GetAtom(name);
|
|
|
|
content->SetAttr(namespaceID, nameAtom, prefixAtom, val, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MOZ_XUL
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Now read the attribute forwarding entries (xbl:inherits)
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t srcNamespaceID, destNamespaceID;
|
2011-11-03 13:39:08 -07:00
|
|
|
rv = ReadNamespace(aStream, srcNamespaceID);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
while (srcNamespaceID != XBLBinding_Serialize_NoMoreAttributes) {
|
|
|
|
nsAutoString srcAttribute, destAttribute;
|
|
|
|
rv = aStream->ReadString(srcAttribute);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = ReadNamespace(aStream, destNamespaceID);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = aStream->ReadString(destAttribute);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> srcAtom = do_GetAtom(srcAttribute);
|
|
|
|
nsCOMPtr<nsIAtom> destAtom = do_GetAtom(destAttribute);
|
|
|
|
|
|
|
|
EnsureAttributeTable();
|
|
|
|
AddToAttributeTable(srcNamespaceID, srcAtom, destNamespaceID, destAtom, content);
|
|
|
|
|
|
|
|
rv = ReadNamespace(aStream, srcNamespaceID);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finally, read in the child nodes.
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t childCount;
|
2011-11-03 13:39:08 -07:00
|
|
|
rv = aStream->Read32(&childCount);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < childCount; i++) {
|
2011-11-03 13:39:08 -07:00
|
|
|
nsCOMPtr<nsIContent> child;
|
|
|
|
ReadContentNode(aStream, aDocument, aNim, getter_AddRefs(child));
|
|
|
|
|
|
|
|
// Child may be null if this was a comment for example and can just be ignored.
|
|
|
|
if (child) {
|
|
|
|
content->AppendChildTo(child, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
content.swap(*aContent);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This structure holds information about a forwarded attribute that needs to be
|
|
|
|
// written out. This is used because we need several fields passed within the
|
|
|
|
// enumeration closure.
|
|
|
|
struct WriteAttributeData
|
|
|
|
{
|
|
|
|
nsXBLPrototypeBinding* binding;
|
|
|
|
nsIObjectOutputStream* stream;
|
|
|
|
nsIContent* content;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t srcNamespace;
|
2011-11-03 13:39:08 -07:00
|
|
|
|
|
|
|
WriteAttributeData(nsXBLPrototypeBinding* aBinding,
|
|
|
|
nsIObjectOutputStream* aStream,
|
|
|
|
nsIContent* aContent)
|
|
|
|
: binding(aBinding), stream(aStream), content(aContent)
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
static
|
|
|
|
bool
|
|
|
|
WriteAttribute(nsHashKey *aKey, void *aData, void* aClosure)
|
|
|
|
{
|
|
|
|
WriteAttributeData* data = static_cast<WriteAttributeData *>(aClosure);
|
|
|
|
nsIObjectOutputStream* stream = data->stream;
|
2012-08-22 08:56:38 -07:00
|
|
|
const int32_t srcNamespace = data->srcNamespace;
|
2011-11-03 13:39:08 -07:00
|
|
|
|
|
|
|
nsXBLAttributeEntry* entry = static_cast<nsXBLAttributeEntry *>(aData);
|
|
|
|
do {
|
|
|
|
if (entry->GetElement() == data->content) {
|
|
|
|
data->binding->WriteNamespace(stream, srcNamespace);
|
|
|
|
stream->WriteWStringZ(nsDependentAtomString(entry->GetSrcAttribute()).get());
|
|
|
|
data->binding->WriteNamespace(stream, entry->GetDstNameSpace());
|
|
|
|
stream->WriteWStringZ(nsDependentAtomString(entry->GetDstAttribute()).get());
|
|
|
|
}
|
|
|
|
|
|
|
|
entry = entry->GetNext();
|
|
|
|
} while (entry);
|
|
|
|
|
|
|
|
return kHashEnumerateNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
// WriteAttributeNS is the callback to enumerate over the attribute
|
|
|
|
// forwarding entries. Since these are stored in a hash of hashes,
|
|
|
|
// we need to iterate over the inner hashes, calling WriteAttribute
|
|
|
|
// to do the actual work.
|
|
|
|
static
|
|
|
|
bool
|
|
|
|
WriteAttributeNS(nsHashKey *aKey, void *aData, void* aClosure)
|
|
|
|
{
|
|
|
|
WriteAttributeData* data = static_cast<WriteAttributeData *>(aClosure);
|
|
|
|
data->srcNamespace = static_cast<nsPRUint32Key *>(aKey)->GetValue();
|
|
|
|
|
|
|
|
nsObjectHashtable* attributes = static_cast<nsObjectHashtable*>(aData);
|
|
|
|
attributes->Enumerate(WriteAttribute, data);
|
|
|
|
|
|
|
|
return kHashEnumerateNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXBLPrototypeBinding::WriteContentNode(nsIObjectOutputStream* aStream,
|
2013-05-01 15:50:08 -07:00
|
|
|
nsIContent* aNode)
|
2011-11-03 13:39:08 -07:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
if (!aNode->IsElement()) {
|
|
|
|
// Text is writen out as a single byte for the type, followed by the text.
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t type = XBLBinding_Serialize_NoContent;
|
2011-11-03 13:39:08 -07:00
|
|
|
switch (aNode->NodeType()) {
|
|
|
|
case nsIDOMNode::TEXT_NODE:
|
|
|
|
type = XBLBinding_Serialize_TextNode;
|
|
|
|
break;
|
|
|
|
case nsIDOMNode::CDATA_SECTION_NODE:
|
|
|
|
type = XBLBinding_Serialize_CDATANode;
|
|
|
|
break;
|
|
|
|
case nsIDOMNode::COMMENT_NODE:
|
|
|
|
type = XBLBinding_Serialize_CommentNode;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = aStream->Write8(type);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsAutoString content;
|
|
|
|
aNode->GetText()->AppendTo(content);
|
|
|
|
return aStream->WriteWStringZ(content.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, this is an element.
|
|
|
|
|
|
|
|
// Write the namespace id followed by the tag name
|
|
|
|
rv = WriteNamespace(aStream, aNode->GetNameSpaceID());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsAutoString prefixStr;
|
|
|
|
aNode->NodeInfo()->GetPrefix(prefixStr);
|
|
|
|
rv = aStream->WriteWStringZ(prefixStr.get());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = aStream->WriteWStringZ(nsDependentAtomString(aNode->Tag()).get());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Write attributes
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t count = aNode->GetAttrCount();
|
2011-11-03 13:39:08 -07:00
|
|
|
rv = aStream->Write32(count);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t i;
|
2011-11-03 13:39:08 -07:00
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
// Write out the namespace id, the namespace prefix, the local tag name,
|
|
|
|
// and the value, in that order.
|
|
|
|
|
|
|
|
const nsAttrName* attr = aNode->GetAttrNameAt(i);
|
|
|
|
|
|
|
|
// XXXndeakin don't write out xbl:inherits?
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t namespaceID = attr->NamespaceID();
|
2011-11-03 13:39:08 -07:00
|
|
|
rv = WriteNamespace(aStream, namespaceID);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsAutoString prefixStr;
|
|
|
|
nsIAtom* prefix = attr->GetPrefix();
|
|
|
|
if (prefix)
|
|
|
|
prefix->ToString(prefixStr);
|
|
|
|
rv = aStream->WriteWStringZ(prefixStr.get());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = aStream->WriteWStringZ(nsDependentAtomString(attr->LocalName()).get());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsAutoString val;
|
|
|
|
aNode->GetAttr(attr->NamespaceID(), attr->LocalName(), val);
|
|
|
|
rv = aStream->WriteWStringZ(val.get());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write out the attribute fowarding information
|
|
|
|
if (mAttributeTable) {
|
|
|
|
WriteAttributeData data(this, aStream, aNode);
|
|
|
|
mAttributeTable->Enumerate(WriteAttributeNS, &data);
|
|
|
|
}
|
|
|
|
rv = aStream->Write8(XBLBinding_Serialize_NoMoreAttributes);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Finally, write out the child nodes.
|
|
|
|
count = aNode->GetChildCount();
|
|
|
|
rv = aStream->Write32(count);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
2013-05-01 15:50:08 -07:00
|
|
|
rv = WriteContentNode(aStream, aNode->GetChildAt(i));
|
2011-11-03 13:39:08 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXBLPrototypeBinding::ReadNamespace(nsIObjectInputStream* aStream,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t& aNameSpaceID)
|
2011-11-03 13:39:08 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t namespaceID;
|
2011-11-03 13:39:08 -07:00
|
|
|
nsresult rv = aStream->Read8(&namespaceID);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (namespaceID == XBLBinding_Serialize_CustomNamespace) {
|
|
|
|
nsAutoString namesp;
|
|
|
|
rv = aStream->ReadString(namesp);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsContentUtils::NameSpaceManager()->RegisterNameSpace(namesp, aNameSpaceID);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aNameSpaceID = namespaceID;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXBLPrototypeBinding::WriteNamespace(nsIObjectOutputStream* aStream,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aNameSpaceID)
|
2011-11-03 13:39:08 -07:00
|
|
|
{
|
|
|
|
// Namespaces are stored as a single byte id for well-known namespaces.
|
|
|
|
// This saves time and space as other namespaces aren't very common in
|
|
|
|
// XBL. If another namespace is used however, the namespace id will be
|
|
|
|
// XBLBinding_Serialize_CustomNamespace and the string namespace written
|
|
|
|
// out directly afterwards.
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
if (aNameSpaceID <= kNameSpaceID_LastBuiltin) {
|
2012-08-22 08:56:38 -07:00
|
|
|
rv = aStream->Write8((int8_t)aNameSpaceID);
|
2011-11-03 13:39:08 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rv = aStream->Write8(XBLBinding_Serialize_CustomNamespace);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsAutoString namesp;
|
|
|
|
nsContentUtils::NameSpaceManager()->GetNameSpaceURI(aNameSpaceID, namesp);
|
|
|
|
aStream->WriteWStringZ(namesp.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
bool CheckTagNameWhiteList(int32_t aNameSpaceID, nsIAtom *aTagName)
|
2011-11-03 13:39:07 -07:00
|
|
|
{
|
|
|
|
static nsIContent::AttrValuesArray kValidXULTagNames[] = {
|
|
|
|
&nsGkAtoms::autorepeatbutton, &nsGkAtoms::box, &nsGkAtoms::browser,
|
|
|
|
&nsGkAtoms::button, &nsGkAtoms::hbox, &nsGkAtoms::image, &nsGkAtoms::menu,
|
|
|
|
&nsGkAtoms::menubar, &nsGkAtoms::menuitem, &nsGkAtoms::menupopup,
|
|
|
|
&nsGkAtoms::row, &nsGkAtoms::slider, &nsGkAtoms::spacer,
|
2012-07-30 07:20:58 -07:00
|
|
|
&nsGkAtoms::splitter, &nsGkAtoms::text, &nsGkAtoms::tree, nullptr};
|
2011-11-03 13:39:07 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t i;
|
2011-11-03 13:39:07 -07:00
|
|
|
if (aNameSpaceID == kNameSpaceID_XUL) {
|
|
|
|
for (i = 0; kValidXULTagNames[i]; ++i) {
|
|
|
|
if (aTagName == *(kValidXULTagNames[i])) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (aNameSpaceID == kNameSpaceID_SVG &&
|
2012-03-22 07:18:41 -07:00
|
|
|
aTagName == nsGkAtoms::generic_) {
|
2011-11-03 13:39:07 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXBLPrototypeBinding::ResolveBaseBinding()
|
|
|
|
{
|
|
|
|
if (mCheckedBaseProto)
|
|
|
|
return NS_OK;
|
|
|
|
mCheckedBaseProto = true;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc = mXBLDocInfoWeak->GetDocument();
|
|
|
|
|
|
|
|
// Check for the presence of 'extends' and 'display' attributes
|
|
|
|
nsAutoString display, extends;
|
|
|
|
mBinding->GetAttr(kNameSpaceID_None, nsGkAtoms::extends, extends);
|
|
|
|
if (extends.IsEmpty())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
mBinding->GetAttr(kNameSpaceID_None, nsGkAtoms::display, display);
|
|
|
|
bool hasDisplay = !display.IsEmpty();
|
|
|
|
|
|
|
|
nsAutoString value(extends);
|
|
|
|
|
|
|
|
// Now slice 'em up to see what we've got.
|
|
|
|
nsAutoString prefix;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t offset;
|
2011-11-03 13:39:07 -07:00
|
|
|
if (hasDisplay) {
|
|
|
|
offset = display.FindChar(':');
|
|
|
|
if (-1 != offset) {
|
|
|
|
display.Left(prefix, offset);
|
|
|
|
display.Cut(0, offset+1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
offset = extends.FindChar(':');
|
|
|
|
if (-1 != offset) {
|
|
|
|
extends.Left(prefix, offset);
|
|
|
|
extends.Cut(0, offset+1);
|
|
|
|
display = extends;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString nameSpace;
|
|
|
|
|
|
|
|
if (!prefix.IsEmpty()) {
|
|
|
|
mBinding->LookupNamespaceURI(prefix, nameSpace);
|
|
|
|
if (!nameSpace.IsEmpty()) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t nameSpaceID =
|
2011-11-03 13:39:07 -07:00
|
|
|
nsContentUtils::NameSpaceManager()->GetNameSpaceID(nameSpace);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> tagName = do_GetAtom(display);
|
|
|
|
// Check the white list
|
|
|
|
if (!CheckTagNameWhiteList(nameSpaceID, tagName)) {
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t* params[] = { display.get() };
|
2011-12-15 06:47:03 -08:00
|
|
|
nsContentUtils::ReportToConsole(nsIScriptError::errorFlag,
|
2013-08-21 12:28:26 -07:00
|
|
|
NS_LITERAL_CSTRING("XBL"), nullptr,
|
2011-12-15 06:47:03 -08:00
|
|
|
nsContentUtils::eXBL_PROPERTIES,
|
2011-11-03 13:39:07 -07:00
|
|
|
"InvalidExtendsBinding",
|
2011-12-15 06:47:03 -08:00
|
|
|
params, ArrayLength(params),
|
|
|
|
doc->GetDocumentURI());
|
2011-11-03 13:39:07 -07:00
|
|
|
NS_ASSERTION(!nsXBLService::IsChromeOrResourceURI(doc->GetDocumentURI()),
|
|
|
|
"Invalid extends value");
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetBaseTag(nameSpaceID, tagName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasDisplay || nameSpace.IsEmpty()) {
|
|
|
|
mBinding->UnsetAttr(kNameSpaceID_None, nsGkAtoms::extends, false);
|
|
|
|
mBinding->UnsetAttr(kNameSpaceID_None, nsGkAtoms::display, false);
|
|
|
|
|
|
|
|
return NS_NewURI(getter_AddRefs(mBaseBindingURI), value,
|
|
|
|
doc->GetDocumentCharacterSet().get(),
|
|
|
|
doc->GetDocBaseURI());
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|