2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2001-11-02 04:53:13 +03:00
|
|
|
|
2013-12-09 06:52:54 +04:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2011-10-11 09:50:08 +04:00
|
|
|
|
2001-11-02 04:53:13 +03:00
|
|
|
#include "nsXBLContentSink.h"
|
|
|
|
#include "nsIDocument.h"
|
2007-02-17 02:02:08 +03:00
|
|
|
#include "nsBindingManager.h"
|
2001-11-02 04:53:13 +03:00
|
|
|
#include "nsIDOMNode.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2014-02-28 03:04:46 +04:00
|
|
|
#include "nsNameSpaceManager.h"
|
2001-11-02 04:53:13 +03:00
|
|
|
#include "nsIURI.h"
|
2001-11-02 12:29:33 +03:00
|
|
|
#include "nsTextFragment.h"
|
2003-04-11 04:56:27 +04:00
|
|
|
#ifdef MOZ_XUL
|
2001-11-03 13:12:20 +03:00
|
|
|
#include "nsXULElement.h"
|
2003-04-11 04:56:27 +04:00
|
|
|
#endif
|
2001-11-13 07:09:56 +03:00
|
|
|
#include "nsXBLProtoImplProperty.h"
|
|
|
|
#include "nsXBLProtoImplMethod.h"
|
|
|
|
#include "nsXBLProtoImplField.h"
|
2003-03-07 02:59:18 +03:00
|
|
|
#include "nsXBLPrototypeBinding.h"
|
2004-09-14 21:26:35 +04:00
|
|
|
#include "nsContentUtils.h"
|
2002-08-06 16:55:44 +04:00
|
|
|
#include "nsIConsoleService.h"
|
|
|
|
#include "nsIScriptError.h"
|
2004-06-25 16:26:02 +04:00
|
|
|
#include "nsNodeInfoManager.h"
|
2005-08-26 18:47:35 +04:00
|
|
|
#include "nsIPrincipal.h"
|
2010-05-05 22:18:05 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2010-04-30 17:12:05 +04:00
|
|
|
|
2011-10-11 09:50:08 +04:00
|
|
|
using namespace mozilla;
|
2010-04-30 17:12:05 +04:00
|
|
|
using namespace mozilla::dom;
|
2001-11-03 13:12:20 +03:00
|
|
|
|
2001-11-02 04:53:13 +03:00
|
|
|
nsresult
|
|
|
|
NS_NewXBLContentSink(nsIXMLContentSink** aResult,
|
|
|
|
nsIDocument* aDoc,
|
2004-01-10 02:54:21 +03:00
|
|
|
nsIURI* aURI,
|
2003-04-03 22:57:33 +04:00
|
|
|
nsISupports* aContainer)
|
2001-11-02 04:53:13 +03:00
|
|
|
{
|
2002-12-11 17:24:49 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsXBLContentSink> it = new nsXBLContentSink();
|
2004-01-10 02:54:21 +03:00
|
|
|
nsresult rv = it->Init(aDoc, aURI, aContainer);
|
2002-12-11 17:24:49 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2015-03-12 20:20:29 +03:00
|
|
|
it.forget(aResult);
|
|
|
|
return NS_OK;
|
2001-11-02 04:53:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsXBLContentSink::nsXBLContentSink()
|
2003-02-28 04:04:45 +03:00
|
|
|
: mState(eXBL_InDocument),
|
|
|
|
mSecondaryState(eXBL_None),
|
2012-07-30 18:20:58 +04:00
|
|
|
mDocInfo(nullptr),
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsChromeOrResource(false),
|
2013-08-22 03:45:52 +04:00
|
|
|
mFoundFirstBinding(false),
|
2012-07-30 18:20:58 +04:00
|
|
|
mBinding(nullptr),
|
|
|
|
mHandler(nullptr),
|
|
|
|
mImplementation(nullptr),
|
|
|
|
mImplMember(nullptr),
|
|
|
|
mImplField(nullptr),
|
|
|
|
mProperty(nullptr),
|
|
|
|
mMethod(nullptr),
|
|
|
|
mField(nullptr)
|
2001-11-02 04:53:13 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
mPrettyPrintXML = false;
|
2001-11-02 04:53:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsXBLContentSink::~nsXBLContentSink()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXBLContentSink::Init(nsIDocument* aDoc,
|
2004-01-10 02:54:21 +03:00
|
|
|
nsIURI* aURI,
|
2003-04-03 22:57:33 +04:00
|
|
|
nsISupports* aContainer)
|
2001-11-02 04:53:13 +03:00
|
|
|
{
|
|
|
|
nsresult rv;
|
2012-07-30 18:20:58 +04:00
|
|
|
rv = nsXMLContentSink::Init(aDoc, aURI, aContainer, nullptr);
|
2001-11-02 04:53:13 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2007-01-31 00:21:06 +03:00
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsXBLContentSink::MaybeStartLayout(bool aIgnorePendingSheets)
|
2007-01-31 00:21:06 +03:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-11-02 12:29:33 +03:00
|
|
|
nsresult
|
2011-09-29 10:19:26 +04:00
|
|
|
nsXBLContentSink::FlushText(bool aReleaseTextNode)
|
2001-11-02 12:29:33 +03:00
|
|
|
{
|
2008-10-16 01:29:35 +04: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;
|
2001-11-13 07:09:56 +03:00
|
|
|
}
|
2008-10-16 01:29:35 +04: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 20:20:01 +04:00
|
|
|
if (mField)
|
|
|
|
mField->AppendFieldText(text);
|
2008-10-16 01:29:35 +04:00
|
|
|
}
|
|
|
|
mTextLength = 0;
|
|
|
|
return NS_OK;
|
2001-11-14 04:37:43 +03:00
|
|
|
}
|
|
|
|
|
2008-10-16 01:29:35 +04:00
|
|
|
nsIContent* content = GetCurrentContent();
|
|
|
|
if (content &&
|
|
|
|
(content->NodeInfo()->NamespaceEquals(kNameSpaceID_XBL) ||
|
2015-03-03 14:09:00 +03:00
|
|
|
(content->IsXULElement() &&
|
|
|
|
!content->IsAnyOfXULElements(nsGkAtoms::label,
|
|
|
|
nsGkAtoms::description)))) {
|
2008-10-16 01:29:35 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isWS = true;
|
2008-10-16 01:29:35 +04:00
|
|
|
if (mTextLength > 0) {
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* cp = mText;
|
|
|
|
const char16_t* end = mText + mTextLength;
|
2008-10-16 01:29:35 +04:00
|
|
|
while (cp < end) {
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t ch = *cp++;
|
2012-11-30 20:04:11 +04:00
|
|
|
if (!dom::IsSpaceCharacter(ch)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
isWS = false;
|
2008-10-16 01:29:35 +04:00
|
|
|
break;
|
|
|
|
}
|
2004-01-11 02:40:54 +03:00
|
|
|
}
|
2001-11-02 04:53:13 +03:00
|
|
|
}
|
2001-11-13 07:09:56 +03:00
|
|
|
|
2008-10-16 01:29:35 +04:00
|
|
|
if (isWS && mTextLength > 0) {
|
|
|
|
mTextLength = 0;
|
|
|
|
// Make sure to drop the textnode, if any
|
|
|
|
return nsXMLContentSink::FlushText(aReleaseTextNode);
|
|
|
|
}
|
2004-01-11 02:40:54 +03:00
|
|
|
}
|
2001-11-02 04:53:13 +03:00
|
|
|
}
|
|
|
|
|
2008-10-16 01:29:35 +04:00
|
|
|
return nsXMLContentSink::FlushText(aReleaseTextNode);
|
2001-11-02 04:53:13 +03:00
|
|
|
}
|
|
|
|
|
2002-08-06 16:55:44 +04:00
|
|
|
NS_IMETHODIMP
|
2014-01-04 19:02:17 +04:00
|
|
|
nsXBLContentSink::ReportError(const char16_t* aErrorText,
|
|
|
|
const char16_t* aSourceText,
|
2006-08-25 20:34:57 +04:00
|
|
|
nsIScriptError *aError,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool *_retval)
|
2002-08-06 16:55:44 +04:00
|
|
|
{
|
2006-08-25 20:34:57 +04: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.
|
|
|
|
|
2002-08-06 16:55:44 +04:00
|
|
|
// 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",
|
2006-02-03 17:18:39 +03:00
|
|
|
NS_LossyConvertUTF16toASCII(aErrorText).get(),
|
|
|
|
NS_LossyConvertUTF16toASCII(aSourceText).get());
|
2002-08-06 16:55:44 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Most of what this does won't be too useful, but whatever...
|
2006-08-25 20:34:57 +04:00
|
|
|
// nsXMLContentSink::ReportError will handle the console logging.
|
2006-01-21 05:02:02 +03:00
|
|
|
return nsXMLContentSink::ReportError(aErrorText,
|
|
|
|
aSourceText,
|
2006-08-25 20:34:57 +04:00
|
|
|
aError,
|
|
|
|
_retval);
|
2002-08-06 16:55:44 +04:00
|
|
|
}
|
|
|
|
|
2004-01-06 21:30:45 +03:00
|
|
|
nsresult
|
|
|
|
nsXBLContentSink::ReportUnexpectedElement(nsIAtom* aElementName,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aLineNumber)
|
2004-01-06 21:30:45 +03: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 19:02:17 +04:00
|
|
|
const char16_t* params[] = { elementName.get() };
|
2004-01-06 21:30:45 +03:00
|
|
|
|
2011-12-15 18:47:03 +04:00
|
|
|
return nsContentUtils::ReportToConsole(nsIScriptError::errorFlag,
|
2013-08-21 23:28:26 +04:00
|
|
|
NS_LITERAL_CSTRING("XBL Content Sink"),
|
2011-12-15 18:47:03 +04:00
|
|
|
mDocument,
|
|
|
|
nsContentUtils::eXBL_PROPERTIES,
|
2004-09-14 21:26:35 +04:00
|
|
|
"UnexpectedElement",
|
2011-10-11 09:50:08 +04:00
|
|
|
params, ArrayLength(params),
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr,
|
2004-11-23 20:45:37 +03:00
|
|
|
EmptyString() /* source line */,
|
2011-12-15 18:47:03 +04:00
|
|
|
aLineNumber);
|
2004-01-06 21:30:45 +03:00
|
|
|
}
|
|
|
|
|
2004-09-10 19:29:19 +04: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 17:45:01 +04: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.
|
|
|
|
}
|
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
NS_IMETHODIMP
|
2014-01-04 19:02:17 +04:00
|
|
|
nsXBLContentSink::HandleStartElement(const char16_t *aName,
|
|
|
|
const char16_t **aAtts,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aAttsCount,
|
|
|
|
uint32_t aLineNumber)
|
2001-11-03 13:12:20 +03:00
|
|
|
{
|
2014-05-30 11:36:53 +04:00
|
|
|
nsresult rv = nsXMLContentSink::HandleStartElement(aName, aAtts, aAttsCount,
|
|
|
|
aLineNumber);
|
2002-01-09 04:37:50 +03:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2001-11-03 13:12:20 +03:00
|
|
|
|
2003-11-18 00:03:32 +03:00
|
|
|
if (mState == eXBL_InBinding && !mBinding) {
|
2011-03-23 17:45:20 +03:00
|
|
|
rv = ConstructBinding(aLineNumber);
|
2004-09-16 22:26:18 +04: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.
|
2003-11-18 00:03:32 +03:00
|
|
|
}
|
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
return rv;
|
|
|
|
}
|
2001-11-03 13:12:20 +03:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
NS_IMETHODIMP
|
2014-01-04 19:02:17 +04:00
|
|
|
nsXBLContentSink::HandleEndElement(const char16_t *aName)
|
2002-01-09 04:37:50 +03:00
|
|
|
{
|
|
|
|
FlushText();
|
2001-11-03 13:12:20 +03:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
if (mState != eXBL_InDocument) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t nameSpaceID;
|
2004-12-15 18:37:23 +03:00
|
|
|
nsCOMPtr<nsIAtom> prefix, localName;
|
|
|
|
nsContentUtils::SplitExpatName(aName, getter_AddRefs(prefix),
|
|
|
|
getter_AddRefs(localName), &nameSpaceID);
|
2001-11-03 13:12:20 +03:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
if (nameSpaceID == kNameSpaceID_XBL) {
|
2004-12-02 05:15:37 +03:00
|
|
|
if (mState == eXBL_Error) {
|
|
|
|
// Check whether we've opened this tag before; we may not have if
|
2010-05-13 16:19:50 +04:00
|
|
|
// it was a real XBL tag before the error occurred.
|
2005-09-24 22:43:15 +04:00
|
|
|
if (!GetCurrentContent()->NodeInfo()->Equals(localName,
|
|
|
|
nameSpaceID)) {
|
2004-12-02 05:15:37 +03:00
|
|
|
// 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) {
|
2006-12-26 20:47:52 +03:00
|
|
|
if (localName == nsGkAtoms::handlers) {
|
2002-01-09 04:37:50 +03:00
|
|
|
mState = eXBL_InBinding;
|
2012-07-30 18:20:58 +04:00
|
|
|
mHandler = nullptr;
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (localName == nsGkAtoms::handler)
|
2002-01-09 04:37:50 +03:00
|
|
|
mSecondaryState = eXBL_None;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else if (mState == eXBL_InResources) {
|
2006-12-26 20:47:52 +03:00
|
|
|
if (localName == nsGkAtoms::resources)
|
2002-01-09 04:37:50 +03:00
|
|
|
mState = eXBL_InBinding;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else if (mState == eXBL_InImplementation) {
|
2006-12-26 20:47:52 +03:00
|
|
|
if (localName == nsGkAtoms::implementation)
|
2002-01-09 04:37:50 +03:00
|
|
|
mState = eXBL_InBinding;
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (localName == nsGkAtoms::property) {
|
2002-01-09 04:37:50 +03:00
|
|
|
mSecondaryState = eXBL_None;
|
2012-07-30 18:20:58 +04:00
|
|
|
mProperty = nullptr;
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (localName == nsGkAtoms::method) {
|
2002-01-09 04:37:50 +03:00
|
|
|
mSecondaryState = eXBL_None;
|
2012-07-30 18:20:58 +04:00
|
|
|
mMethod = nullptr;
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (localName == nsGkAtoms::field) {
|
2002-01-09 04:37:50 +03:00
|
|
|
mSecondaryState = eXBL_None;
|
2012-07-30 18:20:58 +04:00
|
|
|
mField = nullptr;
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (localName == nsGkAtoms::constructor ||
|
|
|
|
localName == nsGkAtoms::destructor)
|
2002-01-09 04:37:50 +03:00
|
|
|
mSecondaryState = eXBL_None;
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (localName == nsGkAtoms::getter ||
|
|
|
|
localName == nsGkAtoms::setter)
|
2002-01-09 04:37:50 +03:00
|
|
|
mSecondaryState = eXBL_InProperty;
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (localName == nsGkAtoms::parameter ||
|
|
|
|
localName == nsGkAtoms::body)
|
2002-01-09 04:37:50 +03:00
|
|
|
mSecondaryState = eXBL_InMethod;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2004-12-15 18:37:23 +03:00
|
|
|
else if (mState == eXBL_InBindings &&
|
2006-12-26 20:47:52 +03:00
|
|
|
localName == nsGkAtoms::bindings) {
|
2004-01-06 21:30:45 +03:00
|
|
|
mState = eXBL_InDocument;
|
|
|
|
}
|
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
nsresult rv = nsXMLContentSink::HandleEndElement(aName);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2001-11-03 13:12:20 +03:00
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
if (mState == eXBL_InBinding && localName == nsGkAtoms::binding) {
|
2004-01-06 21:30:45 +03:00
|
|
|
mState = eXBL_InBindings;
|
2004-09-16 22:26:18 +04:00
|
|
|
if (mBinding) { // See comment in HandleStartElement()
|
|
|
|
mBinding->Initialize();
|
2012-07-30 18:20:58 +04:00
|
|
|
mBinding = nullptr; // Clear our current binding ref.
|
2004-09-16 22:26:18 +04:00
|
|
|
}
|
2001-11-03 13:12:20 +03:00
|
|
|
}
|
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
return NS_OK;
|
2001-11-03 13:12:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
return nsXMLContentSink::HandleEndElement(aName);
|
2001-11-03 13:12:20 +03:00
|
|
|
}
|
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
NS_IMETHODIMP
|
2014-01-04 19:02:17 +04:00
|
|
|
nsXBLContentSink::HandleCDataSection(const char16_t *aData,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aLength)
|
2002-01-09 04:37:50 +03:00
|
|
|
{
|
|
|
|
if (mState == eXBL_InHandlers || mState == eXBL_InImplementation)
|
|
|
|
return AddText(aData, aLength);
|
|
|
|
return nsXMLContentSink::HandleCDataSection(aData, aLength);
|
|
|
|
}
|
|
|
|
|
2005-04-22 01:31:05 +04:00
|
|
|
#define ENSURE_XBL_STATE(_cond) \
|
|
|
|
PR_BEGIN_MACRO \
|
2011-10-17 18:59:28 +04:00
|
|
|
if (!(_cond)) { ReportUnexpectedElement(aTagName, aLineNumber); return true; } \
|
2005-04-22 01:31:05 +04:00
|
|
|
PR_END_MACRO
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2014-01-04 19:02:17 +04:00
|
|
|
nsXBLContentSink::OnOpenContainer(const char16_t **aAtts,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aAttsCount,
|
|
|
|
int32_t aNameSpaceID,
|
2003-06-24 05:20:40 +04:00
|
|
|
nsIAtom* aTagName,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aLineNumber)
|
2001-11-03 13:12:20 +03:00
|
|
|
{
|
2004-01-06 21:30:45 +03:00
|
|
|
if (mState == eXBL_Error) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2004-01-06 21:30:45 +03:00
|
|
|
}
|
|
|
|
|
2005-04-22 01:31:05 +04:00
|
|
|
if (aNameSpaceID != kNameSpaceID_XBL) {
|
|
|
|
// Construct non-XBL nodes
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2005-04-22 01:31:05 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool ret = true;
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aTagName == nsGkAtoms::bindings) {
|
2005-04-22 01:31:05 +04:00
|
|
|
ENSURE_XBL_STATE(mState == eXBL_InDocument);
|
2012-03-23 00:46:03 +04:00
|
|
|
|
|
|
|
NS_ASSERTION(mDocument, "Must have a document!");
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsXBLDocumentInfo> info = new nsXBLDocumentInfo(mDocument);
|
2012-03-23 00:46:03 +04:00
|
|
|
|
|
|
|
// We keep a weak ref. We're creating a cycle between doc/binding manager/doc info.
|
|
|
|
mDocInfo = info;
|
|
|
|
|
2005-04-22 01:31:05 +04:00
|
|
|
if (!mDocInfo) {
|
|
|
|
mState = eXBL_Error;
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2005-04-22 01:31:05 +04:00
|
|
|
}
|
2001-11-05 09:45:04 +03:00
|
|
|
|
2005-04-22 01:31:05 +04:00
|
|
|
mDocument->BindingManager()->PutXBLDocumentInfo(mDocInfo);
|
2001-11-05 09:45:04 +03:00
|
|
|
|
2005-04-22 01:31:05 +04:00
|
|
|
nsIURI *uri = mDocument->GetDocumentURI();
|
2012-03-23 00:46:03 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isChrome = false;
|
|
|
|
bool isRes = false;
|
2001-11-03 13:12:20 +03:00
|
|
|
|
2005-04-22 01:31:05 +04:00
|
|
|
uri->SchemeIs("chrome", &isChrome);
|
|
|
|
uri->SchemeIs("resource", &isRes);
|
|
|
|
mIsChromeOrResource = isChrome || isRes;
|
2012-03-23 00:46:03 +04:00
|
|
|
|
2005-04-22 01:31:05 +04:00
|
|
|
mState = eXBL_InBindings;
|
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (aTagName == nsGkAtoms::binding) {
|
2005-04-22 01:31:05 +04:00
|
|
|
ENSURE_XBL_STATE(mState == eXBL_InBindings);
|
|
|
|
mState = eXBL_InBinding;
|
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (aTagName == nsGkAtoms::handlers) {
|
2005-04-22 01:31:05 +04:00
|
|
|
ENSURE_XBL_STATE(mState == eXBL_InBinding && mBinding);
|
|
|
|
mState = eXBL_InHandlers;
|
2011-10-17 18:59:28 +04:00
|
|
|
ret = false;
|
2005-04-22 01:31:05 +04:00
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (aTagName == nsGkAtoms::handler) {
|
2005-04-22 01:31:05 +04:00
|
|
|
ENSURE_XBL_STATE(mState == eXBL_InHandlers);
|
|
|
|
mSecondaryState = eXBL_InHandler;
|
|
|
|
ConstructHandler(aAtts, aLineNumber);
|
2011-10-17 18:59:28 +04:00
|
|
|
ret = false;
|
2005-04-22 01:31:05 +04:00
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (aTagName == nsGkAtoms::resources) {
|
2005-04-22 01:31:05 +04:00
|
|
|
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.
|
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (aTagName == nsGkAtoms::stylesheet || aTagName == nsGkAtoms::image) {
|
2005-04-22 01:31:05 +04:00
|
|
|
ENSURE_XBL_STATE(mState == eXBL_InResources);
|
|
|
|
NS_ASSERTION(mBinding, "Must have binding here");
|
|
|
|
ConstructResource(aAtts, aTagName);
|
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (aTagName == nsGkAtoms::implementation) {
|
2005-04-22 01:31:05 +04:00
|
|
|
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.
|
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (aTagName == nsGkAtoms::constructor) {
|
2005-04-22 01:31:05 +04:00
|
|
|
ENSURE_XBL_STATE(mState == eXBL_InImplementation &&
|
|
|
|
mSecondaryState == eXBL_None);
|
|
|
|
NS_ASSERTION(mBinding, "Must have binding here");
|
|
|
|
|
|
|
|
mSecondaryState = eXBL_InConstructor;
|
2013-08-22 03:45:52 +04:00
|
|
|
nsAutoString name;
|
|
|
|
if (!mCurrentBindingID.IsEmpty()) {
|
|
|
|
name.Assign(mCurrentBindingID);
|
|
|
|
name.AppendLiteral("_XBL_Constructor");
|
|
|
|
} else {
|
|
|
|
name.AppendLiteral("XBL_Constructor");
|
|
|
|
}
|
2005-04-22 01:31:05 +04:00
|
|
|
nsXBLProtoImplAnonymousMethod* newMethod =
|
2013-08-22 03:45:52 +04:00
|
|
|
new nsXBLProtoImplAnonymousMethod(name.get());
|
2015-01-30 21:55:11 +03:00
|
|
|
newMethod->SetLineNumber(aLineNumber);
|
|
|
|
mBinding->SetConstructor(newMethod);
|
|
|
|
AddMember(newMethod);
|
2005-04-22 01:31:05 +04:00
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (aTagName == nsGkAtoms::destructor) {
|
2005-04-22 01:31:05 +04:00
|
|
|
ENSURE_XBL_STATE(mState == eXBL_InImplementation &&
|
|
|
|
mSecondaryState == eXBL_None);
|
|
|
|
NS_ASSERTION(mBinding, "Must have binding here");
|
|
|
|
mSecondaryState = eXBL_InDestructor;
|
2013-08-22 03:45:52 +04:00
|
|
|
nsAutoString name;
|
|
|
|
if (!mCurrentBindingID.IsEmpty()) {
|
|
|
|
name.Assign(mCurrentBindingID);
|
|
|
|
name.AppendLiteral("_XBL_Destructor");
|
|
|
|
} else {
|
|
|
|
name.AppendLiteral("XBL_Destructor");
|
|
|
|
}
|
2005-04-22 01:31:05 +04:00
|
|
|
nsXBLProtoImplAnonymousMethod* newMethod =
|
2013-08-22 03:45:52 +04:00
|
|
|
new nsXBLProtoImplAnonymousMethod(name.get());
|
2015-01-30 21:55:11 +03:00
|
|
|
newMethod->SetLineNumber(aLineNumber);
|
|
|
|
mBinding->SetDestructor(newMethod);
|
|
|
|
AddMember(newMethod);
|
2001-11-03 13:12:20 +03:00
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (aTagName == nsGkAtoms::field) {
|
2005-04-22 01:31:05 +04:00
|
|
|
ENSURE_XBL_STATE(mState == eXBL_InImplementation &&
|
|
|
|
mSecondaryState == eXBL_None);
|
|
|
|
NS_ASSERTION(mBinding, "Must have binding here");
|
|
|
|
mSecondaryState = eXBL_InField;
|
|
|
|
ConstructField(aAtts, aLineNumber);
|
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (aTagName == nsGkAtoms::property) {
|
2005-04-22 01:31:05 +04:00
|
|
|
ENSURE_XBL_STATE(mState == eXBL_InImplementation &&
|
|
|
|
mSecondaryState == eXBL_None);
|
|
|
|
NS_ASSERTION(mBinding, "Must have binding here");
|
|
|
|
mSecondaryState = eXBL_InProperty;
|
2012-12-18 00:22:38 +04:00
|
|
|
ConstructProperty(aAtts, aLineNumber);
|
2005-04-22 01:31:05 +04:00
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (aTagName == nsGkAtoms::getter) {
|
2005-04-22 01:31:05 +04:00
|
|
|
ENSURE_XBL_STATE(mSecondaryState == eXBL_InProperty && mProperty);
|
|
|
|
NS_ASSERTION(mState == eXBL_InImplementation, "Unexpected state");
|
|
|
|
mProperty->SetGetterLineNumber(aLineNumber);
|
|
|
|
mSecondaryState = eXBL_InGetter;
|
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (aTagName == nsGkAtoms::setter) {
|
2005-04-22 01:31:05 +04:00
|
|
|
ENSURE_XBL_STATE(mSecondaryState == eXBL_InProperty && mProperty);
|
|
|
|
NS_ASSERTION(mState == eXBL_InImplementation, "Unexpected state");
|
|
|
|
mProperty->SetSetterLineNumber(aLineNumber);
|
|
|
|
mSecondaryState = eXBL_InSetter;
|
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (aTagName == nsGkAtoms::method) {
|
2005-04-22 01:31:05 +04:00
|
|
|
ENSURE_XBL_STATE(mState == eXBL_InImplementation &&
|
|
|
|
mSecondaryState == eXBL_None);
|
|
|
|
NS_ASSERTION(mBinding, "Must have binding here");
|
|
|
|
mSecondaryState = eXBL_InMethod;
|
|
|
|
ConstructMethod(aAtts);
|
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (aTagName == nsGkAtoms::parameter) {
|
2005-04-22 01:31:05 +04:00
|
|
|
ENSURE_XBL_STATE(mSecondaryState == eXBL_InMethod && mMethod);
|
|
|
|
NS_ASSERTION(mState == eXBL_InImplementation, "Unexpected state");
|
|
|
|
ConstructParameter(aAtts);
|
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (aTagName == nsGkAtoms::body) {
|
2005-04-22 01:31:05 +04:00
|
|
|
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;
|
|
|
|
}
|
2001-11-03 13:12:20 +03:00
|
|
|
|
2005-04-22 01:31:05 +04:00
|
|
|
return ret && mState != eXBL_InResources && mState != eXBL_InImplementation;
|
2001-11-03 13:12:20 +03:00
|
|
|
}
|
|
|
|
|
2005-04-22 01:31:05 +04:00
|
|
|
#undef ENSURE_XBL_STATE
|
|
|
|
|
2004-09-16 22:26:18 +04:00
|
|
|
nsresult
|
2012-08-22 19:56:38 +04:00
|
|
|
nsXBLContentSink::ConstructBinding(uint32_t aLineNumber)
|
2001-11-02 04:53:13 +03:00
|
|
|
{
|
2003-07-03 09:34:26 +04:00
|
|
|
nsCOMPtr<nsIContent> binding = GetCurrentContent();
|
2013-08-22 03:45:52 +04:00
|
|
|
binding->GetAttr(kNameSpaceID_None, nsGkAtoms::id, mCurrentBindingID);
|
|
|
|
NS_ConvertUTF16toUTF8 cid(mCurrentBindingID);
|
2001-11-02 04:53:13 +03:00
|
|
|
|
2004-09-16 22:26:18 +04:00
|
|
|
nsresult rv = NS_OK;
|
2011-11-04 00:39:08 +04:00
|
|
|
|
|
|
|
// Don't create a binding with no id. nsXBLPrototypeBinding::Read also
|
|
|
|
// performs this check.
|
2001-11-02 04:53:13 +03:00
|
|
|
if (!cid.IsEmpty()) {
|
2003-11-18 00:03:32 +03:00
|
|
|
mBinding = new nsXBLPrototypeBinding();
|
2015-01-30 21:55:11 +03:00
|
|
|
|
2009-11-04 00:45:10 +03:00
|
|
|
rv = mBinding->Init(cid, mDocInfo, binding, !mFoundFirstBinding);
|
2007-11-27 23:02:42 +03:00
|
|
|
if (NS_SUCCEEDED(rv) &&
|
|
|
|
NS_SUCCEEDED(mDocInfo->SetPrototypeBinding(cid, mBinding))) {
|
2007-02-24 19:27:51 +03:00
|
|
|
if (!mFoundFirstBinding) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mFoundFirstBinding = true;
|
2007-02-24 19:27:51 +03:00
|
|
|
mDocInfo->SetFirstPrototypeBinding(mBinding);
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
binding->UnsetAttr(kNameSpaceID_None, nsGkAtoms::id, false);
|
2004-09-16 22:26:18 +04:00
|
|
|
} else {
|
|
|
|
delete mBinding;
|
2012-07-30 18:20:58 +04:00
|
|
|
mBinding = nullptr;
|
2003-11-18 00:03:32 +03:00
|
|
|
}
|
2011-03-23 17:45:20 +03:00
|
|
|
} else {
|
2011-12-15 18:47:03 +04:00
|
|
|
nsContentUtils::ReportToConsole(nsIScriptError::errorFlag,
|
2013-08-21 23:28:26 +04:00
|
|
|
NS_LITERAL_CSTRING("XBL Content Sink"), nullptr,
|
2011-12-15 18:47:03 +04:00
|
|
|
nsContentUtils::eXBL_PROPERTIES,
|
2012-07-30 18:20:58 +04:00
|
|
|
"MissingIdAttr", nullptr, 0,
|
2011-03-23 17:45:20 +03:00
|
|
|
mDocumentURI,
|
|
|
|
EmptyString(),
|
2011-12-15 18:47:03 +04:00
|
|
|
aLineNumber);
|
2001-11-02 04:53:13 +03:00
|
|
|
}
|
2004-09-16 22:26:18 +04:00
|
|
|
|
|
|
|
return rv;
|
2001-11-02 04:53:13 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2014-01-04 19:02:17 +04:00
|
|
|
FindValue(const char16_t **aAtts, nsIAtom *aAtom, const char16_t **aResult)
|
2004-12-15 18:37:23 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAtom> prefix, localName;
|
|
|
|
for (; *aAtts; aAtts += 2) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t nameSpaceID;
|
2004-12-15 18:37:23 +03: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 18:59:28 +04:00
|
|
|
return true;
|
2004-12-15 18:37:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2004-12-15 18:37:23 +03:00
|
|
|
}
|
2002-01-09 04:37:50 +03:00
|
|
|
|
2001-11-02 04:53:13 +03:00
|
|
|
void
|
2014-01-04 19:02:17 +04:00
|
|
|
nsXBLContentSink::ConstructHandler(const char16_t **aAtts, uint32_t aLineNumber)
|
2001-11-02 04:53:13 +03:00
|
|
|
{
|
2014-01-04 19:02:17 +04: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;
|
2002-01-09 04:37:50 +03:00
|
|
|
|
2004-12-15 18:37:23 +03:00
|
|
|
nsCOMPtr<nsIAtom> prefix, localName;
|
2002-01-09 04:37:50 +03:00
|
|
|
for (; *aAtts; aAtts += 2) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t nameSpaceID;
|
2004-12-15 18:37:23 +03:00
|
|
|
nsContentUtils::SplitExpatName(aAtts[0], getter_AddRefs(prefix),
|
|
|
|
getter_AddRefs(localName), &nameSpaceID);
|
2001-11-02 04:53:13 +03:00
|
|
|
|
2004-12-15 18:37:23 +03:00
|
|
|
if (nameSpaceID != kNameSpaceID_None) {
|
2001-11-02 04:53:13 +03:00
|
|
|
continue;
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
2001-11-02 04:53:13 +03:00
|
|
|
|
|
|
|
// Is this attribute one of the ones we care about?
|
2006-12-26 20:47:52 +03:00
|
|
|
if (localName == nsGkAtoms::event)
|
2002-01-09 04:37:50 +03:00
|
|
|
event = aAtts[1];
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (localName == nsGkAtoms::modifiers)
|
2002-01-09 04:37:50 +03:00
|
|
|
modifiers = aAtts[1];
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (localName == nsGkAtoms::button)
|
2002-01-09 04:37:50 +03:00
|
|
|
button = aAtts[1];
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (localName == nsGkAtoms::clickcount)
|
2002-01-09 04:37:50 +03:00
|
|
|
clickcount = aAtts[1];
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (localName == nsGkAtoms::keycode)
|
2002-01-09 04:37:50 +03:00
|
|
|
keycode = aAtts[1];
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (localName == nsGkAtoms::key || localName == nsGkAtoms::charcode)
|
2002-01-09 04:37:50 +03:00
|
|
|
charcode = aAtts[1];
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (localName == nsGkAtoms::phase)
|
2002-01-09 04:37:50 +03:00
|
|
|
phase = aAtts[1];
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (localName == nsGkAtoms::command)
|
2002-01-09 04:37:50 +03:00
|
|
|
command = aAtts[1];
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (localName == nsGkAtoms::action)
|
2002-01-09 04:37:50 +03:00
|
|
|
action = aAtts[1];
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (localName == nsGkAtoms::group)
|
2005-03-30 16:26:02 +04:00
|
|
|
group = aAtts[1];
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (localName == nsGkAtoms::preventdefault)
|
2002-06-19 04:43:46 +04:00
|
|
|
preventdefault = aAtts[1];
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (localName == nsGkAtoms::allowuntrusted)
|
2005-08-22 02:20:36 +04:00
|
|
|
allowuntrusted = aAtts[1];
|
2001-11-02 04:53:13 +03:00
|
|
|
}
|
|
|
|
|
2006-12-07 05:34:57 +03:00
|
|
|
if (command && !mIsChromeOrResource) {
|
2001-11-02 04:53:13 +03:00
|
|
|
// Make sure the XBL doc is chrome or resource if we have a command
|
|
|
|
// shorthand syntax.
|
2006-12-07 05:34:57 +03:00
|
|
|
mState = eXBL_Error;
|
2011-12-15 18:47:03 +04:00
|
|
|
nsContentUtils::ReportToConsole(nsIScriptError::errorFlag,
|
2013-08-21 23:28:26 +04:00
|
|
|
NS_LITERAL_CSTRING("XBL Content Sink"),
|
2011-12-15 18:47:03 +04:00
|
|
|
mDocument,
|
|
|
|
nsContentUtils::eXBL_PROPERTIES,
|
2012-07-30 18:20:58 +04:00
|
|
|
"CommandNotInChrome", nullptr, 0,
|
|
|
|
nullptr,
|
2006-12-07 05:34:57 +03:00
|
|
|
EmptyString() /* source line */,
|
2011-12-15 18:47:03 +04:00
|
|
|
aLineNumber);
|
2001-11-02 04:53:13 +03:00
|
|
|
return; // Don't even make this handler.
|
2006-12-07 05:34:57 +03:00
|
|
|
}
|
2001-11-02 04:53:13 +03:00
|
|
|
|
2004-12-15 18:37:23 +03:00
|
|
|
// All of our pointers are now filled in. Construct our handler with all of
|
|
|
|
// these parameters.
|
2003-02-28 04:04:45 +03:00
|
|
|
nsXBLPrototypeHandler* newHandler;
|
|
|
|
newHandler = new nsXBLPrototypeHandler(event, phase, action, command,
|
|
|
|
keycode, charcode, modifiers, button,
|
2005-08-22 02:20:36 +04:00
|
|
|
clickcount, group, preventdefault,
|
2007-12-05 10:21:18 +03:00
|
|
|
allowuntrusted, mBinding, aLineNumber);
|
2003-02-28 04:04:45 +03:00
|
|
|
|
2015-01-30 21:55:11 +03:00
|
|
|
// Add this handler to our chain of handlers.
|
|
|
|
if (mHandler) {
|
|
|
|
// Already have a chain. Just append to the end.
|
|
|
|
mHandler->SetNextHandler(newHandler);
|
2006-12-07 05:34:57 +03:00
|
|
|
} else {
|
2015-01-30 21:55:11 +03:00
|
|
|
// We're the first handler in the chain.
|
|
|
|
mBinding->SetPrototypeHandlers(newHandler);
|
2001-11-02 04:53:13 +03:00
|
|
|
}
|
2015-01-30 21:55:11 +03:00
|
|
|
// Adjust our mHandler pointer to point to the new last handler in the
|
|
|
|
// chain.
|
|
|
|
mHandler = newHandler;
|
2001-11-02 04:53:13 +03:00
|
|
|
}
|
2001-11-11 04:15:22 +03:00
|
|
|
|
|
|
|
void
|
2014-01-04 19:02:17 +04:00
|
|
|
nsXBLContentSink::ConstructResource(const char16_t **aAtts,
|
2002-01-09 04:37:50 +03:00
|
|
|
nsIAtom* aResourceType)
|
2001-11-11 04:15:22 +03:00
|
|
|
{
|
|
|
|
if (!mBinding)
|
|
|
|
return;
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* src = nullptr;
|
2006-12-26 20:47:52 +03:00
|
|
|
if (FindValue(aAtts, nsGkAtoms::src, &src)) {
|
2004-12-15 18:37:23 +03:00
|
|
|
mBinding->AddResource(aResourceType, nsDependentString(src));
|
2001-11-11 04:15:22 +03:00
|
|
|
}
|
|
|
|
}
|
2001-11-13 07:09:56 +03:00
|
|
|
|
|
|
|
void
|
2014-01-04 19:02:17 +04:00
|
|
|
nsXBLContentSink::ConstructImplementation(const char16_t **aAtts)
|
2001-11-13 07:09:56 +03:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
mImplementation = nullptr;
|
|
|
|
mImplMember = nullptr;
|
|
|
|
mImplField = nullptr;
|
2007-09-28 17:45:01 +04:00
|
|
|
|
2001-11-13 07:09:56 +03:00
|
|
|
if (!mBinding)
|
|
|
|
return;
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* name = nullptr;
|
2001-11-13 07:09:56 +03:00
|
|
|
|
2004-12-15 18:37:23 +03:00
|
|
|
nsCOMPtr<nsIAtom> prefix, localName;
|
|
|
|
for (; *aAtts; aAtts += 2) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t nameSpaceID;
|
2004-12-15 18:37:23 +03:00
|
|
|
nsContentUtils::SplitExpatName(aAtts[0], getter_AddRefs(prefix),
|
|
|
|
getter_AddRefs(localName), &nameSpaceID);
|
2001-11-13 07:09:56 +03:00
|
|
|
|
2004-12-15 18:37:23 +03:00
|
|
|
if (nameSpaceID != kNameSpaceID_None) {
|
2001-11-13 07:09:56 +03:00
|
|
|
continue;
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
2001-11-13 07:09:56 +03:00
|
|
|
|
|
|
|
// Is this attribute one of the ones we care about?
|
2006-12-26 20:47:52 +03:00
|
|
|
if (localName == nsGkAtoms::name) {
|
2002-01-09 04:37:50 +03:00
|
|
|
name = aAtts[1];
|
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (localName == nsGkAtoms::implements) {
|
2005-08-26 18:47:35 +04:00
|
|
|
// Only allow implementation of interfaces via XBL if the principal of
|
2012-10-22 10:29:55 +04:00
|
|
|
// our XBL document is the system principal.
|
|
|
|
if (nsContentUtils::IsSystemPrincipal(mDocument->NodePrincipal())) {
|
2006-04-27 22:21:11 +04:00
|
|
|
mBinding->ConstructInterfaceTable(nsDependentString(aAtts[1]));
|
2005-08-26 18:47:35 +04:00
|
|
|
}
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
2001-11-13 07:09:56 +03:00
|
|
|
}
|
|
|
|
|
2002-01-10 00:50:08 +03:00
|
|
|
NS_NewXBLProtoImpl(mBinding, name, &mImplementation);
|
2001-11-13 07:09:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-01-04 19:02:17 +04:00
|
|
|
nsXBLContentSink::ConstructField(const char16_t **aAtts, uint32_t aLineNumber)
|
2001-11-13 07:09:56 +03:00
|
|
|
{
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* name = nullptr;
|
|
|
|
const char16_t* readonly = nullptr;
|
2004-12-15 18:37:23 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> prefix, localName;
|
2002-01-09 04:37:50 +03:00
|
|
|
for (; *aAtts; aAtts += 2) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t nameSpaceID;
|
2004-12-15 18:37:23 +03:00
|
|
|
nsContentUtils::SplitExpatName(aAtts[0], getter_AddRefs(prefix),
|
|
|
|
getter_AddRefs(localName), &nameSpaceID);
|
2001-11-13 07:09:56 +03:00
|
|
|
|
2004-12-15 18:37:23 +03:00
|
|
|
if (nameSpaceID != kNameSpaceID_None) {
|
2001-11-13 07:09:56 +03:00
|
|
|
continue;
|
2004-12-15 18:37:23 +03:00
|
|
|
}
|
2001-11-13 07:09:56 +03:00
|
|
|
|
|
|
|
// Is this attribute one of the ones we care about?
|
2006-12-26 20:47:52 +03:00
|
|
|
if (localName == nsGkAtoms::name) {
|
2002-01-09 04:37:50 +03:00
|
|
|
name = aAtts[1];
|
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (localName == nsGkAtoms::readonly) {
|
2002-01-09 04:37:50 +03:00
|
|
|
readonly = aAtts[1];
|
|
|
|
}
|
2001-11-13 07:09:56 +03:00
|
|
|
}
|
|
|
|
|
2005-11-28 02:51:42 +03:00
|
|
|
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 21:55:11 +03:00
|
|
|
mField->SetLineNumber(aLineNumber);
|
|
|
|
AddField(mField);
|
2001-11-13 07:09:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-01-04 19:02:17 +04:00
|
|
|
nsXBLContentSink::ConstructProperty(const char16_t **aAtts, uint32_t aLineNumber)
|
2001-11-13 07:09:56 +03:00
|
|
|
{
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* name = nullptr;
|
|
|
|
const char16_t* readonly = nullptr;
|
|
|
|
const char16_t* onget = nullptr;
|
|
|
|
const char16_t* onset = nullptr;
|
2013-11-01 18:31:56 +04:00
|
|
|
bool exposeToUntrustedContent = false;
|
2004-12-15 18:37:23 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> prefix, localName;
|
2002-01-09 04:37:50 +03:00
|
|
|
for (; *aAtts; aAtts += 2) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t nameSpaceID;
|
2004-12-15 18:37:23 +03:00
|
|
|
nsContentUtils::SplitExpatName(aAtts[0], getter_AddRefs(prefix),
|
|
|
|
getter_AddRefs(localName), &nameSpaceID);
|
2001-11-13 07:09:56 +03:00
|
|
|
|
2004-12-15 18:37:23 +03:00
|
|
|
if (nameSpaceID != kNameSpaceID_None) {
|
2001-11-13 07:09:56 +03:00
|
|
|
continue;
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
2001-11-13 07:09:56 +03:00
|
|
|
|
|
|
|
// Is this attribute one of the ones we care about?
|
2006-12-26 20:47:52 +03:00
|
|
|
if (localName == nsGkAtoms::name) {
|
2002-01-09 04:37:50 +03:00
|
|
|
name = aAtts[1];
|
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (localName == nsGkAtoms::readonly) {
|
2002-01-09 04:37:50 +03:00
|
|
|
readonly = aAtts[1];
|
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (localName == nsGkAtoms::onget) {
|
2002-01-09 04:37:50 +03:00
|
|
|
onget = aAtts[1];
|
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (localName == nsGkAtoms::onset) {
|
2002-01-09 04:37:50 +03:00
|
|
|
onset = aAtts[1];
|
|
|
|
}
|
2013-11-01 18:31:56 +04:00
|
|
|
else if (localName == nsGkAtoms::exposeToUntrustedContent &&
|
|
|
|
nsDependentString(aAtts[1]).EqualsLiteral("true"))
|
|
|
|
{
|
|
|
|
exposeToUntrustedContent = true;
|
|
|
|
}
|
2001-11-13 07:09:56 +03:00
|
|
|
}
|
|
|
|
|
2005-01-20 19:44:00 +03:00
|
|
|
if (name) {
|
|
|
|
// All of our pointers are now filled in. Construct our property with all of
|
|
|
|
// these parameters.
|
2012-12-18 00:22:38 +04:00
|
|
|
mProperty = new nsXBLProtoImplProperty(name, onget, onset, readonly, aLineNumber);
|
2013-11-01 18:31:56 +04:00
|
|
|
if (exposeToUntrustedContent) {
|
|
|
|
mProperty->SetExposeToUntrustedContent(true);
|
2005-01-20 19:44:00 +03:00
|
|
|
}
|
2013-11-01 18:31:56 +04:00
|
|
|
AddMember(mProperty);
|
2001-11-13 07:09:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-01-04 19:02:17 +04:00
|
|
|
nsXBLContentSink::ConstructMethod(const char16_t **aAtts)
|
2001-11-13 07:09:56 +03:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
mMethod = nullptr;
|
2001-11-13 07:09:56 +03:00
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* name = nullptr;
|
|
|
|
const char16_t* expose = nullptr;
|
2006-12-26 20:47:52 +03:00
|
|
|
if (FindValue(aAtts, nsGkAtoms::name, &name)) {
|
2004-12-15 18:37:23 +03:00
|
|
|
mMethod = new nsXBLProtoImplMethod(name);
|
2013-11-01 18:31:56 +04:00
|
|
|
if (FindValue(aAtts, nsGkAtoms::exposeToUntrustedContent, &expose) &&
|
|
|
|
nsDependentString(expose).EqualsLiteral("true"))
|
|
|
|
{
|
|
|
|
mMethod->SetExposeToUntrustedContent(true);
|
|
|
|
}
|
2001-11-13 07:09:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mMethod) {
|
2004-09-10 19:29:19 +04:00
|
|
|
AddMember(mMethod);
|
2001-11-13 07:09:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-01-04 19:02:17 +04:00
|
|
|
nsXBLContentSink::ConstructParameter(const char16_t **aAtts)
|
2001-11-13 07:09:56 +03:00
|
|
|
{
|
|
|
|
if (!mMethod)
|
|
|
|
return;
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* name = nullptr;
|
2006-12-26 20:47:52 +03:00
|
|
|
if (FindValue(aAtts, nsGkAtoms::name, &name)) {
|
2004-12-15 18:37:23 +03:00
|
|
|
mMethod->AddParameter(nsDependentString(name));
|
2001-11-13 07:09:56 +03:00
|
|
|
}
|
|
|
|
}
|
2002-01-09 04:37:50 +03:00
|
|
|
|
|
|
|
nsresult
|
2014-01-04 19:02:17 +04:00
|
|
|
nsXBLContentSink::CreateElement(const char16_t** aAtts, uint32_t aAttsCount,
|
2014-06-20 06:01:40 +04:00
|
|
|
mozilla::dom::NodeInfo* aNodeInfo, uint32_t aLineNumber,
|
2011-09-29 10:19:26 +04:00
|
|
|
nsIContent** aResult, bool* aAppendContent,
|
2010-10-25 16:17:38 +04:00
|
|
|
FromParser aFromParser)
|
2002-01-09 04:37:50 +03:00
|
|
|
{
|
2003-04-11 04:56:27 +04:00
|
|
|
#ifdef MOZ_XUL
|
2002-12-03 02:24:57 +03:00
|
|
|
if (!aNodeInfo->NamespaceEquals(kNameSpaceID_XUL)) {
|
2003-04-11 04:56:27 +04:00
|
|
|
#endif
|
2002-12-03 02:24:57 +03:00
|
|
|
return nsXMLContentSink::CreateElement(aAtts, aAttsCount, aNodeInfo,
|
|
|
|
aLineNumber, aResult,
|
2008-09-25 20:58:11 +04:00
|
|
|
aAppendContent, aFromParser);
|
2003-04-11 04:56:27 +04:00
|
|
|
#ifdef MOZ_XUL
|
2002-12-03 02:24:57 +03:00
|
|
|
}
|
2002-01-09 04:37:50 +03:00
|
|
|
|
2011-11-04 00:39:08 +04:00
|
|
|
// Note that this needs to match the code in nsXBLPrototypeBinding::ReadContentNode.
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
*aAppendContent = true;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsXULPrototypeElement> prototype = new nsXULPrototypeElement();
|
2002-01-09 04:37:50 +03:00
|
|
|
|
2002-12-03 02:24:57 +03:00
|
|
|
prototype->mNodeInfo = aNodeInfo;
|
2002-01-09 04:37:50 +03:00
|
|
|
|
2002-12-03 02:24:57 +03:00
|
|
|
AddAttributesToXULPrototype(aAtts, aAttsCount, prototype);
|
|
|
|
|
2010-04-30 17:12:05 +04:00
|
|
|
Element* result;
|
2013-02-05 03:22:51 +04:00
|
|
|
nsresult rv = nsXULElement::Create(prototype, mDocument, false, false, &result);
|
2010-04-30 17:12:05 +04:00
|
|
|
*aResult = result;
|
|
|
|
return rv;
|
2003-04-11 04:56:27 +04:00
|
|
|
#endif
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-01-04 19:02:17 +04:00
|
|
|
nsXBLContentSink::AddAttributes(const char16_t** aAtts,
|
2002-12-03 02:24:57 +03:00
|
|
|
nsIContent* aContent)
|
2002-01-09 04:37:50 +03:00
|
|
|
{
|
2015-03-03 14:08:59 +03:00
|
|
|
if (aContent->IsXULElement())
|
2002-01-09 04:37:50 +03:00
|
|
|
return NS_OK; // Nothing to do, since the proto already has the attrs.
|
2002-12-03 02:24:57 +03:00
|
|
|
|
|
|
|
return nsXMLContentSink::AddAttributes(aAtts, aContent);
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
|
|
|
|
2003-04-11 04:56:27 +04:00
|
|
|
#ifdef MOZ_XUL
|
2002-01-09 04:37:50 +03:00
|
|
|
nsresult
|
2014-01-04 19:02:17 +04:00
|
|
|
nsXBLContentSink::AddAttributesToXULPrototype(const char16_t **aAtts,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aAttsCount,
|
2002-01-09 04:37:50 +03:00
|
|
|
nsXULPrototypeElement* aElement)
|
|
|
|
{
|
|
|
|
// Add tag attributes to the element
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Create storage for the attributes
|
2012-07-30 18:20:58 +04:00
|
|
|
nsXULPrototypeAttribute* attrs = nullptr;
|
2002-01-09 04:37:50 +03:00
|
|
|
if (aAttsCount > 0) {
|
|
|
|
attrs = new nsXULPrototypeAttribute[aAttsCount];
|
|
|
|
}
|
|
|
|
|
|
|
|
aElement->mAttributes = attrs;
|
|
|
|
aElement->mNumAttributes = aAttsCount;
|
|
|
|
|
|
|
|
// Copy the attributes into the prototype
|
2004-12-15 18:37:23 +03:00
|
|
|
nsCOMPtr<nsIAtom> prefix, localName;
|
2004-02-10 12:08:06 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t i;
|
2004-02-10 12:08:06 +03:00
|
|
|
for (i = 0; i < aAttsCount; ++i) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t nameSpaceID;
|
2004-12-15 18:37:23 +03:00
|
|
|
nsContentUtils::SplitExpatName(aAtts[i * 2], getter_AddRefs(prefix),
|
|
|
|
getter_AddRefs(localName), &nameSpaceID);
|
2002-01-09 04:37:50 +03:00
|
|
|
|
2004-02-10 12:08:06 +03:00
|
|
|
if (nameSpaceID == kNameSpaceID_None) {
|
2004-12-15 18:37:23 +03:00
|
|
|
attrs[i].mName.SetTo(localName);
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
2004-02-10 12:08:06 +03:00
|
|
|
else {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<NodeInfo> ni;
|
2011-06-14 11:56:49 +04:00
|
|
|
ni = mNodeInfoManager->GetNodeInfo(localName, prefix, nameSpaceID,
|
|
|
|
nsIDOMNode::ATTRIBUTE_NODE);
|
2004-02-10 12:08:06 +03:00
|
|
|
attrs[i].mName.SetTo(ni);
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
2004-02-10 12:08:06 +03:00
|
|
|
|
|
|
|
rv = aElement->SetAttrAt(i, nsDependentString(aAtts[i * 2 + 1]),
|
|
|
|
mDocumentURI);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2003-04-11 04:56:27 +04:00
|
|
|
#endif
|