Title: [285273] branches/safari-612-branch/Source
Revision
285273
Author
[email protected]
Date
2021-11-04 12:38:42 -0700 (Thu, 04 Nov 2021)

Log Message

Cherry-pick r282313. rdar://problem/82987695

    CFNotificationCenterAddObserver() should use weak observers
    <https://webkit.org/b/230168>
    <rdar://problem/82987695>

    Reviewed by Darin Adler.

    Source/WebCore/PAL:

    * PAL.xcodeproj/project.pbxproj:
    - Add CFNotificationCenterSPI.h to the project.
    * pal/spi/cf/CFNotificationCenterSPI.h: Add.

    Source/WebKit:

    * UIProcess/API/Cocoa/WKWebView.mm:
    (hardwareKeyboardAvailabilityChangedCallback):
    - Use RetainPtr to store `observer` for the duration of the
      function, and add an early return if it is nil.
    (-[WKWebView _initializeWithConfiguration:]):
    - Use _CFNotificationObserverIsObjC to fix the bug.
    - Extract local variables and change notificationName cast to be
      ARC-ready.  Remove notificationName from autoreleasePool.
    (-[WKWebView dealloc]):
    - Extract local variable and change notificationName cast to be
      ARC-ready.  Remove notificationName from autoreleasePool.

    Source/WebKitLegacy/mac:

    * WebView/WebHTMLView.mm:
    (hardwareKeyboardAvailabilityChangedCallback):
    - Modernize syntax for WeakObjCPtr constructor.
    (-[WebHTMLView initWithFrame:]):
    - Use _CFNotificationObserverIsObjC to fix the bug.
    - Extract local variables and change notificationName cast to be
      ARC-ready.  Remove notificationName from autoreleasePool.
    (-[WebHTMLView dealloc]):
    - Extract local variable and change notificationName cast to be
      ARC-ready.  Remove notificationName from autoreleasePool.

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

Modified Paths

Added Paths

Diff

Modified: branches/safari-612-branch/Source/WebCore/PAL/ChangeLog (285272 => 285273)


--- branches/safari-612-branch/Source/WebCore/PAL/ChangeLog	2021-11-04 18:44:52 UTC (rev 285272)
+++ branches/safari-612-branch/Source/WebCore/PAL/ChangeLog	2021-11-04 19:38:42 UTC (rev 285273)
@@ -1,3 +1,61 @@
+2021-11-04  Russell Epstein  <[email protected]>
+
+        Cherry-pick r282313. rdar://problem/82987695
+
+    CFNotificationCenterAddObserver() should use weak observers
+    <https://webkit.org/b/230168>
+    <rdar://problem/82987695>
+    
+    Reviewed by Darin Adler.
+    
+    Source/WebCore/PAL:
+    
+    * PAL.xcodeproj/project.pbxproj:
+    - Add CFNotificationCenterSPI.h to the project.
+    * pal/spi/cf/CFNotificationCenterSPI.h: Add.
+    
+    Source/WebKit:
+    
+    * UIProcess/API/Cocoa/WKWebView.mm:
+    (hardwareKeyboardAvailabilityChangedCallback):
+    - Use RetainPtr to store `observer` for the duration of the
+      function, and add an early return if it is nil.
+    (-[WKWebView _initializeWithConfiguration:]):
+    - Use _CFNotificationObserverIsObjC to fix the bug.
+    - Extract local variables and change notificationName cast to be
+      ARC-ready.  Remove notificationName from autoreleasePool.
+    (-[WKWebView dealloc]):
+    - Extract local variable and change notificationName cast to be
+      ARC-ready.  Remove notificationName from autoreleasePool.
+    
+    Source/WebKitLegacy/mac:
+    
+    * WebView/WebHTMLView.mm:
+    (hardwareKeyboardAvailabilityChangedCallback):
+    - Modernize syntax for WeakObjCPtr constructor.
+    (-[WebHTMLView initWithFrame:]):
+    - Use _CFNotificationObserverIsObjC to fix the bug.
+    - Extract local variables and change notificationName cast to be
+      ARC-ready.  Remove notificationName from autoreleasePool.
+    (-[WebHTMLView dealloc]):
+    - Extract local variable and change notificationName cast to be
+      ARC-ready.  Remove notificationName from autoreleasePool.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@282313 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-09-11  David Kilzer  <[email protected]>
+
+            CFNotificationCenterAddObserver() should use weak observers
+            <https://webkit.org/b/230168>
+            <rdar://problem/82987695>
+
+            Reviewed by Darin Adler.
+
+            * PAL.xcodeproj/project.pbxproj:
+            - Add CFNotificationCenterSPI.h to the project.
+            * pal/spi/cf/CFNotificationCenterSPI.h: Add.
+
 2021-10-29  Russell Epstein  <[email protected]>
 
         Cherry-pick r284494. rdar://problem/84816590

