• 一起学libcef--给你的浏览器删除cookie


    long long ago, 我们讨论了如给你cef设置cookie.

    如今来补充一点,假设给你的浏览器删除某一cookie。

    review一下设置cookie:

        std::wstring username_key = L"username";
        std::wstring username_value = L"xidada";
        std::wstring domain = L"blog.csdn.net"
    
        CefRefPtr<CefCookieManager> manager = CefCookieManager::GetGlobalManager();
        CefCookie cookie;
        CefString(&cookie.name).FromWString(username_key.c_str());
        CefString(&cookie.value).FromWString(username_value.c_str());
        CefString(&cookie.domain).FromWString(domain.c_str());
        CefString(&cookie.path).FromASCII("/");
        cookie.has_expires = false;
    
        domain = L"https://" + domain;
        CefPostTask(TID_IO, NewCefRunnableMethod(manager.get(), &CefCookieManager::SetCookie,CefString(domain.c_str()), cookie));
    
    //创建浏览器
        CefBrowserHost::CreateBrowser(info, g_web_browser_client.get(),
            domain.c_str(), browserSettings, NULL);

    如今就開始删除某一cookie:
    DeleteCookies
    看看函数描写叙述:

    // Delete all cookies that match the specified parameters. If both |url| and
      // values |cookie_name| are specified all host and domain cookies matching
      // both will be deleted. If only |url| is specified all host cookies (but not
      // domain cookies) irrespective of path will be deleted. If |url| is empty all
      // cookies for all hosts and domains will be deleted. Returns false if a non-
      // empty invalid URL is specified or if cookies cannot be accessed. This
      // method must be called on the IO thread.
      ///
      /*--cef(optional_param=url,optional_param=cookie_name)--*/
      virtual bool DeleteCookies(const CefString& url,
                                 const CefString& cookie_name) =0;

    应用:

    CefPostTask(TID_IO, NewCefRunnableMethod(manager.get(), &CefCookieManager::DeleteCookies,
            CefString(domain.c_str()), CefString("username")));

    以上代码就删除了为”blog.csdn.net”设置的cookie:
    username = xidada

  • 相关阅读:
    DOM和XMLHttpRequest对象的属性和方法
    【代码版】今天,你的密码泄露了吗?
    使用Smarty的相关注意事项及访问变量的几种方式
    HttpWatch工具简介及使用技巧
    Smarty中的请求变量和保留变量的使用范例
    Linux管道操作
    发布mvc3报错:403.14Forbidden Web 服务器被配置为不列出此目录的内容
    仿Linux中的cp操作
    Fedora的ifconfig命令
    @ Register和@ Reference的区别
  • 原文地址:https://www.cnblogs.com/llguanli/p/7198637.html
Copyright © 2020-2023  润新知