Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / xml / XMLHttpRequest.h
index 5025564..b3a719d 100644 (file)
 #ifndef XMLHttpRequest_h
 #define XMLHttpRequest_h
 
-#include "bindings/v8/ScriptString.h"
-#include "bindings/v8/ScriptWrappable.h"
+#include "bindings/core/v8/ScriptString.h"
 #include "core/dom/ActiveDOMObject.h"
 #include "core/events/EventListener.h"
 #include "core/loader/ThreadableLoaderClient.h"
 #include "core/xml/XMLHttpRequestEventTarget.h"
 #include "core/xml/XMLHttpRequestProgressEventThrottle.h"
-#include "platform/AsyncMethodRunner.h"
 #include "platform/heap/Handle.h"
 #include "platform/network/FormData.h"
 #include "platform/network/ResourceResponse.h"
@@ -38,7 +36,7 @@
 #include "wtf/text/AtomicStringHash.h"
 #include "wtf/text/StringBuilder.h"
 
-namespace WebCore {
+namespace blink {
 
 class Blob;
 class DOMFormData;
@@ -55,7 +53,6 @@ typedef int ExceptionCode;
 
 class XMLHttpRequest FINAL
     : public RefCountedWillBeRefCountedGarbageCollected<XMLHttpRequest>
-    , public ScriptWrappable
     , public XMLHttpRequestEventTarget
     , private ThreadableLoaderClient
     , public ActiveDOMObject {
@@ -82,18 +79,14 @@ public:
         ResponseTypeDocument,
         ResponseTypeBlob,
         ResponseTypeArrayBuffer,
-        ResponseTypeStream
-    };
-
-    enum DropProtection {
-        DropProtectionSync,
-        DropProtectionAsync,
+        ResponseTypeLegacyStream
     };
 
     virtual void contextDestroyed() OVERRIDE;
     virtual void suspend() OVERRIDE;
     virtual void resume() OVERRIDE;
     virtual void stop() OVERRIDE;
+    virtual bool hasPendingActivity() const OVERRIDE;
 
     virtual const AtomicString& interfaceName() const OVERRIDE;
     virtual ExecutionContext* executionContext() const OVERRIDE;
@@ -131,9 +124,7 @@ public:
     void sendForInspectorXHRReplay(PassRefPtr<FormData>, ExceptionState&);
 
     // Expose HTTP validation methods for other untrusted requests.
-    static bool isAllowedHTTPMethod(const String&);
     static AtomicString uppercaseKnownHTTPMethod(const AtomicString&);
-    static bool isAllowedHTTPHeader(const String&);
 
     void setResponseType(const String&, ExceptionState&);
     String responseType();
@@ -169,9 +160,23 @@ private:
     virtual void didFail(const ResourceError&) OVERRIDE;
     virtual void didFailRedirectCheck() OVERRIDE;
 
-    AtomicString responseMIMEType() const;
+    // Returns the MIME type part of m_mimeTypeOverride if present and
+    // successfully parsed, or returns one of the "Content-Type" header value
+    // of the received response.
+    //
+    // This method is named after the term "final MIME type" defined in the
+    // spec but doesn't convert the result to ASCII lowercase as specified in
+    // the spec. Must be lowered later or compared using case insensitive
+    // comparison functions if required.
+    AtomicString finalResponseMIMEType() const;
+    // The same as finalResponseMIMEType() but fallbacks to "text/xml" if
+    // finalResponseMIMEType() returns an empty string.
+    AtomicString finalResponseMIMETypeWithFallback() const;
     bool responseIsXML() const;
 
+    PassOwnPtr<TextResourceDecoder> createDecoder() const;
+
+    void initResponseDocument();
     bool areMethodAndURLValidForSend();
 
     bool initSend(ExceptionState&);
@@ -186,12 +191,10 @@ private:
     void changeState(State newState);
     void dispatchReadyStateChangeEvent();
 
-    void dropProtectionSoon();
-    void dropProtection();
     // Clears variables used only while the resource is being loaded.
     void clearVariablesForLoading();
     // Returns false iff reentry happened and a new load is started.
-    bool internalAbort(DropProtection = DropProtectionSync);
+    bool internalAbort();
     // Clears variables holding response header and body data.
     void clearResponse();
     void clearRequest();
@@ -208,7 +211,9 @@ private:
     void handleDidFailGeneric();
     // Handles didFail() call not caused by cancellation or timeout.
     void handleNetworkError();
-    // Handles didFail() call triggered by m_loader->cancel().
+    // Handles didFail() call for cancellations. For example, the
+    // ResourceLoader handling the load notifies m_loader of an error
+    // cancellation when the frame containing the XHR navigates away.
     void handleDidCancel();
     // Handles didFail() call for timeout.
     void handleDidTimeout();
@@ -220,9 +225,9 @@ private:
     KURL m_url;
     AtomicString m_method;
     HTTPHeaderMap m_requestHeaders;
+    // Not converted to ASCII lowercase. Must be lowered later or compared
+    // using case insensitive comparison functions if needed.
     AtomicString m_mimeTypeOverride;
-    bool m_async;
-    bool m_includeCredentials;
     unsigned long m_timeoutMilliseconds;
     RefPtrWillBeMember<Blob> m_responseBlob;
     RefPtrWillBeMember<Stream> m_responseStream;
@@ -231,14 +236,11 @@ private:
     State m_state;
 
     ResourceResponse m_response;
-    String m_responseEncoding;
+    String m_finalResponseCharset;
 
     OwnPtr<TextResourceDecoder> m_decoder;
 
     ScriptString m_responseText;
-    // Used to skip m_responseDocument creation if it's done previously. We need
-    // this separate flag since m_responseDocument can be 0 for some cases.
-    bool m_createdDocument;
     RefPtrWillBeMember<Document> m_responseDocument;
 
     RefPtr<SharedBuffer> m_binaryResponseBuilder;
@@ -246,13 +248,6 @@ private:
 
     RefPtr<ArrayBuffer> m_responseArrayBuffer;
 
-    bool m_error;
-
-    bool m_uploadEventsAllowed;
-    bool m_uploadComplete;
-
-    bool m_sameOriginRequest;
-
     // Used for onprogress tracking
     long long m_receivedLength;
 
@@ -267,10 +262,19 @@ private:
 
     // An enum corresponding to the allowed string values for the responseType attribute.
     ResponseTypeCode m_responseTypeCode;
-    AsyncMethodRunner<XMLHttpRequest> m_dropProtectionRunner;
     RefPtr<SecurityOrigin> m_securityOrigin;
+
+    bool m_async;
+    bool m_includeCredentials;
+    // Used to skip m_responseDocument creation if it's done previously. We need
+    // this separate flag since m_responseDocument can be 0 for some cases.
+    bool m_parsedResponse;
+    bool m_error;
+    bool m_uploadEventsAllowed;
+    bool m_uploadComplete;
+    bool m_sameOriginRequest;
 };
 
-} // namespace WebCore
+} // namespace blink
 
 #endif // XMLHttpRequest_h