Bug 213825 - Allow the File object to be created with a replacement file
Summary: Allow the File object to be created with a replacement file
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Images (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Said Abou-Hallawa
URL:
Keywords: InRadar
Depends on:
Blocks: 213347
  Show dependency treegraph
 
Reported: 2020-06-30 18:46 PDT by Said Abou-Hallawa
Modified: 2020-07-01 20:10 PDT (History)
12 users (show)

See Also:


Attachments
Patch (34.32 KB, patch)
2020-06-30 19:53 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (37.44 KB, patch)
2020-07-01 13:21 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (37.84 KB, patch)
2020-07-01 13:44 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (37.80 KB, patch)
2020-07-01 14:58 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Said Abou-Hallawa 2020-06-30 18:46:55 PDT
This work is towards bug 213347.

The goal is to enable the UIProcess to pass an original path and an optional replacement path to the WebProcess, e.g. a HIEF image and its transcoded PNG image. The Web process will create the File object with the replacement file but will register the Blob in the NetworkProcess with both: the original file and the replacement file. The Blob in the NetworkProcess will delete the replacement file when it is destroyed.

It is important to create the File object with the replacement file because it needs to get the size and the bytes of the replacement file not the original files.
Comment 1 Said Abou-Hallawa 2020-06-30 19:53:55 PDT
Created attachment 403259 [details]
Patch
Comment 2 Darin Adler 2020-07-01 10:04:11 PDT
Comment on attachment 403259 [details]
Patch

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

"objet" -> "object"

> Source/WebCore/ChangeLog:3
> +        Allow the File objet to be created with a replacement file

type: "objet"

Am I correct that this adds unused code, to be used later? Is that why there is no test coverage?

> Source/WebCore/ChangeLog:14
> +        t is important to create the File object with the replacement file because

typo: "t"

> Source/WebCore/fileapi/File.cpp:59
> +    return adoptRef(*new File(WTFMove(internalURL), WTFMove(type), String { effectivePath }, WTFMove(name)));

Why not WTFMove(effectivePath)?

> Source/WebCore/fileapi/File.h:45
> -    WEBCORE_EXPORT static Ref<File> create(const String& path, const String& nameOverride = { });
> +    WEBCORE_EXPORT static Ref<File> create(const String& path, const String& replacementPath = { }, const String& nameOverride = { });

With this change, we have to inspect every File::create call site, because anyone specifying a nameOverride might now be specifying a replacementPath instead by accident. I presume you did that. This is the kind of refactoring that is risky since it silently changes the behavior of existing code.

> Source/WebCore/platform/FileChooser.h:54
> -    FileChooserFileInfo(const String& path, const String& displayName = String())
> +    FileChooserFileInfo(const String& path, const String& replacementPath = { }, const String& displayName = { })
>          : path(path)
> +        , replacementPath(replacementPath)
>          , displayName(displayName)
>      {
>      }

Why do we need a constructor? Can’t we delete it and just use aggregate initialization instead?
Comment 3 Said Abou-Hallawa 2020-07-01 13:20:27 PDT
Comment on attachment 403259 [details]
Patch

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

>> Source/WebCore/ChangeLog:3
>> +        Allow the File objet to be created with a replacement file
> 
> type: "objet"
> 
> Am I correct that this adds unused code, to be used later? Is that why there is no test coverage?

The typo is fixed. You are right this patch is work towards webkit.org/b/213347. I added this to the ChangeLog.

>> Source/WebCore/ChangeLog:14
>> +        t is important to create the File object with the replacement file because
> 
> typo: "t"

Fixed.

>> Source/WebCore/fileapi/File.cpp:59
>> +    return adoptRef(*new File(WTFMove(internalURL), WTFMove(type), String { effectivePath }, WTFMove(name)));
> 
> Why not WTFMove(effectivePath)?

Fixed.

>> Source/WebCore/fileapi/File.h:45
>> +    WEBCORE_EXPORT static Ref<File> create(const String& path, const String& replacementPath = { }, const String& nameOverride = { });
> 
> With this change, we have to inspect every File::create call site, because anyone specifying a nameOverride might now be specifying a replacementPath instead by accident. I presume you did that. This is the kind of refactoring that is risky since it silently changes the behavior of existing code.

Yes I did that by removing the default values for both replacementPath and nameOverride from the create() method. Then I fixed all compilation errors. And finally I put back the default values and removed the unnecessary initializations in the caller side. This way I made sure nameOverride was never passed as the second argument.

>> Source/WebCore/platform/FileChooser.h:54
>>      }
> 
> Why do we need a constructor? Can’t we delete it and just use aggregate initialization instead?

Fixed. But I had to pass three values always in the aggregate initialization because I was getting this error in the caller side:

error: missing field 'replacementPath' initializer [-Werror,-Wmissing-field-initializers]

I am not sure whether -Wmissing-field-initializers is enabled by default or this is WebKit Xcode project settings.
Comment 4 Said Abou-Hallawa 2020-07-01 13:21:36 PDT
Created attachment 403314 [details]
Patch
Comment 5 Said Abou-Hallawa 2020-07-01 13:44:00 PDT
Created attachment 403316 [details]
Patch
Comment 6 Darin Adler 2020-07-01 14:20:42 PDT
Comment on attachment 403316 [details]
Patch

Many of the places we have nullString() here we could alternatively have { }.
Comment 7 Said Abou-Hallawa 2020-07-01 14:58:04 PDT
Created attachment 403322 [details]
Patch
Comment 8 EWS 2020-07-01 20:09:01 PDT
Committed r263830: <https://trac.webkit.org/changeset/263830>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 403322 [details].
Comment 9 Radar WebKit Bug Importer 2020-07-01 20:10:15 PDT
<rdar://problem/65015820>