Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/dom/PushManager.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
/**
8
 * PushManager and PushSubscription are exposed on the main and worker threads.
9
 * The main thread version is implemented in Push.js. The JS implementation
10
 * makes it easier to use certain APIs like the permission prompt and Promises.
11
 *
12
 * Unfortunately, JS-implemented WebIDL is not supported off the main thread.
13
 * To work around this, we use a chain of runnables to query the JS-implemented
14
 * nsIPushService component for subscription information, and return the
15
 * results to the worker. We don't have to deal with permission prompts, since
16
 * we just reject calls if the principal does not have permission.
17
 *
18
 * On the main thread, PushManager wraps a JS-implemented PushManagerImpl
19
 * instance. The C++ wrapper is necessary because our bindings code cannot
20
 * accomodate "JS-implemented on the main thread, C++ on the worker" bindings.
21
 *
22
 * PushSubscription is in C++ on both threads since it isn't particularly
23
 * verbose to implement in C++ compared to JS.
24
 */
25
26
#ifndef mozilla_dom_PushManager_h
27
#define mozilla_dom_PushManager_h
28
29
#include "nsWrapperCache.h"
30
31
#include "mozilla/AlreadyAddRefed.h"
32
#include "mozilla/ErrorResult.h"
33
#include "mozilla/dom/BindingDeclarations.h"
34
#include "mozilla/dom/TypedArray.h"
35
#include "mozilla/dom/DOMPrefs.h"
36
37
#include "nsCOMPtr.h"
38
#include "mozilla/RefPtr.h"
39
40
class nsIGlobalObject;
41
class nsIPrincipal;
42
43
namespace mozilla {
44
namespace dom {
45
46
class OwningArrayBufferViewOrArrayBufferOrString;
47
class Promise;
48
class PushManagerImpl;
49
struct PushSubscriptionOptionsInit;
50
class WorkerPrivate;
51
52
class PushManager final : public nsISupports
53
                        , public nsWrapperCache
54
{
55
public:
56
  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
57
  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(PushManager)
58
59
  enum SubscriptionAction {
60
    SubscribeAction,
61
    GetSubscriptionAction,
62
  };
63
64
  // The main thread constructor.
65
  PushManager(nsIGlobalObject* aGlobal, PushManagerImpl* aImpl);
66
67
  // The worker thread constructor.
68
  explicit PushManager(const nsAString& aScope);
69
70
  nsIGlobalObject*
71
  GetParentObject() const
72
0
  {
73
0
    return mGlobal;
74
0
  }
75
76
  JSObject*
77
  WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
78
79
  static already_AddRefed<PushManager>
80
  Constructor(GlobalObject& aGlobal, const nsAString& aScope,
81
              ErrorResult& aRv);
82
83
  already_AddRefed<Promise>
84
  PerformSubscriptionActionFromWorker(SubscriptionAction aAction,
85
                                      ErrorResult& aRv);
86
87
  already_AddRefed<Promise>
88
  PerformSubscriptionActionFromWorker(SubscriptionAction aAction,
89
                                      const PushSubscriptionOptionsInit& aOptions,
90
                                      ErrorResult& aRv);
91
92
  already_AddRefed<Promise>
93
  Subscribe(const PushSubscriptionOptionsInit& aOptions, ErrorResult& aRv);
94
95
  already_AddRefed<Promise>
96
  GetSubscription(ErrorResult& aRv);
97
98
  already_AddRefed<Promise>
99
  PermissionState(const PushSubscriptionOptionsInit& aOptions,
100
                  ErrorResult& aRv);
101
102
private:
103
  ~PushManager();
104
105
  nsresult
106
  NormalizeAppServerKey(const OwningArrayBufferViewOrArrayBufferOrString& aSource,
107
                        nsTArray<uint8_t>& aAppServerKey);
108
109
  // The following are only set and accessed on the main thread.
110
  nsCOMPtr<nsIGlobalObject> mGlobal;
111
  RefPtr<PushManagerImpl> mImpl;
112
113
  // Only used on the worker thread.
114
  nsString mScope;
115
};
116
} // namespace dom
117
} // namespace mozilla
118
119
#endif // mozilla_dom_PushManager_h