atl80: Added AtlComModuleRegisterServer implementation (based on AtlModuleRegisterSer...
[wine] / dlls / mshtml / htmlstorage.c
1 /*
2  * Copyright 2012 Jacek Caban for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #include <stdarg.h>
20
21 #define COBJMACROS
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "ole2.h"
27
28 #include "wine/debug.h"
29
30 #include "mshtml_private.h"
31
32 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
33
34 typedef struct {
35     DispatchEx dispex;
36     IHTMLStorage IHTMLStorage_iface;
37     LONG ref;
38 } HTMLStorage;
39
40 static inline HTMLStorage *impl_from_IHTMLStorage(IHTMLStorage *iface)
41 {
42     return CONTAINING_RECORD(iface, HTMLStorage, IHTMLStorage_iface);
43 }
44
45 static HRESULT WINAPI HTMLStorage_QueryInterface(IHTMLStorage *iface, REFIID riid, void **ppv)
46 {
47     HTMLStorage *This = impl_from_IHTMLStorage(iface);
48
49     *ppv = NULL;
50
51     if(IsEqualGUID(&IID_IUnknown, riid)) {
52         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
53         *ppv = &This->IHTMLStorage_iface;
54     }else if(IsEqualGUID(&IID_IHTMLStorage, riid)) {
55         TRACE("(%p)->(IID_IHTMLStorage %p)\n", This, ppv);
56         *ppv = &This->IHTMLStorage_iface;
57     }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
58         return *ppv ? S_OK : E_NOINTERFACE;
59     }
60
61     if(*ppv) {
62         IUnknown_AddRef((IUnknown*)*ppv);
63         return S_OK;
64     }
65
66     WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
67     return E_NOINTERFACE;
68 }
69
70 static ULONG WINAPI HTMLStorage_AddRef(IHTMLStorage *iface)
71 {
72     HTMLStorage *This = impl_from_IHTMLStorage(iface);
73     LONG ref = InterlockedIncrement(&This->ref);
74
75     TRACE("(%p) ref=%d\n", This, ref);
76
77     return ref;
78 }
79
80 static ULONG WINAPI HTMLStorage_Release(IHTMLStorage *iface)
81 {
82     HTMLStorage *This = impl_from_IHTMLStorage(iface);
83     LONG ref = InterlockedDecrement(&This->ref);
84
85     TRACE("(%p) ref=%d\n", This, ref);
86
87     if(!ref) {
88         release_dispex(&This->dispex);
89         heap_free(This);
90     }
91
92     return ref;
93 }
94
95 static HRESULT WINAPI HTMLStorage_GetTypeInfoCount(IHTMLStorage *iface, UINT *pctinfo)
96 {
97     HTMLStorage *This = impl_from_IHTMLStorage(iface);
98     FIXME("(%p)->(%p)\n", This, pctinfo);
99     return E_NOTIMPL;
100 }
101
102 static HRESULT WINAPI HTMLStorage_GetTypeInfo(IHTMLStorage *iface, UINT iTInfo,
103         LCID lcid, ITypeInfo **ppTInfo)
104 {
105     HTMLStorage *This = impl_from_IHTMLStorage(iface);
106
107     return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
108 }
109
110 static HRESULT WINAPI HTMLStorage_GetIDsOfNames(IHTMLStorage *iface, REFIID riid, LPOLESTR *rgszNames, UINT cNames,
111         LCID lcid, DISPID *rgDispId)
112 {
113     HTMLStorage *This = impl_from_IHTMLStorage(iface);
114
115     return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
116             lcid, rgDispId);
117 }
118
119 static HRESULT WINAPI HTMLStorage_Invoke(IHTMLStorage *iface, DISPID dispIdMember, REFIID riid, LCID lcid,
120         WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
121 {
122     HTMLStorage *This = impl_from_IHTMLStorage(iface);
123
124     return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
125             pDispParams, pVarResult, pExcepInfo, puArgErr);
126 }
127
128 static HRESULT WINAPI HTMLStorage_get_length(IHTMLStorage *iface, LONG *p)
129 {
130     HTMLStorage *This = impl_from_IHTMLStorage(iface);
131     FIXME("(%p)->(%p)\n", This, p);
132     return E_NOTIMPL;
133 }
134
135 static HRESULT WINAPI HTMLStorage_get_remainingSpace(IHTMLStorage *iface, LONG *p)
136 {
137     HTMLStorage *This = impl_from_IHTMLStorage(iface);
138     FIXME("(%p)->(%p)\n", This, p);
139     return E_NOTIMPL;
140 }
141
142 static HRESULT WINAPI HTMLStorage_key(IHTMLStorage *iface, LONG lIndex, BSTR *p)
143 {
144     HTMLStorage *This = impl_from_IHTMLStorage(iface);
145     FIXME("(%p)->(%d %p)\n", This, lIndex, p);
146     return E_NOTIMPL;
147 }
148
149 static HRESULT WINAPI HTMLStorage_getItem(IHTMLStorage *iface, BSTR bstrKey, VARIANT *p)
150 {
151     HTMLStorage *This = impl_from_IHTMLStorage(iface);
152     FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrKey), p);
153     return E_NOTIMPL;
154 }
155
156 static HRESULT WINAPI HTMLStorage_setItem(IHTMLStorage *iface, BSTR bstrKey, BSTR bstrValue)
157 {
158     HTMLStorage *This = impl_from_IHTMLStorage(iface);
159     FIXME("(%p)->(%s %s)\n", This, debugstr_w(bstrKey), debugstr_w(bstrValue));
160     return E_NOTIMPL;
161 }
162
163 static HRESULT WINAPI HTMLStorage_removeItem(IHTMLStorage *iface, BSTR bstrKey)
164 {
165     HTMLStorage *This = impl_from_IHTMLStorage(iface);
166     FIXME("(%p)->(%s)\n", This, debugstr_w(bstrKey));
167     return E_NOTIMPL;
168 }
169
170 static HRESULT WINAPI HTMLStorage_clear(IHTMLStorage *iface)
171 {
172     HTMLStorage *This = impl_from_IHTMLStorage(iface);
173     FIXME("(%p)->()\n", This);
174     return E_NOTIMPL;
175 }
176
177 static const IHTMLStorageVtbl HTMLStorageVtbl = {
178     HTMLStorage_QueryInterface,
179     HTMLStorage_AddRef,
180     HTMLStorage_Release,
181     HTMLStorage_GetTypeInfoCount,
182     HTMLStorage_GetTypeInfo,
183     HTMLStorage_GetIDsOfNames,
184     HTMLStorage_Invoke,
185     HTMLStorage_get_length,
186     HTMLStorage_get_remainingSpace,
187     HTMLStorage_key,
188     HTMLStorage_getItem,
189     HTMLStorage_setItem,
190     HTMLStorage_removeItem,
191     HTMLStorage_clear
192 };
193
194 static const tid_t HTMLStorage_iface_tids[] = {
195     IHTMLStorage_tid,
196     0
197 };
198 static dispex_static_data_t HTMLStorage_dispex = {
199     NULL,
200     IHTMLStorage_tid,
201     NULL,
202     HTMLStorage_iface_tids
203 };
204
205 HRESULT create_storage(IHTMLStorage **p)
206 {
207     HTMLStorage *storage;
208
209     storage = heap_alloc_zero(sizeof(*storage));
210     if(!storage)
211         return E_OUTOFMEMORY;
212
213     storage->IHTMLStorage_iface.lpVtbl = &HTMLStorageVtbl;
214     storage->ref = 1;
215     init_dispex(&storage->dispex, (IUnknown*)&storage->IHTMLStorage_iface, &HTMLStorage_dispex);
216
217     *p = &storage->IHTMLStorage_iface;
218     return S_OK;
219 }