c++ - 如何处理具有 IWebBrowser2 对象的 IHttpSecurity::OnSecurityProblem

标签 c++ http com mfc https

我似乎无法理解如何将 IHttpSecurity::OnSecurityProblem 的实现赋予 IWebBrowser2 对象。

我知道我需要实现一个像这样的类:

class CServiceProvider : public IServiceProvider
{
public:
CServiceProvider();
~CServiceProvider(); 

    // IUnknown
    ULONG STDMETHODCALLTYPE AddRef();
    ULONG STDMETHODCALLTYPE Release();
    STDMETHODIMP QueryInterface(REFIID iid, void ** ppvObject);

//QueryService
STDMETHODIMP QueryService(REFGUID guidService,REFIID riid,void **ppv);

private:
 ULONG m_ulRefCnt;
};

在 QueryService 函数中,当它请求 IID_IHttpSecurity 时,我返回 IHttpSecurity 接口(interface)的实现。

但我的问题是如何在 IWebBrowser2 对象上设置我的服务提供程序实现以及何时?

我的代码是这样的:

IWebBrowser2 *_Browser;

IServiceProvider* pServiceProvider = NULL;
    _Browser->QueryInterface(
                IID_IServiceProvider, 
                (void**)&pServiceProvider);

    IHttpSecurity* pi;
    pServiceProvider->QueryService(IID_IHttpSecurity, &pi);


    _Browser->Navigate(url.AllocSysString(),
                       &flags,
                       &target_frame_name,
                       &post_data,
                       &headers);

这个问题就像我在想的那样,如果是,我该怎么做,如果不是,你能解释一下它是如何工作的以及如何设置吗?

PS:我只想实现 IID_IHttpSecurity 接口(interface),QueryService 上请求的所有其他接口(interface)都应该执行系统提供的默认实现...

谢谢

最佳答案

我已经弄清楚这是如何完成的。

使用 MFC,我们只需要实现 CCustomOccManager,它实现 COccManager,而 CreateSite 函数的实现返回 COleControlSite 的实现(例如 CCustomControlSite)。在此类中,您至少需要重写 IServiceProvider 接口(interface)的 QueryService 函数,并在此实现中提供您的 IHttpSecurity 实现(当接口(interface)需要时)。

最后,我们使用 MFC 函数 AfxEnableControlContainer 在 App InitInstance 中注册所有这些。

代码:

// declare our custom control site to serve as the client site
class CCustomControlSite:public COleControlSite
{
public:
    // constructor associates this site with the container
    CCustomControlSite(COleControlContainer *pCnt):COleControlSite(pCnt){}
protected:
DECLARE_INTERFACE_MAP();
BEGIN_INTERFACE_PART(ServiceProvider, IServiceProvider)
// declare the interface method(s)
STDMETHOD(QueryService) ( 
            /* [in] */ REFGUID guidService,
            /* [in] */ REFIID riid,
            /* [out] */ void __RPC_FAR *__RPC_FAR *ppvObject);
END_INTERFACE_PART(ServiceProvider)
};

// declare our control container manager
class CCustomOccManager :public COccManager
{
public:
    CCustomOccManager(){}
    // creates an instance of our custom control site and associates it with the container
    COleControlSite* CreateSite(COleControlContainer* pCtrlCont)
    {
        CCustomControlSite *pSite = new CCustomControlSite(pCtrlCont);
        return pSite;
    }
};

在 App InitInstance 中简单调用我们的实现上的 AfxEnableControlContainer:

// Create a custom control container manager class so we can overide the client site
CCustomOccManager *pMgr = new CCustomOccManager;

// Set our control containment up but using our control container 
// management class instead of MFC's default
AfxEnableControlContainer(pMgr);

如果有人了解如何在不使用 MFC 的情况下完成此操作,请告诉我。

谢谢

关于c++ - 如何处理具有 IWebBrowser2 对象的 IHttpSecurity::OnSecurityProblem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3496901/

相关文章:

c++ - 可以将类对象创建为仅左值吗?

c++ - 什么是复制赋值运算符?

c++ - std::deque<char> 上的简单插入-删除-插入给出了奇怪的结果

c# - 理解正确的 http keep-alive 实现

c# - 在 VB6 list 中包含 .NET 程序集?

c++ - IHTMLDocument2->documentElement->outerHTML 从 DOM 重新创建 HTML 太慢了,有没有更快的方法?

c# - 如何成功注册 certadm.dll 以便能够在 C# 代码中使用 ICertView2

c++ - 初学者 C++ - 带有奇怪 setw 错误的简单随机游走程序

javascript - Node.js:http 完成事件、响应关闭事件和响应结束事件之间的区别

c# - Azure函数: Cannot bind parameter '_return' to type HttpResponseMessage