15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/*
25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *  Copyright (C) 2003, 2006, 2008 Apple Inc. All rights reserved.
35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *  Copyright (C) 2005, 2006 Alexey Proskuryakov <ap@nypop.com>
45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *  Copyright (C) 2011 Google Inc. All rights reserved.
55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *  Copyright (C) 2012 Intel Corporation
65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *  This library is free software; you can redistribute it and/or
85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *  modify it under the terms of the GNU Lesser General Public
95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *  License as published by the Free Software Foundation; either
105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *  version 2 of the License, or (at your option) any later version.
115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *  This library is distributed in the hope that it will be useful,
135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *  but WITHOUT ANY WARRANTY; without even the implied warranty of
145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *  Lesser General Public License for more details.
165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *  You should have received a copy of the GNU Lesser General Public
185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *  License along with this library; if not, write to the Free Software
195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */
215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef XMLHttpRequest_h
235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define XMLHttpRequest_h
245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
25197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "bindings/core/v8/ScriptString.h"
2653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/dom/ActiveDOMObject.h"
277242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci#include "core/dom/DocumentParserClient.h"
2806f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)#include "core/events/EventListener.h"
2953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/loader/ThreadableLoaderClient.h"
309e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)#include "core/streams/ReadableStreamImpl.h"
31e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)#include "core/xml/XMLHttpRequestEventTarget.h"
3253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/xml/XMLHttpRequestProgressEventThrottle.h"
33f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include "platform/heap/Handle.h"
34bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)#include "platform/network/FormData.h"
35bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)#include "platform/network/ResourceResponse.h"
3651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#include "platform/weborigin/SecurityOrigin.h"
37521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)#include "wtf/OwnPtr.h"
38521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)#include "wtf/text/AtomicStringHash.h"
39521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)#include "wtf/text/StringBuilder.h"
405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
41c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink {
425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class Blob;
445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class DOMFormData;
45df95704c49daea886ddad70775bda23618d6274dBen Murdochclass Document;
469e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)class DocumentParser;
47df95704c49daea886ddad70775bda23618d6274dBen Murdochclass ExceptionState;
485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class ResourceRequest;
495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class SecurityOrigin;
505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class SharedBuffer;
518abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)class Stream;
525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class TextResourceDecoder;
535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class ThreadableLoader;
549e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)class UnderlyingSource;
555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
56df95704c49daea886ddad70775bda23618d6274dBen Murdochtypedef int ExceptionCode;
57df95704c49daea886ddad70775bda23618d6274dBen Murdoch
5876c265b59aa821ccbf8c75ab2bb0d036e97d2956Torne (Richard Coles)class XMLHttpRequest FINAL
599e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    : public RefCountedWillBeGarbageCollectedFinalized<XMLHttpRequest>
6076c265b59aa821ccbf8c75ab2bb0d036e97d2956Torne (Richard Coles)    , public XMLHttpRequestEventTarget
6176c265b59aa821ccbf8c75ab2bb0d036e97d2956Torne (Richard Coles)    , private ThreadableLoaderClient
627242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    , public DocumentParserClient
6376c265b59aa821ccbf8c75ab2bb0d036e97d2956Torne (Richard Coles)    , public ActiveDOMObject {
647242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    DEFINE_WRAPPERTYPEINFO();
65d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    REFCOUNTED_EVENT_TARGET(XMLHttpRequest);
66d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(XMLHttpRequest);
677242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)public:
69d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    static PassRefPtrWillBeRawPtr<XMLHttpRequest> create(ExecutionContext*, PassRefPtr<SecurityOrigin> = nullptr);
7009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    virtual ~XMLHttpRequest();
715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // These exact numeric values are important because JS expects them.
735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    enum State {
745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        UNSENT = 0,
755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        OPENED = 1,
765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        HEADERS_RECEIVED = 2,
775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        LOADING = 3,
785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        DONE = 4
795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    };
8002772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch
815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    enum ResponseTypeCode {
825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        ResponseTypeDefault,
8302772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch        ResponseTypeText,
84e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)        ResponseTypeJSON,
855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        ResponseTypeDocument,
865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        ResponseTypeBlob,
878abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)        ResponseTypeArrayBuffer,
889e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)        ResponseTypeLegacyStream,
899e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)        ResponseTypeStream,
905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    };
915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    virtual void contextDestroyed() OVERRIDE;
9309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    virtual void suspend() OVERRIDE;
9409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    virtual void resume() OVERRIDE;
9509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    virtual void stop() OVERRIDE;
96197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    virtual bool hasPendingActivity() const OVERRIDE;
975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
98e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    virtual const AtomicString& interfaceName() const OVERRIDE;
991e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    virtual ExecutionContext* executionContext() const OVERRIDE;
1005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    const KURL& url() const { return m_url; }
102a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    String statusText() const;
103a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    int status() const;
1045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    State readyState() const;
1055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    bool withCredentials() const { return m_includeCredentials; }
106df95704c49daea886ddad70775bda23618d6274dBen Murdoch    void setWithCredentials(bool, ExceptionState&);
107a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    void open(const AtomicString& method, const KURL&, ExceptionState&);
108a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    void open(const AtomicString& method, const KURL&, bool async, ExceptionState&);
109a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    void open(const AtomicString& method, const KURL&, bool async, const String& user, ExceptionState&);
110a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    void open(const AtomicString& method, const KURL&, bool async, const String& user, const String& password, ExceptionState&);
111df95704c49daea886ddad70775bda23618d6274dBen Murdoch    void send(ExceptionState&);
112df95704c49daea886ddad70775bda23618d6274dBen Murdoch    void send(Document*, ExceptionState&);
113df95704c49daea886ddad70775bda23618d6274dBen Murdoch    void send(const String&, ExceptionState&);
114df95704c49daea886ddad70775bda23618d6274dBen Murdoch    void send(Blob*, ExceptionState&);
115df95704c49daea886ddad70775bda23618d6274dBen Murdoch    void send(DOMFormData*, ExceptionState&);
116df95704c49daea886ddad70775bda23618d6274dBen Murdoch    void send(ArrayBuffer*, ExceptionState&);
117df95704c49daea886ddad70775bda23618d6274dBen Murdoch    void send(ArrayBufferView*, ExceptionState&);
1185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    void abort();
119a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    void setRequestHeader(const AtomicString& name, const AtomicString& value, ExceptionState&);
1209e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    void overrideMimeType(const AtomicString& override, ExceptionState&);
121a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    String getAllResponseHeaders() const;
122a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    const AtomicString& getResponseHeader(const AtomicString&) const;
123df95704c49daea886ddad70775bda23618d6274dBen Murdoch    ScriptString responseText(ExceptionState&);
124c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)    ScriptString responseJSONSource();
125df95704c49daea886ddad70775bda23618d6274dBen Murdoch    Document* responseXML(ExceptionState&);
126e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    Blob* responseBlob();
1279e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    Stream* responseLegacyStream();
1289e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    ReadableStream* responseStream();
1295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    unsigned long timeout() const { return m_timeoutMilliseconds; }
130df95704c49daea886ddad70775bda23618d6274dBen Murdoch    void setTimeout(unsigned long timeout, ExceptionState&);
1315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
132df95704c49daea886ddad70775bda23618d6274dBen Murdoch    void sendForInspectorXHRReplay(PassRefPtr<FormData>, ExceptionState&);
1335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Expose HTTP validation methods for other untrusted requests.
135a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    static AtomicString uppercaseKnownHTTPMethod(const AtomicString&);
1365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
137df95704c49daea886ddad70775bda23618d6274dBen Murdoch    void setResponseType(const String&, ExceptionState&);
1385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    String responseType();
1395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ResponseTypeCode responseTypeCode() const { return m_responseTypeCode; }
14002772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch
141f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    String responseURL();
142f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)
1435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // response attribute has custom getter.
144e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    ArrayBuffer* responseArrayBuffer();
1455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    void setLastSendLineNumber(unsigned lineNumber) { m_lastSendLineNumber = lineNumber; }
1475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    void setLastSendURL(const String& url) { m_lastSendURL = url; }
1485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    XMLHttpRequestUpload* upload();
1505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    DEFINE_ATTRIBUTE_EVENT_LISTENER(readystatechange);
1525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
153d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    virtual void trace(Visitor*) OVERRIDE;
154d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
1555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)private:
1561e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    XMLHttpRequest(ExecutionContext*, PassRefPtr<SecurityOrigin>);
1575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    Document* document() const;
1595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    SecurityOrigin* securityOrigin() const;
1605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
16109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    virtual void didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent) OVERRIDE;
16209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    virtual void didReceiveResponse(unsigned long identifier, const ResourceResponse&) OVERRIDE;
16309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    virtual void didReceiveData(const char* data, int dataLength) OVERRIDE;
164f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    // When responseType is set to "blob", didDownloadData() is called instead
165f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    // of didReceiveData().
166f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    virtual void didDownloadData(int dataLength) OVERRIDE;
16709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    virtual void didFinishLoading(unsigned long identifier, double finishTime) OVERRIDE;
16809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    virtual void didFail(const ResourceError&) OVERRIDE;
16909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    virtual void didFailRedirectCheck() OVERRIDE;
1705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1717242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    // DocumentParserClient
1727242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    virtual void notifyParserStopped() OVERRIDE;
1737242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci
1747242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    void endLoading();
1757242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci
176e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    // Returns the MIME type part of m_mimeTypeOverride if present and
177e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    // successfully parsed, or returns one of the "Content-Type" header value
178e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    // of the received response.
179e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    //
180e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    // This method is named after the term "final MIME type" defined in the
181e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    // spec but doesn't convert the result to ASCII lowercase as specified in
182e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    // the spec. Must be lowered later or compared using case insensitive
183e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    // comparison functions if required.
184e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    AtomicString finalResponseMIMEType() const;
185e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    // The same as finalResponseMIMEType() but fallbacks to "text/xml" if
186e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    // finalResponseMIMEType() returns an empty string.
187e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    AtomicString finalResponseMIMETypeWithFallback() const;
1885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    bool responseIsXML() const;
1899e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    bool responseIsHTML() const;
1905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
191e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    PassOwnPtr<TextResourceDecoder> createDecoder() const;
192e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)
193e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    void initResponseDocument();
1949e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    void parseDocumentChunk(const char* data, int dataLength);
1959e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)
196f5e4ad553afbc08dd2e729bb77e937a9a94d5827Torne (Richard Coles)    bool areMethodAndURLValidForSend();
197f5e4ad553afbc08dd2e729bb77e937a9a94d5827Torne (Richard Coles)
198df95704c49daea886ddad70775bda23618d6274dBen Murdoch    bool initSend(ExceptionState&);
199df95704c49daea886ddad70775bda23618d6274dBen Murdoch    void sendBytesData(const void*, size_t, ExceptionState&);
2005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
201a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    const AtomicString& getRequestHeader(const AtomicString& name) const;
202a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    void setRequestHeaderInternal(const AtomicString& name, const AtomicString& value);
2035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
204a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    void trackProgress(int dataLength);
20506f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    // Changes m_state and dispatches a readyStateChange event if new m_state
20606f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    // value is different from last one.
2075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    void changeState(State newState);
2081e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    void dispatchReadyStateChangeEvent();
2091e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
2101e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    // Clears variables used only while the resource is being loaded.
2111e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    void clearVariablesForLoading();
21206f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    // Returns false iff reentry happened and a new load is started.
213197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    bool internalAbort();
21419cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)    // Clears variables holding response header and body data.
2155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    void clearResponse();
2165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    void clearRequest();
2175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2185d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    void createRequest(PassRefPtr<FormData>, ExceptionState&);
2195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
220f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    // Dispatches a response ProgressEvent.
221f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    void dispatchProgressEvent(const AtomicString&, long long, long long);
222f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    // Dispatches a response ProgressEvent using values sampled from
22351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    // m_receivedLength and m_response.
224f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    void dispatchProgressEventFromSnapshot(const AtomicString&);
22551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
22606f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    // Handles didFail() call not caused by cancellation or timeout.
22706f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    void handleNetworkError();
228e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    // Handles didFail() call for cancellations. For example, the
229e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    // ResourceLoader handling the load notifies m_loader of an error
230e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    // cancellation when the frame containing the XHR navigates away.
23106f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    void handleDidCancel();
23206f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    // Handles didFail() call for timeout.
23306f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    void handleDidTimeout();
2345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
23551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    void handleRequestError(ExceptionCode, const AtomicString&, long long, long long);
23651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
237d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    OwnPtrWillBeMember<XMLHttpRequestUpload> m_upload;
2385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    KURL m_url;
240a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    AtomicString m_method;
2415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    HTTPHeaderMap m_requestHeaders;
242e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    // Not converted to ASCII lowercase. Must be lowered later or compared
243e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    // using case insensitive comparison functions if needed.
244a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    AtomicString m_mimeTypeOverride;
2455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    unsigned long m_timeoutMilliseconds;
246d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    RefPtrWillBeMember<Blob> m_responseBlob;
2479e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    RefPtrWillBeMember<Stream> m_responseLegacyStream;
2489e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    PersistentWillBeMember<ReadableStreamImpl<ReadableStreamChunkTypeTraits<ArrayBuffer> > > m_responseStream;
2499e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    PersistentWillBeMember<UnderlyingSource> m_streamSource;
2505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    RefPtr<ThreadableLoader> m_loader;
2527242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    unsigned long m_loaderIdentifier;
2535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    State m_state;
2545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ResourceResponse m_response;
256e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    String m_finalResponseCharset;
2575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
25851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    OwnPtr<TextResourceDecoder> m_decoder;
2595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
260521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)    ScriptString m_responseText;
261d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    RefPtrWillBeMember<Document> m_responseDocument;
2629e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    RefPtrWillBeMember<DocumentParser> m_responseDocumentParser;
26302772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch
2645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    RefPtr<SharedBuffer> m_binaryResponseBuilder;
2657242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    long long m_lengthDownloadedToFile;
266f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)
267f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    RefPtr<ArrayBuffer> m_responseArrayBuffer;
2685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Used for onprogress tracking
2705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    long long m_receivedLength;
2715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    unsigned m_lastSendLineNumber;
2735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    String m_lastSendURL;
27406f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    // An exception to throw in synchronous mode. It's set when failure
27506f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    // notification is received from m_loader and thrown at the end of send() if
27606f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    // any.
2775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ExceptionCode m_exceptionCode;
2785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    XMLHttpRequestProgressEventThrottle m_progressEventThrottle;
2805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // An enum corresponding to the allowed string values for the responseType attribute.
2825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ResponseTypeCode m_responseTypeCode;
2835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    RefPtr<SecurityOrigin> m_securityOrigin;
284197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
285197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    bool m_async;
286197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    bool m_includeCredentials;
287197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    // Used to skip m_responseDocument creation if it's done previously. We need
288197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    // this separate flag since m_responseDocument can be 0 for some cases.
289e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    bool m_parsedResponse;
290197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    bool m_error;
291197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    bool m_uploadEventsAllowed;
292197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    bool m_uploadComplete;
293197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    bool m_sameOriginRequest;
2947242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    // True iff the ongoing resource loading is using the downloadToFile
2957242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    // option.
2967242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    bool m_downloadingToFile;
2975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)};
2985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
299c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink
3005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif // XMLHttpRequest_h
302