2001-11-02 01:53:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-17 21:52:36 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2001-11-02 01:53:13 +00:00
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
2001-11-02 01:53:13 +00:00
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-11-02 01:53:13 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2001-11-03 10:12:20 +00:00
|
|
|
* David Hyatt <hyatt@netscape.com> (Original Author)
|
2001-11-02 01:53:13 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-17 21:52:36 +00:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-11-02 01:53:13 +00:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-17 21:52:36 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-11-02 01:53:13 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-17 21:52:36 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-11-02 01:53:13 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "nsXBLContentSink.h"
|
|
|
|
#include "nsIDocument.h"
|
2007-02-16 23:02:08 +00:00
|
|
|
#include "nsBindingManager.h"
|
2001-11-02 01:53:13 +00:00
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsIParser.h"
|
2007-01-30 00:06:41 +00:00
|
|
|
#include "nsGkAtoms.h"
|
2006-12-26 17:47:52 +00:00
|
|
|
#include "nsINameSpaceManager.h"
|
2001-11-02 01:53:13 +00:00
|
|
|
#include "nsHTMLTokens.h"
|
|
|
|
#include "nsIURI.h"
|
2001-11-02 09:29:33 +00:00
|
|
|
#include "nsTextFragment.h"
|
2003-04-11 00:56:27 +00:00
|
|
|
#ifdef MOZ_XUL
|
2001-11-03 10:12:20 +00:00
|
|
|
#include "nsXULElement.h"
|
2003-04-11 00:56:27 +00:00
|
|
|
#endif
|
2001-11-13 04:09:56 +00:00
|
|
|
#include "nsXBLProtoImplProperty.h"
|
|
|
|
#include "nsXBLProtoImplMethod.h"
|
|
|
|
#include "nsXBLProtoImplField.h"
|
2003-03-06 23:59:18 +00:00
|
|
|
#include "nsXBLPrototypeBinding.h"
|
2004-09-14 17:26:35 +00:00
|
|
|
#include "nsContentUtils.h"
|
2002-08-06 12:55:44 +00:00
|
|
|
#include "nsIConsoleService.h"
|
|
|
|
#include "nsIScriptError.h"
|
2004-06-25 12:26:02 +00:00
|
|
|
#include "nsNodeInfoManager.h"
|
2004-06-25 14:35:40 +00:00
|
|
|
#include "nsINodeInfo.h"
|
2005-08-26 14:47:35 +00:00
|
|
|
#include "nsIPrincipal.h"
|
2001-11-03 10:12:20 +00:00
|
|
|
|
2001-11-02 01:53:13 +00:00
|
|
|
nsresult
|
|
|
|
NS_NewXBLContentSink(nsIXMLContentSink** aResult,
|
|
|
|
nsIDocument* aDoc,
|
2004-01-09 23:54:21 +00:00
|
|
|
nsIURI* aURI,
|
2003-04-03 18:57:33 +00:00
|
|
|
nsISupports* aContainer)
|
2001-11-02 01:53:13 +00:00
|
|
|
{
|
2002-12-11 14:24:49 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
|
2001-11-02 01:53:13 +00:00
|
|
|
nsXBLContentSink* it;
|
|
|
|
NS_NEWXPCOM(it, nsXBLContentSink);
|
2002-12-11 14:24:49 +00:00
|
|
|
NS_ENSURE_TRUE(it, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2003-01-14 22:32:18 +00:00
|
|
|
nsCOMPtr<nsIXMLContentSink> kungFuDeathGrip = it;
|
2004-01-09 23:54:21 +00:00
|
|
|
nsresult rv = it->Init(aDoc, aURI, aContainer);
|
2002-12-11 14:24:49 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return CallQueryInterface(it, aResult);
|
2001-11-02 01:53:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsXBLContentSink::nsXBLContentSink()
|
2003-02-28 01:04:45 +00:00
|
|
|
: mState(eXBL_InDocument),
|
|
|
|
mSecondaryState(eXBL_None),
|
|
|
|
mDocInfo(nsnull),
|
2007-02-24 16:27:51 +00:00
|
|
|
mFoundFirstBinding(PR_FALSE),
|
2003-02-28 01:04:45 +00:00
|
|
|
mIsChromeOrResource(PR_FALSE),
|
2003-03-06 23:59:18 +00:00
|
|
|
mBinding(nsnull),
|
2003-02-28 01:04:45 +00:00
|
|
|
mHandler(nsnull),
|
|
|
|
mImplementation(nsnull),
|
|
|
|
mImplMember(nsnull),
|
|
|
|
mProperty(nsnull),
|
|
|
|
mMethod(nsnull),
|
|
|
|
mField(nsnull)
|
2001-11-02 01:53:13 +00:00
|
|
|
{
|
2002-09-04 06:57:25 +00:00
|
|
|
mPrettyPrintXML = PR_FALSE;
|
2001-11-02 01:53:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsXBLContentSink::~nsXBLContentSink()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXBLContentSink::Init(nsIDocument* aDoc,
|
2004-01-09 23:54:21 +00:00
|
|
|
nsIURI* aURI,
|
2003-04-03 18:57:33 +00:00
|
|
|
nsISupports* aContainer)
|
2001-11-02 01:53:13 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
2004-01-09 23:54:21 +00:00
|
|
|
rv = nsXMLContentSink::Init(aDoc, aURI, aContainer, nsnull);
|
2001-11-02 01:53:13 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2007-01-30 21:21:06 +00:00
|
|
|
void
|
|
|
|
nsXBLContentSink::MaybeStartLayout()
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-11-02 09:29:33 +00:00
|
|
|
nsresult
|
|
|
|
nsXBLContentSink::FlushText(PRBool aCreateTextNode,
|
|
|
|
PRBool* aDidFlush)
|
|
|
|
{
|
2001-11-14 08:17:19 +00:00
|
|
|
if (mTextLength == 0) {
|
|
|
|
if (aDidFlush)
|
|
|
|
*aDidFlush = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-11-14 01:37:43 +00:00
|
|
|
const nsASingleFragmentString& text = Substring(mText, mText+mTextLength);
|
|
|
|
if (mState == eXBL_InHandlers) {
|
2004-09-16 18:26:18 +00:00
|
|
|
NS_ASSERTION(mBinding, "Must have binding here");
|
2001-11-14 01:37:43 +00:00
|
|
|
// Get the text and add it to the event handler.
|
|
|
|
if (mSecondaryState == eXBL_InHandler)
|
|
|
|
mHandler->AppendHandlerText(text);
|
2001-11-02 09:29:33 +00:00
|
|
|
mTextLength = 0;
|
|
|
|
if (aDidFlush)
|
|
|
|
*aDidFlush = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-11-13 04:09:56 +00:00
|
|
|
else if (mState == eXBL_InImplementation) {
|
2004-09-16 18:26:18 +00:00
|
|
|
NS_ASSERTION(mBinding, "Must have binding here");
|
2001-11-13 04:09:56 +00:00
|
|
|
if (mSecondaryState == eXBL_InConstructor ||
|
|
|
|
mSecondaryState == eXBL_InDestructor) {
|
2004-09-10 15:29:19 +00:00
|
|
|
// Construct a method for the constructor/destructor.
|
|
|
|
nsXBLProtoImplMethod* method;
|
2001-11-13 04:09:56 +00:00
|
|
|
if (mSecondaryState == eXBL_InConstructor)
|
2004-09-10 15:29:19 +00:00
|
|
|
method = mBinding->GetConstructor();
|
2001-11-13 04:09:56 +00:00
|
|
|
else
|
2004-09-10 15:29:19 +00:00
|
|
|
method = mBinding->GetDestructor();
|
2001-11-13 04:09:56 +00:00
|
|
|
|
|
|
|
// Get the text and add it to the constructor/destructor.
|
2004-09-10 15:29:19 +00:00
|
|
|
method->AppendBodyText(text);
|
2001-11-13 04:09:56 +00:00
|
|
|
}
|
|
|
|
else if (mSecondaryState == eXBL_InGetter ||
|
|
|
|
mSecondaryState == eXBL_InSetter) {
|
2004-09-10 15:29:19 +00:00
|
|
|
// Get the text and add it to the getter/setter
|
2001-11-14 01:37:43 +00:00
|
|
|
if (mSecondaryState == eXBL_InGetter)
|
|
|
|
mProperty->AppendGetterText(text);
|
|
|
|
else
|
|
|
|
mProperty->AppendSetterText(text);
|
2001-11-13 04:09:56 +00:00
|
|
|
}
|
|
|
|
else if (mSecondaryState == eXBL_InBody) {
|
|
|
|
// Get the text and add it to the method
|
2003-07-13 07:19:28 +00:00
|
|
|
if (mMethod)
|
|
|
|
mMethod->AppendBodyText(text);
|
2001-11-13 04:09:56 +00:00
|
|
|
}
|
|
|
|
else if (mSecondaryState == eXBL_InField) {
|
|
|
|
// Get the text and add it to the method
|
2001-11-14 01:37:43 +00:00
|
|
|
mField->AppendFieldText(text);
|
|
|
|
}
|
|
|
|
mTextLength = 0;
|
|
|
|
if (aDidFlush)
|
|
|
|
*aDidFlush = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-01-10 23:40:54 +00:00
|
|
|
nsIContent* content = GetCurrentContent();
|
2005-09-24 18:43:15 +00:00
|
|
|
if (content &&
|
|
|
|
(content->NodeInfo()->NamespaceEquals(kNameSpaceID_XBL) ||
|
|
|
|
(content->NodeInfo()->NamespaceEquals(kNameSpaceID_XUL) &&
|
2006-12-26 17:47:52 +00:00
|
|
|
content->Tag() != nsGkAtoms::label &&
|
|
|
|
content->Tag() != nsGkAtoms::description))) {
|
2004-01-10 23:40:54 +00:00
|
|
|
|
|
|
|
PRBool isWS = PR_TRUE;
|
|
|
|
if (mTextLength > 0) {
|
|
|
|
const PRUnichar* cp = mText;
|
|
|
|
const PRUnichar* end = mText + mTextLength;
|
|
|
|
while (cp < end) {
|
|
|
|
PRUnichar ch = *cp++;
|
|
|
|
if (!XP_IS_SPACE(ch)) {
|
|
|
|
isWS = PR_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2001-11-02 01:53:13 +00:00
|
|
|
}
|
|
|
|
}
|
2001-11-13 04:09:56 +00:00
|
|
|
|
2004-01-10 23:40:54 +00:00
|
|
|
if (isWS && mTextLength > 0) {
|
|
|
|
mTextLength = 0;
|
|
|
|
if (aDidFlush)
|
|
|
|
*aDidFlush = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-11-02 01:53:13 +00:00
|
|
|
}
|
|
|
|
|
2001-11-14 01:37:43 +00:00
|
|
|
return nsXMLContentSink::FlushText(aCreateTextNode, aDidFlush);
|
2001-11-02 01:53:13 +00:00
|
|
|
}
|
|
|
|
|
2002-08-06 12:55:44 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXBLContentSink::ReportError(const PRUnichar* aErrorText,
|
2006-01-21 02:02:02 +00:00
|
|
|
const PRUnichar* aSourceText,
|
2006-08-25 16:34:57 +00:00
|
|
|
nsIScriptError *aError,
|
|
|
|
PRBool *_retval)
|
2002-08-06 12:55:44 +00:00
|
|
|
{
|
2006-08-25 16:34:57 +00: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 12:55:44 +00: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 14:18:39 +00:00
|
|
|
NS_LossyConvertUTF16toASCII(aErrorText).get(),
|
|
|
|
NS_LossyConvertUTF16toASCII(aSourceText).get());
|
2002-08-06 12:55:44 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Most of what this does won't be too useful, but whatever...
|
2006-08-25 16:34:57 +00:00
|
|
|
// nsXMLContentSink::ReportError will handle the console logging.
|
2006-01-21 02:02:02 +00:00
|
|
|
return nsXMLContentSink::ReportError(aErrorText,
|
|
|
|
aSourceText,
|
2006-08-25 16:34:57 +00:00
|
|
|
aError,
|
|
|
|
_retval);
|
2002-08-06 12:55:44 +00:00
|
|
|
}
|
|
|
|
|
2004-01-06 18:30:45 +00:00
|
|
|
nsresult
|
|
|
|
nsXBLContentSink::ReportUnexpectedElement(nsIAtom* aElementName,
|
|
|
|
PRUint32 aLineNumber)
|
|
|
|
{
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
const PRUnichar* params[] = { elementName.get() };
|
|
|
|
|
2004-09-14 17:26:35 +00:00
|
|
|
return nsContentUtils::ReportToConsole(nsContentUtils::eXBL_PROPERTIES,
|
|
|
|
"UnexpectedElement",
|
|
|
|
params, NS_ARRAY_LENGTH(params),
|
|
|
|
mDocumentURI,
|
2004-11-23 17:45:37 +00:00
|
|
|
EmptyString() /* source line */,
|
2004-09-14 17:26:35 +00:00
|
|
|
aLineNumber, 0 /* column number */,
|
|
|
|
nsIScriptError::errorFlag,
|
|
|
|
"XBL Content Sink");
|
2004-01-06 18:30:45 +00:00
|
|
|
}
|
|
|
|
|
2004-09-10 15:29:19 +00: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.
|
|
|
|
}
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXBLContentSink::HandleStartElement(const PRUnichar *aName,
|
|
|
|
const PRUnichar **aAtts,
|
2002-01-09 18:15:36 +00:00
|
|
|
PRUint32 aAttsCount,
|
2003-10-30 02:17:50 +00:00
|
|
|
PRInt32 aIndex,
|
2002-01-09 18:15:36 +00:00
|
|
|
PRUint32 aLineNumber)
|
2001-11-03 10:12:20 +00:00
|
|
|
{
|
2002-01-09 01:37:50 +00:00
|
|
|
nsresult rv = nsXMLContentSink::HandleStartElement(aName,aAtts,aAttsCount,aIndex,aLineNumber);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2001-11-03 10:12:20 +00:00
|
|
|
|
2003-11-17 21:03:32 +00:00
|
|
|
if (mState == eXBL_InBinding && !mBinding) {
|
2004-09-16 18:26:18 +00:00
|
|
|
rv = ConstructBinding();
|
|
|
|
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-17 21:03:32 +00:00
|
|
|
}
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
return rv;
|
|
|
|
}
|
2001-11-03 10:12:20 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXBLContentSink::HandleEndElement(const PRUnichar *aName)
|
|
|
|
{
|
|
|
|
FlushText();
|
2001-11-03 10:12:20 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
if (mState != eXBL_InDocument) {
|
2004-12-15 15:37:23 +00:00
|
|
|
PRInt32 nameSpaceID;
|
|
|
|
nsCOMPtr<nsIAtom> prefix, localName;
|
|
|
|
nsContentUtils::SplitExpatName(aName, getter_AddRefs(prefix),
|
|
|
|
getter_AddRefs(localName), &nameSpaceID);
|
2001-11-03 10:12:20 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
if (nameSpaceID == kNameSpaceID_XBL) {
|
2004-12-02 02:15:37 +00:00
|
|
|
if (mState == eXBL_Error) {
|
|
|
|
// Check whether we've opened this tag before; we may not have if
|
|
|
|
// it was a real XBL tag before the error occured.
|
2005-09-24 18:43:15 +00:00
|
|
|
if (!GetCurrentContent()->NodeInfo()->Equals(localName,
|
|
|
|
nameSpaceID)) {
|
2004-12-02 02:15:37 +00: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 17:47:52 +00:00
|
|
|
if (localName == nsGkAtoms::handlers) {
|
2002-01-09 01:37:50 +00:00
|
|
|
mState = eXBL_InBinding;
|
|
|
|
mHandler = nsnull;
|
|
|
|
}
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (localName == nsGkAtoms::handler)
|
2002-01-09 01:37:50 +00:00
|
|
|
mSecondaryState = eXBL_None;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else if (mState == eXBL_InResources) {
|
2006-12-26 17:47:52 +00:00
|
|
|
if (localName == nsGkAtoms::resources)
|
2002-01-09 01:37:50 +00:00
|
|
|
mState = eXBL_InBinding;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else if (mState == eXBL_InImplementation) {
|
2006-12-26 17:47:52 +00:00
|
|
|
if (localName == nsGkAtoms::implementation)
|
2002-01-09 01:37:50 +00:00
|
|
|
mState = eXBL_InBinding;
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (localName == nsGkAtoms::property) {
|
2002-01-09 01:37:50 +00:00
|
|
|
mSecondaryState = eXBL_None;
|
|
|
|
mProperty = nsnull;
|
|
|
|
}
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (localName == nsGkAtoms::method) {
|
2002-01-09 01:37:50 +00:00
|
|
|
mSecondaryState = eXBL_None;
|
|
|
|
mMethod = nsnull;
|
|
|
|
}
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (localName == nsGkAtoms::field) {
|
2002-01-09 01:37:50 +00:00
|
|
|
mSecondaryState = eXBL_None;
|
|
|
|
mField = nsnull;
|
|
|
|
}
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (localName == nsGkAtoms::constructor ||
|
|
|
|
localName == nsGkAtoms::destructor)
|
2002-01-09 01:37:50 +00:00
|
|
|
mSecondaryState = eXBL_None;
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (localName == nsGkAtoms::getter ||
|
|
|
|
localName == nsGkAtoms::setter)
|
2002-01-09 01:37:50 +00:00
|
|
|
mSecondaryState = eXBL_InProperty;
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (localName == nsGkAtoms::parameter ||
|
|
|
|
localName == nsGkAtoms::body)
|
2002-01-09 01:37:50 +00:00
|
|
|
mSecondaryState = eXBL_InMethod;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2004-12-15 15:37:23 +00:00
|
|
|
else if (mState == eXBL_InBindings &&
|
2006-12-26 17:47:52 +00:00
|
|
|
localName == nsGkAtoms::bindings) {
|
2004-01-06 18:30:45 +00:00
|
|
|
mState = eXBL_InDocument;
|
|
|
|
}
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsresult rv = nsXMLContentSink::HandleEndElement(aName);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2001-11-03 10:12:20 +00:00
|
|
|
|
2006-12-26 17:47:52 +00:00
|
|
|
if (mState == eXBL_InBinding && localName == nsGkAtoms::binding) {
|
2004-01-06 18:30:45 +00:00
|
|
|
mState = eXBL_InBindings;
|
2004-09-16 18:26:18 +00:00
|
|
|
if (mBinding) { // See comment in HandleStartElement()
|
|
|
|
mBinding->Initialize();
|
|
|
|
mBinding = nsnull; // Clear our current binding ref.
|
|
|
|
}
|
2001-11-03 10:12:20 +00:00
|
|
|
}
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
return NS_OK;
|
2001-11-03 10:12:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
return nsXMLContentSink::HandleEndElement(aName);
|
2001-11-03 10:12:20 +00:00
|
|
|
}
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXBLContentSink::HandleCDataSection(const PRUnichar *aData,
|
|
|
|
PRUint32 aLength)
|
|
|
|
{
|
|
|
|
if (mState == eXBL_InHandlers || mState == eXBL_InImplementation)
|
|
|
|
return AddText(aData, aLength);
|
|
|
|
return nsXMLContentSink::HandleCDataSection(aData, aLength);
|
|
|
|
}
|
|
|
|
|
2005-04-21 21:31:05 +00:00
|
|
|
#define ENSURE_XBL_STATE(_cond) \
|
|
|
|
PR_BEGIN_MACRO \
|
|
|
|
if (!(_cond)) { ReportUnexpectedElement(aTagName, aLineNumber); return PR_TRUE; } \
|
|
|
|
PR_END_MACRO
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
PRBool
|
|
|
|
nsXBLContentSink::OnOpenContainer(const PRUnichar **aAtts,
|
|
|
|
PRUint32 aAttsCount,
|
|
|
|
PRInt32 aNameSpaceID,
|
2003-06-24 01:20:40 +00:00
|
|
|
nsIAtom* aTagName,
|
|
|
|
PRUint32 aLineNumber)
|
2001-11-03 10:12:20 +00:00
|
|
|
{
|
2004-01-06 18:30:45 +00:00
|
|
|
if (mState == eXBL_Error) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2005-04-21 21:31:05 +00:00
|
|
|
if (aNameSpaceID != kNameSpaceID_XBL) {
|
|
|
|
// Construct non-XBL nodes
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
PRBool ret = PR_TRUE;
|
2006-12-26 17:47:52 +00:00
|
|
|
if (aTagName == nsGkAtoms::bindings) {
|
2005-04-21 21:31:05 +00:00
|
|
|
ENSURE_XBL_STATE(mState == eXBL_InDocument);
|
2004-01-06 18:30:45 +00:00
|
|
|
|
2005-04-21 21:31:05 +00:00
|
|
|
NS_NewXBLDocumentInfo(mDocument, &mDocInfo);
|
|
|
|
if (!mDocInfo) {
|
|
|
|
mState = eXBL_Error;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2001-11-05 06:45:04 +00:00
|
|
|
|
2005-04-21 21:31:05 +00:00
|
|
|
mDocument->BindingManager()->PutXBLDocumentInfo(mDocInfo);
|
2001-11-05 06:45:04 +00:00
|
|
|
|
2005-04-21 21:31:05 +00:00
|
|
|
nsIURI *uri = mDocument->GetDocumentURI();
|
2002-01-09 01:37:50 +00:00
|
|
|
|
2005-04-21 21:31:05 +00:00
|
|
|
PRBool isChrome = PR_FALSE;
|
|
|
|
PRBool isRes = PR_FALSE;
|
2001-11-03 10:12:20 +00:00
|
|
|
|
2005-04-21 21:31:05 +00:00
|
|
|
uri->SchemeIs("chrome", &isChrome);
|
|
|
|
uri->SchemeIs("resource", &isRes);
|
|
|
|
mIsChromeOrResource = isChrome || isRes;
|
2002-01-09 01:37:50 +00:00
|
|
|
|
2005-04-21 21:31:05 +00:00
|
|
|
nsIXBLDocumentInfo* info = mDocInfo;
|
|
|
|
NS_RELEASE(info); // We keep a weak ref. We've created a cycle between doc/binding manager/doc info.
|
|
|
|
mState = eXBL_InBindings;
|
|
|
|
}
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (aTagName == nsGkAtoms::binding) {
|
2005-04-21 21:31:05 +00:00
|
|
|
ENSURE_XBL_STATE(mState == eXBL_InBindings);
|
|
|
|
mState = eXBL_InBinding;
|
|
|
|
}
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (aTagName == nsGkAtoms::handlers) {
|
2005-04-21 21:31:05 +00:00
|
|
|
ENSURE_XBL_STATE(mState == eXBL_InBinding && mBinding);
|
|
|
|
mState = eXBL_InHandlers;
|
|
|
|
ret = PR_FALSE;
|
|
|
|
}
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (aTagName == nsGkAtoms::handler) {
|
2005-04-21 21:31:05 +00:00
|
|
|
ENSURE_XBL_STATE(mState == eXBL_InHandlers);
|
|
|
|
mSecondaryState = eXBL_InHandler;
|
|
|
|
ConstructHandler(aAtts, aLineNumber);
|
|
|
|
ret = PR_FALSE;
|
|
|
|
}
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (aTagName == nsGkAtoms::resources) {
|
2005-04-21 21:31:05 +00: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 17:47:52 +00:00
|
|
|
else if (aTagName == nsGkAtoms::stylesheet || aTagName == nsGkAtoms::image) {
|
2005-04-21 21:31:05 +00:00
|
|
|
ENSURE_XBL_STATE(mState == eXBL_InResources);
|
|
|
|
NS_ASSERTION(mBinding, "Must have binding here");
|
|
|
|
ConstructResource(aAtts, aTagName);
|
|
|
|
}
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (aTagName == nsGkAtoms::implementation) {
|
2005-04-21 21:31:05 +00: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 17:47:52 +00:00
|
|
|
else if (aTagName == nsGkAtoms::constructor) {
|
2005-04-21 21:31:05 +00:00
|
|
|
ENSURE_XBL_STATE(mState == eXBL_InImplementation &&
|
|
|
|
mSecondaryState == eXBL_None);
|
|
|
|
NS_ASSERTION(mBinding, "Must have binding here");
|
|
|
|
|
|
|
|
mSecondaryState = eXBL_InConstructor;
|
|
|
|
nsXBLProtoImplAnonymousMethod* newMethod =
|
|
|
|
new nsXBLProtoImplAnonymousMethod();
|
|
|
|
if (newMethod) {
|
|
|
|
newMethod->SetLineNumber(aLineNumber);
|
|
|
|
mBinding->SetConstructor(newMethod);
|
|
|
|
AddMember(newMethod);
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
2005-04-21 21:31:05 +00:00
|
|
|
}
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (aTagName == nsGkAtoms::destructor) {
|
2005-04-21 21:31:05 +00:00
|
|
|
ENSURE_XBL_STATE(mState == eXBL_InImplementation &&
|
|
|
|
mSecondaryState == eXBL_None);
|
|
|
|
NS_ASSERTION(mBinding, "Must have binding here");
|
|
|
|
mSecondaryState = eXBL_InDestructor;
|
|
|
|
nsXBLProtoImplAnonymousMethod* newMethod =
|
|
|
|
new nsXBLProtoImplAnonymousMethod();
|
|
|
|
if (newMethod) {
|
|
|
|
newMethod->SetLineNumber(aLineNumber);
|
|
|
|
mBinding->SetDestructor(newMethod);
|
|
|
|
AddMember(newMethod);
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
2001-11-03 10:12:20 +00:00
|
|
|
}
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (aTagName == nsGkAtoms::field) {
|
2005-04-21 21:31:05 +00: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 17:47:52 +00:00
|
|
|
else if (aTagName == nsGkAtoms::property) {
|
2005-04-21 21:31:05 +00:00
|
|
|
ENSURE_XBL_STATE(mState == eXBL_InImplementation &&
|
|
|
|
mSecondaryState == eXBL_None);
|
|
|
|
NS_ASSERTION(mBinding, "Must have binding here");
|
|
|
|
mSecondaryState = eXBL_InProperty;
|
|
|
|
ConstructProperty(aAtts);
|
|
|
|
}
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (aTagName == nsGkAtoms::getter) {
|
2005-04-21 21:31:05 +00:00
|
|
|
ENSURE_XBL_STATE(mSecondaryState == eXBL_InProperty && mProperty);
|
|
|
|
NS_ASSERTION(mState == eXBL_InImplementation, "Unexpected state");
|
|
|
|
mProperty->SetGetterLineNumber(aLineNumber);
|
|
|
|
mSecondaryState = eXBL_InGetter;
|
|
|
|
}
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (aTagName == nsGkAtoms::setter) {
|
2005-04-21 21:31:05 +00:00
|
|
|
ENSURE_XBL_STATE(mSecondaryState == eXBL_InProperty && mProperty);
|
|
|
|
NS_ASSERTION(mState == eXBL_InImplementation, "Unexpected state");
|
|
|
|
mProperty->SetSetterLineNumber(aLineNumber);
|
|
|
|
mSecondaryState = eXBL_InSetter;
|
|
|
|
}
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (aTagName == nsGkAtoms::method) {
|
2005-04-21 21:31:05 +00: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 17:47:52 +00:00
|
|
|
else if (aTagName == nsGkAtoms::parameter) {
|
2005-04-21 21:31:05 +00:00
|
|
|
ENSURE_XBL_STATE(mSecondaryState == eXBL_InMethod && mMethod);
|
|
|
|
NS_ASSERTION(mState == eXBL_InImplementation, "Unexpected state");
|
|
|
|
ConstructParameter(aAtts);
|
|
|
|
}
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (aTagName == nsGkAtoms::body) {
|
2005-04-21 21:31:05 +00: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 10:12:20 +00:00
|
|
|
|
2005-04-21 21:31:05 +00:00
|
|
|
return ret && mState != eXBL_InResources && mState != eXBL_InImplementation;
|
2001-11-03 10:12:20 +00:00
|
|
|
}
|
|
|
|
|
2005-04-21 21:31:05 +00:00
|
|
|
#undef ENSURE_XBL_STATE
|
|
|
|
|
2004-09-16 18:26:18 +00:00
|
|
|
nsresult
|
2001-11-02 01:53:13 +00:00
|
|
|
nsXBLContentSink::ConstructBinding()
|
|
|
|
{
|
2003-07-03 05:34:26 +00:00
|
|
|
nsCOMPtr<nsIContent> binding = GetCurrentContent();
|
2001-11-02 01:53:13 +00:00
|
|
|
nsAutoString id;
|
2006-12-26 17:47:52 +00:00
|
|
|
binding->GetAttr(kNameSpaceID_None, nsGkAtoms::id, id);
|
2004-09-16 18:26:18 +00:00
|
|
|
NS_ConvertUTF16toUTF8 cid(id);
|
2001-11-02 01:53:13 +00:00
|
|
|
|
2004-09-16 18:26:18 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2001-11-02 01:53:13 +00:00
|
|
|
if (!cid.IsEmpty()) {
|
2003-11-17 21:03:32 +00:00
|
|
|
mBinding = new nsXBLPrototypeBinding();
|
2004-09-16 18:26:18 +00:00
|
|
|
if (!mBinding)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
rv = mBinding->Init(cid, mDocInfo, binding);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2007-02-24 16:27:51 +00:00
|
|
|
if (!mFoundFirstBinding) {
|
|
|
|
mFoundFirstBinding = PR_TRUE;
|
|
|
|
mDocInfo->SetFirstPrototypeBinding(mBinding);
|
|
|
|
}
|
2004-09-16 18:26:18 +00:00
|
|
|
mDocInfo->SetPrototypeBinding(cid, mBinding);
|
2006-12-26 17:47:52 +00:00
|
|
|
binding->UnsetAttr(kNameSpaceID_None, nsGkAtoms::id, PR_FALSE);
|
2004-09-16 18:26:18 +00:00
|
|
|
} else {
|
|
|
|
delete mBinding;
|
|
|
|
mBinding = nsnull;
|
2003-11-17 21:03:32 +00:00
|
|
|
}
|
2001-11-02 01:53:13 +00:00
|
|
|
}
|
2004-09-16 18:26:18 +00:00
|
|
|
|
|
|
|
return rv;
|
2001-11-02 01:53:13 +00:00
|
|
|
}
|
|
|
|
|
2004-12-15 15:37:23 +00:00
|
|
|
static PRBool
|
|
|
|
FindValue(const PRUnichar **aAtts, nsIAtom *aAtom, const PRUnichar **aResult)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAtom> prefix, localName;
|
|
|
|
for (; *aAtts; aAtts += 2) {
|
|
|
|
PRInt32 nameSpaceID;
|
|
|
|
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];
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2002-01-09 01:37:50 +00:00
|
|
|
|
2001-11-02 01:53:13 +00:00
|
|
|
void
|
2003-06-24 01:20:40 +00:00
|
|
|
nsXBLContentSink::ConstructHandler(const PRUnichar **aAtts, PRUint32 aLineNumber)
|
2001-11-02 01:53:13 +00:00
|
|
|
{
|
2002-06-19 00:43:46 +00:00
|
|
|
const PRUnichar* event = nsnull;
|
|
|
|
const PRUnichar* modifiers = nsnull;
|
|
|
|
const PRUnichar* button = nsnull;
|
|
|
|
const PRUnichar* clickcount = nsnull;
|
|
|
|
const PRUnichar* keycode = nsnull;
|
|
|
|
const PRUnichar* charcode = nsnull;
|
|
|
|
const PRUnichar* phase = nsnull;
|
|
|
|
const PRUnichar* command = nsnull;
|
|
|
|
const PRUnichar* action = nsnull;
|
2005-03-30 13:32:47 +00:00
|
|
|
const PRUnichar* group = nsnull;
|
2002-06-19 00:43:46 +00:00
|
|
|
const PRUnichar* preventdefault = nsnull;
|
2005-08-21 22:20:36 +00:00
|
|
|
const PRUnichar* allowuntrusted = nsnull;
|
2002-01-09 01:37:50 +00:00
|
|
|
|
2004-12-15 15:37:23 +00:00
|
|
|
nsCOMPtr<nsIAtom> prefix, localName;
|
2002-01-09 01:37:50 +00:00
|
|
|
for (; *aAtts; aAtts += 2) {
|
2004-12-15 15:37:23 +00:00
|
|
|
PRInt32 nameSpaceID;
|
|
|
|
nsContentUtils::SplitExpatName(aAtts[0], getter_AddRefs(prefix),
|
|
|
|
getter_AddRefs(localName), &nameSpaceID);
|
2001-11-02 01:53:13 +00:00
|
|
|
|
2004-12-15 15:37:23 +00:00
|
|
|
if (nameSpaceID != kNameSpaceID_None) {
|
2001-11-02 01:53:13 +00:00
|
|
|
continue;
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
2001-11-02 01:53:13 +00:00
|
|
|
|
|
|
|
// Is this attribute one of the ones we care about?
|
2006-12-26 17:47:52 +00:00
|
|
|
if (localName == nsGkAtoms::event)
|
2002-01-09 01:37:50 +00:00
|
|
|
event = aAtts[1];
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (localName == nsGkAtoms::modifiers)
|
2002-01-09 01:37:50 +00:00
|
|
|
modifiers = aAtts[1];
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (localName == nsGkAtoms::button)
|
2002-01-09 01:37:50 +00:00
|
|
|
button = aAtts[1];
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (localName == nsGkAtoms::clickcount)
|
2002-01-09 01:37:50 +00:00
|
|
|
clickcount = aAtts[1];
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (localName == nsGkAtoms::keycode)
|
2002-01-09 01:37:50 +00:00
|
|
|
keycode = aAtts[1];
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (localName == nsGkAtoms::key || localName == nsGkAtoms::charcode)
|
2002-01-09 01:37:50 +00:00
|
|
|
charcode = aAtts[1];
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (localName == nsGkAtoms::phase)
|
2002-01-09 01:37:50 +00:00
|
|
|
phase = aAtts[1];
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (localName == nsGkAtoms::command)
|
2002-01-09 01:37:50 +00:00
|
|
|
command = aAtts[1];
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (localName == nsGkAtoms::action)
|
2002-01-09 01:37:50 +00:00
|
|
|
action = aAtts[1];
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (localName == nsGkAtoms::group)
|
2005-03-30 12:26:02 +00:00
|
|
|
group = aAtts[1];
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (localName == nsGkAtoms::preventdefault)
|
2002-06-19 00:43:46 +00:00
|
|
|
preventdefault = aAtts[1];
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (localName == nsGkAtoms::allowuntrusted)
|
2005-08-21 22:20:36 +00:00
|
|
|
allowuntrusted = aAtts[1];
|
2001-11-02 01:53:13 +00:00
|
|
|
}
|
|
|
|
|
2006-12-07 02:34:57 +00:00
|
|
|
if (command && !mIsChromeOrResource) {
|
2001-11-02 01:53:13 +00:00
|
|
|
// Make sure the XBL doc is chrome or resource if we have a command
|
|
|
|
// shorthand syntax.
|
2006-12-07 02:34:57 +00:00
|
|
|
mState = eXBL_Error;
|
|
|
|
nsContentUtils::ReportToConsole(nsContentUtils::eXBL_PROPERTIES,
|
|
|
|
"CommandNotInChrome", nsnull, 0,
|
|
|
|
mDocumentURI,
|
|
|
|
EmptyString() /* source line */,
|
|
|
|
aLineNumber, 0 /* column number */,
|
|
|
|
nsIScriptError::errorFlag,
|
|
|
|
"XBL Content Sink");
|
2001-11-02 01:53:13 +00:00
|
|
|
return; // Don't even make this handler.
|
2006-12-07 02:34:57 +00:00
|
|
|
}
|
2001-11-02 01:53:13 +00:00
|
|
|
|
2004-12-15 15:37:23 +00:00
|
|
|
// All of our pointers are now filled in. Construct our handler with all of
|
|
|
|
// these parameters.
|
2003-02-28 01:04:45 +00:00
|
|
|
nsXBLPrototypeHandler* newHandler;
|
|
|
|
newHandler = new nsXBLPrototypeHandler(event, phase, action, command,
|
|
|
|
keycode, charcode, modifiers, button,
|
2005-08-21 22:20:36 +00:00
|
|
|
clickcount, group, preventdefault,
|
|
|
|
allowuntrusted, mBinding);
|
2003-02-28 01:04:45 +00:00
|
|
|
|
2001-11-02 01:53:13 +00:00
|
|
|
if (newHandler) {
|
2003-06-24 01:20:40 +00:00
|
|
|
newHandler->SetLineNumber(aLineNumber);
|
|
|
|
|
2001-11-02 01:53:13 +00:00
|
|
|
// Add this handler to our chain of handlers.
|
2004-12-15 15:37:23 +00:00
|
|
|
if (mHandler) {
|
|
|
|
// Already have a chain. Just append to the end.
|
|
|
|
mHandler->SetNextHandler(newHandler);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// We're the first handler in the chain.
|
|
|
|
mBinding->SetPrototypeHandlers(newHandler);
|
|
|
|
}
|
|
|
|
// Adjust our mHandler pointer to point to the new last handler in the
|
|
|
|
// chain.
|
|
|
|
mHandler = newHandler;
|
2006-12-07 02:34:57 +00:00
|
|
|
} else {
|
|
|
|
mState = eXBL_Error;
|
2001-11-02 01:53:13 +00:00
|
|
|
}
|
|
|
|
}
|
2001-11-11 01:15:22 +00:00
|
|
|
|
|
|
|
void
|
2002-01-09 01:37:50 +00:00
|
|
|
nsXBLContentSink::ConstructResource(const PRUnichar **aAtts,
|
|
|
|
nsIAtom* aResourceType)
|
2001-11-11 01:15:22 +00:00
|
|
|
{
|
|
|
|
if (!mBinding)
|
|
|
|
return;
|
|
|
|
|
2004-12-15 15:37:23 +00:00
|
|
|
const PRUnichar* src = nsnull;
|
2006-12-26 17:47:52 +00:00
|
|
|
if (FindValue(aAtts, nsGkAtoms::src, &src)) {
|
2004-12-15 15:37:23 +00:00
|
|
|
mBinding->AddResource(aResourceType, nsDependentString(src));
|
2001-11-11 01:15:22 +00:00
|
|
|
}
|
|
|
|
}
|
2001-11-13 04:09:56 +00:00
|
|
|
|
|
|
|
void
|
2002-01-09 01:37:50 +00:00
|
|
|
nsXBLContentSink::ConstructImplementation(const PRUnichar **aAtts)
|
2001-11-13 04:09:56 +00:00
|
|
|
{
|
|
|
|
mImplementation = nsnull;
|
|
|
|
mImplMember = nsnull;
|
|
|
|
|
|
|
|
if (!mBinding)
|
|
|
|
return;
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
const PRUnichar* name = nsnull;
|
2001-11-13 04:09:56 +00:00
|
|
|
|
2004-12-15 15:37:23 +00:00
|
|
|
nsCOMPtr<nsIAtom> prefix, localName;
|
|
|
|
for (; *aAtts; aAtts += 2) {
|
|
|
|
PRInt32 nameSpaceID;
|
|
|
|
nsContentUtils::SplitExpatName(aAtts[0], getter_AddRefs(prefix),
|
|
|
|
getter_AddRefs(localName), &nameSpaceID);
|
2001-11-13 04:09:56 +00:00
|
|
|
|
2004-12-15 15:37:23 +00:00
|
|
|
if (nameSpaceID != kNameSpaceID_None) {
|
2001-11-13 04:09:56 +00:00
|
|
|
continue;
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
2001-11-13 04:09:56 +00:00
|
|
|
|
|
|
|
// Is this attribute one of the ones we care about?
|
2006-12-26 17:47:52 +00:00
|
|
|
if (localName == nsGkAtoms::name) {
|
2002-01-09 01:37:50 +00:00
|
|
|
name = aAtts[1];
|
|
|
|
}
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (localName == nsGkAtoms::implements) {
|
2005-08-26 14:47:35 +00:00
|
|
|
// Only allow implementation of interfaces via XBL if the principal of
|
|
|
|
// our XBL document has UniversalXPConnect privileges. No principal
|
|
|
|
// means no privs!
|
|
|
|
|
2006-04-27 18:21:11 +00:00
|
|
|
// XXX this api is so badly tied to JS it's not even funny. We don't
|
|
|
|
// have a concept of enabling capabilities on a per-principal basis,
|
|
|
|
// but only on a per-principal-and-JS-stackframe basis! So for now
|
|
|
|
// this is basically equivalent to testing that we have the system
|
|
|
|
// principal, since there is no JS stackframe in sight here...
|
|
|
|
PRBool hasUniversalXPConnect;
|
|
|
|
nsresult rv = mDocument->NodePrincipal()->
|
|
|
|
IsCapabilityEnabled("UniversalXPConnect", nsnull,
|
|
|
|
&hasUniversalXPConnect);
|
|
|
|
if (NS_SUCCEEDED(rv) && hasUniversalXPConnect) {
|
|
|
|
mBinding->ConstructInterfaceTable(nsDependentString(aAtts[1]));
|
2005-08-26 14:47:35 +00:00
|
|
|
}
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
2001-11-13 04:09:56 +00:00
|
|
|
}
|
|
|
|
|
2002-01-09 21:50:08 +00:00
|
|
|
NS_NewXBLProtoImpl(mBinding, name, &mImplementation);
|
2001-11-13 04:09:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-06-24 01:20:40 +00:00
|
|
|
nsXBLContentSink::ConstructField(const PRUnichar **aAtts, PRUint32 aLineNumber)
|
2001-11-13 04:09:56 +00:00
|
|
|
{
|
2002-01-09 01:37:50 +00:00
|
|
|
const PRUnichar* name = nsnull;
|
|
|
|
const PRUnichar* readonly = nsnull;
|
2004-12-15 15:37:23 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> prefix, localName;
|
2002-01-09 01:37:50 +00:00
|
|
|
for (; *aAtts; aAtts += 2) {
|
2004-12-15 15:37:23 +00:00
|
|
|
PRInt32 nameSpaceID;
|
|
|
|
nsContentUtils::SplitExpatName(aAtts[0], getter_AddRefs(prefix),
|
|
|
|
getter_AddRefs(localName), &nameSpaceID);
|
2001-11-13 04:09:56 +00:00
|
|
|
|
2004-12-15 15:37:23 +00:00
|
|
|
if (nameSpaceID != kNameSpaceID_None) {
|
2001-11-13 04:09:56 +00:00
|
|
|
continue;
|
2004-12-15 15:37:23 +00:00
|
|
|
}
|
2001-11-13 04:09:56 +00:00
|
|
|
|
|
|
|
// Is this attribute one of the ones we care about?
|
2006-12-26 17:47:52 +00:00
|
|
|
if (localName == nsGkAtoms::name) {
|
2002-01-09 01:37:50 +00:00
|
|
|
name = aAtts[1];
|
|
|
|
}
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (localName == nsGkAtoms::readonly) {
|
2002-01-09 01:37:50 +00:00
|
|
|
readonly = aAtts[1];
|
|
|
|
}
|
2001-11-13 04:09:56 +00:00
|
|
|
}
|
|
|
|
|
2005-11-27 23:51:42 +00:00
|
|
|
if (name) {
|
|
|
|
// All of our pointers are now filled in. Construct our field with all of
|
|
|
|
// these parameters.
|
|
|
|
mField = new nsXBLProtoImplField(name, readonly);
|
|
|
|
if (mField) {
|
|
|
|
mField->SetLineNumber(aLineNumber);
|
|
|
|
AddMember(mField);
|
|
|
|
}
|
2001-11-13 04:09:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-01-09 01:37:50 +00:00
|
|
|
nsXBLContentSink::ConstructProperty(const PRUnichar **aAtts)
|
2001-11-13 04:09:56 +00:00
|
|
|
{
|
2002-01-09 01:37:50 +00:00
|
|
|
const PRUnichar* name = nsnull;
|
|
|
|
const PRUnichar* readonly = nsnull;
|
|
|
|
const PRUnichar* onget = nsnull;
|
|
|
|
const PRUnichar* onset = nsnull;
|
2004-12-15 15:37:23 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> prefix, localName;
|
2002-01-09 01:37:50 +00:00
|
|
|
for (; *aAtts; aAtts += 2) {
|
2004-12-15 15:37:23 +00:00
|
|
|
PRInt32 nameSpaceID;
|
|
|
|
nsContentUtils::SplitExpatName(aAtts[0], getter_AddRefs(prefix),
|
|
|
|
getter_AddRefs(localName), &nameSpaceID);
|
2001-11-13 04:09:56 +00:00
|
|
|
|
2004-12-15 15:37:23 +00:00
|
|
|
if (nameSpaceID != kNameSpaceID_None) {
|
2001-11-13 04:09:56 +00:00
|
|
|
continue;
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
2001-11-13 04:09:56 +00:00
|
|
|
|
|
|
|
// Is this attribute one of the ones we care about?
|
2006-12-26 17:47:52 +00:00
|
|
|
if (localName == nsGkAtoms::name) {
|
2002-01-09 01:37:50 +00:00
|
|
|
name = aAtts[1];
|
|
|
|
}
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (localName == nsGkAtoms::readonly) {
|
2002-01-09 01:37:50 +00:00
|
|
|
readonly = aAtts[1];
|
|
|
|
}
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (localName == nsGkAtoms::onget) {
|
2002-01-09 01:37:50 +00:00
|
|
|
onget = aAtts[1];
|
|
|
|
}
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (localName == nsGkAtoms::onset) {
|
2002-01-09 01:37:50 +00:00
|
|
|
onset = aAtts[1];
|
|
|
|
}
|
2001-11-13 04:09:56 +00:00
|
|
|
}
|
|
|
|
|
2005-01-20 16:44:00 +00:00
|
|
|
if (name) {
|
|
|
|
// All of our pointers are now filled in. Construct our property with all of
|
|
|
|
// these parameters.
|
|
|
|
mProperty = new nsXBLProtoImplProperty(name, onget, onset, readonly);
|
|
|
|
if (mProperty) {
|
|
|
|
AddMember(mProperty);
|
|
|
|
}
|
2001-11-13 04:09:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-01-09 01:37:50 +00:00
|
|
|
nsXBLContentSink::ConstructMethod(const PRUnichar **aAtts)
|
2001-11-13 04:09:56 +00:00
|
|
|
{
|
|
|
|
mMethod = nsnull;
|
|
|
|
|
2004-12-15 15:37:23 +00:00
|
|
|
const PRUnichar* name = nsnull;
|
2006-12-26 17:47:52 +00:00
|
|
|
if (FindValue(aAtts, nsGkAtoms::name, &name)) {
|
2004-12-15 15:37:23 +00:00
|
|
|
mMethod = new nsXBLProtoImplMethod(name);
|
2001-11-13 04:09:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mMethod) {
|
2004-09-10 15:29:19 +00:00
|
|
|
AddMember(mMethod);
|
2001-11-13 04:09:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-01-09 01:37:50 +00:00
|
|
|
nsXBLContentSink::ConstructParameter(const PRUnichar **aAtts)
|
2001-11-13 04:09:56 +00:00
|
|
|
{
|
|
|
|
if (!mMethod)
|
|
|
|
return;
|
|
|
|
|
2004-12-15 15:37:23 +00:00
|
|
|
const PRUnichar* name = nsnull;
|
2006-12-26 17:47:52 +00:00
|
|
|
if (FindValue(aAtts, nsGkAtoms::name, &name)) {
|
2004-12-15 15:37:23 +00:00
|
|
|
mMethod->AddParameter(nsDependentString(name));
|
2001-11-13 04:09:56 +00:00
|
|
|
}
|
|
|
|
}
|
2002-01-09 01:37:50 +00:00
|
|
|
|
|
|
|
nsresult
|
2002-12-02 23:24:57 +00:00
|
|
|
nsXBLContentSink::CreateElement(const PRUnichar** aAtts, PRUint32 aAttsCount,
|
|
|
|
nsINodeInfo* aNodeInfo, PRUint32 aLineNumber,
|
|
|
|
nsIContent** aResult, PRBool* aAppendContent)
|
2002-01-09 01:37:50 +00:00
|
|
|
{
|
2003-04-11 00:56:27 +00:00
|
|
|
#ifdef MOZ_XUL
|
2002-12-02 23:24:57 +00:00
|
|
|
if (!aNodeInfo->NamespaceEquals(kNameSpaceID_XUL)) {
|
2003-04-11 00:56:27 +00:00
|
|
|
#endif
|
2002-12-02 23:24:57 +00:00
|
|
|
return nsXMLContentSink::CreateElement(aAtts, aAttsCount, aNodeInfo,
|
|
|
|
aLineNumber, aResult,
|
|
|
|
aAppendContent);
|
2003-04-11 00:56:27 +00:00
|
|
|
#ifdef MOZ_XUL
|
2002-12-02 23:24:57 +00:00
|
|
|
}
|
2002-01-09 01:37:50 +00:00
|
|
|
|
2002-12-02 23:24:57 +00:00
|
|
|
*aAppendContent = PR_TRUE;
|
|
|
|
nsXULPrototypeElement* prototype = new nsXULPrototypeElement();
|
|
|
|
if (!prototype)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2002-01-09 01:37:50 +00:00
|
|
|
|
2002-12-02 23:24:57 +00:00
|
|
|
prototype->mNodeInfo = aNodeInfo;
|
2006-06-13 03:07:47 +00:00
|
|
|
// XXX - we need to do exactly what the XUL content-sink does (eg,
|
|
|
|
// look for 'type', 'version' etc attributes)
|
|
|
|
prototype->mScriptTypeID = nsIProgrammingLanguage::JAVASCRIPT;
|
2002-01-09 01:37:50 +00:00
|
|
|
|
2002-12-02 23:24:57 +00:00
|
|
|
AddAttributesToXULPrototype(aAtts, aAttsCount, prototype);
|
|
|
|
|
2004-01-09 00:01:05 +00:00
|
|
|
nsresult rv = nsXULElement::Create(prototype, mDocument, PR_FALSE, aResult);
|
|
|
|
|
|
|
|
// XUL prototype elements start with a refcnt of 1 to represent
|
|
|
|
// ownership by the XUL prototype document. In our case we have no
|
|
|
|
// prototype document, so release that reference. The Create call
|
|
|
|
// above took a reference.
|
|
|
|
prototype->Release();
|
|
|
|
|
|
|
|
return rv;
|
2003-04-11 00:56:27 +00:00
|
|
|
#endif
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXBLContentSink::AddAttributes(const PRUnichar** aAtts,
|
2002-12-02 23:24:57 +00:00
|
|
|
nsIContent* aContent)
|
2002-01-09 01:37:50 +00:00
|
|
|
{
|
2006-05-05 06:52:21 +00:00
|
|
|
if (aContent->IsNodeOfType(nsINode::eXUL))
|
2002-01-09 01:37:50 +00:00
|
|
|
return NS_OK; // Nothing to do, since the proto already has the attrs.
|
2002-12-02 23:24:57 +00:00
|
|
|
|
|
|
|
return nsXMLContentSink::AddAttributes(aAtts, aContent);
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
|
|
|
|
2003-04-11 00:56:27 +00:00
|
|
|
#ifdef MOZ_XUL
|
2002-01-09 01:37:50 +00:00
|
|
|
nsresult
|
|
|
|
nsXBLContentSink::AddAttributesToXULPrototype(const PRUnichar **aAtts,
|
|
|
|
PRUint32 aAttsCount,
|
|
|
|
nsXULPrototypeElement* aElement)
|
|
|
|
{
|
|
|
|
// Add tag attributes to the element
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Create storage for the attributes
|
|
|
|
nsXULPrototypeAttribute* attrs = nsnull;
|
|
|
|
if (aAttsCount > 0) {
|
|
|
|
attrs = new nsXULPrototypeAttribute[aAttsCount];
|
|
|
|
if (!attrs)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
aElement->mAttributes = attrs;
|
|
|
|
aElement->mNumAttributes = aAttsCount;
|
|
|
|
|
|
|
|
// Copy the attributes into the prototype
|
2004-12-15 15:37:23 +00:00
|
|
|
nsCOMPtr<nsIAtom> prefix, localName;
|
2004-02-10 09:08:06 +00:00
|
|
|
|
|
|
|
PRUint32 i;
|
|
|
|
for (i = 0; i < aAttsCount; ++i) {
|
2002-01-09 01:37:50 +00:00
|
|
|
PRInt32 nameSpaceID;
|
2004-12-15 15:37:23 +00:00
|
|
|
nsContentUtils::SplitExpatName(aAtts[i * 2], getter_AddRefs(prefix),
|
|
|
|
getter_AddRefs(localName), &nameSpaceID);
|
2002-01-09 01:37:50 +00:00
|
|
|
|
2004-02-10 09:08:06 +00:00
|
|
|
if (nameSpaceID == kNameSpaceID_None) {
|
2004-12-15 15:37:23 +00:00
|
|
|
attrs[i].mName.SetTo(localName);
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
2004-02-10 09:08:06 +00:00
|
|
|
else {
|
|
|
|
nsCOMPtr<nsINodeInfo> ni;
|
2004-12-15 15:37:23 +00:00
|
|
|
mNodeInfoManager->GetNodeInfo(localName, prefix, nameSpaceID,
|
2004-02-10 09:08:06 +00:00
|
|
|
getter_AddRefs(ni));
|
|
|
|
attrs[i].mName.SetTo(ni);
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
2004-02-10 09:08:06 +00:00
|
|
|
|
|
|
|
rv = aElement->SetAttrAt(i, nsDependentString(aAtts[i * 2 + 1]),
|
|
|
|
mDocumentURI);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2003-04-11 00:56:27 +00:00
|
|
|
#endif
|