Title: [231825] trunk/Source/WebKit
Revision
231825
Author
[email protected]
Date
2018-05-15 17:39:10 -0700 (Tue, 15 May 2018)

Log Message

Launch System Preview as the download starts, rather than waiting for a response
https://bugs.webkit.org/show_bug.cgi?id=185669
<rdar://problem/40278181>

Reviewed by Tim Horton.

We were waiting for the RequestResponse to get a MIME-type before
launching the system preview. This causes an annoying delay.

Instead, assume that the system preview is one of the handled
mime types and launch the viewer immediately. If it gets something it
didn't expect, it will show an error.

* UIProcess/Cocoa/DownloadClient.mm:
(WebKit::DownloadClient::didStart):
(WebKit::DownloadClient::didReceiveResponse):
* UIProcess/Cocoa/SystemPreviewControllerCocoa.mm:
(-[_WKPreviewControllerDataSource previewController:previewItemAtIndex:]):
(WebKit::SystemPreviewController::start): Small cleanup to ensure we
don't try to present twice (this shouldn't happen).

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (231824 => 231825)


--- trunk/Source/WebKit/ChangeLog	2018-05-16 00:30:25 UTC (rev 231824)
+++ trunk/Source/WebKit/ChangeLog	2018-05-16 00:39:10 UTC (rev 231825)
@@ -1,5 +1,28 @@
 2018-05-15  Dean Jackson  <[email protected]>
 
+        Launch System Preview as the download starts, rather than waiting for a response
+        https://bugs.webkit.org/show_bug.cgi?id=185669
+        <rdar://problem/40278181>
+
+        Reviewed by Tim Horton.
+
+        We were waiting for the RequestResponse to get a MIME-type before
+        launching the system preview. This causes an annoying delay.
+
+        Instead, assume that the system preview is one of the handled
+        mime types and launch the viewer immediately. If it gets something it
+        didn't expect, it will show an error.
+
+        * UIProcess/Cocoa/DownloadClient.mm:
+        (WebKit::DownloadClient::didStart):
+        (WebKit::DownloadClient::didReceiveResponse):
+        * UIProcess/Cocoa/SystemPreviewControllerCocoa.mm:
+        (-[_WKPreviewControllerDataSource previewController:previewItemAtIndex:]):
+        (WebKit::SystemPreviewController::start): Small cleanup to ensure we
+        don't try to present twice (this shouldn't happen).
+
+2018-05-15  Dean Jackson  <[email protected]>
+
         Post-review cleanup for 185459
         https://bugs.webkit.org/show_bug.cgi?id=185665
         <rdar://problem/40276689>

Modified: trunk/Source/WebKit/UIProcess/Cocoa/DownloadClient.mm (231824 => 231825)


--- trunk/Source/WebKit/UIProcess/Cocoa/DownloadClient.mm	2018-05-16 00:30:25 UTC (rev 231824)
+++ trunk/Source/WebKit/UIProcess/Cocoa/DownloadClient.mm	2018-05-16 00:39:10 UTC (rev 231825)
@@ -76,6 +76,10 @@
 {
 #if USE(SYSTEM_PREVIEW)
     if (downloadProxy.isSystemPreviewDownload()) {
+        if (auto* webPage = downloadProxy.originatingPage()) {
+            // FIXME: Update the MIME-type once it is known in the ResourceResponse.
+            webPage->systemPreviewController()->start(ASCIILiteral { "application/octet-stream" });
+        }
         takeActivityToken(downloadProxy);
         return;
     }
@@ -91,10 +95,8 @@
     if (downloadProxy.isSystemPreviewDownload()) {
         downloadProxy.setExpectedContentLength(response.expectedContentLength());
         downloadProxy.setBytesLoaded(0);
-        if (auto* webPage = downloadProxy.originatingPage()) {
-            webPage->systemPreviewController()->start(response.mimeType());
+        if (auto* webPage = downloadProxy.originatingPage())
             webPage->systemPreviewController()->updateProgress(0);
-        }
         return;
     }
 #endif

Modified: trunk/Source/WebKit/UIProcess/Cocoa/SystemPreviewControllerCocoa.mm (231824 => 231825)


--- trunk/Source/WebKit/UIProcess/Cocoa/SystemPreviewControllerCocoa.mm	2018-05-16 00:30:25 UTC (rev 231824)
+++ trunk/Source/WebKit/UIProcess/Cocoa/SystemPreviewControllerCocoa.mm	2018-05-16 00:39:10 UTC (rev 231825)
@@ -80,7 +80,9 @@
     _itemProvider = adoptNS([[NSItemProvider alloc] init]);
     NSString *contentType = @"public.content";
 #if USE(APPLE_INTERNAL_SDK)
-    contentType = WebKit::getUTIForMIMEType(self.mimeType);
+    // FIXME: We are launching the preview controller before getting a response from the resource, which
+    // means we don't actually know the real MIME type yet. Assume it is one of those that we registered.
+    contentType = WebKit::getUTIForMIMEType(*WebKit::getSystemPreviewMIMETypes().begin());
 #endif
     _item = adoptNS([allocQLItemInstance() initWithPreviewItemProvider:_itemProvider.get() contentType:contentType previewTitle:@"Preview" fileSize:@(0)]);
     [_item setUseLoadingTimeout:NO];
@@ -158,7 +160,9 @@
 
 void SystemPreviewController::start(const String& mimeType)
 {
-    // FIXME: Make sure you can't show a preview if we're already previewing.
+    ASSERT(!m_qlPreviewController);
+    if (m_qlPreviewController)
+        return;
 
     UIViewController *presentingViewController = m_webPageProxy.uiClient().presentingViewController();
 
@@ -165,17 +169,14 @@
     if (!presentingViewController)
         return;
 
-    if (!m_qlPreviewController) {
-        m_qlPreviewController = adoptNS([allocQLPreviewControllerInstance() init]);
+    m_qlPreviewController = adoptNS([allocQLPreviewControllerInstance() init]);
 
-        m_qlPreviewControllerDelegate = adoptNS([[_WKPreviewControllerDelegate alloc] initWithSystemPreviewController:this]);
-        [m_qlPreviewController setDelegate:m_qlPreviewControllerDelegate.get()];
+    m_qlPreviewControllerDelegate = adoptNS([[_WKPreviewControllerDelegate alloc] initWithSystemPreviewController:this]);
+    [m_qlPreviewController setDelegate:m_qlPreviewControllerDelegate.get()];
 
-        m_qlPreviewControllerDataSource = adoptNS([[_WKPreviewControllerDataSource alloc] initWithMIMEType:mimeType]);
-        [m_qlPreviewController setDataSource:m_qlPreviewControllerDataSource.get()];
+    m_qlPreviewControllerDataSource = adoptNS([[_WKPreviewControllerDataSource alloc] initWithMIMEType:mimeType]);
+    [m_qlPreviewController setDataSource:m_qlPreviewControllerDataSource.get()];
 
-    }
-
     [presentingViewController presentViewController:m_qlPreviewController.get() animated:YES completion:nullptr];
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to