Changeset 260478 in webkit


Ignore:
Timestamp:
Apr 21, 2020 5:51:48 PM (4 years ago)
Author:
ddkilzer@apple.com
Message:

Clean up QuickLookThumbnailLoader
<https://webkit.org/b/210814>

Reviewed by Darin Adler.

The following items are cleaned up:

  • Extract using PlatformImage into QuickLookThumbnailLoader.h, rename to CocoaImage and use to get rid of duplicate code.
  • Change id to instancetype for -init methods.
  • Add atomic keyword to @property definitions that were using it as the default. (Use of atomic properties is rare in WebKit, so being explicit avoids a scenario where it looks like nonatomic was left off by accident.)
  • Change @property definitions to readonly that are never written to outside of QuickLookThumbnailLoader.mm.
  • Delete unused @property definitions.
  • Change method declarations into read-only @property definitions.
  • Re-declare atomic read-only @property definitions in QuickLookThumbnailLoader.h as read-write definitions in QuickLookThumbnailLoader.mm if they are written to.
  • UIProcess/Cocoa/WebPageProxyCocoa.mm:

(WebKit::convertPlatformImageToBitmap):

  • UIProcess/QuickLookThumbnailLoader.h:
  • Rename qlThumbnailGenerationQueue @property to just queue.
  • Remove contentType @property. It is not used anywhere. This also fixes a theoretical leak found by the clang static analyzer.
  • Remove shouldWrite @property. It is only used within QuickLookThumbnailLoader.mm.
  • Change identifier and thumbnail to @property declarations.
  • UIProcess/QuickLookThumbnailLoader.mm:
  • Change WKQLThumbnailLoadOperation._identifier type from NSMutableString to NSString. There was no reason for it to be mutable.

(-[WKQLThumbnailQueueManager init]):
(-[WKQLThumbnailQueueManager dealloc]):

  • Release _queue to fix theoretical leak found by the clang static analyzer.

(-[WKQLThumbnailLoadOperation initWithAttachment:identifier:]):
(-[WKQLThumbnailLoadOperation initWithURL:identifier:]):
(-[WKQLThumbnailLoadOperation start]):

  • Rename req to request and use RetainPtr<>.
  • Change separate #if macros to #if/#else since only one version of this code can be used at a time.

(-[WKQLThumbnailLoadOperation thumbnail]):

  • Use CocoaImage to use one copy of the method.
