From 090ca37720121aa2aa8d3f07deb15dab7f533d0c Mon Sep 17 00:00:00 2001 From: "mscott%netscape.com" Date: Wed, 12 Jul 2000 05:06:28 +0000 Subject: [PATCH] Fix for Bug #41707 --> JS and data urls were not getting an owner set on them when they were entered from the urlbar. this prevented them from getting executed properly. For now, we'll inherit the owner of the current document in these two cases. r=mstoltz git-svn-id: svn://10.0.0.236/trunk@74090 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/docshell/base/nsDocShell.cpp | 45 +++++++++++++++++----------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index dac656bc0cd..885a9214c59 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -2898,23 +2898,34 @@ NS_IMETHODIMP nsDocShell::DoURILoad(nsIURI* aURI, nsIURI* aReferrerURI, } else { - 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) - channel->SetOwner(aOwner); - if (scheme) - nsCRT::free(scheme); - } - else - { // Also set owner for data: URLs - nsCOMPtr dataChannel(do_QueryInterface(channel)); - if (dataChannel) - channel->SetOwner(aOwner); - } + // 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)); + 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);