Title: [243337] trunk/Source/WebCore
Revision
243337
Author
[email protected]
Date
2019-03-21 15:36:08 -0700 (Thu, 21 Mar 2019)

Log Message

Hardening: Use WeakPtrs in PlaybackSessionInterface{Mac,AVKit}
https://bugs.webkit.org/show_bug.cgi?id=195935
<rdar://problem/49007015>

Reviewed by Eric Carlson.

The PlaybackSessionInterface{Mac,AVKit} implementations store their playback session model
and playback controls manager members as bare pointers, something we've been working
to eliminate.

This patch corrects this oversight.

No new tests since no changes in behavior.

* platform/cocoa/PlaybackSessionModel.h:
* platform/ios/PlaybackSessionInterfaceAVKit.h:
* platform/ios/PlaybackSessionInterfaceAVKit.mm:
(WebCore::PlaybackSessionInterfaceAVKit::PlaybackSessionInterfaceAVKit):
(WebCore::playbackSessionModel const): Moved to implementation since WEBCORE_EXPORT is not
supposed to be used with inline methods.
* platform/mac/PlaybackSessionInterfaceMac.h:
* platform/mac/PlaybackSessionInterfaceMac.mm:
(WebCore::PlaybackSessionInterfaceMac::PlaybackSessionInterfaceMac):
(WebCore::PlaybackSessionInterfaceMac::playbackSessionModel const):
(WebCore::PlaybackSessionInterfaceMac::beginScrubbing):
(WebCore::PlaybackSessionInterfaceMac::endScrubbing):
(WebCore::PlaybackSessionInterfaceMac::playBackControlsManager):
* platform/mac/VideoFullscreenInterfaceMac.mm:
(WebCore::VideoFullscreenInterfaceMac::~VideoFullscreenInterfaceMac):
* platform/mac/WebPlaybackControlsManager.mm:
(-[WebPlaybackControlsManager seekToTime:toleranceBefore:toleranceAfter:]):
(-[WebPlaybackControlsManager setCurrentAudioTouchBarMediaSelectionOption:]):
(-[WebPlaybackControlsManager setCurrentLegibleTouchBarMediaSelectionOption:]):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (243336 => 243337)


--- trunk/Source/WebCore/ChangeLog	2019-03-21 22:21:58 UTC (rev 243336)
+++ trunk/Source/WebCore/ChangeLog	2019-03-21 22:36:08 UTC (rev 243337)
@@ -1,3 +1,39 @@
+2019-03-21  Brent Fulgham  <[email protected]>
+
+        Hardening: Use WeakPtrs in PlaybackSessionInterface{Mac,AVKit}
+        https://bugs.webkit.org/show_bug.cgi?id=195935
+        <rdar://problem/49007015>
+
+        Reviewed by Eric Carlson.
+
+        The PlaybackSessionInterface{Mac,AVKit} implementations store their playback session model
+        and playback controls manager members as bare pointers, something we've been working
+        to eliminate.
+        
+        This patch corrects this oversight.
+
+        No new tests since no changes in behavior.
+
+        * platform/cocoa/PlaybackSessionModel.h:
+        * platform/ios/PlaybackSessionInterfaceAVKit.h:
+        * platform/ios/PlaybackSessionInterfaceAVKit.mm:
+        (WebCore::PlaybackSessionInterfaceAVKit::PlaybackSessionInterfaceAVKit):
+        (WebCore::playbackSessionModel const): Moved to implementation since WEBCORE_EXPORT is not
+        supposed to be used with inline methods.
+        * platform/mac/PlaybackSessionInterfaceMac.h:
+        * platform/mac/PlaybackSessionInterfaceMac.mm:
+        (WebCore::PlaybackSessionInterfaceMac::PlaybackSessionInterfaceMac):
+        (WebCore::PlaybackSessionInterfaceMac::playbackSessionModel const):
+        (WebCore::PlaybackSessionInterfaceMac::beginScrubbing):
+        (WebCore::PlaybackSessionInterfaceMac::endScrubbing):
+        (WebCore::PlaybackSessionInterfaceMac::playBackControlsManager):
+        * platform/mac/VideoFullscreenInterfaceMac.mm:
+        (WebCore::VideoFullscreenInterfaceMac::~VideoFullscreenInterfaceMac):
+        * platform/mac/WebPlaybackControlsManager.mm:
+        (-[WebPlaybackControlsManager seekToTime:toleranceBefore:toleranceAfter:]):
+        (-[WebPlaybackControlsManager setCurrentAudioTouchBarMediaSelectionOption:]):
+        (-[WebPlaybackControlsManager setCurrentLegibleTouchBarMediaSelectionOption:]):
+
 2019-03-21  Said Abou-Hallawa  <[email protected]>
 
         Remove the SVG tear off objects for SVGPoint, SVGPointList and SVGAnimatedPointList

