Changeset 211355 in webkit


Ignore:
Timestamp:
Jan 29, 2017 5:40:29 PM (7 years ago)
Author:
aestes@apple.com
Message:

[QuickLook] Add a WebPreference to enable saving QuickLook documents in WebKitLegacy
https://bugs.webkit.org/show_bug.cgi?id=167563
<rdar://problem/30253207>

Reviewed by Andreas Kling.

Source/WebCore:

  • loader/ios/QuickLook.h: Removed unused declarations.

(WebCore::QuickLookHandle::firstRequestURL): Deleted.

  • loader/ios/QuickLook.mm:

(WebCore::removeQLPreviewConverterForURL): Stopped deleting the temporary file here; that's
now done in QuickLookDocumentWriter.
(addQLPreviewConverterWithFileForURL): Changed from an exported function to a static
function since it's now only called inside QuickLook.mm.
(WebCore::QuickLookHandle::QuickLookHandle): Stopped initializing m_firstRequestURL.
(WebCore::addQLPreviewConverterWithFileForURL): Deleted.
(WebCore::qlPreviewConverterFileNameForURL): Deleted.
(WebCore::qlPreviewConverterUTIForURL): Deleted.
(WebCore::QuickLookHandle::previewRequestURL): Deleted.
(WebCore::QuickLookHandle::converter): Deleted.

Source/WebKit/mac:

Instead of only saving QuickLook documents to a temporary file when the client is
MobileSafari, base this decision on a WebPreference that clients can choose to enable.

This also changes the SPI for accessing the temporary file path and UTI. Instead of
-[WebView quickLookContentForURL:], which requires the client to pass the response URL of
the frame that saved the QuickLook document, the content dictionary is now stored as a
property of WebDataSource.

This also removes the manual lifetime management of the QLPreviewConverter from
QuickLookDocumentWriter. The QLPreviewConverter is kept alive by DocumentLoader these days,
which ensures it lives long enough to respond to subresource requests.

New API test: QuickLook.LegacyQuickLookContent

  • WebCoreSupport/WebFrameLoaderClient.mm:

(WebFrameLoaderClient::didCreateQuickLookHandle): Moved the logic of deciding whether to
write a temporary file to here from the QuickLookDocumentWriter constructor.

  • WebView/WebDataSource.mm: Declared _quickLookContent.

(-[WebDataSource _quickLookContent]):
(-[WebDataSource _setQuickLookContent:]):

  • WebView/WebDataSourceInternal.h: Overrode _quickLookContent as a read/write property.
  • WebView/WebDataSourcePrivate.h: Declared _quickLookContent as a readonly property.
  • WebView/WebPreferenceKeysPrivate.h: Defined WebKitQuickLookDocumentSavingPreferenceKey.
  • WebView/WebPreferences.mm:

(-[WebPreferences quickLookDocumentSavingEnabled]):
(-[WebPreferences setQuickLookDocumentSavingEnabled:]):

  • WebView/WebPreferencesPrivate.h: Declared property quickLookDocumentSavingEnabled.
  • WebView/WebView.mm:

(-[WebView quickLookContentForURL:]): Changed to always return nil.

  • WebView/WebViewPrivate.h: Added a comment stating that clients should use

-[WebDataSource _quickLookContent] instead.

Tools:

  • TestWebKitAPI/Tests/WebKit2Cocoa/QuickLook.mm:

(-[QuickLookNavigationDelegate _webView:didStartLoadForQuickLookDocumentInMainFrameWithFileName:uti:]):
(-[QuickLookNavigationDelegate _webView:didFinishLoadForQuickLookDocumentInMainFrame:]):
(runTest):
(-[QuickLookFrameLoadDelegate webView:didFinishLoadForFrame:]):
(TEST):

