problem with loading local website after upgrade JCEF

Having problems with building or using the JCEF Java binding? Ask your questions here.

problem with loading local website after upgrade JCEF

Postby majeddotcom » Tue Mar 03, 2020 9:44 am

Hi,

I am using JCEF for my application. I was using old version of JCEF and never upgraded it in last 2 years till I realized there is a bad memory leak issue with my program and I think it is a bug with my version of JCEF.
so I upgraded it to latest version (as of yesterday) and I realized many things changed in terms of structure and I have to change my own code to launch the cefClient in y code.
The problem that I have is the method that has been changed where function ".getResourceHandler" used to call in CefClient.Java. I see it is changed to ".getResourceRequestHandler" in new version.
so I changed my handler classes and instead of calling a new resourceHandler in "getResourceHandler" inside getReguestHandler class, I call a new "ResourceRequestHandler" inside getResourceRequestHandler and inside that I call a getResourceHandler.
so far so good. I pass my local handlers and all good. but inside "processRequest" function, for some reason, my CefRequest that I passed earlier to resourceHandler, gets reset to 0. I am sure that I do not have any line inside my code that reset that to 0. it has to be something inside CEF java codes that this value gets reset.

can anyone help me to see what is the right sequence of creating the CEF frame with local address and handler options?
FYI, here is my old sequence that used to work perfect with old JCEF V3.33....

UiMain lUiMain = new UiMain(); //local customized HTTP Handlers
CefSettings lCefSettings = new CefSettings();
lCefSettings.windowless_rendering_enabled = OS.isLinux();
CefApp lCefApp = CefApp.getInstance(lCefSettings);
CefClient lCefClient = lCefApp.createClient();
lCefClient.addRequestHandler(new ChromiumRequestHandler(lUiMain));// here I do what I explained above.
lCefClient.addLifeSpanHandler(new ChromiumLifeSpanHandler());
lCefClient.addDownloadHandler(new ChromiumDownloadHandler());
majeddotcom
Newbie
 
Posts: 6
Joined: Mon Mar 02, 2020 2:26 pm

Re: problem with loading local website after upgrade JCEF

Postby magreenblatt » Tue Mar 03, 2020 11:20 am

majeddotcom wrote:I call a new "ResourceRequestHandler" inside getResourceRequestHandler and inside that I call a getResourceHandler.

You should return the same ResourceRequestHandler object every time getResourceRequestHandler is called.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: problem with loading local website after upgrade JCEF

Postby majeddotcom » Tue Mar 03, 2020 1:46 pm

