2006-06-22 16:14:14 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2006 Jacek Caban for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "ole2.h"
|
|
|
|
#include "optary.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
#include "mshtml_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
|
|
|
|
|
2006-06-23 22:12:48 +02:00
|
|
|
typedef struct load_opt {
|
|
|
|
DWORD option;
|
|
|
|
PVOID buffer;
|
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
struct load_opt *next;
|
|
|
|
} load_opt;
|
|
|
|
|
2006-06-22 16:14:14 +02:00
|
|
|
typedef struct {
|
2010-12-06 23:32:10 +01:00
|
|
|
IHtmlLoadOptions IHtmlLoadOptions_iface;
|
2006-06-22 16:14:14 +02:00
|
|
|
|
|
|
|
LONG ref;
|
2006-06-23 22:12:48 +02:00
|
|
|
|
|
|
|
load_opt *opts;
|
2006-06-22 16:14:14 +02:00
|
|
|
} HTMLLoadOptions;
|
|
|
|
|
2010-12-06 23:32:10 +01:00
|
|
|
static inline HTMLLoadOptions *impl_from_IHtmlLoadOptions(IHtmlLoadOptions *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, HTMLLoadOptions, IHtmlLoadOptions_iface);
|
|
|
|
}
|
2006-06-22 16:14:14 +02:00
|
|
|
|
|
|
|
static HRESULT WINAPI HtmlLoadOptions_QueryInterface(IHtmlLoadOptions *iface,
|
|
|
|
REFIID riid, void **ppv)
|
|
|
|
{
|
2010-12-06 23:32:10 +01:00
|
|
|
HTMLLoadOptions *This = impl_from_IHtmlLoadOptions(iface);
|
2006-06-22 16:14:14 +02:00
|
|
|
|
2014-05-09 13:08:48 +02:00
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
|
2006-06-22 16:14:14 +02:00
|
|
|
|
|
|
|
if(IsEqualGUID(&IID_IUnknown, riid)) {
|
2010-12-06 23:32:10 +01:00
|
|
|
*ppv = &This->IHtmlLoadOptions_iface;
|
2006-06-22 16:14:14 +02:00
|
|
|
}else if(IsEqualGUID(&IID_IOptionArray, riid)) {
|
2010-12-06 23:32:10 +01:00
|
|
|
*ppv = &This->IHtmlLoadOptions_iface;
|
2006-06-22 16:14:14 +02:00
|
|
|
}else if(IsEqualGUID(&IID_IHtmlLoadOptions, riid)) {
|
2010-12-06 23:32:10 +01:00
|
|
|
*ppv = &This->IHtmlLoadOptions_iface;
|
2014-05-09 13:08:48 +02:00
|
|
|
}else {
|
|
|
|
*ppv = NULL;
|
|
|
|
WARN("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
|
|
|
|
return E_NOINTERFACE;
|
2006-06-22 16:14:14 +02:00
|
|
|
}
|
|
|
|
|
2014-05-09 13:08:48 +02:00
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
2006-06-22 16:14:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI HtmlLoadOptions_AddRef(IHtmlLoadOptions *iface)
|
|
|
|
{
|
2010-12-06 23:32:10 +01:00
|
|
|
HTMLLoadOptions *This = impl_from_IHtmlLoadOptions(iface);
|
2006-06-22 16:14:14 +02:00
|
|
|
LONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
2006-10-05 23:50:39 +02:00
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
2006-06-22 16:14:14 +02:00
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI HtmlLoadOptions_Release(IHtmlLoadOptions *iface)
|
|
|
|
{
|
2010-12-06 23:32:10 +01:00
|
|
|
HTMLLoadOptions *This = impl_from_IHtmlLoadOptions(iface);
|
2006-06-22 16:14:14 +02:00
|
|
|
LONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
2006-10-05 23:50:39 +02:00
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
2006-06-22 16:14:14 +02:00
|
|
|
|
2006-06-23 22:12:48 +02:00
|
|
|
if(!ref) {
|
|
|
|
load_opt *iter = This->opts, *last;
|
|
|
|
|
|
|
|
while(iter) {
|
|
|
|
last = iter;
|
|
|
|
iter = iter->next;
|
|
|
|
|
2007-12-05 21:52:31 +01:00
|
|
|
heap_free(last->buffer);
|
|
|
|
heap_free(last);
|
2006-06-23 22:12:48 +02:00
|
|
|
}
|
|
|
|
|
2007-12-05 21:52:31 +01:00
|
|
|
heap_free(This);
|
2006-06-23 22:12:48 +02:00
|
|
|
}
|
2006-06-22 16:14:14 +02:00
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HtmlLoadOptions_QueryOption(IHtmlLoadOptions *iface, DWORD dwOption,
|
|
|
|
LPVOID pBuffer, ULONG *pcbBuf)
|
|
|
|
{
|
2010-12-06 23:32:10 +01:00
|
|
|
HTMLLoadOptions *This = impl_from_IHtmlLoadOptions(iface);
|
2006-06-23 22:12:48 +02:00
|
|
|
load_opt *iter;
|
|
|
|
|
2006-10-05 23:50:39 +02:00
|
|
|
TRACE("(%p)->(%d %p %p)\n", This, dwOption, pBuffer, pcbBuf);
|
2006-06-23 22:12:48 +02:00
|
|
|
|
|
|
|
for(iter = This->opts; iter; iter = iter->next) {
|
|
|
|
if(iter->option == dwOption)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!iter) {
|
|
|
|
*pcbBuf = 0;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(*pcbBuf < iter->size) {
|
|
|
|
*pcbBuf = iter->size;
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(pBuffer, iter->buffer, iter->size);
|
|
|
|
*pcbBuf = iter->size;
|
|
|
|
|
|
|
|
return S_OK;
|
2006-06-22 16:14:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HtmlLoadOptions_SetOption(IHtmlLoadOptions *iface, DWORD dwOption,
|
|
|
|
LPVOID pBuffer, ULONG cbBuf)
|
|
|
|
{
|
2010-12-06 23:32:10 +01:00
|
|
|
HTMLLoadOptions *This = impl_from_IHtmlLoadOptions(iface);
|
2006-06-23 22:12:48 +02:00
|
|
|
load_opt *iter = NULL;
|
|
|
|
|
2006-10-05 23:50:39 +02:00
|
|
|
TRACE("(%p)->(%d %p %d)\n", This, dwOption, pBuffer, cbBuf);
|
2006-06-23 22:12:48 +02:00
|
|
|
|
|
|
|
for(iter = This->opts; iter; iter = iter->next) {
|
|
|
|
if(iter->option == dwOption)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!iter) {
|
2007-12-05 21:52:31 +01:00
|
|
|
iter = heap_alloc(sizeof(load_opt));
|
2006-06-23 22:12:48 +02:00
|
|
|
iter->next = This->opts;
|
|
|
|
This->opts = iter;
|
|
|
|
|
|
|
|
iter->option = dwOption;
|
|
|
|
}else {
|
2007-12-05 21:52:31 +01:00
|
|
|
heap_free(iter->buffer);
|
2006-06-23 22:12:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!cbBuf) {
|
|
|
|
iter->buffer = NULL;
|
|
|
|
iter->size = 0;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
iter->size = cbBuf;
|
2007-12-05 21:52:31 +01:00
|
|
|
iter->buffer = heap_alloc(cbBuf);
|
2006-06-23 22:12:48 +02:00
|
|
|
memcpy(iter->buffer, pBuffer, iter->size);
|
|
|
|
|
|
|
|
return S_OK;
|
2006-06-22 16:14:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IHtmlLoadOptionsVtbl HtmlLoadOptionsVtbl = {
|
|
|
|
HtmlLoadOptions_QueryInterface,
|
|
|
|
HtmlLoadOptions_AddRef,
|
|
|
|
HtmlLoadOptions_Release,
|
|
|
|
HtmlLoadOptions_QueryOption,
|
|
|
|
HtmlLoadOptions_SetOption
|
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT HTMLLoadOptions_Create(IUnknown *pUnkOuter, REFIID riid, void** ppv)
|
|
|
|
{
|
|
|
|
HTMLLoadOptions *ret;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2014-05-09 13:08:48 +02:00
|
|
|
TRACE("(%p %s %p)\n", pUnkOuter, debugstr_mshtml_guid(riid), ppv);
|
2006-06-22 16:14:14 +02:00
|
|
|
|
2007-12-05 21:52:31 +01:00
|
|
|
ret = heap_alloc(sizeof(HTMLLoadOptions));
|
2014-05-09 13:08:48 +02:00
|
|
|
if(!ret)
|
|
|
|
return E_OUTOFMEMORY;
|
2006-06-22 16:14:14 +02:00
|
|
|
|
2010-12-06 23:32:10 +01:00
|
|
|
ret->IHtmlLoadOptions_iface.lpVtbl = &HtmlLoadOptionsVtbl;
|
2006-06-22 16:14:14 +02:00
|
|
|
ret->ref = 1;
|
2006-06-23 22:12:48 +02:00
|
|
|
ret->opts = NULL;
|
2006-06-22 16:14:14 +02:00
|
|
|
|
2010-12-06 23:32:10 +01:00
|
|
|
hres = IHtmlLoadOptions_QueryInterface(&ret->IHtmlLoadOptions_iface, riid, ppv);
|
|
|
|
IHtmlLoadOptions_Release(&ret->IHtmlLoadOptions_iface);
|
2006-06-22 16:14:14 +02:00
|
|
|
return hres;
|
|
|
|
}
|