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 const IHtmlLoadOptionsVtbl
*lpHtmlLoadOptionsVtbl
;
54 #define LOADOPTS(x) ((IHtmlLoadOptions*) &(x)->lpHtmlLoadOptionsVtbl)
56 #define LOADOPTS_THIS(iface) DEFINE_THIS(HTMLLoadOptions, HtmlLoadOptions, iface)
58 static HRESULT WINAPI
HtmlLoadOptions_QueryInterface(IHtmlLoadOptions
*iface
,
59 REFIID riid
, void **ppv
)
61 HTMLLoadOptions
*This
= LOADOPTS_THIS(iface
);
65 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
66 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
67 *ppv
= LOADOPTS(This
);
68 }else if(IsEqualGUID(&IID_IOptionArray
, riid
)) {
69 TRACE("(%p)->(IID_IOptionArray %p)\n", This
, ppv
);
70 *ppv
= LOADOPTS(This
);
71 }else if(IsEqualGUID(&IID_IHtmlLoadOptions
, riid
)) {
72 TRACE("(%p)->(IID_IHtmlLoadOptions %p)\n", This
, ppv
);
73 *ppv
= LOADOPTS(This
);
77 IHtmlLoadOptions_AddRef(LOADOPTS(This
));
81 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
85 static ULONG WINAPI
HtmlLoadOptions_AddRef(IHtmlLoadOptions
*iface
)
87 HTMLLoadOptions
*This
= LOADOPTS_THIS(iface
);
88 LONG ref
= InterlockedIncrement(&This
->ref
);
90 TRACE("(%p) ref=%d\n", This
, ref
);
95 static ULONG WINAPI
HtmlLoadOptions_Release(IHtmlLoadOptions
*iface
)
97 HTMLLoadOptions
*This
= LOADOPTS_THIS(iface
);
98 LONG ref
= InterlockedDecrement(&This
->ref
);
100 TRACE("(%p) ref=%d\n", This
, ref
);
103 load_opt
*iter
= This
->opts
, *last
;
109 heap_free(last
->buffer
);
119 static HRESULT WINAPI
HtmlLoadOptions_QueryOption(IHtmlLoadOptions
*iface
, DWORD dwOption
,
120 LPVOID pBuffer
, ULONG
*pcbBuf
)
122 HTMLLoadOptions
*This
= LOADOPTS_THIS(iface
);
125 TRACE("(%p)->(%d %p %p)\n", This
, dwOption
, pBuffer
, pcbBuf
);
127 for(iter
= This
->opts
; iter
; iter
= iter
->next
) {
128 if(iter
->option
== dwOption
)
137 if(*pcbBuf
< iter
->size
) {
138 *pcbBuf
= iter
->size
;
142 memcpy(pBuffer
, iter
->buffer
, iter
->size
);
143 *pcbBuf
= iter
->size
;
148 static HRESULT WINAPI
HtmlLoadOptions_SetOption(IHtmlLoadOptions
*iface
, DWORD dwOption
,
149 LPVOID pBuffer
, ULONG cbBuf
)
151 HTMLLoadOptions
*This
= LOADOPTS_THIS(iface
);
152 load_opt
*iter
= NULL
;
154 TRACE("(%p)->(%d %p %d)\n", This
, dwOption
, pBuffer
, cbBuf
);
156 for(iter
= This
->opts
; iter
; iter
= iter
->next
) {
157 if(iter
->option
== dwOption
)
162 iter
= heap_alloc(sizeof(load_opt
));
163 iter
->next
= This
->opts
;
166 iter
->option
= dwOption
;
168 heap_free(iter
->buffer
);
179 iter
->buffer
= heap_alloc(cbBuf
);
180 memcpy(iter
->buffer
, pBuffer
, iter
->size
);
187 static const IHtmlLoadOptionsVtbl HtmlLoadOptionsVtbl
= {
188 HtmlLoadOptions_QueryInterface
,
189 HtmlLoadOptions_AddRef
,
190 HtmlLoadOptions_Release
,
191 HtmlLoadOptions_QueryOption
,
192 HtmlLoadOptions_SetOption
195 HRESULT
HTMLLoadOptions_Create(IUnknown
*pUnkOuter
, REFIID riid
, void** ppv
)
197 HTMLLoadOptions
*ret
;
200 TRACE("(%p %s %p)\n", pUnkOuter
, debugstr_guid(riid
), ppv
);
202 ret
= heap_alloc(sizeof(HTMLLoadOptions
));
204 ret
->lpHtmlLoadOptionsVtbl
= &HtmlLoadOptionsVtbl
;
208 hres
= IHtmlLoadOptions_QueryInterface(LOADOPTS(ret
), riid
, ppv
);
209 IHtmlLoadOptions_Release(LOADOPTS(ret
));