The Correct way to Work with CookieManager in VC++?

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.

The Correct way to Work with CookieManager in VC++?

Postby LJSong » Fri Dec 19, 2014 12:38 am

Sorry I can't find a complete tutorial or example to work with CefCookieManager so had to find help here.
any tip will be appreicate.
I just want to study the usage of CefCookieManager,so I test my code in cefSimple project packed wtih Cef3 downloads.I use cef3.1750(win32),vs2013(vc12),windows7
First,I write a class(WXRequestContextHandler) which inherited form CefRequestContextHandler,like this:
Code: Select all
#include "include/cef_app.h"
#include "include/cef_request_context_handler.h"
#include "include/cef_cookie.h"

class WXRequestContextHandler :public CefRequestContextHandler
{
public:
   WXRequestContextHandler(){};
   ~WXRequestContextHandler(){};
   CefRefPtr<CefCookieManager> GetCookieManager() OVERRIDE{
         
      return CefCookieManager::CreateManager("F:\\CefCookie",FALSE);
   }
private:
   // Include the default reference counting implementation.
   IMPLEMENT_REFCOUNTING(WXRequestContextHandler);
};


then Create an instance of this Class,like this:
Code: Select all
CefRefPtr<CefRequestContext> rc = CefRequestContext::CreateContext(new WXRequestContextHandler());


and Create the browser:
Code: Select all
CefBrowserHost::CreateBrowser(window_info, handler.get(), url,
                                browser_settings, rc);


OK,I don't know anymore about the CefCookieManager,so I run the code press F5,and got a exception(triggered in libcef.dll ,access violation 0xc0000005),the cefSimple application crashed.
I noticted the getCookieManager methed was called and when it return the exception will be triggered.but if it return NULL(which means use global cookieManager) the app runs as normal.
Obviously,I think I didn't use the CookieManager::CreateManager Correctly.
My problem is:what is the correct way to use CefCookieManager::CreateManager?
hope help.
advance thank.

Follow is my complete code I revised in CefSimple's simple_app.cpp,just one line code.

Code: Select all
void SimpleApp::OnContextInitialized() {
  REQUIRE_UI_THREAD();

  // 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, "cefsimple");
#endif

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

  // Specify CEF browser settings here.
  CefBrowserSettings browser_settings;

  std::string url;

   url = "http://www.google.com";
 
  //here is my code
  CefRefPtr<CefRequestContext> rc = CefRequestContext::CreateContext(new WXRequestContextHandler());

  // Create the first browser window.
  CefBrowserHost::CreateBrowser(window_info, handler.get(), url,
                                browser_settings, rc);
}
LJSong
Newbie
 
Posts: 6
Joined: Thu Dec 18, 2014 11:40 pm

Re: The Correct way to Work with CookieManager in VC++?

Postby magreenblatt » Fri Dec 19, 2014 5:56 am

It's likely trying to create multiple CookieManager instances accessing the same path ("F:\\CefCookie"). Try creating the CookieManager in the WXRequestContextHandler constructor and always returning the single instance of it.
magreenblatt
Site Admin
 
Posts: 12407
Joined: Fri May 29, 2009 6:57 pm

Re: The Correct way to Work with CookieManager in VC++?

Postby LJSong » Fri Dec 19, 2014 7:16 am

yep! that's the way,thank magreenblatt!
Now I noticed that the method GetCookieManager was called many times,even I create only one browser window.
thanks again!
LJSong
Newbie
 
Posts: 6
Joined: Thu Dec 18, 2014 11:40 pm


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 13 guests