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 #ifndef nsDOMWindowList_h___
7 #define nsDOMWindowList_h___
8 
9 #include "nsCOMPtr.h"
10 #include "nsIDOMWindowCollection.h"
11 #include <stdint.h>
12 #include "nsIDocShell.h"
13 
14 class nsIDocShell;
15 class nsIDOMWindow;
16 
17 class nsDOMWindowList : public nsIDOMWindowCollection
18 {
19 public:
20   explicit nsDOMWindowList(nsIDocShell* aDocShell);
21 
22   NS_DECL_ISUPPORTS
23   NS_DECL_NSIDOMWINDOWCOLLECTION
24 
25   uint32_t GetLength();
26   already_AddRefed<nsPIDOMWindowOuter> IndexedGetter(uint32_t aIndex);
27 
28   //local methods
29   NS_IMETHOD SetDocShell(nsIDocShell* aDocShell);
GetDocShellTreeItemAt(uint32_t aIndex)30   already_AddRefed<nsIDocShellTreeItem> GetDocShellTreeItemAt(uint32_t aIndex)
31   {
32     EnsureFresh();
33     nsCOMPtr<nsIDocShellTreeItem> item;
34     if (mDocShellNode) {
35       mDocShellNode->GetChildAt(aIndex, getter_AddRefs(item));
36     }
37     return item.forget();
38   }
39 
40 protected:
41   virtual ~nsDOMWindowList();
42 
43   // Note: this function may flush and cause mDocShellNode to become null.
44   void EnsureFresh();
45 
46   nsIDocShell* mDocShellNode; //Weak Reference
47 };
48 
49 #endif // nsDOMWindowList_h___
50