Changeset 61546 in webkit


Ignore:
Timestamp:
Jun 21, 2010 9:36:40 AM (11 years ago)
Author:
Dimitri Glazkov
Message:

2010-06-03 Dimitri Glazkov <Dimitri Glazkov>

Reviewed by Darin Adler.

Plumb FormSubmission through to ScheduledFormSubmission.
https://bugs.webkit.org/show_bug.cgi?id=40137

No behavior change, covered by existing tests.

  • html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::prepareFormSubmission): Moved creation of action URL

instance here from FrameLoader::submit, because it makes more sense here,
also added a FIXME to investigate existing code later.

  • loader/FormSubmission.cpp: (WebCore::FormSubmission::FormSubmission): Changed action to be a KURL, not a String. (WebCore::FormSubmission::create): Ditto. (WebCore::FormSubmission::populateFrameLoadRequest): Added, moving the logic from

FrameLoader::submit closer to the data.

  • loader/FormSubmission.h: (WebCore::FormSubmission::action): Changed type to KURL. (WebCore::FormSubmission::clearTarget): Added. (WebCore::FormSubmission::referrer): Added. (WebCore::FormSubmission::setReferrer): Added. (WebCore::FormSubmission::origin): Added. (WebCore::FormSubmission::setOrigin): Added.
  • loader/FrameLoader.cpp: (WebCore::FrameLoader::submitForm): Cleaned up to make it more about decision-making,

not data manipulation.

  • loader/RedirectScheduler.cpp: (WebCore::ScheduledFormSubmission::ScheduledFormSubmission): Changed to accept FormSubmission as argument. (WebCore::ScheduledFormSubmission::fire): Changed to use FormSubmission. (WebCore::RedirectScheduler::scheduleFormSubmission): Removed assert that no longer makes sense,

changed to use FormSubmission.

  • loader/RedirectScheduler.h: Updated ScheduledFormSubmission decl to hold FormSubmission ref.
