2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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
|
|
|
{
|
2014-01-07 02:34:15 +04:00
|
|
|
mDocShellNode = aDocShell; // 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) {
|
2017-01-05 10:31:56 +03:00
|
|
|
doc->FlushPendingNotifications(FlushType::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);
|
|
|
|
}
|
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
NS_IMETHODIMP
|
2012-10-02 12:07:35 +04:00
|
|
|
nsDOMWindowList::GetLength(uint32_t* aLength)
|
|
|
|
{
|
|
|
|
*aLength = GetLength();
|
|
|
|
return NS_OK;
|
1999-02-01 20:16:17 +03:00
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
already_AddRefed<nsPIDOMWindowOuter>
|
2015-07-17 08:10:35 +03:00
|
|
|
nsDOMWindowList::IndexedGetter(uint32_t aIndex)
|
1999-02-01 20:16:17 +03: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
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> window = item->GetWindow();
|
2012-10-02 12:07:36 +04:00
|
|
|
MOZ_ASSERT(window);
|
|
|
|
|
|
|
|
return window.forget();
|
|
|
|
}
|
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
NS_IMETHODIMP
|
2016-01-30 20:05:36 +03:00
|
|
|
nsDOMWindowList::Item(uint32_t aIndex, mozIDOMWindowProxy** aReturn)
|
2012-10-02 12:07:36 +04:00
|
|
|
{
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> window = IndexedGetter(aIndex);
|
2012-10-02 12:07:36 +04:00
|
|
|
window.forget(aReturn);
|
1999-02-01 20:16:17 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
NS_IMETHODIMP
|
2016-01-30 20:05:36 +03:00
|
|
|
nsDOMWindowList::NamedItem(const nsAString& aName, mozIDOMWindowProxy** 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) {
|
2016-10-15 01:00:47 +03:00
|
|
|
mDocShellNode->FindChildWithName(aName, false, false, nullptr,
|
2012-07-30 18:20:58 +04:00
|
|
|
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;
|
|
|
|
}
|