Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/dom/MessageManagerGlobal.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_dom_MessageManagerGlobal_h
8
#define mozilla_dom_MessageManagerGlobal_h
9
10
#include "nsFrameMessageManager.h"
11
#include "mozilla/ErrorResult.h"
12
13
namespace mozilla {
14
namespace dom {
15
16
/**
17
 * Base class for implementing the WebIDL MessageManagerGlobal class.
18
 */
19
class MessageManagerGlobal
20
{
21
public:
22
  // MessageListenerManager
23
  void AddMessageListener(const nsAString& aMessageName,
24
                          MessageListener& aListener,
25
                          bool aListenWhenClosed,
26
                          ErrorResult& aError)
27
0
  {
28
0
    if (!mMessageManager) {
29
0
      aError.Throw(NS_ERROR_NULL_POINTER);
30
0
      return;
31
0
    }
32
0
    mMessageManager->AddMessageListener(aMessageName, aListener,
33
0
                                        aListenWhenClosed, aError);
34
0
  }
35
  void RemoveMessageListener(const nsAString& aMessageName,
36
                             MessageListener& aListener,
37
                             ErrorResult& aError)
38
0
  {
39
0
    if (!mMessageManager) {
40
0
      aError.Throw(NS_ERROR_NULL_POINTER);
41
0
      return;
42
0
    }
43
0
    mMessageManager->RemoveMessageListener(aMessageName, aListener, aError);
44
0
  }
45
  void AddWeakMessageListener(const nsAString& aMessageName,
46
                              MessageListener& aListener,
47
                              ErrorResult& aError)
48
0
  {
49
0
    if (!mMessageManager) {
50
0
      aError.Throw(NS_ERROR_NULL_POINTER);
51
0
      return;
52
0
    }
53
0
    mMessageManager->AddWeakMessageListener(aMessageName, aListener, aError);
54
0
  }
55
  void RemoveWeakMessageListener(const nsAString& aMessageName,
56
                                 MessageListener& aListener,
57
                                 ErrorResult& aError)
58
0
  {
59
0
    if (!mMessageManager) {
60
0
      aError.Throw(NS_ERROR_NULL_POINTER);
61
0
      return;
62
0
    }
63
0
    mMessageManager->RemoveWeakMessageListener(aMessageName, aListener, aError);
64
0
  }
65
66
  // MessageSender
67
  void SendAsyncMessage(JSContext* aCx, const nsAString& aMessageName,
68
                        JS::Handle<JS::Value> aObj,
69
                        JS::Handle<JSObject*> aObjects,
70
                        nsIPrincipal* aPrincipal,
71
                        JS::Handle<JS::Value> aTransfers,
72
                        ErrorResult& aError)
73
0
  {
74
0
    if (!mMessageManager) {
75
0
      aError.Throw(NS_ERROR_NULL_POINTER);
76
0
      return;
77
0
    }
78
0
    mMessageManager->SendAsyncMessage(aCx, aMessageName, aObj, aObjects,
79
0
                                      aPrincipal, aTransfers, aError);
80
0
  }
81
  already_AddRefed<ProcessMessageManager> GetProcessMessageManager(mozilla::ErrorResult& aError)
82
0
  {
83
0
    if (!mMessageManager) {
84
0
      aError.Throw(NS_ERROR_NULL_POINTER);
85
0
      return nullptr;
86
0
    }
87
0
    return mMessageManager->GetProcessMessageManager(aError);
88
0
  }
89
90
  void GetRemoteType(nsAString& aRemoteType, mozilla::ErrorResult& aError)
91
0
  {
92
0
    if (!mMessageManager) {
93
0
      aError.Throw(NS_ERROR_NULL_POINTER);
94
0
      return;
95
0
    }
96
0
    mMessageManager->GetRemoteType(aRemoteType, aError);
97
0
  }
98
99
  // SyncMessageSender
100
  void SendSyncMessage(JSContext* aCx, const nsAString& aMessageName,
101
                       JS::Handle<JS::Value> aObj,
102
                       JS::Handle<JSObject*> aObjects,
103
                       nsIPrincipal* aPrincipal,
104
                       nsTArray<JS::Value>& aResult,
105
                       ErrorResult& aError)
106
0
  {
107
0
    if (!mMessageManager) {
108
0
      aError.Throw(NS_ERROR_NULL_POINTER);
109
0
      return;
110
0
    }
111
0
    mMessageManager->SendSyncMessage(aCx, aMessageName, aObj, aObjects,
112
0
                                     aPrincipal, aResult, aError);
113
0
  }
114
  void SendRpcMessage(JSContext* aCx, const nsAString& aMessageName,
115
                      JS::Handle<JS::Value> aObj,
116
                      JS::Handle<JSObject*> aObjects,
117
                      nsIPrincipal* aPrincipal,
118
                      nsTArray<JS::Value>& aResult,
119
                      ErrorResult& aError)
120
0
  {
121
0
    if (!mMessageManager) {
122
0
      aError.Throw(NS_ERROR_NULL_POINTER);
123
0
      return;
124
0
    }
125
0
    mMessageManager->SendRpcMessage(aCx, aMessageName, aObj, aObjects,
126
0
                                    aPrincipal, aResult, aError);
127
0
  }
128
129
  // MessageManagerGlobal
130
  void Dump(const nsAString& aStr);
131
  void PrivateNoteIntentionalCrash(ErrorResult& aError);
132
  void Atob(const nsAString& aAsciiString, nsAString& aBase64Data, ErrorResult& aError);
133
  void Btoa(const nsAString& aBase64Data, nsAString& aAsciiString, ErrorResult& aError);
134
135
  void MarkForCC()
136
0
  {
137
0
    if (mMessageManager) {
138
0
      mMessageManager->MarkForCC();
139
0
    }
140
0
  }
141
142
protected:
143
  explicit MessageManagerGlobal(nsFrameMessageManager* aMessageManager)
144
    : mMessageManager(aMessageManager)
145
0
  {}
146
147
  RefPtr<nsFrameMessageManager> mMessageManager;
148
};
149
150
} // namespace dom
151
} // namespace mozilla
152
153
#endif // mozilla_dom_MessageManagerGlobal_h