2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #include "WebKitDLL.h"
30 #include "CFDictionaryPropertyBag.h"
31 #include <WebCore/ApplicationCacheStorage.h>
32 #include <WebCore/MemoryCache.h>
33 #include <WebCore/CrossOriginPreflightResultCache.h>
35 // WebCache ---------------------------------------------------------------------------
41 gClassNameCount.add("WebCache");
47 gClassNameCount.remove("WebCache");
50 WebCache* WebCache::createInstance()
52 WebCache* instance = new WebCache();
57 // IUnknown -------------------------------------------------------------------
59 HRESULT STDMETHODCALLTYPE WebCache::QueryInterface(REFIID riid, void** ppvObject)
62 if (IsEqualGUID(riid, IID_IUnknown))
63 *ppvObject = static_cast<WebCache*>(this);
64 else if (IsEqualGUID(riid, IID_IWebCache))
65 *ppvObject = static_cast<WebCache*>(this);
73 ULONG STDMETHODCALLTYPE WebCache::AddRef(void)
78 ULONG STDMETHODCALLTYPE WebCache::Release(void)
80 ULONG newRef = --m_refCount;
87 // IWebCache ------------------------------------------------------------------------------
89 HRESULT STDMETHODCALLTYPE WebCache::statistics(
90 /* [in][out] */ int* count,
91 /* [retval][out] */ IPropertyBag ** s)
93 if (!count || (s && *count < 4))
100 WebCore::MemoryCache::Statistics stat = WebCore::memoryCache()->getStatistics();
102 static CFStringRef imagesKey = CFSTR("images");
103 static CFStringRef stylesheetsKey = CFSTR("style sheets");
104 static CFStringRef xslKey = CFSTR("xsl");
105 static CFStringRef scriptsKey = CFSTR("scripts");
110 RetainPtr<CFMutableDictionaryRef> dictionary(AdoptCF,
111 CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
113 RetainPtr<CFNumberRef> value(AdoptCF, CFNumberCreate(0, kCFNumberIntType, &stat.images.count));
114 CFDictionaryAddValue(dictionary.get(), imagesKey, value.get());
116 value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.cssStyleSheets.count));
117 CFDictionaryAddValue(dictionary.get(), stylesheetsKey, value.get());
120 value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.xslStyleSheets.count));
122 value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &zero));
124 CFDictionaryAddValue(dictionary.get(), xslKey, value.get());
126 value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.scripts.count));
127 CFDictionaryAddValue(dictionary.get(), scriptsKey, value.get());
129 COMPtr<CFDictionaryPropertyBag> propBag = CFDictionaryPropertyBag::createInstance();
130 propBag->setDictionary(dictionary.get());
131 s[0] = propBag.leakRef();
133 dictionary.adoptCF(CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
135 value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.images.size));
136 CFDictionaryAddValue(dictionary.get(), imagesKey, value.get());
138 value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.cssStyleSheets.size));
139 CFDictionaryAddValue(dictionary.get(), stylesheetsKey, value.get());
142 value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.xslStyleSheets.size));
144 value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &zero));
146 CFDictionaryAddValue(dictionary.get(), xslKey, value.get());
148 value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.scripts.size));
149 CFDictionaryAddValue(dictionary.get(), scriptsKey, value.get());
151 propBag = CFDictionaryPropertyBag::createInstance();
152 propBag->setDictionary(dictionary.get());
153 s[1] = propBag.leakRef();
155 dictionary.adoptCF(CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
157 value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.images.liveSize));
158 CFDictionaryAddValue(dictionary.get(), imagesKey, value.get());
160 value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.cssStyleSheets.liveSize));
161 CFDictionaryAddValue(dictionary.get(), stylesheetsKey, value.get());
164 value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.xslStyleSheets.liveSize));
166 value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &zero));
168 CFDictionaryAddValue(dictionary.get(), xslKey, value.get());
170 value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.scripts.liveSize));
171 CFDictionaryAddValue(dictionary.get(), scriptsKey, value.get());
173 propBag = CFDictionaryPropertyBag::createInstance();
174 propBag->setDictionary(dictionary.get());
175 s[2] = propBag.leakRef();
177 dictionary.adoptCF(CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
179 value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.images.decodedSize));
180 CFDictionaryAddValue(dictionary.get(), imagesKey, value.get());
182 value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.cssStyleSheets.decodedSize));
183 CFDictionaryAddValue(dictionary.get(), stylesheetsKey, value.get());
186 value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.xslStyleSheets.decodedSize));
188 value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &zero));
190 CFDictionaryAddValue(dictionary.get(), xslKey, value.get());
192 value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.scripts.decodedSize));
193 CFDictionaryAddValue(dictionary.get(), scriptsKey, value.get());
195 propBag = CFDictionaryPropertyBag::createInstance();
196 propBag->setDictionary(dictionary.get());
197 s[3] = propBag.leakRef();
202 HRESULT STDMETHODCALLTYPE WebCache::empty( void)
204 if (WebCore::memoryCache()->disabled())
206 WebCore::memoryCache()->setDisabled(true);
207 WebCore::memoryCache()->setDisabled(false);
209 // Empty the application cache.
210 WebCore::cacheStorage().empty();
212 // Empty the Cross-Origin Preflight cache
213 WebCore::CrossOriginPreflightResultCache::shared().empty();
218 HRESULT STDMETHODCALLTYPE WebCache::setDisabled(
219 /* [in] */ BOOL disabled)
221 WebCore::memoryCache()->setDisabled(!!disabled);
225 HRESULT STDMETHODCALLTYPE WebCache::disabled(
226 /* [out][retval] */ BOOL* disabled)
230 *disabled = WebCore::memoryCache()->disabled();