Modified: branches/safari-612-branch/Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj (285272 => 285273)


--- branches/safari-612-branch/Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj	2021-11-04 18:44:52 UTC (rev 285272)
+++ branches/safari-612-branch/Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj	2021-11-04 19:38:42 UTC (rev 285273)
@@ -133,6 +133,7 @@
 		41B99E4625DD70160007829A /* AVStreamDataParserSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 41B99E4525DD70150007829A /* AVStreamDataParserSPI.h */; };
 		41E1F344248A6A000022D5DE /* VideoToolboxSoftLink.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 416E995523DAEFF700E871CB /* VideoToolboxSoftLink.cpp */; };
 		442956CD218A72DF0080DB54 /* RevealSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 442956CC218A72DE0080DB54 /* RevealSPI.h */; };
+		445097BC26EBF66D003EF771 /* CFNotificationCenterSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 445097BB26EBF66D003EF771 /* CFNotificationCenterSPI.h */; };
 		4450FC9F21F5F602004DFA56 /* QuickLookSoftLink.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4450FC9D21F5F602004DFA56 /* QuickLookSoftLink.mm */; };
 		4450FCA021F5F602004DFA56 /* QuickLookSoftLink.h in Headers */ = {isa = PBXBuildFile; fileRef = 4450FC9E21F5F602004DFA56 /* QuickLookSoftLink.h */; };
 		44E1A8AF21FA54E600C3048E /* LookupSoftLink.h in Headers */ = {isa = PBXBuildFile; fileRef = 44E1A8AD21FA54DA00C3048E /* LookupSoftLink.h */; };
@@ -356,6 +357,7 @@
 		416E995623DAEFF700E871CB /* VideoToolboxSoftLink.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VideoToolboxSoftLink.h; sourceTree = "<group>"; };
 		41B99E4525DD70150007829A /* AVStreamDataParserSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AVStreamDataParserSPI.h; sourceTree = "<group>"; };
 		442956CC218A72DE0080DB54 /* RevealSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RevealSPI.h; sourceTree = "<group>"; };
+		445097BB26EBF66D003EF771 /* CFNotificationCenterSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CFNotificationCenterSPI.h; sourceTree = "<group>"; };
 		4450FC9D21F5F602004DFA56 /* QuickLookSoftLink.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = QuickLookSoftLink.mm; sourceTree = "<group>"; };
 		4450FC9E21F5F602004DFA56 /* QuickLookSoftLink.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QuickLookSoftLink.h; sourceTree = "<group>"; };
 		44E1A8AD21FA54DA00C3048E /* LookupSoftLink.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LookupSoftLink.h; sourceTree = "<group>"; };
@@ -495,6 +497,7 @@
 				0C2DA0671F33CA8400DBC317 /* CFLocaleSPI.h */,
 				0C2DA0681F33CA8400DBC317 /* CFNetworkConnectionCacheSPI.h */,
 				0C2DA0691F33CA8400DBC317 /* CFNetworkSPI.h */,
