Make MediaStream constructor take a Document instead of a ScriptExecutionContext
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 16 Jun 2019 04:47:05 +0000 (04:47 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 16 Jun 2019 04:47:05 +0000 (04:47 +0000)
https://bugs.webkit.org/show_bug.cgi?id=198873

Reviewed by Darin Adler.

Update MediaStream constructors and call site to take a Document&.
Make the same for creation of CanvasCaptureMediaStreamTrack.
No observable change of behavior.

* Modules/mediastream/CanvasCaptureMediaStreamTrack.cpp:
(WebCore::CanvasCaptureMediaStreamTrack::create):
(WebCore::CanvasCaptureMediaStreamTrack::CanvasCaptureMediaStreamTrack):
(WebCore::loggerFromContext): Deleted.
* Modules/mediastream/CanvasCaptureMediaStreamTrack.h:
* Modules/mediastream/MediaStream.cpp:
(WebCore::MediaStream::create):
(WebCore::MediaStream::MediaStream):
(WebCore::MediaStream::clone):
(WebCore::loggerFromContext): Deleted.
* Modules/mediastream/MediaStream.h:
* Modules/mediastream/MediaStream.idl:
* Modules/mediastream/UserMediaRequest.cpp:
(WebCore::UserMediaRequest::allow):
* html/HTMLCanvasElement.cpp:
(WebCore::HTMLCanvasElement::captureStream):
* html/HTMLCanvasElement.h:
* html/HTMLCanvasElement.idl:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@246470 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/Modules/mediastream/CanvasCaptureMediaStreamTrack.cpp
Source/WebCore/Modules/mediastream/CanvasCaptureMediaStreamTrack.h
Source/WebCore/Modules/mediastream/MediaStream.cpp
Source/WebCore/Modules/mediastream/MediaStream.h
Source/WebCore/Modules/mediastream/MediaStream.idl
Source/WebCore/Modules/mediastream/UserMediaRequest.cpp
Source/WebCore/html/HTMLCanvasElement.cpp
Source/WebCore/html/HTMLCanvasElement.h
Source/WebCore/html/HTMLCanvasElement.idl

index 5c19611..f603b98 100644 (file)
@@ -1,3 +1,33 @@
+2019-06-15  Youenn Fablet  <youenn@apple.com>
+
+        Make MediaStream constructor take a Document instead of a ScriptExecutionContext
+        https://bugs.webkit.org/show_bug.cgi?id=198873
+
+        Reviewed by Darin Adler.
+
+        Update MediaStream constructors and call site to take a Document&.
+        Make the same for creation of CanvasCaptureMediaStreamTrack.
+        No observable change of behavior.
+
+        * Modules/mediastream/CanvasCaptureMediaStreamTrack.cpp:
+        (WebCore::CanvasCaptureMediaStreamTrack::create):
+        (WebCore::CanvasCaptureMediaStreamTrack::CanvasCaptureMediaStreamTrack):
+        (WebCore::loggerFromContext): Deleted.
+        * Modules/mediastream/CanvasCaptureMediaStreamTrack.h:
+        * Modules/mediastream/MediaStream.cpp:
+        (WebCore::MediaStream::create):
+        (WebCore::MediaStream::MediaStream):
+        (WebCore::MediaStream::clone):
+        (WebCore::loggerFromContext): Deleted.
+        * Modules/mediastream/MediaStream.h:
+        * Modules/mediastream/MediaStream.idl:
+        * Modules/mediastream/UserMediaRequest.cpp:
+        (WebCore::UserMediaRequest::allow):
+        * html/HTMLCanvasElement.cpp:
+        (WebCore::HTMLCanvasElement::captureStream):
+        * html/HTMLCanvasElement.h:
+        * html/HTMLCanvasElement.idl:
+
 2019-06-15  Zalan Bujtas  <zalan@apple.com>
 
         [LFC][BFC] Fix available width for non-floating positioned float avoiders.
index 3b66aef..2e9befe 100644 (file)
@@ -36,25 +36,20 @@ namespace WebCore {
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(CanvasCaptureMediaStreamTrack);
 
-Ref<CanvasCaptureMediaStreamTrack> CanvasCaptureMediaStreamTrack::create(ScriptExecutionContext& context, Ref<HTMLCanvasElement>&& canvas, Optional<double>&& frameRequestRate)
+Ref<CanvasCaptureMediaStreamTrack> CanvasCaptureMediaStreamTrack::create(Document& document, Ref<HTMLCanvasElement>&& canvas, Optional<double>&& frameRequestRate)
 {
     auto source = CanvasCaptureMediaStreamTrack::Source::create(canvas.get(), WTFMove(frameRequestRate));
-    return adoptRef(*new CanvasCaptureMediaStreamTrack(context, WTFMove(canvas), WTFMove(source)));
+    return adoptRef(*new CanvasCaptureMediaStreamTrack(document, WTFMove(canvas), WTFMove(source)));
 }
 
-static inline Ref<const Logger> loggerFromContext(ScriptExecutionContext& context)
-{
-    return downcast<Document>(context).logger();
-}
-
-CanvasCaptureMediaStreamTrack::CanvasCaptureMediaStreamTrack(ScriptExecutionContext& context, Ref<HTMLCanvasElement>&& canvas, Ref<CanvasCaptureMediaStreamTrack::Source>&& source)
-    : MediaStreamTrack(context, MediaStreamTrackPrivate::create(loggerFromContext(context), source.copyRef()))
+CanvasCaptureMediaStreamTrack::CanvasCaptureMediaStreamTrack(Document& document, Ref<HTMLCanvasElement>&& canvas, Ref<CanvasCaptureMediaStreamTrack::Source>&& source)
+    : MediaStreamTrack(document, MediaStreamTrackPrivate::create(document.logger(), source.copyRef()))
     , m_canvas(WTFMove(canvas))
 {
 }
 
-CanvasCaptureMediaStreamTrack::CanvasCaptureMediaStreamTrack(ScriptExecutionContext& context, Ref<HTMLCanvasElement>&& canvas, Ref<MediaStreamTrackPrivate>&& privateTrack)
-    : MediaStreamTrack(context, WTFMove(privateTrack))
+CanvasCaptureMediaStreamTrack::CanvasCaptureMediaStreamTrack(Document& document, Ref<HTMLCanvasElement>&& canvas, Ref<MediaStreamTrackPrivate>&& privateTrack)
+    : MediaStreamTrack(document, WTFMove(privateTrack))
     , m_canvas(WTFMove(canvas))
 {
 }
@@ -198,7 +193,7 @@ RefPtr<MediaStreamTrack> CanvasCaptureMediaStreamTrack::clone()
     if (!scriptExecutionContext())
         return nullptr;
     
-    return adoptRef(*new CanvasCaptureMediaStreamTrack(*scriptExecutionContext(), m_canvas.copyRef(), m_private->clone()));
+    return adoptRef(*new CanvasCaptureMediaStreamTrack(downcast<Document>(*scriptExecutionContext()), m_canvas.copyRef(), m_private->clone()));
 }
 
 }
