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"
14 #include "nsIPermission.h"
16 namespace mozilla::dom
{
18 class PermissionObserver
;
20 class PermissionStatus
: public DOMEventTargetHelper
{
21 friend class PermissionObserver
;
24 using SimplePromise
= MozPromise
<nsresult
, nsresult
, true>;
26 PermissionStatus(nsPIDOMWindowInner
* aWindow
, PermissionName aName
);
28 JSObject
* WrapObject(JSContext
* aCx
,
29 JS::Handle
<JSObject
*> aGivenProto
) override
;
31 PermissionState
State() const { return mState
; }
32 void SetState(PermissionState aState
) { mState
= aState
; }
34 IMPL_EVENT_HANDLER(change
)
36 void DisconnectFromOwner() override
;
38 PermissionName
Name() const { return mName
; }
40 void GetType(nsACString
& aName
) const;
42 RefPtr
<SimplePromise
> Init();
48 * This method returns the internal permission type, which should be equal to
49 * the permission name for all but the MIDI permission because of the SysEx
50 * support: internally, we have both "midi" and "midi-sysex" permission types
51 * but we only have a "midi" (public) permission name.
53 * Note: the `MidiPermissionDescriptor` descriptor has an optional `sysex`
54 * boolean, which is used to determine whether to return "midi" or
55 * "midi-sysex" for the MIDI permission.
57 virtual nsLiteralCString
GetPermissionType() const;
60 virtual RefPtr
<SimplePromise
> UpdateState();
62 // These functions should be called when an permission is updated which may
63 // change the state of this PermissionStatus. MaybeUpdatedBy accepts the
64 // permission object itself that is update. When the permission's key is not
65 // same-origin with this object's owner window, such as for secondary-keyed
66 // permissions like `3rdPartyFrameStorage^...`, MaybeUpdatedByNotifyOnly will
67 // be called with the updated window as an argument. MaybeUpdatedByNotifyOnly
68 // must be defined by PermissionStatus inheritors that are double-keyed.
69 virtual bool MaybeUpdatedBy(nsIPermission
* aPermission
) const;
70 virtual bool MaybeUpdatedByNotifyOnly(nsPIDOMWindowInner
* aInnerWindow
) const;
72 void PermissionChanged();
76 RefPtr
<PermissionObserver
> mObserver
;
79 PermissionState mState
;
82 } // namespace mozilla::dom
84 #endif // mozilla_dom_permissionstatus_h_