Fix for bug 31818. Dogfood. r=brendan

This commit is contained in:
mstoltz%netscape.com 2000-06-13 23:56:30 +00:00
Родитель 7cca6b9a06
Коммит a62193e278
8 изменённых файлов: 102 добавлений и 51 удалений

Просмотреть файл

@ -55,6 +55,7 @@
// Interfaces Needed
#include "nsICharsetConverterManager.h"
#include "nsIHTTPChannel.h"
#include "nsIDataChannel.h"
#include "nsIProgressEventSink.h"
#include "nsILayoutHistoryState.h"
#include "nsILocaleService.h"
@ -62,6 +63,8 @@
#include "nsITimer.h"
#include "nsIFileStream.h"
#include "nsIPrincipal.h"
// For reporting errors with the console service.
// These can go away if error reporting is propagated up past nsDocShell.
#include "nsIConsoleService.h"
@ -204,6 +207,7 @@ NS_IMETHODIMP nsDocShell::LoadURI(nsIURI* aURI, nsIDocShellLoadInfo* aLoadInfo)
NS_ENSURE_ARG(aURI);
nsCOMPtr<nsIURI> referrer;
nsCOMPtr<nsISupports> owner;
PRBool replace = PR_FALSE;
PRBool refresh = PR_FALSE;
if(aLoadInfo)
@ -211,10 +215,10 @@ NS_IMETHODIMP nsDocShell::LoadURI(nsIURI* aURI, nsIDocShellLoadInfo* aLoadInfo)
aLoadInfo->GetReferrer(getter_AddRefs(referrer));
aLoadInfo->GetReplaceSessionHistorySlot(&replace);
aLoadInfo->GetRefresh(&refresh);
aLoadInfo->GetOwner(getter_AddRefs(owner));
}
NS_ENSURE_SUCCESS(InternalLoad(aURI, referrer, nsnull, nsnull,
NS_ENSURE_SUCCESS(InternalLoad(aURI, referrer, owner, nsnull, nsnull,
replace ? loadNormalReplace : (refresh ? loadRefresh : loadNormal)), NS_ERROR_FAILURE);
return NS_OK;
@ -1090,7 +1094,7 @@ NS_IMETHODIMP nsDocShell::Reload(PRInt32 aReloadType)
type = loadReloadBypassProxyAndCache;
NS_ENSURE_SUCCESS(InternalLoad(mCurrentURI, mReferrerURI, nsnull, nsnull,
type), NS_ERROR_FAILURE);
nsnull, type), NS_ERROR_FAILURE);
return NS_OK;
}
@ -2358,7 +2362,8 @@ NS_IMETHODIMP nsDocShell::SetupNewViewer(nsIContentViewer* aNewViewer)
//*****************************************************************************
NS_IMETHODIMP nsDocShell::InternalLoad(nsIURI* aURI, nsIURI* aReferrer,
const char* aWindowTarget, nsIInputStream* aPostData, loadType aLoadType)
nsISupports* aOwner, const char* aWindowTarget, nsIInputStream* aPostData,
loadType aLoadType)
{
// Check to see if the new URI is an anchor in the existing document.
if (aLoadType == loadNormal ||
@ -2385,7 +2390,7 @@ NS_IMETHODIMP nsDocShell::InternalLoad(nsIURI* aURI, nsIURI* aReferrer,
nsURILoadCommand loadCmd = nsIURILoader::viewNormal;
if(loadLink == aLoadType)
loadCmd = nsIURILoader::viewUserClick;
NS_ENSURE_SUCCESS(DoURILoad(aURI, aReferrer, loadCmd, aWindowTarget,
NS_ENSURE_SUCCESS(DoURILoad(aURI, aReferrer, aOwner, loadCmd, aWindowTarget,
aPostData), NS_ERROR_FAILURE);
return NS_OK;
@ -2597,8 +2602,24 @@ NS_IMETHODIMP nsDocShell::KeywordURIFixup(const PRUnichar* aStringURI,
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsDocShell::DoURILoad(nsIURI* aURI, nsIURI* aReferrerURI,
nsURILoadCommand aLoadCmd, const char* aWindowTarget,
NS_IMETHODIMP nsDocShell::GetCurrentDocumentOwner(nsISupports** aOwner)
{
nsresult rv;
*aOwner = nsnull;
nsCOMPtr<nsIDocumentViewer> docv(do_QueryInterface(mContentViewer));
if (!docv) return NS_ERROR_FAILURE;
nsCOMPtr<nsIDocument> doc;
rv = docv->GetDocument(*getter_AddRefs(doc));
if (NS_FAILED(rv) || !doc) return NS_ERROR_FAILURE;
nsCOMPtr<nsIPrincipal> principal;
rv = doc->GetPrincipal(getter_AddRefs(principal));
if (NS_FAILED(rv) || !principal) return NS_ERROR_FAILURE;
rv = principal->QueryInterface(NS_GET_IID(nsISupports),(void**)aOwner);
return rv;
}
NS_IMETHODIMP nsDocShell::DoURILoad(nsIURI* aURI, nsIURI* aReferrerURI,
nsISupports* aOwner, nsURILoadCommand aLoadCmd, const char* aWindowTarget,
nsIInputStream* aPostData)
{
nsCOMPtr<nsIURILoader> uriLoader(do_GetService(NS_URI_LOADER_PROGID));
@ -2622,17 +2643,7 @@ NS_IMETHODIMP nsDocShell::DoURILoad(nsIURI* aURI, nsIURI* aReferrerURI,
else
return NS_ERROR_FAILURE;
}
//XXX Wrong, but needed for now. See bug 31818.
static const char kJavaScriptScheme[] = "javascript";
nsXPIDLCString scheme;
aURI->GetScheme(getter_Copies(scheme));
if (0 == PL_strncasecmp(NS_STATIC_CAST(const char*, scheme), kJavaScriptScheme, sizeof(kJavaScriptScheme) - 1)) {
channel->SetOriginalURI(aReferrerURI ? aReferrerURI : aURI);
}
else {
channel->SetOriginalURI(aURI);
}
channel->SetOriginalURI(aURI);
// Mark the channel as being a document URI...
nsLoadFlags loadAttribs = 0;
@ -2706,6 +2717,24 @@ NS_IMETHODIMP nsDocShell::DoURILoad(nsIURI* aURI, nsIURI* aReferrerURI,
httpChannel->SetReferrer(aReferrerURI,
nsIHTTPChannel::REFERRER_LINK_CLICK);
}
else
{
nsCOMPtr<nsIStreamIOChannel> 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)
channel->SetOwner(aOwner);
}
else
{ // Also set owner for data: URLs
nsCOMPtr<nsIDataChannel> dataChannel(do_QueryInterface(channel));
if (dataChannel)
channel->SetOwner(aOwner);
}
}
NS_ENSURE_SUCCESS(uriLoader->OpenURI(channel, aLoadCmd,
aWindowTarget, NS_STATIC_CAST(nsIDocShell*, this)), NS_ERROR_FAILURE);
@ -3143,7 +3172,7 @@ NS_IMETHODIMP nsDocShell::LoadHistoryEntry(nsISHEntry* aEntry)
}
NS_ENSURE_SUCCESS(InternalLoad(uri, nsnull, nsnull, postData, loadHistory),
NS_ENSURE_SUCCESS(InternalLoad(uri, nsnull, nsnull, nsnull, postData, loadHistory),
NS_ERROR_FAILURE);
return NS_OK;

Просмотреть файл

@ -184,15 +184,16 @@ protected:
loadRefresh
} loadType;
NS_IMETHOD InternalLoad(nsIURI* aURI, nsIURI* aReferrerURI,
const char* aWindowTarget=nsnull, nsIInputStream* aPostData=nsnull,
loadType aLoadType=loadNormal);
NS_IMETHOD InternalLoad(nsIURI* aURI, nsIURI* aReferrerURI,
nsISupports* owner, const char* aWindowTarget=nsnull,
nsIInputStream* aPostData=nsnull, loadType aLoadType=loadNormal);
NS_IMETHOD CreateFixupURI(const PRUnichar* aStringURI, nsIURI** aURI);
NS_IMETHOD FileURIFixup(const PRUnichar* aStringURI, nsIURI** aURI);
NS_IMETHOD ConvertFileToStringURI(nsString& aIn, nsString& aOut);
NS_IMETHOD ConvertStringURIToFileCharset(nsString& aIn, nsCString& aOut);
NS_IMETHOD KeywordURIFixup(const PRUnichar* aStringURI, nsIURI** aURI);
NS_IMETHOD DoURILoad(nsIURI* aURI, nsIURI* aReferrer,
NS_IMETHOD GetCurrentDocumentOwner(nsISupports** aOwner);
NS_IMETHOD DoURILoad(nsIURI* aURI, nsIURI* aReferrer, nsISupports *aOwner,
nsURILoadCommand aLoadCmd, const char* aWindowTarget,
nsIInputStream* aPostData);
NS_IMETHOD StopCurrentLoads();

Просмотреть файл

@ -96,6 +96,21 @@ NS_IMETHODIMP nsDocShellLoadInfo::SetRefresh(PRBool aRefresh)
return NS_OK;
}
NS_IMETHODIMP nsDocShellLoadInfo::GetOwner(nsISupports** aOwner)
{
NS_ENSURE_ARG_POINTER(aOwner);
*aOwner = mOwner;
NS_IF_ADDREF(*aOwner);
return NS_OK;
}
NS_IMETHODIMP nsDocShellLoadInfo::SetOwner(nsISupports* aOwner)
{
mOwner = aOwner;
return NS_OK;
}
//*****************************************************************************
// nsDocShellLoadInfo: Helpers
//*****************************************************************************

Просмотреть файл

@ -47,6 +47,7 @@ protected:
nsCOMPtr<nsIURI> mReferrer;
PRBool mReplaceSessionHistorySlot;
PRBool mRefresh;
nsCOMPtr<nsISupports> mOwner;
};
#endif /* nsDocShellLoadInfo_h__ */

Просмотреть файл

@ -49,4 +49,10 @@ interface nsIDocShellLoadInfo : nsISupports
directive
*/
attribute boolean refresh;
};
/*
The owner of the load, that is, the entity responsible for
causing the load to occur. This should be a nsIPrincipal typically.
*/
attribute nsISupports owner;
};

Просмотреть файл

@ -1019,7 +1019,10 @@ nsWebShell::HandleLinkClickEvent(nsIContent *aContent,
nsCOMPtr<nsIURI> uri;
NS_NewURI(getter_AddRefs(uri), aURLSpec, nsnull);
InternalLoad(uri, mCurrentURI, target, aPostDataStream, loadLink);
nsCOMPtr<nsISupports> owner;
GetCurrentDocumentOwner(getter_AddRefs(owner));
InternalLoad(uri, mCurrentURI, owner, target, aPostDataStream, loadLink);
}
break;
case eLinkVerb_Embed:

Просмотреть файл

@ -115,33 +115,26 @@ nsEvaluateStringProxy::EvaluateString(char **aRetValue, PRBool *aIsUndefined)
if (NS_FAILED(rv)) return rv;
// Get principal of code for execution
NS_WITH_SERVICE(nsIScriptSecurityManager, securityManager,
NS_SCRIPTSECURITYMANAGER_PROGID, &rv);
if (NS_FAILED(rv)) return rv;
// Get principal
nsCOMPtr<nsISupports> owner;
rv = mChannel->GetOwner(getter_AddRefs(owner));
nsCOMPtr<nsIPrincipal> principal;
nsCOMPtr<nsIURI> referringUri;
// XXX this is wrong: see bugs 31818 and 29831. Norris is looking at it.
rv = mChannel->GetOriginalURI(getter_AddRefs(referringUri));
if (NS_FAILED(rv)) {
// No referrer available. Use the current javascript: URI, which will mean
// that this script will be in another trust domain than any other script
// since SameOrigin should be false for anything other than the same
// javascript: URI.
#if 0
nsCOMPtr<nsIDocShell> docShell;
docShell = do_QueryInterface(globalOwner, &rv);
if (NS_FAILED(rv)) return rv;
rv = docShell->GetCurrentURI(getter_AddRefs(referringUri));
#else
rv = mChannel->GetURI(getter_AddRefs(referringUri));
#endif
if (NS_FAILED(rv)) return rv;
if (owner)
{
principal = do_QueryInterface(owner, &rv);
NS_ASSERTION(principal, "Channel's owner is not a principal");
if (!principal) return NS_ERROR_FAILURE;
}
else // No owner from channel, use the current URI to generate a principal
{
nsCOMPtr<nsIURI> uri;
rv = mChannel->GetURI(getter_AddRefs(uri));
if (NS_FAILED(rv) || !uri) return NS_ERROR_FAILURE;
NS_WITH_SERVICE(nsIScriptSecurityManager, securityManager,
NS_SCRIPTSECURITYMANAGER_PROGID, &rv);
if (NS_FAILED(rv)) return rv;
rv =securityManager->GetCodebasePrincipal(uri, getter_AddRefs(principal));
if (NS_FAILED(rv) || !principal) return NS_ERROR_FAILURE;
}
rv = securityManager->GetCodebasePrincipal(referringUri,
getter_AddRefs(principal));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIURI> jsURI;
rv = mChannel->GetURI(getter_AddRefs(jsURI));

Просмотреть файл

@ -1019,7 +1019,10 @@ nsWebShell::HandleLinkClickEvent(nsIContent *aContent,
nsCOMPtr<nsIURI> uri;
NS_NewURI(getter_AddRefs(uri), aURLSpec, nsnull);
InternalLoad(uri, mCurrentURI, target, aPostDataStream, loadLink);
nsCOMPtr<nsISupports> owner;
GetCurrentDocumentOwner(getter_AddRefs(owner));
InternalLoad(uri, mCurrentURI, owner, target, aPostDataStream, loadLink);
}
break;
case eLinkVerb_Embed: