iOS Safari will not load USDZ in QLPreview when opening as BLOB
authordino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 18 Feb 2019 19:09:39 +0000 (19:09 +0000)
committerdino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 18 Feb 2019 19:09:39 +0000 (19:09 +0000)
https://bugs.webkit.org/show_bug.cgi?id=194766
<rdar://problem/42769186>

Reviewed by Wenson Hsieh.

A download from a Blob URL can happen effectively instantly, which means
that the loadHandler on the registerItemForTypeIdentifier method might not have
been called yet, and we haven't been told what the completionHandler is.
In this case, keep a record of the URL we finished with, and call the completionHandler
right away.

* UIProcess/Cocoa/SystemPreviewControllerCocoa.mm: Add a new private member variable: _downloadedURL.
(-[_WKPreviewControllerDataSource previewController:previewItemAtIndex:]): Call the completionHandler
right away if we've finished.
(-[_WKPreviewControllerDataSource finish:]): Remember that we've finished by recording the URL.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@241730 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/Cocoa/SystemPreviewControllerCocoa.mm

index 9bdcb97..fd3379f 100644 (file)
@@ -1,3 +1,22 @@
+2019-02-18  Dean Jackson  <dino@apple.com>
+
+        iOS Safari will not load USDZ in QLPreview when opening as BLOB
+        https://bugs.webkit.org/show_bug.cgi?id=194766
+        <rdar://problem/42769186>
+
+        Reviewed by Wenson Hsieh.
+
+        A download from a Blob URL can happen effectively instantly, which means
+        that the loadHandler on the registerItemForTypeIdentifier method might not have
+        been called yet, and we haven't been told what the completionHandler is.
+        In this case, keep a record of the URL we finished with, and call the completionHandler
+        right away.
+
+        * UIProcess/Cocoa/SystemPreviewControllerCocoa.mm: Add a new private member variable: _downloadedURL.
+        (-[_WKPreviewControllerDataSource previewController:previewItemAtIndex:]): Call the completionHandler
+        right away if we've finished.
+        (-[_WKPreviewControllerDataSource finish:]): Remember that we've finished by recording the URL.
+
 2019-02-18  Alex Christensen  <achristensen@webkit.org>
 
         Disable safe browsing in WKWebView and remove its WKPreferences API
index 31f2871..7498ba4 100644 (file)
@@ -41,6 +41,7 @@
 @interface _WKPreviewControllerDataSource : NSObject <QLPreviewControllerDataSource> {
     RetainPtr<NSItemProvider> _itemProvider;
     RetainPtr<QLItem> _item;
+    URL _downloadedURL;
 };
 
 @property (strong) NSItemProviderCompletionHandler completionHandler;
 
     WeakObjCPtr<_WKPreviewControllerDataSource> weakSelf { self };
     [_itemProvider registerItemForTypeIdentifier:contentType loadHandler:[weakSelf = WTFMove(weakSelf)] (NSItemProviderCompletionHandler completionHandler, Class expectedValueClass, NSDictionary * options) {
-        if (auto strongSelf = weakSelf.get())
-            [strongSelf setCompletionHandler:completionHandler];
+        if (auto strongSelf = weakSelf.get()) {
+            // If the download happened instantly, the call to finish might have come before this
+            // loadHandler. In that case, call the completionHandler here.
+            if (!strongSelf->_downloadedURL.isEmpty())
+                completionHandler((NSURL*)strongSelf->_downloadedURL, nil);
+            else
+                [strongSelf setCompletionHandler:completionHandler];
+        }
     }];
     return _item.get();
 }
 
 - (void)finish:(URL)url
 {
+    _downloadedURL = url;
+
     if (self.completionHandler)
         self.completionHandler((NSURL*)url, nil);
 }