Calling LoadUrl() from OnProcessMessageReceived()

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.

Calling LoadUrl() from OnProcessMessageReceived()

Postby eren » Thu Jul 10, 2014 8:40 am

In CEF3 i'm trying to call frame->LoadUrl() inside of ClientHandler::OnProcessMessageReceived function.
Code: Select all
bool ClientHandler::OnProcessMessageReceived(
    CefRefPtr<CefBrowser> browser,
    CefProcessId source_process,
    CefRefPtr<CefProcessMessage> message)
{
   // Check for messages from the client renderer.
   std::string message_name = message->GetName();
   
   if (message_name == client_renderer::kFocusedNodeChangedMessage)
   {
      // A message is sent from ClientRenderDelegate to tell us whether the
      // currently focused DOM node is editable. Use of |m_bFocusOnEditableField|
      // is redundant with CefKeyEvent.focus_on_editable_field in OnPreKeyEvent
      // but is useful for demonstration purposes.
      m_bFocusOnEditableField = message->GetArgumentList()->GetBool(0);
      return true;
   }
   // my code
   //---------------------------------------------------------------------
   else if (message_name == "my_message")
   {
      CefString url = message->GetArgumentList()->GetString(0);
      browser->GetMainFrame()->LoadURL(url);
   }
   //---------------------------------------------------------------------
   
   bool handled = false;
   
   // Execute delegate callbacks.
   ProcessMessageDelegateSet::iterator it = process_message_delegates_.begin();
   for (; it != process_message_delegates_.end() && !handled; ++it)
   {
      handled = (*it)->OnProcessMessageReceived(
         this, browser, source_process, message);
   }
   
   return handled;
}

url is valid but application crashes when i call LoadUrl() method.

I also tried to do it via CefPostTask like this:
Code: Select all
bool ClientHandler::OnProcessMessageReceived(
    CefRefPtr<CefBrowser> browser,
    CefProcessId source_process,
    CefRefPtr<CefProcessMessage> message)
{
   // Check for messages from the client renderer.
   std::string message_name = message->GetName();
   
   if (message_name == client_renderer::kFocusedNodeChangedMessage)
   {
      // A message is sent from ClientRenderDelegate to tell us whether the
      // currently focused DOM node is editable. Use of |m_bFocusOnEditableField|
      // is redundant with CefKeyEvent.focus_on_editable_field in OnPreKeyEvent
      // but is useful for demonstration purposes.
      m_bFocusOnEditableField = message->GetArgumentList()->GetBool(0);
      return true;
   }
   // my code
   //---------------------------------------------------------------------
   else if (message_name == "my_message")
   {
      CefString url = message->GetArgumentList()->GetString(0);
      
      CefRefPtr<CefTask> loadUrlTask =
         NewCefRunnableMethod(this, &ClientHandler::OpenURL, url);
      CefPostTask(TID_UI, loadUrlTask);
   }
   //---------------------------------------------------------------------
   
   bool handled = false;
   
   // Execute delegate callbacks.
   ProcessMessageDelegateSet::iterator it = process_message_delegates_.begin();
   for (; it != process_message_delegates_.end() && !handled; ++it)
   {
      handled = (*it)->OnProcessMessageReceived(
         this, browser, source_process, message);
   }
   
   return handled;
}

// my code
//---------------------------------------------------------------------
void ClientHandler::OpenURL(const CefString& _url)
{
   this->GetBrowser()->GetMainFrame()->LoadURL(_url);
}
//---------------------------------------------------------------------

But application still crashes right after LoadURL() being called.

Am i doing it wrong?
And what is the right way to load URL when some message from render process arrieved to browser porcess?
CEF v3.1650.1567_windows32
eren
Techie
 
Posts: 25
Joined: Mon Feb 03, 2014 8:11 am

Re: Calling LoadUrl() from OnProcessMessageReceived()

Postby magreenblatt » Thu Jul 10, 2014 9:12 am

What process is crashing? What is the call stack for the crash? You can get VS2013 debug symbols from http://cefbuilds.com or wherever you download the binary distribution.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Calling LoadUrl() from OnProcessMessageReceived()

Postby eren » Thu Jul 10, 2014 10:14 am

