Title: [189031] trunk
Revision
189031
Author
[email protected]
Date
2015-08-27 10:33:48 -0700 (Thu, 27 Aug 2015)

Log Message

Media Session: MediaSession constructor 'kind' argument optional
https://bugs.webkit.org/show_bug.cgi?id=148527

Reviewed by Jer Noble.

Source/WebCore:

No new tests, updated media/session/session-creation.html.

* Modules/mediasession/MediaSession.cpp:
(WebCore::MediaSession::parseKind): Treat null kind "content".
(WebCore::MediaSession::MediaSession): Delete Document* version.
* Modules/mediasession/MediaSession.h: Make constructor private.
* Modules/mediasession/MediaSession.idl:

* WebCore.xcodeproj/project.pbxproj: Add JSMediaSessionCustom.cpp.

* bindings/js/JSMediaSessionCustom.cpp: Added.
(WebCore::constructJSMediaSession):

* dom/Document.cpp:
(WebCore::Document::defaultMediaSession): Call MediaSession::create.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::session): Compare session with document.defaultMediaSession, not
  its kind.
(WebCore::HTMLMediaElement::setSession): Update comments.

LayoutTests:

* media/session/content-interruptions.html: Restructure to make less timing dependent. Minor cleanup.
* media/session/session-creation-expected.txt:
* media/session/session-creation.html: Test default MediaSession constructor argument.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (189030 => 189031)


--- trunk/LayoutTests/ChangeLog	2015-08-27 17:23:26 UTC (rev 189030)
+++ trunk/LayoutTests/ChangeLog	2015-08-27 17:33:48 UTC (rev 189031)
@@ -1,3 +1,14 @@
+2015-08-27  Eric Carlson  <[email protected]>
+
+        Media Session: MediaSession constructor 'kind' argument optional
+        https://bugs.webkit.org/show_bug.cgi?id=148527
+
+        Reviewed by Jer Noble.
+
+        * media/session/content-interruptions.html: Restructure to make less timing dependent. Minor cleanup.
+        * media/session/session-creation-expected.txt:
+        * media/session/session-creation.html: Test default MediaSession constructor argument.
+
 2015-08-27  Alexey Proskuryakov  <[email protected]>
 
         Add an expectation for another momentum scrolling test that became flaky.

Modified: trunk/LayoutTests/media/session/content-interruptions.html (189030 => 189031)


--- trunk/LayoutTests/media/session/content-interruptions.html	2015-08-27 17:23:26 UTC (rev 189030)
+++ trunk/LayoutTests/media/session/content-interruptions.html	2015-08-27 17:33:48 UTC (rev 189031)
@@ -8,27 +8,25 @@
     
         function runTest() 
         {
-            if (window.testRunner) {
-                testRunner.dumpAsText();
-                testRunner.waitUntilDone();
-            }
-
-            window.jsTestIsAsync = true;
-
+            findMediaElement();
             session = new MediaSession("content");
 
             consoleWrite("Waiting for Content media to begin playing.")
-            var video = document.getElementById("video");
             video.src = "" "../content/counting");
             video.session = session;
             video._onplaying_ = beganPlaying;
