Skip to content

Commit

Permalink
Request event handler (#1918)
Browse files Browse the repository at this point in the history
* Create RequestEventArgs.cs

* Create RequestEventHandler

* Update RequestEventArgs.cs

corrected namespace

* removed regions, splitted up classes per file

* reformatted code

* removed wrong class doc

* deleted empty line

* removed TODOs (moved them in pr comments)

* adapted @amaitland 's pr notes

* made code backwards compatible to c# < 6

* made code backwards compatible to c# < 6 ++ (moved default values for event args to ctor)

* made code backwards compatible to c# < 6 ++ (added private setters to properties)
  • Loading branch information
FlorianObermayer authored and amaitland committed Feb 9, 2017
1 parent 4d697e0 commit ee56382
Show file tree
Hide file tree
Showing 17 changed files with 700 additions and 0 deletions.
16 changes: 16 additions & 0 deletions CefSharp.Example/CefSharp.Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@
<Compile Include="Filters\PassThruResponseFilter.cs" />
<Compile Include="Handlers\BrowserProcessHandler.cs" />
<Compile Include="InMemorySchemeAndResourceHandlerFactory.cs" />
<Compile Include="RequestEventHandler\EventArgs\BaseRequestEventArgs.cs" />
<Compile Include="RequestEventHandler\EventArgs\GetAuthCredentialsEventArgs.cs" />
<Compile Include="RequestEventHandler\EventArgs\GetResourceResponseFilterEventArgs.cs" />
<Compile Include="RequestEventHandler\EventArgs\OnBeforeBrowseEventArgs.cs" />
<Compile Include="RequestEventHandler\EventArgs\OnBeforeResourceLoadEventArgs.cs" />
<Compile Include="RequestEventHandler\EventArgs\OnCertificateErrorEventArgs.cs" />
<Compile Include="RequestEventHandler\EventArgs\OnOpenUrlFromTabEventArgs.cs" />
<Compile Include="RequestEventHandler\EventArgs\OnPluginCrashedEventArgs.cs" />
<Compile Include="RequestEventHandler\EventArgs\OnProtocolExecutionEventArgs.cs" />
<Compile Include="RequestEventHandler\EventArgs\OnQuotaRequestEventArgs.cs" />
<Compile Include="RequestEventHandler\EventArgs\OnRenderProcessTerminatedEventArgs.cs" />
<Compile Include="RequestEventHandler\EventArgs\OnRenderViewReadyEventArgs.cs" />
<Compile Include="RequestEventHandler\EventArgs\OnResourceLoadCompleteEventArgs.cs" />
<Compile Include="RequestEventHandler\EventArgs\OnResourceRedirectEventArgs.cs" />
<Compile Include="RequestEventHandler\EventArgs\OnResourceResponseEventArgs.cs" />
<Compile Include="RequestEventHandler\RequestEventHandler.cs" />
<Compile Include="ScriptedMethodsBoundObject.cs" />
<Compile Include="ExceptionTestBoundObject.cs" />
<Compile Include="JsDialogHandler.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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.

namespace CefSharp.Example.RequestEventHandler
{
public abstract class BaseRequestEventArgs : System.EventArgs
{
protected BaseRequestEventArgs(IWebBrowser browserControl, IBrowser browser)
{
BrowserControl = browserControl;
Browser = browser;
}

public IWebBrowser BrowserControl { get; private set; }
public IBrowser Browser { get; private set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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.

namespace CefSharp.Example.RequestEventHandler
{
public class GetAuthCredentialsEventArgs : BaseRequestEventArgs
{
public GetAuthCredentialsEventArgs(IWebBrowser browserControl, IBrowser browser, IFrame frame, bool isProxy, string host, int port, string realm, string scheme, IAuthCallback callback) : base(browserControl, browser)
{
Frame = frame;
IsProxy = isProxy;
Host = host;
Port = port;
Realm = realm;
Scheme = scheme;
Callback = callback;

ContinueAsync = false; // default
}

public IFrame Frame { get; private set; }
public bool IsProxy { get; private set; }
public string Host { get; private set; }
public int Port { get; private set; }
public string Realm { get; private set; }
public string Scheme { get; private set; }

/// <summary>
/// Callback interface used for asynchronous continuation of authentication requests.
/// </summary>
public IAuthCallback Callback { get; private set; }

/// <summary>
/// Set to true to continue the request and call
/// <see cref="T:CefSharp.GetAuthCredentialsEventArgs.Continue(System.String, System.String)" /> when the authentication information
/// is available. Set to false to cancel the request.
/// </summary>
public bool ContinueAsync { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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.

namespace CefSharp.Example.RequestEventHandler
{
public class GetResourceResponseFilterEventArgs : BaseRequestEventArgs
{
public GetResourceResponseFilterEventArgs(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response) : base(browserControl, browser)
{
Frame = frame;
Request = request;
Response = response;

ResponseFilter = null; // default
}

public IFrame Frame { get; private set; }
public IRequest Request { get; private set; }
public IResponse Response { get; private set; }

/// <summary>
/// Set a ResponseFilter to intercept this response, leave it null otherwise.
/// </summary>
public IResponseFilter ResponseFilter { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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.

namespace CefSharp.Example.RequestEventHandler
{
public class OnBeforeBrowseEventArgs : BaseRequestEventArgs
{
public OnBeforeBrowseEventArgs(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, bool isRedirect)
: base(browserControl, browser)
{
Frame = frame;
Request = request;
IsRedirect = isRedirect;

CancelNavigation = false; // default
}

public IFrame Frame { get; private set; }
public IRequest Request { get; private set; }
public bool IsRedirect { get; private set; }

/// <summary>
/// Set to true to cancel the navigation or false to allow the navigation to proceed.
/// </summary>
public bool CancelNavigation { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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.

namespace CefSharp.Example.RequestEventHandler
{
public class OnBeforeResourceLoadEventArgs : BaseRequestEventArgs
{
public OnBeforeResourceLoadEventArgs(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IRequestCallback callback)
: base(browserControl, browser)
{
Frame = frame;
Request = request;
Callback = callback;

ContinuationHandling = CefReturnValue.Continue; // default
}

public IFrame Frame { get; private set; }
public IRequest Request { get; private set; }

/// <summary>
/// Callback interface used for asynchronous continuation of url requests.
/// </summary>
public IRequestCallback Callback { get; private set; }

/// <summary>
/// To cancel loading of the resource return <see cref="F:CefSharp.CefReturnValue.Cancel" />
/// or <see cref="F:CefSharp.CefReturnValue.Continue" /> to allow the resource to load normally. For async
/// return <see cref="F:CefSharp.CefReturnValue.ContinueAsync" /> and use
/// <see cref="OnBeforeResourceLoadEventArgs.Callback" /> to handle continuation.
/// </summary>
public CefReturnValue ContinuationHandling { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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.

namespace CefSharp.Example.RequestEventHandler
{
public class OnCertificateErrorEventArgs : BaseRequestEventArgs
{
public OnCertificateErrorEventArgs(IWebBrowser browserControl, IBrowser browser, CefErrorCode errorCode, string requestUrl, ISslInfo sslInfo, IRequestCallback callback)
: base(browserControl, browser)
{
ErrorCode = errorCode;
RequestUrl = requestUrl;
SSLInfo = sslInfo;
Callback = callback;

ContinueAsync = false; // default
}

public CefErrorCode ErrorCode { get; private set; }
public string RequestUrl { get; private set; }
public ISslInfo SSLInfo { get; private set; }

/// <summary>
/// Callback interface used for asynchronous continuation of url requests.
/// If empty the error cannot be recovered from and the request will be canceled automatically.
/// </summary>
public IRequestCallback Callback { get; private set; }

/// <summary>
/// Set to false to cancel the request immediately. Set to true and use <see cref="T:CefSharp.IRequestCallback" /> to
/// execute in an async fashion.
/// </summary>
public bool ContinueAsync { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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.

namespace CefSharp.Example.RequestEventHandler
{
public class OnOpenUrlFromTabEventArgs : BaseRequestEventArgs
{
public OnOpenUrlFromTabEventArgs(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, WindowOpenDisposition targetDisposition, bool userGesture)
: base(browserControl, browser)
{
Frame = frame;
TargetUrl = targetUrl;
TargetDisposition = targetDisposition;
UserGesture = userGesture;

CancelNavigation = false; // default
}

public IFrame Frame { get; private set; }
public string TargetUrl { get; private set; }
public WindowOpenDisposition TargetDisposition { get; private set; }
public bool UserGesture { get; private set; }

/// <summary>
/// Set to true to cancel the navigation or false to allow the navigation to proceed.
/// </summary>
public bool CancelNavigation { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// 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.

namespace CefSharp.Example.RequestEventHandler
{
public class OnPluginCrashedEventArgs : BaseRequestEventArgs
{
public OnPluginCrashedEventArgs(IWebBrowser browserControl, IBrowser browser, string pluginPath) : base(browserControl, browser)
{
PluginPath = pluginPath;
}

public string PluginPath { get; private set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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.

namespace CefSharp.Example.RequestEventHandler
{
public class OnProtocolExecutionEventArgs : BaseRequestEventArgs
{
public OnProtocolExecutionEventArgs(IWebBrowser browserControl, IBrowser browser, string url) : base(browserControl, browser)
{
Url = url;

AttemptExecution = false; // default
}

public string Url { get; private set; }

/// <summary>
/// Set to true to attempt execution via the registered OS protocol handler, if any. Otherwise set to false.
/// </summary>
public bool AttemptExecution { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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.

namespace CefSharp.Example.RequestEventHandler
{
public class OnQuotaRequestEventArgs : BaseRequestEventArgs
{
public OnQuotaRequestEventArgs(IWebBrowser browserControl, IBrowser browser, string originUrl, long newSize, IRequestCallback callback)
: base(browserControl, browser)
{
OriginUrl = originUrl;
NewSize = newSize;
Callback = callback;

ContinueAsync = false; // default
}

public string OriginUrl { get; private set; }
public long NewSize { get; private set; }

/// <summary>
/// Callback interface used for asynchronous continuation of url requests.
/// </summary>
public IRequestCallback Callback { get; private set; }

/// <summary>
/// Set to false to cancel the request immediately. Set to true to continue the request
/// and call <see cref="T:OnQuotaRequestEventArgs.Callback.Continue(System.Boolean)" /> either in this method or at a later
/// time to grant or deny the request.
/// </summary>
public bool ContinueAsync { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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.

namespace CefSharp.Example.RequestEventHandler
{
public class OnRenderProcessTerminatedEventArgs : BaseRequestEventArgs
{
public OnRenderProcessTerminatedEventArgs(IWebBrowser browserControl, IBrowser browser, CefTerminationStatus status)
: base(browserControl, browser)
{
Status = status;
}

public CefTerminationStatus Status { get; private set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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.

namespace CefSharp.Example.RequestEventHandler
{
public class OnRenderViewReadyEventArgs : BaseRequestEventArgs
{
public OnRenderViewReadyEventArgs(IWebBrowser browserControl, IBrowser browser) : base(browserControl, browser)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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.

namespace CefSharp.Example.RequestEventHandler
{
public class OnResourceLoadCompleteEventArgs : BaseRequestEventArgs
{
public OnResourceLoadCompleteEventArgs(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response, UrlRequestStatus status, long receivedContentLength)
: base(browserControl, browser)
{
Frame = frame;
Request = request;
Response = response;
Status = status;
ReceivedContentLength = receivedContentLength;
}

public IFrame Frame { get; private set; }
public IRequest Request { get; private set; }
public IResponse Response { get; private set; }
public UrlRequestStatus Status { get; private set; }
public long ReceivedContentLength { get; private set; }
}
}
Loading

0 comments on commit ee56382

Please sign in to comment.