Home | History | Annotate | Download | only in serviceworkers
      1 // Copyright 2014 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef FetchResponseData_h
      6 #define FetchResponseData_h
      7 
      8 #include "platform/heap/Handle.h"
      9 #include "platform/weborigin/KURL.h"
     10 #include "wtf/PassRefPtr.h"
     11 #include "wtf/text/AtomicString.h"
     12 
     13 namespace blink {
     14 
     15 class BlobDataHandle;
     16 class FetchHeaderList;
     17 class WebServiceWorkerResponse;
     18 
     19 class FetchResponseData FINAL : public GarbageCollectedFinalized<FetchResponseData> {
     20     WTF_MAKE_NONCOPYABLE(FetchResponseData);
     21 public:
     22     // "A response has an associated type which is one of basic, CORS, default,
     23     // error, and opaque. Unless stated otherwise, it is default."
     24     enum Type { BasicType, CORSType, DefaultType, ErrorType, OpaqueType };
     25     // "A response can have an associated termination reason which is one of
     26     // end-user abort, fatal, and timeout."
     27     enum TerminationReason { EndUserAbortTermination, FatalTermination, TimeoutTermination };
     28 
     29     static FetchResponseData* create();
     30     static FetchResponseData* createNetworkErrorResponse();
     31 
     32     FetchResponseData* createBasicFilteredResponse();
     33     FetchResponseData* createCORSFilteredResponse();
     34     FetchResponseData* createOpaqueFilteredResponse();
     35 
     36     Type type() const { return m_type; }
     37     const KURL& url() const { return m_url; }
     38     unsigned short status() const { return m_status; }
     39     AtomicString statusMessage() const { return m_statusMessage; }
     40     FetchHeaderList* headerList() const { return m_headerList.get(); }
     41     PassRefPtr<BlobDataHandle> blobDataHandle() const { return m_blobDataHandle; }
     42 
     43     void setURL(const KURL& url) { m_url = url; }
     44     void setStatus(unsigned short status) { m_status = status; }
     45     void setStatusMessage(AtomicString statusMessage) { m_statusMessage = statusMessage; }
     46     void setBlobDataHandle(PassRefPtr<BlobDataHandle> blobDataHandle) { m_blobDataHandle = blobDataHandle; }
     47 
     48     void populateWebServiceWorkerResponse(blink::WebServiceWorkerResponse&);
     49 
     50     void trace(Visitor*);
     51 
     52 private:
     53     FetchResponseData(Type, unsigned short, AtomicString);
     54 
     55     Type m_type;
     56     OwnPtr<TerminationReason> m_terminationReason;
     57     KURL m_url;
     58     unsigned short m_status;
     59     AtomicString m_statusMessage;
     60     Member<FetchHeaderList> m_headerList;
     61     RefPtr<BlobDataHandle> m_blobDataHandle;
     62     Member<FetchResponseData> m_internalResponse;
     63 };
     64 
     65 } // namespace blink
     66 
     67 #endif // FetchResponseData_h
     68