From 17ff11d2dbbfb78eedc457f10883bff266cbf0af Mon Sep 17 00:00:00 2001 From: "danm%netscape.com" Date: Tue, 6 Nov 2001 01:24:39 +0000 Subject: [PATCH] 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 --- mozilla/content/build/nsContentDLF.cpp | 59 +++++++++++++++++++ mozilla/content/build/nsContentDLF.h | 16 +---- mozilla/docshell/base/nsDocShell.cpp | 29 ++++++++- mozilla/layout/build/nsContentDLF.cpp | 59 +++++++++++++++++++ mozilla/layout/build/nsContentDLF.h | 16 +---- .../base/src/nsPluginDocLoaderFactory.cpp | 7 +++ .../base/src/nsPluginDocLoaderFactory.h | 16 +---- .../public/nsIDocumentLoaderFactory.idl | 2 + .../directory/nsDirectoryViewer.cpp | 8 +++ .../components/directory/nsDirectoryViewer.h | 16 +---- 10 files changed, 166 insertions(+), 62 deletions(-) diff --git a/mozilla/content/build/nsContentDLF.cpp b/mozilla/content/build/nsContentDLF.cpp index 133aa8ce2a1..83ce20e0691 100644 --- a/mozilla/content/build/nsContentDLF.cpp +++ b/mozilla/content/build/nsContentDLF.cpp @@ -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 blankDoc(do_CreateInstance(kHTMLDocumentCID)); + if (!blankDoc) + return NS_ERROR_FAILURE; + + nsCOMPtr nim; + blankDoc->GetNodeInfoManager(*getter_AddRefs(nim)); + + nsCOMPtr htmlNodeInfo; + + // generate an html html element + nsCOMPtr htmlElement; + nim->GetNodeInfo(nsHTMLAtoms::html, 0, kNameSpaceID_None, + *getter_AddRefs(htmlNodeInfo)); + NS_NewHTMLHtmlElement(getter_AddRefs(htmlElement), htmlNodeInfo); + + // generate an html head element + nsCOMPtr headElement; + nim->GetNodeInfo(nsHTMLAtoms::html, 0, kNameSpaceID_None, + *getter_AddRefs(htmlNodeInfo)); + NS_NewHTMLHeadElement(getter_AddRefs(headElement), htmlNodeInfo); + + // generate an html body element + nsCOMPtr 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, diff --git a/mozilla/content/build/nsContentDLF.h b/mozilla/content/build/nsContentDLF.h index 82c8a31f8aa..6fdfa003352 100644 --- a/mozilla/content/build/nsContentDLF.h +++ b/mozilla/content/build/nsContentDLF.h @@ -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, diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index 82352942a27..89c983d248d 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -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 blankDoc; + nsCOMPtr viewer; + + // one helper factory, please + nsCOMPtr 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 domdoc(do_QueryInterface(blankDoc)); + Embed(viewer, "", 0); + viewer->SetDOMDocument(domdoc); + return NS_OK; + } + return NS_ERROR_FAILURE; } NS_IMETHODIMP diff --git a/mozilla/layout/build/nsContentDLF.cpp b/mozilla/layout/build/nsContentDLF.cpp index 133aa8ce2a1..83ce20e0691 100644 --- a/mozilla/layout/build/nsContentDLF.cpp +++ b/mozilla/layout/build/nsContentDLF.cpp @@ -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 blankDoc(do_CreateInstance(kHTMLDocumentCID)); + if (!blankDoc) + return NS_ERROR_FAILURE; + + nsCOMPtr nim; + blankDoc->GetNodeInfoManager(*getter_AddRefs(nim)); + + nsCOMPtr htmlNodeInfo; + + // generate an html html element + nsCOMPtr htmlElement; + nim->GetNodeInfo(nsHTMLAtoms::html, 0, kNameSpaceID_None, + *getter_AddRefs(htmlNodeInfo)); + NS_NewHTMLHtmlElement(getter_AddRefs(htmlElement), htmlNodeInfo); + + // generate an html head element + nsCOMPtr headElement; + nim->GetNodeInfo(nsHTMLAtoms::html, 0, kNameSpaceID_None, + *getter_AddRefs(htmlNodeInfo)); + NS_NewHTMLHeadElement(getter_AddRefs(headElement), htmlNodeInfo); + + // generate an html body element + nsCOMPtr 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, diff --git a/mozilla/layout/build/nsContentDLF.h b/mozilla/layout/build/nsContentDLF.h index 82c8a31f8aa..6fdfa003352 100644 --- a/mozilla/layout/build/nsContentDLF.h +++ b/mozilla/layout/build/nsContentDLF.h @@ -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, diff --git a/mozilla/modules/plugin/base/src/nsPluginDocLoaderFactory.cpp b/mozilla/modules/plugin/base/src/nsPluginDocLoaderFactory.cpp index 4f718dafb93..dafdc04a63d 100644 --- a/mozilla/modules/plugin/base/src/nsPluginDocLoaderFactory.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginDocLoaderFactory.cpp @@ -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; +} + diff --git a/mozilla/modules/plugin/base/src/nsPluginDocLoaderFactory.h b/mozilla/modules/plugin/base/src/nsPluginDocLoaderFactory.h index 7aef7ab0b9d..4146e2454e0 100644 --- a/mozilla/modules/plugin/base/src/nsPluginDocLoaderFactory.h +++ b/mozilla/modules/plugin/base/src/nsPluginDocLoaderFactory.h @@ -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 */ diff --git a/mozilla/webshell/public/nsIDocumentLoaderFactory.idl b/mozilla/webshell/public/nsIDocumentLoaderFactory.idl index 7498bee24f3..652329153c2 100644 --- a/mozilla/webshell/public/nsIDocumentLoaderFactory.idl +++ b/mozilla/webshell/public/nsIDocumentLoaderFactory.idl @@ -56,4 +56,6 @@ interface nsIDocumentLoaderFactory : nsISupports { nsIContentViewer createInstanceForDocument(in nsISupports aContainer, in nsIDocument aDocument, in string aCommand); + + nsIDocument createBlankDocument(); }; diff --git a/mozilla/xpfe/components/directory/nsDirectoryViewer.cpp b/mozilla/xpfe/components/directory/nsDirectoryViewer.cpp index 9def7e56dd1..291e5274301 100644 --- a/mozilla/xpfe/components/directory/nsDirectoryViewer.cpp +++ b/mozilla/xpfe/components/directory/nsDirectoryViewer.cpp @@ -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; +} + diff --git a/mozilla/xpfe/components/directory/nsDirectoryViewer.h b/mozilla/xpfe/components/directory/nsDirectoryViewer.h index 29010fc6c74..015a74aabe9 100644 --- a/mozilla/xpfe/components/directory/nsDirectoryViewer.h +++ b/mozilla/xpfe/components/directory/nsDirectoryViewer.h @@ -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 };