hooking up popup window management. bug 166442 r=jag,jst,timeless

This commit is contained in:
danm%netscape.com 2002-09-11 02:29:27 +00:00
Родитель 1e98ed5c4a
Коммит c38c9628a2
3 изменённых файлов: 90 добавлений и 6 удалений

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

@ -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 <window> 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 "));

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

@ -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);
}
}
}
}

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

@ -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