本文介绍了delphi CEF4 Chromium不显示带有安全连接错误的网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个使用CEF4 Chromium的应用程序,该应用程序可以浏览本地网络中的页面。
,但是我的页面上出现安全连接错误,因为我的网址以 https开头。例如
我的程序没有在Chromiumwindow或CEFWindowParent中不显示任何内容。
可能会对我有帮助。

I am created an application with CEF4 Chromium that browse pages in a local network.but my page has "Secure Connection Error" because of my url begin with "https". for example "https://10.36.159.212/login.html"my program don't display anything at Chromiumwindow or CEFWindowParent.it would be appriciate that help me.

推荐答案

默认情况下,当证书颁发过程中发生证书问题时,CEF会取消该请求。它的导航。很难说出要做什么,但是总的来说,您不应该处理带有某些证书问题的内容。但是,如果您知道这样做对您安全,则可以至少以以下两种方式允许您的请求继续:

By default, CEF cancels the request when a certificate issue occurs during its navigation. Hard to say what you want to do in your case, but in general, you should not work with content with some certificate issue. But if you know that it's safe for you, you can allow your request(s) to continue at least in these two ways:

您可以为库,您可以例如这样:

You can write handler for the OnCertificateError event and handle each request certificate issue separately. With CEF4Delphi library you can do it e.g. this way:

type
  TFormMain = class(TForm)
    ChromiumWindow1: TChromiumWindow;
    procedure FormShow(Sender: TObject);
  private
    procedure ChromiumCertificateError(Sender: TObject; const browser: ICefBrowser;
      certError: TCefErrorcode; const requestUrl: ustring; const sslInfo: ICefSslInfo;
      const callback: ICefRequestCallback; out Result: Boolean);
  end;

procedure TFormMain.FormShow(Sender: TObject);
begin
  ChromiumWindow1.ChromiumBrowser.OnCertificateError := ChromiumCertificateError;
  ChromiumWindow1.CreateBrowser;
end;

procedure TFormMain.ChromiumCertificateError(Sender: TObject; const browser: ICefBrowser;
  certError: TCefErrorcode; const requestUrl: ustring; const sslInfo: ICefSslInfo;
  const callback: ICefRequestCallback; out Result: Boolean);
begin
  Result := False;

  if MessageDlg(Format('Certificate error. Code: %d. Do you want to continue?',
    [Integer(certError)]), mtConfirmation, [mbYes, mbNo], 0) = mrYes then
  begin
    Result := True;
    callback.Cont(True);
  end;
end;

此事件的原理很简单。当您将 False 返回到 Result 参数时,报告了证书问题的请求将立即被取消。当您将 True 返回到 Result 参数时,请求导航将继续。但是,除了必须在此事件中或在以后的某个事件中说继续的请求(即上面代码中的呼叫 callback.Cont(True))。

The principle of this event is simple. When you return False to the Result parameter, request that has reported a certificate issue will be immediately cancelled. When you return True to the Result parameter, request navigation will continue. But, except that you must say the request to continue (that's the call callback.Cont(True) in the above code), either in this event, or in some later one.

如果您对特定的证书错误感兴趣,请参考事件的 certError 参数,该错误代码常量的前缀为 ERR_CERT _ 。 模块(有关说明,请参阅头文件)。

If you were interested about specific certificate errors, consult the certError parameter of the event with error code constants prefixed by ERR_CERT_ defined in the uCEFConstants.pas module (for descriptions then see the net_error_list.h header file).

处理特定证书错误的另一种方法是从 sslInfo 界面获取状态并通过 CERT_STATUS _ 标志()。

Another way of handling specific certificate errors would be getting status from the sslInfo interface and masking the status value by the CERT_STATUS_ flags (uCEFConstants.pas).

您可以启用选项可全局忽略所有证书问题,从而使所有已创建的CEF浏览器都能浏览至内容,尽管存在所有证书问题(这是不安全的)。对于库,您通常可以在项目源中设置全局设置,例如像这样:

You can enable the ignore_certificate_errors option to globally ignore all certificate issues letting all the created CEF browsers navigate to the content despite all certificate issues (which is unsafe). For CEF4Delphi library you can setup global settings typically in your project source, e.g. like this:

GlobalCEFApp := TCefApplication.Create;
try
  GlobalCEFApp.IgnoreCertificateErrors := True;

  if GlobalCEFApp.StartMainProcess then
  begin
    Application.Initialize;
    Application.MainFormOnTaskbar := True;
    Application.CreateForm(TFormMain, FormMain);
    Application.Run;
  end;
finally
  GlobalCEFApp.Free;
end;

我不鼓励使用这种方式,因为导航到带有证书问题的内容可能并不安全。

I would discourage from using this way as it may not be safe to navigate to content with certificate issue.

这篇关于delphi CEF4 Chromium不显示带有安全连接错误的网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 21:25