Download and present System Preview
authordino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 15 May 2018 09:50:07 +0000 (09:50 +0000)
committerdino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 15 May 2018 09:50:07 +0000 (09:50 +0000)
https://bugs.webkit.org/show_bug.cgi?id=185459
<rdar://problem/40079228>

Reviewed by Tim Horton.

Source/WebCore:

If an <a> is a system preview, tell the resource request about it.

* html/HTMLAnchorElement.cpp:
(WebCore::HTMLAnchorElement::handleClick):

Source/WebKit:

Extend DownloadClient so that it can handle the case where
the download was triggered by a System Preview. In this situation
the result (and progress) are piped into QuickLook via the SystemPreviewController.

The DownloadProxy class is also extended to handle the destination
filename and the size of the content.

Lastly, SystemPreviewController is updated to have a start(), show()
and cancel() interface, and no longer adjusts page navigation.

* UIProcess/Cocoa/DownloadClient.h:
* UIProcess/Cocoa/DownloadClient.mm: Handle the SystemPreview case, which
doesn't have a download delegate, but instead needs to communicate with
the SystemPreviewController, if one exists.
(WebKit::DownloadClient::didStart):
(WebKit::DownloadClient::didReceiveResponse):
(WebKit::DownloadClient::didReceiveData):
(WebKit::DownloadClient::didCreateDestination):
(WebKit::DownloadClient::processDidCrash):
(WebKit::DownloadClient::decideDestinationWithSuggestedFilename):
(WebKit::DownloadClient::didFinish):
(WebKit::DownloadClient::didFail):
(WebKit::DownloadClient::didCancel):
(WebKit::DownloadClient::releaseActivityToken):

* UIProcess/Cocoa/SystemPreviewControllerCocoa.mm: Implement the new API.
(-[_WKPreviewControllerDataSource initWithMIMEType:]):
(-[_WKPreviewControllerDataSource previewController:previewItemAtIndex:]):
(-[_WKPreviewControllerDataSource setProgress:]):
(-[_WKPreviewControllerDataSource finish:]):
(-[_WKPreviewControllerDelegate previewControllerDidDismiss:]):
(WebKit::SystemPreviewController::start):
(WebKit::SystemPreviewController::updateProgress):
(WebKit::SystemPreviewController::finish):
(WebKit::SystemPreviewController::cancel):
(-[_WKPreviewControllerDataSource initWithURL:]): Deleted.
(-[_WKPreviewControllerDelegate previewControllerWillDismiss:]): Deleted.
(WebKit::SystemPreviewController::canPreview const): Deleted.
(WebKit::SystemPreviewController::showPreview): Deleted.
* UIProcess/Downloads/DownloadProxy.h: Track the destination file by name
and size. Also expose a helper to identify system preview downloads.
(WebKit::DownloadProxy::destinationFilename const):
(WebKit::DownloadProxy::setDestinationFilename):
(WebKit::DownloadProxy::expectedContentLength const):
(WebKit::DownloadProxy::setExpectedContentLength):
(WebKit::DownloadProxy::bytesLoaded const):
(WebKit::DownloadProxy::setBytesLoaded):
(WebKit::DownloadProxy::isSystemPreviewDownload const):

* UIProcess/SystemPreviewController.cpp: New API.
(WebKit::SystemPreviewController::canPreview const):
(WebKit::SystemPreviewController::sendPageBack): Deleted.
(WebKit::SystemPreviewController::showPreview): Deleted.
* UIProcess/SystemPreviewController.h:

* UIProcess/WebPageProxy.cpp:
(WebKit::m_configurationPreferenceValues):
(WebKit::WebPageProxy::reattachToWebProcess):
(WebKit::WebPageProxy::resetState):
* UIProcess/WebPageProxy.h:

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

