Home | History | Annotate | Download | only in cf
      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)
     33 typedef struct _CFURLResponse* CFURLResponseRef;
     34 #else
     35 #ifdef __OBJC__
     36 @class NSURLResponse;
     37 #else
     38 class NSURLResponse;
     39 #endif
     40 #endif
     41 
     42 namespace WebCore {
     43 
     44 class ResourceResponse : public ResourceResponseBase {
     45 public:
     46     ResourceResponse()
     47         : m_initLevel(AllFields)
     48     {
     49     }
     50 
     51 #if USE(CFNETWORK)
     52     ResourceResponse(CFURLResponseRef cfResponse)
     53         : m_cfResponse(cfResponse)
     54         , m_initLevel(Uninitialized)
     55     {
     56         m_isNull = !cfResponse;
     57     }
     58 #else
     59     ResourceResponse(NSURLResponse* nsResponse)
     60         : m_nsResponse(nsResponse)
     61         , m_initLevel(Uninitialized)
     62     {
     63         m_isNull = !nsResponse;
     64     }
     65 #endif
     66 
     67     ResourceResponse(const KURL& url, const String& mimeType, long long expectedLength, const String& textEncodingName, const String& filename)
     68         : ResourceResponseBase(url, mimeType, expectedLength, textEncodingName, filename)
     69         , m_initLevel(AllFields)
     70     {
     71     }
     72 
     73     unsigned memoryUsage() const
     74     {
     75         // FIXME: Find some programmatic lighweight way to calculate ResourceResponse and associated classes.
     76         // This is a rough estimate of resource overhead based on stats collected from memory usage tests.
     77         return 3800;
     78         /*  1280 * 2 +                // average size of ResourceResponse. Doubled to account for the WebCore copy and the CF copy.
     79                                       // Mostly due to the size of the hash maps, the Header Map strings and the URL.
     80             256 * 2                   // Overhead from ResourceRequest, doubled to account for WebCore copy and CF copy.
     81                                       // Mostly due to the URL and Header Map.
     82          */
     83     }
     84 
     85 #if USE(CFNETWORK)
     86     CFURLResponseRef cfURLResponse() const;
     87 #else
     88     NSURLResponse *nsURLResponse() const;
     89 #endif
     90 
     91 private:
     92     friend class ResourceResponseBase;
     93 
     94     void platformLazyInit(InitLevel);
     95     PassOwnPtr<CrossThreadResourceResponseData> doPlatformCopyData(PassOwnPtr<CrossThreadResourceResponseData> data) const { return data; }
     96     void doPlatformAdopt(PassOwnPtr<CrossThreadResourceResponseData>) { }
     97 
     98     static bool platformCompare(const ResourceResponse& a, const ResourceResponse& b);
     99 
    100 #if USE(CFNETWORK)
    101     mutable RetainPtr<CFURLResponseRef> m_cfResponse;
    102 #else
    103     mutable RetainPtr<NSURLResponse> m_nsResponse;
    104 #endif
    105     InitLevel m_initLevel;
    106 };
    107 
    108 struct CrossThreadResourceResponseData : public CrossThreadResourceResponseDataBase {
    109 };
    110 
    111 } // namespace WebCore
    112 
    113 #endif // ResourceResponse_h
    114