index 265c378..c8659ff 100644 (file)
 
 namespace WebCore {
 
+class Document;
 class HTMLCanvasElement;
 class Image;
-class ScriptExecutionContext;
 
 class CanvasCaptureMediaStreamTrack final : public MediaStreamTrack {
     WTF_MAKE_ISO_ALLOCATED(CanvasCaptureMediaStreamTrack);
 public:
-    static Ref<CanvasCaptureMediaStreamTrack> create(ScriptExecutionContext&, Ref<HTMLCanvasElement>&&, Optional<double>&& frameRequestRate);
+    static Ref<CanvasCaptureMediaStreamTrack> create(Document&, Ref<HTMLCanvasElement>&&, Optional<double>&& frameRequestRate);
 
     HTMLCanvasElement& canvas() { return m_canvas.get(); }
     void requestFrame() { static_cast<Source&>(source()).requestFrame(); }
@@ -82,8 +82,8 @@ private:
         RefPtr<Image> m_currentImage;
     };
 
-    CanvasCaptureMediaStreamTrack(ScriptExecutionContext&, Ref<HTMLCanvasElement>&&, Ref<Source>&&);
-    CanvasCaptureMediaStreamTrack(ScriptExecutionContext&, Ref<HTMLCanvasElement>&&, Ref<MediaStreamTrackPrivate>&&);
+    CanvasCaptureMediaStreamTrack(Document&, Ref<HTMLCanvasElement>&&, Ref<Source>&&);
+    CanvasCaptureMediaStreamTrack(Document&, Ref<HTMLCanvasElement>&&, Ref<MediaStreamTrackPrivate>&&);
 
     bool isCanvas() const final { return true; }
 
index 45d8050..5eb8ca5 100644 (file)
@@ -48,29 +48,24 @@ namespace WebCore {
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(MediaStream);
 
-static inline Ref<const Logger> loggerFromContext(ScriptExecutionContext& context)
+Ref<MediaStream> MediaStream::create(Document& document)
 {
-    return downcast<Document>(context).logger();
+    return MediaStream::create(document, MediaStreamPrivate::create(document.logger(), { }));
 }
 
-Ref<MediaStream> MediaStream::create(ScriptExecutionContext& context)
+Ref<MediaStream> MediaStream::create(Document& document, MediaStream& stream)
 {
-    return MediaStream::create(context, MediaStreamPrivate::create(loggerFromContext(context), { }));
+    return adoptRef(*new MediaStream(document, stream.getTracks()));
 }
 
-Ref<MediaStream> MediaStream::create(ScriptExecutionContext& context, MediaStream& stream)
+Ref<MediaStream> MediaStream::create(Document& document, const MediaStreamTrackVector& tracks)
 {
-    return adoptRef(*new MediaStream(context, stream.getTracks()));
+    return adoptRef(*new MediaStream(document, tracks));
 }
 
-Ref<MediaStream> MediaStream::create(ScriptExecutionContext& context, const MediaStreamTrackVector& tracks)
+Ref<MediaStream> MediaStream::create(Document& document, Ref<MediaStreamPrivate>&& streamPrivate)
 {
-    return adoptRef(*new MediaStream(context, tracks));
-}
-
-Ref<MediaStream> MediaStream::create(ScriptExecutionContext& context, Ref<MediaStreamPrivate>&& streamPrivate)
-{
-    return adoptRef(*new MediaStream(context, WTFMove(streamPrivate)));
+    return adoptRef(*new MediaStream(document, WTFMove(streamPrivate)));
 }
 
 static inline MediaStreamTrackPrivateVector createTrackPrivateVector(const MediaStreamTrackVector& tracks)
@@ -82,9 +77,9 @@ static inline MediaStreamTrackPrivateVector createTrackPrivateVector(const Media
     return trackPrivates;
 }
 
-MediaStream::MediaStream(ScriptExecutionContext& context, const MediaStreamTrackVector& tracks)
-    : ActiveDOMObject(&context)
-    , m_private(MediaStreamPrivate::create(document()->logger(), createTrackPrivateVector(tracks)))
+MediaStream::MediaStream(Document& document, const MediaStreamTrackVector& tracks)
+    : ActiveDOMObject(document)
+    , m_private(MediaStreamPrivate::create(document.logger(), createTrackPrivateVector(tracks)))
     , m_mediaSession(PlatformMediaSession::create(*this))
 {
     // This constructor preserves MediaStreamTrack instances and must be used by calls originating
@@ -101,8 +96,8 @@ MediaStream::MediaStream(ScriptExecutionContext& context, const MediaStreamTrack
     suspendIfNeeded();
 }
 
-MediaStream::MediaStream(ScriptExecutionContext& context, Ref<MediaStreamPrivate>&& streamPrivate)
-    : ActiveDOMObject(&context)
+MediaStream::MediaStream(Document& document, Ref<MediaStreamPrivate>&& streamPrivate)
+    : ActiveDOMObject(document)
     , m_private(WTFMove(streamPrivate))
     , m_mediaSession(PlatformMediaSession::create(*this))
 {
@@ -113,7 +108,7 @@ MediaStream::MediaStream(ScriptExecutionContext& context, Ref<MediaStreamPrivate
     MediaStreamRegistry::shared().registerStream(*this);
 
     for (auto& trackPrivate : m_private->tracks()) {
-        auto track = MediaStreamTrack::create(context, *trackPrivate);
+        auto track = MediaStreamTrack::create(document, *trackPrivate);
         track->addObserver(*this);
         m_trackSet.add(track->id(), WTFMove(track));
     }
@@ -145,7 +140,7 @@ RefPtr<MediaStream> MediaStream::clone()
     for (auto& track : m_trackSet.values())
         clonedTracks.uncheckedAppend(track->clone());
 
-    return MediaStream::create(*scriptExecutionContext(), clonedTracks);
+    return MediaStream::create(*document(), clonedTracks);
 }
 
 void MediaStream::addTrack(MediaStreamTrack& track)
index 5db3bd7..b9e7e75 100644 (file)
@@ -68,10 +68,10 @@ public:
         virtual void didAddOrRemoveTrack() = 0;
     };
 
-    static Ref<MediaStream> create(ScriptExecutionContext&);
-    static Ref<MediaStream> create(ScriptExecutionContext&, MediaStream&);
-    static Ref<MediaStream> create(ScriptExecutionContext&, const MediaStreamTrackVector&);
-    static Ref<MediaStream> create(ScriptExecutionContext&, Ref<MediaStreamPrivate>&&);
+    static Ref<MediaStream> create(Document&);
+    static Ref<MediaStream> create(Document&, MediaStream&);
+    static Ref<MediaStream> create(Document&, const MediaStreamTrackVector&);
+    static Ref<MediaStream> create(Document&, Ref<MediaStreamPrivate>&&);
     virtual ~MediaStream();
 
     String id() const { return m_private->id(); }
@@ -121,8 +121,8 @@ public:
     WEBCORE_EXPORT bool internalRemoveTrack(const String&, StreamModifier);
 
 protected:
-    MediaStream(ScriptExecutionContext&, const MediaStreamTrackVector&);
-    MediaStream(ScriptExecutionContext&, Ref<MediaStreamPrivate>&&);
+    MediaStream(Document&, const MediaStreamTrackVector&);
+    MediaStream(Document&, Ref<MediaStreamPrivate>&&);
 
 #if !RELEASE_LOG_DISABLED
     const Logger& logger() const final { return m_private->logger(); }
index e4b4f36..1bedaf0 100644 (file)
@@ -28,7 +28,7 @@
     Constructor,
     Constructor(MediaStream stream),
     Constructor(sequence<MediaStreamTrack> tracks),
-    ConstructorCallWith=ScriptExecutionContext,
+    ConstructorCallWith=Document,
     ExportToWrappedFunction,
     PrivateIdentifier,
     PublicIdentifier
index 8e136c0..2c8edb9 100644 (file)
@@ -233,7 +233,7 @@ void UserMediaRequest::allow(CaptureDevice&& audioDevice, CaptureDevice&& videoD
         }
         privateStream->monitorOrientation(downcast<Document>(m_scriptExecutionContext)->orientationNotifier());
 
-        auto stream = MediaStream::create(*m_scriptExecutionContext, privateStream.releaseNonNull());
+        auto stream = MediaStream::create(*downcast<Document>(m_scriptExecutionContext), privateStream.releaseNonNull());
         if (stream->getTracks().isEmpty()) {
             deny(MediaAccessDenialReason::HardwareError);
             return;
index 231acfe..39ab860 100644 (file)
@@ -785,18 +785,18 @@ RefPtr<MediaSample> HTMLCanvasElement::toMediaSample()
 #endif
 }
 
-ExceptionOr<Ref<MediaStream>> HTMLCanvasElement::captureStream(ScriptExecutionContext& context, Optional<double>&& frameRequestRate)
+ExceptionOr<Ref<MediaStream>> HTMLCanvasElement::captureStream(Document& document, Optional<double>&& frameRequestRate)
 {
     if (!originClean())
         return Exception(SecurityError, "Canvas is tainted"_s);
     if (RuntimeEnabledFeatures::sharedFeatures().webAPIStatisticsEnabled())
-        ResourceLoadObserver::shared().logCanvasRead(document());
+        ResourceLoadObserver::shared().logCanvasRead(this->document());
 
     if (frameRequestRate && frameRequestRate.value() < 0)
         return Exception(NotSupportedError, "frameRequestRate is negative"_s);
 
-    auto track = CanvasCaptureMediaStreamTrack::create(context, *this, WTFMove(frameRequestRate));
-    auto stream =  MediaStream::create(context);
+    auto track = CanvasCaptureMediaStreamTrack::create(document, *this, WTFMove(frameRequestRate));
+    auto stream =  MediaStream::create(document);
     stream->addTrack(track);
     return stream;
 }
index 7b52b8f..172d991 100644 (file)
@@ -121,7 +121,7 @@ public:
 
 #if ENABLE(MEDIA_STREAM)
     RefPtr<MediaSample> toMediaSample();
-    ExceptionOr<Ref<MediaStream>> captureStream(ScriptExecutionContext&, Optional<double>&& frameRequestRate);
+    ExceptionOr<Ref<MediaStream>> captureStream(Document&, Optional<double>&& frameRequestRate);
 #endif
 
     ImageBuffer* buffer() const;
index fe06c2b..6fcacd4 100644 (file)
@@ -50,5 +50,5 @@ typedef (
     [MayThrowException] DOMString toDataURL(optional DOMString type, optional any quality);
     [CallWith=ScriptExecutionContext, MayThrowException] void toBlob(BlobCallback callback, optional DOMString type, optional any quality);
 
-    [Conditional=MEDIA_STREAM, CallWith=ScriptExecutionContext, MayThrowException, NewObject] MediaStream captureStream(optional double frameRequestRate);
+    [Conditional=MEDIA_STREAM, CallWith=Document, MayThrowException, NewObject] MediaStream captureStream(optional double frameRequestRate);
 };