GetRenderProcessHandler never called

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.

GetRenderProcessHandler never called

Postby JonasVenture » Thu Oct 06, 2016 1:52 am

simple_app.h
Code: Select all
class SimpleApp : public CefApp,
                  public CefBrowserProcessHandler,
                  public CefRenderProcessHandler {
 public:
  SimpleApp();

  // CefApp methods:
  virtual CefRefPtr<CefBrowserProcessHandler> GetBrowserProcessHandler() OVERRIDE;
  virtual CefRefPtr<CefRenderProcessHandler> GetRenderProcessHandler() OVERRIDE;

  // CefBrowserProcessHandler methods:
  virtual void OnContextInitialized() OVERRIDE;


  // CefRenderProcessHandler methods:
  virtual void OnContextCreated(CefRefPtr<CefBrowser> browser,
    CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context) OVERRIDE;
  virtual void OnContextReleased(CefRefPtr<CefBrowser> browser,
    CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context) OVERRIDE;


 private:
  // Include the default reference counting implementation.
  IMPLEMENT_REFCOUNTING(SimpleApp);
};



simple_app.cc
Code: Select all

#include "simple_app.h"

#include <string>

#include "simple_handler.h"
#include "include/cef_browser.h"
#include "include/cef_command_line.h"
#include "include/views/cef_browser_view.h"
#include "include/views/cef_window.h"
#include "include/wrapper/cef_helpers.h"

namespace {
  // When using the Views framework this object provides the delegate
  // implementation for the CefWindow that hosts the Views-based browser.
  class SimpleWindowDelegate : public CefWindowDelegate {
   public:
    explicit SimpleWindowDelegate(CefRefPtr<CefBrowserView> browser_view)
        : browser_view_(browser_view) {
    }

    void OnWindowCreated(CefRefPtr<CefWindow> window) OVERRIDE {
      // Add the browser view and show the window.
      window->AddChildView(browser_view_);
      window->Show();

      // Give keyboard focus to the browser view.
      browser_view_->RequestFocus();
    }

    void OnWindowDestroyed(CefRefPtr<CefWindow> window) OVERRIDE {
      browser_view_ = NULL;
    }

    bool CanClose(CefRefPtr<CefWindow> window) OVERRIDE {
      // Allow the window to close if the browser says it's OK.
      CefRefPtr<CefBrowser> browser = browser_view_->GetBrowser();
      if (browser)
        return browser->GetHost()->TryCloseBrowser();
      return true;
    }

   private:
    CefRefPtr<CefBrowserView> browser_view_;

    IMPLEMENT_REFCOUNTING(SimpleWindowDelegate);
    DISALLOW_COPY_AND_ASSIGN(SimpleWindowDelegate);
  };
}  // namespace


CefRefPtr<CefBrowserProcessHandler> SimpleApp::GetBrowserProcessHandler() {
  return this;
}
CefRefPtr<CefRenderProcessHandler> SimpleApp::GetRenderProcessHandler() {
  LOG(WARNING) << "TEST";
  return this;
}



SimpleApp::SimpleApp() {
}

std::string getExecutableBaseFolder() {
    std::string path    = "";
    pid_t       pid     = getpid();
    char        buf[20] = {
        0
    };

    sprintf(buf, "%d", pid);
    std::string _link = "/proc/";
    _link.append(buf);
    _link.append("/exe");
    char proc[512];
    int  ch = readlink(_link.c_str(), proc, 512);
    if ( ch != -1 ) {
        proc[ch] = 0;
        path     = proc;
        std::string::size_type t = path.find_last_of("/");
        path = path.substr(0, t);
    }

    return path;
}

void SimpleApp::OnContextInitialized() {
  /**
   *  Browser Creation Preparations
   */
  CEF_REQUIRE_UI_THREAD();

  CefRefPtr<CefCommandLine> command_line =
      CefCommandLine::GetGlobalCommandLine();

#if defined(OS_WIN) || defined(OS_LINUX)
  // Create the browser using the Views framework if "--use-views" is specified
  // via the command-line. Otherwise, create the browser using the native
  // platform framework. The Views framework is currently only supported on
  // Windows and Linux.
  const bool use_views = command_line->HasSwitch("use-views");
#else
  const bool use_views = false;
#endif

  /**
   *  Custom Setup
   */
  // SimpleHandler implements browser-level callbacks.
  CefRefPtr<SimpleHandler> handler(new SimpleHandler(use_views));

  // Specify CEF browser settings here.
  CefBrowserSettings browser_settings;

  std::string url = "file://";
  url.append(getExecutableBaseFolder());
  url.append("/web_files/html/index.html");
  LOG(WARNING) << url;


  /**
   *  Create Browser
   */
  if (use_views) {
    // Create the BrowserView.
    CefRefPtr<CefBrowserView> browser_view = CefBrowserView::CreateBrowserView(
        handler, url, browser_settings, NULL, NULL);

    // Create the Window. It will show itself after creation.
    CefWindow::CreateTopLevelWindow(new SimpleWindowDelegate(browser_view));
  } else {
    // Information used when creating the native window.
    CefWindowInfo window_info;

#if defined(OS_WIN)
    // On Windows we need to specify certain flags that will be passed to
    // CreateWindowEx().
    window_info.SetAsPopup(NULL, "terminal");
#endif

    // Create the first browser window.
    CefBrowserHost::CreateBrowser(window_info, handler, url, browser_settings,
                                  NULL);
  }
}

void SimpleApp::OnContextCreated(CefRefPtr<CefBrowser> browser,
  CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context) {
  LOG(WARNING) << "TEST CREATED";
}

void SimpleApp::OnContextReleased(CefRefPtr<CefBrowser> browser,
      CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context) {
  LOG(WARNING) << "TEST RELEASED";
}




I'm not sure why those log messages aren't showing up, but i never see TEST printed out. Can anyone give me some pointers?
JonasVenture
Newbie
 
Posts: 2
Joined: Thu Oct 06, 2016 1:49 am

Re: GetRenderProcessHandler never called

Postby magreenblatt » Thu Oct 06, 2016 8:59 am

What OS and CEF version? Are you passing a SimpleApp instance to CefExecuteProcess()? The renderer is a separate sandboxed process so you will not see logging output in the console.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: GetRenderProcessHandler never called

Postby JonasVenture » Thu Oct 06, 2016 11:05 am

I'm on ubuntu 16.04 and the latest CEF (checked out yesterday).
Oh, ok so how can i see the logs that happen in the sandboxed renderer process?

I'd like to be able to track what's happening in the code I write. Are my only options single process mode and gdb?

Do you have another suggestion for development work-flow to make tracking what's happening easier?
JonasVenture
Newbie
 
Posts: 2
Joined: Thu Oct 06, 2016 1:49 am

Re: GetRenderProcessHandler never called

Postby magreenblatt » Thu Oct 06, 2016 1:16 pm

If you disable the sandbox (pass `--no-sandbox`) you will see logging in the console from sub-processes. Otherwise, you can check the log file that's specified via CefSettings.log_file. Make sure to specify an appropriate CefSettings.log_severity value.
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 90 guests