2 * Copyright 2006 Jacek Caban for CodeWeavers
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.
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.
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
30 #include "wine/debug.h"
32 #include "mshtml_private.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
36 typedef struct load_opt
{
41 struct load_opt
*next
;
45 IHtmlLoadOptions IHtmlLoadOptions_iface
;
52 static inline HTMLLoadOptions
*impl_from_IHtmlLoadOptions(IHtmlLoadOptions
*iface
)
54 return CONTAINING_RECORD(iface
, HTMLLoadOptions
, IHtmlLoadOptions_iface
);
57 static HRESULT WINAPI
HtmlLoadOptions_QueryInterface(IHtmlLoadOptions
*iface
,
58 REFIID riid
, void **ppv
)
60 HTMLLoadOptions
*This
= impl_from_IHtmlLoadOptions(iface
);
62 TRACE("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
64 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
65 *ppv
= &This
->IHtmlLoadOptions_iface
;
66 }else if(IsEqualGUID(&IID_IOptionArray
, riid
)) {
67 *ppv
= &This
->IHtmlLoadOptions_iface
;
68 }else if(IsEqualGUID(&IID_IHtmlLoadOptions
, riid
)) {
69 *ppv
= &This
->IHtmlLoadOptions_iface
;
72 WARN("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
76 IUnknown_AddRef((IUnknown
*)*ppv
);
80 static ULONG WINAPI
HtmlLoadOptions_AddRef(IHtmlLoadOptions
*iface
)
82 HTMLLoadOptions
*This
= impl_from_IHtmlLoadOptions(iface
);
83 LONG ref
= InterlockedIncrement(&This
->ref
);
85 TRACE("(%p) ref=%ld\n", This
, ref
);
90 static ULONG WINAPI
HtmlLoadOptions_Release(IHtmlLoadOptions
*iface
)
92 HTMLLoadOptions
*This
= impl_from_IHtmlLoadOptions(iface
);
93 LONG ref
= InterlockedDecrement(&This
->ref
);
95 TRACE("(%p) ref=%ld\n", This
, ref
);
98 load_opt
*iter
= This
->opts
, *last
;
114 static HRESULT WINAPI
HtmlLoadOptions_QueryOption(IHtmlLoadOptions
*iface
, DWORD dwOption
,
115 LPVOID pBuffer
, ULONG
*pcbBuf
)
117 HTMLLoadOptions
*This
= impl_from_IHtmlLoadOptions(iface
);
120 TRACE("(%p)->(%ld %p %p)\n", This
, dwOption
, pBuffer
, pcbBuf
);
122 for(iter
= This
->opts
; iter
; iter
= iter
->next
) {
123 if(iter
->option
== dwOption
)
132 if(*pcbBuf
< iter
->size
) {
133 *pcbBuf
= iter
->size
;
137 memcpy(pBuffer
, iter
->buffer
, iter
->size
);
138 *pcbBuf
= iter
->size
;
143 static HRESULT WINAPI
HtmlLoadOptions_SetOption(IHtmlLoadOptions
*iface
, DWORD dwOption
,
144 LPVOID pBuffer
, ULONG cbBuf
)
146 HTMLLoadOptions
*This
= impl_from_IHtmlLoadOptions(iface
);
147 load_opt
*iter
= NULL
;
149 TRACE("(%p)->(%ld %p %ld)\n", This
, dwOption
, pBuffer
, cbBuf
);
151 for(iter
= This
->opts
; iter
; iter
= iter
->next
) {
152 if(iter
->option
== dwOption
)
157 iter
= malloc(sizeof(load_opt
));
158 iter
->next
= This
->opts
;
161 iter
->option
= dwOption
;
174 iter
->buffer
= malloc(cbBuf
);
175 memcpy(iter
->buffer
, pBuffer
, iter
->size
);
180 static const IHtmlLoadOptionsVtbl HtmlLoadOptionsVtbl
= {
181 HtmlLoadOptions_QueryInterface
,
182 HtmlLoadOptions_AddRef
,
183 HtmlLoadOptions_Release
,
184 HtmlLoadOptions_QueryOption
,
185 HtmlLoadOptions_SetOption
188 HRESULT
HTMLLoadOptions_Create(IUnknown
*pUnkOuter
, REFIID riid
, void** ppv
)
190 HTMLLoadOptions
*ret
;
193 TRACE("(%p %s %p)\n", pUnkOuter
, debugstr_mshtml_guid(riid
), ppv
);
195 ret
= malloc(sizeof(HTMLLoadOptions
));
197 return E_OUTOFMEMORY
;
199 ret
->IHtmlLoadOptions_iface
.lpVtbl
= &HtmlLoadOptionsVtbl
;
203 hres
= IHtmlLoadOptions_QueryInterface(&ret
->IHtmlLoadOptions_iface
, riid
, ppv
);
204 IHtmlLoadOptions_Release(&ret
->IHtmlLoadOptions_iface
);