PageRenderTime 27ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

/external/webkit/Source/WebKit/win/WebCache.cpp

https://gitlab.com/brian0218/rk3188_r-box_android4.2.2_sdk
C++ | 232 lines | 155 code | 48 blank | 29 comment | 10 complexity | 523dce77e03602bada73ac8db9040057 MD5 | raw file
  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. #include "config.h"
  26. #include "WebKitDLL.h"
  27. #include "WebCache.h"
  28. #include "CFDictionaryPropertyBag.h"
  29. #include <WebCore/ApplicationCacheStorage.h>
  30. #include <WebCore/MemoryCache.h>
  31. #include <WebCore/CrossOriginPreflightResultCache.h>
  32. // WebCache ---------------------------------------------------------------------------
  33. WebCache::WebCache()
  34. : m_refCount(0)
  35. {
  36. gClassCount++;
  37. gClassNameCount.add("WebCache");
  38. }
  39. WebCache::~WebCache()
  40. {
  41. gClassCount--;
  42. gClassNameCount.remove("WebCache");
  43. }
  44. WebCache* WebCache::createInstance()
  45. {
  46. WebCache* instance = new WebCache();
  47. instance->AddRef();
  48. return instance;
  49. }
  50. // IUnknown -------------------------------------------------------------------
  51. HRESULT STDMETHODCALLTYPE WebCache::QueryInterface(REFIID riid, void** ppvObject)
  52. {
  53. *ppvObject = 0;
  54. if (IsEqualGUID(riid, IID_IUnknown))
  55. *ppvObject = static_cast<WebCache*>(this);
  56. else if (IsEqualGUID(riid, IID_IWebCache))
  57. *ppvObject = static_cast<WebCache*>(this);
  58. else
  59. return E_NOINTERFACE;
  60. AddRef();
  61. return S_OK;
  62. }
  63. ULONG STDMETHODCALLTYPE WebCache::AddRef(void)
  64. {
  65. return ++m_refCount;
  66. }
  67. ULONG STDMETHODCALLTYPE WebCache::Release(void)
  68. {
  69. ULONG newRef = --m_refCount;
  70. if (!newRef)
  71. delete(this);
  72. return newRef;
  73. }
  74. // IWebCache ------------------------------------------------------------------------------
  75. HRESULT STDMETHODCALLTYPE WebCache::statistics(
  76. /* [in][out] */ int* count,
  77. /* [retval][out] */ IPropertyBag ** s)
  78. {
  79. if (!count || (s && *count < 4))
  80. return E_FAIL;
  81. *count = 4;
  82. if (!s)
  83. return S_OK;
  84. WebCore::MemoryCache::Statistics stat = WebCore::memoryCache()->getStatistics();
  85. static CFStringRef imagesKey = CFSTR("images");
  86. static CFStringRef stylesheetsKey = CFSTR("style sheets");
  87. static CFStringRef xslKey = CFSTR("xsl");
  88. static CFStringRef scriptsKey = CFSTR("scripts");
  89. #if !ENABLE(XSLT)
  90. const int zero = 0;
  91. #endif
  92. RetainPtr<CFMutableDictionaryRef> dictionary(AdoptCF,
  93. CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
  94. RetainPtr<CFNumberRef> value(AdoptCF, CFNumberCreate(0, kCFNumberIntType, &stat.images.count));
  95. CFDictionaryAddValue(dictionary.get(), imagesKey, value.get());
  96. value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.cssStyleSheets.count));
  97. CFDictionaryAddValue(dictionary.get(), stylesheetsKey, value.get());
  98. #if ENABLE(XSLT)
  99. value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.xslStyleSheets.count));
  100. #else
  101. value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &zero));
  102. #endif
  103. CFDictionaryAddValue(dictionary.get(), xslKey, value.get());
  104. value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.scripts.count));
  105. CFDictionaryAddValue(dictionary.get(), scriptsKey, value.get());
  106. COMPtr<CFDictionaryPropertyBag> propBag = CFDictionaryPropertyBag::createInstance();
  107. propBag->setDictionary(dictionary.get());
  108. s[0] = propBag.releaseRef();
  109. dictionary.adoptCF(CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
  110. value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.images.size));
  111. CFDictionaryAddValue(dictionary.get(), imagesKey, value.get());
  112. value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.cssStyleSheets.size));
  113. CFDictionaryAddValue(dictionary.get(), stylesheetsKey, value.get());
  114. #if ENABLE(XSLT)
  115. value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.xslStyleSheets.size));
  116. #else
  117. value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &zero));
  118. #endif
  119. CFDictionaryAddValue(dictionary.get(), xslKey, value.get());
  120. value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.scripts.size));
  121. CFDictionaryAddValue(dictionary.get(), scriptsKey, value.get());
  122. propBag = CFDictionaryPropertyBag::createInstance();
  123. propBag->setDictionary(dictionary.get());
  124. s[1] = propBag.releaseRef();
  125. dictionary.adoptCF(CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
  126. value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.images.liveSize));
  127. CFDictionaryAddValue(dictionary.get(), imagesKey, value.get());
  128. value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.cssStyleSheets.liveSize));
  129. CFDictionaryAddValue(dictionary.get(), stylesheetsKey, value.get());
  130. #if ENABLE(XSLT)
  131. value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.xslStyleSheets.liveSize));
  132. #else
  133. value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &zero));
  134. #endif
  135. CFDictionaryAddValue(dictionary.get(), xslKey, value.get());
  136. value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.scripts.liveSize));
  137. CFDictionaryAddValue(dictionary.get(), scriptsKey, value.get());
  138. propBag = CFDictionaryPropertyBag::createInstance();
  139. propBag->setDictionary(dictionary.get());
  140. s[2] = propBag.releaseRef();
  141. dictionary.adoptCF(CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
  142. value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.images.decodedSize));
  143. CFDictionaryAddValue(dictionary.get(), imagesKey, value.get());
  144. value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.cssStyleSheets.decodedSize));
  145. CFDictionaryAddValue(dictionary.get(), stylesheetsKey, value.get());
  146. #if ENABLE(XSLT)
  147. value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.xslStyleSheets.decodedSize));
  148. #else
  149. value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &zero));
  150. #endif
  151. CFDictionaryAddValue(dictionary.get(), xslKey, value.get());
  152. value.adoptCF(CFNumberCreate(0, kCFNumberIntType, &stat.scripts.decodedSize));
  153. CFDictionaryAddValue(dictionary.get(), scriptsKey, value.get());
  154. propBag = CFDictionaryPropertyBag::createInstance();
  155. propBag->setDictionary(dictionary.get());
  156. s[3] = propBag.releaseRef();
  157. return S_OK;
  158. }
  159. HRESULT STDMETHODCALLTYPE WebCache::empty( void)
  160. {
  161. if (WebCore::memoryCache()->disabled())
  162. return S_OK;
  163. WebCore::memoryCache()->setDisabled(true);
  164. WebCore::memoryCache()->setDisabled(false);
  165. // Empty the application cache.
  166. WebCore::cacheStorage().empty();
  167. // Empty the Cross-Origin Preflight cache
  168. WebCore::CrossOriginPreflightResultCache::shared().empty();
  169. return S_OK;
  170. }
  171. HRESULT STDMETHODCALLTYPE WebCache::setDisabled(
  172. /* [in] */ BOOL disabled)
  173. {
  174. WebCore::memoryCache()->setDisabled(!!disabled);
  175. return S_OK;
  176. }
  177. HRESULT STDMETHODCALLTYPE WebCache::disabled(
  178. /* [out][retval] */ BOOL* disabled)
  179. {
  180. if (!disabled)
  181. return E_POINTER;
  182. *disabled = WebCore::memoryCache()->disabled();
  183. return S_OK;
  184. }