<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[260478] trunk/Source/WebKit</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/260478">260478</a></dd>
<dt>Author</dt> <dd>ddkilzer@apple.com</dd>
<dt>Date</dt> <dd>2020-04-21 17:51:48 -0700 (Tue, 21 Apr 2020)</dd>
</dl>

<h3>Log Message</h3>
<pre>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.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitUIProcessCocoaWebPageProxyCocoamm">trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm</a></li>
<li><a href="#trunkSourceWebKitUIProcessQuickLookThumbnailLoaderh">trunk/Source/WebKit/UIProcess/QuickLookThumbnailLoader.h</a></li>
<li><a href="#trunkSourceWebKitUIProcessQuickLookThumbnailLoadermm">trunk/Source/WebKit/UIProcess/QuickLookThumbnailLoader.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (260477 => 260478)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog    2020-04-22 00:29:33 UTC (rev 260477)
+++ trunk/Source/WebKit/ChangeLog       2020-04-22 00:51:48 UTC (rev 260478)
</span><span class="lines">@@ -1,5 +1,57 @@
</span><span class="cx"> 2020-04-21  David Kilzer  <ddkilzer@apple.com>
</span><span class="cx"> 
</span><ins>+        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.
+
+2020-04-21  David Kilzer  <ddkilzer@apple.com>
+
</ins><span class="cx">         Fix extra/missing #undef statements
</span><span class="cx">         <https://webkit.org/b/210818>
</span><span class="cx">         <rdar://problem/61973329>
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessCocoaWebPageProxyCocoamm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm (260477 => 260478)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm 2020-04-22 00:29:33 UTC (rev 260477)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm    2020-04-22 00:51:48 UTC (rev 260478)
</span><span class="lines">@@ -389,13 +389,8 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if HAVE(QUICKLOOK_THUMBNAILING)
</span><del>-#if PLATFORM(MAC)
-using PlatformImage = NSImage*;
-#elif PLATFORM(IOS_FAMILY)
-using PlatformImage = UIImage*;
-#endif
</del><span class="cx"> 
</span><del>-static RefPtr<WebKit::ShareableBitmap> convertPlatformImageToBitmap(PlatformImage image, const WebCore::IntSize& size)
</del><ins>+static RefPtr<WebKit::ShareableBitmap> convertPlatformImageToBitmap(CocoaImage *image, const WebCore::IntSize& size)
</ins><span class="cx"> {
</span><span class="cx">     WebKit::ShareableBitmap::Configuration bitmapConfiguration;
</span><span class="cx">     auto bitmap = WebKit::ShareableBitmap::createShareable(size, bitmapConfiguration);
</span><span class="lines">@@ -432,7 +427,7 @@
</span><span class="cx">         });
</span><span class="cx">     }];
</span><span class="cx">         
</span><del>-    [[WKQLThumbnailQueueManager sharedInstance].qlThumbnailGenerationQueue addOperation:operation];
</del><ins>+    [[WKQLThumbnailQueueManager sharedInstance].queue addOperation:operation];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -449,7 +444,8 @@
</span><span class="cx">     
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-#endif
</del><ins>+#endif // HAVE(QUICKLOOK_THUMBNAILING)
+
</ins><span class="cx"> } // namespace WebKit
</span><span class="cx"> 
</span><span class="cx"> #undef MESSAGE_CHECK_COMPLETION
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessQuickLookThumbnailLoaderh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/QuickLookThumbnailLoader.h (260477 => 260478)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/QuickLookThumbnailLoader.h 2020-04-22 00:29:33 UTC (rev 260477)
+++ trunk/Source/WebKit/UIProcess/QuickLookThumbnailLoader.h    2020-04-22 00:51:48 UTC (rev 260478)
</span><span class="lines">@@ -25,36 +25,35 @@
</span><span class="cx"> 
</span><span class="cx"> #if HAVE(QUICKLOOK_THUMBNAILING)
</span><span class="cx"> 
</span><del>-#if PLATFORM(IOS_FAMILY)
</del><ins>+#if USE(APPKIT)
+@class NSImage;
+using CocoaImage = NSImage;
+#else
</ins><span class="cx"> @class UIImage;
</span><ins>+using CocoaImage = UIImage;
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> @interface WKQLThumbnailQueueManager : NSObject
</span><span class="cx"> 
</span><del>-@property (nonatomic, readwrite, retain) NSOperationQueue* qlThumbnailGenerationQueue;
-- (id)init;
</del><ins>+@property (nonatomic, readonly, retain) NSOperationQueue *queue;
+
+- (instancetype)init;
</ins><span class="cx"> + (WKQLThumbnailQueueManager *)sharedInstance;
</span><ins>+
</ins><span class="cx"> @end
</span><span class="cx"> 
</span><span class="cx"> @interface WKQLThumbnailLoadOperation : NSOperation
</span><span class="cx"> 
</span><del>-@property (readonly, getter=isAsynchronous) BOOL asynchronous;
-@property (readonly, getter=isExecuting) BOOL executing;
-@property (readonly, getter=isFinished) BOOL finished;
</del><ins>+@property (atomic, readonly, getter=isAsynchronous) BOOL asynchronous;
+@property (atomic, readonly, getter=isExecuting) BOOL executing;
+@property (atomic, readonly, getter=isFinished) BOOL finished;
</ins><span class="cx"> 
</span><del>-@property (nonatomic, copy) NSString *contentType;
-@property (nonatomic) BOOL shouldWrite;
</del><ins>+@property (nonatomic, readonly, copy) NSString *identifier;
+@property (nonatomic, readonly, retain) CocoaImage *thumbnail;
</ins><span class="cx"> 
</span><del>-- (id)initWithAttachment:(NSFileWrapper *)fileWrapper identifier:(NSString *)identifier;
-- (id)initWithURL:(NSString *)fileURL identifier:(NSString *)identifier;
-- (NSString *)identifier;
-#if PLATFORM(IOS_FAMILY)
--(UIImage *)thumbnail;
-#endif
-#if PLATFORM(MAC)
--(NSImage *)thumbnail;
-#endif
</del><ins>+- (instancetype)initWithAttachment:(NSFileWrapper *)fileWrapper identifier:(NSString *)identifier;
+- (instancetype)initWithURL:(NSString *)fileURL identifier:(NSString *)identifier;
</ins><span class="cx"> 
</span><span class="cx"> @end
</span><span class="cx"> 
</span><del>-#endif
</del><ins>+#endif // HAVE(QUICKLOOK_THUMBNAILING)
</ins></span></pre></div>
<a id="trunkSourceWebKitUIProcessQuickLookThumbnailLoadermm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/QuickLookThumbnailLoader.mm (260477 => 260478)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/QuickLookThumbnailLoader.mm        2020-04-22 00:29:33 UTC (rev 260477)
+++ trunk/Source/WebKit/UIProcess/QuickLookThumbnailLoader.mm   2020-04-22 00:51:48 UTC (rev 260478)
</span><span class="lines">@@ -33,14 +33,20 @@
</span><span class="cx"> 
</span><span class="cx"> @implementation WKQLThumbnailQueueManager 
</span><span class="cx"> 
</span><del>-- (id)init
</del><ins>+- (instancetype)init
</ins><span class="cx"> {
</span><span class="cx">     self = [super init];
</span><span class="cx">     if (self)
</span><del>-        _qlThumbnailGenerationQueue = [[NSOperationQueue alloc] init];
</del><ins>+        _queue = [[NSOperationQueue alloc] init];
</ins><span class="cx">     return self;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (void)dealloc
+{
+    [_queue release];
+    [super dealloc];
+}
+
</ins><span class="cx"> + (WKQLThumbnailQueueManager *)sharedInstance
</span><span class="cx"> {
</span><span class="cx">     static WKQLThumbnailQueueManager *sharedInstance = [[WKQLThumbnailQueueManager alloc] init];
</span><span class="lines">@@ -49,19 +55,20 @@
</span><span class="cx"> 
</span><span class="cx"> @end
</span><span class="cx"> 
</span><ins>+@interface WKQLThumbnailLoadOperation ()
+@property (atomic, readwrite, getter=isExecuting) BOOL executing;
+@property (atomic, readwrite, getter=isFinished) BOOL finished;
+@end
+
</ins><span class="cx"> @implementation WKQLThumbnailLoadOperation {
</span><span class="cx">     RetainPtr<NSURL> _filePath;
</span><del>-    RetainPtr<NSMutableString> _identifier;
</del><ins>+    RetainPtr<NSString> _identifier;
</ins><span class="cx">     RetainPtr<NSFileWrapper> _fileWrapper;
</span><del>-#if PLATFORM(MAC)
-    RetainPtr<NSImage> _thumbnail;
-#endif
-#if PLATFORM(IOS_FAMILY)
-    RetainPtr<UIImage> _thumbnail;
-#endif
</del><ins>+    RetainPtr<CocoaImage> _thumbnail;
+    BOOL _shouldWrite;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (id)initWithAttachment:(NSFileWrapper *)fileWrapper identifier:(NSString *)identifier
</del><ins>+- (instancetype)initWithAttachment:(NSFileWrapper *)fileWrapper identifier:(NSString *)identifier
</ins><span class="cx"> {
</span><span class="cx">     if (self = [super init]) {
</span><span class="cx">         _fileWrapper = fileWrapper;
</span><span class="lines">@@ -71,7 +78,7 @@
</span><span class="cx">     return self;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (id)initWithURL:(NSString *)fileURL identifier:(NSString *)identifier
</del><ins>+- (instancetype)initWithURL:(NSString *)fileURL identifier:(NSString *)identifier
</ins><span class="cx"> {
</span><span class="cx">     if (self = [super init]) {
</span><span class="cx">         _identifier = adoptNS([identifier copy]);
</span><span class="lines">@@ -83,14 +90,14 @@
</span><span class="cx"> - (void)start
</span><span class="cx"> {
</span><span class="cx">     self.executing = YES;
</span><del>-    
</del><ins>+
</ins><span class="cx">     if (_shouldWrite) {
</span><span class="cx">         NSString *temporaryDirectory = FileSystem::createTemporaryDirectory(@"QLTempFileData");
</span><del>-    
</del><ins>+
</ins><span class="cx">         NSString *filePath = [temporaryDirectory stringByAppendingPathComponent:[_fileWrapper preferredFilename]];
</span><span class="cx">         NSFileWrapperWritingOptions options = 0;
</span><span class="cx">         NSError *error = nil;
</span><del>-        
</del><ins>+
</ins><span class="cx">         auto fileURLPath = adoptNS([NSURL fileURLWithPath:filePath]);
</span><span class="cx"> 
</span><span class="cx">         [_fileWrapper writeToURL:fileURLPath.get() options:options originalContentsURL:nil error:&error];
</span><span class="lines">@@ -99,18 +106,17 @@
</span><span class="cx">             return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    QLThumbnailGenerationRequest *req = [[QLThumbnailGenerationRequest alloc] initWithFileAtURL:_filePath.get() size:CGSizeMake(400, 400) scale:1 representationTypes:QLThumbnailGenerationRequestRepresentationTypeAll];
-    req.iconMode = YES;
-    
-    [[QLThumbnailGenerator sharedGenerator] generateBestRepresentationForRequest:req completionHandler:^(QLThumbnailRepresentation *thumbnail, NSError *error) {
</del><ins>+    RetainPtr<QLThumbnailGenerationRequest> request = adoptNS([[QLThumbnailGenerationRequest alloc] initWithFileAtURL:_filePath.get() size:CGSizeMake(400, 400) scale:1 representationTypes:QLThumbnailGenerationRequestRepresentationTypeAll]);
+    request.get().iconMode = YES;
+
+    [[QLThumbnailGenerator sharedGenerator] generateBestRepresentationForRequest:request.get() completionHandler:^(QLThumbnailRepresentation *thumbnail, NSError *error) {
</ins><span class="cx">         if (error)
</span><span class="cx">             return;
</span><span class="cx">         if (_thumbnail)
</span><span class="cx">             return;
</span><del>-#if PLATFORM(MAC)
</del><ins>+#if USE(APPKIT)
</ins><span class="cx">         _thumbnail = thumbnail.NSImage;
</span><del>-#endif
-#if PLATFORM(IOS_FAMILY)
</del><ins>+#else
</ins><span class="cx">         _thumbnail = thumbnail.UIImage;
</span><span class="cx"> #endif
</span><span class="cx">         if (_shouldWrite)
</span><span class="lines">@@ -121,20 +127,11 @@
</span><span class="cx">     }];
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-#if PLATFORM(IOS_FAMILY)
-- (UIImage *)thumbnail
</del><ins>+- (CocoaImage *)thumbnail
</ins><span class="cx"> {
</span><span class="cx">     return _thumbnail.get();
</span><span class="cx"> }
</span><del>-#endif
</del><span class="cx"> 
</span><del>-#if PLATFORM(MAC)
-- (NSImage *)thumbnail
-{
-    return _thumbnail.get();
-}
-#endif
-
</del><span class="cx"> - (NSString *)identifier
</span><span class="cx"> {
</span><span class="cx">     return _identifier.get();
</span><span class="lines">@@ -187,4 +184,4 @@
</span><span class="cx"> 
</span><span class="cx"> @end
</span><span class="cx"> 
</span><del>-#endif
</del><ins>+#endif // HAVE(QUICKLOOK_THUMBNAILING)
</ins></span></pre>
</div>
</div>

</body>
</html>