+				445097BB26EBF66D003EF771 /* CFNotificationCenterSPI.h */,
 				0C2DA06A1F33CA8400DBC317 /* CFUtilitiesSPI.h */,
 				0C2DA06B1F33CA8400DBC317 /* CoreAudioSPI.h */,
 				0C2DA06C1F33CA8400DBC317 /* CoreMediaSPI.h */,
@@ -877,6 +880,7 @@
 				0C2DA06D1F33CA8400DBC317 /* CFLocaleSPI.h in Headers */,
 				0C2DA06E1F33CA8400DBC317 /* CFNetworkConnectionCacheSPI.h in Headers */,
 				0C2DA06F1F33CA8400DBC317 /* CFNetworkSPI.h in Headers */,
+				445097BC26EBF66D003EF771 /* CFNotificationCenterSPI.h in Headers */,
 				0C2DA13F1F3BEB4900DBC317 /* CFNSURLConnectionSPI.h in Headers */,
 				0C2DA0701F33CA8400DBC317 /* CFUtilitiesSPI.h in Headers */,
 				0C5FFF0C1F78D990009EFF1A /* Clock.h in Headers */,

Added: branches/safari-612-branch/Source/WebCore/PAL/pal/spi/cf/CFNotificationCenterSPI.h (0 => 285273)


--- branches/safari-612-branch/Source/WebCore/PAL/pal/spi/cf/CFNotificationCenterSPI.h	                        (rev 0)
+++ branches/safari-612-branch/Source/WebCore/PAL/pal/spi/cf/CFNotificationCenterSPI.h	2021-11-04 19:38:42 UTC (rev 285273)
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 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. AND ITS CONTRIBUTORS ``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 ITS 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.
+ */
+
+#pragma once
+
+#if USE(APPLE_INTERNAL_SDK)
+#include <CoreFoundation/CFNotificationCenterPriv.h>
+#else
+static const CFIndex _CFNotificationObserverIsObjC = 1 << 10;
+#endif

Modified: branches/safari-612-branch/Source/WebKit/ChangeLog (285272 => 285273)


--- branches/safari-612-branch/Source/WebKit/ChangeLog	2021-11-04 18:44:52 UTC (rev 285272)
+++ branches/safari-612-branch/Source/WebKit/ChangeLog	2021-11-04 19:38:42 UTC (rev 285273)
@@ -1,3 +1,69 @@
+2021-11-04  Russell Epstein  <[email protected]>
+
+        Cherry-pick r282313. rdar://problem/82987695
+
+    CFNotificationCenterAddObserver() should use weak observers
+    <https://webkit.org/b/230168>
+    <rdar://problem/82987695>
+    
+    Reviewed by Darin Adler.
+    
+    Source/WebCore/PAL:
+    
+    * PAL.xcodeproj/project.pbxproj:
+    - Add CFNotificationCenterSPI.h to the project.
+    * pal/spi/cf/CFNotificationCenterSPI.h: Add.
+    
+    Source/WebKit:
+    
+    * UIProcess/API/Cocoa/WKWebView.mm:
+    (hardwareKeyboardAvailabilityChangedCallback):
+    - Use RetainPtr to store `observer` for the duration of the
+      function, and add an early return if it is nil.
+    (-[WKWebView _initializeWithConfiguration:]):
+    - Use _CFNotificationObserverIsObjC to fix the bug.
+    - Extract local variables and change notificationName cast to be
+      ARC-ready.  Remove notificationName from autoreleasePool.
+    (-[WKWebView dealloc]):
+    - Extract local variable and change notificationName cast to be
+      ARC-ready.  Remove notificationName from autoreleasePool.
+    
+    Source/WebKitLegacy/mac:
+    
+    * WebView/WebHTMLView.mm:
+    (hardwareKeyboardAvailabilityChangedCallback):
+    - Modernize syntax for WeakObjCPtr constructor.
+    (-[WebHTMLView initWithFrame:]):
+    - Use _CFNotificationObserverIsObjC to fix the bug.
+    - Extract local variables and change notificationName cast to be
+      ARC-ready.  Remove notificationName from autoreleasePool.
+    (-[WebHTMLView dealloc]):
+    - Extract local variable and change notificationName cast to be
+      ARC-ready.  Remove notificationName from autoreleasePool.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@282313 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-09-11  David Kilzer  <[email protected]>
+
+            CFNotificationCenterAddObserver() should use weak observers
+            <https://webkit.org/b/230168>
+            <rdar://problem/82987695>
+
+            Reviewed by Darin Adler.
+
+            * UIProcess/API/Cocoa/WKWebView.mm:
+            (hardwareKeyboardAvailabilityChangedCallback):
+            - Use RetainPtr to store `observer` for the duration of the
+              function, and add an early return if it is nil.
+            (-[WKWebView _initializeWithConfiguration:]):
+            - Use _CFNotificationObserverIsObjC to fix the bug.
+            - Extract local variables and change notificationName cast to be
+              ARC-ready.  Remove notificationName from autoreleasePool.
+            (-[WKWebView dealloc]):
+            - Extract local variable and change notificationName cast to be
+              ARC-ready.  Remove notificationName from autoreleasePool.
+
 2021-10-26  Russell Epstein  <[email protected]>
 
         Cherry-pick r284349. rdar://problem/81171560

