Title: [285325] branches/safari-612-branch/Source/WebCore
Revision
285325
Author
[email protected]
Date
2021-11-04 18:54:42 -0700 (Thu, 04 Nov 2021)

Log Message

Cherry-pick r284163. rdar://problem/85042122

    WebCore::CaptionUserPreferencesMediaAF should use a weak observer with CFNotificationCenter
    <https://webkit.org/b/231550>
    <rdar://problem/84129338>

    Reviewed by Darin Adler.

    * SourcesCocoa.txt:
    * WebCore.xcodeproj/project.pbxproj:
    - Add CaptionUserPreferencesMediaAF.mm.

    * page/CaptionUserPreferences.cpp:
    (WebCore::CaptionUserPreferences::create): Add.
    * page/CaptionUserPreferences.h:
    (WebCore::CaptionUserPreferences):
    - Make subclass of RefCounted<> and CanMakeWeakPtr<>.
    (WebCore::CaptionUserPreferences::create): Add.
    (WebCore::CaptionUserPreferences::CaptionUserPreferences):
    - Move constructor to protected visiblity with explicit keyword,
      and add static create() method.

    * page/CaptionUserPreferencesMediaAF.cpp:
    (WebCore::userCaptionPreferencesChangedNotificationCallback):
    - Update to use extractCaptionUserPreferencesMediaAF() for
      Cococa platforms.  Note that -> is used for two different
      `userPreferences` variable types based on the platform.
    (WebCore::CaptionUserPreferencesMediaAF::create): Add.
    (WebCore::CaptionUserPreferencesMediaAF::CaptionUserPreferencesMediaAF):
    - Move initialization of m_listeningForPreferenceChanges to
      class definition.
    (WebCore::CaptionUserPreferencesMediaAF::~CaptionUserPreferencesMediaAF):
    - Update to use m_weakObserver as observer for Cocoa platforms.
    (WebCore::CaptionUserPreferencesMediaAF::setInterestedInCaptionPreferenceChanges):
    - Update to use m_weakObserver as observer and
      _CFNotificationObserverIsObjC in suspension behavior for Cocoa
      platforms.

    * page/CaptionUserPreferencesMediaAF.h:
    (WebCore::CaptionUserPreferencesMediaAF::create): Add.
    (WebCore::CaptionUserPreferencesMediaAF::CaptionUserPreferencesMediaAF):
    - Move constructor to private visiblity, and add static create()
      method.
    (WebCore::CaptionUserPreferencesMediaAF::extractCaptionUserPreferencesMediaAF): Add.
    (WebCore::CaptionUserPreferencesMediaAF::createWeakObserver): Add.
    (WebCore::CaptionUserPreferencesMediaAF::m_weakObserver):
    - Add m_weakObserver instance variable for use with
      CFNotificationCenter.
    (WebCore::CaptionUserPreferencesMediaAF::m_listeningForPreferenceChanges):
    - Move initialization of m_listeningForPreferenceChanges here
      from the constructor.

    * page/cocoa/CaptionUserPreferencesMediaAFCocoa.mm: Add.
    (-[WebCaptionUserPreferencesMediaAFWeakObserver initWithWeakPtr:]):
    (-[WebCaptionUserPreferencesMediaAFWeakObserver userPreferences]):
    - Declare and implement
      WebCaptionUserPreferencesMediaAFWeakObserver class for use as
      a weak CFNotificationCenter observer.
    (WebCore::CaptionUserPreferencesMediaAF::createWeakObserver): Add.
    - Helper method to call from C++ that creates weak observer
      object from Objective-C++.
    (WebCore::CaptionUserPreferencesMediaAF::extractCaptionUserPreferencesMediaAF): Add.
    - Helper method to extract RefPtr<CaptionUserPreferencesMediaAF>
      from CFNotification observer parameter.

    * page/PageGroup.cpp:
    (WebCore::PageGroup::ensureCaptionPreferences):
    - Switch to using new create() methods.

    * page/PageGroup.h:
    (WebCore::PageGroup::m_captionPreferences):
    - Change from std::unique_ptr<> to RefPtr<>.

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

