1/* 2 * Copyright (C) 2006 Apple Computer, 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 COMPUTER, 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 COMPUTER, 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#ifndef ResourceResponse_h 27#define ResourceResponse_h 28 29#include "ResourceResponseBase.h" 30#include <wtf/RetainPtr.h> 31 32#if USE(CFNETWORK) 33typedef struct _CFURLResponse* CFURLResponseRef; 34#endif 35 36OBJC_CLASS NSURLResponse; 37 38namespace WebCore { 39 40class ResourceResponse : public ResourceResponseBase { 41public: 42 ResourceResponse() 43 : m_initLevel(CommonAndUncommonFields) 44 , m_platformResponseIsUpToDate(true) 45 { 46 } 47 48#if USE(CFNETWORK) 49 ResourceResponse(CFURLResponseRef cfResponse) 50 : m_cfResponse(cfResponse) 51 , m_initLevel(Uninitialized) 52 , m_platformResponseIsUpToDate(true) 53 { 54 m_isNull = !cfResponse; 55 } 56#if PLATFORM(MAC) 57 ResourceResponse(NSURLResponse *); 58#endif 59#else 60 ResourceResponse(NSURLResponse *nsResponse) 61 : m_nsResponse(nsResponse) 62 , m_initLevel(Uninitialized) 63 , m_platformResponseIsUpToDate(true) 64 { 65 m_isNull = !nsResponse; 66 } 67#endif 68 69 ResourceResponse(const KURL& url, const String& mimeType, long long expectedLength, const String& textEncodingName, const String& filename) 70 : ResourceResponseBase(url, mimeType, expectedLength, textEncodingName, filename) 71 , m_initLevel(CommonAndUncommonFields) 72 , m_platformResponseIsUpToDate(false) 73 { 74 } 75 76 unsigned memoryUsage() const 77 { 78 // FIXME: Find some programmatic lighweight way to calculate ResourceResponse and associated classes. 79 // This is a rough estimate of resource overhead based on stats collected from memory usage tests. 80 return 3800; 81 /* 1280 * 2 + // average size of ResourceResponse. Doubled to account for the WebCore copy and the CF copy. 82 // Mostly due to the size of the hash maps, the Header Map strings and the URL. 83 256 * 2 // Overhead from ResourceRequest, doubled to account for WebCore copy and CF copy. 84 // Mostly due to the URL and Header Map. 85 */ 86 } 87 88#if USE(CFNETWORK) 89 CFURLResponseRef cfURLResponse() const; 90#endif 91#if PLATFORM(MAC) 92 NSURLResponse *nsURLResponse() const; 93#endif 94 95#if PLATFORM(MAC) || USE(CFNETWORK) 96 void setCertificateChain(CFArrayRef); 97 RetainPtr<CFArrayRef> certificateChain() const; 98#endif 99 100 bool platformResponseIsUpToDate() const { return m_platformResponseIsUpToDate; } 101 102private: 103 friend class ResourceResponseBase; 104 105 void platformLazyInit(InitLevel); 106 PassOwnPtr<CrossThreadResourceResponseData> doPlatformCopyData(PassOwnPtr<CrossThreadResourceResponseData> data) const { return data; } 107 void doPlatformAdopt(PassOwnPtr<CrossThreadResourceResponseData>) { } 108#if PLATFORM(MAC) 109 void initNSURLResponse() const; 110#endif 111 112 static bool platformCompare(const ResourceResponse& a, const ResourceResponse& b); 113 114#if USE(CFNETWORK) 115 mutable RetainPtr<CFURLResponseRef> m_cfResponse; 116#endif 117#if PLATFORM(MAC) 118 mutable RetainPtr<NSURLResponse> m_nsResponse; 119#endif 120#if PLATFORM(MAC) || USE(CFNETWORK) 121 // Certificate chain is normally part of NS/CFURLResponse, but there is no way to re-add it to a deserialized response after IPC. 122 RetainPtr<CFArrayRef> m_externalCertificateChain; 123#endif 124 InitLevel m_initLevel; 125 bool m_platformResponseIsUpToDate; 126}; 127 128struct CrossThreadResourceResponseData : public CrossThreadResourceResponseDataBase { 129}; 130 131} // namespace WebCore 132 133#endif // ResourceResponse_h 134