<!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>[177479] branches/safari-600.1.4.13-branch/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/177479">177479</a></dd>
<dt>Author</dt> <dd>bshafiei@apple.com</dd>
<dt>Date</dt> <dd>2014-12-17 17:05:33 -0800 (Wed, 17 Dec 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Merged patch for <a href="http://trac.webkit.org/projects/webkit/changeset/177375">r177375</a>.  rdar://problem/19271256</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari6001413branchSourceWebCoreChangeLog">branches/safari-600.1.4.13-branch/Source/WebCore/ChangeLog</a></li>
<li><a href="#branchessafari6001413branchSourceWebCoreplatformiosWebVideoFullscreenInterfaceAVKith">branches/safari-600.1.4.13-branch/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.h</a></li>
<li><a href="#branchessafari6001413branchSourceWebCoreplatformiosWebVideoFullscreenInterfaceAVKitmm">branches/safari-600.1.4.13-branch/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari6001413branchSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-600.1.4.13-branch/Source/WebCore/ChangeLog (177478 => 177479)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.1.4.13-branch/Source/WebCore/ChangeLog        2014-12-18 00:33:49 UTC (rev 177478)
+++ branches/safari-600.1.4.13-branch/Source/WebCore/ChangeLog        2014-12-18 01:05:33 UTC (rev 177479)
</span><span class="lines">@@ -1,3 +1,43 @@
</span><ins>+2014-12-17  Babak Shafiei  &lt;bshafiei@apple.com&gt;
+
+        Merge patch for r177375.
+
+    2014-12-16  Jer Noble  &lt;jer.noble@apple.com&gt;
+
+            [iOS] Crash in WebKit::WebPageProxy::dispatchViewStateChange() tapping a link from another app while playing a video
+            https://bugs.webkit.org/show_bug.cgi?id=139550
+
+            Reviewed by Anders Carlsson.
+
+            The existing &quot;dispatch to WebThread, then release&quot; model is insufficient and still
+            can result in RefPtr race conditions between the main thread and the web thread.
+            Make WebVideoFullscreenInterfaceAVKit a thread-safe ref-counted class, which
+            eliminates the necessity of disptaching back to the web thread before releasing.
+
+            * platform/ios/WebVideoFullscreenInterfaceAVKit.h:
+            * platform/ios/WebVideoFullscreenInterfaceAVKit.mm:
+            (WebVideoFullscreenInterfaceAVKit::setDuration): Use a strongThis model.
+            (WebVideoFullscreenInterfaceAVKit::setCurrentTime): Ditto.
+            (WebVideoFullscreenInterfaceAVKit::setRate): Ditto.
+            (WebVideoFullscreenInterfaceAVKit::setVideoDimensions): Ditto.
+            (WebVideoFullscreenInterfaceAVKit::setSeekableRanges): Ditto.
+            (mediaSelectionOptions): Return a RetainPtr object.
+            (WebVideoFullscreenInterfaceAVKit::setAudioMediaSelectionOptions): Use a strongThis model.
+            (WebVideoFullscreenInterfaceAVKit::setLegibleMediaSelectionOptions): Ditto.
+            (WebVideoFullscreenInterfaceAVKit::setExternalPlayback): Ditto.
+            (WebVideoFullscreenInterfaceAVKit::setupFullscreen): Ditto.
+            (WebVideoFullscreenInterfaceAVKit::enterFullscreen): Ditto.
+            (WebVideoFullscreenInterfaceAVKit::exitFullscreen): Ditto.
+            (WebVideoFullscreenInterfaceAVKit::cleanupFullscreen): Ditto.
+            (WebVideoFullscreenInterfaceAVKit::setupFullscreenInternal): Added utility
+                function. Lets us use the implied this pointer rather than an explicit
+                strongThis.
+            (WebVideoFullscreenInterfaceAVKit::enterFullscreenOptimized): Ditto.
+            (WebVideoFullscreenInterfaceAVKit::enterFullscreenStandard): Ditto.
+            (WebVideoFullscreenInterfaceAVKit::exitFullscreenInternal): Ditto.
+            (WebVideoFullscreenInterfaceAVKit::cleanupFullscreenInternal): Ditto.
+            (WebVideoFullscreenInterfaceAVKit::requestHideAndExitFullscreen): Use a strongThis model.
+
</ins><span class="cx"> 2014-12-10  Babak Shafiei  &lt;bshafiei@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Merge r176803.
</span></span></pre></div>
<a id="branchessafari6001413branchSourceWebCoreplatformiosWebVideoFullscreenInterfaceAVKith"></a>
<div class="modfile"><h4>Modified: branches/safari-600.1.4.13-branch/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.h (177478 => 177479)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.1.4.13-branch/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.h        2014-12-18 00:33:49 UTC (rev 177478)
+++ branches/safari-600.1.4.13-branch/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.h        2014-12-18 01:05:33 UTC (rev 177479)
</span><span class="lines">@@ -35,6 +35,7 @@
</span><span class="cx"> #include &lt;WebCore/WebVideoFullscreenInterface.h&gt;
</span><span class="cx"> #include &lt;wtf/RefPtr.h&gt;
</span><span class="cx"> #include &lt;wtf/RetainPtr.h&gt;
</span><ins>+#include &lt;wtf/ThreadSafeRefCounted.h&gt;
</ins><span class="cx"> 
</span><span class="cx"> OBJC_CLASS WebAVPlayerController;
</span><span class="cx"> OBJC_CLASS AVPlayerViewController;
</span><span class="lines">@@ -58,8 +59,15 @@
</span><span class="cx">     
</span><span class="cx"> class WebVideoFullscreenInterfaceAVKit
</span><span class="cx">     : public WebVideoFullscreenInterface
</span><del>-    , public RefCounted&lt;WebVideoFullscreenInterfaceAVKit&gt; {
-        
</del><ins>+    , public ThreadSafeRefCounted&lt;WebVideoFullscreenInterfaceAVKit&gt; {
+
+protected:
+    void setupFullscreenInternal(PlatformLayer&amp;, IntRect initialRect, UIView *);
+    void enterFullscreenOptimized();
+    void enterFullscreenStandard();
+    void exitFullscreenInternal(IntRect finalRect);
+    void cleanupFullscreenInternal();
+
</ins><span class="cx">     RetainPtr&lt;WebAVPlayerController&gt; m_playerController;
</span><span class="cx">     RetainPtr&lt;AVPlayerViewController&gt; m_playerViewController;
</span><span class="cx">     RetainPtr&lt;CALayer&gt; m_videoLayer;
</span></span></pre></div>
<a id="branchessafari6001413branchSourceWebCoreplatformiosWebVideoFullscreenInterfaceAVKitmm"></a>
<div class="modfile"><h4>Modified: branches/safari-600.1.4.13-branch/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.mm (177478 => 177479)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.1.4.13-branch/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.mm        2014-12-18 00:33:49 UTC (rev 177478)
+++ branches/safari-600.1.4.13-branch/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.mm        2014-12-18 01:05:33 UTC (rev 177479)
</span><span class="lines">@@ -587,11 +587,11 @@
</span><span class="cx"> 
</span><span class="cx"> void WebVideoFullscreenInterfaceAVKit::setDuration(double duration)
</span><span class="cx"> {
</span><del>-    WebAVPlayerController* playerController = this-&gt;playerController();
</del><ins>+    RefPtr&lt;WebVideoFullscreenInterfaceAVKit&gt; strongThis(this);
</ins><span class="cx">     
</span><del>-    __block RefPtr&lt;WebVideoFullscreenInterfaceAVKit&gt; protect(this);
-    
-    dispatch_async(dispatch_get_main_queue(), ^{
</del><ins>+    dispatch_async(dispatch_get_main_queue(), [strongThis, duration] {
+        WebAVPlayerController* playerController = strongThis-&gt;playerController();
+
</ins><span class="cx">         // FIXME: https://bugs.webkit.org/show_bug.cgi?id=127017 use correct values instead of duration for all these
</span><span class="cx">         playerController.contentDuration = duration;
</span><span class="cx">         playerController.maxTime = duration;
</span><span class="lines">@@ -606,59 +606,43 @@
</span><span class="cx">         playerController.canSeek = YES;
</span><span class="cx">         playerController.minTime = 0;
</span><span class="cx">         playerController.status = AVPlayerControllerStatusReadyToPlay;
</span><del>-        
-        WebThreadRun(^{
-            protect = nullptr;
-        });
</del><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebVideoFullscreenInterfaceAVKit::setCurrentTime(double currentTime, double anchorTime)
</span><span class="cx"> {
</span><del>-    __block RefPtr&lt;WebVideoFullscreenInterfaceAVKit&gt; protect(this);
</del><ins>+    RefPtr&lt;WebVideoFullscreenInterfaceAVKit&gt; strongThis(this);
</ins><span class="cx">     
</span><del>-    dispatch_async(dispatch_get_main_queue(), ^{
-        NSTimeInterval anchorTimeStamp = ![playerController() rate] ? NAN : anchorTime;
</del><ins>+    dispatch_async(dispatch_get_main_queue(), [strongThis, currentTime, anchorTime] {
+        NSTimeInterval anchorTimeStamp = ![strongThis-&gt;playerController() rate] ? NAN : anchorTime;
</ins><span class="cx">         AVValueTiming *timing = [getAVValueTimingClass() valueTimingWithAnchorValue:currentTime
</span><span class="cx">             anchorTimeStamp:anchorTimeStamp rate:0];
</span><del>-        playerController().timing = timing;
-        
-        WebThreadRun(^{
-            protect = nullptr;
-        });
</del><ins>+        strongThis-&gt;playerController().timing = timing;
</ins><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebVideoFullscreenInterfaceAVKit::setRate(bool isPlaying, float playbackRate)
</span><span class="cx"> {
</span><del>-    __block RefPtr&lt;WebVideoFullscreenInterfaceAVKit&gt; protect(this);
</del><ins>+    RefPtr&lt;WebVideoFullscreenInterfaceAVKit&gt; strongThis(this);
</ins><span class="cx">     
</span><del>-    dispatch_async(dispatch_get_main_queue(), ^{
-        playerController().rate = isPlaying ? playbackRate : 0.;
-        
-        WebThreadRun(^{
-            protect = nullptr;
-        });
</del><ins>+    dispatch_async(dispatch_get_main_queue(), [strongThis, isPlaying, playbackRate] {
+        strongThis-&gt;playerController().rate = isPlaying ? playbackRate : 0.;
</ins><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebVideoFullscreenInterfaceAVKit::setVideoDimensions(bool hasVideo, float width, float height)
</span><span class="cx"> {
</span><del>-    __block RefPtr&lt;WebVideoFullscreenInterfaceAVKit&gt; protect(this);
</del><ins>+    RefPtr&lt;WebVideoFullscreenInterfaceAVKit&gt; strongThis(this);
</ins><span class="cx">     
</span><del>-    dispatch_async(dispatch_get_main_queue(), ^{
-        playerController().hasEnabledVideo = hasVideo;
-        playerController().contentDimensions = CGSizeMake(width, height);
-        
-        WebThreadRun(^{
-            protect = nullptr;
-        });
</del><ins>+    dispatch_async(dispatch_get_main_queue(), [strongThis, hasVideo, width, height] {
+        strongThis-&gt;playerController().hasEnabledVideo = hasVideo;
+        strongThis-&gt;playerController().contentDimensions = CGSizeMake(width, height);
</ins><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebVideoFullscreenInterfaceAVKit::setSeekableRanges(const TimeRanges&amp; timeRanges)
</span><span class="cx"> {
</span><del>-    NSMutableArray* seekableRanges = [NSMutableArray array];
</del><ins>+    RetainPtr&lt;NSMutableArray&gt; seekableRanges = adoptNS([[NSMutableArray alloc] init]);
</ins><span class="cx">     ExceptionCode exceptionCode;
</span><span class="cx"> 
</span><span class="cx">     for (unsigned i = 0; i &lt; timeRanges.length(); i++) {
</span><span class="lines">@@ -669,14 +653,10 @@
</span><span class="cx">         [seekableRanges addObject:[NSValue valueWithCMTimeRange:range]];
</span><span class="cx">     }
</span><span class="cx">     
</span><del>-    __block RefPtr&lt;WebVideoFullscreenInterfaceAVKit&gt; protect(this);
</del><ins>+    RefPtr&lt;WebVideoFullscreenInterfaceAVKit&gt; strongThis(this);
</ins><span class="cx">     
</span><del>-    dispatch_async(dispatch_get_main_queue(), ^{
-        playerController().seekableTimeRanges = seekableRanges;
-        
-        WebThreadRun(^{
-            protect = nullptr;
-        });
</del><ins>+    dispatch_async(dispatch_get_main_queue(), [strongThis, seekableRanges] {
+        strongThis-&gt;playerController().seekableTimeRanges = seekableRanges.get();
</ins><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -685,9 +665,9 @@
</span><span class="cx">     playerController().canScanBackward = canPlayFastReverse;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static NSMutableArray *mediaSelectionOptions(const Vector&lt;String&gt;&amp; options)
</del><ins>+static RetainPtr&lt;NSMutableArray&gt; mediaSelectionOptions(const Vector&lt;String&gt;&amp; options)
</ins><span class="cx"> {
</span><del>-    NSMutableArray *webOptions = [NSMutableArray arrayWithCapacity:options.size()];
</del><ins>+    RetainPtr&lt;NSMutableArray&gt; webOptions = adoptNS([[NSMutableArray alloc] initWithCapacity:options.size()]);
</ins><span class="cx">     for (auto&amp; name : options) {
</span><span class="cx">         RetainPtr&lt;WebAVMediaSelectionOption&gt; webOption = adoptNS([[WebAVMediaSelectionOption alloc] init]);
</span><span class="cx">         [webOption setLocalizedDisplayName:name];
</span><span class="lines">@@ -698,33 +678,25 @@
</span><span class="cx"> 
</span><span class="cx"> void WebVideoFullscreenInterfaceAVKit::setAudioMediaSelectionOptions(const Vector&lt;String&gt;&amp; options, uint64_t selectedIndex)
</span><span class="cx"> {
</span><del>-    NSMutableArray *webOptions = mediaSelectionOptions(options);
-    __block RefPtr&lt;WebVideoFullscreenInterfaceAVKit&gt; protect(this);
</del><ins>+    RetainPtr&lt;NSMutableArray&gt; webOptions = mediaSelectionOptions(options);
+    RefPtr&lt;WebVideoFullscreenInterfaceAVKit&gt; strongThis(this);
</ins><span class="cx">     
</span><del>-    dispatch_async(dispatch_get_main_queue(), ^{
-        playerController().audioMediaSelectionOptions = webOptions;
-        if (selectedIndex &lt; webOptions.count)
-            playerController().currentAudioMediaSelectionOption = webOptions[(size_t)selectedIndex];
-        
-        WebThreadRun(^{
-            protect = nullptr;
-        });
</del><ins>+    dispatch_async(dispatch_get_main_queue(), [webOptions, strongThis, selectedIndex] {
+        strongThis-&gt;playerController().audioMediaSelectionOptions = webOptions.get();
+        if (selectedIndex &lt; [webOptions count])
+            strongThis-&gt;playerController().currentAudioMediaSelectionOption = [webOptions objectAtIndex:selectedIndex];
</ins><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebVideoFullscreenInterfaceAVKit::setLegibleMediaSelectionOptions(const Vector&lt;String&gt;&amp; options, uint64_t selectedIndex)
</span><span class="cx"> {
</span><del>-    NSMutableArray *webOptions = mediaSelectionOptions(options);
-    __block RefPtr&lt;WebVideoFullscreenInterfaceAVKit&gt; protect(this);
-    
-    dispatch_async(dispatch_get_main_queue(), ^{
-        playerController().legibleMediaSelectionOptions = webOptions;
-        if (selectedIndex &lt; webOptions.count)
-            playerController().currentLegibleMediaSelectionOption = webOptions[(size_t)selectedIndex];
-        
-        WebThreadRun(^{
-            protect = nullptr;
-        });
</del><ins>+    RetainPtr&lt;NSMutableArray&gt; webOptions = mediaSelectionOptions(options);
+    RefPtr&lt;WebVideoFullscreenInterfaceAVKit&gt; strongThis(this);
+
+    dispatch_async(dispatch_get_main_queue(), [webOptions, strongThis, selectedIndex] {
+        strongThis-&gt;playerController().legibleMediaSelectionOptions = webOptions.get();
+        if (selectedIndex &lt; [webOptions count])
+            strongThis-&gt;playerController().currentLegibleMediaSelectionOption = [webOptions objectAtIndex:selectedIndex];
</ins><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -736,132 +708,139 @@
</span><span class="cx">     else if (targetType == TargetTypeTVOut)
</span><span class="cx">         externalPlaybackType = AVPlayerControllerExternalPlaybackTypeTVOut;
</span><span class="cx"> 
</span><del>-    __block RefPtr&lt;WebVideoFullscreenInterfaceAVKit&gt; protect(this);
-    
-    dispatch_async(dispatch_get_main_queue(), ^{
-        playerController().externalPlaybackAirPlayDeviceLocalizedName = localizedDeviceName;
-        playerController().externalPlaybackType = externalPlaybackType;
-        playerController().externalPlaybackActive = enabled;
-        [m_videoLayerContainer.get() setHidden:enabled];
-        
-        WebThreadRun(^{
-            protect = nullptr;
-        });
</del><ins>+    RefPtr&lt;WebVideoFullscreenInterfaceAVKit&gt; strongThis(this);
+
+    dispatch_async(dispatch_get_main_queue(), [strongThis, enabled, localizedDeviceName, externalPlaybackType] {
+        WebAVPlayerController* playerController = strongThis-&gt;playerController();
+        playerController.externalPlaybackAirPlayDeviceLocalizedName = localizedDeviceName;
+        playerController.externalPlaybackType = externalPlaybackType;
+        playerController.externalPlaybackActive = enabled;
+        [strongThis-&gt;m_videoLayerContainer.get() setHidden:enabled];
</ins><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebVideoFullscreenInterfaceAVKit::setupFullscreen(PlatformLayer&amp; videoLayer, WebCore::IntRect initialRect, UIView* parentView)
</span><span class="cx"> {
</span><del>-    __block RefPtr&lt;WebVideoFullscreenInterfaceAVKit&gt; protect(this);
-    
</del><ins>+    RefPtr&lt;WebVideoFullscreenInterfaceAVKit&gt; strongThis(this);
+
</ins><span class="cx">     m_videoLayer = &amp;videoLayer;
</span><del>-    
-    dispatch_async(dispatch_get_main_queue(), ^{
</del><span class="cx"> 
</span><del>-        [CATransaction begin];
-        [CATransaction setDisableActions:YES];
-        m_parentView = parentView;
</del><ins>+    dispatch_async(dispatch_get_main_queue(), [strongThis, &amp;videoLayer, initialRect, parentView] {
+        strongThis-&gt;setupFullscreenInternal(videoLayer, initialRect, parentView);
+    });
+}
</ins><span class="cx"> 
</span><del>-        if (!applicationIsAdSheet()) {
-            m_window = adoptNS([[getUIWindowClass() alloc] initWithFrame:[[getUIScreenClass() mainScreen] bounds]]);
-            [m_window setBackgroundColor:[getUIColorClass() clearColor]];
-            m_viewController = adoptNS([[getUIViewControllerClass() alloc] init]);
-            [[m_viewController view] setFrame:[m_window bounds]];
-            [m_window setRootViewController:m_viewController.get()];
-            [m_window makeKeyAndVisible];
-        }
-        
-        [m_videoLayer removeFromSuperlayer];
-        
-        m_videoLayerContainer = [WebAVVideoLayer videoLayer];
-        [m_videoLayerContainer setHidden:playerController().externalPlaybackActive];
-        [m_videoLayerContainer addSublayer:m_videoLayer.get()];
-        
-        CGSize videoSize = playerController().contentDimensions;
-        CGRect videoRect = CGRectMake(0, 0, videoSize.width, videoSize.height);
-        [m_videoLayerContainer setVideoRect:videoRect];
</del><ins>+void WebVideoFullscreenInterfaceAVKit::setupFullscreenInternal(PlatformLayer&amp; videoLayer, WebCore::IntRect initialRect, UIView* parentView)
+{
+    UNUSED_PARAM(videoLayer);
</ins><span class="cx"> 
</span><del>-        m_playerViewController = adoptNS([[getAVPlayerViewControllerClass() alloc] initWithVideoLayer:m_videoLayerContainer.get()]);
-        [m_playerViewController setShowsPlaybackControls:NO];
-        [m_playerViewController setPlayerController:(AVPlayerController *)playerController()];
-        [m_playerViewController setDelegate:playerController()];
-        [m_videoLayerContainer setPlayerViewController:m_playerViewController.get()];
</del><ins>+    [CATransaction begin];
+    [CATransaction setDisableActions:YES];
+    m_parentView = parentView;
</ins><span class="cx"> 
</span><del>-        if (m_viewController) {
-            [m_viewController addChildViewController:m_playerViewController.get()];
-            [[m_viewController view] addSubview:[m_playerViewController view]];
-            [m_playerViewController view].frame = [parentView convertRect:initialRect toView:nil];
-        } else {
-            [parentView addSubview:[m_playerViewController view]];
-            [m_playerViewController view].frame = initialRect;
-        }
</del><ins>+    if (!applicationIsAdSheet()) {
+        m_window = adoptNS([[getUIWindowClass() alloc] initWithFrame:[[getUIScreenClass() mainScreen] bounds]]);
+        [m_window setBackgroundColor:[getUIColorClass() clearColor]];
+        m_viewController = adoptNS([[getUIViewControllerClass() alloc] init]);
+        [[m_viewController view] setFrame:[m_window bounds]];
+        [m_window setRootViewController:m_viewController.get()];
+        [m_window makeKeyAndVisible];
+    }
</ins><span class="cx"> 
</span><del>-        [[m_playerViewController view] setBackgroundColor:[getUIColorClass() clearColor]];
-        [[m_playerViewController view] setNeedsLayout];
-        [[m_playerViewController view] layoutIfNeeded];
</del><ins>+    [m_videoLayer removeFromSuperlayer];
</ins><span class="cx"> 
</span><del>-        [CATransaction commit];
</del><ins>+    m_videoLayerContainer = [WebAVVideoLayer videoLayer];
+    [m_videoLayerContainer setHidden:playerController().externalPlaybackActive];
+    [m_videoLayerContainer addSublayer:m_videoLayer.get()];
</ins><span class="cx"> 
</span><del>-        dispatch_async(dispatch_get_main_queue(), ^{
-            WebThreadRun(^{
-                if (m_fullscreenChangeObserver)
-                    m_fullscreenChangeObserver-&gt;didSetupFullscreen();
</del><ins>+    CGSize videoSize = playerController().contentDimensions;
+    CGRect videoRect = CGRectMake(0, 0, videoSize.width, videoSize.height);
+    [m_videoLayerContainer setVideoRect:videoRect];
</ins><span class="cx"> 
</span><del>-                protect = nullptr;
-            });
-        });
</del><ins>+    m_playerViewController = adoptNS([[getAVPlayerViewControllerClass() alloc] initWithVideoLayer:m_videoLayerContainer.get()]);
+    [m_playerViewController setShowsPlaybackControls:NO];
+    [m_playerViewController setPlayerController:(AVPlayerController *)playerController()];
+    [m_playerViewController setDelegate:playerController()];
+    [m_videoLayerContainer setPlayerViewController:m_playerViewController.get()];
+
+    if (m_viewController) {
+        [m_viewController addChildViewController:m_playerViewController.get()];
+        [[m_viewController view] addSubview:[m_playerViewController view]];
+        [m_playerViewController view].frame = [parentView convertRect:initialRect toView:nil];
+    } else {
+        [parentView addSubview:[m_playerViewController view]];
+        [m_playerViewController view].frame = initialRect;
+    }
+
+    [[m_playerViewController view] setBackgroundColor:[getUIColorClass() clearColor]];
+    [[m_playerViewController view] setNeedsLayout];
+    [[m_playerViewController view] layoutIfNeeded];
+
+    [CATransaction commit];
+
+    RefPtr&lt;WebVideoFullscreenInterfaceAVKit&gt; strongThis(this);
+    WebThreadRun([strongThis] {
+        if (strongThis-&gt;m_fullscreenChangeObserver)
+            strongThis-&gt;m_fullscreenChangeObserver-&gt;didSetupFullscreen();
</ins><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebVideoFullscreenInterfaceAVKit::enterFullscreen()
</span><span class="cx"> {
</span><del>-    __block RefPtr&lt;WebVideoFullscreenInterfaceAVKit&gt; protect(this);
-    
-    dispatch_async(dispatch_get_main_queue(), ^{
-        [m_videoLayerContainer setBackgroundColor:[[getUIColorClass() blackColor] CGColor]];
-        [m_playerViewController enterFullScreenWithCompletionHandler:^(BOOL, NSError*)
-        {
-            [m_playerViewController setShowsPlaybackControls:YES];
</del><ins>+    RefPtr&lt;WebVideoFullscreenInterfaceAVKit&gt; strongThis(this);
+    dispatch_async(dispatch_get_main_queue(), [strongThis] {
+        [strongThis-&gt;m_videoLayerContainer setBackgroundColor:[[getUIColorClass() blackColor] CGColor]];
+        strongThis-&gt;enterFullscreenStandard();
+    });
+}
</ins><span class="cx"> 
</span><del>-            WebThreadRun(^{
-                if (m_fullscreenChangeObserver)
-                    m_fullscreenChangeObserver-&gt;didEnterFullscreen();
</del><ins>+void WebVideoFullscreenInterfaceAVKit::enterFullscreenStandard()
+{
+    RefPtr&lt;WebVideoFullscreenInterfaceAVKit&gt; strongThis(this);
+    [m_playerViewController enterFullScreenWithCompletionHandler:[this, strongThis] (BOOL, NSError*) {
+        [m_playerViewController setShowsPlaybackControls:YES];
</ins><span class="cx"> 
</span><del>-                protect = nullptr;
-            });
-        }];
-    });
</del><ins>+        WebThreadRun([this, strongThis] {
+            if (m_fullscreenChangeObserver)
+                m_fullscreenChangeObserver-&gt;didEnterFullscreen();
+        });
+    }];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebVideoFullscreenInterfaceAVKit::exitFullscreen(WebCore::IntRect finalRect)
</span><span class="cx"> {
</span><del>-    __block RefPtr&lt;WebVideoFullscreenInterfaceAVKit&gt; protect(this);
-    
</del><ins>+    RefPtr&lt;WebVideoFullscreenInterfaceAVKit&gt; strongThis(this);
+
</ins><span class="cx">     m_playerController = nil;
</span><del>-    
-    dispatch_async(dispatch_get_main_queue(), ^{
-        [m_playerViewController setShowsPlaybackControls:NO];
-        if (m_viewController)
-            [m_playerViewController view].frame = [m_parentView convertRect:finalRect toView:nil];
-        else
-            [m_playerViewController view].frame = finalRect;
</del><span class="cx"> 
</span><del>-        if ([m_videoLayerContainer videoLayerGravity] != AVVideoLayerGravityResizeAspect)
-            [m_videoLayerContainer setVideoLayerGravity:AVVideoLayerGravityResizeAspect];
-        [[m_playerViewController view] layoutIfNeeded];
-        [m_playerViewController exitFullScreenWithCompletionHandler:^(BOOL, NSError*) {
-            [m_videoLayerContainer setBackgroundColor:[[getUIColorClass() clearColor] CGColor]];
-            [[m_playerViewController view] setBackgroundColor:[getUIColorClass() clearColor]];
-
-            WebThreadRun(^{
-                if (m_fullscreenChangeObserver)
-                    m_fullscreenChangeObserver-&gt;didExitFullscreen();
-                protect = nullptr;
-            });
-        }];
</del><ins>+    dispatch_async(dispatch_get_main_queue(), [strongThis, finalRect] {
+        strongThis-&gt;exitFullscreenInternal(finalRect);
</ins><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebVideoFullscreenInterfaceAVKit::exitFullscreenInternal(WebCore::IntRect finalRect)
+{
+    [m_playerViewController setShowsPlaybackControls:NO];
+    if (m_viewController)
+        [m_playerViewController view].frame = [m_parentView convertRect:finalRect toView:nil];
+    else
+        [m_playerViewController view].frame = finalRect;
+
+    if ([m_videoLayerContainer videoLayerGravity] != AVVideoLayerGravityResizeAspect)
+        [m_videoLayerContainer setVideoLayerGravity:AVVideoLayerGravityResizeAspect];
+    [[m_playerViewController view] layoutIfNeeded];
+
+    RefPtr&lt;WebVideoFullscreenInterfaceAVKit&gt; strongThis(this);
+    [m_playerViewController exitFullScreenWithCompletionHandler:[strongThis] (BOOL, NSError*) {
+        [strongThis-&gt;m_videoLayerContainer setBackgroundColor:[[getUIColorClass() clearColor] CGColor]];
+        [[strongThis-&gt;m_playerViewController view] setBackgroundColor:[getUIColorClass() clearColor]];
+        WebThreadRun([strongThis] {
+            if (strongThis-&gt;m_fullscreenChangeObserver)
+                strongThis-&gt;m_fullscreenChangeObserver-&gt;didExitFullscreen();
+        });
+    }];
+}
+
</ins><span class="cx"> @interface UIApplication ()
</span><span class="cx"> -(void)_setStatusBarOrientation:(UIInterfaceOrientation)o;
</span><span class="cx"> @end
</span><span class="lines">@@ -872,39 +851,43 @@
</span><span class="cx"> 
</span><span class="cx"> void WebVideoFullscreenInterfaceAVKit::cleanupFullscreen()
</span><span class="cx"> {
</span><del>-    // Retain this to extend object life until async block completes.
-    __block RefPtr&lt;WebVideoFullscreenInterfaceAVKit&gt; protect(this);
</del><ins>+    RefPtr&lt;WebVideoFullscreenInterfaceAVKit&gt; strongThis(this);
</ins><span class="cx">     
</span><del>-    dispatch_async(dispatch_get_main_queue(), ^{
-        if (m_window) {
-            [m_window setHidden:YES];
-            [m_window setRootViewController:nil];
-            [[getUIApplicationClass() sharedApplication] _setStatusBarOrientation:[[m_parentView window] interfaceOrientation]];
-        }
-        [m_playerViewController setDelegate:nil];
-        [[m_playerViewController view] removeFromSuperview];
-        if (m_viewController)
-            [m_playerViewController removeFromParentViewController];
-        [m_playerViewController setPlayerController:nil];
-        m_playerViewController = nil;
-        [m_videoLayer removeFromSuperlayer];
-        m_videoLayer = nil;
-        [m_videoLayerContainer removeFromSuperlayer];
-        [m_videoLayerContainer setPlayerViewController:nil];
-        m_videoLayerContainer = nil;
-        [[m_viewController view] removeFromSuperview];
-        m_viewController = nil;
-        m_window = nil;
-        m_parentView = nil;
-        
-        WebThreadRun(^{
-            if (m_fullscreenChangeObserver)
-                m_fullscreenChangeObserver-&gt;didCleanupFullscreen();
-            protect = nullptr;
-        });
</del><ins>+    dispatch_async(dispatch_get_main_queue(), [strongThis] {
+        strongThis-&gt;cleanupFullscreenInternal();
</ins><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebVideoFullscreenInterfaceAVKit::cleanupFullscreenInternal()
+{
+    if (m_window) {
+        [m_window setHidden:YES];
+        [m_window setRootViewController:nil];
+        [[getUIApplicationClass() sharedApplication] _setStatusBarOrientation:[[m_parentView window] interfaceOrientation]];
+    }
+    [m_playerViewController setDelegate:nil];
+    [[m_playerViewController view] removeFromSuperview];
+    if (m_viewController)
+        [m_playerViewController removeFromParentViewController];
+    [m_playerViewController setPlayerController:nil];
+    m_playerViewController = nil;
+    [m_videoLayer removeFromSuperlayer];
+    m_videoLayer = nil;
+    [m_videoLayerContainer removeFromSuperlayer];
+    [m_videoLayerContainer setPlayerViewController:nil];
+    m_videoLayerContainer = nil;
+    [[m_viewController view] removeFromSuperview];
+    m_viewController = nil;
+    m_window = nil;
+    m_parentView = nil;
+    
+    RefPtr&lt;WebVideoFullscreenInterfaceAVKit&gt; strongThis(this);
+    WebThreadRun([strongThis] {
+        if (strongThis-&gt;m_fullscreenChangeObserver)
+            strongThis-&gt;m_fullscreenChangeObserver-&gt;didCleanupFullscreen();
+    });
+}
+
</ins><span class="cx"> void WebVideoFullscreenInterfaceAVKit::invalidate()
</span><span class="cx"> {
</span><span class="cx">     [m_window setHidden:YES];
</span><span class="lines">@@ -930,14 +913,10 @@
</span><span class="cx"> 
</span><span class="cx"> void WebVideoFullscreenInterfaceAVKit::requestHideAndExitFullscreen()
</span><span class="cx"> {
</span><del>-    __block RefPtr&lt;WebVideoFullscreenInterfaceAVKit&gt; protect(this);
-
-    dispatch_async(dispatch_get_main_queue(), ^{
-        [m_window setHidden:YES];
-        [m_playerViewController exitFullScreenAnimated:NO completionHandler:^(BOOL, NSError*) {
-            WebThreadRun(^{
-                protect = nullptr;
-            });
</del><ins>+    RefPtr&lt;WebVideoFullscreenInterfaceAVKit&gt; strongThis(this);
+    dispatch_async(dispatch_get_main_queue(), [strongThis] {
+        [strongThis-&gt;m_window setHidden:YES];
+        [strongThis-&gt;m_playerViewController exitFullScreenAnimated:NO completionHandler:[strongThis] (BOOL, NSError*) {
</ins><span class="cx">         }];
</span><span class="cx">     });
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>