<!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>[187092] branches/safari-601.1-branch/Source</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/187092">187092</a></dd>
<dt>Author</dt> <dd>matthew_hanson@apple.com</dd>
<dt>Date</dt> <dd>2015-07-20 22:27:51 -0700 (Mon, 20 Jul 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Merge <a href="http://trac.webkit.org/projects/webkit/changeset/187044">r187044</a>. rdar://problem/21661808</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari6011branchSourceWebCoreChangeLog">branches/safari-601.1-branch/Source/WebCore/ChangeLog</a></li>
<li><a href="#branchessafari6011branchSourceWebCoreplatformgraphicsavfoundationobjcMediaPlayerPrivateAVFoundationObjCmm">branches/safari-601.1-branch/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm</a></li>
<li><a href="#branchessafari6011branchSourceWebCoreplatformiosWebVideoFullscreenControllerAVKitmm">branches/safari-601.1-branch/Source/WebCore/platform/ios/WebVideoFullscreenControllerAVKit.mm</a></li>
<li><a href="#branchessafari6011branchSourceWebCoreplatformiosWebVideoFullscreenInterfaceAVKith">branches/safari-601.1-branch/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.h</a></li>
<li><a href="#branchessafari6011branchSourceWebCoreplatformiosWebVideoFullscreenInterfaceAVKitmm">branches/safari-601.1-branch/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.mm</a></li>
<li><a href="#branchessafari6011branchSourceWebCoreplatformiosWebVideoFullscreenModelh">branches/safari-601.1-branch/Source/WebCore/platform/ios/WebVideoFullscreenModel.h</a></li>
<li><a href="#branchessafari6011branchSourceWebCoreplatformiosWebVideoFullscreenModelVideoElementh">branches/safari-601.1-branch/Source/WebCore/platform/ios/WebVideoFullscreenModelVideoElement.h</a></li>
<li><a href="#branchessafari6011branchSourceWebCoreplatformiosWebVideoFullscreenModelVideoElementmm">branches/safari-601.1-branch/Source/WebCore/platform/ios/WebVideoFullscreenModelVideoElement.mm</a></li>
<li><a href="#branchessafari6011branchSourceWebCoreplatformspicocoaAVKitSPIh">branches/safari-601.1-branch/Source/WebCore/platform/spi/cocoa/AVKitSPI.h</a></li>
<li><a href="#branchessafari6011branchSourceWebCoreplatformspicocoaQuartzCoreSPIh">branches/safari-601.1-branch/Source/WebCore/platform/spi/cocoa/QuartzCoreSPI.h</a></li>
<li><a href="#branchessafari6011branchSourceWebKit2ChangeLog">branches/safari-601.1-branch/Source/WebKit2/ChangeLog</a></li>
<li><a href="#branchessafari6011branchSourceWebKit2UIProcessiosWebVideoFullscreenManagerProxyh">branches/safari-601.1-branch/Source/WebKit2/UIProcess/ios/WebVideoFullscreenManagerProxy.h</a></li>
<li><a href="#branchessafari6011branchSourceWebKit2UIProcessiosWebVideoFullscreenManagerProxymm">branches/safari-601.1-branch/Source/WebKit2/UIProcess/ios/WebVideoFullscreenManagerProxy.mm</a></li>
<li><a href="#branchessafari6011branchSourceWebKit2WebProcessiosWebVideoFullscreenManagermm">branches/safari-601.1-branch/Source/WebKit2/WebProcess/ios/WebVideoFullscreenManager.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari6011branchSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1-branch/Source/WebCore/ChangeLog (187091 => 187092)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1-branch/Source/WebCore/ChangeLog        2015-07-21 05:27:45 UTC (rev 187091)
+++ branches/safari-601.1-branch/Source/WebCore/ChangeLog        2015-07-21 05:27:51 UTC (rev 187092)
</span><span class="lines">@@ -1,5 +1,123 @@
</span><span class="cx"> 2015-07-20  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Merge r187044. rdar://problem/21661808
+
+    2015-07-20  Jeremy Jones  &lt;jeremyj@apple.com&gt;
+
+            Adopt AVPlayerLayerView
+            https://bugs.webkit.org/show_bug.cgi?id=146862
+
+            Reviewed by Jer Noble.
+
+            The CALayerHost is replaced with WebLayerHostView to be compatible with UIView animations.
+            Some animation is improved in the conversion.
+
+            WebAVPlayerLayerView and WebAVPictureInPicturePlayerLayerView derive from AVKit and UIKit respectively.
+            Because these frameworks are loaded at runtime, these classes must be generate using objc/runtime.h to
+            register them from c functions at runtime. The most important part of these UIViews is that their
+            backing layer is a WebAVPlayerLayer.
+
+            WebCALayerHostWrapper and WebAVVideoLayer are combined into WebAVPlayerLayer to simplify the hierarchy.
+            WebAVPlayerLayer is a stand-in for an AVPlayerLayer.
+
+            * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
+            (WebCore::MediaPlayerPrivateAVFoundationObjC::setVideoFullscreenLayer): -removeFromSuperlayer is redundant.
+            (WebCore::MediaPlayerPrivateAVFoundationObjC::setVideoFullscreenGravity): syncTextTrackBounds on change.
+            (WebCore::MediaPlayerPrivateAVFoundationObjC::setVideoFullscreenFrame):
+            We never want animation here, since all animation will happen in UIViews.
+            This is just for going into the final size after a transform based animation.
+
+            * platform/ios/WebVideoFullscreenControllerAVKit.mm:
+            (WebVideoFullscreenControllerContext::didSetupFullscreen): layer -&gt; view
+            (WebVideoFullscreenControllerContext::didCleanupFullscreen): layer -&gt; view
+            (WebVideoFullscreenControllerContext::setUpFullscreen): layer -&gt; view
+
+            (WebVideoFullscreenControllerContext::setVideoLayerFrame): layer -&gt; view
+            Use fence port to synchronize between the UIThread and the WebThread,
+            the same way WebKit2 uses a fence port to synchronize between processes.
+
+            (WebVideoFullscreenControllerContext::setVideoLayerGravity):
+            No longer necessary to cache videoGravity at this level.
+
+            * platform/ios/WebVideoFullscreenInterfaceAVKit.h:
+            * platform/ios/WebVideoFullscreenInterfaceAVKit.mm:
+
+            (-[WebAVPlayerLayer init]):
+            (-[WebAVPlayerLayer dealloc]):
+            (-[WebAVPlayerLayer playerController]):
+            (-[WebAVPlayerLayer setBounds:]):
+            (-[WebAVPlayerLayer resolveBounds]):
+            (-[WebAVPlayerLayer setVideoGravity:]):
+            (-[WebAVPlayerLayer videoGravity]):
+            (-[WebAVPlayerLayer videoRect]):
+            (+[WebAVPlayerLayer keyPathsForValuesAffectingVideoRect]):
+            Added class WebAVPlayerLayer, replacing WebAVVideoLayer and WebCALayerHostWrapper.
+
+            (WebAVPictureInPicturePlayerLayerView_layerClass):
+            (getWebAVPictureInPicturePlayerLayerViewClass):
+            Added runtime class WebAVPictureInPicturePlayerLayerView
+
+            (WebAVPlayerLayerView_layerClass):
+            (WebAVPlayerLayerView_playerController):
+            (WebAVPlayerLayerView_setPlayerController):
+            (WebAVPlayerLayerView_videoView):
+            (WebAVPlayerLayerView_setVideoView):
+            (WebAVPlayerLayerView_startRoutingVideoToPictureInPicturePlayerLayerView):
+            (WebAVPlayerLayerView_stopRoutingVideoToPictureInPicturePlayerLayerView):
+            (WebAVPlayerLayerView_pictureInPicturePlayerLayerView):
+            (getWebAVPlayerLayerViewClass):
+            Added runtime class WebAVPlayerLayerView
+
+            (WebVideoFullscreenInterfaceAVKit::setVideoDimensions):
+            Dimensions are also stored in WebAVPlayerLayer so it can make decisions about
+            animating the video layer.
+
+            (WebVideoFullscreenInterfaceAVKit::setExternalPlayback):
+            (WebVideoFullscreenInterfaceAVKit::enterFullscreen):
+            (WebVideoFullscreenInterfaceAVKit::didStopPictureInPicture):
+            (WebVideoFullscreenInterfaceAVKit::cleanupFullscreen):
+            Straightforward layer to view conversion.
+
+            (WebVideoFullscreenInterfaceAVKit::preparedToReturnToInline):
+            Set view frame using the view hierarchy instead of assuming it is directly in a window.
+
+            (WebVideoFullscreenInterfaceAVKit::exitFullscreen):
+            Set view frame using the view hierarchy instead of assuming it is directly in a window.
+            dispatch_async before calling didExitFullscreen() to allows CATransactions to complete.
+
+            (WebVideoFullscreenInterfaceAVKit::setupFullscreen):
+            Set view frame using the view hierarchy instead of assuming it is directly in a window.
+            dispatch_async before calling didSetupFullscreen() to allows CATransactions to complete.
+
+            (-[WebCALayerHostWrapper dealloc]): Deleted.
+            (-[WebCALayerHostWrapper setVideoSublayer:]): Deleted.
+            (-[WebCALayerHostWrapper videoSublayer]): Deleted.
+            (-[WebCALayerHostWrapper setBounds:]): Deleted.
+            (-[WebCALayerHostWrapper resolveBounds]): Deleted.
+            Class WebCALayerHostWrapper deleted. Functionality rolled into WebAVPlayerLayer.
+
+            (+[WebAVVideoLayer videoLayer]): Deleted.
+            (-[WebAVVideoLayer init]): Deleted.
+            (-[WebAVVideoLayer setPlayerViewController:]): Deleted.
+            (-[WebAVVideoLayer setVideoSublayer:]): Deleted.
+            (-[WebAVVideoLayer setBounds:]): Deleted.
+            (-[WebAVVideoLayer setVideoLayerGravity:]): Deleted.
+            (-[WebAVVideoLayer videoLayerGravity]): Deleted.
+            (-[WebAVVideoLayer enterPIPModeRedirectingVideoToLayer:]): Deleted.
+            (-[WebAVVideoLayer leavePIPMode]): Deleted.
+            Class WebAVVideoLayer deleted. Functionality rolled into WebAVPlayerLayer.
+
+            * platform/ios/WebVideoFullscreenModel.h:
+            * platform/ios/WebVideoFullscreenModelVideoElement.h:
+            * platform/ios/WebVideoFullscreenModelVideoElement.mm:
+            No need to store frame and gravity in the model. It is stored in the UI where it is used.
+
+            (WebVideoFullscreenModelVideoElement::videoLayerFrame): Deleted.
+            (WebVideoFullscreenModelVideoElement::videoLayerGravity): Deleted.
+            * platform/spi/cocoa/AVKitSPI.h: Add AVPlayerLayerView.
+
+2015-07-20  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
+
</ins><span class="cx">         Merge r187039. rdar://problem/21474317
</span><span class="cx"> 
</span><span class="cx">     2015-07-20  Tim Horton  &lt;timothy_horton@apple.com&gt;
</span></span></pre></div>
<a id="branchessafari6011branchSourceWebCoreplatformgraphicsavfoundationobjcMediaPlayerPrivateAVFoundationObjCmm"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1-branch/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm (187091 => 187092)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1-branch/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm        2015-07-21 05:27:45 UTC (rev 187091)
+++ branches/safari-601.1-branch/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm        2015-07-21 05:27:51 UTC (rev 187092)
</span><span class="lines">@@ -1124,9 +1124,8 @@
</span><span class="cx">     CAContext *newContext = nil;
</span><span class="cx">     
</span><span class="cx">     if (m_videoFullscreenLayer &amp;&amp; m_videoLayer) {
</span><del>-        [m_videoLayer setFrame:CGRectMake(0, 0, m_videoFullscreenFrame.width(), m_videoFullscreenFrame.height())];
-        [m_videoLayer removeFromSuperlayer];
</del><span class="cx">         [m_videoFullscreenLayer insertSublayer:m_videoLayer.get() atIndex:0];
</span><ins>+        [m_videoLayer setFrame:CGRectMake(0, 0, m_videoFullscreenFrame.width(), m_videoFullscreenFrame.height())];
</ins><span class="cx">         newContext = [m_videoFullscreenLayer context];
</span><span class="cx">     } else if (m_videoInlineLayer &amp;&amp; m_videoLayer) {
</span><span class="cx">         [m_videoLayer setFrame:[m_videoInlineLayer bounds]];
</span><span class="lines">@@ -1158,11 +1157,7 @@
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     if (m_videoLayer) {
</span><del>-        [m_videoLayer setStyle:nil]; // This enables actions, i.e. implicit animations.
-        [CATransaction begin];
</del><span class="cx">         [m_videoLayer setFrame:CGRectMake(0, 0, frame.width(), frame.height())];
</span><del>-        [CATransaction commit];
-        [m_videoLayer web_disableAllActions];
</del><span class="cx">     }
</span><span class="cx">     syncTextTrackBounds();
</span><span class="cx"> }
</span><span class="lines">@@ -1182,8 +1177,12 @@
</span><span class="cx">         videoGravity = AVLayerVideoGravityResizeAspectFill;
</span><span class="cx">     else
</span><span class="cx">         ASSERT_NOT_REACHED();
</span><ins>+    
+    if ([m_videoLayer videoGravity] == videoGravity)
+        return;
</ins><span class="cx"> 
</span><span class="cx">     [m_videoLayer setVideoGravity:videoGravity];
</span><ins>+    syncTextTrackBounds();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void MediaPlayerPrivateAVFoundationObjC::setVideoFullscreenMode(MediaPlayer::VideoFullscreenMode mode)
</span></span></pre></div>
<a id="branchessafari6011branchSourceWebCoreplatformiosWebVideoFullscreenControllerAVKitmm"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1-branch/Source/WebCore/platform/ios/WebVideoFullscreenControllerAVKit.mm (187091 => 187092)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1-branch/Source/WebCore/platform/ios/WebVideoFullscreenControllerAVKit.mm        2015-07-21 05:27:45 UTC (rev 187091)
+++ branches/safari-601.1-branch/Source/WebCore/platform/ios/WebVideoFullscreenControllerAVKit.mm        2015-07-21 05:27:51 UTC (rev 187092)
</span><span class="lines">@@ -30,6 +30,8 @@
</span><span class="cx"> #import &quot;WebVideoFullscreenControllerAVKit.h&quot;
</span><span class="cx"> 
</span><span class="cx"> #import &quot;Logging.h&quot;
</span><ins>+#import &quot;QuartzCoreSPI.h&quot;
+#import &quot;SoftLinking.h&quot;
</ins><span class="cx"> #import &quot;TimeRanges.h&quot;
</span><span class="cx"> #import &quot;WebVideoFullscreenInterfaceAVKit.h&quot;
</span><span class="cx"> #import &quot;WebVideoFullscreenModelVideoElement.h&quot;
</span><span class="lines">@@ -37,6 +39,9 @@
</span><span class="cx"> #import &lt;WebCore/HTMLVideoElement.h&gt;
</span><span class="cx"> #import &lt;WebCore/WebCoreThreadRun.h&gt;
</span><span class="cx"> 
</span><ins>+SOFT_LINK_FRAMEWORK(UIKit)
+SOFT_LINK_CLASS(UIKit, UIView)
+
</ins><span class="cx"> using namespace WebCore;
</span><span class="cx"> 
</span><span class="cx"> #if __IPHONE_OS_VERSION_MIN_REQUIRED &lt;= 80200 || !HAVE(AVKIT)
</span><span class="lines">@@ -129,9 +134,7 @@
</span><span class="cx">     virtual void endScanning() override;
</span><span class="cx">     virtual void requestExitFullscreen() override;
</span><span class="cx">     virtual void setVideoLayerFrame(FloatRect) override;
</span><del>-    virtual FloatRect videoLayerFrame() const override { return m_frame; }
</del><span class="cx">     virtual void setVideoLayerGravity(WebVideoFullscreenModel::VideoGravity) override;
</span><del>-    virtual VideoGravity videoLayerGravity() const override { return m_gravity; }
</del><span class="cx">     virtual void selectAudioMediaOption(uint64_t index) override;
</span><span class="cx">     virtual void selectLegibleMediaOption(uint64_t index) override;
</span><span class="cx">     virtual void fullscreenModeChanged(HTMLMediaElementEnums::VideoFullscreenMode) override;
</span><span class="lines">@@ -139,10 +142,8 @@
</span><span class="cx">     RefPtr&lt;WebVideoFullscreenInterfaceAVKit&gt; m_interface;
</span><span class="cx">     RefPtr&lt;WebVideoFullscreenModelVideoElement&gt; m_model;
</span><span class="cx">     RefPtr&lt;HTMLVideoElement&gt; m_videoElement;
</span><del>-    RetainPtr&lt;PlatformLayer&gt; m_videoFullscreenLayer;
</del><ins>+    RetainPtr&lt;UIView&gt; m_videoFullscreenView;
</ins><span class="cx">     RetainPtr&lt;WebVideoFullscreenController&gt; m_controller;
</span><del>-    FloatRect m_frame;
-    VideoGravity m_gravity;
</del><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> #pragma mark WebVideoFullscreenChangeObserver
</span><span class="lines">@@ -151,8 +152,9 @@
</span><span class="cx"> {
</span><span class="cx">     ASSERT(isUIThread());
</span><span class="cx">     RefPtr&lt;WebVideoFullscreenControllerContext&gt; strongThis(this);
</span><del>-    WebThreadRun([strongThis, this] {
-        m_model-&gt;setVideoFullscreenLayer(m_videoFullscreenLayer.get());
</del><ins>+    RetainPtr&lt;CALayer&gt; videoFullscreenLayer = [m_videoFullscreenView layer];
+    WebThreadRun([strongThis, this, videoFullscreenLayer] {
+        m_model-&gt;setVideoFullscreenLayer(videoFullscreenLayer.get());
</ins><span class="cx">         dispatch_async(dispatch_get_main_queue(), [strongThis, this] {
</span><span class="cx">             m_interface-&gt;enterFullscreen();
</span><span class="cx">         });
</span><span class="lines">@@ -177,6 +179,7 @@
</span><span class="cx">     m_interface-&gt;setWebVideoFullscreenModel(nullptr);
</span><span class="cx">     m_interface-&gt;setWebVideoFullscreenChangeObserver(nullptr);
</span><span class="cx">     m_interface = nullptr;
</span><ins>+    m_videoFullscreenView = nil;
</ins><span class="cx">     
</span><span class="cx">     RefPtr&lt;WebVideoFullscreenControllerContext&gt; strongThis(this);
</span><span class="cx">     WebThreadRun([strongThis, this] {
</span><span class="lines">@@ -185,7 +188,6 @@
</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>-        m_videoFullscreenLayer = nil;
</del><span class="cx">         
</span><span class="cx">         [m_controller didFinishFullscreen:this];
</span><span class="cx">     });
</span><span class="lines">@@ -450,18 +452,25 @@
</span><span class="cx"> void WebVideoFullscreenControllerContext::setVideoLayerFrame(FloatRect frame)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(isUIThread());
</span><del>-    m_frame = frame;
</del><span class="cx">     RefPtr&lt;WebVideoFullscreenControllerContext&gt; strongThis(this);
</span><del>-    WebThreadRun([strongThis, this, frame] {
</del><ins>+    RetainPtr&lt;CALayer&gt; videoFullscreenLayer = [m_videoFullscreenView layer];
+
+    mach_port_name_t fencePort = [[videoFullscreenLayer context] createFencePort];
+    
+    WebThreadRun([strongThis, this, frame, fencePort, videoFullscreenLayer] {
+        [CATransaction begin];
+        [CATransaction setAnimationDuration:0];
</ins><span class="cx">         if (m_model)
</span><span class="cx">             m_model-&gt;setVideoLayerFrame(frame);
</span><ins>+        [[videoFullscreenLayer context] setFencePort:fencePort];
+        mach_port_deallocate(mach_task_self(), fencePort);
+        [CATransaction commit];
</ins><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebVideoFullscreenControllerContext::setVideoLayerGravity(WebVideoFullscreenModel::VideoGravity videoGravity)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(isUIThread());
</span><del>-    m_gravity = videoGravity;
</del><span class="cx">     RefPtr&lt;WebVideoFullscreenControllerContext&gt; strongThis(this);
</span><span class="cx">     WebThreadRun([strongThis, this, videoGravity] {
</span><span class="cx">         if (m_model)
</span><span class="lines">@@ -510,19 +519,19 @@
</span><span class="cx">     m_interface = WebVideoFullscreenInterfaceAVKit::create();
</span><span class="cx">     m_interface-&gt;setWebVideoFullscreenChangeObserver(this);
</span><span class="cx">     m_interface-&gt;setWebVideoFullscreenModel(this);
</span><ins>+    m_videoFullscreenView = adoptNS([[getUIViewClass() alloc] init]);
</ins><span class="cx">     
</span><span class="cx">     RefPtr&lt;WebVideoFullscreenControllerContext&gt; strongThis(this);
</span><span class="cx">     WebThreadRun([strongThis, this, viewRef, mode] {
</span><span class="cx">         m_model = WebVideoFullscreenModelVideoElement::create();
</span><span class="cx">         m_model-&gt;setWebVideoFullscreenInterface(this);
</span><span class="cx">         m_model-&gt;setVideoElement(m_videoElement.get());
</span><del>-        m_videoFullscreenLayer = [CALayer layer];
</del><span class="cx">         
</span><span class="cx">         bool allowsPictureInPicture = m_videoElement-&gt;mediaSession().allowsPictureInPicture(*m_videoElement.get());
</span><span class="cx">         IntRect videoElementClientRect = m_videoElement-&gt;clientRect();
</span><span class="cx">         
</span><span class="cx">         dispatch_async(dispatch_get_main_queue(), [strongThis, this, videoElementClientRect, viewRef, mode, allowsPictureInPicture] {
</span><del>-            m_interface-&gt;setupFullscreen(*m_videoFullscreenLayer.get(), videoElementClientRect, viewRef.get(), mode, allowsPictureInPicture);
</del><ins>+            m_interface-&gt;setupFullscreen(*m_videoFullscreenView.get(), videoElementClientRect, viewRef.get(), mode, allowsPictureInPicture);
</ins><span class="cx">         });
</span><span class="cx">     });
</span><span class="cx"> }
</span></span></pre></div>
<a id="branchessafari6011branchSourceWebCoreplatformiosWebVideoFullscreenInterfaceAVKith"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1-branch/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.h (187091 => 187092)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1-branch/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.h        2015-07-21 05:27:45 UTC (rev 187091)
+++ branches/safari-601.1-branch/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.h        2015-07-21 05:27:51 UTC (rev 187092)
</span><span class="lines">@@ -45,8 +45,8 @@
</span><span class="cx"> OBJC_CLASS UIWindow;
</span><span class="cx"> OBJC_CLASS UIView;
</span><span class="cx"> OBJC_CLASS CALayer;
</span><del>-OBJC_CLASS WebAVVideoLayer;
-OBJC_CLASS WebCALayerHostWrapper;
</del><ins>+OBJC_CLASS WebAVPlayerLayerView;
+OBJC_CLASS WebAVPlayerLayer;
</ins><span class="cx"> 
</span><span class="cx"> namespace WTF {
</span><span class="cx"> class String;
</span><span class="lines">@@ -91,7 +91,7 @@
</span><span class="cx">     WEBCORE_EXPORT virtual void setLegibleMediaSelectionOptions(const Vector&lt;WTF::String&gt;&amp; options, uint64_t selectedIndex) override;
</span><span class="cx">     WEBCORE_EXPORT virtual void setExternalPlayback(bool enabled, ExternalPlaybackTargetType, WTF::String localizedDeviceName) override;
</span><span class="cx">     
</span><del>-    WEBCORE_EXPORT virtual void setupFullscreen(PlatformLayer&amp;, const IntRect&amp; initialRect, UIView *, HTMLMediaElementEnums::VideoFullscreenMode, bool allowsPictureInPicturePlayback);
</del><ins>+    WEBCORE_EXPORT virtual void setupFullscreen(UIView&amp;, const IntRect&amp; initialRect, UIView *, HTMLMediaElementEnums::VideoFullscreenMode, bool allowsPictureInPicturePlayback);
</ins><span class="cx">     WEBCORE_EXPORT virtual void enterFullscreen();
</span><span class="cx">     WEBCORE_EXPORT virtual void exitFullscreen(const IntRect&amp; finalRect);
</span><span class="cx">     WEBCORE_EXPORT virtual void cleanupFullscreen();
</span><span class="lines">@@ -133,9 +133,6 @@
</span><span class="cx"> 
</span><span class="cx">     RetainPtr&lt;WebAVPlayerController&gt; m_playerController;
</span><span class="cx">     RetainPtr&lt;AVPlayerViewController&gt; m_playerViewController;
</span><del>-    RetainPtr&lt;CALayer&gt; m_videoLayer;
-    RetainPtr&lt;WebAVVideoLayer&gt; m_videoLayerContainer;
-    RetainPtr&lt;WebCALayerHostWrapper&gt; m_layerHostWrapper;
</del><span class="cx">     WebVideoFullscreenModel* m_videoFullscreenModel { nullptr };
</span><span class="cx">     WebVideoFullscreenChangeObserver* m_fullscreenChangeObserver { nullptr };
</span><span class="cx"> 
</span><span class="lines">@@ -144,6 +141,7 @@
</span><span class="cx">     RetainPtr&lt;UIViewController&gt; m_viewController;
</span><span class="cx">     RetainPtr&lt;UIView&gt; m_parentView;
</span><span class="cx">     RetainPtr&lt;UIWindow&gt; m_parentWindow;
</span><ins>+    RetainPtr&lt;WebAVPlayerLayerView&gt; m_playerLayerView;
</ins><span class="cx">     HTMLMediaElementEnums::VideoFullscreenMode m_mode { HTMLMediaElementEnums::VideoFullscreenModeNone };
</span><span class="cx">     std::function&lt;void(bool)&gt; m_prepareToInlineCallback;
</span><span class="cx">     bool m_allowsPictureInPicturePlayback { false };
</span></span></pre></div>
<a id="branchessafari6011branchSourceWebCoreplatformiosWebVideoFullscreenInterfaceAVKitmm"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1-branch/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.mm (187091 => 187092)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1-branch/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.mm        2015-07-21 05:27:45 UTC (rev 187091)
+++ branches/safari-601.1-branch/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.mm        2015-07-21 05:27:51 UTC (rev 187092)
</span><span class="lines">@@ -39,6 +39,8 @@
</span><span class="cx"> #import &quot;WebVideoFullscreenModel.h&quot;
</span><span class="cx"> #import &lt;AVFoundation/AVTime.h&gt;
</span><span class="cx"> #import &lt;UIKit/UIKit.h&gt;
</span><ins>+#import &lt;objc/message.h&gt;
+#import &lt;objc/runtime.h&gt;
</ins><span class="cx"> #import &lt;wtf/RetainPtr.h&gt;
</span><span class="cx"> #import &lt;wtf/text/CString.h&gt;
</span><span class="cx"> #import &lt;wtf/text/WTFString.h&gt;
</span><span class="lines">@@ -50,11 +52,16 @@
</span><span class="cx"> 
</span><span class="cx"> SOFT_LINK_FRAMEWORK(AVFoundation)
</span><span class="cx"> SOFT_LINK_CLASS(AVFoundation, AVPlayerLayer)
</span><ins>+SOFT_LINK_CONSTANT(AVFoundation, AVLayerVideoGravityResize, NSString *)
+SOFT_LINK_CONSTANT(AVFoundation, AVLayerVideoGravityResizeAspect, NSString *)
+SOFT_LINK_CONSTANT(AVFoundation, AVLayerVideoGravityResizeAspectFill, NSString *)
</ins><span class="cx"> 
</span><span class="cx"> SOFT_LINK_FRAMEWORK(AVKit)
</span><span class="cx"> SOFT_LINK_CLASS(AVKit, AVPlayerController)
</span><span class="cx"> SOFT_LINK_CLASS(AVKit, AVPlayerViewController)
</span><span class="cx"> SOFT_LINK_CLASS(AVKit, AVValueTiming)
</span><ins>+SOFT_LINK_CLASS(AVKit, AVPlayerLayerView)
+SOFT_LINK_CLASS(AVKit, AVPictureInPicturePlayerLayerView)
</ins><span class="cx"> 
</span><span class="cx"> SOFT_LINK_FRAMEWORK(UIKit)
</span><span class="cx"> SOFT_LINK_CLASS(UIKit, UIApplication)
</span><span class="lines">@@ -74,13 +81,12 @@
</span><span class="cx"> 
</span><span class="cx"> @class WebAVMediaSelectionOption;
</span><span class="cx"> 
</span><del>-@interface WebAVPlayerController : NSObject &lt;AVPlayerViewControllerDelegate&gt;
-{
</del><ins>+@interface WebAVPlayerController : NSObject &lt;AVPlayerViewControllerDelegate&gt; {
</ins><span class="cx">     WebAVMediaSelectionOption *_currentAudioMediaSelectionOption;
</span><span class="cx">     WebAVMediaSelectionOption *_currentLegibleMediaSelectionOption;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>--(void)resetState;
</del><ins>+- (void)resetState;
</ins><span class="cx"> 
</span><span class="cx"> @property (retain) AVPlayerController* playerControllerProxy;
</span><span class="cx"> @property (assign) WebVideoFullscreenModel* delegate;
</span><span class="lines">@@ -150,7 +156,8 @@
</span><span class="cx">     [super dealloc];
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>--(void)resetState {
</del><ins>+- (void)resetState
+{
</ins><span class="cx">     self.contentDuration = 0;
</span><span class="cx">     self.maxTime = 0;
</span><span class="cx">     self.contentDurationWithinEndTimes = 0;
</span><span class="lines">@@ -181,7 +188,8 @@
</span><span class="cx">     self.currentLegibleMediaSelectionOption = nil;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (AVPlayer*) player {
</del><ins>+- (AVPlayer *) player
+{
</ins><span class="cx">     return nil;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -568,25 +576,52 @@
</span><span class="cx"> @implementation WebAVMediaSelectionOption
</span><span class="cx"> @end
</span><span class="cx"> 
</span><del>-
-@interface WebCALayerHostWrapper : CALayer
-@property (assign) WebVideoFullscreenModel* model;
</del><ins>+@interface WebAVPlayerLayer : CALayer
+@property (nonatomic, retain) NSString *videoGravity;
+@property (nonatomic, getter=isReadyForDisplay) BOOL readyForDisplay;
+@property (nonatomic, retain) AVPlayerController *playerController;
+@property (nonatomic, retain) CALayer *videoSublayer;
+@property (nonatomic, copy, nullable) NSDictionary *pixelBufferAttributes;
+@property CGSize videoDimensions;
+@property CGRect modelVideoLayerFrame;
</ins><span class="cx"> @end
</span><span class="cx"> 
</span><del>-@implementation WebCALayerHostWrapper {
</del><ins>+@implementation WebAVPlayerLayer {
+    RetainPtr&lt;WebAVPlayerController&gt; _avPlayerController;
</ins><span class="cx">     RetainPtr&lt;CALayer&gt; _videoSublayer;
</span><ins>+    RetainPtr&lt;NSString&gt; _videoGravity;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (instancetype)init
+{
+    self = [super init];
+    if (self) {
+        [self setMasksToBounds:YES];
+        _videoGravity = getAVLayerVideoGravityResizeAspect();
+    }
+    return self;
+}
+
</ins><span class="cx"> - (void)dealloc
</span><span class="cx"> {
</span><span class="cx">     [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(resolveBounds) object:nil];
</span><span class="cx">     [super dealloc];
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (void)setVideoSublayer:(CALayer*)videoSublayer
</del><ins>+- (AVPlayerController *)playerController
</ins><span class="cx"> {
</span><ins>+    return (AVPlayerController *)_avPlayerController.get();
+}
+
+- (void)setPlayerController:(AVPlayerController *)playerController
+{
+    ASSERT(!playerController || [playerController isKindOfClass:[WebAVPlayerController class]]);
+    _avPlayerController = (WebAVPlayerController *)playerController;
+}
+
+- (void)setVideoSublayer:(CALayer *)videoSublayer
+{
</ins><span class="cx">     _videoSublayer = videoSublayer;
</span><del>-    [self addSublayer:videoSublayer];
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (CALayer*)videoSublayer
</span><span class="lines">@@ -598,152 +633,239 @@
</span><span class="cx"> {
</span><span class="cx">     if (CGRectEqualToRect(bounds, self.bounds))
</span><span class="cx">         return;
</span><del>-
</del><ins>+    
</ins><span class="cx">     [super setBounds:bounds];
</span><ins>+    
+    if ([_videoSublayer superlayer] != self)
+        return;
</ins><span class="cx"> 
</span><span class="cx">     [_videoSublayer setPosition:CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds))];
</span><del>-
-    if (!self.model)
</del><ins>+    
+    if (![_avPlayerController delegate])
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    FloatRect videoFrame = self.model-&gt;videoLayerFrame();
-    FloatRect targetFrame;
-    switch (self.model-&gt;videoLayerGravity()) {
-    case WebCore::WebVideoFullscreenModel::VideoGravityResize:
-        targetFrame = bounds;
-        break;
-    case WebCore::WebVideoFullscreenModel::VideoGravityResizeAspect:
-        targetFrame = largestRectWithAspectRatioInsideRect(videoFrame.size().aspectRatio(), bounds);
-        break;
-    case WebCore::WebVideoFullscreenModel::VideoGravityResizeAspectFill:
-        targetFrame = smallestRectWithAspectRatioAroundRect(videoFrame.size().aspectRatio(), bounds);
-        break;
-    }
-    CATransform3D transform = CATransform3DMakeScale(targetFrame.width() / videoFrame.width(), targetFrame.height() / videoFrame.height(), 1);
-    [_videoSublayer setSublayerTransform:transform];
</del><ins>+    FloatRect sourceVideoFrame;
+    FloatRect targetVideoFrame;
+    float videoAspectRatio = self.videoDimensions.width / self.videoDimensions.height;
+    
+    if ([getAVLayerVideoGravityResize() isEqualToString:self.videoGravity]) {
+        sourceVideoFrame = self.modelVideoLayerFrame;
+        targetVideoFrame = self.bounds;
+    } else if ([getAVLayerVideoGravityResizeAspect() isEqualToString:self.videoGravity]) {
+        sourceVideoFrame = largestRectWithAspectRatioInsideRect(videoAspectRatio, self.modelVideoLayerFrame);
+        targetVideoFrame = largestRectWithAspectRatioInsideRect(videoAspectRatio, self.bounds);
+    } else if ([getAVLayerVideoGravityResizeAspectFill() isEqualToString:self.videoGravity]) {
+        sourceVideoFrame = smallestRectWithAspectRatioAroundRect(videoAspectRatio, self.modelVideoLayerFrame);
+        self.modelVideoLayerFrame = CGRectMake(0, 0, sourceVideoFrame.width(), sourceVideoFrame.height());
+        [_avPlayerController delegate]-&gt;setVideoLayerFrame(self.modelVideoLayerFrame);
+        targetVideoFrame = smallestRectWithAspectRatioAroundRect(videoAspectRatio, self.bounds);
+    } else
+        ASSERT_NOT_REACHED();
</ins><span class="cx"> 
</span><ins>+    UIView *view = [_videoSublayer delegate];
+    CGAffineTransform transform = CGAffineTransformMakeScale(targetVideoFrame.width() / sourceVideoFrame.width(), targetVideoFrame.height() / sourceVideoFrame.height());
+    [view setTransform:transform];
+    
</ins><span class="cx">     [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(resolveBounds) object:nil];
</span><del>-    [self performSelector:@selector(resolveBounds) withObject:nil afterDelay:[CATransaction animationDuration] + 0.1];
</del><ins>+    
+    if (!CGAffineTransformEqualToTransform(CGAffineTransformIdentity, transform))
+        [self performSelector:@selector(resolveBounds) withObject:nil afterDelay:[CATransaction animationDuration] + 0.1];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (void)resolveBounds
</span><span class="cx"> {
</span><span class="cx">     [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(resolveBounds) object:nil];
</span><del>-    if (!self.model)
</del><ins>+    if (![_avPlayerController delegate])
</ins><span class="cx">         return;
</span><del>-
</del><ins>+    
+    if ([_videoSublayer superlayer] != self)
+        return;
+    
</ins><span class="cx">     [CATransaction begin];
</span><span class="cx">     [CATransaction setAnimationDuration:0];
</span><del>-
-    [_videoSublayer setSublayerTransform:CATransform3DIdentity];
-    self.model-&gt;setVideoLayerFrame([self bounds]);
</del><span class="cx">     
</span><ins>+    [(UIView *)[_videoSublayer delegate] setTransform:CGAffineTransformIdentity];
+    self.modelVideoLayerFrame = [self bounds];
+    [_avPlayerController delegate]-&gt;setVideoLayerFrame(self.modelVideoLayerFrame);
+    
</ins><span class="cx">     [CATransaction commit];
</span><span class="cx"> }
</span><ins>+
+- (void)setVideoGravity:(NSString *)videoGravity
+{
+    _videoGravity = videoGravity;
+    
+    if (![_avPlayerController delegate])
+        return;
+
+    WebCore::WebVideoFullscreenModel::VideoGravity gravity = WebCore::WebVideoFullscreenModel::VideoGravityResizeAspect;
+    if (videoGravity == getAVLayerVideoGravityResize())
+        gravity = WebCore::WebVideoFullscreenModel::VideoGravityResize;
+    if (videoGravity == getAVLayerVideoGravityResizeAspect())
+        gravity = WebCore::WebVideoFullscreenModel::VideoGravityResizeAspect;
+    else if (videoGravity == getAVLayerVideoGravityResizeAspectFill())
+        gravity = WebCore::WebVideoFullscreenModel::VideoGravityResizeAspectFill;
+    else
+        ASSERT_NOT_REACHED();
+    
+    [_avPlayerController delegate]-&gt;setVideoLayerGravity(gravity);
+}
+
+- (NSString *)videoGravity
+{
+    return _videoGravity.get();
+}
+
+- (CGRect)videoRect
+{
+    float videoAspectRatio = self.videoDimensions.width / self.videoDimensions.height;
+    
+    if ([getAVLayerVideoGravityResizeAspect() isEqualToString:self.videoGravity])
+        return largestRectWithAspectRatioInsideRect(videoAspectRatio, self.bounds);
+    if ([getAVLayerVideoGravityResizeAspectFill() isEqualToString:self.videoGravity])
+        return smallestRectWithAspectRatioAroundRect(videoAspectRatio, self.bounds);
+
+    return self.bounds;
+}
+
++ (NSSet *)keyPathsForValuesAffectingVideoRect
+{
+    return [NSSet setWithObjects:@&quot;videoDimensions&quot;, @&quot;videoGravity&quot;, nil];
+}
+
</ins><span class="cx"> @end
</span><span class="cx"> 
</span><del>-@interface WebAVVideoLayer : CALayer &lt;AVVideoLayer&gt;
-+(WebAVVideoLayer *)videoLayer;
-@property (nonatomic) AVVideoLayerGravity videoLayerGravity;
-@property (nonatomic, getter = isReadyForDisplay) BOOL readyForDisplay;
-@property (nonatomic) CGRect videoRect;
-- (void)setPlayerViewController:(AVPlayerViewController *)playerViewController;
-- (void)setPlayerController:(AVPlayerController *)playerController;
-@property (nonatomic, retain) CALayer* videoSublayer;
</del><ins>+@interface WebAVPictureInPicturePlayerLayerView : AVPictureInPicturePlayerLayerView
</ins><span class="cx"> @end
</span><span class="cx"> 
</span><del>-@implementation WebAVVideoLayer
</del><ins>+static CALayer* WebAVPictureInPicturePlayerLayerView_layerClass(id, SEL)
</ins><span class="cx"> {
</span><del>-    RetainPtr&lt;WebAVPlayerController&gt; _avPlayerController;
-    RetainPtr&lt;AVPlayerViewController&gt; _avPlayerViewController;
-    RetainPtr&lt;CALayer&gt; _videoSublayer;
-    AVVideoLayerGravity _videoLayerGravity;
</del><ins>+    return [WebAVPlayerLayer class];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-+(WebAVVideoLayer *)videoLayer
</del><ins>+static Class getWebAVPictureInPicturePlayerLayerViewClass()
</ins><span class="cx"> {
</span><del>-    return [[[WebAVVideoLayer alloc] init] autorelease];
</del><ins>+    static Class theClass = nil;
+    static dispatch_once_t onceToken;
+    dispatch_once(&amp;onceToken, ^{
+        theClass = objc_allocateClassPair(getAVPictureInPicturePlayerLayerViewClass(), &quot;WebAVPictureInPicturePlayerLayerView&quot;, 0);
+        objc_registerClassPair(theClass);
+        Class metaClass = objc_getMetaClass(&quot;WebAVPictureInPicturePlayerLayerView&quot;);
+        class_addMethod(metaClass, @selector(layerClass), (IMP)WebAVPictureInPicturePlayerLayerView_layerClass, &quot;@@:&quot;);
+    });
+    
+    return theClass;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (instancetype)init
</del><ins>+@interface WebAVPlayerLayerView : AVPlayerLayerView
+@property (retain) UIView* videoView;
+@end
+
+static CALayer* WebAVPlayerLayerView_layerClass(id, SEL)
</ins><span class="cx"> {
</span><del>-    self = [super init];
-    if (self) {
-        [self setMasksToBounds:YES];
-        [self setVideoLayerGravity:AVVideoLayerGravityResizeAspect];
-    }
-    return self;
</del><ins>+    return [WebAVPlayerLayer class];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (void)setPlayerController:(AVPlayerController *)playerController
</del><ins>+static AVPlayerController* WebAVPlayerLayerView_playerController(id aSelf, SEL)
</ins><span class="cx"> {
</span><del>-    ASSERT(!playerController || [playerController isKindOfClass:[WebAVPlayerController class]]);
-    _avPlayerController = (WebAVPlayerController *)playerController;
</del><ins>+    AVPlayerLayerView *playerLayer = aSelf;
+    WebAVPlayerLayer *webAVPlayerLayer = (WebAVPlayerLayer *)[playerLayer playerLayer];
+    return [webAVPlayerLayer playerController];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (void)setPlayerViewController:(AVPlayerViewController *)playerViewController
</del><ins>+static void WebAVPlayerLayerView_setPlayerController(id aSelf, SEL, AVPlayerController *playerController)
</ins><span class="cx"> {
</span><del>-    _avPlayerViewController = playerViewController;
</del><ins>+    AVPlayerLayerView *playerLayerView = aSelf;
+    WebAVPlayerLayer *webAVPlayerLayer = (WebAVPlayerLayer *)[playerLayerView playerLayer];
+    [webAVPlayerLayer setPlayerController: playerController];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (void)setVideoSublayer:(CALayer *)videoSublayer
</del><ins>+static UIView* WebAVPlayerLayerView_videoView(id aSelf, SEL)
</ins><span class="cx"> {
</span><del>-    _videoSublayer = videoSublayer;
-    [self addSublayer:videoSublayer];
</del><ins>+    AVPlayerLayerView *playerLayer = aSelf;
+    WebAVPlayerLayer *webAVPlayerLayer = (WebAVPlayerLayer *)[playerLayer playerLayer];
+    CALayer* videoLayer = [webAVPlayerLayer videoSublayer];
+    if (!videoLayer)
+        return nil;
+    ASSERT([[videoLayer delegate] isKindOfClass:getUIViewClass()]);
+    return (UIView *)[videoLayer delegate];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (CALayer*)videoSublayer
</del><ins>+static void WebAVPlayerLayerView_setVideoView(id aSelf, SEL, UIView *videoView)
</ins><span class="cx"> {
</span><del>-    return _videoSublayer.get();
</del><ins>+    AVPlayerLayerView *playerLayerView = aSelf;
+    WebAVPlayerLayer *webAVPlayerLayer = (WebAVPlayerLayer *)[playerLayerView playerLayer];
+    [webAVPlayerLayer setVideoSublayer:[videoView layer]];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (void)setBounds:(CGRect)bounds
</del><ins>+static void WebAVPlayerLayerView_startRoutingVideoToPictureInPicturePlayerLayerView(id aSelf, SEL)
</ins><span class="cx"> {
</span><del>-    [super setBounds:bounds];
</del><ins>+    WebAVPlayerLayerView *playerLayerView = aSelf;
+    AVPictureInPicturePlayerLayerView *pipView = [playerLayerView pictureInPicturePlayerLayerView];
</ins><span class="cx"> 
</span><del>-    if ([_videoSublayer superlayer] == self) {
-        [_videoSublayer setPosition:CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds))];
-        [_videoSublayer setBounds:bounds];
-    }
</del><ins>+    WebAVPlayerLayer *playerLayer = (WebAVPlayerLayer *)[playerLayerView playerLayer];
+    WebAVPlayerLayer *pipPlayerLayer = (WebAVPlayerLayer *)[pipView playerLayer];
+    [playerLayer setVideoGravity:getAVLayerVideoGravityResizeAspect()];
+    [pipPlayerLayer setVideoSublayer:playerLayer.videoSublayer];
+    [pipPlayerLayer setVideoDimensions:playerLayer.videoDimensions];
+    [pipPlayerLayer setVideoGravity:playerLayer.videoGravity];
+    [pipPlayerLayer setModelVideoLayerFrame:playerLayer.modelVideoLayerFrame];
+    [pipPlayerLayer setPlayerController:playerLayer.playerController];
+    [pipView addSubview:playerLayerView.videoView];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (void)setVideoLayerGravity:(AVVideoLayerGravity)videoLayerGravity
</del><ins>+static void WebAVPlayerLayerView_stopRoutingVideoToPictureInPicturePlayerLayerView(id aSelf, SEL)
</ins><span class="cx"> {
</span><del>-    _videoLayerGravity = videoLayerGravity;
-    
-    if (![_avPlayerController delegate])
-        return;
-
-    WebCore::WebVideoFullscreenModel::VideoGravity gravity = WebCore::WebVideoFullscreenModel::VideoGravityResizeAspect;
-    if (videoLayerGravity == AVVideoLayerGravityResize)
-        gravity = WebCore::WebVideoFullscreenModel::VideoGravityResize;
-    if (videoLayerGravity == AVVideoLayerGravityResizeAspect)
-        gravity = WebCore::WebVideoFullscreenModel::VideoGravityResizeAspect;
-    else if (videoLayerGravity == AVVideoLayerGravityResizeAspectFill)
-        gravity = WebCore::WebVideoFullscreenModel::VideoGravityResizeAspectFill;
-    else
-        ASSERT_NOT_REACHED();
-    
-    [_avPlayerController delegate]-&gt;setVideoLayerGravity(gravity);
</del><ins>+    WebAVPlayerLayerView *playerLayerView = aSelf;
+    [playerLayerView addSubview:playerLayerView.videoView];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (AVVideoLayerGravity)videoLayerGravity
</del><ins>+static AVPictureInPicturePlayerLayerView *WebAVPlayerLayerView_pictureInPicturePlayerLayerView(id aSelf, SEL)
</ins><span class="cx"> {
</span><del>-    return _videoLayerGravity;
</del><ins>+    WebAVPlayerLayerView *playerLayerView = aSelf;
+    WebAVPictureInPicturePlayerLayerView *pipView = [playerLayerView valueForKey:@&quot;_pictureInPicturePlayerLayerView&quot;];
+    if (!pipView) {
+        pipView = [[getWebAVPictureInPicturePlayerLayerViewClass() alloc] initWithFrame:CGRectZero];
+        [playerLayerView setValue:pipView forKey:@&quot;_pictureInPicturePlayerLayerView&quot;];
+    }
+    return pipView;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (void)enterPIPModeRedirectingVideoToLayer:(CALayer *)layer
</del><ins>+static void WebAVPlayerLayerView_dealloc(id aSelf, SEL)
</ins><span class="cx"> {
</span><del>-    [_videoSublayer removeFromSuperlayer];
-    [layer addSublayer:_videoSublayer.get()];
</del><ins>+    WebAVPlayerLayerView *playerLayerView = aSelf;
+    RetainPtr&lt;WebAVPictureInPicturePlayerLayerView&gt; pipView = adoptNS([playerLayerView valueForKey:@&quot;_pictureInPicturePlayerLayerView&quot;]);
+    [playerLayerView setValue:nil forKey:@&quot;_pictureInPicturePlayerLayerView&quot;];
+    objc_super superClass { playerLayerView, getAVPlayerLayerViewClass() };
+    auto super_dealloc = reinterpret_cast&lt;void(*)(objc_super*, SEL)&gt;(objc_msgSendSuper);
+    super_dealloc(&amp;superClass, @selector(dealloc));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (void)leavePIPMode
</del><ins>+#pragma mark - Methods
+
+static Class getWebAVPlayerLayerViewClass()
</ins><span class="cx"> {
</span><del>-    [_videoSublayer removeFromSuperlayer];
-    [self addSublayer:_videoSublayer.get()];
</del><ins>+    static Class theClass = nil;
+    static dispatch_once_t onceToken;
+    dispatch_once(&amp;onceToken, ^{
+        theClass = objc_allocateClassPair(getAVPlayerLayerViewClass(), &quot;WebAVPlayerLayerView&quot;, 0);
+        class_addMethod(theClass, @selector(dealloc), (IMP)WebAVPlayerLayerView_dealloc, &quot;v@:&quot;);
+        class_addMethod(theClass, @selector(setPlayerController:), (IMP)WebAVPlayerLayerView_setPlayerController, &quot;v@:@&quot;);
+        class_addMethod(theClass, @selector(playerController), (IMP)WebAVPlayerLayerView_playerController, &quot;@@:&quot;);
+        class_addMethod(theClass, @selector(setVideoView:), (IMP)WebAVPlayerLayerView_setVideoView, &quot;v@:@&quot;);
+        class_addMethod(theClass, @selector(videoView), (IMP)WebAVPlayerLayerView_videoView, &quot;@@:&quot;);
+        class_addMethod(theClass, @selector(startRoutingVideoToPictureInPicturePlayerLayerView), (IMP)WebAVPlayerLayerView_startRoutingVideoToPictureInPicturePlayerLayerView, &quot;v@:&quot;);
+        class_addMethod(theClass, @selector(stopRoutingVideoToPictureInPicturePlayerLayerView), (IMP)WebAVPlayerLayerView_stopRoutingVideoToPictureInPicturePlayerLayerView, &quot;v@:&quot;);
+        class_addMethod(theClass, @selector(pictureInPicturePlayerLayerView), (IMP)WebAVPlayerLayerView_pictureInPicturePlayerLayerView, &quot;@@:&quot;);
+        
+        class_addIvar(theClass, &quot;_pictureInPicturePlayerLayerView&quot;, sizeof(WebAVPictureInPicturePlayerLayerView *), log2(sizeof(WebAVPictureInPicturePlayerLayerView *)), &quot;@&quot;);
+        
+        objc_registerClassPair(theClass);
+        Class metaClass = objc_getMetaClass(&quot;WebAVPlayerLayerView&quot;);
+        class_addMethod(metaClass, @selector(layerClass), (IMP)WebAVPlayerLayerView_layerClass, &quot;@@:&quot;);
+    });
+    return theClass;
</ins><span class="cx"> }
</span><del>-@end
</del><span class="cx"> 
</span><span class="cx"> WebVideoFullscreenInterfaceAVKit::WebVideoFullscreenInterfaceAVKit()
</span><span class="cx">     : m_playerController(adoptNS([[WebAVPlayerController alloc] init]))
</span><span class="lines">@@ -826,6 +948,9 @@
</span><span class="cx"> 
</span><span class="cx"> void WebVideoFullscreenInterfaceAVKit::setVideoDimensions(bool hasVideo, float width, float height)
</span><span class="cx"> {
</span><ins>+    WebAVPlayerLayer *playerLayer = (WebAVPlayerLayer *)[m_playerLayerView playerLayer];
+
+    [playerLayer setVideoDimensions:CGSizeMake(width, height)];
</ins><span class="cx">     [m_playerController setHasEnabledVideo:hasVideo];
</span><span class="cx">     [m_playerController setContentDimensions:CGSizeMake(width, height)];
</span><span class="cx"> }
</span><span class="lines">@@ -890,14 +1015,14 @@
</span><span class="cx">     playerController.externalPlaybackAirPlayDeviceLocalizedName = localizedDeviceName;
</span><span class="cx">     playerController.externalPlaybackType = externalPlaybackType;
</span><span class="cx">     playerController.externalPlaybackActive = enabled;
</span><del>-    [m_videoLayerContainer.get() setHidden:enabled];
</del><ins>+    [m_playerLayerView setHidden:enabled];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> @interface UIWindow ()
</span><del>--(BOOL)_isHostedInAnotherProcess;
</del><ins>+- (BOOL)_isHostedInAnotherProcess;
</ins><span class="cx"> @end
</span><span class="cx"> 
</span><del>-void WebVideoFullscreenInterfaceAVKit::setupFullscreen(PlatformLayer&amp; videoLayer, const WebCore::IntRect&amp; initialRect, UIView* parentView, HTMLMediaElementEnums::VideoFullscreenMode mode, bool allowsPictureInPicturePlayback)
</del><ins>+void WebVideoFullscreenInterfaceAVKit::setupFullscreen(UIView&amp; videoView, const WebCore::IntRect&amp; initialRect, UIView* parentView, HTMLMediaElementEnums::VideoFullscreenMode mode, bool allowsPictureInPicturePlayback)
</ins><span class="cx"> {
</span><span class="cx">     ASSERT(mode != HTMLMediaElementEnums::VideoFullscreenModeNone);
</span><span class="cx">     LOG(Fullscreen, &quot;WebVideoFullscreenInterfaceAVKit::setupFullscreen(%p)&quot;, this);
</span><span class="lines">@@ -906,7 +1031,6 @@
</span><span class="cx"> 
</span><span class="cx">     [CATransaction begin];
</span><span class="cx">     [CATransaction setDisableActions:YES];
</span><del>-    m_videoLayer = &amp;videoLayer;
</del><span class="cx">     m_mode = mode;
</span><span class="cx">     m_parentView = parentView;
</span><span class="cx">     m_parentWindow = parentView.window;
</span><span class="lines">@@ -920,51 +1044,46 @@
</span><span class="cx">         [m_window makeKeyAndVisible];
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    [m_videoLayer removeFromSuperlayer];
</del><ins>+    m_playerLayerView = adoptNS([[getWebAVPlayerLayerViewClass() alloc] init]);
+    [m_playerLayerView setHidden:[m_playerController isExternalPlaybackActive]];
+    [m_playerLayerView setBackgroundColor:[getUIColorClass() clearColor]];
+    
+    [m_playerLayerView setVideoView:&amp;videoView];
+    [m_playerLayerView addSubview:&amp;videoView];
</ins><span class="cx"> 
</span><del>-    m_layerHostWrapper = adoptNS([[WebCALayerHostWrapper alloc] init]);
-    [m_layerHostWrapper setModel:m_videoFullscreenModel];
-    [m_layerHostWrapper setVideoSublayer:m_videoLayer.get()];
</del><ins>+    WebAVPlayerLayer *playerLayer = (WebAVPlayerLayer *)[m_playerLayerView playerLayer];
</ins><span class="cx"> 
</span><del>-    m_videoLayerContainer = [WebAVVideoLayer videoLayer];
-    [m_videoLayerContainer setHidden:[m_playerController isExternalPlaybackActive]];
-    [m_videoLayerContainer setVideoSublayer:m_layerHostWrapper.get()];
</del><ins>+    [playerLayer setModelVideoLayerFrame:CGRectMake(0, 0, initialRect.width(), initialRect.height())];
+    [playerLayer setVideoDimensions:[m_playerController contentDimensions]];
</ins><span class="cx"> 
</span><del>-    CGSize videoSize = [m_playerController contentDimensions];
-    CGRect videoRect = CGRectMake(0, 0, videoSize.width, videoSize.height);
-    [m_videoLayerContainer setVideoRect:videoRect];
-    if (m_videoFullscreenModel)
-        m_videoFullscreenModel-&gt;setVideoLayerFrame(videoRect);
</del><ins>+    m_playerViewController = adoptNS([allocAVPlayerViewControllerInstance() initWithPlayerLayerView:m_playerLayerView.get()]);
</ins><span class="cx"> 
</span><del>-    // This method has been deprecated so ignore the warning until we port our code to the new API.
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored &quot;-Wdeprecated-declarations&quot;
-    m_playerViewController = adoptNS([allocAVPlayerViewControllerInstance() initWithVideoLayer:m_videoLayerContainer.get()]);
-#pragma clang diagnostic pop
-
</del><span class="cx">     [m_playerViewController setShowsPlaybackControls:NO];
</span><span class="cx">     [m_playerViewController setPlayerController:(AVPlayerController *)m_playerController.get()];
</span><span class="cx">     [m_playerViewController setDelegate:m_playerController.get()];
</span><span class="cx">     [m_playerViewController setAllowsPictureInPicturePlayback:m_allowsPictureInPicturePlayback];
</span><span class="cx"> 
</span><del>-    [m_videoLayerContainer setPlayerViewController:m_playerViewController.get()];
-
</del><span class="cx">     if (m_viewController) {
</span><span class="cx">         [m_viewController addChildViewController:m_playerViewController.get()];
</span><span class="cx">         [[m_viewController view] addSubview:[m_playerViewController view]];
</span><span class="cx">     } else
</span><del>-        [parentView.window addSubview:[m_playerViewController view]];
</del><ins>+        [parentView addSubview:[m_playerViewController view]];
</ins><span class="cx"> 
</span><del>-    [m_playerViewController view].frame = [parentView convertRect:initialRect toView:nil];
</del><ins>+    [m_playerViewController view].frame = [parentView convertRect:initialRect toView:[m_playerViewController view].superview];
</ins><span class="cx"> 
</span><span class="cx">     [[m_playerViewController view] setBackgroundColor:[getUIColorClass() clearColor]];
</span><ins>+    [[m_playerViewController view] setAutoresizingMask:(UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin)];
+
</ins><span class="cx">     [[m_playerViewController view] setNeedsLayout];
</span><span class="cx">     [[m_playerViewController view] layoutIfNeeded];
</span><span class="cx"> 
</span><span class="cx">     [CATransaction commit];
</span><span class="cx"> 
</span><del>-    if (m_fullscreenChangeObserver)
-        m_fullscreenChangeObserver-&gt;didSetupFullscreen();
</del><ins>+    RefPtr&lt;WebVideoFullscreenInterfaceAVKit&gt; strongThis(this);
+    dispatch_async(dispatch_get_main_queue(), [strongThis, this] {
+        if (m_fullscreenChangeObserver)
+            m_fullscreenChangeObserver-&gt;didSetupFullscreen();
+    });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebVideoFullscreenInterfaceAVKit::enterFullscreen()
</span><span class="lines">@@ -975,7 +1094,7 @@
</span><span class="cx">     m_exitRequested = false;
</span><span class="cx">     m_enterRequested = true;
</span><span class="cx"> 
</span><del>-    [m_videoLayerContainer setBackgroundColor:[[getUIColorClass() blackColor] CGColor]];
</del><ins>+    [m_playerLayerView setBackgroundColor:[getUIColorClass() blackColor]];
</ins><span class="cx">     if (mode() == HTMLMediaElementEnums::VideoFullscreenModePictureInPicture)
</span><span class="cx">         enterPictureInPicture();
</span><span class="cx">     else if (mode() == HTMLMediaElementEnums::VideoFullscreenModeStandard)
</span><span class="lines">@@ -1019,13 +1138,12 @@
</span><span class="cx">     
</span><span class="cx">     LOG(Fullscreen, &quot;WebVideoFullscreenInterfaceAVKit::exitFullscreen(%p)&quot;, this);
</span><span class="cx">     [m_playerViewController setShowsPlaybackControls:NO];
</span><del>-    if (m_viewController)
-        [m_playerViewController view].frame = [m_parentView convertRect:finalRect toView:nil];
-    else
-        [m_playerViewController view].frame = finalRect;
</del><ins>+    
+    [m_playerViewController view].frame = [m_parentView convertRect:finalRect toView:[m_playerViewController view].superview];
</ins><span class="cx"> 
</span><del>-    if ([m_videoLayerContainer videoLayerGravity] != AVVideoLayerGravityResizeAspect)
-        [m_videoLayerContainer setVideoLayerGravity:AVVideoLayerGravityResizeAspect];
</del><ins>+    WebAVPlayerLayer *playerLayer = (WebAVPlayerLayer *)[m_playerLayerView playerLayer];
+    if ([playerLayer videoGravity] != getAVLayerVideoGravityResizeAspect())
+        [playerLayer setVideoGravity:getAVLayerVideoGravityResizeAspect()];
</ins><span class="cx">     [[m_playerViewController view] layoutIfNeeded];
</span><span class="cx"> 
</span><span class="cx">     if (isMode(HTMLMediaElementEnums::VideoFullscreenModePictureInPicture)) {
</span><span class="lines">@@ -1044,22 +1162,24 @@
</span><span class="cx"> 
</span><span class="cx">             [CATransaction begin];
</span><span class="cx">             [CATransaction setDisableActions:YES];
</span><del>-            [m_videoLayerContainer setBackgroundColor:[[getUIColorClass() clearColor] CGColor]];
</del><ins>+            [m_playerLayerView setBackgroundColor:[getUIColorClass() clearColor]];
</ins><span class="cx">             [[m_playerViewController view] setBackgroundColor:[getUIColorClass() clearColor]];
</span><span class="cx">             [CATransaction commit];
</span><span class="cx"> 
</span><del>-            if (m_fullscreenChangeObserver)
-                m_fullscreenChangeObserver-&gt;didExitFullscreen();
</del><ins>+            dispatch_async(dispatch_get_main_queue(), ^{
+                if (m_fullscreenChangeObserver)
+                    m_fullscreenChangeObserver-&gt;didExitFullscreen();
+            });
</ins><span class="cx">         }];
</span><span class="cx">     };
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> @interface UIApplication ()
</span><del>--(void)_setStatusBarOrientation:(UIInterfaceOrientation)o;
</del><ins>+- (void)_setStatusBarOrientation:(UIInterfaceOrientation)o;
</ins><span class="cx"> @end
</span><span class="cx"> 
</span><span class="cx"> @interface UIWindow ()
</span><del>--(UIInterfaceOrientation)interfaceOrientation;
</del><ins>+- (UIInterfaceOrientation)interfaceOrientation;
</ins><span class="cx"> @end
</span><span class="cx"> 
</span><span class="cx"> void WebVideoFullscreenInterfaceAVKit::cleanupFullscreen()
</span><span class="lines">@@ -1087,16 +1207,10 @@
</span><span class="cx">     if (m_viewController)
</span><span class="cx">         [m_playerViewController removeFromParentViewController];
</span><span class="cx">     
</span><del>-    [m_videoLayer removeFromSuperlayer];
-    [m_videoLayerContainer removeFromSuperlayer];
-    [m_videoLayerContainer setPlayerViewController:nil];
</del><ins>+    [m_playerLayerView removeFromSuperview];
</ins><span class="cx">     [[m_viewController view] removeFromSuperview];
</span><span class="cx"> 
</span><del>-    [m_layerHostWrapper setModel:nullptr];
-
-    m_layerHostWrapper = nil;
-    m_videoLayer = nil;
-    m_videoLayerContainer = nil;
</del><ins>+    m_playerLayerView = nil;
</ins><span class="cx">     m_playerViewController = nil;
</span><span class="cx">     m_playerController = nil;
</span><span class="cx">     m_viewController = nil;
</span><span class="lines">@@ -1142,7 +1256,7 @@
</span><span class="cx">     LOG(Fullscreen, &quot;WebVideoFullscreenInterfaceAVKit::preparedToReturnToInline(%p) - visible(%s)&quot;, this, boolString(visible));
</span><span class="cx">     if (m_prepareToInlineCallback) {
</span><span class="cx">         
</span><del>-        [m_playerViewController view].frame = [m_parentView convertRect:inlineRect toView:nil];
</del><ins>+        [m_playerViewController view].frame = [m_parentView convertRect:inlineRect toView:[m_playerViewController view].superview];
</ins><span class="cx"> 
</span><span class="cx">         std::function&lt;void(bool)&gt; callback = WTF::move(m_prepareToInlineCallback);
</span><span class="cx">         callback(visible);
</span><span class="lines">@@ -1213,7 +1327,7 @@
</span><span class="cx"> 
</span><span class="cx">     m_exitCompleted = true;
</span><span class="cx"> 
</span><del>-    [m_videoLayerContainer setBackgroundColor:[[getUIColorClass() clearColor] CGColor]];
</del><ins>+    [m_playerLayerView setBackgroundColor:[getUIColorClass() clearColor]];
</ins><span class="cx">     [[m_playerViewController view] setBackgroundColor:[getUIColorClass() clearColor]];
</span><span class="cx"> 
</span><span class="cx">     clearMode(HTMLMediaElementEnums::VideoFullscreenModePictureInPicture);
</span></span></pre></div>
<a id="branchessafari6011branchSourceWebCoreplatformiosWebVideoFullscreenModelh"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1-branch/Source/WebCore/platform/ios/WebVideoFullscreenModel.h (187091 => 187092)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1-branch/Source/WebCore/platform/ios/WebVideoFullscreenModel.h        2015-07-21 05:27:45 UTC (rev 187091)
+++ branches/safari-601.1-branch/Source/WebCore/platform/ios/WebVideoFullscreenModel.h        2015-07-21 05:27:51 UTC (rev 187092)
</span><span class="lines">@@ -48,10 +48,8 @@
</span><span class="cx">     virtual void endScanning() = 0;
</span><span class="cx">     virtual void requestExitFullscreen() = 0;
</span><span class="cx">     virtual void setVideoLayerFrame(FloatRect) = 0;
</span><del>-    virtual FloatRect videoLayerFrame() const = 0;
</del><span class="cx">     enum VideoGravity { VideoGravityResize, VideoGravityResizeAspect, VideoGravityResizeAspectFill };
</span><span class="cx">     virtual void setVideoLayerGravity(VideoGravity) = 0;
</span><del>-    virtual VideoGravity videoLayerGravity() const = 0;
</del><span class="cx">     virtual void selectAudioMediaOption(uint64_t index) = 0;
</span><span class="cx">     virtual void selectLegibleMediaOption(uint64_t index) = 0;
</span><span class="cx">     virtual void fullscreenModeChanged(HTMLMediaElementEnums::VideoFullscreenMode) = 0;
</span></span></pre></div>
<a id="branchessafari6011branchSourceWebCoreplatformiosWebVideoFullscreenModelVideoElementh"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1-branch/Source/WebCore/platform/ios/WebVideoFullscreenModelVideoElement.h (187091 => 187092)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1-branch/Source/WebCore/platform/ios/WebVideoFullscreenModelVideoElement.h        2015-07-21 05:27:45 UTC (rev 187091)
+++ branches/safari-601.1-branch/Source/WebCore/platform/ios/WebVideoFullscreenModelVideoElement.h        2015-07-21 05:27:51 UTC (rev 187092)
</span><span class="lines">@@ -72,9 +72,7 @@
</span><span class="cx">     WEBCORE_EXPORT virtual void endScanning() override;
</span><span class="cx">     WEBCORE_EXPORT virtual void requestExitFullscreen() override;
</span><span class="cx">     WEBCORE_EXPORT virtual void setVideoLayerFrame(FloatRect) override;
</span><del>-    WEBCORE_EXPORT virtual FloatRect videoLayerFrame() const override;
</del><span class="cx">     WEBCORE_EXPORT virtual void setVideoLayerGravity(VideoGravity) override;
</span><del>-    WEBCORE_EXPORT virtual VideoGravity videoLayerGravity() const override;
</del><span class="cx">     WEBCORE_EXPORT virtual void selectAudioMediaOption(uint64_t index) override;
</span><span class="cx">     WEBCORE_EXPORT virtual void selectLegibleMediaOption(uint64_t index) override;
</span><span class="cx">     WEBCORE_EXPORT virtual void fullscreenModeChanged(HTMLMediaElementEnums::VideoFullscreenMode) override;
</span></span></pre></div>
<a id="branchessafari6011branchSourceWebCoreplatformiosWebVideoFullscreenModelVideoElementmm"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1-branch/Source/WebCore/platform/ios/WebVideoFullscreenModelVideoElement.mm (187091 => 187092)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1-branch/Source/WebCore/platform/ios/WebVideoFullscreenModelVideoElement.mm        2015-07-21 05:27:45 UTC (rev 187091)
+++ branches/safari-601.1-branch/Source/WebCore/platform/ios/WebVideoFullscreenModelVideoElement.mm        2015-07-21 05:27:51 UTC (rev 187092)
</span><span class="lines">@@ -254,11 +254,6 @@
</span><span class="cx">         m_videoElement-&gt;setVideoFullscreenFrame(rect);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-FloatRect WebVideoFullscreenModelVideoElement::videoLayerFrame() const
-{
-    return m_videoFrame;
-}
-
</del><span class="cx"> void WebVideoFullscreenModelVideoElement::setVideoLayerGravity(WebVideoFullscreenModel::VideoGravity gravity)
</span><span class="cx"> {
</span><span class="cx">     MediaPlayer::VideoGravity videoGravity = MediaPlayer::VideoGravityResizeAspect;
</span><span class="lines">@@ -274,21 +269,6 @@
</span><span class="cx">     m_videoElement-&gt;setVideoFullscreenGravity(videoGravity);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-WebVideoFullscreenModel::VideoGravity WebVideoFullscreenModelVideoElement::videoLayerGravity() const
-{
-    switch (m_videoElement-&gt;videoFullscreenGravity()) {
-    case MediaPlayer::VideoGravityResize:
-        return VideoGravityResize;
-    case MediaPlayer::VideoGravityResizeAspect:
-        return VideoGravityResizeAspect;
-    case MediaPlayer::VideoGravityResizeAspectFill:
-        return VideoGravityResizeAspectFill;
-    }
-
-    ASSERT_NOT_REACHED();
-    return VideoGravityResize;
-}
-
</del><span class="cx"> void WebVideoFullscreenModelVideoElement::selectAudioMediaOption(uint64_t selectedAudioIndex)
</span><span class="cx"> {
</span><span class="cx">     AudioTrack* selectedAudioTrack = nullptr;
</span></span></pre></div>
<a id="branchessafari6011branchSourceWebCoreplatformspicocoaAVKitSPIh"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1-branch/Source/WebCore/platform/spi/cocoa/AVKitSPI.h (187091 => 187092)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1-branch/Source/WebCore/platform/spi/cocoa/AVKitSPI.h        2015-07-21 05:27:45 UTC (rev 187091)
+++ branches/safari-601.1-branch/Source/WebCore/platform/spi/cocoa/AVKitSPI.h        2015-07-21 05:27:51 UTC (rev 187092)
</span><span class="lines">@@ -34,9 +34,12 @@
</span><span class="cx"> #if USE(APPLE_INTERNAL_SDK)
</span><span class="cx"> 
</span><span class="cx"> #import &lt;AVKit/AVPlayerController.h&gt;
</span><ins>+#pragma clang diagnostic push
+#pragma clang diagnostic ignored &quot;-Wobjc-property-no-attribute&quot;
+#import &lt;AVKit/AVPlayerLayerView.h&gt;
+#pragma clang diagnostic pop
</ins><span class="cx"> #import &lt;AVKit/AVPlayerViewController_Private.h&gt;
</span><span class="cx"> #import &lt;AVKit/AVPlayerViewController_WebKitOnly.h&gt;
</span><del>-#import &lt;AVKit/AVVideoLayer.h&gt;
</del><span class="cx"> 
</span><span class="cx"> #else
</span><span class="cx"> 
</span><span class="lines">@@ -58,19 +61,19 @@
</span><span class="cx"> @property (NS_NONATOMIC_IOSONLY, readonly) AVPlayerControllerStatus status;
</span><span class="cx"> @end
</span><span class="cx"> 
</span><del>-@protocol AVVideoLayer
-typedef NS_ENUM(NSInteger, AVVideoLayerGravity) {
-    AVVideoLayerGravityInvalid = 0,
-    AVVideoLayerGravityResizeAspect = 1,
-    AVVideoLayerGravityResizeAspectFill = 2,
-    AVVideoLayerGravityResize = 3,
-};
-- (void)setPlayerController:(AVPlayerController *)playerController;
-@property (nonatomic) AVVideoLayerGravity videoLayerGravity;
-@property (nonatomic) CGRect videoRect;
-@property (nonatomic, readonly, getter=isReadyForDisplay) BOOL readyForDisplay;
</del><ins>+@class AVPlayerLayer;
+
+@interface AVPictureInPicturePlayerLayerView : UIView
+@property (nonatomic, readonly) AVPlayerLayer *playerLayer;
</ins><span class="cx"> @end
</span><span class="cx"> 
</span><ins>+@interface AVPlayerLayerView : UIView
+@property (nonatomic, readonly) AVPlayerLayer *playerLayer;
+@property (nonatomic, readonly) AVPictureInPicturePlayerLayerView *pictureInPicturePlayerLayerView;
+- (void)startRoutingVideoToPictureInPicturePlayerLayerView;
+- (void)stopRoutingVideoToPictureInPicturePlayerLayerView;
+@end
+
</ins><span class="cx"> @protocol AVPlayerViewControllerDelegate &lt;NSObject&gt;
</span><span class="cx"> @optional
</span><span class="cx"> typedef NS_ENUM(NSInteger, AVPlayerViewControllerExitFullScreenReason) {
</span><span class="lines">@@ -85,15 +88,15 @@
</span><span class="cx"> @end
</span><span class="cx"> 
</span><span class="cx"> @interface AVPlayerViewController (Details)
</span><del>-- (instancetype)initWithVideoLayer:(CALayer &lt;AVVideoLayer&gt; *)videoLayer;
</del><ins>+- (instancetype)initWithPlayerLayerView:(AVPlayerLayerView *)playerLayerView;
</ins><span class="cx"> - (void)enterFullScreenAnimated:(BOOL)animated completionHandler:(void (^)(BOOL success, NSError *))completionHandler;
</span><span class="cx"> - (void)exitFullScreenAnimated:(BOOL)animated completionHandler:(void (^)(BOOL success, NSError *))completionHandler;
</span><span class="cx"> 
</span><span class="cx"> - (BOOL)isPictureInPicturePossible;
</span><span class="cx"> - (void)startPictureInPicture;
</span><span class="cx"> - (void)stopPictureInPicture;
</span><del>-- (void)setAllowsPictureInPicturePlayback:(BOOL)allow;
</del><span class="cx"> 
</span><ins>+@property (nonatomic) BOOL allowsPictureInPicturePlayback;
</ins><span class="cx"> @property (nonatomic, strong) AVPlayerController *playerController;
</span><span class="cx"> @property (nonatomic, weak) id &lt;AVPlayerViewControllerDelegate&gt; delegate;
</span><span class="cx"> @end
</span></span></pre></div>
<a id="branchessafari6011branchSourceWebCoreplatformspicocoaQuartzCoreSPIh"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1-branch/Source/WebCore/platform/spi/cocoa/QuartzCoreSPI.h (187091 => 187092)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1-branch/Source/WebCore/platform/spi/cocoa/QuartzCoreSPI.h        2015-07-21 05:27:45 UTC (rev 187091)
+++ branches/safari-601.1-branch/Source/WebCore/platform/spi/cocoa/QuartzCoreSPI.h        2015-07-21 05:27:51 UTC (rev 187092)
</span><span class="lines">@@ -32,6 +32,7 @@
</span><span class="cx"> #include &lt;QuartzCore/CARenderServer.h&gt;
</span><span class="cx"> 
</span><span class="cx"> #ifdef __OBJC__
</span><ins>+#import &lt;QuartzCore/CALayerHost.h&gt;
</ins><span class="cx"> #import &lt;QuartzCore/CALayerPrivate.h&gt;
</span><span class="cx"> 
</span><span class="cx"> // FIXME: As a workaround for &lt;rdar://problem/18985152&gt;, we conditionally enclose the following
</span><span class="lines">@@ -134,6 +135,12 @@
</span><span class="cx"> + (void)addCommitHandler:(void(^)(void))block forPhase:(CATransactionPhase)phase;
</span><span class="cx"> @end
</span><span class="cx"> #endif
</span><ins>+
+@interface CALayerHost : CALayer
+@property uint32_t contextId;
+@property BOOL inheritsSecurity;
+@end
+
</ins><span class="cx"> #endif // __OBJC__
</span><span class="cx"> 
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="branchessafari6011branchSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1-branch/Source/WebKit2/ChangeLog (187091 => 187092)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1-branch/Source/WebKit2/ChangeLog        2015-07-21 05:27:45 UTC (rev 187091)
+++ branches/safari-601.1-branch/Source/WebKit2/ChangeLog        2015-07-21 05:27:51 UTC (rev 187092)
</span><span class="lines">@@ -1,5 +1,46 @@
</span><span class="cx"> 2015-07-20  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Merge r187044. rdar://problem/21661808
+
+    2015-07-20  Jeremy Jones  &lt;jeremyj@apple.com&gt;
+
+            Adopt AVPlayerLayerView
+            https://bugs.webkit.org/show_bug.cgi?id=146862
+
+            Reviewed by Simon Fraser.
+
+            The CALayerHost is replaced with WebLayerHostView to be compatible with UIView animations.
+            videoLayerFrame and videoLayerGravity no longer need to be stored because they are stored
+            where they are used in the interface. Some animation is improved in the conversion.
+
+            * UIProcess/ios/WebVideoFullscreenManagerProxy.h:
+            * UIProcess/ios/WebVideoFullscreenManagerProxy.mm:
+            (+[WebLayerHostView layerClass]): Add class WebLayerHostView.
+            (-[WebLayerHostView contextID]):
+            (-[WebLayerHostView setContextID:]):
+            (-[WebLayerHostView layerHost]):
+            (WebKit::WebVideoFullscreenManagerProxy::invalidate): layer -&gt; view
+            (WebKit::WebVideoFullscreenManagerProxy::setupFullscreenWithID):
+            Apply the hostingDeviceScaleFactor transform to -sublayerTransform instead of to
+            -transform. This more directly inverts the tranform WebProcess and allows -transform
+            to be used for animation in the UIProcess. This is important because UIView's actions
+            animate -transform, but not -sublayerTrasform.
+
+            (WebKit::WebVideoFullscreenManagerProxy::didCleanupFullscreen): layer -&gt; view
+            (WebKit::WebVideoFullscreenModelContext::setVideoLayerFrame): Deleted.
+            (WebKit::WebVideoFullscreenModelContext::videoLayerFrame): Deleted.
+            (WebKit::WebVideoFullscreenModelContext::setVideoLayerGravity): Deleted.
+            (WebKit::WebVideoFullscreenModelContext::videoLayerGravity): Deleted.
+            * WebProcess/ios/WebVideoFullscreenManager.mm:
+            (WebKit::WebVideoFullscreenManager::enterVideoFullscreenForVideoElement):
+            Set initial video layer frame to fix start point of animation.
+
+            (WebKit::WebVideoFullscreenManager::didSetupFullscreen):
+            dispatch_async allows the CATransaction to complete before continuing with the animation.
+            This prevents a flash during animation.
+
+2015-07-20  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
+
</ins><span class="cx">         Merge r187039. rdar://problem/21474317
</span><span class="cx"> 
</span><span class="cx">     2015-07-20  Tim Horton  &lt;timothy_horton@apple.com&gt;
</span></span></pre></div>
<a id="branchessafari6011branchSourceWebKit2UIProcessiosWebVideoFullscreenManagerProxyh"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1-branch/Source/WebKit2/UIProcess/ios/WebVideoFullscreenManagerProxy.h (187091 => 187092)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1-branch/Source/WebKit2/UIProcess/ios/WebVideoFullscreenManagerProxy.h        2015-07-21 05:27:45 UTC (rev 187091)
+++ branches/safari-601.1-branch/Source/WebKit2/UIProcess/ios/WebVideoFullscreenManagerProxy.h        2015-07-21 05:27:51 UTC (rev 187092)
</span><span class="lines">@@ -53,11 +53,9 @@
</span><span class="cx"> 
</span><span class="cx">     void invalidate() { m_manager = nullptr; }
</span><span class="cx"> 
</span><del>-    PlatformLayer* layerHost() const { return m_layerHost.get(); }
-    void setLayerHost(RetainPtr&lt;PlatformLayer&gt;&amp;&amp; layerHost) { m_layerHost = WTF::move(layerHost); }
</del><ins>+    UIView *layerHostView() const { return m_layerHostView.get(); }
+    void setLayerHostView(RetainPtr&lt;UIView&gt;&amp;&amp; layerHostView) { m_layerHostView = WTF::move(layerHostView); }
</ins><span class="cx"> 
</span><del>-    void setInitialVideoLayerFrame(WebCore::FloatRect frame) { m_videoLayerFrame = frame; }
-
</del><span class="cx"> private:
</span><span class="cx">     WebVideoFullscreenModelContext(WebVideoFullscreenManagerProxy&amp; manager, uint64_t contextId)
</span><span class="cx">         : m_manager(&amp;manager)
</span><span class="lines">@@ -78,9 +76,7 @@
</span><span class="cx">     virtual void endScanning() override;
</span><span class="cx">     virtual void requestExitFullscreen() override;
</span><span class="cx">     virtual void setVideoLayerFrame(WebCore::FloatRect) override;
</span><del>-    virtual WebCore::FloatRect videoLayerFrame() const override;
</del><span class="cx">     virtual void setVideoLayerGravity(VideoGravity) override;
</span><del>-    virtual VideoGravity videoLayerGravity() const override;
</del><span class="cx">     virtual void selectAudioMediaOption(uint64_t) override;
</span><span class="cx">     virtual void selectLegibleMediaOption(uint64_t) override;
</span><span class="cx">     virtual void fullscreenModeChanged(WebCore::HTMLMediaElementEnums::VideoFullscreenMode) override;
</span><span class="lines">@@ -94,9 +90,7 @@
</span><span class="cx"> 
</span><span class="cx">     WebVideoFullscreenManagerProxy* m_manager;
</span><span class="cx">     uint64_t m_contextId;
</span><del>-    RetainPtr&lt;PlatformLayer&gt; m_layerHost;
-    WebCore::FloatRect m_videoLayerFrame;
-    VideoGravity m_videoLayerGravity { VideoGravityResize };
</del><ins>+    RetainPtr&lt;UIView *&gt; m_layerHostView;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> class WebVideoFullscreenManagerProxy : public RefCounted&lt;WebVideoFullscreenManagerProxy&gt;, private IPC::MessageReceiver {
</span></span></pre></div>
<a id="branchessafari6011branchSourceWebKit2UIProcessiosWebVideoFullscreenManagerProxymm"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1-branch/Source/WebKit2/UIProcess/ios/WebVideoFullscreenManagerProxy.mm (187091 => 187092)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1-branch/Source/WebKit2/UIProcess/ios/WebVideoFullscreenManagerProxy.mm        2015-07-21 05:27:45 UTC (rev 187091)
+++ branches/safari-601.1-branch/Source/WebKit2/UIProcess/ios/WebVideoFullscreenManagerProxy.mm        2015-07-21 05:27:51 UTC (rev 187092)
</span><span class="lines">@@ -35,9 +35,34 @@
</span><span class="cx"> #import &quot;WebVideoFullscreenManagerMessages.h&quot;
</span><span class="cx"> #import &quot;WebVideoFullscreenManagerProxyMessages.h&quot;
</span><span class="cx"> #import &lt;QuartzCore/CoreAnimation.h&gt;
</span><ins>+#import &lt;WebCore/QuartzCoreSPI.h&gt;
</ins><span class="cx"> #import &lt;WebCore/TimeRanges.h&gt;
</span><span class="cx"> #import &lt;WebKitSystemInterface.h&gt;
</span><span class="cx"> 
</span><ins>+@interface WebLayerHostView : UIView
+@property (nonatomic, assign) uint32_t contextID;
+@end
+
+@implementation WebLayerHostView
+
++ (Class)layerClass {
+    return [CALayerHost class];
+}
+
+- (uint32_t)contextID {
+    return [[self layerHost] contextId];
+}
+
+- (void)setContextID:(uint32_t)contextID {
+    [[self layerHost] setContextId:contextID];
+}
+
+- (CALayerHost *)layerHost {
+    return (CALayerHost *)[self layer];
+}
+
+@end
+
</ins><span class="cx"> using namespace WebCore;
</span><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="lines">@@ -139,28 +164,16 @@
</span><span class="cx"> 
</span><span class="cx"> void WebVideoFullscreenModelContext::setVideoLayerFrame(WebCore::FloatRect frame)
</span><span class="cx"> {
</span><del>-    m_videoLayerFrame = frame;
</del><span class="cx">     if (m_manager)
</span><span class="cx">         m_manager-&gt;setVideoLayerFrame(m_contextId, frame);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-WebCore::FloatRect WebVideoFullscreenModelContext::videoLayerFrame() const
-{
-    return m_videoLayerFrame;
-}
-
</del><span class="cx"> void WebVideoFullscreenModelContext::setVideoLayerGravity(WebCore::WebVideoFullscreenModel::VideoGravity gravity)
</span><span class="cx"> {
</span><del>-    m_videoLayerGravity = gravity;
</del><span class="cx">     if (m_manager)
</span><span class="cx">         m_manager-&gt;setVideoLayerGravity(m_contextId, gravity);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-WebCore::WebVideoFullscreenModel::VideoGravity WebVideoFullscreenModelContext::videoLayerGravity() const
-{
-    return m_videoLayerGravity;
-}
-
</del><span class="cx"> void WebVideoFullscreenModelContext::selectAudioMediaOption(uint64_t optionId)
</span><span class="cx"> {
</span><span class="cx">     if (m_manager)
</span><span class="lines">@@ -240,8 +253,8 @@
</span><span class="cx">         std::tie(model, interface) = tuple;
</span><span class="cx"> 
</span><span class="cx">         interface-&gt;invalidate();
</span><del>-        [model-&gt;layerHost() removeFromSuperlayer];
-        model-&gt;setLayerHost(nullptr);
</del><ins>+        [model-&gt;layerHostView() removeFromSuperview];
+        model-&gt;setLayerHostView(nullptr);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     m_contextMap.clear();
</span><span class="lines">@@ -310,16 +323,17 @@
</span><span class="cx"> 
</span><span class="cx">     std::tie(model, interface) = ensureModelAndInterface(contextId);
</span><span class="cx"> 
</span><del>-    model-&gt;setInitialVideoLayerFrame(initialRect);
-    model-&gt;setLayerHost(WKMakeRenderLayer(videoLayerID));
</del><ins>+    RetainPtr&lt;WebLayerHostView&gt; view = adoptNS([[WebLayerHostView alloc] init]);
+    [view setContextID:videoLayerID];
+    model-&gt;setLayerHostView(view);
</ins><span class="cx">     if (hostingDeviceScaleFactor != 1) {
</span><span class="cx">         // Invert the scale transform added in the WebProcess to fix &lt;rdar://problem/18316542&gt;.
</span><span class="cx">         float inverseScale = 1 / hostingDeviceScaleFactor;
</span><del>-        [model-&gt;layerHost() setTransform:CATransform3DMakeScale(inverseScale, inverseScale, 1)];
</del><ins>+        [[model-&gt;layerHostView() layer] setSublayerTransform:CATransform3DMakeScale(inverseScale, inverseScale, 1)];
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     UIView *parentView = downcast&lt;RemoteLayerTreeDrawingAreaProxy&gt;(*m_page-&gt;drawingArea()).remoteLayerTreeHost().rootLayer();
</span><del>-    interface-&gt;setupFullscreen(*model-&gt;layerHost(), initialRect, parentView, videoFullscreenMode, allowsPictureInPicture);
</del><ins>+    interface-&gt;setupFullscreen(*model-&gt;layerHostView(), initialRect, parentView, videoFullscreenMode, allowsPictureInPicture);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebVideoFullscreenManagerProxy::resetMediaState(uint64_t contextId)
</span><span class="lines">@@ -502,8 +516,8 @@
</span><span class="cx">     auto&amp; model = ensureModel(contextId);
</span><span class="cx"> 
</span><span class="cx">     [CATransaction flush];
</span><del>-    [model.layerHost() removeFromSuperlayer];
-    model.setLayerHost(nullptr);
</del><ins>+    [model.layerHostView() removeFromSuperview];
+    model.setLayerHostView(nullptr);
</ins><span class="cx">     m_page-&gt;send(Messages::WebVideoFullscreenManager::DidCleanupFullscreen(contextId), m_page-&gt;pageID());
</span><span class="cx"> 
</span><span class="cx">     m_contextMap.remove(contextId);
</span></span></pre></div>
<a id="branchessafari6011branchSourceWebKit2WebProcessiosWebVideoFullscreenManagermm"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1-branch/Source/WebKit2/WebProcess/ios/WebVideoFullscreenManager.mm (187091 => 187092)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1-branch/Source/WebKit2/WebProcess/ios/WebVideoFullscreenManager.mm        2015-07-21 05:27:45 UTC (rev 187091)
+++ branches/safari-601.1-branch/Source/WebKit2/WebProcess/ios/WebVideoFullscreenManager.mm        2015-07-21 05:27:51 UTC (rev 187092)
</span><span class="lines">@@ -232,9 +232,13 @@
</span><span class="cx">     RefPtr&lt;WebVideoFullscreenInterfaceContext&gt; interface;
</span><span class="cx">     std::tie(model, interface) = ensureModelAndInterface(contextId);
</span><span class="cx"> 
</span><ins>+    FloatRect clientRect = clientRectForElement(&amp;videoElement);
+    FloatRect videoLayerFrame = FloatRect(0, 0, clientRect.width(), clientRect.height());
+    
</ins><span class="cx">     interface-&gt;setTargetIsFullscreen(true);
</span><span class="cx">     interface-&gt;setFullscreenMode(mode);
</span><span class="cx">     model-&gt;setVideoElement(&amp;videoElement);
</span><ins>+    model-&gt;setVideoLayerFrame(videoLayerFrame);
</ins><span class="cx"> 
</span><span class="cx">     if (interface-&gt;isAnimating())
</span><span class="cx">         return;
</span><span class="lines">@@ -428,7 +432,10 @@
</span><span class="cx"> 
</span><span class="cx">     [CATransaction commit];
</span><span class="cx"> 
</span><del>-    m_page-&gt;send(Messages::WebVideoFullscreenManagerProxy::EnterFullscreen(contextId), m_page-&gt;pageID());
</del><ins>+    RefPtr&lt;WebVideoFullscreenManager&gt; strongThis(this);
+    dispatch_async(dispatch_get_main_queue(), [strongThis, this, contextId] {
+        m_page-&gt;send(Messages::WebVideoFullscreenManagerProxy::EnterFullscreen(contextId), m_page-&gt;pageID());
+    });
</ins><span class="cx"> }
</span><span class="cx">     
</span><span class="cx"> void WebVideoFullscreenManager::didEnterFullscreen(uint64_t contextId)
</span></span></pre>
</div>
</div>

</body>
</html>