Source/WebCore/ChangeLog
Source/WebCore/html/HTMLAnchorElement.cpp
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/Cocoa/DownloadClient.h
Source/WebKit/UIProcess/Cocoa/DownloadClient.mm
Source/WebKit/UIProcess/Cocoa/SystemPreviewControllerCocoa.mm
Source/WebKit/UIProcess/Downloads/DownloadProxy.h
Source/WebKit/UIProcess/SystemPreviewController.cpp
Source/WebKit/UIProcess/SystemPreviewController.h
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.h

index 7b17536..b959a4f 100644 (file)
@@ -1,3 +1,16 @@
+2018-05-14  Dean Jackson  <dino@apple.com>
+
+        Download and present System Preview
+        https://bugs.webkit.org/show_bug.cgi?id=185459
+        <rdar://problem/40079228>
+
+        Reviewed by Tim Horton.
+
+        If an <a> is a system preview, tell the resource request about it.
+
+        * html/HTMLAnchorElement.cpp:
+        (WebCore::HTMLAnchorElement::handleClick):
+
 2018-05-15  Antti Koivisto  <antti@apple.com>
 
         animation-play-state: paused causes very high cpu load because of style invalidation loop
index a73f680..89a38c1 100644 (file)
@@ -418,6 +418,10 @@ void HTMLAnchorElement::handleClick(Event& event)
 #endif
 
     bool isSystemPreview = false;
+#if USE(SYSTEM_PREVIEW)
+    isSystemPreview = isSystemPreviewLink();
+#endif
+
     ShouldSendReferrer shouldSendReferrer = hasRel(Relation::NoReferrer) ? NeverSendReferrer : MaybeSendReferrer;
     auto newFrameOpenerPolicy = hasRel(Relation::NoOpener) ? std::make_optional(NewFrameOpenerPolicy::Suppress) : std::nullopt;
     frame->loader().urlSelected(completedURL, target(), &event, LockHistory::No, LockBackForwardList::No, shouldSendReferrer, document().shouldOpenExternalURLsPolicyToPropagate(), newFrameOpenerPolicy, downloadAttribute, isSystemPreview);
index 65eb717..dac7438 100644 (file)
@@ -1,3 +1,72 @@
+2018-05-14  Dean Jackson  <dino@apple.com>
+
+        Download and present System Preview
+        https://bugs.webkit.org/show_bug.cgi?id=185459
+        <rdar://problem/40079228>
+
+        Reviewed by Tim Horton.
+
+        Extend DownloadClient so that it can handle the case where
+        the download was triggered by a System Preview. In this situation
+        the result (and progress) are piped into QuickLook via the SystemPreviewController.
+
+        The DownloadProxy class is also extended to handle the destination
+        filename and the size of the content.
+
+        Lastly, SystemPreviewController is updated to have a start(), show()
+        and cancel() interface, and no longer adjusts page navigation.
+
+        * UIProcess/Cocoa/DownloadClient.h:
+        * UIProcess/Cocoa/DownloadClient.mm: Handle the SystemPreview case, which
+        doesn't have a download delegate, but instead needs to communicate with
+        the SystemPreviewController, if one exists.
+        (WebKit::DownloadClient::didStart):
+        (WebKit::DownloadClient::didReceiveResponse):
+        (WebKit::DownloadClient::didReceiveData):
+        (WebKit::DownloadClient::didCreateDestination):
+        (WebKit::DownloadClient::processDidCrash):
+        (WebKit::DownloadClient::decideDestinationWithSuggestedFilename):
+        (WebKit::DownloadClient::didFinish):
+        (WebKit::DownloadClient::didFail):
+        (WebKit::DownloadClient::didCancel):
+        (WebKit::DownloadClient::releaseActivityToken):
+
+        * UIProcess/Cocoa/SystemPreviewControllerCocoa.mm: Implement the new API.
+        (-[_WKPreviewControllerDataSource initWithMIMEType:]):
+        (-[_WKPreviewControllerDataSource previewController:previewItemAtIndex:]):
+        (-[_WKPreviewControllerDataSource setProgress:]):
+        (-[_WKPreviewControllerDataSource finish:]):
+        (-[_WKPreviewControllerDelegate previewControllerDidDismiss:]):
+        (WebKit::SystemPreviewController::start):
+        (WebKit::SystemPreviewController::updateProgress):
+        (WebKit::SystemPreviewController::finish):
+        (WebKit::SystemPreviewController::cancel):
+        (-[_WKPreviewControllerDataSource initWithURL:]): Deleted.
+        (-[_WKPreviewControllerDelegate previewControllerWillDismiss:]): Deleted.
+        (WebKit::SystemPreviewController::canPreview const): Deleted.
+        (WebKit::SystemPreviewController::showPreview): Deleted.
+        * UIProcess/Downloads/DownloadProxy.h: Track the destination file by name
+        and size. Also expose a helper to identify system preview downloads.
+        (WebKit::DownloadProxy::destinationFilename const):
+        (WebKit::DownloadProxy::setDestinationFilename):
+        (WebKit::DownloadProxy::expectedContentLength const):
+        (WebKit::DownloadProxy::setExpectedContentLength):
+        (WebKit::DownloadProxy::bytesLoaded const):
+        (WebKit::DownloadProxy::setBytesLoaded):
+        (WebKit::DownloadProxy::isSystemPreviewDownload const):
+
+        * UIProcess/SystemPreviewController.cpp: New API.
+        (WebKit::SystemPreviewController::canPreview const):
+        (WebKit::SystemPreviewController::sendPageBack): Deleted.
+        (WebKit::SystemPreviewController::showPreview): Deleted.
+        * UIProcess/SystemPreviewController.h:
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::m_configurationPreferenceValues):
+        (WebKit::WebPageProxy::reattachToWebProcess):
+        (WebKit::WebPageProxy::resetState):
+        * UIProcess/WebPageProxy.h:
+
 2018-05-14  Brady Eidson  <beidson@apple.com>
 
         Add an API test to guard against regressions while re-entering setDefersLoading:.
