1 // Copyright (c) 2019 The Chromium Embedded Framework Authors. All rights 2 // reserved. Use of this source code is governed by a BSD-style license that can 3 // be found in the LICENSE file. 4 5 #ifndef CEF_LIBCEF_BROWSER_NET_SERVICE_COOKIE_HELPER_H_ 6 #define CEF_LIBCEF_BROWSER_NET_SERVICE_COOKIE_HELPER_H_ 7 8 #include "libcef/browser/browser_context.h" 9 10 #include "base/callback_forward.h" 11 #include "net/cookies/canonical_cookie.h" 12 13 namespace net { 14 class HttpResponseHeaders; 15 } 16 17 namespace network { 18 struct ResourceRequest; 19 } // namespace network 20 21 namespace net_service { 22 namespace cookie_helper { 23 24 // Returns true if the scheme for |url| supports cookies. |cookieable_schemes| 25 // is the optional list of schemes that the client has explicitly registered as 26 // cookieable, which may intentionally exclude standard schemes. 27 bool IsCookieableScheme( 28 const GURL& url, 29 const absl::optional<std::vector<std::string>>& cookieable_schemes); 30 31 using AllowCookieCallback = 32 base::RepeatingCallback<void(const net::CanonicalCookie&, 33 bool* /* allow */)>; 34 using DoneCookieCallback = 35 base::OnceCallback<void(int /* total_count */, 36 net::CookieList /* allowed_cookies */)>; 37 38 // Load cookies for |request|. |allow_cookie_callback| will be executed for each 39 // cookie and should return true to allow it. |done_callback| will be executed 40 // on completion with |total_count| representing the total number of cookies 41 // retrieved, and |allowed_cookies| representing the list of cookies that were 42 // both retrieved and allowed by |allow_cookie_callback|. The loaded cookies 43 // will not be set on |request|; that should be done in |done_callback|. Must be 44 // called on the IO thread. 45 void LoadCookies(const CefBrowserContext::Getter& browser_context_getter, 46 const network::ResourceRequest& request, 47 const AllowCookieCallback& allow_cookie_callback, 48 DoneCookieCallback done_callback); 49 50 // Save cookies from |head|. |allow_cookie_callback| will be executed for each 51 // cookie and should return true to allow it. |done_callback| will be executed 52 // on completion with |total_count| representing the total number of cookies 53 // retrieved, and |allowed_cookies| representing the list of cookies that were 54 // both allowed by |allow_cookie_callback| an successfully saved. Must be called 55 // on the IO thread. 56 void SaveCookies(const CefBrowserContext::Getter& browser_context_getter, 57 const network::ResourceRequest& request, 58 net::HttpResponseHeaders* headers, 59 const AllowCookieCallback& allow_cookie_callback, 60 DoneCookieCallback done_callback); 61 62 } // namespace cookie_helper 63 } // namespace net_service 64 65 #endif // CEF_LIBCEF_BROWSER_NET_SERVICE_COOKIE_HELPER_H_ 66