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
|
|
|
|
|
|
|
#include "nsDOMWindowList.h"
|
2000-02-14 09:23:02 +03:00
|
|
|
|
2017-10-26 12:40:12 +03:00
|
|
|
#include "FlushType.h"
|
2000-02-14 09:23:02 +03:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIDocument.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
|
|
|
|
2017-10-26 12:40:12 +03:00
|
|
|
using namespace mozilla;
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-05-25 06:32:19 +03:00
|
|
|
void
|
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
|
|
|
}
|
|
|
|
|
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) {
|
2018-05-11 20:46:15 +03:00
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
shellAsNav->GetDocument(getter_AddRefs(doc));
|
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);
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2018-05-25 06:32:19 +03:00
|
|
|
already_AddRefed<nsPIDOMWindowOuter>
|
|
|
|
nsDOMWindowList::NamedItem(const nsAString& aName)
|
1999-02-01 20:16:17 +03:00
|
|
|
{
|
2012-09-06 11:14:49 +04:00
|
|
|
EnsureFresh();
|
2000-02-12 02:08:57 +03:00
|
|
|
|
2018-05-25 06:32:19 +03:00
|
|
|
if (!mDocShellNode) {
|
|
|
|
return nullptr;
|
1999-02-01 20:16:17 +03:00
|
|
|
}
|
2000-02-12 02:08:57 +03:00
|
|
|
|
2018-05-25 06:32:19 +03:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> item;
|
|
|
|
mDocShellNode->FindChildWithName(aName, false, false, nullptr,
|
|
|
|
nullptr, getter_AddRefs(item));
|
|
|
|
|
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> childWindow(do_GetInterface(item));
|
|
|
|
return childWindow.forget();
|
|
|
|
}
|