Files
cefsharp/CefSharp/DefaultResourceHandlerFactory.cs
T
2015-03-03 00:19:52 -05:00

37 lines
1.1 KiB
C#

// Copyright © 2010-2014 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
{
public class DefaultResourceHandlerFactory : IResourceHandlerFactory
{
public Dictionary<string, ResourceHandler> Handlers { get; private set; }
public DefaultResourceHandlerFactory(IEqualityComparer<string> comparer = null)
{
Handlers = new Dictionary<string, ResourceHandler>(comparer ?? StringComparer.OrdinalIgnoreCase);
}
public virtual void RegisterHandler(string url, ResourceHandler handler)
{
Handlers[url] = handler;
}
public virtual void UnregisterHandler(string url)
{
Handlers.Remove(url);
}
public virtual ResourceHandler GetResourceHandler(IWebBrowser browser, IRequest request)
{
ResourceHandler handler;
return Handlers.TryGetValue(request.Url, out handler) ? handler : null;
}
}
}