CHtmlView 处理/禁止 JavaScript 脚本错误!

CSiteControlSite.h

#pragma once
#include <afxocc.h>
#include <afxhtml.h>

class CHtmlControlSite : public COleControlSite
{
public:
	CHtmlControlSite(COleControlContainer* pParentWnd);
	~CHtmlControlSite();

	CHtmlView* GetView() const;

	BEGIN_INTERFACE_PART(DocHostUIHandler, IDocHostUIHandler)
		STDMETHOD(ShowContextMenu)(DWORD, LPPOINT, LPUNKNOWN, LPDISPATCH);
		STDMETHOD(GetHostInfo)(DOCHOSTUIINFO*);
		STDMETHOD(ShowUI)(DWORD, LPOLEINPLACEACTIVEOBJECT,
			LPOLECOMMANDTARGET, LPOLEINPLACEFRAME, LPOLEINPLACEUIWINDOW);
		STDMETHOD(HideUI)(void);
		STDMETHOD(UpdateUI)(void);
		STDMETHOD(EnableModeless)(BOOL);
		STDMETHOD(OnDocWindowActivate)(BOOL);
		STDMETHOD(OnFrameWindowActivate)(BOOL);
		STDMETHOD(ResizeBorder)(LPCRECT, LPOLEINPLACEUIWINDOW, BOOL);
		STDMETHOD(TranslateAccelerator)(LPMSG, const GUID*, DWORD);
		STDMETHOD(GetOptionKeyPath)(OLECHAR **, DWORD);
		STDMETHOD(GetDropTarget)(LPDROPTARGET, LPDROPTARGET*);
		STDMETHOD(GetExternal)(LPDISPATCH*);
		STDMETHOD(TranslateUrl)(DWORD, OLECHAR*, OLECHAR **);
		STDMETHOD(FilterDataObject)(LPDATAOBJECT, LPDATAOBJECT*);
	END_INTERFACE_PART(DocHostUIHandler)

	DECLARE_INTERFACE_MAP()
};

class CSiteControlSite : public CHtmlControlSite
{
public:
	CSiteControlSite(COleControlContainer *pCnt = NULL) :CHtmlControlSite(pCnt) {}

	DECLARE_INTERFACE_MAP();

	BEGIN_INTERFACE_PART(CmdTargetObj, IOleCommandTarget)
		STDMETHOD(QueryStatus)(const GUID*, ULONG, OLECMD[], OLECMDTEXT*);
		STDMETHOD(Exec)(const GUID*, DWORD, DWORD, VARIANTARG*, VARIANTARG*);
	END_INTERFACE_PART(CmdTargetObj)
};



CSiteControlSite.cpp

#include "stdafx.h"
#include "SiteControlSite.h"


BEGIN_INTERFACE_MAP(CSiteControlSite, COleControlSite)
	INTERFACE_PART(CSiteControlSite, IID_IOleCommandTarget, CmdTargetObj)
END_INTERFACE_MAP()

ULONG FAR EXPORT CSiteControlSite::XCmdTargetObj::AddRef()
{
	METHOD_PROLOGUE(CSiteControlSite, CmdTargetObj)
		return pThis->ExternalAddRef();
}

ULONG FAR EXPORT CSiteControlSite::XCmdTargetObj::Release()
{
	METHOD_PROLOGUE(CSiteControlSite, CmdTargetObj)
		return pThis->ExternalRelease();
}

HRESULT FAR EXPORT CSiteControlSite::XCmdTargetObj::QueryInterface(REFIID iid, void FAR* FAR* ppvObj)
{
	METHOD_PROLOGUE(CSiteControlSite, CmdTargetObj)
		return (HRESULT)pThis->ExternalQueryInterface(&iid, ppvObj);
}

STDMETHODIMP CSiteControlSite::XCmdTargetObj::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, OLECMD rgCmds[], OLECMDTEXT* pcmdtext)
{
	METHOD_PROLOGUE(CSiteControlSite, CmdTargetObj)

		return S_OK;
}

STDMETHODIMP CSiteControlSite::XCmdTargetObj::Exec(const GUID* pguidCmdGroup, DWORD nCmdID, DWORD nCmdExecOpt, VARIANTARG* pvarargIn, VARIANTARG* pvarargOut)
{
	METHOD_PROLOGUE(CSiteControlSite, CmdTargetObj)
		HRESULT hr = S_OK;

	if (pguidCmdGroup && IsEqualGUID(*pguidCmdGroup, CGID_DocHostCommandHandler))
	{
		switch (nCmdID)
		{
		case OLECMDID_SHOWSCRIPTERROR:
		{
			// pvarargOut 设置为TRUE,继续运行此scripts  
			(*pvarargOut).vt = VT_BOOL;
			(*pvarargOut).boolVal = VARIANT_TRUE;
			return S_OK;
			break;
		}
		default:
			hr = OLECMDERR_E_NOTSUPPORTED;
			break;
		}
	}
	else
	{
		hr = OLECMDERR_E_UNKNOWNGROUP;
	}
	return (hr);
}

定义 CreateControlSite 接口

ExpView.h

class CExpView : public CHtmlView
{
...........省略.....
public:
	virtual BOOL CreateControlSite(COleControlContainer* pContainer,COleControlSite** ppSite, UINT nID, REFCLSID clsid);
};

ExpView.cpp

BOOL CExpView::CreateControlSite(COleControlContainer* pContainer, COleControlSite** ppSite, UINT nID, REFCLSID clsid)
{
	// TODO:  在此添加专用代码和/或调用基类
	ASSERT(ppSite != NULL);
	*ppSite = new CSiteControlSite(pContainer);
	return TRUE;
}



参考来源:

BUG: Proxy Authentication Through IAuthenticate May Fail on Secure URL

用CHTMLView 来处理script脚本错误


相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页