Diff
Modified: trunk/Source/_javascript_Core/API/JSContext.mm (273609 => 273610)
--- trunk/Source/_javascript_Core/API/JSContext.mm 2021-02-27 01:08:23 UTC (rev 273609)
+++ trunk/Source/_javascript_Core/API/JSContext.mm 2021-02-27 01:54:54 UTC (rev 273610)
@@ -242,13 +242,13 @@
if (!entry->currentArguments) {
JSContext *context = [JSContext currentContext];
size_t count = entry->argumentCount;
- NSMutableArray *arguments = [[NSMutableArray alloc] initWithCapacity:count];
+ auto arguments = adoptNS([[NSMutableArray alloc] initWithCapacity:count]);
for (size_t i = 0; i < count; ++i)
[arguments setObject:[JSValue valueWithJSValueRef:entry->arguments[i] inContext:context] atIndexedSubscript:i];
- entry->currentArguments = arguments;
+ entry->currentArguments = WTFMove(arguments);
}
- return entry->currentArguments;
+ return entry->currentArguments.get();
}
- (JSVirtualMachine *)virtualMachine
@@ -371,7 +371,7 @@
Thread& thread = Thread::current();
[self retain];
CallbackData *prevStack = (CallbackData *)thread.m_apiData;
- *callbackData = (CallbackData){ prevStack, self, [self.exception retain], calleeValue, thisValue, argumentCount, arguments, nil };
+ *callbackData = CallbackData { prevStack, self, self.exception, calleeValue, thisValue, argumentCount, arguments, nil };
thread.m_apiData = callbackData;
self.exception = nil;
}
@@ -379,9 +379,7 @@
- (void)endCallbackWithData:(CallbackData *)callbackData
{
Thread& thread = Thread::current();
- self.exception = callbackData->preservedException;
- [callbackData->preservedException release];
- [callbackData->currentArguments release];
+ self.exception = callbackData->preservedException.get();
thread.m_apiData = callbackData->next;
[self release];
}
Modified: trunk/Source/_javascript_Core/API/JSContextInternal.h (273609 => 273610)
--- trunk/Source/_javascript_Core/API/JSContextInternal.h 2021-02-27 01:08:23 UTC (rev 273609)
+++ trunk/Source/_javascript_Core/API/JSContextInternal.h 2021-02-27 01:54:54 UTC (rev 273610)
@@ -32,12 +32,12 @@
struct CallbackData {
CallbackData* next;
JSContext *context;
- JSValue *preservedException;
+ RetainPtr<JSValue> preservedException;
JSValueRef calleeValue;
JSValueRef thisValue;
size_t argumentCount;
const JSValueRef *arguments;
- NSArray *currentArguments;
+ RetainPtr<NSArray> currentArguments;
};
@class JSWrapperMap;
Modified: trunk/Source/_javascript_Core/API/tests/testapi.mm (273609 => 273610)
--- trunk/Source/_javascript_Core/API/tests/testapi.mm 2021-02-27 01:08:23 UTC (rev 273609)
+++ trunk/Source/_javascript_Core/API/tests/testapi.mm 2021-02-27 01:54:54 UTC (rev 273610)
@@ -53,6 +53,7 @@
#import <wtf/MemoryFootprint.h>
#import <wtf/Optional.h>
#import <wtf/DataLog.h>
+#import <wtf/RetainPtr.h>
extern "C" void JSSynchronousGarbageCollectForDebugging(JSContextRef);
extern "C" void JSSynchronousEdenCollectForDebugging(JSContextRef);
@@ -217,7 +218,7 @@
@implementation TinyDOMNode {
NSMutableArray *m_children;
- JSVirtualMachine *m_sharedVirtualMachine;
+ RetainPtr<JSVirtualMachine> m_sharedVirtualMachine;
}
- (id)initWithVirtualMachine:(JSVirtualMachine *)virtualMachine
@@ -228,9 +229,6 @@
m_children = [[NSMutableArray alloc] initWithCapacity:0];
m_sharedVirtualMachine = virtualMachine;
-#if !__has_feature(objc_arc)
- [m_sharedVirtualMachine retain];
-#endif
return self;
}
Modified: trunk/Source/_javascript_Core/ChangeLog (273609 => 273610)
--- trunk/Source/_javascript_Core/ChangeLog 2021-02-27 01:08:23 UTC (rev 273609)
+++ trunk/Source/_javascript_Core/ChangeLog 2021-02-27 01:54:54 UTC (rev 273610)
@@ -1,3 +1,20 @@
+2021-02-26 Chris Dumez <[email protected]>
+
+ Reduce explicit usage of [objC retain] in WebKit
+ https://bugs.webkit.org/show_bug.cgi?id=222439
+
+ Reviewed by Darin Adler.
+
+ Reduce explicit usage of [objC retain] in WebKit by using RetainPtr<>.
+
+ * API/JSContext.mm:
+ (+[JSContext currentArguments]):
+ (-[JSContext beginCallbackWithData:calleeValue:thisValue:argumentCount:arguments:]):
+ (-[JSContext endCallbackWithData:]):
+ * API/JSContextInternal.h:
+ * API/tests/testapi.mm:
+ (-[TinyDOMNode initWithVirtualMachine:]):
+
2021-02-26 Yusuke Suzuki <[email protected]>
[JSC] Avoid function allocations for non-user-provided Promise then callbacks
Modified: trunk/Source/WebCore/ChangeLog (273609 => 273610)
--- trunk/Source/WebCore/ChangeLog 2021-02-27 01:08:23 UTC (rev 273609)
+++ trunk/Source/WebCore/ChangeLog 2021-02-27 01:54:54 UTC (rev 273610)
@@ -1,3 +1,37 @@
+2021-02-26 Chris Dumez <[email protected]>
+
+ Reduce explicit usage of [objC retain] in WebKit
+ https://bugs.webkit.org/show_bug.cgi?id=222439
+
+ Reviewed by Darin Adler.
+
+ Reduce explicit usage of [objC retain] in WebKit by using RetainPtr<>.
+
+ * accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
+ (-[WebAccessibilityObjectWrapper ALLOW_DEPRECATED_IMPLEMENTATIONS_END]):
+ * editing/cocoa/DataDetection.mm:
+ (WebCore::resultIsURL):
+ * editing/cocoa/HTMLConverter.mm:
+ (WebDefaultFont):
+ * platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.mm:
+ (WebCore::imageDecoderAssetOptions):
+ * platform/graphics/mac/ColorMac.mm:
+ (WebCore::nsColor):
+ * platform/ios/QuickLook.mm:
+ (WebCore::QLPreviewGetSupportedMIMETypesSet):
+ (WebCore::temporaryFileAttributes):
+ (WebCore::temporaryDirectoryAttributes):
+ * platform/ios/WebCoreMotionManager.mm:
+ (-[WebCoreMotionManager checkClientStatus]):
+ * platform/ios/wak/WebCoreThread.mm:
+ (SendMessage):
+ (HandleDelegateSource):
+ (SendDelegateMessage):
+ (WebThreadCallDelegate):
+ (WebRunLoopUnlockInternal):
+ (RunWebThread):
+ (WebThreadNSRunLoop):
+
2021-02-26 Commit Queue <[email protected]>
Unreviewed, reverting r273435.
Modified: trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm (273609 => 273610)
--- trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm 2021-02-27 01:08:23 UTC (rev 273609)
+++ trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm 2021-02-27 01:54:54 UTC (rev 273610)
@@ -1154,29 +1154,29 @@
// All elements should get ShowMenu and ScrollToVisible.
// But certain earlier VoiceOver versions do not support scroll to visible, and it confuses them to see it in the list.
- static NSArray *defaultElementActions = [@[NSAccessibilityShowMenuAction, NSAccessibilityScrollToVisibleAction] retain];
+ static NeverDestroyed<RetainPtr<NSArray>> defaultElementActions = @[NSAccessibilityShowMenuAction, NSAccessibilityScrollToVisibleAction];
// Action elements allow Press.
// The order is important to VoiceOver, which expects the 'default' action to be the first action. In this case the default action should be press.
- static NSArray *actionElementActions = [@[NSAccessibilityPressAction, NSAccessibilityShowMenuAction, NSAccessibilityScrollToVisibleAction] retain];
+ static NeverDestroyed<RetainPtr<NSArray>> actionElementActions = @[NSAccessibilityPressAction, NSAccessibilityShowMenuAction, NSAccessibilityScrollToVisibleAction];
// Menu elements allow Press and Cancel.
- static NSArray *menuElementActions = [[actionElementActions arrayByAddingObject:NSAccessibilityCancelAction] retain];
+ static NeverDestroyed<RetainPtr<NSArray>> menuElementActions = [actionElementActions.get() arrayByAddingObject:NSAccessibilityCancelAction];
// Slider elements allow Increment/Decrement.
- static NSArray *sliderActions = [[defaultElementActions arrayByAddingObjectsFromArray:@[NSAccessibilityIncrementAction, NSAccessibilityDecrementAction]] retain];
+ static NeverDestroyed<RetainPtr<NSArray>> sliderActions = [defaultElementActions.get() arrayByAddingObjectsFromArray:@[NSAccessibilityIncrementAction, NSAccessibilityDecrementAction]];
NSArray *actions;
if (backingObject->supportsPressAction())
- actions = actionElementActions;
+ actions = actionElementActions.get().get();
else if (backingObject->isMenuRelated())
- actions = menuElementActions;
+ actions = menuElementActions.get().get();
else if (backingObject->isSlider())
- actions = sliderActions;
+ actions = sliderActions.get().get();
else if (backingObject->isAttachment())
actions = [[self attachmentView] accessibilityActionNames];
else
- actions = defaultElementActions;
+ actions = defaultElementActions.get().get();
return actions;
}
Modified: trunk/Source/WebCore/editing/cocoa/DataDetection.mm (273609 => 273610)
--- trunk/Source/WebCore/editing/cocoa/DataDetection.mm 2021-02-27 01:08:23 UTC (rev 273609)
+++ trunk/Source/WebCore/editing/cocoa/DataDetection.mm 2021-02-27 01:54:54 UTC (rev 273610)
@@ -215,8 +215,13 @@
if (!result)
return NO;
- static NSSet *urlTypes = [[NSSet setWithObjects: (NSString *)get_DataDetectorsCore_DDBinderHttpURLKey(), (NSString *)get_DataDetectorsCore_DDBinderWebURLKey(), (NSString *)get_DataDetectorsCore_DDBinderMailURLKey(), (NSString *)get_DataDetectorsCore_DDBinderGenericURLKey(), (NSString *)get_DataDetectorsCore_DDBinderEmailKey(), nil] retain];
- return [urlTypes containsObject:(NSString *)softLink_DataDetectorsCore_DDResultGetType(result)];
+ static NeverDestroyed<RetainPtr<NSSet>> urlTypes = [NSSet setWithObjects:
+ (NSString *)get_DataDetectorsCore_DDBinderHttpURLKey(),
+ (NSString *)get_DataDetectorsCore_DDBinderWebURLKey(),
+ (NSString *)get_DataDetectorsCore_DDBinderMailURLKey(),
+ (NSString *)get_DataDetectorsCore_DDBinderGenericURLKey(),
+ (NSString *)get_DataDetectorsCore_DDBinderEmailKey(), nil];
+ return [urlTypes.get() containsObject:(NSString *)softLink_DataDetectorsCore_DDResultGetType(result)];
}
static NSString *constructURLStringForResult(DDResultRef currentResult, NSString *resultIdentifier, NSDate *referenceDate, NSTimeZone *referenceTimeZone, OptionSet<DataDetectorType> detectionTypes)
Modified: trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm (273609 => 273610)
--- trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm 2021-02-27 01:08:23 UTC (rev 273609)
+++ trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm 2021-02-27 01:54:54 UTC (rev 273610)
@@ -415,16 +415,13 @@
// Returns the font to be used if the NSFontAttributeName doesn't exist
static NSFont *WebDefaultFont()
{
- static NSFont *defaultFont = nil;
- if (defaultFont)
- return defaultFont;
-
- NSFont *font = [NSFont fontWithName:@"Helvetica" size:12];
- if (!font)
- font = [NSFont systemFontOfSize:12];
-
- defaultFont = [font retain];
- return defaultFont;
+ static auto defaultFont = makeNeverDestroyed([] {
+ NSFont *font = [NSFont fontWithName:@"Helvetica" size:12];
+ if (!font)
+ font = [NSFont systemFontOfSize:12];
+ return retainPtr(font);
+ }());
+ return defaultFont.get().get();
}
#endif
Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.mm (273609 => 273610)
--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.mm 2021-02-27 01:08:23 UTC (rev 273609)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.mm 2021-02-27 01:54:54 UTC (rev 273610)
@@ -225,13 +225,11 @@
static NSDictionary *imageDecoderAssetOptions()
{
- static NSDictionary *options = [] {
- return [@{
- AVURLAssetReferenceRestrictionsKey: @(AVAssetReferenceRestrictionForbidAll),
- AVURLAssetUsesNoPersistentCacheKey: @YES,
- } retain];
- }();
- return options;
+ static NeverDestroyed<RetainPtr<NSDictionary>> options = @{
+ AVURLAssetReferenceRestrictionsKey: @(AVAssetReferenceRestrictionForbidAll),
+ AVURLAssetUsesNoPersistentCacheKey: @YES,
+ };
+ return options.get().get();
}
class ImageDecoderAVFObjCSample : public MediaSampleAVFObjC {
Modified: trunk/Source/WebCore/platform/graphics/mac/ColorMac.mm (273609 => 273610)
--- trunk/Source/WebCore/platform/graphics/mac/ColorMac.mm 2021-02-27 01:08:23 UTC (rev 273609)
+++ trunk/Source/WebCore/platform/graphics/mac/ColorMac.mm 2021-02-27 01:54:54 UTC (rev 273610)
@@ -116,16 +116,16 @@
if (color.isInline()) {
switch (PackedColor::RGBA { color.asInline() }.value) {
case PackedColor::RGBA { Color::transparentBlack }.value: {
- static NSColor *clearColor = [[NSColor colorWithSRGBRed:0 green:0 blue:0 alpha:0] retain];
- return clearColor;
+ static NeverDestroyed<RetainPtr<NSColor>> clearColor = [NSColor colorWithSRGBRed:0 green:0 blue:0 alpha:0];
+ return clearColor.get().get();
}
case PackedColor::RGBA { Color::black }.value: {
- static NSColor *blackColor = [[NSColor colorWithSRGBRed:0 green:0 blue:0 alpha:1] retain];
- return blackColor;
+ static NeverDestroyed<RetainPtr<NSColor>> blackColor = [NSColor colorWithSRGBRed:0 green:0 blue:0 alpha:1];
+ return blackColor.get().get();
}
case PackedColor::RGBA { Color::white }.value: {
- static NSColor *whiteColor = [[NSColor colorWithSRGBRed:1 green:1 blue:1 alpha:1] retain];
- return whiteColor;
+ static NeverDestroyed<RetainPtr<NSColor>> whiteColor = [NSColor colorWithSRGBRed:1 green:1 blue:1 alpha:1];
+ return whiteColor.get().get();
}
}
}
Modified: trunk/Source/WebCore/platform/ios/QuickLook.mm (273609 => 273610)
--- trunk/Source/WebCore/platform/ios/QuickLook.mm 2021-02-27 01:08:23 UTC (rev 273609)
+++ trunk/Source/WebCore/platform/ios/QuickLook.mm 2021-02-27 01:54:54 UTC (rev 273610)
@@ -41,8 +41,8 @@
NSSet *QLPreviewGetSupportedMIMETypesSet()
{
- static NSSet *set = [PAL::softLink_QuickLook_QLPreviewGetSupportedMIMETypes() retain];
- return set;
+ static NeverDestroyed<RetainPtr<NSSet>> set = PAL::softLink_QuickLook_QLPreviewGetSupportedMIMETypes();
+ return set.get().get();
}
static Lock qlPreviewConverterDictionaryLock;
@@ -102,21 +102,21 @@
static NSDictionary *temporaryFileAttributes()
{
- static NSDictionary *attributes = [@{
+ static NeverDestroyed<RetainPtr<NSDictionary>> attributes = @{
NSFileOwnerAccountName : NSUserName(),
NSFilePosixPermissions : [NSNumber numberWithInteger:(WEB_UREAD | WEB_UWRITE)],
- } retain];
- return attributes;
+ };
+ return attributes.get().get();
}
static NSDictionary *temporaryDirectoryAttributes()
{
- static NSDictionary *attributes = [@{
+ static NeverDestroyed<RetainPtr<NSDictionary>> attributes = @{
NSFileOwnerAccountName : NSUserName(),
NSFilePosixPermissions : [NSNumber numberWithInteger:(WEB_UREAD | WEB_UWRITE | WEB_UEXEC)],
NSFileProtectionKey : NSFileProtectionCompleteUnlessOpen,
- } retain];
- return attributes;
+ };
+ return attributes.get().get();
}
NSString *createTemporaryFileForQuickLook(NSString *fileName)
Modified: trunk/Source/WebCore/platform/ios/WebCoreMotionManager.mm (273609 => 273610)
--- trunk/Source/WebCore/platform/ios/WebCoreMotionManager.mm 2021-02-27 01:08:23 UTC (rev 273609)
+++ trunk/Source/WebCore/platform/ios/WebCoreMotionManager.mm 2021-02-27 01:54:54 UTC (rev 273610)
@@ -178,13 +178,8 @@
if (m_headingAvailable)
[m_locationManager startUpdatingHeading];
- if (!m_updateTimer) {
- m_updateTimer = [[NSTimer scheduledTimerWithTimeInterval:kMotionUpdateInterval
- target:self
- selector:@selector(update)
- userInfo:nil
- repeats:YES] retain];
- }
+ if (!m_updateTimer)
+ m_updateTimer = [NSTimer scheduledTimerWithTimeInterval:kMotionUpdateInterval target:self selector:@selector(update) userInfo:nil repeats:YES];
} else {
[m_updateTimer invalidate];
m_updateTimer = nil;
Modified: trunk/Source/WebCore/platform/ios/wak/WebCoreThread.mm (273609 => 273610)
--- trunk/Source/WebCore/platform/ios/wak/WebCoreThread.mm 2021-02-27 01:08:23 UTC (rev 273609)
+++ trunk/Source/WebCore/platform/ios/wak/WebCoreThread.mm 2021-02-27 01:54:54 UTC (rev 273610)
@@ -47,6 +47,7 @@
#import <objc/runtime.h>
#import <wtf/Assertions.h>
#import <wtf/MainThread.h>
+#import <wtf/NeverDestroyed.h>
#import <wtf/RecursiveLockAdapter.h>
#import <wtf/RunLoop.h>
#import <wtf/ThreadSpecific.h>
@@ -111,7 +112,6 @@
static void* autoreleasePoolMark;
static CFRunLoopRef webThreadRunLoop;
-static NSRunLoop* webThreadNSRunLoop;
static pthread_t webThread;
static BOOL isWebThreadLocked;
static BOOL webThreadStarted;
@@ -127,11 +127,8 @@
static CFRunLoopSourceRef WebThreadReleaseSource;
static CFMutableArrayRef WebThreadReleaseObjArray;
-static void MainThreadAdoptAndRelease(id obj);
-
static Lock delegateLock;
static StaticCondition delegateCondition;
-static NSInvocation* delegateInvocation;
static CFRunLoopSourceRef delegateSource = nullptr;
static BOOL delegateHandled;
#if LOG_MAIN_THREAD_LOCKING
@@ -161,14 +158,30 @@
return asyncDelegates;
}
+static RetainPtr<NSRunLoop>& webThreadNSRunLoop()
+{
+ static NeverDestroyed<RetainPtr<NSRunLoop>> webThreadNSRunLoop;
+ return webThreadNSRunLoop;
+}
+
+static RetainPtr<NSInvocation>& delegateInvocation()
+{
+ static NeverDestroyed<RetainPtr<NSInvocation>> delegateInvocation;
+ return delegateInvocation;
+}
+
WEBCORE_EXPORT volatile unsigned webThreadDelegateMessageScopeCount = 0;
static bool perCalloutAutoreleasepoolEnabled;
-static inline void SendMessage(NSInvocation* invocation)
+static inline void SendMessage(RetainPtr<NSInvocation>&& invocation)
{
[invocation invoke];
- MainThreadAdoptAndRelease(invocation);
+
+ if (!WebThreadIsEnabled() || CFRunLoopGetMain() == CFRunLoopGetCurrent())
+ return;
+
+ RunLoop::main().dispatch([invocation = WTFMove(invocation)] { });
}
static void HandleDelegateSource(void*)
@@ -185,15 +198,15 @@
auto locker = holdLock(delegateLock);
#if LOG_MESSAGES
- if ([[delegateInvocation target] isKindOfClass:[NSNotificationCenter class]]) {
+ if ([[delegateInvocation() target] isKindOfClass:[NSNotificationCenter class]]) {
id argument0;
- [delegateInvocation getArgument:&argument0 atIndex:0];
+ [delegateInvocation() getArgument:&argument0 atIndex:0];
NSLog(@"notification receive: %@", argument0);
} else
- NSLog(@"delegate receive: %@", NSStringFromSelector([delegateInvocation selector]));
+ NSLog(@"delegate receive: %@", NSStringFromSelector([delegateInvocation() selector]));
#endif
- SendMessage(delegateInvocation);
+ SendMessage(WTFMove(delegateInvocation()));
delegateHandled = YES;
delegateCondition.notifyOne();
@@ -214,10 +227,10 @@
}
};
-static void SendDelegateMessage(NSInvocation* invocation)
+static void SendDelegateMessage(RetainPtr<NSInvocation>&& invocation)
{
if (!WebThreadIsCurrent()) {
- SendMessage(invocation);
+ SendMessage(WTFMove(invocation));
return;
}
@@ -224,16 +237,16 @@
ASSERT(delegateSource);
delegateLock.lock();
- delegateInvocation = invocation;
+ delegateInvocation() = WTFMove(invocation);
delegateHandled = NO;
#if LOG_MESSAGES
- if ([[delegateInvocation target] isKindOfClass:[NSNotificationCenter class]]) {
+ if ([[delegateInvocation() target] isKindOfClass:[NSNotificationCenter class]]) {
id argument0;
- [delegateInvocation getArgument:&argument0 atIndex:0];
+ [delegateInvocation() getArgument:&argument0 atIndex:0];
NSLog(@"notification send: %@", argument0);
} else
- NSLog(@"delegate send: %@", NSStringFromSelector([delegateInvocation selector]));
+ NSLog(@"delegate send: %@", NSStringFromSelector([delegateInvocation() selector]));
#endif
{
@@ -248,10 +261,10 @@
while (!delegateHandled) {
if (!delegateCondition.waitFor(delegateLock, DelegateWaitInterval)) {
id delegateInformation;
- if ([[delegateInvocation target] isKindOfClass:[NSNotificationCenter class]])
- [delegateInvocation getArgument:&delegateInformation atIndex:0];
+ if ([[delegateInvocation() target] isKindOfClass:[NSNotificationCenter class]])
+ [delegateInvocation() getArgument:&delegateInformation atIndex:0];
else
- delegateInformation = NSStringFromSelector([delegateInvocation selector]);
+ delegateInformation = NSStringFromSelector([delegateInvocation() selector]);
CFStringRef mode = CFRunLoopCopyCurrentMode(CFRunLoopGetMain());
NSLog(@"%s: delegate (%@) failed to return after waiting %f seconds. main run loop mode: %@", __PRETTY_FUNCTION__, delegateInformation, DelegateWaitInterval.seconds(), mode);
@@ -282,19 +295,6 @@
_WebThreadLock();
}
-static void MainThreadAdoptAndRelease(id obj)
-{
- auto adoptedObj = adoptNS(obj);
- if (!WebThreadIsEnabled() || CFRunLoopGetMain() == CFRunLoopGetCurrent())
- return;
-#if LOG_RELEASES
- NSLog(@"Release send [web thread] : %@", obj);
-#endif
- // We own obj at this point, so we don't need the block to implicitly
- // retain it.
- RunLoop::main().dispatch([adoptedObj = WTFMove(adoptedObj)] { });
-}
-
void WebThreadAdoptAndRelease(id obj)
{
ASSERT(!WebThreadIsCurrent());
@@ -426,7 +426,7 @@
void WebThreadCallDelegate(NSInvocation* invocation)
{
// NSInvocation released in SendMessage()
- SendDelegateMessage([invocation retain]);
+ SendDelegateMessage(invocation);
}
void WebThreadPostNotification(NSString* name, id object, id userInfo)
@@ -505,7 +505,7 @@
ASSERT(sAsyncDelegates());
if ([sAsyncDelegates() count]) {
for (NSInvocation* invocation in sAsyncDelegates().get())
- SendDelegateMessage([invocation retain]);
+ SendDelegateMessage(invocation);
[sAsyncDelegates() removeAllObjects];
}
@@ -632,7 +632,7 @@
webThreadContext = CurrentThreadContext();
webThreadRunLoop = CFRunLoopGetCurrent();
- webThreadNSRunLoop = [[NSRunLoop currentRunLoop] retain];
+ webThreadNSRunLoop() = [NSRunLoop currentRunLoop];
CFRunLoopObserverRef webRunLoopLockObserverRef = CFRunLoopObserverCreate(nullptr, kCFRunLoopBeforeTimers | kCFRunLoopBeforeSources | kCFRunLoopAfterWaiting, YES, 0, WebRunLoopLock, nullptr);
CFRunLoopAddObserver(webThreadRunLoop, webRunLoopLockObserverRef, kCFRunLoopCommonModes);
@@ -898,8 +898,8 @@
NSRunLoop* WebThreadNSRunLoop(void)
{
if (webThreadStarted) {
- ASSERT(webThreadNSRunLoop);
- return webThreadNSRunLoop;
+ ASSERT(webThreadNSRunLoop());
+ return webThreadNSRunLoop().get();
}
return [NSRunLoop currentRunLoop];
Modified: trunk/Source/WebKit/ChangeLog (273609 => 273610)
--- trunk/Source/WebKit/ChangeLog 2021-02-27 01:08:23 UTC (rev 273609)
+++ trunk/Source/WebKit/ChangeLog 2021-02-27 01:54:54 UTC (rev 273610)
@@ -1,3 +1,29 @@
+2021-02-26 Chris Dumez <[email protected]>
+
+ Reduce explicit usage of [objC retain] in WebKit
+ https://bugs.webkit.org/show_bug.cgi?id=222439
+
+ Reviewed by Darin Adler.
+
+ Reduce explicit usage of [objC retain] in WebKit by using RetainPtr<>.
+
+ * NetworkProcess/Downloads/cocoa/DownloadCocoa.mm:
+ (WebKit::Download::resume):
+ * Shared/Cocoa/WebPreferencesDefaultValuesCocoa.mm:
+ (WebKit::isFeatureFlagEnabled):
+ * UIProcess/API/Cocoa/APIContentRuleListStoreCocoa.mm:
+ (API::ContentRuleListStore::defaultStorePath):
+ * UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
+ (+[WKWebsiteDataStore _allWebsiteDataTypesIncludingPrivate]):
+ * UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
+ (WebKit::WebsiteDataStore::tempDirectoryFileSystemRepresentation):
+ (WebKit::WebsiteDataStore::cacheDirectoryFileSystemRepresentation):
+ (WebKit::WebsiteDataStore::websiteDataDirectoryFileSystemRepresentation):
+ * UIProcess/ios/WKContentViewInteraction.mm:
+ (-[WKContentView keyCommands]):
+ * WebProcess/Plugins/PDF/PDFPlugin.mm:
+ (-[WKPDFPluginAccessibilityObject ALLOW_DEPRECATED_IMPLEMENTATIONS_END]):
+
2021-02-26 Commit Queue <[email protected]>
Unreviewed, reverting r273560.
Modified: trunk/Source/WebKit/NetworkProcess/Downloads/cocoa/DownloadCocoa.mm (273609 => 273610)
--- trunk/Source/WebKit/NetworkProcess/Downloads/cocoa/DownloadCocoa.mm 2021-02-27 01:08:23 UTC (rev 273609)
+++ trunk/Source/WebKit/NetworkProcess/Downloads/cocoa/DownloadCocoa.mm 2021-02-27 01:54:54 UTC (rev 273610)
@@ -51,15 +51,15 @@
// FIXME: This is a temporary workaround for <rdar://problem/34745171>. Fixed in iOS 13 and macOS 10.15, but we still need to support macOS 10.14 for now.
#if USE(LEGACY_CFNETWORK_DOWNLOADS)
- static NSSet<Class> *plistClasses = nil;
+ static NeverDestroyed<RetainPtr<NSSet<Class>>> plistClasses;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
- plistClasses = [[NSSet setWithObjects:[NSDictionary class], [NSArray class], [NSString class], [NSNumber class], [NSData class], [NSURL class], [NSURLRequest class], nil] retain];
+ plistClasses.get() = [NSSet setWithObjects:[NSDictionary class], [NSArray class], [NSString class], [NSNumber class], [NSData class], [NSURL class], [NSURLRequest class], nil];
});
auto unarchiver = adoptNS([[NSKeyedUnarchiver alloc] initForReadingFromData:nsData.get() error:nil]);
[unarchiver setDecodingFailurePolicy:NSDecodingFailurePolicyRaiseException];
- auto dictionary = adoptNS(static_cast<NSMutableDictionary *>([[unarchiver decodeObjectOfClasses:plistClasses forKey:@"NSKeyedArchiveRootObjectKey"] mutableCopy]));
+ auto dictionary = adoptNS(static_cast<NSMutableDictionary *>([[unarchiver decodeObjectOfClasses:plistClasses.get().get() forKey:@"NSKeyedArchiveRootObjectKey"] mutableCopy]));
[unarchiver finishDecoding];
[dictionary setObject:static_cast<NSString*>(path) forKey:@"NSURLSessionResumeInfoLocalPath"];
auto encoder = adoptNS([[NSKeyedArchiver alloc] initRequiringSecureCoding:YES]);
Modified: trunk/Source/WebKit/Shared/Cocoa/WebPreferencesDefaultValuesCocoa.mm (273609 => 273610)
--- trunk/Source/WebKit/Shared/Cocoa/WebPreferencesDefaultValuesCocoa.mm 2021-02-27 01:08:23 UTC (rev 273609)
+++ trunk/Source/WebKit/Shared/Cocoa/WebPreferencesDefaultValuesCocoa.mm 2021-02-27 01:54:54 UTC (rev 273610)
@@ -45,12 +45,12 @@
if (!isWebKitBundleFromStagedFramework)
return _os_feature_enabled_impl("WebKit", (const char*)featureName.utf8().data());
- static NSDictionary* dictionary = [[NSDictionary dictionaryWithContentsOfFile:@"/Library/Apple/System/Library/FeatureFlags/Domain/WebKit.plist"] retain];
+ static NeverDestroyed<RetainPtr<NSDictionary>> dictionary = [NSDictionary dictionaryWithContentsOfFile:@"/Library/Apple/System/Library/FeatureFlags/Domain/WebKit.plist"];
- if (![[dictionary objectForKey:featureName] objectForKey:@"Enabled"])
+ if (![[dictionary.get() objectForKey:featureName] objectForKey:@"Enabled"])
return _os_feature_enabled_impl("WebKit", (const char*)featureName.characters8());
- return [[[dictionary objectForKey:featureName] objectForKey:@"Enabled"] isKindOfClass:[NSNumber class]] && [[[dictionary objectForKey:featureName] objectForKey:@"Enabled"] boolValue];
+ return [[[dictionary.get() objectForKey:featureName] objectForKey:@"Enabled"] isKindOfClass:[NSNumber class]] && [[[dictionary.get() objectForKey:featureName] objectForKey:@"Enabled"] boolValue];
}
} // namespace WebKit
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/APIContentRuleListStoreCocoa.mm (273609 => 273610)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/APIContentRuleListStoreCocoa.mm 2021-02-27 01:08:23 UTC (rev 273609)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/APIContentRuleListStoreCocoa.mm 2021-02-27 01:54:54 UTC (rev 273610)
@@ -36,7 +36,7 @@
WTF::String ContentRuleListStore::defaultStorePath(bool legacyFilename)
{
static dispatch_once_t onceToken;
- static NSURL *contentRuleListStoreURL;
+ static NeverDestroyed<RetainPtr<NSURL>> contentRuleListStoreURL;
dispatch_once(&onceToken, ^{
NSURL *url = "" defaultManager] URLForDirectory:NSLibraryDirectory inDomain:NSUserDomainMask appropriateForURL:nullptr create:NO error:nullptr];
@@ -53,15 +53,15 @@
}
if (legacyFilename)
- contentRuleListStoreURL = [[url URLByAppendingPathComponent:@"ContentExtensions" isDirectory:YES] retain];
+ contentRuleListStoreURL.get() = [url URLByAppendingPathComponent:@"ContentExtensions" isDirectory:YES];
else
- contentRuleListStoreURL = [[url URLByAppendingPathComponent:@"ContentRuleLists" isDirectory:YES] retain];
+ contentRuleListStoreURL.get() = [url URLByAppendingPathComponent:@"ContentRuleLists" isDirectory:YES];
});
- if (![[NSFileManager defaultManager] createDirectoryAtURL:contentRuleListStoreURL withIntermediateDirectories:YES attributes:nil error:nullptr])
- LOG_ERROR("Failed to create directory %@", contentRuleListStoreURL);
+ if (![[NSFileManager defaultManager] createDirectoryAtURL:contentRuleListStoreURL.get().get() withIntermediateDirectories:YES attributes:nil error:nullptr])
+ LOG_ERROR("Failed to create directory %@", contentRuleListStoreURL.get().get());
- return contentRuleListStoreURL.absoluteURL.path.fileSystemRepresentation;
+ return [contentRuleListStoreURL.get() absoluteURL].path.fileSystemRepresentation;
}
} // namespace API
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm (273609 => 273610)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm 2021-02-27 01:08:23 UTC (rev 273609)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm 2021-02-27 01:54:54 UTC (rev 273610)
@@ -231,7 +231,7 @@
+ (NSSet<NSString *> *)_allWebsiteDataTypesIncludingPrivate
{
static dispatch_once_t onceToken;
- static NSSet *allWebsiteDataTypes;
+ static NeverDestroyed<RetainPtr<NSSet>> allWebsiteDataTypes;
dispatch_once(&onceToken, ^ {
auto *privateTypes = @[
_WKWebsiteDataTypeHSTSCache,
@@ -247,10 +247,10 @@
#endif
];
- allWebsiteDataTypes = [[[self allWebsiteDataTypes] setByAddingObjectsFromArray:privateTypes] retain];
+ allWebsiteDataTypes.get() = [[self allWebsiteDataTypes] setByAddingObjectsFromArray:privateTypes];
});
- return allWebsiteDataTypes;
+ return allWebsiteDataTypes.get().get();
}
+ (BOOL)_defaultDataStoreExists
Modified: trunk/Source/WebKit/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm (273609 => 273610)
--- trunk/Source/WebKit/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm 2021-02-27 01:08:23 UTC (rev 273609)
+++ trunk/Source/WebKit/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm 2021-02-27 01:54:54 UTC (rev 273610)
@@ -332,7 +332,7 @@
WTF::String WebsiteDataStore::tempDirectoryFileSystemRepresentation(const WTF::String& directoryName, ShouldCreateDirectory shouldCreateDirectory)
{
static dispatch_once_t onceToken;
- static NSURL *tempURL;
+ static NeverDestroyed<RetainPtr<NSURL>> tempURL;
dispatch_once(&onceToken, ^{
NSURL *url = "" fileURLWithPath:NSTemporaryDirectory() isDirectory:YES];
@@ -346,10 +346,10 @@
url = "" URLByAppendingPathComponent:bundleIdentifier isDirectory:YES];
}
- tempURL = [[url URLByAppendingPathComponent:@"WebKit" isDirectory:YES] retain];
+ tempURL.get() = [url URLByAppendingPathComponent:@"WebKit" isDirectory:YES];
});
- NSURL *url = "" URLByAppendingPathComponent:directoryName isDirectory:YES];
+ NSURL *url = "" URLByAppendingPathComponent:directoryName isDirectory:YES];
if (shouldCreateDirectory == ShouldCreateDirectory::Yes
&& (![[NSFileManager defaultManager] createDirectoryAtURL:url withIntermediateDirectories:YES attributes:nil error:nullptr]))
@@ -361,7 +361,7 @@
WTF::String WebsiteDataStore::cacheDirectoryFileSystemRepresentation(const WTF::String& directoryName, ShouldCreateDirectory shouldCreateDirectory)
{
static dispatch_once_t onceToken;
- static NSURL *cacheURL;
+ static NeverDestroyed<RetainPtr<NSURL>> cacheURL;
dispatch_once(&onceToken, ^{
NSURL *url = "" defaultManager] URLForDirectory:NSCachesDirectory inDomain:NSUserDomainMask appropriateForURL:nullptr create:NO error:nullptr];
@@ -375,10 +375,10 @@
url = "" URLByAppendingPathComponent:bundleIdentifier isDirectory:YES];
}
- cacheURL = [[url URLByAppendingPathComponent:@"WebKit" isDirectory:YES] retain];
+ cacheURL.get() = [url URLByAppendingPathComponent:@"WebKit" isDirectory:YES];
});
- NSURL *url = "" URLByAppendingPathComponent:directoryName isDirectory:YES];
+ NSURL *url = "" URLByAppendingPathComponent:directoryName isDirectory:YES];
if (shouldCreateDirectory == ShouldCreateDirectory::Yes
&& ![[NSFileManager defaultManager] createDirectoryAtURL:url withIntermediateDirectories:YES attributes:nil error:nullptr])
LOG_ERROR("Failed to create directory %@", url);
@@ -389,7 +389,7 @@
WTF::String WebsiteDataStore::websiteDataDirectoryFileSystemRepresentation(const WTF::String& directoryName)
{
static dispatch_once_t onceToken;
- static NSURL *websiteDataURL;
+ static NeverDestroyed<RetainPtr<NSURL>> websiteDataURL;
dispatch_once(&onceToken, ^{
NSURL *url = "" defaultManager] URLForDirectory:NSLibraryDirectory inDomain:NSUserDomainMask appropriateForURL:nullptr create:NO error:nullptr];
@@ -405,10 +405,10 @@
url = "" URLByAppendingPathComponent:bundleIdentifier isDirectory:YES];
}
- websiteDataURL = [[url URLByAppendingPathComponent:@"WebsiteData" isDirectory:YES] retain];
+ websiteDataURL.get() = [url URLByAppendingPathComponent:@"WebsiteData" isDirectory:YES];
});
- NSURL *url = "" URLByAppendingPathComponent:directoryName isDirectory:YES];
+ NSURL *url = "" URLByAppendingPathComponent:directoryName isDirectory:YES];
if (![[NSFileManager defaultManager] createDirectoryAtURL:url withIntermediateDirectories:YES attributes:nil error:nullptr])
LOG_ERROR("Failed to create directory %@", url);
Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (273609 => 273610)
--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm 2021-02-27 01:08:23 UTC (rev 273609)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm 2021-02-27 01:54:54 UTC (rev 273610)
@@ -4503,11 +4503,11 @@
if (!_page->editorState().isContentEditable)
return nil;
- static NSArray* editableKeyCommands = [@[
+ static NeverDestroyed<RetainPtr<NSArray>> editableKeyCommands = @[
[UIKeyCommand keyCommandWithInput:@"\t" modifierFlags:0 action:@selector(_nextAccessoryTab:)],
[UIKeyCommand keyCommandWithInput:@"\t" modifierFlags:UIKeyModifierShift action:@selector(_previousAccessoryTab:)]
- ] retain];
- return editableKeyCommands;
+ ];
+ return editableKeyCommands.get().get();
}
#endif
Modified: trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm (273609 => 273610)
--- trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm 2021-02-27 01:08:23 UTC (rev 273609)
+++ trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm 2021-02-27 01:54:54 UTC (rev 273610)
@@ -253,25 +253,20 @@
- (NSArray *)accessibilityAttributeNames
ALLOW_DEPRECATED_IMPLEMENTATIONS_END
{
- static NSArray *attributeNames = 0;
+ static NeverDestroyed<RetainPtr<NSArray>> attributeNames = @[
+ NSAccessibilityParentAttribute,
+ NSAccessibilityWindowAttribute,
+ NSAccessibilityTopLevelUIElementAttribute,
+ NSAccessibilityRoleDescriptionAttribute,
+ NSAccessibilitySizeAttribute,
+ NSAccessibilityEnabledAttribute,
+ NSAccessibilityPositionAttribute,
+ NSAccessibilityFocusedAttribute,
+ // PDFLayerController has its own accessibilityChildren.
+ NSAccessibilityChildrenAttribute
+ ];
- if (!attributeNames) {
- attributeNames = @[
- NSAccessibilityParentAttribute,
- NSAccessibilityWindowAttribute,
- NSAccessibilityTopLevelUIElementAttribute,
- NSAccessibilityRoleDescriptionAttribute,
- NSAccessibilitySizeAttribute,
- NSAccessibilityEnabledAttribute,
- NSAccessibilityPositionAttribute,
- NSAccessibilityFocusedAttribute,
- // PDFLayerController has its own accessibilityChildren.
- NSAccessibilityChildrenAttribute
- ];
- [attributeNames retain];
- }
-
- return attributeNames;
+ return attributeNames.get().get();
}
ALLOW_DEPRECATED_IMPLEMENTATIONS_BEGIN
Modified: trunk/Source/WebKitLegacy/mac/ChangeLog (273609 => 273610)
--- trunk/Source/WebKitLegacy/mac/ChangeLog 2021-02-27 01:08:23 UTC (rev 273609)
+++ trunk/Source/WebKitLegacy/mac/ChangeLog 2021-02-27 01:54:54 UTC (rev 273610)
@@ -1,3 +1,38 @@
+2021-02-26 Chris Dumez <[email protected]>
+
+ Reduce explicit usage of [objC retain] in WebKit
+ https://bugs.webkit.org/show_bug.cgi?id=222439
+
+ Reviewed by Darin Adler.
+
+ Reduce explicit usage of [objC retain] in WebKit by using RetainPtr<>.
+
+ * Misc/WebNSURLExtras.mm:
+ (-[NSString _webkit_rangeOfURLScheme]):
+ * Misc/WebStringTruncator.mm:
+ (+[WebStringTruncator centerTruncateString:toWidth:]):
+ * Storage/WebStorageManager.mm:
+ (+[WebStorageManager _storageDirectoryPath]):
+ * WebCoreSupport/WebEditorClient.mm:
+ (_WebCreateFragment):
+ * WebView/WebHTMLRepresentation.mm:
+ (+[WebHTMLRepresentation supportedMIMETypes]):
+ (+[WebHTMLRepresentation supportedMediaMIMETypes]):
+ (+[WebHTMLRepresentation supportedNonImageMIMETypes]):
+ (+[WebHTMLRepresentation supportedImageMIMETypes]):
+ (+[WebHTMLRepresentation unsupportedTextMIMETypes]):
+ * WebView/WebPreferencesDefaultValues.mm:
+ (WebKit::isFeatureFlagEnabled):
+ * WebView/WebView.mm:
+ (-[WebView _commonInitializationWithFrameName:groupName:]):
+ (-[WebView initSimpleHTMLDocumentWithStyle:frame:preferences:groupName:]):
+ (-[WebView _close]):
+ (-[WebView _checkDidPerformFirstNavigation]):
+ (-[WebView setPreferences:]):
+ (-[WebView preferences]):
+ (-[WebView setGroupName:]):
+ * WebView/WebViewData.h:
+
2021-02-25 Truitt Savell <[email protected]>
Unreviewed, reverting r273462.
Modified: trunk/Source/WebKitLegacy/mac/Misc/WebNSURLExtras.mm (273609 => 273610)
--- trunk/Source/WebKitLegacy/mac/Misc/WebNSURLExtras.mm 2021-02-27 01:08:23 UTC (rev 273609)
+++ trunk/Source/WebKitLegacy/mac/Misc/WebNSURLExtras.mm 2021-02-27 01:54:54 UTC (rev 273610)
@@ -276,8 +276,7 @@
NSRange colon = [self rangeOfString:@":"];
if (colon.location != NSNotFound && colon.location > 0) {
NSRange scheme = {0, colon.location};
- static NSCharacterSet *InverseSchemeCharacterSet = nil;
- if (!InverseSchemeCharacterSet) {
+ static auto inverseSchemeCharacterSet = makeNeverDestroyed([] {
/*
This stuff is very expensive. 10-15 msec on a 2x1.2GHz. If not cached it swamps
everything else when adding items to the autocomplete DB. Makes me wonder if we
@@ -284,9 +283,9 @@
even need to enforce the character set here.
*/
NSString *acceptableCharacters = @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+.-";
- InverseSchemeCharacterSet = [[[NSCharacterSet characterSetWithCharactersInString:acceptableCharacters] invertedSet] retain];
- }
- NSRange illegals = [self rangeOfCharacterFromSet:InverseSchemeCharacterSet options:0 range:scheme];
+ return retainPtr([[NSCharacterSet characterSetWithCharactersInString:acceptableCharacters] invertedSet]);
+ }());
+ NSRange illegals = [self rangeOfCharacterFromSet:inverseSchemeCharacterSet.get().get() options:0 range:scheme];
if (illegals.location == NSNotFound)
return scheme;
}
Modified: trunk/Source/WebKitLegacy/mac/Misc/WebStringTruncator.mm (273609 => 273610)
--- trunk/Source/WebKitLegacy/mac/Misc/WebStringTruncator.mm 2021-02-27 01:08:23 UTC (rev 273609)
+++ trunk/Source/WebKitLegacy/mac/Misc/WebStringTruncator.mm 2021-02-27 01:54:54 UTC (rev 273610)
@@ -58,13 +58,13 @@
+ (NSString *)centerTruncateString:(NSString *)string toWidth:(float)maxWidth
{
- static NSFont *menuFont = [[NSFont menuFontOfSize:0] retain];
+ static NeverDestroyed<RetainPtr<NSFont>> menuFont = [NSFont menuFontOfSize:0];
- ASSERT(menuFont);
- if (!menuFont)
+ ASSERT(menuFont.get());
+ if (!menuFont.get())
return nil;
- return WebCore::StringTruncator::centerTruncate(string, maxWidth, fontFromNSFont(menuFont));
+ return WebCore::StringTruncator::centerTruncate(string, maxWidth, fontFromNSFont(menuFont.get().get()));
}
+ (NSString *)centerTruncateString:(NSString *)string toWidth:(float)maxWidth withFont:(NSFont *)font
Modified: trunk/Source/WebKitLegacy/mac/Storage/WebStorageManager.mm (273609 => 273610)
--- trunk/Source/WebKitLegacy/mac/Storage/WebStorageManager.mm 2021-02-27 01:08:23 UTC (rev 273609)
+++ trunk/Source/WebKitLegacy/mac/Storage/WebStorageManager.mm 2021-02-27 01:54:54 UTC (rev 273610)
@@ -97,19 +97,19 @@
+ (NSString *)_storageDirectoryPath
{
- static NSString *sLocalStoragePath;
+ static NeverDestroyed<RetainPtr<NSString>> sLocalStoragePath;
static dispatch_once_t flag;
dispatch_once(&flag, ^{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
- sLocalStoragePath = [defaults objectForKey:WebStorageDirectoryDefaultsKey];
- if (!sLocalStoragePath || ![sLocalStoragePath isKindOfClass:[NSString class]]) {
+ RetainPtr<NSString> localStoragePath = [defaults objectForKey:WebStorageDirectoryDefaultsKey];
+ if (!localStoragePath || ![localStoragePath isKindOfClass:[NSString class]]) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *libraryDirectory = [paths objectAtIndex:0];
- sLocalStoragePath = [libraryDirectory stringByAppendingPathComponent:@"WebKit/LocalStorage"];
+ localStoragePath = [libraryDirectory stringByAppendingPathComponent:@"WebKit/LocalStorage"];
}
- sLocalStoragePath = [[sLocalStoragePath stringByStandardizingPath] retain];
+ sLocalStoragePath.get() = [localStoragePath stringByStandardizingPath];
});
- return sLocalStoragePath;
+ return sLocalStoragePath.get().get();
}
+ (void)setStorageDatabaseIdleInterval:(double)interval
Modified: trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.mm (273609 => 273610)
--- trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.mm 2021-02-27 01:08:23 UTC (rev 273609)
+++ trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.mm 2021-02-27 01:54:54 UTC (rev 273610)
@@ -459,10 +459,10 @@
void _WebCreateFragment(Document& document, NSAttributedString *string, FragmentAndResources& result)
{
- static NSDictionary *documentAttributes = [attributesForAttributedStringConversion() retain];
+ static NeverDestroyed<RetainPtr<NSDictionary>> documentAttributes = attributesForAttributedStringConversion();
NSArray *subresources;
DOMDocumentFragment* fragment = [string _documentFromRange:NSMakeRange(0, [string length])
- document:kit(&document) documentAttributes:documentAttributes subresources:&subresources];
+ document:kit(&document) documentAttributes:documentAttributes.get().get() subresources:&subresources];
result.fragment = core(fragment);
for (WebResource* resource in subresources)
result.resources.append([resource _coreResource].get());
Modified: trunk/Source/WebKitLegacy/mac/WebView/WebHTMLRepresentation.mm (273609 => 273610)
--- trunk/Source/WebKitLegacy/mac/WebView/WebHTMLRepresentation.mm 2021-02-27 01:08:23 UTC (rev 273609)
+++ trunk/Source/WebKitLegacy/mac/WebView/WebHTMLRepresentation.mm 2021-02-27 01:54:54 UTC (rev 273610)
@@ -97,34 +97,33 @@
+ (NSArray *)supportedMIMETypes
{
- static NSArray *staticSupportedMIMETypes = [[[[self supportedNonImageMIMETypes] arrayByAddingObjectsFromArray:
- [self supportedImageMIMETypes]] arrayByAddingObjectsFromArray:
- [self supportedMediaMIMETypes]] retain];
- return staticSupportedMIMETypes;
+ static NeverDestroyed<RetainPtr<NSArray>> staticSupportedMIMETypes = [[[self supportedNonImageMIMETypes] arrayByAddingObjectsFromArray:
+ [self supportedImageMIMETypes]] arrayByAddingObjectsFromArray:[self supportedMediaMIMETypes]];
+ return staticSupportedMIMETypes.get().get();
}
+ (NSArray *)supportedMediaMIMETypes
{
- static NSArray *staticSupportedMediaMIMETypes = newArrayWithStrings(MIMETypeRegistry::supportedMediaMIMETypes()).leakRef();
- return staticSupportedMediaMIMETypes;
+ static NeverDestroyed<RetainPtr<NSArray>> staticSupportedMediaMIMETypes = newArrayWithStrings(MIMETypeRegistry::supportedMediaMIMETypes());
+ return staticSupportedMediaMIMETypes.get().get();
}
+ (NSArray *)supportedNonImageMIMETypes
{
- static NSArray *staticSupportedNonImageMIMETypes = newArrayWithStrings(MIMETypeRegistry::supportedNonImageMIMETypes()).leakRef();
- return staticSupportedNonImageMIMETypes;
+ static NeverDestroyed<RetainPtr<NSArray>> staticSupportedNonImageMIMETypes = newArrayWithStrings(MIMETypeRegistry::supportedNonImageMIMETypes());
+ return staticSupportedNonImageMIMETypes.get().get();
}
+ (NSArray *)supportedImageMIMETypes
{
- static NSArray *staticSupportedImageMIMETypes = newArrayWithStrings(MIMETypeRegistry::supportedImageMIMETypes()).leakRef();
- return staticSupportedImageMIMETypes;
+ static NeverDestroyed<RetainPtr<NSArray>> staticSupportedImageMIMETypes = newArrayWithStrings(MIMETypeRegistry::supportedImageMIMETypes());
+ return staticSupportedImageMIMETypes.get().get();
}
+ (NSArray *)unsupportedTextMIMETypes
{
- static NSArray *staticUnsupportedTextMIMETypes = newArrayWithStrings(MIMETypeRegistry::unsupportedTextMIMETypes()).leakRef();
- return staticUnsupportedTextMIMETypes;
+ static NeverDestroyed<RetainPtr<NSArray>> staticUnsupportedTextMIMETypes = newArrayWithStrings(MIMETypeRegistry::unsupportedTextMIMETypes());
+ return staticUnsupportedTextMIMETypes.get().get();
}
- (id)init
Modified: trunk/Source/WebKitLegacy/mac/WebView/WebPreferencesDefaultValues.mm (273609 => 273610)
--- trunk/Source/WebKitLegacy/mac/WebView/WebPreferencesDefaultValues.mm 2021-02-27 01:08:23 UTC (rev 273609)
+++ trunk/Source/WebKitLegacy/mac/WebView/WebPreferencesDefaultValues.mm 2021-02-27 01:54:54 UTC (rev 273610)
@@ -52,12 +52,12 @@
if (!isWebKitBundleFromStagedFramework)
return _os_feature_enabled_impl("WebKit", (const char*)featureName.utf8().data());
- static NSDictionary* dictionary = [[NSDictionary dictionaryWithContentsOfFile:@"/Library/Apple/System/Library/FeatureFlags/Domain/WebKit.plist"] retain];
+ static NeverDestroyed<RetainPtr<NSDictionary>> dictionary = [NSDictionary dictionaryWithContentsOfFile:@"/Library/Apple/System/Library/FeatureFlags/Domain/WebKit.plist"];
- if (![[dictionary objectForKey:featureName] objectForKey:@"Enabled"])
+ if (![[dictionary.get() objectForKey:featureName] objectForKey:@"Enabled"])
return _os_feature_enabled_impl("WebKit", (const char*)featureName.characters8());
- return [[[dictionary objectForKey:featureName] objectForKey:@"Enabled"] isKindOfClass:[NSNumber class]] && [[[dictionary objectForKey:featureName] objectForKey:@"Enabled"] boolValue];
+ return [[[dictionary.get() objectForKey:featureName] objectForKey:@"Enabled"] isKindOfClass:[NSNumber class]] && [[[dictionary.get() objectForKey:featureName] objectForKey:@"Enabled"] boolValue];
}
#endif
Modified: trunk/Source/WebKitLegacy/mac/WebView/WebView.mm (273609 => 273610)
--- trunk/Source/WebKitLegacy/mac/WebView/WebView.mm 2021-02-27 01:08:23 UTC (rev 273609)
+++ trunk/Source/WebKitLegacy/mac/WebView/WebView.mm 2021-02-27 01:54:54 UTC (rev 273610)
@@ -1438,11 +1438,11 @@
WebPreferences *standardPreferences = [WebPreferences standardPreferences];
[standardPreferences willAddToWebView];
- _private->preferences = [standardPreferences retain];
+ _private->preferences = standardPreferences;
_private->mainFrameDocumentReady = NO;
_private->drawsBackground = YES;
#if !PLATFORM(IOS_FAMILY)
- _private->backgroundColor = adoptNS([[NSColor colorWithDeviceWhite:1 alpha:1] retain]);
+ _private->backgroundColor = [NSColor colorWithDeviceWhite:1 alpha:1];
#else
_private->backgroundColor = WebCore::cachedCGColor(WebCore::Color::white);
#endif
@@ -1514,7 +1514,7 @@
didOneTimeInitialization = true;
}
- _private->group = WebViewGroup::getOrCreate(groupName, _private->preferences._localStorageDatabasePath);
+ _private->group = WebViewGroup::getOrCreate(groupName, [_private->preferences _localStorageDatabasePath]);
_private->group->addWebView(self);
auto storageProvider = PageStorageSessionProvider::create();
@@ -1780,7 +1780,7 @@
preferences = [WebPreferences standardPreferences];
[preferences willAddToWebView];
- _private->preferences = [preferences retain];
+ _private->preferences = preferences;
_private->mainFrameDocumentReady = NO;
_private->drawsBackground = YES;
_private->backgroundColor = WebCore::cachedCGColor(WebCore::Color::white);
@@ -1789,7 +1789,7 @@
[frameView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[self addSubview:frameView.get()];
- _private->group = WebViewGroup::getOrCreate(groupName, _private->preferences._localStorageDatabasePath);
+ _private->group = WebViewGroup::getOrCreate(groupName, [_private->preferences _localStorageDatabasePath]);
_private->group->addWebView(self);
auto storageProvider = PageStorageSessionProvider::create();
@@ -2506,7 +2506,7 @@
[WebPreferences _removeReferenceForIdentifier:[self preferencesIdentifier]];
- auto preferences = adoptNS(std::exchange(_private->preferences, nil));
+ auto preferences = std::exchange(_private->preferences, nil);
[preferences didRemoveFromWebView];
[self _closePluginDatabases];
@@ -3375,8 +3375,8 @@
_private->_didPerformFirstNavigation = YES;
- if (_private->preferences.automaticallyDetectsCacheModel && _private->preferences.cacheModel < WebCacheModelDocumentBrowser)
- _private->preferences.cacheModel = WebCacheModelDocumentBrowser;
+ if ([_private->preferences automaticallyDetectsCacheModel] && [_private->preferences cacheModel] < WebCacheModelDocumentBrowser)
+ [_private->preferences setCacheModel:WebCacheModelDocumentBrowser];
}
- (void)_didCommitLoadForFrame:(WebFrame *)frame
@@ -5783,12 +5783,12 @@
[prefs willAddToWebView];
- auto oldPrefs = adoptNS(_private->preferences);
+ auto oldPrefs = std::exchange(_private->preferences, nullptr);
[[NSNotificationCenter defaultCenter] removeObserver:self name:WebPreferencesChangedInternalNotification object:[self preferences]];
[WebPreferences _removeReferenceForIdentifier:[oldPrefs identifier]];
- _private->preferences = [prefs retain];
+ _private->preferences = prefs;
// After registering for the notification, post it so the WebCore settings update.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_preferencesChangedNotification:)
@@ -5801,7 +5801,7 @@
- (WebPreferences *)preferences
{
- return _private->preferences;
+ return _private->preferences.get();
}
- (void)setPreferencesIdentifier:(NSString *)anIdentifier
@@ -6559,7 +6559,7 @@
if (_private->group)
_private->group->removeWebView(self);
- _private->group = WebViewGroup::getOrCreate(groupName, _private->preferences._localStorageDatabasePath);
+ _private->group = WebViewGroup::getOrCreate(groupName, [_private->preferences _localStorageDatabasePath]);
_private->group->addWebView(self);
if (!_private->page)
Modified: trunk/Source/WebKitLegacy/mac/WebView/WebViewData.h (273609 => 273610)
--- trunk/Source/WebKitLegacy/mac/WebView/WebViewData.h 2021-02-27 01:08:23 UTC (rev 273609)
+++ trunk/Source/WebKitLegacy/mac/WebView/WebViewData.h 2021-02-27 01:54:54 UTC (rev 273610)
@@ -226,7 +226,7 @@
WTF::String userAgent;
BOOL userAgentOverridden;
- WebPreferences *preferences;
+ RetainPtr<WebPreferences> preferences;
#if PLATFORM(IOS_FAMILY)
NSURL *userStyleSheetLocation;
#endif
Modified: trunk/Tools/ChangeLog (273609 => 273610)
--- trunk/Tools/ChangeLog 2021-02-27 01:08:23 UTC (rev 273609)
+++ trunk/Tools/ChangeLog 2021-02-27 01:54:54 UTC (rev 273610)
@@ -1,3 +1,30 @@
+2021-02-26 Chris Dumez <[email protected]>
+
+ Reduce explicit usage of [objC retain] in WebKit
+ https://bugs.webkit.org/show_bug.cgi?id=222439
+
+ Reviewed by Darin Adler.
+
+ Reduce explicit usage of [objC retain] in WebKit by using RetainPtr<>.
+
+ * DumpRenderTree/mac/DumpRenderTree.mm:
+ (allowedFontFamilySet):
+ (-[DRTMockScroller drawKnob]):
+ (-[DRTMockScroller drawRect:]):
+ (prepareConsistentTestingEnvironment):
+ * TestWebKitAPI/Tests/WebKitCocoa/QuickLook.mm:
+ (TEST):
+ * TestWebKitAPI/cocoa/TestWKWebView.mm:
+ (-[TestWKWebView selectionRectsAfterPresentationUpdate]):
+ * WebKitTestRunner/ios/TestControllerIOS.mm:
+ (WTR::TestController::platformLibraryPathForTesting):
+ * WebKitTestRunner/mac/TestControllerMac.mm:
+ (WTR::allowedFontFamilySet):
+ (WTR::systemHiddenFontFamilySet):
+ (WTR::TestController::platformLibraryPathForTesting):
+ * WebKitTestRunner/mac/main.mm:
+ (disableAppNapInUIProcess):
+
2021-02-26 Ryan Haddad <[email protected]>
macOS bots should build with _ONLY_ACTIVE_ARCH_=NO
Modified: trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm (273609 => 273610)
--- trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm 2021-02-27 01:08:23 UTC (rev 273609)
+++ trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm 2021-02-27 01:54:54 UTC (rev 273610)
@@ -218,15 +218,45 @@
}
// Delegates
-static RetainPtr<FrameLoadDelegate> frameLoadDelegate;
-static RetainPtr<UIDelegate> uiDelegate;
-static RetainPtr<EditingDelegate> editingDelegate;
-static RetainPtr<ResourceLoadDelegate> resourceLoadDelegate;
-static RetainPtr<HistoryDelegate> historyDelegate;
+static RetainPtr<FrameLoadDelegate>& frameLoadDelegate()
+{
+ static NeverDestroyed<RetainPtr<FrameLoadDelegate>> frameLoadDelegate;
+ return frameLoadDelegate;
+}
+
+static RetainPtr<UIDelegate>& uiDelegate()
+{
+ static NeverDestroyed<RetainPtr<UIDelegate>> uiDelegate;
+ return uiDelegate;
+}
+
+static RetainPtr<EditingDelegate>& editingDelegate()
+{
+ static NeverDestroyed<RetainPtr<EditingDelegate>> editingDelegate;
+ return editingDelegate;
+}
+
+static RetainPtr<ResourceLoadDelegate>& resourceLoadDelegate()
+{
+ static NeverDestroyed<RetainPtr<ResourceLoadDelegate>> resourceLoadDelegate;
+ return resourceLoadDelegate;
+}
+
+static RetainPtr<HistoryDelegate>& historyDelegate()
+{
+ static NeverDestroyed<RetainPtr<HistoryDelegate>> historyDelegate;
+ return historyDelegate;
+}
+
RetainPtr<PolicyDelegate> policyDelegate;
RetainPtr<DefaultPolicyDelegate> defaultPolicyDelegate;
+
#if PLATFORM(IOS_FAMILY)
-static RetainPtr<ScrollViewResizerDelegate> scrollViewResizerDelegate;
+static RetainPtr<ScrollViewResizerDelegate>& scrollViewResizerDelegate()
+{
+ static NeverDestroyed<RetainPtr<ScrollViewResizerDelegate>> scrollViewResizerDelegate;
+ return scrollViewResizerDelegate;
+}
#endif
static int dumpPixelsForAllTests;
@@ -242,7 +272,13 @@
static int printTestCount;
static int checkForWorldLeaks;
static BOOL printSeparators;
-static RetainPtr<CFStringRef> persistentUserStyleSheetLocation;
+
+static RetainPtr<CFStringRef>& persistentUserStyleSheetLocation()
+{
+ static NeverDestroyed<RetainPtr<CFStringRef>> persistentUserStyleSheetLocation;
+ return persistentUserStyleSheetLocation;
+}
+
static std::set<std::string> allowedHosts;
static RetainPtr<WebHistoryItem>& prevTestBFItem()
@@ -260,7 +296,7 @@
void setPersistentUserStyleSheetLocation(CFStringRef url)
{
- persistentUserStyleSheetLocation = url;
+ persistentUserStyleSheetLocation() = url;
}
static bool shouldIgnoreWebCoreNodeLeaks(const std::string& urlString)
@@ -283,7 +319,7 @@
#if !PLATFORM(IOS_FAMILY)
static NSSet *allowedFontFamilySet()
{
- static NSSet *fontFamilySet = [[NSSet setWithObjects:
+ static NeverDestroyed<RetainPtr<NSSet>> fontFamilySet = [NSSet setWithObjects:
@"Ahem",
@"Al Bayan",
@"American Typewriter",
@@ -410,14 +446,14 @@
@"Wingdings",
@"Zapf Dingbats",
@"Zapfino",
- nil] retain];
+ nil];
- return fontFamilySet;
+ return fontFamilySet.get().get();
}
static NSArray *fontAllowList()
{
- static RetainPtr<NSArray> availableFonts = [] {
+ static auto availableFonts = makeNeverDestroyed([] {
auto availableFonts = adoptNS([[NSMutableArray alloc] init]);
for (NSString *fontFamily in allowedFontFamilySet()) {
NSArray* fontsForFamily = [[NSFontManager sharedFontManager] availableMembersOfFontFamily:fontFamily];
@@ -428,8 +464,8 @@
}
}
return availableFonts;
- }();
- return availableFonts.get();
+ }());
+ return availableFonts.get().get();
}
// Activating system copies of these fonts overrides any others that could be preferred, such as ones
@@ -573,7 +609,7 @@
// Adjust the viewport view and viewport to have similar behavior
// as the browser.
[(DumpRenderTreeBrowserView *)webBrowserView setScrollingUsesUIWebScrollView:YES];
- [webBrowserView setDelegate:scrollViewResizerDelegate.get()];
+ [webBrowserView setDelegate:scrollViewResizerDelegate().get()];
CGRect screenBounds = [UIScreen mainScreen].bounds;
CGRect viewportRect = CGRectMake(0, 0, screenBounds.size.width, screenBounds.size.height);
@@ -643,8 +679,8 @@
NSRect knobRect = [self rectForPart:NSScrollerKnob];
- static NSColor *knobColor = [[NSColor colorWithDeviceRed:0x80 / 255.0 green:0x80 / 255.0 blue:0x80 / 255.0 alpha:1] retain];
- [knobColor set];
+ static NeverDestroyed<RetainPtr<NSColor>> knobColor = [NSColor colorWithDeviceRed:0x80 / 255.0 green:0x80 / 255.0 blue:0x80 / 255.0 alpha:1];
+ [knobColor.get() set];
NSRectFill(knobRect);
}
@@ -651,13 +687,13 @@
- (void)drawRect:(NSRect)dirtyRect
{
- static NSColor *trackColor = [[NSColor colorWithDeviceRed:0xC0 / 255.0 green:0xC0 / 255.0 blue:0xC0 / 255.0 alpha:1] retain];
- static NSColor *disabledTrackColor = [[NSColor colorWithDeviceRed:0xE0 / 255.0 green:0xE0 / 255.0 blue:0xE0 / 255.0 alpha:1] retain];
+ static NeverDestroyed<RetainPtr<NSColor>> trackColor = [NSColor colorWithDeviceRed:0xC0 / 255.0 green:0xC0 / 255.0 blue:0xC0 / 255.0 alpha:1];
+ static NeverDestroyed<RetainPtr<NSColor>> disabledTrackColor = [NSColor colorWithDeviceRed:0xE0 / 255.0 green:0xE0 / 255.0 blue:0xE0 / 255.0 alpha:1];
if ([self isEnabled])
- [trackColor set];
+ [trackColor.get() set];
else
- [disabledTrackColor set];
+ [disabledTrackColor.get() set];
NSRectFill(dirtyRect);
@@ -684,10 +720,10 @@
[webView setGroupName:@"org.webkit.DumpRenderTree"];
#endif
- [webView setUIDelegate:uiDelegate.get()];
- [webView setFrameLoadDelegate:frameLoadDelegate.get()];
- [webView setEditingDelegate:editingDelegate.get()];
- [webView setResourceLoadDelegate:resourceLoadDelegate.get()];
+ [webView setUIDelegate:uiDelegate().get()];
+ [webView setFrameLoadDelegate:frameLoadDelegate().get()];
+ [webView setEditingDelegate:editingDelegate().get()];
+ [webView setResourceLoadDelegate:resourceLoadDelegate().get()];
[webView _setGeolocationProvider:[MockGeolocationProvider shared]];
[webView _setDeviceOrientationProvider:[WebDeviceOrientationProviderMock shared]];
[webView _setNotificationProvider:[MockWebNotificationProvider shared]];
@@ -836,8 +872,8 @@
[preferences _setBoolPreferenceForTestingWithValue:NO forKey:@"WebKitLazyImageLoadingEnabled"];
[preferences _setBoolPreferenceForTestingWithValue:NO forKey:@"WebKitWebAuthenticationEnabled"];
- if (persistentUserStyleSheetLocation) {
- [preferences setUserStyleSheetLocation:[NSURL URLWithString:(__bridge NSString *)persistentUserStyleSheetLocation.get()]];
+ if (persistentUserStyleSheetLocation()) {
+ [preferences setUserStyleSheetLocation:[NSURL URLWithString:(__bridge NSString *)persistentUserStyleSheetLocation().get()]];
[preferences setUserStyleSheetEnabled:YES];
} else
[preferences setUserStyleSheetEnabled:NO];
@@ -990,15 +1026,15 @@
{
// FIXME: We should remove these and move to the ObjC standard [Foo sharedInstance] model
gNavigationController = adoptNS([[NavigationController alloc] init]);
- frameLoadDelegate = adoptNS([[FrameLoadDelegate alloc] init]);
- uiDelegate = adoptNS([[UIDelegate alloc] init]);
- editingDelegate = adoptNS([[EditingDelegate alloc] init]);
- resourceLoadDelegate = adoptNS([[ResourceLoadDelegate alloc] init]);
+ frameLoadDelegate() = adoptNS([[FrameLoadDelegate alloc] init]);
+ uiDelegate() = adoptNS([[UIDelegate alloc] init]);
+ editingDelegate() = adoptNS([[EditingDelegate alloc] init]);
+ resourceLoadDelegate() = adoptNS([[ResourceLoadDelegate alloc] init]);
policyDelegate = adoptNS([[PolicyDelegate alloc] init]);
- historyDelegate = adoptNS([[HistoryDelegate alloc] init]);
+ historyDelegate() = adoptNS([[HistoryDelegate alloc] init]);
defaultPolicyDelegate = adoptNS([[DefaultPolicyDelegate alloc] init]);
#if PLATFORM(IOS_FAMILY)
- scrollViewResizerDelegate = adoptNS([[ScrollViewResizerDelegate alloc] init]);
+ scrollViewResizerDelegate() = adoptNS([[ScrollViewResizerDelegate alloc] init]);
#endif
}
@@ -1005,15 +1041,15 @@
static void releaseGlobalControllers()
{
gNavigationController = nil;
- frameLoadDelegate = nil;
- editingDelegate = nil;
- resourceLoadDelegate = nil;
- uiDelegate = nil;
- historyDelegate = nil;
+ frameLoadDelegate() = nil;
+ editingDelegate() = nil;
+ resourceLoadDelegate() = nil;
+ uiDelegate() = nil;
+ historyDelegate() = nil;
policyDelegate = nil;
defaultPolicyDelegate = nil;
#if PLATFORM(IOS_FAMILY)
- scrollViewResizerDelegate = nil;
+ scrollViewResizerDelegate() = nil;
#endif
}
@@ -1147,8 +1183,8 @@
#if PLATFORM(MAC)
NSActivityOptions options = (NSActivityUserInitiatedAllowingIdleSystemSleep | NSActivityLatencyCritical) & ~(NSActivitySuddenTerminationDisabled | NSActivityAutomaticTerminationDisabled);
- static id assertion = [[[NSProcessInfo processInfo] beginActivityWithOptions:options reason:@"DumpRenderTree should not be subject to process suppression"] retain];
- ASSERT_UNUSED(assertion, assertion);
+ static NeverDestroyed<RetainPtr<id>> assertion = [[NSProcessInfo processInfo] beginActivityWithOptions:options reason:@"DumpRenderTree should not be subject to process suppression"];
+ ASSERT_UNUSED(assertion, assertion.get());
#endif
}
@@ -1539,7 +1575,7 @@
static void sizeWebViewForCurrentTest()
{
- [uiDelegate resetWindowOrigin];
+ [uiDelegate() resetWindowOrigin];
// W3C SVG tests expect to be 480x360
bool isSVGW3CTest = (gTestRunner->testURL().find("svg/W3C-SVG-1.1") != std::string::npos);
@@ -1765,8 +1801,8 @@
[webView setPolicyDelegate:defaultPolicyDelegate.get()];
[policyDelegate setPermissive:NO];
[policyDelegate setControllerToNotifyDone:0];
- [uiDelegate resetToConsistentStateBeforeTesting:options];
- [frameLoadDelegate resetToConsistentState];
+ [uiDelegate() resetToConsistentStateBeforeTesting:options];
+ [frameLoadDelegate() resetToConsistentState];
[webView _clearMainFrameName];
[[webView undoManager] removeAllActions];
[WebView _removeAllUserContentFromGroup:[webView groupName]];
@@ -1951,7 +1987,7 @@
gTestRunner->setDumpFrameLoadCallbacks(true);
if (shouldLogHistoryDelegates(pathOrURL.c_str()))
- [[mainFrame webView] setHistoryDelegate:historyDelegate.get()];
+ [[mainFrame webView] setHistoryDelegate:historyDelegate().get()];
else
[[mainFrame webView] setHistoryDelegate:nil];
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/QuickLook.mm (273609 => 273610)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/QuickLook.mm 2021-02-27 01:08:23 UTC (rev 273609)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/QuickLook.mm 2021-02-27 01:54:54 UTC (rev 273610)
@@ -43,6 +43,7 @@
#import <WebKit/WebViewPrivate.h>
#import <WebKit/_WKDownload.h>
#import <WebKit/_WKDownloadDelegate.h>
+#import <wtf/NeverDestroyed.h>
#import <wtf/RetainPtr.h>
using namespace TestWebKitAPI;
@@ -51,8 +52,13 @@
static bool downloadIsDone;
static NSString * const pagesDocumentPreviewMIMEType = @"application/pdf";
-static NSURL * const pagesDocumentURL = [[NSBundle.mainBundle URLForResource:@"pages" withExtension:@"pages" subdirectory:@"TestWebKitAPI.resources"] retain];
+static RetainPtr<NSURL> pagesDocumentURL()
+{
+ static NeverDestroyed<RetainPtr<NSURL>> pagesDocumentURL = [NSBundle.mainBundle URLForResource:@"pages" withExtension:@"pages" subdirectory:@"TestWebKitAPI.resources"];
+ return pagesDocumentURL;
+}
+
@interface QuickLookDelegate : NSObject <WKNavigationDelegatePrivate, _WKDownloadDelegate>
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithExpectedFileURL:(NSURL *)fileURL responsePolicy:(WKNavigationResponsePolicy)responsePolicy;
@@ -280,8 +286,8 @@
TEST(QuickLook, AllowResponseBeforeLoadingPreview)
{
- auto delegate = adoptNS([[QuickLookDelegate alloc] initWithExpectedFileURL:pagesDocumentURL responsePolicy:WKNavigationResponsePolicyAllow]);
- runTestDecideBeforeLoading(delegate.get(), [NSURLRequest requestWithURL:pagesDocumentURL]);
+ auto delegate = adoptNS([[QuickLookDelegate alloc] initWithExpectedFileURL:pagesDocumentURL().get() responsePolicy:WKNavigationResponsePolicyAllow]);
+ runTestDecideBeforeLoading(delegate.get(), [NSURLRequest requestWithURL:pagesDocumentURL().get()]);
EXPECT_FALSE([delegate didFailNavigation]);
EXPECT_TRUE([delegate didFinishNavigation]);
EXPECT_TRUE([delegate didFinishQuickLookLoad]);
@@ -290,8 +296,8 @@
TEST(QuickLook, AllowResponseAfterLoadingPreview)
{
- auto delegate = adoptNS([[QuickLookDelegate alloc] initWithExpectedFileURL:pagesDocumentURL previewMIMEType:pagesDocumentPreviewMIMEType responsePolicy:WKNavigationResponsePolicyAllow]);
- runTestDecideAfterLoading(delegate.get(), [NSURLRequest requestWithURL:pagesDocumentURL]);
+ auto delegate = adoptNS([[QuickLookDelegate alloc] initWithExpectedFileURL:pagesDocumentURL().get() previewMIMEType:pagesDocumentPreviewMIMEType responsePolicy:WKNavigationResponsePolicyAllow]);
+ runTestDecideAfterLoading(delegate.get(), [NSURLRequest requestWithURL:pagesDocumentURL().get()]);
EXPECT_FALSE([delegate didFailNavigation]);
EXPECT_TRUE([delegate didFinishNavigation]);
EXPECT_TRUE([delegate didFinishQuickLookLoad]);
@@ -319,8 +325,8 @@
#if PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED > 130400
TEST(QuickLook, AsyncAllowResponseBeforeLoadingPreview)
{
- auto delegate = adoptNS([[QuickLookAsyncDelegate alloc] initWithExpectedFileURL:pagesDocumentURL responsePolicy:WKNavigationResponsePolicyAllow]);
- runTestDecideBeforeLoading(delegate.get(), [NSURLRequest requestWithURL:pagesDocumentURL]);
+ auto delegate = adoptNS([[QuickLookAsyncDelegate alloc] initWithExpectedFileURL:pagesDocumentURL().get() responsePolicy:WKNavigationResponsePolicyAllow]);
+ runTestDecideBeforeLoading(delegate.get(), [NSURLRequest requestWithURL:pagesDocumentURL().get()]);
EXPECT_FALSE([delegate didFailNavigation]);
EXPECT_TRUE([delegate didFinishNavigation]);
EXPECT_TRUE([delegate didFinishQuickLookLoad]);
@@ -329,8 +335,8 @@
TEST(QuickLook, AsyncAllowResponseAfterLoadingPreview)
{
- auto delegate = adoptNS([[QuickLookAsyncDelegate alloc] initWithExpectedFileURL:pagesDocumentURL previewMIMEType:pagesDocumentPreviewMIMEType responsePolicy:WKNavigationResponsePolicyAllow]);
- runTestDecideAfterLoading(delegate.get(), [NSURLRequest requestWithURL:pagesDocumentURL]);
+ auto delegate = adoptNS([[QuickLookAsyncDelegate alloc] initWithExpectedFileURL:pagesDocumentURL().get() previewMIMEType:pagesDocumentPreviewMIMEType responsePolicy:WKNavigationResponsePolicyAllow]);
+ runTestDecideAfterLoading(delegate.get(), [NSURLRequest requestWithURL:pagesDocumentURL().get()]);
EXPECT_FALSE([delegate didFailNavigation]);
EXPECT_TRUE([delegate didFinishNavigation]);
EXPECT_TRUE([delegate didFinishQuickLookLoad]);
@@ -340,8 +346,8 @@
TEST(QuickLook, CancelResponseBeforeLoadingPreview)
{
- auto delegate = adoptNS([[QuickLookDelegate alloc] initWithExpectedFileURL:pagesDocumentURL responsePolicy:WKNavigationResponsePolicyCancel]);
- runTestDecideBeforeLoading(delegate.get(), [NSURLRequest requestWithURL:pagesDocumentURL]);
+ auto delegate = adoptNS([[QuickLookDelegate alloc] initWithExpectedFileURL:pagesDocumentURL().get() responsePolicy:WKNavigationResponsePolicyCancel]);
+ runTestDecideBeforeLoading(delegate.get(), [NSURLRequest requestWithURL:pagesDocumentURL().get()]);
EXPECT_EQ(WebKitErrorFrameLoadInterruptedByPolicyChange, [delegate navigationError].code);
EXPECT_FALSE([delegate didFinishNavigation]);
EXPECT_FALSE([delegate didFinishQuickLookLoad]);
@@ -352,8 +358,8 @@
#if PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED > 130400
TEST(QuickLook, CancelResponseAfterLoadingPreview)
{
- auto delegate = adoptNS([[QuickLookDelegate alloc] initWithExpectedFileURL:pagesDocumentURL previewMIMEType:pagesDocumentPreviewMIMEType responsePolicy:WKNavigationResponsePolicyCancel]);
- runTestDecideAfterLoading(delegate.get(), [NSURLRequest requestWithURL:pagesDocumentURL]);
+ auto delegate = adoptNS([[QuickLookDelegate alloc] initWithExpectedFileURL:pagesDocumentURL().get() previewMIMEType:pagesDocumentPreviewMIMEType responsePolicy:WKNavigationResponsePolicyCancel]);
+ runTestDecideAfterLoading(delegate.get(), [NSURLRequest requestWithURL:pagesDocumentURL().get()]);
EXPECT_EQ(WebKitErrorFrameLoadInterruptedByPolicyChange, [delegate navigationError].code);
EXPECT_FALSE([delegate didFinishNavigation]);
EXPECT_TRUE([delegate didFailNavigation]);
@@ -364,8 +370,8 @@
TEST(QuickLook, DownloadResponseBeforeLoadingPreview)
{
- auto delegate = adoptNS([[QuickLookDelegate alloc] initWithExpectedFileURL:pagesDocumentURL responsePolicy:WKNavigationResponsePolicyDownload]);
- runTestDecideBeforeLoading(delegate.get(), [NSURLRequest requestWithURL:pagesDocumentURL]);
+ auto delegate = adoptNS([[QuickLookDelegate alloc] initWithExpectedFileURL:pagesDocumentURL().get() responsePolicy:WKNavigationResponsePolicyDownload]);
+ runTestDecideBeforeLoading(delegate.get(), [NSURLRequest requestWithURL:pagesDocumentURL().get()]);
EXPECT_EQ(WebKitErrorFrameLoadInterruptedByPolicyChange, [delegate navigationError].code);
EXPECT_FALSE([delegate didFinishNavigation]);
EXPECT_FALSE([delegate didFinishQuickLookLoad]);
@@ -379,8 +385,8 @@
#if PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED > 130400
TEST(QuickLook, DownloadResponseAfterLoadingPreview)
{
- auto delegate = adoptNS([[QuickLookDelegate alloc] initWithExpectedFileURL:pagesDocumentURL previewMIMEType:pagesDocumentPreviewMIMEType responsePolicy:WKNavigationResponsePolicyDownload]);
- runTestDecideAfterLoading(delegate.get(), [NSURLRequest requestWithURL:pagesDocumentURL]);
+ auto delegate = adoptNS([[QuickLookDelegate alloc] initWithExpectedFileURL:pagesDocumentURL().get() previewMIMEType:pagesDocumentPreviewMIMEType responsePolicy:WKNavigationResponsePolicyDownload]);
+ runTestDecideAfterLoading(delegate.get(), [NSURLRequest requestWithURL:pagesDocumentURL().get()]);
EXPECT_EQ(WebKitErrorFrameLoadInterruptedByPolicyChange, [delegate navigationError].code);
EXPECT_FALSE([delegate didFinishNavigation]);
EXPECT_TRUE([delegate didFailNavigation]);
@@ -430,8 +436,8 @@
TEST(QuickLook, ReloadAndSameDocumentNavigation)
{
- auto delegate = adoptNS([[QuickLookDelegate alloc] initWithExpectedFileURL:pagesDocumentURL responsePolicy:WKNavigationResponsePolicyAllow]);
- auto webView = runTestDecideBeforeLoading(delegate.get(), [NSURLRequest requestWithURL:pagesDocumentURL]);
+ auto delegate = adoptNS([[QuickLookDelegate alloc] initWithExpectedFileURL:pagesDocumentURL().get() responsePolicy:WKNavigationResponsePolicyAllow]);
+ auto webView = runTestDecideBeforeLoading(delegate.get(), [NSURLRequest requestWithURL:pagesDocumentURL().get()]);
EXPECT_FALSE([delegate didFailNavigation]);
EXPECT_TRUE([delegate didFinishNavigation]);
EXPECT_TRUE([delegate didFinishQuickLookLoad]);
@@ -491,7 +497,7 @@
WebFrame *mainFrame = [webView mainFrame];
- [mainFrame loadRequest:[NSURLRequest requestWithURL:pagesDocumentURL]];
+ [mainFrame loadRequest:[NSURLRequest requestWithURL:pagesDocumentURL().get()]];
Util::run(&isDone);
WebThreadLock();
@@ -500,7 +506,7 @@
RetainPtr<NSString> expectedFileName;
RetainPtr<NSString> expectedFileType;
RetainPtr<NSString> expectedMIMEType;
- readFile(pagesDocumentURL, expectedFileSize, expectedFileName, expectedFileType, expectedMIMEType, expectedFileData);
+ readFile(pagesDocumentURL().get(), expectedFileSize, expectedFileName, expectedFileType, expectedMIMEType, expectedFileData);
NSDictionary *quickLookContent = mainFrame.dataSource._quickLookContent;
NSString *filePath = quickLookContent[WebQuickLookFileNameKey];
Modified: trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.mm (273609 => 273610)
--- trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.mm 2021-02-27 01:08:23 UTC (rev 273609)
+++ trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.mm 2021-02-27 01:54:54 UTC (rev 273610)
@@ -669,7 +669,7 @@
__block bool isDone = false;
__block RetainPtr<NSArray> selectionRects;
[self _doAfterNextPresentationUpdate:^() {
- selectionRects = adoptNS([[retainedSelf _uiTextSelectionRects] retain]);
+ selectionRects = [retainedSelf _uiTextSelectionRects];
isDone = true;
}];
Modified: trunk/Tools/WebKitTestRunner/ios/TestControllerIOS.mm (273609 => 273610)
--- trunk/Tools/WebKitTestRunner/ios/TestControllerIOS.mm 2021-02-27 01:08:23 UTC (rev 273609)
+++ trunk/Tools/WebKitTestRunner/ios/TestControllerIOS.mm 2021-02-27 01:54:54 UTC (rev 273610)
@@ -316,12 +316,12 @@
const char* TestController::platformLibraryPathForTesting()
{
- static NSString *platformLibraryPath = nil;
+ static NeverDestroyed<RetainPtr<NSString>> platformLibraryPath;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
- platformLibraryPath = [[@"~/Library/Application Support/WebKitTestRunner" stringByExpandingTildeInPath] retain];
+ platformLibraryPath.get() = [@"~/Library/Application Support/WebKitTestRunner" stringByExpandingTildeInPath];
});
- return platformLibraryPath.UTF8String;
+ return [platformLibraryPath.get() UTF8String];
}
void TestController::setHidden(bool)
Modified: trunk/Tools/WebKitTestRunner/mac/TestControllerMac.mm (273609 => 273610)
--- trunk/Tools/WebKitTestRunner/mac/TestControllerMac.mm 2021-02-27 01:08:23 UTC (rev 273609)
+++ trunk/Tools/WebKitTestRunner/mac/TestControllerMac.mm 2021-02-27 01:54:54 UTC (rev 273610)
@@ -227,7 +227,7 @@
static NSSet *allowedFontFamilySet()
{
- static NSSet *fontFamilySet = [[NSSet setWithObjects:
+ static NeverDestroyed<RetainPtr<NSSet>> fontFamilySet = [NSSet setWithObjects:
@"Ahem",
@"Al Bayan",
@"American Typewriter",
@@ -355,18 +355,18 @@
@"Wingdings",
@"Zapf Dingbats",
@"Zapfino",
- nil] retain];
+ nil];
- return fontFamilySet;
+ return fontFamilySet.get().get();
}
static NSSet *systemHiddenFontFamilySet()
{
- static NSSet *fontFamilySet = [[NSSet setWithObjects:
+ static NeverDestroyed<RetainPtr<NSSet>> fontFamilySet = [NSSet setWithObjects:
@".LucidaGrandeUI",
- nil] retain];
+ nil];
- return fontFamilySet;
+ return fontFamilySet.get().get();
}
static WKRetainPtr<WKArrayRef> generateFontAllowList()
@@ -430,12 +430,12 @@
const char* TestController::platformLibraryPathForTesting()
{
- static NSString *platformLibraryPath = nil;
+ static NeverDestroyed<RetainPtr<NSString>> platformLibraryPath;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
- platformLibraryPath = [[@"~/Library/Application Support/DumpRenderTree" stringByExpandingTildeInPath] retain];
+ platformLibraryPath.get() = [@"~/Library/Application Support/DumpRenderTree" stringByExpandingTildeInPath];
});
- return platformLibraryPath.UTF8String;
+ return [platformLibraryPath.get() UTF8String];
}
} // namespace WTR
Modified: trunk/Tools/WebKitTestRunner/mac/main.mm (273609 => 273610)
--- trunk/Tools/WebKitTestRunner/mac/main.mm 2021-02-27 01:08:23 UTC (rev 273609)
+++ trunk/Tools/WebKitTestRunner/mac/main.mm 2021-02-27 01:54:54 UTC (rev 273610)
@@ -54,8 +54,8 @@
static void disableAppNapInUIProcess()
{
NSActivityOptions options = (NSActivityUserInitiatedAllowingIdleSystemSleep | NSActivityLatencyCritical) & ~(NSActivitySuddenTerminationDisabled | NSActivityAutomaticTerminationDisabled);
- static id assertion = [[[NSProcessInfo processInfo] beginActivityWithOptions:options reason:@"WebKitTestRunner should not be subject to process suppression"] retain];
- ASSERT_UNUSED(assertion, assertion);
+ static NeverDestroyed<RetainPtr<id>> assertion = [[NSProcessInfo processInfo] beginActivityWithOptions:options reason:@"WebKitTestRunner should not be subject to process suppression"];
+ ASSERT_UNUSED(assertion, assertion.get());
}