+            video._oncanplaythrough_ = canplaythrough;
+        }
+
+        function canplaythrough() 
+        {
             video.play();
         }
 
         function beganPlaying(event)
         {
             consoleWrite("Media began playing.");
-            document.getElementById("video")._onpause_ = paused;
+            video._onpause_ = paused;
 
             if (window.internals) {
                 testExpected('internals.mediaSessionCurrentState(session)', "active");
@@ -51,6 +49,6 @@
 </head>
 <body _onload_="runTest()">
     <p>'Content' start of interruption events should indefinitely pause 'Content' media sessions.</p>
-    <video id="video" />
+    <video id="video" controls> </video>
 </body>
 </html>

Modified: trunk/LayoutTests/media/session/session-creation-expected.txt (189030 => 189031)


--- trunk/LayoutTests/media/session/session-creation-expected.txt	2015-08-27 17:23:26 UTC (rev 189030)
+++ trunk/LayoutTests/media/session/session-creation-expected.txt	2015-08-27 17:33:48 UTC (rev 189031)
@@ -1,20 +1,30 @@
 New media sessions should be in an Idle state after creation.
 
+
 ---
-Testing 'content' session
+Testing "new MediaSession('content')"
+EXPECTED (internals.mediaSessionCurrentState(session) == 'idle') OK
 ---
+
+---
+Testing "new MediaSession('transient')"
 EXPECTED (internals.mediaSessionCurrentState(session) == 'idle') OK
 ---
-Testing 'transient' session
+
 ---
+Testing "new MediaSession('transient-solo')"
 EXPECTED (internals.mediaSessionCurrentState(session) == 'idle') OK
 ---
-Testing 'transient-solo' session
+
 ---
+Testing "new MediaSession('ambient')"
 EXPECTED (internals.mediaSessionCurrentState(session) == 'idle') OK
 ---
-Testing 'ambient' session
+
 ---
+Testing "new MediaSession()"
 EXPECTED (internals.mediaSessionCurrentState(session) == 'idle') OK
+---
+
 END OF TEST
 

Modified: trunk/LayoutTests/media/session/session-creation.html (189030 => 189031)


--- trunk/LayoutTests/media/session/session-creation.html	2015-08-27 17:23:26 UTC (rev 189030)
+++ trunk/LayoutTests/media/session/session-creation.html	2015-08-27 17:33:48 UTC (rev 189031)
@@ -9,20 +9,27 @@
             testSessionKind("transient");
             testSessionKind("transient-solo");
             testSessionKind("ambient");
+            testSessionKind();
 
+            consoleWrite("");
             endTest();
         }
 
         function testSessionKind(sessionKind)
         {
-            consoleWrite("---");
-            consoleWrite("Testing '" + sessionKind + "' session");
-            consoleWrite("---");
+            consoleWrite("<br>---");
 
-            session = new MediaSession(sessionKind);
+            if (sessionKind != undefined) {
+                consoleWrite("Testing \"new MediaSession('" + sessionKind + "')\"");
+                session = new MediaSession(sessionKind);
+            } else {
+                consoleWrite("Testing \"new MediaSession()\"");
+                session = new MediaSession();
+            }
 
             if (window.internals)
                 testExpected('internals.mediaSessionCurrentState(session)', "idle");
+            consoleWrite("---");
         }
     </script>
 </head>

Modified: trunk/Source/WebCore/ChangeLog (189030 => 189031)


--- trunk/Source/WebCore/ChangeLog	2015-08-27 17:23:26 UTC (rev 189030)
+++ trunk/Source/WebCore/ChangeLog	2015-08-27 17:33:48 UTC (rev 189031)
@@ -1,3 +1,31 @@
+2015-08-27  Eric Carlson  <[email protected]>
+
+        Media Session: MediaSession constructor 'kind' argument optional
+        https://bugs.webkit.org/show_bug.cgi?id=148527
+
+        Reviewed by Jer Noble.
+
+        No new tests, updated media/session/session-creation.html.
+
+        * Modules/mediasession/MediaSession.cpp:
+        (WebCore::MediaSession::parseKind): Treat null kind "content".
+        (WebCore::MediaSession::MediaSession): Delete Document* version.
+        * Modules/mediasession/MediaSession.h: Make constructor private.
+        * Modules/mediasession/MediaSession.idl:
+
+        * WebCore.xcodeproj/project.pbxproj: Add JSMediaSessionCustom.cpp.
+
+        * bindings/js/JSMediaSessionCustom.cpp: Added.
+        (WebCore::constructJSMediaSession):
+
+        * dom/Document.cpp:
+        (WebCore::Document::defaultMediaSession): Call MediaSession::create.
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::session): Compare session with document.defaultMediaSession, not
+          its kind.
+        (WebCore::HTMLMediaElement::setSession): Update comments.
+
 2015-08-27  Zalan Bujtas  <[email protected]>
 
         Simple line layout: Use float types wherever possible to match line tree.

Modified: trunk/Source/WebCore/Modules/mediasession/MediaSession.cpp (189030 => 189031)