Modified: branches/safari-612-branch/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (285272 => 285273)


--- branches/safari-612-branch/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2021-11-04 18:44:52 UTC (rev 285272)
+++ branches/safari-612-branch/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2021-11-04 19:38:42 UTC (rev 285273)
@@ -170,6 +170,7 @@
 #import "WKWebViewContentProviderRegistry.h"
 #import <MobileCoreServices/MobileCoreServices.h>
 #import <UIKit/UIApplication.h>
+#import <pal/spi/cf/CFNotificationCenterSPI.h>
 #import <pal/spi/cocoa/QuartzCoreSPI.h>
 #import <pal/spi/ios/GraphicsServicesSPI.h>
 #import <wtf/cocoa/Entitlements.h>
@@ -324,9 +325,11 @@
 static void hardwareKeyboardAvailabilityChangedCallback(CFNotificationCenterRef, void* observer, CFStringRef, const void*, CFDictionaryRef)
 {
     ASSERT(observer);
-    WKWebView *webView = (__bridge WKWebView *)observer;
+    RetainPtr webView { (__bridge WKWebView *)observer };
+    if (!webView)
+        return;
     [webView->_contentView _hardwareKeyboardAvailabilityChanged];
-    webView._page->hardwareKeyboardAvailabilityChanged(GSEventIsHardwareKeyboardAttached());
+    webView->_page->hardwareKeyboardAvailabilityChanged(GSEventIsHardwareKeyboardAttached());
 }
 #endif
 
@@ -394,7 +397,9 @@
 
     _page->contentSizeCategoryDidChange([self _contentSizeCategory]);
 
-    CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), (__bridge const void *)(self), hardwareKeyboardAvailabilityChangedCallback, (CFStringRef)[NSString stringWithUTF8String:kGSEventHardwareKeyboardAvailabilityChangedNotification], nullptr, CFNotificationSuspensionBehaviorCoalesce);
+    auto notificationName = adoptNS([[NSString alloc] initWithCString:kGSEventHardwareKeyboardAvailabilityChangedNotification encoding:NSUTF8StringEncoding]);
+    auto notificationBehavior = static_cast<CFNotificationSuspensionBehavior>(CFNotificationSuspensionBehaviorCoalesce | _CFNotificationObserverIsObjC);
+    CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), (__bridge const void *)(self), hardwareKeyboardAvailabilityChangedCallback, (__bridge CFStringRef)notificationName.get(), nullptr, notificationBehavior);
 #endif // PLATFORM(IOS_FAMILY)
 
 #if ENABLE(META_VIEWPORT)
