Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/docshell/base/nsDocShellEnumerator.h
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
#ifndef nsDocShellEnumerator_h___
8
#define nsDocShellEnumerator_h___
9
10
#include "nsSimpleEnumerator.h"
11
#include "nsTArray.h"
12
#include "nsIWeakReferenceUtils.h"
13
14
class nsIDocShellTreeItem;
15
16
/*
17
// {13cbc281-35ae-11d5-be5b-bde0edece43c}
18
#define NS_DOCSHELL_FORWARDS_ENUMERATOR_CID  \
19
{ 0x13cbc281, 0x35ae, 0x11d5, { 0xbe, 0x5b, 0xbd, 0xe0, 0xed, 0xec, 0xe4, 0x3c } }
20
21
#define NS_DOCSHELL_FORWARDS_ENUMERATOR_CONTRACTID \
22
"@mozilla.org/docshell/enumerator-forwards;1"
23
24
// {13cbc282-35ae-11d5-be5b-bde0edece43c}
25
#define NS_DOCSHELL_BACKWARDS_ENUMERATOR_CID  \
26
{ 0x13cbc282, 0x35ae, 0x11d5, { 0xbe, 0x5b, 0xbd, 0xe0, 0xed, 0xec, 0xe4, 0x3c } }
27
28
#define NS_DOCSHELL_BACKWARDS_ENUMERATOR_CONTRACTID \
29
"@mozilla.org/docshell/enumerator-backwards;1"
30
*/
31
32
class nsDocShellEnumerator : public nsSimpleEnumerator
33
{
34
protected:
35
  enum
36
  {
37
    enumerateForwards,
38
    enumerateBackwards
39
  };
40
41
  virtual ~nsDocShellEnumerator();
42
43
public:
44
  explicit nsDocShellEnumerator(int32_t aEnumerationDirection);
45
46
  // nsISimpleEnumerator
47
  NS_DECL_NSISIMPLEENUMERATOR
48
49
0
  const nsID& DefaultInterface() override { return NS_GET_IID(nsIDocShell); }
50
51
public:
52
  nsresult GetEnumerationRootItem(nsIDocShellTreeItem** aEnumerationRootItem);
53
  nsresult SetEnumerationRootItem(nsIDocShellTreeItem* aEnumerationRootItem);
54
55
  nsresult GetEnumDocShellType(int32_t* aEnumerationItemType);
56
  nsresult SetEnumDocShellType(int32_t aEnumerationItemType);
57
58
  nsresult First();
59
60
protected:
61
  nsresult EnsureDocShellArray();
62
  nsresult ClearState();
63
64
  nsresult BuildDocShellArray(nsTArray<nsWeakPtr>& aItemArray);
65
  virtual nsresult BuildArrayRecursive(nsIDocShellTreeItem* aItem,
66
                                       nsTArray<nsWeakPtr>& aItemArray) = 0;
67
68
protected:
69
  nsWeakPtr mRootItem;  // weak ref!
70
71
  nsTArray<nsWeakPtr> mItemArray;  // flattened list of items with matching type
72
  uint32_t mCurIndex;
73
74
  int32_t mDocShellType;  // only want shells of this type
75
  bool mArrayValid;  // is mItemArray up to date?
76
77
  const int8_t mEnumerationDirection;
78
};
79
80
class nsDocShellForwardsEnumerator : public nsDocShellEnumerator
81
{
82
public:
83
  nsDocShellForwardsEnumerator()
84
    : nsDocShellEnumerator(enumerateForwards)
85
0
  {
86
0
  }
87
88
protected:
89
  virtual nsresult BuildArrayRecursive(nsIDocShellTreeItem* aItem,
90
                                       nsTArray<nsWeakPtr>& aItemArray) override;
91
};
92
93
class nsDocShellBackwardsEnumerator : public nsDocShellEnumerator
94
{
95
public:
96
  nsDocShellBackwardsEnumerator()
97
    : nsDocShellEnumerator(enumerateBackwards)
98
0
  {
99
0
  }
100
101
protected:
102
  virtual nsresult BuildArrayRecursive(nsIDocShellTreeItem* aItem,
103
                                       nsTArray<nsWeakPtr>& aItemArray) override;
104
};
105
106
#endif // nsDocShellEnumerator_h___