gecko-dev/dom/base/nsDOMWindowList.cpp

94 строки
2.1 KiB
C++
Исходник Обычный вид История

/* -*- 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"
#include "FlushType.h"
#include "nsCOMPtr.h"
#include "nsIDocument.h"
1999-02-01 20:16:17 +03:00
#include "nsIDOMWindow.h"
#include "nsIDocShell.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIScriptGlobalObject.h"
#include "nsIWebNavigation.h"
1999-02-01 20:16:17 +03:00
using namespace mozilla;
nsDOMWindowList::nsDOMWindowList(nsIDocShell *aDocShell)
1999-02-01 20:16:17 +03:00
{
SetDocShell(aDocShell);
1999-02-01 20:16:17 +03:00
}
nsDOMWindowList::~nsDOMWindowList()
{
}
void
nsDOMWindowList::SetDocShell(nsIDocShell* aDocShell)
1999-02-01 20:16:17 +03:00
{
mDocShellNode = aDocShell; // Weak Reference
1999-02-01 20:16:17 +03:00
}
void
nsDOMWindowList::EnsureFresh()
1999-02-01 20:16:17 +03:00
{
nsCOMPtr<nsIWebNavigation> shellAsNav = do_QueryInterface(mDocShellNode);
if (shellAsNav) {
nsCOMPtr<nsIDocument> doc;
shellAsNav->GetDocument(getter_AddRefs(doc));
if (doc) {
doc->FlushPendingNotifications(FlushType::ContentAndNotify);
}
}
}
uint32_t
nsDOMWindowList::GetLength()
{
EnsureFresh();
NS_ENSURE_TRUE(mDocShellNode, 0);
int32_t length;
nsresult rv = mDocShellNode->GetChildCount(&length);
NS_ENSURE_SUCCESS(rv, 0);
return uint32_t(length);
}
already_AddRefed<nsPIDOMWindowOuter>
nsDOMWindowList::IndexedGetter(uint32_t aIndex)
1999-02-01 20:16:17 +03:00
{
nsCOMPtr<nsIDocShellTreeItem> item = GetDocShellTreeItemAt(aIndex);
if (!item) {
return nullptr;
1999-02-01 20:16:17 +03:00
}
nsCOMPtr<nsPIDOMWindowOuter> window = item->GetWindow();
MOZ_ASSERT(window);
return window.forget();
}
already_AddRefed<nsPIDOMWindowOuter>
nsDOMWindowList::NamedItem(const nsAString& aName)
1999-02-01 20:16:17 +03:00
{
EnsureFresh();
if (!mDocShellNode) {
return nullptr;
1999-02-01 20:16:17 +03:00
}
nsCOMPtr<nsIDocShellTreeItem> item;
mDocShellNode->FindChildWithName(aName, false, false, nullptr,
nullptr, getter_AddRefs(item));
nsCOMPtr<nsPIDOMWindowOuter> childWindow(do_GetInterface(item));
return childWindow.forget();
}