<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[278497] trunk/Source/WebCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/278497">278497</a></dd>
<dt>Author</dt> <dd>darin@apple.com</dd>
<dt>Date</dt> <dd>2021-06-04 14:04:14 -0700 (Fri, 04 Jun 2021)</dd>
</dl>

<h3>Log Message</h3>
<pre>Move from WebCore::SuccessOr to WTF::Expected
https://bugs.webkit.org/show_bug.cgi?id=226614

Reviewed by Sam Weinig.

The upcoming std::expected is designed for cases like the ones we
are using SuccessOr for, using void for the expected type in a case like
this where it's success or failure. Our WTF::Expected is for our use
while waiting for compilers with std::expected. It was straightforward
to port our uses of SuccessOr to instead use Expected.

* Headers.cmake: Removed SuccessOr.h.
* WebCore.xcodeproj/project.pbxproj: Ditto.

* dom/SuccessOr.h: Emptied out this file for now; delete later.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::canTransitionFromAutoplayToPlay const): Use
Expected for the return type and call makeUnexpected as needed. Also
updated the check of the result from playbackStateChangePermitted to
call Expected::error instead of SuccessOr::value.
(WebCore::HTMLMediaElement::setReadyState): Use Expected::error
instead of SuccessOr::value, and updated local variable name for
greater clarity. Also fixed one call site that had the success check
backwards: The symptom is that it would never log "Autoplay blocked"
in that case, but otherwise seems harmless.
(WebCore::HTMLMediaElement::play): Ditto.

* html/HTMLMediaElement.h: Use Expected for the return type of
canTransitionFromAutoplayToPlay.

* html/MediaElementSession.cpp:
(WebCore::MediaElementSession::playbackStateChangePermitted const): Use
Expected for the return type and call makeUnexpected as needed.

