1999-02-01 17:16:17 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* 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/
|
1999-02-01 17:16:17 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* 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.
|
1999-02-01 17:16:17 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1999-02-01 17:16:17 +00:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 03:40:37 +00:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
1999-12-17 22:25:22 +00:00
|
|
|
* Contributor(s):
|
|
|
|
* travis@netscape.com
|
1999-02-01 17:16:17 +00:00
|
|
|
*/
|
|
|
|
|
1999-12-03 19:02:31 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1999-02-01 17:16:17 +00:00
|
|
|
#include "nsDOMWindowList.h"
|
1999-12-17 22:25:22 +00:00
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsIDocShellTreeNode.h"
|
|
|
|
#include "nsIDocShellTreeItem.h"
|
1999-02-01 17:16:17 +00:00
|
|
|
#include "nsIScriptGlobalObject.h"
|
2000-02-11 23:08:57 +00:00
|
|
|
#include "nsIDOMDocument.h"
|
1999-02-01 17:16:17 +00:00
|
|
|
#include "nsIDOMWindow.h"
|
2000-02-11 23:08:57 +00:00
|
|
|
#include "nsIDocument.h"
|
1999-12-03 19:02:31 +00:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
1999-02-01 17:16:17 +00:00
|
|
|
|
1999-12-17 22:25:22 +00:00
|
|
|
nsDOMWindowList::nsDOMWindowList(nsIDocShell *aDocShell)
|
1999-02-01 17:16:17 +00:00
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
mScriptObject = nsnull;
|
1999-12-17 22:25:22 +00:00
|
|
|
SetDocShell(aDocShell);
|
1999-02-01 17:16:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsDOMWindowList::~nsDOMWindowList()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsDOMWindowList)
|
|
|
|
NS_IMPL_RELEASE(nsDOMWindowList)
|
|
|
|
|
1999-12-17 22:25:22 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN(nsDOMWindowList)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMWindowCollection)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIScriptObjectOwner)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMWindowCollection)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
1999-02-01 17:16:17 +00:00
|
|
|
NS_IMETHODIMP
|
1999-12-17 22:25:22 +00:00
|
|
|
nsDOMWindowList::SetDocShell(nsIDocShell* aDocShell)
|
1999-02-01 17:16:17 +00:00
|
|
|
{
|
1999-12-17 22:25:22 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeNode> docShellAsNode(do_QueryInterface(aDocShell));
|
|
|
|
mDocShellNode = docShellAsNode.get(); // Weak Reference
|
1999-02-01 17:16:17 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMWindowList::GetLength(PRUint32* aLength)
|
|
|
|
{
|
|
|
|
nsresult ret;
|
1999-12-17 22:25:22 +00:00
|
|
|
PRInt32 length;
|
1999-02-01 17:16:17 +00:00
|
|
|
|
2000-02-11 23:08:57 +00:00
|
|
|
*aLength = 0;
|
|
|
|
if (mDocShellNode) {
|
|
|
|
nsCOMPtr<nsIDocShell> shell = do_QueryInterface(mDocShellNode);
|
|
|
|
if (shell) {
|
|
|
|
nsCOMPtr<nsIDOMDocument> domdoc;
|
|
|
|
|
|
|
|
shell->GetDocument(getter_AddRefs(domdoc));
|
|
|
|
if (domdoc) {
|
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domdoc);
|
|
|
|
if (doc) {
|
|
|
|
doc->FlushPendingNotifications();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = mDocShellNode->GetChildCount(&length);
|
|
|
|
*aLength = length;
|
|
|
|
}
|
|
|
|
|
1999-02-01 17:16:17 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMWindowList::Item(PRUint32 aIndex, nsIDOMWindow** aReturn)
|
|
|
|
{
|
1999-12-17 22:25:22 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> item;
|
1999-12-03 19:02:31 +00:00
|
|
|
|
2000-02-11 23:08:57 +00:00
|
|
|
*aReturn = nsnull;
|
|
|
|
if (mDocShellNode) {
|
|
|
|
nsCOMPtr<nsIDocShell> shell = do_QueryInterface(mDocShellNode);
|
|
|
|
if (shell) {
|
|
|
|
nsCOMPtr<nsIDOMDocument> domdoc;
|
|
|
|
|
|
|
|
shell->GetDocument(getter_AddRefs(domdoc));
|
|
|
|
if (domdoc) {
|
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domdoc);
|
|
|
|
if (doc) {
|
|
|
|
doc->FlushPendingNotifications();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mDocShellNode->GetChildAt(aIndex, getter_AddRefs(item));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> globalObject(do_GetInterface(item));
|
|
|
|
NS_ASSERTION(globalObject, "Couldn't get to the globalObject");
|
|
|
|
if (globalObject) {
|
|
|
|
CallQueryInterface(globalObject.get(), aReturn);
|
|
|
|
}
|
1999-02-01 17:16:17 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMWindowList::NamedItem(const nsString& aName, nsIDOMWindow** aReturn)
|
|
|
|
{
|
1999-12-17 22:25:22 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> item;
|
1999-12-03 19:02:31 +00:00
|
|
|
|
2000-02-11 23:08:57 +00:00
|
|
|
*aReturn = nsnull;
|
|
|
|
if (mDocShellNode) {
|
|
|
|
nsCOMPtr<nsIDocShell> shell = do_QueryInterface(mDocShellNode);
|
|
|
|
if (shell) {
|
|
|
|
nsCOMPtr<nsIDOMDocument> domdoc;
|
|
|
|
|
|
|
|
shell->GetDocument(getter_AddRefs(domdoc));
|
|
|
|
if (domdoc) {
|
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domdoc);
|
|
|
|
if (doc) {
|
|
|
|
doc->FlushPendingNotifications();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mDocShellNode->FindChildWithName(aName.GetUnicode(), PR_FALSE,
|
|
|
|
nsnull, getter_AddRefs(item));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> globalObject(do_GetInterface(item));
|
|
|
|
NS_ASSERTION(globalObject, "Couldn't get to the globalObject");
|
|
|
|
if (globalObject) {
|
|
|
|
CallQueryInterface(globalObject.get(), aReturn);
|
|
|
|
}
|
1999-02-01 17:16:17 +00:00
|
|
|
}
|
2000-02-11 23:08:57 +00:00
|
|
|
|
1999-02-01 17:16:17 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMWindowList::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
|
|
|
|
{
|
|
|
|
nsresult res = NS_OK;
|
|
|
|
nsIScriptGlobalObject *global = aContext->GetGlobalObject();
|
|
|
|
|
|
|
|
if (nsnull == mScriptObject) {
|
|
|
|
res = NS_NewScriptWindowCollection(aContext, (nsISupports *)(nsIDOMWindowCollection *)this, global, (void**)&mScriptObject);
|
|
|
|
}
|
|
|
|
*aScriptObject = mScriptObject;
|
|
|
|
|
|
|
|
NS_RELEASE(global);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMWindowList::SetScriptObject(void *aScriptObject)
|
|
|
|
{
|
|
|
|
mScriptObject = aScriptObject;
|
|
|
|
return NS_OK;
|
|
|
|
}
|