popup with TempContext

Post Reply
w1ld32
Posts: 19
Joined: Wed Feb 12, 2020 10:28 am

popup with TempContext

Post by w1ld32 » Sat Oct 17, 2020 10:27 am

Salvador, thank you for your constant help.
Is it possible to create a popup window with a new TempContent ?
And how save cookies without cache?

User avatar
salvadordf
Posts: 2640
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: popup with TempContext

Post by salvadordf » Sun Oct 18, 2020 9:11 am

w1ld32 wrote:
Sat Oct 17, 2020 10:27 am
Salvador, thank you for your constant help.
Is it possible to create a popup window with a new TempContent ?
When the main browser in your application needs to open a new popup window because it executed window.popup in JavaScript or the user clicked on a targeted link then you will get a TChromium.OnBeforePopup event.

As you can see in the PopupBrowser2 demo you only need to call TChromium.CreateClientHandler and send a message to show the hidden popup window.

Acording to the CEF documentation "Browser objects created indirectly via the JavaScript window.open function or targeted links will share the same render process and the same request context as the source browser."
https://bitbucket.org/chromiumembedded/cef/src/c3aa36323b59f130b18b7ee25a6911bfbef36574/include/capi/cef_request_context_capi.h#lines-83

In case you just want to create a new browser window manually with a request context that shares the storage with the main request context then you would have to call TChromium.ShareRequestContext before calling TChromium.CreateBrowser.
You would have to call ShareRequestContext on the main browser and it will return a ICefRequestContext instance that you can use in the TChromium.CreateBrowser call to create the new browser.
This is what the CEF code comments say about TChromium.ShareRequestContext :
https://bitbucket.org/chromiumembedded/cef/src/c3aa36323b59f130b18b7ee25a6911bfbef36574/include/capi/cef_request_context_capi.h#lines-379
Creates a new context object that shares storage with |other| and uses an optional |handler|.
w1ld32 wrote:
Sat Oct 17, 2020 10:27 am
And how save cookies without cache?
Cookies are stored inside the cache directory. If your application uses RAM memory to store the cache then the cookies will disappear when you close your application.

w1ld32
Posts: 19
Joined: Wed Feb 12, 2020 10:28 am

Re: popup with TempContext

Post by w1ld32 » Mon Oct 19, 2020 1:43 pm

Thank you, is there a way to combine 2 Contexts into one? Now I do this:
Chromium1BeforePopup

Code: Select all

Result := (targetDisposition in [WOD_NEW_FOREGROUND_TAB, WOD_NEW_BACKGROUND_TAB, WOD_NEW_POPUP, WOD_NEW_WINDOW]);
Chromium1.ShareRequestContext(PopUpContext);
TestCreate(PopUpContext, targetUrl);

procedure TestCreate(context : ICefRequestContext; url : string);
var
  TempChromium: TChromium;
begin
      TempChromium                 := TChromium.Create(Application);
      try
        TempChromium.DefaultUrl      := url;
        TempContext := context;
        if not(TempChromium.CreateBrowser(CEFWindowParent2, '', TempContext)) and not(TempChromium.Initialized) then exit;
      except
          exit;
      end;
end;
I need to start a popupwindow with other files cookies, I used to do this :

Code: Select all

TempContext := TCefRequestContextRef.New(ExtractFilePath(Application.ExeName) +'cache\user2', '', True, True, True);
But if I change it, the page doesn't load in the new chromium.

Post Reply