Skip to content

Commit

Permalink
DocShell cleanup. Removed the implementation of the unused nsIDocSHel…
Browse files Browse the repository at this point in the history
…l::SetDocument() method and moved the implementation responsibility to the nsIContentViewer
  • Loading branch information
rpotts%netscape.com committed Jun 22, 2000
1 parent be4230e commit cf3e824
Show file tree
Hide file tree
Showing 11 changed files with 180 additions and 557 deletions.
28 changes: 28 additions & 0 deletions content/base/src/nsDocumentViewer.cpp
Expand Up @@ -192,7 +192,11 @@ class DocumentViewerImpl : public nsIDocumentViewer,
NS_IMETHOD BindToDocument(nsISupports* aDoc, const char* aCommand); NS_IMETHOD BindToDocument(nsISupports* aDoc, const char* aCommand);
NS_IMETHOD SetContainer(nsISupports* aContainer); NS_IMETHOD SetContainer(nsISupports* aContainer);
NS_IMETHOD GetContainer(nsISupports** aContainerResult); NS_IMETHOD GetContainer(nsISupports** aContainerResult);
NS_IMETHOD LoadComplete(nsresult aStatus);
NS_IMETHOD Destroy(void);
NS_IMETHOD Stop(void); NS_IMETHOD Stop(void);
NS_IMETHOD GetDOMDocument(nsIDOMDocument **aResult);
NS_IMETHOD SetDOMDocument(nsIDOMDocument *aDocument);
NS_IMETHOD GetBounds(nsRect& aResult); NS_IMETHOD GetBounds(nsRect& aResult);
NS_IMETHOD SetBounds(const nsRect& aBounds); NS_IMETHOD SetBounds(const nsRect& aBounds);
NS_IMETHOD Move(PRInt32 aX, PRInt32 aY); NS_IMETHOD Move(PRInt32 aX, PRInt32 aY);
Expand Down Expand Up @@ -621,6 +625,18 @@ DocumentViewerImpl::Init(nsIWidget* aParentWidget,
return rv; return rv;
} }


NS_IMETHODIMP
DocumentViewerImpl::LoadComplete(nsresult aStatus)
{
return NS_ERROR_FAILURE;
}

NS_IMETHODIMP
DocumentViewerImpl::Destroy(void)
{
return NS_ERROR_FAILURE;
}

NS_IMETHODIMP NS_IMETHODIMP
DocumentViewerImpl::Stop(void) DocumentViewerImpl::Stop(void)
{ {
Expand All @@ -634,6 +650,18 @@ DocumentViewerImpl::Stop(void)
return NS_OK; 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 NS_IMETHODIMP
DocumentViewerImpl::SetUAStyleSheet(nsIStyleSheet* aUAStyleSheet) DocumentViewerImpl::SetUAStyleSheet(nsIStyleSheet* aUAStyleSheet)
{ {
Expand Down
314 changes: 3 additions & 311 deletions docshell/base/nsDocShell.cpp
Expand Up @@ -268,109 +268,11 @@ NS_IMETHODIMP nsDocShell::StopLoad()
return NS_OK; return NS_OK;
} }


// SetDocument is only meaningful for doc shells that support DOM documents. Not all do.
NS_IMETHODIMP NS_IMETHODIMP
nsDocShell::SetDocument(nsIDOMDocument *aDOMDoc, nsIDOMElement *aRootNode) nsDocShell::SetDocument(nsIDOMDocument *aDOMDoc, nsIDOMElement *aRootNode)
{ {

/* XXX: This method is obsolete and will be removed. */
// The tricky part is bypassing the normal load process and just putting a document into return NS_ERROR_FAILURE;
// the webshell. This is particularly nasty, since webshells don't normally even know
// about their documents

// (1) Create a document viewer
nsCOMPtr<nsIContentViewer> documentViewer;
nsCOMPtr<nsIDocumentLoaderFactory> 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<nsIDocument> 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<nsIURI> 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<nsIChannel> dummyChannel;
NS_ENSURE_SUCCESS(NS_OpenURI(getter_AddRefs(dummyChannel), uri, nsnull), NS_ERROR_FAILURE);

// (4) fire start document load notification
nsCOMPtr<nsIStreamListener> 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<nsIContent> 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<nsIPresShell> 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<nsIDocumentViewer> docViewer = do_QueryInterface(documentViewer);
NS_ENSURE_TRUE(docViewer, NS_ERROR_OUT_OF_MEMORY);
nsCOMPtr<nsIPresContext> 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<nsIViewManager> 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;
} }


NS_IMETHODIMP nsDocShell::GetCurrentURI(nsIURI** aURI) NS_IMETHODIMP nsDocShell::GetCurrentURI(nsIURI** aURI)
Expand Down Expand Up @@ -1207,17 +1109,7 @@ NS_IMETHODIMP nsDocShell::GetDocument(nsIDOMDocument** aDocument)
NS_ENSURE_ARG_POINTER(aDocument); NS_ENSURE_ARG_POINTER(aDocument);
NS_ENSURE_STATE(mContentViewer); NS_ENSURE_STATE(mContentViewer);


nsCOMPtr<nsIDocumentViewer> docv(do_QueryInterface(mContentViewer)); return mContentViewer->GetDOMDocument(aDocument);
NS_ENSURE_TRUE(docv, NS_ERROR_FAILURE);

nsCOMPtr<nsIDocument>doc;
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;
} }


