reinstating earlier version; Txul regression in hand. long live bug 166442 r=jag,jst,et al. still applies

git-svn-id: svn://10.0.0.236/trunk@129624 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
danm%netscape.com
2002-09-14 19:44:29 +00:00
parent 687461e0ac
commit f832d33f47
8 changed files with 332 additions and 40 deletions

View File

@@ -66,21 +66,30 @@
#include "nsCOMPtr.h"
#include "nsAppShellCIDs.h"
#include "nsNetUtil.h"
#include "nsString.h"
#include "nsWidgetsCID.h"
#include "nsWindowCreator.h"
#include "nsIAppShell.h"
#include "nsIAppShellService.h"
#include "nsIDocShellTreeItem.h"
#include "nsIDocShellTreeOwner.h"
#include "nsIDOMLocation.h"
#include "nsIDOMWindowInternal.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIJSContextStack.h"
#include "nsIPopupWindowManager.h"
#include "nsIPref.h"
#include "nsIServiceManager.h"
#include "nsIURI.h"
#include "nsIXULWindow.h"
#include "nsIWebBrowserChrome.h"
static NS_DEFINE_CID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID);
static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
nsWindowCreator::nsWindowCreator() {
NS_INIT_ISUPPORTS();
@@ -89,21 +98,44 @@ nsWindowCreator::nsWindowCreator() {
nsWindowCreator::~nsWindowCreator() {
}
NS_IMPL_ISUPPORTS1(nsWindowCreator, nsIWindowCreator)
NS_IMPL_ISUPPORTS2(nsWindowCreator, nsIWindowCreator, nsIWindowCreator2)
NS_IMETHODIMP
nsWindowCreator::CreateChromeWindow(nsIWebBrowserChrome *aParent,
PRUint32 aChromeFlags,
nsIWebBrowserChrome **_retval)
{
return CreateChromeWindow2(aParent, aChromeFlags, 0, _retval);
}
NS_IMETHODIMP
nsWindowCreator::CreateChromeWindow2(nsIWebBrowserChrome *aParent,
PRUint32 aChromeFlags,
PRUint32 aContextFlags,
nsIWebBrowserChrome **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
*_retval = 0;
PRUint32 allow = nsIPopupWindowManager::eAllow;
nsCOMPtr<nsIURI> parentURI;
GetParentURI(aParent, getter_AddRefs(parentURI));
if (aContextFlags & PARENT_IS_LOADING_OR_RUNNING_TIMEOUT)
allow = AllowWindowCreation(parentURI);
nsCOMPtr<nsIXULWindow> newWindow;
if (aParent) {
if (allow == nsIPopupWindowManager::eDisallow)
return NS_OK; // ruse to not give scripts a catchable error
if (allow == nsIPopupWindowManager::eAllow &&
(aContextFlags & PARENT_IS_LOADING_OR_RUNNING_TIMEOUT))
aContextFlags &= ~PARENT_IS_LOADING_OR_RUNNING_TIMEOUT;
nsCOMPtr<nsIXULWindow> xulParent(do_GetInterface(aParent));
NS_ASSERTION(xulParent, "window created using non-XUL parent. that's unexpected, but may work.");
if (xulParent)
xulParent->CreateNewWindow(aChromeFlags, getter_AddRefs(newWindow));
// And if it fails, don't try again without a parent. It could fail
@@ -125,10 +157,49 @@ nsWindowCreator::CreateChromeWindow(nsIWebBrowserChrome *aParent,
}
// if anybody gave us anything to work with, use it
nsCOMPtr<nsIInterfaceRequestor> thing(do_QueryInterface(newWindow));
if (thing)
thing->GetInterface(NS_GET_IID(nsIWebBrowserChrome), (void **) _retval);
if (newWindow) {
newWindow->SetContextFlags(aContextFlags);
nsCOMPtr<nsIInterfaceRequestor> thing(do_QueryInterface(newWindow));
if (thing)
thing->GetInterface(NS_GET_IID(nsIWebBrowserChrome), (void **) _retval);
}
return *_retval ? NS_OK : NS_ERROR_FAILURE;
}
PRUint32
nsWindowCreator::AllowWindowCreation(nsIURI *aURI)
{
nsCOMPtr<nsIPopupWindowManager> pm(do_GetService(NS_POPUPWINDOWMANAGER_CONTRACTID));
if (!pm)
return nsIPopupWindowManager::eAllow;
PRUint32 permission;
if (NS_SUCCEEDED(pm->TestPermission(aURI, &permission)))
return permission;
return nsIPopupWindowManager::eAllow;
}
void
nsWindowCreator::GetParentURI(nsIWebBrowserChrome *aParent, nsIURI **aURI)
{
if (!aParent)
return;
nsCOMPtr<nsIDocShellTreeOwner> treeOwner(do_GetInterface(aParent));
if (treeOwner) {
nsCOMPtr<nsIDocShellTreeItem> content;
treeOwner->GetPrimaryContentShell(getter_AddRefs(content));
nsCOMPtr<nsIDOMWindowInternal> domParent(do_GetInterface(content));
if (domParent) {
nsCOMPtr<nsIDOMLocation> location;
domParent->GetLocation(getter_AddRefs(location));
if (location) {
nsAutoString url;
location->GetHref(url);
NS_NewURI(aURI, url);
}
}
}
}