Location:
trunk/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r61545 r61546  
     12010-06-03  Dimitri Glazkov  <dglazkov@chromium.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        Plumb FormSubmission through to ScheduledFormSubmission.
     6        https://bugs.webkit.org/show_bug.cgi?id=40137
     7
     8        No behavior change, covered by existing tests.
     9
     10        * html/HTMLFormElement.cpp:
     11        (WebCore::HTMLFormElement::prepareFormSubmission): Moved creation of action URL
     12            instance here from FrameLoader::submit, because it makes more sense here,
     13            also added a FIXME to investigate existing code later.
     14        * loader/FormSubmission.cpp:
     15        (WebCore::FormSubmission::FormSubmission): Changed action to be a KURL, not a String.
     16        (WebCore::FormSubmission::create): Ditto.
     17        (WebCore::FormSubmission::populateFrameLoadRequest): Added, moving the logic from
     18            FrameLoader::submit closer to the data.
     19        * loader/FormSubmission.h:
     20        (WebCore::FormSubmission::action): Changed type to KURL.
     21        (WebCore::FormSubmission::clearTarget): Added.
     22        (WebCore::FormSubmission::referrer): Added.
     23        (WebCore::FormSubmission::setReferrer): Added.
     24        (WebCore::FormSubmission::origin): Added.
     25        (WebCore::FormSubmission::setOrigin): Added.
     26        * loader/FrameLoader.cpp:
     27        (WebCore::FrameLoader::submitForm): Cleaned up to make it more about decision-making,
     28            not data manipulation.
     29        * loader/RedirectScheduler.cpp:
     30        (WebCore::ScheduledFormSubmission::ScheduledFormSubmission): Changed to accept FormSubmission as argument.
     31        (WebCore::ScheduledFormSubmission::fire): Changed to use FormSubmission.
     32        (WebCore::RedirectScheduler::scheduleFormSubmission): Removed assert that no longer makes sense,
     33            changed to use FormSubmission.
     34        * loader/RedirectScheduler.h: Updated ScheduledFormSubmission decl to hold FormSubmission ref.
     35
    1362010-06-21  Satish Sampath  <satish@chromium.org>
    237
  • trunk/WebCore/html/HTMLFormElement.cpp

    r61511 r61546  
    253253    RefPtr<FormData> formData;
    254254    String boundary;
     255    // FIXME: Figure out whether m_url.isNull check is necessary.
     256    KURL actionURL = document()->completeURL(m_url.isNull() ? "" : m_url);
    255257
    256258    if (m_formDataBuilder.isMultiPartForm()) {
     
    261263        if (m_formDataBuilder.isPostMethod() && isMailtoForm()) {
    262264            // Convert the form data into a string that we put into the URL.
    263             KURL url = document()->completeURL(m_url);
    264             appendMailtoPostFormDataToURL(url, *formData, m_formDataBuilder.encodingType());
    265             m_url = url.string();
     265            appendMailtoPostFormDataToURL(actionURL, *formData, m_formDataBuilder.encodingType());
     266            // FIXME: Why is setting m_url necessary here? This seems wrong if mail form is submitted multiple times?
     267            m_url = actionURL.string();
    266268
    267269            formData = FormData::create();
     
    271273    formData->setIdentifier(generateFormDataIdentifier());
    272274    FormSubmission::Method method = m_formDataBuilder.isPostMethod() ? FormSubmission::PostMethod : FormSubmission::GetMethod;
    273     return FormSubmission::create(method, m_url, m_target, m_formDataBuilder.encodingType(), FormState::create(this, formValues, document()->frame(), trigger), formData.release(), boundary, lockHistory, event);
     275    String targetOrBaseTarget = m_target.isEmpty() ? document()->baseTarget() : m_target;
     276    return FormSubmission::create(method, actionURL, targetOrBaseTarget, m_formDataBuilder.encodingType(), FormState::create(this, formValues, document()->frame(), trigger), formData.release(), boundary, lockHistory, event);
    274277}
    275278
  • trunk/WebCore/loader/FormSubmission.cpp

    r61511 r61546  
    3636#include "FormState.h"
    3737#include "Frame.h"
     38#include "FrameLoadRequest.h"
     39#include "FrameLoader.h"
    3840#include "HTMLFormElement.h"
    3941#include <wtf/PassRefPtr.h>
     
    4143namespace WebCore {
    4244
    43 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)
     45FormSubmission::FormSubmission(Method method, const KURL& action, const String& target, const String& contentType, PassRefPtr<FormState> state, PassRefPtr<FormData> data, const String& boundary, bool lockHistory, PassRefPtr<Event> event)
    4446    : m_method(method)
    4547    , m_action(action)
     
    5456}
    5557
    56 
    57 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)
     58PassRefPtr<FormSubmission> FormSubmission::create(Method method, const KURL& action, const String& target, const String& contentType, PassRefPtr<FormState> state, PassRefPtr<FormData> data, const String& boundary, bool lockHistory, PassRefPtr<Event> event)
    5859{
    5960    return adoptRef(new FormSubmission(method, action, target, contentType, state, data, boundary, lockHistory, event));
    6061}
    6162
     63void FormSubmission::populateFrameLoadRequest(FrameLoadRequest& frameRequest)
     64{
     65    if (!m_target.isEmpty())
     66        frameRequest.setFrameName(m_target);
     67
     68    if (!m_referrer.isEmpty())
     69        frameRequest.resourceRequest().setHTTPReferrer(m_referrer);
     70
     71    if (m_method == FormSubmission::GetMethod)
     72        m_action.setQuery(m_formData->flattenToString());
     73    else {
     74        frameRequest.resourceRequest().setHTTPMethod("POST");
     75        frameRequest.resourceRequest().setHTTPBody(m_formData);
     76
     77        // construct some user headers if necessary
     78        if (m_contentType.isNull() || m_contentType == "application/x-www-form-urlencoded")
     79            frameRequest.resourceRequest().setHTTPContentType(m_contentType);
     80        else // contentType must be "multipart/form-data"
     81            frameRequest.resourceRequest().setHTTPContentType(m_contentType + "; boundary=" + m_boundary);
     82    }
     83
     84    frameRequest.resourceRequest().setURL(m_action);
     85    FrameLoader::addHTTPOriginIfNeeded(frameRequest.resourceRequest(), m_origin);
    6286}
     87
     88}
  • trunk/WebCore/loader/FormSubmission.h

    r61511 r61546  
    3232#define FormSubmission_h
    3333
    34 #include "PlatformString.h"
    35 #include <wtf/Forward.h>
    36 #include <wtf/RefCounted.h>
     34#include "KURL.h"
    3735
    3836namespace WebCore {
     
    4139class FormData;
    4240class FormState;
     41class FrameLoadRequest;
    4342
    4443class FormSubmission : public RefCounted<FormSubmission> {
     
    4948    };
    5049
    51     static PassRefPtr<FormSubmission> create(Method, const String& action, const String& target, const String& contentType, PassRefPtr<FormState>, PassRefPtr<FormData>, const String& boundary, bool lockHistory, PassRefPtr<Event>);
     50    static PassRefPtr<FormSubmission> create(Method, const KURL& action, const String& target, const String& contentType, PassRefPtr<FormState>, PassRefPtr<FormData>, const String& boundary, bool lockHistory, PassRefPtr<Event>);
     51
     52    void populateFrameLoadRequest(FrameLoadRequest&);
    5253
    5354    Method method() const { return m_method; }
    54     String action() const { return m_action; }
     55    const KURL& action() const { return m_action; }
    5556    String target() const { return m_target; }
     57    void clearTarget() { m_target = String(); }
    5658    String contentType() const { return m_contentType; }
    5759    FormState* state() const { return m_formState.get(); }
     
    6163    Event* event() const { return m_event.get(); }
    6264
     65    const String& referrer() const { return m_referrer; }
     66    void setReferrer(const String& referrer) { m_referrer = referrer; }
     67    const String& origin() const { return m_origin; }
     68    void setOrigin(const String& origin) { m_origin = origin; }
     69
    6370private:
    64     FormSubmission(Method, const String& action, const String& target, const String& contentType, PassRefPtr<FormState>, PassRefPtr<FormData>, const String& boundary, bool lockHistory, PassRefPtr<Event>);
     71    FormSubmission(Method, const KURL& action, const String& target, const String& contentType, PassRefPtr<FormState>, PassRefPtr<FormData>, const String& boundary, bool lockHistory, PassRefPtr<Event>);
    6572
    6673    Method m_method;
    67     String m_action;
     74    KURL m_action;
    6875    String m_target;
    6976    String m_contentType;
     
    7380    bool m_lockHistory;
    7481    RefPtr<Event> m_event;
     82    String m_referrer;
     83    String m_origin;
    7584};
    7685
  • trunk/WebCore/loader/FrameLoader.cpp

    r61511 r61546  
    464464void FrameLoader::submitForm(PassRefPtr<FormSubmission> submission)
    465465{
    466     // FIXME: Plumb this further in.
    467     const char* action = submission->method() == FormSubmission::PostMethod ? "POST" : "GET";
    468     RefPtr<FormData> formData = submission->data();
    469     RefPtr<FormState> formState = submission->state();
    470     String url = submission->action();
    471     String target = submission->target();
    472     String boundary = submission->boundary();
    473     String contentType = submission->contentType();
    474     bool lockHistory = submission->lockHistory();
    475     RefPtr<Event> event = submission->event();
    476 
    477     ASSERT(action);
    478     ASSERT(strcmp(action, "GET") == 0 || strcmp(action, "POST") == 0);
    479     ASSERT(formData);
    480     ASSERT(formState);
    481     ASSERT(formState->sourceFrame() == m_frame);
     466    ASSERT(submission->method() == FormSubmission::PostMethod || submission->method() == FormSubmission::GetMethod);
     467
     468    // FIXME: Find a good spot for these.
     469    ASSERT(submission->data());
     470    ASSERT(submission->state());
     471    ASSERT(submission->state()->sourceFrame() == m_frame);
    482472   
    483473    if (!m_frame->page())
    484474        return;
    485475   
    486     KURL u = completeURL(url.isNull() ? "" : url);
    487     if (u.isEmpty())
     476    if (submission->action().isEmpty())
    488477        return;
    489478
     
    491480        return;
    492481
    493     if (protocolIsJavaScript(u)) {
     482    if (protocolIsJavaScript(submission->action())) {
    494483        m_isExecutingJavaScriptFormAction = true;
    495         m_frame->script()->executeIfJavaScriptURL(u, false, DoNotReplaceDocumentIfJavaScriptURL);
     484        m_frame->script()->executeIfJavaScriptURL(submission->action(), false, DoNotReplaceDocumentIfJavaScriptURL);
    496485        m_isExecutingJavaScriptFormAction = false;
    497486        return;
    498487    }
    499488
    500     FrameLoadRequest frameRequest;
    501 
    502     String targetOrBaseTarget = target.isEmpty() ? m_frame->document()->baseTarget() : target;
    503     Frame* targetFrame = m_frame->tree()->find(targetOrBaseTarget);
     489    Frame* targetFrame = m_frame->tree()->find(submission->target());
    504490    if (!shouldAllowNavigation(targetFrame))
    505491        return;
     
    509495
    510496        targetFrame = m_frame;
    511         frameRequest.setFrameName(targetOrBaseTarget);
    512     }
     497    } else
     498        submission->clearTarget();
     499
    513500    if (!targetFrame->page())
    514501        return;
     
    527514
    528515    if (m_frame->tree()->isDescendantOf(targetFrame)) {
    529         if (m_submittedFormURL == u)
     516        if (m_submittedFormURL == submission->action())
    530517            return;
    531         m_submittedFormURL = u;
    532     }
    533 
    534     formData->generateFiles(m_frame->document());
    535    
    536     if (!m_outgoingReferrer.isEmpty())
    537         frameRequest.resourceRequest().setHTTPReferrer(m_outgoingReferrer);
    538 
    539     if (strcmp(action, "GET") == 0)
    540         u.setQuery(formData->flattenToString());
    541     else {
    542         frameRequest.resourceRequest().setHTTPMethod("POST");
    543         frameRequest.resourceRequest().setHTTPBody(formData);
    544 
    545         // construct some user headers if necessary
    546         if (contentType.isNull() || contentType == "application/x-www-form-urlencoded")
    547             frameRequest.resourceRequest().setHTTPContentType(contentType);
    548         else // contentType must be "multipart/form-data"
    549             frameRequest.resourceRequest().setHTTPContentType(contentType + "; boundary=" + boundary);
    550     }
    551 
    552     frameRequest.resourceRequest().setURL(u);
    553     addHTTPOriginIfNeeded(frameRequest.resourceRequest(), outgoingOrigin());
    554 
    555     targetFrame->redirectScheduler()->scheduleFormSubmission(frameRequest, lockHistory, event, formState);
     518        m_submittedFormURL = submission->action();
     519    }
     520
     521    submission->data()->generateFiles(m_frame->document());
     522    submission->setReferrer(m_outgoingReferrer);
     523    submission->setOrigin(outgoingOrigin());
     524
     525    targetFrame->redirectScheduler()->scheduleFormSubmission(submission);
    556526}
    557527
  • trunk/WebCore/loader/RedirectScheduler.cpp

    r59462 r61546  
    3737#include "Event.h"
    3838#include "FormState.h"
     39#include "FormSubmission.h"
    3940#include "Frame.h"
    4041#include "FrameLoadRequest.h"
     
    171172class ScheduledFormSubmission : public ScheduledNavigation {
    172173public:
    173     ScheduledFormSubmission(const FrameLoadRequest& frameRequest, bool lockHistory, bool lockBackForwardList, PassRefPtr<Event> event, PassRefPtr<FormState> formState, bool duringLoad)
    174         : ScheduledNavigation(0, lockHistory, lockBackForwardList, duringLoad, true)
    175         , m_frameRequest(frameRequest)
    176         , m_event(event)
    177         , m_formState(formState)
     174    ScheduledFormSubmission(PassRefPtr<FormSubmission> submission, bool lockBackForwardList, bool duringLoad)
     175        : ScheduledNavigation(0, submission->lockHistory(), lockBackForwardList, duringLoad, true)
     176        , m_submission(submission)
    178177        , m_wasProcessingUserGesture(UserGestureIndicator::processingUserGesture())
    179178    {
    180         ASSERT(!frameRequest.isEmpty());
    181         ASSERT(m_formState);
     179        ASSERT(m_submission->state());
    182180    }
    183181
     
    190188        // selecting a target, in case conditions have changed. Other code paths avoid this by targeting
    191189        // without leaving a time window. If we fail the check just silently drop the form submission.
    192         if (!m_formState->sourceFrame()->loader()->shouldAllowNavigation(frame))
     190        if (!m_submission->state()->sourceFrame()->loader()->shouldAllowNavigation(frame))
    193191            return;
    194         frame->loader()->loadFrameRequest(m_frameRequest, lockHistory(), lockBackForwardList(), m_event, m_formState, SendReferrer);
     192        FrameLoadRequest frameRequest;
     193        m_submission->populateFrameLoadRequest(frameRequest);
     194        frame->loader()->loadFrameRequest(frameRequest, lockHistory(), lockBackForwardList(), m_submission->event(), m_submission->state(), SendReferrer);
    195195    }
    196196
     
    201201
    202202private:
    203     const FrameLoadRequest m_frameRequest;
    204     const RefPtr<Event> m_event;
    205     const RefPtr<FormState> m_formState;
     203    RefPtr<FormSubmission> m_submission;
    206204    bool m_wasProcessingUserGesture;
    207205};
     
    287285}
    288286
    289 void RedirectScheduler::scheduleFormSubmission(const FrameLoadRequest& frameRequest,
    290     bool lockHistory, PassRefPtr<Event> event, PassRefPtr<FormState> formState)
     287void RedirectScheduler::scheduleFormSubmission(PassRefPtr<FormSubmission> submission)
    291288{
    292289    ASSERT(m_frame->page());
    293     ASSERT(!frameRequest.isEmpty());
    294290
    295291    // FIXME: Do we need special handling for form submissions where the URL is the same
     
    304300    // See https://bugs.webkit.org/show_bug.cgi?id=32383 for the original motivation for this.
    305301
    306     bool lockBackForwardList = mustLockBackForwardList(m_frame) || (formState->formSubmissionTrigger() == SubmittedByJavaScript && m_frame->tree()->parent());
    307 
    308     schedule(new ScheduledFormSubmission(frameRequest, lockHistory, lockBackForwardList, event, formState, duringLoad));
     302    bool lockBackForwardList = mustLockBackForwardList(m_frame) || (submission->state()->formSubmissionTrigger() == SubmittedByJavaScript && m_frame->tree()->parent());
     303
     304    schedule(new ScheduledFormSubmission(submission, lockBackForwardList, duringLoad));
    309305}
    310306
  • trunk/WebCore/loader/RedirectScheduler.h

    r56875 r61546  
    4141
    4242class FormState;
     43class FormSubmission;
    4344class Frame;
    4445class String;
     
    5758    void scheduleRedirect(double delay, const String& url);
    5859    void scheduleLocationChange(const String& url, const String& referrer, bool lockHistory = true, bool lockBackForwardList = true, bool userGesture = false);
    59     void scheduleFormSubmission(const FrameLoadRequest&, bool lockHistory, PassRefPtr<Event>, PassRefPtr<FormState>);
     60    void scheduleFormSubmission(PassRefPtr<FormSubmission>);
    6061    void scheduleRefresh(bool userGesture = false);
    6162    void scheduleHistoryNavigation(int steps);
Note: See TracChangeset for help on using the changeset viewer.