Modified: trunk/Source/WebCore/platform/cocoa/PlaybackSessionModel.h (243336 => 243337)


--- trunk/Source/WebCore/platform/cocoa/PlaybackSessionModel.h	2019-03-21 22:21:58 UTC (rev 243336)
+++ trunk/Source/WebCore/platform/cocoa/PlaybackSessionModel.h	2019-03-21 22:36:08 UTC (rev 243337)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2016-2019 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -30,6 +30,7 @@
 #include <wtf/Forward.h>
 #include <wtf/Ref.h>
 #include <wtf/Vector.h>
+#include <wtf/WeakPtr.h>
 
 namespace WebCore {
 
@@ -37,7 +38,7 @@
 class PlaybackSessionModelClient;
 struct MediaSelectionOption;
 
-class PlaybackSessionModel {
+class PlaybackSessionModel : public CanMakeWeakPtr<PlaybackSessionModel> {
 public:
     virtual ~PlaybackSessionModel() { };
     virtual void addClient(PlaybackSessionModelClient&) = 0;

Modified: trunk/Source/WebCore/platform/ios/PlaybackSessionInterfaceAVKit.h (243336 => 243337)


--- trunk/Source/WebCore/platform/ios/PlaybackSessionInterfaceAVKit.h	2019-03-21 22:21:58 UTC (rev 243336)
+++ trunk/Source/WebCore/platform/ios/PlaybackSessionInterfaceAVKit.h	2019-03-21 22:36:08 UTC (rev 243337)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016-2018 Apple Inc. All rights reserved.
+ * Copyright (C) 2016-2019 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -62,7 +62,7 @@
         return adoptRef(*new PlaybackSessionInterfaceAVKit(model));
     }
     virtual ~PlaybackSessionInterfaceAVKit();
-    PlaybackSessionModel* playbackSessionModel() const { return m_playbackSessionModel; }
+    PlaybackSessionModel* playbackSessionModel() const;
 
     // PlaybackSessionModelClient
     WEBCORE_EXPORT void durationChanged(double) override;
@@ -86,7 +86,7 @@
     WEBCORE_EXPORT PlaybackSessionInterfaceAVKit(PlaybackSessionModel&);
 
     RetainPtr<WebAVPlayerController> m_playerController;
-    PlaybackSessionModel* m_playbackSessionModel { nullptr };
+    WeakPtr<PlaybackSessionModel> m_playbackSessionModel;
 };
 
 }

Modified: trunk/Source/WebCore/platform/ios/PlaybackSessionInterfaceAVKit.mm (243336 => 243337)


--- trunk/Source/WebCore/platform/ios/PlaybackSessionInterfaceAVKit.mm	2019-03-21 22:21:58 UTC (rev 243336)
+++ trunk/Source/WebCore/platform/ios/PlaybackSessionInterfaceAVKit.mm	2019-03-21 22:36:08 UTC (rev 243337)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014, 2015 Apple Inc. All rights reserved.
+ * Copyright (C) 2014-2019 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -51,7 +51,7 @@
 
 PlaybackSessionInterfaceAVKit::PlaybackSessionInterfaceAVKit(PlaybackSessionModel& model)
     : m_playerController(adoptNS([[WebAVPlayerController alloc] init]))