@@ -638,7 +643,8 @@
     [[NSNotificationCenter defaultCenter] removeObserver:self];
     [_scrollView setInternalDelegate:nil];
 
-    CFNotificationCenterRemoveObserver(CFNotificationCenterGetDarwinNotifyCenter(), (__bridge const void *)(self), (CFStringRef)[NSString stringWithUTF8String:kGSEventHardwareKeyboardAvailabilityChangedNotification], nullptr);
+    auto notificationName = adoptNS([[NSString alloc] initWithCString:kGSEventHardwareKeyboardAvailabilityChangedNotification encoding:NSUTF8StringEncoding]);
+    CFNotificationCenterRemoveObserver(CFNotificationCenterGetDarwinNotifyCenter(), (__bridge const void *)(self), (__bridge CFStringRef)notificationName.get(), nullptr);
 #endif
 
     [super dealloc];

Modified: branches/safari-612-branch/Source/WebKitLegacy/mac/ChangeLog (285272 => 285273)


--- branches/safari-612-branch/Source/WebKitLegacy/mac/ChangeLog	2021-11-04 18:44:52 UTC (rev 285272)
+++ branches/safari-612-branch/Source/WebKitLegacy/mac/ChangeLog	2021-11-04 19:38:42 UTC (rev 285273)
@@ -1,3 +1,68 @@
+2021-11-04  Russell Epstein  <[email protected]>
+
+        Cherry-pick r282313. rdar://problem/82987695
+
+    CFNotificationCenterAddObserver() should use weak observers
+    <https://webkit.org/b/230168>
+    <rdar://problem/82987695>
+    
+    Reviewed by Darin Adler.
+    
+    Source/WebCore/PAL:
+    
+    * PAL.xcodeproj/project.pbxproj:
+    - Add CFNotificationCenterSPI.h to the project.
+    * pal/spi/cf/CFNotificationCenterSPI.h: Add.
+    
+    Source/WebKit:
+    
+    * UIProcess/API/Cocoa/WKWebView.mm:
+    (hardwareKeyboardAvailabilityChangedCallback):
+    - Use RetainPtr to store `observer` for the duration of the
+      function, and add an early return if it is nil.
+    (-[WKWebView _initializeWithConfiguration:]):
+    - Use _CFNotificationObserverIsObjC to fix the bug.
+    - Extract local variables and change notificationName cast to be
+      ARC-ready.  Remove notificationName from autoreleasePool.
+    (-[WKWebView dealloc]):
+    - Extract local variable and change notificationName cast to be
+      ARC-ready.  Remove notificationName from autoreleasePool.
+    
+    Source/WebKitLegacy/mac:
+    
+    * WebView/WebHTMLView.mm:
+    (hardwareKeyboardAvailabilityChangedCallback):
+    - Modernize syntax for WeakObjCPtr constructor.
+    (-[WebHTMLView initWithFrame:]):
+    - Use _CFNotificationObserverIsObjC to fix the bug.
+    - Extract local variables and change notificationName cast to be
+      ARC-ready.  Remove notificationName from autoreleasePool.
+    (-[WebHTMLView dealloc]):
+    - Extract local variable and change notificationName cast to be
+      ARC-ready.  Remove notificationName from autoreleasePool.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@282313 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-09-11  David Kilzer  <[email protected]>
+
+            CFNotificationCenterAddObserver() should use weak observers
+            <https://webkit.org/b/230168>
+            <rdar://problem/82987695>
+
+            Reviewed by Darin Adler.
+
+            * WebView/WebHTMLView.mm:
+            (hardwareKeyboardAvailabilityChangedCallback):
+            - Modernize syntax for WeakObjCPtr constructor.
+            (-[WebHTMLView initWithFrame:]):
+            - Use _CFNotificationObserverIsObjC to fix the bug.
+            - Extract local variables and change notificationName cast to be
+              ARC-ready.  Remove notificationName from autoreleasePool.
+            (-[WebHTMLView dealloc]):
+            - Extract local variable and change notificationName cast to be
+              ARC-ready.  Remove notificationName from autoreleasePool.
+
 2021-09-28  Chris Dumez  <[email protected]>
 
         Move Cross-Origin-Opener-Policy handling to the NetworkProcess

