CefCookieAccessFilter.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. namespace Xilium.CefGlue
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Diagnostics;
  6. using System.Runtime.InteropServices;
  7. using Xilium.CefGlue.Interop;
  8. /// <summary>
  9. /// Implement this interface to filter cookies that may be sent or received from
  10. /// resource requests. The methods of this class will be called on the IO thread
  11. /// unless otherwise indicated.
  12. /// </summary>
  13. public abstract unsafe partial class CefCookieAccessFilter
  14. {
  15. private int can_send_cookie(cef_cookie_access_filter_t* self, cef_browser_t* browser, cef_frame_t* frame, cef_request_t* request, cef_cookie_t* cookie)
  16. {
  17. CheckSelf(self);
  18. var m_browser = CefBrowser.FromNativeOrNull(browser);
  19. var m_frame = CefFrame.FromNativeOrNull(frame);
  20. var m_request = CefRequest.FromNative(request);
  21. var m_cookie = CefCookie.FromNative(cookie);
  22. var m_result = CanSendCookie(m_browser, m_frame, m_request, m_cookie);
  23. return m_result ? 1 : 0;
  24. }
  25. /// <summary>
  26. /// Called on the IO thread before a resource request is sent. The |browser|
  27. /// and |frame| values represent the source of the request, and may be NULL for
  28. /// requests originating from service workers or CefURLRequest. |request|
  29. /// cannot be modified in this callback. Return true if the specified cookie
  30. /// can be sent with the request or false otherwise.
  31. /// </summary>
  32. protected abstract bool CanSendCookie(CefBrowser browser, CefFrame frame, CefRequest request, CefCookie cookie);
  33. private int can_save_cookie(cef_cookie_access_filter_t* self, cef_browser_t* browser, cef_frame_t* frame, cef_request_t* request, cef_response_t* response, cef_cookie_t* cookie)
  34. {
  35. CheckSelf(self);
  36. var m_browser = CefBrowser.FromNativeOrNull(browser);
  37. var m_frame = CefFrame.FromNativeOrNull(frame);
  38. var m_request = CefRequest.FromNative(request);
  39. var m_response = CefResponse.FromNative(response);
  40. var m_cookie = CefCookie.FromNative(cookie);
  41. var m_result = CanSaveCookie(m_browser, m_frame, m_request, m_response, m_cookie);
  42. return m_result ? 1 : 0;
  43. }
  44. /// <summary>
  45. /// Called on the IO thread after a resource response is received. The
  46. /// |browser| and |frame| values represent the source of the request, and may
  47. /// be NULL for requests originating from service workers or CefURLRequest.
  48. /// |request| cannot be modified in this callback. Return true if the specified
  49. /// cookie returned with the response can be saved or false otherwise.
  50. /// </summary>
  51. protected abstract bool CanSaveCookie(CefBrowser browser, CefFrame frame, CefRequest request, CefResponse response, CefCookie cookie);
  52. }
  53. }