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/. */
7 #ifndef mozilla_dom_PermissionStatus_h_
8 #define mozilla_dom_PermissionStatus_h_
10 #include "mozilla/dom/PermissionsBinding.h"
11 #include "mozilla/dom/PermissionStatusBinding.h"
12 #include "mozilla/DOMEventTargetHelper.h"
13 #include "mozilla/MozPromise.h"
15 namespace mozilla::dom
{
17 class PermissionStatusSink
;
19 class PermissionStatus
: public DOMEventTargetHelper
{
20 friend class PermissionStatusSink
;
23 using SimplePromise
= MozPromise
<nsresult
, nsresult
, true>;
25 PermissionStatus(nsIGlobalObject
* aGlobal
, PermissionName aName
);
27 JSObject
* WrapObject(JSContext
* aCx
,
28 JS::Handle
<JSObject
*> aGivenProto
) override
;
30 PermissionState
State() const { return mState
; }
31 void SetState(PermissionState aState
) { mState
= aState
; }
33 IMPL_EVENT_HANDLER(change
)
35 void DisconnectFromOwner() override
;
37 PermissionName
Name() const { return mName
; }
39 void GetType(nsACString
& aName
) const;
41 RefPtr
<SimplePromise
> Init();
47 * This method returns the internal permission type, which should be equal to
48 * the permission name for all but the MIDI permission because of the SysEx
49 * support: internally, we have both "midi" and "midi-sysex" permission types
50 * but we only have a "midi" (public) permission name.
52 * Note: the `MidiPermissionDescriptor` descriptor has an optional `sysex`
53 * boolean, which is used to determine whether to return "midi" or
54 * "midi-sysex" for the MIDI permission.
56 virtual nsLiteralCString
GetPermissionType() const;
59 virtual already_AddRefed
<PermissionStatusSink
> CreateSink();
61 void PermissionChanged(uint32_t aAction
);
63 PermissionState
ComputeStateFromAction(uint32_t aAction
);
66 RefPtr
<PermissionStatusSink
> mSink
;
69 PermissionState mState
;
72 } // namespace mozilla::dom
74 #endif // mozilla_dom_permissionstatus_h_