况洋洋
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright © 2020 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.
 
using CefSharp.Internals;
 
namespace CefSharp.JavascriptBinding
{
    /// <summary>
    /// Javascript Binding Settings
    /// </summary>
    public class JavascriptBindingSettings : FreezableBase
    {
        private bool alwaysInterceptAsynchronously;
        private bool legacyBindingEnabled;
        private string jsBindingGlobalObjectName;
        private bool jsBindingApiEnabled = true;
 
        /// <summary>
        /// The Javascript methods that CefSharp provides in relation to JavaScript Binding are
        /// created using a Global (window) Object. Settings this property allows you to disable
        /// the creation of this object. Features like EvaluateScriptAsPromiseAsync that rely on
        /// the creation of this object will no longer function.
        /// </summary>
        public bool JavascriptBindingApiEnabled
        {
            get { return jsBindingApiEnabled; }
            set
            {
                ThrowIfFrozen();
 
                jsBindingApiEnabled = value;
            }
        }
 
        /// <summary>
        /// The Javascript methods that CefSharp provides in relation to JavaScript Binding are
        /// created using a Global (window) Object. Settings this property allows you to customise
        /// the name of this object. If not specified then both cefSharp and CefSharp objects will
        /// be created e.g. cefSharp.bindObjectAsync, CefSharp.BindObjectAsync.
        /// If specified then your custom name will be used, if the name starts with a lowercase letter
        /// then all the functions will be lowercase, e.g. myObjName.bindObjectAsync otherwise
        /// the functions will start with a uppercase letter e.g. MyObjName.BindObjectAsync
        /// </summary>
        /// <remarks>
        /// This object is also accessible through the window property. e.g. window.cefSharp.bindObjectAsync
        /// </remarks>
        public string JavascriptBindingApiGlobalObjectName
        {
            get { return jsBindingGlobalObjectName; }
            set
            {
                ThrowIfFrozen();
 
                if (!StringCheck.IsLettersAndNumbers(value))
                {
                    //TODO: See if there's a better suited Exception class for this.
                    throw new System.Exception("invalid or illegal characters used for binding property names. Alphanumeric and underscores characters only.");
                }
 
                jsBindingGlobalObjectName = value;
            }
        }
 
        /// <summary>
        /// Objects registered using <see cref="IJavascriptObjectRepository.Register"/>
        /// will be automatically bound when a V8Context is created. (Soon as the Javascript
        /// context is created for a browser). This behaviour is like that seen with Javascript
        /// Binding in version 57 and earlier.
        /// </summary>
        public bool LegacyBindingEnabled
        {
            get { return legacyBindingEnabled; }
            set
            {
                ThrowIfFrozen();
 
                legacyBindingEnabled = value;
            }
        }
 
        /// <summary>
        /// When using an <see cref="CefSharp.ModelBinding.IAsyncMethodInterceptor"/>
        /// the <see cref="CefSharp.ModelBinding.IAsyncMethodInterceptor.InterceptAsync(System.Func{object[], object}, object[], string)"/>
        /// method is call for all methods (the default is to call InterceptAsync only for methods that return a Task).
        /// This only applies when <see cref="BindingOptions.MethodInterceptor"/> is of type <see cref="CefSharp.ModelBinding.IAsyncMethodInterceptor"/>
        /// </summary>
        public bool AlwaysInterceptAsynchronously
        {
            get { return alwaysInterceptAsynchronously; }
            set
            {
                ThrowIfFrozen();
 
                alwaysInterceptAsynchronously = value;
            }
        }
    }
}