зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1593843 - part6 : add a static pref to control this feature. r=bryce
`media.geckoview.autoplay.request` is used to control whether we send the play request. `media.geckoview.autoplay.request.testing` is used to control the request result in testing. Differential Revision: https://phabricator.services.mozilla.com/D52605 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
c8642caea0
Коммит
902bd705da
|
@ -5,6 +5,7 @@
|
|||
#include "GVAutoplayPermissionRequest.h"
|
||||
|
||||
#include "mozilla/dom/HTMLMediaElement.h"
|
||||
#include "mozilla/StaticPrefs_media.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
@ -20,6 +21,18 @@ static RStatus GetRequestStatus(BrowsingContext* aContext, RType aType) {
|
|||
: aContext->GetGVInaudibleAutoplayRequestStatus();
|
||||
}
|
||||
|
||||
// This is copied from the value of `media.geckoview.autoplay.request.testing`.
|
||||
enum class TestRequest : uint32_t {
|
||||
ePromptAsNormal = 0,
|
||||
eAllowAll = 1,
|
||||
eDenyAll = 2,
|
||||
eAllowAudible = 3,
|
||||
eDenyAudible = 4,
|
||||
eAllowInAudible = 5,
|
||||
eDenyInAudible = 6,
|
||||
eLeaveAllPending = 7,
|
||||
};
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_INHERITED(GVAutoplayPermissionRequest,
|
||||
ContentPermissionRequestBase)
|
||||
|
||||
|
@ -33,9 +46,27 @@ void GVAutoplayPermissionRequest::CreateRequest(nsGlobalWindowInner* aWindow,
|
|||
RefPtr<GVAutoplayPermissionRequest> request =
|
||||
new GVAutoplayPermissionRequest(aWindow, aContext, aType);
|
||||
request->SetRequestStatus(RStatus::ePENDING);
|
||||
const TestRequest testingPref = static_cast<TestRequest>(
|
||||
StaticPrefs::media_geckoview_autoplay_request_testing());
|
||||
if (testingPref != TestRequest::ePromptAsNormal) {
|
||||
if (testingPref == TestRequest::eAllowAll ||
|
||||
(testingPref == TestRequest::eAllowAudible &&
|
||||
aType == RType::eAUDIBLE) ||
|
||||
(testingPref == TestRequest::eAllowInAudible &&
|
||||
aType == RType::eINAUDIBLE)) {
|
||||
request->Allow(JS::UndefinedHandleValue);
|
||||
} else if (testingPref == TestRequest::eDenyAll ||
|
||||
(testingPref == TestRequest::eDenyAudible &&
|
||||
aType == RType::eAUDIBLE) ||
|
||||
(testingPref == TestRequest::eDenyInAudible &&
|
||||
aType == RType::eINAUDIBLE)) {
|
||||
request->Cancel();
|
||||
}
|
||||
} else {
|
||||
request->RequestDelayedTask(
|
||||
aWindow->EventTargetFor(TaskCategory::Other),
|
||||
GVAutoplayPermissionRequest::DelayedTaskType::Request);
|
||||
}
|
||||
}
|
||||
|
||||
GVAutoplayPermissionRequest::GVAutoplayPermissionRequest(
|
||||
|
@ -115,6 +146,10 @@ void GVAutoplayPermissionRequestor::AskForPermissionIfNeeded(
|
|||
return;
|
||||
}
|
||||
|
||||
if (!StaticPrefs::media_geckoview_autoplay_request()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// The request status is stored in top-level browsing context only.
|
||||
RefPtr<BrowsingContext> context = aWindow->GetBrowsingContext()->Top();
|
||||
if (!HasEverAskForRequest(context, RType::eAUDIBLE)) {
|
||||
|
|
|
@ -6453,6 +6453,24 @@
|
|||
value: false
|
||||
mirror: always
|
||||
|
||||
# If true, then we require explicit approval from the embedding app (ex. Fenix)
|
||||
# on GeckoView to know if we can allow audible, inaudible media or both kinds
|
||||
# of media to autoplay.
|
||||
- name: media.geckoview.autoplay.request
|
||||
type: bool
|
||||
value: false
|
||||
mirror: always
|
||||
|
||||
# This is used in testing only, in order to skip the prompting process. This
|
||||
# pref works only when enabling the pref `media.geckoview.autoplay.request`.
|
||||
# 0=prompt as normal, 1=allow all, 2=deny all, 3=allow audible request,
|
||||
# 4=deny audible request, 5=allow inaudible request, 6=deny inaudible request.
|
||||
# 7=leave all requests pending.
|
||||
- name: media.geckoview.autoplay.request.testing
|
||||
type: uint32_t
|
||||
value: 0
|
||||
mirror: always
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Prefs starting with "mousewheel."
|
||||
#---------------------------------------------------------------------------
|
||||
|
|
|
@ -65,3 +65,5 @@ user_pref("media.allowed-to-play.enabled", true);
|
|||
// Ensure media can always play without delay
|
||||
user_pref("media.block-autoplay-until-in-foreground", false);
|
||||
user_pref("toolkit.telemetry.coverage.endpoint.base", "http://localhost");
|
||||
// Don't ask for a request in testing unless explicitly set this as true.
|
||||
user_pref("media.geckoview.autoplay.request", false);
|
||||
|
|
Загрузка…
Ссылка в новой задаче