Skip to content

Commit

Permalink
Follow up to cefsharp#2015
Browse files Browse the repository at this point in the history
Add license disclaimer
Move example MethodInterceptorLogger into CefSharp.Example project
Reword the IMethodInterceptor xml doc a little bit, probably still needs some work
  • Loading branch information
amaitland committed Jun 1, 2017
1 parent 402b2b9 commit f5e2a93
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 29 deletions.
1 change: 1 addition & 0 deletions CefSharp.Example/CefSharp.Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
<Compile Include="Filters\PassThruResponseFilter.cs" />
<Compile Include="Handlers\BrowserProcessHandler.cs" />
<Compile Include="InMemorySchemeAndResourceHandlerFactory.cs" />
<Compile Include="ModelBinding\MethodInterceptorLogger.cs" />
<Compile Include="RequestEventHandler\EventArgs\BaseRequestEventArgs.cs" />
<Compile Include="RequestEventHandler\EventArgs\GetAuthCredentialsEventArgs.cs" />
<Compile Include="RequestEventHandler\EventArgs\GetResourceResponseFilterEventArgs.cs" />
Expand Down
20 changes: 20 additions & 0 deletions CefSharp.Example/ModelBinding/MethodInterceptorLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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;
using System.Diagnostics;
using CefSharp.ModelBinding;

namespace CefSharp.Example.ModelBinding
{
public class MethodInterceptorLogger : IMethodInterceptor
{
object IMethodInterceptor.Intercept(Func<object> method, string methodName)
{
object result = method();
Debug.WriteLine("Called " + methodName);
return result;
}
}
}
1 change: 0 additions & 1 deletion CefSharp.Wpf.Example/CefSharp.Wpf.Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@
<Compile Include="SpawnBrowsersWindow.xaml.cs">
<DependentUpon>SpawnBrowsersWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Views\BrowserTabView.MethodInterceptionLogger.cs" />
<Compile Include="Views\BrowserTabView.xaml.cs">
<DependentUpon>BrowserTabView.xaml</DependentUpon>
</Compile>
Expand Down

This file was deleted.

5 changes: 2 additions & 3 deletions CefSharp.Wpf.Example/Views/BrowserTabView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@
using CefSharp.ModelBinding;
using CefSharp.Wpf.Example.ViewModels;
using System.IO;
using System;
using CefSharp.Example.ModelBinding;

namespace CefSharp.Wpf.Example.Views
{
public partial class BrowserTabView : UserControl
{

//Store draggable region if we have one - used for hit testing
private Region region;

Expand All @@ -32,7 +31,7 @@ public BrowserTabView()
var bindingOptions = new BindingOptions()
{
Binder = BindingOptions.DefaultBinder.Binder,
MethodInterceptor = new MethodInterceptionLogger() // intercept .net methods calls from js and log it
MethodInterceptor = new MethodInterceptorLogger() // intercept .net methods calls from js and log it
};
browser.RegisterAsyncJsObject("boundAsync", new AsyncBoundObject(), bindingOptions);
// Enable touch scrolling - once properly tested this will likely become the default
Expand Down
19 changes: 14 additions & 5 deletions CefSharp/ModelBinding/IMethodInterceptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,25 @@
namespace CefSharp.ModelBinding
{
/// <summary>
/// Provides the capability to supply an interceptor of
/// .net method calls from js. Can be used to log method calls.
/// Provides the capability intercept Net method calls made from javascript as part of the
/// JavascriptBinding (JSB) implementation. One example use case is logging method calls.
public interface IMethodInterceptor
{
/// <summary>
/// Intercept the given method name
/// Called before the method is invokved. You are now responsible for evaluating
/// the function and returning the result.
/// </summary>
/// <param name="originalMethod">method to be called</param>
/// <param name="method">A Func that represents the method to be called</param>
/// <param name="methodName">Name of the method to be called</param>
/// <returns>The method result</returns>
object Intercept(Func<object> originalMethod, string methodName);
/// <example>
/// object IMethodInterceptor.Intercept(Func<object> method, string methodName)
/// {
/// object result = method();
/// Debug.WriteLine("Called " + methodName);
/// return result;
/// }
/// </example>
object Intercept(Func<object> method, string methodName);
}
}

0 comments on commit f5e2a93

Please sign in to comment.