⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 244749 in webkit


Ignore:
Timestamp:
Apr 29, 2019, 1:04:33 PM (7 years ago)
Author:
youenn@apple.com
Message:

getDisplayMedia should be called on user gesture
https://bugs.webkit.org/show_bug.cgi?id=197356
Source/WebCore:

Reviewed by Eric Carlson.

Allow getDisplayMedia on user gesture only.
Otherwise reject the promise.
Minor refactoring to align getDisplayMedia, getUserMedia and
enumerateDevices when called with no document.

Test: fast/mediastream/screencapture-user-gesture.html

  • Modules/mediastream/MediaDevices.cpp:

(WebCore::MediaDevices::getUserMedia const):

  • Modules/mediastream/MediaDevices.h:
  • Modules/mediastream/NavigatorMediaDevices.h:
  • page/DOMWindow.h:
  • testing/Internals.cpp:

(WebCore::Internals::setDisableGetDisplayMediaUserGestureConstraint):

  • testing/Internals.h:
  • testing/Internals.idl:

Tools:

<rdar://problem/50296074>

Reviewed by Eric Carlson.

Update test configuration to inject internals
so that we can use it to simulate a user click to call getDisplayMedia.

  • TestWebKitAPI/Tests/WebKit/getDisplayMedia.html:
  • TestWebKitAPI/Tests/WebKitCocoa/GetDisplayMedia.mm:

(TestWebKitAPI::GetDisplayMediaTest::SetUp):

LayoutTests:

Reviewed by Eric Carlson.

  • fast/mediastream/media-stream-page-muted.html:
  • fast/mediastream/screencapture-user-gesture-expected.txt: Added.
  • fast/mediastream/screencapture-user-gesture.html: Added.
  • http/tests/media/media-stream/get-display-media-iframe-allow-attribute-expected.txt:
  • http/tests/media/media-stream/get-display-media-iframe-allow-attribute.html:
  • http/tests/media/media-stream/get-display-media-prompt.html:
  • http/tests/media/media-stream/resources/get-display-media-devices-iframe.html:
  • resources/testharnessreport.js:
