2011년 7월 8일 금요일

javascript 에서 ActiveX 메소드/프로퍼티 엑세스할때 경고 메시지박스 뜨는것 막기

< 액티브액스에 IObjectSafety 인터페이스 추가 >
=> ie에서 스크립트가 activex object 메소드/프로퍼티 액세스할때 메시지박스 뜨는것 막아줌
=> 출처 : http://ancdesign.tistory.com/18

[ActiveXCtrl.h]

#include <objsafe.h>

class ActiveXCtrl
{
...
// IObjectSafety
DECLARE_INTERFACE_MAP()

BEGIN_INTERFACE_PART(ObjSafe, IObjectSafety)
STDMETHOD_(HRESULT, GetInterfaceSafetyOptions) (
/* [in] */ REFIID riid,
/* [out] */ DWORD __RPC_FAR *pdwSupportedOptions,
/* [out] */ DWORD __RPC_FAR *pdwEnabledOptions
);

STDMETHOD_(HRESULT, SetInterfaceSafetyOptions) (
/* [in] */ REFIID riid,
/* [in] */ DWORD dwOptionSetMask,
/* [in] */ DWORD dwEnabledOptions
);
END_INTERFACE_PART(ObjSafe);
...
};

[ActiveXCtrl.cpp]

// Interface map for IObjectSafety

BEGIN_INTERFACE_MAP( CActiveXCtrl, COleControl )
INTERFACE_PART(CActiveXCtrl, IID_IObjectSafety, ObjSafe)
END_INTERFACE_MAP()

/////////////////////////////////////////////////////////////
// IObjectSafety member functions

ULONG FAR EXPORT CActiveXCtrl::XObjSafe::AddRef()
{
METHOD_PROLOGUE(CActiveXCtrl, ObjSafe)
return pThis->ExternalAddRef();
}

ULONG FAR EXPORT CActiveXCtrl::XObjSafe::Release()
{
METHOD_PROLOGUE(CActiveXCtrl, ObjSafe)
return pThis->ExternalRelease();
}

HRESULT FAR EXPORT CActiveXCtrl::XObjSafe::QueryInterface(
REFIID iid, void FAR* FAR* ppvObj)
{
METHOD_PROLOGUE(CActiveXCtrl, ObjSafe)
return (HRESULT)pThis->ExternalQueryInterface(&iid, ppvObj);
}

const DWORD dwSupportedBits =
INTERFACESAFE_FOR_UNTRUSTED_CALLER |
INTERFACESAFE_FOR_UNTRUSTED_DATA;
const DWORD dwNotSupportedBits = ~ dwSupportedBits;

HRESULT STDMETHODCALLTYPE
CActiveXCtrl::XObjSafe::GetInterfaceSafetyOptions(
/* [in] */ REFIID riid,
/* [out] */ DWORD __RPC_FAR *pdwSupportedOptions,
/* [out] */ DWORD __RPC_FAR *pdwEnabledOptions)
{
METHOD_PROLOGUE(CActiveXCtrl, ObjSafe)

HRESULT retval = ResultFromScode(S_OK);

// does interface exist?
IUnknown FAR* punkInterface;
retval = pThis->ExternalQueryInterface(&riid, (void * *)&punkInterface);
if (retval != E_NOINTERFACE) { // interface exists
punkInterface->Release(); // release it--just checking!
}

// we support both kinds of safety and have always both set,
// regardless of interface
*pdwSupportedOptions = *pdwEnabledOptions = dwSupportedBits;

return retval; // E_NOINTERFACE if QI failed
}

HRESULT STDMETHODCALLTYPE
CActiveXCtrl::XObjSafe::SetInterfaceSafetyOptions(
/* [in] */ REFIID riid,
/* [in] */ DWORD dwOptionSetMask,
/* [in] */ DWORD dwEnabledOptions)
{
METHOD_PROLOGUE(CActiveXCtrl, ObjSafe)

// does interface exist?
IUnknown FAR* punkInterface;
pThis->ExternalQueryInterface(&riid, (void**)&punkInterface);
if (punkInterface) { // interface exists
punkInterface->Release(); // release it--just checking!
}
else { // interface doesn't exist
return ResultFromScode(E_NOINTERFACE);
}

// can't set bits we don't support
if (dwOptionSetMask & dwNotSupportedBits) {
return ResultFromScode(E_FAIL);
}

// can't set bits we do support to zero
dwEnabledOptions &= dwSupportedBits;
// (we already know there are no extra bits in mask )
if ((dwOptionSetMask & dwEnabledOptions) != dwOptionSetMask) {
return ResultFromScode(E_FAIL);
}

// don't need to change anything since we're always safe
return ResultFromScode(S_OK);
}
//---------------------------------------------------------------------------------------

댓글 없음:

댓글 쓰기