Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added default implementation of IRequestHandler #2157

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CefSharp/CefSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
<Compile Include="Callback\TaskPrintToPdfCallback.cs" />
<Compile Include="Callback\TaskResolveCallback.cs" />
<Compile Include="CdmRegistration.cs" />
<Compile Include="DefaultRequestHandler.cs" />
<Compile Include="Enums\UrlRequestFlags.cs" />
<Compile Include="Internals\ByteArrayResourceHandler.cs" />
<Compile Include="Internals\FileResourceHandler.cs" />
Expand Down
96 changes: 96 additions & 0 deletions CefSharp/DefaultRequestHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Copyright © 2010-2017 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.Security.Cryptography.X509Certificates;

namespace CefSharp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At a minimum this should be in the Handler folder. Probably the CefSharp.Handler namespace as well. (Ideally all the handlers should be in their own namespace, moving the interfaces is a massive breaking change, so probably won't happen).

{
/// <summary>
/// Default implementation of <see cref="IRequestHandler"/>.
/// This class provides default implementations of the methods from <see cref="IRequestHandler"/>,
/// therefore providing a convenience base class for any custom request handler.
/// </summary>
public class DefaultRequestHandler : IRequestHandler
{
public virtual bool GetAuthCredentials(IWebBrowser browserControl, IBrowser browser, IFrame frame, bool isProxy, string host,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally the xmldoc would be copied from the parent IRequestHandler. GhostDoc is handy when it comes to this sort of thing.

int port, string realm, string scheme, IAuthCallback callback)
{
callback.Dispose();
return false;
}

public virtual IResponseFilter GetResourceResponseFilter(IWebBrowser browserControl, IBrowser browser, IFrame frame,
IRequest request, IResponse response)
{
return null;
}

public virtual bool OnBeforeBrowse(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, bool isRedirect)
{
return false;
}

public virtual CefReturnValue OnBeforeResourceLoad(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request,
IRequestCallback callback)
{
callback.Dispose();
return CefReturnValue.Continue;
}

public virtual bool OnCertificateError(IWebBrowser browserControl, IBrowser browser, CefErrorCode errorCode, string requestUrl,
ISslInfo sslInfo, IRequestCallback callback)
{
callback.Dispose();
return false;
}

public virtual bool OnOpenUrlFromTab(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl,
WindowOpenDisposition targetDisposition, bool userGesture)
{
return false;
}

public virtual void OnPluginCrashed(IWebBrowser browserControl, IBrowser browser, string pluginPath)
{ }

public virtual bool OnProtocolExecution(IWebBrowser browserControl, IBrowser browser, string url)
{
return false;
}

public virtual bool OnQuotaRequest(IWebBrowser browserControl, IBrowser browser, string originUrl, long newSize,
IRequestCallback callback)
{
callback.Dispose();
return false;
}

public virtual void OnRenderProcessTerminated(IWebBrowser browserControl, IBrowser browser, CefTerminationStatus status)
{ }

public virtual void OnRenderViewReady(IWebBrowser browserControl, IBrowser browser)
{ }

public virtual void OnResourceLoadComplete(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request,
IResponse response, UrlRequestStatus status, long receivedContentLength)
{ }

public virtual void OnResourceRedirect(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request,
IResponse response, ref string newUrl)
{ }

public virtual bool OnResourceResponse(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request,
IResponse response)
{
return false;
}

public virtual bool OnSelectClientCertificate(IWebBrowser browserControl, IBrowser browser, bool isProxy, string host, int port,
X509Certificate2Collection certificates, ISelectClientCertificateCallback callback)
{
callback.Dispose();
return false;
}
}
}