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 "nsXBLContentSink.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsBindingManager.h"
|
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsGkAtoms.h"
|
2014-02-27 15:04:46 -08:00
|
|
|
#include "nsNameSpaceManager.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsTextFragment.h"
|
|
|
|
#ifdef MOZ_XUL
|
|
|
|
#include "nsXULElement.h"
|
|
|
|
#endif
|
|
|
|
#include "nsXBLProtoImplProperty.h"
|
|
|
|
#include "nsXBLProtoImplMethod.h"
|
|
|
|
#include "nsXBLProtoImplField.h"
|
|
|
|
#include "nsXBLPrototypeBinding.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsIConsoleService.h"
|
|
|
|
#include "nsIScriptError.h"
|
|
|
|
#include "nsNodeInfoManager.h"
|
|
|
|
#include "nsIPrincipal.h"
|
2010-05-05 11:18:05 -07:00
|
|
|
#include "mozilla/dom/Element.h"
|
2010-04-30 06:12:05 -07:00
|
|
|
|
2011-10-10 22:50:08 -07:00
|
|
|
using namespace mozilla;
|
2010-04-30 06:12:05 -07:00
|
|
|
using namespace mozilla::dom;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewXBLContentSink(nsIXMLContentSink** aResult,
|
|
|
|
nsIDocument* aDoc,
|
|
|
|
nsIURI* aURI,
|
|
|
|
nsISupports* aContainer)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
|
2015-03-12 10:20:29 -07:00
|
|
|
nsRefPtr<nsXBLContentSink> it = new nsXBLContentSink();
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult rv = it->Init(aDoc, aURI, aContainer);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2015-03-12 10:20:29 -07:00
|
|
|
it.forget(aResult);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsXBLContentSink::nsXBLContentSink()
|
|
|
|
: mState(eXBL_InDocument),
|
|
|
|
mSecondaryState(eXBL_None),
|
2012-07-30 07:20:58 -07:00
|
|
|
mDocInfo(nullptr),
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsChromeOrResource(false),
|
2013-08-21 16:45:52 -07:00
|
|
|
mFoundFirstBinding(false),
|
2012-07-30 07:20:58 -07:00
|
|
|
mBinding(nullptr),
|
|
|
|
mHandler(nullptr),
|
|
|
|
mImplementation(nullptr),
|
|
|
|
mImplMember(nullptr),
|
|
|
|
mImplField(nullptr),
|
|
|
|
mProperty(nullptr),
|
|
|
|
mMethod(nullptr),
|
|
|
|
mField(nullptr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
mPrettyPrintXML = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsXBLContentSink::~nsXBLContentSink()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXBLContentSink::Init(nsIDocument* aDoc,
|
|
|
|
nsIURI* aURI,
|
|
|
|
nsISupports* aContainer)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
2012-07-30 07:20:58 -07:00
|
|
|
rv = nsXMLContentSink::Init(aDoc, aURI, aContainer, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsXBLContentSink::MaybeStartLayout(bool aIgnorePendingSheets)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2011-09-28 23:19:26 -07:00
|
|
|
nsXBLContentSink::FlushText(bool aReleaseTextNode)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-10-15 14:29:35 -07:00
|
|
|
if (mTextLength != 0) {
|
|
|
|
const nsASingleFragmentString& text = Substring(mText, mText+mTextLength);
|
|
|
|
if (mState == eXBL_InHandlers) {
|
|
|
|
NS_ASSERTION(mBinding, "Must have binding here");
|
|
|
|
// Get the text and add it to the event handler.
|
|
|
|
if (mSecondaryState == eXBL_InHandler)
|
|
|
|
mHandler->AppendHandlerText(text);
|
|
|
|
mTextLength = 0;
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-10-15 14:29:35 -07:00
|
|
|
else if (mState == eXBL_InImplementation) {
|
|
|
|
NS_ASSERTION(mBinding, "Must have binding here");
|
|
|
|
if (mSecondaryState == eXBL_InConstructor ||
|
|
|
|
mSecondaryState == eXBL_InDestructor) {
|
|
|
|
// Construct a method for the constructor/destructor.
|
|
|
|
nsXBLProtoImplMethod* method;
|
|
|
|
if (mSecondaryState == eXBL_InConstructor)
|
|
|
|
method = mBinding->GetConstructor();
|
|
|
|
else
|
|
|
|
method = mBinding->GetDestructor();
|
|
|
|
|
|
|
|
// Get the text and add it to the constructor/destructor.
|
|
|
|
method->AppendBodyText(text);
|
|
|
|
}
|
|
|
|
else if (mSecondaryState == eXBL_InGetter ||
|
|
|
|
mSecondaryState == eXBL_InSetter) {
|
|
|
|
// Get the text and add it to the getter/setter
|
|
|
|
if (mSecondaryState == eXBL_InGetter)
|
|
|
|
mProperty->AppendGetterText(text);
|
|
|
|
else
|
|
|
|
mProperty->AppendSetterText(text);
|
|
|
|
}
|
|
|
|
else if (mSecondaryState == eXBL_InBody) {
|
|
|
|
// Get the text and add it to the method
|
|
|
|
if (mMethod)
|
|
|
|
mMethod->AppendBodyText(text);
|
|
|
|
}
|
|
|
|
else if (mSecondaryState == eXBL_InField) {
|
|
|
|
// Get the text and add it to the method
|
2008-10-20 09:20:01 -07:00
|
|
|
if (mField)
|
|
|
|
mField->AppendFieldText(text);
|
2008-10-15 14:29:35 -07:00
|
|
|
}
|
|
|
|
mTextLength = 0;
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-10-15 14:29:35 -07:00
|
|
|
nsIContent* content = GetCurrentContent();
|
|
|
|
if (content &&
|
|
|
|
(content->NodeInfo()->NamespaceEquals(kNameSpaceID_XBL) ||
|
2015-03-03 03:09:00 -08:00
|
|
|
(content->IsXULElement() &&
|
|
|
|
!content->IsAnyOfXULElements(nsGkAtoms::label,
|
|
|
|
nsGkAtoms::description)))) {
|
2008-10-15 14:29:35 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isWS = true;
|
2008-10-15 14:29:35 -07:00
|
|
|
if (mTextLength > 0) {
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t* cp = mText;
|
|
|
|
const char16_t* end = mText + mTextLength;
|
2008-10-15 14:29:35 -07:00
|
|
|
while (cp < end) {
|
2014-01-04 07:02:17 -08:00
|
|
|
char16_t ch = *cp++;
|
2012-11-30 08:04:11 -08:00
|
|
|
if (!dom::IsSpaceCharacter(ch)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
isWS = false;
|
2008-10-15 14:29:35 -07:00
|
|
|
break;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-15 14:29:35 -07:00
|
|
|
if (isWS && mTextLength > 0) {
|
|
|
|
mTextLength = 0;
|
|
|
|
// Make sure to drop the textnode, if any
|
|
|
|
return nsXMLContentSink::FlushText(aReleaseTextNode);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-15 14:29:35 -07:00
|
|
|
return nsXMLContentSink::FlushText(aReleaseTextNode);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-01-04 07:02:17 -08:00
|
|
|
nsXBLContentSink::ReportError(const char16_t* aErrorText,
|
|
|
|
const char16_t* aSourceText,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIScriptError *aError,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool *_retval)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aError && aSourceText && aErrorText, "Check arguments!!!");
|
|
|
|
|
|
|
|
// XXX FIXME This function overrides and calls on
|
|
|
|
// nsXMLContentSink::ReportError, and probably should die. See bug 347826.
|
|
|
|
|
|
|
|
// XXX We should make sure the binding has no effect, but that it also
|
|
|
|
// gets destroyed properly without leaking. Perhaps we should even
|
|
|
|
// ensure that the content that was bound is displayed with no
|
|
|
|
// binding.
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
// Report the error to stderr.
|
|
|
|
fprintf(stderr,
|
|
|
|
"\n%s\n%s\n\n",
|
|
|
|
NS_LossyConvertUTF16toASCII(aErrorText).get(),
|
|
|
|
NS_LossyConvertUTF16toASCII(aSourceText).get());
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Most of what this does won't be too useful, but whatever...
|
|
|
|
// nsXMLContentSink::ReportError will handle the console logging.
|
|
|
|
return nsXMLContentSink::ReportError(aErrorText,
|
|
|
|
aSourceText,
|
|
|
|
aError,
|
|
|
|
_retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXBLContentSink::ReportUnexpectedElement(nsIAtom* aElementName,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aLineNumber)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// XXX we should really somehow stop the parse and drop the binding
|
|
|
|
// instead of just letting the XML sink build the content model like
|
|
|
|
// we do...
|
|
|
|
mState = eXBL_Error;
|
|
|
|
nsAutoString elementName;
|
|
|
|
aElementName->ToString(elementName);
|
|
|
|
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t* params[] = { elementName.get() };
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-12-15 06:47:03 -08:00
|
|
|
return nsContentUtils::ReportToConsole(nsIScriptError::errorFlag,
|
2013-08-21 12:28:26 -07:00
|
|
|
NS_LITERAL_CSTRING("XBL Content Sink"),
|
2011-12-15 06:47:03 -08:00
|
|
|
mDocument,
|
|
|
|
nsContentUtils::eXBL_PROPERTIES,
|
2007-03-22 10:30:00 -07:00
|
|
|
"UnexpectedElement",
|
2011-10-10 22:50:08 -07:00
|
|
|
params, ArrayLength(params),
|
2012-07-30 07:20:58 -07:00
|
|
|
nullptr,
|
2007-03-22 10:30:00 -07:00
|
|
|
EmptyString() /* source line */,
|
2011-12-15 06:47:03 -08:00
|
|
|
aLineNumber);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXBLContentSink::AddMember(nsXBLProtoImplMember* aMember)
|
|
|
|
{
|
|
|
|
// Add this member to our chain.
|
|
|
|
if (mImplMember)
|
|
|
|
mImplMember->SetNext(aMember); // Already have a chain. Just append to the end.
|
|
|
|
else
|
|
|
|
mImplementation->SetMemberList(aMember); // We're the first member in the chain.
|
|
|
|
|
|
|
|
mImplMember = aMember; // Adjust our pointer to point to the new last member in the chain.
|
|
|
|
}
|
|
|
|
|
2007-09-28 06:45:01 -07:00
|
|
|
void
|
|
|
|
nsXBLContentSink::AddField(nsXBLProtoImplField* aField)
|
|
|
|
{
|
|
|
|
// Add this field to our chain.
|
|
|
|
if (mImplField)
|
|
|
|
mImplField->SetNext(aField); // Already have a chain. Just append to the end.
|
|
|
|
else
|
|
|
|
mImplementation->SetFieldList(aField); // We're the first member in the chain.
|
|
|
|
|
|
|
|
mImplField = aField; // Adjust our pointer to point to the new last field in the chain.
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2014-01-04 07:02:17 -08:00
|
|
|
nsXBLContentSink::HandleStartElement(const char16_t *aName,
|
|
|
|
const char16_t **aAtts,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aAttsCount,
|
|
|
|
uint32_t aLineNumber)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-05-30 00:36:53 -07:00
|
|
|
nsresult rv = nsXMLContentSink::HandleStartElement(aName, aAtts, aAttsCount,
|
|
|
|
aLineNumber);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (mState == eXBL_InBinding && !mBinding) {
|
2011-03-23 07:45:20 -07:00
|
|
|
rv = ConstructBinding(aLineNumber);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
// mBinding may still be null, if the binding had no id. If so,
|
|
|
|
// we'll deal with that later in the sink.
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-01-04 07:02:17 -08:00
|
|
|
nsXBLContentSink::HandleEndElement(const char16_t *aName)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
FlushText();
|
|
|
|
|
|
|
|
if (mState != eXBL_InDocument) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t nameSpaceID;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIAtom> prefix, localName;
|
|
|
|
nsContentUtils::SplitExpatName(aName, getter_AddRefs(prefix),
|
|
|
|
getter_AddRefs(localName), &nameSpaceID);
|
|
|
|
|
|
|
|
if (nameSpaceID == kNameSpaceID_XBL) {
|
|
|
|
if (mState == eXBL_Error) {
|
|
|
|
// Check whether we've opened this tag before; we may not have if
|
2010-05-13 05:19:50 -07:00
|
|
|
// it was a real XBL tag before the error occurred.
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!GetCurrentContent()->NodeInfo()->Equals(localName,
|
|
|
|
nameSpaceID)) {
|
|
|
|
// OK, this tag was never opened as far as the XML sink is
|
|
|
|
// concerned. Just drop the HandleEndElement
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mState == eXBL_InHandlers) {
|
|
|
|
if (localName == nsGkAtoms::handlers) {
|
|
|
|
mState = eXBL_InBinding;
|
2012-07-30 07:20:58 -07:00
|
|
|
mHandler = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (localName == nsGkAtoms::handler)
|
|
|
|
mSecondaryState = eXBL_None;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else if (mState == eXBL_InResources) {
|
|
|
|
if (localName == nsGkAtoms::resources)
|
|
|
|
mState = eXBL_InBinding;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else if (mState == eXBL_InImplementation) {
|
|
|
|
if (localName == nsGkAtoms::implementation)
|
|
|
|
mState = eXBL_InBinding;
|
|
|
|
else if (localName == nsGkAtoms::property) {
|
|
|
|
mSecondaryState = eXBL_None;
|
2012-07-30 07:20:58 -07:00
|
|
|
mProperty = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (localName == nsGkAtoms::method) {
|
|
|
|
mSecondaryState = eXBL_None;
|
2012-07-30 07:20:58 -07:00
|
|
|
mMethod = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (localName == nsGkAtoms::field) {
|
|
|
|
mSecondaryState = eXBL_None;
|
2012-07-30 07:20:58 -07:00
|
|
|
mField = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (localName == nsGkAtoms::constructor ||
|
|
|
|
localName == nsGkAtoms::destructor)
|
|
|
|
mSecondaryState = eXBL_None;
|
|
|
|
else if (localName == nsGkAtoms::getter ||
|
|
|
|
localName == nsGkAtoms::setter)
|
|
|
|
mSecondaryState = eXBL_InProperty;
|
|
|
|
else if (localName == nsGkAtoms::parameter ||
|
|
|
|
localName == nsGkAtoms::body)
|
|
|
|
mSecondaryState = eXBL_InMethod;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else if (mState == eXBL_InBindings &&
|
|
|
|
localName == nsGkAtoms::bindings) {
|
|
|
|
mState = eXBL_InDocument;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = nsXMLContentSink::HandleEndElement(aName);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (mState == eXBL_InBinding && localName == nsGkAtoms::binding) {
|
|
|
|
mState = eXBL_InBindings;
|
|
|
|
if (mBinding) { // See comment in HandleStartElement()
|
|
|
|
mBinding->Initialize();
|
2012-07-30 07:20:58 -07:00
|
|
|
mBinding = nullptr; // Clear our current binding ref.
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsXMLContentSink::HandleEndElement(aName);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-01-04 07:02:17 -08:00
|
|
|
nsXBLContentSink::HandleCDataSection(const char16_t *aData,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aLength)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mState == eXBL_InHandlers || mState == eXBL_InImplementation)
|
|
|
|
return AddText(aData, aLength);
|
|
|
|
return nsXMLContentSink::HandleCDataSection(aData, aLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define ENSURE_XBL_STATE(_cond) \
|
|
|
|
PR_BEGIN_MACRO \
|
2011-10-17 07:59:28 -07:00
|
|
|
if (!(_cond)) { ReportUnexpectedElement(aTagName, aLineNumber); return true; } \
|
2007-03-22 10:30:00 -07:00
|
|
|
PR_END_MACRO
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2014-01-04 07:02:17 -08:00
|
|
|
nsXBLContentSink::OnOpenContainer(const char16_t **aAtts,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aAttsCount,
|
|
|
|
int32_t aNameSpaceID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom* aTagName,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aLineNumber)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mState == eXBL_Error) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aNameSpaceID != kNameSpaceID_XBL) {
|
|
|
|
// Construct non-XBL nodes
|
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 ret = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aTagName == nsGkAtoms::bindings) {
|
|
|
|
ENSURE_XBL_STATE(mState == eXBL_InDocument);
|
2012-03-22 13:46:03 -07:00
|
|
|
|
|
|
|
NS_ASSERTION(mDocument, "Must have a document!");
|
|
|
|
nsRefPtr<nsXBLDocumentInfo> info = new nsXBLDocumentInfo(mDocument);
|
|
|
|
|
|
|
|
// We keep a weak ref. We're creating a cycle between doc/binding manager/doc info.
|
|
|
|
mDocInfo = info;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!mDocInfo) {
|
|
|
|
mState = eXBL_Error;
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
mDocument->BindingManager()->PutXBLDocumentInfo(mDocInfo);
|
|
|
|
|
|
|
|
nsIURI *uri = mDocument->GetDocumentURI();
|
2012-03-22 13:46:03 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isChrome = false;
|
|
|
|
bool isRes = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
uri->SchemeIs("chrome", &isChrome);
|
|
|
|
uri->SchemeIs("resource", &isRes);
|
|
|
|
mIsChromeOrResource = isChrome || isRes;
|
2012-03-22 13:46:03 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
mState = eXBL_InBindings;
|
|
|
|
}
|
|
|
|
else if (aTagName == nsGkAtoms::binding) {
|
|
|
|
ENSURE_XBL_STATE(mState == eXBL_InBindings);
|
|
|
|
mState = eXBL_InBinding;
|
|
|
|
}
|
|
|
|
else if (aTagName == nsGkAtoms::handlers) {
|
|
|
|
ENSURE_XBL_STATE(mState == eXBL_InBinding && mBinding);
|
|
|
|
mState = eXBL_InHandlers;
|
2011-10-17 07:59:28 -07:00
|
|
|
ret = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (aTagName == nsGkAtoms::handler) {
|
|
|
|
ENSURE_XBL_STATE(mState == eXBL_InHandlers);
|
|
|
|
mSecondaryState = eXBL_InHandler;
|
|
|
|
ConstructHandler(aAtts, aLineNumber);
|
2011-10-17 07:59:28 -07:00
|
|
|
ret = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (aTagName == nsGkAtoms::resources) {
|
|
|
|
ENSURE_XBL_STATE(mState == eXBL_InBinding && mBinding);
|
|
|
|
mState = eXBL_InResources;
|
|
|
|
// Note that this mState will cause us to return false, so no need
|
|
|
|
// to set ret to false.
|
|
|
|
}
|
|
|
|
else if (aTagName == nsGkAtoms::stylesheet || aTagName == nsGkAtoms::image) {
|
|
|
|
ENSURE_XBL_STATE(mState == eXBL_InResources);
|
|
|
|
NS_ASSERTION(mBinding, "Must have binding here");
|
|
|
|
ConstructResource(aAtts, aTagName);
|
|
|
|
}
|
|
|
|
else if (aTagName == nsGkAtoms::implementation) {
|
|
|
|
ENSURE_XBL_STATE(mState == eXBL_InBinding && mBinding);
|
|
|
|
mState = eXBL_InImplementation;
|
|
|
|
ConstructImplementation(aAtts);
|
|
|
|
// Note that this mState will cause us to return false, so no need
|
|
|
|
// to set ret to false.
|
|
|
|
}
|
|
|
|
else if (aTagName == nsGkAtoms::constructor) {
|
|
|
|
ENSURE_XBL_STATE(mState == eXBL_InImplementation &&
|
|
|
|
mSecondaryState == eXBL_None);
|
|
|
|
NS_ASSERTION(mBinding, "Must have binding here");
|
|
|
|
|
|
|
|
mSecondaryState = eXBL_InConstructor;
|
2013-08-21 16:45:52 -07:00
|
|
|
nsAutoString name;
|
|
|
|
if (!mCurrentBindingID.IsEmpty()) {
|
|
|
|
name.Assign(mCurrentBindingID);
|
|
|
|
name.AppendLiteral("_XBL_Constructor");
|
|
|
|
} else {
|
|
|
|
name.AppendLiteral("XBL_Constructor");
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXBLProtoImplAnonymousMethod* newMethod =
|
2013-08-21 16:45:52 -07:00
|
|
|
new nsXBLProtoImplAnonymousMethod(name.get());
|
2015-01-30 10:55:11 -08:00
|
|
|
newMethod->SetLineNumber(aLineNumber);
|
|
|
|
mBinding->SetConstructor(newMethod);
|
|
|
|
AddMember(newMethod);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (aTagName == nsGkAtoms::destructor) {
|
|
|
|
ENSURE_XBL_STATE(mState == eXBL_InImplementation &&
|
|
|
|
mSecondaryState == eXBL_None);
|
|
|
|
NS_ASSERTION(mBinding, "Must have binding here");
|
|
|
|
mSecondaryState = eXBL_InDestructor;
|
2013-08-21 16:45:52 -07:00
|
|
|
nsAutoString name;
|
|
|
|
if (!mCurrentBindingID.IsEmpty()) {
|
|
|
|
name.Assign(mCurrentBindingID);
|
|
|
|
name.AppendLiteral("_XBL_Destructor");
|
|
|
|
} else {
|
|
|
|
name.AppendLiteral("XBL_Destructor");
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXBLProtoImplAnonymousMethod* newMethod =
|
2013-08-21 16:45:52 -07:00
|
|
|
new nsXBLProtoImplAnonymousMethod(name.get());
|
2015-01-30 10:55:11 -08:00
|
|
|
newMethod->SetLineNumber(aLineNumber);
|
|
|
|
mBinding->SetDestructor(newMethod);
|
|
|
|
AddMember(newMethod);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (aTagName == nsGkAtoms::field) {
|
|
|
|
ENSURE_XBL_STATE(mState == eXBL_InImplementation &&
|
|
|
|
mSecondaryState == eXBL_None);
|
|
|
|
NS_ASSERTION(mBinding, "Must have binding here");
|
|
|
|
mSecondaryState = eXBL_InField;
|
|
|
|
ConstructField(aAtts, aLineNumber);
|
|
|
|
}
|
|
|
|
else if (aTagName == nsGkAtoms::property) {
|
|
|
|
ENSURE_XBL_STATE(mState == eXBL_InImplementation &&
|
|
|
|
mSecondaryState == eXBL_None);
|
|
|
|
NS_ASSERTION(mBinding, "Must have binding here");
|
|
|
|
mSecondaryState = eXBL_InProperty;
|
2012-12-17 12:22:38 -08:00
|
|
|
ConstructProperty(aAtts, aLineNumber);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (aTagName == nsGkAtoms::getter) {
|
|
|
|
ENSURE_XBL_STATE(mSecondaryState == eXBL_InProperty && mProperty);
|
|
|
|
NS_ASSERTION(mState == eXBL_InImplementation, "Unexpected state");
|
|
|
|
mProperty->SetGetterLineNumber(aLineNumber);
|
|
|
|
mSecondaryState = eXBL_InGetter;
|
|
|
|
}
|
|
|
|
else if (aTagName == nsGkAtoms::setter) {
|
|
|
|
ENSURE_XBL_STATE(mSecondaryState == eXBL_InProperty && mProperty);
|
|
|
|
NS_ASSERTION(mState == eXBL_InImplementation, "Unexpected state");
|
|
|
|
mProperty->SetSetterLineNumber(aLineNumber);
|
|
|
|
mSecondaryState = eXBL_InSetter;
|
|
|
|
}
|
|
|
|
else if (aTagName == nsGkAtoms::method) {
|
|
|
|
ENSURE_XBL_STATE(mState == eXBL_InImplementation &&
|
|
|
|
mSecondaryState == eXBL_None);
|
|
|
|
NS_ASSERTION(mBinding, "Must have binding here");
|
|
|
|
mSecondaryState = eXBL_InMethod;
|
|
|
|
ConstructMethod(aAtts);
|
|
|
|
}
|
|
|
|
else if (aTagName == nsGkAtoms::parameter) {
|
|
|
|
ENSURE_XBL_STATE(mSecondaryState == eXBL_InMethod && mMethod);
|
|
|
|
NS_ASSERTION(mState == eXBL_InImplementation, "Unexpected state");
|
|
|
|
ConstructParameter(aAtts);
|
|
|
|
}
|
|
|
|
else if (aTagName == nsGkAtoms::body) {
|
|
|
|
ENSURE_XBL_STATE(mSecondaryState == eXBL_InMethod && mMethod);
|
|
|
|
NS_ASSERTION(mState == eXBL_InImplementation, "Unexpected state");
|
|
|
|
// stash away the line number
|
|
|
|
mMethod->SetLineNumber(aLineNumber);
|
|
|
|
mSecondaryState = eXBL_InBody;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret && mState != eXBL_InResources && mState != eXBL_InImplementation;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef ENSURE_XBL_STATE
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXBLContentSink::ConstructBinding(uint32_t aLineNumber)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> binding = GetCurrentContent();
|
2013-08-21 16:45:52 -07:00
|
|
|
binding->GetAttr(kNameSpaceID_None, nsGkAtoms::id, mCurrentBindingID);
|
|
|
|
NS_ConvertUTF16toUTF8 cid(mCurrentBindingID);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
2011-11-03 13:39:08 -07:00
|
|
|
|
|
|
|
// Don't create a binding with no id. nsXBLPrototypeBinding::Read also
|
|
|
|
// performs this check.
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!cid.IsEmpty()) {
|
|
|
|
mBinding = new nsXBLPrototypeBinding();
|
2015-01-30 10:55:11 -08:00
|
|
|
|
2009-11-03 13:45:10 -08:00
|
|
|
rv = mBinding->Init(cid, mDocInfo, binding, !mFoundFirstBinding);
|
2007-11-27 12:02:42 -08:00
|
|
|
if (NS_SUCCEEDED(rv) &&
|
|
|
|
NS_SUCCEEDED(mDocInfo->SetPrototypeBinding(cid, mBinding))) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!mFoundFirstBinding) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mFoundFirstBinding = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
mDocInfo->SetFirstPrototypeBinding(mBinding);
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
binding->UnsetAttr(kNameSpaceID_None, nsGkAtoms::id, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
|
|
|
delete mBinding;
|
2012-07-30 07:20:58 -07:00
|
|
|
mBinding = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-03-23 07:45:20 -07:00
|
|
|
} else {
|
2011-12-15 06:47:03 -08:00
|
|
|
nsContentUtils::ReportToConsole(nsIScriptError::errorFlag,
|
2013-08-21 12:28:26 -07:00
|
|
|
NS_LITERAL_CSTRING("XBL Content Sink"), nullptr,
|
2011-12-15 06:47:03 -08:00
|
|
|
nsContentUtils::eXBL_PROPERTIES,
|
2012-07-30 07:20:58 -07:00
|
|
|
"MissingIdAttr", nullptr, 0,
|
2011-03-23 07:45:20 -07:00
|
|
|
mDocumentURI,
|
|
|
|
EmptyString(),
|
2011-12-15 06:47:03 -08:00
|
|
|
aLineNumber);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2014-01-04 07:02:17 -08:00
|
|
|
FindValue(const char16_t **aAtts, nsIAtom *aAtom, const char16_t **aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAtom> prefix, localName;
|
|
|
|
for (; *aAtts; aAtts += 2) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t nameSpaceID;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsContentUtils::SplitExpatName(aAtts[0], getter_AddRefs(prefix),
|
|
|
|
getter_AddRefs(localName), &nameSpaceID);
|
|
|
|
|
|
|
|
// Is this attribute one of the ones we care about?
|
|
|
|
if (nameSpaceID == kNameSpaceID_None && localName == aAtom) {
|
|
|
|
*aResult = aAtts[1];
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-01-04 07:02:17 -08:00
|
|
|
nsXBLContentSink::ConstructHandler(const char16_t **aAtts, uint32_t aLineNumber)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t* event = nullptr;
|
|
|
|
const char16_t* modifiers = nullptr;
|
|
|
|
const char16_t* button = nullptr;
|
|
|
|
const char16_t* clickcount = nullptr;
|
|
|
|
const char16_t* keycode = nullptr;
|
|
|
|
const char16_t* charcode = nullptr;
|
|
|
|
const char16_t* phase = nullptr;
|
|
|
|
const char16_t* command = nullptr;
|
|
|
|
const char16_t* action = nullptr;
|
|
|
|
const char16_t* group = nullptr;
|
|
|
|
const char16_t* preventdefault = nullptr;
|
|
|
|
const char16_t* allowuntrusted = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> prefix, localName;
|
|
|
|
for (; *aAtts; aAtts += 2) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t nameSpaceID;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsContentUtils::SplitExpatName(aAtts[0], getter_AddRefs(prefix),
|
|
|
|
getter_AddRefs(localName), &nameSpaceID);
|
|
|
|
|
|
|
|
if (nameSpaceID != kNameSpaceID_None) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Is this attribute one of the ones we care about?
|
|
|
|
if (localName == nsGkAtoms::event)
|
|
|
|
event = aAtts[1];
|
|
|
|
else if (localName == nsGkAtoms::modifiers)
|
|
|
|
modifiers = aAtts[1];
|
|
|
|
else if (localName == nsGkAtoms::button)
|
|
|
|
button = aAtts[1];
|
|
|
|
else if (localName == nsGkAtoms::clickcount)
|
|
|
|
clickcount = aAtts[1];
|
|
|
|
else if (localName == nsGkAtoms::keycode)
|
|
|
|
keycode = aAtts[1];
|
|
|
|
else if (localName == nsGkAtoms::key || localName == nsGkAtoms::charcode)
|
|
|
|
charcode = aAtts[1];
|
|
|
|
else if (localName == nsGkAtoms::phase)
|
|
|
|
phase = aAtts[1];
|
|
|
|
else if (localName == nsGkAtoms::command)
|
|
|
|
command = aAtts[1];
|
|
|
|
else if (localName == nsGkAtoms::action)
|
|
|
|
action = aAtts[1];
|
|
|
|
else if (localName == nsGkAtoms::group)
|
|
|
|
group = aAtts[1];
|
|
|
|
else if (localName == nsGkAtoms::preventdefault)
|
|
|
|
preventdefault = aAtts[1];
|
|
|
|
else if (localName == nsGkAtoms::allowuntrusted)
|
|
|
|
allowuntrusted = aAtts[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (command && !mIsChromeOrResource) {
|
|
|
|
// Make sure the XBL doc is chrome or resource if we have a command
|
|
|
|
// shorthand syntax.
|
|
|
|
mState = eXBL_Error;
|
2011-12-15 06:47:03 -08:00
|
|
|
nsContentUtils::ReportToConsole(nsIScriptError::errorFlag,
|
2013-08-21 12:28:26 -07:00
|
|
|
NS_LITERAL_CSTRING("XBL Content Sink"),
|
2011-12-15 06:47:03 -08:00
|
|
|
mDocument,
|
|
|
|
nsContentUtils::eXBL_PROPERTIES,
|
2012-07-30 07:20:58 -07:00
|
|
|
"CommandNotInChrome", nullptr, 0,
|
|
|
|
nullptr,
|
2007-03-22 10:30:00 -07:00
|
|
|
EmptyString() /* source line */,
|
2011-12-15 06:47:03 -08:00
|
|
|
aLineNumber);
|
2007-03-22 10:30:00 -07:00
|
|
|
return; // Don't even make this handler.
|
|
|
|
}
|
|
|
|
|
|
|
|
// All of our pointers are now filled in. Construct our handler with all of
|
|
|
|
// these parameters.
|
|
|
|
nsXBLPrototypeHandler* newHandler;
|
|
|
|
newHandler = new nsXBLPrototypeHandler(event, phase, action, command,
|
|
|
|
keycode, charcode, modifiers, button,
|
|
|
|
clickcount, group, preventdefault,
|
2007-12-04 23:21:18 -08:00
|
|
|
allowuntrusted, mBinding, aLineNumber);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2015-01-30 10:55:11 -08:00
|
|
|
// Add this handler to our chain of handlers.
|
|
|
|
if (mHandler) {
|
|
|
|
// Already have a chain. Just append to the end.
|
|
|
|
mHandler->SetNextHandler(newHandler);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2015-01-30 10:55:11 -08:00
|
|
|
// We're the first handler in the chain.
|
|
|
|
mBinding->SetPrototypeHandlers(newHandler);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2015-01-30 10:55:11 -08:00
|
|
|
// Adjust our mHandler pointer to point to the new last handler in the
|
|
|
|
// chain.
|
|
|
|
mHandler = newHandler;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-01-04 07:02:17 -08:00
|
|
|
nsXBLContentSink::ConstructResource(const char16_t **aAtts,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom* aResourceType)
|
|
|
|
{
|
|
|
|
if (!mBinding)
|
|
|
|
return;
|
|
|
|
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t* src = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (FindValue(aAtts, nsGkAtoms::src, &src)) {
|
|
|
|
mBinding->AddResource(aResourceType, nsDependentString(src));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-01-04 07:02:17 -08:00
|
|
|
nsXBLContentSink::ConstructImplementation(const char16_t **aAtts)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
mImplementation = nullptr;
|
|
|
|
mImplMember = nullptr;
|
|
|
|
mImplField = nullptr;
|
2007-09-28 06:45:01 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!mBinding)
|
|
|
|
return;
|
|
|
|
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t* name = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> prefix, localName;
|
|
|
|
for (; *aAtts; aAtts += 2) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t nameSpaceID;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsContentUtils::SplitExpatName(aAtts[0], getter_AddRefs(prefix),
|
|
|
|
getter_AddRefs(localName), &nameSpaceID);
|
|
|
|
|
|
|
|
if (nameSpaceID != kNameSpaceID_None) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Is this attribute one of the ones we care about?
|
|
|
|
if (localName == nsGkAtoms::name) {
|
|
|
|
name = aAtts[1];
|
|
|
|
}
|
|
|
|
else if (localName == nsGkAtoms::implements) {
|
|
|
|
// Only allow implementation of interfaces via XBL if the principal of
|
2012-10-21 23:29:55 -07:00
|
|
|
// our XBL document is the system principal.
|
|
|
|
if (nsContentUtils::IsSystemPrincipal(mDocument->NodePrincipal())) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mBinding->ConstructInterfaceTable(nsDependentString(aAtts[1]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_NewXBLProtoImpl(mBinding, name, &mImplementation);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-01-04 07:02:17 -08:00
|
|
|
nsXBLContentSink::ConstructField(const char16_t **aAtts, uint32_t aLineNumber)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t* name = nullptr;
|
|
|
|
const char16_t* readonly = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> prefix, localName;
|
|
|
|
for (; *aAtts; aAtts += 2) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t nameSpaceID;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsContentUtils::SplitExpatName(aAtts[0], getter_AddRefs(prefix),
|
|
|
|
getter_AddRefs(localName), &nameSpaceID);
|
|
|
|
|
|
|
|
if (nameSpaceID != kNameSpaceID_None) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Is this attribute one of the ones we care about?
|
|
|
|
if (localName == nsGkAtoms::name) {
|
|
|
|
name = aAtts[1];
|
|
|
|
}
|
|
|
|
else if (localName == nsGkAtoms::readonly) {
|
|
|
|
readonly = aAtts[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name) {
|
|
|
|
// All of our pointers are now filled in. Construct our field with all of
|
|
|
|
// these parameters.
|
|
|
|
mField = new nsXBLProtoImplField(name, readonly);
|
2015-01-30 10:55:11 -08:00
|
|
|
mField->SetLineNumber(aLineNumber);
|
|
|
|
AddField(mField);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-01-04 07:02:17 -08:00
|
|
|
nsXBLContentSink::ConstructProperty(const char16_t **aAtts, uint32_t aLineNumber)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t* name = nullptr;
|
|
|
|
const char16_t* readonly = nullptr;
|
|
|
|
const char16_t* onget = nullptr;
|
|
|
|
const char16_t* onset = nullptr;
|
2013-11-01 07:31:56 -07:00
|
|
|
bool exposeToUntrustedContent = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> prefix, localName;
|
|
|
|
for (; *aAtts; aAtts += 2) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t nameSpaceID;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsContentUtils::SplitExpatName(aAtts[0], getter_AddRefs(prefix),
|
|
|
|
getter_AddRefs(localName), &nameSpaceID);
|
|
|
|
|
|
|
|
if (nameSpaceID != kNameSpaceID_None) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Is this attribute one of the ones we care about?
|
|
|
|
if (localName == nsGkAtoms::name) {
|
|
|
|
name = aAtts[1];
|
|
|
|
}
|
|
|
|
else if (localName == nsGkAtoms::readonly) {
|
|
|
|
readonly = aAtts[1];
|
|
|
|
}
|
|
|
|
else if (localName == nsGkAtoms::onget) {
|
|
|
|
onget = aAtts[1];
|
|
|
|
}
|
|
|
|
else if (localName == nsGkAtoms::onset) {
|
|
|
|
onset = aAtts[1];
|
|
|
|
}
|
2013-11-01 07:31:56 -07:00
|
|
|
else if (localName == nsGkAtoms::exposeToUntrustedContent &&
|
|
|
|
nsDependentString(aAtts[1]).EqualsLiteral("true"))
|
|
|
|
{
|
|
|
|
exposeToUntrustedContent = true;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (name) {
|
|
|
|
// All of our pointers are now filled in. Construct our property with all of
|
|
|
|
// these parameters.
|
2012-12-17 12:22:38 -08:00
|
|
|
mProperty = new nsXBLProtoImplProperty(name, onget, onset, readonly, aLineNumber);
|
2013-11-01 07:31:56 -07:00
|
|
|
if (exposeToUntrustedContent) {
|
|
|
|
mProperty->SetExposeToUntrustedContent(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2013-11-01 07:31:56 -07:00
|
|
|
AddMember(mProperty);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-01-04 07:02:17 -08:00
|
|
|
nsXBLContentSink::ConstructMethod(const char16_t **aAtts)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
mMethod = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t* name = nullptr;
|
|
|
|
const char16_t* expose = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (FindValue(aAtts, nsGkAtoms::name, &name)) {
|
|
|
|
mMethod = new nsXBLProtoImplMethod(name);
|
2013-11-01 07:31:56 -07:00
|
|
|
if (FindValue(aAtts, nsGkAtoms::exposeToUntrustedContent, &expose) &&
|
|
|
|
nsDependentString(expose).EqualsLiteral("true"))
|
|
|
|
{
|
|
|
|
mMethod->SetExposeToUntrustedContent(true);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mMethod) {
|
|
|
|
AddMember(mMethod);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-01-04 07:02:17 -08:00
|
|
|
nsXBLContentSink::ConstructParameter(const char16_t **aAtts)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!mMethod)
|
|
|
|
return;
|
|
|
|
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t* name = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (FindValue(aAtts, nsGkAtoms::name, &name)) {
|
|
|
|
mMethod->AddParameter(nsDependentString(name));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-01-04 07:02:17 -08:00
|
|
|
nsXBLContentSink::CreateElement(const char16_t** aAtts, uint32_t aAttsCount,
|
2014-06-19 19:01:40 -07:00
|
|
|
mozilla::dom::NodeInfo* aNodeInfo, uint32_t aLineNumber,
|
2011-09-28 23:19:26 -07:00
|
|
|
nsIContent** aResult, bool* aAppendContent,
|
2010-10-25 05:17:38 -07:00
|
|
|
FromParser aFromParser)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
#ifdef MOZ_XUL
|
|
|
|
if (!aNodeInfo->NamespaceEquals(kNameSpaceID_XUL)) {
|
|
|
|
#endif
|
|
|
|
return nsXMLContentSink::CreateElement(aAtts, aAttsCount, aNodeInfo,
|
|
|
|
aLineNumber, aResult,
|
2008-09-25 09:58:11 -07:00
|
|
|
aAppendContent, aFromParser);
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef MOZ_XUL
|
|
|
|
}
|
|
|
|
|
2011-11-03 13:39:08 -07:00
|
|
|
// Note that this needs to match the code in nsXBLPrototypeBinding::ReadContentNode.
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
*aAppendContent = true;
|
2008-10-08 04:41:52 -07:00
|
|
|
nsRefPtr<nsXULPrototypeElement> prototype = new nsXULPrototypeElement();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
prototype->mNodeInfo = aNodeInfo;
|
|
|
|
|
|
|
|
AddAttributesToXULPrototype(aAtts, aAttsCount, prototype);
|
|
|
|
|
2010-04-30 06:12:05 -07:00
|
|
|
Element* result;
|
2013-02-04 15:22:51 -08:00
|
|
|
nsresult rv = nsXULElement::Create(prototype, mDocument, false, false, &result);
|
2010-04-30 06:12:05 -07:00
|
|
|
*aResult = result;
|
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-01-04 07:02:17 -08:00
|
|
|
nsXBLContentSink::AddAttributes(const char16_t** aAtts,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIContent* aContent)
|
|
|
|
{
|
2015-03-03 03:08:59 -08:00
|
|
|
if (aContent->IsXULElement())
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK; // Nothing to do, since the proto already has the attrs.
|
|
|
|
|
|
|
|
return nsXMLContentSink::AddAttributes(aAtts, aContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MOZ_XUL
|
|
|
|
nsresult
|
2014-01-04 07:02:17 -08:00
|
|
|
nsXBLContentSink::AddAttributesToXULPrototype(const char16_t **aAtts,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aAttsCount,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXULPrototypeElement* aElement)
|
|
|
|
{
|
|
|
|
// Add tag attributes to the element
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Create storage for the attributes
|
2012-07-30 07:20:58 -07:00
|
|
|
nsXULPrototypeAttribute* attrs = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aAttsCount > 0) {
|
|
|
|
attrs = new nsXULPrototypeAttribute[aAttsCount];
|
|
|
|
}
|
|
|
|
|
|
|
|
aElement->mAttributes = attrs;
|
|
|
|
aElement->mNumAttributes = aAttsCount;
|
|
|
|
|
|
|
|
// Copy the attributes into the prototype
|
|
|
|
nsCOMPtr<nsIAtom> prefix, localName;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t i;
|
2007-03-22 10:30:00 -07:00
|
|
|
for (i = 0; i < aAttsCount; ++i) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t nameSpaceID;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsContentUtils::SplitExpatName(aAtts[i * 2], getter_AddRefs(prefix),
|
|
|
|
getter_AddRefs(localName), &nameSpaceID);
|
|
|
|
|
|
|
|
if (nameSpaceID == kNameSpaceID_None) {
|
|
|
|
attrs[i].mName.SetTo(localName);
|
|
|
|
}
|
|
|
|
else {
|
2014-06-19 19:01:40 -07:00
|
|
|
nsRefPtr<NodeInfo> ni;
|
2011-06-14 00:56:49 -07:00
|
|
|
ni = mNodeInfoManager->GetNodeInfo(localName, prefix, nameSpaceID,
|
|
|
|
nsIDOMNode::ATTRIBUTE_NODE);
|
2007-03-22 10:30:00 -07:00
|
|
|
attrs[i].mName.SetTo(ni);
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = aElement->SetAttrAt(i, nsDependentString(aAtts[i * 2 + 1]),
|
|
|
|
mDocumentURI);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|