Is it possible to load javascript from resource?

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.

Is it possible to load javascript from resource?

Postby andornot » Mon Jan 24, 2011 4:42 am

Is it possible to load javascript from resource?
I've been tried the following methods, but does not seem to work.
Is there any other way?

Code: Select all
CefHandler::RetVal ClientHandler::HandleBeforeResourceLoad(
   CefRefPtr<CefBrowser> browser, CefRefPtr<CefRequest> request,
   CefString& redirectUrl, CefRefPtr<CefStreamReader>& resourceStream,
   CefString& mimeType, int loadFlags)
{
   std::wstring url = request->GetURL();

   if (url.find(_T("myscript.js")) != std::wstring::npos) {

      DWORD dwSize;
      LPBYTE pBytes;

      if (LoadBinaryResource(L"IDR_MY_SCRIPT", dwSize, pBytes)) {

         resourceStream = CefStreamReader::CreateForHandler(
            new CefByteReadHandler(pBytes, dwSize, NULL));

         mimeType = _T("text/javascript");

         return RV_HANDLED;
      }
   }

   return RV_CONTINUE;
}
andornot
Newbie
 
Posts: 3
Joined: Tue Dec 21, 2010 9:08 pm

Re: Is it possible to load javascript from resource?

Postby magreenblatt » Mon Jan 24, 2011 11:22 am

How are you initiating the request? HandleBeforeResourceLoad is only called when loading resources during page load. For example, if you load an HTML page that requests a JavaScript file you should see a call to HandleBeforeResourceLoad for that file.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 55 guests