Title: [243579] branches/safari-607-branch/Source/WebCore
Revision
243579
Author
[email protected]
Date
2019-03-27 16:43:57 -0700 (Wed, 27 Mar 2019)

Log Message

Cherry-pick r243298. rdar://problem/49308011

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

    Reviewed by Eric Carlson.

    The VideoFullscreenInterface{Mac,AVKit} implementations store their fullscreen model
    and fullscreen change observer 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/VideoFullscreenChangeObserver.h:
    * platform/cocoa/VideoFullscreenModel.h:
    * platform/ios/VideoFullscreenInterfaceAVKit.h:
    * platform/ios/VideoFullscreenInterfaceAVKit.mm:
    (VideoFullscreenInterfaceAVKit::setVideoFullscreenModel):
    (VideoFullscreenInterfaceAVKit::setVideoFullscreenChangeObserver):
    (VideoFullscreenInterfaceAVKit::presentingViewController):
    (VideoFullscreenInterfaceAVKit::invalidate):
    (VideoFullscreenInterfaceAVKit::preparedToExitFullscreen):
    (VideoFullscreenInterfaceAVKit::shouldExitFullscreenWithReason):
    (VideoFullscreenInterfaceAVKit::doSetup):
    * platform/mac/VideoFullscreenInterfaceMac.h:
    (WebCore::VideoFullscreenInterfaceMac::videoFullscreenModel const):
    (WebCore::VideoFullscreenInterfaceMac::videoFullscreenChangeObserver const):
    * platform/mac/VideoFullscreenInterfaceMac.mm:
    (WebCore::VideoFullscreenInterfaceMac::setVideoFullscreenModel):
    (WebCore::VideoFullscreenInterfaceMac::setVideoFullscreenChangeObserver):
    (WebCore::VideoFullscreenInterfaceMac::enterFullscreen):
    (WebCore::VideoFullscreenInterfaceMac::invalidate):

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@243298 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Diff

Modified: branches/safari-607-branch/Source/WebCore/ChangeLog (243578 => 243579)


--- branches/safari-607-branch/Source/WebCore/ChangeLog	2019-03-27 23:43:54 UTC (rev 243578)
+++ branches/safari-607-branch/Source/WebCore/ChangeLog	2019-03-27 23:43:57 UTC (rev 243579)
@@ -1,5 +1,81 @@
 2019-03-27  Alan Coon  <[email protected]>
 
