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