From 51c6453edf82323602d1ca76642538626e60794e Mon Sep 17 00:00:00 2001 From: "radha%netscape.com" Date: Thu, 19 Sep 2002 21:59:34 +0000 Subject: [PATCH] Fix for bug # 151061. Mozilla loses base uri for wyciwyg documents. r=caillon sr=jst. --- docshell/base/nsDocShell.cpp | 45 ++++++++++++++++++++++++++++++++++++ docshell/base/nsDocShell.h | 2 ++ 2 files changed, 47 insertions(+) diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index faef688d409..ee67b41c9f0 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -3949,6 +3949,22 @@ nsDocShell::Embed(nsIContentViewer * aContentViewer, nsresult rv = SetupNewViewer(aContentViewer); + // If we are loading a wyciwyg url from history, change the base URI for + // the document to the original http url that created the document.write(). + // This makes sure that all relative urls in a document.written page loaded + // via history work properly. + PRBool historyLoad = PR_FALSE, isWyciwyg = PR_FALSE; + + if (mLoadType & LOAD_CMD_HISTORY || + mLoadType == LOAD_RELOAD_NORMAL || + mLoadType == LOAD_RELOAD_CHARSET_CHANGE) + historyLoad = PR_TRUE; + + rv = mCurrentURI->SchemeIs("wyciwyg", &isWyciwyg); + + if (historyLoad && NS_SUCCEEDED(rv) && isWyciwyg) + SetBaseUrlForWyciwyg(aContentViewer); + // XXX What if SetupNewViewer fails? if (mLSHE) mOSHE = mLSHE; @@ -6753,3 +6769,32 @@ nsDocShell::InterfaceRequestorProxy::GetInterface(const nsIID & aIID, void **aSi *aSink = nsnull; return NS_NOINTERFACE; } + +nsresult +nsDocShell::SetBaseUrlForWyciwyg(nsIContentViewer * aContentViewer) +{ + nsCOMPtr baseURI; + nsCOMPtr document; + nsresult rv = NS_OK; + + if (!aContentViewer) + return NS_ERROR_FAILURE; + + // Create the fixup object if necessary + if (!mURIFixup) + mURIFixup = do_GetService(NS_URIFIXUP_CONTRACTID, &rv); + + if (mURIFixup) + rv = mURIFixup->CreateExposableURI(mCurrentURI, getter_AddRefs(baseURI)); + + // Get the current document and set the base uri + if (baseURI) { + nsCOMPtr docViewer(do_QueryInterface(aContentViewer)); + if (docViewer) { + rv = docViewer->GetDocument(*getter_AddRefs(document)); + if (document) + rv = document->SetBaseURL(baseURI); + } + } + return rv; +} diff --git a/docshell/base/nsDocShell.h b/docshell/base/nsDocShell.h index 2469a5729b3..c38e9574d47 100644 --- a/docshell/base/nsDocShell.h +++ b/docshell/base/nsDocShell.h @@ -251,6 +251,8 @@ protected: NS_IMETHOD DisplayLoadError(nsresult aError, nsIURI *aURI, const PRUnichar *aURL); NS_IMETHOD LoadErrorPage(nsIURI *aURI, const PRUnichar *aURL, const PRUnichar *aPage, const PRUnichar *aDescription); + nsresult SetBaseUrlForWyciwyg(nsIContentViewer * aContentViewer); + static inline PRUint32 PRTimeToSeconds(PRTime t_usec) {