Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/URLExtraData.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
/* thread-safe container of information for resolving url values */
8
9
#ifndef mozilla_URLExtraData_h
10
#define mozilla_URLExtraData_h
11
12
#include "mozilla/dom/URL.h"
13
#include "mozilla/Move.h"
14
#include "mozilla/StaticPtr.h"
15
#include "mozilla/net/ReferrerPolicy.h"
16
17
#include "nsCOMPtr.h"
18
#include "nsIPrincipal.h"
19
#include "nsIURI.h"
20
21
namespace mozilla {
22
23
struct URLExtraData
24
{
25
  URLExtraData(already_AddRefed<nsIURI> aBaseURI,
26
               already_AddRefed<nsIURI> aReferrer,
27
               already_AddRefed<nsIPrincipal> aPrincipal,
28
               net::ReferrerPolicy aReferrerPolicy)
29
    : mBaseURI(std::move(aBaseURI))
30
    , mReferrer(std::move(aReferrer))
31
    , mReferrerPolicy(aReferrerPolicy)
32
    , mPrincipal(std::move(aPrincipal))
33
      // When we hold the URI data of a style sheet, mReferrer is always
34
      // equal to the sheet URI.
35
    , mIsChrome(mReferrer ? dom::IsChromeURI(mReferrer) : false)
36
3
  {
37
3
    MOZ_ASSERT(mBaseURI);
38
3
  }
39
40
  URLExtraData(nsIURI* aBaseURI, nsIURI* aReferrer, nsIPrincipal* aPrincipal,
41
               net::ReferrerPolicy aReferrerPolicy)
42
    : URLExtraData(do_AddRef(aBaseURI),
43
                   do_AddRef(aReferrer),
44
                   do_AddRef(aPrincipal),
45
0
                   aReferrerPolicy) {}
46
47
  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(URLExtraData)
48
49
0
  nsIURI* BaseURI() const { return mBaseURI; }
50
0
  nsIURI* GetReferrer() const { return mReferrer; }
51
0
  net::ReferrerPolicy GetReferrerPolicy() const { return mReferrerPolicy;}
52
0
  nsIPrincipal* GetPrincipal() const { return mPrincipal; }
53
54
3
  static URLExtraData* Dummy() {
55
3
    MOZ_ASSERT(sDummy);
56
3
    return sDummy;
57
3
  }
58
  static void InitDummy();
59
  static void ReleaseDummy();
60
61
private:
62
  ~URLExtraData();
63
64
  nsCOMPtr<nsIURI> mBaseURI;
65
  nsCOMPtr<nsIURI> mReferrer;
66
  net::ReferrerPolicy mReferrerPolicy;
67
  nsCOMPtr<nsIPrincipal> mPrincipal;
68
69
  // True if mReferrer is a chrome:// URI.
70
  const bool mIsChrome;
71
72
  static StaticRefPtr<URLExtraData> sDummy;
73
};
74
75
} // namespace mozilla
76
77
#endif // mozilla_URLExtraData_h