NS_IMETHODIMP nsDocShell::GetCurrentURI(PRUnichar** aCurrentURI) NS_IMETHODIMP nsDocShell::GetCurrentURI(PRUnichar** aCurrentURI)
Expand Down Expand Up @@ -3702,206 +3594,6 @@ NS_IMETHODIMP nsDocShell::EnsureScriptEnvironment()
return NS_OK; 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<nsIDocumentViewer> docViewer;
if (mScriptGlobal && (aLoader == mDocLoader.get()))
{
docViewer = do_QueryInterface(mContentViewer);
if (docViewer)
{
nsCOMPtr<nsIPresContext> 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<nsIDocumentLoaderObserver> 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<nsIDocShellTreeItem> rootTreeItem;
NS_ENSURE_SUCCESS(GetSameTypeRootTreeItem(getter_AddRefs(rootTreeItem)),
NS_ERROR_FAILURE);

nsCOMPtr<nsIDocShell> 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<nsIURI> aURL;
NS_ENSURE_SUCCESS(aChannel->GetURI(getter_AddRefs(aURL)), NS_ERROR_FAILURE);

if (aLoader == mDocLoader.get())
{
if (mScriptGlobal && mContentViewer)
{
nsCOMPtr<nsIDocumentViewer> docViewer;
docViewer = do_QueryInterface(mContentViewer);
if (docViewer)
{
nsCOMPtr<nsIPresContext> 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<nsIDocumentLoaderObserver> 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<nsIDocShellTreeItem> rootTreeItem;
NS_ENSURE_SUCCESS(GetSameTypeRootTreeItem(getter_AddRefs(rootTreeItem)),
NS_ERROR_FAILURE);

nsCOMPtr<nsIDocShell> 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<nsIDocShell> parent(do_QueryInterface(mParent));
if(parent)
{
// Get the document object for the parent
nsCOMPtr<nsIContentViewer> parentContentViewer;
NS_ENSURE_SUCCESS(parent->GetContentViewer(getter_AddRefs(parentContentViewer)),
NS_ERROR_FAILURE);
NS_ENSURE_TRUE(parentContentViewer, NS_ERROR_FAILURE);
nsCOMPtr<nsIDocumentViewer> parentDocViewer;
parentDocViewer = do_QueryInterface(parentContentViewer);
NS_ENSURE_TRUE(parentDocViewer, NS_ERROR_FAILURE);

nsCOMPtr<nsIDocument> 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<nsIDocumentViewer> docViewer;
docViewer = do_QueryInterface(mContentViewer);
NS_ENSURE_TRUE(docViewer, NS_ERROR_FAILURE);

nsCOMPtr<nsIDocument> 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() PRBool nsDocShell::IsFrame()
{ {
if(mParent) if(mParent)
Expand Down

0 comments on commit cf3e824

Please sign in to comment.