<!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>[201119] 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/201119">201119</a></dd>
<dt>Author</dt> <dd>eric.carlson@apple.com</dd>
<dt>Date</dt> <dd>2016-05-18 17:20:26 -0700 (Wed, 18 May 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>[iOS] Fullscreen video playback broken in WK1 apps
https://bugs.webkit.org/show_bug.cgi?id=157847
&lt;rdar://problem/25879521&gt;

Reviewed by Jer Noble.

* platform/cocoa/WebVideoFullscreenModelVideoElement.h:
(WebCore::WebVideoFullscreenModelVideoElement::playbackSessionModel): New, model accessor.
* platform/cocoa/WebVideoFullscreenModelVideoElement.mm:
(WebVideoFullscreenModelVideoElement::setWebVideoFullscreenInterface): Set model's playback interface.
(WebVideoFullscreenModelVideoElement::setVideoElement): Set model's video element.

* platform/ios/WebVideoFullscreenControllerAVKit.mm:
(WebVideoFullscreenControllerContext::didCleanupFullscreen): Clear m_sessionModel.
(WebVideoFullscreenControllerContext::setVideoDimensions): This is called from both the UI and
  Web threads, so dispatch to the UI thread when necessary.
(WebVideoFullscreenControllerContext::play): Call the model's playback session on the Web thread.
(WebVideoFullscreenControllerContext::pause): Ditto.
(WebVideoFullscreenControllerContext::togglePlayState): Ditto.
(WebVideoFullscreenControllerContext::beginScrubbing): Ditto.
(WebVideoFullscreenControllerContext::endScrubbing): Ditto.
(WebVideoFullscreenControllerContext::seekToTime): Ditto.
(WebVideoFullscreenControllerContext::fastSeek): Ditto.
(WebVideoFullscreenControllerContext::beginScanningForward): Ditto.
(WebVideoFullscreenControllerContext::beginScanningBackward): Ditto.
(WebVideoFullscreenControllerContext::endScanning): Ditto.
(WebVideoFullscreenControllerContext::selectAudioMediaOption): Ditto.
(WebVideoFullscreenControllerContext::selectLegibleMediaOption): Ditto.
(WebVideoFullscreenControllerContext::setUpFullscreen): Create and configure a session model.
(WebVideoFullscreenSessionModel::play): Pass call back to the controller.
(WebVideoFullscreenSessionModel::pause): Ditto.
(WebVideoFullscreenSessionModel::togglePlayState): Ditto.
(WebVideoFullscreenSessionModel::beginScrubbing): Ditto.
(WebVideoFullscreenSessionModel::endScrubbing): Ditto.
(WebVideoFullscreenSessionModel::seekToTime): Ditto.
(WebVideoFullscreenSessionModel::fastSeek): Ditto.
(WebVideoFullscreenSessionModel::beginScanningForward): Ditto.
(WebVideoFullscreenSessionModel::beginScanningBackward): Ditto.
(WebVideoFullscreenSessionModel::endScanning): Ditto.
(WebVideoFullscreenSessionModel::selectAudioMediaOption): Ditto.
(WebVideoFullscreenSessionModel::selectLegibleMediaOption): Ditto.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformcocoaWebVideoFullscreenModelVideoElementh">trunk/Source/WebCore/platform/cocoa/WebVideoFullscreenModelVideoElement.h</a></li>
<li><a href="#trunkSourceWebCoreplatformcocoaWebVideoFullscreenModelVideoElementmm">trunk/Source/WebCore/platform/cocoa/WebVideoFullscreenModelVideoElement.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformiosWebVideoFullscreenControllerAVKitmm">trunk/Source/WebCore/platform/ios/WebVideoFullscreenControllerAVKit.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (201118 => 201119)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-05-19 00:04:48 UTC (rev 201118)
+++ trunk/Source/WebCore/ChangeLog        2016-05-19 00:20:26 UTC (rev 201119)
</span><span class="lines">@@ -1,3 +1,47 @@
</span><ins>+2016-05-18  Eric Carlson  &lt;eric.carlson@apple.com&gt;
+
+        [iOS] Fullscreen video playback broken in WK1 apps
+        https://bugs.webkit.org/show_bug.cgi?id=157847
+        &lt;rdar://problem/25879521&gt;
+
+        Reviewed by Jer Noble.
+
+        * platform/cocoa/WebVideoFullscreenModelVideoElement.h:
+        (WebCore::WebVideoFullscreenModelVideoElement::playbackSessionModel): New, model accessor.
+        * platform/cocoa/WebVideoFullscreenModelVideoElement.mm:
+        (WebVideoFullscreenModelVideoElement::setWebVideoFullscreenInterface): Set model's playback interface.
+        (WebVideoFullscreenModelVideoElement::setVideoElement): Set model's video element.
+
+        * platform/ios/WebVideoFullscreenControllerAVKit.mm:
+        (WebVideoFullscreenControllerContext::didCleanupFullscreen): Clear m_sessionModel.
+        (WebVideoFullscreenControllerContext::setVideoDimensions): This is called from both the UI and
+          Web threads, so dispatch to the UI thread when necessary.
+        (WebVideoFullscreenControllerContext::play): Call the model's playback session on the Web thread.
+        (WebVideoFullscreenControllerContext::pause): Ditto.
+        (WebVideoFullscreenControllerContext::togglePlayState): Ditto.
+        (WebVideoFullscreenControllerContext::beginScrubbing): Ditto.
+        (WebVideoFullscreenControllerContext::endScrubbing): Ditto.
+        (WebVideoFullscreenControllerContext::seekToTime): Ditto.
+        (WebVideoFullscreenControllerContext::fastSeek): Ditto.
+        (WebVideoFullscreenControllerContext::beginScanningForward): Ditto.
+        (WebVideoFullscreenControllerContext::beginScanningBackward): Ditto.
+        (WebVideoFullscreenControllerContext::endScanning): Ditto.
+        (WebVideoFullscreenControllerContext::selectAudioMediaOption): Ditto.
+        (WebVideoFullscreenControllerContext::selectLegibleMediaOption): Ditto.
+        (WebVideoFullscreenControllerContext::setUpFullscreen): Create and configure a session model.
+        (WebVideoFullscreenSessionModel::play): Pass call back to the controller.
+        (WebVideoFullscreenSessionModel::pause): Ditto.
+        (WebVideoFullscreenSessionModel::togglePlayState): Ditto.
+        (WebVideoFullscreenSessionModel::beginScrubbing): Ditto.
+        (WebVideoFullscreenSessionModel::endScrubbing): Ditto.
+        (WebVideoFullscreenSessionModel::seekToTime): Ditto.
+        (WebVideoFullscreenSessionModel::fastSeek): Ditto.
+        (WebVideoFullscreenSessionModel::beginScanningForward): Ditto.
+        (WebVideoFullscreenSessionModel::beginScanningBackward): Ditto.
+        (WebVideoFullscreenSessionModel::endScanning): Ditto.
+        (WebVideoFullscreenSessionModel::selectAudioMediaOption): Ditto.
+        (WebVideoFullscreenSessionModel::selectLegibleMediaOption): Ditto.
+
</ins><span class="cx"> 2016-05-18  Zalan Bujtas  &lt;zalan@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Remove LayoutUnit::operator unsigned().
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformcocoaWebVideoFullscreenModelVideoElementh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/cocoa/WebVideoFullscreenModelVideoElement.h (201118 => 201119)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/cocoa/WebVideoFullscreenModelVideoElement.h        2016-05-19 00:04:48 UTC (rev 201118)
+++ trunk/Source/WebCore/platform/cocoa/WebVideoFullscreenModelVideoElement.h        2016-05-19 00:20:26 UTC (rev 201119)
</span><span class="lines">@@ -56,6 +56,7 @@
</span><span class="cx">     WEBCORE_EXPORT void setVideoElement(HTMLVideoElement*);
</span><span class="cx">     WEBCORE_EXPORT HTMLVideoElement* videoElement() const { return m_videoElement.get(); }
</span><span class="cx">     WEBCORE_EXPORT void setVideoFullscreenLayer(PlatformLayer*);
</span><ins>+    WebPlaybackSessionModelMediaElement&amp; playbackSessionModel() { return m_playbackSessionModel; }
</ins><span class="cx">     
</span><span class="cx">     WEBCORE_EXPORT void handleEvent(WebCore::ScriptExecutionContext*, WebCore::Event*) override;
</span><span class="cx">     void updateForEventName(const WTF::AtomicString&amp;);
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformcocoaWebVideoFullscreenModelVideoElementmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/cocoa/WebVideoFullscreenModelVideoElement.mm (201118 => 201119)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/cocoa/WebVideoFullscreenModelVideoElement.mm        2016-05-19 00:04:48 UTC (rev 201118)
+++ trunk/Source/WebCore/platform/cocoa/WebVideoFullscreenModelVideoElement.mm        2016-05-19 00:20:26 UTC (rev 201119)
</span><span class="lines">@@ -67,6 +67,7 @@
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     m_videoFullscreenInterface = interface;
</span><ins>+    m_playbackSessionModel-&gt;setWebPlaybackSessionInterface(interface);
</ins><span class="cx"> 
</span><span class="cx">     if (m_videoFullscreenInterface &amp;&amp; m_videoElement)
</span><span class="cx">         m_videoFullscreenInterface-&gt;setVideoDimensions(true, m_videoElement-&gt;videoWidth(), m_videoElement-&gt;videoHeight());
</span><span class="lines">@@ -87,6 +88,7 @@
</span><span class="cx">     m_isListening = false;
</span><span class="cx"> 
</span><span class="cx">     m_videoElement = videoElement;
</span><ins>+    m_playbackSessionModel-&gt;setMediaElement(videoElement);
</ins><span class="cx"> 
</span><span class="cx">     if (!m_videoElement)
</span><span class="cx">         return;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformiosWebVideoFullscreenControllerAVKitmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/ios/WebVideoFullscreenControllerAVKit.mm (201118 => 201119)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/ios/WebVideoFullscreenControllerAVKit.mm        2016-05-19 00:04:48 UTC (rev 201118)
+++ trunk/Source/WebCore/platform/ios/WebVideoFullscreenControllerAVKit.mm        2016-05-19 00:20:26 UTC (rev 201119)
</span><span class="lines">@@ -88,6 +88,7 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> class WebVideoFullscreenControllerContext;
</span><ins>+class WebVideoFullscreenSessionModel;
</ins><span class="cx"> 
</span><span class="cx"> @interface WebVideoFullscreenController (delegate)
</span><span class="cx"> -(void)didFinishFullscreen:(WebVideoFullscreenControllerContext*)context;
</span><span class="lines">@@ -104,13 +105,26 @@
</span><span class="cx">     {
</span><span class="cx">         return adoptRef(*new WebVideoFullscreenControllerContext);
</span><span class="cx">     }
</span><del>-    
</del><ins>+
</ins><span class="cx">     void setController(WebVideoFullscreenController* controller) { m_controller = controller; }
</span><span class="cx">     void setUpFullscreen(HTMLVideoElement&amp;, UIView *, HTMLMediaElementEnums::VideoFullscreenMode);
</span><span class="cx">     void exitFullscreen();
</span><span class="cx">     void requestHideAndExitFullscreen();
</span><span class="cx">     void invalidate();
</span><span class="cx"> 
</span><ins>+    void play();
+    void pause();
+    void togglePlayState();
+    void beginScrubbing();
+    void endScrubbing();
+    void seekToTime(double);
+    void fastSeek(double time);
+    void beginScanningForward();
+    void beginScanningBackward();
+    void endScanning();
+    void selectAudioMediaOption(uint64_t);
+    void selectLegibleMediaOption(uint64_t);
+
</ins><span class="cx"> private:
</span><span class="cx">     WebVideoFullscreenControllerContext() { }
</span><span class="cx"> 
</span><span class="lines">@@ -120,7 +134,7 @@
</span><span class="cx">     void didExitFullscreen() override;
</span><span class="cx">     void didCleanupFullscreen() override;
</span><span class="cx">     void fullscreenMayReturnToInline() override;
</span><del>-    
</del><ins>+
</ins><span class="cx">     // WebVideoFullscreenInterface
</span><span class="cx">     void resetMediaState() override;
</span><span class="cx">     void setDuration(double) override;
</span><span class="lines">@@ -147,8 +161,83 @@
</span><span class="cx">     RefPtr&lt;HTMLVideoElement&gt; m_videoElement;
</span><span class="cx">     RetainPtr&lt;UIView&gt; m_videoFullscreenView;
</span><span class="cx">     RetainPtr&lt;WebVideoFullscreenController&gt; m_controller;
</span><ins>+    RefPtr&lt;WebVideoFullscreenSessionModel&gt; m_sessionModel;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><ins>+
+class WebVideoFullscreenSessionModel final: public RefCounted&lt;WebVideoFullscreenSessionModel&gt;, public WebCore::WebPlaybackSessionModel  {
+public:
+    static Ref&lt;WebVideoFullscreenSessionModel&gt; create(WebVideoFullscreenControllerContext&amp; controller)
+    {
+        return adoptRef(*new WebVideoFullscreenSessionModel(controller));
+    }
+    virtual ~WebVideoFullscreenSessionModel() { }
+
+    void invalidate() { m_controller = nullptr; }
+
+    void setDuration(double duration) { m_duration = duration; }
+    void setCurrentTime(double currentTime) { m_currentTime = currentTime; }
+    void setBufferedTime(double bufferedTime) { m_bufferedTime = bufferedTime; }
+    void setIsPlaying(bool isPlaying) { m_isPlaying = isPlaying; }
+    void setPlaybackRate(float playbackRate) { m_playbackRate = playbackRate; }
+    void setSeekableRanges(WebCore::TimeRanges&amp; seekableRanges) { m_seekableRanges = seekableRanges; }
+    void setCanPlayFastReverse(bool canPlayFastReverse) { m_canPlayFastReverse = canPlayFastReverse; }
+    void setAudioMediaSelectionOptions(const Vector&lt;WTF::String&gt;&amp; audioMediaSelectionOptions) { m_audioMediaSelectionOptions = audioMediaSelectionOptions; }
+    void setAudioMediaSelectedIndex(uint64_t audioMediaSelectedIndex) { m_audioMediaSelectedIndex = audioMediaSelectedIndex; }
+    void setLegibleMediaSelectionOptions(const Vector&lt;WTF::String&gt;&amp; legibleMediaSelectionOptions) { m_legibleMediaSelectionOptions = legibleMediaSelectionOptions; }
+    void setLegibleMediaSelectedIndex(uint64_t legibleMediaSelectedIndex) { m_legibleMediaSelectedIndex = legibleMediaSelectedIndex; }
+    void setExternalPlaybackEnabled(bool externalPlaybackEnabled) { m_externalPlaybackEnabled = externalPlaybackEnabled; }
+    void setWirelessVideoPlaybackDisabled(bool wirelessVideoPlaybackDisabled) { m_wirelessVideoPlaybackDisabled = wirelessVideoPlaybackDisabled; }
+
+private:
+    WebVideoFullscreenSessionModel(WebVideoFullscreenControllerContext&amp; controller)
+        : m_controller(&amp;controller)
+    {
+    }
+
+    void play() final;
+    void pause() final;
+    void togglePlayState() final;
+    void beginScrubbing() final;
+    void endScrubbing() final;
+    void seekToTime(double) final;
+    void fastSeek(double time) final;
+    void beginScanningForward() final;
+    void beginScanningBackward() final;
+    void endScanning() final;
+    void selectAudioMediaOption(uint64_t) final;
+    void selectLegibleMediaOption(uint64_t) final;
+
+    double duration() const final { return m_duration; }
+    double currentTime() const final { return m_currentTime; }
+    double bufferedTime() const final { return m_bufferedTime; }
+    bool isPlaying() const final { return m_isPlaying; }
+    float playbackRate() const final { return m_playbackRate; }
+    Ref&lt;WebCore::TimeRanges&gt; seekableRanges() const final { return m_seekableRanges.copyRef(); }
+    bool canPlayFastReverse() const final { return m_canPlayFastReverse; }
+    Vector&lt;WTF::String&gt; audioMediaSelectionOptions() const final { return m_audioMediaSelectionOptions; }
+    uint64_t audioMediaSelectedIndex() const final { return m_audioMediaSelectedIndex; }
+    Vector&lt;WTF::String&gt; legibleMediaSelectionOptions() const final { return m_legibleMediaSelectionOptions; }
+    uint64_t legibleMediaSelectedIndex() const final { return m_legibleMediaSelectedIndex; }
+    bool externalPlaybackEnabled() const final { return m_externalPlaybackEnabled; }
+    bool wirelessVideoPlaybackDisabled() const final { return m_wirelessVideoPlaybackDisabled; }
+
+    WebVideoFullscreenControllerContext* m_controller;
+    double m_duration { 0 };
+    double m_currentTime { 0 };
+    double m_bufferedTime { 0 };
+    bool m_isPlaying { false };
+    float m_playbackRate { 0 };
+    Ref&lt;WebCore::TimeRanges&gt; m_seekableRanges { WebCore::TimeRanges::create() };
+    bool m_canPlayFastReverse { false };
+    Vector&lt;WTF::String&gt; m_audioMediaSelectionOptions;
+    uint64_t m_audioMediaSelectedIndex { 0 };
+    Vector&lt;WTF::String&gt; m_legibleMediaSelectionOptions;
+    uint64_t m_legibleMediaSelectedIndex { 0 };
+    bool m_externalPlaybackEnabled { false };
+    bool m_wirelessVideoPlaybackDisabled { false };
+};
+
</ins><span class="cx"> #pragma mark WebVideoFullscreenChangeObserver
</span><span class="cx"> 
</span><span class="cx"> void WebVideoFullscreenControllerContext::didSetupFullscreen()
</span><span class="lines">@@ -184,7 +273,9 @@
</span><span class="cx">     m_interface-&gt;setWebVideoFullscreenChangeObserver(nullptr);
</span><span class="cx">     m_interface = nullptr;
</span><span class="cx">     m_videoFullscreenView = nil;
</span><del>-    
</del><ins>+    m_sessionModel-&gt;invalidate();
+    m_sessionModel = nullptr;
+
</ins><span class="cx">     RefPtr&lt;WebVideoFullscreenControllerContext&gt; protectedThis(this);
</span><span class="cx">     WebThreadRun([protectedThis, this] {
</span><span class="cx">         m_model-&gt;setVideoFullscreenLayer(nil);
</span><span class="lines">@@ -192,7 +283,7 @@
</span><span class="cx">         m_model-&gt;setVideoElement(nullptr);
</span><span class="cx">         m_model = nullptr;
</span><span class="cx">         m_videoElement = nullptr;
</span><del>-        
</del><ins>+
</ins><span class="cx">         [m_controller didFinishFullscreen:this];
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="lines">@@ -263,12 +354,17 @@
</span><span class="cx"> 
</span><span class="cx"> void WebVideoFullscreenControllerContext::setVideoDimensions(bool hasVideo, float width, float height)
</span><span class="cx"> {
</span><del>-    ASSERT(WebThreadIsCurrent());
-    RefPtr&lt;WebVideoFullscreenControllerContext&gt; protectedThis(this);
-    dispatch_async(dispatch_get_main_queue(), [protectedThis, this, hasVideo, width, height] {
-        if (m_interface)
-            m_interface-&gt;setVideoDimensions(hasVideo, width, height);
-    });
</del><ins>+    if (WebThreadIsCurrent()) {
+        RefPtr&lt;WebVideoFullscreenControllerContext&gt; protectedThis(this);
+        dispatch_async(dispatch_get_main_queue(), [protectedThis, this, hasVideo, width, height] {
+            if (m_interface)
+                m_interface-&gt;setVideoDimensions(hasVideo, width, height);
+        });
+        return;
+    }
+
+    if (m_interface)
+        m_interface-&gt;setVideoDimensions(hasVideo, width, height);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebVideoFullscreenControllerContext::setSeekableRanges(const TimeRanges&amp; timeRanges)
</span><span class="lines">@@ -412,6 +508,128 @@
</span><span class="cx">     return m_model ? m_model-&gt;isVisible() : false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#pragma mark - WebPlaybackSessionModelContext
+
+void WebVideoFullscreenControllerContext::play()
+{
+    ASSERT(isUIThread());
+    RefPtr&lt;WebVideoFullscreenControllerContext&gt; protectedThis(this);
+    WebThreadRun([protectedThis, this] {
+        if (m_model)
+            m_model-&gt;playbackSessionModel().play();
+    });
+}
+
+void WebVideoFullscreenControllerContext::pause()
+{
+    ASSERT(isUIThread());
+    RefPtr&lt;WebVideoFullscreenControllerContext&gt; protectedThis(this);
+    WebThreadRun([protectedThis, this] {
+        if (m_model)
+            m_model-&gt;playbackSessionModel().pause();
+    });
+}
+
+void WebVideoFullscreenControllerContext::togglePlayState()
+{
+    ASSERT(isUIThread());
+    RefPtr&lt;WebVideoFullscreenControllerContext&gt; protectedThis(this);
+    WebThreadRun([protectedThis, this] {
+        if (m_model)
+            m_model-&gt;playbackSessionModel().togglePlayState();
+    });
+}
+
+void WebVideoFullscreenControllerContext::beginScrubbing()
+{
+    ASSERT(isUIThread());
+    RefPtr&lt;WebVideoFullscreenControllerContext&gt; protectedThis(this);
+    WebThreadRun([protectedThis, this] {
+        if (m_model)
+            m_model-&gt;playbackSessionModel().beginScrubbing();
+    });
+}
+
+void WebVideoFullscreenControllerContext::endScrubbing()
+{
+    ASSERT(isUIThread());
+    RefPtr&lt;WebVideoFullscreenControllerContext&gt; protectedThis(this);
+    WebThreadRun([protectedThis, this] {
+        if (m_model)
+            m_model-&gt;playbackSessionModel().endScrubbing();
+    });
+}
+
+void WebVideoFullscreenControllerContext::seekToTime(double time)
+{
+    ASSERT(isUIThread());
+    RefPtr&lt;WebVideoFullscreenControllerContext&gt; protectedThis(this);
+    WebThreadRun([protectedThis, this, time] {
+        if (m_model)
+            m_model-&gt;playbackSessionModel().seekToTime(time);
+    });
+}
+
+void WebVideoFullscreenControllerContext::fastSeek(double time)
+{
+    ASSERT(isUIThread());
+    RefPtr&lt;WebVideoFullscreenControllerContext&gt; protectedThis(this);
+    WebThreadRun([protectedThis, this, time] {
+        if (m_model)
+            m_model-&gt;playbackSessionModel().fastSeek(time);
+    });
+}
+
+void WebVideoFullscreenControllerContext::beginScanningForward()
+{
+    ASSERT(isUIThread());
+    RefPtr&lt;WebVideoFullscreenControllerContext&gt; protectedThis(this);
+    WebThreadRun([protectedThis, this] {
+        if (m_model)
+            m_model-&gt;playbackSessionModel().beginScanningForward();
+    });
+}
+
+void WebVideoFullscreenControllerContext::beginScanningBackward()
+{
+    ASSERT(isUIThread());
+    RefPtr&lt;WebVideoFullscreenControllerContext&gt; protectedThis(this);
+    WebThreadRun([protectedThis, this] {
+        if (m_model)
+            m_model-&gt;playbackSessionModel().beginScanningBackward();
+    });
+}
+
+void WebVideoFullscreenControllerContext::endScanning()
+{
+    ASSERT(isUIThread());
+    RefPtr&lt;WebVideoFullscreenControllerContext&gt; protectedThis(this);
+    WebThreadRun([protectedThis, this] {
+        if (m_model)
+            m_model-&gt;playbackSessionModel().endScanning();
+    });
+}
+
+void WebVideoFullscreenControllerContext::selectAudioMediaOption(uint64_t index)
+{
+    ASSERT(isUIThread());
+    RefPtr&lt;WebVideoFullscreenControllerContext&gt; protectedThis(this);
+    WebThreadRun([protectedThis, this, index] {
+        if (m_model)
+            m_model-&gt;playbackSessionModel().selectAudioMediaOption(index);
+    });
+}
+
+void WebVideoFullscreenControllerContext::selectLegibleMediaOption(uint64_t index)
+{
+    ASSERT(isUIThread());
+    RefPtr&lt;WebVideoFullscreenControllerContext&gt; protectedThis(this);
+    WebThreadRun([protectedThis, this, index] {
+        if (m_model)
+            m_model-&gt;playbackSessionModel().selectLegibleMediaOption(index);
+    });
+}
+
</ins><span class="cx"> #pragma mark Other
</span><span class="cx"> 
</span><span class="cx"> void WebVideoFullscreenControllerContext::setUpFullscreen(HTMLVideoElement&amp; videoElement, UIView *view, HTMLMediaElementEnums::VideoFullscreenMode mode)
</span><span class="lines">@@ -424,9 +642,15 @@
</span><span class="cx">     dispatch_async(dispatch_get_main_queue(), [protectedThis, this, viewRef, mode] {
</span><span class="cx">         ASSERT(isUIThread());
</span><span class="cx"> 
</span><del>-        m_interface = WebVideoFullscreenInterfaceAVKit::create(WebPlaybackSessionInterfaceAVKit::create().get());
</del><ins>+        Ref&lt;WebPlaybackSessionInterfaceAVKit&gt; sessionInterface = WebPlaybackSessionInterfaceAVKit::create();
+        m_interface = WebVideoFullscreenInterfaceAVKit::create(sessionInterface.get());
+
+        m_sessionModel = WebVideoFullscreenSessionModel::create(*this);
+        sessionInterface-&gt;setWebPlaybackSessionModel(m_sessionModel.get());
+
+        m_interface-&gt;setWebVideoFullscreenModel(this);
</ins><span class="cx">         m_interface-&gt;setWebVideoFullscreenChangeObserver(this);
</span><del>-        m_interface-&gt;setWebVideoFullscreenModel(this);
</del><ins>+
</ins><span class="cx">         m_videoFullscreenView = adoptNS([[getUIViewClass() alloc] init]);
</span><span class="cx">         
</span><span class="cx">         RefPtr&lt;WebVideoFullscreenControllerContext&gt; protectedThis(this);
</span><span class="lines">@@ -434,13 +658,12 @@
</span><span class="cx">             m_model = WebVideoFullscreenModelVideoElement::create(WebPlaybackSessionModelMediaElement::create().get());
</span><span class="cx">             m_model-&gt;setWebVideoFullscreenInterface(this);
</span><span class="cx">             m_model-&gt;setVideoElement(m_videoElement.get());
</span><del>-            
-            bool allowsPictureInPicture = m_videoElement-&gt;mediaSession().allowsPictureInPicture(*m_videoElement.get());
</del><span class="cx"> 
</span><span class="cx">             IntRect videoElementClientRect = elementRectInWindow(m_videoElement.get());
</span><span class="cx">             FloatRect videoLayerFrame = FloatRect(FloatPoint(), videoElementClientRect.size());
</span><span class="cx">             m_model-&gt;setVideoLayerFrame(videoLayerFrame);
</span><span class="cx">             
</span><ins>+            bool allowsPictureInPicture = m_videoElement-&gt;mediaSession().allowsPictureInPicture(*m_videoElement.get());
</ins><span class="cx">             dispatch_async(dispatch_get_main_queue(), [protectedThis, this, videoElementClientRect, viewRef, mode, allowsPictureInPicture] {
</span><span class="cx">                 m_interface-&gt;setupFullscreen(*m_videoFullscreenView.get(), videoElementClientRect, viewRef.get(), mode, allowsPictureInPicture);
</span><span class="cx">             });
</span><span class="lines">@@ -465,6 +688,81 @@
</span><span class="cx">     m_interface-&gt;requestHideAndExitFullscreen();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#pragma mark WebPlaybackSessionModel
+
+void WebVideoFullscreenSessionModel::play()
+{
+    if (m_controller)
+        m_controller-&gt;play();
+}
+
+void WebVideoFullscreenSessionModel::pause()
+{
+    if (m_controller)
+        m_controller-&gt;pause();
+}
+
+void WebVideoFullscreenSessionModel::togglePlayState()
+{
+    if (m_controller)
+        m_controller-&gt;togglePlayState();
+}
+
+void WebVideoFullscreenSessionModel::beginScrubbing()
+{
+    if (m_controller)
+        m_controller-&gt;beginScrubbing();
+}
+
+void WebVideoFullscreenSessionModel::endScrubbing()
+{
+    if (m_controller)
+        m_controller-&gt;endScrubbing();
+}
+
+void WebVideoFullscreenSessionModel::seekToTime(double time)
+{
+    if (m_controller)
+        m_controller-&gt;seekToTime(time);
+}
+
+void WebVideoFullscreenSessionModel::fastSeek(double time)
+{
+    if (m_controller)
+        m_controller-&gt;fastSeek(time);
+}
+
+void WebVideoFullscreenSessionModel::beginScanningForward()
+{
+    if (m_controller)
+        m_controller-&gt;beginScanningForward();
+}
+
+void WebVideoFullscreenSessionModel::beginScanningBackward()
+{
+    if (m_controller)
+        m_controller-&gt;beginScanningBackward();
+}
+
+void WebVideoFullscreenSessionModel::endScanning()
+{
+    if (m_controller)
+        m_controller-&gt;endScanning();
+}
+
+void WebVideoFullscreenSessionModel::selectAudioMediaOption(uint64_t optionId)
+{
+    if (m_controller)
+        m_controller-&gt;selectAudioMediaOption(optionId);
+}
+
+void WebVideoFullscreenSessionModel::selectLegibleMediaOption(uint64_t optionId)
+{
+    if (m_controller)
+        m_controller-&gt;selectLegibleMediaOption(optionId);
+}
+
+
</ins><span class="cx"> @implementation WebVideoFullscreenController {
</span><span class="cx">     RefPtr&lt;WebVideoFullscreenControllerContext&gt; _context;
</span><span class="cx">     RefPtr&lt;HTMLVideoElement&gt; _videoElement;
</span></span></pre>
</div>
</div>

</body>
</html>