admin
2020-06-22 924bdf1c9fb74babf2438d5545db3594756625d1
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
// Copyright © 2019 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 System.Collections.Generic;
 
namespace CefSharp
{
    /// <summary>
    /// Default implementation of <see cref="IApp"/> which represents the CefApp class.
    /// </summary>
    /// <seealso cref="T:CefSharp.IApp"/>
    public class DefaultApp : IApp
    {
        /// <summary>
        /// Return the handler for functionality specific to the browser process. This method is called on multiple threads.
        /// </summary>
        /// <value>
        /// The browser process handler.
        /// </value>
        public IBrowserProcessHandler BrowserProcessHandler { get; private set; }
        /// <summary>
        /// Gets or sets the schemes.
        /// </summary>
        /// <value>
        /// The schemes.
        /// </value>
        public IEnumerable<CefCustomScheme> Schemes { get; private set; }
 
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="browserProcessHandler">The browser process handler.</param>
        /// <param name="schemes">The schemes.</param>
        public DefaultApp(IBrowserProcessHandler browserProcessHandler, IEnumerable<CefCustomScheme> schemes)
        {
            BrowserProcessHandler = browserProcessHandler;
            Schemes = schemes;
        }
 
        /// <summary>
        /// Provides an opportunity to register custom schemes. Do not keep a reference to the <paramref name="registrar"/> object. This
        /// method is called on the main thread for each process and the registered schemes should be the same across all processes.
        /// 
        /// </summary>
        /// <param name="registrar">scheme registra.</param>
        void IApp.OnRegisterCustomSchemes(ISchemeRegistrar registrar)
        {
            OnRegisterCustomSchemes(registrar);
        }
 
        /// <summary>
        /// Provides an opportunity to register custom schemes. Do not keep a reference to the <paramref name="registrar"/> object. This
        /// method is called on the main thread for each process and the registered schemes should be the same across all processes.
        /// 
        /// </summary>
        /// <param name="registrar">scheme registra.</param>
        protected virtual void OnRegisterCustomSchemes(ISchemeRegistrar registrar)
        {
            //Possible we have duplicate scheme names, we'll only register the first one
            //Keep a list so we don't call AddCustomScheme twice for the same scheme name
            var registeredSchemes = new List<string>();
 
            foreach (var scheme in Schemes)
            {
                //We don't need to register http or https, they're built in schemes
                if (scheme.SchemeName == "http" || scheme.SchemeName == "https")
                {
                    continue;
                }
 
                //We've already registered this scheme name
                if (registeredSchemes.Contains(scheme.SchemeName))
                {
                    continue;
                }
 
                var success = registrar.AddCustomScheme(scheme.SchemeName, scheme.Options);
                if (success)
                {
                    registeredSchemes.Add(scheme.SchemeName);
                }
                else
                {
                    var msg = "CefSchemeRegistrar::AddCustomScheme failed for schemeName:" + scheme.SchemeName;
                    //TODO: Log error
                    //LOG(ERROR) << StringUtils::ToNative(msg).ToString();
                }
            }
        }
    }
}