WebNotification.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 "WebNotification.h"
  28. #include <wtf/Assertions.h>
  29. // WebNotification ------------------------------------------------------------
  30. WebNotification::WebNotification(BSTR name, IUnknown* anObject, IPropertyBag* userInfo)
  31. : m_refCount(0)
  32. , m_name(0)
  33. , m_anObject(anObject)
  34. , m_userInfo(userInfo)
  35. {
  36. if (name)
  37. m_name = SysAllocString(name);
  38. if (m_anObject)
  39. m_anObject->AddRef();
  40. if (m_userInfo)
  41. m_userInfo->AddRef();
  42. gClassCount++;
  43. gClassNameCount.add("WebNotification");
  44. }
  45. WebNotification::~WebNotification()
  46. {
  47. if (m_name)
  48. SysFreeString(m_name);
  49. if (m_anObject)
  50. m_anObject->Release();
  51. if (m_userInfo)
  52. m_userInfo->Release();
  53. gClassCount--;
  54. gClassNameCount.remove("WebNotification");
  55. }
  56. WebNotification* WebNotification::createInstance(BSTR name /*=0*/, IUnknown* anObject /*=0*/, IPropertyBag* userInfo /*=0*/)
  57. {
  58. WebNotification* instance = new WebNotification(name, anObject, userInfo);
  59. instance->AddRef();
  60. return instance;
  61. }
  62. // IUnknown -------------------------------------------------------------------
  63. HRESULT STDMETHODCALLTYPE WebNotification::QueryInterface(REFIID riid, void** ppvObject)
  64. {
  65. *ppvObject = 0;
  66. if (IsEqualGUID(riid, IID_IUnknown))
  67. *ppvObject = static_cast<IWebNotification*>(this);
  68. else if (IsEqualGUID(riid, IID_IWebNotification))
  69. *ppvObject = static_cast<IWebNotification*>(this);
  70. else
  71. return E_NOINTERFACE;
  72. AddRef();
  73. return S_OK;
  74. }
  75. ULONG STDMETHODCALLTYPE WebNotification::AddRef(void)
  76. {
  77. return ++m_refCount;
  78. }
  79. ULONG STDMETHODCALLTYPE WebNotification::Release(void)
  80. {
  81. ULONG newRef = --m_refCount;
  82. if (!newRef)
  83. delete(this);
  84. return newRef;
  85. }
  86. // IWebNotification -----------------------------------------------------------
  87. HRESULT STDMETHODCALLTYPE WebNotification::notificationWithName(
  88. /* [in] */ BSTR /*aName*/,
  89. /* [in] */ IUnknown* /*anObject*/,
  90. /* [optional][in] */ IPropertyBag* /*userInfo*/)
  91. {
  92. ASSERT_NOT_REACHED();
  93. return E_NOTIMPL;
  94. }
  95. HRESULT STDMETHODCALLTYPE WebNotification::name(
  96. /* [retval][out] */ BSTR* result)
  97. {
  98. *result = 0;
  99. if (m_name) {
  100. *result = SysAllocString(m_name);
  101. if (!*result)
  102. return E_OUTOFMEMORY;
  103. }
  104. return S_OK;
  105. }
  106. HRESULT STDMETHODCALLTYPE WebNotification::getObject(
  107. /* [retval][out] */ IUnknown** result)
  108. {
  109. *result = m_anObject;
  110. if (*result)
  111. (*result)->AddRef();
  112. return S_OK;
  113. }
  114. HRESULT STDMETHODCALLTYPE WebNotification::userInfo(
  115. /* [retval][out] */ IPropertyBag** result)
  116. {
  117. *result = m_userInfo;
  118. if (*result)
  119. (*result)->AddRef();
  120. return S_OK;
  121. }