/
FBControl.h
625 lines (533 loc) · 26.3 KB
/
FBControl.h
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
/**********************************************************\
Original Author: Richard Bateman (taxilian)
Created: Sept 17, 2009
License: Dual license model; choose one of two:
New BSD License
http://www.opensource.org/licenses/bsd-license.php
- or -
GNU Lesser General Public License, version 2.1
http://www.gnu.org/licenses/lgpl-2.1.html
Copyright 2009 Richard Bateman, Firebreath development team
\**********************************************************/
// FBControl.h : Declaration of the CFBControl
#pragma once
#ifndef H_FBCONTROL
#define H_FBCONTROL
#include "win_common.h"
#include "win_targetver.h"
#include <atlctl.h>
#include <ShlGuid.h>
#include <mshtml.h>
#include <boost/algorithm/string.hpp>
#include <boost/cast.hpp>
#include <boost/scoped_array.hpp>
#include "DOM/Window.h"
#include "FactoryBase.h"
#include "logging.h"
#include "JSAPI_IDispatchEx.h"
#include "PluginInfo.h"
#include "ShareableReference.h"
#include "BrowserPlugin.h"
#include "PluginCore.h"
#include "Win/WindowContextWin.h"
#ifdef FBWIN_ASYNCSURFACE
#include "ActiveXAsyncDrawService.h"
#endif
#include "registrymap.hpp"
extern std::string g_dllPath;
// CFBControl
namespace FB {
namespace ActiveX {
class ActiveXBrowserHost;
typedef boost::shared_ptr<ActiveXBrowserHost> ActiveXBrowserHostPtr;
void flagStaticInitialized(bool init = true);
bool isStaticInitialized();
template <const GUID* pFbCLSID, const char* pMT, class ICurObjInterface, const IID* piid, const GUID* plibid>
class ATL_NO_VTABLE CFBControl :
public CComObjectRootEx<CComMultiThreadModel>,
public CComCoClass<CFBControl<pFbCLSID,pMT,ICurObjInterface,piid,plibid>, pFbCLSID >,
public CComControl<CFBControl<pFbCLSID,pMT,ICurObjInterface,piid,plibid> >,
public JSAPI_IDispatchEx< CFBControl<pFbCLSID,pMT,ICurObjInterface,piid,plibid>, ICurObjInterface, piid>,
// Required for standard events
public IProvideClassInfo2Impl<pFbCLSID, NULL, plibid>,
public IObjectSafety,
//public IPersistStreamInitImpl<CFBControl<pFbCLSID,pMT> >,
public IOleControlImpl<CFBControl<pFbCLSID,pMT,ICurObjInterface,piid,plibid> >,
public IOleObjectImpl<CFBControl<pFbCLSID,pMT,ICurObjInterface,piid,plibid> >,
public IOleInPlaceActiveObjectImpl<CFBControl<pFbCLSID,pMT,ICurObjInterface,piid,plibid> >,
public IQuickActivateImpl<CFBControl<pFbCLSID,pMT,ICurObjInterface,piid,plibid> >,
public IViewObjectExImpl<CFBControl<pFbCLSID,pMT,ICurObjInterface,piid,plibid> >,
public IOleInPlaceObjectWindowlessImpl<CFBControl<pFbCLSID,pMT,ICurObjInterface,piid,plibid> >,
public IObjectWithSiteImpl<CFBControl<pFbCLSID,pMT,ICurObjInterface,piid,plibid> >,
// Provides methods for getting <params>
public IPersistPropertyBag,
#ifdef FBWIN_ASYNCSURFACE
public IViewObjectPresentNotify,
#endif
public FB::BrowserPlugin
{
public:
typedef CFBControl<pFbCLSID,pMT,ICurObjInterface,piid,plibid> CFBControlX;
protected:
boost::scoped_ptr<FB::PluginWindow> pluginWin;
CComQIPtr<IServiceProvider> m_serviceProvider;
CComQIPtr<IWebBrowser2> m_webBrowser;
const std::string m_mimetype;
DWORD m_dwCurrentSafety;
ActiveXBrowserHostPtr m_host;
bool m_setReadyDone;
#ifdef FBWIN_ASYNCSURFACE
CComPtr<IViewObjectPresentSite> m_viewObjectPresentSite;
#endif
protected:
public:
// The methods in this class are positioned in this file in the
// rough order that they will be called in.
CFBControl() : JSAPI_IDispatchEx<CFBControlX, ICurObjInterface, piid>(pMT), FB::BrowserPlugin(pMT),
m_mimetype(pMT),
m_setReadyDone(false)
{
setFSPath(g_dllPath);
}
~CFBControl()
{
}
virtual FB::VariantMap getProperties(const CComQIPtr<IPropertyBag2>& pBag);
virtual void setReady();
virtual void setWindow(HWND);
virtual void clientSiteSet();
virtual DWORD getSupportedObjectSafety();
STDMETHOD(GetInterfaceSafetyOptions)(REFIID riid, DWORD *pdwSupportedOptions,
DWORD *pdwEnabledOptions);
STDMETHOD(SetInterfaceSafetyOptions)(REFIID riid, DWORD dwOptionSetMask,
DWORD dwEnabledOptions);
// Note that the window has not been created yet; this is where we get
// access to the DOM Document and Window
STDMETHOD(SetClientSite)(IOleClientSite *pClientSite);
// This method will only be called if we are instantiated without a window
STDMETHOD(SetSite)(IUnknown *pUnkSite);
STDMETHOD(SetObjectRects)(LPCRECT prcPos, LPCRECT prcClip);
STDMETHOD(InPlaceActivate)(LONG iVerb, const RECT* prcPosRect);
// Called when the control is deactivated when it's time to shut down
STDMETHOD(InPlaceDeactivate)(void);
STDMETHOD(Close)(DWORD dwSaveOption) {
shutdown();
return IOleObjectImpl<CFBControlX>::Close(dwSaveOption);
}
/* IViewObjectPresentNotify calls */
STDMETHOD(OnPreRender)(void) {
return S_OK;
}
/* IPersistPropertyBag calls */
// This will be called once when the browser initializes the property bag (PARAM tags)
// Often (always?) this is only called if there are no items in the property bag
STDMETHOD(InitNew)();
// When this is called, we load any <param> tag values there are
STDMETHOD(Load)(IPropertyBag *pPropBag, IErrorLog *pErrorLog);
// This is called on shutdown
void shutdown();
// This is part of the event system
STDMETHOD(GetClassID)(CLSID *pClassID);
// This is a required method for implementing IPersistPropertyBag, but it shouldn't
// ever get called
STDMETHOD(Save)(IPropertyBag *pPropBag, BOOL fClearDirty, BOOL fSaveAllProperties);
virtual HRESULT OnDraw(ATL_DRAWINFO& di);
void invalidateWindow( uint32_t left, uint32_t top, uint32_t right, uint32_t bottom );
public:
DECLARE_OLEMISC_STATUS(OLEMISC_RECOMPOSEONRESIZE |
OLEMISC_CANTLINKINSIDE |
OLEMISC_INSIDEOUT |
OLEMISC_ACTIVATEWHENVISIBLE |
OLEMISC_SETCLIENTSITEFIRST
)
DECLARE_REGISTRY_RESOURCEID_EX(IDR_FBCONTROL)
BEGIN_REGMAP(CFBControlX)
REGMAP_UUID("LIBID", (*plibid))
//REGMAP_ENTRY("THREADING", "Free")
REGMAP_ENTRY("THREADING", "Apartment")
//REGMAP_ENTRY("THREADING", "Single")
END_REGMAP()
DECLARE_NOT_AGGREGATABLE(CFBControlX)
BEGIN_COM_MAP(CFBControlX)
COM_INTERFACE_ENTRY_IID((*piid), ICurObjInterface)
COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(IDispatchEx)
COM_INTERFACE_ENTRY(IFireBreathObject)
COM_INTERFACE_ENTRY(IViewObjectEx)
COM_INTERFACE_ENTRY(IViewObject2)
COM_INTERFACE_ENTRY(IViewObject)
COM_INTERFACE_ENTRY(IOleInPlaceObjectWindowless)
COM_INTERFACE_ENTRY(IOleInPlaceObject)
COM_INTERFACE_ENTRY2(IOleWindow, IOleInPlaceObjectWindowless)
COM_INTERFACE_ENTRY(IOleInPlaceActiveObject)
COM_INTERFACE_ENTRY(IOleControl)
COM_INTERFACE_ENTRY(IOleObject)
COM_INTERFACE_ENTRY(IConnectionPointContainer)
COM_INTERFACE_ENTRY(IConnectionPoint)
COM_INTERFACE_ENTRY(IQuickActivate)
COM_INTERFACE_ENTRY(IObjectWithSite)
COM_INTERFACE_ENTRY(IObjectSafety)
COM_INTERFACE_ENTRY(IPersistPropertyBag)
COM_INTERFACE_ENTRY(IProvideClassInfo)
COM_INTERFACE_ENTRY(IProvideClassInfo2)
END_COM_MAP()
BOOL ProcessWindowMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lResult,
DWORD dwMsgMapID = 0);
// IViewObjectEx
DECLARE_VIEW_STATUS(VIEWSTATUS_SOLIDBKGND | VIEWSTATUS_OPAQUE)
// IFBControl
DECLARE_PROTECT_FINAL_CONSTRUCT()
HRESULT FinalConstruct()
{
return S_OK;
}
void FinalRelease()
{
}
};
template <const GUID* pFbCLSID, const char* pMT, class ICurObjInterface, const IID* piid, const GUID* plibid>
HRESULT FB::ActiveX::CFBControl<pFbCLSID, pMT, ICurObjInterface, piid, plibid>::OnDraw( ATL_DRAWINFO& di )
{
if (pluginWin && m_bWndLess && FB::pluginGuiEnabled()) {
LRESULT lRes(0);
PluginWindowlessWin* win = static_cast<PluginWindowlessWin*>(pluginWin.get());
FB::Rect bounds = { di.prcBounds->top, di.prcBounds->left, di.prcBounds->bottom, di.prcBounds->right };
win->HandleDraw(di.hdcDraw, bounds);
}
return S_OK;
}
template <const GUID* pFbCLSID, const char* pMT, class ICurObjInterface, const IID* piid, const GUID* plibid>
void FB::ActiveX::CFBControl<pFbCLSID, pMT, ICurObjInterface, piid, plibid>::invalidateWindow( uint32_t left, uint32_t top, uint32_t right, uint32_t bottom )
{
if (!m_host->isMainThread() && m_spInPlaceSite) {
boost::shared_ptr<FB::ShareableReference<CFBControlX> > ref(boost::make_shared<FB::ShareableReference<CFBControlX> >(this));
m_host->ScheduleOnMainThread(ref, boost::bind(&CFBControlX::invalidateWindow, this, left, top, right, bottom));
} else {
if (m_spInPlaceSite){
if(pluginWin){
FB::Rect pos = pluginWin->getWindowPosition();
RECT r = { left+pos.left, top+pos.top, right+pos.left, bottom+pos.top };
m_spInPlaceSite->InvalidateRect(&r, FALSE);
}else {
m_spInPlaceSite->InvalidateRect(NULL, FALSE);
}
}
}
}
template <const GUID* pFbCLSID, const char* pMT, class ICurObjInterface, const IID* piid, const GUID* plibid>
DWORD FB::ActiveX::CFBControl<pFbCLSID, pMT,ICurObjInterface,piid,plibid>::getSupportedObjectSafety()
{
return INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA/* | INTERFACE_USES_DISPEX*/;
}
template <const GUID* pFbCLSID, const char* pMT, class ICurObjInterface, const IID* piid, const GUID* plibid>
STDMETHODIMP CFBControl<pFbCLSID, pMT,ICurObjInterface,piid,plibid>::SetSite(IUnknown *pUnkSite)
{
HRESULT hr = IObjectWithSiteImpl<CFBControl<pFbCLSID,pMT,ICurObjInterface,piid,plibid> >::SetSite(pUnkSite);
if (!pUnkSite || !pluginMain) {
shutdown();
return hr;
}
m_serviceProvider = pUnkSite;
if (!m_serviceProvider)
return E_FAIL;
m_serviceProvider->QueryService(SID_SWebBrowserApp, IID_IWebBrowser2, reinterpret_cast<void**>(&m_webBrowser));
m_serviceProvider.Release();
if (m_webBrowser) {
m_propNotify = m_spClientSite;
}
// There will be no window this time!
clientSiteSet();
pluginMain->setScriptingOnly(true);
setReady();
return S_OK;
}
template <const GUID* pFbCLSID, const char* pMT, class ICurObjInterface, const IID* piid, const GUID* plibid>
STDMETHODIMP CFBControl<pFbCLSID, pMT,ICurObjInterface,piid,plibid>::SetClientSite( IOleClientSite *pClientSite )
{
HRESULT hr = IOleObjectImpl<CFBControlX>::SetClientSite (pClientSite);
if (!pClientSite || !pluginMain) {
shutdown();
return hr;
}
#ifdef FBWIN_ASYNCSURFACE
pClientSite->QueryInterface(__uuidof(IViewObjectPresentSite), (void **) &m_viewObjectPresentSite);
#endif
m_serviceProvider = pClientSite;
if (!m_serviceProvider)
return E_FAIL;
m_serviceProvider->QueryService(SID_SWebBrowserApp, IID_IWebBrowser2, reinterpret_cast<void**>(&m_webBrowser));
m_serviceProvider.Release();
if (m_webBrowser) {
m_propNotify = m_spClientSite;
}
clientSiteSet();
return S_OK;
}
template <const GUID* pFbCLSID, const char* pMT, class ICurObjInterface, const IID* piid, const GUID* plibid>
STDMETHODIMP CFBControl<pFbCLSID, pMT,ICurObjInterface,piid,plibid>::SetObjectRects(LPCRECT prcPos, LPCRECT prcClip)
{
HRESULT hr = IOleInPlaceObjectWindowlessImpl<CFBControlX>::SetObjectRects(prcPos, prcClip);
if (m_bWndLess && pluginWin) {
FB::PluginWindowlessWin* ptr(static_cast<FB::PluginWindowlessWin*>(pluginWin.get()));
ptr->setWindowClipping(prcClip->top, prcClip->left, prcClip->bottom, prcClip->right);
ptr->setWindowPosition(prcPos->left, prcPos->top, prcPos->right-prcPos->left, prcPos->bottom-prcPos->top);
}
return hr;
}
template <const GUID* pFbCLSID, const char* pMT, class ICurObjInterface, const IID* piid, const GUID* plibid>
STDMETHODIMP CFBControl<pFbCLSID, pMT,ICurObjInterface,piid,plibid>::InPlaceActivate( LONG iVerb, const RECT* prcPosRect)
{
m_bWindowOnly = (FB::pluginGuiEnabled() && !pluginMain->isWindowless());
HRESULT hr = CComControl<CFBControlX>::InPlaceActivate(iVerb, prcPosRect);
if (m_host)
m_host->resume(m_webBrowser, m_spClientSite);
if (hr != S_OK)
return hr;
if (pluginWin || !FB::pluginGuiEnabled() || !pluginMain) {
// window already created or gui disabled
return hr;
}
#ifdef FBWIN_ASYNCSURFACE
std::string param = pluginMain->negotiateDrawingModel();
{
using namespace boost::algorithm;
std::vector<std::string> prefs;
split(prefs, param, !is_alnum());
bool gotone = false;
for (size_t i = 0; !gotone && i < prefs.size(); i++) {
if (0 == strcmp(prefs[i].c_str(), "AsyncWindowsDXGISurface") &&
m_viewObjectPresentSite &&
m_host)
{
BOOL accelEnabled = FALSE;
HRESULT hr = m_viewObjectPresentSite->IsHardwareComposition(&accelEnabled);
if (SUCCEEDED(hr) && accelEnabled) {
hr = m_viewObjectPresentSite->SetCompositionMode(VIEW_OBJECT_COMPOSITION_MODE_SURFACEPRESENTER);
if (SUCCEEDED(hr)) {
AsyncDrawServicePtr asd = boost::make_shared<ActiveXAsyncDrawService>(m_host, m_viewObjectPresentSite);
boost::scoped_ptr<PluginWindow> pw(getFactoryInstance()->createPluginWindowless(FB::WindowContextWindowless(NULL, asd)));
pluginWin.swap(pw);
gotone = true;
}
}
}
}
}
#endif
if (!pluginWin) {
PluginWindow* pw = 0;
if (m_bWndLess) {
FB::PluginWindowlessWin* pww;
pw = pww = getFactoryInstance()->createPluginWindowless(FB::WindowContextWindowless(NULL));
pww->setInvalidateWindowFunc(boost::bind(&CFBControlX::invalidateWindow, this, _1, _2, _3, _4));
if (m_spInPlaceSite) {
HWND hwnd = 0;
HRESULT hr = m_spInPlaceSite->GetWindow(&hwnd);
if (SUCCEEDED(hr)) {
pww->setHWND(hwnd);
}
}
} else {
PluginWindowWin* pww;
pw = pww = getFactoryInstance()->createPluginWindowWin(FB::WindowContextWin(m_hWnd));
pww->setCallOldWinProc(true);
}
pluginWin.swap(boost::scoped_ptr<PluginWindow>(pw));
}
pluginMain->SetWindow(pluginWin.get());
setReady();
return hr;
}
template <const GUID* pFbCLSID, const char* pMT, class ICurObjInterface, const IID* piid, const GUID* plibid>
STDMETHODIMP CFBControl<pFbCLSID, pMT,ICurObjInterface,piid,plibid>::InPlaceDeactivate( void )
{
if (pluginMain) {
pluginMain->ClearWindow();
pluginWin.reset();
}
// We have to release all event handlers and other held objects at this point, because
// if we don't the plugin won't shut down properly; normally it isn't an issue to do
// so, but note that this gets called if you move the plugin around in the DOM!
if (m_host) {
m_host->ReleaseAllHeldObjects();
m_connPtMap.clear();
m_host->suspend();
}
HRESULT hr = IOleInPlaceObjectWindowlessImpl<CFBControlX>::InPlaceDeactivate();
return hr;
}
template <const GUID* pFbCLSID, const char* pMT, class ICurObjInterface, const IID* piid, const GUID* plibid>
STDMETHODIMP CFBControl<pFbCLSID, pMT,ICurObjInterface,piid,plibid>::InitNew()
{
pluginMain->setParams(FB::VariantMap());
setReady();
return S_OK;
}
template <const GUID* pFbCLSID, const char* pMT, class ICurObjInterface, const IID* piid, const GUID* plibid>
FB::VariantMap CFBControl<pFbCLSID, pMT, ICurObjInterface, piid, plibid>::getProperties( const CComQIPtr<IPropertyBag2>& pBag )
{
ULONG pCount(0), pGot(0);
HRESULT hr = pBag->CountProperties(&pCount);
FB::VariantMap paramMap;
boost::scoped_array<PROPBAG2> pArr(new PROPBAG2[pCount]);
hr = pBag->GetPropertyInfo(0, pCount, pArr.get(), &pGot);
boost::scoped_array<HRESULT> results(new HRESULT[pCount]);
boost::scoped_array<CComVariant> vals(new CComVariant[pCount]);
hr = pBag->Read(pGot, pArr.get(), NULL, vals.get(), results.get());
if (SUCCEEDED(hr)) {
for(ULONG i = 0; i < pGot; ++i) {
HRESULT curRes = results[i];
if (SUCCEEDED(curRes)) {
PROPBAG2* curInfo = &pArr[i];
VARIANT* curVal = &vals[i];
std::string name(FB::wstring_to_utf8(curInfo->pstrName));
FB::variant varval(m_host->getVariant(curVal));
paramMap[name] = varval;
// Clean up
CoTaskMemFree(curInfo->pstrName);
}
}
}
return paramMap;
}
template <const GUID* pFbCLSID, const char* pMT, class ICurObjInterface, const IID* piid, const GUID* plibid>
STDMETHODIMP CFBControl<pFbCLSID, pMT,ICurObjInterface,piid,plibid>::Load( IPropertyBag *pPropBag, IErrorLog *pErrorLog )
{
pluginMain->setParams(getProperties(CComQIPtr<IPropertyBag2>(pPropBag)));
setReady();
return S_OK;
}
template <const GUID* pFbCLSID, const char* pMT, class ICurObjInterface, const IID* piid, const GUID* plibid>
void CFBControl<pFbCLSID, pMT,ICurObjInterface,piid,plibid>::clientSiteSet()
{
m_host = ActiveXBrowserHostPtr(new ActiveXBrowserHost(m_webBrowser, m_spClientSite));
pluginMain->SetHost(FB::ptr_cast<FB::BrowserHost>(m_host));
}
template <const GUID* pFbCLSID, const char* pMT, class ICurObjInterface, const IID* piid, const GUID* plibid>
void CFBControl<pFbCLSID, pMT,ICurObjInterface,piid,plibid>::setReady()
{
// This is when we can consider the plugin "ready".
// setReady is called at object activation, which can happen multiple times
// (eg: if the object is reparented in the dom); only act on the first one.
if (!m_setReadyDone) {
m_setReadyDone = true;
this->setAPI(pluginMain->getRootJSAPI(), m_host);
setReadyState(READYSTATE_COMPLETE);
pluginMain->setReady();
}
}
template <const GUID* pFbCLSID, const char* pMT, class ICurObjInterface, const IID* piid, const GUID* plibid>
void CFBControl<pFbCLSID, pMT,ICurObjInterface,piid,plibid>::setWindow( HWND hWnd )
{
}
template <const GUID* pFbCLSID, const char* pMT, class ICurObjInterface, const IID* piid, const GUID* plibid>
void CFBControl<pFbCLSID, pMT,ICurObjInterface,piid,plibid>::shutdown()
{
// the host must be shut down before the rest to prevent deadlocks on async calls
if (m_host)
m_host->shutdown();
if (pluginMain) {
pluginMain->ClearWindow(); //Already done during InPlaceDeactivate
pluginMain->shutdown();
}
if (pluginWin) {
pluginWin.reset();
}
m_api.reset(); // Once we release this, pluginMain releasing should free it
pluginMain.reset(); // This should delete the plugin object
m_propNotify.Release();
m_webBrowser.Release();
m_serviceProvider.Release();
m_connPtMap.clear();
m_host.reset();
}
template <const GUID* pFbCLSID, const char* pMT, class ICurObjInterface, const IID* piid, const GUID* plibid>
STDMETHODIMP CFBControl<pFbCLSID, pMT,ICurObjInterface,piid,plibid>::GetClassID( CLSID *pClassID )
{
if (pClassID == NULL)
return E_POINTER;
*pClassID = GetObjectCLSID();
return S_OK;
}
template <const GUID* pFbCLSID, const char* pMT, class ICurObjInterface, const IID* piid, const GUID* plibid>
STDMETHODIMP CFBControl<pFbCLSID, pMT,ICurObjInterface,piid,plibid>::Save( IPropertyBag *pPropBag, BOOL fClearDirty, BOOL fSaveAllProperties )
{
return S_OK;
}
template <const GUID* pFbCLSID, const char* pMT, class ICurObjInterface, const IID* piid, const GUID* plibid>
STDMETHODIMP CFBControl<pFbCLSID, pMT,ICurObjInterface,piid,plibid>::GetInterfaceSafetyOptions(REFIID riid, DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions)
{
if (pdwSupportedOptions == NULL || pdwEnabledOptions == NULL)
return E_POINTER;
HRESULT hr;
CComPtr<IUnknown> pUnk;
// Check if we support this interface
hr = GetUnknown()->QueryInterface(riid, (void**)&pUnk);
if (SUCCEEDED(hr)) {
*pdwSupportedOptions = getSupportedObjectSafety();
*pdwEnabledOptions = m_dwCurrentSafety;
} else {
// We don't support this interface
*pdwSupportedOptions = 0;
*pdwEnabledOptions = 0;
}
return hr;
}
template <const GUID* pFbCLSID, const char* pMT, class ICurObjInterface, const IID* piid, const GUID* plibid>
STDMETHODIMP CFBControl<pFbCLSID, pMT,ICurObjInterface,piid,plibid>::SetInterfaceSafetyOptions(REFIID riid, DWORD dwOptionSetMask, DWORD dwEnabledOptions)
{
CComPtr<IUnknown> pUnk;
// Check if we support the interface and return E_NOINTEFACE if we don't
if (FAILED(GetUnknown()->QueryInterface(riid, (void**)&pUnk)))
return E_NOINTERFACE;
// If we are asked to set options we don't support then fail
if (dwOptionSetMask & ~getSupportedObjectSafety())
return E_FAIL;
m_dwCurrentSafety = (m_dwCurrentSafety & ~dwOptionSetMask) | (dwOptionSetMask & dwEnabledOptions);
return S_OK;
}
template <const GUID* pFbCLSID, const char* pMT, class ICurObjInterface, const IID* piid, const GUID* plibid>
BOOL CFBControl<pFbCLSID, pMT,ICurObjInterface,piid,plibid>::ProcessWindowMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lResult, DWORD dwMsgMapID)
{
BOOL bHandled = FALSE;
switch(dwMsgMapID)
{
case 0: {
// Set Focus & Capture whenever a button is pushed inside of the plugin instance.
switch(uMsg)
{
case WM_LBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_RBUTTONDOWN:
if (m_bNegotiatedWnd && m_bWndLess && m_spInPlaceSite) {
m_spInPlaceSite->SetFocus(true);
m_spInPlaceSite->SetCapture(true);
}
break;
case WM_LBUTTONUP:
case WM_MBUTTONUP:
case WM_RBUTTONUP:
if (m_bNegotiatedWnd && m_bWndLess && m_spInPlaceSite) {
m_spInPlaceSite->SetCapture(false);
}
break;
case WM_MOUSEACTIVATE:
break;
//lResult = ::DefWindowProc(hWnd, uMsg, wParam, lParam);
//return TRUE;
}
if (bHandled)
return TRUE;
else if (m_bWndLess && pluginWin && static_cast<PluginWindowlessWin*>(pluginWin.get())->HandleEvent(uMsg, wParam, lParam, lResult))
return TRUE;
else if(CComControl<CFBControlX>::ProcessWindowMessage(hWnd, uMsg, wParam, lParam, lResult))
return TRUE;
else if(DefaultReflectionHandler(hWnd, uMsg, wParam, lParam, lResult))
return TRUE;
} break;
}
return FALSE;
}
}
}
#endif