From cf3e8244497a771bd8a6fe6022582b4a8f806b93 Mon Sep 17 00:00:00 2001 From: "rpotts%netscape.com" Date: Thu, 22 Jun 2000 05:38:07 +0000 Subject: [PATCH] DocShell cleanup. Removed the implementation of the unused nsIDocSHell::SetDocument() method and moved the implementation responsibility to the nsIContentViewer --- content/base/src/nsDocumentViewer.cpp | 28 ++ docshell/base/nsDocShell.cpp | 314 +-------------------- docshell/base/nsDocShell.h | 11 - docshell/base/nsWebShell.cpp | 116 -------- layout/base/nsDocumentViewer.cpp | 28 ++ layout/base/src/nsDocumentViewer.cpp | 28 ++ layout/base/src/nsPluginViewer.cpp | 30 +- modules/plugin/base/src/nsPluginViewer.cpp | 30 +- modules/plugin/nglsrc/nsPluginViewer.cpp | 30 +- webshell/public/nsIContentViewer.h | 6 + webshell/src/nsWebShell.cpp | 116 -------- 11 files changed, 180 insertions(+), 557 deletions(-) diff --git a/content/base/src/nsDocumentViewer.cpp b/content/base/src/nsDocumentViewer.cpp index 5894506384cc..fe56e5471746 100644 --- a/content/base/src/nsDocumentViewer.cpp +++ b/content/base/src/nsDocumentViewer.cpp @@ -192,7 +192,11 @@ public: NS_IMETHOD BindToDocument(nsISupports* aDoc, const char* aCommand); NS_IMETHOD SetContainer(nsISupports* aContainer); NS_IMETHOD GetContainer(nsISupports** aContainerResult); + NS_IMETHOD LoadComplete(nsresult aStatus); + NS_IMETHOD Destroy(void); NS_IMETHOD Stop(void); + NS_IMETHOD GetDOMDocument(nsIDOMDocument **aResult); + NS_IMETHOD SetDOMDocument(nsIDOMDocument *aDocument); NS_IMETHOD GetBounds(nsRect& aResult); NS_IMETHOD SetBounds(const nsRect& aBounds); NS_IMETHOD Move(PRInt32 aX, PRInt32 aY); @@ -621,6 +625,18 @@ DocumentViewerImpl::Init(nsIWidget* aParentWidget, return rv; } +NS_IMETHODIMP +DocumentViewerImpl::LoadComplete(nsresult aStatus) +{ + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +DocumentViewerImpl::Destroy(void) +{ + return NS_ERROR_FAILURE; +} + NS_IMETHODIMP DocumentViewerImpl::Stop(void) { @@ -634,6 +650,18 @@ DocumentViewerImpl::Stop(void) return NS_OK; } +NS_IMETHODIMP +DocumentViewerImpl::GetDOMDocument(nsIDOMDocument **aResult) +{ + return CallQueryInterface(mDocument.get(), aResult); +} + +NS_IMETHODIMP +DocumentViewerImpl::SetDOMDocument(nsIDOMDocument *aDocument) +{ + return NS_ERROR_FAILURE; +} + NS_IMETHODIMP DocumentViewerImpl::SetUAStyleSheet(nsIStyleSheet* aUAStyleSheet) { diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index c436b0546b97..e05be3e0f978 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -268,109 +268,11 @@ NS_IMETHODIMP nsDocShell::StopLoad() return NS_OK; } -// SetDocument is only meaningful for doc shells that support DOM documents. Not all do. NS_IMETHODIMP nsDocShell::SetDocument(nsIDOMDocument *aDOMDoc, nsIDOMElement *aRootNode) { - - // The tricky part is bypassing the normal load process and just putting a document into - // the webshell. This is particularly nasty, since webshells don't normally even know - // about their documents - - // (1) Create a document viewer - nsCOMPtr documentViewer; - nsCOMPtr docFactory; - static NS_DEFINE_CID(kLayoutDocumentLoaderFactoryCID, NS_LAYOUT_DOCUMENT_LOADER_FACTORY_CID); - NS_ENSURE_SUCCESS(nsComponentManager::CreateInstance(kLayoutDocumentLoaderFactoryCID, nsnull, - NS_GET_IID(nsIDocumentLoaderFactory), - (void**)getter_AddRefs(docFactory)), - NS_ERROR_FAILURE); - - nsCOMPtr doc = do_QueryInterface(aDOMDoc); - NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE); - NS_ENSURE_SUCCESS(docFactory->CreateInstanceForDocument(NS_STATIC_CAST(nsIContentViewerContainer*, this), - doc, - "view", - getter_AddRefs(documentViewer)), - NS_ERROR_FAILURE); - - // (2) Feed the docshell to the content viewer - NS_ENSURE_SUCCESS(documentViewer->SetContainer((nsIDocShell*)this), - NS_ERROR_FAILURE); - - // (3) Tell the content viewer container to setup the content viewer. - // (This step causes everything to be set up for an initial flow.) - NS_ENSURE_SUCCESS(SetupNewViewer(documentViewer), NS_ERROR_FAILURE); - - // XXX: It would be great to get rid of this dummy channel! - nsCOMPtr uri; - NS_ENSURE_SUCCESS(NS_NewURI(getter_AddRefs(uri), NS_ConvertASCIItoUCS2("about:blank")), NS_ERROR_FAILURE); - NS_ENSURE_TRUE(uri, NS_ERROR_OUT_OF_MEMORY); - - nsCOMPtr dummyChannel; - NS_ENSURE_SUCCESS(NS_OpenURI(getter_AddRefs(dummyChannel), uri, nsnull), NS_ERROR_FAILURE); - - // (4) fire start document load notification - nsCOMPtr outStreamListener; - NS_ENSURE_SUCCESS(doc->StartDocumentLoad("view", dummyChannel, nsnull, - NS_STATIC_CAST(nsIContentViewerContainer*, this), - getter_AddRefs(outStreamListener), PR_TRUE), NS_ERROR_FAILURE); - NS_ENSURE_SUCCESS(FireStartDocumentLoad(mDocLoader, uri, "load"), NS_ERROR_FAILURE); - - // (5) hook up the document and its content - nsCOMPtr rootContent = do_QueryInterface(aRootNode); - NS_ENSURE_TRUE(doc, NS_ERROR_OUT_OF_MEMORY); - NS_ENSURE_SUCCESS(rootContent->SetDocument(doc, PR_FALSE, PR_TRUE), NS_ERROR_FAILURE); - doc->SetRootContent(rootContent); - - // (6) reflow the document - PRInt32 i; - PRInt32 ns = doc->GetNumberOfShells(); - for (i = 0; i < ns; i++) - { - nsCOMPtr shell(dont_AddRef(doc->GetShellAt(i))); - if (shell) - { - // Make shell an observer for next time - NS_ENSURE_SUCCESS(shell->BeginObservingDocument(), NS_ERROR_FAILURE); - - // Resize-reflow this time - nsCOMPtr docViewer = do_QueryInterface(documentViewer); - NS_ENSURE_TRUE(docViewer, NS_ERROR_OUT_OF_MEMORY); - nsCOMPtr presContext; - NS_ENSURE_SUCCESS(docViewer->GetPresContext(*(getter_AddRefs(presContext))), NS_ERROR_FAILURE); - NS_ENSURE_TRUE(presContext, NS_ERROR_OUT_OF_MEMORY); - float p2t; - presContext->GetScaledPixelsToTwips(&p2t); - - nsRect r; - NS_ENSURE_SUCCESS(GetPosition(&r.x, &r.y), NS_ERROR_FAILURE);; - NS_ENSURE_SUCCESS(GetSize(&r.width, &r.height), NS_ERROR_FAILURE);; - NS_ENSURE_SUCCESS(shell->InitialReflow(NSToCoordRound(r.width * p2t), NSToCoordRound(r.height * p2t)), NS_ERROR_FAILURE); - - // Now trigger a refresh - nsCOMPtr vm; - NS_ENSURE_SUCCESS(shell->GetViewManager(getter_AddRefs(vm)), NS_ERROR_FAILURE); - if (vm) - { - PRBool enabled; - documentViewer->GetEnableRendering(&enabled); - if (enabled) { - vm->EnableRefresh(NS_VMREFRESH_IMMEDIATE); - } - NS_ENSURE_SUCCESS(vm->SetWindowDimensions(NSToCoordRound(r.width * p2t), - NSToCoordRound(r.height * p2t)), - NS_ERROR_FAILURE); - } - } - } - - // (7) fire end document load notification - nsresult rv = NS_OK; - NS_ENSURE_SUCCESS(FireEndDocumentLoad(mDocLoader, dummyChannel, rv), NS_ERROR_FAILURE); - NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); // test the resulting out-param separately - - return NS_OK; + /* XXX: This method is obsolete and will be removed. */ + return NS_ERROR_FAILURE; } NS_IMETHODIMP nsDocShell::GetCurrentURI(nsIURI** aURI) @@ -1207,17 +1109,7 @@ NS_IMETHODIMP nsDocShell::GetDocument(nsIDOMDocument** aDocument) NS_ENSURE_ARG_POINTER(aDocument); NS_ENSURE_STATE(mContentViewer); - nsCOMPtr docv(do_QueryInterface(mContentViewer)); - NS_ENSURE_TRUE(docv, NS_ERROR_FAILURE); - - nsCOMPtrdoc; - NS_ENSURE_SUCCESS(docv->GetDocument(*getter_AddRefs(doc)), NS_ERROR_FAILURE); - NS_ENSURE_TRUE(doc, NS_ERROR_NULL_POINTER); - - // the result's addref comes from this QueryInterface call - NS_ENSURE_SUCCESS(CallQueryInterface(doc.get(), aDocument), NS_ERROR_FAILURE); - - return NS_OK; + return mContentViewer->GetDOMDocument(aDocument); } NS_IMETHODIMP nsDocShell::GetCurrentURI(PRUnichar** aCurrentURI) @@ -3702,206 +3594,6 @@ NS_IMETHODIMP nsDocShell::EnsureScriptEnvironment() return NS_OK; } -NS_IMETHODIMP -nsDocShell::FireStartDocumentLoad(nsIDocumentLoader* aLoader, - nsIURI * aURL, //XXX: should be the channel? - const char * aCommand) -{ - NS_ENSURE_ARG_POINTER(aLoader); - NS_ENSURE_ARG_POINTER(aURL); - NS_ENSURE_ARG_POINTER(aCommand); - - nsCOMPtr docViewer; - if (mScriptGlobal && (aLoader == mDocLoader.get())) - { - docViewer = do_QueryInterface(mContentViewer); - if (docViewer) - { - nsCOMPtr presContext; - NS_ENSURE_SUCCESS(docViewer->GetPresContext(*(getter_AddRefs(presContext))), NS_ERROR_FAILURE); - if (presContext) - { - nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event; - event.eventStructType = NS_EVENT; - event.message = NS_PAGE_UNLOAD; - NS_ENSURE_SUCCESS(mScriptGlobal->HandleDOMEvent(presContext, - &event, - nsnull, - NS_EVENT_FLAG_INIT, - &status), - NS_ERROR_FAILURE); - } - } - } - - if (aLoader == mDocLoader.get()) - { - nsCOMPtr dlObserver; - - if (!mDocLoaderObserver && mParent) - { - /* If this is a frame (in which case it would have a parent && doesn't - * have a documentloaderObserver, get it from the rootWebShell - */ - nsCOMPtr rootTreeItem; - NS_ENSURE_SUCCESS(GetSameTypeRootTreeItem(getter_AddRefs(rootTreeItem)), - NS_ERROR_FAILURE); - - nsCOMPtr rootAsDocShell(do_QueryInterface(rootTreeItem)); - if(rootAsDocShell) - NS_ENSURE_SUCCESS(rootAsDocShell->GetDocLoaderObserver(getter_AddRefs(dlObserver)), - NS_ERROR_FAILURE); - } - else - { - dlObserver = do_QueryInterface(mDocLoaderObserver); // we need this to addref - } - /* - * Fire the OnStartDocumentLoad of the webshell observer - */ - /* XXX This code means "notify dlObserver only if we're the top level webshell. - I don't know why that would be, can't subdocument have doc loader observers? - */ - if (/*(nsnull != mContainer) && */(nsnull != dlObserver)) - { - NS_ENSURE_SUCCESS(dlObserver->OnStartDocumentLoad(mDocLoader, aURL, aCommand), - NS_ERROR_FAILURE); - } - } - - return NS_OK; -} - - - -NS_IMETHODIMP -nsDocShell::FireEndDocumentLoad(nsIDocumentLoader* aLoader, - nsIChannel * aChannel, - nsresult aStatus) -{ - NS_ENSURE_ARG_POINTER(aLoader); - NS_ENSURE_ARG_POINTER(aChannel); - - nsCOMPtr aURL; - NS_ENSURE_SUCCESS(aChannel->GetURI(getter_AddRefs(aURL)), NS_ERROR_FAILURE); - - if (aLoader == mDocLoader.get()) - { - if (mScriptGlobal && mContentViewer) - { - nsCOMPtr docViewer; - docViewer = do_QueryInterface(mContentViewer); - if (docViewer) - { - nsCOMPtr presContext; - NS_ENSURE_SUCCESS(docViewer->GetPresContext(*(getter_AddRefs(presContext))), NS_ERROR_FAILURE); - if (presContext) - { - nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event; - event.eventStructType = NS_EVENT; - event.message = NS_PAGE_LOAD; - NS_ENSURE_SUCCESS(mScriptGlobal->HandleDOMEvent(presContext, - &event, - nsnull, - NS_EVENT_FLAG_INIT, - &status), - NS_ERROR_FAILURE); - } - } - } - - // Fire the EndLoadURL of the web shell container - /* XXX: what replaces mContainer? - if (nsnull != aURL) - { - nsAutoString urlString; - char* spec; - rv = aURL->GetSpec(&spec); - if (NS_SUCCEEDED(rv)) - { - urlString = spec; - if (nsnull != mContainer) { - rv = mContainer->EndLoadURL(this, urlString.GetUnicode(), 0); - } - nsCRT::free(spec); - } - } - */ - - nsCOMPtr dlObserver; - if (!mDocLoaderObserver && mParent) - { - // If this is a frame (in which case it would have a parent && doesn't - // have a documentloaderObserver, get it from the rootWebShell - nsCOMPtr rootTreeItem; - NS_ENSURE_SUCCESS(GetSameTypeRootTreeItem(getter_AddRefs(rootTreeItem)), - NS_ERROR_FAILURE); - - nsCOMPtr rootAsDocShell(do_QueryInterface(rootTreeItem)); - if(rootAsDocShell) - NS_ENSURE_SUCCESS(rootAsDocShell->GetDocLoaderObserver(getter_AddRefs(dlObserver)), - NS_ERROR_FAILURE); - } - else - { - /* Take care of the Trailing slash situation */ -/* XXX: session history stuff, should be taken care of external to the docshell - if (mSHist) - CheckForTrailingSlash(aURL); -*/ - dlObserver = do_QueryInterface(mDocLoaderObserver); // we need this to addref - } - - /* - * Fire the OnEndDocumentLoad of the DocLoaderobserver - */ - if (dlObserver && aURL) { - NS_ENSURE_SUCCESS(dlObserver->OnEndDocumentLoad(mDocLoader, aChannel, aStatus), - NS_ERROR_FAILURE); - } - - /* put the new document in the doc tree */ - NS_ENSURE_SUCCESS(InsertDocumentInDocTree(), NS_ERROR_FAILURE); - } - - return NS_OK; -} - -NS_IMETHODIMP nsDocShell::InsertDocumentInDocTree() -{ - nsCOMPtr parent(do_QueryInterface(mParent)); - if(parent) - { - // Get the document object for the parent - nsCOMPtr parentContentViewer; - NS_ENSURE_SUCCESS(parent->GetContentViewer(getter_AddRefs(parentContentViewer)), - NS_ERROR_FAILURE); - NS_ENSURE_TRUE(parentContentViewer, NS_ERROR_FAILURE); - nsCOMPtr parentDocViewer; - parentDocViewer = do_QueryInterface(parentContentViewer); - NS_ENSURE_TRUE(parentDocViewer, NS_ERROR_FAILURE); - - nsCOMPtr parentDoc; - NS_ENSURE_SUCCESS(parentDocViewer->GetDocument(*getter_AddRefs(parentDoc)), NS_ERROR_FAILURE); - NS_ENSURE_TRUE(parentDoc, NS_ERROR_FAILURE); - - // Get the document object for this - nsCOMPtr docViewer; - docViewer = do_QueryInterface(mContentViewer); - NS_ENSURE_TRUE(docViewer, NS_ERROR_FAILURE); - - nsCOMPtr doc; - NS_ENSURE_SUCCESS(docViewer->GetDocument(*getter_AddRefs(doc)), NS_ERROR_FAILURE); - NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE); - - doc->SetParentDocument(parentDoc); - parentDoc->AddSubDocument(doc); - } - return NS_OK; -} - PRBool nsDocShell::IsFrame() { if(mParent) diff --git a/docshell/base/nsDocShell.h b/docshell/base/nsDocShell.h index f22473dc401e..674e658e8eb0 100644 --- a/docshell/base/nsDocShell.h +++ b/docshell/base/nsDocShell.h @@ -235,17 +235,6 @@ protected: NS_IMETHOD EnsureContentListener(); NS_IMETHOD EnsureScriptEnvironment(); - - NS_IMETHOD FireStartDocumentLoad(nsIDocumentLoader* aLoader, - nsIURI* aURL, - const char* aCommand); - - NS_IMETHOD FireEndDocumentLoad(nsIDocumentLoader* aLoader, - nsIChannel* aChannel, - nsresult aStatus); - - NS_IMETHOD InsertDocumentInDocTree(); - PRBool IsFrame(); protected: diff --git a/docshell/base/nsWebShell.cpp b/docshell/base/nsWebShell.cpp index b4b2b09dc594..d99dc95d90d8 100644 --- a/docshell/base/nsWebShell.cpp +++ b/docshell/base/nsWebShell.cpp @@ -280,9 +280,6 @@ public: NS_IMETHOD GetPositionAndSize(PRInt32* x, PRInt32* y, PRInt32* cx, PRInt32* cy); - // nsIDocShell - NS_IMETHOD SetDocument(nsIDOMDocument *aDOMDoc, nsIDOMElement *aRootNode); - // nsWebShell nsIEventQueue* GetEventQueue(void); void HandleLinkClickEvent(nsIContent *aContent, @@ -1617,119 +1614,6 @@ NS_IMETHODIMP nsWebShell::GetPositionAndSize(PRInt32* x, PRInt32* y, } -//***************************************************************************** -// nsWebShell::nsIDocShell -//***************************************************************************** - -NS_IMETHODIMP nsWebShell::SetDocument(nsIDOMDocument *aDOMDoc, - nsIDOMElement *aRootNode) -{ - // The tricky part is bypassing the normal load process and just putting a document into - // the webshell. This is particularly nasty, since webshells don't normally even know - // about their documents - - // (1) Create a document viewer - nsCOMPtr documentViewer; - nsCOMPtr docFactory; - static NS_DEFINE_CID(kLayoutDocumentLoaderFactoryCID, NS_LAYOUT_DOCUMENT_LOADER_FACTORY_CID); - NS_ENSURE_SUCCESS(nsComponentManager::CreateInstance(kLayoutDocumentLoaderFactoryCID, nsnull, - NS_GET_IID(nsIDocumentLoaderFactory), - (void**)getter_AddRefs(docFactory)), - NS_ERROR_FAILURE); - - nsCOMPtr doc = do_QueryInterface(aDOMDoc); - if (!doc) { return NS_ERROR_NULL_POINTER; } - - NS_ENSURE_SUCCESS(docFactory->CreateInstanceForDocument(NS_STATIC_CAST(nsIContentViewerContainer*, (nsIWebShell*)this), - doc, - "view", - getter_AddRefs(documentViewer)), - NS_ERROR_FAILURE); - - // (2) Feed the webshell to the content viewer - NS_ENSURE_SUCCESS(documentViewer->SetContainer((nsIWebShell*)this), NS_ERROR_FAILURE); - - // (3) Tell the content viewer container to embed the content viewer. - // (This step causes everything to be set up for an initial flow.) - NS_ENSURE_SUCCESS(SetupNewViewer(documentViewer), NS_ERROR_FAILURE); - - // XXX: It would be great to get rid of this dummy channel! - nsCOMPtr uri; - NS_ENSURE_SUCCESS(NS_NewURI(getter_AddRefs(uri), NS_ConvertASCIItoUCS2("about:blank")), NS_ERROR_FAILURE); - if (!uri) { return NS_ERROR_OUT_OF_MEMORY; } - - nsCOMPtr dummyChannel; - NS_ENSURE_SUCCESS(NS_OpenURI(getter_AddRefs(dummyChannel), uri, nsnull), NS_ERROR_FAILURE); - - // (4) fire start document load notification - nsCOMPtr outStreamListener; // a valid pointer is required for the returned stream listener - // XXX: warning: magic cookie! should get string "view delayedContentLoad" - // from somewhere, maybe nsIHTMLDocument? - NS_ENSURE_SUCCESS(doc->StartDocumentLoad("view delayedContentLoad", - dummyChannel, - nsnull, - NS_STATIC_CAST(nsIContentViewerContainer*, (nsIWebShell*)this), - getter_AddRefs(outStreamListener), - PR_TRUE), - NS_ERROR_FAILURE); - NS_ENSURE_SUCCESS(OnStartDocumentLoad(mDocLoader, uri, "load"), NS_ERROR_FAILURE); - - // (5) hook up the document and its content - nsCOMPtr rootContent = do_QueryInterface(aRootNode); - if (!doc) { return NS_ERROR_OUT_OF_MEMORY; } - NS_ENSURE_SUCCESS(rootContent->SetDocument(doc, PR_FALSE, PR_TRUE), NS_ERROR_FAILURE); - doc->SetRootContent(rootContent); - rootContent->SetDocument(doc, PR_TRUE, PR_TRUE); - - // (6) reflow the document - PRInt32 i; - PRInt32 ns = doc->GetNumberOfShells(); - for (i = 0; i < ns; i++) - { - nsCOMPtr shell(dont_AddRef(doc->GetShellAt(i))); - if (shell) - { - // Make shell an observer for next time - NS_ENSURE_SUCCESS(shell->BeginObservingDocument(), NS_ERROR_FAILURE); - - // Resize-reflow this time - nsCOMPtr docViewer = do_QueryInterface(documentViewer); - if (!docViewer) { return NS_ERROR_OUT_OF_MEMORY; } - nsCOMPtr presContext; - NS_ENSURE_SUCCESS(docViewer->GetPresContext(*(getter_AddRefs(presContext))), NS_ERROR_FAILURE); - if (!presContext) { return NS_ERROR_OUT_OF_MEMORY; } - float p2t; - presContext->GetScaledPixelsToTwips(&p2t); - - nsRect r; - GetPositionAndSize(&r.x, &r.y, &r.width, &r.height); - NS_ENSURE_SUCCESS(shell->InitialReflow(NSToCoordRound(r.width * p2t), NSToCoordRound(r.height * p2t)), NS_ERROR_FAILURE); - - // Now trigger a refresh - nsCOMPtr vm; - NS_ENSURE_SUCCESS(shell->GetViewManager(getter_AddRefs(vm)), NS_ERROR_FAILURE); - if (vm) - { - PRBool enabled; - documentViewer->GetEnableRendering(&enabled); - if (enabled) { - vm->EnableRefresh(NS_VMREFRESH_IMMEDIATE); - } - NS_ENSURE_SUCCESS(vm->SetWindowDimensions(NSToCoordRound(r.width * p2t), - NSToCoordRound(r.height * p2t)), - NS_ERROR_FAILURE); - } - } - } - - // (7) fire end document load notification - nsresult rv = NS_OK; - NS_ENSURE_SUCCESS(OnEndDocumentLoad(mDocLoader, dummyChannel, rv), NS_ERROR_FAILURE); - NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); // test the resulting out-param separately - - return NS_OK; -} - //---------------------------------------------------------------------- // Factory code for creating nsWebShell's diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index 5894506384cc..fe56e5471746 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -192,7 +192,11 @@ public: NS_IMETHOD BindToDocument(nsISupports* aDoc, const char* aCommand); NS_IMETHOD SetContainer(nsISupports* aContainer); NS_IMETHOD GetContainer(nsISupports** aContainerResult); + NS_IMETHOD LoadComplete(nsresult aStatus); + NS_IMETHOD Destroy(void); NS_IMETHOD Stop(void); + NS_IMETHOD GetDOMDocument(nsIDOMDocument **aResult); + NS_IMETHOD SetDOMDocument(nsIDOMDocument *aDocument); NS_IMETHOD GetBounds(nsRect& aResult); NS_IMETHOD SetBounds(const nsRect& aBounds); NS_IMETHOD Move(PRInt32 aX, PRInt32 aY); @@ -621,6 +625,18 @@ DocumentViewerImpl::Init(nsIWidget* aParentWidget, return rv; } +NS_IMETHODIMP +DocumentViewerImpl::LoadComplete(nsresult aStatus) +{ + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +DocumentViewerImpl::Destroy(void) +{ + return NS_ERROR_FAILURE; +} + NS_IMETHODIMP DocumentViewerImpl::Stop(void) { @@ -634,6 +650,18 @@ DocumentViewerImpl::Stop(void) return NS_OK; } +NS_IMETHODIMP +DocumentViewerImpl::GetDOMDocument(nsIDOMDocument **aResult) +{ + return CallQueryInterface(mDocument.get(), aResult); +} + +NS_IMETHODIMP +DocumentViewerImpl::SetDOMDocument(nsIDOMDocument *aDocument) +{ + return NS_ERROR_FAILURE; +} + NS_IMETHODIMP DocumentViewerImpl::SetUAStyleSheet(nsIStyleSheet* aUAStyleSheet) { diff --git a/layout/base/src/nsDocumentViewer.cpp b/layout/base/src/nsDocumentViewer.cpp index 5894506384cc..fe56e5471746 100644 --- a/layout/base/src/nsDocumentViewer.cpp +++ b/layout/base/src/nsDocumentViewer.cpp @@ -192,7 +192,11 @@ public: NS_IMETHOD BindToDocument(nsISupports* aDoc, const char* aCommand); NS_IMETHOD SetContainer(nsISupports* aContainer); NS_IMETHOD GetContainer(nsISupports** aContainerResult); + NS_IMETHOD LoadComplete(nsresult aStatus); + NS_IMETHOD Destroy(void); NS_IMETHOD Stop(void); + NS_IMETHOD GetDOMDocument(nsIDOMDocument **aResult); + NS_IMETHOD SetDOMDocument(nsIDOMDocument *aDocument); NS_IMETHOD GetBounds(nsRect& aResult); NS_IMETHOD SetBounds(const nsRect& aBounds); NS_IMETHOD Move(PRInt32 aX, PRInt32 aY); @@ -621,6 +625,18 @@ DocumentViewerImpl::Init(nsIWidget* aParentWidget, return rv; } +NS_IMETHODIMP +DocumentViewerImpl::LoadComplete(nsresult aStatus) +{ + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +DocumentViewerImpl::Destroy(void) +{ + return NS_ERROR_FAILURE; +} + NS_IMETHODIMP DocumentViewerImpl::Stop(void) { @@ -634,6 +650,18 @@ DocumentViewerImpl::Stop(void) return NS_OK; } +NS_IMETHODIMP +DocumentViewerImpl::GetDOMDocument(nsIDOMDocument **aResult) +{ + return CallQueryInterface(mDocument.get(), aResult); +} + +NS_IMETHODIMP +DocumentViewerImpl::SetDOMDocument(nsIDOMDocument *aDocument) +{ + return NS_ERROR_FAILURE; +} + NS_IMETHODIMP DocumentViewerImpl::SetUAStyleSheet(nsIStyleSheet* aUAStyleSheet) { diff --git a/layout/base/src/nsPluginViewer.cpp b/layout/base/src/nsPluginViewer.cpp index f96eb8b33928..15d1e8a678a4 100644 --- a/layout/base/src/nsPluginViewer.cpp +++ b/layout/base/src/nsPluginViewer.cpp @@ -41,6 +41,7 @@ #include "nsIDocShellTreeItem.h" #include "nsIDocShellTreeOwner.h" #include "nsIWebBrowserChrome.h" +#include "nsIDOMDocument.h" // Class IDs static NS_DEFINE_IID(kChildWindowCID, NS_CHILD_CID); @@ -133,7 +134,11 @@ public: NS_IMETHOD BindToDocument(nsISupports* aDoc, const char* aCommand); NS_IMETHOD SetContainer(nsISupports* aContainer); NS_IMETHOD GetContainer(nsISupports** aContainerResult); + NS_IMETHOD LoadComplete(nsresult aStatus); + NS_IMETHOD Destroy(void); NS_IMETHOD Stop(void); + NS_IMETHOD GetDOMDocument(nsIDOMDocument **aResult); + NS_IMETHOD SetDOMDocument(nsIDOMDocument *aDocument); NS_IMETHOD GetBounds(nsRect& aResult); NS_IMETHOD SetBounds(const nsRect& aBounds); NS_IMETHOD Move(PRInt32 aX, PRInt32 aY); @@ -382,12 +387,35 @@ PluginViewerImpl::Stop(void) return NS_OK; } +NS_IMETHODIMP +PluginViewerImpl::LoadComplete(nsresult aStatus) +{ + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +PluginViewerImpl::Destroy(void) +{ + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +PluginViewerImpl::GetDOMDocument(nsIDOMDocument **aResult) +{ + return CallQueryInterface(mDocument, aResult); +} + +NS_IMETHODIMP +PluginViewerImpl::SetDOMDocument(nsIDOMDocument *aDocument) +{ + return NS_ERROR_FAILURE; +} + static nsEventStatus PR_CALLBACK HandlePluginEvent(nsGUIEvent *aEvent) { return nsEventStatus_eIgnore; } - nsresult PluginViewerImpl::MakeWindow(nsNativeWidget aParent, nsIDeviceContext* aDeviceContext, diff --git a/modules/plugin/base/src/nsPluginViewer.cpp b/modules/plugin/base/src/nsPluginViewer.cpp index f96eb8b33928..15d1e8a678a4 100644 --- a/modules/plugin/base/src/nsPluginViewer.cpp +++ b/modules/plugin/base/src/nsPluginViewer.cpp @@ -41,6 +41,7 @@ #include "nsIDocShellTreeItem.h" #include "nsIDocShellTreeOwner.h" #include "nsIWebBrowserChrome.h" +#include "nsIDOMDocument.h" // Class IDs static NS_DEFINE_IID(kChildWindowCID, NS_CHILD_CID); @@ -133,7 +134,11 @@ public: NS_IMETHOD BindToDocument(nsISupports* aDoc, const char* aCommand); NS_IMETHOD SetContainer(nsISupports* aContainer); NS_IMETHOD GetContainer(nsISupports** aContainerResult); + NS_IMETHOD LoadComplete(nsresult aStatus); + NS_IMETHOD Destroy(void); NS_IMETHOD Stop(void); + NS_IMETHOD GetDOMDocument(nsIDOMDocument **aResult); + NS_IMETHOD SetDOMDocument(nsIDOMDocument *aDocument); NS_IMETHOD GetBounds(nsRect& aResult); NS_IMETHOD SetBounds(const nsRect& aBounds); NS_IMETHOD Move(PRInt32 aX, PRInt32 aY); @@ -382,12 +387,35 @@ PluginViewerImpl::Stop(void) return NS_OK; } +NS_IMETHODIMP +PluginViewerImpl::LoadComplete(nsresult aStatus) +{ + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +PluginViewerImpl::Destroy(void) +{ + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +PluginViewerImpl::GetDOMDocument(nsIDOMDocument **aResult) +{ + return CallQueryInterface(mDocument, aResult); +} + +NS_IMETHODIMP +PluginViewerImpl::SetDOMDocument(nsIDOMDocument *aDocument) +{ + return NS_ERROR_FAILURE; +} + static nsEventStatus PR_CALLBACK HandlePluginEvent(nsGUIEvent *aEvent) { return nsEventStatus_eIgnore; } - nsresult PluginViewerImpl::MakeWindow(nsNativeWidget aParent, nsIDeviceContext* aDeviceContext, diff --git a/modules/plugin/nglsrc/nsPluginViewer.cpp b/modules/plugin/nglsrc/nsPluginViewer.cpp index f96eb8b33928..15d1e8a678a4 100644 --- a/modules/plugin/nglsrc/nsPluginViewer.cpp +++ b/modules/plugin/nglsrc/nsPluginViewer.cpp @@ -41,6 +41,7 @@ #include "nsIDocShellTreeItem.h" #include "nsIDocShellTreeOwner.h" #include "nsIWebBrowserChrome.h" +#include "nsIDOMDocument.h" // Class IDs static NS_DEFINE_IID(kChildWindowCID, NS_CHILD_CID); @@ -133,7 +134,11 @@ public: NS_IMETHOD BindToDocument(nsISupports* aDoc, const char* aCommand); NS_IMETHOD SetContainer(nsISupports* aContainer); NS_IMETHOD GetContainer(nsISupports** aContainerResult); + NS_IMETHOD LoadComplete(nsresult aStatus); + NS_IMETHOD Destroy(void); NS_IMETHOD Stop(void); + NS_IMETHOD GetDOMDocument(nsIDOMDocument **aResult); + NS_IMETHOD SetDOMDocument(nsIDOMDocument *aDocument); NS_IMETHOD GetBounds(nsRect& aResult); NS_IMETHOD SetBounds(const nsRect& aBounds); NS_IMETHOD Move(PRInt32 aX, PRInt32 aY); @@ -382,12 +387,35 @@ PluginViewerImpl::Stop(void) return NS_OK; } +NS_IMETHODIMP +PluginViewerImpl::LoadComplete(nsresult aStatus) +{ + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +PluginViewerImpl::Destroy(void) +{ + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +PluginViewerImpl::GetDOMDocument(nsIDOMDocument **aResult) +{ + return CallQueryInterface(mDocument, aResult); +} + +NS_IMETHODIMP +PluginViewerImpl::SetDOMDocument(nsIDOMDocument *aDocument) +{ + return NS_ERROR_FAILURE; +} + static nsEventStatus PR_CALLBACK HandlePluginEvent(nsGUIEvent *aEvent) { return nsEventStatus_eIgnore; } - nsresult PluginViewerImpl::MakeWindow(nsNativeWidget aParent, nsIDeviceContext* aDeviceContext, diff --git a/webshell/public/nsIContentViewer.h b/webshell/public/nsIContentViewer.h index 0138fac182e7..a649f44c0de8 100644 --- a/webshell/public/nsIContentViewer.h +++ b/webshell/public/nsIContentViewer.h @@ -31,6 +31,7 @@ class nsIDeviceContext; class nsString; struct nsRect; class nsIContentViewerContainer; +class nsIDOMDocument; // IID for the nsIContentViewer interface #define NS_ICONTENT_VIEWER_IID \ @@ -61,8 +62,13 @@ public: NS_IMETHOD GetContainer(nsISupports** aContainerResult) = 0; + NS_IMETHOD LoadComplete(nsresult aStatus) = 0; + NS_IMETHOD Destroy(void) = 0; NS_IMETHOD Stop(void) = 0; + NS_IMETHOD GetDOMDocument(nsIDOMDocument **aResult) = 0; + NS_IMETHOD SetDOMDocument(nsIDOMDocument *aDocument) = 0; + NS_IMETHOD GetBounds(nsRect& aBounds) = 0; NS_IMETHOD SetBounds(const nsRect& aBounds) = 0; diff --git a/webshell/src/nsWebShell.cpp b/webshell/src/nsWebShell.cpp index b4b2b09dc594..d99dc95d90d8 100644 --- a/webshell/src/nsWebShell.cpp +++ b/webshell/src/nsWebShell.cpp @@ -280,9 +280,6 @@ public: NS_IMETHOD GetPositionAndSize(PRInt32* x, PRInt32* y, PRInt32* cx, PRInt32* cy); - // nsIDocShell - NS_IMETHOD SetDocument(nsIDOMDocument *aDOMDoc, nsIDOMElement *aRootNode); - // nsWebShell nsIEventQueue* GetEventQueue(void); void HandleLinkClickEvent(nsIContent *aContent, @@ -1617,119 +1614,6 @@ NS_IMETHODIMP nsWebShell::GetPositionAndSize(PRInt32* x, PRInt32* y, } -//***************************************************************************** -// nsWebShell::nsIDocShell -//***************************************************************************** - -NS_IMETHODIMP nsWebShell::SetDocument(nsIDOMDocument *aDOMDoc, - nsIDOMElement *aRootNode) -{ - // The tricky part is bypassing the normal load process and just putting a document into - // the webshell. This is particularly nasty, since webshells don't normally even know - // about their documents - - // (1) Create a document viewer - nsCOMPtr documentViewer; - nsCOMPtr docFactory; - static NS_DEFINE_CID(kLayoutDocumentLoaderFactoryCID, NS_LAYOUT_DOCUMENT_LOADER_FACTORY_CID); - NS_ENSURE_SUCCESS(nsComponentManager::CreateInstance(kLayoutDocumentLoaderFactoryCID, nsnull, - NS_GET_IID(nsIDocumentLoaderFactory), - (void**)getter_AddRefs(docFactory)), - NS_ERROR_FAILURE); - - nsCOMPtr doc = do_QueryInterface(aDOMDoc); - if (!doc) { return NS_ERROR_NULL_POINTER; } - - NS_ENSURE_SUCCESS(docFactory->CreateInstanceForDocument(NS_STATIC_CAST(nsIContentViewerContainer*, (nsIWebShell*)this), - doc, - "view", - getter_AddRefs(documentViewer)), - NS_ERROR_FAILURE); - - // (2) Feed the webshell to the content viewer - NS_ENSURE_SUCCESS(documentViewer->SetContainer((nsIWebShell*)this), NS_ERROR_FAILURE); - - // (3) Tell the content viewer container to embed the content viewer. - // (This step causes everything to be set up for an initial flow.) - NS_ENSURE_SUCCESS(SetupNewViewer(documentViewer), NS_ERROR_FAILURE); - - // XXX: It would be great to get rid of this dummy channel! - nsCOMPtr uri; - NS_ENSURE_SUCCESS(NS_NewURI(getter_AddRefs(uri), NS_ConvertASCIItoUCS2("about:blank")), NS_ERROR_FAILURE); - if (!uri) { return NS_ERROR_OUT_OF_MEMORY; } - - nsCOMPtr dummyChannel; - NS_ENSURE_SUCCESS(NS_OpenURI(getter_AddRefs(dummyChannel), uri, nsnull), NS_ERROR_FAILURE); - - // (4) fire start document load notification - nsCOMPtr outStreamListener; // a valid pointer is required for the returned stream listener - // XXX: warning: magic cookie! should get string "view delayedContentLoad" - // from somewhere, maybe nsIHTMLDocument? - NS_ENSURE_SUCCESS(doc->StartDocumentLoad("view delayedContentLoad", - dummyChannel, - nsnull, - NS_STATIC_CAST(nsIContentViewerContainer*, (nsIWebShell*)this), - getter_AddRefs(outStreamListener), - PR_TRUE), - NS_ERROR_FAILURE); - NS_ENSURE_SUCCESS(OnStartDocumentLoad(mDocLoader, uri, "load"), NS_ERROR_FAILURE); - - // (5) hook up the document and its content - nsCOMPtr rootContent = do_QueryInterface(aRootNode); - if (!doc) { return NS_ERROR_OUT_OF_MEMORY; } - NS_ENSURE_SUCCESS(rootContent->SetDocument(doc, PR_FALSE, PR_TRUE), NS_ERROR_FAILURE); - doc->SetRootContent(rootContent); - rootContent->SetDocument(doc, PR_TRUE, PR_TRUE); - - // (6) reflow the document - PRInt32 i; - PRInt32 ns = doc->GetNumberOfShells(); - for (i = 0; i < ns; i++) - { - nsCOMPtr shell(dont_AddRef(doc->GetShellAt(i))); - if (shell) - { - // Make shell an observer for next time - NS_ENSURE_SUCCESS(shell->BeginObservingDocument(), NS_ERROR_FAILURE); - - // Resize-reflow this time - nsCOMPtr docViewer = do_QueryInterface(documentViewer); - if (!docViewer) { return NS_ERROR_OUT_OF_MEMORY; } - nsCOMPtr presContext; - NS_ENSURE_SUCCESS(docViewer->GetPresContext(*(getter_AddRefs(presContext))), NS_ERROR_FAILURE); - if (!presContext) { return NS_ERROR_OUT_OF_MEMORY; } - float p2t; - presContext->GetScaledPixelsToTwips(&p2t); - - nsRect r; - GetPositionAndSize(&r.x, &r.y, &r.width, &r.height); - NS_ENSURE_SUCCESS(shell->InitialReflow(NSToCoordRound(r.width * p2t), NSToCoordRound(r.height * p2t)), NS_ERROR_FAILURE); - - // Now trigger a refresh - nsCOMPtr vm; - NS_ENSURE_SUCCESS(shell->GetViewManager(getter_AddRefs(vm)), NS_ERROR_FAILURE); - if (vm) - { - PRBool enabled; - documentViewer->GetEnableRendering(&enabled); - if (enabled) { - vm->EnableRefresh(NS_VMREFRESH_IMMEDIATE); - } - NS_ENSURE_SUCCESS(vm->SetWindowDimensions(NSToCoordRound(r.width * p2t), - NSToCoordRound(r.height * p2t)), - NS_ERROR_FAILURE); - } - } - } - - // (7) fire end document load notification - nsresult rv = NS_OK; - NS_ENSURE_SUCCESS(OnEndDocumentLoad(mDocLoader, dummyChannel, rv), NS_ERROR_FAILURE); - NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); // test the resulting out-param separately - - return NS_OK; -} - //---------------------------------------------------------------------- // Factory code for creating nsWebShell's