2011-04-12 05:31:55 -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
|
|
|
|
|
|
|
|
|
|
|
#include "nsXULPrototypeDocument.h"
|
2013-03-26 08:31:53 -07:00
|
|
|
#include "XULDocument.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsAString.h"
|
|
|
|
#include "nsIObjectInputStream.h"
|
|
|
|
#include "nsIObjectOutputStream.h"
|
|
|
|
#include "nsIPrincipal.h"
|
2012-10-25 08:01:07 -07:00
|
|
|
#include "nsJSPrincipals.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIScriptObjectPrincipal.h"
|
|
|
|
#include "nsIScriptSecurityManager.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIArray.h"
|
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "jsapi.h"
|
2013-07-29 16:45:26 -07:00
|
|
|
#include "jsfriendapi.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsIConsoleService.h"
|
|
|
|
#include "nsIScriptError.h"
|
|
|
|
#include "nsIDOMScriptObjectFactory.h"
|
|
|
|
#include "nsDOMCID.h"
|
|
|
|
#include "nsNodeInfoManager.h"
|
|
|
|
#include "nsContentUtils.h"
|
2008-10-08 04:41:52 -07:00
|
|
|
#include "nsCCUncollectableMarker.h"
|
2010-09-02 20:07:49 -07:00
|
|
|
#include "xpcpublic.h"
|
2012-05-02 21:35:38 -07:00
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
2012-03-30 21:42:20 -07:00
|
|
|
|
2012-10-09 11:50:27 -07:00
|
|
|
using mozilla::dom::DestroyProtoAndIfaceCache;
|
2013-03-26 08:31:53 -07:00
|
|
|
using mozilla::dom::XULDocument;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t nsXULPrototypeDocument::gRefCnt;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ctors, dtors, n' stuff
|
|
|
|
//
|
|
|
|
|
|
|
|
nsXULPrototypeDocument::nsXULPrototypeDocument()
|
2012-07-30 07:20:58 -07:00
|
|
|
: mRoot(nullptr),
|
2011-12-29 06:34:05 -08:00
|
|
|
mLoaded(false),
|
2012-08-24 13:22:23 -07:00
|
|
|
mCCGeneration(0),
|
|
|
|
mGCNumber(0)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
++gRefCnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULPrototypeDocument::Init()
|
|
|
|
{
|
|
|
|
mNodeInfoManager = new nsNodeInfoManager();
|
|
|
|
NS_ENSURE_TRUE(mNodeInfoManager, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return mNodeInfoManager->Init(nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsXULPrototypeDocument::~nsXULPrototypeDocument()
|
|
|
|
{
|
|
|
|
if (mRoot)
|
|
|
|
mRoot->ReleaseSubtree();
|
|
|
|
}
|
|
|
|
|
2013-08-01 18:29:05 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsXULPrototypeDocument)
|
|
|
|
|
2011-07-01 07:02:04 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsXULPrototypeDocument)
|
2014-06-06 01:06:25 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPrototypeWaiters)
|
2011-07-01 07:02:04 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXULPrototypeDocument)
|
2011-12-29 06:34:05 -08:00
|
|
|
if (nsCCUncollectableMarker::InGeneration(cb, tmp->mCCGeneration)) {
|
|
|
|
return NS_SUCCESS_INTERRUPTED_TRAVERSE;
|
|
|
|
}
|
2012-11-14 23:32:40 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRoot)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mNodeInfoManager)
|
2014-06-06 01:06:25 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPrototypeWaiters)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2007-04-25 09:35:27 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsXULPrototypeDocument)
|
2007-08-09 15:30:30 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISerializable)
|
2013-08-19 16:24:27 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2011-03-06 03:11:31 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsXULPrototypeDocument)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsXULPrototypeDocument)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
NS_NewXULPrototypeDocument(nsXULPrototypeDocument** aResult)
|
|
|
|
{
|
|
|
|
*aResult = new nsXULPrototypeDocument();
|
|
|
|
if (! *aResult)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
rv = (*aResult)->Init();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
delete *aResult;
|
2012-07-30 07:20:58 -07:00
|
|
|
*aResult = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsISerializable methods
|
|
|
|
//
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULPrototypeDocument::Read(nsIObjectInputStream* aStream)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
2014-03-15 12:00:17 -07:00
|
|
|
nsCOMPtr<nsISupports> supports;
|
|
|
|
rv = aStream->ReadObject(true, getter_AddRefs(supports));
|
|
|
|
mURI = do_QueryInterface(supports);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t count, i;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIURI> styleOverlayURI;
|
|
|
|
|
2012-07-27 07:03:08 -07:00
|
|
|
nsresult tmp = aStream->Read32(&count);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
for (i = 0; i < count; ++i) {
|
2014-03-15 12:00:17 -07:00
|
|
|
tmp = aStream->ReadObject(true, getter_AddRefs(supports));
|
2012-07-27 07:03:08 -07:00
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2014-03-15 12:00:17 -07:00
|
|
|
styleOverlayURI = do_QueryInterface(supports);
|
2007-03-22 10:30:00 -07:00
|
|
|
mStyleSheetReferences.AppendObject(styleOverlayURI);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// nsIPrincipal mNodeInfoManager->mPrincipal
|
|
|
|
nsCOMPtr<nsIPrincipal> principal;
|
2014-03-15 12:00:17 -07:00
|
|
|
tmp = aStream->ReadObject(true, getter_AddRefs(supports));
|
|
|
|
principal = do_QueryInterface(supports);
|
2012-07-27 07:03:08 -07:00
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
// Better safe than sorry....
|
|
|
|
mNodeInfoManager->SetDocumentPrincipal(principal);
|
|
|
|
|
|
|
|
mRoot = new nsXULPrototypeElement();
|
|
|
|
if (! mRoot)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2014-06-19 19:01:40 -07:00
|
|
|
// mozilla::dom::NodeInfo table
|
|
|
|
nsTArray<nsRefPtr<mozilla::dom::NodeInfo>> nodeInfos;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-27 07:03:08 -07:00
|
|
|
tmp = aStream->Read32(&count);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2008-10-07 11:53:22 -07:00
|
|
|
nsAutoString namespaceURI, prefixStr, localName;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool prefixIsNull;
|
2008-10-07 11:53:22 -07:00
|
|
|
nsCOMPtr<nsIAtom> prefix;
|
2007-03-22 10:30:00 -07:00
|
|
|
for (i = 0; i < count; ++i) {
|
2012-07-27 07:03:08 -07:00
|
|
|
tmp = aStream->ReadString(namespaceURI);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
|
|
|
tmp = aStream->ReadBoolean(&prefixIsNull);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2008-10-07 11:53:22 -07:00
|
|
|
if (prefixIsNull) {
|
2012-07-30 07:20:58 -07:00
|
|
|
prefix = nullptr;
|
2008-10-07 11:53:22 -07:00
|
|
|
} else {
|
2012-07-27 07:03:08 -07:00
|
|
|
tmp = aStream->ReadString(prefixStr);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2008-10-07 11:53:22 -07:00
|
|
|
prefix = do_GetAtom(prefixStr);
|
|
|
|
}
|
2012-07-27 07:03:08 -07:00
|
|
|
tmp = aStream->ReadString(localName);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-06-19 19:01:40 -07:00
|
|
|
nsRefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2012-09-27 23:57:33 -07:00
|
|
|
// Using UINT16_MAX here as we don't know which nodeinfos will be
|
2011-06-14 00:56:49 -07:00
|
|
|
// used for attributes and which for elements. And that doesn't really
|
|
|
|
// matter.
|
2012-07-27 07:03:08 -07:00
|
|
|
tmp = mNodeInfoManager->GetNodeInfo(localName, prefix, namespaceURI,
|
2012-09-27 23:57:33 -07:00
|
|
|
UINT16_MAX,
|
2008-10-07 11:53:22 -07:00
|
|
|
getter_AddRefs(nodeInfo));
|
2012-07-27 07:03:08 -07:00
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2014-06-19 19:01:40 -07:00
|
|
|
nodeInfos.AppendElement(nodeInfo);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Document contents
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t type;
|
2007-03-22 10:30:00 -07:00
|
|
|
while (NS_SUCCEEDED(rv)) {
|
2012-07-27 07:03:08 -07:00
|
|
|
tmp = aStream->Read32(&type);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if ((nsXULPrototypeNode::Type)type == nsXULPrototypeNode::eType_PI) {
|
2008-10-08 04:41:52 -07:00
|
|
|
nsRefPtr<nsXULPrototypePI> pi = new nsXULPrototypePI();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (! pi) {
|
2012-07-27 07:03:08 -07:00
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-08-19 16:24:27 -07:00
|
|
|
tmp = pi->Deserialize(aStream, this, mURI, &nodeInfos);
|
2012-07-27 07:03:08 -07:00
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
|
|
|
tmp = AddProcessingInstruction(pi);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
} else if ((nsXULPrototypeNode::Type)type == nsXULPrototypeNode::eType_Element) {
|
2013-08-19 16:24:27 -07:00
|
|
|
tmp = mRoot->Deserialize(aStream, this, mURI, &nodeInfos);
|
2012-07-27 07:03:08 -07:00
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
NS_NOTREACHED("Unexpected prototype node type");
|
2012-07-27 07:03:08 -07:00
|
|
|
rv = NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-07-27 07:03:08 -07:00
|
|
|
tmp = NotifyLoadDone();
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsresult
|
|
|
|
GetNodeInfos(nsXULPrototypeElement* aPrototype,
|
2014-06-19 19:01:40 -07:00
|
|
|
nsTArray<nsRefPtr<mozilla::dom::NodeInfo>>& aArray)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-06-19 19:01:40 -07:00
|
|
|
if (aArray.IndexOf(aPrototype->mNodeInfo) == aArray.NoIndex) {
|
|
|
|
aArray.AppendElement(aPrototype->mNodeInfo);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Search attributes
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t i;
|
2007-03-22 10:30:00 -07:00
|
|
|
for (i = 0; i < aPrototype->mNumAttributes; ++i) {
|
2014-06-19 19:01:40 -07:00
|
|
|
nsRefPtr<mozilla::dom::NodeInfo> ni;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAttrName* name = &aPrototype->mAttributes[i].mName;
|
|
|
|
if (name->IsAtom()) {
|
2008-09-12 15:32:18 -07:00
|
|
|
ni = aPrototype->mNodeInfo->NodeInfoManager()->
|
2012-07-30 07:20:58 -07:00
|
|
|
GetNodeInfo(name->Atom(), nullptr, kNameSpaceID_None,
|
2011-06-14 00:56:49 -07:00
|
|
|
nsIDOMNode::ATTRIBUTE_NODE);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
ni = name->NodeInfo();
|
|
|
|
}
|
|
|
|
|
2014-06-19 19:01:40 -07:00
|
|
|
if (aArray.IndexOf(ni) == aArray.NoIndex) {
|
|
|
|
aArray.AppendElement(ni);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Search children
|
2008-10-08 04:41:52 -07:00
|
|
|
for (i = 0; i < aPrototype->mChildren.Length(); ++i) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXULPrototypeNode* child = aPrototype->mChildren[i];
|
|
|
|
if (child->mType == nsXULPrototypeNode::eType_Element) {
|
2014-06-19 19:01:40 -07:00
|
|
|
nsresult rv =
|
|
|
|
GetNodeInfos(static_cast<nsXULPrototypeElement*>(child), aArray);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULPrototypeDocument::Write(nsIObjectOutputStream* aStream)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
rv = aStream->WriteCompoundObject(mURI, NS_GET_IID(nsIURI), true);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t count;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
count = mStyleSheetReferences.Count();
|
2012-07-27 07:03:08 -07:00
|
|
|
nsresult tmp = aStream->Write32(count);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t i;
|
2007-03-22 10:30:00 -07:00
|
|
|
for (i = 0; i < count; ++i) {
|
2012-07-27 07:03:08 -07:00
|
|
|
tmp = aStream->WriteCompoundObject(mStyleSheetReferences[i],
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_GET_IID(nsIURI), true);
|
2012-07-27 07:03:08 -07:00
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// nsIPrincipal mNodeInfoManager->mPrincipal
|
2012-07-27 07:03:08 -07:00
|
|
|
tmp = aStream->WriteObject(mNodeInfoManager->DocumentPrincipal(),
|
2011-10-17 07:59:28 -07:00
|
|
|
true);
|
2012-07-27 07:03:08 -07:00
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-12 12:42:36 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
// XXX Worrisome if we're caching things without system principal.
|
|
|
|
if (!nsContentUtils::IsSystemPrincipal(mNodeInfoManager->DocumentPrincipal())) {
|
|
|
|
NS_WARNING("Serializing document without system principal");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-06-19 19:01:40 -07:00
|
|
|
// mozilla::dom::NodeInfo table
|
|
|
|
nsTArray<nsRefPtr<mozilla::dom::NodeInfo>> nodeInfos;
|
2012-07-27 07:03:08 -07:00
|
|
|
if (mRoot) {
|
|
|
|
tmp = GetNodeInfos(mRoot, nodeInfos);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-06-19 19:01:40 -07:00
|
|
|
uint32_t nodeInfoCount = nodeInfos.Length();
|
2012-07-27 07:03:08 -07:00
|
|
|
tmp = aStream->Write32(nodeInfoCount);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
for (i = 0; i < nodeInfoCount; ++i) {
|
2014-06-19 19:01:40 -07:00
|
|
|
mozilla::dom::NodeInfo *nodeInfo = nodeInfos[i];
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_TRUE(nodeInfo, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsAutoString namespaceURI;
|
2013-01-29 14:53:52 -08:00
|
|
|
nodeInfo->GetNamespaceURI(namespaceURI);
|
2012-07-27 07:03:08 -07:00
|
|
|
tmp = aStream->WriteWStringZ(namespaceURI.get());
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-10-07 11:53:22 -07:00
|
|
|
nsAutoString prefix;
|
|
|
|
nodeInfo->GetPrefix(prefix);
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nullPrefix = DOMStringIsNull(prefix);
|
2012-07-27 07:03:08 -07:00
|
|
|
tmp = aStream->WriteBoolean(nullPrefix);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2008-10-07 11:53:22 -07:00
|
|
|
if (!nullPrefix) {
|
2012-07-27 07:03:08 -07:00
|
|
|
tmp = aStream->WriteWStringZ(prefix.get());
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2008-10-07 11:53:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString localName;
|
|
|
|
nodeInfo->GetName(localName);
|
2012-07-27 07:03:08 -07:00
|
|
|
tmp = aStream->WriteWStringZ(localName.get());
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now serialize the document contents
|
|
|
|
count = mProcessingInstructions.Length();
|
|
|
|
for (i = 0; i < count; ++i) {
|
|
|
|
nsXULPrototypePI* pi = mProcessingInstructions[i];
|
2013-08-19 16:24:27 -07:00
|
|
|
tmp = pi->Serialize(aStream, this, &nodeInfos);
|
2012-07-27 07:03:08 -07:00
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-07-27 07:03:08 -07:00
|
|
|
if (mRoot) {
|
2013-08-19 16:24:27 -07:00
|
|
|
tmp = mRoot->Serialize(aStream, this, &nodeInfos);
|
2012-07-27 07:03:08 -07:00
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULPrototypeDocument::InitPrincipal(nsIURI* aURI, nsIPrincipal* aPrincipal)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aURI);
|
|
|
|
|
|
|
|
mURI = aURI;
|
|
|
|
mNodeInfoManager->SetDocumentPrincipal(aPrincipal);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsIURI*
|
|
|
|
nsXULPrototypeDocument::GetURI()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mURI, "null URI");
|
|
|
|
return mURI;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsXULPrototypeElement*
|
|
|
|
nsXULPrototypeDocument::GetRootElement()
|
|
|
|
{
|
|
|
|
return mRoot;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXULPrototypeDocument::SetRootElement(nsXULPrototypeElement* aElement)
|
|
|
|
{
|
|
|
|
mRoot = aElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULPrototypeDocument::AddProcessingInstruction(nsXULPrototypePI* aPI)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aPI, "null ptr");
|
|
|
|
if (!mProcessingInstructions.AppendElement(aPI)) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-10-08 04:41:52 -07:00
|
|
|
const nsTArray<nsRefPtr<nsXULPrototypePI> >&
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXULPrototypeDocument::GetProcessingInstructions() const
|
|
|
|
{
|
|
|
|
return mProcessingInstructions;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXULPrototypeDocument::AddStyleSheetReference(nsIURI* aURI)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aURI, "null ptr");
|
|
|
|
if (!mStyleSheetReferences.AppendObject(aURI)) {
|
|
|
|
NS_WARNING("mStyleSheetReferences->AppendElement() failed."
|
|
|
|
"Stylesheet overlay dropped.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsCOMArray<nsIURI>&
|
|
|
|
nsXULPrototypeDocument::GetStyleSheetReferences() const
|
|
|
|
{
|
|
|
|
return mStyleSheetReferences;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULPrototypeDocument::GetHeaderData(nsIAtom* aField, nsAString& aData) const
|
|
|
|
{
|
|
|
|
// XXX Not implemented
|
|
|
|
aData.Truncate();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULPrototypeDocument::SetHeaderData(nsIAtom* aField, const nsAString& aData)
|
|
|
|
{
|
|
|
|
// XXX Not implemented
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsIPrincipal*
|
|
|
|
nsXULPrototypeDocument::DocumentPrincipal()
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(mNodeInfoManager, "missing nodeInfoManager");
|
|
|
|
return mNodeInfoManager->DocumentPrincipal();
|
|
|
|
}
|
|
|
|
|
2007-07-11 12:44:27 -07:00
|
|
|
void
|
|
|
|
nsXULPrototypeDocument::SetDocumentPrincipal(nsIPrincipal* aPrincipal)
|
|
|
|
{
|
|
|
|
mNodeInfoManager->SetDocumentPrincipal(aPrincipal);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-08-19 16:24:28 -07:00
|
|
|
void
|
|
|
|
nsXULPrototypeDocument::MarkInCCGeneration(uint32_t aCCGeneration)
|
|
|
|
{
|
|
|
|
mCCGeneration = aCCGeneration;
|
2013-08-19 16:24:27 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsNodeInfoManager*
|
|
|
|
nsXULPrototypeDocument::GetNodeInfoManager()
|
|
|
|
{
|
|
|
|
return mNodeInfoManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
2013-03-26 08:31:53 -07:00
|
|
|
nsXULPrototypeDocument::AwaitLoadDone(XULDocument* aDocument, bool* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
*aResult = mLoaded;
|
|
|
|
|
|
|
|
if (!mLoaded) {
|
|
|
|
rv = mPrototypeWaiters.AppendElement(aDocument)
|
|
|
|
? NS_OK : NS_ERROR_OUT_OF_MEMORY; // addrefs
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULPrototypeDocument::NotifyLoadDone()
|
|
|
|
{
|
|
|
|
// Call back to each XUL document that raced to start the same
|
|
|
|
// prototype document load, lost the race, but hit the XUL
|
|
|
|
// prototype cache because the winner filled the cache with
|
|
|
|
// the not-yet-loaded prototype object.
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mLoaded = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = mPrototypeWaiters.Length(); i > 0; ) {
|
2007-03-22 10:30:00 -07:00
|
|
|
--i;
|
2011-10-17 07:59:28 -07:00
|
|
|
// true means that OnPrototypeLoadDone will also
|
2007-03-22 10:30:00 -07:00
|
|
|
// call ResumeWalk().
|
2011-10-17 07:59:28 -07:00
|
|
|
rv = mPrototypeWaiters[i]->OnPrototypeLoadDone(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv)) break;
|
|
|
|
}
|
|
|
|
mPrototypeWaiters.Clear();
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-08-24 13:22:23 -07:00
|
|
|
void
|
|
|
|
nsXULPrototypeDocument::TraceProtos(JSTracer* aTrc, uint32_t aGCNumber)
|
|
|
|
{
|
|
|
|
// Only trace the protos once per GC.
|
|
|
|
if (mGCNumber == aGCNumber) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mGCNumber = aGCNumber;
|
2013-01-05 11:16:06 -08:00
|
|
|
if (mRoot) {
|
|
|
|
mRoot->TraceAllScripts(aTrc);
|
|
|
|
}
|
2012-08-24 13:22:23 -07:00
|
|
|
}
|