How to use CefPostTask on browser process?

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.

How to use CefPostTask on browser process?

Postby tiplip » Mon Nov 06, 2017 1:26 am

Hi,

I am on CEF3 2623.1401 (to work with XP).

I create CefURLRequest on render process, after that, I want to delete cookies at runtime. So I use SendProcessMessage to browser.

I handle the message in ClientHandler::OnProcessMessageReceived

Code: Select all
    CefRefPtr<CefListValue> args = message->GetArgumentList();
    const CefString& domain = args->GetString(0);
    CefRefPtr<CefCookieManager> manager =
        CefCookieManager::GetGlobalManager(NULL);
    //manager->DeleteCookies(domain, "", NULL);

    CefPostTask(TID_IO, base::Bind(&CefCookieManager::DeleteCookies, manager, domain));

    return true;


compile error:

Code: Select all
1>D:\Develop\CEF3\cef_binary_3.2623.1401.gb90a3be_windows32\cefclient\browser\client_handler.cc(248): error C2665: 'CefPostTask' : none of the 2 overloads could convert all the argument types
1>          D:\Develop\CEF3\cef_binary_3.2623.1401.gb90a3be_windows32\include/cef_task.h(137): could be 'bool CefPostTask(CefThreadId,CefRefPtr<T>)'
1>          with
1>          [
1>              T=CefTask
1>          ]
1>          D:\Develop\CEF3\cef_binary_3.2623.1401.gb90a3be_windows32\include/wrapper/cef_closure_task.h(93): or       'bool CefPostTask(CefThreadId,const base::Closure &)'
1>          while trying to match the argument list '(cef_thread_id_t, base::Callback<Sig>)'
1>          with
1>          [
1>              Sig=bool (void)
1>          ]


where am I wrong?

what's the right way for my case? from render

thanks.
tiplip
Mentor
 
Posts: 77
Joined: Thu Mar 26, 2015 3:09 am

Re: How to use CefPostTask on browser process?

Postby magreenblatt » Mon Nov 06, 2017 9:21 am

You need to use base::IgnoreResult(&CefCookieManager::DeleteCookies)
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: How to use CefPostTask on browser process?

Postby tiplip » Mon Nov 06, 2017 10:16 pm

magreenblatt wrote:You need to use base::IgnoreResult(&CefCookieManager::DeleteCookies)


hi, I tried your advice as follows
Code: Select all
bool ClientHandler::OnProcessMessageReceived(
    CefRefPtr<CefBrowser> browser,
    CefProcessId source_process,
    CefRefPtr<CefProcessMessage> message) {
  CEF_REQUIRE_UI_THREAD();
...
if (message_name == kClearCookies) {
    CefRefPtr<CefListValue> args = message->GetArgumentList();
    const CefString& domain = args->GetString(0);
    CefRefPtr<CefCookieManager> manager =
        CefCookieManager::GetGlobalManager(NULL);
    //manager->DeleteCookies(domain, "", NULL);

    CefPostTask(TID_IO, base::Bind(base::IgnoreResult(&CefCookieManager::DeleteCookies), this, domain));

    return true;
  }


still the same compile error, then I define one new function
Code: Select all
void ClientHandler::ClearCookies(const CefString& domain) {
    CefRefPtr<CefCookieManager> manager =
        CefCookieManager::GetGlobalManager(NULL);
    manager->DeleteCookies(domain, "", NULL);
}

bool ClientHandler::OnProcessMessageReceived(
    CefRefPtr<CefBrowser> browser,
    CefProcessId source_process,
    CefRefPtr<CefProcessMessage> message) {
  CEF_REQUIRE_UI_THREAD();
...
if (message_name == kClearCookies) {
    CefRefPtr<CefListValue> args = message->GetArgumentList();
    const CefString& domain = args->GetString(0);
    //CefRefPtr<CefCookieManager> manager =
    //    CefCookieManager::GetGlobalManager(NULL);
    //manager->DeleteCookies(domain, "", NULL);

    //CefPostTask(TID_IO, base::Bind(base::IgnoreResult(&CefCookieManager::DeleteCookies), this, domain));
    CefPostTask(TID_IO, base::Bind(&ClientHandler::ClearCookies, this, domain));

    return true;
  }


compile successfully, I have no idea about the usage limitation on CefPostTask.

thanks.
tiplip
Mentor
 
Posts: 77
Joined: Thu Mar 26, 2015 3:09 am


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 62 guests