Bug 91702 - Files from drag and file <input> should use getMIMETypeForExtension to determine content type.
Summary: Files from drag and file <input> should use getMIMETypeForExtension to determ...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Daniel Cheng
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-07-18 18:35 PDT by Daniel Cheng
Modified: 2019-02-06 09:18 PST (History)
9 users (show)

See Also:


Attachments
Patch (6.31 KB, patch)
2012-07-19 21:37 PDT, Daniel Cheng
no flags Details | Formatted Diff | Diff
Patch (adds special ctor for FileSystem) (9.57 KB, patch)
2012-07-19 22:38 PDT, Kinuko Yasuda
no flags Details | Formatted Diff | Diff
Special ctor for drag/file input (12.22 KB, patch)
2012-07-20 13:40 PDT, Daniel Cheng
no flags Details | Formatted Diff | Diff
Patch (12.43 KB, patch)
2012-07-23 13:48 PDT, Daniel Cheng
no flags Details | Formatted Diff | Diff
Patch (11.92 KB, patch)
2012-07-23 17:40 PDT, Daniel Cheng
jianli: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Cheng 2012-07-18 18:35:52 PDT
In r117432, kinuko merged some code together. One path was using getMIMETypeForExtension and another was using getWellKnownMIMETypeForExtension. Using the latter causes sites like youtube.com, which filter on the content-type of the dragged file, to break since the .type attribute would be empty.

(Unrelated: wouldn't it be nice if the header file for MIMETypeRegistry described the difference between the two and what a 'well known' MIME type is?)
Comment 1 Kinuko Yasuda 2012-07-18 22:00:03 PDT
Thanks for catching this!
Recalling the history, we intentionally use getWellKnownMIMETypeForExtension for files from FileSystem API (c.f. http://code.google.com/p/chromium/issues/detail?id=86108).  So probably a quick conservative fix would be to revert the merging part but have two slightly different getMIMEType code around.
Comment 2 Daniel Cheng 2012-07-19 21:37:44 PDT
Created attachment 153402 [details]
Patch

Rough patch that sketches out what we need.
Comment 3 Jian Li 2012-07-19 22:10:03 PDT
(In reply to comment #2)
> Created an attachment (id=153402) [details]
> Patch
> 
> Rough patch that sketches out what we need.

The patch looks OK in terms of just fixing the youtube upload bug. However, I am wondering what should be the right fix in order to take all scenarios into account.

We choose to use the well known MIME type for files from FileSystem. For all other types of files, do we also have the same concern and want to use the well known MIME type too? If not, I think we should let FileSystem caller pass the wellknow type as another argument to File constructor. Darin, could you please comment on this?
Comment 4 Daniel Cheng 2012-07-19 22:14:43 PDT
(In reply to comment #3)
> (In reply to comment #2)
> > Created an attachment (id=153402) [details] [details]
> > Patch
> > 
> > Rough patch that sketches out what we need.
> 
> The patch looks OK in terms of just fixing the youtube upload bug. However, I am wondering what should be the right fix in order to take all scenarios into account.
> 
> We choose to use the well known MIME type for files from FileSystem. For all other types of files, do we also have the same concern and want to use the well known MIME type too? If not, I think we should let FileSystem caller pass the wellknow type as another argument to File constructor. Darin, could you please comment on this?

Kinuko mentioned that the file input element should probably be covered as well. I am currently updating my patch to reflect this, as well as updating the platform/* implementations.

Kinuko is also working on this bug from the opposite direction--she is modifying the filesystem calls to use a special File constructor/argument.

I think it's slightly safer to limit File to 'well-known' MIME types by default and require an explicit call to allow WebKit to use the OS rather than the other way around, but I'm not sure if this is a strong enough argument to prefer my patch over Kinuko's.
Comment 5 Kinuko Yasuda 2012-07-19 22:38:24 PDT
Created attachment 153415 [details]
Patch (adds special ctor for FileSystem)
Comment 6 Kinuko Yasuda 2012-07-19 22:48:39 PDT
(In reply to comment #5)
> Created an attachment (id=153415) [details]
> Patch (adds special ctor for FileSystem)

The patch that does the other way around.
My take is: if we want to call getMIMEType by default and only handle FileSystem files specifically we should just handle add a special ctor foro them. Otherwise Daniel's way might work better.

(I'll dig to see if we can add a test for this patch)
Comment 7 Jian Li 2012-07-19 23:43:26 PDT
(In reply to comment #6)
> (In reply to comment #5)
> > Created an attachment (id=153415) [details] [details]
> > Patch (adds special ctor for FileSystem)
> 
> The patch that does the other way around.
> My take is: if we want to call getMIMEType by default and only handle FileSystem files specifically we should just handle add a special ctor foro them. Otherwise Daniel's way might work better.
> 
> (I'll dig to see if we can add a test for this patch)

Yes, we need to find out which case(s) we want to guard against.
Comment 8 Daniel Cheng 2012-07-20 13:40:19 PDT
Created attachment 153588 [details]
Special ctor for drag/file input
Comment 9 Daniel Cheng 2012-07-20 16:05:21 PDT
I talked to Darin and he said that the usual approach is to 'default to safe'... but my patch is definitely bigger than Kinuko's patch and touches more places, so it may be harder to merge into Chrome 21. I'm adding some security folks as well to see if they have any thoughts.
Comment 10 Daniel Cheng 2012-07-23 13:48:44 PDT
Created attachment 153856 [details]
Patch
Comment 11 Jian Li 2012-07-23 14:23:47 PDT
Comment on attachment 153856 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=153856&action=review

> Source/WebCore/fileapi/File.h:53
> +    static PassRefPtr<File> createWithRelativePathFromUserAction(const String& path, const String& relativePath);

The new naming scheme seems to be a bit confusing. How about we make enum public and force the caller to select the right creator to call for most cases, sth like:
    enum FileOrigin {
        // The file is selected as a result of an user action, such as ...
        FromUserAction,
        // The file is created ...
        FromSystem
    };

    static PassRefPtr<File> create(FileOrigin, const String& path)

    // Create a file with a name exposed to the author ...
    static PassRefPtr<File> createWithName(FileOrigin, const String& path, const String& name)

    // For deserialization.
    static PassRefPtr<File> create(const String& path, const KURL& srcURL, const String& type)

#if ENABLE(DIRECTORY_UPLOAD)
    // FromUserAction is assumed.
    static PassRefPtr<File> createWithRelativePath(const String& path, const String& relativePath)
#endif

#if ENABLE(FILE_SYSTEM)
    // FromSystem is assumed.
    static PassRefPtr<File> createForFileSystemFile(const String& name, const FileMetadata& metadata)
#endif
Comment 12 Daniel Cheng 2012-07-23 17:40:16 PDT
Created attachment 153918 [details]
Patch
Comment 13 Jian Li 2012-07-23 17:49:38 PDT
Comment on attachment 153918 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=153918&action=review

> Source/WebCore/fileapi/File.h:47
> +    static PassRefPtr<File> create(const String& path, ContentTypeLookupPolicy policy = WellKnownContentTypes)

nit: empty line before the enum definition and the creator definition .
Comment 14 Daniel Cheng 2012-07-24 11:18:00 PDT
Committed r123495: <http://trac.webkit.org/changeset/123495>
Comment 15 Lucas Forschler 2019-02-06 09:18:26 PST
Mass move bugs into the DOM component.