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

发布于 2024-09-15 02:39:08 字数 1321 浏览 3 评论 0原文

我似乎无法理解如何将 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 接口的实现。

但我的问题是如何在 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 接口,QueryService 上请求的所有其他接口都应该执行系统提供的默认实现...

谢谢

I can't seem to understand how i give my implementation of the IHttpSecurity::OnSecurityProblem to my IWebBrowser2 object.

I know that i need to implement a class something like this:

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;
};

And in the QueryService function when it requests the IID_IHttpSecurity i return my implementation of the IHttpSecurity interface.

But my problem is how i set the my service provider implementation on the IWebBrowser2 object and when?

My code is something like this:

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);

The question this works like i'm thinking if yes how i do this then, and if not can you explain how this works and can be setted?

PS: i only whant to implement the IID_IHttpSecurity interface, all other interfaces requested on the QueryService should do the default implementation provided by the system...

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

音盲 2024-09-22 02:39:08

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

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

最后,我们使用 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 的情况下完成此操作,请告诉我。

谢谢

I already figure out how this is done.

Using MFC we only need to implement CCustomOccManager that implements the COccManager in witch the implementation of CreateSite function returns an implementation of our COleControlSite (example CCustomControlSite). In this class you will need to override at least the QueryService function of IServiceProvider interface and in this implementation supply yours IHttpSecurity implementation (when required by the interface).

In the end the we register all this in the App InitInstance using the MFC function AfxEnableControlContainer.

Code:

// 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;
    }
};

In the App InitInstance simple call AfxEnableControlContainer on our implementation:

// 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);

If someone has the knowledge on how this is done without using MFC please let me know.

Thanks

安静 2024-09-22 02:39:08

从 IServiceProvider 的 文档 中的注释来看,您的IOleClientSite 对象需要实现 IServiceProvider。

Judging by the remarks in the documentation for IServiceProvider, it seems like your IOleClientSite object needs to implement IServiceProvider.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文