--- trunk/Source/WebCore/Modules/mediasession/MediaSession.cpp	2015-08-27 17:23:26 UTC (rev 189030)
+++ trunk/Source/WebCore/Modules/mediasession/MediaSession.cpp	2015-08-27 17:33:48 UTC (rev 189031)
@@ -46,23 +46,21 @@
 MediaSession::Kind MediaSession::parseKind(const String& kind)
 {
     // 4. Media Session
-    // 2. If no corresponding media session type can be found for the provided media session category or media session
-    //    category is empty, then set media session's current media session type to "content".
+    // 2. Set media session's current media session type to the corresponding media session type of media session category.
+
+    if (kind.isNull() || kind == contentKind)
+        return MediaSession::Kind::Content;
     if (kind == ambientKind)
         return MediaSession::Kind::Ambient;
     if (kind == transientKind)
         return MediaSession::Kind::Transient;
     if (kind == transientSoloKind)
         return MediaSession::Kind::TransientSolo;
+
+    ASSERT_NOT_REACHED();
     return MediaSession::Kind::Content;
 }
 
-MediaSession::MediaSession(Document& document)
-    : m_document(document)
-{
-    MediaSessionManager::singleton().addMediaSession(*this);
-}
-
 MediaSession::MediaSession(ScriptExecutionContext& context, const String& kind)
     : m_document(downcast<Document>(context))
     , m_kind(parseKind(kind))

Modified: trunk/Source/WebCore/Modules/mediasession/MediaSession.h (189030 => 189031)


--- trunk/Source/WebCore/Modules/mediasession/MediaSession.h	2015-08-27 17:23:26 UTC (rev 189030)
+++ trunk/Source/WebCore/Modules/mediasession/MediaSession.h	2015-08-27 17:33:48 UTC (rev 189031)
@@ -53,13 +53,11 @@
         Ambient
     };
 
-    static Ref<MediaSession> create(ScriptExecutionContext& context, const String& kind)
+    static Ref<MediaSession> create(ScriptExecutionContext& context, const String& kind = String())
     {
         return adoptRef(*new MediaSession(context, kind));
     }
 
-    explicit MediaSession(Document&);
-    MediaSession(ScriptExecutionContext&, const String&);
     ~MediaSession();
 
     String kind() const;
@@ -91,6 +89,8 @@
 private:
     friend class HTMLMediaElement;
 
+    MediaSession(ScriptExecutionContext&, const String&);
+
     static Kind parseKind(const String&);
 
     void addMediaElement(HTMLMediaElement&);

Modified: trunk/Source/WebCore/Modules/mediasession/MediaSession.idl (189030 => 189031)


--- trunk/Source/WebCore/Modules/mediasession/MediaSession.idl	2015-08-27 17:23:26 UTC (rev 189030)
+++ trunk/Source/WebCore/Modules/mediasession/MediaSession.idl	2015-08-27 17:33:48 UTC (rev 189031)
@@ -25,7 +25,7 @@
 
 [
     Conditional=MEDIA_SESSION,
-    Constructor(MediaSessionKind kind),
+    CustomConstructor(optional MediaSessionKind kind),
     ConstructorCallWith=ScriptExecutionContext,
     ImplementationLacksVTable,
 ] interface MediaSession {

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (189030 => 189031)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2015-08-27 17:23:26 UTC (rev 189030)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2015-08-27 17:33:48 UTC (rev 189031)
@@ -204,6 +204,7 @@
 		077AF14018F4AE400001ED61 /* SerializedPlatformRepresentation.h in Headers */ = {isa = PBXBuildFile; fileRef = 077AF13E18F4AE400001ED61 /* SerializedPlatformRepresentation.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		077AF14318F4B1BB0001ED61 /* SerializedPlatformRepresentationMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 077AF14118F4B1BB0001ED61 /* SerializedPlatformRepresentationMac.h */; };
 		077AF14418F4B1BB0001ED61 /* SerializedPlatformRepresentationMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 077AF14218F4B1BB0001ED61 /* SerializedPlatformRepresentationMac.mm */; };