+        Cherry-pick r243298. rdar://problem/49308011
+
+    Hardening: Use WeakPtrs in VideoFullscreenInterface{Mac,AVKit}
+    https://bugs.webkit.org/show_bug.cgi?id=196052
+    <rdar://problem/48778571>
+    
+    Reviewed by Eric Carlson.
+    
+    The VideoFullscreenInterface{Mac,AVKit} implementations store their fullscreen model
+    and fullscreen change observer 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/VideoFullscreenChangeObserver.h:
+    * platform/cocoa/VideoFullscreenModel.h:
+    * platform/ios/VideoFullscreenInterfaceAVKit.h:
+    * platform/ios/VideoFullscreenInterfaceAVKit.mm:
+    (VideoFullscreenInterfaceAVKit::setVideoFullscreenModel):
+    (VideoFullscreenInterfaceAVKit::setVideoFullscreenChangeObserver):
+    (VideoFullscreenInterfaceAVKit::presentingViewController):
+    (VideoFullscreenInterfaceAVKit::invalidate):
+    (VideoFullscreenInterfaceAVKit::preparedToExitFullscreen):
+    (VideoFullscreenInterfaceAVKit::shouldExitFullscreenWithReason):
+    (VideoFullscreenInterfaceAVKit::doSetup):
+    * platform/mac/VideoFullscreenInterfaceMac.h:
+    (WebCore::VideoFullscreenInterfaceMac::videoFullscreenModel const):
+    (WebCore::VideoFullscreenInterfaceMac::videoFullscreenChangeObserver const):
+    * platform/mac/VideoFullscreenInterfaceMac.mm:
+    (WebCore::VideoFullscreenInterfaceMac::setVideoFullscreenModel):
+    (WebCore::VideoFullscreenInterfaceMac::setVideoFullscreenChangeObserver):
+    (WebCore::VideoFullscreenInterfaceMac::enterFullscreen):
+    (WebCore::VideoFullscreenInterfaceMac::invalidate):
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@243298 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2019-03-21  Brent Fulgham  <[email protected]>
+
+            Hardening: Use WeakPtrs in VideoFullscreenInterface{Mac,AVKit}
+            https://bugs.webkit.org/show_bug.cgi?id=196052
+            <rdar://problem/48778571>
+
+            Reviewed by Eric Carlson.
+
+            The VideoFullscreenInterface{Mac,AVKit} implementations store their fullscreen model
+            and fullscreen change observer 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/VideoFullscreenChangeObserver.h:
+            * platform/cocoa/VideoFullscreenModel.h:
+            * platform/ios/VideoFullscreenInterfaceAVKit.h:
+            * platform/ios/VideoFullscreenInterfaceAVKit.mm:
+            (VideoFullscreenInterfaceAVKit::setVideoFullscreenModel):
+            (VideoFullscreenInterfaceAVKit::setVideoFullscreenChangeObserver):
+            (VideoFullscreenInterfaceAVKit::presentingViewController):
+            (VideoFullscreenInterfaceAVKit::invalidate):
+            (VideoFullscreenInterfaceAVKit::preparedToExitFullscreen):
+            (VideoFullscreenInterfaceAVKit::shouldExitFullscreenWithReason):
+            (VideoFullscreenInterfaceAVKit::doSetup):
+            * platform/mac/VideoFullscreenInterfaceMac.h:
+            (WebCore::VideoFullscreenInterfaceMac::videoFullscreenModel const):
+            (WebCore::VideoFullscreenInterfaceMac::videoFullscreenChangeObserver const):
+            * platform/mac/VideoFullscreenInterfaceMac.mm:
+            (WebCore::VideoFullscreenInterfaceMac::setVideoFullscreenModel):
+            (WebCore::VideoFullscreenInterfaceMac::setVideoFullscreenChangeObserver):
+            (WebCore::VideoFullscreenInterfaceMac::enterFullscreen):
+            (WebCore::VideoFullscreenInterfaceMac::invalidate):
+
+2019-03-27  Alan Coon  <[email protected]>
+
         Cherry-pick r242946. rdar://problem/49308005
 
     Certain videos are causing a crash when used as WebGL texture

Modified: branches/safari-607-branch/Source/WebCore/platform/cocoa/VideoFullscreenChangeObserver.h (243578 => 243579)


