I want to detect that the next navigation is to a page that I care about, and if so to set an in-memory cookie. This is what I've tried in CefClient - client_app.cc, but it just kills the render process:
- Code: Select all
#include "include/cef_runnable.h"
bool ClientApp::OnBeforeNavigation(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
NavigationType navigation_type,
bool is_redirect) {
// set cookie if dell.com - home - laptops (http://www.dell.com/us/p/laptops.aspx?~ck=mn)
std::string strURL = request->GetURL();
if (strURL.find("dell.com") != std::string::npos && strURL.find("laptops") != std::string::npos)
{
// CefRefPtr<CefCookieManager> cookie_manager = CefCookieManager::GetGlobalManager();
CefCookieManager* cookie_manager = CefCookieManager::GetGlobalManager();
CefCookie cookie;
CefString(&cookie.name).FromASCII("testname");
CefString(&cookie.value).FromASCII("testval");
BOOL okc = CefPostTask(TID_IO, NewCefRunnableMethod(cookie_manager, &CefCookieManager::SetCookie, strURL, cookie)); // async so true response not reliable
// ** above terminates render thread **
}
...
Can anyone point out what I'm doing wrong? (Or can you supply a working example?)
Can I do this with JavaScript instead, *in this event*? A sample of that would be very helpful too. I just need to set an in-memory cookie here, I don't care how