WebKitStatistics.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * Copyright (C) 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. *
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
  14. * its contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
  18. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  21. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. #include "config.h"
  29. #include "WebKitDLL.h"
  30. #include "WebKitStatistics.h"
  31. #include "WebKitStatisticsPrivate.h"
  32. #include <WebCore/BString.h>
  33. using namespace WebCore;
  34. int WebViewCount;
  35. int WebDataSourceCount;
  36. int WebFrameCount;
  37. int WebHTMLRepresentationCount;
  38. int WebFrameViewCount;
  39. // WebKitStatistics ---------------------------------------------------------------------------
  40. WebKitStatistics::WebKitStatistics()
  41. : m_refCount(0)
  42. {
  43. gClassCount++;
  44. gClassNameCount.add("WebKitStatistics");
  45. }
  46. WebKitStatistics::~WebKitStatistics()
  47. {
  48. gClassCount--;
  49. gClassNameCount.remove("WebKitStatistics");
  50. }
  51. WebKitStatistics* WebKitStatistics::createInstance()
  52. {
  53. WebKitStatistics* instance = new WebKitStatistics();
  54. instance->AddRef();
  55. return instance;
  56. }
  57. // IUnknown -------------------------------------------------------------------
  58. HRESULT STDMETHODCALLTYPE WebKitStatistics::QueryInterface(REFIID riid, void** ppvObject)
  59. {
  60. *ppvObject = 0;
  61. if (IsEqualGUID(riid, IID_IUnknown))
  62. *ppvObject = static_cast<WebKitStatistics*>(this);
  63. else if (IsEqualGUID(riid, IID_IWebKitStatistics))
  64. *ppvObject = static_cast<WebKitStatistics*>(this);
  65. else
  66. return E_NOINTERFACE;
  67. AddRef();
  68. return S_OK;
  69. }
  70. ULONG STDMETHODCALLTYPE WebKitStatistics::AddRef(void)
  71. {
  72. return ++m_refCount;
  73. }
  74. ULONG STDMETHODCALLTYPE WebKitStatistics::Release(void)
  75. {
  76. ULONG newRef = --m_refCount;
  77. if (!newRef)
  78. delete(this);
  79. return newRef;
  80. }
  81. // IWebKitStatistics ------------------------------------------------------------------------------
  82. HRESULT STDMETHODCALLTYPE WebKitStatistics::webViewCount(
  83. /* [retval][out] */ int *count)
  84. {
  85. *count = WebViewCount;
  86. return S_OK;
  87. }
  88. HRESULT STDMETHODCALLTYPE WebKitStatistics::frameCount(
  89. /* [retval][out] */ int *count)
  90. {
  91. *count = WebFrameCount;
  92. return S_OK;
  93. }
  94. HRESULT STDMETHODCALLTYPE WebKitStatistics::dataSourceCount(
  95. /* [retval][out] */ int *count)
  96. {
  97. *count = WebDataSourceCount;
  98. return S_OK;
  99. }
  100. HRESULT STDMETHODCALLTYPE WebKitStatistics::viewCount(
  101. /* [retval][out] */ int *count)
  102. {
  103. *count = WebFrameViewCount;
  104. return S_OK;
  105. }
  106. HRESULT STDMETHODCALLTYPE WebKitStatistics::HTMLRepresentationCount(
  107. /* [retval][out] */ int *count)
  108. {
  109. *count = WebHTMLRepresentationCount;
  110. return S_OK;
  111. }
  112. HRESULT STDMETHODCALLTYPE WebKitStatistics::comClassCount(
  113. /* [retval][out] */ int *classCount)
  114. {
  115. *classCount = gClassCount;
  116. return S_OK;
  117. }
  118. HRESULT STDMETHODCALLTYPE WebKitStatistics::comClassNameCounts(
  119. /* [retval][out] */ BSTR *output)
  120. {
  121. typedef HashCountedSet<String>::const_iterator Iterator;
  122. Iterator end = gClassNameCount.end();
  123. Vector<UChar> vector;
  124. for (Iterator current = gClassNameCount.begin(); current != end; ++current) {
  125. append(vector, String::format("%4u", current->value));
  126. vector.append('\t');
  127. append(vector, static_cast<String>(current->key));
  128. vector.append('\n');
  129. }
  130. *output = BString(String::adopt(vector)).release();
  131. return S_OK;
  132. }