Bug 226172 - Implement form[method=dialog]
Summary: Implement form[method=dialog]
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Tim Nguyen (:ntim)
URL:
Keywords: InRadar
Depends on:
Blocks: dialog-element 227574
  Show dependency treegraph
 
Reported: 2021-05-24 03:11 PDT by Tim Nguyen (:ntim)
Modified: 2021-07-01 02:05 PDT (History)
9 users (show)

See Also:


Attachments
Patch (19.07 KB, patch)
2021-06-29 10:40 PDT, Tim Nguyen (:ntim)
no flags Details | Formatted Diff | Diff
Patch (15.07 KB, patch)
2021-06-29 11:55 PDT, Tim Nguyen (:ntim)
no flags Details | Formatted Diff | Diff
Patch (19.35 KB, patch)
2021-06-29 12:02 PDT, Tim Nguyen (:ntim)
no flags Details | Formatted Diff | Diff
Patch (19.33 KB, patch)
2021-06-29 12:05 PDT, Tim Nguyen (:ntim)
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (47.82 KB, patch)
2021-06-29 13:51 PDT, Tim Nguyen (:ntim)
no flags Details | Formatted Diff | Diff
Patch (49.21 KB, patch)
2021-06-29 14:02 PDT, Tim Nguyen (:ntim)
no flags Details | Formatted Diff | Diff
Patch (15.33 KB, patch)
2021-06-29 14:12 PDT, Tim Nguyen (:ntim)
no flags Details | Formatted Diff | Diff
Patch (49.50 KB, patch)
2021-06-29 14:16 PDT, Tim Nguyen (:ntim)
no flags Details | Formatted Diff | Diff
Patch (49.51 KB, patch)
2021-06-29 21:42 PDT, Tim Nguyen (:ntim)
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Comment 1 Radar WebKit Bug Importer 2021-05-31 03:12:15 PDT
<rdar://problem/78682625>
Comment 2 Tim Nguyen (:ntim) 2021-06-29 10:40:55 PDT
Created attachment 432499 [details]
Patch
Comment 3 Chris Dumez 2021-06-29 10:54:19 PDT
Comment on attachment 432499 [details]
Patch

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

> Source/WebCore/html/HTMLFormElement.cpp:421
> +    HTMLDialogElement* dialog = ancestorsOfType<HTMLDialogElement>(*this).first();

Ref dialog = ancestorsOfType<HTMLDialogElement>(*this).first();

would be safer.

> Source/WebCore/html/ImageInputType.cpp:220
> +    return String::number(m_clickLocation.x()) + "," + String::number(m_clickLocation.y());

You probably want:
return makeString(m_clickLocation.x(), ',', m_clickLocation.y());

for better perf.

You'll likely need to include <wtf/text/StringConcatenateNumbers.h>

> Source/WebCore/loader/FormSubmission.cpp:266
> +        frameRequest.resourceRequest().setHTTPBody(WTFMove(m_formData));

Assuming m_formData can be used later on, you probably should use std::exchange(), not WTFMove().

Also, is it really OK to consume m_formData? Cannot populateFrameLoadRequest() be called several times?

> Source/WebCore/loader/FormSubmission.h:48
> +    enum class Method : int { Get, Post, Dialog };

int -> uint8_t

> Source/WebCore/loader/FormSubmission.h:96
> +    FormData& data() const { return *m_formData; }

