Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/dom/BrowsingContext.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 BrowsingContext_h
8
#define BrowsingContext_h
9
10
#include "mozilla/LinkedList.h"
11
#include "mozilla/Maybe.h"
12
#include "mozilla/RefPtr.h"
13
#include "mozilla/WeakPtr.h"
14
#include "nsCOMPtr.h"
15
#include "nsCycleCollectionParticipant.h"
16
#include "nsString.h"
17
#include "nsTArray.h"
18
#include "nsWrapperCache.h"
19
20
class nsIDocShell;
21
22
namespace mozilla {
23
24
class LogModule;
25
26
namespace dom {
27
28
// BrowsingContext, in this context, is the cross process replicated
29
// environment in which information about documents is stored. In
30
// particular the tree structure of nested browsing contexts is
31
// represented by the tree of BrowsingContexts.
32
//
33
// The tree of BrowsingContexts in created in step with its
34
// corresponding nsDocShell, and when nsDocShells are connected
35
// through a parent/child relationship, so are BrowsingContexts. The
36
// major difference is that BrowsingContexts are replicated (synced)
37
// to the parent process, making it possible to traverse the
38
// BrowsingContext tree for a tab, in both the parent and the child
39
// process.
40
class BrowsingContext
41
  : public nsWrapperCache
42
  , public SupportsWeakPtr<BrowsingContext>
43
  , public LinkedListElement<RefPtr<BrowsingContext>>
44
{
45
public:
46
  static void Init();
47
  static LogModule* GetLog();
48
  static void CleanupContexts(uint64_t aProcessId);
49
50
  static already_AddRefed<BrowsingContext> Get(uint64_t aId);
51
  static already_AddRefed<BrowsingContext> Create(nsIDocShell* aDocShell);
52
53
  // Attach the current BrowsingContext to its parent, in both the
54
  // child and the parent process. If 'aParent' is null, 'this' is
55
  // taken to be a root BrowsingContext.
56
  void Attach(BrowsingContext* aParent);
57
58
  // Detach the current BrowsingContext from its parent, in both the
59
  // child and the parent process.
60
  void Detach();
61
62
  // Remove all children from the current BrowsingContext and cache
63
  // them to allow them to be attached again.
64
  void CacheChildren();
65
66
  bool IsCached();
67
68
0
  void SetName(const nsAString& aName) { mName = aName; }
69
0
  void GetName(nsAString& aName) { aName = mName; }
70
0
  bool NameEquals(const nsAString& aName) { return mName.Equals(aName); }
71
72
0
  uint64_t Id() const { return mBrowsingContextId; }
73
  uint64_t OwnerProcessId() const;
74
75
  already_AddRefed<BrowsingContext> GetParent()
76
0
  {
77
0
    return do_AddRef(mParent.get());
78
0
  }
79
80
  void GetChildren(nsTArray<RefPtr<BrowsingContext>>& aChildren);
81
82
  static void GetRootBrowsingContexts(
83
    nsTArray<RefPtr<BrowsingContext>>& aBrowsingContexts);
84
85
  nsISupports* GetParentObject() const;
86
  virtual JSObject* WrapObject(JSContext* aCx,
87
                               JS::Handle<JSObject*> aGivenProto) override;
88
89
  MOZ_DECLARE_WEAKREFERENCE_TYPENAME(BrowsingContext)
90
  NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(BrowsingContext)
91
  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(BrowsingContext)
92
93
  using Children = AutoCleanLinkedList<RefPtr<BrowsingContext>>;
94
95
protected:
96
  virtual ~BrowsingContext();
97
  // Create a new BrowsingContext for 'aDocShell'. The id will be
98
  // generated so that it is unique across all content child processes
99
  // and the content parent process.
100
  explicit BrowsingContext(nsIDocShell* aDocShell);
101
  BrowsingContext(uint64_t aBrowsingContextId,
102
                  const nsAString& aName);
103
104
private:
105
  const uint64_t mBrowsingContextId;
106
107
  WeakPtr<BrowsingContext> mParent;
108
  Children mChildren;
109
  nsCOMPtr<nsIDocShell> mDocShell;
110
  nsString mName;
111
};
112
113
} // namespace dom
114
} // namespace mozilla
115
#endif