1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
/*
* Implementation of event-related interfaces for WebBrowser control:
*
* - IConnectionPointContainer
* - IConnectionPoint
*
* Copyright 2001 John R. Sheets (for CodeWeavers)
* 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 <string.h>
#include "wine/debug.h"
#include "shdocvw.h"
WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
struct ConnectionPoint {
IConnectionPoint IConnectionPoint_iface;
IConnectionPointContainer *container;
IDispatch **sinks;
DWORD sinks_size;
IID iid;
};
/**********************************************************************
* Implement the IConnectionPointContainer interface
*/
static inline ConnectionPointContainer *impl_from_IConnectionPointContainer(IConnectionPointContainer *iface)
{
return CONTAINING_RECORD(iface, ConnectionPointContainer, IConnectionPointContainer_iface);
}
static HRESULT WINAPI ConnectionPointContainer_QueryInterface(IConnectionPointContainer *iface,
REFIID riid, LPVOID *ppv)
{
ConnectionPointContainer *This = impl_from_IConnectionPointContainer(iface);
return IUnknown_QueryInterface(This->impl, riid, ppv);
}
static ULONG WINAPI ConnectionPointContainer_AddRef(IConnectionPointContainer *iface)
{
ConnectionPointContainer *This = impl_from_IConnectionPointContainer(iface);
return IUnknown_AddRef(This->impl);
}
static ULONG WINAPI ConnectionPointContainer_Release(IConnectionPointContainer *iface)
{
ConnectionPointContainer *This = impl_from_IConnectionPointContainer(iface);
return IUnknown_Release(This->impl);
}
static HRESULT WINAPI ConnectionPointContainer_EnumConnectionPoints(IConnectionPointContainer *iface,
LPENUMCONNECTIONPOINTS *ppEnum)
{
ConnectionPointContainer *This = impl_from_IConnectionPointContainer(iface);
FIXME("(%p)->(%p)\n", This, ppEnum);
return E_NOTIMPL;
}
static HRESULT WINAPI ConnectionPointContainer_FindConnectionPoint(IConnectionPointContainer *iface,
REFIID riid, LPCONNECTIONPOINT *ppCP)
{
ConnectionPointContainer *This = impl_from_IConnectionPointContainer(iface);
if(!ppCP) {
WARN("ppCP == NULL\n");
return E_POINTER;
}
*ppCP = NULL;
if(IsEqualGUID(&DIID_DWebBrowserEvents2, riid)) {
TRACE("(%p)->(DIID_DWebBrowserEvents2 %p)\n", This, ppCP);
*ppCP = &This->wbe2->IConnectionPoint_iface;
}else if(IsEqualGUID(&DIID_DWebBrowserEvents, riid)) {
TRACE("(%p)->(DIID_DWebBrowserEvents %p)\n", This, ppCP);
*ppCP = &This->wbe->IConnectionPoint_iface;
}else if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
TRACE("(%p)->(IID_IPropertyNotifySink %p)\n", This, ppCP);
*ppCP = &This->pns->IConnectionPoint_iface;
}
if(*ppCP) {
IConnectionPoint_AddRef(*ppCP);
return S_OK;
}
WARN("Unsupported IID %s\n", debugstr_guid(riid));
return CONNECT_E_NOCONNECTION;
}
#undef impl_from_IConnectionPointContainer
static const IConnectionPointContainerVtbl ConnectionPointContainerVtbl =
{
ConnectionPointContainer_QueryInterface,
ConnectionPointContainer_AddRef,
ConnectionPointContainer_Release,
ConnectionPointContainer_EnumConnectionPoints,
ConnectionPointContainer_FindConnectionPoint
};
/**********************************************************************
* Implement the IConnectionPoint interface
*/
static inline ConnectionPoint *impl_from_IConnectionPoint(IConnectionPoint *iface)
{
return CONTAINING_RECORD(iface, ConnectionPoint, IConnectionPoint_iface);
}
static HRESULT WINAPI ConnectionPoint_QueryInterface(IConnectionPoint *iface,
REFIID riid, LPVOID *ppv)
{
ConnectionPoint *This = impl_from_IConnectionPoint(iface);
*ppv = NULL;
if(IsEqualGUID(&IID_IUnknown, riid)) {
TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
*ppv = &This->IConnectionPoint_iface;
}else if(IsEqualGUID(&IID_IConnectionPoint, riid)) {
TRACE("(%p)->(IID_IConnectionPoint %p)\n", This, ppv);
*ppv = &This->IConnectionPoint_iface;
}
if(*ppv) {
IConnectionPointContainer_AddRef(This->container);
return S_OK;
}
WARN("Unsupported interface %s\n", debugstr_guid(riid));
return E_NOINTERFACE;
}
static ULONG WINAPI ConnectionPoint_AddRef(IConnectionPoint *iface)
{
ConnectionPoint *This = impl_from_IConnectionPoint(iface);
return IConnectionPointContainer_AddRef(This->container);
}
static ULONG WINAPI ConnectionPoint_Release(IConnectionPoint *iface)
{
ConnectionPoint *This = impl_from_IConnectionPoint(iface);
return IConnectionPointContainer_Release(This->container);
}
static HRESULT WINAPI ConnectionPoint_GetConnectionInterface(IConnectionPoint *iface, IID *pIID)
{
ConnectionPoint *This = impl_from_IConnectionPoint(iface);
TRACE("(%p)->(%p)\n", This, pIID);
*pIID = This->iid;
return S_OK;
}
static HRESULT WINAPI ConnectionPoint_GetConnectionPointContainer(IConnectionPoint *iface,
IConnectionPointContainer **ppCPC)
{
ConnectionPoint *This = impl_from_IConnectionPoint(iface);
TRACE("(%p)->(%p)\n", This, ppCPC);
*ppCPC = This->container;
IConnectionPointContainer_AddRef(This->container);
return S_OK;
}
static HRESULT WINAPI ConnectionPoint_Advise(IConnectionPoint *iface, IUnknown *pUnkSink,
DWORD *pdwCookie)
{
ConnectionPoint *This = impl_from_IConnectionPoint(iface);
IDispatch *disp;
DWORD i;
HRESULT hres;
TRACE("(%p)->(%p %p)\n", This, pUnkSink, pdwCookie);
hres = IUnknown_QueryInterface(pUnkSink, &This->iid, (void**)&disp);
if(FAILED(hres)) {
hres = IUnknown_QueryInterface(pUnkSink, &IID_IDispatch, (void**)&disp);
if(FAILED(hres))
return CONNECT_E_CANNOTCONNECT;
}
if(This->sinks) {
for(i=0; i<This->sinks_size; i++) {
if(!This->sinks[i])
break;
}
if(i == This->sinks_size)
This->sinks = heap_realloc(This->sinks,
(++This->sinks_size)*sizeof(*This->sinks));
}else {
This->sinks = heap_alloc(sizeof(*This->sinks));
This->sinks_size = 1;
i = 0;
}
This->sinks[i] = disp;
*pdwCookie = i+1;
return S_OK;
}
static HRESULT WINAPI ConnectionPoint_Unadvise(IConnectionPoint *iface, DWORD dwCookie)
{
ConnectionPoint *This = impl_from_IConnectionPoint(iface);
TRACE("(%p)->(%d)\n", This, dwCookie);
if(!dwCookie || dwCookie > This->sinks_size || !This->sinks[dwCookie-1])
return CONNECT_E_NOCONNECTION;
IDispatch_Release(This->sinks[dwCookie-1]);
This->sinks[dwCookie-1] = NULL;
return S_OK;
}
static HRESULT WINAPI ConnectionPoint_EnumConnections(IConnectionPoint *iface,
IEnumConnections **ppEnum)
{
ConnectionPoint *This = impl_from_IConnectionPoint(iface);
FIXME("(%p)->(%p)\n", This, ppEnum);
return E_NOTIMPL;
}
static const IConnectionPointVtbl ConnectionPointVtbl =
{
ConnectionPoint_QueryInterface,
ConnectionPoint_AddRef,
ConnectionPoint_Release,
ConnectionPoint_GetConnectionInterface,
ConnectionPoint_GetConnectionPointContainer,
ConnectionPoint_Advise,
ConnectionPoint_Unadvise,
ConnectionPoint_EnumConnections
};
void call_sink(ConnectionPoint *This, DISPID dispid, DISPPARAMS *dispparams)
{
DWORD i;
for(i=0; i<This->sinks_size; i++) {
if(This->sinks[i])
IDispatch_Invoke(This->sinks[i], dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
DISPATCH_METHOD, dispparams, NULL, NULL, NULL);
}
}
static void ConnectionPoint_Create(REFIID riid, ConnectionPoint **cp,
IConnectionPointContainer *container)
{
ConnectionPoint *ret = heap_alloc(sizeof(ConnectionPoint));
ret->IConnectionPoint_iface.lpVtbl = &ConnectionPointVtbl;
ret->sinks = NULL;
ret->sinks_size = 0;
ret->container = container;
ret->iid = *riid;
*cp = ret;
}
static void ConnectionPoint_Destroy(ConnectionPoint *This)
{
DWORD i;
for(i=0; i<This->sinks_size; i++) {
if(This->sinks[i])
IDispatch_Release(This->sinks[i]);
}
heap_free(This->sinks);
heap_free(This);
}
void ConnectionPointContainer_Init(ConnectionPointContainer *This, IUnknown *impl)
{
This->IConnectionPointContainer_iface.lpVtbl = &ConnectionPointContainerVtbl;
ConnectionPoint_Create(&DIID_DWebBrowserEvents2, &This->wbe2, &This->IConnectionPointContainer_iface);
ConnectionPoint_Create(&DIID_DWebBrowserEvents, &This->wbe, &This->IConnectionPointContainer_iface);
ConnectionPoint_Create(&IID_IPropertyNotifySink, &This->pns, &This->IConnectionPointContainer_iface);
This->impl = impl;
}
void ConnectionPointContainer_Destroy(ConnectionPointContainer *This)
{
ConnectionPoint_Destroy(This->wbe2);
ConnectionPoint_Destroy(This->wbe);
ConnectionPoint_Destroy(This->pns);
}