193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)/*
293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * Copyright (C) 2009 Google Inc. All rights reserved.
393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) *
493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without
593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * modification, are permitted provided that the following conditions are
693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * met:
793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) *
893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) *     * Redistributions of source code must retain the above copyright
993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * notice, this list of conditions and the following disclaimer.
1093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) *     * Redistributions in binary form must reproduce the above
1193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * copyright notice, this list of conditions and the following disclaimer
1293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * in the documentation and/or other materials provided with the
1393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * distribution.
1493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) *     * Neither the name of Google Inc. nor the names of its
1593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * contributors may be used to endorse or promote products derived from
1693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * this software without specific prior written permission.
1793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) *
1893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) */
3093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
3193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#ifndef WebHTTPBody_h
3293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#define WebHTTPBody_h
3393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
341e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "WebBlobData.h"
3593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#include "WebData.h"
3693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#include "WebNonCopyable.h"
3793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#include "WebString.h"
3893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#include "WebURL.h"
3993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
40bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)#if INSIDE_BLINK
4193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)namespace WTF { template <typename T> class PassRefPtr; }
4293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#endif
4393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
4451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)namespace blink {
4593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
46e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)class FormData;
4793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)class WebHTTPBodyPrivate;
4893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
4993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)class WebHTTPBody {
5093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)public:
5193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    struct Element {
528abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)        enum Type { TypeData, TypeFile, TypeBlob, TypeFileSystemURL } type;
5393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        WebData data;
5493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        WebString filePath;
5593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        long long fileStart;
5693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        long long fileLength; // -1 means to the end of the file.
5793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        double modificationTime;
588abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)        WebURL fileSystemURL;
598abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)        WebString blobUUID;
6093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    };
6193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
6293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    ~WebHTTPBody() { reset(); }
6393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
6493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    WebHTTPBody() : m_private(0) { }
6593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    WebHTTPBody(const WebHTTPBody& b) : m_private(0) { assign(b); }
6693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    WebHTTPBody& operator=(const WebHTTPBody& b)
6793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    {
6893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        assign(b);
6993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        return *this;
7093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    }
7193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
72bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    BLINK_PLATFORM_EXPORT void initialize();
73bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    BLINK_PLATFORM_EXPORT void reset();
74bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    BLINK_PLATFORM_EXPORT void assign(const WebHTTPBody&);
7593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
7693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    bool isNull() const { return !m_private; }
7793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
7893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // Returns the number of elements comprising the http body.
79bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    BLINK_PLATFORM_EXPORT size_t elementCount() const;
8093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
8193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // Sets the values of the element at the given index. Returns false if
8293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // index is out of bounds.
83bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    BLINK_PLATFORM_EXPORT bool elementAt(size_t index, Element&) const;
8493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
8593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // Append to the list of elements.
86bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    BLINK_PLATFORM_EXPORT void appendData(const WebData&);
87bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    BLINK_PLATFORM_EXPORT void appendFile(const WebString&);
8893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // Passing -1 to fileLength means to the end of the file.
89bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    BLINK_PLATFORM_EXPORT void appendFileRange(const WebString&, long long fileStart, long long fileLength, double modificationTime);
90bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    BLINK_PLATFORM_EXPORT void appendBlob(const WebString& uuid);
9193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
928abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    // Append a resource which is identified by the FileSystem URL.
93bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    BLINK_PLATFORM_EXPORT void appendFileSystemURLRange(const WebURL&, long long start, long long length, double modificationTime);
9493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
9593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // Identifies a particular form submission instance. A value of 0 is
9693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // used to indicate an unspecified identifier.
97bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    BLINK_PLATFORM_EXPORT long long identifier() const;
98bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    BLINK_PLATFORM_EXPORT void setIdentifier(long long);
9993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
100bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    BLINK_PLATFORM_EXPORT bool containsPasswordData() const;
101bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    BLINK_PLATFORM_EXPORT void setContainsPasswordData(bool);
10293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
103bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)#if INSIDE_BLINK
104e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    BLINK_PLATFORM_EXPORT WebHTTPBody(const WTF::PassRefPtr<FormData>&);
105e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    BLINK_PLATFORM_EXPORT WebHTTPBody& operator=(const WTF::PassRefPtr<FormData>&);
106e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    BLINK_PLATFORM_EXPORT operator WTF::PassRefPtr<FormData>() const;
10793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#endif
10893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
10993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)private:
110bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    BLINK_PLATFORM_EXPORT void assign(WebHTTPBodyPrivate*);
111bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    BLINK_PLATFORM_EXPORT void ensureMutable();
112bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)
11393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    WebHTTPBodyPrivate* m_private;
11493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)};
11593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
11651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)} // namespace blink
11793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
11893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#endif
119