HTML file input elements do not support file extensions in the "accept" attribute
authorbburg@apple.com <bburg@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 2 Aug 2017 17:38:57 +0000 (17:38 +0000)
committerbburg@apple.com <bburg@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 2 Aug 2017 17:38:57 +0000 (17:38 +0000)
https://bugs.webkit.org/show_bug.cgi?id=95698
<rdar://problem/12231850>

Reviewed by Darin Adler.

Source/WebCore:

Serialize the accepted file extensions so they can be accessed in the UI process.

* platform/FileChooser.h:
* platform/FileChooser.cpp:
(WebCore::FileChooser::invalidate): Modernize.
(WebCore::FileChooserSettings::acceptTypes const): Deleted.
This is dead code, it was only used by Chromium.

Source/WebKit:

Plumb accepted file extensions out to the C API.
The Cocoa API will be improved in a later patch.

* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<FileChooserSettings>::encode):
(IPC::ArgumentCoder<FileChooserSettings>::decode):
* UIProcess/API/APIOpenPanelParameters.cpp:
(API::OpenPanelParameters::acceptFileExtensions const):
* UIProcess/API/APIOpenPanelParameters.h:
* UIProcess/API/C/WKOpenPanelParametersRef.cpp:
(WKOpenPanelParametersCopyAcceptedFileExtensions):
* UIProcess/API/C/WKOpenPanelParametersRef.h:

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

Source/WebCore/ChangeLog
Source/WebCore/platform/FileChooser.cpp
Source/WebCore/platform/FileChooser.h
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebCoreArgumentCoders.cpp
Source/WebKit/UIProcess/API/APIOpenPanelParameters.cpp
Source/WebKit/UIProcess/API/APIOpenPanelParameters.h
Source/WebKit/UIProcess/API/C/WKOpenPanelParametersRef.cpp
Source/WebKit/UIProcess/API/C/WKOpenPanelParametersRef.h

index 026a2f9..0341991 100644 (file)
@@ -1,3 +1,19 @@
+2017-08-01  Brian Burg  <bburg@apple.com>
+
+        HTML file input elements do not support file extensions in the "accept" attribute
+        https://bugs.webkit.org/show_bug.cgi?id=95698
+        <rdar://problem/12231850>
+
+        Reviewed by Darin Adler.
+
+        Serialize the accepted file extensions so they can be accessed in the UI process.
+
+        * platform/FileChooser.h:
+        * platform/FileChooser.cpp:
+        (WebCore::FileChooser::invalidate): Modernize.
+        (WebCore::FileChooserSettings::acceptTypes const): Deleted.
+        This is dead code, it was only used by Chromium.
+
 2017-08-02  Fujii Hironori  <Hironori.Fujii@sony.com>
 
         Use LazyNeverDestroyed instead of DEFINE_GLOBAL for QualifiedName
index eada49b..f30c49f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2007-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -50,7 +50,7 @@ void FileChooser::invalidate()
 {
     ASSERT(m_client);
 
-    m_client = 0;
+    m_client = nullptr;
 }
 
 void FileChooser::chooseFile(const String& filename)
@@ -110,13 +110,4 @@ void FileChooser::chooseFiles(const Vector<FileChooserFileInfo>& files)
         m_client->filesChosen(files);
 }
 
-Vector<String> FileChooserSettings::acceptTypes() const
-{
-    Vector<String> acceptTypes;
-    acceptTypes.reserveCapacity(acceptMIMETypes.size() + acceptFileExtensions.size());
-    acceptTypes.appendVector(acceptMIMETypes);
-    acceptTypes.appendVector(acceptFileExtensions);
-    return acceptTypes;
-}
-
-}
+} // namespace WebCore
index 7e3290f..072714b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2006-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -41,7 +41,7 @@ enum MediaCaptureType {
     MediaCaptureTypeUser,
     MediaCaptureTypeEnvironment
 };
-    
+
 class FileChooser;
 class Icon;
 
@@ -64,9 +64,6 @@ struct FileChooserSettings {
 #if ENABLE(MEDIA_CAPTURE)
     MediaCaptureType mediaCaptureType;
 #endif
-
-    // Returns a combined vector of acceptMIMETypes and acceptFileExtensions.
-    Vector<String> acceptTypes() const;
 };
 
 class FileChooserClient {
@@ -89,7 +86,7 @@ public:
     // FIXME: This function is almost identical to FileChooser::chooseFiles(). We should merge this
     // function with FileChooser::chooseFiles() and hence remove the PLATFORM(IOS)-guard.
     WEBCORE_EXPORT void chooseMediaFiles(const Vector<String>& paths, const String& displayString, Icon*);
-#endif    
+#endif
 
     // FIXME: We should probably just pass file paths that could be virtual paths with proper display names rather than passing structs.
     void chooseFiles(const Vector<FileChooserFileInfo>& files);
@@ -99,7 +96,7 @@ public:
 private:
     FileChooser(FileChooserClient*, const FileChooserSettings&);
 
-    FileChooserClient* m_client;
+    FileChooserClient* m_client { nullptr };
     FileChooserSettings m_settings;
 };
 
