webengine/osswebengine/WebKit/win/WebCache.cpp
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2  * Copyright (C) 2006, 2007 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 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 #include "config.h"
       
    27 #include "WebKitDLL.h"
       
    28 #include "WebCache.h"
       
    29 
       
    30 #include "CFDictionaryPropertyBag.h"
       
    31 
       
    32 #pragma warning(push, 0)
       
    33 #include <WebCore/Cache.h>
       
    34 #pragma warning(pop)
       
    35 
       
    36 // WebCache ---------------------------------------------------------------------------
       
    37 
       
    38 WebCache::WebCache()
       
    39 : m_refCount(0)
       
    40 {
       
    41     gClassCount++;
       
    42 }
       
    43 
       
    44 WebCache::~WebCache()
       
    45 {
       
    46     gClassCount--;
       
    47 }
       
    48 
       
    49 WebCache* WebCache::createInstance()
       
    50 {
       
    51     WebCache* instance = new WebCache();
       
    52     instance->AddRef();
       
    53     return instance;
       
    54 }
       
    55 
       
    56 // IUnknown -------------------------------------------------------------------
       
    57 
       
    58 HRESULT STDMETHODCALLTYPE WebCache::QueryInterface(REFIID riid, void** ppvObject)
       
    59 {
       
    60     *ppvObject = 0;
       
    61     if (IsEqualGUID(riid, IID_IUnknown))
       
    62         *ppvObject = static_cast<WebCache*>(this);
       
    63     else if (IsEqualGUID(riid, IID_IWebCache))
       
    64         *ppvObject = static_cast<WebCache*>(this);
       
    65     else
       
    66         return E_NOINTERFACE;
       
    67 
       
    68     AddRef();
       
    69     return S_OK;
       
    70 }
       
    71 
       
    72 ULONG STDMETHODCALLTYPE WebCache::AddRef(void)
       
    73 {
       
    74     return ++m_refCount;
       
    75 }
       
    76 
       
    77 ULONG STDMETHODCALLTYPE WebCache::Release(void)
       
    78 {
       
    79     ULONG newRef = --m_refCount;
       
    80     if (!newRef)
       
    81         delete(this);
       
    82 
       
    83     return newRef;
       
    84 }
       
    85 
       
    86 // IWebCache ------------------------------------------------------------------------------
       
    87 
       
    88 HRESULT STDMETHODCALLTYPE WebCache::statistics( 
       
    89     /* [in][out] */ int* count,
       
    90     /* [retval][out] */ IPropertyBag ** s)
       
    91 {
       
    92     if (!count || (s && *count < 2))
       
    93         return E_FAIL;
       
    94 
       
    95     *count = 2;
       
    96     if (!s)
       
    97         return S_OK;
       
    98 
       
    99     WebCore::Cache::Statistics stat = WebCore::cache()->getStatistics();
       
   100 
       
   101     static CFStringRef imagesKey = CFSTR("images");
       
   102     static CFStringRef stylesheetsKey = CFSTR("style sheets");
       
   103     static CFStringRef scriptsKey = CFSTR("scripts");
       
   104 
       
   105     RetainPtr<CFMutableDictionaryRef> dictionary(AdoptCF,
       
   106         CFDictionaryCreateMutable(0, 0, 0, &kCFTypeDictionaryValueCallBacks));
       
   107 
       
   108     RetainPtr<CFNumberRef> value(AdoptCF, CFNumberCreate(0, kCFNumberIntType, &stat.images.count));
       
   109     CFDictionaryAddValue(dictionary.get(), imagesKey, value.get());
       
   110     
       
   111     value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.cssStyleSheets.count));
       
   112     CFDictionaryAddValue(dictionary.get(), stylesheetsKey, value.get());
       
   113     
       
   114     value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.scripts.count));
       
   115     CFDictionaryAddValue(dictionary.get(), scriptsKey, value.get());
       
   116 
       
   117     CFDictionaryPropertyBag* propBag = CFDictionaryPropertyBag::createInstance();
       
   118     propBag->setDictionary(dictionary.get());
       
   119     s[0] = propBag;
       
   120 
       
   121     dictionary.adoptCF(CFDictionaryCreateMutable(0, 0, 0, &kCFTypeDictionaryValueCallBacks));
       
   122 
       
   123     value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.images.size));
       
   124     CFDictionaryAddValue(dictionary.get(), imagesKey, value.get());
       
   125     
       
   126     value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.cssStyleSheets.size));
       
   127     CFDictionaryAddValue(dictionary.get(), stylesheetsKey, value.get());
       
   128     
       
   129     value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.scripts.size));
       
   130     CFDictionaryAddValue(dictionary.get(), scriptsKey, value.get());
       
   131 
       
   132     propBag = CFDictionaryPropertyBag::createInstance();
       
   133     propBag->setDictionary(dictionary.get());
       
   134     s[1] = propBag;
       
   135 
       
   136     return S_OK;
       
   137 }
       
   138 
       
   139 HRESULT STDMETHODCALLTYPE WebCache::empty( void)
       
   140 {
       
   141     if (WebCore::cache()->disabled())
       
   142         return S_OK;
       
   143     WebCore::cache()->setDisabled(true);
       
   144     WebCore::cache()->setDisabled(false);
       
   145     return S_OK;
       
   146 }
       
   147 
       
   148 HRESULT STDMETHODCALLTYPE WebCache::setDisabled( 
       
   149     /* [in] */ BOOL disabled)
       
   150 {
       
   151     WebCore::cache()->setDisabled(!!disabled);
       
   152     return S_OK;
       
   153 }