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
);
64 TRACE("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
66 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
67 *ppv
= &This
->IHtmlLoadOptions_iface
;
68 }else if(IsEqualGUID(&IID_IOptionArray
, riid
)) {
69 *ppv
= &This
->IHtmlLoadOptions_iface
;
70 }else if(IsEqualGUID(&IID_IHtmlLoadOptions
, riid
)) {
71 *ppv
= &This
->IHtmlLoadOptions_iface
;
74 WARN("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
78 IUnknown_AddRef((IUnknown
*)*ppv
);
82 static ULONG WINAPI
HtmlLoadOptions_AddRef(IHtmlLoadOptions
*iface
)
84 HTMLLoadOptions
*This
= impl_from_IHtmlLoadOptions(iface
);
85 LONG ref
= InterlockedIncrement(&This
->ref
);
87 TRACE("(%p) ref=%d\n", This
, ref
);
92 static ULONG WINAPI
HtmlLoadOptions_Release(IHtmlLoadOptions
*iface
)
94 HTMLLoadOptions
*This
= impl_from_IHtmlLoadOptions(iface
);
95 LONG ref
= InterlockedDecrement(&This
->ref
);
97 TRACE("(%p) ref=%d\n", This
, ref
);
100 load_opt
*iter
= This
->opts
, *last
;
106 heap_free(last
->buffer
);
116 static HRESULT WINAPI
HtmlLoadOptions_QueryOption(IHtmlLoadOptions
*iface
, DWORD dwOption
,
117 LPVOID pBuffer
, ULONG
*pcbBuf
)
119 HTMLLoadOptions
*This
= impl_from_IHtmlLoadOptions(iface
);
122 TRACE("(%p)->(%d %p %p)\n", This
, dwOption
, pBuffer
, pcbBuf
);
124 for(iter
= This
->opts
; iter
; iter
= iter
->next
) {
125 if(iter
->option
== dwOption
)
134 if(*pcbBuf
< iter
->size
) {
135 *pcbBuf
= iter
->size
;
139 memcpy(pBuffer
, iter
->buffer
, iter
->size
);
140 *pcbBuf
= iter
->size
;
145 static HRESULT WINAPI
HtmlLoadOptions_SetOption(IHtmlLoadOptions
*iface
, DWORD dwOption
,
146 LPVOID pBuffer
, ULONG cbBuf
)
148 HTMLLoadOptions
*This
= impl_from_IHtmlLoadOptions(iface
);
149 load_opt
*iter
= NULL
;
151 TRACE("(%p)->(%d %p %d)\n", This
, dwOption
, pBuffer
, cbBuf
);
153 for(iter
= This
->opts
; iter
; iter
= iter
->next
) {
154 if(iter
->option
== dwOption
)
159 iter
= heap_alloc(sizeof(load_opt
));
160 iter
->next
= This
->opts
;
163 iter
->option
= dwOption
;
165 heap_free(iter
->buffer
);
176 iter
->buffer
= heap_alloc(cbBuf
);
177 memcpy(iter
->buffer
, pBuffer
, iter
->size
);
182 static const IHtmlLoadOptionsVtbl HtmlLoadOptionsVtbl
= {
183 HtmlLoadOptions_QueryInterface
,
184 HtmlLoadOptions_AddRef
,
185 HtmlLoadOptions_Release
,
186 HtmlLoadOptions_QueryOption
,
187 HtmlLoadOptions_SetOption
190 HRESULT
HTMLLoadOptions_Create(IUnknown
*pUnkOuter
, REFIID riid
, void** ppv
)
192 HTMLLoadOptions
*ret
;
195 TRACE("(%p %s %p)\n", pUnkOuter
, debugstr_mshtml_guid(riid
), ppv
);
197 ret
= heap_alloc(sizeof(HTMLLoadOptions
));
199 return E_OUTOFMEMORY
;
201 ret
->IHtmlLoadOptions_iface
.lpVtbl
= &HtmlLoadOptionsVtbl
;
205 hres
= IHtmlLoadOptions_QueryInterface(&ret
->IHtmlLoadOptions_iface
, riid
, ppv
);
206 IHtmlLoadOptions_Release(&ret
->IHtmlLoadOptions_iface
);