how to add new API method to cef classes

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.

how to add new API method to cef classes

Postby turtle1 » Sun Dec 31, 2023 12:49 am

Hi,

I want to add a new method to CefBrowser but I can't seem to get my new distribution to compile. I tried adding the following to cef_browser.h:

Code: Select all
///
/// Set a script in the render manager.
///
/*--cef()--*/
// virtual void SetScriptInRenderManager(const std::string& script) = 0;


then in browser_impl.h I added the signature
void SetScriptInRenderManager(const std::string& script) override;
and in browser_impl.cc I added the implementation

Code: Select all
void CefBrowserImpl::SetScriptInRenderManager(const std::string& script) {
  LOG(INFO) << "CefBrowserImpl: SetScriptInRenderManager";
  CefRenderManager::Get()->SetScript(script);
}


but when I try to compile I get:
Code: Select all
In file included from ../../cef/libcef_dll/cpptoc/client_cpptoc.cc:34:
In file included from ../../cef/libcef_dll/ctocpp/browser_ctocpp.h:28:
../../cef/libcef_dll/ctocpp/ctocpp_ref_counted.h:112:13: error: field type 'CefBrowserCToCpp' is an abstract class
  112 |   ClassName wrapper_;
      |             ^
../../cef/libcef_dll/ctocpp/ctocpp_ref_counted.h:123:38: note: in instantiation of member class 'CefCToCppRefCounted<CefBrowserCToCpp, CefBrowser, _cef_browser_t>::WrapperStruct' requested here
  123 |   WrapperStruct* wrapperStruct = new WrapperStruct;
      |                                      ^
../../cef/libcef_dll/cpptoc/client_cpptoc.cc:378:25: note: in instantiation of member function 'CefCToCppRefCounted<CefBrowserCToCpp, CefBrowser, _cef_browser_t>::Wrap' requested here
  378 |       CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame),
      |                         ^
../../cef/include/cef_browser.h:203:16: note: unimplemented pure virtual method 'SetScriptInRenderManager' in 'CefBrowserCToCpp'
  203 |   virtual void SetScriptInRenderManager(const std::string& script) = 0;
      |                ^
1 error generated.
[47/398] CXX obj/cef/libcef_static/frame_impl.o
ninja: build stopped: subcommand failed.


Am I missing a step here or am I supposed to write the C implementation in CefBrowserCToCpp myself? Is there a way around this? I'm only working in cpp.
I just want to be able to call the new method I've implemented on a CefBrowser instance in my application.

Any help is much appreciated.
turtle1
Newbie
 
Posts: 9
Joined: Wed Sep 20, 2023 3:45 pm

Re: how to add new API method to cef classes

Postby turtle1 » Sun Dec 31, 2023 2:51 am

Figured it out, it was my mistake.
I thought the build process was running the translator tool automatically. Once I ran translator.sh in cef/tools and added another implementation of the function to a different class that also inherits from CefBrowser I could compile successfully.
Edit: Also had to change to using CefString instead of std::string.
turtle1
Newbie
 
Posts: 9
Joined: Wed Sep 20, 2023 3:45 pm


Return to Support Forum

Who is online

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