index f163ea0..db3efb7 100644 (file)
@@ -30,6 +30,7 @@
 #if WK_API_ENABLED
 
 #import "APIDownloadClient.h"
+#import "ProcessThrottler.h"
 #import "WeakObjCPtr.h"
 
 @protocol _WKDownloadDelegate;
@@ -59,6 +60,10 @@ private:
     void didCreateDestination(WebProcessPool&, DownloadProxy&, const String&) final;
     void processDidCrash(WebProcessPool&, DownloadProxy&) final;
 
+#if PLATFORM(IOS) && USE(SYSTEM_PREVIEW)
+    void releaseActivityToken(DownloadProxy&);
+#endif
+
     WeakObjCPtr<id <_WKDownloadDelegate>> m_delegate;
 
     struct {
@@ -76,6 +81,10 @@ private:
         bool downloadDidCreateDestination : 1;
         bool downloadProcessDidCrash : 1;
     } m_delegateMethods;
+
+#if PLATFORM(IOS) && USE(SYSTEM_PREVIEW)
+    ProcessThrottler::BackgroundActivityToken m_activityToken;
+#endif
 };
 
 } // namespace WebKit
index b65358e..13ae6da 100644 (file)
 #import "AuthenticationDecisionListener.h"
 #import "CompletionHandlerCallChecker.h"
 #import "DownloadProxy.h"
+#import "Logging.h"
+#import "SystemPreviewController.h"
 #import "WKNSURLAuthenticationChallenge.h"
 #import "WKNSURLExtras.h"
 #import "WebCredential.h"
+#import "WebPageProxy.h"
+#import "WebProcessProxy.h"
 #import "_WKDownloadDelegate.h"
 #import "_WKDownloadInternal.h"
+#import <WebCore/FileSystem.h>
 #import <WebCore/ResourceError.h>
 #import <WebCore/ResourceResponse.h>
 #import <wtf/BlockPtr.h>
