Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/docshell/base/ChromeBrowsingContext.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 "ChromeBrowsingContext.h"
8
9
namespace mozilla {
10
namespace dom {
11
12
ChromeBrowsingContext::ChromeBrowsingContext(uint64_t aBrowsingContextId,
13
                                             const nsAString& aName,
14
                                             uint64_t aProcessId)
15
  : BrowsingContext(aBrowsingContextId, aName)
16
  , mProcessId(aProcessId)
17
0
{
18
0
  // You are only ever allowed to create ChromeBrowsingContexts in the
19
0
  // parent process.
20
0
  MOZ_RELEASE_ASSERT(XRE_IsParentProcess());
21
0
}
22
23
ChromeBrowsingContext::ChromeBrowsingContext(nsIDocShell* aDocShell)
24
  : BrowsingContext(aDocShell)
25
  , mProcessId(0)
26
0
{
27
0
  // You are only ever allowed to create ChromeBrowsingContexts in the
28
0
  // parent process.
29
0
  MOZ_RELEASE_ASSERT(XRE_IsParentProcess());
30
0
}
31
32
// TODO(farre): ChromeBrowsingContext::CleanupContexts starts from the
33
// list of root BrowsingContexts. This isn't enough when separate
34
// BrowsingContext nodes of a BrowsingContext tree, not in a crashing
35
// child process, are from that process and thus needs to be
36
// cleaned. [Bug 1472108]
37
/* static */ void
38
ChromeBrowsingContext::CleanupContexts(uint64_t aProcessId)
39
0
{
40
0
  nsTArray<RefPtr<BrowsingContext>> roots;
41
0
  BrowsingContext::GetRootBrowsingContexts(roots);
42
0
43
0
  for (RefPtr<BrowsingContext> context : roots) {
44
0
    if (Cast(context)->IsOwnedByProcess(aProcessId)) {
45
0
      context->Detach();
46
0
    }
47
0
  }
48
0
}
49
50
/* static */ already_AddRefed<ChromeBrowsingContext>
51
ChromeBrowsingContext::Get(uint64_t aId)
52
0
{
53
0
  MOZ_RELEASE_ASSERT(XRE_IsParentProcess());
54
0
  return BrowsingContext::Get(aId).downcast<ChromeBrowsingContext>();
55
0
}
56
57
/* static */ ChromeBrowsingContext*
58
ChromeBrowsingContext::Cast(BrowsingContext* aContext)
59
0
{
60
0
  MOZ_RELEASE_ASSERT(XRE_IsParentProcess());
61
0
  return static_cast<ChromeBrowsingContext*>(aContext);
62
0
}
63
64
/* static */ already_AddRefed<ChromeBrowsingContext>
65
ChromeBrowsingContext::Create(
66
  uint64_t aBrowsingContextId,
67
  const nsAString& aName,
68
  uint64_t aProcessId)
69
0
{
70
0
  return do_AddRef(new ChromeBrowsingContext(aBrowsingContextId, aName, aProcessId));
71
0
}
72
73
} // namespace dom
74
} // namespace mozilla