Modified Paths

Added Paths

Diff

Modified: branches/safari-612-branch/Source/WebCore/ChangeLog (285324 => 285325)


--- branches/safari-612-branch/Source/WebCore/ChangeLog	2021-11-05 01:35:44 UTC (rev 285324)
+++ branches/safari-612-branch/Source/WebCore/ChangeLog	2021-11-05 01:54:42 UTC (rev 285325)
@@ -1,5 +1,156 @@
 2021-11-04  Russell Epstein  <[email protected]>
 
+        Cherry-pick r284163. rdar://problem/85042122
+
+    WebCore::CaptionUserPreferencesMediaAF should use a weak observer with CFNotificationCenter
+    <https://webkit.org/b/231550>
+    <rdar://problem/84129338>
+    
+    Reviewed by Darin Adler.
+    
+    * SourcesCocoa.txt:
+    * WebCore.xcodeproj/project.pbxproj:
+    - Add CaptionUserPreferencesMediaAF.mm.
+    
+    * page/CaptionUserPreferences.cpp:
+    (WebCore::CaptionUserPreferences::create): Add.
+    * page/CaptionUserPreferences.h:
+    (WebCore::CaptionUserPreferences):
+    - Make subclass of RefCounted<> and CanMakeWeakPtr<>.
+    (WebCore::CaptionUserPreferences::create): Add.
+    (WebCore::CaptionUserPreferences::CaptionUserPreferences):
+    - Move constructor to protected visiblity with explicit keyword,
+      and add static create() method.
+    
+    * page/CaptionUserPreferencesMediaAF.cpp:
+    (WebCore::userCaptionPreferencesChangedNotificationCallback):
+    - Update to use extractCaptionUserPreferencesMediaAF() for
+      Cococa platforms.  Note that -> is used for two different
+      `userPreferences` variable types based on the platform.
+    (WebCore::CaptionUserPreferencesMediaAF::create): Add.
+    (WebCore::CaptionUserPreferencesMediaAF::CaptionUserPreferencesMediaAF):
+    - Move initialization of m_listeningForPreferenceChanges to
+      class definition.
+    (WebCore::CaptionUserPreferencesMediaAF::~CaptionUserPreferencesMediaAF):
+    - Update to use m_weakObserver as observer for Cocoa platforms.
+    (WebCore::CaptionUserPreferencesMediaAF::setInterestedInCaptionPreferenceChanges):
+    - Update to use m_weakObserver as observer and
+      _CFNotificationObserverIsObjC in suspension behavior for Cocoa
+      platforms.
+    
+    * page/CaptionUserPreferencesMediaAF.h:
+    (WebCore::CaptionUserPreferencesMediaAF::create): Add.
+    (WebCore::CaptionUserPreferencesMediaAF::CaptionUserPreferencesMediaAF):
+    - Move constructor to private visiblity, and add static create()
+      method.
+    (WebCore::CaptionUserPreferencesMediaAF::extractCaptionUserPreferencesMediaAF): Add.
+    (WebCore::CaptionUserPreferencesMediaAF::createWeakObserver): Add.
+    (WebCore::CaptionUserPreferencesMediaAF::m_weakObserver):
+    - Add m_weakObserver instance variable for use with
+      CFNotificationCenter.
+    (WebCore::CaptionUserPreferencesMediaAF::m_listeningForPreferenceChanges):
+    - Move initialization of m_listeningForPreferenceChanges here
+      from the constructor.
+    
+    * page/cocoa/CaptionUserPreferencesMediaAFCocoa.mm: Add.
+    (-[WebCaptionUserPreferencesMediaAFWeakObserver initWithWeakPtr:]):
+    (-[WebCaptionUserPreferencesMediaAFWeakObserver userPreferences]):
+    - Declare and implement
+      WebCaptionUserPreferencesMediaAFWeakObserver class for use as
+      a weak CFNotificationCenter observer.
+    (WebCore::CaptionUserPreferencesMediaAF::createWeakObserver): Add.
+    - Helper method to call from C++ that creates weak observer
+      object from Objective-C++.
+    (WebCore::CaptionUserPreferencesMediaAF::extractCaptionUserPreferencesMediaAF): Add.
+    - Helper method to extract RefPtr<CaptionUserPreferencesMediaAF>
+      from CFNotification observer parameter.
+    
+    * page/PageGroup.cpp:
+    (WebCore::PageGroup::ensureCaptionPreferences):
+    - Switch to using new create() methods.
+    
+    * page/PageGroup.h:
+    (WebCore::PageGroup::m_captionPreferences):
+    - Change from std::unique_ptr<> to RefPtr<>.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@284163 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-10-14  David Kilzer  <[email protected]>
+
+            WebCore::CaptionUserPreferencesMediaAF should use a weak observer with CFNotificationCenter
+            <https://webkit.org/b/231550>
+            <rdar://problem/84129338>
+
+            Reviewed by Darin Adler.
+
+            * SourcesCocoa.txt:
+            * WebCore.xcodeproj/project.pbxproj:
+            - Add CaptionUserPreferencesMediaAF.mm.
+
+            * page/CaptionUserPreferences.cpp:
+            (WebCore::CaptionUserPreferences::create): Add.
+            * page/CaptionUserPreferences.h:
+            (WebCore::CaptionUserPreferences):
+            - Make subclass of RefCounted<> and CanMakeWeakPtr<>.
+            (WebCore::CaptionUserPreferences::create): Add.
+            (WebCore::CaptionUserPreferences::CaptionUserPreferences):
+            - Move constructor to protected visiblity with explicit keyword,
+              and add static create() method.
+
+            * page/CaptionUserPreferencesMediaAF.cpp:
+            (WebCore::userCaptionPreferencesChangedNotificationCallback):
+            - Update to use extractCaptionUserPreferencesMediaAF() for
+              Cococa platforms.  Note that -> is used for two different
+              `userPreferences` variable types based on the platform.
+            (WebCore::CaptionUserPreferencesMediaAF::create): Add.
+            (WebCore::CaptionUserPreferencesMediaAF::CaptionUserPreferencesMediaAF):
+            - Move initialization of m_listeningForPreferenceChanges to
+              class definition.
+            (WebCore::CaptionUserPreferencesMediaAF::~CaptionUserPreferencesMediaAF):
+            - Update to use m_weakObserver as observer for Cocoa platforms.
+            (WebCore::CaptionUserPreferencesMediaAF::setInterestedInCaptionPreferenceChanges):
+            - Update to use m_weakObserver as observer and
+              _CFNotificationObserverIsObjC in suspension behavior for Cocoa
+              platforms.
+
+            * page/CaptionUserPreferencesMediaAF.h:
+            (WebCore::CaptionUserPreferencesMediaAF::create): Add.
+            (WebCore::CaptionUserPreferencesMediaAF::CaptionUserPreferencesMediaAF):
+            - Move constructor to private visiblity, and add static create()
+              method.
+            (WebCore::CaptionUserPreferencesMediaAF::extractCaptionUserPreferencesMediaAF): Add.
+            (WebCore::CaptionUserPreferencesMediaAF::createWeakObserver): Add.
+            (WebCore::CaptionUserPreferencesMediaAF::m_weakObserver):
+            - Add m_weakObserver instance variable for use with
+              CFNotificationCenter.
+            (WebCore::CaptionUserPreferencesMediaAF::m_listeningForPreferenceChanges):
+            - Move initialization of m_listeningForPreferenceChanges here
+              from the constructor.
+
+            * page/cocoa/CaptionUserPreferencesMediaAFCocoa.mm: Add.
+            (-[WebCaptionUserPreferencesMediaAFWeakObserver initWithWeakPtr:]):
+            (-[WebCaptionUserPreferencesMediaAFWeakObserver userPreferences]):
+            - Declare and implement
+              WebCaptionUserPreferencesMediaAFWeakObserver class for use as
+              a weak CFNotificationCenter observer.
+            (WebCore::CaptionUserPreferencesMediaAF::createWeakObserver): Add.
+            - Helper method to call from C++ that creates weak observer
+              object from Objective-C++.
+            (WebCore::CaptionUserPreferencesMediaAF::extractCaptionUserPreferencesMediaAF): Add.
+            - Helper method to extract RefPtr<CaptionUserPreferencesMediaAF>
+              from CFNotification observer parameter.
+
+            * page/PageGroup.cpp:
+            (WebCore::PageGroup::ensureCaptionPreferences):
+            - Switch to using new create() methods.
+
+            * page/PageGroup.h:
+            (WebCore::PageGroup::m_captionPreferences):
+            - Change from std::unique_ptr<> to RefPtr<>.
+
+2021-11-04  Russell Epstein  <[email protected]>
+
         Cherry-pick r282379. rdar://problem/85039227
 
     Fix computed style for transform-origin on SVG boxes