--- branches/safari-607-branch/Source/WebCore/platform/cocoa/VideoFullscreenChangeObserver.h	2019-03-27 23:43:54 UTC (rev 243578)
+++ branches/safari-607-branch/Source/WebCore/platform/cocoa/VideoFullscreenChangeObserver.h	2019-03-27 23:43:57 UTC (rev 243579)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016 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,7 +30,7 @@
 
 namespace WebCore {
 
-class VideoFullscreenChangeObserver {
+class VideoFullscreenChangeObserver : public CanMakeWeakPtr<VideoFullscreenChangeObserver> {
 public:
     virtual ~VideoFullscreenChangeObserver() { };
     virtual void requestUpdateInlineRect() = 0;

Modified: branches/safari-607-branch/Source/WebCore/platform/cocoa/VideoFullscreenModel.h (243578 => 243579)


--- branches/safari-607-branch/Source/WebCore/platform/cocoa/VideoFullscreenModel.h	2019-03-27 23:43:54 UTC (rev 243578)
+++ branches/safari-607-branch/Source/WebCore/platform/cocoa/VideoFullscreenModel.h	2019-03-27 23:43:57 UTC (rev 243579)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014 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
@@ -44,7 +44,7 @@
 
 class VideoFullscreenModelClient;
 
-class VideoFullscreenModel {
+class VideoFullscreenModel : public CanMakeWeakPtr<VideoFullscreenModel> {
 public:
     virtual ~VideoFullscreenModel() { };
     virtual void addClient(VideoFullscreenModelClient&) = 0;

Modified: branches/safari-607-branch/Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.h (243578 => 243579)


--- branches/safari-607-branch/Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.h	2019-03-27 23:43:54 UTC (rev 243578)
+++ branches/safari-607-branch/Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.h	2019-03-27 23:43:57 UTC (rev 243579)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014-2018 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
@@ -127,7 +127,7 @@
     Mode m_currentMode;
     Mode m_targetMode;
 
-    VideoFullscreenModel* videoFullscreenModel() const { return m_videoFullscreenModel; }
+    VideoFullscreenModel* videoFullscreenModel() const { return m_videoFullscreenModel.get(); }
     bool shouldExitFullscreenWithReason(ExitFullScreenReason);
     HTMLMediaElementEnums::VideoFullscreenMode mode() const { return m_currentMode.mode(); }
     bool allowsPictureInPicturePlayback() const { return m_allowsPictureInPicturePlayback; }
@@ -171,8 +171,8 @@
     Ref<PlaybackSessionInterfaceAVKit> m_playbackSessionInterface;
     RetainPtr<WebAVPlayerViewControllerDelegate> m_playerViewControllerDelegate;
     RetainPtr<WebAVPlayerViewController> m_playerViewController;
-    VideoFullscreenModel* m_videoFullscreenModel { nullptr };
-    VideoFullscreenChangeObserver* m_fullscreenChangeObserver { nullptr };
+    WeakPtr<VideoFullscreenModel> m_videoFullscreenModel;
+    WeakPtr<VideoFullscreenChangeObserver> m_fullscreenChangeObserver;
 
     // These are only used when fullscreen is presented in a separate window.
     RetainPtr<UIWindow> m_window;

Modified: branches/safari-607-branch/Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.mm (243578 => 243579)


--- branches/safari-607-branch/Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.mm	2019-03-27 23:43:54 UTC (rev 243578)
+++ branches/safari-607-branch/Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.mm	2019-03-27 23:43:57 UTC (rev 243579)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014-2018 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
@@ -771,7 +771,7 @@
     if (m_videoFullscreenModel)
         m_videoFullscreenModel->removeClient(*this);
 
-    m_videoFullscreenModel = model;
+    m_videoFullscreenModel = makeWeakPtr(model);
 
     if (m_videoFullscreenModel) {
         m_videoFullscreenModel->addClient(*this);
@@ -790,7 +790,7 @@
 
 void VideoFullscreenInterfaceAVKit::setVideoFullscreenChangeObserver(VideoFullscreenChangeObserver* observer)
 {
-    m_fullscreenChangeObserver = observer;
+    m_fullscreenChangeObserver = makeWeakPtr(observer);
 }
 
 void VideoFullscreenInterfaceAVKit::hasVideoChanged(bool hasVideo)
@@ -841,7 +841,7 @@
 
 UIViewController *VideoFullscreenInterfaceAVKit::presentingViewController()
 {
-    auto *controller = videoFullscreenModel()->presentingViewController();
+    auto *controller = videoFullscreenModel() ? videoFullscreenModel()->presentingViewController() : nil;
     if (!controller)
         controller = fallbackViewController(m_parentView.get());
 
@@ -935,8 +935,8 @@
 
 void VideoFullscreenInterfaceAVKit::invalidate()
 {
-    m_videoFullscreenModel = nil;
-    m_fullscreenChangeObserver = nil;
+    m_videoFullscreenModel = nullptr;
+    m_fullscreenChangeObserver = nullptr;
     
     cleanupFullscreen();
 }
@@ -974,7 +974,9 @@
         return;
 
     m_waitingForPreparedToExit = false;
-    m_videoFullscreenModel->requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenModeNone, true);
+    ASSERT(m_videoFullscreenModel);
+    if (m_videoFullscreenModel)
+        m_videoFullscreenModel->requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenModeNone, true);
 #endif
 }
 
@@ -1143,7 +1145,9 @@
 #endif
     
     BOOL finished = reason == ExitFullScreenReason::DoneButtonTapped || reason == ExitFullScreenReason::PinchGestureHandled;
-    m_videoFullscreenModel->requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenModeNone, finished);
+    ASSERT(m_videoFullscreenModel);
+    if (m_videoFullscreenModel)
+        m_videoFullscreenModel->requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenModeNone, finished);
 
     return false;
 }
@@ -1250,7 +1254,7 @@
         [m_playerViewController setWebKitOverrideRouteSharingPolicy:(NSUInteger)m_routeSharingPolicy routingContextUID:m_routingContextUID];
 
 #if PLATFORM(WATCHOS)
-    m_viewController = videoFullscreenModel()->createVideoFullscreenViewController(m_playerViewController.get().avPlayerViewController);
+    m_viewController = videoFullscreenModel() ? videoFullscreenModel()->createVideoFullscreenViewController(m_playerViewController.get().avPlayerViewController) : nil;
 #endif
 
     if (m_viewController) {

Modified: branches/safari-607-branch/Source/WebCore/platform/mac/VideoFullscreenInterfaceMac.h (243578 => 243579)


--- branches/safari-607-branch/Source/WebCore/platform/mac/VideoFullscreenInterfaceMac.h	2019-03-27 23:43:54 UTC (rev 243578)
+++ branches/safari-607-branch/Source/WebCore/platform/mac/VideoFullscreenInterfaceMac.h	2019-03-27 23:43:57 UTC (rev 243579)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016 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
@@ -56,10 +56,10 @@
     }
     virtual ~VideoFullscreenInterfaceMac();
     PlaybackSessionInterfaceMac& playbackSessionInterface() const { return m_playbackSessionInterface.get(); }
-    VideoFullscreenModel* videoFullscreenModel() const { return m_videoFullscreenModel; }
+    VideoFullscreenModel* videoFullscreenModel() const { return m_videoFullscreenModel.get(); }
     PlaybackSessionModel* playbackSessionModel() const { return m_playbackSessionInterface->playbackSessionModel(); }
     WEBCORE_EXPORT void setVideoFullscreenModel(VideoFullscreenModel*);
-    VideoFullscreenChangeObserver* videoFullscreenChangeObserver() const { return m_fullscreenChangeObserver; }
+    VideoFullscreenChangeObserver* videoFullscreenChangeObserver() const { return m_fullscreenChangeObserver.get(); }
     WEBCORE_EXPORT void setVideoFullscreenChangeObserver(VideoFullscreenChangeObserver*);
 
     // PlaybackSessionModelClient
@@ -99,8 +99,8 @@
 private:
     WEBCORE_EXPORT VideoFullscreenInterfaceMac(PlaybackSessionInterfaceMac&);
     Ref<PlaybackSessionInterfaceMac> m_playbackSessionInterface;
-    VideoFullscreenModel* m_videoFullscreenModel { nullptr };
-    VideoFullscreenChangeObserver* m_fullscreenChangeObserver { nullptr };
+    WeakPtr<VideoFullscreenModel> m_videoFullscreenModel;
+    WeakPtr<VideoFullscreenChangeObserver> m_fullscreenChangeObserver;
     HTMLMediaElementEnums::VideoFullscreenMode m_mode { HTMLMediaElementEnums::VideoFullscreenModeNone };
     RetainPtr<WebVideoFullscreenInterfaceMacObjC> m_webVideoFullscreenInterfaceObjC;
 };