* html/MediaElementSession.h: Removed include of SuccessOr.h, and
tweaked coding style a bit. Use Expected for the return type of
playbackStateChangePermitted.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreHeaderscmake">trunk/Source/WebCore/Headers.cmake</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebCoredomSuccessOrh">trunk/Source/WebCore/dom/SuccessOr.h</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLMediaElementcpp">trunk/Source/WebCore/html/HTMLMediaElement.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLMediaElementh">trunk/Source/WebCore/html/HTMLMediaElement.h</a></li>
<li><a href="#trunkSourceWebCorehtmlMediaElementSessioncpp">trunk/Source/WebCore/html/MediaElementSession.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlMediaElementSessionh">trunk/Source/WebCore/html/MediaElementSession.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (278496 => 278497)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2021-06-04 20:41:45 UTC (rev 278496)
+++ trunk/Source/WebCore/ChangeLog      2021-06-04 21:04:14 UTC (rev 278497)
</span><span class="lines">@@ -1,3 +1,44 @@
</span><ins>+2021-06-03  Darin Adler  <darin@apple.com>
+
+        Move from WebCore::SuccessOr to WTF::Expected
+        https://bugs.webkit.org/show_bug.cgi?id=226614
+
+        Reviewed by Sam Weinig.
+
+        The upcoming std::expected is designed for cases like the ones we
+        are using SuccessOr for, using void for the expected type in a case like
+        this where it's success or failure. Our WTF::Expected is for our use
+        while waiting for compilers with std::expected. It was straightforward
+        to port our uses of SuccessOr to instead use Expected.
+
+        * Headers.cmake: Removed SuccessOr.h.
+        * WebCore.xcodeproj/project.pbxproj: Ditto.
+
+        * dom/SuccessOr.h: Emptied out this file for now; delete later.
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::canTransitionFromAutoplayToPlay const): Use
+        Expected for the return type and call makeUnexpected as needed. Also
+        updated the check of the result from playbackStateChangePermitted to
+        call Expected::error instead of SuccessOr::value.
+        (WebCore::HTMLMediaElement::setReadyState): Use Expected::error
+        instead of SuccessOr::value, and updated local variable name for
+        greater clarity. Also fixed one call site that had the success check
+        backwards: The symptom is that it would never log "Autoplay blocked"
+        in that case, but otherwise seems harmless.
+        (WebCore::HTMLMediaElement::play): Ditto.
+
+        * html/HTMLMediaElement.h: Use Expected for the return type of
+        canTransitionFromAutoplayToPlay.
+
+        * html/MediaElementSession.cpp:
+        (WebCore::MediaElementSession::playbackStateChangePermitted const): Use
+        Expected for the return type and call makeUnexpected as needed.
+
+        * html/MediaElementSession.h: Removed include of SuccessOr.h, and
+        tweaked coding style a bit. Use Expected for the return type of
+        playbackStateChangePermitted.
+
</ins><span class="cx"> 2021-06-04  Ryosuke Niwa  <rniwa@webkit.org>
</span><span class="cx"> 
</span><span class="cx">         Store MediaPlayer using WeakPtr in MediaPlayerPrivateRemote
</span></span></pre></div>
<a id="trunkSourceWebCoreHeaderscmake"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Headers.cmake (278496 => 278497)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Headers.cmake       2021-06-04 20:41:45 UTC (rev 278496)
+++ trunk/Source/WebCore/Headers.cmake  2021-06-04 21:04:14 UTC (rev 278497)
</span><span class="lines">@@ -525,7 +525,6 @@
</span><span class="cx">     dom/SpaceSplitString.h
</span><span class="cx">     dom/StaticRange.h
</span><span class="cx">     dom/StyledElement.h
</span><del>-    dom/SuccessOr.h
</del><span class="cx">     dom/TaskSource.h
</span><span class="cx">     dom/Text.h
</span><span class="cx">     dom/TextEvent.h
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (278496 => 278497)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj   2021-06-04 20:41:45 UTC (rev 278496)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj      2021-06-04 21:04:14 UTC (rev 278497)
</span><span class="lines">@@ -4297,7 +4297,6 @@
</span><span class="cx">          C6F0900A14327B6100685849 /* MutationCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = C6F0900114327B6100685849 /* MutationCallback.h */; };
</span><span class="cx">          C6F0900F14327B6100685849 /* MutationObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = C6F0900614327B6100685849 /* MutationObserver.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">          C6F0902D14327D4F00685849 /* JSMutationObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = C6F0902514327D4F00685849 /* JSMutationObserver.h */; };
</span><del>-               C99058131E32C75F0073BDDA /* SuccessOr.h in Headers */ = {isa = PBXBuildFile; fileRef = C99058121E32B7340073BDDA /* SuccessOr.h */; settings = {ATTRIBUTES = (Private, ); }; };
</del><span class="cx">           C9D467051E60C465008195FB /* AutoplayEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = C9D467041E60C3EB008195FB /* AutoplayEvent.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">          CA3A4AAF25416E40006CDAE2 /* ImageResolution.h in Headers */ = {isa = PBXBuildFile; fileRef = CA3A4AAD25416E3E006CDAE2 /* ImageResolution.h */; };
</span><span class="cx">          CA3BF67E10D99BAE00E6CE53 /* ScrollAnimator.h in Headers */ = {isa = PBXBuildFile; fileRef = CA3BF67D10D99BAE00E6CE53 /* ScrollAnimator.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="lines">@@ -14848,7 +14847,6 @@
</span><span class="cx">          C6F0902414327D4F00685849 /* JSMutationObserver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSMutationObserver.cpp; sourceTree = "<group>"; };
</span><span class="cx">          C6F0902514327D4F00685849 /* JSMutationObserver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSMutationObserver.h; sourceTree = "<group>"; };
</span><span class="cx">          C6F0917E143A2BB900685849 /* JSMutationObserverCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSMutationObserverCustom.cpp; sourceTree = "<group>"; };
</span><del>-               C99058121E32B7340073BDDA /* SuccessOr.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SuccessOr.h; sourceTree = "<group>"; };
</del><span class="cx">           C9D467041E60C3EB008195FB /* AutoplayEvent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AutoplayEvent.h; sourceTree = "<group>"; };
</span><span class="cx">          CA091D8623CF907800AD4346 /* StyleImageSet.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = StyleImageSet.cpp; sourceTree = "<group>"; };
</span><span class="cx">          CA091D8923CF908800AD4346 /* StyleImageSet.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = StyleImageSet.h; sourceTree = "<group>"; };
</span><span class="lines">@@ -30911,7 +30909,6 @@
</span><span class="cx">                          81AC6C34131C57C20009A7E0 /* StringCallback.idl */,
</span><span class="cx">                          A8C4A7EC09D563270003AC8D /* StyledElement.cpp */,
</span><span class="cx">                          A8C4A7EB09D563270003AC8D /* StyledElement.h */,
</span><del>-                               C99058121E32B7340073BDDA /* SuccessOr.h */,
</del><span class="cx">                           463EB6201B8789CB0096ED51 /* TagCollection.cpp */,
</span><span class="cx">                          463EB6211B8789CB0096ED51 /* TagCollection.h */,
</span><span class="cx">                          9B0ABCAC236BB40A00B45085 /* TaskSource.h */,
</span><span class="lines">@@ -35455,7 +35452,6 @@
</span><span class="cx">                          659A7D130B6DB4D9001155B3 /* SubstituteData.h in Headers */,
</span><span class="cx">                          1A8F6B020DB53006001DB794 /* SubstituteResource.h in Headers */,
</span><span class="cx">                          5778BD821DA4806C009E3009 /* SubtleCrypto.h in Headers */,
</span><del>-                               C99058131E32C75F0073BDDA /* SuccessOr.h in Headers */,
</del><span class="cx">                           93B2D8160F9920D2006AE6B2 /* SuddenTermination.h in Headers */,
</span><span class="cx">                          97C078501165D5BE003A32EF /* SuffixTree.h in Headers */,
</span><span class="cx">                          97627B9814FB5424002CDCA1 /* Supplementable.h in Headers */,
</span></span></pre></div>
<a id="trunkSourceWebCoredomSuccessOrh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/SuccessOr.h (278496 => 278497)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/SuccessOr.h     2021-06-04 20:41:45 UTC (rev 278496)
+++ trunk/Source/WebCore/dom/SuccessOr.h        2021-06-04 21:04:14 UTC (rev 278497)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2017 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2021 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -25,17 +25,4 @@
</span><span class="cx"> 
</span><span class="cx"> #pragma once
</span><span class="cx"> 
</span><del>-#include <optional>
-
-namespace WebCore {
-
-// FIXME: This is used in two places. We should switch them to WTF::Expected and delete this.
-template<typename T> class SuccessOr : public std::optional<T> {
-public:
-    SuccessOr() : std::optional<T>() { }
-    SuccessOr(T&& error) : std::optional<T>(error) { }
-
-    explicit constexpr operator bool() const { return !std::optional<T>::operator bool(); }
-};
-
-} // namespace WebCore
</del><ins>+// Nothing here any more. No need to include it. We plan to delete this header.
</ins></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLMediaElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (278496 => 278497)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLMediaElement.cpp   2021-06-04 20:41:45 UTC (rev 278496)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp      2021-06-04 21:04:14 UTC (rev 278497)
</span><span class="lines">@@ -2321,41 +2321,41 @@
</span><span class="cx">     endProcessingMediaPlayerCallback();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-SuccessOr<MediaPlaybackDenialReason> HTMLMediaElement::canTransitionFromAutoplayToPlay() const
</del><ins>+Expected<void, MediaPlaybackDenialReason> HTMLMediaElement::canTransitionFromAutoplayToPlay() const
</ins><span class="cx"> {
</span><span class="cx">     if (m_readyState != HAVE_ENOUGH_DATA) {
</span><span class="cx">         ALWAYS_LOG(LOGIDENTIFIER, "m_readyState != HAVE_ENOUGH_DATA");
</span><del>-        return MediaPlaybackDenialReason::PageConsentRequired;
</del><ins>+        return makeUnexpected(MediaPlaybackDenialReason::PageConsentRequired);
</ins><span class="cx">     }
</span><span class="cx">     if (!isAutoplaying()) {
</span><span class="cx">         ALWAYS_LOG(LOGIDENTIFIER, "!isAutoplaying");
</span><del>-        return MediaPlaybackDenialReason::PageConsentRequired;
</del><ins>+        return makeUnexpected(MediaPlaybackDenialReason::PageConsentRequired);
</ins><span class="cx">     }
</span><span class="cx">     if (!mediaSession().autoplayPermitted()) {
</span><span class="cx">         ALWAYS_LOG(LOGIDENTIFIER, "!mediaSession().autoplayPermitted");
</span><del>-        return MediaPlaybackDenialReason::PageConsentRequired;
</del><ins>+        return makeUnexpected(MediaPlaybackDenialReason::PageConsentRequired);
</ins><span class="cx">     }
</span><span class="cx">     if (!paused()) {
</span><span class="cx">         ALWAYS_LOG(LOGIDENTIFIER, "!paused");
</span><del>-        return MediaPlaybackDenialReason::PageConsentRequired;
</del><ins>+        return makeUnexpected(MediaPlaybackDenialReason::PageConsentRequired);
</ins><span class="cx">     }
</span><span class="cx">     if (!autoplay()) {
</span><span class="cx">         ALWAYS_LOG(LOGIDENTIFIER, "!autoplay");
</span><del>-        return MediaPlaybackDenialReason::PageConsentRequired;
</del><ins>+        return makeUnexpected(MediaPlaybackDenialReason::PageConsentRequired);
</ins><span class="cx">     }
</span><span class="cx">     if (pausedForUserInteraction()) {
</span><span class="cx">         ALWAYS_LOG(LOGIDENTIFIER, "pausedForUserInteraction");
</span><del>-        return MediaPlaybackDenialReason::PageConsentRequired;
</del><ins>+        return makeUnexpected(MediaPlaybackDenialReason::PageConsentRequired);
</ins><span class="cx">     }
</span><span class="cx">     if (document().isSandboxed(SandboxAutomaticFeatures)) {
</span><span class="cx">         ALWAYS_LOG(LOGIDENTIFIER, "isSandboxed");
</span><del>-        return MediaPlaybackDenialReason::PageConsentRequired;
</del><ins>+        return makeUnexpected(MediaPlaybackDenialReason::PageConsentRequired);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     auto permitted = mediaSession().playbackStateChangePermitted(MediaPlaybackState::Playing);
</span><span class="cx"> #if !RELEASE_LOG_DISABLED
</span><span class="cx">     if (!permitted)
</span><del>-        ALWAYS_LOG(LOGIDENTIFIER, permitted.value());
</del><ins>+        ALWAYS_LOG(LOGIDENTIFIER, permitted.error());
</ins><span class="cx">     else
</span><span class="cx">         ALWAYS_LOG(LOGIDENTIFIER, "can transition!");
</span><span class="cx"> #endif
</span><span class="lines">@@ -2470,8 +2470,8 @@
</span><span class="cx"> 
</span><span class="cx">         scheduleEvent(eventNames().canplaythroughEvent);
</span><span class="cx"> 
</span><del>-        auto success = canTransitionFromAutoplayToPlay();
-        if (success) {
</del><ins>+        auto canTransition = canTransitionFromAutoplayToPlay();
+        if (canTransition) {
</ins><span class="cx">             m_paused = false;
</span><span class="cx">             setShowPosterFlag(false);
</span><span class="cx">             invalidateCachedTime();
</span><span class="lines">@@ -2478,7 +2478,7 @@
</span><span class="cx">             setAutoplayEventPlaybackState(AutoplayEventPlaybackState::StartedWithoutUserGesture);
</span><span class="cx">             m_playbackStartedTime = currentMediaTime().toDouble();
</span><span class="cx">             scheduleEvent(eventNames().playEvent);
</span><del>-        } else if (success.value() == MediaPlaybackDenialReason::UserGestureRequired) {
</del><ins>+        } else if (canTransition.error() == MediaPlaybackDenialReason::UserGestureRequired) {
</ins><span class="cx">             ALWAYS_LOG(LOGIDENTIFIER, "Autoplay blocked, user gesture required");
</span><span class="cx">             setAutoplayEventPlaybackState(AutoplayEventPlaybackState::PreventedAutoplay);
</span><span class="cx">         }
</span><span class="lines">@@ -2488,7 +2488,7 @@
</span><span class="cx">     // honoring any playback denial reasons such as the requirement of a user gesture.
</span><span class="cx">     if (m_readyState == HAVE_FUTURE_DATA && oldState < HAVE_FUTURE_DATA && potentiallyPlaying() && !mediaSession().playbackStateChangePermitted(MediaPlaybackState::Playing)) {
</span><span class="cx">         auto canTransition = canTransitionFromAutoplayToPlay();
</span><del>-        if (canTransition && canTransition.value() == MediaPlaybackDenialReason::UserGestureRequired)
</del><ins>+        if (!canTransition && canTransition.error() == MediaPlaybackDenialReason::UserGestureRequired)
</ins><span class="cx">             ALWAYS_LOG(LOGIDENTIFIER, "Autoplay blocked, user gesture required");
</span><span class="cx"> 
</span><span class="cx">         pauseInternal();
</span><span class="lines">@@ -3475,11 +3475,11 @@
</span><span class="cx"> {
</span><span class="cx">     ALWAYS_LOG(LOGIDENTIFIER);
</span><span class="cx"> 
</span><del>-    auto success = mediaSession().playbackStateChangePermitted(MediaPlaybackState::Playing);
-    if (!success) {
-        if (success.value() == MediaPlaybackDenialReason::UserGestureRequired)
</del><ins>+    auto permitted = mediaSession().playbackStateChangePermitted(MediaPlaybackState::Playing);
+    if (!permitted) {
+        if (permitted.error() == MediaPlaybackDenialReason::UserGestureRequired)
</ins><span class="cx">             setAutoplayEventPlaybackState(AutoplayEventPlaybackState::PreventedAutoplay);
</span><del>-        ERROR_LOG(LOGIDENTIFIER, "rejecting promise: ", success.value());
</del><ins>+        ERROR_LOG(LOGIDENTIFIER, "rejecting promise: ", permitted.error());
</ins><span class="cx">         promise.reject(NotAllowedError);
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="lines">@@ -3501,10 +3501,10 @@
</span><span class="cx"> {
</span><span class="cx">     ALWAYS_LOG(LOGIDENTIFIER);
</span><span class="cx"> 
</span><del>-    auto success = mediaSession().playbackStateChangePermitted(MediaPlaybackState::Playing);
-    if (!success) {
-        ERROR_LOG(LOGIDENTIFIER, "playback not permitted: ", success.value());
-        if (success.value() == MediaPlaybackDenialReason::UserGestureRequired)
</del><ins>+    auto permitted = mediaSession().playbackStateChangePermitted(MediaPlaybackState::Playing);
+    if (!permitted) {
+        ERROR_LOG(LOGIDENTIFIER, "playback not permitted: ", permitted.error());
+        if (permitted.error() == MediaPlaybackDenialReason::UserGestureRequired)
</ins><span class="cx">             setAutoplayEventPlaybackState(AutoplayEventPlaybackState::PreventedAutoplay);
</span><span class="cx">         return;
</span><span class="cx">     }
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLMediaElementh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (278496 => 278497)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLMediaElement.h     2021-06-04 20:41:45 UTC (rev 278496)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h        2021-06-04 21:04:14 UTC (rev 278497)
</span><span class="lines">@@ -818,7 +818,7 @@
</span><span class="cx">     bool pausedForUserInteraction() const;
</span><span class="cx">     bool couldPlayIfEnoughData() const;
</span><span class="cx">     void dispatchPlayPauseEventsIfNeedsQuirks();
</span><del>-    SuccessOr<MediaPlaybackDenialReason> canTransitionFromAutoplayToPlay() const;
</del><ins>+    Expected<void, MediaPlaybackDenialReason> canTransitionFromAutoplayToPlay() const;
</ins><span class="cx"> 
</span><span class="cx">     void setAutoplayEventPlaybackState(AutoplayEventPlaybackState);
</span><span class="cx">     void userDidInterfereWithAutoplay();
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlMediaElementSessioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/MediaElementSession.cpp (278496 => 278497)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/MediaElementSession.cpp        2021-06-04 20:41:45 UTC (rev 278496)
+++ trunk/Source/WebCore/html/MediaElementSession.cpp   2021-06-04 21:04:14 UTC (rev 278497)
</span><span class="lines">@@ -327,12 +327,12 @@
</span><span class="cx">     m_restrictions &= ~restriction;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-SuccessOr<MediaPlaybackDenialReason> MediaElementSession::playbackStateChangePermitted(MediaPlaybackState state) const
</del><ins>+Expected<void, MediaPlaybackDenialReason> MediaElementSession::playbackStateChangePermitted(MediaPlaybackState state) const
</ins><span class="cx"> {
</span><span class="cx">     INFO_LOG(LOGIDENTIFIER, "state = ", state);
</span><span class="cx">     if (m_element.isSuspended()) {
</span><span class="cx">         ALWAYS_LOG(LOGIDENTIFIER, "Returning FALSE because element is suspended");
</span><del>-        return MediaPlaybackDenialReason::InvalidState;
</del><ins>+        return makeUnexpected(MediaPlaybackDenialReason::InvalidState);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     auto& document = m_element.document();
</span><span class="lines">@@ -339,7 +339,7 @@
</span><span class="cx">     auto* page = document.page();
</span><span class="cx">     if (!page || page->mediaPlaybackIsSuspended()) {
</span><span class="cx">         ALWAYS_LOG(LOGIDENTIFIER, "Returning FALSE because media playback is suspended");
</span><del>-        return MediaPlaybackDenialReason::PageConsentRequired;
</del><ins>+        return makeUnexpected(MediaPlaybackDenialReason::PageConsentRequired);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if (document.isMediaDocument() && !document.ownerElement())
</span><span class="lines">@@ -350,7 +350,7 @@
</span><span class="cx"> 
</span><span class="cx">     if (requiresFullscreenForVideoPlayback() && !fullscreenPermitted()) {
</span><span class="cx">         ALWAYS_LOG(LOGIDENTIFIER, "Returning FALSE because of fullscreen restriction");
</span><del>-        return MediaPlaybackDenialReason::FullscreenRequired;
</del><ins>+        return makeUnexpected(MediaPlaybackDenialReason::FullscreenRequired);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if (m_restrictions & OverrideUserGestureRequirementForMainContent && updateIsMainContent())
</span><span class="lines">@@ -372,7 +372,7 @@
</span><span class="cx">         && !m_element.paused() && state == MediaPlaybackState::Paused
</span><span class="cx">         && !document.processingUserGestureForMedia()) {
</span><span class="cx">         ALWAYS_LOG(LOGIDENTIFIER, "Returning FALSE because a quirk requires a user gesture to pause while in Picture-in-Picture");
</span><del>-        return MediaPlaybackDenialReason::UserGestureRequired;
</del><ins>+        return makeUnexpected(MediaPlaybackDenialReason::UserGestureRequired);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if (topDocument.mediaState() & MediaProducer::MediaState::HasUserInteractedWithMediaElement && topDocument.quirks().needsPerDocumentAutoplayBehavior())
</span><span class="lines">@@ -383,17 +383,17 @@
</span><span class="cx"> 
</span><span class="cx">     if (m_restrictions & RequireUserGestureForVideoRateChange && m_element.isVideo() && !document.processingUserGestureForMedia()) {
</span><span class="cx">         ALWAYS_LOG(LOGIDENTIFIER, "Returning FALSE because a user gesture is required for video rate change restriction");
</span><del>-        return MediaPlaybackDenialReason::UserGestureRequired;
</del><ins>+        return makeUnexpected(MediaPlaybackDenialReason::UserGestureRequired);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if (m_restrictions & RequireUserGestureForAudioRateChange && (!m_element.isVideo() || m_element.hasAudio()) && !m_element.muted() && m_element.volume() && !document.processingUserGestureForMedia()) {
</span><span class="cx">         ALWAYS_LOG(LOGIDENTIFIER, "Returning FALSE because a user gesture is required for audio rate change restriction");
</span><del>-        return MediaPlaybackDenialReason::UserGestureRequired;
</del><ins>+        return makeUnexpected(MediaPlaybackDenialReason::UserGestureRequired);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if (m_restrictions & RequireUserGestureForVideoDueToLowPowerMode && m_element.isVideo() && !document.processingUserGestureForMedia()) {
</span><span class="cx">         ALWAYS_LOG(LOGIDENTIFIER, "Returning FALSE because of video low power mode restriction");
</span><del>-        return MediaPlaybackDenialReason::UserGestureRequired;
</del><ins>+        return makeUnexpected(MediaPlaybackDenialReason::UserGestureRequired);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     return { };
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlMediaElementSessionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/MediaElementSession.h (278496 => 278497)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/MediaElementSession.h  2021-06-04 20:41:45 UTC (rev 278496)
+++ trunk/Source/WebCore/html/MediaElementSession.h     2021-06-04 21:04:14 UTC (rev 278497)
</span><span class="lines">@@ -31,26 +31,15 @@
</span><span class="cx"> #include "MediaProducer.h"
</span><span class="cx"> #include "MediaUsageInfo.h"
</span><span class="cx"> #include "PlatformMediaSession.h"
</span><del>-#include "SuccessOr.h"
</del><span class="cx"> #include "Timer.h"
</span><ins>+#include <memory>
</ins><span class="cx"> #include <wtf/TypeCasts.h>
</span><span class="cx"> 
</span><del>-#if ENABLE(MEDIA_SESSION)
-#include <memory>
-#endif
-
</del><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><del>-enum class MediaSessionMainContentPurpose {
-    MediaControls,
-    Autoplay
-};
</del><ins>+enum class MediaSessionMainContentPurpose { MediaControls, Autoplay };
+enum class MediaPlaybackState { Playing, Paused };
</ins><span class="cx"> 
</span><del>-enum class MediaPlaybackState {
-    Playing,
-    Paused
-};
-
</del><span class="cx"> enum class MediaPlaybackDenialReason {
</span><span class="cx">     UserGestureRequired,
</span><span class="cx">     FullscreenRequired,
</span><span class="lines">@@ -61,14 +50,15 @@
</span><span class="cx"> class Document;
</span><span class="cx"> class HTMLMediaElement;
</span><span class="cx"> class MediaMetadata;
</span><del>-struct MediaPositionState;
</del><span class="cx"> class MediaSession;
</span><span class="cx"> class MediaSessionObserver;
</span><span class="cx"> class SourceBuffer;
</span><ins>+
+struct MediaPositionState;
+
</ins><span class="cx"> enum class MediaSessionPlaybackState : uint8_t;
</span><span class="cx"> 
</span><del>-class MediaElementSession final : public PlatformMediaSession
-{
</del><ins>+class MediaElementSession final : public PlatformMediaSession {
</ins><span class="cx">     WTF_MAKE_FAST_ALLOCATED;
</span><span class="cx"> public:
</span><span class="cx">     explicit MediaElementSession(HTMLMediaElement&);
</span><span class="lines">@@ -85,7 +75,7 @@
</span><span class="cx">     void isVisibleInViewportChanged();
</span><span class="cx">     void inActiveDocumentChanged();
</span><span class="cx"> 
</span><del>-    SuccessOr<MediaPlaybackDenialReason> playbackStateChangePermitted(MediaPlaybackState) const;
</del><ins>+    Expected<void, MediaPlaybackDenialReason> playbackStateChangePermitted(MediaPlaybackState) const;
</ins><span class="cx">     bool autoplayPermitted() const;
</span><span class="cx">     bool dataLoadingPermitted() const;
</span><span class="cx">     MediaPlayer::BufferingPolicy preferredBufferingPolicy() const;
</span></span></pre>
</div>
</div>

</body>
</html>