-    , m_playbackSessionModel(&model)
+    , m_playbackSessionModel(makeWeakPtr(model))
 {
     model.addClient(*this);
     [m_playerController setPlaybackSessionInterface:this];
@@ -77,6 +77,11 @@
     invalidate();
 }
 
+PlaybackSessionModel* playbackSessionModel() const
+{
+    return m_playbackSessionModel.get();
+}
+
 void PlaybackSessionInterfaceAVKit::durationChanged(double duration)
 {
     WebAVPlayerController* playerController = m_playerController.get();

Modified: trunk/Source/WebCore/platform/mac/PlaybackSessionInterfaceMac.h (243336 => 243337)


--- trunk/Source/WebCore/platform/mac/PlaybackSessionInterfaceMac.h	2019-03-21 22:21:58 UTC (rev 243336)
+++ trunk/Source/WebCore/platform/mac/PlaybackSessionInterfaceMac.h	2019-03-21 22:36:08 UTC (rev 243337)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2016-2019 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -32,6 +32,8 @@
 #include "PlaybackSessionModel.h"
 #include <wtf/RefCounted.h>
 #include <wtf/RetainPtr.h>
+#include <wtf/WeakObjCPtr.h>
+#include <wtf/WeakPtr.h>
 #include <wtf/text/WTFString.h>
 
 OBJC_CLASS WebPlaybackControlsManager;
@@ -74,9 +76,9 @@
 
 private:
     PlaybackSessionInterfaceMac(PlaybackSessionModel&);
-    PlaybackSessionModel* m_playbackSessionModel { nullptr };
+    WeakPtr<PlaybackSessionModel> m_playbackSessionModel;
 #if ENABLE(WEB_PLAYBACK_CONTROLS_MANAGER)
-    WebPlaybackControlsManager *m_playbackControlsManager  { nullptr };
+    WeakObjCPtr<WebPlaybackControlsManager> m_playbackControlsManager;
 
     void updatePlaybackControlsManagerTiming(double currentTime, double anchorTime, double playbackRate, bool isPlaying);
 #endif

Modified: trunk/Source/WebCore/platform/mac/PlaybackSessionInterfaceMac.mm (243336 => 243337)


--- trunk/Source/WebCore/platform/mac/PlaybackSessionInterfaceMac.mm	2019-03-21 22:21:58 UTC (rev 243336)
+++ trunk/Source/WebCore/platform/mac/PlaybackSessionInterfaceMac.mm	2019-03-21 22:36:08 UTC (rev 243337)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2016-2019 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -52,7 +52,7 @@
 }
 
 PlaybackSessionInterfaceMac::PlaybackSessionInterfaceMac(PlaybackSessionModel& model)
-    : m_playbackSessionModel(&model)
+    : m_playbackSessionModel(makeWeakPtr(model))
 {
 }
 
@@ -63,7 +63,7 @@
 
 PlaybackSessionModel* PlaybackSessionInterfaceMac::playbackSessionModel() const
 {
-    return m_playbackSessionModel;
+    return m_playbackSessionModel.get();
 }
 
 void PlaybackSessionInterfaceMac::durationChanged(double duration)
@@ -110,12 +110,14 @@
 #if ENABLE(WEB_PLAYBACK_CONTROLS_MANAGER)
     updatePlaybackControlsManagerTiming(m_playbackSessionModel ? m_playbackSessionModel->currentTime() : 0, [[NSProcessInfo processInfo] systemUptime], 0, false);
 #endif
