2001-09-25 22:43:09 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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 17:16:17 +00:00
|
|
|
|
2000-02-14 06:23:02 +00:00
|
|
|
// Local Includes
|
1999-02-01 17:16:17 +00:00
|
|
|
#include "nsDOMWindowList.h"
|
2000-02-14 06:23:02 +00:00
|
|
|
|
|
|
|
// Helper classes
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
|
|
|
// Interfaces needed
|
|
|
|
#include "nsIDocument.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-14 06:23:02 +00:00
|
|
|
#include "nsIDocShell.h"
|
2001-09-05 21:28:38 +00:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2000-02-14 06:23:02 +00:00
|
|
|
#include "nsIScriptGlobalObject.h"
|
|
|
|
#include "nsIWebNavigation.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
|
|
|
{
|
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)
|
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 17:42:36 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
1999-12-17 22:25:22 +00:00
|
|
|
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
|
|
|
{
|
2014-01-06 22:34:15 +00:00
|
|
|
mDocShellNode = aDocShell; // Weak Reference
|
1999-02-01 17:16:17 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-06 07:14:49 +00:00
|
|
|
void
|
|
|
|
nsDOMWindowList::EnsureFresh()
|
1999-02-01 17:16:17 +00:00
|
|
|
{
|
2012-09-06 07:14:49 +00:00
|
|
|
nsCOMPtr<nsIWebNavigation> shellAsNav = do_QueryInterface(mDocShellNode);
|
2002-05-18 00:02:50 +00:00
|
|
|
|
|
|
|
if (shellAsNav) {
|
|
|
|
nsCOMPtr<nsIDOMDocument> domdoc;
|
|
|
|
shellAsNav->GetDocument(getter_AddRefs(domdoc));
|
|
|
|
|
2012-09-06 07:14:49 +00:00
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domdoc);
|
2002-05-18 00:02:50 +00:00
|
|
|
|
|
|
|
if (doc) {
|
2004-05-27 22:08:42 +00:00
|
|
|
doc->FlushPendingNotifications(Flush_ContentAndNotify);
|
2000-02-11 23:08:57 +00:00
|
|
|
}
|
2002-05-18 00:02:50 +00:00
|
|
|
}
|
2012-09-06 07:14:49 +00:00
|
|
|
}
|
|
|
|
|
2012-10-02 08:07:35 +00:00
|
|
|
uint32_t
|
|
|
|
nsDOMWindowList::GetLength()
|
2012-09-06 07:14:49 +00:00
|
|
|
{
|
|
|
|
EnsureFresh();
|
2002-05-18 00:02:50 +00:00
|
|
|
|
2012-10-02 08:07:35 +00:00
|
|
|
NS_ENSURE_TRUE(mDocShellNode, 0);
|
2002-05-18 00:02:50 +00:00
|
|
|
|
2012-10-02 08:07:35 +00:00
|
|
|
int32_t length;
|
|
|
|
nsresult rv = mDocShellNode->GetChildCount(&length);
|
|
|
|
NS_ENSURE_SUCCESS(rv, 0);
|
2000-02-11 23:08:57 +00:00
|
|
|
|
2012-10-02 08:07:35 +00:00
|
|
|
return uint32_t(length);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMWindowList::GetLength(uint32_t* aLength)
|
|
|
|
{
|
|
|
|
*aLength = GetLength();
|
|
|
|
return NS_OK;
|
1999-02-01 17:16:17 +00:00
|
|
|
}
|
|
|
|
|
2012-10-02 08:07:36 +00:00
|
|
|
already_AddRefed<nsIDOMWindow>
|
|
|
|
nsDOMWindowList::IndexedGetter(uint32_t aIndex, bool& aFound)
|
1999-02-01 17:16:17 +00:00
|
|
|
{
|
2012-10-02 08:07:36 +00:00
|
|
|
aFound = false;
|
2001-07-11 09:09:30 +00:00
|
|
|
|
2013-07-09 14:45:13 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> item = GetDocShellTreeItemAt(aIndex);
|
2012-10-02 08:07:36 +00:00
|
|
|
if (!item) {
|
|
|
|
return nullptr;
|
1999-02-01 17:16:17 +00:00
|
|
|
}
|
2012-10-02 08:07:36 +00: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 17:16:17 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 00:16:18 +00:00
|
|
|
nsDOMWindowList::NamedItem(const nsAString& aName, nsIDOMWindow** aReturn)
|
1999-02-01 17:16:17 +00:00
|
|
|
{
|
1999-12-17 22:25:22 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> item;
|
1999-12-03 19:02:31 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
*aReturn = nullptr;
|
2002-05-18 00:02:50 +00:00
|
|
|
|
2012-09-06 07:14:49 +00:00
|
|
|
EnsureFresh();
|
2000-02-11 23:08:57 +00:00
|
|
|
|
2002-05-18 00:02:50 +00:00
|
|
|
if (mDocShellNode) {
|
2001-04-02 19:40:52 +00:00
|
|
|
mDocShellNode->FindChildWithName(PromiseFlatString(aName).get(),
|
2012-07-30 14:20:58 +00:00
|
|
|
false, false, nullptr,
|
|
|
|
nullptr, getter_AddRefs(item));
|
2000-08-23 17:27:06 +00:00
|
|
|
|
2000-02-11 23:08:57 +00:00
|
|
|
nsCOMPtr<nsIScriptGlobalObject> globalObject(do_GetInterface(item));
|
|
|
|
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;
|
|
|
|
}
|