tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

PermissionStatus.h (2230B)


      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 #ifndef mozilla_dom_PermissionStatus_h_
      8 #define mozilla_dom_PermissionStatus_h_
      9 
     10 #include "mozilla/DOMEventTargetHelper.h"
     11 #include "mozilla/MozPromise.h"
     12 #include "mozilla/dom/PermissionStatusBinding.h"
     13 #include "mozilla/dom/PermissionsBinding.h"
     14 
     15 namespace mozilla::dom {
     16 
     17 class PermissionStatusSink;
     18 
     19 class PermissionStatus : public DOMEventTargetHelper {
     20  friend class PermissionStatusSink;
     21 
     22 public:
     23  using SimplePromise = MozPromise<nsresult, nsresult, true>;
     24 
     25  PermissionStatus(nsIGlobalObject* aGlobal, PermissionName aName);
     26 
     27  JSObject* WrapObject(JSContext* aCx,
     28                       JS::Handle<JSObject*> aGivenProto) override;
     29 
     30  PermissionState State() const { return mState; }
     31  void SetState(PermissionState aState) { mState = aState; }
     32 
     33  IMPL_EVENT_HANDLER(change)
     34 
     35  void DisconnectFromOwner() override;
     36 
     37  PermissionName Name() const { return mName; }
     38 
     39  void GetType(nsACString& aName) const;
     40 
     41  RefPtr<SimplePromise> Init();
     42 
     43 protected:
     44  ~PermissionStatus();
     45 
     46  /**
     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.
     51   *
     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.
     55   */
     56  virtual nsLiteralCString GetPermissionType() const;
     57 
     58 private:
     59  virtual already_AddRefed<PermissionStatusSink> CreateSink();
     60 
     61  void PermissionChanged(uint32_t aAction);
     62 
     63  PermissionState ComputeStateFromAction(uint32_t aAction);
     64 
     65  PermissionName mName;
     66  RefPtr<PermissionStatusSink> mSink;
     67 
     68 protected:
     69  PermissionState mState;
     70 };
     71 
     72 }  // namespace mozilla::dom
     73 
     74 #endif  // mozilla_dom_permissionstatus_h_