+		077B640F1B8F5D6B003E9AD5 /* JSMediaSessionCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 077B640E1B8F5375003E9AD5 /* JSMediaSessionCustom.cpp */; };
 		0783228418013ED800999E0C /* MediaStreamAudioSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0783228218013ED700999E0C /* MediaStreamAudioSource.cpp */; };
 		0783228518013ED800999E0C /* MediaStreamAudioSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 0783228318013ED800999E0C /* MediaStreamAudioSource.h */; };
 		07846342145B151A00A58DF1 /* JSTrackEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 07846340145B151A00A58DF1 /* JSTrackEvent.cpp */; };
@@ -7386,6 +7387,7 @@
 		077AF13E18F4AE400001ED61 /* SerializedPlatformRepresentation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SerializedPlatformRepresentation.h; sourceTree = "<group>"; };
 		077AF14118F4B1BB0001ED61 /* SerializedPlatformRepresentationMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SerializedPlatformRepresentationMac.h; sourceTree = "<group>"; };
 		077AF14218F4B1BB0001ED61 /* SerializedPlatformRepresentationMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SerializedPlatformRepresentationMac.mm; sourceTree = "<group>"; };
+		077B640E1B8F5375003E9AD5 /* JSMediaSessionCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSMediaSessionCustom.cpp; sourceTree = "<group>"; };
 		0783228218013ED700999E0C /* MediaStreamAudioSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MediaStreamAudioSource.cpp; sourceTree = "<group>"; };
 		0783228318013ED800999E0C /* MediaStreamAudioSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaStreamAudioSource.h; sourceTree = "<group>"; };
 		07846340145B151A00A58DF1 /* JSTrackEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSTrackEvent.cpp; sourceTree = "<group>"; };
@@ -21484,6 +21486,7 @@
 		BC4EDEF70C08F414007EDD49 /* Custom */ = {
 			isa = PBXGroup;
 			children = (
+				077B640E1B8F5375003E9AD5 /* JSMediaSessionCustom.cpp */,
 				BC2ED6BB0C6BD2F000920BFF /* JSAttrCustom.cpp */,
 				FDEAAAEF12B02EE400DCF33B /* JSAudioBufferSourceNodeCustom.cpp */,
 				FDEAAAF012B02EE400DCF33B /* JSAudioContextCustom.cpp */,
@@ -28224,6 +28227,7 @@
 				14DCF3B21B6BE2080062D4C2 /* JSCountQueuingStrategy.cpp in Sources */,
 				CD37B39815C1B971006DC898 /* DiagnosticLoggingKeys.cpp in Sources */,
 				CECADFC6153778FF00E37068 /* DictationAlternative.cpp in Sources */,
+				077B640F1B8F5D6B003E9AD5 /* JSMediaSessionCustom.cpp in Sources */,
 				CECADFC8153778FF00E37068 /* DictationCommand.cpp in Sources */,
 				D0BD4F5C1408850F006839B6 /* DictationCommandIOS.cpp in Sources */,
 				312D67B11535691F00563D0D /* Dictionary.cpp in Sources */,

Added: trunk/Source/WebCore/bindings/js/JSMediaSessionCustom.cpp (0 => 189031)


--- trunk/Source/WebCore/bindings/js/JSMediaSessionCustom.cpp	                        (rev 0)
+++ trunk/Source/WebCore/bindings/js/JSMediaSessionCustom.cpp	2015-08-27 17:33:48 UTC (rev 189031)
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "JSMediaSession.h"
+
+#if ENABLE(MEDIA_SESSION)
+
+#include "ExceptionCode.h"
+#include "JSDOMBinding.h"
+#include "MediaSession.h"
+#include <runtime/Error.h>
+#include <runtime/JSString.h>
+#include <wtf/GetPtr.h>
+
+using namespace JSC;
+
+namespace WebCore {
+
+EncodedJSValue JSC_HOST_CALL constructJSMediaSession(ExecState* exec)
+{
+    auto* castedThis = jsCast<DOMConstructorObject*>(exec->callee());
+    auto* context = castedThis->scriptExecutionContext();
+    if (!context)
+        return throwConstructorDocumentUnavailableError(*exec, "MediaSession");
+
+    String kind;
+    if (exec->argumentCount() > 0) {
+        JSString* kindString = exec->argument(0).toString(exec);
+        if (UNLIKELY(exec->hadException()))
+            return JSValue::encode(jsUndefined());
+        kind = kindString->value(exec);
+        if (kind != "content" && kind != "transient" && kind != "transient-solo" && kind != "ambient")
+            return throwArgumentMustBeEnumError(*exec, 0, "kind", "MediaSession", nullptr, "\"content\", \"transient\", \"transient-solo\", \"ambient\"");
+    } else
+        kind = "content";
+
+    RefPtr<MediaSession> object = MediaSession::create(*context, kind);
+    return JSValue::encode(asObject(toJS(exec, castedThis->globalObject(), object.get())));
+}
+
+} // namespace WebCore
+
+#endif

Modified: trunk/Source/WebCore/dom/Document.cpp (189030 => 189031)


--- trunk/Source/WebCore/dom/Document.cpp	2015-08-27 17:23:26 UTC (rev 189030)
+++ trunk/Source/WebCore/dom/Document.cpp	2015-08-27 17:33:48 UTC (rev 189031)
@@ -6701,7 +6701,7 @@
 MediaSession& Document::defaultMediaSession()
 {
     if (!m_defaultMediaSession)
-        m_defaultMediaSession = adoptRef(*new MediaSession(*this));
+        m_defaultMediaSession = MediaSession::create(*scriptExecutionContext());
 
     return *m_defaultMediaSession;
 }

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (189030 => 189031)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2015-08-27 17:23:26 UTC (rev 189030)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2015-08-27 17:33:48 UTC (rev 189031)
@@ -6542,36 +6542,32 @@
 MediaSession* HTMLMediaElement::session() const
 {
     MediaSession* session = m_session.get();
-    if (session && session->kindEnum() == MediaSession::Kind::Default)
+    if (session && session == &document().defaultMediaSession())
         return nullptr;
+
     return session;
 }
 
 void HTMLMediaElement::setSession(MediaSession* session)
 {
-    // 6.1
+    // 6.1. Extensions to the HTMLMediaElement interface
     // 1. Let m be the media element in question.
-    // 2. Let old media session be m's current media session, if it has one, and null otherwise.
-    // 3. Let new media session be null.
-    // 4. Set m's current media session to null, if it currently has one.
-    // 5. Let m's current media session be the new value or the top-level browsing context's media session if the new
-    //    value is null.
-    // 6. If the new value is null, then set the m's kind IDL attribute to the empty string. Otherwise, set m's kind IDL
-    //    attribute to the value of current media session's kind attribute.
-    // 7. Let new media session be m's current media session.
-    // 8. Update media sessions: If old media session and new media session are the same (whether both null or both the
-    //    same media session), then terminate these steps.
-    // 9. If m is an active audio-producing participant of old media session, then pause m and remove m from old media
-    //    session's active audio-producing participants.
-    // 10. If old media session is not null and no longer has one or more active audio-producing participants, then run
-    //     the media session release algorithm for old media session.
+    // 2. Let old media session be m’s current media session, if it has one, and null otherwise.
+    // 3. Let m’s current media session be the new value or the top-level browsing context’s media session if the new value is null.
+    // 4. Let new media session be m’s current media session.
 
+    // 5. Update media sessions: If old media session and new media session are the same (whether both null or both the same media session), then terminate these steps.
+    if (m_session.get() == session)
+        return;
+
     if (m_session) {
+        // 6. If m is an audio-producing participant of old media session, then pause m and remove m from old media session’s list of audio-producing participants.
         if (m_session->isMediaElementActive(*this))
             pause();
 
         m_session->removeMediaElement(*this);
 
+        // 7. If old media session is not null and no longer has one or more audio-producing participants, then run the media session deactivation algorithm for old media session.
         if (!m_session->hasActiveMediaElements())
             m_session->releaseSession();
     }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to