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
32 #include "wine/debug.h"
34 #include "mshtml_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
38 typedef struct load_opt
{
43 struct load_opt
*next
;
47 IHtmlLoadOptions IHtmlLoadOptions_iface
;
54 static inline HTMLLoadOptions
*impl_from_IHtmlLoadOptions(IHtmlLoadOptions
*iface
)
56 return CONTAINING_RECORD(iface
, HTMLLoadOptions
, IHtmlLoadOptions_iface
);
59 static HRESULT WINAPI
HtmlLoadOptions_QueryInterface(IHtmlLoadOptions
*iface
,
60 REFIID riid
, void **ppv
)
62 HTMLLoadOptions
*This
= impl_from_IHtmlLoadOptions(iface
);
66 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
67 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
68 *ppv
= &This
->IHtmlLoadOptions_iface
;
69 }else if(IsEqualGUID(&IID_IOptionArray
, riid
)) {
70 TRACE("(%p)->(IID_IOptionArray %p)\n", This
, ppv
);
71 *ppv
= &This
->IHtmlLoadOptions_iface
;
72 }else if(IsEqualGUID(&IID_IHtmlLoadOptions
, riid
)) {
73 TRACE("(%p)->(IID_IHtmlLoadOptions %p)\n", This
, ppv
);
74 *ppv
= &This
->IHtmlLoadOptions_iface
;
78 IHtmlLoadOptions_AddRef(&This
->IHtmlLoadOptions_iface
);
82 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
86 static ULONG WINAPI
HtmlLoadOptions_AddRef(IHtmlLoadOptions
*iface
)
88 HTMLLoadOptions
*This
= impl_from_IHtmlLoadOptions(iface
);
89 LONG ref
= InterlockedIncrement(&This
->ref
);
91 TRACE("(%p) ref=%d\n", This
, ref
);
96 static ULONG WINAPI
HtmlLoadOptions_Release(IHtmlLoadOptions
*iface
)
98 HTMLLoadOptions
*This
= impl_from_IHtmlLoadOptions(iface
);
99 LONG ref
= InterlockedDecrement(&This
->ref
);
101 TRACE("(%p) ref=%d\n", This
, ref
);
104 load_opt
*iter
= This
->opts
, *last
;
110 heap_free(last
->buffer
);
120 static HRESULT WINAPI
HtmlLoadOptions_QueryOption(IHtmlLoadOptions
*iface
, DWORD dwOption
,
121 LPVOID pBuffer
, ULONG
*pcbBuf
)
123 HTMLLoadOptions
*This
= impl_from_IHtmlLoadOptions(iface
);
126 TRACE("(%p)->(%d %p %p)\n", This
, dwOption
, pBuffer
, pcbBuf
);
128 for(iter
= This
->opts
; iter
; iter
= iter
->next
) {
129 if(iter
->option
== dwOption
)
138 if(*pcbBuf
< iter
->size
) {
139 *pcbBuf
= iter
->size
;
143 memcpy(pBuffer
, iter
->buffer
, iter
->size
);
144 *pcbBuf
= iter
->size
;
149 static HRESULT WINAPI
HtmlLoadOptions_SetOption(IHtmlLoadOptions
*iface
, DWORD dwOption
,
150 LPVOID pBuffer
, ULONG cbBuf
)
152 HTMLLoadOptions
*This
= impl_from_IHtmlLoadOptions(iface
);
153 load_opt
*iter
= NULL
;
155 TRACE("(%p)->(%d %p %d)\n", This
, dwOption
, pBuffer
, cbBuf
);
157 for(iter
= This
->opts
; iter
; iter
= iter
->next
) {
158 if(iter
->option
== dwOption
)
163 iter
= heap_alloc(sizeof(load_opt
));
164 iter
->next
= This
->opts
;
167 iter
->option
= dwOption
;
169 heap_free(iter
->buffer
);
180 iter
->buffer
= heap_alloc(cbBuf
);
181 memcpy(iter
->buffer
, pBuffer
, iter
->size
);
186 static const IHtmlLoadOptionsVtbl HtmlLoadOptionsVtbl
= {
187 HtmlLoadOptions_QueryInterface
,
188 HtmlLoadOptions_AddRef
,
189 HtmlLoadOptions_Release
,
190 HtmlLoadOptions_QueryOption
,
191 HtmlLoadOptions_SetOption
194 HRESULT
HTMLLoadOptions_Create(IUnknown
*pUnkOuter
, REFIID riid
, void** ppv
)
196 HTMLLoadOptions
*ret
;
199 TRACE("(%p %s %p)\n", pUnkOuter
, debugstr_guid(riid
), ppv
);
201 ret
= heap_alloc(sizeof(HTMLLoadOptions
));
203 ret
->IHtmlLoadOptions_iface
.lpVtbl
= &HtmlLoadOptionsVtbl
;
207 hres
= IHtmlLoadOptions_QueryInterface(&ret
->IHtmlLoadOptions_iface
, riid
, ppv
);
208 IHtmlLoadOptions_Release(&ret
->IHtmlLoadOptions_iface
);