IPC V8 to Native C++

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.

IPC V8 to Native C++

Postby Concorde » Sat Mar 17, 2018 4:19 pm

I am very much a newbie and can't seem to do this. It seems I need to use a scheme handler to accomplish this, I call CefRegisterSchemeHandlerFactory from CefBrowserProcessHandler::OnContextInitialized with my implementation of CefSchemeHandlerFactory and CefResourceHandler. Now, I can't hit a break-point at MySchemeHandlerFactory::Create function after a GET request is sent from V8 . AFAIK, a request like such should execute MySchemeHandlerFactory::Create .
Code: Select all
                  var Request = new XMLHttpRequest();
                  Request.addEventListener("load", reqListener);
                  Request.open("GET", "client://myapp");
                  Request.send();


Code: Select all
class MySchemeHandlerFactory : public CefSchemeHandlerFactory, public CefResourceHandler
{
public:
   MySchemeHandlerFactory()
   {
      getchar();
   }

   virtual CefRefPtr<CefResourceHandler> Create(CefRefPtr< CefBrowser > browser, CefRefPtr< CefFrame > frame, const CefString& scheme_name, CefRefPtr< CefRequest > request) OVERRIDE
   {


      const std::string& html_content = "<html><body>Hello!< / body>< / html>";

      // Create a stream reader for |html_content|.
      CefRefPtr<CefStreamReader> stream =
         CefStreamReader::CreateForData(
            static_cast<void*>(const_cast<char*>(html_content.c_str())),
            html_content.size());

      // Constructor for HTTP status code 200 and no custom response headers.
      // There’s also a version of the constructor for custom status code and response headers.
      return new CefStreamResourceHandler("text/html", stream);
   }

   virtual void Cancel() OVERRIDE
   {

   }
   virtual bool CanGetCookie(const CefCookie& cookie) OVERRIDE
   {
      return true;
   }
   virtual bool CanSetCookie(const CefCookie& cookie) OVERRIDE
   {
      return true;
   }
   virtual void GetResponseHeaders(CefRefPtr< CefResponse > response, int64& response_length, CefString& redirectUrl) OVERRIDE
   {

   }
   virtual bool ProcessRequest(CefRefPtr< CefRequest > request, CefRefPtr< CefCallback > callback) OVERRIDE
   {
      return true;
   }
   virtual bool ReadResponse(void* data_out, int bytes_to_read, int& bytes_read, CefRefPtr< CefCallback > callback) OVERRIDE
   {
      return true;
   }

   IMPLEMENT_REFCOUNTING(MySchemeHandlerFactory);
};


Any help would be appreciated , thanks :oops: . There is something I'm just not getting.
Concorde
Newbie
 
Posts: 1
Joined: Sat Mar 17, 2018 3:06 pm

Re: IPC V8 to Native C++

Postby payalord » Sun Mar 18, 2018 2:54 am

Are you sure that "CefBrowserProcessHandler::OnContextInitialized" is fired? I had problem with it when I was implementing my custom resource handler. Because my mistake was that i forgot to add as parent to my ClientApp, the class "CefBrowserProcessHandler". So when i changed it

from "class ClientApp : public CefApp, public CefRenderProcessHandler {"
to "class ClientApp : public CefApp, public CefRenderProcessHandler, public CefBrowserProcessHandler {"

I finally hit break-point inside "OnContextInitialized" where i have next:

Code: Select all
   // CefBrowserProcessHandler methods:
   void OnContextInitialized() OVERRIDE {
      // Register the custom scheme handler factory.
      CefRegisterSchemeHandlerFactory("resource", "html", new ResourceShemeHandlerFactory());
   }


and also hit break-point in Create function then. But I'm not sure will my situation help you or not. Maybe your problem is little bit different than mine.
payalord
Techie
 
Posts: 21
Joined: Sun Jan 07, 2018 8:21 am


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 77 guests

cron