Changeset 221216 in webkit


Ignore:
Timestamp:
Aug 25, 2017, 5:13:47 PM (8 years ago)
Author:
achristensen@apple.com
Message:

Add WKUIDelegatePrivate equivalent of WKPageUIClient's saveDataToFileInDownloadsFolder
https://bugs.webkit.org/show_bug.cgi?id=176000
<rdar://problem/29270035>

Reviewed by Andy Estes.
Source/WebKit:


Covered by a new API test.

  • Shared/Cocoa/WKNSData.h:

(wrapper): Deleted.

  • UIProcess/API/APIUIClient.h:

(API::UIClient::saveDataToFileInDownloadsFolder):

  • UIProcess/API/C/WKPage.cpp:

(WKPageSetPageUIClient):

  • UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
  • UIProcess/Cocoa/UIDelegate.h:
  • UIProcess/Cocoa/UIDelegate.mm:

(WebKit::UIDelegate::setDelegate):
(WebKit::UIDelegate::UIClient::saveDataToFileInDownloadsFolder):

  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::saveDataToFileInDownloadsFolder):
(WebKit::WebPageProxy::savePDFToFileInDownloadsFolder):

  • UIProcess/WebPageProxy.h:
  • UIProcess/WebPageProxy.messages.in:
  • WebProcess/WebPage/WebFrame.cpp:

(WebKit::WebFrame::url const):

  • WebProcess/WebPage/WebFrame.h:
  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::savePDFToFileInDownloadsFolder):

  • WebProcess/WebPage/WebPage.h:

Tools:

  • TestWebKitAPI/Tests/WebKit2Cocoa/UIDelegate.mm:

