Changeset 260611 in webkit


Ignore:
Timestamp:
Apr 23, 2020 5:46:18 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.
  • 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

    r260608 r260611  
     12020-04-23  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`.
     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-23  Megan Gardner  <megan_gardner@apple.com>
    254
  • trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm

    r260498 r260611  
    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

    r260498 r260611  
    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

    r260581 r260611  
    3535@implementation WKQLThumbnailQueueManager
    3636
    37 - (id)init
     37- (instancetype)init
    3838{
    3939    self = [super init];
    4040    if (self)
    41         _qlThumbnailGenerationQueue = [[NSOperationQueue alloc] init];
     41        _queue = [[NSOperationQueue alloc] init];
    4242    return self;
     43}
     44
     45- (void)dealloc
     46{
     47    [_queue release];
     48    [super dealloc];
    4349}
    4450
     
    5157@end
    5258
     59@interface WKQLThumbnailLoadOperation ()
     60@property (atomic, readwrite, getter=isExecuting) BOOL executing;
     61@property (atomic, readwrite, getter=isFinished) BOOL finished;
     62@end
     63
    5364@implementation WKQLThumbnailLoadOperation {
    5465    RetainPtr<NSURL> _filePath;
    55     RetainPtr<NSMutableString> _identifier;
     66    RetainPtr<NSString> _identifier;
    5667    RetainPtr<NSFileWrapper> _fileWrapper;
    57 #if PLATFORM(MAC)
    58     RetainPtr<NSImage> _thumbnail;
    59 #endif
    60 #if PLATFORM(IOS_FAMILY)
    61     RetainPtr<UIImage> _thumbnail;
    62 #endif
     68    RetainPtr<CocoaImage> _thumbnail;
     69    BOOL _shouldWrite;
    6370}
    6471
    65 - (id)initWithAttachment:(NSFileWrapper *)fileWrapper identifier:(NSString *)identifier
     72- (instancetype)initWithAttachment:(NSFileWrapper *)fileWrapper identifier:(NSString *)identifier
    6673{
    6774    if (self = [super init]) {
     
    7380}
    7481
    75 - (id)initWithURL:(NSString *)fileURL identifier:(NSString *)identifier
     82- (instancetype)initWithURL:(NSString *)fileURL identifier:(NSString *)identifier
    7683{
    7784    if (self = [super init]) {
     
    8592{
    8693    self.executing = YES;
    87    
     94
    8895    if (_shouldWrite) {
    8996        NSString *temporaryDirectory = FileSystem::createTemporaryDirectory(@"QLTempFileData");
    90    
     97
    9198        NSString *filePath = [temporaryDirectory stringByAppendingPathComponent:[_fileWrapper preferredFilename]];
    9299        NSFileWrapperWritingOptions options = 0;
     
    101108    }
    102109
    103     auto req = adoptNS([WebKit::allocQLThumbnailGenerationRequestInstance() initWithFileAtURL:_filePath.get() size:CGSizeMake(400, 400) scale:1 representationTypes:QLThumbnailGenerationRequestRepresentationTypeAll]);
    104     [req setIconMode:YES];
     110    auto request = adoptNS([WebKit::allocQLThumbnailGenerationRequestInstance() initWithFileAtURL:_filePath.get() size:CGSizeMake(400, 400) scale:1 representationTypes:QLThumbnailGenerationRequestRepresentationTypeAll]);
     111    [request setIconMode:YES];
    105112   
    106     [[WebKit::getQLThumbnailGeneratorClass() sharedGenerator] generateBestRepresentationForRequest:req.get() completionHandler:^(QLThumbnailRepresentation *thumbnail, NSError *error) {
     113    [[WebKit::getQLThumbnailGeneratorClass() sharedGenerator] generateBestRepresentationForRequest:request.get() completionHandler:^(QLThumbnailRepresentation *thumbnail, NSError *error) {
    107114        if (error)
    108115            return;
    109116        if (_thumbnail)
    110117            return;
    111 #if PLATFORM(MAC)
     118#if USE(APPKIT)
    112119        _thumbnail = thumbnail.NSImage;
    113 #endif
    114 #if PLATFORM(IOS_FAMILY)
     120#else
    115121        _thumbnail = thumbnail.UIImage;
    116122#endif
     
    123129}
    124130
    125 #if PLATFORM(IOS_FAMILY)
    126 - (UIImage *)thumbnail
     131- (CocoaImage *)thumbnail
    127132{
    128133    return _thumbnail.get();
    129134}
    130 #endif
    131 
    132 #if PLATFORM(MAC)
    133 - (NSImage *)thumbnail
    134 {
    135     return _thumbnail.get();
    136 }
    137 #endif
    138135
    139136- (NSString *)identifier
     
    189186@end
    190187
    191 #endif
     188#endif // HAVE(QUICKLOOK_THUMBNAILING)
Note: See TracChangeset for help on using the changeset viewer.