Bug 1679735 require recent user gesture for getDisplayMedia() r=jib

Previous behavior was to allow requests if the user has ever interacted with
the window.  This patch changes from sticky activation to transient
activation.

WindowContext is used rather than Document for the
HasValidTransientUserGestureActivation() test because user activation is a
property of the Window/global.

The error reported when WindowContext is null is the same as that for missing
transient activation, which is keeping the existing behavior.
https://searchfox.org/mozilla-central/rev/66547980e8e8ca583473c74f207cae5bac1ed541/dom/base/Document.cpp#15806
i.e. a missing WindowContext is still treated as missing transient activation.

Depends on D98274

Differential Revision: https://phabricator.services.mozilla.com/D98275
This commit is contained in:
Karl Tomlinson 2020-12-08 21:45:44 +00:00
Родитель 73ce7338df
Коммит 7a9d51be77
2 изменённых файлов: 3 добавлений и 10 удалений

Просмотреть файл

@ -10,6 +10,7 @@
#include "mozilla/dom/MediaDevicesBinding.h"
#include "mozilla/dom/NavigatorBinding.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/WindowContext.h"
#include "mozilla/MediaManager.h"
#include "MediaTrackConstraints.h"
#include "nsContentUtils.h"
@ -166,12 +167,8 @@ already_AddRefed<Promise> MediaDevices::GetDisplayMedia(
/* If the relevant global object of this does not have transient activation,
* return a promise rejected with a DOMException object whose name attribute
* has the value InvalidStateError. */
Document* doc = owner->GetExtantDoc();
if (NS_WARN_IF(!doc)) {
p->MaybeRejectWithSecurityError("No document.");
return p.forget();
}
if (!doc->HasBeenUserGestureActivated()) {
WindowContext* wc = owner->GetWindowContext();
if (!wc || !wc->HasValidTransientUserGestureActivation()) {
p->MaybeRejectWithInvalidStateError(
"getDisplayMedia must be called from a user gesture handler.");
return p.forget();

Просмотреть файл

@ -1,4 +0,0 @@
[getdisplaymedia-user-activation-consumed.https.html]
[Test getDisplayMedia() after user activation is consumed]
expected: FAIL