1

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.

FelixSFD
  • 6,052
  • 10
  • 43
  • 117
Abraham Tugalov
  • 1,902
  • 18
  • 25
  • It's just an observation. Setting the property of the first created instance is the only one which will be used for all instances. If you don't add an handler in the OI and you assign an event via code to Chromium1 it will be called for Chromium2 too. If you however assign it to Chromium2, none of them will be handled. – bummi Nov 11 '14 at 17:29
  • Thanks for revision and answer :) – Abraham Tugalov Nov 11 '14 at 18:50

1 Answers1

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.
Abraham Tugalov
  • 1,902
  • 18
  • 25
  • Can you please help me with this question ? This task is a lot harder than the one i'm trying to achieve, this should be easy for you : http://stackoverflow.com/questions/34615234/tchromium-how-to-keep-session-alive?lq=1 – delphirules Jan 05 '16 at 16:17