Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/ipc/ContentProcessManager.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 file,
5
 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef mozilla_dom_ContentProcessManager_h
8
#define mozilla_dom_ContentProcessManager_h
9
10
#include <map>
11
#include <set>
12
#include "mozilla/StaticPtr.h"
13
#include "mozilla/dom/TabContext.h"
14
#include "mozilla/dom/ipc/IdType.h"
15
#include "nsTArray.h"
16
17
namespace mozilla {
18
namespace dom {
19
class ContentParent;
20
21
struct RemoteFrameInfo
22
{
23
  ContentParentId mOpenerCpId;
24
  TabId mOpenerTabId;
25
  TabContext mContext;
26
};
27
28
struct ContentProcessInfo
29
{
30
  ContentParent* mCp;
31
  ContentParentId mParentCpId;
32
  std::set<ContentParentId> mChildrenCpId;
33
  std::map<TabId, RemoteFrameInfo> mRemoteFrames;
34
};
35
36
class ContentProcessManager final
37
{
38
public:
39
  static ContentProcessManager* GetSingleton();
40
0
  ~ContentProcessManager() {MOZ_COUNT_DTOR(ContentProcessManager);};
41
42
  /**
43
   * Add a new content process into the map.
44
   * If aParentCpId is not 0, it's a nested content process.
45
   */
46
  void AddContentProcess(ContentParent* aChildCp,
47
                         const ContentParentId& aParentCpId = ContentParentId(0));
48
  /**
49
   * Remove the content process by id.
50
   */
51
  void RemoveContentProcess(const ContentParentId& aChildCpId);
52
  /**
53
   * Add a grandchild content process into the map.
54
   * aParentCpId must be already added in the map by AddContentProcess().
55
   */
56
  bool AddGrandchildProcess(const ContentParentId& aParentCpId,
57
                            const ContentParentId& aChildCpId);
58
  /**
59
   * Get the parent process's id by child process's id.
60
   * Used to check if a child really belongs to the parent.
61
   */
62
  bool GetParentProcessId(const ContentParentId& aChildCpId,
63
                          /*out*/ ContentParentId* aParentCpId);
64
  /**
65
   * Return the ContentParent pointer by id.
66
   */
67
  ContentParent* GetContentProcessById(const ContentParentId& aChildCpId);
68
69
  /**
70
   * Return a list of all child process's id.
71
   */
72
  nsTArray<ContentParentId>
73
  GetAllChildProcessById(const ContentParentId& aParentCpId);
74
75
  /**
76
   * Register RemoteFrameInfo with given tab id.
77
   * Used when a content process wants to create a new tab. aOpenerTabId and
78
   * aContext are saved in RemoteFrameInfo, which is a part of
79
   * ContentProcessInfo.  We can use the tab id and process id to locate the
80
   * TabContext for future use.
81
   */
82
  bool RegisterRemoteFrame(const TabId& aTabId,
83
                           const ContentParentId& aOpenerCpId,
84
                           const TabId& aOpenerTabId,
85
                           const IPCTabContext& aContext,
86
                           const ContentParentId& aChildCpId);
87
88
89
  /**
90
   * Remove the RemoteFrameInfo by the given process and tab id.
91
   */
92
  void UnregisterRemoteFrame(const ContentParentId& aChildCpId,
93
                             const TabId& aChildTabId);
94
95
  /**
96
   * Get the TabContext by the given content process and tab id.
97
   */
98
  bool
99
  GetTabContextByProcessAndTabId(const ContentParentId& aChildCpId,
100
                                 const TabId& aChildTabId,
101
                                 /*out*/ TabContext* aTabContext);
102
103
  /**
104
   * Get all TabContext which are inside the given content process.
105
   */
106
  nsTArray<TabContext>
107
  GetTabContextByContentProcess(const ContentParentId& aChildCpId);
108
109
  /**
110
   * Query a tab's opener id by the given process and tab id.
111
   * XXX Currently not used. Plan to be used for bug 1020179.
112
   */
113
  bool GetRemoteFrameOpenerTabId(const ContentParentId& aChildCpId,
114
                                 const TabId& aChildTabId,
115
                                 /*out*/ContentParentId* aOpenerCpId,
116
                                 /*out*/ TabId* aOpenerTabId);
117
118
  /**
119
   * Get all TabParents' Ids managed by the givent content process.
120
   * Return empty array when TabParent couldn't be found via aChildCpId
121
   */
122
  nsTArray<TabId>
123
  GetTabParentsByProcessId(const ContentParentId& aChildCpId);
124
125
  /**
126
   * Get the number of TabParents managed by the givent content process.
127
   * Return 0 when TabParent couldn't be found via aChildCpId.
128
   */
129
  uint32_t
130
  GetTabParentCountByProcessId(const ContentParentId& aChildCpId);
131
132
  /**
133
   * Get the TabParent by the given content process and tab id.
134
   * Return nullptr when TabParent couldn't be found via aChildCpId
135
   * and aChildTabId.
136
   * (or probably because the TabParent is not in the chrome process)
137
   */
138
  already_AddRefed<TabParent>
139
  GetTabParentByProcessAndTabId(const ContentParentId& aChildCpId,
140
                                const TabId& aChildTabId);
141
142
  /**
143
   * Get the TabParent on top level by the given content process and tab id.
144
   *
145
   *  This function return the TabParent belong to the chrome process,
146
   *  called top-level TabParent here, by given aChildCpId and aChildTabId.
147
   *  The given aChildCpId and aChildTabId are related to a content process
148
   *  and a tab respectively. In nested-oop, the top-level TabParent isn't
149
   *  always the opener tab of the given tab in content process. This function
150
   *  will call GetTabParentByProcessAndTabId iteratively until the Tab returned
151
   *  is belong to the chrome process.
152
   */
153
  already_AddRefed<TabParent>
154
  GetTopLevelTabParentByProcessAndTabId(const ContentParentId& aChildCpId,
155
                                        const TabId& aChildTabId);
156
157
private:
158
  static StaticAutoPtr<ContentProcessManager> sSingleton;
159
  std::map<ContentParentId, ContentProcessInfo> mContentParentMap;
160
161
0
  ContentProcessManager() {MOZ_COUNT_CTOR(ContentProcessManager);};
162
};
163
164
} // namespace dom
165
} // namespace mozilla
166
167
#endif // mozilla_dom_ContentProcessManager_h