Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/LoadContext.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 LoadContext_h
8
#define LoadContext_h
9
10
#include "SerializedLoadContext.h"
11
#include "mozilla/Attributes.h"
12
#include "mozilla/BasePrincipal.h"
13
#include "nsIWeakReferenceUtils.h"
14
#include "mozilla/dom/Element.h"
15
#include "nsIInterfaceRequestor.h"
16
#include "nsILoadContext.h"
17
18
namespace mozilla {
19
20
/**
21
 * Class that provides nsILoadContext info in Parent process.  Typically copied
22
 * from Child via SerializedLoadContext.
23
 *
24
 * Note: this is not the "normal" or "original" nsILoadContext.  That is
25
 * typically provided by nsDocShell.  This is only used when the original
26
 * docshell is in a different process and we need to copy certain values from
27
 * it.
28
 */
29
30
class LoadContext final
31
  : public nsILoadContext
32
  , public nsIInterfaceRequestor
33
{
34
public:
35
  NS_DECL_ISUPPORTS
36
  NS_DECL_NSILOADCONTEXT
37
  NS_DECL_NSIINTERFACEREQUESTOR
38
39
  // appId/inIsolatedMozBrowser arguments override those in SerializedLoadContext
40
  // provided by child process.
41
  LoadContext(const IPC::SerializedLoadContext& aToCopy,
42
              dom::Element* aTopFrameElement,
43
              OriginAttributes& aAttrs)
44
    : mTopFrameElement(do_GetWeakReference(aTopFrameElement))
45
    , mNestedFrameId(0)
46
    , mIsContent(aToCopy.mIsContent)
47
    , mUseRemoteTabs(aToCopy.mUseRemoteTabs)
48
    , mUseTrackingProtection(aToCopy.mUseTrackingProtection)
49
    , mOriginAttributes(aAttrs)
50
#ifdef DEBUG
51
    , mIsNotNull(aToCopy.mIsNotNull)
52
#endif
53
0
  {
54
0
  }
55
56
  // appId/inIsolatedMozBrowser arguments override those in SerializedLoadContext
57
  // provided by child process.
58
  LoadContext(const IPC::SerializedLoadContext& aToCopy,
59
              uint64_t aNestedFrameId,
60
              OriginAttributes& aAttrs)
61
    : mTopFrameElement(nullptr)
62
    , mNestedFrameId(aNestedFrameId)
63
    , mIsContent(aToCopy.mIsContent)
64
    , mUseRemoteTabs(aToCopy.mUseRemoteTabs)
65
    , mUseTrackingProtection(aToCopy.mUseTrackingProtection)
66
    , mOriginAttributes(aAttrs)
67
#ifdef DEBUG
68
    , mIsNotNull(aToCopy.mIsNotNull)
69
#endif
70
0
  {
71
0
  }
72
73
  LoadContext(dom::Element* aTopFrameElement,
74
              bool aIsContent,
75
              bool aUsePrivateBrowsing,
76
              bool aUseRemoteTabs,
77
              bool aUseTrackingProtection,
78
              const OriginAttributes& aAttrs)
79
    : mTopFrameElement(do_GetWeakReference(aTopFrameElement))
80
    , mNestedFrameId(0)
81
    , mIsContent(aIsContent)
82
    , mUseRemoteTabs(aUseRemoteTabs)
83
    , mUseTrackingProtection(aUseTrackingProtection)
84
    , mOriginAttributes(aAttrs)
85
#ifdef DEBUG
86
    , mIsNotNull(true)
87
#endif
88
  {
89
    MOZ_DIAGNOSTIC_ASSERT(aUsePrivateBrowsing == (aAttrs.mPrivateBrowsingId > 0));
90
  }
91
92
  // Constructor taking reserved origin attributes.
93
  explicit LoadContext(OriginAttributes& aAttrs)
94
    : mTopFrameElement(nullptr)
95
    , mNestedFrameId(0)
96
    , mIsContent(false)
97
    , mUseRemoteTabs(false)
98
    , mUseTrackingProtection(false)
99
    , mOriginAttributes(aAttrs)
100
#ifdef DEBUG
101
    , mIsNotNull(true)
102
#endif
103
0
  {
104
0
  }
105
106
  // Constructor for creating a LoadContext with a given principal's appId and
107
  // browser flag.
108
  explicit LoadContext(nsIPrincipal* aPrincipal,
109
                       nsILoadContext* aOptionalBase = nullptr);
110
111
private:
112
0
  ~LoadContext() {}
113
114
  nsWeakPtr mTopFrameElement;
115
  uint64_t mNestedFrameId;
116
  bool mIsContent;
117
  bool mUseRemoteTabs;
118
  bool mUseTrackingProtection;
119
  OriginAttributes mOriginAttributes;
120
#ifdef DEBUG
121
  bool mIsNotNull;
122
#endif
123
};
124
125
already_AddRefed<nsILoadContext> CreateLoadContext();
126
already_AddRefed<nsILoadContext> CreatePrivateLoadContext();
127
128
} // namespace mozilla
129
130
#endif // LoadContext_h