tags:

views:

61

answers:

2

Hello,

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

A: 

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

Luke
And in my case who is the IOleClientSite? the IWebBrowser2 or the CWnd? And how can i get this interface?(my code is like this:CWnd _BrowserWindow;_BrowserWindow.CreateControl(CLSID_WebBrowser,NULL,(WS_VISIBLE | WS_TABSTOP),browser_window_rect,this,AFX_IDW_PANE_FIRST);LPUNKNOWN unknown = _BrowserWindow.GetControlUnknown();IWebBrowser2 *_Browser;unknown->QueryInterface(IID_IWebBrowser2,(void **)
Nuno
You have to implement it yourself and pass it to the web browser's IOleObject::SetClientSite. You can probably just return E_NOTIMPL for all the IOleClientSite methods. Or maybe you can use COleControlSite (I'm not very familiar with MFC).
Luke
A: 

Hi,

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

Nuno