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.
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