GlobalWindow now calls up nsIDocShellTreeOwner rather than nsIBrowserWindow. GlobalWindow has mostly been re-organized as well as cleaned up to provide this new functionality. DocShellTreeOwners got implementations filled in and many bugs fixed. nsIScriptGlobalObject now talks in terms of docShells instead of webShells. Fixed a number of cases where people were walking through content viewers etc to get to a presShell and changed them to simply ask for the presShell from the docShell. GlobalWindow now deals completely in terms of docShells. r=vidur

This commit is contained in:
tbogard%aol.net 2000-02-08 13:40:10 +00:00
Родитель aa15488556
Коммит 840c8350e1
43 изменённых файлов: 5029 добавлений и 4753 удалений

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

@ -777,9 +777,9 @@ NS_IMETHODIMP nsHTMLDocument::SetTitle(const nsString& aTitle)
nsCOMPtr<nsISupports> container;
if (NS_OK == cx->GetContainer(getter_AddRefs(container))) {
if (container) {
nsCOMPtr<nsIBaseWindow> webShell(do_QueryInterface(container));
if(webShell) {
webShell->SetTitle(aTitle.GetUnicode());
nsCOMPtr<nsIBaseWindow> docShell(do_QueryInterface(container));
if(docShell) {
docShell->SetTitle(aTitle.GetUnicode());
}
}
}

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

@ -82,8 +82,8 @@ public:
NS_IMETHOD SetContext(nsIScriptContext *aContext);
NS_IMETHOD GetContext(nsIScriptContext **aContext);
NS_IMETHOD SetNewDocument(nsIDOMDocument *aDocument);
NS_IMETHOD SetWebShell(nsIWebShell *aWebShell);
NS_IMETHOD GetWebShell(nsIWebShell **aWebShell);
NS_IMETHOD SetDocShell(nsIDocShell *aDocShell);
NS_IMETHOD GetDocShell(nsIDocShell **aDocShell);
NS_IMETHOD SetOpenerWindow(nsIDOMWindow *aOpener);
NS_IMETHOD SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner);
NS_IMETHOD GetGlobalObjectOwner(nsIScriptGlobalObjectOwner** aOwner);
@ -418,7 +418,7 @@ nsXULPrototypeDocument::SetNewDocument(nsIDOMDocument *aDocument)
NS_IMETHODIMP
nsXULPrototypeDocument::SetWebShell(nsIWebShell *aWebShell)
nsXULPrototypeDocument::SetDocShell(nsIDocShell *aDocShell)
{
NS_NOTREACHED("waaah!");
return NS_ERROR_UNEXPECTED;
@ -426,7 +426,7 @@ nsXULPrototypeDocument::SetWebShell(nsIWebShell *aWebShell)
NS_IMETHODIMP
nsXULPrototypeDocument::GetWebShell(nsIWebShell **aWebShell)
nsXULPrototypeDocument::GetDocShell(nsIDocShell **aDocShell)
{
NS_NOTREACHED("waaah!");
return NS_ERROR_UNEXPECTED;

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

@ -122,6 +122,34 @@ NS_INTERFACE_MAP_BEGIN(nsDocShell)
NS_INTERFACE_MAP_ENTRY(nsIScriptGlobalObjectOwner)
NS_INTERFACE_MAP_END
///*****************************************************************************
// nsDocShell::nsIInterfaceRequestor
//*****************************************************************************
NS_IMETHODIMP nsDocShell::GetInterface(const nsIID& aIID, void** aSink)
{
NS_ENSURE_ARG_POINTER(aSink);
if(aIID.Equals(NS_GET_IID(nsIURIContentListener)) &&
NS_SUCCEEDED(EnsureContentListener()))
*aSink = mContentListener;
else if(aIID.Equals(NS_GET_IID(nsIScriptGlobalObject)) &&
NS_SUCCEEDED(EnsureScriptEnvironment()))
*aSink = mScriptGlobal;
else if(aIID.Equals(NS_GET_IID(nsIDOMWindow)) &&
NS_SUCCEEDED(EnsureScriptEnvironment()))
{
NS_ENSURE_SUCCESS(mScriptGlobal->QueryInterface(NS_GET_IID(nsIDOMWindow),
aSink), NS_ERROR_FAILURE);
return NS_OK;
}
else
return QueryInterface(aIID, aSink);
NS_IF_ADDREF(((nsISupports*)*aSink));
return NS_OK;
}
//*****************************************************************************
// nsDocShell::nsIDocShell
//*****************************************************************************
@ -320,10 +348,13 @@ NS_IMETHODIMP nsDocShell::GetPresContext(nsIPresContext** aPresContext)
NS_IMETHODIMP nsDocShell::GetPresShell(nsIPresShell** aPresShell)
{
NS_ENSURE_ARG_POINTER(aPresShell);
*aPresShell = nsnull;
nsCOMPtr<nsIPresContext> presContext;
NS_ENSURE_SUCCESS(GetPresContext(getter_AddRefs(presContext)),
NS_ERROR_FAILURE);
if(!presContext)
return NS_OK;
NS_ENSURE_SUCCESS(presContext->GetShell(aPresShell), NS_ERROR_FAILURE);
@ -923,25 +954,31 @@ NS_IMETHODIMP nsDocShell::SetPositionAndSize(PRInt32 x, PRInt32 y, PRInt32 cx,
NS_IMETHODIMP nsDocShell::GetPositionAndSize(PRInt32* x, PRInt32* y, PRInt32* cx,
PRInt32* cy)
{
NS_ENSURE_ARG_POINTER(x && y && cx && cy);
if(mContentViewer)
{
nsRect bounds;
NS_ENSURE_SUCCESS(mContentViewer->GetBounds(bounds), NS_ERROR_FAILURE);
*x = bounds.x;
*y = bounds.y;
*cx = bounds.width;
*cy = bounds.height;
if(x)
*x = bounds.x;
if(y)
*y = bounds.y;
if(cx)
*cx = bounds.width;
if(cy)
*cy = bounds.height;
}
else if(InitInfo())
{
*x = mInitInfo->x;
*y = mInitInfo->y;
*cx = mInitInfo->cx;
*cy = mInitInfo->cy;
if(x)
*x = mInitInfo->x;
if(y)
*y = mInitInfo->y;
if(cx)
*cx = mInitInfo->cx;
if(cy)
*cy = mInitInfo->cy;
}
else
NS_ENSURE_TRUE(PR_FALSE, NS_ERROR_FAILURE);
@ -1399,34 +1436,6 @@ NS_IMETHODIMP nsDocShell::ScrollByPages(PRInt32 numPages)
return NS_OK;
}
///*****************************************************************************
// nsDocShell::nsIInterfaceRequestor
//*****************************************************************************
NS_IMETHODIMP nsDocShell::GetInterface(const nsIID& aIID, void** aSink)
{
NS_ENSURE_ARG_POINTER(aSink);
if(aIID.Equals(NS_GET_IID(nsIURIContentListener)) &&
NS_SUCCEEDED(EnsureContentListener()))
*aSink = mContentListener;
else if(aIID.Equals(NS_GET_IID(nsIScriptGlobalObject)) &&
NS_SUCCEEDED(EnsureScriptEnvironment()))
*aSink = mScriptGlobal;
else if(aIID.Equals(NS_GET_IID(nsIDOMWindow)) &&
NS_SUCCEEDED(EnsureScriptEnvironment()))
{
NS_ENSURE_SUCCESS(mScriptGlobal->QueryInterface(NS_GET_IID(nsIDOMWindow),
aSink), NS_ERROR_FAILURE);
return NS_OK;
}
else
return QueryInterface(aIID, aSink);
NS_IF_ADDREF(((nsISupports*)*aSink));
return NS_OK;
}
//*****************************************************************************
// nsDocShell::nsIScriptGlobalObjectOwner
//*****************************************************************************
@ -1653,8 +1662,7 @@ NS_IMETHODIMP nsDocShell::EnsureScriptEnvironment()
NS_ENSURE_SUCCESS(NS_NewScriptGlobalObject(getter_AddRefs(scriptGlobalObject)),
NS_ERROR_FAILURE);
//XXXWEBSHELL
//mScriptGlobal->SetDocShell(NS_STATIC_CAST(nsIDocShell*, this));
mScriptGlobal->SetDocShell(NS_STATIC_CAST(nsIDocShell*, this));
mScriptGlobal->SetGlobalObjectOwner(
NS_STATIC_CAST(nsIScriptGlobalObjectOwner*, this));

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

@ -72,14 +72,12 @@ interface nsIDocShellTreeOwner : nsISupports
void showModal();
/*
Tells the implementer of this interface to create a new webBrowserChrome
object for it. Typically this means the implemetor will create a new
top level window that is represented by nsIWebBrowserChrome. This
most often will be called when for instance there is a need for a new
JS window, etc. Soon after this new object is returned, the webBrowser
attribute will checked, if one does not exist, one will be created and
setWebBrowser will be called with the new widget to instantiate in this
new window.
Tells the implementer of this interface to create a new window. This is
a new logical window. Meaning in some implementations the result may not
be an actual new window, but rather a new tab or view in an existing
window. What is returned is the new DocShellTreeItem from which the
internals can operate on. This most often will be called when there is
a need for a new JS window, etc.
*/
void getNewBrowserChrome(in long aChromeFlags, out nsIWebBrowserChrome webBrowserChrome);
nsIDocShellTreeItem getNewWindow(in long aChromeFlags);
};

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

@ -84,6 +84,7 @@
#include "nsIDocShellTreeNode.h"
#include "nsIDocShellTreeOwner.h"
#include "nsCURILoader.h"
#include "nsIDOMWindow.h"
#include "nsIHTTPChannel.h" // add this to the ick include list...we need it to QI for post data interface
#include "nsHTTPEnums.h"
@ -631,7 +632,7 @@ nsWebShell::~nsWebShell()
NS_IF_RELEASE(mContainer);
if (nsnull != mScriptGlobal) {
mScriptGlobal->SetWebShell(nsnull);
mScriptGlobal->SetDocShell(nsnull);
NS_RELEASE(mScriptGlobal);
}
if (nsnull != mScriptContext) {
@ -767,6 +768,13 @@ nsWebShell::GetInterface(const nsIID &aIID, void** aInstancePtr)
NS_ADDREF((nsISupports*)*aInstancePtr);
return NS_OK;
}
else if(aIID.Equals(NS_GET_IID(nsIDOMWindow)))
{
NS_ENSURE_SUCCESS(CreateScriptEnvironment(), NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(mScriptGlobal->QueryInterface(NS_GET_IID(nsIDOMWindow),
aInstancePtr), NS_ERROR_FAILURE);
return NS_OK;
}
else if(mPluginManager) //XXX this seems a little wrong. MMP
rv = mPluginManager->QueryInterface(aIID, aInstancePtr);
@ -3040,7 +3048,7 @@ nsWebShell::CreateScriptEnvironment()
if (NS_FAILED(res)) {
return res;
}
mScriptGlobal->SetWebShell(this);
mScriptGlobal->SetDocShell(this);
mScriptGlobal->SetGlobalObjectOwner(
NS_STATIC_CAST(nsIScriptGlobalObjectOwner*, this));
}
@ -3964,10 +3972,14 @@ NS_IMETHODIMP nsWebShell::GetPositionAndSize(PRInt32* aX, PRInt32* aY,
else
result = mBounds;
*aX = result.x;
*aY = result.y;
*aCX = result.width;
*aCY = result.height;
if(aX)
*aX = result.x;
if(aY)
*aY = result.y;
if(aCX)
*aCX = result.width;
if(aCY)
*aCY = result.height;
return NS_OK;
}

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

@ -29,7 +29,7 @@
#include "nsIScriptContext.h"
#include "nsIDOMLocation.h"
class nsIWebShell;
class nsIDocShell;
#define NS_PIDOMWINDOW_IID \
{ 0x3aa80781, 0x7e6a, 0x11d3, { 0xbf, 0x87, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } }
@ -42,7 +42,7 @@ public:
NS_IMETHOD GetPrivateParent(nsPIDOMWindow** aResult)=0;
NS_IMETHOD GetLocation(nsIDOMLocation** aLocation) = 0;
NS_IMETHOD GetWebShell(nsIWebShell **aWebShell) =0;// XXX This may be temporary - rods
NS_IMETHOD GetDocShell(nsIDocShell **aDocShell) =0;// XXX This may be temporary - rods
// This is private because activate/deactivate events are not part of the DOM spec.
NS_IMETHOD Activate() = 0;

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

@ -31,7 +31,7 @@ class nsIScriptContext;
class nsIDOMDocument;
class nsIDOMEvent;
class nsIPresContext;
class nsIWebShell;
class nsIDocShell;
class nsIDOMWindow;
class nsIScriptGlobalObjectOwner;
@ -51,8 +51,8 @@ public:
NS_IMETHOD SetContext(nsIScriptContext *aContext)=0;
NS_IMETHOD GetContext(nsIScriptContext **aContext)=0;
NS_IMETHOD SetNewDocument(nsIDOMDocument *aDocument)=0;
NS_IMETHOD SetWebShell(nsIWebShell *aWebShell)=0;
NS_IMETHOD GetWebShell(nsIWebShell **aWebShell)=0;
NS_IMETHOD SetDocShell(nsIDocShell *aDocShell)=0;
NS_IMETHOD GetDocShell(nsIDocShell **aDocShell)=0;
NS_IMETHOD SetOpenerWindow(nsIDOMWindow *aOpener)=0;
/**

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

@ -17,226 +17,231 @@
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Travis Bogard <travis@netscape.com>
*/
#include "nsCOMPtr.h"
#include "nscore.h"
#include "nsBarProps.h"
#include "nsIBrowserWindow.h"
#include "nsIWebBrowserChrome.h"
#include "nsIDOMWindow.h"
#include "nsIScriptGlobalObject.h"
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIDOMBarPropIID, NS_IDOMBARPROP_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
//
// Basic (virtual) BarProp class implementation
//
BarPropImpl::BarPropImpl() {
BarPropImpl::BarPropImpl() : mBrowserChrome(nsnull), mScriptObject(nsnull)
{
NS_INIT_REFCNT();
mBrowser = nsnull;
mScriptObject = nsnull;
}
BarPropImpl::~BarPropImpl() {
BarPropImpl::~BarPropImpl()
{
}
NS_IMPL_ADDREF(BarPropImpl)
NS_IMPL_RELEASE(BarPropImpl)
nsresult
BarPropImpl::QueryInterface(const nsIID& aIID,
void** aInstancePtrResult) {
NS_INTERFACE_MAP_BEGIN(BarPropImpl)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMBarProp)
NS_INTERFACE_MAP_ENTRY(nsIScriptObjectOwner)
NS_INTERFACE_MAP_ENTRY(nsIDOMBarProp)
NS_INTERFACE_MAP_END
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
if (nsnull == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kIScriptObjectOwnerIID)) {
*aInstancePtrResult = (void*) ((nsIScriptObjectOwner*)this);
AddRef();
return NS_OK;
}
if (aIID.Equals(kIDOMBarPropIID)) {
*aInstancePtrResult = (void*) ((nsIDOMBarProp*)this);
AddRef();
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
*aInstancePtrResult = (void*)(nsISupports*)(nsIScriptObjectOwner*)this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
NS_IMETHODIMP BarPropImpl::GetScriptObject(nsIScriptContext *aContext,
void** aScriptObject)
{
NS_ENSURE_ARG_POINTER(aScriptObject);
if(!mScriptObject)
{
nsCOMPtr<nsIScriptGlobalObject> global;
global = aContext->GetGlobalObject();
nsCOMPtr<nsIDOMWindow> domWindow(do_QueryInterface(global));
NS_ENSURE_SUCCESS(NS_NewScriptBarProp(aContext,
NS_STATIC_CAST(nsIDOMBarProp*, this), domWindow, &mScriptObject),
NS_ERROR_FAILURE);
}
*aScriptObject = mScriptObject;
return NS_OK;
}
NS_IMETHODIMP
BarPropImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) {
NS_PRECONDITION(nsnull != aScriptObject, "null arg");
nsresult res = NS_OK;
if (nsnull == mScriptObject) {
nsIScriptGlobalObject *global = aContext->GetGlobalObject();
res = NS_NewScriptBarProp(aContext, (nsIDOMBarProp *) this, (nsIDOMWindow *) global, &mScriptObject);
NS_IF_RELEASE(global);
}
*aScriptObject = mScriptObject;
return res;
NS_IMETHODIMP BarPropImpl::SetScriptObject(void *aScriptObject)
{
// Weak Reference
mScriptObject = aScriptObject;
return NS_OK;
}
NS_IMETHODIMP
BarPropImpl::SetScriptObject(void *aScriptObject) {
mScriptObject = aScriptObject;
return NS_OK;
NS_IMETHODIMP BarPropImpl::SetWebBrowserChrome(nsIWebBrowserChrome* aBrowserChrome)
{
mBrowserChrome = aBrowserChrome;
return NS_OK;
}
NS_IMETHODIMP_(void)
BarPropImpl::SetBrowserWindow(nsIBrowserWindow *aBrowser) {
mBrowser = aBrowser;
}
NS_IMETHODIMP
BarPropImpl::GetVisibleByFlag(PRBool *aVisible, PRUint32 aChromeFlag) {
PRUint32 chromeFlags;
*aVisible = PR_FALSE;
if (mBrowser && NS_SUCCEEDED(mBrowser->GetChrome(chromeFlags))) {
if (chromeFlags & aChromeFlag)
*aVisible = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP BarPropImpl::GetVisibleByFlag(PRBool *aVisible,
PRUint32 aChromeFlag)
{
PRUint32 chromeFlags;
*aVisible = PR_FALSE;
if(mBrowserChrome)
{
NS_ENSURE_SUCCESS(mBrowserChrome->GetChromeMask(&chromeFlags),
NS_ERROR_FAILURE);
if(chromeFlags & aChromeFlag)
*aVisible = PR_TRUE;
return NS_OK;
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
BarPropImpl::SetVisibleByFlag(PRBool aVisible, PRUint32 aChromeFlag) {
PRUint32 chromeFlags;
if (mBrowser && NS_SUCCEEDED(mBrowser->GetChrome(chromeFlags))) {
if (aVisible)
chromeFlags |= aChromeFlag;
else
chromeFlags &= ~aChromeFlag;
return mBrowser->SetChrome(chromeFlags);
}
return NS_ERROR_FAILURE;
NS_IMETHODIMP BarPropImpl::SetVisibleByFlag(PRBool aVisible,
PRUint32 aChromeFlag)
{
PRUint32 chromeFlags;
if(mBrowserChrome)
{
NS_ENSURE_SUCCESS(mBrowserChrome->GetChromeMask(&chromeFlags),
NS_ERROR_FAILURE);
if(aVisible)
chromeFlags |= aChromeFlag;
else
chromeFlags |= ~aChromeFlag;
NS_ENSURE_SUCCESS(mBrowserChrome->SetChromeMask(chromeFlags),
NS_ERROR_FAILURE);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
//
// MenubarProp class implementation
//
MenubarPropImpl::MenubarPropImpl() {
MenubarPropImpl::MenubarPropImpl()
{
}
MenubarPropImpl::~MenubarPropImpl() {
MenubarPropImpl::~MenubarPropImpl()
{
}
NS_IMETHODIMP
MenubarPropImpl::GetVisible(PRBool *aVisible) {
return BarPropImpl::GetVisibleByFlag(aVisible, NS_CHROME_MENU_BAR_ON);
NS_IMETHODIMP MenubarPropImpl::GetVisible(PRBool *aVisible)
{
return BarPropImpl::GetVisibleByFlag(aVisible, nsIWebBrowserChrome::menuBarOn);
}
NS_IMETHODIMP
MenubarPropImpl::SetVisible(PRBool aVisible) {
return BarPropImpl::SetVisibleByFlag(aVisible, NS_CHROME_MENU_BAR_ON);
NS_IMETHODIMP MenubarPropImpl::SetVisible(PRBool aVisible)
{
return BarPropImpl::SetVisibleByFlag(aVisible, nsIWebBrowserChrome::menuBarOn);
}
//
// ToolbarProp class implementation
//
ToolbarPropImpl::ToolbarPropImpl() {
ToolbarPropImpl::ToolbarPropImpl()
{
}
ToolbarPropImpl::~ToolbarPropImpl() {
ToolbarPropImpl::~ToolbarPropImpl()
{
}
NS_IMETHODIMP
ToolbarPropImpl::GetVisible(PRBool *aVisible) {
return BarPropImpl::GetVisibleByFlag(aVisible, NS_CHROME_TOOL_BAR_ON);
NS_IMETHODIMP ToolbarPropImpl::GetVisible(PRBool *aVisible)
{
return BarPropImpl::GetVisibleByFlag(aVisible, nsIWebBrowserChrome::toolBarOn);
}
NS_IMETHODIMP
ToolbarPropImpl::SetVisible(PRBool aVisible) {
return BarPropImpl::SetVisibleByFlag(aVisible, NS_CHROME_TOOL_BAR_ON);
NS_IMETHODIMP ToolbarPropImpl::SetVisible(PRBool aVisible)
{
return BarPropImpl::SetVisibleByFlag(aVisible, nsIWebBrowserChrome::toolBarOn);
}
//
// LocationbarProp class implementation
//
LocationbarPropImpl::LocationbarPropImpl() {
LocationbarPropImpl::LocationbarPropImpl()
{
}
LocationbarPropImpl::~LocationbarPropImpl() {
LocationbarPropImpl::~LocationbarPropImpl()
{
}
NS_IMETHODIMP
LocationbarPropImpl::GetVisible(PRBool *aVisible) {
return BarPropImpl::GetVisibleByFlag(aVisible, NS_CHROME_LOCATION_BAR_ON);
NS_IMETHODIMP LocationbarPropImpl::GetVisible(PRBool *aVisible)
{
return BarPropImpl::GetVisibleByFlag(aVisible, nsIWebBrowserChrome::locationBarOn);
}
NS_IMETHODIMP
LocationbarPropImpl::SetVisible(PRBool aVisible) {
return BarPropImpl::SetVisibleByFlag(aVisible, NS_CHROME_LOCATION_BAR_ON);
NS_IMETHODIMP LocationbarPropImpl::SetVisible(PRBool aVisible)
{
return BarPropImpl::SetVisibleByFlag(aVisible, nsIWebBrowserChrome::locationBarOn);
}
//
// PersonalbarProp class implementation
//
PersonalbarPropImpl::PersonalbarPropImpl() {
PersonalbarPropImpl::PersonalbarPropImpl()
{
}
PersonalbarPropImpl::~PersonalbarPropImpl() {
PersonalbarPropImpl::~PersonalbarPropImpl()
{
}
NS_IMETHODIMP
PersonalbarPropImpl::GetVisible(PRBool *aVisible) {
return BarPropImpl::GetVisibleByFlag(aVisible, NS_CHROME_PERSONAL_TOOLBAR_ON);
NS_IMETHODIMP PersonalbarPropImpl::GetVisible(PRBool *aVisible)
{
return BarPropImpl::GetVisibleByFlag(aVisible, nsIWebBrowserChrome::personalToolBarOn);
}
NS_IMETHODIMP
PersonalbarPropImpl::SetVisible(PRBool aVisible) {
return BarPropImpl::SetVisibleByFlag(aVisible, NS_CHROME_PERSONAL_TOOLBAR_ON);
NS_IMETHODIMP PersonalbarPropImpl::SetVisible(PRBool aVisible)
{
return BarPropImpl::SetVisibleByFlag(aVisible, nsIWebBrowserChrome::personalToolBarOn);
}
//
// StatusbarProp class implementation
//
StatusbarPropImpl::StatusbarPropImpl() {
StatusbarPropImpl::StatusbarPropImpl()
{
}
StatusbarPropImpl::~StatusbarPropImpl() {
StatusbarPropImpl::~StatusbarPropImpl()
{
}
NS_IMETHODIMP
StatusbarPropImpl::GetVisible(PRBool *aVisible) {
return BarPropImpl::GetVisibleByFlag(aVisible, NS_CHROME_STATUS_BAR_ON);
NS_IMETHODIMP StatusbarPropImpl::GetVisible(PRBool *aVisible)
{
return BarPropImpl::GetVisibleByFlag(aVisible, nsIWebBrowserChrome::statusBarOn);
}
NS_IMETHODIMP
StatusbarPropImpl::SetVisible(PRBool aVisible) {
return BarPropImpl::SetVisibleByFlag(aVisible, NS_CHROME_STATUS_BAR_ON);
NS_IMETHODIMP StatusbarPropImpl::SetVisible(PRBool aVisible)
{
return BarPropImpl::SetVisibleByFlag(aVisible, nsIWebBrowserChrome::statusBarOn);
}
//
// ScrollbarsProp class implementation
//
ScrollbarsPropImpl::ScrollbarsPropImpl() {
ScrollbarsPropImpl::ScrollbarsPropImpl()
{
}
ScrollbarsPropImpl::~ScrollbarsPropImpl() {
ScrollbarsPropImpl::~ScrollbarsPropImpl()
{
}
NS_IMETHODIMP
ScrollbarsPropImpl::GetVisible(PRBool *aVisible) {
return NS_ERROR_FAILURE;
NS_IMETHODIMP ScrollbarsPropImpl::GetVisible(PRBool *aVisible)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
ScrollbarsPropImpl::SetVisible(PRBool aVisible) {
return NS_ERROR_FAILURE;
NS_IMETHODIMP ScrollbarsPropImpl::SetVisible(PRBool aVisible)
{
return NS_ERROR_FAILURE;
}

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

@ -34,81 +34,82 @@
#include "nsIScriptObjectOwner.h"
#include "nsIDOMBarProp.h"
class nsIBrowserWindow;
class nsIWebBrowserChrome;
// Script "BarProp" object
class BarPropImpl : public nsIScriptObjectOwner, public nsIDOMBarProp {
public:
BarPropImpl();
virtual ~BarPropImpl();
BarPropImpl();
virtual ~BarPropImpl();
NS_DECL_ISUPPORTS
NS_DECL_ISUPPORTS
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void *aScriptObject);
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void *aScriptObject);
NS_IMETHOD_(void) SetBrowserWindow(nsIBrowserWindow *aBrowser);
NS_IMETHOD SetWebBrowserChrome(nsIWebBrowserChrome* aBrowserChrome);
NS_IMETHOD GetVisibleByFlag(PRBool *aVisible, PRUint32 aChromeFlag);
NS_IMETHOD SetVisibleByFlag(PRBool aVisible, PRUint32 aChromeFlag);
NS_IMETHOD GetVisibleByFlag(PRBool *aVisible, PRUint32 aChromeFlag);
NS_IMETHOD SetVisibleByFlag(PRBool aVisible, PRUint32 aChromeFlag);
protected:
nsIBrowserWindow* mBrowser;
void *mScriptObject;
// Weak Reference
nsIWebBrowserChrome* mBrowserChrome;
void *mScriptObject;
};
// Script "menubar" object
class MenubarPropImpl : public BarPropImpl {
public:
MenubarPropImpl();
virtual ~MenubarPropImpl();
MenubarPropImpl();
virtual ~MenubarPropImpl();
NS_DECL_IDOMBARPROP
NS_DECL_IDOMBARPROP
};
// Script "toolbar" object
class ToolbarPropImpl : public BarPropImpl {
public:
ToolbarPropImpl();
virtual ~ToolbarPropImpl();
ToolbarPropImpl();
virtual ~ToolbarPropImpl();
NS_DECL_IDOMBARPROP
NS_DECL_IDOMBARPROP
};
// Script "locationbar" object
class LocationbarPropImpl : public BarPropImpl {
public:
LocationbarPropImpl();
virtual ~LocationbarPropImpl();
LocationbarPropImpl();
virtual ~LocationbarPropImpl();
NS_DECL_IDOMBARPROP
NS_DECL_IDOMBARPROP
};
// Script "personalbar" object
class PersonalbarPropImpl : public BarPropImpl {
public:
PersonalbarPropImpl();
virtual ~PersonalbarPropImpl();
PersonalbarPropImpl();
virtual ~PersonalbarPropImpl();
NS_DECL_IDOMBARPROP
NS_DECL_IDOMBARPROP
};
// Script "statusbar" object
class StatusbarPropImpl : public BarPropImpl {
public:
StatusbarPropImpl();
virtual ~StatusbarPropImpl();
StatusbarPropImpl();
virtual ~StatusbarPropImpl();
NS_DECL_IDOMBARPROP
NS_DECL_IDOMBARPROP
};
// Script "scrollbars" object
class ScrollbarsPropImpl : public BarPropImpl {
public:
ScrollbarsPropImpl();
virtual ~ScrollbarsPropImpl();
ScrollbarsPropImpl();
virtual ~ScrollbarsPropImpl();
NS_DECL_IDOMBARPROP
NS_DECL_IDOMBARPROP
};
#endif /* nsBarProps_h___ */

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -17,35 +17,33 @@
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Travis Bogard <travis@netscape.com>
*/
#ifndef nsGlobalWindow_h___
#define nsGlobalWindow_h___
#include "nscore.h"
// Local Includes
// Helper Classes
#include "nsCOMPtr.h"
#include "nsIFactory.h"
#include "nsIPrincipal.h"
#include "nsISupports.h"
#include "nsIScriptContext.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsIDOMWindow.h"
#include "nsIDOMNavigator.h"
#include "nsIDOMLocation.h"
#include "nsIDOMEventReceiver.h"
#include "nsIDOMNSLocation.h"
#include "nsIDOMScreen.h"
#include "nsITimer.h"
#include "nsIJSScriptObject.h"
#include "nsGUIEvent.h"
#include "nsFrameList.h"
// Interfaces Needed
#include "nsDOMWindowList.h"
#include "nsIDOMEventTarget.h"
#include "nsIControllers.h"
#include "nsPIDOMWindow.h"
#include "nsIDOMAbstractView.h"
#include "nsIBaseWindow.h"
#include "nsIChromeEventHandler.h"
#include "nsIControllers.h"
#include "nsIDocShellTreeOwner.h"
#include "nsIDocShellTreeItem.h"
#include "nsIDOMAbstractView.h"
#include "nsIDOMEventReceiver.h"
#include "nsIDOMNavigator.h"
#include "nsIDOMNSLocation.h"
#include "nsIDOMWindow.h"
#include "nsIJSScriptObject.h"
#include "nsIScriptGlobalObject.h"
#include "nsITimer.h"
#include "nsIWebBrowserChrome.h"
#include "nsPIDOMWindow.h"
#define DEFAULT_HOME_PAGE "www.mozilla.org"
#define PREF_BROWSER_STARTUP_HOMEPAGE "browser.startup.homepage"
@ -60,7 +58,6 @@ class nsIDOMEvent;
class nsIBrowserWindow;
class nsIScrollableView;
#include "jsapi.h"
typedef struct nsTimeoutImpl nsTimeoutImpl;
@ -70,240 +67,154 @@ class NavigatorImpl;
class ScreenImpl;
class HistoryImpl;
// Global object for scripting
class GlobalWindowImpl : public nsIScriptObjectOwner, public nsIScriptGlobalObject, public nsIDOMWindow,
public nsIJSScriptObject, public nsIScriptObjectPrincipal, public nsIDOMEventReceiver,
public nsPIDOMWindow, public nsIDOMAbstractView
//*****************************************************************************
// GlobalWindowImpl: Global Object for Scripting
//*****************************************************************************
class GlobalWindowImpl : public nsIScriptObjectOwner,
public nsIScriptGlobalObject,
public nsIDOMWindow,
public nsIJSScriptObject,
public nsIScriptObjectPrincipal,
public nsIDOMEventReceiver,
public nsPIDOMWindow,
public nsIDOMAbstractView
{
public:
GlobalWindowImpl();
virtual ~GlobalWindowImpl();
// nsISupports
NS_DECL_ISUPPORTS
NS_DECL_ISUPPORTS
// nsIScriptObjectOwner
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void *aScriptObject);
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void *aScriptObject);
// nsIScriptGlobalObject
NS_IMETHOD SetContext(nsIScriptContext *aContext);
NS_IMETHOD GetContext(nsIScriptContext **aContext);
NS_IMETHOD SetNewDocument(nsIDOMDocument *aDocument);
NS_IMETHOD SetDocShell(nsIDocShell* aDocShell);
NS_IMETHOD GetDocShell(nsIDocShell** aDocShell);
NS_IMETHOD SetOpenerWindow(nsIDOMWindow *aOpener);
NS_IMETHOD SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner);
NS_IMETHOD GetGlobalObjectOwner(nsIScriptGlobalObjectOwner** aOwner);
NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent,
nsIDOMEvent** aDOMEvent, PRUint32 aFlags,
nsEventStatus* aEventStatus);
NS_IMETHOD SetContext(nsIScriptContext *aContext);
NS_IMETHOD GetContext(nsIScriptContext **aContext);
NS_IMETHOD SetNewDocument(nsIDOMDocument *aDocument);
NS_IMETHOD SetWebShell(nsIWebShell *aWebShell);
NS_IMETHOD GetWebShell(nsIWebShell **aWebShell);// XXX This may be temporary - rods
NS_IMETHOD SetOpenerWindow(nsIDOMWindow *aOpener);
NS_IMETHOD SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner);
NS_IMETHOD GetGlobalObjectOwner(nsIScriptGlobalObjectOwner** aOwner);
// nsIScriptObjectPrincipal
NS_IMETHOD GetPrincipal(nsIPrincipal **prin);
NS_IMETHOD GetWindow(nsIDOMWindow** aWindow);
NS_IMETHOD GetSelf(nsIDOMWindow** aSelf);
NS_IMETHOD GetDocument(nsIDOMDocument** aDocument);
NS_IMETHOD GetNavigator(nsIDOMNavigator** aNavigator);
NS_IMETHOD GetScreen(nsIDOMScreen** aScreen);
NS_IMETHOD GetHistory(nsIDOMHistory** aHistory);
NS_IMETHOD GetLocation(nsIDOMLocation** aLocation);
NS_IMETHOD GetParent(nsIDOMWindow** aOpener);
NS_IMETHOD GetTop(nsIDOMWindow** aTop);
NS_IMETHOD GetContent(nsIDOMWindow** aContent);
NS_IMETHOD GetClosed(PRBool* aClosed);
NS_IMETHOD GetMenubar(nsIDOMBarProp** aMenubar);
NS_IMETHOD GetToolbar(nsIDOMBarProp** aToolbar);
NS_IMETHOD GetLocationbar(nsIDOMBarProp** aLocationbar);
NS_IMETHOD GetPersonalbar(nsIDOMBarProp** aPersonalbar);
NS_IMETHOD GetStatusbar(nsIDOMBarProp** aStatusbar);
NS_IMETHOD GetScrollbars(nsIDOMBarProp** aScrollbars);
NS_IMETHOD GetDirectories(nsIDOMBarProp** aDirectories);
NS_IMETHOD GetFrames(nsIDOMWindowCollection** aFrames);
// nsIDOMWindow
NS_DECL_IDOMWINDOW
NS_IMETHOD GetOpener(nsIDOMWindow** aOpener);
NS_IMETHOD SetOpener(nsIDOMWindow* aOpener);
// nsIJSScriptObject
virtual PRBool AddProperty(JSContext *aContext, JSObject *aObj,
jsval aID, jsval *aVp);
virtual PRBool DeleteProperty(JSContext *aContext, JSObject *aObj,
jsval aID, jsval *aVp);
virtual PRBool GetProperty(JSContext *aContext, JSObject *aObj,
jsval aID, jsval *aVp);
virtual PRBool SetProperty(JSContext *aContext, JSObject *aObj,
jsval aID, jsval *aVp);
virtual PRBool EnumerateProperty(JSContext *aContext, JSObject *aObj);
virtual PRBool Resolve(JSContext *aContext, JSObject *aObj, jsval aID);
virtual PRBool Convert(JSContext *aContext, JSObject *aObj, jsval aID);
virtual void Finalize(JSContext *aContext, JSObject *aObj);
NS_IMETHOD GetStatus(nsString& aStatus);
NS_IMETHOD SetStatus(const nsString& aStatus);
// nsIDOMEventTarget
NS_IMETHOD AddEventListener(const nsString& aType,
nsIDOMEventListener* aListener, PRBool aUseCapture);
NS_IMETHOD RemoveEventListener(const nsString& aType,
nsIDOMEventListener* aListener, PRBool aUseCapture);
NS_IMETHOD GetDefaultStatus(nsString& aDefaultStatus);
NS_IMETHOD SetDefaultStatus(const nsString& aDefaultStatus);
// nsIDOMEventReceiver
NS_IMETHOD AddEventListenerByIID(nsIDOMEventListener *aListener,
const nsIID& aIID);
NS_IMETHOD RemoveEventListenerByIID(nsIDOMEventListener *aListener,
const nsIID& aIID);
NS_IMETHOD GetListenerManager(nsIEventListenerManager** aInstancePtrResult);
NS_IMETHOD GetNewListenerManager(nsIEventListenerManager **aInstancePtrResult);
NS_IMETHOD GetName(nsString& aName);
NS_IMETHOD SetName(const nsString& aName);
// nsPIDOMWindow
NS_IMETHOD GetPrivateParent(nsPIDOMWindow** aResult);
NS_IMETHOD GetLocation(nsIDOMLocation** aLocation);
//NS_IMETHOD GetDocShell(nsIDocShell** aDocShell);
NS_IMETHOD Activate();
NS_IMETHOD Deactivate();
NS_IMETHOD GetInnerWidth(PRInt32* aInnerWidth);
NS_IMETHOD SetInnerWidth(PRInt32 aInnerWidth);
// nsIDOMAbstractView
//NS_IMETHOD GetDocument(nsIDOMDocument** aDocument);
NS_IMETHOD GetInnerHeight(PRInt32* aInnerHeight);
NS_IMETHOD SetInnerHeight(PRInt32 aInnerHeight);
public:
// Object Management
GlobalWindowImpl();
NS_IMETHOD GetOuterWidth(PRInt32* aOuterWidth);
NS_IMETHOD SetOuterWidth(PRInt32 aOuterWidth);
NS_IMETHOD GetOuterHeight(PRInt32* aOuterHeight);
NS_IMETHOD SetOuterHeight(PRInt32 aOuterHeight);
NS_IMETHOD GetScreenX(PRInt32* aScreenX);
NS_IMETHOD SetScreenX(PRInt32 aScreenX);
NS_IMETHOD GetScreenY(PRInt32* aScreenY);
NS_IMETHOD SetScreenY(PRInt32 aScreenY);
NS_IMETHOD GetPageXOffset(PRInt32* aPageXOffset);
NS_IMETHOD SetPageXOffset(PRInt32 aPageXOffset);
NS_IMETHOD GetPageYOffset(PRInt32* aPageYOffset);
NS_IMETHOD SetPageYOffset(PRInt32 aPageYOffset);
NS_IMETHOD Dump(const nsString& aStr);
NS_IMETHOD Alert(JSContext *cx, jsval *argv, PRUint32 argc);
NS_IMETHOD Confirm(JSContext *cx, jsval *argv, PRUint32 argc, PRBool* aReturn);
NS_IMETHOD Prompt(JSContext *cx, jsval *argv, PRUint32 argc, nsString& aReturn);
NS_IMETHOD Focus();
NS_IMETHOD Blur();
NS_IMETHOD Forward();
NS_IMETHOD Back();
NS_IMETHOD Home();
NS_IMETHOD Stop();
NS_IMETHOD Print();
NS_IMETHOD MoveTo(PRInt32 aXPos, PRInt32 aYPos);
NS_IMETHOD MoveBy(PRInt32 aXDif, PRInt32 aYDif);
NS_IMETHOD ResizeTo(PRInt32 aWidth, PRInt32 aHeight);
NS_IMETHOD ResizeBy(PRInt32 aWidthDif, PRInt32 aHeightDif);
NS_IMETHOD SizeToContent();
NS_IMETHOD GetAttention();
NS_IMETHOD Scroll(PRInt32 aXScroll, PRInt32 aYScroll);
NS_IMETHOD ScrollTo(PRInt32 aXScroll, PRInt32 aYScroll);
NS_IMETHOD ScrollBy(PRInt32 aXScrollDif, PRInt32 aYScrollDif);
NS_IMETHOD GetScrollX(PRInt32* aScrollX);
NS_IMETHOD GetScrollY(PRInt32* aScrollY);
NS_IMETHOD ClearTimeout(PRInt32 aTimerID);
NS_IMETHOD ClearInterval(PRInt32 aTimerID);
NS_IMETHOD SetTimeout(JSContext *cx, jsval *argv, PRUint32 argc,
PRInt32* aReturn);
NS_IMETHOD SetInterval(JSContext *cx, jsval *argv, PRUint32 argc,
PRInt32* aReturn);
NS_IMETHOD Open(JSContext *cx, jsval *argv, PRUint32 argc,
nsIDOMWindow** aReturn);
NS_IMETHOD OpenDialog(JSContext *cx, jsval *argv, PRUint32 argc,
nsIDOMWindow** aReturn);
NS_IMETHOD Close();
NS_IMETHOD Close(JSContext* cx, jsval* argv, PRUint32 argc);
NS_IMETHOD Escape(const nsString& aStr, nsString& aReturn);
NS_IMETHOD Unescape(const nsString& aStr, nsString& aReturn);
NS_IMETHOD CaptureEvents(PRInt32 aEventFlags);
NS_IMETHOD ReleaseEvents(PRInt32 aEventFlags);
NS_IMETHOD RouteEvent(nsIDOMEvent* aEvt);
NS_IMETHOD EnableExternalCapture();
NS_IMETHOD DisableExternalCapture();
NS_IMETHOD GetControllers(nsIControllers** aResult);
// nsIDOMEventReceiver interface
NS_IMETHOD AddEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID);
NS_IMETHOD RemoveEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID);
NS_IMETHOD GetListenerManager(nsIEventListenerManager** aInstancePtrResult);
NS_IMETHOD GetNewListenerManager(nsIEventListenerManager **aInstancePtrResult);
// nsIDOMEventTarget interface
NS_IMETHOD AddEventListener(const nsString& aType, nsIDOMEventListener* aListener,
PRBool aUseCapture);
NS_IMETHOD RemoveEventListener(const nsString& aType, nsIDOMEventListener* aListener,
PRBool aUseCapture);
NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext,
nsEvent* aEvent,
nsIDOMEvent** aDOMEvent,
PRUint32 aFlags,
nsEventStatus* aEventStatus);
// nsIJSScriptObject interface
virtual PRBool AddProperty(JSContext *aContext, JSObject *aObj,
jsval aID, jsval *aVp);
virtual PRBool DeleteProperty(JSContext *aContext, JSObject *aObj,
jsval aID, jsval *aVp);
virtual PRBool GetProperty(JSContext *aContext, JSObject *aObj,
jsval aID, jsval *aVp);
virtual PRBool SetProperty(JSContext *aContext, JSObject *aObj,
jsval aID, jsval *aVp);
virtual PRBool EnumerateProperty(JSContext *aContext, JSObject *aObj);
virtual PRBool Resolve(JSContext *aContext, JSObject *aObj, jsval aID);
virtual PRBool Convert(JSContext *aContext, JSObject *aObj, jsval aID);
virtual void Finalize(JSContext *aContext, JSObject *aObj);
// nsIScriptObjectPrincipal interface
NS_IMETHOD GetPrincipal(nsIPrincipal **prin);
// nsPIDOMWindowInterface
NS_IMETHOD GetPrivateParent(nsPIDOMWindow** aResult);
NS_IMETHOD Activate();
NS_IMETHOD Deactivate();
friend void nsGlobalWindow_RunTimeout(nsITimer *aTimer, void *aClosure);
static void CloseWindow(nsISupports* aWindow);
protected:
PRBool RunTimeout(nsTimeoutImpl *aTimeout);
nsresult ClearTimeoutOrInterval(PRInt32 aTimerID);
nsresult SetTimeoutOrInterval(JSContext *cx, jsval *argv,
PRUint32 argc, PRInt32* aReturn,
PRBool aIsInterval);
void InsertTimeoutIntoList(nsTimeoutImpl **aInsertionPoint,
nsTimeoutImpl *aTimeout);
void ClearAllTimeouts();
void DropTimeout(nsTimeoutImpl *aTimeout,
nsIScriptContext* aContext=nsnull);
void HoldTimeout(nsTimeoutImpl *aTimeout);
nsresult GetBrowserWindowInterface(nsIBrowserWindow*& aBrowser,
nsIWebShell *aWebShell=nsnull);
nsresult CheckWindowName(JSContext *cx, nsString& aName);
PRInt32 WinHasOption(char *options, char *name, PRBool& aPresenceFlag);
PRBool CheckForEventListener(JSContext *aContext, nsString& aPropName);
// Object Management
virtual ~GlobalWindowImpl();
void CleanUp();
// Window Control Functions
NS_IMETHOD OpenInternal(JSContext* cx, jsval* argv, PRUint32 argc,
PRBool aDialog, nsIDOMWindow** aReturn);
NS_IMETHOD AttachArguments(nsIDOMWindow* aWindow, jsval* argv, PRUint32 argc);
PRUint32 CalculateChromeFlags(char* aFeatures, PRBool aDialog);
NS_IMETHOD SizeOpenedDocShellItem(nsIDocShellTreeItem* aDocShellItem,
char* aFeatures, PRUint32 aChromeFlags);
NS_IMETHOD ReadyOpenedDocShellItem(nsIDocShellTreeItem* aDocShellItem,
nsIDOMWindow** aDOMWindow);
NS_IMETHOD CheckWindowName(JSContext* cx, nsString& aName);
PRInt32 WinHasOption(char* options, char* name, PRBool* aPresenceFlag);
static void CloseWindow(nsISupports* aWindow);
nsresult OpenInternal(JSContext *cx, jsval *argv, PRUint32 argc,
PRBool aDialog, nsIDOMWindow** aReturn);
nsresult AttachArguments(nsIDOMWindow *aWindow, jsval *argv, PRUint32 argc);
PRUint32 CalculateChromeFlags(char *aFeatures, PRBool aDialog);
nsresult SizeAndShowOpenedWebShell(nsIWebShell *aOuterShell,
char *aFeatures, PRBool aNewWindow, PRBool aDialog);
nsresult ReadyOpenedWebShell(nsIWebShell *aWebShell, nsIDOMWindow **aDOMWindow);
nsresult GetScrollInfo(nsIScrollableView** aScrollableView,
float* aP2T, float* aT2P);
// Timeout Functions
NS_IMETHOD SetTimeoutOrInterval(JSContext *cx, jsval *argv, PRUint32 argc,
PRInt32* aReturn, PRBool aIsInterval);
PRBool RunTimeout(nsTimeoutImpl *aTimeout);
void DropTimeout(nsTimeoutImpl *aTimeout, nsIScriptContext* aContext=nsnull);
void HoldTimeout(nsTimeoutImpl *aTimeout);
NS_IMETHOD ClearTimeoutOrInterval(PRInt32 aTimerID);
void ClearAllTimeouts();
void InsertTimeoutIntoList(nsTimeoutImpl **aInsertionPoint,
nsTimeoutImpl *aTimeout);
friend void nsGlobalWindow_RunTimeout(nsITimer *aTimer, void *aClosure);
static nsresult WebShellToDOMWindow(nsIWebShell *aWebShell, nsIDOMWindow **aDOMWindow);
// Helper Functions
NS_IMETHOD GetTreeOwner(nsIDocShellTreeOwner** aTreeOwner);
NS_IMETHOD GetTreeOwner(nsIBaseWindow** aTreeOwner);
NS_IMETHOD GetWebBrowserChrome(nsIWebBrowserChrome** aBrowserChrome);
NS_IMETHOD GetScrollInfo(nsIScrollableView** aScrollableView, float* aP2T,
float* aT2P);
PRBool CheckForEventListener(JSContext* aContext, nsString& aPropName);
nsIScriptContext *mContext;
void *mScriptObject;
nsIDOMDocument *mDocument;
NavigatorImpl *mNavigator;
LocationImpl *mLocation;
ScreenImpl *mScreen;
HistoryImpl *mHistory;
nsIWebShell *mWebShell;
nsIDOMWindow *mOpener;
nsIScriptGlobalObjectOwner* mGlobalObjectOwner; // [Weak Ref]
protected:
nsCOMPtr<nsIScriptContext> mContext;
nsCOMPtr<nsIDOMDocument> mDocument;
nsCOMPtr<nsIDOMWindow> mOpener;
nsCOMPtr<nsIControllers> mControllers;
nsCOMPtr<nsIEventListenerManager> mListenerManager;
void* mScriptObject;
NavigatorImpl* mNavigator;
ScreenImpl* mScreen;
HistoryImpl* mHistory;
nsDOMWindowList* mFrames;
LocationImpl* mLocation;
BarPropImpl* mMenubar;
BarPropImpl* mToolbar;
BarPropImpl* mLocationbar;
BarPropImpl* mPersonalbar;
BarPropImpl* mStatusbar;
BarPropImpl* mScrollbars;
nsTimeoutImpl* mTimeouts;
nsTimeoutImpl** mTimeoutInsertionPoint;
nsTimeoutImpl* mRunningTimeout;
PRUint32 mTimeoutPublicIdCounter;
PRBool mFirstDocumentLoad;
nsString mStatus;
nsString mDefaultStatus;
BarPropImpl *mMenubar;
BarPropImpl *mToolbar;
BarPropImpl *mLocationbar;
BarPropImpl *mPersonalbar;
BarPropImpl *mStatusbar;
BarPropImpl *mScrollbars;
nsIChromeEventHandler* mChromeEventHandler;
nsCOMPtr<nsIControllers> mControllers;
nsTimeoutImpl *mTimeouts;
nsTimeoutImpl **mTimeoutInsertionPoint;
nsTimeoutImpl *mRunningTimeout;
PRUint32 mTimeoutPublicIdCounter;
nsIEventListenerManager* mListenerManager;
nsDOMWindowList *mFrames;
PRBool mFirstDocumentLoad;
void CleanUp();
nsIScriptGlobalObjectOwner* mGlobalObjectOwner; // Weak Reference
nsIDocShell* mDocShell; // Weak Reference
nsIChromeEventHandler* mChromeEventHandler; // Weak Reference
};
/*
@ -329,26 +240,35 @@ struct nsTimeoutImpl {
nsTimeoutImpl *next;
};
//*****************************************************************************
// NavigatorImpl: Script "navigator" object
//*****************************************************************************
// Script "navigator" object
class NavigatorImpl : public nsIScriptObjectOwner, public nsIDOMNavigator {
class NavigatorImpl : public nsIScriptObjectOwner, public nsIDOMNavigator
{
public:
NavigatorImpl();
virtual ~NavigatorImpl();
NavigatorImpl();
virtual ~NavigatorImpl();
NS_DECL_ISUPPORTS
NS_DECL_IDOMNAVIGATOR
NS_DECL_ISUPPORTS
NS_DECL_IDOMNAVIGATOR
// nsIScriptObjectOnwer interface
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void *aScriptObject);
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void *aScriptObject);
protected:
void *mScriptObject;
nsIDOMMimeTypeArray* mMimeTypes;
nsIDOMPluginArray* mPlugins;
void *mScriptObject;
nsIDOMMimeTypeArray* mMimeTypes;
nsIDOMPluginArray* mPlugins;
};
class nsIURI;
//*****************************************************************************
// LocationImpl: Script "location" object
//*****************************************************************************
class LocationImpl : public nsIScriptObjectOwner,
public nsIDOMLocation,
public nsIDOMNSLocation,
@ -357,62 +277,63 @@ class LocationImpl : public nsIScriptObjectOwner,
protected:
public:
LocationImpl(nsIWebShell *aWebShell);
virtual ~LocationImpl();
LocationImpl(nsIDocShell *aDocShell);
virtual ~LocationImpl();
NS_DECL_ISUPPORTS
NS_DECL_ISUPPORTS
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void *aScriptObject);
//nsIScriptObjectOwner
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void *aScriptObject);
NS_IMETHOD_(void) SetWebShell(nsIWebShell *aWebShell);
NS_IMETHOD_(void) SetDocShell(nsIDocShell *aDocShell);
// nsIDOMLocation
NS_IMETHOD GetHash(nsString& aHash);
NS_IMETHOD SetHash(const nsString& aHash);
NS_IMETHOD GetHost(nsString& aHost);
NS_IMETHOD SetHost(const nsString& aHost);
NS_IMETHOD GetHostname(nsString& aHostname);
NS_IMETHOD SetHostname(const nsString& aHostname);
NS_IMETHOD GetHref(nsString& aHref);
NS_IMETHOD SetHref(const nsString& aHref);
NS_IMETHOD GetPathname(nsString& aPathname);
NS_IMETHOD SetPathname(const nsString& aPathname);
NS_IMETHOD GetPort(nsString& aPort);
NS_IMETHOD SetPort(const nsString& aPort);
NS_IMETHOD GetProtocol(nsString& aProtocol);
NS_IMETHOD SetProtocol(const nsString& aProtocol);
NS_IMETHOD GetSearch(nsString& aSearch);
NS_IMETHOD SetSearch(const nsString& aSearch);
NS_IMETHOD Reload(PRBool aForceget);
NS_IMETHOD Replace(const nsString& aUrl);
NS_IMETHOD ToString(nsString& aReturn);
// nsIDOMNSLocation
NS_IMETHOD Reload(JSContext *cx, jsval *argv, PRUint32 argc);
NS_IMETHOD Replace(JSContext *cx, jsval *argv, PRUint32 argc);
// nsIDOMLocation
NS_IMETHOD GetHash(nsString& aHash);
NS_IMETHOD SetHash(const nsString& aHash);
NS_IMETHOD GetHost(nsString& aHost);
NS_IMETHOD SetHost(const nsString& aHost);
NS_IMETHOD GetHostname(nsString& aHostname);
NS_IMETHOD SetHostname(const nsString& aHostname);
NS_IMETHOD GetHref(nsString& aHref);
NS_IMETHOD SetHref(const nsString& aHref);
NS_IMETHOD GetPathname(nsString& aPathname);
NS_IMETHOD SetPathname(const nsString& aPathname);
NS_IMETHOD GetPort(nsString& aPort);
NS_IMETHOD SetPort(const nsString& aPort);
NS_IMETHOD GetProtocol(nsString& aProtocol);
NS_IMETHOD SetProtocol(const nsString& aProtocol);
NS_IMETHOD GetSearch(nsString& aSearch);
NS_IMETHOD SetSearch(const nsString& aSearch);
NS_IMETHOD Reload(PRBool aForceget);
NS_IMETHOD Replace(const nsString& aUrl);
NS_IMETHOD ToString(nsString& aReturn);
// nsIJSScriptObject
virtual PRBool AddProperty(JSContext *aContext, JSObject *aObj, jsval aID, jsval *aVp);
virtual PRBool DeleteProperty(JSContext *aContext, JSObject *aObj, jsval aID, jsval *aVp);
virtual PRBool GetProperty(JSContext *aContext, JSObject *aObj, jsval aID, jsval *aVp);
virtual PRBool SetProperty(JSContext *aContext, JSObject *aObj, jsval aID, jsval *aVp);
virtual PRBool EnumerateProperty(JSContext *aContext, JSObject *aObj);
virtual PRBool Resolve(JSContext *aContext, JSObject *aObj, jsval aID);
virtual PRBool Convert(JSContext *aContext, JSObject *aObj, jsval aID);
virtual void Finalize(JSContext *aContext, JSObject *aObj);
// nsIDOMNSLocation
NS_IMETHOD Reload(JSContext *cx, jsval *argv, PRUint32 argc);
NS_IMETHOD Replace(JSContext *cx, jsval *argv, PRUint32 argc);
// nsIJSScriptObject
virtual PRBool AddProperty(JSContext *aContext, JSObject *aObj, jsval aID, jsval *aVp);
virtual PRBool DeleteProperty(JSContext *aContext, JSObject *aObj, jsval aID, jsval *aVp);
virtual PRBool GetProperty(JSContext *aContext, JSObject *aObj, jsval aID, jsval *aVp);
virtual PRBool SetProperty(JSContext *aContext, JSObject *aObj, jsval aID, jsval *aVp);
virtual PRBool EnumerateProperty(JSContext *aContext, JSObject *aObj);
virtual PRBool Resolve(JSContext *aContext, JSObject *aObj, jsval aID);
virtual PRBool Convert(JSContext *aContext, JSObject *aObj, jsval aID);
virtual void Finalize(JSContext *aContext, JSObject *aObj);
protected:
nsresult SetURL(nsIURI* aURL);
nsresult SetHrefWithBase(const nsString& aHref,
nsresult SetURL(nsIURI* aURL);
nsresult SetHrefWithBase(const nsString& aHref,
nsIURI* aBase,
PRBool aReplace);
nsresult GetSourceURL(JSContext* cx,
nsresult GetSourceURL(JSContext* cx,
nsIURI** sourceURL);
nsresult CheckURL(nsIURI *url);
nsresult CheckURL(nsIURI *url);
nsIWebShell *mWebShell;
void *mScriptObject;
nsIDocShell *mDocShell; // Weak Reference
void *mScriptObject;
};
#define DOM_CONTROLLER

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

@ -17,27 +17,25 @@
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Travis Bogard <travis@netscape.com>
*/
#include "nsCOMPtr.h"
#include "nscore.h"
#include "nsHistory.h"
#include "nsIDOMWindow.h"
#include "nsIScriptGlobalObject.h"
#include "nsIWebShell.h"
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIDOMHistoryIID, NS_IDOMHISTORY_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
#include "nsIDocShell.h"
//
// History class implementation
//
HistoryImpl::HistoryImpl()
HistoryImpl::HistoryImpl(nsIDocShell* aDocShell) : mScriptObject(nsnull),
mDocShell(aDocShell)
{
NS_INIT_REFCNT();
mWebShell = nsnull;
mScriptObject = nsnull;
}
HistoryImpl::~HistoryImpl()
@ -47,31 +45,11 @@ HistoryImpl::~HistoryImpl()
NS_IMPL_ADDREF(HistoryImpl)
NS_IMPL_RELEASE(HistoryImpl)
nsresult
HistoryImpl::QueryInterface(const nsIID& aIID,
void** aInstancePtrResult)
{
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
if (nsnull == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kIScriptObjectOwnerIID)) {
*aInstancePtrResult = (void*) ((nsIScriptObjectOwner*)this);
AddRef();
return NS_OK;
}
if (aIID.Equals(kIDOMHistoryIID)) {
*aInstancePtrResult = (void*) ((nsIDOMHistory*)this);
AddRef();
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
*aInstancePtrResult = (void*)(nsISupports*)(nsIScriptObjectOwner*)this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_INTERFACE_MAP_BEGIN(HistoryImpl)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIScriptObjectOwner)
NS_INTERFACE_MAP_ENTRY(nsIScriptObjectOwner)
NS_INTERFACE_MAP_ENTRY(nsIDOMHistory)
NS_INTERFACE_MAP_END
NS_IMETHODIMP
HistoryImpl::SetScriptObject(void *aScriptObject)
@ -96,18 +74,17 @@ HistoryImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
}
NS_IMETHODIMP_(void)
HistoryImpl::SetWebShell(nsIWebShell *aWebShell)
HistoryImpl::SetDocShell(nsIDocShell *aDocShell)
{
//mWebShell isn't refcnt'd here. GlobalWindow calls SetWebShell(nsnull)
//when it's told that the WebShell is going to be deleted.
mWebShell = aWebShell;
mDocShell = aDocShell; // Weak Reference
}
NS_IMETHODIMP
HistoryImpl::GetLength(PRInt32* aLength)
{
if (nsnull != mWebShell) {
mWebShell->GetHistoryLength(*aLength);
if (mDocShell) {
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(mDocShell));
webShell->GetHistoryLength(*aLength);
return NS_OK;
}
return NS_ERROR_FAILURE;
@ -119,8 +96,9 @@ HistoryImpl::GetCurrent(nsString& aCurrent)
PRInt32 curIndex;
const PRUnichar* curURL = nsnull;
if (nsnull != mWebShell && NS_OK == mWebShell->GetHistoryIndex(curIndex)) {
mWebShell->GetURL(curIndex, &curURL);
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(mDocShell));
if (webShell && NS_OK == webShell->GetHistoryIndex(curIndex)) {
webShell->GetURL(curIndex, &curURL);
}
aCurrent.SetString(curURL);
@ -133,8 +111,9 @@ HistoryImpl::GetPrevious(nsString& aPrevious)
PRInt32 curIndex;
const PRUnichar* prevURL = nsnull;
if (nsnull != mWebShell && NS_OK == mWebShell->GetHistoryIndex(curIndex)) {
mWebShell->GetURL(curIndex-1, &prevURL);
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(mDocShell));
if (webShell && NS_OK == webShell->GetHistoryIndex(curIndex)) {
webShell->GetURL(curIndex-1, &prevURL);
}
aPrevious.SetString(prevURL);
@ -147,8 +126,9 @@ HistoryImpl::GetNext(nsString& aNext)
PRInt32 curIndex;
const PRUnichar* nextURL = nsnull;
if (nsnull != mWebShell && NS_OK == mWebShell->GetHistoryIndex(curIndex)) {
mWebShell->GetURL(curIndex+1, &nextURL);
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(mDocShell));
if (webShell && NS_OK == webShell->GetHistoryIndex(curIndex)) {
webShell->GetURL(curIndex+1, &nextURL);
}
aNext.SetString(nextURL);
@ -158,8 +138,9 @@ HistoryImpl::GetNext(nsString& aNext)
NS_IMETHODIMP
HistoryImpl::Back()
{
if (nsnull != mWebShell && NS_OK == mWebShell->CanBack()) {
mWebShell->Back();
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(mDocShell));
if (webShell && NS_OK == webShell->CanBack()) {
webShell->Back();
}
return NS_OK;
@ -168,8 +149,9 @@ HistoryImpl::Back()
NS_IMETHODIMP
HistoryImpl::Forward()
{
if (nsnull != mWebShell && NS_OK == mWebShell->CanForward()) {
mWebShell->Forward();
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(mDocShell));
if (webShell && NS_OK == webShell->CanForward()) {
webShell->Forward();
}
return NS_OK;
@ -179,14 +161,15 @@ NS_IMETHODIMP
HistoryImpl::Go(JSContext* cx, jsval* argv, PRUint32 argc)
{
nsresult result = NS_OK;
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(mDocShell));
if (argc > 0) {
if (JSVAL_IS_INT(argv[0])) {
PRInt32 delta = JSVAL_TO_INT(argv[0]);
PRInt32 curIndex;
result = mWebShell->GetHistoryIndex(curIndex);
result = webShell->GetHistoryIndex(curIndex);
if (NS_SUCCEEDED(result)) {
result = mWebShell->GoTo(curIndex + delta);
result = webShell->GoTo(curIndex + delta);
}
}
else {
@ -196,18 +179,18 @@ HistoryImpl::Go(JSContext* cx, jsval* argv, PRUint32 argc)
if (nsnull != jsstr) {
nsAutoString substr(JS_GetStringBytes(jsstr));
result = mWebShell->GetHistoryLength(count);
result = webShell->GetHistoryLength(count);
for (i = 0; (i < count) && NS_SUCCEEDED(result); i++) {
const PRUnichar* urlstr;
nsAutoString url;
// XXX Ownership rules for the string passed back for this
// method are not XPCOM compliant. If they were correct,
// we'd be deallocating the string passed back.
result = mWebShell->GetURL(i, &urlstr);
result = webShell->GetURL(i, &urlstr);
url.SetString(urlstr);
if (-1 != url.Find(substr)) {
result = mWebShell->GoTo(i);
result = webShell->GoTo(i);
break;
}
}

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

@ -28,12 +28,12 @@
#include "nscore.h"
#include "nsIScriptContext.h"
class nsIWebShell;
class nsIDocShell;
// Script "History" object
class HistoryImpl : public nsIScriptObjectOwner, public nsIDOMHistory {
public:
HistoryImpl();
HistoryImpl(nsIDocShell* aDocShell);
virtual ~HistoryImpl();
NS_DECL_ISUPPORTS
@ -41,7 +41,7 @@ public:
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void *aScriptObject);
NS_IMETHOD_(void) SetWebShell(nsIWebShell *aWebShell);
NS_IMETHOD_(void) SetDocShell(nsIDocShell *aDocShell);
NS_IMETHOD GetLength(PRInt32* aLength);
NS_IMETHOD GetCurrent(nsString& aCurrent);
@ -52,7 +52,7 @@ public:
NS_IMETHOD Go(JSContext* cx, jsval* argv, PRUint32 argc);
protected:
nsIWebShell* mWebShell;
nsIDocShell* mDocShell;
void *mScriptObject;
};

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

@ -17,18 +17,19 @@
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Travis Bogard <travis@netscape.com>
* Pierre Phaneuf <pp@ludusdesign.com>
*/
#include "nsGlobalWindow.h"
#include "nsIWebShell.h"
#include "nsIDocShell.h"
#include "nsIURL.h"
#include "nsIIOService.h"
#include "nsIURL.h"
#include "nsIServiceManager.h"
#include "nsNetUtil.h"
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
#include "plstr.h"
#include "prmem.h"
#include "nsCOMPtr.h"
@ -44,12 +45,13 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIDOMLocationIID, NS_IDOMLOCATION_IID);
static NS_DEFINE_IID(kIDOMNSLocationIID, NS_IDOMNSLOCATION_IID);
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
LocationImpl::LocationImpl(nsIWebShell *aWebShell)
LocationImpl::LocationImpl(nsIDocShell *aDocShell)
{
NS_INIT_REFCNT();
mScriptObject = nsnull;
mWebShell = aWebShell;
mDocShell = aDocShell; // Weak Reference
}
LocationImpl::~LocationImpl()
@ -59,41 +61,13 @@ LocationImpl::~LocationImpl()
NS_IMPL_ADDREF(LocationImpl)
NS_IMPL_RELEASE(LocationImpl)
nsresult
LocationImpl::QueryInterface(const nsIID& aIID,
void** aInstancePtrResult)
{
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
if (nsnull == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kIScriptObjectOwnerIID)) {
*aInstancePtrResult = (void*) ((nsIScriptObjectOwner*)this);
AddRef();
return NS_OK;
}
if (aIID.Equals(kIDOMLocationIID)) {
*aInstancePtrResult = (void*) ((nsIDOMLocation*)this);
AddRef();
return NS_OK;
}
if (aIID.Equals(kIDOMNSLocationIID)) {
*aInstancePtrResult = (void*) ((nsIDOMNSLocation*)this);
AddRef();
return NS_OK;
}
if (aIID.Equals(kIJSScriptObjectIID)) {
*aInstancePtrResult = (void*)(nsISupports*)(nsIJSScriptObject*)this;
AddRef();
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
*aInstancePtrResult = (void*)(nsISupports*)(nsIScriptObjectOwner*)this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_INTERFACE_MAP_BEGIN(LocationImpl)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIScriptObjectOwner)
NS_INTERFACE_MAP_ENTRY(nsIScriptObjectOwner)
NS_INTERFACE_MAP_ENTRY(nsIDOMLocation)
NS_INTERFACE_MAP_ENTRY(nsIDOMNSLocation)
NS_INTERFACE_MAP_ENTRY(nsIJSScriptObject)
NS_INTERFACE_MAP_END
nsresult
LocationImpl::SetScriptObject(void *aScriptObject)
@ -108,7 +82,7 @@ LocationImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
NS_ENSURE_ARG_POINTER(aScriptObject);
if (!mScriptObject) {
nsCOMPtr<nsIScriptGlobalObject> global(do_GetInterface(mWebShell));
nsCOMPtr<nsIScriptGlobalObject> global(do_GetInterface(mDocShell));
NS_ENSURE_TRUE(global, NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(NS_NewScriptLocation(aContext,
NS_STATIC_CAST(nsIDOMLocation*, this),global, &mScriptObject),
@ -118,12 +92,9 @@ LocationImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
return NS_OK;
}
NS_IMETHODIMP_(void)
LocationImpl::SetWebShell(nsIWebShell *aWebShell)
NS_IMETHODIMP_(void) LocationImpl::SetDocShell(nsIDocShell *aDocShell)
{
//mWebShell isn't refcnt'd here. GlobalWindow calls SetWebShell(nsnull)
// when it's told that the WebShell is going to be deleted.
mWebShell = aWebShell;
mDocShell = aDocShell; // Weak Reference
}
nsresult
@ -156,7 +127,7 @@ LocationImpl::CheckURL(nsIURI* aURL)
nsresult
LocationImpl::SetURL(nsIURI* aURL)
{
if (nsnull != mWebShell) {
if (mDocShell) {
char* spec;
aURL->GetSpec(&spec);
nsAutoString s = spec;
@ -165,7 +136,8 @@ LocationImpl::SetURL(nsIURI* aURL)
if (NS_FAILED(CheckURL(aURL)))
return NS_ERROR_FAILURE;
return mWebShell->LoadURL(s.GetUnicode(), nsnull, PR_TRUE);
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(mDocShell));
return webShell->LoadURL(s.GetUnicode(), nsnull, PR_TRUE);
}
else {
return NS_OK;
@ -336,14 +308,10 @@ LocationImpl::GetHref(nsString& aHref)
// PRInt32 index;
nsresult result = NS_OK;
if (nsnull != mWebShell) {
if (mDocShell) {
const PRUnichar *href;
/* no need to use session history to get the url for the
* current document. Fix until webshell's generic session history
* is restored. S'd work even otherwise
*/
//mWebShell->GetHistoryIndex(index);
result = mWebShell->GetURL (&href);
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(mDocShell));
result = webShell->GetURL (&href);
aHref = href;
}
@ -388,13 +356,14 @@ LocationImpl::SetHrefWithBase(const nsString& aHref,
}
}
if ((NS_OK == result) && (nsnull != mWebShell)) {
if ((NS_OK == result) && (mDocShell)) {
if (NS_FAILED(CheckURL(newUrl)))
return NS_ERROR_FAILURE;
// Load new URI.
result = mWebShell->LoadURL(newHref.GetUnicode(), nsnull, aReplace);
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(mDocShell));
result = webShell->LoadURL(newHref.GetUnicode(), nsnull, aReplace);
}
return result;
@ -612,13 +581,15 @@ LocationImpl::SetSearch(const nsString& aSearch)
NS_IMETHODIMP
LocationImpl::Reload(PRBool aForceget)
{
nsresult result = NS_OK;
nsresult result = NS_OK;
if (nsnull != mWebShell) {
result = mWebShell->Reload(nsIChannel::LOAD_NORMAL);
}
if(mDocShell)
{
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(mDocShell));
result = webShell->Reload(nsIChannel::LOAD_NORMAL);
}
return result;
return result;
}
NS_IMETHODIMP

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

@ -17,69 +17,48 @@
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Travis Bogard <travis@netscape.com>
*/
#include "nscore.h"
#include "nsScreen.h"
#include "nsIDOMWindow.h"
#include "nsIScriptGlobalObject.h"
#include "nsIWebShell.h"
#include "nsIDocShell.h"
#include "nsIDeviceContext.h"
#include "nsIPresContext.h"
#include "nsCOMPtr.h"
#include "nsIDocumentViewer.h"
#include "nsIDocumentLoader.h"
static NS_DEFINE_IID(kIDocumentViewerIID, NS_IDOCUMENT_VIEWER_IID);
static NS_DEFINE_IID(kIDocumentLoaderIID, NS_IDOCUMENTLOADER_IID);
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIDOMScreenIID, NS_IDOMSCREEN_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
//
// Screen class implementation
//
ScreenImpl::ScreenImpl( nsIWebShell* aWebShell): mWebShell( aWebShell )
ScreenImpl::ScreenImpl( nsIDocShell* aDocShell): mDocShell(aDocShell)
{
NS_INIT_REFCNT();
mScriptObject = nsnull;
NS_IF_ADDREF( mWebShell );
}
ScreenImpl::~ScreenImpl()
{
NS_IF_RELEASE( mWebShell );
}
NS_IMPL_ADDREF(ScreenImpl)
NS_IMPL_RELEASE(ScreenImpl)
nsresult
ScreenImpl::QueryInterface(const nsIID& aIID,
void** aInstancePtrResult)
NS_INTERFACE_MAP_BEGIN(ScreenImpl)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIScriptObjectOwner)
NS_INTERFACE_MAP_ENTRY(nsIScriptObjectOwner)
NS_INTERFACE_MAP_ENTRY(nsIDOMScreen)
NS_INTERFACE_MAP_END
NS_IMETHODIMP ScreenImpl::SetDocShell(nsIDocShell* aDocShell)
{
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
if (nsnull == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kIScriptObjectOwnerIID)) {
*aInstancePtrResult = (void*) ((nsIScriptObjectOwner*)this);
AddRef();
return NS_OK;
}
if (aIID.Equals(kIDOMScreenIID)) {
*aInstancePtrResult = (void*) ((nsIDOMScreen*)this);
AddRef();
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
*aInstancePtrResult = (void*)(nsISupports*)(nsIScriptObjectOwner*)this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
mDocShell = aDocShell; // Weak Reference
return NS_OK;
}
NS_IMETHODIMP
@ -258,23 +237,25 @@ ScreenImpl::GetAvailTop(PRInt32* aAvailTop)
nsIDeviceContext* ScreenImpl::GetDeviceContext()
{
nsCOMPtr<nsIDocumentViewer> docViewer;
nsCOMPtr<nsIContentViewer> contentViewer;
nsIPresContext* presContext = nsnull;
nsIDeviceContext* context = nsnull;
if( mWebShell && NS_SUCCEEDED( mWebShell->GetContentViewer( getter_AddRefs(contentViewer) )) )
{
if ( NS_SUCCEEDED( contentViewer->QueryInterface(kIDocumentViewerIID, getter_AddRefs(docViewer) ) ) )
{
if (NS_SUCCEEDED( docViewer->GetPresContext( presContext ) ) )
{
presContext->GetDeviceContext( &context );
}
NS_IF_RELEASE( presContext );
}
}
return context;
if(!mDocShell)
return nsnull;
nsCOMPtr<nsIContentViewer> contentViewer;
mDocShell->GetContentViewer(getter_AddRefs(contentViewer));
nsCOMPtr<nsIDocumentViewer> docViewer(do_QueryInterface(contentViewer));
if(!docViewer)
return nsnull;
nsCOMPtr<nsIPresContext> presContext;
docViewer->GetPresContext(*getter_AddRefs(presContext));
nsIDeviceContext* context = nsnull;
if(presContext)
presContext->GetDeviceContext(&context);
return context;
}

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

@ -27,15 +27,18 @@
#include "nsISupports.h"
#include "nscore.h"
#include "nsIScriptContext.h"
class nsIWebShell;
class nsIDocShell;
class nsIDeviceContext;
// Script "screen" object
class ScreenImpl : public nsIScriptObjectOwner, public nsIDOMScreen {
public:
ScreenImpl( nsIWebShell* aWebShell );
ScreenImpl( nsIDocShell* aDocShell );
virtual ~ScreenImpl();
NS_IMETHOD SetDocShell(nsIDocShell* aDocShell);
NS_DECL_ISUPPORTS
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
@ -50,11 +53,12 @@ public:
NS_IMETHOD GetAvailLeft(PRInt32* aAvailLeft);
NS_IMETHOD GetAvailTop(PRInt32* aAvailTop);
protected:
nsIDeviceContext* GetDeviceContext();
void *mScriptObject;
nsIWebShell* mWebShell;
nsIDocShell* mDocShell; // Weak Reference
};
#endif /* nsScreen_h___ */

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

@ -80,6 +80,7 @@
#include "nsIEditorController.h"
#include "nsEditorController.h"
#include "nsIControllers.h"
#include "nsIDocShell.h"
///////////////////////////////////////
@ -453,8 +454,9 @@ nsEditorShell::SetContentWindow(nsIDOMWindow* aWin)
if (NS_FAILED(rv) || !globalObj)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIWebShell> webShell;
globalObj->GetWebShell(getter_AddRefs(webShell));
nsCOMPtr<nsIDocShell> docShell;
globalObj->GetDocShell(getter_AddRefs(docShell));
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(docShell));
if (!webShell)
return NS_ERROR_FAILURE;
@ -477,8 +479,9 @@ nsEditorShell::SetWebShellWindow(nsIDOMWindow* aWin)
nsresult rv = NS_OK;
nsCOMPtr<nsIWebShell> webShell;
globalObj->GetWebShell(getter_AddRefs(webShell));
nsCOMPtr<nsIDocShell> docShell;
globalObj->GetDocShell(getter_AddRefs(docShell));
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(docShell));
if (!webShell)
return NS_ERROR_NOT_INITIALIZED;

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

@ -80,6 +80,7 @@
#include "nsIEditorController.h"
#include "nsEditorController.h"
#include "nsIControllers.h"
#include "nsIDocShell.h"
///////////////////////////////////////
@ -453,8 +454,9 @@ nsEditorShell::SetContentWindow(nsIDOMWindow* aWin)
if (NS_FAILED(rv) || !globalObj)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIWebShell> webShell;
globalObj->GetWebShell(getter_AddRefs(webShell));
nsCOMPtr<nsIDocShell> docShell;
globalObj->GetDocShell(getter_AddRefs(docShell));
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(docShell));
if (!webShell)
return NS_ERROR_FAILURE;
@ -477,8 +479,9 @@ nsEditorShell::SetWebShellWindow(nsIDOMWindow* aWin)
nsresult rv = NS_OK;
nsCOMPtr<nsIWebShell> webShell;
globalObj->GetWebShell(getter_AddRefs(webShell));
nsCOMPtr<nsIDocShell> docShell;
globalObj->GetDocShell(getter_AddRefs(docShell));
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(docShell));
if (!webShell)
return NS_ERROR_NOT_INITIALIZED;

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

@ -29,6 +29,7 @@
#include "nsIDOMWindow.h"
#include "nsCOMPtr.h"
#include "nsIWebShell.h"
#include "nsIDocShell.h"
#include "nsIWebShellWindow.h"
#include "nsIScriptGlobalObject.h"
#include "nsWalletEditor.h"
@ -74,10 +75,12 @@ static void DOMWindowToWebShellWindow(
return; // with webWindow unchanged -- its constructor gives it a null ptr
}
nsCOMPtr<nsIScriptGlobalObject> globalScript(do_QueryInterface(DOMWindow));
nsCOMPtr<nsIWebShell> webshell, rootWebshell;
nsCOMPtr<nsIDocShell> docShell;
if (globalScript) {
globalScript->GetWebShell(getter_AddRefs(webshell));
globalScript->GetDocShell(getter_AddRefs(docShell));
}
nsCOMPtr<nsIWebShell> webshell(do_QueryInterface(docShell));
nsCOMPtr<nsIWebShell> rootWebshell;
if(!webshell)
return;
nsCOMPtr<nsIWebShellContainer> topLevelWindow;

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

@ -32,6 +32,7 @@
#include "nsIWebShellWindow.h"
#include "nsIScriptGlobalObject.h"
#include "nsWalletPreview.h"
#include "nsIDocShell.h"
static NS_DEFINE_IID(kWalletServiceCID, NS_WALLETSERVICE_CID);
@ -74,10 +75,12 @@ static void DOMWindowToWebShellWindow(
return; // with webWindow unchanged -- its constructor gives it a null ptr
}
nsCOMPtr<nsIScriptGlobalObject> globalScript(do_QueryInterface(DOMWindow));
nsCOMPtr<nsIWebShell> webshell, rootWebshell;
nsCOMPtr<nsIDocShell> docShell;
if (globalScript) {
globalScript->GetWebShell(getter_AddRefs(webshell));
globalScript->GetDocShell(getter_AddRefs(docShell));
}
nsCOMPtr<nsIWebShell> webshell(do_QueryInterface(docShell));
nsCOMPtr<nsIWebShell> rootWebshell;
if(!webshell)
return;
nsCOMPtr<nsIWebShellContainer> topLevelWindow;

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

@ -777,9 +777,9 @@ NS_IMETHODIMP nsHTMLDocument::SetTitle(const nsString& aTitle)
nsCOMPtr<nsISupports> container;
if (NS_OK == cx->GetContainer(getter_AddRefs(container))) {
if (container) {
nsCOMPtr<nsIBaseWindow> webShell(do_QueryInterface(container));
if(webShell) {
webShell->SetTitle(aTitle.GetUnicode());
nsCOMPtr<nsIBaseWindow> docShell(do_QueryInterface(container));
if(docShell) {
docShell->SetTitle(aTitle.GetUnicode());
}
}
}

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

@ -48,6 +48,7 @@
#include "nsIDOMWindow.h"
#include "nsIContentViewer.h"
#include "nsIContentViewerFile.h"
#include "nsIDocShell.h"
#include "nsXPIDLString.h"
#include "nsICategoryManager.h"
@ -322,8 +323,9 @@ NS_IMETHODIMP nsAddressBook::SetWebShellWindow(nsIDOMWindow *aWin)
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIWebShell> webShell;
globalObj->GetWebShell(getter_AddRefs(webShell));
nsCOMPtr<nsIDocShell> docShell;
globalObj->GetDocShell(getter_AddRefs(docShell));
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(docShell));
if (!webShell)
return NS_ERROR_NOT_INITIALIZED;

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

@ -57,6 +57,7 @@
#include "nsIBrowserWindow.h"
#include "nsIWebShellWindow.h"
#include "nsIScriptGlobalObject.h"
#include "nsIDocShell.h"
// mail
@ -203,14 +204,14 @@ nsMessenger::SetWindow(nsIDOMWindow *aWin, nsIMsgWindow *aMsgWindow)
nsCOMPtr<nsIScriptGlobalObject> globalObj( do_QueryInterface(aWin) );
NS_ENSURE_TRUE(globalObj, NS_ERROR_FAILURE);
nsIWebShell *webShell = nsnull;
nsCOMPtr<nsIWebShell> rootWebShell;
globalObj->GetWebShell(&webShell);
if (nsnull == webShell)
nsCOMPtr<nsIDocShell> docShell;
globalObj->GetDocShell(getter_AddRefs(docShell));
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(docShell));
if (!webShell)
{
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIWebShell> rootWebShell;
webShell->GetRootWebShell(*getter_AddRefs(rootWebShell));
if (nsnull != rootWebShell)
@ -235,7 +236,6 @@ nsMessenger::SetWindow(nsIDOMWindow *aWin, nsIMsgWindow *aMsgWindow)
}
}
NS_RELEASE(webShell);
return NS_OK;
}

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

@ -29,6 +29,7 @@
#include "nsIDOMElement.h"
#include "nsIDOMXULDocument.h"
#include "nsIObserverService.h"
#include "nsIDocShell.h"
#define MSGFEEDBACK_TIMER_INTERVAL 500
@ -80,9 +81,11 @@ nsMsgStatusFeedback::OnStartDocumentLoad(nsIDocumentLoader* aLoader, nsIURI* aUR
nsIDOMWindow *aWindow = mWindow;
nsCOMPtr<nsIScriptGlobalObject>
globalScript(do_QueryInterface(aWindow));
nsCOMPtr<nsIWebShell> webshell, rootWebshell;
nsCOMPtr<nsIDocShell> docShell;
if (globalScript)
globalScript->GetWebShell(getter_AddRefs(webshell));
globalScript->GetDocShell(getter_AddRefs(docShell));
nsCOMPtr<nsIWebShell> webshell(do_QueryInterface(docShell));
nsCOMPtr<nsIWebShell> rootWebshell;
if (webshell)
webshell->GetRootWebShell(*getter_AddRefs(rootWebshell));
if (rootWebshell)
@ -117,9 +120,11 @@ nsMsgStatusFeedback::OnEndDocumentLoad(nsIDocumentLoader* aLoader, nsIChannel* c
nsIDOMWindow *aWindow = mWindow;
nsCOMPtr<nsIScriptGlobalObject>
globalScript(do_QueryInterface(aWindow));
nsCOMPtr<nsIWebShell> webshell, rootWebshell;
nsCOMPtr<nsIDocShell> docShell;
if (globalScript)
globalScript->GetWebShell(getter_AddRefs(webshell));
globalScript->GetDocShell(getter_AddRefs(docShell));
nsCOMPtr<nsIWebShell> webshell(do_QueryInterface(docShell));
nsCOMPtr<nsIWebShell> rootWebshell;
if (webshell)
webshell->GetRootWebShell(*getter_AddRefs(rootWebshell));
if (rootWebshell)
@ -310,9 +315,11 @@ NS_IMETHODIMP nsMsgStatusFeedback::SetWebShell(nsIWebShell *shell, nsIDOMWindow
{
nsCOMPtr<nsIScriptGlobalObject>
globalScript(do_QueryInterface(aWindow));
nsCOMPtr<nsIWebShell> webshell, rootWebshell;
nsCOMPtr<nsIDocShell> docShell;
if (globalScript)
globalScript->GetWebShell(getter_AddRefs(webshell));
globalScript->GetDocShell(getter_AddRefs(docShell));
nsCOMPtr<nsIWebShell> webshell(do_QueryInterface(docShell));
nsCOMPtr<nsIWebShell> rootWebshell;
if (webshell)
{
webshell->GetRootWebShell(mWebShell);

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

@ -191,9 +191,11 @@ NS_IMETHODIMP nsMsgWindow::SetDOMWindow(nsIDOMWindow *aWindow)
nsCOMPtr<nsIScriptGlobalObject>
globalScript(do_QueryInterface(aWindow));
nsCOMPtr<nsIWebShell> webshell, rootWebshell;
nsCOMPtr<nsIDocShell> docShell;
if (globalScript)
globalScript->GetWebShell(getter_AddRefs(webshell));
globalScript->GetDocShell(getter_AddRefs(docShell));
nsCOMPtr<nsIWebShell> webshell(do_QueryInterface(docShell));
nsCOMPtr<nsIWebShell> rootWebshell;
if (webshell)
{
webshell->GetRootWebShell(mRootWebShell);

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

@ -53,6 +53,7 @@
#include "nsIDOMNode.h"
#include "nsEscape.h"
#include "plstr.h"
#include "nsIDocShell.h"
// Defines....
static NS_DEFINE_CID(kMsgQuoteCID, NS_MSGQUOTE_CID);
@ -401,8 +402,9 @@ nsresult nsMsgCompose::Initialize(nsIDOMWindow *aWindow,
if (!globalObj)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIWebShell> webShell;
globalObj->GetWebShell(getter_AddRefs(webShell));
nsCOMPtr<nsIDocShell> docShell;
globalObj->GetDocShell(getter_AddRefs(docShell));
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(docShell));
if (!webShell)
return NS_ERROR_NOT_INITIALIZED;
m_webShell = webShell;

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

@ -57,6 +57,7 @@
#include "nsNetUtil.h"
#include "plstr.h"
#include "nsIWebShell.h"
#include "nsIDocShell.h"
#include "nsIContentViewer.h"
#include "nsIDocumentViewer.h"
#include "nsIPresContext.h"
@ -538,23 +539,12 @@ nsresult nsXULKeyListenerImpl::DoKey(nsIDOMEvent* aKeyEvent, eEventType aEventTy
if (!handled) {
// Give the DOM window's associated key binding doc a shot.
// XXX Check to see if we're in edit mode (how??!)
nsCOMPtr<nsIWebShell> webShell;
nsCOMPtr<nsIPresShell> presShell;
result = piWindow->GetWebShell(getter_AddRefs(webShell));
nsCOMPtr<nsIDocShell> docShell;
result = piWindow->GetDocShell(getter_AddRefs(docShell));
nsCOMPtr<nsIContentViewer> cv;
webShell->GetContentViewer(getter_AddRefs(cv));
if (nsnull != cv) {
nsCOMPtr<nsIDocumentViewer> docv;
cv->QueryInterface(NS_GET_IID(nsIDocumentViewer), getter_AddRefs(docv));
if (nsnull != docv) {
nsCOMPtr<nsIPresContext> cx;
docv->GetPresContext(*getter_AddRefs(cx));
if (nsnull != cx) {
result = cx->GetShell(getter_AddRefs(presShell));
}
}
}
nsCOMPtr<nsIPresShell> presShell;
if(docShell)
docShell->GetPresShell(getter_AddRefs(presShell));
PRBool editorHasBindings = PR_FALSE;
nsCOMPtr<nsIDOMXULDocument> platformDoc;

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

@ -82,8 +82,8 @@ public:
NS_IMETHOD SetContext(nsIScriptContext *aContext);
NS_IMETHOD GetContext(nsIScriptContext **aContext);
NS_IMETHOD SetNewDocument(nsIDOMDocument *aDocument);
NS_IMETHOD SetWebShell(nsIWebShell *aWebShell);
NS_IMETHOD GetWebShell(nsIWebShell **aWebShell);
NS_IMETHOD SetDocShell(nsIDocShell *aDocShell);
NS_IMETHOD GetDocShell(nsIDocShell **aDocShell);
NS_IMETHOD SetOpenerWindow(nsIDOMWindow *aOpener);
NS_IMETHOD SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner);
NS_IMETHOD GetGlobalObjectOwner(nsIScriptGlobalObjectOwner** aOwner);
@ -418,7 +418,7 @@ nsXULPrototypeDocument::SetNewDocument(nsIDOMDocument *aDocument)
NS_IMETHODIMP
nsXULPrototypeDocument::SetWebShell(nsIWebShell *aWebShell)
nsXULPrototypeDocument::SetDocShell(nsIDocShell *aDocShell)
{
NS_NOTREACHED("waaah!");
return NS_ERROR_UNEXPECTED;
@ -426,7 +426,7 @@ nsXULPrototypeDocument::SetWebShell(nsIWebShell *aWebShell)
NS_IMETHODIMP
nsXULPrototypeDocument::GetWebShell(nsIWebShell **aWebShell)
nsXULPrototypeDocument::GetDocShell(nsIDocShell **aDocShell)
{
NS_NOTREACHED("waaah!");
return NS_ERROR_UNEXPECTED;

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

@ -53,6 +53,7 @@
#include "nsIScriptGlobalObject.h"
#include "nsIWebShell.h"
#include "nsIDocShell.h"
#include "nsIContentViewer.h"
#include "nsIDocumentViewer.h"
#include "nsIPresContext.h"
@ -1216,36 +1217,15 @@ nsRDFDOMDataSource::SetWindow(nsIDOMWindow *window) {
return NS_OK;
}
nsCOMPtr<nsIWebShell> webShell;
scriptGlobalObject->GetWebShell(getter_AddRefs(webShell));
if (!webShell) {
nsCOMPtr<nsIDocShell> docShell;
scriptGlobalObject->GetDocShell(getter_AddRefs(docShell));
if (!docShell) {
printf("Couldn't get webshell\n");
return NS_OK;
}
nsCOMPtr<nsIContentViewer> cv;
rv = webShell->GetContentViewer(getter_AddRefs(cv));
if (NS_FAILED(rv)) {
printf("Couldn't get content viewer\n");
return NS_OK;
}
nsCOMPtr<nsIDocumentViewer> dv =
do_QueryInterface(cv, &rv);
if (NS_FAILED(rv)) {
printf("Couldn't get document viewer\n");
return NS_OK;
}
nsCOMPtr<nsIPresContext> pcx;
rv = dv->GetPresContext(*getter_AddRefs(pcx));
if (NS_FAILED(rv)) {
printf("Couldn't get pres context\n");
return NS_OK;
}
nsCOMPtr<nsIPresShell> pshell;
pcx->GetShell(getter_AddRefs(pshell));
rv = docShell->GetPresShell(getter_AddRefs(pshell));
if (NS_FAILED(rv)) {
printf("Couldn't get presshell\n");
return NS_OK;

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

@ -84,6 +84,7 @@
#include "nsIDocShellTreeNode.h"
#include "nsIDocShellTreeOwner.h"
#include "nsCURILoader.h"
#include "nsIDOMWindow.h"
#include "nsIHTTPChannel.h" // add this to the ick include list...we need it to QI for post data interface
#include "nsHTTPEnums.h"
@ -631,7 +632,7 @@ nsWebShell::~nsWebShell()
NS_IF_RELEASE(mContainer);
if (nsnull != mScriptGlobal) {
mScriptGlobal->SetWebShell(nsnull);
mScriptGlobal->SetDocShell(nsnull);
NS_RELEASE(mScriptGlobal);
}
if (nsnull != mScriptContext) {
@ -767,6 +768,13 @@ nsWebShell::GetInterface(const nsIID &aIID, void** aInstancePtr)
NS_ADDREF((nsISupports*)*aInstancePtr);
return NS_OK;
}
else if(aIID.Equals(NS_GET_IID(nsIDOMWindow)))
{
NS_ENSURE_SUCCESS(CreateScriptEnvironment(), NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(mScriptGlobal->QueryInterface(NS_GET_IID(nsIDOMWindow),
aInstancePtr), NS_ERROR_FAILURE);
return NS_OK;
}
else if(mPluginManager) //XXX this seems a little wrong. MMP
rv = mPluginManager->QueryInterface(aIID, aInstancePtr);
@ -3040,7 +3048,7 @@ nsWebShell::CreateScriptEnvironment()
if (NS_FAILED(res)) {
return res;
}
mScriptGlobal->SetWebShell(this);
mScriptGlobal->SetDocShell(this);
mScriptGlobal->SetGlobalObjectOwner(
NS_STATIC_CAST(nsIScriptGlobalObjectOwner*, this));
}
@ -3964,10 +3972,14 @@ NS_IMETHODIMP nsWebShell::GetPositionAndSize(PRInt32* aX, PRInt32* aY,
else
result = mBounds;
*aX = result.x;
*aY = result.y;
*aCX = result.width;
*aCY = result.height;
if(aX)
*aX = result.x;
if(aY)
*aY = result.y;
if(aCX)
*aCX = result.width;
if(aCY)
*aCY = result.height;
return NS_OK;
}

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

@ -167,8 +167,8 @@ NS_IMETHODIMP nsWebBrowserChrome::ShowModal()
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsWebBrowserChrome::GetNewBrowserChrome(PRInt32 aChromeFlags,
nsIWebBrowserChrome** aWebBrowserChrome)
NS_IMETHODIMP nsWebBrowserChrome::GetNewWindow(PRInt32 aChromeFlags,
nsIDocShellTreeItem** aDocShellTreeItem)
{
NS_ERROR("Haven't Implemented this yet");
return NS_ERROR_FAILURE;

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

@ -46,8 +46,9 @@ public:
NS_DECL_NSIWEBBROWSERCHROME
NS_DECL_NSIDOCSHELLTREEOWNER
// nsIDocShellTreeOwner
NS_IMETHOD FindItemWithName(const PRUnichar* aName,
/* NS_IMETHOD FindItemWithName(const PRUnichar* aName,
nsIDocShellTreeItem* aRequestor, nsIDocShellTreeItem** aFoundItem);
NS_IMETHOD ContentShellAdded(nsIDocShellTreeItem* aContentShell,
PRBool aPrimary, const PRUnichar* aID);
@ -56,7 +57,7 @@ public:
NS_IMETHOD ShowModal();
NS_IMETHOD GetNewBrowserChrome(PRInt32 aChromeFlags,
nsIWebBrowserChrome** aWebBrowserChrome);
nsIWebBrowserChrome** aWebBrowserChrome); */
NS_DECL_NSIBASEWINDOW
NS_DECL_NSIINTERFACEREQUESTOR

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

@ -28,6 +28,7 @@
#include "nsIDOMWindow.h"
#include "nsIScriptGlobalObject.h"
#include "nsIWebShell.h"
#include "nsIDocShell.h"
#include "nsIDocumentViewer.h"
#include "nsIPresShell.h"
#include "nsIViewManager.h"
@ -51,29 +52,22 @@ static nsIWidget *parentWidget( nsIDOMWindow *window ) {
if ( window ) {
nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface( window );
if ( sgo ) {
nsCOMPtr<nsIWebShell> webShell;
sgo->GetWebShell( getter_AddRefs( webShell ) );
if ( webShell ) {
nsCOMPtr<nsIContentViewer> contentViewer;
webShell->GetContentViewer( getter_AddRefs( contentViewer ) );
if ( contentViewer ) {
nsCOMPtr<nsIDocumentViewer> documentViewer = do_QueryInterface( contentViewer );
if ( documentViewer ) {
nsCOMPtr<nsIPresShell> presShell;
documentViewer->GetPresShell( *getter_AddRefs( presShell ) );
if ( presShell ) {
nsCOMPtr<nsIViewManager> viewManager;
presShell->GetViewManager( getter_AddRefs( viewManager ) );
if ( viewManager ) {
nsIView *view; // GetRootView doesn't AddRef!
viewManager->GetRootView( view );
if ( view ) {
nsCOMPtr<nsIWidget> widget;
view->GetWidget( *getter_AddRefs( widget ) );
if ( widget ) {
result = widget.get();
}
}
nsCOMPtr<nsIDocShell> docShell;
sgo->GetDocShell( getter_AddRefs( docShell ) );
if ( docShell ) {
nsCOMPtr<nsIPresShell> presShell;
docShell->GetPresShell( getter_AddRefs( presShell ) );
if ( presShell ) {
nsCOMPtr<nsIViewManager> viewManager;
presShell->GetViewManager( getter_AddRefs( viewManager ) );
if ( viewManager ) {
nsIView *view; // GetRootView doesn't AddRef!
viewManager->GetRootView( view );
if ( view ) {
nsCOMPtr<nsIWidget> widget;
view->GetWidget( *getter_AddRefs( widget ) );
if ( widget ) {
result = widget.get();
}
}
}

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

@ -0,0 +1,374 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
*/
#include "nsAppCoresManager.h"
#include "nsAppShellCIDs.h"
#include "nsIAppShellService.h"
#include "nsIEventQueueService.h"
#include "nsIDOMBaseAppCore.h"
#include "nsIDOMWindow.h"
#include "nsIScriptGlobalObject.h"
#include "nsIServiceManager.h"
#include "nsISupports.h"
#include "nsIURL.h"
#include "nsIIOService.h"
#include "nsIURL.h"
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
#include "nsIBrowserWindow.h"
#include "nsIWebShell.h"
#include "nsIDocShell.h"
#include "nsIWebShellWindow.h"
#include "nsIWidget.h"
#include "nsToolkitCore.h"
#include "nsIXULWindowCallbacks.h"
#include "nsIDocumentViewer.h"
#include "nsIDOMXULDocument.h"
#include "nsIDocument.h"
#include "nsIDOMElement.h"
class nsIScriptContext;
static NS_DEFINE_IID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID);
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
static NS_DEFINE_IID(kIEventQueueServiceIID, NS_IEVENTQUEUESERVICE_IID);
static NS_DEFINE_IID(kIDOMBaseAppCoreIID, NS_IDOMBASEAPPCORE_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIToolkitCoreIID, NS_IDOMTOOLKITCORE_IID);
/////////////////////////////////////////////////////////////////////////
// nsToolkitCore
/////////////////////////////////////////////////////////////////////////
nsToolkitCore::nsToolkitCore() {
printf("Created nsToolkitCore\n");
IncInstanceCount();
NS_INIT_REFCNT();
}
nsToolkitCore::~nsToolkitCore() {
DecInstanceCount();
}
NS_IMPL_ADDREF(nsToolkitCore)
NS_IMPL_RELEASE(nsToolkitCore)
NS_IMETHODIMP
nsToolkitCore::QueryInterface(REFNSIID aIID, void** aInstancePtr) {
if (aInstancePtr == NULL)
return NS_ERROR_NULL_POINTER;
*aInstancePtr = NULL;
if (aIID.Equals(kIToolkitCoreIID)) {
*aInstancePtr = (void*) ((nsIDOMToolkitCore*) this);
AddRef();
return NS_OK;
}
return nsBaseAppCore::QueryInterface(aIID, aInstancePtr);
}
NS_IMETHODIMP
nsToolkitCore::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) {
nsresult rv = NS_OK;
NS_PRECONDITION(aScriptObject != nsnull, "null arg");
if (mScriptObject == nsnull) {
nsISupports *core;
rv = QueryInterface(kISupportsIID, (void **)&core);
if (NS_SUCCEEDED(rv)) {
rv = NS_NewScriptToolkitCore(aContext,
(nsISupports *) core,
nsnull,
&mScriptObject);
NS_RELEASE(core);
}
}
*aScriptObject = mScriptObject;
return rv;
}
NS_IMETHODIMP
nsToolkitCore::Init(const nsString& aId) {
nsresult rv;
nsBaseAppCore::Init(aId);
nsIDOMBaseAppCore *core;
rv = QueryInterface(kIDOMBaseAppCoreIID, (void **)&core);
if (NS_SUCCEEDED(rv)) {
nsAppCoresManager* sdm = new nsAppCoresManager();
if (sdm) {
sdm->Add(core);
delete sdm;
return NS_OK;
} else
rv = NS_ERROR_OUT_OF_MEMORY;
NS_RELEASE(core);
}
return rv;
}
NS_IMETHODIMP
nsToolkitCore::ShowDialog(const nsString& aUrl, nsIDOMWindow* aParent) {
nsresult rv;
nsIWebShellWindow *window;
window = nsnull;
nsCOMPtr<nsIURI> urlObj;
NS_WITH_SERVICE(nsIIOService, service, kIOServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = service->NewURI(nsCAutoString(aUrl), nsnull, getter_AddRefs(urlObj));
if (NS_FAILED(rv)) return rv;
if (NS_FAILED(rv))
return rv;
NS_WITH_SERVICE(nsIAppShellService, appShell, kAppShellServiceCID, &rv);
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIWebShellWindow> parent;
DOMWindowToWebShellWindow(aParent, &parent);
window = nsnull;
appShell->CreateTopLevelWindow(parent, urlObj, PR_TRUE, PR_TRUE,
NS_CHROME_ALL_CHROME | NS_CHROME_OPEN_AS_DIALOG,
nsnull, 615, 480, &window);
if (window != nsnull)
window->Show(PR_TRUE);
return rv;
}
NS_IMETHODIMP
nsToolkitCore::ShowWindow(const nsString& aUrl, nsIDOMWindow* aParent) {
nsresult rv;
nsCOMPtr<nsIURI> urlObj;
NS_WITH_SERVICE(nsIIOService, service, kIOServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = service->NewURI(nsCAutoString(aUrl), nsnull, getter_AddRefs(urlObj));
if (NS_FAILED(rv)) return rv;
NS_WITH_SERVICE(nsIAppShellService, appShell, kAppShellServiceCID, &rv);
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIWebShellWindow> parent;
DOMWindowToWebShellWindow(aParent, &parent);
nsCOMPtr<nsIWebShellWindow> window;
appShell->CreateTopLevelWindow(parent, urlObj, PR_TRUE, PR_TRUE,
NS_CHROME_ALL_CHROME, nsnull,
NS_SIZETOCONTENT, NS_SIZETOCONTENT,
getter_AddRefs(window));
return rv;
}
struct nsArgCallbacks : public nsIXULWindowCallbacks {
// Declare implementation of ISupports stuff.
NS_DECL_ISUPPORTS
// Declare implementations of nsIXULWindowCallbacks interface functions.
NS_IMETHOD ConstructBeforeJavaScript(nsIWebShell *aWebShell);
NS_IMETHOD ConstructAfterJavaScript(nsIWebShell *aWebShell) { return NS_OK; }
// Specifics...
nsArgCallbacks( const nsString& aArgs ) : mArgs( aArgs ) { NS_INIT_REFCNT(); }
nsArgCallbacks() { NS_INIT_REFCNT(); }
virtual ~nsArgCallbacks() {}
private:
nsString mArgs;
}; // nsArgCallbacks
// Implement ISupports stuff.
NS_IMPL_ISUPPORTS( nsArgCallbacks, NS_GET_IID(nsIXULWindowCallbacks) );
static const int APP_DEBUG = 0;
static nsresult setAttribute( nsIWebShell *shell,
const char *id,
const char *name,
const nsString &value ) {
nsresult rv = NS_OK;
nsCOMPtr<nsIContentViewer> cv;
rv = shell ? shell->GetContentViewer(getter_AddRefs(cv))
: NS_ERROR_NULL_POINTER;
if ( cv ) {
// Up-cast.
nsCOMPtr<nsIDocumentViewer> docv(do_QueryInterface(cv));
if ( docv ) {
// Get the document from the doc viewer.
nsCOMPtr<nsIDocument> doc;
rv = docv->GetDocument(*getter_AddRefs(doc));
if ( doc ) {
// Up-cast.
nsCOMPtr<nsIDOMXULDocument> xulDoc( do_QueryInterface(doc) );
if ( xulDoc ) {
// Find specified element.
nsCOMPtr<nsIDOMElement> elem;
rv = xulDoc->GetElementById( id, getter_AddRefs(elem) );
if ( elem ) {
// Set the text attribute.
rv = elem->SetAttribute( name, value );
if ( APP_DEBUG ) {
char *p = value.ToNewCString();
delete [] p;
}
if ( rv != NS_OK ) {
if (APP_DEBUG) printf("SetAttribute failed, rv=0x%X\n",(int)rv);
}
} else {
if (APP_DEBUG) printf("GetElementByID failed, rv=0x%X\n",(int)rv);
}
} else {
if (APP_DEBUG) printf("Upcast to nsIDOMXULDocument failed\n");
}
} else {
if (APP_DEBUG) printf("GetDocument failed, rv=0x%X\n",(int)rv);
}
} else {
if (APP_DEBUG) printf("Upcast to nsIDocumentViewer failed\n");
}
} else {
if (APP_DEBUG) printf("GetContentViewer failed, rv=0x%X\n",(int)rv);
}
return rv;
}
// Stick the arg in the document.
NS_IMETHODIMP
nsArgCallbacks::ConstructBeforeJavaScript( nsIWebShell *aWebShell ) {
nsresult rv = NS_OK;
setAttribute( aWebShell, "args", "value", mArgs );
// Trigger dialog arg handling.
setAttribute( aWebShell, "dialog.start", "ready", "true" );
return rv;
}
NS_IMETHODIMP
nsToolkitCore::ShowWindowWithArgs(const nsString& aUrl,
nsIDOMWindow* aParent,
const nsString& aArgs) {
nsresult rv;
nsCOMPtr<nsIURI> urlObj;
NS_WITH_SERVICE(nsIIOService, service, kIOServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = service->NewURI(nsCAutoString(aUrl), nsnull, getter_AddRefs(urlObj));
if (NS_FAILED(rv)) return rv;
NS_WITH_SERVICE(nsIAppShellService, appShell, kAppShellServiceCID, &rv);
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIWebShellWindow> parent;
DOMWindowToWebShellWindow(aParent, &parent);
nsCOMPtr<nsArgCallbacks> cb;
cb = dont_QueryInterface( new nsArgCallbacks( aArgs ) );
nsCOMPtr<nsIWebShellWindow> window;
appShell->CreateTopLevelWindow(parent, urlObj, PR_TRUE, PR_TRUE,
NS_CHROME_ALL_CHROME, cb,
NS_SIZETOCONTENT, NS_SIZETOCONTENT,
getter_AddRefs(window));
return rv;
}
NS_IMETHODIMP
nsToolkitCore::ShowModalDialog(const nsString& aUrl, nsIDOMWindow* aParent) {
nsresult rv;
nsCOMPtr<nsIURI> urlObj;
NS_WITH_SERVICE(nsIIOService, service, kIOServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = service->NewURI(nsCAutoString(aUrl), nsnull, getter_AddRefs(urlObj));
if (NS_FAILED(rv)) return rv;
NS_WITH_SERVICE(nsIAppShellService, appShell, kAppShellServiceCID, &rv);
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIWebShellWindow> parent;
DOMWindowToWebShellWindow(aParent, &parent);
rv = appShell->RunModalDialog(nsnull, parent, urlObj,
NS_CHROME_ALL_CHROME | NS_CHROME_OPEN_AS_DIALOG,
nsnull, 615, 480);
return rv;
}
NS_IMETHODIMP
nsToolkitCore::CloseWindow(nsIDOMWindow* aWindow) {
nsCOMPtr<nsIWebShellWindow> window;
DOMWindowToWebShellWindow(aWindow, &window);
if (window)
window->Close();
return NS_OK;
}
// horribly complicated routine to simply convert from one to the other
void nsToolkitCore::DOMWindowToWebShellWindow(
nsIDOMWindow *DOMWindow,
nsCOMPtr<nsIWebShellWindow> *webWindow) const {
*webWindow = 0;
if (!DOMWindow)
return;
nsCOMPtr<nsIScriptGlobalObject> globalScript(do_QueryInterface(DOMWindow));
nsCOMPtr<nsIDocShell> docShell;
if (globalScript)
globalScript->GetDocShell(getter_AddRefs(docShell));
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(docShell));
if(!webShell)
return;
nsCOMPtr<nsIWebShellContainer> topLevelWindow;
webShell->GetTopLevelWindow(getter_AddRefs(topLevelWindow));
*webWindow = do_QueryInterface(topLevelWindow);
}

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

@ -60,8 +60,26 @@ NS_INTERFACE_MAP_BEGIN(nsChromeTreeOwner)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDocShellTreeOwner)
NS_INTERFACE_MAP_ENTRY(nsIDocShellTreeOwner)
NS_INTERFACE_MAP_ENTRY(nsIBaseWindow)
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
NS_INTERFACE_MAP_END
//*****************************************************************************
// nsChromeTreeOwner::nsIInterfaceRequestor
//*****************************************************************************
NS_IMETHODIMP nsChromeTreeOwner::GetInterface(const nsIID& aIID, void** aSink)
{
NS_ENSURE_ARG_POINTER(aSink);
// if(aIID.Equals(NS_GET_IID(nsISomeInterface)))
// *aSink = NS_STATIC_CAST(nsISomeInterface*, this);
// else
return QueryInterface(aIID, aSink);
NS_IF_ADDREF(((nsISupports*)*aSink));
return NS_OK;
}
//*****************************************************************************
// nsChromeTreeOwner::nsIDocShellTreeOwner
//*****************************************************************************
@ -143,10 +161,10 @@ NS_IMETHODIMP nsChromeTreeOwner::ShowModal()
return mXULWindow->ShowModal();
}
NS_IMETHODIMP nsChromeTreeOwner::GetNewBrowserChrome(PRInt32 aChromeFlags,
nsIWebBrowserChrome** aWebBrowserChrome)
NS_IMETHODIMP nsChromeTreeOwner::GetNewWindow(PRInt32 aChromeFlags,
nsIDocShellTreeItem** aDocShellTreeItem)
{
return mXULWindow->GetNewBrowserChrome(aChromeFlags, aWebBrowserChrome);
return mXULWindow->GetNewWindow(aChromeFlags, aDocShellTreeItem);
}
//*****************************************************************************
@ -170,8 +188,7 @@ NS_IMETHODIMP nsChromeTreeOwner::Create()
NS_IMETHODIMP nsChromeTreeOwner::Destroy()
{
NS_ASSERTION(PR_FALSE, "You can't call this");
return NS_ERROR_UNEXPECTED;
return mXULWindow->Destroy();
}
NS_IMETHODIMP nsChromeTreeOwner::SetPosition(PRInt32 x, PRInt32 y)
@ -213,11 +230,7 @@ NS_IMETHODIMP nsChromeTreeOwner::Repaint(PRBool aForce)
NS_IMETHODIMP nsChromeTreeOwner::GetParentWidget(nsIWidget** aParentWidget)
{
NS_ENSURE_ARG_POINTER(aParentWidget);
NS_ENSURE_STATE(mXULWindow->mWindow);
*aParentWidget = mXULWindow->mWindow->GetParent();
return NS_OK;
return mXULWindow->GetParentWidget(aParentWidget);
}
NS_IMETHODIMP nsChromeTreeOwner::SetParentWidget(nsIWidget* aParentWidget)
@ -228,14 +241,7 @@ NS_IMETHODIMP nsChromeTreeOwner::SetParentWidget(nsIWidget* aParentWidget)
NS_IMETHODIMP nsChromeTreeOwner::GetParentNativeWindow(nativeWindow* aParentNativeWindow)
{
NS_ENSURE_ARG_POINTER(aParentNativeWindow);
nsCOMPtr<nsIWidget> parentWidget;
NS_ENSURE_SUCCESS(GetParentWidget(getter_AddRefs(parentWidget)), NS_ERROR_FAILURE);
*aParentNativeWindow = parentWidget->GetNativeData(NS_NATIVE_WIDGET);
return NS_OK;
return mXULWindow->GetParentNativeWindow(aParentNativeWindow);
}
NS_IMETHODIMP nsChromeTreeOwner::SetParentNativeWindow(nativeWindow aParentNativeWindow)

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

@ -23,20 +23,26 @@
#ifndef nsChromeTreeOwner_h__
#define nsChromeTreeOwner_h__
// Helper Classes
#include "nsCOMPtr.h"
#include "nsIDocShellTreeOwner.h"
// Interfaces Needed
#include "nsIBaseWindow.h"
#include "nsIDocShellTreeOwner.h"
#include "nsIInterfaceRequestor.h"
class nsXULWindow;
class nsChromeTreeOwner : public nsIDocShellTreeOwner,
public nsIBaseWindow
public nsIBaseWindow,
public nsIInterfaceRequestor
{
friend class nsXULWindow;
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_NSIBASEWINDOW
NS_DECL_NSIDOCSHELLTREEOWNER

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

@ -31,6 +31,8 @@
// Interfaces needed to be included
#include "nsIDOMNode.h"
#include "nsIDOMElement.h"
#include "nsIDOMNodeList.h"
#include "nsIDOMXULElement.h"
#include "nsIWindowMediator.h"
// CIDs
@ -41,7 +43,7 @@ static NS_DEFINE_CID(kWindowMediatorCID, NS_WINDOWMEDIATOR_CID);
//*****************************************************************************
nsContentTreeOwner::nsContentTreeOwner(PRBool fPrimary) : mXULWindow(nsnull),
mPrimary(fPrimary)
mPrimary(fPrimary), mChromeMask(0)
{
NS_INIT_REFCNT();
}
@ -61,8 +63,27 @@ NS_INTERFACE_MAP_BEGIN(nsContentTreeOwner)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDocShellTreeOwner)
NS_INTERFACE_MAP_ENTRY(nsIDocShellTreeOwner)
NS_INTERFACE_MAP_ENTRY(nsIBaseWindow)
NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome)
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
NS_INTERFACE_MAP_END
//*****************************************************************************
// nsContentTreeOwner::nsIInterfaceRequestor
//*****************************************************************************
NS_IMETHODIMP nsContentTreeOwner::GetInterface(const nsIID& aIID, void** aSink)
{
NS_ENSURE_ARG_POINTER(aSink);
if(aIID.Equals(NS_GET_IID(nsIWebBrowserChrome)))
*aSink = NS_STATIC_CAST(nsIWebBrowserChrome*, this);
else
return QueryInterface(aIID, aSink);
NS_IF_ADDREF(((nsISupports*)*aSink));
return NS_OK;
}
//*****************************************************************************
// nsContentTreeOwner::nsIDocShellTreeOwner
//*****************************************************************************
@ -143,10 +164,74 @@ NS_IMETHODIMP nsContentTreeOwner::ShowModal()
return mXULWindow->ShowModal();
}
NS_IMETHODIMP nsContentTreeOwner::GetNewBrowserChrome(PRInt32 aChromeFlags,
NS_IMETHODIMP nsContentTreeOwner::GetNewWindow(PRInt32 aChromeFlags,
nsIDocShellTreeItem** aDocShellTreeItem)
{
return mXULWindow->GetNewWindow(aChromeFlags, aDocShellTreeItem);
}
//*****************************************************************************
// nsContentTreeOwner::nsIWebBrowserChrome
//*****************************************************************************
NS_IMETHODIMP nsContentTreeOwner::SetJSStatus(const PRUnichar* aStatus)
{
NS_ERROR("Haven't Implemented this yet");
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsContentTreeOwner::SetJSDefaultStatus(const PRUnichar* aStatus)
{
NS_ERROR("Haven't Implemented this yet");
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsContentTreeOwner::SetOverLink(const PRUnichar* aLink)
{
NS_ERROR("Haven't Implemented this yet");
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsContentTreeOwner::SetWebBrowser(nsIWebBrowser* aWebBrowser)
{
NS_ERROR("Haven't Implemented this yet");
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsContentTreeOwner::GetWebBrowser(nsIWebBrowser** aWebBrowser)
{
NS_ERROR("Haven't Implemented this yet");
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsContentTreeOwner::SetChromeMask(PRUint32 aChromeMask)
{
mChromeMask = aChromeMask;
NS_ENSURE_SUCCESS(ApplyChromeMask(), NS_ERROR_FAILURE);
return NS_OK;
}
NS_IMETHODIMP nsContentTreeOwner::GetChromeMask(PRUint32* aChromeMask)
{
NS_ENSURE_ARG_POINTER(aChromeMask);
*aChromeMask = mChromeMask;
return NS_OK;
}
NS_IMETHODIMP nsContentTreeOwner::GetNewBrowserChrome(nsIWebBrowserChrome**
aWebBrowserChrome)
{
NS_ERROR("Haven't Implemented this yet");
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsContentTreeOwner::FindNamedBrowserChrome(const PRUnichar* aName,
nsIWebBrowserChrome** aWebBrowserChrome)
{
return mXULWindow->GetNewBrowserChrome(aChromeFlags, aWebBrowserChrome);
NS_ERROR("Haven't Implemented this yet");
return NS_ERROR_FAILURE;
}
//*****************************************************************************
@ -170,72 +255,49 @@ NS_IMETHODIMP nsContentTreeOwner::Create()
NS_IMETHODIMP nsContentTreeOwner::Destroy()
{
NS_ASSERTION(PR_FALSE, "You can't call this");
return NS_ERROR_UNEXPECTED;
return mXULWindow->Destroy();
}
NS_IMETHODIMP nsContentTreeOwner::SetPosition(PRInt32 x, PRInt32 y)
NS_IMETHODIMP nsContentTreeOwner::SetPosition(PRInt32 aX, PRInt32 aY)
{
//XXX First Check In
NS_ASSERTION(PR_FALSE, "Not Yet Implemented");
return NS_OK;
return mXULWindow->SetPosition(aX, aY);
}
NS_IMETHODIMP nsContentTreeOwner::GetPosition(PRInt32* x, PRInt32* y)
NS_IMETHODIMP nsContentTreeOwner::GetPosition(PRInt32* aX, PRInt32* aY)
{
NS_ENSURE_ARG_POINTER(x && y);
//XXX First Check In
NS_ASSERTION(PR_FALSE, "Not Yet Implemented");
return NS_OK;
return mXULWindow->GetPosition(aX, aY);
}
NS_IMETHODIMP nsContentTreeOwner::SetSize(PRInt32 cx, PRInt32 cy, PRBool fRepaint)
NS_IMETHODIMP nsContentTreeOwner::SetSize(PRInt32 aCX, PRInt32 aCY, PRBool aRepaint)
{
//XXX First Check In
NS_ASSERTION(PR_FALSE, "Not Yet Implemented");
return NS_OK;
return mXULWindow->SetSize(aCX, aCY, aRepaint);
}
NS_IMETHODIMP nsContentTreeOwner::GetSize(PRInt32* cx, PRInt32* cy)
NS_IMETHODIMP nsContentTreeOwner::GetSize(PRInt32* aCX, PRInt32* aCY)
{
NS_ENSURE_ARG_POINTER(cx && cy);
//XXX First Check In
NS_ASSERTION(PR_FALSE, "Not Yet Implemented");
return NS_OK;
return mXULWindow->GetSize(aCX, aCY);
}
NS_IMETHODIMP nsContentTreeOwner::SetPositionAndSize(PRInt32 x, PRInt32 y, PRInt32 cx,
PRInt32 cy, PRBool fRepaint)
NS_IMETHODIMP nsContentTreeOwner::SetPositionAndSize(PRInt32 aX, PRInt32 aY,
PRInt32 aCX, PRInt32 aCY, PRBool aRepaint)
{
//XXX First Check In
NS_ASSERTION(PR_FALSE, "Not Yet Implemented");
return NS_OK;
return mXULWindow->SetPositionAndSize(aX, aY, aCX, aCY, aRepaint);
}
NS_IMETHODIMP nsContentTreeOwner::GetPositionAndSize(PRInt32* x, PRInt32* y, PRInt32* cx,
PRInt32* cy)
NS_IMETHODIMP nsContentTreeOwner::GetPositionAndSize(PRInt32* aX, PRInt32* aY,
PRInt32* aCX, PRInt32* aCY)
{
//XXX First Check In
NS_ASSERTION(PR_FALSE, "Not Yet Implemented");
return NS_OK;
return mXULWindow->GetPositionAndSize(aX, aY, aCX, aCY);
}
NS_IMETHODIMP nsContentTreeOwner::Repaint(PRBool aForce)
{
//XXX First Check In
NS_ASSERTION(PR_FALSE, "Not Yet Implemented");
return NS_OK;
return mXULWindow->Repaint(aForce);
}
NS_IMETHODIMP nsContentTreeOwner::GetParentWidget(nsIWidget** aParentWidget)
{
NS_ENSURE_ARG_POINTER(aParentWidget);
//XXX First Check In
NS_ASSERTION(PR_FALSE, "Not Yet Implemented");
return NS_OK;
return mXULWindow->GetParentWidget(aParentWidget);
}
NS_IMETHODIMP nsContentTreeOwner::SetParentWidget(nsIWidget* aParentWidget)
@ -246,11 +308,7 @@ NS_IMETHODIMP nsContentTreeOwner::SetParentWidget(nsIWidget* aParentWidget)
NS_IMETHODIMP nsContentTreeOwner::GetParentNativeWindow(nativeWindow* aParentNativeWindow)
{
NS_ENSURE_ARG_POINTER(aParentNativeWindow);
//XXX First Check In
NS_ASSERTION(PR_FALSE, "Not Yet Implemented");
return NS_OK;
return mXULWindow->GetParentNativeWindow(aParentNativeWindow);
}
NS_IMETHODIMP nsContentTreeOwner::SetParentNativeWindow(nativeWindow aParentNativeWindow)
@ -261,18 +319,12 @@ NS_IMETHODIMP nsContentTreeOwner::SetParentNativeWindow(nativeWindow aParentNati
NS_IMETHODIMP nsContentTreeOwner::GetVisibility(PRBool* aVisibility)
{
NS_ENSURE_ARG_POINTER(aVisibility);
//XXX First Check In
NS_ASSERTION(PR_FALSE, "Not Yet Implemented");
return NS_OK;
return mXULWindow->GetVisibility(aVisibility);
}
NS_IMETHODIMP nsContentTreeOwner::SetVisibility(PRBool aVisibility)
{
//XXX First Check In
NS_ASSERTION(PR_FALSE, "Not Yet Implemented");
return NS_OK;
return mXULWindow->SetVisibility(aVisibility);
}
NS_IMETHODIMP nsContentTreeOwner::GetMainWidget(nsIWidget** aMainWidget)
@ -364,6 +416,92 @@ NS_IMETHODIMP nsContentTreeOwner::SetTitle(const PRUnichar* aTitle)
// nsContentTreeOwner: Helpers
//*****************************************************************************
NS_IMETHODIMP nsContentTreeOwner::ApplyChromeMask()
{
if(!mXULWindow->mChromeLoaded)
return NS_OK; // We'll do this later when chrome is loaded
nsCOMPtr<nsIDOMElement> domElement;
mXULWindow->GetDOMElementFromDocShell(mXULWindow->mDocShell,
getter_AddRefs(domElement));
NS_ENSURE_TRUE(domElement, NS_ERROR_FAILURE);
mXULWindow->mWindow->ShowMenuBar(mChromeMask &
nsIWebBrowserChrome::menuBarOn ?
PR_TRUE : PR_FALSE);
// get a list of this document's elements with the chromeclass attribute specified
nsCOMPtr<nsIDOMXULElement> xulRoot(do_QueryInterface(domElement));
NS_ENSURE_TRUE(xulRoot, NS_ERROR_FAILURE);
// todo (maybe) the longer, straight DOM (not RDF) version?
nsCOMPtr<nsIDOMNodeList> chromeNodes;
xulRoot->GetElementsByAttribute("chromeclass", "*",
getter_AddRefs(chromeNodes));
NS_ENSURE_TRUE(chromeNodes, NS_ERROR_FAILURE);
PRUint32 nodeCtr;
PRUint32 nodeCount;
chromeNodes->GetLength(&nodeCount);
for(nodeCtr = 0; nodeCtr < nodeCount; nodeCtr++)
{
nsCOMPtr<nsIDOMNode> domNode;
chromeNodes->Item(nodeCtr, getter_AddRefs(domNode));
nsCOMPtr<nsIDOMElement> domElement(do_QueryInterface(domNode));
if(domElement)
{
nsAutoString chromeClass;
PRBool makeChange;
PRUint32 flag;
// show or hide the element according to its chromeclass and the chromemask
domElement->GetAttribute("chromeclass", chromeClass);
makeChange = PR_FALSE;
if(chromeClass == "menubar")
{
makeChange = PR_TRUE;
flag = mChromeMask & nsIWebBrowserChrome::menuBarOn;
}
else if(chromeClass == "toolbar")
{
makeChange = PR_TRUE;
flag = mChromeMask & nsIWebBrowserChrome::toolBarOn;
}
else if(chromeClass == "location")
{
makeChange = PR_TRUE;
flag = mChromeMask & nsIWebBrowserChrome::locationBarOn;
}
else if(chromeClass == "directories")
{
makeChange = PR_TRUE;
flag = mChromeMask & nsIWebBrowserChrome::personalToolBarOn;
}
else if(chromeClass == "status")
{
makeChange = PR_TRUE;
flag = mChromeMask & nsIWebBrowserChrome::statusBarOn;
}
else if(chromeClass == "extrachrome")
{
makeChange = PR_TRUE;
flag = mChromeMask & nsIWebBrowserChrome::extraChromeOn;
}
if(makeChange)
{
if(flag)
domElement->RemoveAttribute("chromehidden");
else
domElement->SetAttribute("chromehidden", "T");
}
}
}
return NS_OK;
}
//*****************************************************************************
// nsContentTreeOwner: Accessors
//*****************************************************************************

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

@ -23,14 +23,21 @@
#ifndef nsContentTreeOwner_h__
#define nsContentTreeOwner_h__
// Helper Classes
#include "nsCOMPtr.h"
#include "nsIDocShellTreeOwner.h"
// Interfaces Needed
#include "nsIBaseWindow.h"
#include "nsIDocShellTreeOwner.h"
#include "nsIInterfaceRequestor.h"
#include "nsIWebBrowserChrome.h"
class nsXULWindow;
class nsContentTreeOwner : public nsIDocShellTreeOwner,
public nsIBaseWindow
public nsIBaseWindow,
public nsIInterfaceRequestor,
public nsIWebBrowserChrome
{
friend class nsXULWindow;
@ -39,6 +46,8 @@ public:
NS_DECL_NSIBASEWINDOW
NS_DECL_NSIDOCSHELLTREEOWNER
NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_NSIWEBBROWSERCHROME
protected:
nsContentTreeOwner(PRBool fPrimary);
@ -47,9 +56,12 @@ protected:
void XULWindow(nsXULWindow* aXULWindow);
nsXULWindow* XULWindow();
NS_IMETHOD ApplyChromeMask();
protected:
nsXULWindow* mXULWindow;
PRBool mPrimary;
PRUint32 mChromeMask;
};
#endif /* nsContentTreeOwner_h__ */

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

@ -213,12 +213,9 @@ nsWebShellWindow::nsWebShellWindow() : nsXULWindow()
mWebShell = nsnull;
mWindow = nsnull;
mCallbacks = nsnull;
mContinueModalLoop = PR_FALSE;
mChromeInitialized = PR_FALSE;
mLockedUntilChromeLoad = PR_FALSE;
mChromeMask = NS_CHROME_ALL_CHROME;
mIntrinsicallySized = PR_FALSE;
mCreatedVisible = PR_TRUE;
mDebuting = PR_FALSE;
mLoadDefaultPage = PR_TRUE;
}
@ -250,6 +247,7 @@ NS_INTERFACE_MAP_BEGIN(nsWebShellWindow)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_INTERFACE_MAP_ENTRY(nsIXULWindow)
NS_INTERFACE_MAP_ENTRY(nsIBaseWindow)
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
NS_INTERFACE_MAP_END
nsresult nsWebShellWindow::Initialize(nsIWebShellWindow* aParent,
@ -263,7 +261,7 @@ nsresult nsWebShellWindow::Initialize(nsIWebShellWindow* aParent,
nsresult rv;
nsCOMPtr<nsIWidget> parentWidget;
mCreatedVisible = aCreatedVisible;
mShowAfterLoad = aCreatedVisible;
mLoadDefaultPage = aLoadDefaultPage;
// XXX: need to get the default window size from prefs...
@ -372,43 +370,7 @@ nsresult nsWebShellWindow::Initialize(nsIWebShellWindow* aParent,
NS_METHOD
nsWebShellWindow::Close()
{
#ifdef XP_MAC // Anyone still using native menus should add themselves here.
// unregister as document listener
// this is needed for menus
nsCOMPtr<nsIContentViewer> cv;
if ( mWebShell )
mWebShell->GetContentViewer(getter_AddRefs(cv));
if (cv) {
nsCOMPtr<nsIDocumentViewer> docv(do_QueryInterface(cv));
if (!docv)
return NS_OK;
nsCOMPtr<nsIDocument> doc;
docv->GetDocument(*getter_AddRefs(doc));
if (!doc)
return NS_OK;
doc->RemoveObserver(NS_STATIC_CAST(nsIDocumentObserver*, this));
}
#endif
nsresult rv;
NS_WITH_SERVICE(nsIAppShellService, appShell, kAppShellServiceCID, &rv)
if (NS_SUCCEEDED(rv))
appShell->UnregisterTopLevelWindow(this);
// let's make sure the window doesn't get deleted out from under us
// while we are trying to close....this can happen if the webshell
// we close ends up being the last owning reference to this webshell
// window.
nsCOMPtr<nsIWebShellWindow> placeHolder = this;
ExitModalLoop();
nsXULWindow::Destroy();
return rv;
return nsXULWindow::Destroy();
}
@ -577,7 +539,7 @@ nsWebShellWindow::BeginLoadURL(nsIWebShell* aShell, const PRUnichar* aURL)
{
// If loading a new root .xul document, then redo chrome.
if (aShell == mWebShell) {
mChromeInitialized = PR_FALSE;
mChromeLoaded = PR_FALSE;
}
return NS_OK;
}
@ -598,38 +560,6 @@ nsWebShellWindow::EndLoadURL(nsIWebShell* aWebShell, const PRUnichar* aURL,
//----------------------------------------
nsCOMPtr<nsIDOMNode> nsWebShellWindow::FindNamedParentFromDoc(nsIDOMDocument * aDomDoc, const nsString &aName)
{
nsCOMPtr<nsIDOMNode> node; // result.
nsCOMPtr<nsIDOMElement> element;
aDomDoc->GetDocumentElement(getter_AddRefs(element));
if (!element)
return node;
nsCOMPtr<nsIDOMNode> parent(do_QueryInterface(element));
if (!parent)
return node;
parent->GetFirstChild(getter_AddRefs(node));
while (node) {
nsString name;
node->GetNodeName(name);
#ifdef DEBUG_rods
printf("Looking for [%s] [%s]\n", aName.ToNewCString(), name.ToNewCString()); // this leaks
#endif
if (name.Equals(aName))
return node;
nsCOMPtr<nsIDOMNode> oldNode(node);
oldNode->GetNextSibling(getter_AddRefs(node));
}
node = do_QueryInterface(nsnull);
return node;
}
//----------------------------------------
NS_IMETHODIMP nsWebShellWindow::CreateMenu(nsIMenuBar * aMenuBar,
nsIDOMNode * aMenuNode,
@ -1213,7 +1143,10 @@ NS_IMETHODIMP
nsWebShellWindow::NewWebShell(PRUint32 aChromeMask, PRBool aVisible,
nsIWebShell *&aNewWebShell)
{
nsresult rv;
NS_ERROR("Can't use this anymore");
return NS_ERROR_FAILURE;
/* nsresult rv;
NS_WITH_SERVICE(nsIAppShellService, appShell, kAppShellServiceCID, &rv);
if (NS_FAILED(rv))
return rv;
@ -1327,7 +1260,7 @@ nsWebShellWindow::NewWebShell(PRUint32 aChromeMask, PRBool aVisible,
}
}
return rv;
return rv; */
}
@ -1369,46 +1302,7 @@ nsWebShellWindow::FocusAvailable(nsIWebShell* aFocusedWebShell, PRBool& aFocusTa
NS_IMETHODIMP
nsWebShellWindow::Show(PRBool aShow)
{
if (mDebuting)
return NS_OK;
mDebuting = PR_TRUE; // (Show/Focus is recursive)
nsCOMPtr<nsIBaseWindow> shellAsWin(do_QueryInterface(mWebShell));
shellAsWin->SetVisibility(aShow);
mWindow->Show(aShow);
// this may cause problems, focusing the content webshell on every show.
// still, this code's previous position, in OnEndDocumentLoad, was
// forcing the window visible too early. this made the window flash,
// as it was resized, and aggravated a gtk bug in which windows cannot
// be resized after they're made visible. yes, that wants fixing.
// repercussions were myriad. focusing here, instead.
nsCOMPtr<nsIWebShell> contentShell;
GetContentWebShell(getter_AddRefs(contentShell));
if (contentShell) {
nsCOMPtr<nsIDOMWindow> domWindow;
if (NS_SUCCEEDED(ConvertWebShellToDOMWindow(contentShell,
getter_AddRefs(domWindow)))) {
domWindow->Focus();
}
}
nsresult rv;
NS_WITH_SERVICE(nsIWindowMediator, windowMediator, kWindowMediatorCID, &rv);
if ( NS_SUCCEEDED(rv) )
{
windowMediator->UpdateWindowTimeStamp( this );
}
// Hide splash screen (if there is one).
static PRBool splashScreenGone = PR_FALSE;
if ( !splashScreenGone ) {
NS_WITH_SERVICE(nsIAppShellService, appShellService, kAppShellServiceCID, &rv);
if ( NS_SUCCEEDED(rv) && appShellService ) {
appShellService->HideSplashScreen();
}
splashScreenGone = PR_TRUE;
}
mDebuting = PR_FALSE;
return NS_OK;
return nsXULWindow::SetVisibility(aShow);
}
NS_IMETHODIMP
@ -1423,51 +1317,7 @@ nsWebShellWindow::ShowModal()
NS_IMETHODIMP
nsWebShellWindow::ShowModalInternal()
{
nsresult rv;
nsIAppShell *subshell;
// spin up a new application shell: event loops live there
rv = nsComponentManager::CreateInstance(kAppShellCID, nsnull, NS_GET_IID(nsIAppShell), (void**)&subshell);
if (NS_FAILED(rv))
return rv;
subshell->Create(0, nsnull);
subshell->Spinup();
nsIWidget *window = GetWidget();
window->SetModal(PR_TRUE);
NS_ADDREF(window);
mContinueModalLoop = PR_TRUE;
// Push nsnull onto the JSContext stack before we dispatch a native event.
NS_WITH_SERVICE(nsIJSContextStack, stack, "nsThreadJSContextStack",
&rv);
if (NS_SUCCEEDED(rv) && NS_SUCCEEDED(stack->Push(nsnull))) {
while (NS_SUCCEEDED(rv) && mContinueModalLoop) {
void *data;
PRBool isRealEvent,
processEvent;
rv = subshell->GetNativeEvent(isRealEvent, data);
if (NS_SUCCEEDED(rv)) {
window->ModalEventFilter(isRealEvent, data, &processEvent);
if (processEvent)
subshell->DispatchNativeEvent(isRealEvent, data);
}
}
JSContext *cx;
stack->Pop(&cx);
NS_ASSERTION(cx == nsnull, "JSContextStack mismatch");
}
window->SetModal(PR_FALSE);
subshell->Spindown();
NS_RELEASE(window);
NS_RELEASE(subshell);
return rv;
return nsXULWindow::ShowModal();
}
@ -1589,10 +1439,10 @@ nsWebShellWindow::OnEndDocumentLoad(nsIDocumentLoader* loader,
* the mChrome Initialized member to check whether chrome should be
* initialized or not - Radha
*/
if (mChromeInitialized)
if (mChromeLoaded)
return NS_OK;
mChromeInitialized = PR_TRUE;
mChromeLoaded = PR_TRUE;
mLockedUntilChromeLoad = PR_FALSE;
@ -1650,8 +1500,7 @@ nsWebShellWindow::OnEndDocumentLoad(nsIDocumentLoader* loader,
mWebShell->SizeToContent();
// Here's where we service the "show" request initially given in Initialize()
if (mCreatedVisible)
Show(PR_TRUE);
OnChromeLoaded();
return NS_OK;
}
@ -1728,22 +1577,6 @@ nsCOMPtr<nsIDOMNode> nsWebShellWindow::FindNamedDOMNode(const nsString &aName, n
} // nsWebShellWindow::FindNamedDOMNode
//----------------------------------------
nsCOMPtr<nsIDOMNode> nsWebShellWindow::GetParentNodeFromDOMDoc(nsIDOMDocument * aDOMDoc)
{
nsCOMPtr<nsIDOMNode> node; // null
if (nsnull == aDOMDoc) {
return node;
}
nsCOMPtr<nsIDOMElement> element;
aDOMDoc->GetDocumentElement(getter_AddRefs(element));
if (element)
return nsCOMPtr<nsIDOMNode>(do_QueryInterface(element));
return node;
} // nsWebShellWindow::GetParentNodeFromDOMDoc
//----------------------------------------
nsCOMPtr<nsIDOMDocument> nsWebShellWindow::GetNamedDOMDoc(const nsString & aWebShellName)
{

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

@ -217,7 +217,7 @@ public:
NS_IMETHOD GetContentBounds(nsRect& aResult);
NS_IMETHOD GetWindowBounds(nsRect& aResult);
NS_IMETHOD IsIntrinsicallySized(PRBool& aResult);
NS_IMETHOD ShowAfterCreation() { mCreatedVisible = PR_TRUE; return NS_OK; }
NS_IMETHOD ShowAfterCreation() { mShowAfterLoad = PR_TRUE; return NS_OK; }
NS_IMETHOD Show() { return Show(PR_TRUE); }
NS_IMETHOD Hide() { return Show(PR_FALSE); }
NS_IMETHOD SetChrome(PRUint32 aNewChromeMask);
@ -246,10 +246,8 @@ protected:
void LoadMenus(nsIDOMDocument * aDOMDoc, nsIWidget * aParentWindow);
void DynamicLoadMenus(nsIDOMDocument * aDOMDoc, nsIWidget * aParentWindow);
nsCOMPtr<nsIDOMNode> FindNamedParentFromDoc(nsIDOMDocument * aDomDoc, const nsString &aName);
nsCOMPtr<nsIDOMNode> FindNamedDOMNode(const nsString &aName, nsIDOMNode * aParent, PRInt32 & aCount, PRInt32 aEndCount);
nsCOMPtr<nsIDOMDocument> GetNamedDOMDoc(const nsString & aWebShellName);
nsCOMPtr<nsIDOMNode> GetParentNodeFromDOMDoc(nsIDOMDocument * aDOMDoc);
NS_IMETHOD CreateMenu(nsIMenuBar * aMenuBar, nsIDOMNode * aMenuNode, nsString & aMenuName);
void LoadSubMenu(nsIMenu * pParentMenu, nsIDOMElement * menuElement,nsIDOMNode * menuNode);
NS_IMETHOD LoadMenuItem(nsIMenu * pParentMenu, nsIDOMElement * menuitemElement, nsIDOMNode * menuitemNode);
@ -268,19 +266,14 @@ protected:
static nsEventStatus PR_CALLBACK HandleEvent(nsGUIEvent *aEvent);
NS_IMETHODIMP ShowModalInternal();
void ExitModalLoop() { mContinueModalLoop = PR_FALSE; }
nsresult NotifyObservers( const nsString &aTopic, const nsString &someData );
nsIWebShell* mWebShell;
nsCOMPtr<nsIWeakReference> mParentWindow;
nsIXULWindowCallbacks* mCallbacks;
PRBool mContinueModalLoop;
PRBool mLockedUntilChromeLoad;
PRBool mChromeInitialized;
PRUint32 mChromeMask;
PRBool mCreatedVisible; // requested visible at creation
PRBool mDebuting; // being made visible right now
PRBool mLoadDefaultPage;
nsVoidArray mMenuDelegates;

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

@ -24,15 +24,23 @@
#include "nsXULWindow.h"
// Helper classes
#include "nsAppShellCIDs.h"
#include "nsString.h"
#include "nsWidgetsCID.h"
#include "prprf.h"
//Interfaces needed to be included
#include "nsIAppShell.h"
#include "nsIAppShellService.h"
#include "nsIServiceManager.h"
#include "nsIDocumentViewer.h"
#include "nsIDocument.h"
#include "nsIDOMDocument.h"
#include "nsIDOMElement.h"
#include "nsIDOMWindow.h"
#include "nsIInterfaceRequestor.h"
#include "nsIIOService.h"
#include "nsIJSContextStack.h"
#include "nsIWindowMediator.h"
// XXX Get rid of this
@ -40,6 +48,10 @@
#include "nsIWebShellWindow.h"
// CIDs
static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
static NS_DEFINE_CID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID);
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
static NS_DEFINE_CID(kWindowMediatorCID, NS_WINDOWMEDIATOR_CID);
//*****************************************************************************
@ -47,7 +59,9 @@ static NS_DEFINE_CID(kWindowMediatorCID, NS_WINDOWMEDIATOR_CID);
//*****************************************************************************
nsXULWindow::nsXULWindow() : mChromeTreeOwner(nsnull),
mContentTreeOwner(nsnull), mPrimaryContentTreeOwner(nsnull)
mContentTreeOwner(nsnull), mPrimaryContentTreeOwner(nsnull),
mContinueModalLoop(PR_FALSE), mChromeLoaded(PR_FALSE),
mShowAfterLoad(PR_FALSE)
{
NS_INIT_REFCNT();
@ -69,8 +83,28 @@ NS_INTERFACE_MAP_BEGIN(nsXULWindow)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXULWindow)
NS_INTERFACE_MAP_ENTRY(nsIXULWindow)
NS_INTERFACE_MAP_ENTRY(nsIBaseWindow)
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
NS_INTERFACE_MAP_END
//*****************************************************************************
// nsXULWindow::nsIIntefaceRequestor
//*****************************************************************************
NS_IMETHODIMP nsXULWindow::GetInterface(const nsIID& aIID, void** aSink)
{
NS_ENSURE_ARG_POINTER(aSink);
if(aIID.Equals(NS_GET_IID(nsIWebBrowserChrome)) &&
NS_SUCCEEDED(EnsureContentTreeOwner()) &&
NS_SUCCEEDED(mContentTreeOwner->QueryInterface(aIID, aSink)))
return NS_OK;
else
return QueryInterface(aIID, aSink);
NS_IF_ADDREF(((nsISupports*)*aSink));
return NS_OK;
}
//*****************************************************************************
// nsXULWindow::nsIXULWindow
//*****************************************************************************
@ -240,6 +274,44 @@ NS_IMETHODIMP nsXULWindow::Create()
NS_IMETHODIMP nsXULWindow::Destroy()
{
if(!mWindow)
return NS_OK;
#ifdef XP_MAC // Anyone still using native menus should add themselves here.
// unregister as document listener
// this is needed for menus
nsCOMPtr<nsIContentViewer> cv;
if(mDocShell)
mDocShell->GetContentViewer(getter_AddRefs(cv));
nsCOMPtr<nsIDocumentViewer> docv(do_QueryInterface(cv));
if(docv)
{
nsCOMPtr<nsIDocument> doc;
docv->GetDocument(*getter_AddRefs(doc));
if(doc)
doc->RemoveObserver(NS_STATIC_CAST(nsIDocumentObserver*, this));
}
#endif
nsCOMPtr<nsIAppShellService> appShell(do_GetService(kAppShellServiceCID));
//XXXTAB remove this when we convert appshell to talk with nsIXULWindow
nsCOMPtr<nsIWebShellWindow>
webShellWindow(do_QueryInterface(NS_STATIC_CAST(nsIXULWindow*, this)));
if(appShell)
appShell->UnregisterTopLevelWindow(webShellWindow);
// let's make sure the window doesn't get deleted out from under us
// while we are trying to close....this can happen if the docshell
// we close ends up being the last owning reference to this xulwindow
// XXXTAB This shouldn't be an issue anymore because the ownership model
// only goes in one direction. When webshell container is fully removed
// try removing this...
nsCOMPtr<nsIXULWindow> placeHolder = this;
ExitModalLoop();
if(mDocShell)
{
nsCOMPtr<nsIBaseWindow> shellAsWin(do_QueryInterface(mDocShell));
@ -338,8 +410,9 @@ NS_IMETHODIMP nsXULWindow::Repaint(PRBool aForce)
NS_IMETHODIMP nsXULWindow::GetParentWidget(nsIWidget** aParentWidget)
{
NS_ENSURE_ARG_POINTER(aParentWidget);
//XXX First Check In
NS_ASSERTION(PR_FALSE, "Not Yet Implemented");
NS_ENSURE_STATE(mWindow);
*aParentWidget = mWindow->GetParent();
return NS_OK;
}
@ -354,8 +427,11 @@ NS_IMETHODIMP nsXULWindow::GetParentNativeWindow(nativeWindow* aParentNativeWind
{
NS_ENSURE_ARG_POINTER(aParentNativeWindow);
//XXX First Check In
NS_ASSERTION(PR_FALSE, "Not Yet Implemented");
nsCOMPtr<nsIWidget> parentWidget;
NS_ENSURE_SUCCESS(GetParentWidget(getter_AddRefs(parentWidget)), NS_ERROR_FAILURE);
*aParentNativeWindow = parentWidget->GetNativeData(NS_NATIVE_WIDGET);
return NS_OK;
}
@ -377,17 +453,60 @@ NS_IMETHODIMP nsXULWindow::GetVisibility(PRBool* aVisibility)
NS_IMETHODIMP nsXULWindow::SetVisibility(PRBool aVisibility)
{
//XXX First Check In
NS_ASSERTION(PR_FALSE, "Not Yet Implemented");
if(!mChromeLoaded)
{
mShowAfterLoad = aVisibility;
return NS_OK;
}
if(mDebuting)
return NS_OK;
mDebuting = PR_TRUE; // (Show / Focus is recursive)
//XXXTAB Do we really need to show docshell and the window? Isn't
// the window good enough?
nsCOMPtr<nsIBaseWindow> shellAsWin(do_QueryInterface(mDocShell));
shellAsWin->SetVisibility(aVisibility);
mWindow->Show(aVisibility);
// this may cause problems, focusing the content webshell on every show.
// still, this code's previous position, in OnEndDocumentLoad, was
// forcing the window visible too early. this made the window flash,
// as it was resized, and aggravated a gtk bug in which windows cannot
// be resized after they're made visible. yes, that wants fixing.
// repercussions were myriad. focusing here, instead.
nsCOMPtr<nsIDocShellTreeItem> contentShell;
GetPrimaryContentShell(getter_AddRefs(contentShell));
nsCOMPtr<nsIDOMWindow> domWindow(do_GetInterface(contentShell));
if(domWindow)
domWindow->Focus();
nsCOMPtr<nsIWindowMediator> windowMediator(do_GetService(kWindowMediatorCID));
//XXXTAB Update windowMediator to take a nsIXULWindow instead
nsCOMPtr<nsIWebShellWindow>
thisWindow(do_QueryInterface(NS_STATIC_CAST(nsIXULWindow*, this)));
if(windowMediator)
windowMediator->UpdateWindowTimeStamp(thisWindow);
// Hide splash screen (if there is one).
static PRBool splashScreenGone = PR_FALSE;
if(!splashScreenGone)
{
nsCOMPtr<nsIAppShellService> appShellService(do_GetService(kAppShellServiceCID));
if(appShellService)
appShellService->HideSplashScreen();
splashScreenGone = PR_TRUE;
}
mDebuting = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP nsXULWindow::GetMainWidget(nsIWidget** aMainWidget)
{
NS_ENSURE_ARG_POINTER(aMainWidget);
//XXX First Check In
NS_ASSERTION(PR_FALSE, "Not Yet Implemented");
*aMainWidget = mWindow;
NS_IF_ADDREF(*aMainWidget);
return NS_OK;
}
@ -483,6 +602,16 @@ NS_IMETHODIMP nsXULWindow::EnsurePrimaryContentTreeOwner()
return NS_OK;
}
void nsXULWindow::OnChromeLoaded()
{
mChromeLoaded = PR_TRUE;
if(mContentTreeOwner)
mContentTreeOwner->ApplyChromeMask();
if(mShowAfterLoad)
SetVisibility(PR_TRUE);
}
NS_IMETHODIMP nsXULWindow::GetDOMElementFromDocShell(nsIDocShell* aDocShell,
nsIDOMElement** aDOMElement)
{
@ -603,36 +732,211 @@ NS_IMETHODIMP nsXULWindow::ContentShellAdded(nsIDocShellTreeItem* aContentShell,
NS_IMETHODIMP nsXULWindow::SizeShellTo(nsIDocShellTreeItem* aShellItem,
PRInt32 aCX, PRInt32 aCY)
{
// XXXTAB
NS_ERROR("Not Yet Implemented");
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsXULWindow::ShowModal()
{
//XXXTAB
NS_ERROR("Not Yet Implemented");
return NS_ERROR_FAILURE;
}
// XXXTAB This is wrong, we should actually reflow based on the passed in'
// shell. For now we are hacking and doing delta sizing. This is bad
// because it assumes all size we add will go to the shell which probably
// won't happen.
NS_IMETHODIMP nsXULWindow::GetNewBrowserChrome(PRInt32 aChromeFlags,
nsIWebBrowserChrome** aWebBrowserChrome)
{
/*
Tells the implementer of this interface to create a new webBrowserChrome
object for it. Typically this means the implemetor will create a new
top level window that is represented by nsIWebBrowserChrome. This
most often will be called when for instance there is a need for a new
JS window, etc. Soon after this new object is returned, the webBrowser
attribute will checked, if one does not exist, one will be created and
setWebBrowser will be called with the new widget to instantiate in this
new window.
*/
nsCOMPtr<nsIBaseWindow> shellAsWin(do_QueryInterface(aShellItem));
NS_ENSURE_TRUE(shellAsWin, NS_ERROR_FAILURE);
PRInt32 width = 0;
PRInt32 height = 0;
shellAsWin->GetSize(&width, &height);
PRInt32 widthDelta = aCX - width;
PRInt32 heightDelta = aCY - height;
if(widthDelta || heightDelta)
{
PRInt32 winCX = 0;
PRInt32 winCY = 0;
GetSize(&winCX, &winCY);
SetSize(winCX + widthDelta, winCY + heightDelta, PR_FALSE);
PersistPositionAndSize(PR_FALSE, PR_TRUE);
}
//XXX First Check In
NS_ASSERTION(PR_FALSE, "Not Yet Implemented");
return NS_OK;
}
NS_IMETHODIMP nsXULWindow::ShowModal()
{
nsCOMPtr<nsIAppShell> appShell(do_CreateInstance(kAppShellCID));
NS_ENSURE_TRUE(appShell, NS_ERROR_FAILURE);
appShell->Create(0, nsnull);
appShell->Spinup();
nsCOMPtr<nsIWidget> window = mWindow; // Store locally so it doesn't die on
// us
window->SetModal(PR_TRUE);
mContinueModalLoop = PR_TRUE;
nsCOMPtr<nsIJSContextStack> stack(do_GetService("nsThreadJSContextStack"));
nsresult rv = NS_OK;
if(stack && stack->Push(nsnull))
{
while(NS_SUCCEEDED(rv) && mContinueModalLoop)
{
void* data;
PRBool isRealEvent;
PRBool processEvent;
rv = appShell->GetNativeEvent(isRealEvent, data);
if(NS_SUCCEEDED(rv))
{
mWindow->ModalEventFilter(isRealEvent, data, &processEvent);
if(processEvent)
appShell->DispatchNativeEvent(isRealEvent, data);
}
}
JSContext* cx;
stack->Pop(&cx);
NS_ASSERTION(cx == nsnull, "JSContextStack mismatch");
}
else
rv = NS_ERROR_FAILURE;
mContinueModalLoop = PR_FALSE;
window->SetModal(PR_FALSE);
appShell->Spindown();
return NS_OK;
}
NS_IMETHODIMP nsXULWindow::ExitModalLoop()
{
mContinueModalLoop = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP nsXULWindow::GetNewWindow(PRInt32 aChromeFlags,
nsIDocShellTreeItem** aDocShellTreeItem)
{
NS_ENSURE_ARG_POINTER(aDocShellTreeItem);
if(aChromeFlags & nsIWebBrowserChrome::openAsChrome)
return CreateNewChromeWindow(aChromeFlags, aDocShellTreeItem);
else
return CreateNewContentWindow(aChromeFlags, aDocShellTreeItem);
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsXULWindow::CreateNewChromeWindow(PRInt32 aChromeFlags,
nsIDocShellTreeItem** aDocShellTreeItem)
{
nsCOMPtr<nsIAppShellService> appShell(do_GetService(kAppShellServiceCID));
NS_ENSURE_TRUE(appShell, NS_ERROR_FAILURE);
// Just do a normal create of a window and return.
//XXXTAB remove this when appshell talks in terms of nsIXULWindow
nsCOMPtr<nsIWebShellWindow> parent;
if(aChromeFlags & nsIWebBrowserChrome::dependent)
parent = do_QueryInterface(NS_STATIC_CAST(nsIXULWindow*, this));
nsCOMPtr<nsIWebShellWindow> newWindow;
appShell->CreateTopLevelWindow(parent, nsnull, PR_FALSE, PR_FALSE,
aChromeFlags, nsnull, NS_SIZETOCONTENT, NS_SIZETOCONTENT,
getter_AddRefs(newWindow));
nsCOMPtr<nsIXULWindow> xulWindow(do_QueryInterface(newWindow));
NS_ENSURE_TRUE(xulWindow, NS_ERROR_FAILURE);
// XXX Ick, this should be able to go away.....
nsCOMPtr<nsIWebBrowserChrome> browserChrome(do_GetInterface(newWindow));
if(browserChrome)
browserChrome->SetChromeMask(aChromeFlags);
nsCOMPtr<nsIDocShell> docShell;
xulWindow->GetDocShell(getter_AddRefs(docShell));
CallQueryInterface(docShell, aDocShellTreeItem);
return NS_OK;
}
NS_IMETHODIMP nsXULWindow::CreateNewContentWindow(PRInt32 aChromeFlags,
nsIDocShellTreeItem** aDocShellTreeItem)
{
nsCOMPtr<nsIAppShellService> appShell(do_GetService(kAppShellServiceCID));
NS_ENSURE_TRUE(appShell, NS_ERROR_FAILURE);
// We need to create a new top level window and then enter a nested
// loop. Eventually the new window will be told that it has loaded,
// at which time we know it is safe to spin out of the nested loop
// and allow the opening code to proceed.
// First push a nested event queue for event processing from netlib
// onto our UI thread queue stack.
nsEventQueueStack queuePusher;
NS_ENSURE_SUCCESS(queuePusher.Success(), NS_ERROR_FAILURE);
char * urlStr = "chrome://navigator/content/";
nsCOMPtr<nsIIOService> service(do_GetService(kIOServiceCID));
NS_ENSURE_TRUE(service, NS_ERROR_FAILURE);
nsCOMPtr<nsIURI> uri;
service->NewURI(urlStr, nsnull, getter_AddRefs(uri));
NS_ENSURE_TRUE(uri, NS_ERROR_FAILURE);
nsCOMPtr<nsIWebShellWindow> newWindow;
appShell->CreateTopLevelWindow(nsnull, uri, PR_FALSE, PR_FALSE,
aChromeFlags, nsnull, 615, 480,
getter_AddRefs(newWindow));
nsCOMPtr<nsIXULWindow> xulWindow(do_QueryInterface(newWindow));
NS_ENSURE_TRUE(xulWindow, NS_ERROR_FAILURE);
nsCOMPtr<nsIWebBrowserChrome> browserChrome(do_GetInterface(newWindow));
if(browserChrome)
browserChrome->SetChromeMask(aChromeFlags);
nsCOMPtr<nsIAppShell> subShell(do_CreateInstance(kAppShellCID));
NS_ENSURE_TRUE(subShell, NS_ERROR_FAILURE);
subShell->Create(0, nsnull);
subShell->Spinup();
// Specify that we want the window to remain locked until the chrome has loaded.
newWindow->LockUntilChromeLoad();
PRBool locked = PR_FALSE;
newWindow->GetLockedState(locked);
// Push nsnull onto the JSContext stack before we dispatch a native event.
nsCOMPtr<nsIJSContextStack> stack(do_GetService("nsThreadJSContextStack"));
if(stack && NS_SUCCEEDED(stack->Push(nsnull)))
{
nsresult looprv = NS_OK;
while(NS_SUCCEEDED(looprv) && locked)
{
void *data;
PRBool isRealEvent;
looprv = subShell->GetNativeEvent(isRealEvent, data);
subShell->DispatchNativeEvent(isRealEvent, data);
newWindow->GetLockedState(locked);
}
JSContext *cx;
stack->Pop(&cx);
NS_ASSERTION(cx == nsnull, "JSContextStack mismatch");
}
subShell->Spindown();
// We're out of the nested loop.
// During the layout of the new window, all content shells were located and placed
// into the new window's content shell array. Locate the "content area" content
// shell.
xulWindow->GetPrimaryContentShell(aDocShellTreeItem);
return NS_OK;
}
//*****************************************************************************
// nsXULWindow: Accessors
@ -650,5 +954,30 @@ nsContentShellInfo::nsContentShellInfo(const nsString& aID, PRBool aPrimary,
nsContentShellInfo::~nsContentShellInfo()
{
//XXX Set Tree Owner to null if the tree owner is nsXULWindow->mContentTreeOwner
}
//*****************************************************************************
//*** nsEventQueueStack: Object Implementation
//*****************************************************************************
nsEventQueueStack::nsEventQueueStack() : mQueue(nsnull)
{
mService = do_GetService(kEventQueueServiceCID);
if(mService)
mService->PushThreadEventQueue(&mQueue);
}
nsEventQueueStack::~nsEventQueueStack()
{
if(mQueue)
mService->PopThreadEventQueue(mQueue);
mService = nsnull;
}
nsresult nsEventQueueStack::Success()
{
return mQueue ? NS_OK : NS_ERROR_FAILURE;
}

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

@ -33,15 +33,18 @@
#include "nsString.h"
// Interfaces needed
#include "nsIXULWindow.h"
#include "nsIBaseWindow.h"
#include "nsIDocShell.h"
#include "nsIWidget.h"
#include "nsIDocShellTreeItem.h"
#include "nsIEventQueueService.h"
#include "nsIInterfaceRequestor.h"
#include "nsIWidget.h"
#include "nsIXULWindow.h"
// nsXULWindow
class nsXULWindow : public nsIXULWindow, public nsIBaseWindow
class nsXULWindow : public nsIXULWindow, public nsIBaseWindow,
public nsIInterfaceRequestor
{
friend class nsChromeTreeOwner;
friend class nsContentTreeOwner;
@ -49,6 +52,7 @@ friend class nsContentTreeOwner;
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_NSIXULWINDOW
NS_DECL_NSIBASEWINDOW
@ -59,6 +63,8 @@ protected:
NS_IMETHOD EnsureChromeTreeOwner();
NS_IMETHOD EnsureContentTreeOwner();
NS_IMETHOD EnsurePrimaryContentTreeOwner();
void OnChromeLoaded();
NS_IMETHOD GetDOMElementFromDocShell(nsIDocShell* aDocShell,
nsIDOMElement** aDOMElement);
@ -68,8 +74,13 @@ protected:
NS_IMETHOD SizeShellTo(nsIDocShellTreeItem* aShellItem, PRInt32 aCX,
PRInt32 aCY);
NS_IMETHOD ShowModal();
NS_IMETHOD GetNewBrowserChrome(PRInt32 aChromeFlags,
nsIWebBrowserChrome** aWebBrowserChrome);
NS_IMETHOD ExitModalLoop();
NS_IMETHOD GetNewWindow(PRInt32 aChromeFlags,
nsIDocShellTreeItem** aDocShellTreeItem);
NS_IMETHOD CreateNewChromeWindow(PRInt32 aChromeFlags,
nsIDocShellTreeItem** aDocShellTreeItem);
NS_IMETHOD CreateNewContentWindow(PRInt32 aChromeFlags,
nsIDocShellTreeItem** aDocShellTreeItem);
protected:
nsChromeTreeOwner* mChromeTreeOwner;
@ -78,6 +89,10 @@ protected:
nsCOMPtr<nsIWidget> mWindow;
nsCOMPtr<nsIDocShell> mDocShell;
nsVoidArray mContentShells;
PRBool mContinueModalLoop;
PRBool mDebuting; // being made visible right now
PRBool mChromeLoaded; // True when chrome has loaded
PRBool mShowAfterLoad;
};
// nsContentShellInfo
@ -94,4 +109,20 @@ public:
nsCOMPtr<nsIDocShellTreeItem> child; // content shell
};
// nsEventQueueStack
// a little utility object to push an event queue and pop it when it
// goes out of scope. should probably be in a file of utility functions.
class nsEventQueueStack
{
public:
nsEventQueueStack();
~nsEventQueueStack();
nsresult Success();
protected:
nsCOMPtr<nsIEventQueueService> mService;
nsIEventQueue *mQueue;
};
#endif /* nsXULWindow_h__ */

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

@ -188,33 +188,6 @@ NS_INTERFACE_MAP_BEGIN(nsBrowserInstance)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIURIContentListener)
NS_INTERFACE_MAP_END
static
nsIPresShell*
GetPresShellFor(nsIWebShell* aWebShell)
{
nsIPresShell* shell = nsnull;
if (nsnull != aWebShell) {
nsIContentViewer* cv = nsnull;
aWebShell->GetContentViewer(&cv);
if (nsnull != cv) {
nsIDocumentViewer* docv = nsnull;
cv->QueryInterface(kIDocumentViewerIID, (void**) &docv);
if (nsnull != docv) {
nsIPresContext* cx;
docv->GetPresContext(cx);
if (nsnull != cx) {
cx->GetShell(&shell);
NS_RELEASE(cx);
}
NS_RELEASE(docv);
}
NS_RELEASE(cv);
}
}
return shell;
}
NS_IMETHODIMP
nsBrowserAppCore::Init()
{
@ -262,12 +235,12 @@ nsBrowserAppCore::SetDocumentCharset(const PRUnichar *aCharset)
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIWebShell> webShell;
globalObj->GetWebShell(getter_AddRefs(webShell));
if (webShell)
nsCOMPtr<nsIDocShell> docShell;
globalObj->GetDocShell(getter_AddRefs(docShell));
if (docShell)
{
nsCOMPtr<nsIContentViewer> childCV;
NS_ENSURE_SUCCESS(webShell->GetContentViewer(getter_AddRefs(childCV)), NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(docShell->GetContentViewer(getter_AddRefs(childCV)), NS_ERROR_FAILURE);
if (childCV)
{
nsCOMPtr<nsIMarkupDocumentViewer> markupCV = do_QueryInterface(childCV);
@ -782,9 +755,10 @@ static void DOMWindowToWebShellWindow(
return; // with webWindow unchanged -- its constructor gives it a null ptr
nsCOMPtr<nsIScriptGlobalObject> globalScript(do_QueryInterface(DOMWindow));
nsCOMPtr<nsIWebShell> webshell, rootWebshell;
nsCOMPtr<nsIDocShell> docShell;
if (globalScript)
globalScript->GetWebShell(getter_AddRefs(webshell));
globalScript->GetDocShell(getter_AddRefs(docShell));
nsCOMPtr<nsIWebShell> webshell(do_QueryInterface(docShell));
if(!webshell)
return;
nsCOMPtr<nsIWebShellContainer> topLevelWindow;
@ -800,21 +774,20 @@ nsBrowserAppCore::WalletPreview(nsIDOMWindow* aWin, nsIDOMWindow* aForm)
if (! aForm)
return NS_ERROR_NULL_POINTER;
nsIPresShell* shell;
shell = nsnull;
nsCOMPtr<nsIWebShell> webcontent;
nsCOMPtr<nsIScriptGlobalObject> scriptGlobalObject;
nsCOMPtr<nsIScriptGlobalObject> scriptGlobalObject;
scriptGlobalObject = do_QueryInterface(aForm);
scriptGlobalObject->GetWebShell(getter_AddRefs(webcontent));
nsCOMPtr<nsIDocShell> docShell;
scriptGlobalObject->GetDocShell(getter_AddRefs(docShell));
shell = GetPresShellFor(webcontent);
nsCOMPtr<nsIPresShell> presShell;
if(docShell)
docShell->GetPresShell(getter_AddRefs(presShell));
nsIWalletService *walletservice;
nsresult res = nsServiceManager::GetService(kWalletServiceCID,
kIWalletServiceIID,
(nsISupports **)&walletservice);
if (NS_SUCCEEDED(res) && (nsnull != walletservice)) {
res = walletservice->WALLET_Prefill(shell, PR_FALSE);
res = walletservice->WALLET_Prefill(presShell, PR_FALSE);
nsServiceManager::ReleaseService(kWalletServiceCID, walletservice);
if (NS_FAILED(res)) { /* this just means that there was nothing to prefill */
return NS_OK;
@ -894,22 +867,21 @@ nsBrowserAppCore::WalletQuickFillin(nsIDOMWindow* aWin)
if (! aWin)
return NS_ERROR_NULL_POINTER;
nsIPresShell* shell;
shell = nsnull;
nsCOMPtr<nsIWebShell> webcontent;
nsCOMPtr<nsIScriptGlobalObject> scriptGlobalObject;
scriptGlobalObject = do_QueryInterface(aWin);
scriptGlobalObject->GetWebShell(getter_AddRefs(webcontent));
scriptGlobalObject = do_QueryInterface(aWin);
nsCOMPtr<nsIDocShell> docShell;
scriptGlobalObject->GetDocShell(getter_AddRefs(docShell));
shell = GetPresShellFor(webcontent);
nsCOMPtr<nsIPresShell> presShell;
if(docShell)
docShell->GetPresShell(getter_AddRefs(presShell));
nsIWalletService *walletservice;
nsresult res;
res = nsServiceManager::GetService(kWalletServiceCID,
kIWalletServiceIID,
(nsISupports **)&walletservice);
if ((NS_OK == res) && (nsnull != walletservice)) {
res = walletservice->WALLET_Prefill(shell, PR_TRUE);
res = walletservice->WALLET_Prefill(presShell, PR_TRUE);
nsServiceManager::ReleaseService(kWalletServiceCID, walletservice);
return NS_OK;
} else {
@ -924,22 +896,21 @@ nsBrowserAppCore::WalletRequestToCapture(nsIDOMWindow* aWin)
if (! aWin)
return NS_ERROR_NULL_POINTER;
nsIPresShell* shell;
shell = nsnull;
nsCOMPtr<nsIWebShell> webcontent;
nsCOMPtr<nsIScriptGlobalObject> scriptGlobalObject;
scriptGlobalObject = do_QueryInterface(aWin);
scriptGlobalObject->GetWebShell(getter_AddRefs(webcontent));
scriptGlobalObject = do_QueryInterface(aWin);
nsCOMPtr<nsIDocShell> docShell;
scriptGlobalObject->GetDocShell(getter_AddRefs(docShell));
shell = GetPresShellFor(webcontent);
nsCOMPtr<nsIPresShell> presShell;
if(docShell)
docShell->GetPresShell(getter_AddRefs(presShell));
nsIWalletService *walletservice;
nsresult res;
res = nsServiceManager::GetService(kWalletServiceCID,
kIWalletServiceIID,
(nsISupports **)&walletservice);
if ((NS_OK == res) && (nsnull != walletservice)) {
res = walletservice->WALLET_RequestToCapture(shell);
res = walletservice->WALLET_RequestToCapture(presShell);
nsServiceManager::ReleaseService(kWalletServiceCID, walletservice);
return NS_OK;
} else {
@ -1233,9 +1204,10 @@ nsBrowserAppCore::SetContentWindow(nsIDOMWindow* aWin)
if (!globalObj) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIWebShell> webShell;
globalObj->GetWebShell(getter_AddRefs(webShell));
nsCOMPtr<nsIDocShell> docShell;
globalObj->GetDocShell(getter_AddRefs(docShell));
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(docShell));
if (webShell) {
mContentAreaWebShell = webShell;
// NS_ADDREF(mContentAreaWebShell); WE DO NOT OWN THIS
@ -1277,15 +1249,14 @@ nsBrowserAppCore::SetWebShellWindow(nsIDOMWindow* aWin)
return NS_ERROR_FAILURE;
}
nsIWebShell * webShell;
globalObj->GetWebShell(&webShell);
if (nsnull != webShell) {
mWebShell = webShell;
nsCOMPtr<nsIDocShell> docShell;
globalObj->GetDocShell(getter_AddRefs(docShell));
if (docShell) {
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(docShell));
mWebShell = webShell.get();
//NS_ADDREF(mWebShell); WE DO NOT OWN THIS
// inform our top level webshell that we are its parent URI content listener...
nsCOMPtr<nsIDocShell> docShell (do_QueryInterface(mWebShell));
if (docShell)
docShell->SetParentURIContentListener(this);
docShell->SetParentURIContentListener(this);
const PRUnichar * name;
webShell->GetName( &name);
@ -1306,7 +1277,6 @@ nsBrowserAppCore::SetWebShellWindow(nsIDOMWindow* aWin)
}
NS_RELEASE(webShellContainer);
}
NS_RELEASE(webShell);
}
return NS_OK;
}
@ -1977,8 +1947,10 @@ nsBrowserAppCore::PrintPreview()
NS_IMETHODIMP
nsBrowserAppCore::Copy()
{
nsIPresShell * presShell = GetPresShellFor(mContentAreaWebShell);
if (nsnull != presShell) {
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(mContentAreaWebShell));
nsCOMPtr<nsIPresShell> presShell;
docShell->GetPresShell(getter_AddRefs(presShell));
if (presShell) {
presShell->DoCopy();
}