This looks dangerous, why is it safe?
Comment 4 Tim Nguyen (:ntim) 2021-06-29 11:22:58 PDT
(In reply to Chris Dumez from comment #3)
> Comment on attachment 432499 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=432499&action=review
> 
> > Source/WebCore/html/HTMLFormElement.cpp:421
> > +    HTMLDialogElement* dialog = ancestorsOfType<HTMLDialogElement>(*this).first();
> 
> Ref dialog = ancestorsOfType<HTMLDialogElement>(*this).first();
> 
> would be safer.

I've used RefPtr, since this can be null (when there are no ancestors), there's a check just below handling that case.

> > Source/WebCore/html/ImageInputType.cpp:220
> > +    return String::number(m_clickLocation.x()) + "," + String::number(m_clickLocation.y());
> 
> You probably want:
> return makeString(m_clickLocation.x(), ',', m_clickLocation.y());
> 
> for better perf.
> 
> You'll likely need to include <wtf/text/StringConcatenateNumbers.h>

Done, thanks.

> > Source/WebCore/loader/FormSubmission.h:48
> > +    enum class Method : int { Get, Post, Dialog };
> 
> int -> uint8_t
>

Done.

> > Source/WebCore/loader/FormSubmission.cpp:266
> > +        frameRequest.resourceRequest().setHTTPBody(WTFMove(m_formData));
> 
> Assuming m_formData can be used later on, you probably should use
> std::exchange(), not WTFMove().
> 
> Also, is it really OK to consume m_formData? Cannot
> populateFrameLoadRequest() be called several times?
>
>
> > Source/WebCore/loader/FormSubmission.h:96
> > +    FormData& data() const { return *m_formData; }
> 
> This looks dangerous, why is it safe?

I mostly changed these bits because I needed m_formData to be optional to construct, I thought of using std::optional<Ref<>>, but it's not much cleaner. Happy to take any suggestions.
Comment 5 Tim Nguyen (:ntim) 2021-06-29 11:55:50 PDT
Created attachment 432506 [details]
Patch
Comment 6 Chris Dumez 2021-06-29 12:02:39 PDT
Comment on attachment 432506 [details]
Patch

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

r=me with changes.

> Source/WebCore/html/HTMLFormElement.cpp:421
> +    RefPtr<HTMLDialogElement> dialog = ancestorsOfType<HTMLDialogElement>(*this).first();

RefPtr<HTMLDialogElement> -> RefPtr

> Source/WebCore/html/ImageInputType.cpp:220
> +    return String::number(m_clickLocation.x()) + "," + String::number(m_clickLocation.y());

As mentioned earlier, this is inefficient and should be using makeString(), NOT String::number().
Comment 7 Tim Nguyen (:ntim) 2021-06-29 12:02:55 PDT
Created attachment 432507 [details]
Patch
Comment 8 Chris Dumez 2021-06-29 12:04:42 PDT
Comment on attachment 432507 [details]
Patch

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

> Source/WebCore/html/HTMLFormElement.cpp:421
> +    RefPtr<HTMLDialogElement> dialog = ancestorsOfType<HTMLDialogElement>(*this).first();

nit: RefPtr<HTMLDialogElement> -> RefPtr (with C++17, the compiler should be able to deduce the type).
Comment 9 Tim Nguyen (:ntim) 2021-06-29 12:05:42 PDT
Created attachment 432509 [details]
Patch
Comment 10 Chris Dumez 2021-06-29 12:08:03 PDT
Comment on attachment 432509 [details]
Patch

Let's make sure the bots are happy before landing.
Comment 11 Chris Dumez 2021-06-29 12:57:56 PDT
Looks like imported/w3c/web-platform-tests/html/dom/reflection-forms.html needs rebaselining.
Comment 12 Darin Adler 2021-06-29 13:03:43 PDT
Comment on attachment 432509 [details]
Patch

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

> Source/WebCore/loader/FormSubmission.cpp:184
> +        String returnValue = submitter ? submitter->resultForDialogSubmit() : "";

emptyString() is more efficient than “” when passing a String. Null string is even more efficient if it’s acceptable.

> Source/WebCore/loader/FormSubmission.h:55
> +        static ASCIILiteral methodString(Method method)

When function body becomes multi-line like this we prefer to put the inline function definition outside the class definition, at the namespace level to preserve readability of the class definition.
Comment 13 Tim Nguyen (:ntim) 2021-06-29 13:51:46 PDT
Created attachment 432521 [details]
Patch
Comment 14 Chris Dumez 2021-06-29 13:53:21 PDT
Comment on attachment 432521 [details]
Patch

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

> Source/WebCore/loader/FormSubmission.cpp:184
> +        String returnValue = submitter ? submitter->resultForDialogSubmit() : "";

Darin recommended:
String returnValue = submitter ? submitter->resultForDialogSubmit() : emptyString();

As it is more efficient.

> Source/WebCore/loader/FormSubmission.h:55
> +        static ASCIILiteral methodString(Method method)

Ditto, please see Darin's feedback about moving this outside the class.
Comment 15 Tim Nguyen (:ntim) 2021-06-29 14:02:50 PDT
Created attachment 432524 [details]
Patch
Comment 16 Chris Dumez 2021-06-29 14:11:48 PDT
Comment on attachment 432524 [details]
Patch

Doesn't address Darin's feedback.
Comment 17 Tim Nguyen (:ntim) 2021-06-29 14:12:17 PDT
Created attachment 432529 [details]
Patch
Comment 18 Tim Nguyen (:ntim) 2021-06-29 14:16:11 PDT
Created attachment 432531 [details]
Patch
Comment 19 Chris Dumez 2021-06-29 19:28:55 PDT
Comment on attachment 432531 [details]
Patch

Looks like the baseline for imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-form-submission.html on iOS-wk2 is missing a blank line, causing a failure on iOS-EWS.
Comment 20 Tim Nguyen (:ntim) 2021-06-29 21:42:54 PDT
Created attachment 432566 [details]
Patch
Comment 21 EWS 2021-06-29 22:38:03 PDT
Committed r279401 (239266@main): <https://commits.webkit.org/239266@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 432566 [details].