Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
Separate sessions in tabbed CEF browser
-
- Posts: 41
- Joined: Sun Feb 05, 2017 8:53 am
Separate sessions in tabbed CEF browser
I have tabbed CEF browser. Every tab has it's own TChromium component. Is there any way to separate sessions between tabs so that user can use different logins on the same site.
Scenario:
1. user logs in into web app with LOGIN1
2. user opens another tab - starts the same web app in it, and this web app doesn't "recognize" that the user is logged in - so user can log in using LOGIN2
Is there any way in CEF to acomplish this task within the same application ?
Scenario:
1. user logs in into web app with LOGIN1
2. user opens another tab - starts the same web app in it, and this web app doesn't "recognize" that the user is logged in - so user can log in using LOGIN2
Is there any way in CEF to acomplish this task within the same application ?
- salvadordf
- Posts: 4057
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Separate sessions in tabbed CEF browser
Hi,
Yes. The MDIBrowser has all the code to create several independent browsers.
You have to create a new request context with a different cache directory like this :
https://github.com/salvadordf/CEF4Delphi/blob/9e7da7a03e92f4367b4cbf86f1ff3a56c581afdc/demos/Delphi_VCL/MDIBrowser/uChildForm.pas#L225
Then use that context as a parameter in TChromium.CreateBrowser like this :
https://github.com/salvadordf/CEF4Delphi/blob/9e7da7a03e92f4367b4cbf86f1ff3a56c581afdc/demos/Delphi_VCL/MDIBrowser/uChildForm.pas#L242
Yes. The MDIBrowser has all the code to create several independent browsers.
You have to create a new request context with a different cache directory like this :
https://github.com/salvadordf/CEF4Delphi/blob/9e7da7a03e92f4367b4cbf86f1ff3a56c581afdc/demos/Delphi_VCL/MDIBrowser/uChildForm.pas#L225
Then use that context as a parameter in TChromium.CreateBrowser like this :
https://github.com/salvadordf/CEF4Delphi/blob/9e7da7a03e92f4367b4cbf86f1ff3a56c581afdc/demos/Delphi_VCL/MDIBrowser/uChildForm.pas#L242
-
- Posts: 41
- Joined: Sun Feb 05, 2017 8:53 am
Re: Separate sessions in tabbed CEF browser
Great help!
Thank You very much!
Thank You very much!
-
- Posts: 41
- Joined: Sun Feb 05, 2017 8:53 am
Re: Separate sessions in tabbed CEF browser
One more thing.
Can I safely share this context between TChromium components ?
Let's say I would like to do this:
If this is wrong - how can I do this safely ?
Can I safely share this context between TChromium components ?
Let's say I would like to do this:
Code: Select all
myGlobalContext := TCefRequestContextRef.New('', '', '', False, False, False, Chromium1.ReqContextHandler)
Chromium1.CreateBrowser(CEFWindowParent1, '', myGlobalContext);
...
Chromium2.CreateBrowser(CEFWindowParent2, '', myGlobalContext);
...
Chromium3.CreateBrowser(CEFWindowParent3, '', myGlobalContext);
- salvadordf
- Posts: 4057
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Separate sessions in tabbed CEF browser
I think it should be OK to use the context like that.
If that doesn't work then call TChromium.ShareRequestContext
If you already have a browser and you need to create a new browser using the same context then do this :
If that doesn't work then call TChromium.ShareRequestContext
If you already have a browser and you need to create a new browser using the same context then do this :
Code: Select all
var
TempContext : ICefRequestContext;
begin
ExistingBrowser.ShareRequestContext(TempContext, NewBrowser.ReqContextHandler);
NewBrowser.CreateBrowser(NewWindowParent, '', TempContext);
end;
Re: Separate sessions in tabbed CEF browser
Code: Select all
TempContext: array [0..MaxARR] of ICefRequestContext;
After all, if you do according to the proposed scheme, there will be no access to the context of a particular browser.
- salvadordf
- Posts: 4057
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Separate sessions in tabbed CEF browser
I use the TChromium.ShareRequestContext method in BriskBard and it works fine. I haven't tried to save the ICefRequestContext instances but I guess it should work.
Re: Separate sessions in tabbed CEF browser
Code: Select all
myGlobalContext := TCefRequestContextRef.New('', '', '', False, False, False, Chromium1.ReqContextHandler);
Chromium1.CreateBrowser(CEFWindowParent1, '', myGlobalContext);
myGlobalContext:= nil;
myGlobalContext := TCefRequestContextRef.New('', '', '', False, False, False, Chromium1.ReqContextHandler);
Chromium2.CreateBrowser(CEFWindowParent2, '', myGlobalContext);
myGlobalContext:= nil;
myGlobalContext := TCefRequestContextRef.New('', '', '', False, False, False, Chromium1.ReqContextHandler);
Chromium3.CreateBrowser(CEFWindowParent3, '', myGlobalContext);
![Smile :)](./images/smilies/icon_e_smile.gif)
If you don't save it, then how to use context references for any interaction?
Code: Select all
try
TempCallback := TCefCloseAllConnectionsCompletionCallback.Create(nil);
TempContext[FCefID].CloseAllConnections(TempCallback);
finally
TempCallback := nil;
end;
- salvadordf
- Posts: 4057
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact: