2018-09-10 02:41:13 +02:00
|
|
|
// Copyright © 2016 The CefSharp Authors. All rights reserved.
|
2016-09-25 20:35:04 +10:00
|
|
|
//
|
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
|
|
|
|
|
2020-09-24 09:45:19 +10:00
|
|
|
namespace CefSharp.Example.Handlers
|
2016-09-25 20:35:04 +10:00
|
|
|
{
|
2020-10-13 13:40:46 +10:00
|
|
|
public class RequestContextHandler : CefSharp.Handler.RequestContextHandler
|
2016-09-25 20:35:04 +10:00
|
|
|
{
|
2020-10-13 13:40:46 +10:00
|
|
|
protected override IResourceRequestHandler GetResourceRequestHandler(IBrowser browser, IFrame frame, IRequest request, bool isNavigation, bool isDownload, string requestInitiator, ref bool disableDefaultHandling)
|
2019-06-11 12:29:57 +10:00
|
|
|
{
|
2022-04-05 11:00:41 +10:00
|
|
|
// Return null for the default behaviour
|
|
|
|
|
//return null;
|
|
|
|
|
|
|
|
|
|
// To handle resource requests at the RequestContext level
|
|
|
|
|
// Implement CefSharp.IResourceRequestHandler or inherit from CefSharp.Handler.ResourceRequestHandler
|
2020-10-13 13:40:46 +10:00
|
|
|
return new ExampleResourceRequestHandler();
|
2019-06-11 12:29:57 +10:00
|
|
|
}
|
2017-12-20 09:52:01 +10:00
|
|
|
|
2020-10-13 13:40:46 +10:00
|
|
|
protected override void OnRequestContextInitialized(IRequestContext requestContext)
|
2018-07-10 20:11:02 +10:00
|
|
|
{
|
2022-04-05 11:00:41 +10:00
|
|
|
// You can set preferences here on your newly initialized request context.
|
|
|
|
|
// Note, there is called on the CEF UI Thread, so you can directly call SetPreference
|
2018-07-10 20:11:02 +10:00
|
|
|
|
2022-04-05 11:00:41 +10:00
|
|
|
// Use this to check that settings preferences are working in your code
|
|
|
|
|
// You should see the minimum font size is now 24pt
|
2018-07-10 20:11:02 +10:00
|
|
|
//string errorMessage;
|
|
|
|
|
//var success = requestContext.SetPreference("webkit.webprefs.minimum_font_size", 24, out errorMessage);
|
|
|
|
|
|
2022-04-05 11:00:41 +10:00
|
|
|
// This is the preferred place to set the proxy as it's called before the first request is made,
|
|
|
|
|
// ensuring all requests go through the specified proxy
|
2018-07-10 20:11:02 +10:00
|
|
|
//string errorMessage;
|
2020-10-13 13:40:46 +10:00
|
|
|
//bool success = requestContext.SetProxy("http://localhost:8080", out errorMessage);
|
2018-07-10 20:11:02 +10:00
|
|
|
}
|
2016-09-25 20:35:04 +10:00
|
|
|
}
|
|
|
|
|
}
|