From a18a64d70a46f250413b7d13e49abbcbe628929d Mon Sep 17 00:00:00 2001 From: amaitland Date: Thu, 28 Aug 2014 22:43:56 +1000 Subject: [PATCH] Add basic ReadOnly property support --- .../JavascriptPropertyWrapper.cpp | 4 +- .../Internals/JavascriptObjectRepository.cs | 1 + CefSharp/Internals/JavascriptProperty.cs | 51 +++++++++++-------- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/CefSharp.BrowserSubprocess.Core/JavascriptPropertyWrapper.cpp b/CefSharp.BrowserSubprocess.Core/JavascriptPropertyWrapper.cpp index e6272e63b..1aa2e7a04 100644 --- a/CefSharp.BrowserSubprocess.Core/JavascriptPropertyWrapper.cpp +++ b/CefSharp.BrowserSubprocess.Core/JavascriptPropertyWrapper.cpp @@ -26,7 +26,9 @@ namespace CefSharp } else { - V8Value->SetValue(methodName, V8_ACCESS_CONTROL_DEFAULT, V8_PROPERTY_ATTRIBUTE_NONE); + auto propertyAttribute = _javascriptProperty->IsReadOnly ? V8_PROPERTY_ATTRIBUTE_READONLY : V8_PROPERTY_ATTRIBUTE_NONE; + + V8Value->SetValue(methodName, V8_ACCESS_CONTROL_DEFAULT, propertyAttribute); } }; } \ No newline at end of file diff --git a/CefSharp/Internals/JavascriptObjectRepository.cs b/CefSharp/Internals/JavascriptObjectRepository.cs index 37abdd321..4e0338113 100644 --- a/CefSharp/Internals/JavascriptObjectRepository.cs +++ b/CefSharp/Internals/JavascriptObjectRepository.cs @@ -160,6 +160,7 @@ namespace CefSharp.Internals jsProperty.GetValue = (o) => propertyInfo.GetValue(o, null); jsProperty.IsComplexType = !propertyInfo.PropertyType.IsPrimitive && propertyInfo.PropertyType != typeof(string); + jsProperty.IsReadOnly = !propertyInfo.CanWrite; return jsProperty; } diff --git a/CefSharp/Internals/JavascriptProperty.cs b/CefSharp/Internals/JavascriptProperty.cs index eca1567ae..c72fd4f8c 100644 --- a/CefSharp/Internals/JavascriptProperty.cs +++ b/CefSharp/Internals/JavascriptProperty.cs @@ -19,30 +19,39 @@ namespace CefSharp.Internals /// public Func GetValue { get; set; } - /// - /// Identifies the for BrowserProcess to RenderProcess communication - /// - [DataMember] - public long Id { get; set; } + /// + /// Identifies the for BrowserProcess to RenderProcess communication + /// + [DataMember] + public long Id { get; set; } - /// - /// Gets or sets the name of the managed property. - /// - [DataMember] - public string ManagedName { get; set; } + /// + /// Gets or sets the name of the managed property. + /// + [DataMember] + public string ManagedName { get; set; } - /// - /// Gets or sets the name of the property in the JavaScript runtime. - /// - [DataMember] - public string JavascriptName { get; set; } + /// + /// Gets or sets the name of the property in the JavaScript runtime. + /// + [DataMember] + public string JavascriptName { get; set; } - [DataMember] - public bool IsComplexType { get; set; } + /// + /// Gets or sets if this property represents a complex type + /// + [DataMember] + public bool IsComplexType { get; set; } - public override string ToString() - { - return ManagedName ?? base.ToString(); - } + /// + /// Gets or sets if this property is read-only + /// + [DataMember] + public bool IsReadOnly { get; set; } + + public override string ToString() + { + return ManagedName ?? base.ToString(); + } } }