Changeset 226330 in webkit


Ignore:
Timestamp:
Jan 2, 2018, 12:02:50 PM (7 years ago)
Author:
achristensen@apple.com
Message:

Use BlockPtrs and lambdas instead of new/delete to pass parameters to blocks in WebViewImpl::performDragOperation
https://bugs.webkit.org/show_bug.cgi?id=180795

Reviewed by Brent Fulgham.

  • UIProcess/Cocoa/WebViewImpl.mm:

(WebKit::WebViewImpl::performDragOperation):

Location:
trunk/Source/WebKit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r226327 r226330  
     12018-01-02  Alex Christensen  <achristensen@webkit.org>
     2
     3        Use BlockPtrs and lambdas instead of new/delete to pass parameters to blocks in WebViewImpl::performDragOperation
     4        https://bugs.webkit.org/show_bug.cgi?id=180795
     5
     6        Reviewed by Brent Fulgham.
     7
     8        * UIProcess/Cocoa/WebViewImpl.mm:
     9        (WebKit::WebViewImpl::performDragOperation):
     10
    1112018-01-02  Michael Catanzaro  <mcatanzaro@igalia.com>
    212
  • trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm

    r226312 r226330  
    36913691    WebCore::IntPoint client([m_view convertPoint:draggingInfo.draggingLocation fromView:nil]);
    36923692    WebCore::IntPoint global(WebCore::globalPoint(draggingInfo.draggingLocation, [m_view window]));
    3693     WebCore::DragData *dragData = new WebCore::DragData(draggingInfo, client, global, static_cast<WebCore::DragOperation>(draggingInfo.draggingSourceOperationMask), applicationFlagsForDrag(m_view.getAutoreleased(), draggingInfo));
     3693    WebCore::DragData dragData(draggingInfo, client, global, static_cast<WebCore::DragOperation>(draggingInfo.draggingSourceOperationMask), applicationFlagsForDrag(m_view.getAutoreleased(), draggingInfo));
    36943694
    36953695    NSArray *types = draggingInfo.draggingPasteboard.types;
     
    36993699    if ([types containsObject:WebCore::legacyFilenamesPasteboardType()]) {
    37003700        NSArray *files = [draggingInfo.draggingPasteboard propertyListForType:WebCore::legacyFilenamesPasteboardType()];
    3701         if (![files isKindOfClass:[NSArray class]]) {
    3702             delete dragData;
     3701        if (![files isKindOfClass:[NSArray class]])
    37033702            return false;
    3704         }
    37053703
    37063704        Vector<String> fileNames;
     
    37133711    else if (![types containsObject:PasteboardTypes::WebArchivePboardType] && [types containsObject:WebCore::legacyFilesPromisePasteboardType()]) {
    37143712        NSArray *files = [draggingInfo.draggingPasteboard propertyListForType:WebCore::legacyFilesPromisePasteboardType()];
    3715         if (![files isKindOfClass:[NSArray class]]) {
    3716             delete dragData;
     3713        if (![files isKindOfClass:[NSArray class]])
    37173714            return false;
    3718         }
    37193715        size_t fileCount = files.count;
    3720         Vector<String> *fileNames = new Vector<String>;
     3716        Vector<String> fileNames;
    37213717        NSURL *dropLocation = [NSURL fileURLWithPath:NSTemporaryDirectory() isDirectory:YES];
    37223718        String pasteboardName = draggingInfo.draggingPasteboard.name;
    3723         [draggingInfo enumerateDraggingItemsWithOptions:0 forView:m_view.getAutoreleased() classes:@[[NSFilePromiseReceiver class]] searchOptions:@{ } usingBlock:^(NSDraggingItem * __nonnull draggingItem, NSInteger idx, BOOL * __nonnull stop) {
     3719        [draggingInfo enumerateDraggingItemsWithOptions:0 forView:m_view.getAutoreleased() classes:@[[NSFilePromiseReceiver class]] searchOptions:@{ } usingBlock:BlockPtr<void (NSDraggingItem *, NSInteger, BOOL *)>::fromCallable([this, fileNames = WTFMove(fileNames), dropLocation = retainPtr(dropLocation), fileCount, dragData = WTFMove(dragData), pasteboardName](NSDraggingItem * __nonnull draggingItem, NSInteger idx, BOOL * __nonnull stop) mutable {
    37243720            NSFilePromiseReceiver *item = draggingItem.item;
    37253721            NSDictionary *options = @{ };
    37263722
    37273723            RetainPtr<NSOperationQueue> queue = adoptNS([NSOperationQueue new]);
    3728             [item receivePromisedFilesAtDestination:dropLocation options:options operationQueue:queue.get() reader:^(NSURL * _Nonnull fileURL, NSError * _Nullable errorOrNil) {
     3724            [item receivePromisedFilesAtDestination:dropLocation.get() options:options operationQueue:queue.get() reader:BlockPtr<void(NSURL *, NSError *)>::fromCallable([this, fileNames = WTFMove(fileNames), fileCount, dragData = WTFMove(dragData), pasteboardName](NSURL * _Nonnull fileURL, NSError * _Nullable errorOrNil) mutable {
    37293725                if (errorOrNil)
    37303726                    return;
    37313727
    3732                 dispatch_async(dispatch_get_main_queue(), [this, path = RetainPtr<NSString>(fileURL.path), fileNames, fileCount, dragData, pasteboardName] {
    3733                     fileNames->append(path.get());
    3734                     if (fileNames->size() == fileCount) {
     3728                dispatch_async(dispatch_get_main_queue(), BlockPtr<void()>::fromCallable([this, path = retainPtr(fileURL.path), fileNames, fileCount, dragData = WTFMove(dragData), pasteboardName]() mutable {
     3729                    fileNames.append(path.get());
     3730                    if (fileNames.size() == fileCount) {
    37353731                        SandboxExtension::Handle sandboxExtensionHandle;
    37363732                        SandboxExtension::HandleArray sandboxExtensionForUpload;
    37373733
    3738                         m_page->createSandboxExtensionsIfNeeded(*fileNames, sandboxExtensionHandle, sandboxExtensionForUpload);
    3739                         dragData->setFileNames(*fileNames);
    3740                         m_page->performDragOperation(*dragData, pasteboardName, WTFMove(sandboxExtensionHandle), WTFMove(sandboxExtensionForUpload));
    3741                         delete dragData;
    3742                         delete fileNames;
     3734                        m_page->createSandboxExtensionsIfNeeded(fileNames, sandboxExtensionHandle, sandboxExtensionForUpload);
     3735                        dragData.setFileNames(fileNames);
     3736                        m_page->performDragOperation(dragData, pasteboardName, WTFMove(sandboxExtensionHandle), WTFMove(sandboxExtensionForUpload));
    37433737                    }
    3744                 });
    3745             }];
    3746         }];
     3738                }).get());
     3739            }).get()];
     3740        }).get()];
    37473741
    37483742        return true;
     
    37503744#endif
    37513745
    3752     m_page->performDragOperation(*dragData, draggingInfo.draggingPasteboard.name, WTFMove(sandboxExtensionHandle), WTFMove(sandboxExtensionForUpload));
    3753     delete dragData;
     3746    m_page->performDragOperation(dragData, draggingInfo.draggingPasteboard.name, WTFMove(sandboxExtensionHandle), WTFMove(sandboxExtensionForUpload));
    37543747
    37553748    return true;
Note: See TracChangeset for help on using the changeset viewer.