// 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
{
///
/// Default implementation of which represents the CefApp class.
///
///
public class DefaultApp : IApp
{
///
/// Return the handler for functionality specific to the browser process. This method is called on multiple threads.
///
///
/// The browser process handler.
///
public IBrowserProcessHandler BrowserProcessHandler { get; private set; }
///
/// Gets or sets the schemes.
///
///
/// The schemes.
///
public IEnumerable Schemes { get; private set; }
///
/// Constructor.
///
/// The browser process handler.
/// The schemes.
public DefaultApp(IBrowserProcessHandler browserProcessHandler, IEnumerable schemes)
{
BrowserProcessHandler = browserProcessHandler;
Schemes = schemes;
}
///
/// Provides an opportunity to register custom schemes. Do not keep a reference to the object. This
/// method is called on the main thread for each process and the registered schemes should be the same across all processes.
///
///
/// scheme registra.
void IApp.OnRegisterCustomSchemes(ISchemeRegistrar registrar)
{
OnRegisterCustomSchemes(registrar);
}
///
/// Provides an opportunity to register custom schemes. Do not keep a reference to the object. This
/// method is called on the main thread for each process and the registered schemes should be the same across all processes.
///
///
/// scheme registra.
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();
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();
}
}
}
}
}