Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/base/nsDOMWindowList.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "nsDOMWindowList.h"
8
9
#include "FlushType.h"
10
#include "nsCOMPtr.h"
11
#include "nsIDocument.h"
12
#include "nsIDOMWindow.h"
13
#include "nsIDocShell.h"
14
#include "nsIInterfaceRequestorUtils.h"
15
#include "nsIScriptGlobalObject.h"
16
#include "nsIWebNavigation.h"
17
18
using namespace mozilla;
19
20
nsDOMWindowList::nsDOMWindowList(nsIDocShell *aDocShell)
21
0
{
22
0
  SetDocShell(aDocShell);
23
0
}
24
25
nsDOMWindowList::~nsDOMWindowList()
26
0
{
27
0
}
28
29
void
30
nsDOMWindowList::SetDocShell(nsIDocShell* aDocShell)
31
0
{
32
0
  mDocShellNode = aDocShell; // Weak Reference
33
0
}
34
35
void
36
nsDOMWindowList::EnsureFresh()
37
0
{
38
0
  nsCOMPtr<nsIWebNavigation> shellAsNav = do_QueryInterface(mDocShellNode);
39
0
40
0
  if (shellAsNav) {
41
0
    nsCOMPtr<nsIDocument> doc;
42
0
    shellAsNav->GetDocument(getter_AddRefs(doc));
43
0
44
0
    if (doc) {
45
0
      doc->FlushPendingNotifications(FlushType::ContentAndNotify);
46
0
    }
47
0
  }
48
0
}
49
50
uint32_t
51
nsDOMWindowList::GetLength()
52
0
{
53
0
  EnsureFresh();
54
0
55
0
  NS_ENSURE_TRUE(mDocShellNode, 0);
56
0
57
0
  int32_t length;
58
0
  nsresult rv = mDocShellNode->GetChildCount(&length);
59
0
  NS_ENSURE_SUCCESS(rv, 0);
60
0
61
0
  return uint32_t(length);
62
0
}
63
64
already_AddRefed<nsPIDOMWindowOuter>
65
nsDOMWindowList::IndexedGetter(uint32_t aIndex)
66
0
{
67
0
  nsCOMPtr<nsIDocShellTreeItem> item = GetDocShellTreeItemAt(aIndex);
68
0
  if (!item) {
69
0
    return nullptr;
70
0
  }
71
0
72
0
  nsCOMPtr<nsPIDOMWindowOuter> window = item->GetWindow();
73
0
  MOZ_ASSERT(window);
74
0
75
0
  return window.forget();
76
0
}
77
78
already_AddRefed<nsPIDOMWindowOuter>
79
nsDOMWindowList::NamedItem(const nsAString& aName)
80
0
{
81
0
  EnsureFresh();
82
0
83
0
  if (!mDocShellNode) {
84
0
    return nullptr;
85
0
  }
86
0
87
0
  nsCOMPtr<nsIDocShellTreeItem> item;
88
0
  mDocShellNode->FindChildWithName(aName, false, false, nullptr,
89
0
                                   nullptr, getter_AddRefs(item));
90
0
91
0
  nsCOMPtr<nsPIDOMWindowOuter> childWindow(do_GetInterface(item));
92
0
  return childWindow.forget();
93
0
}