Bug 1874684 - Part 4: Prefer const references instead of copying Instant values....
[gecko.git] / dom / midi / MIDIPermissionRequest.h
blob935abf580acd51024fea9724e192b224bf5e8a1d
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
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_MIDIPermissionRequest_h
8 #define mozilla_dom_MIDIPermissionRequest_h
10 #include "mozilla/dom/Promise.h"
11 #include "nsContentPermissionHelper.h"
13 namespace mozilla::dom {
15 struct MIDIOptions;
17 /**
18 * Handles permission dialog management when requesting MIDI permissions.
20 class MIDIPermissionRequest final : public ContentPermissionRequestBase,
21 public nsIRunnable {
22 public:
23 MIDIPermissionRequest(nsPIDOMWindowInner* aWindow, Promise* aPromise,
24 const MIDIOptions& aOptions);
26 NS_DECL_ISUPPORTS_INHERITED
27 NS_DECL_NSIRUNNABLE
28 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MIDIPermissionRequest,
29 ContentPermissionRequestBase)
30 // nsIContentPermissionRequest
31 NS_IMETHOD Cancel(void) override;
32 NS_IMETHOD Allow(JS::Handle<JS::Value> choices) override;
33 NS_IMETHOD GetTypes(nsIArray** aTypes) override;
35 private:
36 ~MIDIPermissionRequest() = default;
37 nsresult DoPrompt();
38 void CancelWithRandomizedDelay();
40 // If we're canceling on a timer, we need to hold a strong ref while it's
41 // outstanding.
42 nsCOMPtr<nsITimer> mCancelTimer;
44 // Promise for returning MIDIAccess on request success
45 RefPtr<Promise> mPromise;
46 // True if sysex permissions should be requested
47 bool mNeedsSysex;
50 } // namespace mozilla::dom
52 #endif // mozilla_dom_MIDIPermissionRequest_h