-    playbackSessionModel()->beginScrubbing();
+    if (auto* model = playbackSessionModel())
+        model->beginScrubbing();
 }
 
 void PlaybackSessionInterfaceMac::endScrubbing()
 {
-    playbackSessionModel()->endScrubbing();
+    if (auto* model = playbackSessionModel())
+        model->endScrubbing();
 }
 
 #if ENABLE(WEB_PLAYBACK_CONTROLS_MANAGER)
@@ -214,7 +216,7 @@
 
 WebPlaybackControlsManager *PlaybackSessionInterfaceMac::playBackControlsManager()
 {
-    return m_playbackControlsManager;
+    return m_playbackControlsManager.getAutoreleased();
 }
 
 void PlaybackSessionInterfaceMac::setPlayBackControlsManager(WebPlaybackControlsManager *manager)

Modified: trunk/Source/WebCore/platform/mac/VideoFullscreenInterfaceMac.mm (243336 => 243337)


--- trunk/Source/WebCore/platform/mac/VideoFullscreenInterfaceMac.mm	2019-03-21 22:21:58 UTC (rev 243336)
+++ trunk/Source/WebCore/platform/mac/VideoFullscreenInterfaceMac.mm	2019-03-21 22:36:08 UTC (rev 243337)
@@ -366,8 +366,8 @@
 
 VideoFullscreenInterfaceMac::~VideoFullscreenInterfaceMac()
 {
-    if (m_playbackSessionInterface->playbackSessionModel())
-        m_playbackSessionInterface->playbackSessionModel()->removeClient(*this);
+    if (auto* model = m_playbackSessionInterface->playbackSessionModel())
+        model->removeClient(*this);
     if (m_videoFullscreenModel)
         m_videoFullscreenModel->removeClient(*this);
 }

Modified: trunk/Source/WebCore/platform/mac/WebPlaybackControlsManager.mm (243336 => 243337)


--- trunk/Source/WebCore/platform/mac/WebPlaybackControlsManager.mm	2019-03-21 22:21:58 UTC (rev 243336)
+++ trunk/Source/WebCore/platform/mac/WebPlaybackControlsManager.mm	2019-03-21 22:36:08 UTC (rev 243337)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2016-2019 Apple Inc. All rights reserved.
  * 
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -94,7 +94,8 @@
 {
     UNUSED_PARAM(toleranceBefore);
     UNUSED_PARAM(toleranceAfter);
-    _playbackSessionInterfaceMac->playbackSessionModel()->seekToTime(time);
+    if (auto* model = _playbackSessionInterfaceMac->playbackSessionModel())
+        model->seekToTime(time);
 }
 
 - (void)cancelThumbnailAndAudioAmplitudeSampleGeneration
@@ -193,7 +194,8 @@
     if (audioMediaSelectionOption && _audioTouchBarMediaSelectionOptions)
         index = [_audioTouchBarMediaSelectionOptions indexOfObject:audioMediaSelectionOption];
 
-    _playbackSessionInterfaceMac->playbackSessionModel()->selectAudioMediaOption(index != NSNotFound ? index : UINT64_MAX);
+    if (auto* model = _playbackSessionInterfaceMac->playbackSessionModel())
+        model->selectAudioMediaOption(index != NSNotFound ? index : UINT64_MAX);
 }
 
 - (NSArray<AVTouchBarMediaSelectionOption *> *)legibleTouchBarMediaSelectionOptions
@@ -223,7 +225,8 @@
     if (legibleMediaSelectionOption && _legibleTouchBarMediaSelectionOptions)
         index = [_legibleTouchBarMediaSelectionOptions indexOfObject:legibleMediaSelectionOption];
 
-    _playbackSessionInterfaceMac->playbackSessionModel()->selectLegibleMediaOption(index != NSNotFound ? index : UINT64_MAX);
+    if (auto* model = _playbackSessionInterfaceMac->playbackSessionModel())
+        model->selectLegibleMediaOption(index != NSNotFound ? index : UINT64_MAX);
 }
 
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to