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 CreatePromise
= MozPromise
<RefPtr
<PermissionStatus
>, nsresult
, true>;
25 using SimplePromise
= MozPromise
<nsresult
, nsresult
, true>;
27 static RefPtr
<CreatePromise
> Create(nsPIDOMWindowInner
* aWindow
,
28 PermissionName aName
);
30 JSObject
* WrapObject(JSContext
* aCx
,
31 JS::Handle
<JSObject
*> aGivenProto
) override
;
33 PermissionState
State() const { return mState
; }
35 IMPL_EVENT_HANDLER(change
)
37 void DisconnectFromOwner() override
;
39 PermissionName
Name() const { return mName
; }
41 RefPtr
<SimplePromise
> Init();
46 PermissionStatus(nsPIDOMWindowInner
* aWindow
, PermissionName aName
);
49 * This method returns the internal permission type, which should be equal to
50 * the permission name for all but the MIDI permission because of the SysEx
51 * support: internally, we have both "midi" and "midi-sysex" permission types
52 * but we only have a "midi" (public) permission name.
54 * Note: the `MidiPermissionDescriptor` descriptor has an optional `sysex`
55 * boolean, which is used to determine whether to return "midi" or
56 * "midi-sysex" for the MIDI permission.
58 virtual nsLiteralCString
GetPermissionType();
61 virtual RefPtr
<SimplePromise
> UpdateState();
63 // These functions should be called when an permission is updated which may
64 // change the state of this PermissionStatus. MaybeUpdatedBy accepts the
65 // permission object itself that is update. When the permission's key is not
66 // same-origin with this object's owner window, such as for secondary-keyed
67 // permissions like `3rdPartyFrameStorage^...`, MaybeUpdatedByNotifyOnly will
68 // be called with the updated window as an argument. MaybeUpdatedByNotifyOnly
69 // must be defined by PermissionStatus inheritors that are double-keyed.
70 virtual bool MaybeUpdatedBy(nsIPermission
* aPermission
) const;
71 virtual bool MaybeUpdatedByNotifyOnly(nsPIDOMWindowInner
* aInnerWindow
) const;
73 void PermissionChanged();
77 RefPtr
<PermissionObserver
> mObserver
;
80 PermissionState mState
;
83 } // namespace mozilla::dom
85 #endif // mozilla_dom_permissionstatus_h_