Location:
trunk
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r211353 r211355  
     12017-01-29  Andy Estes  <aestes@apple.com>
     2
     3        [QuickLook] Add a WebPreference to enable saving QuickLook documents in WebKitLegacy
     4        https://bugs.webkit.org/show_bug.cgi?id=167563
     5        <rdar://problem/30253207>
     6
     7        Reviewed by Andreas Kling.
     8
     9        * loader/ios/QuickLook.h: Removed unused declarations.
     10        (WebCore::QuickLookHandle::firstRequestURL): Deleted.
     11        * loader/ios/QuickLook.mm:
     12        (WebCore::removeQLPreviewConverterForURL): Stopped deleting the temporary file here; that's
     13        now done in QuickLookDocumentWriter.
     14        (addQLPreviewConverterWithFileForURL): Changed from an exported function to a static
     15        function since it's now only called inside QuickLook.mm.
     16        (WebCore::QuickLookHandle::QuickLookHandle): Stopped initializing m_firstRequestURL.
     17        (WebCore::addQLPreviewConverterWithFileForURL): Deleted.
     18        (WebCore::qlPreviewConverterFileNameForURL): Deleted.
     19        (WebCore::qlPreviewConverterUTIForURL): Deleted.
     20        (WebCore::QuickLookHandle::previewRequestURL): Deleted.
     21        (WebCore::QuickLookHandle::converter): Deleted.
     22
    1232017-01-29  Zalan Bujtas  <zalan@apple.com>
    224
  • trunk/Source/WebCore/loader/ios/QuickLook.h

    r211248 r211355  
    3232#include <wtf/RetainPtr.h>
    3333
    34 OBJC_CLASS NSArray;
    3534OBJC_CLASS NSData;
    36 OBJC_CLASS NSDictionary;
    3735OBJC_CLASS NSSet;
    3836OBJC_CLASS NSString;
    3937OBJC_CLASS NSURL;
    4038OBJC_CLASS NSURLRequest;
    41 OBJC_CLASS NSURLResponse;
    42 OBJC_CLASS QLPreviewConverter;
    4339OBJC_CLASS WebPreviewConverter;
    4440
     
    5046class ResourceResponse;
    5147class SharedBuffer;
    52 class URL;
    5348
    5449WEBCORE_EXPORT NSSet *QLPreviewGetSupportedMIMETypesSet();
    55 
    56 WEBCORE_EXPORT void addQLPreviewConverterWithFileForURL(NSURL *, id converter, NSString *fileName);
    57 WEBCORE_EXPORT NSString *qlPreviewConverterFileNameForURL(NSURL *);
    58 WEBCORE_EXPORT NSString *qlPreviewConverterUTIForURL(NSURL *);
    5950WEBCORE_EXPORT void removeQLPreviewConverterForURL(NSURL *);
    60 
    6151WEBCORE_EXPORT RetainPtr<NSURLRequest> registerQLPreviewConverterIfNeeded(NSURL *, NSString *mimeType, NSData *);
    62 
    6352WEBCORE_EXPORT const char* QLPreviewProtocol();
    64 
    6553WEBCORE_EXPORT NSString *createTemporaryFileForQuickLook(NSString *fileName);
    6654
     
    8371    WEBCORE_EXPORT String previewFileName() const;
    8472    WEBCORE_EXPORT String previewUTI() const;
    85     WEBCORE_EXPORT NSURL *previewRequestURL() const;
    86     WEBCORE_EXPORT QLPreviewConverter *converter() const;
    87     NSURL *firstRequestURL() const { return m_firstRequestURL.get(); }
    8873
    8974private:
     
    9176    QuickLookHandle(ResourceLoader&, const ResourceResponse&);
    9277
    93     RetainPtr<NSURL> m_firstRequestURL;
    9478    RetainPtr<WebPreviewConverter> m_converter;
    9579    bool m_finishedLoadingDataIntoConverter { false };
  • trunk/Source/WebCore/loader/ios/QuickLook.mm

    r211248 r211355  
    6969}
    7070
    71 void WebCore::addQLPreviewConverterWithFileForURL(NSURL *url, id converter, NSString *fileName)
     71void WebCore::removeQLPreviewConverterForURL(NSURL *url)
     72{
     73    LockHolder lock(qlPreviewConverterDictionaryMutex());
     74    [QLPreviewConverterDictionary() removeObjectForKey:url];
     75    [QLContentDictionary() removeObjectForKey:url];
     76}
     77
     78static void addQLPreviewConverterWithFileForURL(NSURL *url, id converter, NSString *fileName)
    7279{
    7380    ASSERT(url);
     
    7683    [QLPreviewConverterDictionary() setObject:converter forKey:url];
    7784    [QLContentDictionary() setObject:(fileName ? fileName : @"") forKey:url];
    78 }
    79 
    80 NSString *WebCore::qlPreviewConverterFileNameForURL(NSURL *url)
    81 {
    82     return [QLContentDictionary() objectForKey:url];
    83 }
    84 
    85 NSString *WebCore::qlPreviewConverterUTIForURL(NSURL *url)
    86 {
    87     id converter = nil;
    88     {
    89         LockHolder lock(qlPreviewConverterDictionaryMutex());
    90         converter = [QLPreviewConverterDictionary() objectForKey:url];
    91     }
    92     if (!converter)
    93         return nil;
    94     return [converter previewUTI];
    95 }
    96 
    97 void WebCore::removeQLPreviewConverterForURL(NSURL *url)
    98 {
    99     LockHolder lock(qlPreviewConverterDictionaryMutex());
    100     [QLPreviewConverterDictionary() removeObjectForKey:url];
    101 
    102     // Delete the file when we remove the preview converter
    103     NSString *filename = qlPreviewConverterFileNameForURL(url);
    104     if ([filename length])
    105         [[NSFileManager defaultManager] _web_removeFileOnlyAtPath:filename];
    106     [QLContentDictionary() removeObjectForKey:url];
    10785}
    10886
     
    341319
    342320QuickLookHandle::QuickLookHandle(ResourceLoader& loader, const ResourceResponse& response)
    343     : m_firstRequestURL { loader.originalRequest().nsURLRequest(DoNotUpdateHTTPBody).URL }
    344     , m_converter { adoptNS([[WebPreviewConverter alloc] initWithResourceLoader:loader resourceResponse:response quickLookHandle:*this]) }
     321    : m_converter { adoptNS([[WebPreviewConverter alloc] initWithResourceLoader:loader resourceResponse:response quickLookHandle:*this]) }
    345322{
    346323    loader.didCreateQuickLookHandle(*this);
     
    422399}
    423400
    424 NSURL *QuickLookHandle::previewRequestURL() const
    425 {
    426     return [m_converter platformConverter].previewRequest.URL;
    427 }
    428 
    429 QLPreviewConverter *QuickLookHandle::converter() const
    430 {
    431     return [m_converter platformConverter];
    432 }
    433 
    434401}
    435402
  • trunk/Source/WebKit/mac/ChangeLog

    r211341 r211355  
     12017-01-29  Andy Estes  <aestes@apple.com>
     2
     3        [QuickLook] Add a WebPreference to enable saving QuickLook documents in WebKitLegacy
     4        https://bugs.webkit.org/show_bug.cgi?id=167563
     5        <rdar://problem/30253207>
     6
     7        Reviewed by Andreas Kling.
     8
     9        Instead of only saving QuickLook documents to a temporary file when the client is
     10        MobileSafari, base this decision on a WebPreference that clients can choose to enable.
     11
     12        This also changes the SPI for accessing the temporary file path and UTI. Instead of
     13        -[WebView quickLookContentForURL:], which requires the client to pass the response URL of
     14        the frame that saved the QuickLook document, the content dictionary is now stored as a
     15        property of WebDataSource.
     16
     17        This also removes the manual lifetime management of the QLPreviewConverter from
     18        QuickLookDocumentWriter. The QLPreviewConverter is kept alive by DocumentLoader these days,
     19        which ensures it lives long enough to respond to subresource requests.
     20
     21        New API test: QuickLook.LegacyQuickLookContent
     22
     23        * WebCoreSupport/WebFrameLoaderClient.mm:
     24        (WebFrameLoaderClient::didCreateQuickLookHandle): Moved the logic of deciding whether to
     25        write a temporary file to here from the QuickLookDocumentWriter constructor.
     26        * WebView/WebDataSource.mm: Declared _quickLookContent.
     27        (-[WebDataSource _quickLookContent]):
     28        (-[WebDataSource _setQuickLookContent:]):
     29        * WebView/WebDataSourceInternal.h: Overrode _quickLookContent as a read/write property.
     30        * WebView/WebDataSourcePrivate.h: Declared _quickLookContent as a readonly property.
     31        * WebView/WebPreferenceKeysPrivate.h: Defined WebKitQuickLookDocumentSavingPreferenceKey.
     32        * WebView/WebPreferences.mm:
     33        (-[WebPreferences quickLookDocumentSavingEnabled]):
     34        (-[WebPreferences setQuickLookDocumentSavingEnabled:]):
     35        * WebView/WebPreferencesPrivate.h: Declared property quickLookDocumentSavingEnabled.
     36        * WebView/WebView.mm:
     37        (-[WebView quickLookContentForURL:]): Changed to always return nil.
     38        * WebView/WebViewPrivate.h: Added a comment stating that clients should use
     39        -[WebDataSource _quickLookContent] instead.
     40
    1412017-01-28  Yoav Weiss  <yoav@yoav.ws>
    242
  • trunk/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.mm

    r210859 r211355  
    150150
    151151#if USE(QUICK_LOOK)
    152 #import <WebCore/FileSystemIOS.h>
    153152#import <WebCore/NSFileManagerSPI.h>
    154153#import <WebCore/QuickLook.h>
     
    22312230    class QuickLookDocumentWriter : public WebCore::QuickLookHandleClient {
    22322231    public:
    2233         explicit QuickLookDocumentWriter(const WebCore::QuickLookHandle& handle)
    2234             : m_firstRequestURL(handle.firstRequestURL())
     2232        explicit QuickLookDocumentWriter(NSString *filePath)
     2233            : m_filePath { filePath }
     2234            , m_fileHandle { [NSFileHandle fileHandleForWritingAtPath:filePath] }
    22352235        {
    2236             NSURL *previewRequestURL = handle.previewRequestURL();
    2237             if (!IOSApplication::isMobileSafari()) {
    2238                 // This keeps the QLPreviewConverter alive to serve any subresource requests.
    2239                 // It is removed by -[WebDataSource dealloc].
    2240                 addQLPreviewConverterWithFileForURL(previewRequestURL, handle.converter(), nil);
    2241                 return;
    2242             }
    2243 
    2244             // QuickLook consumes the incoming data, we need to store it so that it can be opened in the handling application.
    2245             NSString *quicklookContentPath = createTemporaryFileForQuickLook(handle.previewFileName());
    2246 
    2247             if (quicklookContentPath) {
    2248                 m_fileHandle = [NSFileHandle fileHandleForWritingAtPath:quicklookContentPath];
    2249                 // previewRequestURL should match the URL removed from -[WebDataSource dealloc].
    2250                 addQLPreviewConverterWithFileForURL(previewRequestURL, handle.converter(), quicklookContentPath);
    2251             }
     2236            ASSERT(filePath.length);
    22522237        }
    22532238
    2254         virtual ~QuickLookDocumentWriter()
     2239        ~QuickLookDocumentWriter()
    22552240        {
    2256             if (m_fileHandle)
    2257                 removeQLPreviewConverterForURL(m_firstRequestURL.get());
     2241            [[NSFileManager defaultManager] _web_removeFileOnlyAtPath:m_filePath.get()];
    22582242        }
    22592243
    22602244    private:
     2245        RetainPtr<NSString> m_filePath;
    22612246        RetainPtr<NSFileHandle> m_fileHandle;
    2262         RetainPtr<NSURL> m_firstRequestURL;
    22632247
    22642248        void didReceiveDataArray(CFArrayRef dataArray) override
    22652249        {
    2266             if (m_fileHandle) {
    2267                 for (NSData *data in (NSArray *)dataArray)
    2268                     [m_fileHandle writeData:data];
    2269             }
     2250            for (NSData *data in (NSArray *)dataArray)
     2251                [m_fileHandle writeData:data];
    22702252        }
    22712253
     
    22772259        void didFail() override
    22782260        {
    2279             m_fileHandle = nil;
    2280             // removeQLPreviewConverterForURL deletes the temporary file created.
    2281             removeQLPreviewConverterForURL(m_firstRequestURL.get());
     2261            [m_fileHandle closeFile];
    22822262        }
    22832263    };
    2284     handle.setClient(adoptRef(*new QuickLookDocumentWriter(handle)));
     2264
     2265    if (![m_webFrame webView].preferences.quickLookDocumentSavingEnabled)
     2266        return;
     2267
     2268    NSString *filePath = createTemporaryFileForQuickLook(handle.previewFileName());
     2269    if (!filePath)
     2270        return;
     2271
     2272    [m_webFrame provisionalDataSource]._quickLookContent = @{ WebQuickLookFileNameKey : filePath, WebQuickLookUTIKey : handle.previewUTI() };
     2273    handle.setClient(adoptRef(*new QuickLookDocumentWriter(filePath)));
    22852274}
    22862275#endif
  • trunk/Source/WebKit/mac/WebView/WebDataSource.mm

    r210845 r211355  
    110110    NSObject<WebDataSourcePrivateDelegate> *_dataSourceDelegate;
    111111#endif
     112#if USE(QUICK_LOOK)
     113    RetainPtr<NSDictionary> _quickLookContent;
     114#endif
    112115};
    113116
     
    225228    return nullptr;
    226229}
     230
     231#if PLATFORM(IOS)
     232- (NSDictionary *)_quickLookContent
     233{
     234#if USE(QUICK_LOOK)
     235    return toPrivate(_private)->_quickLookContent.get();
     236#else
     237    return nil;
     238#endif
     239}
     240#endif
    227241
    228242@end
     
    411425}
    412426
     427#if USE(QUICK_LOOK)
     428- (void)_setQuickLookContent:(NSDictionary *)quickLookContent
     429{
     430    toPrivate(_private)->_quickLookContent = adoptNS([quickLookContent copy]);
     431}
     432#endif
     433
    413434@end
    414435
  • trunk/Source/WebKit/mac/WebView/WebDataSourceInternal.h

    r165676 r211355  
    5858- (void)_setMainDocumentError:(NSError *)error;
    5959- (WebCore::DocumentLoader*)_documentLoader;
     60#if USE(QUICK_LOOK)
     61@property (nonatomic, copy, setter=_setQuickLookContent:) NSDictionary *_quickLookContent;
     62#endif
    6063@end
  • trunk/Source/WebKit/mac/WebView/WebDataSourcePrivate.h

    r182115 r211355  
    5353- (NSObject<WebDataSourcePrivateDelegate> *)dataSourceDelegate;
    5454
     55#if TARGET_OS_IPHONE
     56@property (nonatomic, readonly) NSDictionary *_quickLookContent;
     57#endif
     58
    5559@end
  • trunk/Source/WebKit/mac/WebView/WebPreferenceKeysPrivate.h

    r211341 r211355  
    11/*
    2  * Copyright (C) 2005-2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2005-2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    216216#define WebKitNetworkDataUsageTrackingEnabledPreferenceKey @"WebKitNetworkDataUsageTrackingEnabledPreferenceKey"
    217217#define WebKitNetworkInterfaceNamePreferenceKey @"WebKitNetworkInterfaceNamePreferenceKey"
     218#define WebKitQuickLookDocumentSavingPreferenceKey @"WebKitQuickLookDocumentSavingPreferenceKey"
    218219#endif
    219220
  • trunk/Source/WebKit/mac/WebView/WebPreferences.mm

    r211341 r211355  
    11/*
    2  * Copyright (C) 2005-2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2005-2017 Apple Inc. All rights reserved.
    33 *           (C) 2006 Graham Dennis (graham.dennis@gmail.com)
    44 *
     
    29462946}
    29472947
     2948#if PLATFORM(IOS)
     2949- (BOOL)quickLookDocumentSavingEnabled
     2950{
     2951    return [self _boolValueForKey:WebKitQuickLookDocumentSavingPreferenceKey];
     2952}
     2953
     2954- (void)setQuickLookDocumentSavingEnabled:(BOOL)flag
     2955{
     2956    [self _setBoolValue:flag forKey:WebKitQuickLookDocumentSavingPreferenceKey];
     2957}
     2958#endif
     2959
    29482960@end
    29492961
  • trunk/Source/WebKit/mac/WebView/WebPreferencesPrivate.h

    r211341 r211355  
    11/*
    2  * Copyright (C) 2005-2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2005-2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    532532@property (nonatomic) BOOL linkPreloadEnabled;
    533533
     534#if TARGET_OS_IPHONE
     535@property (nonatomic) BOOL quickLookDocumentSavingEnabled;
     536#endif
     537
    534538@end
  • trunk/Source/WebKit/mac/WebView/WebView.mm

    r211341 r211355  
    11/*
    2  * Copyright (C) 2005-2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2005-2017 Apple Inc. All rights reserved.
    33 * Copyright (C) 2006 David Smith (catfish.man@gmail.com)
    44 * Copyright (C) 2010 Igalia S.L
     
    40314031- (NSDictionary *)quickLookContentForURL:(NSURL *)url
    40324032{
    4033 #if USE(QUICK_LOOK)
    4034     NSString *uti = qlPreviewConverterUTIForURL(url);
    4035     if (!uti)
    4036         return nil;
    4037 
    4038     NSString *fileName = qlPreviewConverterFileNameForURL(url);
    4039     if (!fileName)
    4040         return nil;
    4041 
    4042     return [NSDictionary dictionaryWithObjectsAndKeys: fileName, WebQuickLookFileNameKey, uti, WebQuickLookUTIKey, nil];
    4043 #else
    40444033    return nil;
    4045 #endif
    40464034}
    40474035
  • trunk/Source/WebKit/mac/WebView/WebViewPrivate.h

    r211020 r211355  
    463463
    464464#if TARGET_OS_IPHONE
     465// Deprecated. Use -[WebDataSource _quickLookContent] instead.
    465466- (NSDictionary *)quickLookContentForURL:(NSURL *)url;
    466467#endif
  • trunk/Tools/ChangeLog

    r211354 r211355  
     12017-01-29  Andy Estes  <aestes@apple.com>
     2
     3        [QuickLook] Add a WebPreference to enable saving QuickLook documents in WebKitLegacy
     4        https://bugs.webkit.org/show_bug.cgi?id=167563
     5        <rdar://problem/30253207>
     6
     7        Reviewed by Andreas Kling.
     8
     9        * TestWebKitAPI/Tests/WebKit2Cocoa/QuickLook.mm:
     10        (-[QuickLookNavigationDelegate _webView:didStartLoadForQuickLookDocumentInMainFrameWithFileName:uti:]):
     11        (-[QuickLookNavigationDelegate _webView:didFinishLoadForQuickLookDocumentInMainFrame:]):
     12        (runTest):
     13        (-[QuickLookFrameLoadDelegate webView:didFinishLoadForFrame:]):
     14        (TEST):
     15
    1162017-01-29  Dan Bernstein  <mitz@apple.com>
    217
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/QuickLook.mm

    r206801 r211355  
    11/*
    2  * Copyright (C) 2015-2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2015-2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2929
    3030#import "PlatformUtilities.h"
     31#import "Test.h"
     32#import <WebCore/WebCoreThread.h>
    3133#import <WebKit/WKNavigationDelegatePrivate.h>
    32 #import <WebKit/WKWebView.h>
     34#import <WebKit/WebDataSourcePrivate.h>
     35#import <WebKit/WebKit.h>
     36#import <WebKit/WebPreferencesPrivate.h>
     37#import <WebKit/WebUIKitSupport.h>
     38#import <WebKit/WebViewPrivate.h>
    3339#import <wtf/RetainPtr.h>
     40
     41using namespace TestWebKitAPI;
    3442
    3543static bool isDone;
    3644static bool didStartQuickLookLoad;
    3745static bool didFinishQuickLookLoad;
     46
     47static const NSUInteger expectedFileSize = 274143;
     48static NSString * const expectedFileName = @"pages.pages";
     49static NSString * const expectedUTI = @"com.apple.iwork.pages.sffpages";
     50static NSURLRequest * const pagesDocumentRequest = [[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"pages" withExtension:@"pages" subdirectory:@"TestWebKitAPI.resources"]] retain];
    3851
    3952@interface QuickLookNavigationDelegate : NSObject <WKNavigationDelegatePrivate>
     
    4457- (void)_webView:(WKWebView *)webView didStartLoadForQuickLookDocumentInMainFrameWithFileName:(NSString *)fileName uti:(NSString *)uti
    4558{
    46     EXPECT_WK_STREQ(fileName, @"pages.pages");
    47     EXPECT_WK_STREQ(uti, @"com.apple.iwork.pages.sffpages");
     59    EXPECT_WK_STREQ(expectedFileName, fileName);
     60    EXPECT_WK_STREQ(expectedUTI, uti);
    4861    didStartQuickLookLoad = true;
    4962}
     
    5164- (void)_webView:(WKWebView *)webView didFinishLoadForQuickLookDocumentInMainFrame:(NSData *)documentData
    5265{
    53     EXPECT_EQ(documentData.length, 274143U);
     66    EXPECT_EQ(expectedFileSize, documentData.length);
    5467    didFinishQuickLookLoad = true;
    5568}
     
    6780    auto navigationDelegate = adoptNS([[navigationDelegateClass alloc] init]);
    6881    [webView setNavigationDelegate:navigationDelegate.get()];
    69     [webView loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"pages" withExtension:@"pages" subdirectory:@"TestWebKitAPI.resources"]]];
     82    [webView loadRequest:pagesDocumentRequest];
    7083
    7184    isDone = false;
    72     TestWebKitAPI::Util::run(&isDone);
     85    Util::run(&isDone);
    7386}
    7487
     
    97110@end
    98111
     112@interface QuickLookFrameLoadDelegate : NSObject <WebFrameLoadDelegate>
     113@end
     114
     115@implementation QuickLookFrameLoadDelegate
     116
     117- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
     118{
     119    isDone = true;
     120}
     121
     122@end
     123
    99124TEST(QuickLook, CancelNavigationAfterResponse)
    100125{
     
    102127}
    103128
     129TEST(QuickLook, LegacyQuickLookContent)
     130{
     131    WebKitInitialize();
     132    WebThreadLock();
     133
     134    auto webView = adoptNS([[WebView alloc] init]);
     135
     136    auto frameLoadDelegate = adoptNS([[QuickLookFrameLoadDelegate alloc] init]);
     137    [webView setFrameLoadDelegate:frameLoadDelegate.get()];
     138
     139    auto webPreferences = adoptNS([[WebPreferences alloc] initWithIdentifier:@"LegacyQuickLookContent"]);
     140    [webPreferences setQuickLookDocumentSavingEnabled:YES];
     141    [webView setPreferences:webPreferences.get()];
     142
     143    WebFrame *mainFrame = [webView mainFrame];
     144
     145    isDone = false;
     146    [mainFrame loadRequest:pagesDocumentRequest];
     147    Util::run(&isDone);
     148    WebThreadLock();
     149
     150    NSDictionary *quickLookContent = mainFrame.dataSource._quickLookContent;
     151    NSString *filePath = quickLookContent[WebQuickLookFileNameKey];
     152    EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:filePath]);
     153    EXPECT_WK_STREQ(expectedFileName, filePath.lastPathComponent);
     154    EXPECT_WK_STREQ(expectedUTI, quickLookContent[WebQuickLookUTIKey]);
     155
     156    NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];
     157    EXPECT_EQ(expectedFileSize, [fileAttributes[NSFileSize] unsignedIntegerValue]);
     158
     159    isDone = false;
     160    [mainFrame loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]];
     161    Util::run(&isDone);
     162    WebThreadLock();
     163
     164    EXPECT_NULL(mainFrame.dataSource._quickLookContent);
     165}
     166
    104167#endif // PLATFORM(IOS)
Note: See TracChangeset for help on using the changeset viewer.