一个表单上两个chrome实例的不同cookie处理程序



我在Delphi XE3上使用DCEF3。

任务是:为不同的TChromium实例创建不同的cookie存储
问题:我为每个TChromium实例创建不同的ICefCookieManager实例,并在GetCookieManager事件中返回。

示例代码:

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Chromium1: TChromium;
    Chromium2: TChromium;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Chromium1GetCookieManager(Sender: TObject;
      const browser: ICefBrowser; const mainUrl: ustring;
      out Result: ICefCookieManager);
    procedure Chromium2GetCookieManager(Sender: TObject;
      const browser: ICefBrowser; const mainUrl: ustring;
      out Result: ICefCookieManager);
  private
    { Private declarations }
      CookieManager: ICefCookieManager;
      CookieManager2: ICefCookieManager;
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
procedure TForm1.FormCreate(Sender: TObject);
begin
    CookieManager:=TCefCookieManagerRef.New('C:Cookies1');
    CookieManager2:=TCefCookieManagerRef.New('C:Cookies2');
end;
procedure TForm1.Chromium1GetCookieManager(Sender: TObject;
  const browser: ICefBrowser; const mainUrl: ustring;
  out Result: ICefCookieManager);
begin
    Result:=CookieManager;
end;
procedure TForm1.Chromium2GetCookieManager(Sender: TObject;
  const browser: ICefBrowser; const mainUrl: ustring;
  out Result: ICefCookieManager);
begin
    Result:=CookieManager2;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
    Chromium1.Load('http://somesite.com');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
    Chromium2.Load('http://somesite.com');
end;

如果我将ShowMessage('First')添加到Chromium1GetCookieManager事件,将ShowMessage('Second')添加到Chromium2GetCookieManager,则无论我按下按钮1还是按钮2,都将始终显示消息"First"。
换句话说,Chromium1GetCookieManager在这两个实例中都被调用。

感谢所有人,问题得到了解决。

如何解决问题
只需关闭项目1.dpr中的cefsingprocess变量。
示例:

program Project1;
uses
  Forms,
  cefvcl,
  ceflib,
  Unit1 in 'Unit1.pas' {Form1};
{$R *.res}
begin
  CefSingleProcess := False;//this what i'm talking about
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

相关内容

  • 没有找到相关文章

最新更新