initial (disabled) cut at creating about:blank documents synchronously. part of bug 88229 r=hyatt,rpotts

git-svn-id: svn://10.0.0.236/trunk@107393 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
danm%netscape.com 2001-11-06 01:24:39 +00:00
parent 120229a1fc
commit 17ff11d2db
10 changed files with 166 additions and 62 deletions

View File

@ -37,14 +37,19 @@
* ***** END LICENSE BLOCK ***** */
#include "nsCOMPtr.h"
#include "nsContentDLF.h"
#include "nsGenericHTMLElement.h"
#include "nsHTMLAtoms.h"
#include "nsIComponentManager.h"
#include "nsICategoryManager.h"
#include "nsIDocumentLoader.h"
#include "nsIDocumentLoaderFactory.h"
#include "nsIDocument.h"
#include "nsIDocumentViewer.h"
#include "nsIHTMLContent.h"
#include "nsIURL.h"
#include "nsICSSStyleSheet.h"
#include "nsNodeInfo.h"
#include "nsNodeInfoManager.h"
#include "nsString.h"
#include "nsContentCID.h"
#include "prprf.h"
@ -288,6 +293,60 @@ nsContentDLF::CreateInstanceForDocument(nsISupports* aContainer,
return rv;
}
NS_IMETHODIMP
nsContentDLF::CreateBlankDocument(nsIDocument **aDocument)
{
*aDocument = nsnull;
nsCOMPtr<nsIDocument> blankDoc(do_CreateInstance(kHTMLDocumentCID));
if (!blankDoc)
return NS_ERROR_FAILURE;
nsCOMPtr<nsINodeInfoManager> nim;
blankDoc->GetNodeInfoManager(*getter_AddRefs(nim));
nsCOMPtr<nsINodeInfo> htmlNodeInfo;
// generate an html html element
nsCOMPtr<nsIHTMLContent> htmlElement;
nim->GetNodeInfo(nsHTMLAtoms::html, 0, kNameSpaceID_None,
*getter_AddRefs(htmlNodeInfo));
NS_NewHTMLHtmlElement(getter_AddRefs(htmlElement), htmlNodeInfo);
// generate an html head element
nsCOMPtr<nsIHTMLContent> headElement;
nim->GetNodeInfo(nsHTMLAtoms::html, 0, kNameSpaceID_None,
*getter_AddRefs(htmlNodeInfo));
NS_NewHTMLHeadElement(getter_AddRefs(headElement), htmlNodeInfo);
// generate an html body element
nsCOMPtr<nsIHTMLContent> bodyElement;
nim->GetNodeInfo(nsHTMLAtoms::body, 0, kNameSpaceID_None,
*getter_AddRefs(htmlNodeInfo));
NS_NewHTMLBodyElement(getter_AddRefs(bodyElement), htmlNodeInfo);
// hook it all up
if (htmlElement && headElement && bodyElement) {
htmlElement->SetDocument(blankDoc, PR_FALSE, PR_TRUE);
blankDoc->SetRootContent(htmlElement);
headElement->SetDocument(blankDoc, PR_FALSE, PR_TRUE);
htmlElement->AppendChildTo(headElement, PR_FALSE, PR_FALSE);
PRInt32 id;
blankDoc->GetAndIncrementContentID(&id);
bodyElement->SetContentID(id);
bodyElement->SetDocument(blankDoc, PR_FALSE, PR_TRUE);
htmlElement->AppendChildTo(bodyElement, PR_FALSE, PR_FALSE);
*aDocument = blankDoc;
NS_ADDREF(*aDocument);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
nsresult
nsContentDLF::CreateDocument(const char* aCommand,
nsIChannel* aChannel,

View File

@ -42,21 +42,7 @@ public:
virtual ~nsContentDLF();
NS_DECL_ISUPPORTS
// for nsIDocumentLoaderFactory
NS_IMETHOD CreateInstance(const char* aCommand,
nsIChannel* aChannel,
nsILoadGroup* aLoadGroup,
const char* aContentType,
nsISupports* aContainer,
nsISupports* aExtraInfo,
nsIStreamListener** aDocListener,
nsIContentViewer** aDocViewer);
NS_IMETHOD CreateInstanceForDocument(nsISupports* aContainer,
nsIDocument* aDocument,
const char *aCommand,
nsIContentViewer** aDocViewerResult);
NS_DECL_NSIDOCUMENTLOADERFACTORY
// for nsIDocStreamLoaderFactory
NS_METHOD CreateInstance(nsIInputStream& aInputStream,

View File

@ -3413,9 +3413,34 @@ nsDocShell::EnsureDeviceContext()
NS_IMETHODIMP
nsDocShell::CreateAboutBlankContentViewer()
{
// XXX
NS_ERROR("Not Implemented yet");
return NS_ERROR_NOT_IMPLEMENTED; // for now. not quite working yet.
nsCOMPtr<nsIDocument> blankDoc;
nsCOMPtr<nsIContentViewer> viewer;
// one helper factory, please
nsCOMPtr<nsIDocumentLoaderFactory> docFactory(do_CreateInstance(NS_DOCUMENT_LOADER_FACTORY_CONTRACTID_PREFIX "view;1?type=text/html"));
if (!docFactory)
return NS_ERROR_FAILURE;
// generate (about:blank) document to load
docFactory->CreateBlankDocument(getter_AddRefs(blankDoc));
if (!blankDoc)
return NS_ERROR_FAILURE;
// create a content viewer for us and the new document
docFactory->CreateInstanceForDocument(NS_ISUPPORTS_CAST(nsIDocShell *, this),
blankDoc, "view", getter_AddRefs(viewer));
// hook 'em up
if (viewer) {
viewer->SetContainer(NS_STATIC_CAST(nsIContentViewerContainer *,this));
nsCOMPtr<nsIDOMDocument> domdoc(do_QueryInterface(blankDoc));
Embed(viewer, "", 0);
viewer->SetDOMDocument(domdoc);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP

View File

@ -37,14 +37,19 @@
* ***** END LICENSE BLOCK ***** */
#include "nsCOMPtr.h"
#include "nsContentDLF.h"
#include "nsGenericHTMLElement.h"
#include "nsHTMLAtoms.h"
#include "nsIComponentManager.h"
#include "nsICategoryManager.h"
#include "nsIDocumentLoader.h"
#include "nsIDocumentLoaderFactory.h"
#include "nsIDocument.h"
#include "nsIDocumentViewer.h"
#include "nsIHTMLContent.h"
#include "nsIURL.h"
#include "nsICSSStyleSheet.h"
#include "nsNodeInfo.h"
#include "nsNodeInfoManager.h"
#include "nsString.h"
#include "nsContentCID.h"
#include "prprf.h"
@ -288,6 +293,60 @@ nsContentDLF::CreateInstanceForDocument(nsISupports* aContainer,
return rv;
}
NS_IMETHODIMP
nsContentDLF::CreateBlankDocument(nsIDocument **aDocument)
{
*aDocument = nsnull;
nsCOMPtr<nsIDocument> blankDoc(do_CreateInstance(kHTMLDocumentCID));
if (!blankDoc)
return NS_ERROR_FAILURE;
nsCOMPtr<nsINodeInfoManager> nim;
blankDoc->GetNodeInfoManager(*getter_AddRefs(nim));
nsCOMPtr<nsINodeInfo> htmlNodeInfo;
// generate an html html element
nsCOMPtr<nsIHTMLContent> htmlElement;
nim->GetNodeInfo(nsHTMLAtoms::html, 0, kNameSpaceID_None,
*getter_AddRefs(htmlNodeInfo));
NS_NewHTMLHtmlElement(getter_AddRefs(htmlElement), htmlNodeInfo);
// generate an html head element
nsCOMPtr<nsIHTMLContent> headElement;
nim->GetNodeInfo(nsHTMLAtoms::html, 0, kNameSpaceID_None,
*getter_AddRefs(htmlNodeInfo));
NS_NewHTMLHeadElement(getter_AddRefs(headElement), htmlNodeInfo);
// generate an html body element
nsCOMPtr<nsIHTMLContent> bodyElement;
nim->GetNodeInfo(nsHTMLAtoms::body, 0, kNameSpaceID_None,
*getter_AddRefs(htmlNodeInfo));
NS_NewHTMLBodyElement(getter_AddRefs(bodyElement), htmlNodeInfo);
// hook it all up
if (htmlElement && headElement && bodyElement) {
htmlElement->SetDocument(blankDoc, PR_FALSE, PR_TRUE);
blankDoc->SetRootContent(htmlElement);
headElement->SetDocument(blankDoc, PR_FALSE, PR_TRUE);
htmlElement->AppendChildTo(headElement, PR_FALSE, PR_FALSE);
PRInt32 id;
blankDoc->GetAndIncrementContentID(&id);
bodyElement->SetContentID(id);
bodyElement->SetDocument(blankDoc, PR_FALSE, PR_TRUE);
htmlElement->AppendChildTo(bodyElement, PR_FALSE, PR_FALSE);
*aDocument = blankDoc;
NS_ADDREF(*aDocument);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
nsresult
nsContentDLF::CreateDocument(const char* aCommand,
nsIChannel* aChannel,

View File

@ -42,21 +42,7 @@ public:
virtual ~nsContentDLF();
NS_DECL_ISUPPORTS
// for nsIDocumentLoaderFactory
NS_IMETHOD CreateInstance(const char* aCommand,
nsIChannel* aChannel,
nsILoadGroup* aLoadGroup,
const char* aContentType,
nsISupports* aContainer,
nsISupports* aExtraInfo,
nsIStreamListener** aDocListener,
nsIContentViewer** aDocViewer);
NS_IMETHOD CreateInstanceForDocument(nsISupports* aContainer,
nsIDocument* aDocument,
const char *aCommand,
nsIContentViewer** aDocViewerResult);
NS_DECL_NSIDOCUMENTLOADERFACTORY
// for nsIDocStreamLoaderFactory
NS_METHOD CreateInstance(nsIInputStream& aInputStream,

View File

@ -93,3 +93,10 @@ nsPluginDocLoaderFactory::CreateInstanceForDocument(nsISupports* aContainer,
NS_NOTREACHED("how'd I get here?");
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsPluginDocLoaderFactory::CreateBlankDocument(nsIDocument **_retval) {
NS_NOTREACHED("how'd I get here?");
return NS_ERROR_FAILURE;
}

View File

@ -65,21 +65,7 @@ public:
Create(nsISupports* aOuter, REFNSIID aIID, void** aResult);
NS_DECL_ISUPPORTS
// nsIDocumentLoaderFactory
NS_IMETHOD CreateInstance(const char* aCommand,
nsIChannel* aChannel,
nsILoadGroup* aLoadGroup,
const char* aContentType,
nsISupports* aContainer,
nsISupports* aExtraInfo,
nsIStreamListener** aDocListener,
nsIContentViewer** aDocViewer);
NS_IMETHOD CreateInstanceForDocument(nsISupports* aContainer,
nsIDocument* aDocument,
const char *aCommand,
nsIContentViewer** aDocViewerResult);
NS_DECL_NSIDOCUMENTLOADERFACTORY
};
/* dd1b8d10-1dd1-11b2-9852-e162b2c46000 */

View File

@ -56,4 +56,6 @@ interface nsIDocumentLoaderFactory : nsISupports {
nsIContentViewer createInstanceForDocument(in nsISupports aContainer,
in nsIDocument aDocument,
in string aCommand);
nsIDocument createBlankDocument();
};

View File

@ -1496,3 +1496,11 @@ nsDirectoryViewerFactory::CreateInstanceForDocument(nsISupports* aContainer,
NS_NOTYETIMPLEMENTED("didn't expect to get here");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDirectoryViewerFactory::CreateBlankDocument(nsIDocument **_retval) {
NS_NOTYETIMPLEMENTED("didn't expect to get here");
return NS_ERROR_NOT_IMPLEMENTED;
}

View File

@ -63,21 +63,7 @@ public:
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIDocumentLoaderFactory interface
NS_IMETHOD CreateInstance(const char *aCommand,
nsIChannel* aChannel,
nsILoadGroup* aLoadGroup,
const char* aContentType,
nsISupports* aContainer,
nsISupports* aExtraInfo,
nsIStreamListener** aDocListenerResult,
nsIContentViewer** aDocViewerResult);
NS_IMETHOD CreateInstanceForDocument(nsISupports* aContainer,
nsIDocument* aDocument,
const char *aCommand,
nsIContentViewer** aDocViewerResult);
NS_DECL_NSIDOCUMENTLOADERFACTORY
};