Modified: branches/safari-607-branch/Source/WebCore/platform/mac/VideoFullscreenInterfaceMac.mm (243578 => 243579)


--- branches/safari-607-branch/Source/WebCore/platform/mac/VideoFullscreenInterfaceMac.mm	2019-03-27 23:43:54 UTC (rev 243578)
+++ branches/safari-607-branch/Source/WebCore/platform/mac/VideoFullscreenInterfaceMac.mm	2019-03-27 23:43:57 UTC (rev 243579)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016 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
@@ -376,7 +376,7 @@
 {
     if (m_videoFullscreenModel)
         m_videoFullscreenModel->removeClient(*this);
-    m_videoFullscreenModel = model;
+    m_videoFullscreenModel = makeWeakPtr(model);
     if (m_videoFullscreenModel)
         m_videoFullscreenModel->addClient(*this);
 }
@@ -383,7 +383,7 @@
 
 void VideoFullscreenInterfaceMac::setVideoFullscreenChangeObserver(VideoFullscreenChangeObserver* observer)
 {
-    m_fullscreenChangeObserver = observer;
+    m_fullscreenChangeObserver = makeWeakPtr(observer);
 }
 
 void VideoFullscreenInterfaceMac::setMode(HTMLMediaElementEnums::VideoFullscreenMode mode)
@@ -447,6 +447,7 @@
 {
     LOG(Fullscreen, "VideoFullscreenInterfaceMac::enterFullscreen(%p)", this);
 
+    RELEASE_ASSERT(m_videoFullscreenModel);
     if (mode() == HTMLMediaElementEnums::VideoFullscreenModePictureInPicture) {
         m_videoFullscreenModel->willEnterPictureInPicture();
         [m_webVideoFullscreenInterfaceObjC enterPIP];
@@ -510,8 +511,8 @@
 {
     LOG(Fullscreen, "VideoFullscreenInterfaceMac::invalidate(%p)", this);
 
-    m_videoFullscreenModel = nil;
-    m_fullscreenChangeObserver = nil;
+    m_videoFullscreenModel = nullptr;
+    m_fullscreenChangeObserver = nullptr;
 
     cleanupFullscreen();
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to