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