Landing the initial changes to support XUL fragments.

This commit is contained in:
hyatt%netscape.com 1999-03-10 01:37:31 +00:00
Родитель 52ad201ca1
Коммит bf1ce3afd5
8 изменённых файлов: 436 добавлений и 158 удалений

Просмотреть файл

@ -71,6 +71,8 @@
#include "nsIWebShell.h"
#include "nsIXULContentSink.h"
#include "nsIDOMXULElement.h"
#include "nsIXULParentDocument.h"
#include "nsIXULChildDocument.h"
#include "nsIXMLContent.h"
#include "nsDOMCID.h"
#include "nsLayoutCID.h"
@ -306,7 +308,9 @@ class XULDocumentImpl : public nsIDocument,
public nsIScriptObjectOwner,
public nsIHTMLContentContainer,
public nsIDOMNodeObserver,
public nsIDOMElementObserver
public nsIDOMElementObserver,
public nsIXULParentDocument,
public nsIXULChildDocument
{
public:
XULDocumentImpl();
@ -479,6 +483,7 @@ public:
NS_IMETHOD GetElementsForResource(nsIRDFResource* aResource, nsISupportsArray* aElements);
NS_IMETHOD CreateContents(nsIContent* aElement);
NS_IMETHOD AddContentModelBuilder(nsIRDFContentModelBuilder* aBuilder);
NS_IMETHOD GetDocumentDataSource(nsIRDFDataSource** aDatasource);
// nsIDOMDocument interface
NS_IMETHOD GetDoctype(nsIDOMDocumentType** aDoctype);
@ -498,7 +503,15 @@ public:
// nsIDOMXULDocument interface
NS_DECL_IDOMXULDOCUMENT
// nsIXULParentDocument interface
NS_IMETHOD GetContentViewerContainer(nsIContentViewerContainer** aContainer);
NS_IMETHOD GetCommand(nsString& aCommand);
// nsIXULChildDocument Interface
NS_IMETHOD SetFragmentRoot(nsIContent* aFragmentRoot);
NS_IMETHOD GetFragmentRoot(nsIContent** aFragmentRoot);
// nsIDOMNode interface
NS_IMETHOD GetNodeName(nsString& aNodeName);
NS_IMETHOD GetNodeValue(nsString& aNodeValue);
@ -603,6 +616,9 @@ protected:
nsIRDFDataSource* mDocumentDataSource;
nsIParser* mParser;
nsILineBreaker* mLineBreaker;
nsIContentViewerContainer* mContentViewerContainer;
nsString mCommand;
nsIContent* mFragmentRoot;
};
PRInt32 XULDocumentImpl::gRefCnt;
@ -630,7 +646,10 @@ XULDocumentImpl::XULDocumentImpl(void)
mLocalDataSource(nsnull),
mDocumentDataSource(nsnull),
mLineBreaker(nsnull),
mParser(nsnull)
mParser(nsnull),
mContentViewerContainer(nsnull),
mCommand(""),
mFragmentRoot(nsnull)
{
NS_INIT_REFCNT();
@ -673,6 +692,8 @@ XULDocumentImpl::~XULDocumentImpl()
NS_IF_RELEASE(mNameSpaceManager);
NS_IF_RELEASE(mParser);
NS_IF_RELEASE(mLineBreaker);
NS_IF_RELEASE(mContentViewerContainer);
NS_IF_RELEASE(mFragmentRoot);
if (--gRefCnt == 0) {
NS_IF_RELEASE(kIdAtom);
@ -719,6 +740,12 @@ XULDocumentImpl::QueryInterface(REFNSIID iid, void** result)
iid.Equals(kISupportsIID)) {
*result = NS_STATIC_CAST(nsIDocument*, this);
}
else if (iid.Equals(nsIXULParentDocument::GetIID())) {
*result = NS_STATIC_CAST(nsIXULParentDocument*, this);
}
else if (iid.Equals(nsIXULChildDocument::GetIID())) {
*result = NS_STATIC_CAST(nsIXULChildDocument*, this);
}
else if (iid.Equals(kIRDFDocumentIID) ||
iid.Equals(kIXMLDocumentIID)) {
*result = NS_STATIC_CAST(nsIRDFDocument*, this);
@ -774,6 +801,13 @@ XULDocumentImpl::StartDocumentLoad(nsIURL *aURL,
if (! aURL)
return NS_ERROR_NULL_POINTER;
if (aContainer && aContainer != mContentViewerContainer)
{
// AddRef and hold the container
NS_ADDREF(aContainer);
mContentViewerContainer = aContainer;
}
nsresult rv;
mDocumentTitle.Truncate();
@ -835,89 +869,92 @@ XULDocumentImpl::StartDocumentLoad(nsIURL *aURL,
return rv;
}
// Create a composite data source that'll tie together local and
// remote stores.
nsIRDFCompositeDataSource* db;
if (NS_FAILED(rv = nsComponentManager::CreateInstance(kRDFCompositeDataSourceCID,
nsnull,
kIRDFCompositeDataSourceIID,
(void**) &db))) {
NS_ERROR("couldn't create composite datasource");
return rv;
}
// Create various data sources and builders, but only do this if we're
// not a XUL fragment.
if (mFragmentRoot == nsnull) {
// Create a XUL content model builder
NS_IF_RELEASE(mXULBuilder);
if (NS_FAILED(rv = nsComponentManager::CreateInstance(kRDFXULBuilderCID,
nsnull,
kIRDFContentModelBuilderIID,
(void**) &mXULBuilder))) {
NS_ERROR("couldn't create XUL builder");
return rv;
}
nsIRDFCompositeDataSource* db;
if (NS_FAILED(rv = nsComponentManager::CreateInstance(kRDFCompositeDataSourceCID,
nsnull,
kIRDFCompositeDataSourceIID,
(void**) &db))) {
NS_ERROR("couldn't create composite datasource");
return rv;
}
if (NS_FAILED(rv = mXULBuilder->SetDataBase(db))) {
NS_ERROR("couldn't set builder's db");
return rv;
}
// Create a XUL content model builder
NS_IF_RELEASE(mXULBuilder);
if (NS_FAILED(rv = nsComponentManager::CreateInstance(kRDFXULBuilderCID,
nsnull,
kIRDFContentModelBuilderIID,
(void**) &mXULBuilder))) {
NS_ERROR("couldn't create XUL builder");
return rv;
}
NS_IF_RELEASE(mBuilders);
if (NS_FAILED(rv = AddContentModelBuilder(mXULBuilder))) {
NS_ERROR("could't add XUL builder");
return rv;
}
if (NS_FAILED(rv = mXULBuilder->SetDataBase(db))) {
NS_ERROR("couldn't set builder's db");
return rv;
}
// Create a "scratch" in-memory data store to associate with the
// document to be a catch-all for any doc-specific info that we
// need to store (e.g., current sort order, etc.)
//
// XXX This needs to be cloned across windows, and the final
// instance needs to be flushed to disk. It may be that this is
// really an RDFXML data source...
if (NS_FAILED(rv = nsComponentManager::CreateInstance(kRDFInMemoryDataSourceCID,
nsnull,
kIRDFDataSourceIID,
(void**) &mLocalDataSource))) {
NS_ERROR("couldn't create local data source");
return rv;
}
NS_IF_RELEASE(mBuilders);
if (NS_FAILED(rv = AddContentModelBuilder(mXULBuilder))) {
NS_ERROR("could't add XUL builder");
return rv;
}
if (NS_FAILED(rv = db->AddDataSource(mLocalDataSource))) {
NS_ERROR("couldn't add local data source to db");
return rv;
}
// Create a "scratch" in-memory data store to associate with the
// document to be a catch-all for any doc-specific info that we
// need to store (e.g., current sort order, etc.)
//
// XXX This needs to be cloned across windows, and the final
// instance needs to be flushed to disk. It may be that this is
// really an RDFXML data source...
if (NS_FAILED(rv = nsComponentManager::CreateInstance(kRDFInMemoryDataSourceCID,
nsnull,
kIRDFDataSourceIID,
(void**) &mLocalDataSource))) {
NS_ERROR("couldn't create local data source");
return rv;
}
// Now load the actual RDF/XML document data source. First, we'll
// see if the data source has been loaded and is registered with
// the RDF service. If so, do some monkey business to "pretend" to
// load it: really, we'll just walk its graph to generate the
// content model.
const char* uri;
if (NS_FAILED(rv = aURL->GetSpec(&uri)))
return rv;
if (NS_FAILED(rv = db->AddDataSource(mLocalDataSource))) {
NS_ERROR("couldn't add local data source to db");
return rv;
}
// We need to construct a new stream and load it. The stream will
// automagically register itself as a named data source, so if
// subsequent docs ask for it, they'll get the real deal. In the
// meantime, add us as an nsIRDFXMLDataSourceObserver so that
// we'll be notified when we need to load style sheets, etc.
NS_IF_RELEASE(mDocumentDataSource);
if (NS_FAILED(rv = nsComponentManager::CreateInstance(kRDFInMemoryDataSourceCID,
nsnull,
kIRDFDataSourceIID,
(void**) &mDocumentDataSource))) {
NS_ERROR("unable to create XUL datasource");
return rv;
}
// Now load the actual RDF/XML document data source. First, we'll
// see if the data source has been loaded and is registered with
// the RDF service. If so, do some monkey business to "pretend" to
// load it: really, we'll just walk its graph to generate the
// content model.
const char* uri;
if (NS_FAILED(rv = aURL->GetSpec(&uri)))
return rv;
if (NS_FAILED(rv = db->AddDataSource(mDocumentDataSource))) {
NS_ERROR("unable to add XUL datasource to db");
return rv;
}
// We need to construct a new stream and load it. The stream will
// automagically register itself as a named data source, so if
// subsequent docs ask for it, they'll get the real deal. In the
// meantime, add us as an nsIRDFXMLDataSourceObserver so that
// we'll be notified when we need to load style sheets, etc.
NS_IF_RELEASE(mDocumentDataSource);
if (NS_FAILED(rv = nsComponentManager::CreateInstance(kRDFInMemoryDataSourceCID,
nsnull,
kIRDFDataSourceIID,
(void**) &mDocumentDataSource))) {
NS_ERROR("unable to create XUL datasource");
return rv;
}
if (NS_FAILED(rv = mDocumentDataSource->Init(uri))) {
NS_ERROR("unable to initialize XUL data source");
return rv;
if (NS_FAILED(rv = db->AddDataSource(mDocumentDataSource))) {
NS_ERROR("unable to add XUL datasource to db");
return rv;
}
if (NS_FAILED(rv = mDocumentDataSource->Init(uri))) {
NS_ERROR("unable to initialize XUL data source");
return rv;
}
}
nsCOMPtr<nsIXULContentSink> sink;
@ -961,6 +998,8 @@ XULDocumentImpl::StartDocumentLoad(nsIURL *aURL,
return rv;
}
mCommand = aCommand;
mParser->RegisterDTD(dtd);
mParser->SetCommand(aCommand);
mParser->SetContentSink(sink);
@ -2031,7 +2070,14 @@ XULDocumentImpl::AddContentModelBuilder(nsIRDFContentModelBuilder* aBuilder)
return mBuilders->AppendElement(aBuilder) ? NS_OK : NS_ERROR_FAILURE;
}
NS_IMETHODIMP
XULDocumentImpl::GetDocumentDataSource(nsIRDFDataSource** aDataSource) {
if (mDocumentDataSource) {
NS_ADDREF(mDocumentDataSource);
*aDataSource = mDocumentDataSource;
}
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// nsIDOMDocument interface
@ -2284,6 +2330,52 @@ XULDocumentImpl::SearchForNodeByID(const nsString& anID,
}
}
////////////////////////////////////////////////////////////////////////
// nsIXULParentDocument interface
NS_IMETHODIMP
XULDocumentImpl::GetContentViewerContainer(nsIContentViewerContainer** aContainer)
{
if (mContentViewerContainer != nsnull)
{
NS_ADDREF(mContentViewerContainer);
*aContainer = mContentViewerContainer;
}
return NS_OK;
}
NS_IMETHODIMP
XULDocumentImpl::GetCommand(nsString& aCommand)
{
aCommand = mCommand;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// nsIXULChildDocument interface
NS_IMETHODIMP
XULDocumentImpl::SetFragmentRoot(nsIContent* aFragmentRoot)
{
if (aFragmentRoot != mFragmentRoot)
{
NS_IF_RELEASE(mFragmentRoot);
NS_IF_ADDREF(aFragmentRoot);
mFragmentRoot = aFragmentRoot;
}
return NS_OK;
}
NS_IMETHODIMP
XULDocumentImpl::GetFragmentRoot(nsIContent** aFragmentRoot)
{
if (mFragmentRoot) {
NS_ADDREF(mFragmentRoot);
*aFragmentRoot = mFragmentRoot;
}
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// nsIDOMNode interface
NS_IMETHODIMP

Просмотреть файл

@ -5,3 +5,6 @@ nsIDOMXULElement.h
nsIRDFContentModelBuilder.h
nsIRDFDocument.h
nsIXULSortService.h
nsIXULParentDocument.h
nsIXULChildDocument.h

Просмотреть файл

@ -32,6 +32,8 @@ EXPORTS = \
nsIRDFContentModelBuilder.h \
nsIRDFDocument.h \
nsIXULSortService.h \
nsIXULParentDocument.h \
nsIXULChildDocument.h \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))

Просмотреть файл

@ -27,7 +27,9 @@ EXPORTS = \
nsIDOMXULElement.h \
nsIRDFContentModelBuilder.h \
nsIRDFDocument.h \
nsIXULSortService.h \
nsIXULSortService.h \
nsIXULParentDocument.h \
nsIXULChildDocument.h \
$(NULL)
include <$(DEPTH)/config/rules.mak>

Просмотреть файл

@ -46,6 +46,9 @@ class nsIRDFResource;
/**
* RDF document extensions to nsIDocument
*/
class nsIRDFDataSource;
class nsIRDFDocument : public nsIXMLDocument
{
public:
@ -73,6 +76,8 @@ public:
NS_IMETHOD CreateContents(nsIContent* aElement) = 0;
NS_IMETHOD AddContentModelBuilder(nsIRDFContentModelBuilder* aBuilder) = 0;
NS_IMETHOD GetDocumentDataSource(nsIRDFDataSource** aDatasource) = 0;
};
// factory functions

Просмотреть файл

@ -42,7 +42,7 @@ class nsIDOMNode;
class nsIXULSortService : public nsISupports {
public:
static const nsIID& IID() { static nsIID iid = NS_IXULSORTSERVICE_IID; return iid; }
static const nsIID& GetIID() { static nsIID iid = NS_IXULSORTSERVICE_IID; return iid; }
NS_IMETHOD DoSort(nsIDOMNode* node, const nsString& sortResource, const nsString& sortDirection) = 0;
NS_IMETHOD OpenContainer(nsIRDFCompositeDataSource *db, nsIContent *container,

Просмотреть файл

@ -37,6 +37,8 @@
#include "nsIAtom.h"
#include "nsIContent.h"
#include "nsIDocument.h"
#include "nsIXULParentDocument.h"
#include "nsIXULChildDocument.h"
#include "nsIDOMElement.h"
#include "nsIDOMElementObserver.h"
#include "nsIDOMNode.h"
@ -62,6 +64,7 @@
#include "rdfutil.h"
#include "nsIDOMXULElement.h"
#include "nsIDOMXULDocument.h"
#include "nsIContentViewerContainer.h"
// XXX These are needed as scaffolding until we get to a more
// DOM-based solution.
@ -87,6 +90,7 @@ static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kRDFTreeBuilderCID, NS_RDFTREEBUILDER_CID);
static NS_DEFINE_CID(kRDFMenuBuilderCID, NS_RDFMENUBUILDER_CID);
static NS_DEFINE_CID(kRDFToolbarBuilderCID, NS_RDFTOOLBARBUILDER_CID);
static NS_DEFINE_CID(kCXULDocumentCID, NS_XULDOCUMENT_CID);
////////////////////////////////////////////////////////////////////////
// standard vocabulary items
@ -127,6 +131,7 @@ private:
static nsIAtom* kContainerAtom;
static nsIAtom* kXULContentsGeneratedAtom;
static nsIAtom* kXULIncludeSrcAtom;
static nsIAtom* kDataSourcesAtom;
static nsIAtom* kIdAtom;
static nsIAtom* kTreeAtom;
@ -231,6 +236,7 @@ PRInt32 RDFXULBuilderImpl::kNameSpaceID_XUL = kNameSpaceID_Unknown;
nsIAtom* RDFXULBuilderImpl::kContainerAtom;
nsIAtom* RDFXULBuilderImpl::kXULContentsGeneratedAtom;
nsIAtom* RDFXULBuilderImpl::kXULIncludeSrcAtom;
nsIAtom* RDFXULBuilderImpl::kIdAtom;
nsIAtom* RDFXULBuilderImpl::kDataSourcesAtom;
nsIAtom* RDFXULBuilderImpl::kTreeAtom;
@ -289,6 +295,7 @@ RDFXULBuilderImpl::RDFXULBuilderImpl(void)
kContainerAtom = NS_NewAtom("container");
kXULContentsGeneratedAtom = NS_NewAtom("xulcontentsgenerated");
kXULIncludeSrcAtom = NS_NewAtom("includesrc");
kIdAtom = NS_NewAtom("id");
kDataSourcesAtom = NS_NewAtom("datasources");
kTreeAtom = NS_NewAtom("tree");
@ -344,6 +351,7 @@ RDFXULBuilderImpl::~RDFXULBuilderImpl(void)
NS_IF_RELEASE(kContainerAtom);
NS_IF_RELEASE(kXULContentsGeneratedAtom);
NS_IF_RELEASE(kXULIncludeSrcAtom);
NS_IF_RELEASE(kIdAtom);
NS_IF_RELEASE(kDataSourcesAtom);
NS_IF_RELEASE(kTreeAtom);
@ -560,6 +568,80 @@ RDFXULBuilderImpl::CreateContents(nsIContent* aElement)
if (rv == NS_ERROR_RDF_CURSOR_EMPTY)
rv = NS_OK;
// Now that we've built the children, check to see if the includesrc attribute
// exists on the node.
nsString includeSrc;
if (NS_FAILED(rv = aElement->GetAttribute(kNameSpaceID_None,
kXULIncludeSrcAtom,
includeSrc))) {
NS_ERROR("unable to retrieve includeSrc attribute");
return rv;
}
if (rv == NS_CONTENT_ATTR_HAS_VALUE) {
// Build a URL object from the attribute's value.
nsCOMPtr<nsIURL> includeURL;
NS_NewURL(getter_AddRefs(includeURL), includeSrc);
nsCOMPtr<nsIDocument> subDocument;
if (NS_FAILED(rv = nsComponentManager::CreateInstance(kCXULDocumentCID,
nsnull,
kIDocumentIID,
(void **)getter_AddRefs(subDocument)))) {
NS_ERROR("Unable to initialize a XUL fragment's subdocument.");
return rv;
}
nsCOMPtr<nsIDocument> parentDoc;
aElement->GetDocument(*getter_AddRefs(parentDoc));
if (parentDoc == nsnull) {
NS_ERROR("Unable to retrieve parent document for a subdocument.");
return rv;
}
subDocument->SetParentDocument(parentDoc);
nsCOMPtr<nsIStreamListener> streamListener;
nsCOMPtr<nsIContentViewerContainer> container;
nsCOMPtr<nsIXULParentDocument> xulParentDocument;
xulParentDocument = do_QueryInterface(parentDoc);
if (xulParentDocument == nsnull) {
NS_ERROR("Unable to turn document into a XUL parent document.");
return rv;
}
if (NS_FAILED(rv = xulParentDocument->GetContentViewerContainer(getter_AddRefs(container)))) {
NS_ERROR("Unable to retrieve content viewer container from parent document.");
return rv;
}
nsAutoString command;
if (NS_FAILED(rv = xulParentDocument->GetCommand(command))) {
NS_ERROR("Unable to retrieve the command from parent document.");
return rv;
}
char* commandChars = command.ToNewCString();
nsCOMPtr<nsIXULChildDocument> xulChildDocument;
xulChildDocument = do_QueryInterface(subDocument);
if (xulChildDocument == nsnull) {
NS_ERROR("Unable to retrieve a XUL child document.");
return rv;
}
xulChildDocument->SetFragmentRoot(aElement);
if (NS_FAILED(rv = subDocument->StartDocumentLoad(includeURL, container, getter_AddRefs(streamListener),
commandChars))) {
NS_ERROR("Unable to kick off XUL subdocument's document load.");
delete [] commandChars;
return rv;
}
delete [] commandChars;
}
return rv;
}

Просмотреть файл

@ -71,6 +71,8 @@
#include "nsIWebShell.h"
#include "nsIXULContentSink.h"
#include "nsIDOMXULElement.h"
#include "nsIXULParentDocument.h"
#include "nsIXULChildDocument.h"
#include "nsIXMLContent.h"
#include "nsDOMCID.h"
#include "nsLayoutCID.h"
@ -306,7 +308,9 @@ class XULDocumentImpl : public nsIDocument,
public nsIScriptObjectOwner,
public nsIHTMLContentContainer,
public nsIDOMNodeObserver,
public nsIDOMElementObserver
public nsIDOMElementObserver,
public nsIXULParentDocument,
public nsIXULChildDocument
{
public:
XULDocumentImpl();
@ -479,6 +483,7 @@ public:
NS_IMETHOD GetElementsForResource(nsIRDFResource* aResource, nsISupportsArray* aElements);
NS_IMETHOD CreateContents(nsIContent* aElement);
NS_IMETHOD AddContentModelBuilder(nsIRDFContentModelBuilder* aBuilder);
NS_IMETHOD GetDocumentDataSource(nsIRDFDataSource** aDatasource);
// nsIDOMDocument interface
NS_IMETHOD GetDoctype(nsIDOMDocumentType** aDoctype);
@ -498,7 +503,15 @@ public:
// nsIDOMXULDocument interface
NS_DECL_IDOMXULDOCUMENT
// nsIXULParentDocument interface
NS_IMETHOD GetContentViewerContainer(nsIContentViewerContainer** aContainer);
NS_IMETHOD GetCommand(nsString& aCommand);
// nsIXULChildDocument Interface
NS_IMETHOD SetFragmentRoot(nsIContent* aFragmentRoot);
NS_IMETHOD GetFragmentRoot(nsIContent** aFragmentRoot);
// nsIDOMNode interface
NS_IMETHOD GetNodeName(nsString& aNodeName);
NS_IMETHOD GetNodeValue(nsString& aNodeValue);
@ -603,6 +616,9 @@ protected:
nsIRDFDataSource* mDocumentDataSource;
nsIParser* mParser;
nsILineBreaker* mLineBreaker;
nsIContentViewerContainer* mContentViewerContainer;
nsString mCommand;
nsIContent* mFragmentRoot;
};
PRInt32 XULDocumentImpl::gRefCnt;
@ -630,7 +646,10 @@ XULDocumentImpl::XULDocumentImpl(void)
mLocalDataSource(nsnull),
mDocumentDataSource(nsnull),
mLineBreaker(nsnull),
mParser(nsnull)
mParser(nsnull),
mContentViewerContainer(nsnull),
mCommand(""),
mFragmentRoot(nsnull)
{
NS_INIT_REFCNT();
@ -673,6 +692,8 @@ XULDocumentImpl::~XULDocumentImpl()
NS_IF_RELEASE(mNameSpaceManager);
NS_IF_RELEASE(mParser);
NS_IF_RELEASE(mLineBreaker);
NS_IF_RELEASE(mContentViewerContainer);
NS_IF_RELEASE(mFragmentRoot);
if (--gRefCnt == 0) {
NS_IF_RELEASE(kIdAtom);
@ -719,6 +740,12 @@ XULDocumentImpl::QueryInterface(REFNSIID iid, void** result)
iid.Equals(kISupportsIID)) {
*result = NS_STATIC_CAST(nsIDocument*, this);
}
else if (iid.Equals(nsIXULParentDocument::GetIID())) {
*result = NS_STATIC_CAST(nsIXULParentDocument*, this);
}
else if (iid.Equals(nsIXULChildDocument::GetIID())) {
*result = NS_STATIC_CAST(nsIXULChildDocument*, this);
}
else if (iid.Equals(kIRDFDocumentIID) ||
iid.Equals(kIXMLDocumentIID)) {
*result = NS_STATIC_CAST(nsIRDFDocument*, this);
@ -774,6 +801,13 @@ XULDocumentImpl::StartDocumentLoad(nsIURL *aURL,
if (! aURL)
return NS_ERROR_NULL_POINTER;
if (aContainer && aContainer != mContentViewerContainer)
{
// AddRef and hold the container
NS_ADDREF(aContainer);
mContentViewerContainer = aContainer;
}
nsresult rv;
mDocumentTitle.Truncate();
@ -835,89 +869,92 @@ XULDocumentImpl::StartDocumentLoad(nsIURL *aURL,
return rv;
}
// Create a composite data source that'll tie together local and
// remote stores.
nsIRDFCompositeDataSource* db;
if (NS_FAILED(rv = nsComponentManager::CreateInstance(kRDFCompositeDataSourceCID,
nsnull,
kIRDFCompositeDataSourceIID,
(void**) &db))) {
NS_ERROR("couldn't create composite datasource");
return rv;
}
// Create various data sources and builders, but only do this if we're
// not a XUL fragment.
if (mFragmentRoot == nsnull) {
// Create a XUL content model builder
NS_IF_RELEASE(mXULBuilder);
if (NS_FAILED(rv = nsComponentManager::CreateInstance(kRDFXULBuilderCID,
nsnull,
kIRDFContentModelBuilderIID,
(void**) &mXULBuilder))) {
NS_ERROR("couldn't create XUL builder");
return rv;
}
nsIRDFCompositeDataSource* db;
if (NS_FAILED(rv = nsComponentManager::CreateInstance(kRDFCompositeDataSourceCID,
nsnull,
kIRDFCompositeDataSourceIID,
(void**) &db))) {
NS_ERROR("couldn't create composite datasource");
return rv;
}
if (NS_FAILED(rv = mXULBuilder->SetDataBase(db))) {
NS_ERROR("couldn't set builder's db");
return rv;
}
// Create a XUL content model builder
NS_IF_RELEASE(mXULBuilder);
if (NS_FAILED(rv = nsComponentManager::CreateInstance(kRDFXULBuilderCID,
nsnull,
kIRDFContentModelBuilderIID,
(void**) &mXULBuilder))) {
NS_ERROR("couldn't create XUL builder");
return rv;
}
NS_IF_RELEASE(mBuilders);
if (NS_FAILED(rv = AddContentModelBuilder(mXULBuilder))) {
NS_ERROR("could't add XUL builder");
return rv;
}
if (NS_FAILED(rv = mXULBuilder->SetDataBase(db))) {
NS_ERROR("couldn't set builder's db");
return rv;
}
// Create a "scratch" in-memory data store to associate with the
// document to be a catch-all for any doc-specific info that we
// need to store (e.g., current sort order, etc.)
//
// XXX This needs to be cloned across windows, and the final
// instance needs to be flushed to disk. It may be that this is
// really an RDFXML data source...
if (NS_FAILED(rv = nsComponentManager::CreateInstance(kRDFInMemoryDataSourceCID,
nsnull,
kIRDFDataSourceIID,
(void**) &mLocalDataSource))) {
NS_ERROR("couldn't create local data source");
return rv;
}
NS_IF_RELEASE(mBuilders);
if (NS_FAILED(rv = AddContentModelBuilder(mXULBuilder))) {
NS_ERROR("could't add XUL builder");
return rv;
}
if (NS_FAILED(rv = db->AddDataSource(mLocalDataSource))) {
NS_ERROR("couldn't add local data source to db");
return rv;
}
// Create a "scratch" in-memory data store to associate with the
// document to be a catch-all for any doc-specific info that we
// need to store (e.g., current sort order, etc.)
//
// XXX This needs to be cloned across windows, and the final
// instance needs to be flushed to disk. It may be that this is
// really an RDFXML data source...
if (NS_FAILED(rv = nsComponentManager::CreateInstance(kRDFInMemoryDataSourceCID,
nsnull,
kIRDFDataSourceIID,
(void**) &mLocalDataSource))) {
NS_ERROR("couldn't create local data source");
return rv;
}
// Now load the actual RDF/XML document data source. First, we'll
// see if the data source has been loaded and is registered with
// the RDF service. If so, do some monkey business to "pretend" to
// load it: really, we'll just walk its graph to generate the
// content model.
const char* uri;
if (NS_FAILED(rv = aURL->GetSpec(&uri)))
return rv;
if (NS_FAILED(rv = db->AddDataSource(mLocalDataSource))) {
NS_ERROR("couldn't add local data source to db");
return rv;
}
// We need to construct a new stream and load it. The stream will
// automagically register itself as a named data source, so if
// subsequent docs ask for it, they'll get the real deal. In the
// meantime, add us as an nsIRDFXMLDataSourceObserver so that
// we'll be notified when we need to load style sheets, etc.
NS_IF_RELEASE(mDocumentDataSource);
if (NS_FAILED(rv = nsComponentManager::CreateInstance(kRDFInMemoryDataSourceCID,
nsnull,
kIRDFDataSourceIID,
(void**) &mDocumentDataSource))) {
NS_ERROR("unable to create XUL datasource");
return rv;
}
// Now load the actual RDF/XML document data source. First, we'll
// see if the data source has been loaded and is registered with
// the RDF service. If so, do some monkey business to "pretend" to
// load it: really, we'll just walk its graph to generate the
// content model.
const char* uri;
if (NS_FAILED(rv = aURL->GetSpec(&uri)))
return rv;
if (NS_FAILED(rv = db->AddDataSource(mDocumentDataSource))) {
NS_ERROR("unable to add XUL datasource to db");
return rv;
}
// We need to construct a new stream and load it. The stream will
// automagically register itself as a named data source, so if
// subsequent docs ask for it, they'll get the real deal. In the
// meantime, add us as an nsIRDFXMLDataSourceObserver so that
// we'll be notified when we need to load style sheets, etc.
NS_IF_RELEASE(mDocumentDataSource);
if (NS_FAILED(rv = nsComponentManager::CreateInstance(kRDFInMemoryDataSourceCID,
nsnull,
kIRDFDataSourceIID,
(void**) &mDocumentDataSource))) {
NS_ERROR("unable to create XUL datasource");
return rv;
}
if (NS_FAILED(rv = mDocumentDataSource->Init(uri))) {
NS_ERROR("unable to initialize XUL data source");
return rv;
if (NS_FAILED(rv = db->AddDataSource(mDocumentDataSource))) {
NS_ERROR("unable to add XUL datasource to db");
return rv;
}
if (NS_FAILED(rv = mDocumentDataSource->Init(uri))) {
NS_ERROR("unable to initialize XUL data source");
return rv;
}
}
nsCOMPtr<nsIXULContentSink> sink;
@ -961,6 +998,8 @@ XULDocumentImpl::StartDocumentLoad(nsIURL *aURL,
return rv;
}
mCommand = aCommand;
mParser->RegisterDTD(dtd);
mParser->SetCommand(aCommand);
mParser->SetContentSink(sink);
@ -2031,7 +2070,14 @@ XULDocumentImpl::AddContentModelBuilder(nsIRDFContentModelBuilder* aBuilder)
return mBuilders->AppendElement(aBuilder) ? NS_OK : NS_ERROR_FAILURE;
}
NS_IMETHODIMP
XULDocumentImpl::GetDocumentDataSource(nsIRDFDataSource** aDataSource) {
if (mDocumentDataSource) {
NS_ADDREF(mDocumentDataSource);
*aDataSource = mDocumentDataSource;
}
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// nsIDOMDocument interface
@ -2284,6 +2330,52 @@ XULDocumentImpl::SearchForNodeByID(const nsString& anID,
}
}
////////////////////////////////////////////////////////////////////////
// nsIXULParentDocument interface
NS_IMETHODIMP
XULDocumentImpl::GetContentViewerContainer(nsIContentViewerContainer** aContainer)
{
if (mContentViewerContainer != nsnull)
{
NS_ADDREF(mContentViewerContainer);
*aContainer = mContentViewerContainer;
}
return NS_OK;
}
NS_IMETHODIMP
XULDocumentImpl::GetCommand(nsString& aCommand)
{
aCommand = mCommand;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// nsIXULChildDocument interface
NS_IMETHODIMP
XULDocumentImpl::SetFragmentRoot(nsIContent* aFragmentRoot)
{
if (aFragmentRoot != mFragmentRoot)
{
NS_IF_RELEASE(mFragmentRoot);
NS_IF_ADDREF(aFragmentRoot);
mFragmentRoot = aFragmentRoot;
}
return NS_OK;
}
NS_IMETHODIMP
XULDocumentImpl::GetFragmentRoot(nsIContent** aFragmentRoot)
{
if (mFragmentRoot) {
NS_ADDREF(mFragmentRoot);
*aFragmentRoot = mFragmentRoot;
}
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// nsIDOMNode interface
NS_IMETHODIMP