Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: bbb9a28e95477f7f83bb0b2b822d5aebfecf6b44
      
https://github.com/WebKit/WebKit/commit/bbb9a28e95477f7f83bb0b2b822d5aebfecf6b44
  Author: Timothy Hatcher <timo...@apple.com>
  Date:   2022-11-22 (Tue, 22 Nov 2022)

  Changed paths:
    M Source/WebKit/Shared/API/APIObject.h
    M Source/WebKit/Shared/Cocoa/APIObject.mm
    M Source/WebKit/Shared/Cocoa/WKNSArray.mm
    M Source/WebKit/Shared/Cocoa/WKNSDictionary.mm
    M Source/WebKit/UIProcess/Extensions/WebExtension.h
    M Source/WebKit/UIProcess/Extensions/WebExtensionContext.h
    M Source/WebKit/UIProcess/Extensions/WebExtensionController.h
    M Source/WebKit/UIProcess/Extensions/WebExtensionMatchPattern.h
    M Source/WebKit/UIProcess/PageClient.h

  Log Message:
  -----------
  API::Object allocations leak in ObjC ARC due to internal strong wrapper 
reference.
https://bugs.webkit.org/show_bug.cgi?id=248205

Reviewed by Darin Adler and David Kilzer.

The m_wrapper in `API::Object` was counting as a strong reference in objects 
using ObjC ARC.
This was affecting all the new `_WKWebExtension*` API classes.

Changed `m_wrapper` in `API::Object` to be a `CFTypeRef` instead. This hides 
the references from
ARC and continues to let `API::Object` manage the ref counting with 
`CFRetain`/`CFRelease`.

Tested with automated WKWebExtension API tests and manual testing with Xcode's 
memory graph.

* Source/WebKit/Shared/API/APIObject.h:
(API::Object::constructInWrapper): Bridge cast to `CFTypeRef` when setting 
m_wrapper. Use `id <WKObject>`.
(API::Object::wrapper const): Changed to return `id <WKObject>` instead of 
NSObject *. This
better balances with `constructInWrapper()` taking `id <WKObject>`. wrapper() 
is now also limited
to ObjC contexts, like `constructInWrapper()`, which ObjC/ObjC++ files is the 
only place it is used.
The `WKObject` protocol conforms to the `NSObject` protocol, so `NSObject 
<WKObject> *` is redundant.
* Source/WebKit/Shared/Cocoa/APIObject.mm:
(API::Object::ref const): Use `m_wrapper` instead of `wrapper()` since the type 
is now `CFTypeRef`.
(API::Object::deref const): Ditto.
(API::Object::newObject): Bridge cast to `CFTypeRef` when setting m_wrapper.
* Source/WebKit/Shared/Cocoa/WKNSArray.mm:
(-[WKNSArray objectAtIndex:]): Cast `wrapper()` to id to avoid warning about 
NSNull not conforming to `WKObject`.
* Source/WebKit/Shared/Cocoa/WKNSDictionary.mm:
(-[WKNSDictionary objectForKey:]): Ditto.
* Source/WebKit/UIProcess/Extensions/WebExtension.h: Wrap `wrapper()` in `#if 
__OBJC__` to match `API::Object`.
* Source/WebKit/UIProcess/Extensions/WebExtensionContext.h: Ditto.
* Source/WebKit/UIProcess/Extensions/WebExtensionController.h: Ditto.
* Source/WebKit/UIProcess/Extensions/WebExtensionMatchPattern.h: Ditto.
* Source/WebKit/UIProcess/PageClient.h: Added `OBJC_CLASS NSObject;` to fix 
build.

Canonical link: https://commits.webkit.org/256954@main


_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to