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 javascript wrapper objects #307

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions CefSharp/CefSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Internals\BitmapInfo.cs" />
<Compile Include="Internals\JavaScriptObject.cs" />
<Compile Include="Internals\JavaScriptMember.cs" />
<Compile Include="Internals\ManagedCefApp.cs" />
<Compile Include="CefCustomScheme.cs" />
<Compile Include="CefErrorCode.cs" />
Expand Down
76 changes: 76 additions & 0 deletions CefSharp/Internals/JavaScriptMember.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System;
using System.Runtime.Serialization;

namespace CefSharp.Internals
{
[DataContract]
public class JavaScriptMember
{
public JavaScriptMemberDescription Description { get; set; }

[DataMember]
public long DescriptionId { get; set; }

[DataMember]
public JavaScriptObject Value { get; set; }
}

[DataContract]
public class JavaScriptMemberDescription
{
/// <summary>
/// Identifies the <see cref="JavaScriptMemberDescription" /> for BrowserProcess to RenderProcess communication
/// </summary>
/// <value>
/// The identifier.
/// </value>
[DataMember]
public long Id { get; set; }

/// <summary>
/// Gets or sets the name of the managed property.
/// May be null as <see cref="JavaScriptObject" />s may have values attached that are not present in the managed object
/// </summary>
/// <value>
/// The name of the managed property.
/// </value>
[DataMember]
public string ManagedName { get; set; }

/// <summary>
/// Gets or sets the name of the JavaScriptProperty.
/// </summary>
/// <value>
/// The name of the JavaScriptProperty
/// </value>
[DataMember]
public string JSName { get; set; }

// the following members are used to cache reflection code to improve performance

/// <summary>
/// Gets or sets the set value Action which is used to set the property / field value in the managed Object.
/// </summary>
/// <value>
/// The set value.
/// </value>
public Action<object, object> SetValue { get; set; }

/// <summary>
/// Gets or sets the get value Function which is used to get the property / field value from the managed Object.
/// </summary>
/// <value>
/// The get value.
/// </value>
public Func<object, object> GetValue { get; set; }

/// <summary>
/// Gets or sets the function that is called if the Member is a Function.
/// Will be null if the Member is no function.
/// </summary>
/// <value>
/// The function.
/// </value>
public Delegate Function { get; set; }
}
}
41 changes: 41 additions & 0 deletions CefSharp/Internals/JavaScriptObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Collections.Generic;
using System.Dynamic;
using System.Runtime.Serialization;

namespace CefSharp.Internals
{
[DataContract]
public class JavaScriptObject //: DynamicObject maybe later
{
private static long nextId = 0;
private static readonly object Lock = new object();

/// <summary>
/// Identifies the <see cref="JavaScriptObject" /> for BrowserProcess to RenderProcess communication
/// </summary>
/// <value>
/// The identifier.
/// </value>
[DataMember]
public long Id { get; private set; }

/// <summary>
/// Gets the members of the <see cref="JavaScriptObject" />.
/// </summary>
/// <value>
/// The members.
/// </value>
[DataMember]
public List<JavaScriptMember> Members { get; private set; }

public JavaScriptObject()
{
lock (Lock)
{
Id = ++nextId;
}

Members = new List<JavaScriptMember>();
}
}
}