2001-09-26 02:43:09 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-02-01 20:16:17 +03:00
|
|
|
|
2000-02-14 09:23:02 +03:00
|
|
|
// Local Includes
|
1999-02-01 20:16:17 +03:00
|
|
|
#include "nsDOMWindowList.h"
|
2000-02-14 09:23:02 +03:00
|
|
|
|
|
|
|
// Helper classes
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
|
|
|
// Interfaces needed
|
|
|
|
#include "nsIDocument.h"
|
2000-02-12 02:08:57 +03:00
|
|
|
#include "nsIDOMDocument.h"
|
1999-02-01 20:16:17 +03:00
|
|
|
#include "nsIDOMWindow.h"
|
2000-02-14 09:23:02 +03:00
|
|
|
#include "nsIDocShell.h"
|
2001-09-06 01:28:38 +04:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2000-02-14 09:23:02 +03:00
|
|
|
#include "nsIScriptGlobalObject.h"
|
|
|
|
#include "nsIWebNavigation.h"
|
1999-02-01 20:16:17 +03:00
|
|
|
|
1999-12-18 01:25:22 +03:00
|
|
|
nsDOMWindowList::nsDOMWindowList(nsIDocShell *aDocShell)
|
1999-02-01 20:16:17 +03:00
|
|
|
{
|
1999-12-18 01:25:22 +03:00
|
|
|
SetDocShell(aDocShell);
|
1999-02-01 20:16:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsDOMWindowList::~nsDOMWindowList()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsDOMWindowList)
|
|
|
|
NS_IMPL_RELEASE(nsDOMWindowList)
|
|
|
|
|
1999-12-18 01:25:22 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN(nsDOMWindowList)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMWindowCollection)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
1999-12-18 01:25:22 +03:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
1999-02-01 20:16:17 +03:00
|
|
|
NS_IMETHODIMP
|
1999-12-18 01:25:22 +03:00
|
|
|
nsDOMWindowList::SetDocShell(nsIDocShell* aDocShell)
|
1999-02-01 20:16:17 +03:00
|
|
|
{
|
1999-12-18 01:25:22 +03:00
|
|
|
nsCOMPtr<nsIDocShellTreeNode> docShellAsNode(do_QueryInterface(aDocShell));
|
2002-05-18 04:02:50 +04:00
|
|
|
mDocShellNode = docShellAsNode; // Weak Reference
|
1999-02-01 20:16:17 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-06 11:14:49 +04:00
|
|
|
void
|
|
|
|
nsDOMWindowList::EnsureFresh()
|
1999-02-01 20:16:17 +03:00
|
|
|
{
|
2012-09-06 11:14:49 +04:00
|
|
|
nsCOMPtr<nsIWebNavigation> shellAsNav = do_QueryInterface(mDocShellNode);
|
2002-05-18 04:02:50 +04:00
|
|
|
|
|
|
|
if (shellAsNav) {
|
|
|
|
nsCOMPtr<nsIDOMDocument> domdoc;
|
|
|
|
shellAsNav->GetDocument(getter_AddRefs(domdoc));
|
|
|
|
|
2012-09-06 11:14:49 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domdoc);
|
2002-05-18 04:02:50 +04:00
|
|
|
|
|
|
|
if (doc) {
|
2004-05-28 02:08:42 +04:00
|
|
|
doc->FlushPendingNotifications(Flush_ContentAndNotify);
|
2000-02-12 02:08:57 +03:00
|
|
|
}
|
2002-05-18 04:02:50 +04:00
|
|
|
}
|
2012-09-06 11:14:49 +04:00
|
|
|
}
|
|
|
|
|
2012-10-02 12:07:35 +04:00
|
|
|
uint32_t
|
|
|
|
nsDOMWindowList::GetLength()
|
2012-09-06 11:14:49 +04:00
|
|
|
{
|
|
|
|
EnsureFresh();
|
2002-05-18 04:02:50 +04:00
|
|
|
|
2012-10-02 12:07:35 +04:00
|
|
|
NS_ENSURE_TRUE(mDocShellNode, 0);
|
2002-05-18 04:02:50 +04:00
|
|
|
|
2012-10-02 12:07:35 +04:00
|
|
|
int32_t length;
|
|
|
|
nsresult rv = mDocShellNode->GetChildCount(&length);
|
|
|
|
NS_ENSURE_SUCCESS(rv, 0);
|
2000-02-12 02:08:57 +03:00
|
|
|
|
2012-10-02 12:07:35 +04:00
|
|
|
return uint32_t(length);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMWindowList::GetLength(uint32_t* aLength)
|
|
|
|
{
|
|
|
|
*aLength = GetLength();
|
|
|
|
return NS_OK;
|
1999-02-01 20:16:17 +03:00
|
|
|
}
|
|
|
|
|
2012-10-02 12:07:36 +04:00
|
|
|
already_AddRefed<nsIDOMWindow>
|
|
|
|
nsDOMWindowList::IndexedGetter(uint32_t aIndex, bool& aFound)
|
1999-02-01 20:16:17 +03:00
|
|
|
{
|
2012-10-02 12:07:36 +04:00
|
|
|
aFound = false;
|
2001-07-11 13:09:30 +04:00
|
|
|
|
2013-07-09 18:45:13 +04:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> item = GetDocShellTreeItemAt(aIndex);
|
2012-10-02 12:07:36 +04:00
|
|
|
if (!item) {
|
|
|
|
return nullptr;
|
1999-02-01 20:16:17 +03:00
|
|
|
}
|
2012-10-02 12:07:36 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMWindow> window = do_GetInterface(item);
|
|
|
|
MOZ_ASSERT(window);
|
|
|
|
|
|
|
|
aFound = true;
|
|
|
|
return window.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMWindowList::Item(uint32_t aIndex, nsIDOMWindow** aReturn)
|
|
|
|
{
|
|
|
|
bool found;
|
|
|
|
nsCOMPtr<nsIDOMWindow> window = IndexedGetter(aIndex, found);
|
|
|
|
window.forget(aReturn);
|
1999-02-01 20:16:17 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 03:16:18 +03:00
|
|
|
nsDOMWindowList::NamedItem(const nsAString& aName, nsIDOMWindow** aReturn)
|
1999-02-01 20:16:17 +03:00
|
|
|
{
|
1999-12-18 01:25:22 +03:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> item;
|
1999-12-03 22:02:31 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
*aReturn = nullptr;
|
2002-05-18 04:02:50 +04:00
|
|
|
|
2012-09-06 11:14:49 +04:00
|
|
|
EnsureFresh();
|
2000-02-12 02:08:57 +03:00
|
|
|
|
2002-05-18 04:02:50 +04:00
|
|
|
if (mDocShellNode) {
|
2001-04-02 23:40:52 +04:00
|
|
|
mDocShellNode->FindChildWithName(PromiseFlatString(aName).get(),
|
2012-07-30 18:20:58 +04:00
|
|
|
false, false, nullptr,
|
|
|
|
nullptr, getter_AddRefs(item));
|
2000-08-23 21:27:06 +04:00
|
|
|
|
2000-02-12 02:08:57 +03:00
|
|
|
nsCOMPtr<nsIScriptGlobalObject> globalObject(do_GetInterface(item));
|
|
|
|
if (globalObject) {
|
|
|
|
CallQueryInterface(globalObject.get(), aReturn);
|
|
|
|
}
|
1999-02-01 20:16:17 +03:00
|
|
|
}
|
2000-02-12 02:08:57 +03:00
|
|
|
|
1999-02-01 20:16:17 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|