diff --git a/xpfe/appshell/src/nsContentTreeOwner.cpp b/xpfe/appshell/src/nsContentTreeOwner.cpp index c8be88e16ae0..2c9925f9f5e1 100644 --- a/xpfe/appshell/src/nsContentTreeOwner.cpp +++ b/xpfe/appshell/src/nsContentTreeOwner.cpp @@ -38,6 +38,7 @@ #include "nsIEmbeddingSiteWindow2.h" #include "nsIPrompt.h" #include "nsIAuthPrompt.h" +#include "nsIWindowCreator2.h" #include "nsIWindowMediator.h" #include "nsIXULBrowserWindow.h" #include "nsPIDOMWindow.h" @@ -653,6 +654,11 @@ NS_IMETHODIMP nsContentTreeOwner::ApplyChromeFlags() the 'chromehidden' attribute of the tag. */ nsAutoString newvalue; + PRUint32 contextFlags; + mXULWindow->GetContextFlags(&contextFlags); + if (! (contextFlags & nsIWindowCreator2::PARENT_IS_LOADING_OR_RUNNING_TIMEOUT)) + newvalue.Append(NS_LITERAL_STRING("popupcontrol ")); + if (! (mChromeFlags & nsIWebBrowserChrome::CHROME_MENUBAR)) newvalue.Append(NS_LITERAL_STRING("menubar ")); diff --git a/xpfe/bootstrap/nsWindowCreator.cpp b/xpfe/bootstrap/nsWindowCreator.cpp index 7c0d9b725d4e..1a412478a309 100644 --- a/xpfe/bootstrap/nsWindowCreator.cpp +++ b/xpfe/bootstrap/nsWindowCreator.cpp @@ -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 parentURI; + + GetParentURI(aParent, getter_AddRefs(parentURI)); + if (aContextFlags & PARENT_IS_LOADING_OR_RUNNING_TIMEOUT) + allow = AllowWindowCreation(parentURI); + nsCOMPtr 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 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 thing(do_QueryInterface(newWindow)); - if (thing) - thing->GetInterface(NS_GET_IID(nsIWebBrowserChrome), (void **) _retval); + if (newWindow) { + newWindow->SetContextFlags(aContextFlags); + nsCOMPtr 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 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 treeOwner(do_GetInterface(aParent)); + if (treeOwner) { + nsCOMPtr content; + treeOwner->GetPrimaryContentShell(getter_AddRefs(content)); + nsCOMPtr domParent(do_GetInterface(content)); + if (domParent) { + nsCOMPtr location; + domParent->GetLocation(getter_AddRefs(location)); + if (location) { + nsAutoString url; + location->GetHref(url); + NS_NewURI(aURI, url); + } + } + } +} + diff --git a/xpfe/bootstrap/nsWindowCreator.h b/xpfe/bootstrap/nsWindowCreator.h index 524a6a3a0a1d..e9e03e5cd564 100644 --- a/xpfe/bootstrap/nsWindowCreator.h +++ b/xpfe/bootstrap/nsWindowCreator.h @@ -38,10 +38,12 @@ #ifndef __nsWindowCreator_h_ #define __nsWindowCreator_h_ -#include "nsIWindowCreator.h" +#include "nsIWindowCreator2.h" + +class nsIURI; class nsWindowCreator : - public nsIWindowCreator + public nsIWindowCreator2 { public: nsWindowCreator(); @@ -49,6 +51,11 @@ public: NS_DECL_ISUPPORTS NS_DECL_NSIWINDOWCREATOR + NS_DECL_NSIWINDOWCREATOR2 + +private: + PRUint32 AllowWindowCreation(nsIURI *aURI); + void GetParentURI(nsIWebBrowserChrome *aParent, nsIURI **aURI); }; #endif