Modified: branches/safari-612-branch/Source/WebCore/SourcesCocoa.txt (285324 => 285325)


--- branches/safari-612-branch/Source/WebCore/SourcesCocoa.txt	2021-11-05 01:35:44 UTC (rev 285324)
+++ branches/safari-612-branch/Source/WebCore/SourcesCocoa.txt	2021-11-05 01:54:42 UTC (rev 285325)
@@ -184,6 +184,7 @@
 loader/mac/LoaderNSURLExtras.mm
 loader/mac/ResourceLoaderMac.mm
 page/CaptionUserPreferencesMediaAF.cpp
+page/cocoa/CaptionUserPreferencesMediaAFCocoa.mm
 page/cocoa/MemoryReleaseCocoa.mm
 page/cocoa/PerformanceLoggingCocoa.mm
 page/cocoa/ResourceUsageOverlayCocoa.mm

Modified: branches/safari-612-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj (285324 => 285325)


--- branches/safari-612-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-11-05 01:35:44 UTC (rev 285324)
+++ branches/safari-612-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-11-05 01:54:42 UTC (rev 285325)
@@ -8226,6 +8226,7 @@
 		442956CA218A6D300080DB54 /* DictionaryLookupLegacy.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = DictionaryLookupLegacy.mm; sourceTree = "<group>"; };
 		4437C4A724E2AE5F00095128 /* LazyLoadFrameObserver.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LazyLoadFrameObserver.h; sourceTree = "<group>"; };
 		4437C4A924E2AE5F00095128 /* LazyLoadFrameObserver.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = LazyLoadFrameObserver.cpp; sourceTree = "<group>"; };
+		443877E3271681F600FD3E33 /* CaptionUserPreferencesMediaAFCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = CaptionUserPreferencesMediaAFCocoa.mm; sourceTree = "<group>"; };
 		443F04260E75C8FB007E5407 /* NetworkStateNotifierIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NetworkStateNotifierIOS.mm; sourceTree = "<group>"; };
 		444D4E210F708B2E003158E0 /* WebCoreURLResponseIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCoreURLResponseIOS.mm; sourceTree = "<group>"; };
 		445210DD25D61EFF003A2ED8 /* AppHighlight.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppHighlight.h; sourceTree = "<group>"; };
@@ -21511,6 +21512,7 @@
 		5D5975B5196362BE00D00878 /* cocoa */ = {
 			isa = PBXGroup;
 			children = (
+				443877E3271681F600FD3E33 /* CaptionUserPreferencesMediaAFCocoa.mm */,
 				F446EDDD265DAE3F0031DA8F /* DataDetectionResultsStorage.h */,
 				F446EDE7265DD8900031DA8F /* DataDetectorElementInfo.h */,
 				F446EDE0265DB1E50031DA8F /* ImageOverlayDataDetectionResultIdentifier.h */,

Modified: branches/safari-612-branch/Source/WebCore/page/CaptionUserPreferences.cpp (285324 => 285325)


--- branches/safari-612-branch/Source/WebCore/page/CaptionUserPreferences.cpp	2021-11-05 01:35:44 UTC (rev 285324)
+++ branches/safari-612-branch/Source/WebCore/page/CaptionUserPreferences.cpp	2021-11-05 01:54:42 UTC (rev 285325)
@@ -49,6 +49,11 @@
 
 namespace WebCore {
 
+Ref<CaptionUserPreferences> CaptionUserPreferences::create(PageGroup& group)
+{
+    return adoptRef(*new CaptionUserPreferences(group));
+}
+
 CaptionUserPreferences::CaptionUserPreferences(PageGroup& group)
     : m_pageGroup(group)
     , m_displayMode(ForcedOnly)

Modified: branches/safari-612-branch/Source/WebCore/page/CaptionUserPreferences.h (285324 => 285325)


--- branches/safari-612-branch/Source/WebCore/page/CaptionUserPreferences.h	2021-11-05 01:35:44 UTC (rev 285324)
+++ branches/safari-612-branch/Source/WebCore/page/CaptionUserPreferences.h	2021-11-05 01:54:42 UTC (rev 285325)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2012-2021 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,7 @@
 #include "Timer.h"
 #include <wtf/EnumTraits.h>
 #include <wtf/HashSet.h>
+#include <wtf/WeakPtr.h>
 
 namespace WebCore {
 
@@ -41,10 +42,10 @@
 class TextTrackList;
 struct MediaSelectionOption;
 
-class CaptionUserPreferences {
+class CaptionUserPreferences : public RefCounted<CaptionUserPreferences>, public CanMakeWeakPtr<CaptionUserPreferences> {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    CaptionUserPreferences(PageGroup&);
+    static Ref<CaptionUserPreferences> create(PageGroup&);
     virtual ~CaptionUserPreferences();
 
     enum CaptionDisplayMode {
@@ -102,6 +103,8 @@
     PageGroup& pageGroup() const { return m_pageGroup; }
 
 protected:
+    explicit CaptionUserPreferences(PageGroup&);
+
     void updateCaptionStyleSheetOverride();
     void beginBlockingNotifications();
     void endBlockingNotifications();

Modified: branches/safari-612-branch/Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp (285324 => 285325)


--- branches/safari-612-branch/Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp	2021-11-05 01:35:44 UTC (rev 285324)
+++ branches/safari-612-branch/Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp	2021-11-05 01:54:42 UTC (rev 285325)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2012-2021 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -24,13 +24,10 @@
  */
 
 #include "config.h"
+#include "CaptionUserPreferencesMediaAF.h"
 
-#if ENABLE(VIDEO)
+#if ENABLE(VIDEO) && !USE(DIRECT2D)
 
-#if !USE(DIRECT2D)
-
-#include "CaptionUserPreferencesMediaAF.h"
-
 #include "AudioTrackList.h"
 #include "ColorSerialization.h"
 #include "FloatConversion.h"
@@ -51,8 +48,12 @@
 #include <wtf/text/cf/StringConcatenateCF.h>
 #include <wtf/unicode/Collator.h>
 
+#if PLATFORM(COCOA)
+#include <pal/spi/cf/CFNotificationCenterSPI.h>
+#endif
+
 #if PLATFORM(IOS_FAMILY)
-#import "WebCoreThreadRun.h"
+#include "WebCoreThreadRun.h"
 #endif
 
 #if PLATFORM(WIN)
@@ -118,24 +119,35 @@
     return preferredLanguages;
 }
 
-static void userCaptionPreferencesChangedNotificationCallback(CFNotificationCenterRef, void* observer, CFStringRef, const void *, CFDictionaryRef)
+static void userCaptionPreferencesChangedNotificationCallback(CFNotificationCenterRef, void* observer, CFStringRef, const void*, CFDictionaryRef)
 {
+#if PLATFORM(COCOA)
+    RefPtr userPreferences = CaptionUserPreferencesMediaAF::extractCaptionUserPreferencesMediaAF(observer);
+#elif PLATFORM(WIN)
+    auto* userPreferences = static_cast<CaptionUserPreferencesMediaAF*>(observer);
+#endif
+    if (userPreferences) {
 #if !PLATFORM(IOS_FAMILY)
-    static_cast<CaptionUserPreferencesMediaAF*>(observer)->captionPreferencesChanged();
+        userPreferences->captionPreferencesChanged();
 #else
-    WebThreadRun(^{
-        static_cast<CaptionUserPreferencesMediaAF*>(observer)->captionPreferencesChanged();
-    });
+        WebThreadRun(^{
+            userPreferences->captionPreferencesChanged();
+        });
 #endif
+    }
 }
 
-#endif
+#endif // HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)
 
+Ref<CaptionUserPreferencesMediaAF> CaptionUserPreferencesMediaAF::create(PageGroup& group)
+{
+    return adoptRef(*new CaptionUserPreferencesMediaAF(group));
+}
+
 CaptionUserPreferencesMediaAF::CaptionUserPreferencesMediaAF(PageGroup& group)
     : CaptionUserPreferences(group)
 #if HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)
     , m_updateStyleSheetTimer(*this, &CaptionUserPreferencesMediaAF::updateTimerFired)
-    , m_listeningForPreferenceChanges(false)
 #endif
 {
     static bool initialized;
@@ -163,11 +175,19 @@
 CaptionUserPreferencesMediaAF::~CaptionUserPreferencesMediaAF()
 {
 #if HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)
-    if (kMAXCaptionAppearanceSettingsChangedNotification)
-        CFNotificationCenterRemoveObserver(CFNotificationCenterGetLocalCenter(), this, kMAXCaptionAppearanceSettingsChangedNotification, 0);
-    if (kMAAudibleMediaSettingsChangedNotification)
-        CFNotificationCenterRemoveObserver(CFNotificationCenterGetLocalCenter(), this, kMAAudibleMediaSettingsChangedNotification, 0);
+#if PLATFORM(COCOA)
+    auto* observer = m_weakObserver.get();
+#elif PLATFORM(WIN)
+    auto* observer = this;
 #endif
+    if (observer) {
+        auto center = CFNotificationCenterGetLocalCenter();
+        if (kMAXCaptionAppearanceSettingsChangedNotification)
+            CFNotificationCenterRemoveObserver(center, observer, kMAXCaptionAppearanceSettingsChangedNotification, 0);
+        if (kMAAudibleMediaSettingsChangedNotification)
+            CFNotificationCenterRemoveObserver(center, observer, kMAAudibleMediaSettingsChangedNotification, 0);
+    }
+#endif // HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)
 }
 
 #if HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)
@@ -285,10 +305,21 @@
     m_listeningForPreferenceChanges = true;
     m_registeringForNotification = true;
 
+#if PLATFORM(COCOA)
+    if (!m_weakObserver)
+        m_weakObserver = createWeakObserver(this);
+    auto* observer = m_weakObserver.get();
+    auto suspensionBehavior = static_cast<CFNotificationSuspensionBehavior>(CFNotificationSuspensionBehaviorCoalesce | _CFNotificationObserverIsObjC);
+#elif PLATFORM(WIN)
+    auto* observer = this;
+    auto suspensionBehavior = CFNotificationSuspensionBehaviorCoalesce;
+#endif
+    auto center = CFNotificationCenterGetLocalCenter();
     if (kMAXCaptionAppearanceSettingsChangedNotification)
-        CFNotificationCenterAddObserver(CFNotificationCenterGetLocalCenter(), this, userCaptionPreferencesChangedNotificationCallback, kMAXCaptionAppearanceSettingsChangedNotification, 0, CFNotificationSuspensionBehaviorCoalesce);
+        CFNotificationCenterAddObserver(center, observer, userCaptionPreferencesChangedNotificationCallback, kMAXCaptionAppearanceSettingsChangedNotification, 0, suspensionBehavior);
+
     if (canLoad_MediaAccessibility_kMAAudibleMediaSettingsChangedNotification())
-        CFNotificationCenterAddObserver(CFNotificationCenterGetLocalCenter(), this, userCaptionPreferencesChangedNotificationCallback, kMAAudibleMediaSettingsChangedNotification, 0, CFNotificationSuspensionBehaviorCoalesce);
+        CFNotificationCenterAddObserver(center, observer, userCaptionPreferencesChangedNotificationCallback, kMAAudibleMediaSettingsChangedNotification, 0, suspensionBehavior);
     m_registeringForNotification = false;
 
     // Generating and registering the caption stylesheet can be expensive and this method is called indirectly when the parser creates an audio or
@@ -963,6 +994,4 @@
     
 }
 
-#endif
-
-#endif // ENABLE(VIDEO)
+#endif // ENABLE(VIDEO) && !USE(DIRECT2D)

Modified: branches/safari-612-branch/Source/WebCore/page/CaptionUserPreferencesMediaAF.h (285324 => 285325)


--- branches/safari-612-branch/Source/WebCore/page/CaptionUserPreferencesMediaAF.h	2021-11-05 01:35:44 UTC (rev 285324)
+++ branches/safari-612-branch/Source/WebCore/page/CaptionUserPreferencesMediaAF.h	2021-11-05 01:54:42 UTC (rev 285325)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2015 Apple Inc. All rights reserved.
+ * Copyright (C) 2012-2021 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -25,7 +25,7 @@
 
 #pragma once
 
-#if ENABLE(VIDEO)
+#if ENABLE(VIDEO) && !USE(DIRECT2D)
 
 #include "CSSPropertyNames.h"
 #include "CaptionPreferencesDelegate.h"
@@ -32,12 +32,16 @@
 #include "CaptionUserPreferences.h"
 #include "Color.h"
 
+#if PLATFORM(COCOA)
+OBJC_CLASS WebCaptionUserPreferencesMediaAFWeakObserver;
+#endif
+
 namespace WebCore {
 
 class CaptionUserPreferencesMediaAF : public CaptionUserPreferences {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    CaptionUserPreferencesMediaAF(PageGroup&);
+    static Ref<CaptionUserPreferencesMediaAF> create(PageGroup&);
     virtual ~CaptionUserPreferencesMediaAF();
 
 #if HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)
@@ -75,6 +79,10 @@
     bool shouldFilterTrackMenu() const { return false; }
 #endif
 
+#if HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK) && PLATFORM(COCOA)
+    static RefPtr<CaptionUserPreferencesMediaAF> extractCaptionUserPreferencesMediaAF(void* observer);
+#endif
+
     String captionsStyleSheetOverride() const override;
     Vector<RefPtr<AudioTrack>> sortedTrackListForMenu(AudioTrackList*) override;
     Vector<RefPtr<TextTrack>> sortedTrackListForMenu(TextTrackList*, HashSet<TextTrack::Kind>) override;
@@ -82,6 +90,8 @@
     String displayNameForTrack(TextTrack*) const override;
 
 private:
+    CaptionUserPreferencesMediaAF(PageGroup&);
+
 #if HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)
     void updateTimerFired();
 
@@ -93,9 +103,17 @@
     String windowRoundedCornerRadiusCSS() const;
     String captionsTextEdgeCSS() const;
     String colorPropertyCSS(CSSPropertyID, const Color&, bool) const;
+#endif
+
+#if HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK) && PLATFORM(COCOA)
+    static RetainPtr<WebCaptionUserPreferencesMediaAFWeakObserver> createWeakObserver(CaptionUserPreferencesMediaAF*);
+
+    RetainPtr<WebCaptionUserPreferencesMediaAFWeakObserver> m_weakObserver;
+#endif
+
+#if HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)
     Timer m_updateStyleSheetTimer;
-
-    bool m_listeningForPreferenceChanges;
+    bool m_listeningForPreferenceChanges { false };
     bool m_registeringForNotification { false };
 #endif
 };
@@ -102,4 +120,4 @@
 
 } // namespace WebCore
 
-#endif // ENABLE(VIDEO)
+#endif // ENABLE(VIDEO) && !USE(DIRECT2D)

Modified: branches/safari-612-branch/Source/WebCore/page/PageGroup.cpp (285324 => 285325)


--- branches/safari-612-branch/Source/WebCore/page/PageGroup.cpp	2021-11-05 01:35:44 UTC (rev 285324)
+++ branches/safari-612-branch/Source/WebCore/page/PageGroup.cpp	2021-11-05 01:54:42 UTC (rev 285325)
@@ -113,9 +113,9 @@
 {
     if (!m_captionPreferences) {
 #if PLATFORM(MAC) || HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)
-        m_captionPreferences = makeUnique<CaptionUserPreferencesMediaAF>(*this);
+        m_captionPreferences = CaptionUserPreferencesMediaAF::create(*this);
 #else
-        m_captionPreferences = makeUnique<CaptionUserPreferences>(*this);
+        m_captionPreferences = CaptionUserPreferences::create(*this);
 #endif
     }
 

Modified: branches/safari-612-branch/Source/WebCore/page/PageGroup.h (285324 => 285325)


--- branches/safari-612-branch/Source/WebCore/page/PageGroup.h	2021-11-05 01:35:44 UTC (rev 285324)
+++ branches/safari-612-branch/Source/WebCore/page/PageGroup.h	2021-11-05 01:54:42 UTC (rev 285325)
@@ -66,7 +66,7 @@
     unsigned m_identifier;
 
 #if ENABLE(VIDEO)
-    std::unique_ptr<CaptionUserPreferences> m_captionPreferences;
+    RefPtr<CaptionUserPreferences> m_captionPreferences;
 #endif
 };
 

Added: branches/safari-612-branch/Source/WebCore/page/cocoa/CaptionUserPreferencesMediaAFCocoa.mm (0 => 285325)


--- branches/safari-612-branch/Source/WebCore/page/cocoa/CaptionUserPreferencesMediaAFCocoa.mm	                        (rev 0)
+++ branches/safari-612-branch/Source/WebCore/page/cocoa/CaptionUserPreferencesMediaAFCocoa.mm	2021-11-05 01:54:42 UTC (rev 285325)
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2012-2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "config.h"
+#include "CaptionUserPreferencesMediaAF.h"
+
+#if ENABLE(VIDEO) && PLATFORM(COCOA)
+
+#import <wtf/cocoa/TypeCastsCocoa.h>
+#import <wtf/spi/cocoa/NSObjCRuntimeSPI.h>
+
+@interface WebCaptionUserPreferencesMediaAFWeakObserver : NSObject {
+    WeakPtr<WebCore::CaptionUserPreferencesMediaAF> m_weakPtr;
+}
+@property (nonatomic, readonly, direct) RefPtr<WebCore::CaptionUserPreferencesMediaAF> userPreferences;
+- (instancetype)init NS_UNAVAILABLE;
+- (instancetype)initWithWeakPtr:(WeakPtr<WebCore::CaptionUserPreferencesMediaAF>&&)weakPtr NS_DESIGNATED_INITIALIZER;
+@end
+
+NS_DIRECT_MEMBERS
+@implementation WebCaptionUserPreferencesMediaAFWeakObserver
+- (instancetype)initWithWeakPtr:(WeakPtr<WebCore::CaptionUserPreferencesMediaAF>&&)weakPtr
+{
+    if ((self = [super init]))
+        m_weakPtr = WTFMove(weakPtr);
+    return self;
+}
+
+- (RefPtr<WebCore::CaptionUserPreferencesMediaAF>)userPreferences
+{
+    return m_weakPtr.get();
+}
+@end
+
+namespace WebCore {
+
+RetainPtr<WebCaptionUserPreferencesMediaAFWeakObserver> CaptionUserPreferencesMediaAF::createWeakObserver(CaptionUserPreferencesMediaAF* thisPtr)
+{
+    return adoptNS([[WebCaptionUserPreferencesMediaAFWeakObserver alloc] initWithWeakPtr:WeakPtr { *thisPtr }]);
+}
+
+RefPtr<CaptionUserPreferencesMediaAF> CaptionUserPreferencesMediaAF::extractCaptionUserPreferencesMediaAF(void* observer)
+{
+    RetainPtr strongObserver { dynamic_ns_cast<WebCaptionUserPreferencesMediaAFWeakObserver>(reinterpret_cast<id>(observer)) };
+    if (!strongObserver)
+        return nullptr;
+    return [strongObserver userPreferences];
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(VIDEO) && PLATFORM(COCOA)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to