diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index 7e58a10645e..0e11389ca00 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -233,6 +233,7 @@ nsDocShell::LoadURI(nsIURI* aURI, nsIDocShellLoadInfo* aLoadInfo) nsresult rv; nsCOMPtr referrer; nsCOMPtr owner; + PRBool inheritOwner = PR_FALSE; nsCOMPtr shEntry; nsDocShellInfoLoadType loadType = nsIDocShellLoadInfo::loadNormal; @@ -243,6 +244,7 @@ nsDocShell::LoadURI(nsIURI* aURI, nsIDocShellLoadInfo* aLoadInfo) aLoadInfo->GetReferrer(getter_AddRefs(referrer)); aLoadInfo->GetLoadType(&loadType); aLoadInfo->GetOwner(getter_AddRefs(owner)); + aLoadInfo->GetInheritOwner(&inheritOwner); aLoadInfo->GetSHEntry(getter_AddRefs(shEntry)); } @@ -272,7 +274,7 @@ nsDocShell::LoadURI(nsIURI* aURI, nsIDocShellLoadInfo* aLoadInfo) if (shEntry) { rv = LoadHistoryEntry(shEntry, loadType); } else { - rv = InternalLoad(aURI, referrer, owner, nsnull, nsnull, loadType, nsnull); + rv = InternalLoad(aURI, referrer, owner, inheritOwner, nsnull, nsnull, loadType, nsnull); } return rv; @@ -1376,7 +1378,7 @@ NS_IMETHODIMP nsDocShell::Reload(PRInt32 aReloadType) } else { //May be one of those charset reloads in a composer or Messenger - return InternalLoad(mCurrentURI, mReferrerURI, nsnull, nsnull, + return InternalLoad(mCurrentURI, mReferrerURI, nsnull, PR_TRUE, nsnull, nsnull, type); } @@ -1386,7 +1388,7 @@ NS_IMETHODIMP nsDocShell::Reload(PRInt32 aReloadType) // If this really keeps the crash from re-occuring, may be this can stay. However // there is no major difference between this one and the one inside #if 0 - return InternalLoad(mCurrentURI, mReferrerURI, nsnull, nsnull, + return InternalLoad(mCurrentURI, mReferrerURI, nsnull, PR_TRUE, nsnull, nsnull, type); #endif /* 0 */ @@ -1406,7 +1408,7 @@ NS_IMETHODIMP nsDocShell::Reload(PRInt32 aReloadType) UpdateCurrentSessionHistory(); - NS_ENSURE_SUCCESS(InternalLoad(mCurrentURI, mReferrerURI, nsnull, nsnull, + NS_ENSURE_SUCCESS(InternalLoad(mCurrentURI, mReferrerURI, nsnull, PR_TRUE, nsnull, nsnull, type), NS_ERROR_FAILURE); return NS_OK; #endif /* SH_IN_FRAMES */ @@ -2742,11 +2744,13 @@ NS_IMETHODIMP nsDocShell::SetupNewViewer(nsIContentViewer* aNewViewer) //***************************************************************************** #ifdef SH_IN_FRAMES NS_IMETHODIMP nsDocShell::InternalLoad(nsIURI* aURI, nsIURI* aReferrer, - nsISupports* aOwner, const char* aWindowTarget, nsIInputStream* aPostData, + nsISupports* aOwner, PRBool aInheritOwner, + const char* aWindowTarget, nsIInputStream* aPostData, nsDocShellInfoLoadType aLoadType, nsISHEntry * aSHEntry) #else NS_IMETHODIMP nsDocShell::InternalLoad(nsIURI* aURI, nsIURI* aReferrer, - nsISupports* aOwner, const char* aWindowTarget, nsIInputStream* aPostData, + nsISupports* aOwner, PRBool aInheritOwner, + const char* aWindowTarget, nsIInputStream* aPostData, nsDocShellInfoLoadType aLoadType) #endif { @@ -2804,8 +2808,8 @@ NS_IMETHODIMP nsDocShell::InternalLoad(nsIURI* aURI, nsIURI* aReferrer, nsURILoadCommand loadCmd = nsIURILoader::viewNormal; if(nsIDocShellLoadInfo::loadLink == aLoadType) loadCmd = nsIURILoader::viewUserClick; - NS_ENSURE_SUCCESS(DoURILoad(aURI, aReferrer, aOwner, loadCmd, aWindowTarget, - aPostData), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(DoURILoad(aURI, aReferrer, aOwner, aInheritOwner, + loadCmd, aWindowTarget, aPostData), NS_ERROR_FAILURE); return NS_OK; } @@ -3068,10 +3072,10 @@ NS_IMETHODIMP nsDocShell::GetCurrentDocumentOwner(nsISupports** aOwner) } NS_IMETHODIMP nsDocShell::DoURILoad(nsIURI* aURI, nsIURI* aReferrerURI, - nsISupports* aOwner, nsURILoadCommand aLoadCmd, const char* aWindowTarget, - nsIInputStream* aPostData) + nsISupports* aOwner, PRBool aInheritOwner, nsURILoadCommand aLoadCmd, + const char* aWindowTarget, nsIInputStream* aPostData) { - + static const char jsSchemeName[] = "javascript"; // if the load cmd is a user click....and we are supposed to try using // external default protocol handlers....then try to see if we have one for // this protocol @@ -3080,7 +3084,7 @@ NS_IMETHODIMP nsDocShell::DoURILoad(nsIURI* aURI, nsIURI* aReferrerURI, nsXPIDLCString urlScheme; aURI->GetScheme(getter_Copies(urlScheme)); // don't do it for javascript urls! - if (urlScheme && nsCRT::strcasecmp("javascript", urlScheme)) + if (urlScheme && nsCRT::strcasecmp(jsSchemeName, urlScheme)) { nsCOMPtr extProtService (do_GetService(NS_EXTERNALPROTOCOLSERVICE_PROGID)); PRBool haveHandler = PR_FALSE; @@ -3139,34 +3143,29 @@ NS_IMETHODIMP nsDocShell::DoURILoad(nsIURI* aURI, nsIURI* aReferrerURI, } else { - // If an owner was not provided, we want to inherit the principal from the current document iff we - // are dealing with a JS or a data url. - nsCOMPtr owner = aOwner; - nsCOMPtr ioChannel(do_QueryInterface(channel)); - if(ioChannel) // Might be a javascript: URL load, need to set owner - { - static const char jsSchemeName[] = "javascript"; - char* scheme; - aURI->GetScheme(&scheme); - if (PL_strcasecmp(scheme, jsSchemeName) == 0) - { - if (!owner) // only try to call GetCurrentDocumentOwner if we are a JS url or a data url (hence the code duplication) - GetCurrentDocumentOwner(getter_AddRefs(owner)); + // iff we are dealing with a JS or a data url, we may need an inherited owner. + // This is either aOwner or, if aInheritOwner is true, the owner of the + // current document. + nsCOMPtr owner = aOwner; + PRBool isJSOrData = PR_FALSE; + nsCOMPtr ioChannel(do_QueryInterface(channel)); + if(ioChannel) // Might be a javascript: URL load, need to set owner + { + nsXPIDLCString scheme; + aURI->GetScheme(getter_Copies(scheme)); + isJSOrData = (PL_strcasecmp(scheme, jsSchemeName) == 0); + } + else + { // Also set owner for data: URLs + nsCOMPtr dataChannel(do_QueryInterface(channel)); + isJSOrData = (dataChannel != nsnull); + } + if (isJSOrData) + { + if (aInheritOwner && !owner) + GetCurrentDocumentOwner(getter_AddRefs(owner)); channel->SetOwner(owner); - } - if (scheme) - nsCRT::free(scheme); - } - else - { // Also set owner for data: URLs - nsCOMPtr dataChannel(do_QueryInterface(channel)); - if (dataChannel) - { - if (!owner) - GetCurrentDocumentOwner(getter_AddRefs(owner)); - channel->SetOwner(owner); - } - } + } } NS_ENSURE_SUCCESS(DoChannelLoad(channel, aLoadCmd, aWindowTarget, uriLoader), NS_ERROR_FAILURE); @@ -3696,10 +3695,10 @@ NS_IMETHODIMP nsDocShell::LoadHistoryEntry(nsISHEntry* aEntry) #ifdef SH_IN_FRAMES - NS_ENSURE_SUCCESS(InternalLoad(uri, nsnull, nsnull, nsnull, postData, aLoadType, aEntry), + NS_ENSURE_SUCCESS(InternalLoad(uri, nsnull, nsnull, PR_TRUE, nsnull, postData, aLoadType, aEntry), NS_ERROR_FAILURE); #else - NS_ENSURE_SUCCESS(InternalLoad(uri, nsnull, nsnull, nsnull, postData, nsIDocShellLoadInfo::loadHistory), + NS_ENSURE_SUCCESS(InternalLoad(uri, nsnull, nsnull, PR_TRUE, nsnull, postData, nsIDocShellLoadInfo::loadHistory), NS_ERROR_FAILURE); #endif diff --git a/mozilla/docshell/base/nsDocShell.h b/mozilla/docshell/base/nsDocShell.h index 54ac0841a90..e541cb1f4f7 100644 --- a/mozilla/docshell/base/nsDocShell.h +++ b/mozilla/docshell/base/nsDocShell.h @@ -170,11 +170,11 @@ protected: #ifdef SH_IN_FRAMES NS_IMETHOD InternalLoad(nsIURI* aURI, nsIURI* aReferrerURI, - nsISupports* owner, const char* aWindowTarget=nsnull, + nsISupports* owner, PRBool inheritOwnerFromDocument, const char* aWindowTarget=nsnull, nsIInputStream* aPostData=nsnull, nsDocShellInfoLoadType aLoadType=nsIDocShellLoadInfo::loadNormal, nsISHEntry * aSHEntry = nsnull); #else NS_IMETHOD InternalLoad(nsIURI* aURI, nsIURI* aReferrerURI, - nsISupports* owner, const char* aWindowTarget=nsnull, + nsISupports* owner, PRBool inheritOwnerFromDocument, const char* aWindowTarget=nsnull, nsIInputStream* aPostData=nsnull, nsDocShellInfoLoadType aLoadType=nsIDocShellLoadInfo::loadNormal); #endif @@ -185,7 +185,7 @@ protected: NS_IMETHOD KeywordURIFixup(const PRUnichar* aStringURI, nsIURI** aURI); NS_IMETHOD GetCurrentDocumentOwner(nsISupports** aOwner); NS_IMETHOD DoURILoad(nsIURI* aURI, nsIURI* aReferrer, nsISupports *aOwner, - nsURILoadCommand aLoadCmd, const char* aWindowTarget, + PRBool inheritOwnerFromDocument, nsURILoadCommand aLoadCmd, const char* aWindowTarget, nsIInputStream* aPostData); NS_IMETHOD DoChannelLoad(nsIChannel* aChannel, nsURILoadCommand aLoadCmd, const char* aWindowTarget, nsIURILoader *aURILoader); diff --git a/mozilla/docshell/base/nsDocShellLoadInfo.cpp b/mozilla/docshell/base/nsDocShellLoadInfo.cpp index 139b2fecc9f..72b2a638946 100644 --- a/mozilla/docshell/base/nsDocShellLoadInfo.cpp +++ b/mozilla/docshell/base/nsDocShellLoadInfo.cpp @@ -30,7 +30,8 @@ nsDocShellLoadInfo::nsDocShellLoadInfo() { NS_INIT_REFCNT(); - mLoadType = nsIDocShellLoadInfo::loadNormal; + mLoadType = nsIDocShellLoadInfo::loadNormal; + mInheritOwner = PR_FALSE; } nsDocShellLoadInfo::~nsDocShellLoadInfo() @@ -83,6 +84,20 @@ NS_IMETHODIMP nsDocShellLoadInfo::SetOwner(nsISupports* aOwner) return NS_OK; } +NS_IMETHODIMP nsDocShellLoadInfo::GetInheritOwner(PRBool* aInheritOwner) +{ + NS_ENSURE_ARG_POINTER(aInheritOwner); + + *aInheritOwner = mInheritOwner; + return NS_OK; +} + +NS_IMETHODIMP nsDocShellLoadInfo::SetInheritOwner(PRBool aInheritOwner) +{ + mInheritOwner = aInheritOwner; + return NS_OK; +} + NS_IMETHODIMP nsDocShellLoadInfo::GetLoadType(nsDocShellInfoLoadType * aLoadType) { NS_ENSURE_ARG_POINTER(aLoadType); diff --git a/mozilla/docshell/base/nsDocShellLoadInfo.h b/mozilla/docshell/base/nsDocShellLoadInfo.h index 61e950a4a05..43a3b983a32 100644 --- a/mozilla/docshell/base/nsDocShellLoadInfo.h +++ b/mozilla/docshell/base/nsDocShellLoadInfo.h @@ -47,6 +47,7 @@ protected: protected: nsCOMPtr mReferrer; nsCOMPtr mOwner; + PRBool mInheritOwner; nsDocShellInfoLoadType mLoadType; nsCOMPtr mSHEntry; }; diff --git a/mozilla/docshell/base/nsIDocShellLoadInfo.idl b/mozilla/docshell/base/nsIDocShellLoadInfo.idl index 5e1f5d24eba..a05870aa402 100644 --- a/mozilla/docshell/base/nsIDocShellLoadInfo.idl +++ b/mozilla/docshell/base/nsIDocShellLoadInfo.idl @@ -47,6 +47,12 @@ interface nsIDocShellLoadInfo : nsISupports */ attribute nsISupports owner; + /* + If this attribute is true and no owner is specified, copy the owner from + the referring document. + */ + attribute boolean inheritOwner; + /* these are load type enums... */ const long loadNormal = 0; // Normal Load const long loadNormalReplace = 1; // Normal Load but replaces current history slot diff --git a/mozilla/docshell/base/nsWebShell.cpp b/mozilla/docshell/base/nsWebShell.cpp index 22fc65e3c03..b9f08cc70bc 100644 --- a/mozilla/docshell/base/nsWebShell.cpp +++ b/mozilla/docshell/base/nsWebShell.cpp @@ -831,12 +831,10 @@ nsWebShell::HandleLinkClickEvent(nsIContent *aContent, nsCOMPtr uri; NS_NewURI(getter_AddRefs(uri), nsLiteralString(aURLSpec), nsnull); - nsCOMPtr owner; - GetCurrentDocumentOwner(getter_AddRefs(owner)); #ifdef SH_IN_FRAMES - InternalLoad(uri, mCurrentURI, owner, target, aPostDataStream, nsIDocShellLoadInfo::loadLink, nsnull); + InternalLoad(uri, mCurrentURI, nsnull, PR_TRUE, target, aPostDataStream, nsIDocShellLoadInfo::loadLink, nsnull); #else - InternalLoad(uri, mCurrentURI, owner, target, aPostDataStream, nsIDocShellLoadInfo::loadLink); + InternalLoad(uri, mCurrentURI, nsnull, PR_TRUE, target, aPostDataStream, nsIDocShellLoadInfo::loadLink); #endif /* SH_IN_FRAMES */ } break; diff --git a/mozilla/dom/src/base/nsGlobalWindow.cpp b/mozilla/dom/src/base/nsGlobalWindow.cpp index e4b31b8bb55..68956e9864a 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.cpp +++ b/mozilla/dom/src/base/nsGlobalWindow.cpp @@ -2941,23 +2941,17 @@ NS_IMETHODIMP GlobalWindowImpl::OpenInternal(JSContext *cx, newDocShellItem->SetName(nameSpecified ? name.GetUnicode() : nsnull); nsCOMPtr newDocShell(do_QueryInterface(newDocShellItem)); - if (uriToLoad) { + if (uriToLoad) { // Get script principal and pass to docshell nsCOMPtr principal; if (NS_FAILED(secMan->GetSubjectPrincipal(getter_AddRefs(principal)))) return NS_ERROR_FAILURE; - nsCOMPtr codebase = do_QueryInterface(principal); nsCOMPtr loadInfo; - if (codebase) { + if (principal) { + nsCOMPtr owner = do_QueryInterface(principal); newDocShell->CreateLoadInfo(getter_AddRefs(loadInfo)); NS_ENSURE_TRUE(loadInfo, NS_ERROR_FAILURE); - - nsresult rv; - nsCOMPtr codebaseURI; - if (NS_FAILED(rv = codebase->GetURI(getter_AddRefs(codebaseURI)))) - return rv; - - loadInfo->SetReferrer(codebaseURI); + loadInfo->SetOwner(owner); } newDocShell->LoadURI(uriToLoad, loadInfo); } diff --git a/mozilla/dom/src/base/nsLocation.cpp b/mozilla/dom/src/base/nsLocation.cpp index 4398b86695f..f86b7af3ae7 100644 --- a/mozilla/dom/src/base/nsLocation.cpp +++ b/mozilla/dom/src/base/nsLocation.cpp @@ -131,9 +131,8 @@ LocationImpl::CheckURL(nsIURI* aURL, nsIDocShellLoadInfo** aLoadInfo) nsCOMPtr loadInfo; mDocShell->CreateLoadInfo(getter_AddRefs(loadInfo)); NS_ENSURE_TRUE(loadInfo, NS_ERROR_FAILURE); - - // Now get the principal and referrer to use when loading the URI + // Now get the principal to use when loading the URI nsCOMPtr principal; if (NS_FAILED(secMan->GetSubjectPrincipal(getter_AddRefs(principal))) || !principal) @@ -141,15 +140,6 @@ LocationImpl::CheckURL(nsIURI* aURL, nsIDocShellLoadInfo** aLoadInfo) nsCOMPtr owner = do_QueryInterface(principal); loadInfo->SetOwner(owner); - nsCOMPtr codebase = do_QueryInterface(principal); - if (codebase) - { - nsCOMPtr referrer; - if (NS_FAILED(result = codebase->GetURI(getter_AddRefs(referrer)))) - return result; - loadInfo->SetReferrer(referrer); - } - *aLoadInfo = loadInfo.get(); NS_ADDREF(*aLoadInfo); return NS_OK; diff --git a/mozilla/layout/generic/nsFrameFrame.cpp b/mozilla/layout/generic/nsFrameFrame.cpp index 28e7ca55486..b3140b9d41b 100644 --- a/mozilla/layout/generic/nsFrameFrame.cpp +++ b/mozilla/layout/generic/nsFrameFrame.cpp @@ -887,19 +887,32 @@ nsHTMLFrameInnerFrame::DoLoadURL(nsIPresContext* aPresContext) nsCOMPtr baseURI; rv = aPresContext->GetBaseURL(getter_AddRefs(baseURI)); - // Get origin URL (from script, or default to base) + // Get docshell and create load info + nsCOMPtr docShell(do_QueryInterface(mSubShell)); + NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE); + nsCOMPtr loadInfo; + docShell->CreateLoadInfo(getter_AddRefs(loadInfo)); + NS_ENSURE_TRUE(loadInfo, NS_ERROR_FAILURE); + + // Get referring URL nsCOMPtr referrer; nsCOMPtr principal; rv = secMan->GetSubjectPrincipal(getter_AddRefs(principal)); NS_ENSURE_SUCCESS(rv, rv); + // If we were called from script, get the referring URL from the script if (principal) { nsCOMPtr codebase = do_QueryInterface(principal); if (codebase) { rv = codebase->GetURI(getter_AddRefs(referrer)); NS_ENSURE_SUCCESS(rv, rv); } + // Pass the script principal to the docshell + nsCOMPtr owner = do_QueryInterface(principal); + loadInfo->SetOwner(owner); } - if (!referrer) { + if (!referrer) { // We're not being called form script, tell the docshell + // to inherit an owner from the current document. + loadInfo->SetInheritOwner(PR_TRUE); referrer = baseURI; } @@ -911,15 +924,6 @@ nsHTMLFrameInnerFrame::DoLoadURL(nsIPresContext* aPresContext) if (NS_FAILED(rv)) return rv; // We're not - nsCOMPtr docShell(do_QueryInterface(mSubShell)); - NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE); - - nsCOMPtr loadInfo; - docShell->CreateLoadInfo(getter_AddRefs(loadInfo)); - NS_ENSURE_TRUE(loadInfo, NS_ERROR_FAILURE); - - loadInfo->SetReferrer(referrer); - rv = docShell->LoadURI(uri, loadInfo); NS_ASSERTION(NS_SUCCEEDED(rv), "failed to load URL"); diff --git a/mozilla/layout/html/document/src/nsFrameFrame.cpp b/mozilla/layout/html/document/src/nsFrameFrame.cpp index 28e7ca55486..b3140b9d41b 100644 --- a/mozilla/layout/html/document/src/nsFrameFrame.cpp +++ b/mozilla/layout/html/document/src/nsFrameFrame.cpp @@ -887,19 +887,32 @@ nsHTMLFrameInnerFrame::DoLoadURL(nsIPresContext* aPresContext) nsCOMPtr baseURI; rv = aPresContext->GetBaseURL(getter_AddRefs(baseURI)); - // Get origin URL (from script, or default to base) + // Get docshell and create load info + nsCOMPtr docShell(do_QueryInterface(mSubShell)); + NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE); + nsCOMPtr loadInfo; + docShell->CreateLoadInfo(getter_AddRefs(loadInfo)); + NS_ENSURE_TRUE(loadInfo, NS_ERROR_FAILURE); + + // Get referring URL nsCOMPtr referrer; nsCOMPtr principal; rv = secMan->GetSubjectPrincipal(getter_AddRefs(principal)); NS_ENSURE_SUCCESS(rv, rv); + // If we were called from script, get the referring URL from the script if (principal) { nsCOMPtr codebase = do_QueryInterface(principal); if (codebase) { rv = codebase->GetURI(getter_AddRefs(referrer)); NS_ENSURE_SUCCESS(rv, rv); } + // Pass the script principal to the docshell + nsCOMPtr owner = do_QueryInterface(principal); + loadInfo->SetOwner(owner); } - if (!referrer) { + if (!referrer) { // We're not being called form script, tell the docshell + // to inherit an owner from the current document. + loadInfo->SetInheritOwner(PR_TRUE); referrer = baseURI; } @@ -911,15 +924,6 @@ nsHTMLFrameInnerFrame::DoLoadURL(nsIPresContext* aPresContext) if (NS_FAILED(rv)) return rv; // We're not - nsCOMPtr docShell(do_QueryInterface(mSubShell)); - NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE); - - nsCOMPtr loadInfo; - docShell->CreateLoadInfo(getter_AddRefs(loadInfo)); - NS_ENSURE_TRUE(loadInfo, NS_ERROR_FAILURE); - - loadInfo->SetReferrer(referrer); - rv = docShell->LoadURI(uri, loadInfo); NS_ASSERTION(NS_SUCCEEDED(rv), "failed to load URL");