diff --git a/docshell/base/nsDocShellBase.cpp b/docshell/base/nsDocShellBase.cpp index c7919ea80759..073052a6cd10 100644 --- a/docshell/base/nsDocShellBase.cpp +++ b/docshell/base/nsDocShellBase.cpp @@ -20,9 +20,11 @@ * Travis Bogard */ -#include "nsDocShellBase.h" #include "nsIDocument.h" #include "nsIDOMDocument.h" +#include "nsIDocumentViewer.h" + +#include "nsDocShellBase.h" //***************************************************************************** //*** nsDocShellBase: Object Management @@ -54,23 +56,16 @@ NS_IMPL_ISUPPORTS6(nsDocShellBase, nsIDocShell, nsIDocShellEdit, // nsDocShellBase::nsIDocShell //***************************************************************************** -NS_IMETHODIMP nsDocShellBase::LoadURI(const PRUnichar* uri) +NS_IMETHODIMP nsDocShellBase::LoadURI(const PRUnichar* uri, + nsIPresContext* presContext) { - NS_ENSURE_ARG(uri); - //XXX First Check - /* - Loads a given URI. This will give priority to loading the requested URI - in the object implementing this interface. If it can't be loaded here - however, the URL dispatcher will go through its normal process of content - loading. + //NS_ENSURE_ARG(uri); // Done in LoadURIVia for us. - @param uri - The URI to load. - */ - return NS_ERROR_FAILURE; + return LoadURIVia(uri, presContext, 0); } NS_IMETHODIMP nsDocShellBase::LoadURIVia(const PRUnichar* uri, - PRUint32 adapterBinding) + nsIPresContext* presContext, PRUint32 adapterBinding) { NS_ENSURE_ARG(uri); //XXX First Check @@ -89,10 +84,13 @@ NS_IMETHODIMP nsDocShellBase::LoadURIVia(const PRUnichar* uri, NS_IMETHODIMP nsDocShellBase::GetDocument(nsIDOMDocument** aDocument) { NS_ENSURE_ARG_POINTER(aDocument); - NS_ENSURE_STATE(mPresShell); + NS_ENSURE_STATE(mContentViewer); + + nsCOMPtr presShell; + NS_ENSURE_SUCCESS(GetPresShell(getter_AddRefs(presShell)), NS_ERROR_FAILURE); nsCOMPtrdoc; - NS_ENSURE_SUCCESS(mPresShell->GetDocument(getter_AddRefs(doc)), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(presShell->GetDocument(getter_AddRefs(doc)), NS_ERROR_FAILURE); NS_ENSURE(doc, NS_ERROR_NULL_POINTER); // the result's addref comes from this QueryInterface call @@ -102,7 +100,8 @@ NS_IMETHODIMP nsDocShellBase::GetDocument(nsIDOMDocument** aDocument) } // SetDocument is only meaningful for doc shells that support DOM documents. Not all do. -NS_IMETHODIMP nsDocShellBase::SetDocument(nsIDOMDocument* aDocument) +NS_IMETHODIMP nsDocShellBase::SetDocument(nsIDOMDocument* aDocument, + nsIPresContext* presContext) { NS_WARN_IF_FALSE(PR_FALSE, "Subclasses should override this method!!!!"); return NS_ERROR_NOT_IMPLEMENTED; @@ -135,21 +134,20 @@ NS_IMETHODIMP nsDocShellBase::GetPresContext(nsIPresContext** aPresContext) { NS_ENSURE_ARG_POINTER(aPresContext); - *aPresContext = mPresContext; - NS_IF_ADDREF(*aPresContext); + if(!mContentViewer) + { + *aPresContext = nsnull; + return NS_OK; + } + + nsCOMPtr docv(do_QueryInterface(mContentViewer)); + NS_ENSURE(docv, NS_ERROR_FAILURE); + + NS_ENSURE_SUCCESS(docv->GetPresContext(*aPresContext), NS_ERROR_FAILURE); return NS_OK; } -NS_IMETHODIMP nsDocShellBase::SetPresContext(nsIPresContext* aPresContext) -{ - // null aPresContext is ok - mPresContext = aPresContext; // this assignment does an addref - - return NS_OK; -} - - NS_IMETHODIMP nsDocShellBase::GetParent(nsIDocShell** parent) { NS_ENSURE_ARG_POINTER(parent); @@ -250,10 +248,12 @@ NS_IMETHODIMP nsDocShellBase::GetSearchable(PRBool* aSearchable) NS_IMETHODIMP nsDocShellBase::ClearSelection() { - NS_ENSURE_STATE(mPresShell); + NS_ENSURE_STATE(mContentViewer); + nsCOMPtr presShell; + NS_ENSURE_SUCCESS(GetPresShell(getter_AddRefs(presShell)), NS_ERROR_FAILURE); nsCOMPtr selection; - NS_ENSURE_SUCCESS(mPresShell->GetSelection(SELECTION_NORMAL, + NS_ENSURE_SUCCESS(presShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)), NS_ERROR_FAILURE); NS_ENSURE_SUCCESS(selection->ClearSelection(), NS_ERROR_FAILURE); @@ -269,10 +269,12 @@ NS_IMETHODIMP nsDocShellBase::SelectAll() NS_IMETHODIMP nsDocShellBase::CopySelection() { - NS_ENSURE_STATE(mPresShell); + NS_ENSURE_STATE(mContentViewer); + nsCOMPtr presShell; + NS_ENSURE_SUCCESS(GetPresShell(getter_AddRefs(presShell)), NS_ERROR_FAILURE); // the pres shell knows how to copy, so let it do the work - NS_ENSURE_SUCCESS(mPresShell->DoCopy(), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(presShell->DoCopy(), NS_ERROR_FAILURE); return NS_OK; } @@ -283,10 +285,12 @@ NS_IMETHODIMP nsDocShellBase::GetCopyable(PRBool *aCopyable) { NS_ENSURE_ARG_POINTER(aCopyable); - NS_ENSURE_STATE(mPresShell); + NS_ENSURE_STATE(mContentViewer); + nsCOMPtr presShell; + NS_ENSURE_SUCCESS(GetPresShell(getter_AddRefs(presShell)), NS_ERROR_FAILURE); nsCOMPtr selection; - NS_ENSURE_SUCCESS(mPresShell->GetSelection(SELECTION_NORMAL, + NS_ENSURE_SUCCESS(presShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)), NS_ERROR_FAILURE); if(!selection) @@ -1019,4 +1023,64 @@ nsresult nsDocShellBase::GetRootScrollableView(nsIScrollableView** aOutScrollVie NS_ERROR_FAILURE); return NS_OK; -} +} + +nsresult nsDocShellBase::GetPresShell(nsIPresShell** aPresShell) +{ + NS_ENSURE_ARG_POINTER(aPresShell); + + nsCOMPtr presContext; + NS_ENSURE_SUCCESS(GetPresContext(getter_AddRefs(presContext)), + NS_ERROR_FAILURE); + + NS_ENSURE_SUCCESS(presContext->GetShell(aPresShell), NS_ERROR_FAILURE); + + return NS_OK; +} + +/* + +// null result aPresContext is legal +NS_IMETHODIMP nsDocShellBase::GetPresContext(nsIPresContext** aPresContext) +{ + NS_ENSURE_ARG_POINTER(aPresContext); + + nsCOMPtr cv; + NS_ENSURE_SUCCESS(GetContentViewer(getter_AddRefs(cv))); + // null content viewer is legal + + if (cv) + { + nsIDocumentViewer* docv = nsnull; + cv->QueryInterface(kIDocumentViewerIID, (void**) &docv); + if (docv) + { + nsIPresContext* cx; + NS_ENSURE_SUCCESS(docv->GetPresContext(aPresContext)); + } + } + + return NS_OK; +} + + +NS_IMETHODIMP nsDocShellBase::GetDocument(nsIDOMDocument** aDocument) +{ + NS_ENSURE_ARG_POINTER(aDocument); + + nsCOMPtr presShell; + NS_ENSURE_SUCCESS(GetPresShell(getter_AddRefs(presShell))); + NS_ENSURE(presShell, NS_ERROR_FAILURE); + + nsCOMPtrdoc; + NS_ENSURE_SUCCESS(PresShell->GetDocument(getter_AddRefs(doc)), NS_ERROR_FAILURE); + NS_ENSURE(doc, NS_ERROR_NULL_POINTER); + + // the result's addref comes from this QueryInterface call + NS_ENSURE_SUCCESS(CallQueryInterface(doc, aDocument), NS_ERROR_FAILURE); + + return NS_OK; +} + + + */ \ No newline at end of file diff --git a/docshell/base/nsDocShellBase.h b/docshell/base/nsDocShellBase.h index 391fd363fb77..3290ae75cab1 100644 --- a/docshell/base/nsDocShellBase.h +++ b/docshell/base/nsDocShellBase.h @@ -29,6 +29,7 @@ #include "nsIDOMNodeList.h" #include "nsIViewManager.h" #include "nsIScrollableView.h" +#include "nsIContentViewer.h" #include "nsIDocShell.h" #include "nsIDocShellEdit.h" @@ -70,15 +71,15 @@ protected: nsresult GetChildOffset(nsIDOMNode* aChild, nsIDOMNode* aParent, PRInt32* aOffset); nsresult GetRootScrollableView(nsIScrollableView** aOutScrollView); + nsresult GetPresShell(nsIPresShell** aPresShell); protected: PRBool mCreated; nsString mName; nsDocShellInitInfo* mBaseInitInfo; + nsCOMPtr mContentViewer; nsCOMPtr mParent; - nsCOMPtr mPresContext; nsCOMPtr mParentWidget; - nsCOMPtr mPresShell; nsCOMPtr mPrefs; }; diff --git a/docshell/base/nsIDocShell.idl b/docshell/base/nsIDocShell.idl index b1c29fb572f7..e6e4d242b2eb 100644 --- a/docshell/base/nsIDocShell.idl +++ b/docshell/base/nsIDocShell.idl @@ -58,8 +58,10 @@ interface nsIDocShell : nsISupports loading. @param uri - The URI to load. + @param presContext - Presentation Context to use for the new URL. This + may be null. */ - void LoadURI(in wstring uri); + [noscript]void LoadURI(in wstring uri, in nsIPresContext presContext); /* Loads a given URI through the specified adapter. This will give priority @@ -68,15 +70,26 @@ interface nsIDocShell : nsISupports normal process of content loading. @param uri - The URI to load. + @param presContext - Presentation Context to use for the new URL. This + may be null. @param adapterBinding - The local IP address of the adapter to bind to. */ - void LoadURIVia(in wstring uri, in unsigned long adapterBinding); + [noscript]void LoadURIVia(in wstring uri, in nsIPresContext presContext, + in unsigned long adapterBinding); /* - The current document that is loaded in the DocShell. When setting this it - will will simulate the normal load process. + Sets the current document to the one being passed in. This will simulate + a load. + + @param document - The document to load. + @param */ - attribute nsIDOMDocument document; + [noscript]void SetDocument(in nsIDOMDocument document, in nsIPresContext presContext); + + /* + The current document that is loaded in the DocShell. + */ + readonly attribute nsIDOMDocument document; /* name of the DocShell @@ -84,9 +97,9 @@ interface nsIDocShell : nsISupports attribute wstring name; /* - Presentation context + Presentation context for the currently loaded document. This may be null. */ - attribute nsIPresContext presContext; + readonly attribute nsIPresContext presContext; /* Parent DocShell