onBeforeNavigation implementation

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

onBeforeNavigation implementation

Postby kleon » Wed May 30, 2018 10:08 am

Hello,

I'm trying to implement onBeforeNavigation event to cefsimple example, but I'm really bad in c++ developing and now I am confused about what I'm doing :(

I've extends two files (my code is marked by [b] tag):

simple_app.h
Code: Select all
// Implement application-level callbacks for the browser process.
class SimpleApp : public CefApp, public CefBrowserProcessHandler, [b]public CefRenderProcessHandler[/b] {
 public:
  SimpleApp();

  // CefApp methods:
  virtual CefRefPtr<CefBrowserProcessHandler> GetBrowserProcessHandler()
      OVERRIDE {
    return this;
  }
   
  [b]virtual CefRefPtr<CefRenderProcessHandler> GetRenderProcessHandler()
    OVERRIDE {
    return this;
   }[/b]

  // CefBrowserProcessHandler methods:
  virtual void OnContextInitialized() OVERRIDE;
 
  virtual void OnBeforeCommandLineProcessing(const CefString& process_type, CefRefPtr<CefCommandLine> command_line) OVERRIDE;
   
  // CefRenderProcessHandler methods:
  [b]virtual void OnWebKitInitialized() OVERRIDE;[/b]
   
  [b]virtual bool OnBeforeNavigation(CefRefPtr<CefBrowser> browser,
                                    CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request,
                                    NavigationType navigation_type, bool is_redirect)  OVERRIDE;[/b]
   
 private:
  // Include the default reference counting implementation.
  IMPLEMENT_REFCOUNTING(SimpleApp);
};

#endif  // CEF_TESTS_CEFSIMPLE_SIMPLE_APP_H_


and add new method to simple_app.cc

Code: Select all
bool SimpleApp::OnBeforeNavigation(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request, NavigationType navigation_type, bool is_redirect)
{
    CefString cefval = request->GetURL();
    CefString csval = cefval.c_str();
   
    return false;
}


The problem is that my onBeforeNavigation method isn't called. Does anyone can provide some code snippets how to integrate onBeforeNavigation correctly? Also If someone could provide any advices it would be great too!
kleon
Newbie
 
Posts: 8
Joined: Wed Mar 14, 2018 6:15 am

Re: onBeforeNavigation implementation

Postby salvadordf » Wed May 30, 2018 10:11 am

CefRenderHandler::OnBeforeNavigation was removed recently.

https://bitbucket.org/chromiumembedded/ ... 790e0f468b
Maintainer of the CEF4Delphi, WebView4Delphi, WebUI4Delphi and WebUI4CSharp projects.
User avatar
salvadordf
Expert
 
Posts: 129
Joined: Sun Dec 18, 2016 8:39 am
Location: Spain

Re: onBeforeNavigation implementation

Postby kleon » Wed May 30, 2018 10:56 am

salvadordf wrote:CefRenderHandler::OnBeforeNavigation was removed recently.

https://bitbucket.org/chromiumembedded/ ... 790e0f468b

As I understood new function is called OnBeforeLoad(). Could you provide any code snippets how to use it?
kleon
Newbie
 
Posts: 8
Joined: Wed Mar 14, 2018 6:15 am

Re: onBeforeNavigation implementation

Postby salvadordf » Wed May 30, 2018 11:00 am

I'm sorry but I can only give you Delphi code. Perhaps some other forum user can help you with C++.
Maintainer of the CEF4Delphi, WebView4Delphi, WebUI4Delphi and WebUI4CSharp projects.
User avatar
salvadordf
Expert
 
Posts: 129
Joined: Sun Dec 18, 2016 8:39 am
Location: Spain

Re: onBeforeNavigation implementation

Postby HarmlessDave » Wed May 30, 2018 11:07 am

You can search for OnBeforeBrowse in the CefClient sample and unit tests.
HarmlessDave
Expert
 
Posts: 370
Joined: Fri Jul 11, 2014 2:02 pm

Re: onBeforeNavigation implementation

Postby kleon » Wed May 30, 2018 11:37 am

HarmlessDave wrote:You can search for OnBeforeBrowse in the CefClient sample and unit tests.

Yeah, I found it, but can't realize how to implement it to CefSimple example (totally noob in C++ development :( I'm familiar with Java only ) So now I'm looking for any code snippets how to implement "onBeforeNavigation" event to SimpleApp class (main class of CefSimple example) or something that help me understand how to do it.
kleon
Newbie
 
Posts: 8
Joined: Wed Mar 14, 2018 6:15 am

Re: onBeforeNavigation implementation

Postby HarmlessDave » Wed May 30, 2018 12:51 pm

When an event handler function is missing, you need to add the right xxxHandler class as one of the classes included in the main class definition (multiple inheritance) and override the default event handler function which might be virtual.

So in cefclient.h you see

Code: Select all
class ClientHandler : public CefClient,
...
                      public CefRequestHandler {
 public:

....

  // CefRequestHandler methods
  bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
                      CefRefPtr<CefFrame> frame,
                      CefRefPtr<CefRequest> request,
                      bool is_redirect) OVERRIDE;


Then you add the implementation in the .cc or .cpp file.

Try adding that to whatever class in CefSimple has the other xxxHandler parents.
HarmlessDave
Expert
 
Posts: 370
Joined: Fri Jul 11, 2014 2:02 pm

Re: onBeforeNavigation implementation

Postby magreenblatt » Wed May 30, 2018 6:53 pm

Also don't forget to implement the GetRequestHandler method.
magreenblatt
Site Admin
 
Posts: 12402
Joined: Fri May 29, 2009 6:57 pm

Re: onBeforeNavigation implementation

Postby kleon » Tue Sep 04, 2018 7:29 am

Thanx, it works!

Also don't forget to implement the GetRequestHandler method.

This was the key :)
kleon
Newbie
 
Posts: 8
Joined: Wed Mar 14, 2018 6:15 am


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 41 guests