did that and nothing changed. still changing the "N_CefHandle" value to 0.
for some reason, right after I call and create my "ResourceHandler" class, it will call "setNativeRef" function and since the "NativeRef" is 0, it will reset N_CefHandle to 0.
after that it goes and execute "processRequest" function. I think if I can only ignore the step that it goes and reset that N_CefHandle to 0, before calling "processRequest", then all is good. I can`t even sundress why it will go and reset that for already created resourceHandler class.

is there anything that you can offer me to try ?
majeddotcom
Newbie
 
Posts: 6
Joined: Mon Mar 02, 2020 2:26 pm

Re: problem with loading local website after upgrade JCEF

Postby majeddotcom » Tue Mar 03, 2020 1:58 pm

this is my ChromiumRequestHandler file:

Code: Select all
public class ChromiumRequestHandler implements CefRequestHandler {

   private UiMain mUiMain;
   private ChromiumResourceRequestHandler mChromiumResourceRequestHandler;
   
   public ChromiumRequestHandler (UiMain iUiMain)
   {
      mUiMain = iUiMain;
      mChromiumResourceRequestHandler = new ChromiumResourceRequestHandler(mUiMain);
   }
       //-----------------------------------------------------------------------
   @Override
   public CefResourceRequestHandler getResourceRequestHandler(CefBrowser browser, CefFrame frame,
            CefRequest request, boolean isNavigation, boolean isDownload, String requestInitiator,
            BoolRef disableDefaultHandling) {
      return mChromiumResourceRequestHandler;
      //return  null;
   }
   


this is my ChromiumResourceRequestHandler

Code: Select all
public class ChromiumResourceRequestHandler implements CefResourceRequestHandler {

   private UiMain mUiMain;
   
   public ChromiumResourceRequestHandler (UiMain iUiMain)
   {
      mUiMain = iUiMain;
   }
   //-----------------------------------------------------------------------
   
   @Override
   public CefResourceHandler getResourceHandler(CefBrowser iBrowser, CefFrame iFrame, CefRequest iRequest) {
      //return null;  // Uncomment to send the HTTP requests received by cef out to the web
      return new ChromiumResourceHandler(mUiMain, iRequest);   // used to send the HTTP requests received by cef to the processRequest function instead of out to the web
   }



this is my ChromiumResourceHandler
Code: Select all
public class ChromiumResourceHandler implements CefResourceHandler
{
   private UiMain mUiMain;
   private ChromiumHttpExchange mChromiumHttpExchange;
   private int mResponsePointer = 0;
   private byte[] mResponseData;
   
   public ChromiumResourceHandler(UiMain iMain, CefRequest iCefRequest)
   {
      mUiMain = iMain;            
      mChromiumHttpExchange = new ChromiumHttpExchange(iCefRequest);
      //Point1
   }

   //-----------------------------------------------------------------------
   
   @Override
   public boolean processRequest(CefRequest iCefRequest, CefCallback iCallback) {
      // TODO Auto-generated method stub      
      //System.out.println("processRequest : " + iCefRequest.getURL());
      
      try
      {
         mUiMain.mainHandle(mChromiumHttpExchange); // Point 2
      }
      catch (Exception e)
      {
         e.printStackTrace();
      }

      mResponseData = mChromiumHttpExchange.mResponseBody.toByteArray();      
       iCallback.Continue();  // Indicate the headers are available.
      return true;
   }

majeddotcom
Newbie
 
Posts: 6
Joined: Mon Mar 02, 2020 2:26 pm

Re: problem with loading local website after upgrade JCEF

Postby magreenblatt » Tue Mar 03, 2020 2:50 pm

You can compare your implementation to the JCEF detailed sample app.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: problem with loading local website after upgrade JCEF

Postby majeddotcom » Wed Mar 04, 2020 4:14 pm

already did that and I do not do anything faulty as I can undrestand. and again, it used to work properly with older version of Jcef 3.3396.0 .
I changed the request handlet to below as detailed sample implemented. so there is no requirement for "ChromiumResourceRequestHandler" .
but still after creating "ChromiumResourceHandler", first it goes and reset the N_CefHandle and then call the "processRequest" function. and here m_CefRequest is null!.
Code: Select all
public class ChromiumRequestHandler extends CefResourceRequestHandlerAdapter implements CefRequestHandler {

   private UiMain mUiMain;
   
   public ChromiumRequestHandler (UiMain iUiMain)
   {
      mUiMain = iUiMain;
   }
   //-----------------------------------------------------------------------
   @Override
   public CefResourceRequestHandler getResourceRequestHandler(CefBrowser browser, CefFrame frame,
            CefRequest request, boolean isNavigation, boolean isDownload, String requestInitiator,
            BoolRef disableDefaultHandling) {
   
      return this;
   }
   //-----------------------------------------------------------------------
   
   @Override
   public CefResourceHandler getResourceHandler(CefBrowser iBrowser, CefFrame iFrame, CefRequest iRequest) {
      //return null;  // Uncomment to send the HTTP requests received by cef out to the web
      return new ChromiumResourceHandler(mUiMain, iRequest ); // used to send the HTTP requests received by cef to the processRequest function instead of out to the web
   }
   


I can`t understand why instead of moving forward and jumping to "processRequest" function, first it goes and reset the value and then comes back. that is the part that I can`t find any reason for it. even line by line debug is not helping me.
majeddotcom
Newbie
 
Posts: 6
Joined: Mon Mar 02, 2020 2:26 pm


Return to JCEF Forum

Who is online

Users browsing this forum: No registered users and 6 guests