Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/toolkit/components/extensions/webrequest/WebRequestService.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 mozilla_WebRequestService_h
8
#define mozilla_WebRequestService_h
9
10
#include "mozilla/LinkedList.h"
11
#include "mozilla/UniquePtr.h"
12
13
#include "mozilla/extensions/ChannelWrapper.h"
14
#include "mozilla/extensions/WebExtensionPolicy.h"
15
16
#include "nsHashKeys.h"
17
#include "nsDataHashtable.h"
18
19
class nsAtom;
20
class nsITabParent;
21
class nsITraceableChannel;
22
23
namespace mozilla {
24
namespace dom {
25
  class TabParent;
26
  class nsIContentParent;
27
}
28
29
namespace extensions {
30
31
class WebRequestChannelEntry final
32
{
33
public:
34
  ~WebRequestChannelEntry();
35
36
private:
37
  friend class WebRequestService;
38
39
  explicit WebRequestChannelEntry(ChannelWrapper* aChannel);
40
41
  uint64_t mChannelId;
42
  WeakPtr<ChannelWrapper> mChannel;
43
};
44
45
class WebRequestService final
46
{
47
public:
48
  NS_INLINE_DECL_REFCOUNTING(WebRequestService)
49
50
0
  WebRequestService() = default;
51
52
  static already_AddRefed<WebRequestService> GetInstance()
53
  {
54
    return do_AddRef(&GetSingleton());
55
  }
56
57
  static WebRequestService& GetSingleton();
58
59
  using ChannelEntry = WebRequestChannelEntry;
60
61
  UniquePtr<ChannelEntry> RegisterChannel(ChannelWrapper* aChannel);
62
63
  void UnregisterTraceableChannel(uint64_t aChannelId);
64
65
  already_AddRefed<nsITraceableChannel>
66
  GetTraceableChannel(uint64_t aChannelId, nsAtom* aAddonId,
67
                      dom::nsIContentParent* aContentParent);
68
69
private:
70
  ~WebRequestService();
71
72
  friend ChannelEntry;
73
74
  nsDataHashtable<nsUint64HashKey, ChannelEntry*> mChannelEntries;
75
};
76
77
}
78
}
79
80
#endif // mozilla_WebRequestService_h