-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
DefaultApp.cs
121 lines (109 loc) · 4.51 KB
/
DefaultApp.cs
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// 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;
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, IDisposable
{
private bool isDisposed;
/// <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();
}
}
}
/// <summary>
/// Releases unmanaged and managed resources
/// </summary>
/// <param name="disposing"><see langword="true" /> to release both managed and unmanaged resources; <see langword="false" /> to release only unmanaged resources.</param>
protected virtual void Dispose(bool disposing)
{
if (!isDisposed)
{
if (disposing)
{
BrowserProcessHandler?.Dispose();
BrowserProcessHandler = null;
}
isDisposed = true;
}
}
/// <inheritdoc/>
void IDisposable.Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}