Bug 1943650 - Command-line --help output misformatted after --dbus-service. r=emilio
[gecko.git] / dom / media / autoplay / GVAutoplayPermissionRequest.h
blobf432e365c00520c739aaaebe00f6671e00802888
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef DOM_MEDIA_GVAUTOPLAYPERMISSIONREQUEST_H_
6 #define DOM_MEDIA_GVAUTOPLAYPERMISSIONREQUEST_H_
8 #include "GVAutoplayRequestUtils.h"
9 #include "nsContentPermissionHelper.h"
11 class nsGlobalWindowInner;
13 namespace mozilla::dom {
15 /**
16 * This class is used to provide an ability for GeckoView (GV) to allow its
17 * embedder (application) to decide whether the autoplay media should be allowed
18 * or denied on the page. We have two types of request, one for audible media,
19 * another one for inaudible media. Each page would at most have one request per
20 * type at a time, and the result of request would be effective on that page
21 * until the page gets reloaded or closed.
23 class GVAutoplayPermissionRequest : public ContentPermissionRequestBase {
24 public:
25 NS_DECL_ISUPPORTS_INHERITED
26 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(GVAutoplayPermissionRequest,
27 ContentPermissionRequestBase)
29 // nsIContentPermissionRequest methods
30 NS_IMETHOD Cancel(void) override;
31 NS_IMETHOD Allow(JS::Handle<JS::Value> choices) override;
33 private:
34 // Only allow to create this request from the requestor.
35 friend class GVAutoplayPermissionRequestor;
36 static void CreateRequest(nsGlobalWindowInner* aWindow,
37 BrowsingContext* aContext,
38 GVAutoplayRequestType aType);
40 GVAutoplayPermissionRequest(nsGlobalWindowInner* aWindow,
41 BrowsingContext* aContext,
42 GVAutoplayRequestType aType);
43 ~GVAutoplayPermissionRequest();
45 void SetRequestStatus(GVAutoplayRequestStatus aStatus);
47 GVAutoplayRequestType mType;
48 RefPtr<BrowsingContext> mContext;
51 /**
52 * This class provides a method to request autoplay permission for a page, which
53 * would be used to be a factor to determine if media is allowed to autoplay or
54 * not on GeckoView.
56 * A page could only have at most one audible request and one inaudible request,
57 * and once a page has been closed or reloaded, those requests would be dropped.
58 * In order to achieve that all media existing in the same page can share the
59 * result of those requests, the request status would only be stored in the
60 * top-level browsing context, which allows them to be synchronized among
61 * different processes when Fission is enabled.
63 * The current way we choose is to request for a permission when creating media
64 * element, in order to get the response from the embedding app before media
65 * starts playing if the app can response the request quickly enough. However,
66 * the request might be pending if the app doesn't response to it, we might
67 * never get the response. As that is just one factor of determining the
68 * autoplay result, even if we don't get the response for the request, we still
69 * have a chance to play media. Check AutoplayPolicy to see more details about
70 * how we decide the final autoplay decision.
72 class GVAutoplayPermissionRequestor final {
73 public:
74 static void AskForPermissionIfNeeded(nsPIDOMWindowInner* aWindow);
76 private:
77 static bool HasEverAskForRequest(BrowsingContext* aContext,
78 GVAutoplayRequestType aType);
79 static void CreateAsyncRequest(nsPIDOMWindowInner* aWindow,
80 BrowsingContext* aContext,
81 GVAutoplayRequestType aType);
84 } // namespace mozilla::dom
86 #endif