况洋洋
2025-07-04 0d247bd2a17e0f99f3609774a1ce54ae00857997
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright © 2021 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
 
namespace CefSharp.Handler
{
    /// <summary>
    /// Inherit from this class to filter cookies that may be sent or received from
    /// resource requests. The methods of this class will be called on the CEF IO thread
    /// unless otherwise indicated.
    /// </summary>
    public class CookieAccessFilter : ICookieAccessFilter
    {
        /// <inheritdoc/>
        bool ICookieAccessFilter.CanSendCookie(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, Cookie cookie)
        {
            return CanSendCookie(chromiumWebBrowser, browser, frame, request, cookie);
        }
 
        /// <summary>
        /// Called on the CEF IO thread before a resource request is sent.
        /// </summary>
        /// <param name="chromiumWebBrowser">The ChromiumWebBrowser control</param>
        /// <param name="browser">the browser object - may be null if originating from ServiceWorker or CefURLRequest</param>
        /// <param name="frame">the frame object - may be null if originating from ServiceWorker or CefURLRequest</param>
        /// <param name="request">the request object - cannot be modified in this callback</param>
        /// <param name="cookie">the cookie object</param>
        /// <returns>Return true if the specified cookie can be sent with the request or false otherwise.</returns>
        protected virtual bool CanSendCookie(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, Cookie cookie)
        {
            return false;
        }
 
        /// <inheritdoc/>
        bool ICookieAccessFilter.CanSaveCookie(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, IResponse response, Cookie cookie)
        {
            return CanSaveCookie(chromiumWebBrowser, browser, frame, request, response, cookie);
        }
 
        /// <summary>
        /// Called on the CEF IO thread after a resource response is received.
        /// </summary>
        /// <param name="chromiumWebBrowser">The ChromiumWebBrowser control</param>
        /// <param name="browser">the browser object - may be null if originating from ServiceWorker or CefURLRequest</param>
        /// <param name="frame">the frame object - may be null if originating from ServiceWorker or CefURLRequest</param>
        /// <param name="request">the request object - cannot be modified in this callback</param>
        /// <param name="response">the response object - cannot be modified in this callback</param>
        /// <param name="cookie">the cookie object</param>
        /// <returns>Return true if the specified cookie returned with the response can be saved or false otherwise.</returns>
        protected virtual bool CanSaveCookie(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, IResponse response, Cookie cookie)
        {
            return false;
        }
    }
}