Here is the call stack:
Code: Select all
libcef.dll!content::WebContentsImpl::UpdateTitle()Line 3211   C++
libcef.dll!content::RenderViewHostImpl::OnUpdateTitle()Line 1286   C++
libcef.dll!DispatchToMethod<content::RenderViewHostImpl,void (__thiscall content::RenderViewHostImpl::*)(int,std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> > const &,enum WebKit::WebTextDirection),int,std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >,enum WebKit::WebTextDirection>() Line 564   C++
libcef.dll!ViewHostMsg_UpdateTitle::Dispatch<content::RenderViewHostImpl,content::RenderViewHostImpl,void (__thiscall content::RenderViewHostImpl::*)(int,std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> > const &,enum WebKit::WebTextDirection)>() Line 1553    C++
libcef.dll!content::RenderViewHostImpl::OnMessageReceived()Line 944   C++
libcef.dll!content::RenderProcessHostImpl::OnMessageReceived()Line 1282   C++
libcef.dll!IPC::ChannelProxy::Context::OnDispatchMessage()Line 264   C++
libcef.dll!base::internal::RunnableAdapter<void (__thiscall IPC::ChannelProxy::Context::*)(IPC::Message const &)>::Run()Line 190   C++
libcef.dll!base::internal::InvokeHelper<0,void,base::internal::RunnableAdapter<void (__thiscall IPC::ChannelProxy::Context::*)(IPC::Message const &)>,void __cdecl(IPC::ChannelProxy::Context * const &,IPC::Message const &)>::MakeItSo()Line 899   C++
libcef.dll!base::internal::Invoker<2,base::internal::BindState<base::internal::RunnableAdapter<void (__thiscall IPC::ChannelProxy::Context::*)(IPC::Message const &)>,void __cdecl(IPC::ChannelProxy::Context *,IPC::Message const &),void __cdecl(IPC::ChannelProxy::Context *,IPC::Message)>,void __cdecl(IPC::ChannelProxy::Context *,IPC::Message const &)>::Run() Line 1253   C++
libcef.dll!base::Callback<void __cdecl(void)>::Run()Line 396   C++
libcef.dll!base::MessageLoop::RunTask() Line 493   C++
libcef.dll!base::MessageLoop::DeferOrRunPendingTask() Line 506   C++
libcef.dll!base::MessageLoop::DoWork() Line 617   C++
libcef.dll!base::MessagePumpForUI::DoRunLoop() Line 243   C++
libcef.dll!base::MessagePumpWin::RunWithDispatcher() Line 65   C++
libcef.dll!base::MessagePumpWin::Run() Line 48   C++
libcef.dll!base::MessageLoop::RunInternal() Line 441   C++
libcef.dll!base::MessageLoop::RunHandler() Line 414   C++
libcef.dll!base::RunLoop::Run() Line 48   C++
libcef.dll!base::MessageLoop::Run() Line 312   C++
libcef.dll!CefBrowserMessageLoop::RunMessageLoop() Line 28   C++
libcef.dll!CefRunMessageLoop() Line167   C++
libcef.dll!cef_run_message_loop() Line 261   C++
>   my_cef_app.exe!CefRunMessageLoop() Line 252   C++
my_cef_app.exe!wWinMain(HINSTANCE__ * hInstance, HINSTANCE__ * hPrevInstance, wchar_t * lpCmdLine, int nCmdShow) Line 146   C++
my_cef_app.exe!__tmainCRTStartup() Line 237   C
my_cef_app.exe!wWinMainCRTStartup() Line 164   C
Last edited by eren on Thu Jul 10, 2014 10:29 am, edited 2 times in total.
CEF v3.1650.1567_windows32
eren
Techie
 
Posts: 25
Joined: Mon Feb 03, 2014 8:11 am

Re: Calling LoadUrl() from OnProcessMessageReceived()

Postby magreenblatt » Thu Jul 10, 2014 10:20 am

Can you get line numbers in the call stack? Or is "3221" the line number?
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Calling LoadUrl() from OnProcessMessageReceived()

Postby eren » Thu Jul 10, 2014 10:25 am

Yes, line numbers already are there. It's just i mistranslated the word "Line" :) My Visual Studio localization is not english. I fixed it.
CEF v3.1650.1567_windows32
eren
Techie
 
Posts: 25
Joined: Mon Feb 03, 2014 8:11 am

Re: Calling LoadUrl() from OnProcessMessageReceived()

Postby magreenblatt » Thu Jul 10, 2014 10:59 am

It seems to be crashing on this line in http://src.chromium.org/svn/branches/16 ... ts_impl.cc:
Code: Select all
if (entry == controller_.GetEntryAtOffset(0))

That doesn't point to any obvious cause. What kind of crash is it (bad access, etc), and what is the crash memory address?
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Calling LoadUrl() from OnProcessMessageReceived()

Postby eren » Fri Jul 11, 2014 3:07 am

eren wrote:url is valid but application crashes when i call LoadUrl() method

My fault :? It seems that the requested page has been deleted from the server and URL has stopped being valid.

So the real error was on the "404 Not Found" error handling.

Working late causes inadvertence. I'm sorry.
CEF v3.1650.1567_windows32
eren
Techie
 
Posts: 25
Joined: Mon Feb 03, 2014 8:11 am


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 87 guests