2011-04-12 16:31:55 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
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/. */
|
1999-10-29 05:21:15 +04:00
|
|
|
|
2006-12-22 19:11:16 +03:00
|
|
|
#include "nsXULPrototypeDocument.h"
|
2013-03-26 19:31:53 +04:00
|
|
|
#include "XULDocument.h"
|
2006-12-22 19:11:16 +03:00
|
|
|
|
2002-11-14 21:16:31 +03:00
|
|
|
#include "nsAString.h"
|
2001-07-31 23:05:34 +04:00
|
|
|
#include "nsIObjectInputStream.h"
|
|
|
|
#include "nsIObjectOutputStream.h"
|
1999-11-18 05:25:33 +03:00
|
|
|
#include "nsIPrincipal.h"
|
2012-10-25 19:01:07 +04:00
|
|
|
#include "nsJSPrincipals.h"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
#include "nsIScriptObjectPrincipal.h"
|
2000-01-23 01:00:35 +03:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
|
|
|
#include "nsIServiceManager.h"
|
2006-12-22 19:11:16 +03:00
|
|
|
#include "nsIArray.h"
|
1999-11-18 05:25:33 +03:00
|
|
|
#include "nsIURI.h"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
#include "jsapi.h"
|
2013-07-30 03:45:26 +04:00
|
|
|
#include "jsfriendapi.h"
|
2000-03-27 03:17:01 +04:00
|
|
|
#include "nsString.h"
|
2000-04-15 05:56:47 +04:00
|
|
|
#include "nsIConsoleService.h"
|
|
|
|
#include "nsIScriptError.h"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
#include "nsDOMCID.h"
|
2004-06-25 16:26:02 +04:00
|
|
|
#include "nsNodeInfoManager.h"
|
2004-02-10 12:08:06 +03:00
|
|
|
#include "nsContentUtils.h"
|
2008-10-08 15:41:52 +04:00
|
|
|
#include "nsCCUncollectableMarker.h"
|
2010-09-03 07:07:49 +04:00
|
|
|
#include "xpcpublic.h"
|
2012-05-03 08:35:38 +04:00
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2012-10-09 22:50:27 +04:00
|
|
|
using mozilla::dom::DestroyProtoAndIfaceCache;
|
2013-03-26 19:31:53 +04:00
|
|
|
using mozilla::dom::XULDocument;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t nsXULPrototypeDocument::gRefCnt;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
|
1999-10-29 05:21:15 +04:00
|
|
|
//----------------------------------------------------------------------
|
2000-01-23 01:00:35 +03:00
|
|
|
//
|
|
|
|
// ctors, dtors, n' stuff
|
|
|
|
//
|
1999-10-29 05:21:15 +04:00
|
|
|
|
|
|
|
nsXULPrototypeDocument::nsXULPrototypeDocument()
|
2012-07-30 18:20:58 +04:00
|
|
|
: mRoot(nullptr), mLoaded(false), mCCGeneration(0), mGCNumber(0) {
|
2003-05-24 06:14:23 +04:00
|
|
|
++gRefCnt;
|
1999-10-29 05:21:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsXULPrototypeDocument::Init() {
|
2004-06-25 16:26:02 +04:00
|
|
|
mNodeInfoManager = new nsNodeInfoManager();
|
2012-07-30 18:20:58 +04:00
|
|
|
return mNodeInfoManager->Init(nullptr);
|
1999-10-29 05:21:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsXULPrototypeDocument::~nsXULPrototypeDocument() {
|
2001-11-05 09:45:04 +03:00
|
|
|
if (mRoot) mRoot->ReleaseSubtree();
|
1999-10-29 05:21:15 +04:00
|
|
|
}
|
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsXULPrototypeDocument)
|
|
|
|
|
2011-07-01 18:02:04 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsXULPrototypeDocument)
|
2014-06-06 12:06:25 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPrototypeWaiters)
|
2011-07-01 18:02:04 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2007-03-08 14:17:16 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXULPrototypeDocument)
|
2011-12-29 18:34:05 +04:00
|
|
|
if (nsCCUncollectableMarker::InGeneration(cb, tmp->mCCGeneration)) {
|
|
|
|
return NS_SUCCESS_INTERRUPTED_TRAVERSE;
|
|
|
|
}
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRoot)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mNodeInfoManager)
|
2014-06-06 12:06:25 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPrototypeWaiters)
|
2007-03-08 14:17:16 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2007-04-25 20:35:27 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsXULPrototypeDocument)
|
2007-08-10 02:30:30 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISerializable)
|
2013-08-20 03:24:27 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2007-03-08 14:17:16 +03:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2011-03-06 14:11:31 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsXULPrototypeDocument)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsXULPrototypeDocument)
|
1999-10-29 05:21:15 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2006-12-22 19:11:16 +03:00
|
|
|
NS_NewXULPrototypeDocument(nsXULPrototypeDocument** aResult) {
|
2015-03-31 17:05:07 +03:00
|
|
|
*aResult = nullptr;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsXULPrototypeDocument> doc = new nsXULPrototypeDocument();
|
1999-10-29 05:21:15 +04:00
|
|
|
|
2015-03-31 17:05:07 +03:00
|
|
|
nsresult rv = doc->Init();
|
1999-10-29 05:21:15 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2015-03-31 17:05:07 +03:00
|
|
|
doc.forget(aResult);
|
1999-10-29 05:21:15 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-07-31 23:05:34 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsISerializable methods
|
|
|
|
//
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULPrototypeDocument::Read(nsIObjectInputStream* aStream) {
|
2014-03-15 23:00:17 +04:00
|
|
|
nsCOMPtr<nsISupports> supports;
|
2018-02-22 22:33:20 +03:00
|
|
|
nsresult rv = aStream->ReadObject(true, getter_AddRefs(supports));
|
|
|
|
if (NS_FAILED(rv)) {
|
1999-10-29 05:21:15 +04:00
|
|
|
return rv;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-03-15 23:00:17 +04:00
|
|
|
mURI = do_QueryInterface(supports);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2006-11-22 21:27:54 +03:00
|
|
|
// nsIPrincipal mNodeInfoManager->mPrincipal
|
2018-02-22 22:33:20 +03:00
|
|
|
rv = aStream->ReadObject(true, getter_AddRefs(supports));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-02-22 22:33:20 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> principal = do_QueryInterface(supports);
|
2006-11-22 21:27:54 +03:00
|
|
|
// Better safe than sorry....
|
|
|
|
mNodeInfoManager->SetDocumentPrincipal(principal);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2002-09-25 13:56:09 +04:00
|
|
|
mRoot = new nsXULPrototypeElement();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
// mozilla::dom::NodeInfo table
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<mozilla::dom::NodeInfo>> nodeInfos;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-06-07 01:15:25 +03:00
|
|
|
uint32_t count, i;
|
2018-02-22 22:33:20 +03:00
|
|
|
rv = aStream->Read32(&count);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2008-10-07 22:53:22 +04:00
|
|
|
nsAutoString namespaceURI, prefixStr, localName;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool prefixIsNull;
|
2017-10-03 01:05:19 +03:00
|
|
|
RefPtr<nsAtom> prefix;
|
2006-12-22 19:11:16 +03:00
|
|
|
for (i = 0; i < count; ++i) {
|
2018-02-22 22:33:20 +03:00
|
|
|
rv = aStream->ReadString(namespaceURI);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2014-03-15 23:00:17 +04:00
|
|
|
rv = aStream->ReadBoolean(&prefixIsNull);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2006-11-22 21:27:54 +03:00
|
|
|
if (prefixIsNull) {
|
|
|
|
prefix = nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2018-02-22 22:33:20 +03:00
|
|
|
rv = aStream->ReadString(prefixStr);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-02-22 22:33:20 +03:00
|
|
|
prefix = NS_Atomize(prefixStr);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-02-22 22:33:20 +03:00
|
|
|
rv = aStream->ReadString(localName);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2012-07-27 18:03:08 +04:00
|
|
|
}
|
2002-09-04 02:31:38 +04:00
|
|
|
|
2018-06-07 01:15:25 +03:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
|
|
|
// Using UINT16_MAX here as we don't know which nodeinfos will be
|
2018-02-22 22:33:20 +03:00
|
|
|
// used for attributes and which for elements. And that doesn't really
|
2011-06-14 11:56:49 +04:00
|
|
|
// matter.
|
2018-02-22 22:33:20 +03:00
|
|
|
rv = mNodeInfoManager->GetNodeInfo(localName, prefix, namespaceURI,
|
|
|
|
UINT16_MAX, getter_AddRefs(nodeInfo));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2012-07-27 18:03:08 +04:00
|
|
|
}
|
2008-10-07 22:53:22 +04:00
|
|
|
nodeInfos.AppendElement(nodeInfo);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2006-12-22 19:11:16 +03:00
|
|
|
// Document contents
|
2018-02-22 22:33:20 +03:00
|
|
|
uint32_t type;
|
|
|
|
while (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = aStream->Read32(&type);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2014-06-20 06:01:40 +04:00
|
|
|
break;
|
2002-09-04 02:31:38 +04:00
|
|
|
}
|
|
|
|
|
2006-11-12 01:27:00 +03:00
|
|
|
if ((nsXULPrototypeNode::Type)type == nsXULPrototypeNode::eType_PI) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsXULPrototypePI> pi = new nsXULPrototypePI();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-02-22 22:33:20 +03:00
|
|
|
rv = pi->Deserialize(aStream, this, mURI, &nodeInfos);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2012-07-27 18:03:08 +04:00
|
|
|
}
|
2018-02-22 22:33:20 +03:00
|
|
|
rv = AddProcessingInstruction(pi);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2012-07-27 18:03:08 +04:00
|
|
|
}
|
2006-11-12 01:27:00 +03:00
|
|
|
} else if ((nsXULPrototypeNode::Type)type ==
|
|
|
|
nsXULPrototypeNode::eType_Element) {
|
2018-02-22 22:33:20 +03:00
|
|
|
rv = mRoot->Deserialize(aStream, this, mURI, &nodeInfos);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2012-07-27 18:03:08 +04:00
|
|
|
}
|
2006-11-12 01:27:00 +03:00
|
|
|
break;
|
|
|
|
} else {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("Unexpected prototype node type");
|
2018-02-22 22:33:20 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2006-11-12 01:27:00 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2002-05-03 07:04:34 +04:00
|
|
|
|
2018-02-22 22:33:20 +03:00
|
|
|
return NotifyLoadDone();
|
2001-07-31 23:05:34 +04:00
|
|
|
}
|
|
|
|
|
2004-02-10 12:08:06 +03:00
|
|
|
static nsresult GetNodeInfos(nsXULPrototypeElement* aPrototype,
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<mozilla::dom::NodeInfo>>& aArray) {
|
2014-06-20 06:01:40 +04:00
|
|
|
if (aArray.IndexOf(aPrototype->mNodeInfo) == aArray.NoIndex) {
|
|
|
|
aArray.AppendElement(aPrototype->mNodeInfo);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2004-02-10 12:08:06 +03:00
|
|
|
// Search attributes
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t i;
|
2004-02-10 12:08:06 +03:00
|
|
|
for (i = 0; i < aPrototype->mNumAttributes; ++i) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> ni;
|
2004-02-10 12:08:06 +03:00
|
|
|
nsAttrName* name = &aPrototype->mAttributes[i].mName;
|
|
|
|
if (name->IsAtom()) {
|
2008-09-13 02:32:18 +04:00
|
|
|
ni = aPrototype->mNodeInfo->NodeInfoManager()->GetNodeInfo(
|
2012-07-30 18:20:58 +04:00
|
|
|
name->Atom(), nullptr, kNameSpaceID_None, nsINode::ATTRIBUTE_NODE);
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2004-02-10 12:08:06 +03:00
|
|
|
ni = name->NodeInfo();
|
|
|
|
}
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
if (aArray.IndexOf(ni) == aArray.NoIndex) {
|
|
|
|
aArray.AppendElement(ni);
|
2004-02-10 12:08:06 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2004-02-10 12:08:06 +03:00
|
|
|
|
|
|
|
// Search children
|
2008-10-08 15:41:52 +04:00
|
|
|
for (i = 0; i < aPrototype->mChildren.Length(); ++i) {
|
2004-02-10 12:08:06 +03:00
|
|
|
nsXULPrototypeNode* child = aPrototype->mChildren[i];
|
|
|
|
if (child->mType == nsXULPrototypeNode::eType_Element) {
|
2014-06-20 06:01:40 +04:00
|
|
|
nsresult rv =
|
|
|
|
GetNodeInfos(static_cast<nsXULPrototypeElement*>(child), aArray);
|
2004-02-10 12:08:06 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2004-02-10 12:08:06 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-07-31 23:05:34 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULPrototypeDocument::Write(nsIObjectOutputStream* aStream) {
|
|
|
|
nsresult rv;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
rv = aStream->WriteCompoundObject(mURI, NS_GET_IID(nsIURI), true);
|
2001-07-31 23:05:34 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
// nsIPrincipal mNodeInfoManager->mPrincipal
|
|
|
|
nsresult tmp =
|
|
|
|
aStream->WriteObject(mNodeInfoManager->DocumentPrincipal(), true);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2010-08-12 23:42:36 +04: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");
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
#endif
|
2001-07-31 23:05:34 +04:00
|
|
|
|
2006-11-22 21:27:54 +03:00
|
|
|
// mozilla::dom::NodeInfo table
|
2018-06-07 01:15:25 +03:00
|
|
|
nsTArray<RefPtr<mozilla::dom::NodeInfo>> nodeInfos;
|
2012-07-27 18:03:08 +04:00
|
|
|
if (mRoot) {
|
2018-06-07 01:15:25 +03:00
|
|
|
tmp = GetNodeInfos(mRoot, nodeInfos);
|
2012-07-27 18:03:08 +04:00
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2010-08-12 23:42:36 +04:00
|
|
|
uint32_t nodeInfoCount = nodeInfos.Length();
|
|
|
|
tmp = aStream->Write32(nodeInfoCount);
|
|
|
|
if (NS_FAILED(tmp)) {
|
2012-07-27 18:03:08 +04:00
|
|
|
rv = tmp;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2010-08-12 23:42:36 +04:00
|
|
|
uint32_t i;
|
|
|
|
for (i = 0; i < nodeInfoCount; ++i) {
|
|
|
|
mozilla::dom::NodeInfo* nodeInfo = nodeInfos[i];
|
|
|
|
NS_ENSURE_TRUE(nodeInfo, NS_ERROR_FAILURE);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2010-08-12 23:42:36 +04:00
|
|
|
nsAutoString namespaceURI;
|
2013-01-30 02:53:52 +04:00
|
|
|
nodeInfo->GetNamespaceURI(namespaceURI);
|
2010-08-12 23:42:36 +04:00
|
|
|
tmp = aStream->WriteWStringZ(namespaceURI.get());
|
2012-07-27 18:03:08 +04:00
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
2010-08-12 23:42:36 +04:00
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
nsAutoString prefix;
|
|
|
|
nodeInfo->GetPrefix(prefix);
|
|
|
|
bool nullPrefix = DOMStringIsNull(prefix);
|
2012-07-27 18:03:08 +04:00
|
|
|
tmp = aStream->WriteBoolean(nullPrefix);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2012-07-27 18:03:08 +04:00
|
|
|
if (!nullPrefix) {
|
|
|
|
tmp = aStream->WriteWStringZ(prefix.get());
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
|
|
|
}
|
2002-09-04 02:31:38 +04:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
nsAutoString localName;
|
|
|
|
nodeInfo->GetName(localName);
|
2012-07-27 18:03:08 +04:00
|
|
|
tmp = aStream->WriteWStringZ(localName.get());
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
|
|
|
}
|
2002-09-04 02:31:38 +04:00
|
|
|
|
2002-05-03 07:04:34 +04:00
|
|
|
// Now serialize the document contents
|
2018-06-07 01:15:25 +03:00
|
|
|
uint32_t count = mProcessingInstructions.Length();
|
2006-12-22 19:11:16 +03:00
|
|
|
for (i = 0; i < count; ++i) {
|
2006-11-12 01:27:00 +03:00
|
|
|
nsXULPrototypePI* pi = mProcessingInstructions[i];
|
2013-08-20 03:24:27 +04:00
|
|
|
tmp = pi->Serialize(aStream, this, &nodeInfos);
|
2012-07-27 18:03:08 +04:00
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
2006-11-12 01:27:00 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2006-11-12 01:27:00 +03:00
|
|
|
|
2012-07-27 18:03:08 +04:00
|
|
|
if (mRoot) {
|
2013-08-20 03:24:27 +04:00
|
|
|
tmp = mRoot->Serialize(aStream, this, &nodeInfos);
|
2012-07-27 18:03:08 +04:00
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2002-05-03 07:04:34 +04:00
|
|
|
return rv;
|
2001-07-31 23:05:34 +04:00
|
|
|
}
|
|
|
|
|
1999-10-29 05:21:15 +04:00
|
|
|
//----------------------------------------------------------------------
|
2000-01-23 01:00:35 +03:00
|
|
|
//
|
1999-10-29 05:21:15 +04:00
|
|
|
|
2006-11-22 21:27:54 +03:00
|
|
|
nsresult nsXULPrototypeDocument::InitPrincipal(nsIURI* aURI,
|
|
|
|
nsIPrincipal* aPrincipal) {
|
|
|
|
NS_ENSURE_ARG_POINTER(aURI);
|
|
|
|
|
|
|
|
mURI = aURI;
|
|
|
|
mNodeInfoManager->SetDocumentPrincipal(aPrincipal);
|
1999-10-29 05:21:15 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2006-12-22 19:11:16 +03:00
|
|
|
nsIURI* nsXULPrototypeDocument::GetURI() {
|
|
|
|
NS_ASSERTION(mURI, "null URI");
|
|
|
|
return mURI;
|
1999-10-29 05:21:15 +04:00
|
|
|
}
|
|
|
|
|
2006-12-22 19:11:16 +03:00
|
|
|
nsXULPrototypeElement* nsXULPrototypeDocument::GetRootElement() {
|
|
|
|
return mRoot;
|
1999-10-29 05:21:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsXULPrototypeDocument::SetRootElement(nsXULPrototypeElement* aElement) {
|
|
|
|
mRoot = aElement;
|
|
|
|
}
|
|
|
|
|
2006-11-12 01:27:00 +03:00
|
|
|
nsresult nsXULPrototypeDocument::AddProcessingInstruction(
|
|
|
|
nsXULPrototypePI* aPI) {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(aPI, "null ptr");
|
2006-11-12 01:27:00 +03:00
|
|
|
if (!mProcessingInstructions.AppendElement(aPI)) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-10-29 05:21:15 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
const nsTArray<RefPtr<nsXULPrototypePI>>&
|
2006-11-12 01:27:00 +03:00
|
|
|
nsXULPrototypeDocument::GetProcessingInstructions() const {
|
|
|
|
return mProcessingInstructions;
|
1999-10-29 05:21:15 +04:00
|
|
|
}
|
|
|
|
|
2006-11-22 21:27:54 +03:00
|
|
|
nsIPrincipal* nsXULPrototypeDocument::DocumentPrincipal() {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(mNodeInfoManager, "missing nodeInfoManager");
|
2006-11-22 21:27:54 +03:00
|
|
|
return mNodeInfoManager->DocumentPrincipal();
|
1999-11-18 05:25:33 +03:00
|
|
|
}
|
|
|
|
|
2007-07-11 23:44:27 +04:00
|
|
|
void nsXULPrototypeDocument::SetDocumentPrincipal(nsIPrincipal* aPrincipal) {
|
|
|
|
mNodeInfoManager->SetDocumentPrincipal(aPrincipal);
|
|
|
|
}
|
1999-10-29 05:21:15 +04:00
|
|
|
|
2013-08-20 03:24:28 +04:00
|
|
|
void nsXULPrototypeDocument::MarkInCCGeneration(uint32_t aCCGeneration) {
|
|
|
|
mCCGeneration = aCCGeneration;
|
2013-08-20 03:24:27 +04:00
|
|
|
}
|
|
|
|
|
2004-06-25 16:26:02 +04:00
|
|
|
nsNodeInfoManager* nsXULPrototypeDocument::GetNodeInfoManager() {
|
|
|
|
return mNodeInfoManager;
|
2002-07-24 02:16:45 +04:00
|
|
|
}
|
2001-07-31 23:05:34 +04:00
|
|
|
|
2013-03-26 19:31:53 +04:00
|
|
|
nsresult nsXULPrototypeDocument::AwaitLoadDone(XULDocument* aDocument,
|
|
|
|
bool* aResult) {
|
2001-07-31 23:05:34 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
*aResult = mLoaded;
|
|
|
|
|
|
|
|
if (!mLoaded) {
|
2006-12-22 19:11:16 +03:00
|
|
|
rv = mPrototypeWaiters.AppendElement(aDocument)
|
|
|
|
? NS_OK
|
|
|
|
: NS_ERROR_OUT_OF_MEMORY; // addrefs
|
2001-07-31 23:05:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsXULPrototypeDocument::NotifyLoadDone() {
|
2006-11-12 01:27:00 +03:00
|
|
|
// 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.
|
2001-07-31 23:05:34 +04:00
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mLoaded = true;
|
2001-07-31 23:05:34 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = mPrototypeWaiters.Length(); i > 0;) {
|
2006-12-22 19:11:16 +03:00
|
|
|
--i;
|
2011-10-17 18:59:28 +04:00
|
|
|
// true means that OnPrototypeLoadDone will also
|
2006-12-22 19:11:16 +03:00
|
|
|
// call ResumeWalk().
|
2011-10-17 18:59:28 +04:00
|
|
|
rv = mPrototypeWaiters[i]->OnPrototypeLoadDone(true);
|
2006-12-22 19:11:16 +03:00
|
|
|
if (NS_FAILED(rv)) break;
|
2001-07-31 23:05:34 +04:00
|
|
|
}
|
2006-12-22 19:11:16 +03:00
|
|
|
mPrototypeWaiters.Clear();
|
2001-07-31 23:05:34 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2017-11-14 20:10:30 +03:00
|
|
|
void nsXULPrototypeDocument::TraceProtos(JSTracer* aTrc) {
|
|
|
|
// Only trace the protos once per GC if we are marking.
|
|
|
|
if (aTrc->isMarkingTracer()) {
|
|
|
|
uint32_t currentGCNumber = aTrc->gcNumberForMarking();
|
|
|
|
if (mGCNumber == currentGCNumber) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mGCNumber = currentGCNumber;
|
2012-08-25 00:22:23 +04:00
|
|
|
}
|
|
|
|
|
2013-01-05 23:16:06 +04:00
|
|
|
if (mRoot) {
|
|
|
|
mRoot->TraceAllScripts(aTrc);
|
|
|
|
}
|
2012-08-25 00:22:23 +04:00
|
|
|
}
|