Bug 40084 - Introduce FormSubmission, the structure representing a form submission.
Summary: Introduce FormSubmission, the structure representing a form submission.
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Other OS X 10.5
: P2 Normal
Assignee: Dimitri Glazkov (Google)
URL:
Keywords:
Depends on: 39430
Blocks: 40137
  Show dependency treegraph
 
Reported: 2010-06-02 14:36 PDT by Dimitri Glazkov (Google)
Modified: 2010-06-20 14:00 PDT (History)
6 users (show)

See Also:


Attachments
Patch (22.96 KB, patch)
2010-06-02 14:42 PDT, Dimitri Glazkov (Google)
no flags Details | Formatted Diff | Diff
Patch (21.72 KB, patch)
2010-06-14 15:54 PDT, Dimitri Glazkov (Google)
no flags Details | Formatted Diff | Diff
Patch (23.28 KB, patch)
2010-06-14 15:57 PDT, Dimitri Glazkov (Google)
no flags Details | Formatted Diff | Diff
Patch (23.48 KB, patch)
2010-06-14 16:09 PDT, Dimitri Glazkov (Google)
no flags Details | Formatted Diff | Diff
Actually working patch (23.59 KB, patch)
2010-06-15 14:51 PDT, Dimitri Glazkov (Google)
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dimitri Glazkov (Google) 2010-06-02 14:36:11 PDT
Introduce FormSubmission, the structure representing a form submission.
Comment 1 Dimitri Glazkov (Google) 2010-06-02 14:42:41 PDT
Created attachment 57705 [details]
Patch
Comment 2 Adam Barth 2010-06-03 00:25:15 PDT
Did you mean to mark this for review?
Comment 3 Dimitri Glazkov (Google) 2010-06-03 07:22:49 PDT
(In reply to comment #2)
> Did you mean to mark this for review?

Not yet, it depends on bug 39430 to land first.
Comment 4 Dimitri Glazkov (Google) 2010-06-14 15:54:45 PDT
Created attachment 58717 [details]
Patch
Comment 5 Dimitri Glazkov (Google) 2010-06-14 15:56:03 PDT
Comment on attachment 57705 [details]
Patch

Whoops, webkit-patch upload for some reason didn't like the ChangeLog.
Comment 6 Dimitri Glazkov (Google) 2010-06-14 15:57:53 PDT
Created attachment 58721 [details]
Patch
Comment 7 Early Warning System Bot 2010-06-14 16:02:50 PDT
Attachment 58717 [details] did not build on qt:
Build output: http://webkit-commit-queue.appspot.com/results/3281139
Comment 8 Dimitri Glazkov (Google) 2010-06-14 16:06:08 PDT
Comment on attachment 58721 [details]
Patch

Argh. More merge untangling.
Comment 9 Dimitri Glazkov (Google) 2010-06-14 16:09:47 PDT
Created attachment 58723 [details]
Patch
Comment 10 WebKit Review Bot 2010-06-14 17:59:07 PDT
Attachment 58723 [details] did not build on chromium:
Build output: http://webkit-commit-queue.appspot.com/results/3288158
Comment 11 Dimitri Glazkov (Google) 2010-06-14 19:03:02 PDT
Comment on attachment 58723 [details]
Patch

:( I'll figure out what's wrong.
Comment 12 Dimitri Glazkov (Google) 2010-06-15 14:51:50 PDT
Created attachment 58823 [details]
Actually working patch
Comment 13 Dimitri Glazkov (Google) 2010-06-15 14:53:40 PDT
This now works and doesn't regress anything. Chromium fails are because the EWS doesn't seem to refresh the project after applying the patch. Please take a look.
Comment 14 Darin Adler 2010-06-15 15:31:35 PDT
Comment on attachment 58823 [details]
Actually working patch

>      for (unsigned i = 0; i < m_associatedElements.size(); ++i) {
>          HTMLFormControlElement* control = m_associatedElements[i];
>          if (!control->disabled())
>              control->appendFormData(*domFormData, m_formDataBuilder.isMultiPartForm());
> +        if (control->hasLocalName(inputTag)) {
> +            HTMLInputElement* input = static_cast<HTMLInputElement*>(control);
> +            if (input->isTextField()) {
> +                formValues.append(pair<String, String>(input->name(), input->value()));
> +                if (input->isSearchField())
> +                    input->addSearchResult();
> +            }
> +        }
>      }

This redundancy between form data and form values is so bizarre. I can't believe we have it. And for the form data we have a nice abstraction and virtual functions, but for the form values, none at all! We need to fix that.

And the call to addSearchResult here is so random too! Anyway, not your fault, but nutty.

> +    FormSubmission::Method method = m_formDataBuilder.isPostMethod() ? FormSubmission::PostMethod : FormSubmission::GetMethod;
> +    return FormSubmission::create(method, m_url, m_target, m_formDataBuilder.encodingType(), FormState::create(this, formValues, document()->frame(), trigger), formData.release(), boundary, lockHistory, event);

Even I, famous for long lines, would be tempted to break this into multiple lines. Maybe put the FormState into a local variable.

It occurs to me that FormSubmission, FormData, and FormState are all too similar. Too bad, but might be worth thinking about. Do we need all three? Are they all easy to explain?

> +FormSubmission::FormSubmission(Method method, const String& action, const String& target, const String& contentType, PassRefPtr<FormState> state, PassRefPtr<FormData> data, const String& boundary, bool lockHistory, PassRefPtr<Event> event)

I suggest marking this inline since it's called only in one place.

> +{
> +}
> +
> +
> +PassRefPtr<FormSubmission> FormSubmission::create(Method method, const String& action, const String& target, const String& contentType, PassRefPtr<FormState> state, PassRefPtr<FormData> data, const String& boundary, bool lockHistory, PassRefPtr<Event> event)

Extra blank line here.

> +class FormSubmission : public RefCounted<FormSubmission> {

Do we really need a reference counted object for this, and a class? Why not just use a struct, and pass const FormSubmission& to the function that takes it? I'm not sure that a class adds enough value here.

> +    enum Method {
> +        GetMethod,
> +        PostMethod
> +    };

I’d put this on a single line instead of breaking it across multiple lines.

> +    String action() const { return m_action; }
> +    String target() const { return m_target; }
> +    String contentType() const { return m_contentType; }

> +    String boundary() const { return m_boundary; }

More efficient to return const String& from functions like these, and very little downside to doing so.

r=me
Comment 15 Dimitri Glazkov (Google) 2010-06-15 15:52:39 PDT
(In reply to comment #14)
> (From update of attachment 58823 [details])
> >      for (unsigned i = 0; i < m_associatedElements.size(); ++i) {
> >          HTMLFormControlElement* control = m_associatedElements[i];
> >          if (!control->disabled())
> >              control->appendFormData(*domFormData, m_formDataBuilder.isMultiPartForm());
> > +        if (control->hasLocalName(inputTag)) {
> > +            HTMLInputElement* input = static_cast<HTMLInputElement*>(control);
> > +            if (input->isTextField()) {
> > +                formValues.append(pair<String, String>(input->name(), input->value()));
> > +                if (input->isSearchField())
> > +                    input->addSearchResult();
> > +            }
> > +        }
> >      }
> 
> This redundancy between form data and form values is so bizarre. I can't believe we have it. And for the form data we have a nice abstraction and virtual functions, but for the form values, none at all! We need to fix that.

I agree. That's my goal.

> And the call to addSearchResult here is so random too! Anyway, not your fault, but nutty.
> 
> > +    FormSubmission::Method method = m_formDataBuilder.isPostMethod() ? FormSubmission::PostMethod : FormSubmission::GetMethod;
> > +    return FormSubmission::create(method, m_url, m_target, m_formDataBuilder.encodingType(), FormState::create(this, formValues, document()->frame(), trigger), formData.release(), boundary, lockHistory, event);
> 
> Even I, famous for long lines, would be tempted to break this into multiple lines. Maybe put the FormState into a local variable.

Sounds good.

> 
> It occurs to me that FormSubmission, FormData, and FormState are all too similar. Too bad, but might be worth thinking about. Do we need all three? Are they all easy to explain?

Out of the three, I want FormState to go away. It already name-conflicts with a completely separate concept of restoring form state (see Document::formElementsWithState, et al.).

> 
> > +FormSubmission::FormSubmission(Method method, const String& action, const String& target, const String& contentType, PassRefPtr<FormState> state, PassRefPtr<FormData> data, const String& boundary, bool lockHistory, PassRefPtr<Event> event)
> 
> I suggest marking this inline since it's called only in one place.

ok.

> > +{
> > +}
> > +
> > +
> > +PassRefPtr<FormSubmission> FormSubmission::create(Method method, const String& action, const String& target, const String& contentType, PassRefPtr<FormState> state, PassRefPtr<FormData> data, const String& boundary, bool lockHistory, PassRefPtr<Event> event)
> 
> Extra blank line here.
> 
> > +class FormSubmission : public RefCounted<FormSubmission> {
> 
> Do we really need a reference counted object for this, and a class? Why not just use a struct, and pass const FormSubmission& to the function that takes it? I'm not sure that a class adds enough value here.

I've been back and forth on it. So far, I don't see the need for it to be ref-counted -- the ownership flows forward-only, so yes, simpler the better.

> > +    enum Method {
> > +        GetMethod,
> > +        PostMethod
> > +    };
> 
> I’d put this on a single line instead of breaking it across multiple lines.

ok.

> 
> > +    String action() const { return m_action; }
> > +    String target() const { return m_target; }
> > +    String contentType() const { return m_contentType; }
> 
> > +    String boundary() const { return m_boundary; }
> 
> More efficient to return const String& from functions like these, and very little downside to doing so.

ok.

> 
> r=me

Would it be ok for me to land this as-is and address the issues in a separate patch? I have two patches sitting on top of this and my last round of merge resolution was a b*tch :)
Comment 16 Darin Adler 2010-06-16 10:12:54 PDT
(In reply to comment #15)
> Would it be ok for me to land this as-is and address the issues in a separate patch? I have two patches sitting on top of this and my last round of merge resolution was a b*tch :)

Yes, it’s OK with me. If it wasn’t OK I would have said review-.
Comment 17 Dimitri Glazkov (Google) 2010-06-20 14:00:49 PDT
Committed r61511: <http://trac.webkit.org/changeset/61511>