tor-browser

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

MediaKeySystemAccessPermissionRequest.h (3168B)


      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
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef DOM_MEDIA_EME_MEDIAKEYSYSTEMACCESSPERMISSIONREQUEST_H_
      8 #define DOM_MEDIA_EME_MEDIAKEYSYSTEMACCESSPERMISSIONREQUEST_H_
      9 
     10 #include "mozilla/MozPromise.h"
     11 #include "nsContentPermissionHelper.h"
     12 
     13 class nsGlobalWindowInner;
     14 
     15 namespace mozilla::dom {
     16 
     17 /**
     18 * This class encapsulates a permission request to allow media key system
     19 * access. The intention is not for this class to be used in all cases of EME,
     20 * but only when we need to seek explicit approval from an application using
     21 * Gecko, such as an application embedding via GeckoView.
     22 *
     23 * media.eme.require-app-approval should be used to gate this functionality in
     24 * gecko code, and is also used as the testing pref for
     25 * ContentPermissionRequestBase. I.e. CheckPromptPrefs() will respond to having
     26 * `media.eme.require-app-approval.prompt.testing` and
     27 * `media.eme.require-app-approval.prompt.testing.allow` being set to true or
     28 * false and will return an appropriate value to allow for test code to short
     29 * circuit showing a prompt. Note that the code using this class needs to call
     30 * CheckPromptPrefs and implement test specific logic, it is *not* handled by
     31 * this class or ContentPermissionRequestBase.
     32 *
     33 * Expects to be used on main thread as ContentPermissionRequestBase uses
     34 * PContentPermissionRequest which is managed by PContent which is main thread
     35 * to main thread communication.
     36 */
     37 class MediaKeySystemAccessPermissionRequest
     38    : public ContentPermissionRequestBase {
     39 public:
     40  NS_DECL_ISUPPORTS_INHERITED
     41  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(
     42      MediaKeySystemAccessPermissionRequest, ContentPermissionRequestBase)
     43 
     44  using RequestPromise = MozPromise<bool, bool, true /* IsExclusive*/>;
     45 
     46  // Create a MediaKeySystemAccessPermissionRequest.
     47  // @param aWindow The window associated with this request.
     48  static already_AddRefed<MediaKeySystemAccessPermissionRequest> Create(
     49      nsPIDOMWindowInner* aWindow);
     50 
     51  // Returns a promise that will be resolved if this request is allowed or
     52  // rejected in the case the request is denied. If allowed the promise
     53  // will resolve with true, otherwise it will resolve with false.
     54  already_AddRefed<RequestPromise> GetPromise();
     55 
     56  // Helper function that triggers the request. This function will check
     57  // prefs and cancel or allow the request if the appropriate prefs are set,
     58  // otherwise it will fire the request to the associated window.
     59  nsresult Start();
     60 
     61  // nsIContentPermissionRequest methods
     62  NS_IMETHOD Cancel(void) override;
     63  NS_IMETHOD Allow(JS::Handle<JS::Value> choices) override;
     64 
     65 private:
     66  explicit MediaKeySystemAccessPermissionRequest(nsGlobalWindowInner* aWindow);
     67  ~MediaKeySystemAccessPermissionRequest();
     68 
     69  MozPromiseHolder<RequestPromise> mPromiseHolder;
     70 };
     71 
     72 }  // namespace mozilla::dom
     73 
     74 #endif  // DOM_MEDIA_EME_MEDIAKEYSYSTEMACCESSPERMISSIONREQUEST_H_