Home | History | Annotate | Download | only in loader
      1 /*
      2  * Copyright (C) 2010 Google Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions are
      6  * met:
      7  *
      8  *     * Redistributions of source code must retain the above copyright
      9  * notice, this list of conditions and the following disclaimer.
     10  *     * Redistributions in binary form must reproduce the above
     11  * copyright notice, this list of conditions and the following disclaimer
     12  * in the documentation and/or other materials provided with the
     13  * distribution.
     14  *     * Neither the name of Google Inc. nor the names of its
     15  * contributors may be used to endorse or promote products derived from
     16  * this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #ifndef FormSubmission_h
     32 #define FormSubmission_h
     33 
     34 #include "core/loader/FormState.h"
     35 #include "platform/heap/Handle.h"
     36 #include "platform/weborigin/KURL.h"
     37 #include "platform/weborigin/Referrer.h"
     38 
     39 namespace blink {
     40 
     41 class Event;
     42 class FormData;
     43 struct FrameLoadRequest;
     44 class HTMLFormElement;
     45 
     46 class FormSubmission : public RefCountedWillBeGarbageCollectedFinalized<FormSubmission> {
     47 public:
     48     enum Method { GetMethod, PostMethod, DialogMethod };
     49 
     50     class Attributes {
     51         WTF_MAKE_NONCOPYABLE(Attributes);
     52     public:
     53         Attributes()
     54             : m_method(GetMethod)
     55             , m_isMultiPartForm(false)
     56             , m_encodingType("application/x-www-form-urlencoded", AtomicString::ConstructFromLiteral)
     57         {
     58         }
     59 
     60         Method method() const { return m_method; }
     61         static Method parseMethodType(const String&);
     62         void updateMethodType(const String&);
     63         static String methodString(Method);
     64 
     65         const String& action() const { return m_action; }
     66         void parseAction(const String&);
     67 
     68         const AtomicString& target() const { return m_target; }
     69         void setTarget(const AtomicString& target) { m_target = target; }
     70 
     71         const AtomicString& encodingType() const { return m_encodingType; }
     72         static AtomicString parseEncodingType(const String&);
     73         void updateEncodingType(const String&);
     74         bool isMultiPartForm() const { return m_isMultiPartForm; }
     75 
     76         const String& acceptCharset() const { return m_acceptCharset; }
     77         void setAcceptCharset(const String& value) { m_acceptCharset = value; }
     78 
     79         void copyFrom(const Attributes&);
     80 
     81     private:
     82         Method m_method;
     83         bool m_isMultiPartForm;
     84 
     85         String m_action;
     86         AtomicString m_target;
     87         AtomicString m_encodingType;
     88         String m_acceptCharset;
     89     };
     90 
     91     static PassRefPtrWillBeRawPtr<FormSubmission> create(HTMLFormElement*, const Attributes&, PassRefPtrWillBeRawPtr<Event>, FormSubmissionTrigger);
     92     void trace(Visitor*);
     93 
     94     void populateFrameLoadRequest(FrameLoadRequest&);
     95 
     96     KURL requestURL() const;
     97 
     98     Method method() const { return m_method; }
     99     const KURL& action() const { return m_action; }
    100     const AtomicString& target() const { return m_target; }
    101     void clearTarget() { m_target = nullAtom; }
    102     FormState* state() const { return m_formState.get(); }
    103     FormData* data() const { return m_formData.get(); }
    104     Event* event() const { return m_event.get(); }
    105 
    106     void setReferrer(const Referrer& referrer) { m_referrer = referrer; }
    107     void setOrigin(const String& origin) { m_origin = origin; }
    108 
    109     const String& result() const { return m_result; }
    110 
    111 private:
    112     FormSubmission(Method, const KURL& action, const AtomicString& target, const AtomicString& contentType, PassRefPtrWillBeRawPtr<FormState>, PassRefPtr<FormData>, const String& boundary, PassRefPtrWillBeRawPtr<Event>);
    113     // FormSubmission for DialogMethod
    114     FormSubmission(const String& result);
    115 
    116     // FIXME: Hold an instance of Attributes instead of individual members.
    117     Method m_method;
    118     KURL m_action;
    119     AtomicString m_target;
    120     AtomicString m_contentType;
    121     RefPtrWillBeMember<FormState> m_formState;
    122     RefPtr<FormData> m_formData;
    123     String m_boundary;
    124     RefPtrWillBeMember<Event> m_event;
    125     Referrer m_referrer;
    126     String m_origin;
    127     String m_result;
    128 };
    129 
    130 }
    131 
    132 #endif // FormSubmission_h
    133