Question about moving the CEF code into a static library

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.

Question about moving the CEF code into a static library

Postby callum » Tue Mar 03, 2015 4:57 pm

I have (Win32) test application working that renders pages to an off-screen buffer.

Now, for the next phase of my project, I want to wrap the CEF code and expose it to my actual application via a static library and a single header file.

However, I don't know how to replicate the structure of the code in the test app that inspects the command like arguments and exits or continues as appropriate, in my wrapper library.

Is there where the concept of a host executable comes in?

Has anyone done this already and can explain how they did it?
callum
Expert
 
Posts: 326
Joined: Mon Feb 23, 2015 6:19 pm

Re: Question about moving the CEF code into a static library

Postby magreenblatt » Tue Mar 03, 2015 5:31 pm

What do you want the API exposed by the single header file to look like?
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Question about moving the CEF code into a static library

Postby callum » Tue Mar 03, 2015 6:14 pm

I was hoping to replace my test app (comprised of a mix of test code and CEF calls) with something like this that builds against ceflib.lib and ceflib.h
Code: Select all
CEFLIb* lib = new CEFLib(512, 512);

lib->navigateTo("http://news.google.com");

while( ! app_done )
{
    // service work/message loop
    lib->update();

    // render to memory for use in texture later
    if ( lib->pageChanged() )
    {
        mempcy(myPixels, lib->getPixels());
    }

    // trigger mouse events as they come in maybe
    lib->mouseEvent(MOVE, x, y);
}

lib->reset();
callum
Expert
 
Posts: 326
Joined: Mon Feb 23, 2015 6:19 pm

Re: Question about moving the CEF code into a static library

Postby magreenblatt » Tue Mar 03, 2015 7:03 pm

Implementing a procedural structure like you're describing is going to be difficult given the asynchronous nature of CEF callbacks. You would likely have better success defining an API with limited callbacks and extending/implementing it for a specific test. For example:

Code: Select all
// Manages CEF life span.
class CefTestRunner {
 public:
  void Initialize(...);
  void RunMessageLoop();
  void QuitMessageLoop();
  void RunTest(CefTestHandler* handler, int width, int height);
};

// Represents a browser.
class CefTestBrowser {
 public:
  virtual void SendMouseEvent(...) = 0;
  ...
};

// Represents a handler.
class CefTestHandler {
 public:
  virtual void OnBrowserCreated(CefTestBrowser* browser, ...) = 0;
  virtual void OnBrowserDestroyed(CefTestBrowser* browser, ...) = 0;
  virtual void OnContentLoaded(CefTestBrowser* browser, ...) = 0;
  virtual void OnContentChanged(CefTestBrowser* browser, ...) = 0;
  virtual void OnContentRendered(CefTestBrowser* browser, ...) = 0;
  ...
};

// Concrete handler implementation.
class MyTestHandler : public CefTestHandler {
 public:
  explicit MyTestHandler(CefTestRunner* test_runner) : test_runner_(test_runner) {}
  ...
  void OnBrowserDestroyed(CefTestBrowser* browser, ...) override {
    test_runner_->QuitMessageLoop();
  }
  ...
  void OnContentRendered(CefTestBrowser* browser, ...) override {
    // Copy the pixel buffer somewhere
  }

 private:
  CefTestRunner* test_runner_;
};

// In the application main() function or similar.
CefTestRunner test_runner;
test_runner.Initialize(...);
test_runner.RunTest(new MyTestHandler(&test_runner), 512, 512);
test_runner.RunMessageLoop();  // Blocks until QuitMessageLoop() is called.
test_runner.Shutdown();
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm


Return to Support Forum

Who is online

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