index bc81815..b3351c4 100644 (file)
@@ -1,3 +1,24 @@
+2017-08-01  Brian Burg  <bburg@apple.com>
+
+        HTML file input elements do not support file extensions in the "accept" attribute
+        https://bugs.webkit.org/show_bug.cgi?id=95698
+        <rdar://problem/12231850>
+
+        Reviewed by Darin Adler.
+
+        Plumb accepted file extensions out to the C API.
+        The Cocoa API will be improved in a later patch.
+
+        * Shared/WebCoreArgumentCoders.cpp:
+        (IPC::ArgumentCoder<FileChooserSettings>::encode):
+        (IPC::ArgumentCoder<FileChooserSettings>::decode):
+        * UIProcess/API/APIOpenPanelParameters.cpp:
+        (API::OpenPanelParameters::acceptFileExtensions const):
+        * UIProcess/API/APIOpenPanelParameters.h:
+        * UIProcess/API/C/WKOpenPanelParametersRef.cpp:
+        (WKOpenPanelParametersCopyAcceptedFileExtensions):
+        * UIProcess/API/C/WKOpenPanelParametersRef.h:
+
 2017-08-02  Fujii Hironori  <Hironori.Fujii@sony.com>
 
         Use LazyNeverDestroyed instead of DEFINE_GLOBAL for QualifiedName
index 130d63d..99c3954 100644 (file)
@@ -1560,6 +1560,7 @@ void ArgumentCoder<FileChooserSettings>::encode(Encoder& encoder, const FileChoo
 {
     encoder << settings.allowsMultipleFiles;
     encoder << settings.acceptMIMETypes;
+    encoder << settings.acceptFileExtensions;
     encoder << settings.selectedFiles;
 #if ENABLE(MEDIA_CAPTURE)
     encoder.encodeEnum(settings.mediaCaptureType);
@@ -1572,6 +1573,8 @@ bool ArgumentCoder<FileChooserSettings>::decode(Decoder& decoder, FileChooserSet
         return false;
     if (!decoder.decode(settings.acceptMIMETypes))
         return false;
+    if (!decoder.decode(settings.acceptFileExtensions))
+        return false;
     if (!decoder.decode(settings.selectedFiles))
         return false;
 #if ENABLE(MEDIA_CAPTURE)
index d1442a3..771990a 100644 (file)
@@ -54,6 +54,11 @@ Ref<API::Array> OpenPanelParameters::acceptMIMETypes() const
     return API::Array::createStringArray(m_settings.acceptMIMETypes);
 }
 
+Ref<API::Array> OpenPanelParameters::acceptFileExtensions() const
+{
+    return API::Array::createStringArray(m_settings.acceptFileExtensions);
+}
+
 #if ENABLE(MEDIA_CAPTURE)
 WebCore::MediaCaptureType OpenPanelParameters::mediaCaptureType() const
 {
index ddf7a4c..3cd0da6 100644 (file)
@@ -40,6 +40,7 @@ public:
 
     bool allowMultipleFiles() const { return m_settings.allowsMultipleFiles; }
     Ref<API::Array> acceptMIMETypes() const;
+    Ref<API::Array> acceptFileExtensions() const;
     Ref<API::Array> selectedFileNames() const;
 #if ENABLE(MEDIA_CAPTURE)
     WebCore::MediaCaptureType mediaCaptureType() const;
index c8ad8da..f0eac0b 100644 (file)
@@ -48,6 +48,11 @@ WKArrayRef WKOpenPanelParametersCopyAcceptedMIMETypes(WKOpenPanelParametersRef p
     return toAPI(&toImpl(parametersRef)->acceptMIMETypes().leakRef());
 }
 
+WKArrayRef WKOpenPanelParametersCopyAcceptedFileExtensions(WKOpenPanelParametersRef parametersRef)
+{
+    return toAPI(&toImpl(parametersRef)->acceptFileExtensions().leakRef());
+}
+
 // Deprecated.
 WKStringRef WKOpenPanelParametersCopyCapture(WKOpenPanelParametersRef)
 {
index d8ca7c4..f51c5de 100644 (file)
@@ -42,6 +42,7 @@ WK_EXPORT WKTypeID WKOpenPanelParametersGetTypeID();
 WK_EXPORT bool WKOpenPanelParametersGetAllowsMultipleFiles(WKOpenPanelParametersRef parameters);
 
 WK_EXPORT WKArrayRef WKOpenPanelParametersCopyAcceptedMIMETypes(WKOpenPanelParametersRef parameters);
+WK_EXPORT WKArrayRef WKOpenPanelParametersCopyAcceptedFileExtensions(WKOpenPanelParametersRef parameters);
 
 /* DEPRECATED - Please use WKOpenPanelParametersGetCaptureEnabled() instead. */
 WK_EXPORT WKStringRef WKOpenPanelParametersCopyCapture(WKOpenPanelParametersRef parameters);