WebKitStatistics.cpp [plain text]
#include "WebKitDLL.h"
#include "WebKitStatistics.h"
#include "WebKitStatisticsPrivate.h"
#include <WebCore/BString.h>
#include <wtf/text/StringBuilder.h>
using namespace WebCore;
int WebViewCount;
int WebDataSourceCount;
int WebFrameCount;
int WebHTMLRepresentationCount;
int WebFrameViewCount;
WebKitStatistics::WebKitStatistics()
{
gClassCount++;
gClassNameCount().add("WebKitStatistics");
}
WebKitStatistics::~WebKitStatistics()
{
gClassCount--;
gClassNameCount().remove("WebKitStatistics");
}
WebKitStatistics* WebKitStatistics::createInstance()
{
WebKitStatistics* instance = new WebKitStatistics();
instance->AddRef();
return instance;
}
HRESULT WebKitStatistics::QueryInterface(_In_ REFIID riid, _COM_Outptr_ void** ppvObject)
{
if (!ppvObject)
return E_POINTER;
*ppvObject = nullptr;
if (IsEqualGUID(riid, IID_IUnknown))
*ppvObject = static_cast<WebKitStatistics*>(this);
else if (IsEqualGUID(riid, IID_IWebKitStatistics))
*ppvObject = static_cast<WebKitStatistics*>(this);
else
return E_NOINTERFACE;
AddRef();
return S_OK;
}
ULONG WebKitStatistics::AddRef()
{
return ++m_refCount;
}
ULONG WebKitStatistics::Release()
{
ULONG newRef = --m_refCount;
if (!newRef)
delete(this);
return newRef;
}
HRESULT WebKitStatistics::webViewCount(_Out_ int* count)
{
if (!count)
return E_POINTER;
*count = WebViewCount;
return S_OK;
}
HRESULT WebKitStatistics::frameCount(_Out_ int* count)
{
if (!count)
return E_POINTER;
*count = WebFrameCount;
return S_OK;
}
HRESULT WebKitStatistics::dataSourceCount(_Out_ int* count)
{
if (!count)
return E_POINTER;
*count = WebDataSourceCount;
return S_OK;
}
HRESULT WebKitStatistics::viewCount(_Out_ int* count)
{
if (!count)
return E_POINTER;
*count = WebFrameViewCount;
return S_OK;
}
HRESULT WebKitStatistics::HTMLRepresentationCount(_Out_ int* count)
{
if (!count)
return E_POINTER;
*count = WebHTMLRepresentationCount;
return S_OK;
}
HRESULT WebKitStatistics::comClassCount(_Out_ int *classCount)
{
if (!classCount)
return E_POINTER;
*classCount = gClassCount;
return S_OK;
}
HRESULT WebKitStatistics::comClassNameCounts(__deref_out_opt BSTR* output)
{
if (!output)
return E_POINTER;
StringBuilder builder;
for (auto& slot : gClassNameCount()) {
builder.appendNumber(slot.value);
builder.append('\t');
builder.append(slot.key);
builder.append('\n');
}
*output = BString(builder.toString()).release();
return S_OK;
}