| 1 | /* |
| 2 | * Copyright (C) 2006 Apple Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #pragma once |
| 27 | |
| 28 | #include "ResourceResponseBase.h" |
| 29 | |
| 30 | #include <libsoup/soup.h> |
| 31 | #include <wtf/glib/GRefPtr.h> |
| 32 | |
| 33 | namespace WebCore { |
| 34 | |
| 35 | class ResourceResponse : public ResourceResponseBase { |
| 36 | public: |
| 37 | ResourceResponse() |
| 38 | : ResourceResponseBase() |
| 39 | , m_soupFlags(static_cast<SoupMessageFlags>(0)) |
| 40 | , m_tlsErrors(static_cast<GTlsCertificateFlags>(0)) |
| 41 | { |
| 42 | } |
| 43 | |
| 44 | ResourceResponse(const URL& url, const String& mimeType, long long expectedLength, const String& textEncodingName) |
| 45 | : ResourceResponseBase(url, mimeType, expectedLength, textEncodingName) |
| 46 | , m_soupFlags(static_cast<SoupMessageFlags>(0)) |
| 47 | , m_tlsErrors(static_cast<GTlsCertificateFlags>(0)) |
| 48 | { |
| 49 | } |
| 50 | |
| 51 | ResourceResponse(SoupMessage* soupMessage) |
| 52 | : ResourceResponseBase() |
| 53 | , m_soupFlags(static_cast<SoupMessageFlags>(0)) |
| 54 | , m_tlsErrors(static_cast<GTlsCertificateFlags>(0)) |
| 55 | { |
| 56 | updateFromSoupMessage(soupMessage); |
| 57 | } |
| 58 | |
| 59 | void (SoupMessageHeaders*) const; |
| 60 | void updateFromSoupMessage(SoupMessage*); |
| 61 | void (const SoupMessageHeaders*); |
| 62 | |
| 63 | SoupMessageFlags soupMessageFlags() const { return m_soupFlags; } |
| 64 | void setSoupMessageFlags(SoupMessageFlags soupFlags) { m_soupFlags = soupFlags; } |
| 65 | |
| 66 | const String& sniffedContentType() const { return m_sniffedContentType; } |
| 67 | void setSniffedContentType(const String& value) { m_sniffedContentType = value; } |
| 68 | |
| 69 | GTlsCertificate* soupMessageCertificate() const { return m_certificate.get(); } |
| 70 | void setSoupMessageCertificate(GTlsCertificate* certificate) { m_certificate = certificate; } |
| 71 | |
| 72 | GTlsCertificateFlags soupMessageTLSErrors() const { return m_tlsErrors; } |
| 73 | void setSoupMessageTLSErrors(GTlsCertificateFlags tlsErrors) { m_tlsErrors = tlsErrors; } |
| 74 | |
| 75 | template<class Encoder> void encode(Encoder&) const; |
| 76 | template<class Decoder> static bool decode(Decoder&, ResourceResponse&); |
| 77 | |
| 78 | private: |
| 79 | friend class ResourceResponseBase; |
| 80 | |
| 81 | SoupMessageFlags m_soupFlags; |
| 82 | String m_sniffedContentType; |
| 83 | GRefPtr<GTlsCertificate> m_certificate; |
| 84 | GTlsCertificateFlags m_tlsErrors; |
| 85 | |
| 86 | void doUpdateResourceResponse() { } |
| 87 | String platformSuggestedFilename() const; |
| 88 | CertificateInfo platformCertificateInfo() const; |
| 89 | }; |
| 90 | |
| 91 | template<class Encoder> |
| 92 | void ResourceResponse::encode(Encoder& encoder) const |
| 93 | { |
| 94 | ResourceResponseBase::encode(encoder); |
| 95 | encoder.encodeEnum(m_soupFlags); |
| 96 | } |
| 97 | |
| 98 | template<class Decoder> |
| 99 | bool ResourceResponse::decode(Decoder& decoder, ResourceResponse& response) |
| 100 | { |
| 101 | if (!ResourceResponseBase::decode(decoder, response)) |
| 102 | return false; |
| 103 | if (!decoder.decodeEnum(response.m_soupFlags)) |
| 104 | return false; |
| 105 | return true; |
| 106 | } |
| 107 | |
| 108 | } // namespace WebCore |
| 109 | |