Changeset 215385 in webkit


Ignore:
Timestamp:
Apr 14, 2017 6:14:15 PM (7 years ago)
Author:
Wenson Hsieh
Message:

[WK2] Support Icon creation from file URLs on iOS
https://bugs.webkit.org/show_bug.cgi?id=170809
<rdar://problem/31286130>

Reviewed by Tim Horton.

Source/WebCore:

Minor tweaks and refactoring to support displaying a WebCore::Icon from a list of filepaths on iOS. Please see
below annotations for more details. No new tests yet, as behavior on Mac should not have changed, and behavior
on iOS will not change until later patches land. Tests will be added in a later patch.

Most of the changes here remove platform special-casing in FileInputType for iOS and Mac, refactoring the code
such that it works for both platforms while preserving behavior.

  • html/FileInputType.cpp:

(WebCore::FileInputType::~FileInputType):
(WebCore::FileInputType::setFiles):
(WebCore::FileInputType::filesChosen):

  • html/FileInputType.h:

Un-guard m_fileIconLoader on iOS, and un-guard m_displayString for Mac. Consolidate logic in both version of
filesChosen and remove the iOS-specific version. Behavior when passing in an empty display string and null Icon
will be the same as that of the existing filesChosen method on Mac. Also, introduce a version of setFiles that
takes an additional RequestIcon enum that indicates whether or not to additionally use the new filepaths to
request an Icon update. filesChosen invokes this with RequestIcon::No if a non-null Icon was specified, as is
the case when uploading a file via the image picker on iOS.

  • html/HTMLInputElement.cpp:

(WebCore::HTMLInputElement::displayString):

  • html/HTMLInputElement.h:
  • html/InputType.cpp:
  • html/InputType.h:
  • loader/EmptyClients.h:
  • page/ChromeClient.h:

Introduce ChromeClient::createIconForFiles, which generates an icon representing the content at a list of file
paths. See WebKit and WebKit2 ChangeLogs for more details.

  • platform/FileChooser.h:

(WebCore::FileChooserClient::filesChosen):

  • rendering/RenderFileUploadControl.cpp:

(WebCore::RenderFileUploadControl::fileTextValue):

Remove platform special-casing when generating the text to display when uploading a file. If a displayString
is specified, then we use the contents of the displayString; otherwise, fall back to using the input element's
FileList to compute the display string.

Source/WebKit/ios:

Adjust for changes in the ChromeClient in WebCore.

  • WebCoreSupport/WebChromeClientIOS.h:
  • WebCoreSupport/WebChromeClientIOS.mm:

(WebChromeClientIOS::createIconForFiles):

Source/WebKit/mac:

Adjust for changes in the ChromeClient in WebCore.

  • WebCoreSupport/WebChromeClient.h:
  • WebCoreSupport/WebChromeClient.mm:

(WebChromeClient::loadIconForFiles):
(WebChromeClient::createIconForFiles):

Source/WebKit2:

Refactors file icon generation logic to support showing an Icon representing the content at a list of file paths
on iOS. Pulls out logic in WKFileUploadPanel responsible for generating the thumbnail image for a file input into
separate helpers in WebIconUtilities, and then uses these utilities in both WKFileUploadPanel and
WebChromeClientIOS.

  • Shared/ios/WebIconUtilities.h: Added.
  • Shared/ios/WebIconUtilities.mm: Added.

(WebKit::squareCropRectForSize):
(WebKit::squareImage):
(WebKit::thumbnailSizedImageForImage):
(WebKit::fallbackIconForFile):
(WebKit::iconForImageFile):
(WebKit::iconForVideoFile):
(WebKit::iconForFile):

Add logic for generating thumbnail icons, moved from WKFileUploadPanel.mm.

  • UIProcess/ios/forms/WKFileUploadPanel.mm:

(squareCropRectForSize): Deleted.
(squareImage): Deleted.
(thumbnailSizedImageForImage): Deleted.
(fallbackIconForFile): Deleted.
(iconForImageFile): Deleted.
(iconForVideoFile): Deleted.
(iconForFile): Deleted.

Remove logic for generating thumbnail icons.

  • WebKit2.xcodeproj/project.pbxproj:
  • WebProcess/WebCoreSupport/WebChromeClient.cpp:

(WebKit::WebChromeClient::loadIconForFiles):
(WebKit::WebChromeClient::createIconForFiles):