Location:
trunk/Source/WebKit
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r260476 r260478  
     12020-04-21  David Kilzer  <ddkilzer@apple.com>
     2
     3        Clean up QuickLookThumbnailLoader
     4        <https://webkit.org/b/210814>
     5
     6        Reviewed by Darin Adler.
     7
     8        The following items are cleaned up:
     9        - Extract `using PlatformImage` into QuickLookThumbnailLoader.h,
     10          rename to `CocoaImage` and use to get rid of duplicate
     11          code.
     12        - Change `id` to `instancetype` for -init methods.
     13        - Add `atomic` keyword to @property definitions that were using
     14          it as the default.  (Use of atomic properties is rare in
     15          WebKit, so being explicit avoids a scenario where it looks
     16          like `nonatomic` was left off by accident.)
     17        - Change @property definitions to `readonly` that are never
     18          written to outside of QuickLookThumbnailLoader.mm.
     19        - Delete unused @property definitions.
     20        - Change method declarations into read-only @property
     21          definitions.
     22        - Re-declare atomic read-only @property definitions in
     23          QuickLookThumbnailLoader.h as read-write definitions in
     24          QuickLookThumbnailLoader.mm if they are written to.
     25
     26        * UIProcess/Cocoa/WebPageProxyCocoa.mm:
     27        (WebKit::convertPlatformImageToBitmap):
     28        * UIProcess/QuickLookThumbnailLoader.h:
     29        - Rename qlThumbnailGenerationQueue @property to just `queue`.
     30        - Remove `contentType` @property.  It is not used anywhere.
     31          This also fixes a theoretical leak found by the clang static
     32          analyzer.
     33        - Remove `shouldWrite` @property.  It is only used within
     34          QuickLookThumbnailLoader.mm.
     35        - Change `identifier` and `thumbnail` to @property declarations.
     36        * UIProcess/QuickLookThumbnailLoader.mm:
     37        - Change WKQLThumbnailLoadOperation._identifier type from
     38          NSMutableString to NSString.  There was no reason for it to
     39          be mutable.
     40        (-[WKQLThumbnailQueueManager init]):
     41        (-[WKQLThumbnailQueueManager dealloc]):
     42        - Release `_queue` to fix theoretical leak found by the clang
     43          static analyzer.
     44        (-[WKQLThumbnailLoadOperation initWithAttachment:identifier:]):
     45        (-[WKQLThumbnailLoadOperation initWithURL:identifier:]):
     46        (-[WKQLThumbnailLoadOperation start]):
     47        - Rename `req` to `request` and use RetainPtr<>.
     48        - Change separate #if macros to #if/#else since only one version
     49          of this code can be used at a time.
     50        (-[WKQLThumbnailLoadOperation thumbnail]):
     51        - Use CocoaImage to use one copy of the method.
     52
    1532020-04-21  David Kilzer  <ddkilzer@apple.com>
    254
  • trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm

    r260407 r260478  
    390390
    391391#if HAVE(QUICKLOOK_THUMBNAILING)
    392 #if PLATFORM(MAC)
    393 using PlatformImage = NSImage*;
    394 #elif PLATFORM(IOS_FAMILY)
    395 using PlatformImage = UIImage*;
    396 #endif
    397 
    398 static RefPtr<WebKit::ShareableBitmap> convertPlatformImageToBitmap(PlatformImage image, const WebCore::IntSize& size)
     392
     393static RefPtr<WebKit::ShareableBitmap> convertPlatformImageToBitmap(CocoaImage *image, const WebCore::IntSize& size)
    399394{
    400395    WebKit::ShareableBitmap::Configuration bitmapConfiguration;
     
    433428    }];
    434429       
    435     [[WKQLThumbnailQueueManager sharedInstance].qlThumbnailGenerationQueue addOperation:operation];
     430    [[WKQLThumbnailQueueManager sharedInstance].queue addOperation:operation];
    436431}
    437432
     
    450445}
    451446
    452 #endif
     447#endif // HAVE(QUICKLOOK_THUMBNAILING)
     448
    453449} // namespace WebKit
    454450
  • trunk/Source/WebKit/UIProcess/QuickLookThumbnailLoader.h

    r260407 r260478  
    2626#if HAVE(QUICKLOOK_THUMBNAILING)
    2727
    28 #if PLATFORM(IOS_FAMILY)
     28#if USE(APPKIT)
     29@class NSImage;
     30using CocoaImage = NSImage;
     31#else
    2932@class UIImage;
     33using CocoaImage = UIImage;
    3034#endif
    3135
    3236@interface WKQLThumbnailQueueManager : NSObject
    3337
    34 @property (nonatomic, readwrite, retain) NSOperationQueue* qlThumbnailGenerationQueue;
    35 - (id)init;
     38@property (nonatomic, readonly, retain) NSOperationQueue *queue;
     39
     40- (instancetype)init;
    3641+ (WKQLThumbnailQueueManager *)sharedInstance;
     42
    3743@end
    3844
    3945@interface WKQLThumbnailLoadOperation : NSOperation
    4046
    41 @property (readonly, getter=isAsynchronous) BOOL asynchronous;
    42 @property (readonly, getter=isExecuting) BOOL executing;
    43 @property (readonly, getter=isFinished) BOOL finished;
     47@property (atomic, readonly, getter=isAsynchronous) BOOL asynchronous;
     48@property (atomic, readonly, getter=isExecuting) BOOL executing;
     49@property (atomic, readonly, getter=isFinished) BOOL finished;
    4450
    45 @property (nonatomic, copy) NSString *contentType;
    46 @property (nonatomic) BOOL shouldWrite;
     51@property (nonatomic, readonly, copy) NSString *identifier;
     52@property (nonatomic, readonly, retain) CocoaImage *thumbnail;
    4753
    48 - (id)initWithAttachment:(NSFileWrapper *)fileWrapper identifier:(NSString *)identifier;
    49 - (id)initWithURL:(NSString *)fileURL identifier:(NSString *)identifier;
    50 - (NSString *)identifier;
    51 #if PLATFORM(IOS_FAMILY)
    52 -(UIImage *)thumbnail;
    53 #endif
    54 #if PLATFORM(MAC)
    55 -(NSImage *)thumbnail;
    56 #endif
     54- (instancetype)initWithAttachment:(NSFileWrapper *)fileWrapper identifier:(NSString *)identifier;
     55- (instancetype)initWithURL:(NSString *)fileURL identifier:(NSString *)identifier;
    5756
    5857@end
    5958
    60 #endif
     59#endif // HAVE(QUICKLOOK_THUMBNAILING)
  • trunk/Source/WebKit/UIProcess/QuickLookThumbnailLoader.mm

    r260407 r260478  
    3434@implementation WKQLThumbnailQueueManager
    3535
    36 - (id)init
     36- (instancetype)init
    3737{
    3838    self = [super init];
    3939    if (self)
    40         _qlThumbnailGenerationQueue = [[NSOperationQueue alloc] init];
     40        _queue = [[NSOperationQueue alloc] init];
    4141    return self;
     42}
     43
     44- (void)dealloc
     45{
     46    [_queue release];
     47    [super dealloc];
    4248}
    4349
     
    5056@end
    5157
     58@interface WKQLThumbnailLoadOperation ()
     59@property (atomic, readwrite, getter=isExecuting) BOOL executing;
     60@property (atomic, readwrite, getter=isFinished) BOOL finished;
     61@end
     62
    5263@implementation WKQLThumbnailLoadOperation {
    5364    RetainPtr<NSURL> _filePath;
    54     RetainPtr<NSMutableString> _identifier;
     65    RetainPtr<NSString> _identifier;
    5566    RetainPtr<NSFileWrapper> _fileWrapper;
    56 #if PLATFORM(MAC)
    57     RetainPtr<NSImage> _thumbnail;
    58 #endif
    59 #if PLATFORM(IOS_FAMILY)
    60     RetainPtr<UIImage> _thumbnail;
    61 #endif
     67    RetainPtr<CocoaImage> _thumbnail;
     68    BOOL _shouldWrite;
    6269}
    6370
    64 - (id)initWithAttachment:(NSFileWrapper *)fileWrapper identifier:(NSString *)identifier
     71- (instancetype)initWithAttachment:(NSFileWrapper *)fileWrapper identifier:(NSString *)identifier
    6572{
    6673    if (self = [super init]) {
     
    7279}
    7380
    74 - (id)initWithURL:(NSString *)fileURL identifier:(NSString *)identifier
     81- (instancetype)initWithURL:(NSString *)fileURL identifier:(NSString *)identifier
    7582{
    7683    if (self = [super init]) {
     
    8491{
    8592    self.executing = YES;
    86    
     93
    8794    if (_shouldWrite) {
    8895        NSString *temporaryDirectory = FileSystem::createTemporaryDirectory(@"QLTempFileData");
    89    
     96
    9097        NSString *filePath = [temporaryDirectory stringByAppendingPathComponent:[_fileWrapper preferredFilename]];
    9198        NSFileWrapperWritingOptions options = 0;
    9299        NSError *error = nil;
    93        
     100
    94101        auto fileURLPath = adoptNS([NSURL fileURLWithPath:filePath]);
    95102
     
    100107    }
    101108
    102     QLThumbnailGenerationRequest *req = [[QLThumbnailGenerationRequest alloc] initWithFileAtURL:_filePath.get() size:CGSizeMake(400, 400) scale:1 representationTypes:QLThumbnailGenerationRequestRepresentationTypeAll];
    103     req.iconMode = YES;
    104    
    105     [[QLThumbnailGenerator sharedGenerator] generateBestRepresentationForRequest:req completionHandler:^(QLThumbnailRepresentation *thumbnail, NSError *error) {
     109    RetainPtr<QLThumbnailGenerationRequest> request = adoptNS([[QLThumbnailGenerationRequest alloc] initWithFileAtURL:_filePath.get() size:CGSizeMake(400, 400) scale:1 representationTypes:QLThumbnailGenerationRequestRepresentationTypeAll]);
     110    request.get().iconMode = YES;
     111
     112    [[QLThumbnailGenerator sharedGenerator] generateBestRepresentationForRequest:request.get() completionHandler:^(QLThumbnailRepresentation *thumbnail, NSError *error) {
    106113        if (error)
    107114            return;
    108115        if (_thumbnail)
    109116            return;
    110 #if PLATFORM(MAC)
     117#if USE(APPKIT)
    111118        _thumbnail = thumbnail.NSImage;
    112 #endif
    113 #if PLATFORM(IOS_FAMILY)
     119#else
    114120        _thumbnail = thumbnail.UIImage;
    115121#endif
     
    122128}
    123129
    124 #if PLATFORM(IOS_FAMILY)
    125 - (UIImage *)thumbnail
     130- (CocoaImage *)thumbnail
    126131{
    127132    return _thumbnail.get();
    128133}
    129 #endif
    130 
    131 #if PLATFORM(MAC)
    132 - (NSImage *)thumbnail
    133 {
    134     return _thumbnail.get();
    135 }
    136 #endif
    137134
    138135- (NSString *)identifier
     
    188185@end
    189186
    190 #endif
     187#endif // HAVE(QUICKLOOK_THUMBNAILING)
Note: See TracChangeset for help on using the changeset viewer.