WebBrowser Control(一)禁止表单数据提示对话框

  • 问题
    • 通过WebBrowser控件浏览网页,提交数据表单时(如在google中输入关键字,然后确认),会出现一个如下的安全提示框。如何禁止此对话框?

  • 办法:实现自己的安全管理器(URL Security Manager)
    • 实现IServiceProvider接口:
      1     STDMETHOD(QueryService)(REFGUID guidService, REFIID riid, void **ppvObj)
      2 {
      3 if (guidService == IID_IInternetSecurityManager)
      4 {
      5 return QueryInterface(riid, ppvObj);//返回IInternetSecurityManager接口指针
      6 }
      7 else
      8 return E_FAIL;
      9 }
    • 实现IInternetSecurityManager::ProcessUrlAction接口(其他方法直接返回INET_E_DEFAULT_ACTION):
       1     STDMETHOD (ProcessUrlAction)(LPCWSTR pwszUrl,DWORD dwAction,BYTE *pPolicy,DWORD cbPolicy,
      2 BYTE *pContext,DWORD cbContext,DWORD dwFlags,DWORD dwReserved)
      3 {
      4
      5 DWORD dwPolicy = URLPOLICY_ALLOW;
      6 if(dwAction == URLACTION_HTML_SUBMIT_FORMS || dwAction == URLACTION_HTML_SUBMIT_FORMS_FROM ||dwAction == URLACTION_HTML_SUBMIT_FORMS_TO)
      7 {
      8 if (cbPolicy >= sizeof(DWORD))
      9 {
      10 *(DWORD*)pPolicy = dwPolicy;
      11 return S_OK;
      12 }
      13 else
      14 {
      15 return S_FALSE;
      16 }
      17
      18 }
      19 return INET_E_DEFAULT_ACTION;
      20 }
  • 参考:
posted @ 2011-09-26 15:55  iThinking  阅读(658)  评论(0编辑  收藏  举报