Rather than call Icon::createIconForFiles directly, loadIconForFiles now consults ChromeClient::createIconForFiles
instead. On other platforms, this just turns around and calls Icon::createIconForFiles, but on iOS, we use the
utilities introduced in WebIconUtilities to generate a file icon.

  • WebProcess/WebCoreSupport/WebChromeClient.h:
  • WebProcess/WebCoreSupport/ios/WebChromeClientIOS.mm:

(WebKit::WebChromeClient::createIconForFiles):

Location:
trunk/Source
Files:
2 added
23 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r215384 r215385  
     12017-04-14  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [WK2] Support Icon creation from file URLs on iOS
     4        https://bugs.webkit.org/show_bug.cgi?id=170809
     5        <rdar://problem/31286130>
     6
     7        Reviewed by Tim Horton.
     8
     9        Minor tweaks and refactoring to support displaying a WebCore::Icon from a list of filepaths on iOS. Please see
     10        below annotations for more details. No new tests yet, as behavior on Mac should not have changed, and behavior
     11        on iOS will not change until later patches land. Tests will be added in a later patch.
     12
     13        Most of the changes here remove platform special-casing in FileInputType for iOS and Mac, refactoring the code
     14        such that it works for both platforms while preserving behavior.
     15
     16        * html/FileInputType.cpp:
     17        (WebCore::FileInputType::~FileInputType):
     18        (WebCore::FileInputType::setFiles):
     19        (WebCore::FileInputType::filesChosen):
     20        * html/FileInputType.h:
     21
     22        Un-guard m_fileIconLoader on iOS, and un-guard m_displayString for Mac. Consolidate logic in both version of
     23        filesChosen and remove the iOS-specific version. Behavior when passing in an empty display string and null Icon
     24        will be the same as that of the existing filesChosen method on Mac. Also, introduce a version of setFiles that
     25        takes an additional RequestIcon enum that indicates whether or not to additionally use the new filepaths to
     26        request an Icon update. filesChosen invokes this with RequestIcon::No if a non-null Icon was specified, as is
     27        the case when uploading a file via the image picker on iOS.
     28
     29        * html/HTMLInputElement.cpp:
     30        (WebCore::HTMLInputElement::displayString):
     31        * html/HTMLInputElement.h:
     32        * html/InputType.cpp:
     33        * html/InputType.h:
     34        * loader/EmptyClients.h:
     35        * page/ChromeClient.h:
     36
     37        Introduce ChromeClient::createIconForFiles, which generates an icon representing the content at a list of file
     38        paths. See WebKit and WebKit2 ChangeLogs for more details.
     39
     40        * platform/FileChooser.h:
     41        (WebCore::FileChooserClient::filesChosen):
     42        * rendering/RenderFileUploadControl.cpp:
     43        (WebCore::RenderFileUploadControl::fileTextValue):
     44
     45        Remove platform special-casing when generating the text to display when uploading a file. If a displayString
     46        is specified, then we use the contents of the displayString; otherwise, fall back to using the input element's
     47        FileList to compute the display string.
     48
    1492017-04-14  Brady Eidson  <beidson@apple.com>
    250
  • trunk/Source/WebCore/html/FileInputType.cpp

    r210845 r215385  
    101101        m_fileChooser->invalidate();
    102102
    103 #if !PLATFORM(IOS)
    104     // FIXME: Is this correct? Why don't we do this on iOS?
    105103    if (m_fileIconLoader)
    106104        m_fileIconLoader->invalidate();
    107 #endif
    108105}
    109106
     
    302299}
    303300
    304 #if !PLATFORM(IOS)
    305 
    306301void FileInputType::requestIcon(const Vector<String>& paths)
    307302{
     
    326321}
    327322
    328 #endif
    329 
    330323void FileInputType::applyFileChooserSettings(const FileChooserSettings& settings)
    331324{
     
    337330
    338331void FileInputType::setFiles(RefPtr<FileList>&& files)
     332{
     333    setFiles(WTFMove(files), RequestIcon::Yes);
     334}
     335
     336void FileInputType::setFiles(RefPtr<FileList>&& files, RequestIcon shouldRequestIcon)
    339337{
    340338    if (!files)
     
    362360    input->updateValidity();
    363361
    364 #if !PLATFORM(IOS)
    365     Vector<String> paths;
    366     paths.reserveInitialCapacity(length);
    367     for (unsigned i = 0; i < length; ++i)
    368         paths.uncheckedAppend(m_fileList->item(i)->path());
    369     requestIcon(paths);
    370 #endif
     362    if (shouldRequestIcon == RequestIcon::Yes) {
     363        Vector<String> paths;
     364        paths.reserveInitialCapacity(length);
     365        for (unsigned i = 0; i < length; ++i)
     366            paths.uncheckedAppend(m_fileList->item(i)->path());
     367        requestIcon(paths);
     368    }
    371369
    372370    if (input->renderer())
     
    381379}
    382380
    383 #if PLATFORM(IOS)
    384 
    385381void FileInputType::filesChosen(const Vector<FileChooserFileInfo>& paths, const String& displayString, Icon* icon)
    386382{
    387     m_displayString = displayString;
    388     filesChosen(paths);
    389     iconLoaded(icon);
     383    if (!displayString.isEmpty())
     384        m_displayString = displayString;
     385
     386    setFiles(createFileList(paths), icon ? RequestIcon::No : RequestIcon::Yes);
     387
     388    if (icon)
     389        iconLoaded(icon);
    390390}
    391391
     
    393393{
    394394    return m_displayString;
    395 }
    396 
    397 #endif
    398 
    399 void FileInputType::filesChosen(const Vector<FileChooserFileInfo>& files)
    400 {
    401     setFiles(createFileList(files));
    402395}
    403396
  • trunk/Source/WebCore/html/FileInputType.h

    r210319 r215385  
    6262    FileList* files() final;
    6363    void setFiles(RefPtr<FileList>&&) final;
    64 #if PLATFORM(IOS)
     64    enum class RequestIcon { Yes, No };
     65    void setFiles(RefPtr<FileList>&&, RequestIcon);
    6566    String displayString() const final;
    66 #endif
    6767    bool canSetValue(const String&) final;
    6868    bool getTypeSpecificValue(String&) final; // Checked first, before internal storage or the value attribute.
     
    8080    String defaultToolTip() const final;
    8181
    82     // FileChooserClient implementation.
    83     void filesChosen(const Vector<FileChooserFileInfo>&) final;
    84 #if PLATFORM(IOS)
    85     void filesChosen(const Vector<FileChooserFileInfo>&, const String& displayString, Icon*) final;
    86 #endif
     82    void filesChosen(const Vector<FileChooserFileInfo>&, const String& displayString = { }, Icon* = nullptr) final;
    8783
    8884    // FileIconLoaderClient implementation.
     
    9591
    9692    RefPtr<FileChooser> m_fileChooser;
    97 #if !PLATFORM(IOS)
    9893    std::unique_ptr<FileIconLoader> m_fileIconLoader;
    99 #endif
    10094
    10195    Ref<FileList> m_fileList;
    10296    RefPtr<Icon> m_icon;
    103 #if PLATFORM(IOS)
    10497    String m_displayString;
    105 #endif
    10698};
    10799
  • trunk/Source/WebCore/html/HTMLInputElement.cpp

    r211964 r215385  
    13591359}
    13601360
    1361 #if PLATFORM(IOS)
    13621361String HTMLInputElement::displayString() const
    13631362{
    13641363    return m_inputType->displayString();
    13651364}
    1366 #endif
    13671365
    13681366bool HTMLInputElement::canReceiveDroppedFiles() const
  • trunk/Source/WebCore/html/HTMLInputElement.h

    r210780 r215385  
    247247
    248248    Icon* icon() const;
    249 #if PLATFORM(IOS)
    250249    String displayString() const;
    251 #endif
     250
    252251    // These functions are used for rendering the input active during a
    253252    // drag-and-drop operation.
  • trunk/Source/WebCore/html/InputType.cpp

    r210319 r215385  
    742742}
    743743
    744 #if PLATFORM(IOS)
    745 
    746744String InputType::displayString() const
    747745{
     
    749747    return String();
    750748}
    751 
    752 #endif
    753749
    754750bool InputType::shouldResetOnDocumentActivation()
  • trunk/Source/WebCore/html/InputType.h

    r210319 r215385  
    304304#if PLATFORM(IOS)
    305305    virtual DateComponents::Type dateType() const;
     306#endif
    306307    virtual String displayString() const;
    307 #endif
    308308
    309309protected:
  • trunk/Source/WebCore/loader/EmptyClients.h

    r211033 r215385  
    205205    void didAssociateFormControls(const Vector<RefPtr<Element>>&) final { }
    206206    bool shouldNotifyOnFormChanges() final { return false; }
     207
     208    RefPtr<Icon> createIconForFiles(const Vector<String>& /* filenames */) final { return nullptr; }
    207209};
    208210
  • trunk/Source/WebCore/page/ChromeClient.h

    r212982 r215385  
    3232#include "HTMLMediaElementEnums.h"
    3333#include "HostWindow.h"
     34#include "Icon.h"
    3435#include "LayerFlushThrottleState.h"
    3536#include "MediaProducer.h"
     
    466467
    467468    virtual void reportProcessCPUTime(int64_t, ActivityStateForCPUSampling) { }
     469    virtual RefPtr<Icon> createIconForFiles(const Vector<String>& /* filenames */) = 0;
    468470
    469471protected:
  • trunk/Source/WebCore/platform/FileChooser.h

    r204312 r215385  
    7474    virtual ~FileChooserClient() { }
    7575
    76     virtual void filesChosen(const Vector<FileChooserFileInfo>&) = 0;
    77 #if PLATFORM(IOS)
    78     // FIXME: This function is almost identical to FileChooser::filesChosen(). We should merge this
    79     // function with FileChooser::filesChosen() and hence remove the PLATFORM(IOS)-guard.
    80     virtual void filesChosen(const Vector<FileChooserFileInfo>&, const String& displayString, Icon*) = 0;
    81 #endif
     76    virtual void filesChosen(const Vector<FileChooserFileInfo>&, const String& displayString = { }, Icon* = nullptr) = 0;
    8277};
    8378
  • trunk/Source/WebCore/rendering/RenderFileUploadControl.cpp

    r200041 r215385  
    3434#include "RenderTheme.h"
    3535#include "ShadowRoot.h"
     36#include "StringTruncator.h"
    3637#include "TextRun.h"
    3738#include "VisiblePosition.h"
    3839#include <math.h>
    39 
    40 #if PLATFORM(IOS)
    41 #include "StringTruncator.h"
    42 #endif
    4340
    4441namespace WebCore {
     
    267264String RenderFileUploadControl::fileTextValue() const
    268265{
     266    auto& input = inputElement();
    269267    ASSERT(inputElement().files());
    270 #if PLATFORM(IOS)
    271     if (inputElement().files()->length())
    272         return StringTruncator::rightTruncate(inputElement().displayString(), maxFilenameWidth(), style().fontCascade());
    273 #endif
    274     return theme().fileListNameForWidth(inputElement().files(), style().fontCascade(), maxFilenameWidth(), inputElement().multiple());
     268    if (input.files()->length() && !input.displayString().isEmpty())
     269        return StringTruncator::rightTruncate(input.displayString(), maxFilenameWidth(), style().fontCascade());
     270    return theme().fileListNameForWidth(input.files(), style().fontCascade(), maxFilenameWidth(), input.multiple());
    275271}
    276272   
  • trunk/Source/WebKit/ios/ChangeLog

    r213355 r215385  
     12017-04-14  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [WK2] Support Icon creation from file URLs on iOS
     4        https://bugs.webkit.org/show_bug.cgi?id=170809
     5        <rdar://problem/31286130>
     6
     7        Reviewed by Tim Horton.
     8
     9        Adjust for changes in the ChromeClient in WebCore.
     10
     11        * WebCoreSupport/WebChromeClientIOS.h:
     12        * WebCoreSupport/WebChromeClientIOS.mm:
     13        (WebChromeClientIOS::createIconForFiles):
     14
    1152017-03-02  Sam Weinig  <sam@webkit.org>
    216
  • trunk/Source/WebKit/ios/WebCoreSupport/WebChromeClientIOS.h

    r211033 r215385  
    9090    void focusedElementChanged(WebCore::Element*) final;
    9191    void showPlaybackTargetPicker(bool hasVideo) final;
     92    RefPtr<WebCore::Icon> createIconForFiles(const Vector<String>& filenames) final;
    9293
    9394#if ENABLE(ORIENTATION_EVENTS)
  • trunk/Source/WebKit/ios/WebCoreSupport/WebChromeClientIOS.mm

    r211033 r215385  
    356356}
    357357
     358RefPtr<Icon> WebChromeClientIOS::createIconForFiles(const Vector<String>& filenames)
     359{
     360    return Icon::createIconForFiles(filenames);
     361}
     362
    358363#if ENABLE(ORIENTATION_EVENTS)
    359364
  • trunk/Source/WebKit/mac/ChangeLog

    r215316 r215385  
     12017-04-14  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [WK2] Support Icon creation from file URLs on iOS
     4        https://bugs.webkit.org/show_bug.cgi?id=170809
     5        <rdar://problem/31286130>
     6
     7        Reviewed by Tim Horton.
     8
     9        Adjust for changes in the ChromeClient in WebCore.
     10
     11        * WebCoreSupport/WebChromeClient.h:
     12        * WebCoreSupport/WebChromeClient.mm:
     13        (WebChromeClient::loadIconForFiles):
     14        (WebChromeClient::createIconForFiles):
     15
    1162017-04-12  Dan Bernstein  <mitz@apple.com>
    217
  • trunk/Source/WebKit/mac/WebCoreSupport/WebChromeClient.h

    r211042 r215385  
    129129    void runOpenPanel(WebCore::Frame&, WebCore::FileChooser&) override;
    130130    void loadIconForFiles(const Vector<String>&, WebCore::FileIconLoader&) final;
     131    RefPtr<WebCore::Icon> createIconForFiles(const Vector<String>& filenames) override;
    131132
    132133#if !PLATFORM(IOS)
  • trunk/Source/WebKit/mac/WebCoreSupport/WebChromeClient.mm

    r211042 r215385  
    763763void WebChromeClient::loadIconForFiles(const Vector<String>& filenames, FileIconLoader& iconLoader)
    764764{
    765     iconLoader.iconLoaded(Icon::createIconForFiles(filenames));
     765    iconLoader.iconLoaded(createIconForFiles(filenames));
     766}
     767
     768RefPtr<Icon> WebChromeClient::createIconForFiles(const Vector<String>& filenames)
     769{
     770    return Icon::createIconForFiles(filenames);
    766771}
    767772
  • trunk/Source/WebKit2/ChangeLog

    r215384 r215385  
     12017-04-14  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [WK2] Support Icon creation from file URLs on iOS
     4        https://bugs.webkit.org/show_bug.cgi?id=170809
     5        <rdar://problem/31286130>
     6
     7        Reviewed by Tim Horton.
     8
     9        Refactors file icon generation logic to support showing an Icon representing the content at a list of file paths
     10        on iOS. Pulls out logic in WKFileUploadPanel responsible for generating the thumbnail image for a file input into
     11        separate helpers in WebIconUtilities, and then uses these utilities in both WKFileUploadPanel and
     12        WebChromeClientIOS.
     13
     14        * Shared/ios/WebIconUtilities.h: Added.
     15        * Shared/ios/WebIconUtilities.mm: Added.
     16        (WebKit::squareCropRectForSize):
     17        (WebKit::squareImage):
     18        (WebKit::thumbnailSizedImageForImage):
     19        (WebKit::fallbackIconForFile):
     20        (WebKit::iconForImageFile):
     21        (WebKit::iconForVideoFile):
     22        (WebKit::iconForFile):
     23
     24        Add logic for generating thumbnail icons, moved from WKFileUploadPanel.mm.
     25
     26        * UIProcess/ios/forms/WKFileUploadPanel.mm:
     27        (squareCropRectForSize): Deleted.
     28        (squareImage): Deleted.
     29        (thumbnailSizedImageForImage): Deleted.
     30        (fallbackIconForFile): Deleted.
     31        (iconForImageFile): Deleted.
     32        (iconForVideoFile): Deleted.
     33        (iconForFile): Deleted.
     34
     35        Remove logic for generating thumbnail icons.
     36
     37        * WebKit2.xcodeproj/project.pbxproj:
     38        * WebProcess/WebCoreSupport/WebChromeClient.cpp:
     39        (WebKit::WebChromeClient::loadIconForFiles):
     40        (WebKit::WebChromeClient::createIconForFiles):
     41
     42        Rather than call Icon::createIconForFiles directly, loadIconForFiles now consults ChromeClient::createIconForFiles
     43        instead. On other platforms, this just turns around and calls Icon::createIconForFiles, but on iOS, we use the
     44        utilities introduced in WebIconUtilities to generate a file icon.
     45
     46        * WebProcess/WebCoreSupport/WebChromeClient.h:
     47        * WebProcess/WebCoreSupport/ios/WebChromeClientIOS.mm:
     48        (WebKit::WebChromeClient::createIconForFiles):
     49
    1502017-04-14  Brady Eidson  <beidson@apple.com>
    251
  • trunk/Source/WebKit2/UIProcess/ios/forms/WKFileUploadPanel.mm

    r214723 r215385  
    3939#import "WKStringCF.h"
    4040#import "WKURLCF.h"
     41#import "WebIconUtilities.h"
    4142#import "WebOpenPanelResultListenerProxy.h"
    4243#import "WebPageProxy.h"
     
    5152using namespace WebKit;
    5253
    53 SOFT_LINK_FRAMEWORK(AVFoundation);
    54 SOFT_LINK_CLASS(AVFoundation, AVAssetImageGenerator);
    55 SOFT_LINK_CLASS(AVFoundation, AVURLAsset);
    56 
    57 SOFT_LINK_FRAMEWORK(CoreMedia);
    58 SOFT_LINK_CONSTANT(CoreMedia, kCMTimeZero, CMTime);
    59 
    6054SOFT_LINK_FRAMEWORK(Photos);
    6155SOFT_LINK_CLASS(Photos, PHAsset);
     
    6559SOFT_LINK_CONSTANT(Photos, PHImageRequestOptionsVersionCurrent, NSString *);
    6660
    67 #define kCMTimeZero getkCMTimeZero()
    68 
    6961#pragma clang diagnostic push
    7062#pragma clang diagnostic ignored "-Wdeprecated-declarations"
     
    8678    return _UIImageGetWebKitTakePhotoOrVideoIcon();
    8779}
    88 
    89 #pragma mark - Icon generation
    90 
    91 static const CGFloat iconSideLength = 100;
    92 
    93 static CGRect squareCropRectForSize(CGSize size)
    94 {
    95     CGFloat smallerSide = MIN(size.width, size.height);
    96     CGRect cropRect = CGRectMake(0, 0, smallerSide, smallerSide);
    97 
    98     if (size.width < size.height)
    99         cropRect.origin.y = std::round((size.height - smallerSide) / 2);
    100     else
    101         cropRect.origin.x = std::round((size.width - smallerSide) / 2);
    102 
    103     return cropRect;
    104 }
    105 
    106 static UIImage *squareImage(CGImageRef image)
    107 {
    108     if (!image)
    109         return nil;
    110 
    111     CGSize imageSize = CGSizeMake(CGImageGetWidth(image), CGImageGetHeight(image));
    112     if (imageSize.width == imageSize.height)
    113         return [UIImage imageWithCGImage:image];
    114 
    115     CGRect squareCropRect = squareCropRectForSize(imageSize);
    116     RetainPtr<CGImageRef> squareImage = adoptCF(CGImageCreateWithImageInRect(image, squareCropRect));
    117     return [UIImage imageWithCGImage:squareImage.get()];
    118 }
    119 
    120 static UIImage *thumbnailSizedImageForImage(CGImageRef image)
    121 {
    122     UIImage *squaredImage = squareImage(image);
    123     if (!squaredImage)
    124         return nil;
    125 
    126     CGRect destRect = CGRectMake(0, 0, iconSideLength, iconSideLength);
    127     UIGraphicsBeginImageContext(destRect.size);
    128     CGContextSetInterpolationQuality(UIGraphicsGetCurrentContext(), kCGInterpolationHigh);
    129     [squaredImage drawInRect:destRect];
    130     UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext();
    131     UIGraphicsEndImageContext();
    132     return resultImage;
    133 }
    134 
    135 static UIImage* fallbackIconForFile(NSURL *file)
    136 {
    137     ASSERT_ARG(file, [file isFileURL]);
    138 
    139     UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL:file];
    140     return thumbnailSizedImageForImage(interactionController.icons[0].CGImage);
    141 }
    142 
    143 static UIImage* iconForImageFile(NSURL *file)
    144 {
    145     ASSERT_ARG(file, [file isFileURL]);
    146 
    147     NSDictionary *options = @{
    148         (id)kCGImageSourceCreateThumbnailFromImageIfAbsent: @YES,
    149         (id)kCGImageSourceThumbnailMaxPixelSize: @(iconSideLength),
    150         (id)kCGImageSourceCreateThumbnailWithTransform: @YES,
    151     };
    152     RetainPtr<CGImageSource> imageSource = adoptCF(CGImageSourceCreateWithURL((CFURLRef)file, 0));
    153     RetainPtr<CGImageRef> thumbnail = adoptCF(CGImageSourceCreateThumbnailAtIndex(imageSource.get(), 0, (CFDictionaryRef)options));
    154     if (!thumbnail) {
    155         LOG_ERROR("WKFileUploadPanel: Error creating thumbnail image for image: %@", file);
    156         return fallbackIconForFile(file);
    157     }
    158 
    159     return thumbnailSizedImageForImage(thumbnail.get());
    160 }
    161 
    162 static UIImage* iconForVideoFile(NSURL *file)
    163 {
    164     ASSERT_ARG(file, [file isFileURL]);
    165 
    166     RetainPtr<AVURLAsset> asset = adoptNS([allocAVURLAssetInstance() initWithURL:file options:nil]);
    167     RetainPtr<AVAssetImageGenerator> generator = adoptNS([allocAVAssetImageGeneratorInstance() initWithAsset:asset.get()]);
    168     [generator setAppliesPreferredTrackTransform:YES];
    169 
    170     NSError *error = nil;
    171     RetainPtr<CGImageRef> imageRef = adoptCF([generator copyCGImageAtTime:kCMTimeZero actualTime:nil error:&error]);
    172     if (!imageRef) {
    173         LOG_ERROR("WKFileUploadPanel: Error creating image for video '%@': %@", file, error);
    174         return fallbackIconForFile(file);
    175     }
    176 
    177     return thumbnailSizedImageForImage(imageRef.get());
    178 }
    179 
    180 static UIImage* iconForFile(NSURL *file)
    181 {
    182     ASSERT_ARG(file, [file isFileURL]);
    183 
    184     NSString *fileExtension = file.pathExtension;
    185     if (!fileExtension.length)
    186         return nil;
    187 
    188     RetainPtr<CFStringRef> fileUTI = adoptCF(UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (CFStringRef)fileExtension, 0));
    189 
    190     if (UTTypeConformsTo(fileUTI.get(), kUTTypeImage))
    191         return iconForImageFile(file);
    192 
    193     if (UTTypeConformsTo(fileUTI.get(), kUTTypeMovie))
    194         return iconForVideoFile(file);
    195 
    196     return fallbackIconForFile(file);
    197 }
    198 
    19980
    20081#pragma mark - _WKFileUploadItem
  • trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj

    r215247 r215385  
    20082008                F409BA181E6E64BC009DA28E /* WKDragDestinationAction.h in Headers */ = {isa = PBXBuildFile; fileRef = F409BA171E6E64B3009DA28E /* WKDragDestinationAction.h */; settings = {ATTRIBUTES = (Private, ); }; };
    20092009                F43370971E4D72ED00052B0E /* _WKTestingDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = F43370961E4D6A4400052B0E /* _WKTestingDelegate.h */; settings = {ATTRIBUTES = (Private, ); }; };
     2010                F44DFEB21E9E752F0038D196 /* WebIconUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = F44DFEB01E9E752F0038D196 /* WebIconUtilities.h */; };
     2011                F44DFEB31E9E752F0038D196 /* WebIconUtilities.mm in Sources */ = {isa = PBXBuildFile; fileRef = F44DFEB11E9E752F0038D196 /* WebIconUtilities.mm */; };
    20102012                F6113E25126CE1820057D0A7 /* APIUserContentURLPattern.h in Headers */ = {isa = PBXBuildFile; fileRef = F6113E24126CE1820057D0A7 /* APIUserContentURLPattern.h */; };
    20112013                F6113E28126CE19B0057D0A7 /* WKUserContentURLPattern.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F6113E26126CE19B0057D0A7 /* WKUserContentURLPattern.cpp */; };
     
    43404342                F409BA171E6E64B3009DA28E /* WKDragDestinationAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKDragDestinationAction.h; sourceTree = "<group>"; };
    43414343                F43370961E4D6A4400052B0E /* _WKTestingDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKTestingDelegate.h; sourceTree = "<group>"; };
     4344                F44DFEB01E9E752F0038D196 /* WebIconUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebIconUtilities.h; path = ios/WebIconUtilities.h; sourceTree = "<group>"; };
     4345                F44DFEB11E9E752F0038D196 /* WebIconUtilities.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WebIconUtilities.mm; path = ios/WebIconUtilities.mm; sourceTree = "<group>"; };
    43424346                F6113E24126CE1820057D0A7 /* APIUserContentURLPattern.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APIUserContentURLPattern.h; sourceTree = "<group>"; };
    43434347                F6113E26126CE19B0057D0A7 /* WKUserContentURLPattern.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKUserContentURLPattern.cpp; sourceTree = "<group>"; };
     
    53385342                                A118A9EC1907AD6F00F7C92B /* QuickLookDocumentData.cpp */,
    53395343                                A118A9ED1907AD6F00F7C92B /* QuickLookDocumentData.h */,
     5344                                F44DFEB01E9E752F0038D196 /* WebIconUtilities.h */,
     5345                                F44DFEB11E9E752F0038D196 /* WebIconUtilities.mm */,
    53405346                                2DA944991884E4F000ED86DB /* WebIOSEventFactory.h */,
    53415347                                2DA9449A1884E4F000ED86DB /* WebIOSEventFactory.mm */,
     
    82578263                                1AD25E96167AB08100EA9BCD /* DownloadProxyMap.h in Headers */,
    82588264                                1AB7D61A1288B9D900CFD08C /* DownloadProxyMessages.h in Headers */,
     8265                                F44DFEB21E9E752F0038D196 /* WebIconUtilities.h in Headers */,
    82598266                                C517388112DF8F4F00EE3F47 /* DragControllerAction.h in Headers */,
    82608267                                BC8452A81162C80900CAB9B5 /* DrawingArea.h in Headers */,
     
    1029610303                                BC111AE4112F5C2600337BAB /* WebProcess.cpp in Sources */,
    1029710304                                7C6E70FB18B2DC7A00F24E2E /* WebProcessCocoa.mm in Sources */,
     10305                                F44DFEB31E9E752F0038D196 /* WebIconUtilities.mm in Sources */,
    1029810306                                1A043A0A124D11A900FFBFB5 /* WebProcessConnection.cpp in Sources */,
    1029910307                                1A043F6912514D8B00FFBFB5 /* WebProcessConnectionMessageReceiver.cpp in Sources */,
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp

    r212982 r215385  
    783783void WebChromeClient::loadIconForFiles(const Vector<String>& filenames, FileIconLoader& loader)
    784784{
    785     loader.iconLoaded(Icon::createIconForFiles(filenames));
     785    loader.iconLoaded(createIconForFiles(filenames));
    786786}
    787787
     
    796796{
    797797    m_page.send(Messages::WebPageProxy::SetCursorHiddenUntilMouseMoves(hiddenUntilMouseMoves));
     798}
     799
     800RefPtr<Icon> WebChromeClient::createIconForFiles(const Vector<String>& filenames)
     801{
     802    return Icon::createIconForFiles(filenames);
    798803}
    799804
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h

    r212982 r215385  
    335335    void imageOrMediaDocumentSizeChanged(const WebCore::IntSize&) final;
    336336
     337    RefPtr<WebCore::Icon> createIconForFiles(const Vector<String>& filenames) final;
     338
    337339#if ENABLE(VIDEO) && USE(GSTREAMER)
    338340    void requestInstallMissingMediaPlugins(const String& /*details*/, const String& /*description*/, WebCore::MediaPlayerRequestInstallMissingPluginsCallback&) final;
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/ios/WebChromeClientIOS.mm

    r211033 r215385  
    3030
    3131#import "DrawingArea.h"
     32#import "UIKitSPI.h"
    3233#import "WebCoreArgumentCoders.h"
    3334#import "WebFrame.h"
     35#import "WebIconUtilities.h"
    3436#import "WebPage.h"
    3537#import "WebPageProxyMessages.h"
     38#import <WebCore/Icon.h>
    3639#import <WebCore/NotImplemented.h>
     40#import <wtf/RefPtr.h>
     41
     42using namespace WebCore;
    3743
    3844namespace WebKit {
     
    144150}
    145151
     152RefPtr<Icon> WebChromeClient::createIconForFiles(const Vector<String>& filenames)
     153{
     154    if (!filenames.size())
     155        return nullptr;
     156
     157    // FIXME: We should generate an icon showing multiple files here, if applicable. Currently, if there are multiple
     158    // files, we only use the first URL to generate an icon.
     159    return Icon::createIconForImage(iconForFile([NSURL fileURLWithPath:filenames[0]]).CGImage);
     160}
     161
    146162} // namespace WebKit
    147163
Note: See TracChangeset for help on using the changeset viewer.