Modified: branches/safari-612-branch/Source/WebKitLegacy/mac/WebView/WebHTMLView.mm (285272 => 285273)


--- branches/safari-612-branch/Source/WebKitLegacy/mac/WebView/WebHTMLView.mm	2021-11-04 18:44:52 UTC (rev 285272)
+++ branches/safari-612-branch/Source/WebKitLegacy/mac/WebView/WebHTMLView.mm	2021-11-04 19:38:42 UTC (rev 285273)
@@ -174,6 +174,7 @@
 #import <WebCore/WKGraphics.h>
 #import <WebCore/WebCoreThreadRun.h>
 #import <WebCore/WebEvent.h>
+#import <pal/spi/cf/CFNotificationCenterSPI.h>
 #import <pal/spi/ios/GraphicsServicesSPI.h>
 #endif
 
@@ -832,7 +833,7 @@
 static void hardwareKeyboardAvailabilityChangedCallback(CFNotificationCenterRef, void* observer, CFStringRef, const void*, CFDictionaryRef)
 {
     ASSERT(observer);
-    auto weakWebView = WeakObjCPtr<WebHTMLView>((__bridge WebHTMLView *)observer);
+    WeakObjCPtr<WebHTMLView> weakWebView { (__bridge WebHTMLView *)observer };
     WebThreadRun(^{
         if (auto webView = weakWebView.get()) {
             if (auto* coreFrame = core([webView _frame]))
@@ -2601,7 +2602,9 @@
     [[NSNotificationCenter defaultCenter] 
             addObserver:self selector:@selector(markedTextUpdate:) 
                    name:WebMarkedTextUpdatedNotification object:nil];
-    CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), (__bridge const void *)(self), hardwareKeyboardAvailabilityChangedCallback, (CFStringRef)[NSString stringWithUTF8String:kGSEventHardwareKeyboardAvailabilityChangedNotification], nullptr, CFNotificationSuspensionBehaviorCoalesce);
+    auto notificationName = adoptNS([[NSString alloc] initWithCString:kGSEventHardwareKeyboardAvailabilityChangedNotification encoding:NSUTF8StringEncoding]);
+    auto notificationBehavior = static_cast<CFNotificationSuspensionBehavior>(CFNotificationSuspensionBehaviorCoalesce | _CFNotificationObserverIsObjC);
+    CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), (__bridge const void *)(self), hardwareKeyboardAvailabilityChangedCallback, (__bridge CFStringRef)notificationName.get(), nullptr, notificationBehavior);
 #endif
 
 #if PLATFORM(MAC)
@@ -2618,7 +2621,8 @@
 
 #if PLATFORM(IOS_FAMILY)
     [[NSNotificationCenter defaultCenter] removeObserver:self name:WebMarkedTextUpdatedNotification object:nil];
-    CFNotificationCenterRemoveObserver(CFNotificationCenterGetDarwinNotifyCenter(), (__bridge const void *)(self), (CFStringRef)[NSString stringWithUTF8String:kGSEventHardwareKeyboardAvailabilityChangedNotification], nullptr);
+    auto notificationName = adoptNS([[NSString alloc] initWithCString:kGSEventHardwareKeyboardAvailabilityChangedNotification encoding:NSUTF8StringEncoding]);
+    CFNotificationCenterRemoveObserver(CFNotificationCenterGetDarwinNotifyCenter(), (__bridge const void *)(self), (__bridge CFStringRef)notificationName.get(), nullptr);
 #endif
 
     // We can't assert that close has already been called because
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to