9ad18e502997740ef4724880b64580f8c318cce8
[reactos.git] / reactos / dll / win32 / 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 WIN32_NO_STATUS
22 #define _INC_WINDOWS
23
24 #define COBJMACROS
25
26 #include <windef.h>
27 #include <winbase.h>
28 //#include "winuser.h"
29 #include <ole2.h>
30
31 #include <wine/debug.h>
32
33 #include "mshtml_private.h"
34
35 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
36
37 typedef struct {
38 DispatchEx dispex;
39 IHTMLStorage IHTMLStorage_iface;
40 LONG ref;
41 } HTMLStorage;
42
43 static inline HTMLStorage *impl_from_IHTMLStorage(IHTMLStorage *iface)
44 {
45 return CONTAINING_RECORD(iface, HTMLStorage, IHTMLStorage_iface);
46 }
47
48 static HRESULT WINAPI HTMLStorage_QueryInterface(IHTMLStorage *iface, REFIID riid, void **ppv)
49 {
50 HTMLStorage *This = impl_from_IHTMLStorage(iface);
51
52 *ppv = NULL;
53
54 if(IsEqualGUID(&IID_IUnknown, riid)) {
55 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
56 *ppv = &This->IHTMLStorage_iface;
57 }else if(IsEqualGUID(&IID_IHTMLStorage, riid)) {
58 TRACE("(%p)->(IID_IHTMLStorage %p)\n", This, ppv);
59 *ppv = &This->IHTMLStorage_iface;
60 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
61 return *ppv ? S_OK : E_NOINTERFACE;
62 }
63
64 if(*ppv) {
65 IUnknown_AddRef((IUnknown*)*ppv);
66 return S_OK;
67 }
68
69 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
70 return E_NOINTERFACE;
71 }
72
73 static ULONG WINAPI HTMLStorage_AddRef(IHTMLStorage *iface)
74 {
75 HTMLStorage *This = impl_from_IHTMLStorage(iface);
76 LONG ref = InterlockedIncrement(&This->ref);
77
78 TRACE("(%p) ref=%d\n", This, ref);
79
80 return ref;
81 }
82
83 static ULONG WINAPI HTMLStorage_Release(IHTMLStorage *iface)
84 {
85 HTMLStorage *This = impl_from_IHTMLStorage(iface);
86 LONG ref = InterlockedDecrement(&This->ref);
87
88 TRACE("(%p) ref=%d\n", This, ref);
89
90 if(!ref) {
91 release_dispex(&This->dispex);
92 heap_free(This);
93 }
94
95 return ref;
96 }
97
98 static HRESULT WINAPI HTMLStorage_GetTypeInfoCount(IHTMLStorage *iface, UINT *pctinfo)
99 {
100 HTMLStorage *This = impl_from_IHTMLStorage(iface);
101 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
102 }
103
104 static HRESULT WINAPI HTMLStorage_GetTypeInfo(IHTMLStorage *iface, UINT iTInfo,
105 LCID lcid, ITypeInfo **ppTInfo)
106 {
107 HTMLStorage *This = impl_from_IHTMLStorage(iface);
108
109 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
110 }
111
112 static HRESULT WINAPI HTMLStorage_GetIDsOfNames(IHTMLStorage *iface, REFIID riid, LPOLESTR *rgszNames, UINT cNames,
113 LCID lcid, DISPID *rgDispId)
114 {
115 HTMLStorage *This = impl_from_IHTMLStorage(iface);
116
117 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
118 lcid, rgDispId);
119 }
120
121 static HRESULT WINAPI HTMLStorage_Invoke(IHTMLStorage *iface, DISPID dispIdMember, REFIID riid, LCID lcid,
122 WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
123 {
124 HTMLStorage *This = impl_from_IHTMLStorage(iface);
125
126 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
127 pDispParams, pVarResult, pExcepInfo, puArgErr);
128 }
129
130 static HRESULT WINAPI HTMLStorage_get_length(IHTMLStorage *iface, LONG *p)
131 {
132 HTMLStorage *This = impl_from_IHTMLStorage(iface);
133 FIXME("(%p)->(%p)\n", This, p);
134 return E_NOTIMPL;
135 }
136
137 static HRESULT WINAPI HTMLStorage_get_remainingSpace(IHTMLStorage *iface, LONG *p)
138 {
139 HTMLStorage *This = impl_from_IHTMLStorage(iface);
140 FIXME("(%p)->(%p)\n", This, p);
141 return E_NOTIMPL;
142 }
143
144 static HRESULT WINAPI HTMLStorage_key(IHTMLStorage *iface, LONG lIndex, BSTR *p)
145 {
146 HTMLStorage *This = impl_from_IHTMLStorage(iface);
147 FIXME("(%p)->(%d %p)\n", This, lIndex, p);
148 return E_NOTIMPL;
149 }
150
151 static HRESULT WINAPI HTMLStorage_getItem(IHTMLStorage *iface, BSTR bstrKey, VARIANT *p)
152 {
153 HTMLStorage *This = impl_from_IHTMLStorage(iface);
154 FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrKey), p);
155 return E_NOTIMPL;
156 }
157
158 static HRESULT WINAPI HTMLStorage_setItem(IHTMLStorage *iface, BSTR bstrKey, BSTR bstrValue)
159 {
160 HTMLStorage *This = impl_from_IHTMLStorage(iface);
161 FIXME("(%p)->(%s %s)\n", This, debugstr_w(bstrKey), debugstr_w(bstrValue));
162 return E_NOTIMPL;
163 }
164
165 static HRESULT WINAPI HTMLStorage_removeItem(IHTMLStorage *iface, BSTR bstrKey)
166 {
167 HTMLStorage *This = impl_from_IHTMLStorage(iface);
168 FIXME("(%p)->(%s)\n", This, debugstr_w(bstrKey));
169 return E_NOTIMPL;
170 }
171
172 static HRESULT WINAPI HTMLStorage_clear(IHTMLStorage *iface)
173 {
174 HTMLStorage *This = impl_from_IHTMLStorage(iface);
175 FIXME("(%p)->()\n", This);
176 return E_NOTIMPL;
177 }
178
179 static const IHTMLStorageVtbl HTMLStorageVtbl = {
180 HTMLStorage_QueryInterface,
181 HTMLStorage_AddRef,
182 HTMLStorage_Release,
183 HTMLStorage_GetTypeInfoCount,
184 HTMLStorage_GetTypeInfo,
185 HTMLStorage_GetIDsOfNames,
186 HTMLStorage_Invoke,
187 HTMLStorage_get_length,
188 HTMLStorage_get_remainingSpace,
189 HTMLStorage_key,
190 HTMLStorage_getItem,
191 HTMLStorage_setItem,
192 HTMLStorage_removeItem,
193 HTMLStorage_clear
194 };
195
196 static const tid_t HTMLStorage_iface_tids[] = {
197 IHTMLStorage_tid,
198 0
199 };
200 static dispex_static_data_t HTMLStorage_dispex = {
201 NULL,
202 IHTMLStorage_tid,
203 NULL,
204 HTMLStorage_iface_tids
205 };
206
207 HRESULT create_storage(IHTMLStorage **p)
208 {
209 HTMLStorage *storage;
210
211 storage = heap_alloc_zero(sizeof(*storage));
212 if(!storage)
213 return E_OUTOFMEMORY;
214
215 storage->IHTMLStorage_iface.lpVtbl = &HTMLStorageVtbl;
216 storage->ref = 1;
217 init_dispex(&storage->dispex, (IUnknown*)&storage->IHTMLStorage_iface, &HTMLStorage_dispex);
218
219 *p = &storage->IHTMLStorage_iface;
220 return S_OK;
221 }