Location:
trunk
Files:
2 added
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r244748 r244749  
     12019-04-29  Youenn Fablet  <youenn@apple.com>
     2
     3        getDisplayMedia should be called on user gesture
     4        https://bugs.webkit.org/show_bug.cgi?id=197356
     5
     6        Reviewed by Eric Carlson.
     7
     8        * fast/mediastream/media-stream-page-muted.html:
     9        * fast/mediastream/screencapture-user-gesture-expected.txt: Added.
     10        * fast/mediastream/screencapture-user-gesture.html: Added.
     11        * http/tests/media/media-stream/get-display-media-iframe-allow-attribute-expected.txt:
     12        * http/tests/media/media-stream/get-display-media-iframe-allow-attribute.html:
     13        * http/tests/media/media-stream/get-display-media-prompt.html:
     14        * http/tests/media/media-stream/resources/get-display-media-devices-iframe.html:
     15
     16        * resources/testharnessreport.js:
     17
    1182019-04-29  Javier Fernandez  <jfernandez@igalia.com>
    219
  • trunk/LayoutTests/fast/mediastream/media-stream-page-muted.html

    r243899 r244749  
    55    <script src="../../resources/js-test-pre.js"></script>
    66    <script>
     7        if (window.internals)
     8            internals.setDisableGetDisplayMediaUserGestureConstraint(true);
     9
    710        async function checkPageState(activeState, inactiveState) {
    811            await new Promise((resolve, reject) => {
  • trunk/LayoutTests/http/tests/media/media-stream/get-display-media-iframe-allow-attribute-expected.txt

    r238091 r244749  
    1 CONSOLE MESSAGE: line 5: Trying to call getDisplayMedia from a frame without correct 'allow' attribute.
    2 CONSOLE MESSAGE: line 5: Trying to call getDisplayMedia from a frame without correct 'allow' attribute.
    3 CONSOLE MESSAGE: line 5: Trying to call getDisplayMedia from a frame without correct 'allow' attribute.
     1CONSOLE MESSAGE: line 8: Trying to call getDisplayMedia from a frame without correct 'allow' attribute.
     2CONSOLE MESSAGE: line 8: Trying to call getDisplayMedia from a frame without correct 'allow' attribute.
     3CONSOLE MESSAGE: line 8: Trying to call getDisplayMedia from a frame without correct 'allow' attribute.
    44     
    55
  • trunk/LayoutTests/http/tests/media/media-stream/get-display-media-prompt.html

    r236465 r244749  
    1010
    1111<script>
     12    if (window.internals)
     13        internals.setDisableGetDisplayMediaUserGestureConstraint(true);
    1214
    1315    let stream;
  • trunk/LayoutTests/http/tests/media/media-stream/resources/get-display-media-devices-iframe.html

    r238091 r244749  
    11<script>
     2    if (window.internals)
     3        internals.setDisableGetDisplayMediaUserGestureConstraint(true);
     4
    25    async function enumerate(event)
    36    {
  • trunk/LayoutTests/resources/testharnessreport.js

    r230353 r244749  
    2929    }
    3030}
     31
     32if (self.internals && internals.setDisableGetDisplayMediaUserGestureConstraint)
     33    internals.setDisableGetDisplayMediaUserGestureConstraint(true);
    3134
    3235if (self.internals && internals.setICECandidateFiltering)
  • trunk/Source/WebCore/ChangeLog

    r244748 r244749  
     12019-04-29  Youenn Fablet  <youenn@apple.com>
     2
     3        getDisplayMedia should be called on user gesture
     4        https://bugs.webkit.org/show_bug.cgi?id=197356
     5
     6        Reviewed by Eric Carlson.
     7
     8        Allow getDisplayMedia on user gesture only.
     9        Otherwise reject the promise.
     10        Minor refactoring to align getDisplayMedia, getUserMedia and
     11        enumerateDevices when called with no document.
     12
     13        Test: fast/mediastream/screencapture-user-gesture.html
     14
     15        * Modules/mediastream/MediaDevices.cpp:
     16        (WebCore::MediaDevices::getUserMedia const):
     17        * Modules/mediastream/MediaDevices.h:
     18        * Modules/mediastream/NavigatorMediaDevices.h:
     19        * page/DOMWindow.h:
     20        * testing/Internals.cpp:
     21        (WebCore::Internals::setDisableGetDisplayMediaUserGestureConstraint):
     22        * testing/Internals.h:
     23        * testing/Internals.idl:
     24
    1252019-04-29  Javier Fernandez  <jfernandez@igalia.com>
    226
  • trunk/Source/WebCore/Modules/mediastream/MediaDevices.cpp

    r243887 r244749  
    103103{
    104104    auto* document = this->document();
    105     if (!document) {
    106         promise.reject(Exception { InvalidStateError });
    107         return;
    108     }
     105    if (!document)
     106        return;
    109107
    110108    auto audioConstraints = createMediaConstraints(constraints.audio);
     
    115113    auto request = UserMediaRequest::create(*document, { MediaStreamRequest::Type::UserMedia, WTFMove(audioConstraints), WTFMove(videoConstraints) }, WTFMove(promise));
    116114    request->start();
    117 
    118     return;
    119 }
    120 
    121 ExceptionOr<void> MediaDevices::getDisplayMedia(const StreamConstraints& constraints, Promise&& promise) const
     115}
     116
     117void MediaDevices::getDisplayMedia(const StreamConstraints& constraints, Promise&& promise) const
    122118{
    123119    auto* document = this->document();
    124120    if (!document)
    125         return Exception { InvalidStateError };
     121        return;
     122
     123    if (!m_disableGetDisplayMediaUserGestureConstraint && !UserGestureIndicator::processingUserGesture()) {
     124        promise.reject(Exception { InvalidAccessError, "getDisplayMedia must be called from a user gesture handler."_s });
     125        return;
     126    }
    126127
    127128    auto request = UserMediaRequest::create(*document, { MediaStreamRequest::Type::DisplayMedia, { }, createMediaConstraints(constraints.video) }, WTFMove(promise));
    128129    request->start();
    129 
    130     return { };
    131130}
    132131
  • trunk/Source/WebCore/Modules/mediastream/MediaDevices.h

    r243887 r244749  
    7777    };
    7878    void getUserMedia(const StreamConstraints&, Promise&&) const;
    79     ExceptionOr<void> getDisplayMedia(const StreamConstraints&, Promise&&) const;
     79    void getDisplayMedia(const StreamConstraints&, Promise&&) const;
    8080    void enumerateDevices(EnumerateDevicesPromise&&) const;
    8181    MediaTrackSupportedConstraints getSupportedConstraints();
     
    8383    using RefCounted<MediaDevices>::ref;
    8484    using RefCounted<MediaDevices>::deref;
     85
     86    void setDisableGetDisplayMediaUserGestureConstraint(bool value) { m_disableGetDisplayMediaUserGestureConstraint = value; }
    8587
    8688private:
     
    108110    const EventNames& m_eventNames; // Need to cache this so we can use it from GC threads.
    109111    bool m_listeningForDeviceChanges { false };
     112    bool m_disableGetDisplayMediaUserGestureConstraint { false };
    110113};
    111114
  • trunk/Source/WebCore/Modules/mediastream/NavigatorMediaDevices.h

    r241183 r244749  
    4848    static NavigatorMediaDevices* from(Navigator*);
    4949
    50     static MediaDevices* mediaDevices(Navigator&);
     50    WEBCORE_TESTSUPPORT_EXPORT static MediaDevices* mediaDevices(Navigator&);
    5151    MediaDevices* mediaDevices() const;
    5252
  • trunk/Source/WebCore/page/DOMWindow.h

    r243887 r244749  
    159159    BarProp& statusbar();
    160160    BarProp& toolbar();
    161     Navigator& navigator();
     161    WEBCORE_EXPORT Navigator& navigator();
    162162    Navigator* optionalNavigator() const { return m_navigator.get(); }
    163163    Navigator& clientInformation() { return navigator(); }
  • trunk/Source/WebCore/testing/Internals.cpp

    r244675 r244749  
    109109#include "LoaderStrategy.h"
    110110#include "MallocStatistics.h"
     111#include "MediaDevices.h"
    111112#include "MediaEngineConfigurationFactory.h"
    112113#include "MediaPlayer.h"
     
    119120#include "MockPageOverlay.h"
    120121#include "MockPageOverlayClient.h"
     122#include "NavigatorMediaDevices.h"
    121123#include "NetworkLoadInformation.h"
    122124#include "Page.h"
     
    47064708}
    47074709
     4710void Internals::setDisableGetDisplayMediaUserGestureConstraint(bool value)
     4711{
     4712    Document* document = contextDocument();
     4713    if (!document || !document->domWindow())
     4714        return;
     4715
     4716    if (auto* mediaDevices = NavigatorMediaDevices::mediaDevices(document->domWindow()->navigator()))
     4717        mediaDevices->setDisableGetDisplayMediaUserGestureConstraint(value);
     4718}
    47084719#endif
    47094720
  • trunk/Source/WebCore/testing/Internals.h

    r244307 r244749  
    707707    void setMediaStreamTrackIdentifier(MediaStreamTrack&, String&& id);
    708708    void setMediaStreamSourceInterrupted(MediaStreamTrack&, bool);
     709    void setDisableGetDisplayMediaUserGestureConstraint(bool);
    709710#endif
    710711
  • trunk/Source/WebCore/testing/Internals.idl

    r244307 r244749  
    680680    [Conditional=MEDIA_STREAM] void setMediaStreamTrackIdentifier(MediaStreamTrack track, DOMString identifier);
    681681    [Conditional=MEDIA_STREAM] void setMediaStreamSourceInterrupted(MediaStreamTrack track, boolean interrupted);
     682    [Conditional=MEDIA_STREAM] void setDisableGetDisplayMediaUserGestureConstraint(boolean value);
    682683
    683684    unsigned long long documentIdentifier(Document document);
  • trunk/Tools/ChangeLog

    r244730 r244749  
     12019-04-29  Youenn Fablet  <youenn@apple.com>
     2
     3        getDisplayMedia should be called on user gesture
     4        https://bugs.webkit.org/show_bug.cgi?id=197356
     5        <rdar://problem/50296074>
     6
     7        Reviewed by Eric Carlson.
     8
     9        Update test configuration to inject internals
     10        so that we can use it to simulate a user click to call getDisplayMedia.
     11
     12        * TestWebKitAPI/Tests/WebKit/getDisplayMedia.html:
     13        * TestWebKitAPI/Tests/WebKitCocoa/GetDisplayMedia.mm:
     14        (TestWebKitAPI::GetDisplayMediaTest::SetUp):
     15
    1162019-04-26  Stephanie Lewis  <slewis@apple.com>
    217
  • trunk/Tools/TestWebKitAPI/Tests/WebKit/getDisplayMedia.html

    r226412 r244749  
    88            function promptForCapture(constraints)
    99            {
    10                 navigator.mediaDevices.getDisplayMedia(constraints)
    11                 .then((s) => {
    12                     stream = s;
    13                     video.srcObject = stream;
    14                     if (window.webkit)
    15                       window.webkit.messageHandlers.testHandler.postMessage('allowed');
    16                 })
    17                 .catch((error) => {
    18                     if (window.webkit)
    19                        window.webkit.messageHandlers.testHandler.postMessage('denied');
     10                window.internals.withUserGesture(async () => {
     11                    navigator.mediaDevices.getDisplayMedia(constraints)
     12                    .then((s) => {
     13                        stream = s;
     14                        video.srcObject = stream;
     15                        if (window.webkit)
     16                          window.webkit.messageHandlers.testHandler.postMessage('allowed');
     17                    })
     18                    .catch((error) => {
     19                        if (window.webkit)
     20                           window.webkit.messageHandlers.testHandler.postMessage('denied');
     21                    });
    2022                });
    2123            }
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/GetDisplayMedia.mm

    r242339 r244749  
    9494    {
    9595        m_configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     96        auto context = adoptWK(TestWebKitAPI::Util::createContextForInjectedBundleTest("InternalsInjectedBundleTest"));
     97        m_configuration.get().processPool = (WKProcessPool *)context.get();
    9698
    9799        auto handler = adoptNS([[GetDisplayMediaMessageHandler alloc] init]);
Note: See TracChangeset for help on using the changeset viewer.