(-[FocusDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):
(TEST):
(-[SaveDataToFileDelegate _webView:saveDataToFile:suggestedFilename:mimeType:originatingURL:]):
(-[SaveDataToFileDelegate webView:didFinishNavigation:]):

Location:
trunk
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r221215 r221216  
     12017-08-25  Alex Christensen  <achristensen@webkit.org>
     2
     3        Add WKUIDelegatePrivate equivalent of WKPageUIClient's saveDataToFileInDownloadsFolder
     4        https://bugs.webkit.org/show_bug.cgi?id=176000
     5        <rdar://problem/29270035>
     6
     7        Reviewed by Andy Estes.
     8       
     9        Covered by a new API test.
     10
     11        * Shared/Cocoa/WKNSData.h:
     12        (wrapper): Deleted.
     13        * UIProcess/API/APIUIClient.h:
     14        (API::UIClient::saveDataToFileInDownloadsFolder):
     15        * UIProcess/API/C/WKPage.cpp:
     16        (WKPageSetPageUIClient):
     17        * UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
     18        * UIProcess/Cocoa/UIDelegate.h:
     19        * UIProcess/Cocoa/UIDelegate.mm:
     20        (WebKit::UIDelegate::setDelegate):
     21        (WebKit::UIDelegate::UIClient::saveDataToFileInDownloadsFolder):
     22        * UIProcess/WebPageProxy.cpp:
     23        (WebKit::WebPageProxy::saveDataToFileInDownloadsFolder):
     24        (WebKit::WebPageProxy::savePDFToFileInDownloadsFolder):
     25        * UIProcess/WebPageProxy.h:
     26        * UIProcess/WebPageProxy.messages.in:
     27        * WebProcess/WebPage/WebFrame.cpp:
     28        (WebKit::WebFrame::url const):
     29        * WebProcess/WebPage/WebFrame.h:
     30        * WebProcess/WebPage/WebPage.cpp:
     31        (WebKit::WebPage::savePDFToFileInDownloadsFolder):
     32        * WebProcess/WebPage/WebPage.h:
     33
    1342017-08-25  David Kilzer  <ddkilzer@apple.com>
    235
  • trunk/Source/WebKit/Shared/Cocoa/WKNSData.h

    r160653 r221216  
    3131#import "WKObject.h"
    3232
     33namespace API {
     34
    3335inline NSData *wrapper(API::Data& data)
    3436{
     
    3739}
    3840
     41}
     42
    3943@interface WKNSData : NSData <WKObject>
    4044@end
  • trunk/Source/WebKit/UIProcess/API/APIUIClient.h

    r221102 r221216  
    143143    virtual void runModal(WebKit::WebPageProxy*) { }
    144144
    145     virtual void saveDataToFileInDownloadsFolder(WebKit::WebPageProxy*, const WTF::String&, const WTF::String&, const WTF::String&, Data*) { }
     145    virtual void saveDataToFileInDownloadsFolder(WebKit::WebPageProxy*, const WTF::String&, const WTF::String&, const WebCore::URL&, Data&) { }
    146146
    147147    virtual void pinnedStateDidChange(WebKit::WebPageProxy&) { }
  • trunk/Source/WebKit/UIProcess/API/C/WKPage.cpp

    r221102 r221216  
    20442044        }
    20452045
    2046         void saveDataToFileInDownloadsFolder(WebPageProxy* page, const String& suggestedFilename, const String& mimeType, const String& originatingURLString, API::Data* data) final
     2046        void saveDataToFileInDownloadsFolder(WebPageProxy* page, const String& suggestedFilename, const String& mimeType, const WebCore::URL& originatingURL, API::Data& data) final
    20472047        {
    20482048            if (!m_client.saveDataToFileInDownloadsFolder)
    20492049                return;
    20502050
    2051             m_client.saveDataToFileInDownloadsFolder(toAPI(page), toAPI(suggestedFilename.impl()), toAPI(mimeType.impl()), toURLRef(originatingURLString.impl()), toAPI(data), m_client.base.clientInfo);
     2051            m_client.saveDataToFileInDownloadsFolder(toAPI(page), toAPI(suggestedFilename.impl()), toAPI(mimeType.impl()), toURLRef(originatingURL.string().impl()), toAPI(&data), m_client.base.clientInfo);
    20522052        }
    20532053
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h

    r221172 r221216  
    3333#import <WebKit/_WKActivatedElementInfo.h>
    3434
     35@class NSData;
    3536@class UIScrollView;
    3637@class UIViewController;
     
    144145- (void)_webView:(WKWebView *)webView didNotHandleWheelEvent:(NSEvent *)event WK_API_AVAILABLE(macosx(WK_MAC_TBA));
    145146- (void)_webView:(WKWebView *)webView handleAutoplayEvent:(_WKAutoplayEvent)event withFlags:(_WKAutoplayEventFlags)flags WK_API_AVAILABLE(macosx(WK_MAC_TBA));
     147- (void)_webView:(WKWebView *)webView saveDataToFile:(NSData *)data suggestedFilename:(NSString *)suggestedFilename mimeType:(NSString *)mimeType originatingURL:(NSURL *)url WK_API_AVAILABLE(macosx(WK_MAC_TBA));
    146148- (NSMenu *)_webView:(WKWebView *)webView contextMenu:(NSMenu *)menu forElement:(_WKContextMenuElementInfo *)element WK_API_AVAILABLE(macosx(10.12));
    147149- (NSMenu *)_webView:(WKWebView *)webView contextMenu:(NSMenu *)menu forElement:(_WKContextMenuElementInfo *)element userInfo:(id <NSSecureCoding>)userInfo WK_API_AVAILABLE(macosx(10.12));
  • trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h

    r221172 r221216  
    101101        void focus(WebPageProxy*) final;
    102102        void unfocus(WebPageProxy*) final;
    103         void didNotHandleWheelEvent(WebKit::WebPageProxy*, const WebKit::NativeWebWheelEvent&) final;
    104         void handleAutoplayEvent(WebKit::WebPageProxy&, WebCore::AutoplayEvent, OptionSet<WebCore::AutoplayEventFlags>) final;
     103        void didNotHandleWheelEvent(WebPageProxy*, const NativeWebWheelEvent&) final;
     104        void handleAutoplayEvent(WebPageProxy&, WebCore::AutoplayEvent, OptionSet<WebCore::AutoplayEventFlags>) final;
    105105        bool runOpenPanel(WebPageProxy*, WebFrameProxy*, const WebCore::SecurityOriginData&, API::OpenPanelParameters*, WebOpenPanelResultListenerProxy*) final;
     106        void saveDataToFileInDownloadsFolder(WebPageProxy*, const WTF::String&, const WTF::String&, const WebCore::URL&, API::Data&) final;
    106107#endif
    107108        bool decidePolicyForUserMediaPermissionRequest(WebPageProxy&, WebFrameProxy&, API::SecurityOrigin&, API::SecurityOrigin&, UserMediaPermissionRequestProxy&) final;
     
    149150        bool webViewDidNotHandleWheelEvent : 1;
    150151        bool webViewHandleAutoplayEventWithFlags : 1;
     152        bool webViewSaveDataToFileSuggestedFilenameMimeTypeOriginatingURL : 1;
    151153        bool webViewRunOpenPanelWithParametersInitiatedByFrameCompletionHandler : 1;
    152154#endif
  • trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm

    r221172 r221216  
    3636#import "UserMediaPermissionRequestProxy.h"
    3737#import "WKFrameInfoInternal.h"
     38#import "WKNSData.h"
    3839#import "WKNavigationActionInternal.h"
    3940#import "WKOpenPanelParametersInternal.h"
     
    108109    m_delegateMethods.webViewDidNotHandleWheelEvent = [delegate respondsToSelector:@selector(_webView:didNotHandleWheelEvent:)];
    109110    m_delegateMethods.webViewHandleAutoplayEventWithFlags = [delegate respondsToSelector:@selector(_webView:handleAutoplayEvent:withFlags:)];
     111    m_delegateMethods.webViewSaveDataToFileSuggestedFilenameMimeTypeOriginatingURL = [delegate respondsToSelector:@selector(_webView:saveDataToFile:suggestedFilename:mimeType:originatingURL:)];
    110112    m_delegateMethods.webViewRunOpenPanelWithParametersInitiatedByFrameCompletionHandler = [delegate respondsToSelector:@selector(webView:runOpenPanelWithParameters:initiatedByFrame:completionHandler:)];
    111113#endif
    112 
    113114    m_delegateMethods.webViewDecideDatabaseQuotaForSecurityOriginCurrentQuotaCurrentOriginUsageCurrentDatabaseUsageExpectedUsageDecisionHandler = [delegate respondsToSelector:@selector(_webView:decideDatabaseQuotaForSecurityOrigin:currentQuota:currentOriginUsage:currentDatabaseUsage:expectedUsage:decisionHandler:)];
    114115    m_delegateMethods.webViewDecideWebApplicationCacheQuotaForSecurityOriginCurrentQuotaTotalBytesNeeded = [delegate respondsToSelector:@selector(_webView:decideWebApplicationCacheQuotaForSecurityOrigin:currentQuota:totalBytesNeeded:decisionHandler:)];
     
    487488    [(id <WKUIDelegatePrivate>)delegate _showWebView:m_uiDelegate.m_webView];
    488489}
    489 
     490   
     491void UIDelegate::UIClient::saveDataToFileInDownloadsFolder(WebPageProxy*, const WTF::String& suggestedFilename, const WTF::String& mimeType, const WebCore::URL& originatingURL, API::Data& data)
     492{
     493    if (!m_uiDelegate.m_delegateMethods.webViewSaveDataToFileSuggestedFilenameMimeTypeOriginatingURL)
     494        return;
     495   
     496    auto delegate = m_uiDelegate.m_delegate.get();
     497    if (!delegate)
     498        return;
     499
     500    [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView saveDataToFile:wrapper(data) suggestedFilename:suggestedFilename mimeType:mimeType originatingURL:originatingURL];
     501}
     502   
    490503bool UIDelegate::UIClient::runOpenPanel(WebPageProxy*, WebFrameProxy* webFrameProxy, const WebCore::SecurityOriginData& securityOriginData, API::OpenPanelParameters* openPanelParameters, WebOpenPanelResultListenerProxy* listener)
    491504{
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r221102 r221216  
    61146114}
    61156115
    6116 void WebPageProxy::saveDataToFileInDownloadsFolder(const String& suggestedFilename, const String& mimeType, const String& originatingURLString, API::Data* data)
     6116void WebPageProxy::saveDataToFileInDownloadsFolder(String&& suggestedFilename, String&& mimeType, URL&& originatingURLString, API::Data& data)
    61176117{
    61186118    m_uiClient->saveDataToFileInDownloadsFolder(this, suggestedFilename, mimeType, originatingURLString, data);
    61196119}
    61206120
    6121 void WebPageProxy::savePDFToFileInDownloadsFolder(const String& suggestedFilename, const String& originatingURLString, const IPC::DataReference& dataReference)
     6121void WebPageProxy::savePDFToFileInDownloadsFolder(String&& suggestedFilename, URL&& originatingURL, const IPC::DataReference& dataReference)
    61226122{
    61236123    if (!suggestedFilename.endsWith(".pdf", false))
    61246124        return;
    61256125
    6126     saveDataToFileInDownloadsFolder(suggestedFilename, "application/pdf", originatingURLString,
    6127         API::Data::create(dataReference.data(), dataReference.size()).ptr());
     6126    saveDataToFileInDownloadsFolder(WTFMove(suggestedFilename), ASCIILiteral("application/pdf"), WTFMove(originatingURL),
     6127        API::Data::create(dataReference.data(), dataReference.size()).get());
    61286128}
    61296129
  • trunk/Source/WebKit/UIProcess/WebPageProxy.h

    r221065 r221216  
    951951#endif
    952952
    953     void saveDataToFileInDownloadsFolder(const String& suggestedFilename, const String& mimeType, const String& originatingURLString, API::Data*);
    954     void savePDFToFileInDownloadsFolder(const String& suggestedFilename, const String& originatingURLString, const IPC::DataReference&);
     953    void saveDataToFileInDownloadsFolder(String&& suggestedFilename, String&& mimeType, WebCore::URL&& originatingURL, API::Data&);
     954    void savePDFToFileInDownloadsFolder(String&& suggestedFilename, WebCore::URL&& originatingURL, const IPC::DataReference&);
    955955#if PLATFORM(COCOA)
    956956    void savePDFToTemporaryFolderAndOpenWithNativeApplicationRaw(const String& suggestedFilename, const String& originatingURLString, const uint8_t* data, unsigned long size, const String& pdfUUID);
  • trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in

    r219709 r221216  
    405405    LoadRecentSearches(String name) -> (Vector<WebCore::RecentSearch> result)
    406406
    407     SavePDFToFileInDownloadsFolder(String suggestedFilename, String originatingURLString, IPC::DataReference data)
     407    SavePDFToFileInDownloadsFolder(String suggestedFilename, WebCore::URL originatingURL, IPC::DataReference data)
    408408
    409409#if PLATFORM(COCOA)
  • trunk/Source/WebKit/WebProcess/InjectedBundle/API/glib/WebKitFrame.cpp

    r218487 r221216  
    8686
    8787    if (frame->priv->uri.isNull())
    88         frame->priv->uri = frame->priv->webFrame->url().utf8();
     88        frame->priv->uri = frame->priv->webFrame->url().string().utf8();
    8989
    9090    return frame->priv->uri.data();
  • trunk/Source/WebKit/WebProcess/WebPage/WebFrame.cpp

    r221068 r221216  
    393393}
    394394
    395 String WebFrame::url() const
    396 {
    397     if (!m_coreFrame)
    398         return String();
    399 
    400     DocumentLoader* documentLoader = m_coreFrame->loader().documentLoader();
     395URL WebFrame::url() const
     396{
     397    if (!m_coreFrame)
     398        return { };
     399
     400    auto* documentLoader = m_coreFrame->loader().documentLoader();
    401401    if (!documentLoader)
    402         return String();
    403 
    404     return documentLoader->url().string();
     402        return { };
     403
     404    return documentLoader->url();
    405405}
    406406
  • trunk/Source/WebKit/WebProcess/WebPage/WebFrame.h

    r220857 r221216  
    9999    bool isMainFrame() const;
    100100    String name() const;
    101     String url() const;
     101    WebCore::URL url() const;
    102102    WebCore::CertificateInfo certificateInfo() const;
    103103    String innerText() const;
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp

    r221177 r221216  
    45634563#endif
    45644564
    4565 void WebPage::savePDFToFileInDownloadsFolder(const String& suggestedFilename, const String& originatingURLString, const uint8_t* data, unsigned long size)
    4566 {
    4567     send(Messages::WebPageProxy::SavePDFToFileInDownloadsFolder(suggestedFilename, originatingURLString, IPC::DataReference(data, size)));
     4565void WebPage::savePDFToFileInDownloadsFolder(const String& suggestedFilename, const URL& originatingURL, const uint8_t* data, unsigned long size)
     4566{
     4567    send(Messages::WebPageProxy::SavePDFToFileInDownloadsFolder(suggestedFilename, originatingURL, IPC::DataReference(data, size)));
    45684568}
    45694569
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.h

    r221065 r221216  
    872872#endif
    873873
    874     void savePDFToFileInDownloadsFolder(const String& suggestedFilename, const String& originatingURLString, const uint8_t* data, unsigned long size);
     874    void savePDFToFileInDownloadsFolder(const String& suggestedFilename, const WebCore::URL& originatingURL, const uint8_t* data, unsigned long size);
    875875#if PLATFORM(COCOA)
    876876    void savePDFToTemporaryFolderAndOpenWithNativeApplication(const String& suggestedFilename, const String& originatingURLString, const uint8_t* data, unsigned long size, const String& pdfUUID);
  • trunk/Tools/ChangeLog

    r221214 r221216  
     12017-08-25  Alex Christensen  <achristensen@webkit.org>
     2
     3        Add WKUIDelegatePrivate equivalent of WKPageUIClient's saveDataToFileInDownloadsFolder
     4        https://bugs.webkit.org/show_bug.cgi?id=176000
     5        <rdar://problem/29270035>
     6
     7        Reviewed by Andy Estes.
     8
     9        * TestWebKitAPI/Tests/WebKit2Cocoa/UIDelegate.mm:
     10        (-[FocusDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):
     11        (TEST):
     12        (-[SaveDataToFileDelegate _webView:saveDataToFile:suggestedFilename:mimeType:originatingURL:]):
     13        (-[SaveDataToFileDelegate webView:didFinishNavigation:]):
     14
    1152017-08-25  Youenn Fablet  <youenn@apple.com>
    216
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UIDelegate.mm

    r221172 r221216  
    101101}
    102102
    103 static RetainPtr<NSWindow> window;
    104103static _WKFocusDirection takenDirection;
    105104
     
    118117{
    119118    completionHandler();
    120     synthesizeTab(window.get(), webView, true);
     119    synthesizeTab([webView window], webView, true);
    121120}
    122121
     
    125124TEST(WebKit2, Focus)
    126125{
    127     window = adoptNS([[NSWindow alloc] initWithContentRect:CGRectMake(0, 0, 800, 600) styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:YES]);
    128126    auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600)]);
    129     [[window contentView] addSubview:webView.get()];
    130127    auto delegate = adoptNS([[FocusDelegate alloc] init]);
    131128    [webView setUIDelegate:delegate.get()];
     
    135132    TestWebKitAPI::Util::run(&done);
    136133    ASSERT_EQ(takenDirection, _WKFocusDirectionBackward);
     134}
     135
     136@interface SaveDataToFileDelegate : NSObject <WKUIDelegatePrivate, WKNavigationDelegate>
     137@end
     138
     139@implementation SaveDataToFileDelegate
     140
     141- (void)_webView:(WKWebView *)webView saveDataToFile:(NSData *)data suggestedFilename:(NSString *)suggestedFilename mimeType:(NSString *)mimeType originatingURL:(NSURL *)url
     142{
     143    NSURL *pdfURL = [[NSBundle mainBundle] URLForResource:@"test" withExtension:@"pdf" subdirectory:@"TestWebKitAPI.resources"];
     144    EXPECT_TRUE([data isEqualToData:[NSData dataWithContentsOfURL:pdfURL]]);
     145    EXPECT_STREQ([suggestedFilename UTF8String], "test.pdf");
     146    EXPECT_STREQ([mimeType UTF8String], "application/pdf");
     147    EXPECT_STREQ([[url absoluteString] UTF8String], [[pdfURL absoluteString] UTF8String]);
     148    done = true;
     149}
     150
     151- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
     152{
     153    NSPoint location = NSMakePoint(490, 70); // Location of button to download the pdf.
     154    [(TestWKWebView *)webView mouseDownAtPoint:location simulatePressure:NO];
     155    [(TestWKWebView *)webView mouseUpAtPoint:location];
     156}
     157
     158@end
     159
     160TEST(WebKit2, SaveDataToFile)
     161{
     162    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600)]);
     163    auto delegate = adoptNS([[SaveDataToFileDelegate alloc] init]);
     164    [webView setUIDelegate:delegate.get()];
     165    [webView setNavigationDelegate:delegate.get()];
     166    NSURL *pdfURL = [[NSBundle mainBundle] URLForResource:@"test" withExtension:@"pdf" subdirectory:@"TestWebKitAPI.resources"];
     167    [webView loadRequest:[NSURLRequest requestWithURL:pdfURL]];
     168    TestWebKitAPI::Util::run(&done);
    137169}
    138170
Note: See TracChangeset for help on using the changeset viewer.