@@ -69,24 +74,57 @@ DownloadClient::DownloadClient(id <_WKDownloadDelegate> delegate)
 
 void DownloadClient::didStart(WebProcessPool&, DownloadProxy& downloadProxy)
 {
+#if USE(SYSTEM_PREVIEW)
+    if (downloadProxy.isSystemPreviewDownload()) {
+        if (auto* webPage = downloadProxy.originatingPage()) {
+            RELEASE_LOG_IF(webPage->isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p - UIProcess is taking a background assertion because it is downloading a system preview", this);
+            ASSERT(!m_activityToken);
+            m_activityToken = webPage->process().throttler().backgroundActivityToken();
+        }
+        return;
+    }
+#endif
+
     if (m_delegateMethods.downloadDidStart)
         [m_delegate _downloadDidStart:wrapper(downloadProxy)];
 }
 
 void DownloadClient::didReceiveResponse(WebProcessPool&, DownloadProxy& downloadProxy, const WebCore::ResourceResponse& response)
 {
+#if USE(SYSTEM_PREVIEW)
+    if (downloadProxy.isSystemPreviewDownload()) {
+        downloadProxy.setExpectedContentLength(response.expectedContentLength());
+        downloadProxy.setBytesLoaded(0);
+        if (auto* webPage = downloadProxy.originatingPage()) {
+            webPage->systemPreviewController()->start(response.mimeType());
+            webPage->systemPreviewController()->updateProgress(0);
+        }
+        return;
+    }
+#endif
+
     if (m_delegateMethods.downloadDidReceiveResponse)
         [m_delegate _download:wrapper(downloadProxy) didReceiveResponse:response.nsURLResponse()];
 }
 
 void DownloadClient::didReceiveData(WebProcessPool&, DownloadProxy& downloadProxy, uint64_t length)
 {
+#if USE(SYSTEM_PREVIEW)
+    if (downloadProxy.isSystemPreviewDownload()) {
+        downloadProxy.setBytesLoaded(downloadProxy.bytesLoaded() + length);
+        if (auto* webPage = downloadProxy.originatingPage())
+            webPage->systemPreviewController()->updateProgress(static_cast<float>(downloadProxy.bytesLoaded()) / downloadProxy.expectedContentLength());
+        return;
+    }
+#endif
+
     if (m_delegateMethods.downloadDidReceiveData)
         [m_delegate _download:wrapper(downloadProxy) didReceiveData:length];
 }
 
 void DownloadClient::didReceiveAuthenticationChallenge(WebProcessPool&, DownloadProxy& downloadProxy, AuthenticationChallengeProxy& authenticationChallenge)
 {
+    // FIXME: System Preview needs code here.
     if (!m_delegateMethods.downloadDidReceiveAuthenticationChallengeCompletionHandler) {
         authenticationChallenge.listener()->performDefaultHandling();
         return;
@@ -126,18 +164,42 @@ void DownloadClient::didReceiveAuthenticationChallenge(WebProcessPool&, Download
 
 void DownloadClient::didCreateDestination(WebProcessPool&, DownloadProxy& downloadProxy, const String& destination)
 {
+#if USE(SYSTEM_PREVIEW)
+    if (downloadProxy.isSystemPreviewDownload()) {
+        downloadProxy.setDestinationFilename(destination);
+        return;
+    }
+#endif
+
     if (m_delegateMethods.downloadDidCreateDestination)
         [m_delegate _download:wrapper(downloadProxy) didCreateDestination:destination];
 }
 
 void DownloadClient::processDidCrash(WebProcessPool&, DownloadProxy& downloadProxy)
 {
+#if USE(SYSTEM_PREVIEW)
+    if (downloadProxy.isSystemPreviewDownload()) {
+        if (m_activityToken)
+            releaseActivityToken(downloadProxy);
+        return;
+    }
+#endif
+
     if (m_delegateMethods.downloadProcessDidCrash)
         [m_delegate _downloadProcessDidCrash:wrapper(downloadProxy)];
 }
 
 void DownloadClient::decideDestinationWithSuggestedFilename(WebProcessPool&, DownloadProxy& downloadProxy, const String& filename, Function<void(AllowOverwrite, String)>&& completionHandler)
 {
+#if USE(SYSTEM_PREVIEW)
+    if (downloadProxy.isSystemPreviewDownload()) {
+        NSString *temporaryDirectory = WebCore::FileSystem::createTemporaryDirectory(@"SystemPreviews");
+        NSString *destination = [temporaryDirectory stringByAppendingPathComponent:filename];
+        completionHandler(AllowOverwrite::Yes, destination);
+        return;
+    }
+#endif
+
     if (!m_delegateMethods.downloadDecideDestinationWithSuggestedFilenameAllowOverwrite && !m_delegateMethods.downloadDecideDestinationWithSuggestedFilenameCompletionHandler)
         return completionHandler(AllowOverwrite::No, { });
 
@@ -160,18 +222,50 @@ void DownloadClient::decideDestinationWithSuggestedFilename(WebProcessPool&, Dow
 
 void DownloadClient::didFinish(WebProcessPool&, DownloadProxy& downloadProxy)
 {
+#if USE(SYSTEM_PREVIEW)
+    if (downloadProxy.isSystemPreviewDownload()) {
+        if (auto* webPage = downloadProxy.originatingPage()) {
+            NSURL *destinationURL = [NSURL fileURLWithPath:(NSString *)downloadProxy.destinationFilename()];
+            webPage->systemPreviewController()->finish(WebCore::URL(destinationURL));
+        }
+        if (m_activityToken)
+            releaseActivityToken(downloadProxy);
+        return;
+    }
+#endif
+
     if (m_delegateMethods.downloadDidFinish)
         [m_delegate _downloadDidFinish:wrapper(downloadProxy)];
 }
 
 void DownloadClient::didFail(WebProcessPool&, DownloadProxy& downloadProxy, const WebCore::ResourceError& error)
 {
+#if USE(SYSTEM_PREVIEW)
+    if (downloadProxy.isSystemPreviewDownload()) {
+        if (auto* webPage = downloadProxy.originatingPage())
+            webPage->systemPreviewController()->cancel();
+        if (m_activityToken)
+            releaseActivityToken(downloadProxy);
+        return;
+    }
+#endif
+
     if (m_delegateMethods.downloadDidFail)
         [m_delegate _download:wrapper(downloadProxy) didFailWithError:error.nsError()];
 }
 
 void DownloadClient::didCancel(WebProcessPool&, DownloadProxy& downloadProxy)
 {
+#if USE(SYSTEM_PREVIEW)
+    if (downloadProxy.isSystemPreviewDownload()) {
+        if (auto* webPage = downloadProxy.originatingPage())
+            webPage->systemPreviewController()->cancel();
+        if (m_activityToken)
+            releaseActivityToken(downloadProxy);
+        return;
+    }
+#endif
+
     if (m_delegateMethods.downloadDidCancel)
         [m_delegate _downloadDidCancel:wrapper(downloadProxy)];
 }
@@ -184,6 +278,15 @@ void DownloadClient::willSendRequest(WebProcessPool&, DownloadProxy& downloadPro
     completionHandler(WTFMove(request));
 }
 
+#if PLATFORM(IOS) && USE(SYSTEM_PREVIEW)
+void DownloadClient::releaseActivityToken(DownloadProxy& downloadProxy)
+{
+    RELEASE_LOG_IF(downloadProxy.originatingPage()->isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p UIProcess is releasing a background assertion because a system preview download completed", this);
+    ASSERT(m_activityToken);
+    m_activityToken = nullptr;
+}
+#endif
+
 } // namespace WebKit
 
 #endif // WK_API_ENABLED
index d23a22e..4baaeba 100644 (file)
 #import "APIUIClient.h"
 #import "WebPageProxy.h"
 
+#import <MobileCoreServices/MobileCoreServices.h>
 #import <QuickLook/QuickLook.h>
 #import <UIKit/UIViewController.h>
+#import <pal/spi/ios/QuickLookSPI.h>
 #import <wtf/SoftLinking.h>
 
 #if USE(APPLE_INTERNAL_SDK)
 
 SOFT_LINK_FRAMEWORK(QuickLook)
 SOFT_LINK_CLASS(QuickLook, QLPreviewController);
+SOFT_LINK_CLASS(QuickLook, QLItem);
 
 @interface _WKPreviewControllerDataSource : NSObject <QLPreviewControllerDataSource> {
+    RetainPtr<NSItemProvider> _itemProvider;
+    RetainPtr<QLItem> _item;
 };
 
-@property (nonatomic) WebCore::URL url;
+@property (strong) NSItemProviderCompletionHandler completionHandler;
+@property (retain) NSString *mimeType;
 
 @end
 
 @implementation _WKPreviewControllerDataSource
 
-- (id)initWithURL:(const WebCore::URL&)url
+- (id)initWithMIMEType:(NSString*)mimeType
 {
     if (!(self = [super init]))
         return nil;
 
-    self.url = url;
+    self.mimeType = mimeType;
+
     return self;
 }
 
@@ -67,7 +74,33 @@ SOFT_LINK_CLASS(QuickLook, QLPreviewController);
 
 - (id<QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
 {
-    return (NSURL*)self.url;
+    if (!_item) {
+        _itemProvider = adoptNS([[NSItemProvider alloc] init]);
+        NSString *contentType = @"public.content";
+#if USE(APPLE_INTERNAL_SDK)
+        contentType = WebKit::getUTIForMIMEType(self.mimeType);
+#endif
+        _item = adoptNS([allocQLItemInstance() initWithPreviewItemProvider:_itemProvider.get() contentType:contentType previewTitle:@"Preview" fileSize:@(0)]);
+        [_item setUseLoadingTimeout:NO];
+
+        [_itemProvider registerItemForTypeIdentifier:contentType loadHandler:^(NSItemProviderCompletionHandler completionHandler, Class expectedValueClass, NSDictionary * options) {
+            // This will get called once the download completes.
+            self.completionHandler = completionHandler;
+        }];
+    }
+    return _item.get();
+}
+
+- (void)setProgress:(float)progress
+{
+    if (_item)
+        [_item setPreviewItemProviderProgress:@(progress)];
+}
+
+- (void)finish:(WebCore::URL)url
+{
+    if (self.completionHandler)
+        self.completionHandler((NSURL*)url, nil);
 }
 
 @end
@@ -88,26 +121,16 @@ SOFT_LINK_CLASS(QuickLook, QLPreviewController);
     return self;
 }
 
-- (void)previewControllerWillDismiss:(QLPreviewController *)controller
+- (void)previewControllerDidDismiss:(QLPreviewController *)controller
 {
     if (_previewController)
-        _previewController->sendPageBack();
+        _previewController->cancel();
 }
 @end
 
 namespace WebKit {
 
-bool SystemPreviewController::canPreview(const String& mimeType) const
-{
-#if USE(APPLE_INTERNAL_SDK)
-    return canShowSystemPreviewForMIMEType(mimeType);
-#else
-    UNUSED_PARAM(mimeType);
-    return false;
-#endif
-}
-
-void SystemPreviewController::showPreview(const WebCore::URL& url)
+void SystemPreviewController::start(const String& mimeType)
 {
     // FIXME: Make sure you can't show a preview if we're already previewing.
 
@@ -122,16 +145,36 @@ void SystemPreviewController::showPreview(const WebCore::URL& url)
         m_qlPreviewControllerDelegate = adoptNS([[_WKPreviewControllerDelegate alloc] initWithSystemPreviewController:this]);
         [m_qlPreviewController setDelegate:m_qlPreviewControllerDelegate.get()];
 
-        m_qlPreviewControllerDataSource = adoptNS([[_WKPreviewControllerDataSource alloc] initWithURL:url]);
+        m_qlPreviewControllerDataSource = adoptNS([[_WKPreviewControllerDataSource alloc] initWithMIMEType:mimeType]);
         [m_qlPreviewController setDataSource:m_qlPreviewControllerDataSource.get()];
-    } else
-        m_qlPreviewControllerDataSource.get().url = url;
 
-    [m_qlPreviewController reloadData];
+    }
 
     [presentingViewController presentViewController:m_qlPreviewController.get() animated:YES completion:nullptr];
 }
 
+void SystemPreviewController::updateProgress(float progress)
+{
+    if (m_qlPreviewControllerDataSource)
+        [m_qlPreviewControllerDataSource setProgress:progress];
+}
+
+void SystemPreviewController::finish(WebCore::URL url)
+{
+    if (m_qlPreviewControllerDataSource)
+        [m_qlPreviewControllerDataSource finish:url];
+}
+
+void SystemPreviewController::cancel()
+{
+    if (m_qlPreviewController)
+        [m_qlPreviewController.get() dismissViewControllerAnimated:YES completion:nullptr];
+
+    m_qlPreviewControllerDelegate = nullptr;
+    m_qlPreviewControllerDataSource = nullptr;
+    m_qlPreviewController = nullptr;
+}
+
 }
 
 #endif
index f258633..903bc56 100644 (file)
@@ -80,6 +80,19 @@ public:
     void setWasUserInitiated(bool value) { m_wasUserInitiated = value; }
     bool wasUserInitiated() const { return m_wasUserInitiated; }
 
+    String destinationFilename() const { return m_destinationFilename; }
+    void setDestinationFilename(const String& d) { m_destinationFilename = d; }
+
+    uint64_t expectedContentLength() const { return m_expectedContentLength; }
+    void setExpectedContentLength(uint64_t expectedContentLength) { m_expectedContentLength = expectedContentLength; }
+
+    uint64_t bytesLoaded() const { return m_bytesLoaded; }
+    void setBytesLoaded(uint64_t bytesLoaded) { m_bytesLoaded = bytesLoaded; }
+
+#if USE(SYSTEM_PREVIEW)
+    bool isSystemPreviewDownload() const { return request().isSystemPreview(); }
+#endif
+
 private:
     explicit DownloadProxy(DownloadProxyMap&, WebProcessPool&, const WebCore::ResourceRequest&);
 
@@ -106,6 +119,9 @@ private:
     RefPtr<API::Data> m_resumeData;
     WebCore::ResourceRequest m_request;
     String m_suggestedFilename;
+    String m_destinationFilename;
+    uint64_t m_expectedContentLength { 0 };
+    uint64_t m_bytesLoaded { 0 };
 
     WeakPtr<WebPageProxy> m_originatingPage;
     Vector<WebCore::URL> m_redirectChain;
index d45b819..c7212dc 100644 (file)
 #include "config.h"
 #include "SystemPreviewController.h"
 
+#if USE(SYSTEM_PREVIEW)
+
 #include "WebPageProxy.h"
 
+#if USE(APPLE_INTERNAL_SDK)
+#import <WebKitAdditions/SystemPreviewTypes.cpp>
+#endif
+
 namespace WebKit {
 
 SystemPreviewController::SystemPreviewController(WebPageProxy& webPageProxy)
@@ -35,20 +41,16 @@ SystemPreviewController::SystemPreviewController(WebPageProxy& webPageProxy)
 {
 }
 
-void SystemPreviewController::sendPageBack()
-{
-    m_webPageProxy.goBack();
-}
-
-#if !PLATFORM(IOS) || !USE(QUICK_LOOK)
-bool SystemPreviewController::canPreview(const String&) const
+bool SystemPreviewController::canPreview(const String& mimeType) const
 {
+#if USE(APPLE_INTERNAL_SDK)
+    return canShowSystemPreviewForMIMEType(mimeType);
+#else
+    UNUSED_PARAM(mimeType);
     return false;
+#endif
 }
 
-void SystemPreviewController::showPreview(const WebCore::URL&)
-{
 }
-#endif
 
-}
+#endif
index 8141810..f9d4c9a 100644 (file)
 
 #pragma once
 
+#if USE(SYSTEM_PREVIEW)
+
 #include <WebCore/URL.h>
 #include <wtf/RetainPtr.h>
 
-#if PLATFORM(IOS) && USE(QUICK_LOOK)
+#if USE(QUICK_LOOK)
 OBJC_CLASS QLPreviewController;
 OBJC_CLASS _WKPreviewControllerDataSource;
 OBJC_CLASS _WKPreviewControllerDelegate;
@@ -43,14 +45,15 @@ public:
     explicit SystemPreviewController(WebPageProxy&);
 
     bool canPreview(const String& mimeType) const;
-    void showPreview(const WebCore::URL&);
 
-    void sendPageBack();
+    void start(const String& mimeType);
+    void updateProgress(float);
+    void finish(WebCore::URL);
+    void cancel();
 
 private:
     WebPageProxy& m_webPageProxy;
-
-#if PLATFORM(IOS) && USE(QUICK_LOOK)
+#if USE(QUICK_LOOK)
     RetainPtr<QLPreviewController> m_qlPreviewController;
     RetainPtr<_WKPreviewControllerDelegate> m_qlPreviewControllerDelegate;
     RetainPtr<_WKPreviewControllerDataSource> m_qlPreviewControllerDataSource;
@@ -59,3 +62,4 @@ private:
 
 }
 
+#endif
index 9c3b12c..89824ef 100644 (file)
@@ -438,7 +438,9 @@ WebPageProxy::WebPageProxy(PageClient& pageClient, WebProcessProxy& process, uin
     m_paymentCoordinator = std::make_unique<WebPaymentCoordinatorProxy>(*this);
 #endif
 
+#if USE(SYSTEM_PREVIEW)
     m_systemPreviewController = std::make_unique<SystemPreviewController>(*this);
+#endif
 
 #if ENABLE(WEB_AUTHN)
     m_credentialsMessenger = std::make_unique<WebCredentialsMessengerProxy>(*this);
@@ -750,7 +752,9 @@ void WebPageProxy::reattachToWebProcess(Ref<WebProcessProxy>&& process, API::Nav
     m_paymentCoordinator = std::make_unique<WebPaymentCoordinatorProxy>(*this);
 #endif
 
+#if USE(SYSTEM_PREVIEW)
     m_systemPreviewController = std::make_unique<SystemPreviewController>(*this);
+#endif
 
 #if ENABLE(WEB_AUTHN)
     m_credentialsMessenger = std::make_unique<WebCredentialsMessengerProxy>(*this);
@@ -5942,7 +5946,9 @@ void WebPageProxy::resetState(ResetStateReason resetStateReason)
     m_paymentCoordinator = nullptr;
 #endif
 
+#if USE(SYSTEM_PREVIEW)
     m_systemPreviewController = nullptr;
+#endif
 
 #if ENABLE(WEB_AUTHN)
     m_credentialsMessenger = nullptr;
index 4e995e1..2e01436 100644 (file)
@@ -391,7 +391,9 @@ public:
     void setAllowsMediaDocumentInlinePlayback(bool);
 #endif
 
+#if USE(SYSTEM_PREVIEW)
     SystemPreviewController* systemPreviewController() { return m_systemPreviewController.get(); }
+#endif
 
 #if ENABLE(CONTEXT_MENUS)
     API::ContextMenuClient& contextMenuClient() { return *m_contextMenuClient; }
@@ -1854,7 +1856,9 @@ private:
     std::unique_ptr<WebPaymentCoordinatorProxy> m_paymentCoordinator;
 #endif
 
+#if USE(SYSTEM_PREVIEW)
     std::unique_ptr<SystemPreviewController> m_systemPreviewController;
+#endif
 
 #if ENABLE(WEB_AUTHN)
     std::unique_ptr<WebCredentialsMessengerProxy> m_credentialsMessenger;