macOS: Add support for building clients with ARC enabled (fixes issue #2623).

Under ARC (Automatic Reference Counting), assigning to an Objective-C
pointer has different semantics than assigning to a void* pointer.
This makes it dangerous to treat the same memory address as an
Objective-C pointer in some cases and as a "regular C pointer" in
other cases.

This change removes the conditional type defines and instead uses
void* everywhere. Explicit type casting in combination with ARC
annotations makes it safe to get typed Objective-C pointers from the
void* pointers.

This change enables ARC by default in the CEF binary distribution CMake
configuration for the cefclient and cefsimple sample applications. It can be
disabled by adding `-DOPTION_USE_ARC=Off` to the CMake command line.

ARC is not supported when building Chromium due to the substantial
number of changes that would be required in the Chromium code base.
This commit is contained in:
Jesper Papmehl-Dufay
2019-04-23 17:17:56 +00:00
committed by Marshall Greenblatt
parent 491253fa03
commit 019611c764
22 changed files with 1414 additions and 980 deletions

View File

@@ -82,14 +82,21 @@ class MainMessageLoopExternalPumpMac : public MainMessageLoopExternalPump {
namespace client {
MainMessageLoopExternalPumpMac::MainMessageLoopExternalPumpMac()
: owner_thread_([[NSThread currentThread] retain]), timer_(nil) {
event_handler_ = [[[EventHandler alloc] initWithPump:this] retain];
: owner_thread_([NSThread currentThread]), timer_(nil) {
#if !__has_feature(objc_arc)
[owner_thread_ retain];
#endif // !__has_feature(objc_arc)
event_handler_ = [[EventHandler alloc] initWithPump:this];
}
MainMessageLoopExternalPumpMac::~MainMessageLoopExternalPumpMac() {
KillTimer();
#if !__has_feature(objc_arc)
[owner_thread_ release];
[event_handler_ release];
#endif // !__has_feature(objc_arc)
owner_thread_ = nil;
event_handler_ = nil;
}
void MainMessageLoopExternalPumpMac::Quit() {
@@ -140,11 +147,14 @@ void MainMessageLoopExternalPumpMac::SetTimer(int64 delay_ms) {
DCHECK(!timer_);
const double delay_s = static_cast<double>(delay_ms) / 1000.0;
timer_ = [[NSTimer timerWithTimeInterval:delay_s
target:event_handler_
selector:@selector(timerTimeout:)
userInfo:nil
repeats:NO] retain];
timer_ = [NSTimer timerWithTimeInterval:delay_s
target:event_handler_
selector:@selector(timerTimeout:)
userInfo:nil
repeats:NO];
#if !__has_feature(objc_arc)
[timer_ retain];
#endif // !__has_feature(objc_arc)
// Add the timer to default and tracking runloop modes.
NSRunLoop* owner_runloop = [NSRunLoop currentRunLoop];
@@ -155,7 +165,9 @@ void MainMessageLoopExternalPumpMac::SetTimer(int64 delay_ms) {
void MainMessageLoopExternalPumpMac::KillTimer() {
if (timer_ != nil) {
[timer_ invalidate];
#if !__has_feature(objc_arc)
[timer_ release];
#endif // !__has_feature(objc_arc)
timer_ = nil;
}
}