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/. */
7 #include "MediaKeySystemAccessPermissionRequest.h"
9 #include "nsGlobalWindowInner.h"
11 namespace mozilla::dom
{
13 NS_IMPL_CYCLE_COLLECTION_INHERITED(MediaKeySystemAccessPermissionRequest
,
14 ContentPermissionRequestBase
)
16 NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(
17 MediaKeySystemAccessPermissionRequest
, ContentPermissionRequestBase
)
20 already_AddRefed
<MediaKeySystemAccessPermissionRequest
>
21 MediaKeySystemAccessPermissionRequest::Create(nsPIDOMWindowInner
* aWindow
) {
22 // Could conceivably be created off main thread then used on main thread
23 // later. If we really need to do that at some point we could relax this
25 AssertIsOnMainThread();
30 nsGlobalWindowInner
* innerWindow
= nsGlobalWindowInner::Cast(aWindow
);
31 if (!innerWindow
->GetPrincipal()) {
35 RefPtr
<MediaKeySystemAccessPermissionRequest
> request
=
36 new MediaKeySystemAccessPermissionRequest(innerWindow
);
37 return request
.forget();
40 MediaKeySystemAccessPermissionRequest::MediaKeySystemAccessPermissionRequest(
41 nsGlobalWindowInner
* aWindow
)
42 : ContentPermissionRequestBase(aWindow
->GetPrincipal(), aWindow
,
43 "media.eme.require-app-approval"_ns
,
44 "media-key-system-access"_ns
) {}
46 MediaKeySystemAccessPermissionRequest::
47 ~MediaKeySystemAccessPermissionRequest() {
48 AssertIsOnMainThread();
49 // If a request has not been serviced by the time it is destroyed, treat it
50 // as if the request was denied.
54 already_AddRefed
<MediaKeySystemAccessPermissionRequest::RequestPromise
>
55 MediaKeySystemAccessPermissionRequest::GetPromise() {
56 return mPromiseHolder
.Ensure(__func__
);
59 nsresult
MediaKeySystemAccessPermissionRequest::Start() {
60 // Check test prefs to see if we should short circuit. We want to do this
61 // before checking the cached value so we can have pref changes take effect
62 // without refreshing the page.
63 MediaKeySystemAccessPermissionRequest::PromptResult promptResult
=
66 MediaKeySystemAccessPermissionRequest::PromptResult::Granted
) {
67 return Allow(JS::UndefinedHandleValue
);
70 MediaKeySystemAccessPermissionRequest::PromptResult::Denied
) {
74 return nsContentPermissionUtils::AskPermission(this, mWindow
);
78 MediaKeySystemAccessPermissionRequest::Allow(JS::Handle
<JS::Value
> aChoices
) {
79 AssertIsOnMainThread();
80 mPromiseHolder
.ResolveIfExists(true, __func__
);
85 MediaKeySystemAccessPermissionRequest::Cancel() {
86 AssertIsOnMainThread();
87 mPromiseHolder
.RejectIfExists(false, __func__
);
91 } // namespace mozilla::dom