Different cookie handlers for two chromium instances on one form

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-08 06:21:07

问题


I'm using DCEF3 on Delphi XE3.

Task is : Create different cookie storages for different TChromium instances.
Problem : I'm creating different ICefCookieManager instances for each TChromium instances and its returning in GetCookieManager event.

Example code:

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:\Cookies\1');
    CookieManager2:=TCefCookieManagerRef.New('C:\Cookies\2');
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;

If I add ShowMessage('First') to Chromium1GetCookieManager event, and ShowMessage('Second') to Chromium2GetCookieManager, always the message "First" will be shown, no matter whether I press button1 or button2.
In other words Chromium1GetCookieManager is called for both instances.


回答1:


Problem is solved, thanks to all.

How to solve the problem?
Just turn off cefsingleprocess variable in your project1.dpr.
Example:

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.


来源:https://stackoverflow.com/questions/26869366/different-cookie-handlers-for-two-chromium-instances-on-one-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!