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.
6 #include "public/platform/WebServiceWorkerResponse.h"
8 #include "platform/blob/BlobData.h"
9 #include "platform/network/HTTPHeaderMap.h"
10 #include "public/platform/WebHTTPHeaderVisitor.h"
11 #include "wtf/HashMap.h"
15 class WebServiceWorkerResponsePrivate
: public RefCounted
<WebServiceWorkerResponsePrivate
> {
17 WebServiceWorkerResponsePrivate()
19 , responseType(WebServiceWorkerResponseTypeDefault
)
20 , error(WebServiceWorkerResponseErrorUnknown
)
24 unsigned short status
;
26 WebServiceWorkerResponseType responseType
;
27 HTTPHeaderMap headers
;
28 RefPtr
<BlobDataHandle
> blobDataHandle
;
30 WebServiceWorkerResponseError error
;
33 WebServiceWorkerResponse::WebServiceWorkerResponse()
34 : m_private(adoptRef(new WebServiceWorkerResponsePrivate
))
38 void WebServiceWorkerResponse::reset()
43 void WebServiceWorkerResponse::assign(const WebServiceWorkerResponse
& other
)
45 m_private
= other
.m_private
;
48 void WebServiceWorkerResponse::setURL(const WebURL
& url
)
53 WebURL
WebServiceWorkerResponse::url() const
55 return m_private
->url
;
58 void WebServiceWorkerResponse::setStatus(unsigned short status
)
60 m_private
->status
= status
;
63 unsigned short WebServiceWorkerResponse::status() const
65 return m_private
->status
;
68 void WebServiceWorkerResponse::setStatusText(const WebString
& statusText
)
70 m_private
->statusText
= statusText
;
73 WebString
WebServiceWorkerResponse::statusText() const
75 return m_private
->statusText
;
78 void WebServiceWorkerResponse::setResponseType(WebServiceWorkerResponseType responseType
)
80 m_private
->responseType
= responseType
;
83 WebServiceWorkerResponseType
WebServiceWorkerResponse::responseType() const
85 return m_private
->responseType
;
88 void WebServiceWorkerResponse::setHeader(const WebString
& key
, const WebString
& value
)
90 m_private
->headers
.set(key
, value
);
93 void WebServiceWorkerResponse::appendHeader(const WebString
& key
, const WebString
& value
)
95 HTTPHeaderMap::AddResult addResult
= m_private
->headers
.add(key
, value
);
96 if (!addResult
.isNewEntry
)
97 addResult
.storedValue
->value
= addResult
.storedValue
->value
+ ", " + String(value
);
100 WebVector
<WebString
> WebServiceWorkerResponse::getHeaderKeys() const
103 for (HTTPHeaderMap::const_iterator it
= m_private
->headers
.begin(), end
= m_private
->headers
.end(); it
!= end
; ++it
)
104 keys
.append(it
->key
);
109 WebString
WebServiceWorkerResponse::getHeader(const WebString
& key
) const
111 return m_private
->headers
.get(key
);
114 void WebServiceWorkerResponse::visitHTTPHeaderFields(WebHTTPHeaderVisitor
* headerVisitor
) const
116 for (HTTPHeaderMap::const_iterator i
= m_private
->headers
.begin(), end
= m_private
->headers
.end(); i
!= end
; ++i
)
117 headerVisitor
->visitHeader(i
->key
, i
->value
);
120 void WebServiceWorkerResponse::setBlob(const WebString
& uuid
, uint64_t size
)
122 m_private
->blobDataHandle
= BlobDataHandle::create(uuid
, String(), size
);
125 WebString
WebServiceWorkerResponse::blobUUID() const
127 if (!m_private
->blobDataHandle
)
129 return m_private
->blobDataHandle
->uuid();
132 uint64_t WebServiceWorkerResponse::blobSize() const
134 if (!m_private
->blobDataHandle
)
136 return m_private
->blobDataHandle
->size();
139 const HTTPHeaderMap
& WebServiceWorkerResponse::headers() const
141 return m_private
->headers
;
144 void WebServiceWorkerResponse::setBlobDataHandle(PassRefPtr
<BlobDataHandle
> blobDataHandle
)
146 m_private
->blobDataHandle
= blobDataHandle
;
149 PassRefPtr
<BlobDataHandle
> WebServiceWorkerResponse::blobDataHandle() const
151 return m_private
->blobDataHandle
;
154 void WebServiceWorkerResponse::setStreamURL(const WebURL
& url
)
156 m_private
->streamURL
= url
;
159 WebURL
WebServiceWorkerResponse::streamURL() const
161 return m_private
->streamURL
;
164 void WebServiceWorkerResponse::setError(WebServiceWorkerResponseError error
)
166 m_private
->error
= error
;
169 WebServiceWorkerResponseError
WebServiceWorkerResponse::error() const
171 return m_private
->error
;