Added code to create a new window for _blank, _new targets before URI loader tries to push content into it and fails. sr=mscott@netscape.com b=41241

This commit is contained in:
locka%iol.ie 2001-02-05 10:50:33 +00:00
parent 2170634159
commit 06506207df

View File

@ -61,6 +61,8 @@
#include "nsICodebasePrincipal.h"
#include "nsIHTMLDocument.h"
#include "nsIScriptGlobalObject.h"
static NS_DEFINE_CID(kURILoaderCID, NS_URI_LOADER_CID);
static NS_DEFINE_CID(kStreamConverterServiceCID, NS_STREAMCONVERTERSERVICE_CID);
@ -667,12 +669,57 @@ NS_IMETHODIMP nsURILoader::GetTarget(nsIChannel * aChannel, nsCString &aWindowTa
nsCOMPtr<nsIDocShellTreeItem> treeItem;
*aRetargetedWindowContext = nsnull;
if(!name.Length() || name.EqualsIgnoreCase("_self") ||
name.EqualsIgnoreCase("_blank") ||
name.EqualsIgnoreCase("_new"))
if(!name.Length() || name.EqualsIgnoreCase("_self"))
{
*aRetargetedWindowContext = aWindowContext;
}
else if (name.EqualsIgnoreCase("_blank") || name.EqualsIgnoreCase("_new"))
{
nsCOMPtr<nsIDOMWindowInternal> parentWindow;
JSContext* jsContext = nsnull;
if (aWindowContext)
{
parentWindow = do_GetInterface(aWindowContext);
if (parentWindow)
{
nsCOMPtr<nsIScriptGlobalObject> sgo;
sgo = do_QueryInterface( parentWindow );
if (sgo)
{
nsCOMPtr<nsIScriptContext> scriptContext;
sgo->GetContext( getter_AddRefs( scriptContext ) );
if (scriptContext)
jsContext = (JSContext*)scriptContext->GetNativeContext();
}
}
}
if (!parentWindow || !jsContext)
{
return NS_ERROR_FAILURE;
}
// Create a new window (context) so that the uri loader has a proper
// target to push the content into.
void* mark;
jsval* argv;
nsAutoString uriValue; // Empty
argv = JS_PushArguments(jsContext, &mark, "Ws", uriValue.GetUnicode(), "");
NS_ENSURE_TRUE(argv, NS_ERROR_FAILURE);
nsCOMPtr<nsIDOMWindowInternal> newWindow;
parentWindow->Open(jsContext, argv, 2, getter_AddRefs(newWindow));
JS_PopArguments(jsContext, mark);
nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(newWindow);
nsIDocShell *docShell = nsnull;
sgo->GetDocShell(&docShell);
*aRetargetedWindowContext = (nsISupports *) docShell;
aWindowTarget.Assign("");
}
else if(name.EqualsIgnoreCase("_parent"))
{
windowCtxtAsTreeItem->GetSameTypeParent(getter_AddRefs(treeItem));