diff --git a/CefSharp/BindingHandler.cpp b/CefSharp/BindingHandler.cpp index 5f54aed28..18fa8f8b1 100644 --- a/CefSharp/BindingHandler.cpp +++ b/CefSharp/BindingHandler.cpp @@ -314,7 +314,15 @@ namespace CefSharp { // TODO: Handle read-only properties correctly here. auto nameStr = toNative(propertyName); - javascriptObject->SetValue(nameStr, V8_ACCESS_CONTROL_DEFAULT, V8_PROPERTY_ATTRIBUTE_NONE); + + cef_v8_propertyattribute_t propertyAttribute = V8_PROPERTY_ATTRIBUTE_NONE; + + if (properties[propertyName]->GetSetMethod() == nullptr) + { + propertyAttribute = V8_PROPERTY_ATTRIBUTE_READONLY; + } + + javascriptObject->SetValue(nameStr, V8_ACCESS_CONTROL_DEFAULT, propertyAttribute); } } } diff --git a/CefSharp/PropertyAccessor.h b/CefSharp/PropertyAccessor.h index 75335875e..7c20ef96d 100644 --- a/CefSharp/PropertyAccessor.h +++ b/CefSharp/PropertyAccessor.h @@ -66,8 +66,31 @@ namespace CefSharp virtual bool Set(const CefString& name, const CefRefPtr object, const CefRefPtr value, CefString& exception) override { - // TODO: implement. - return false; + auto unmanagedWrapper = static_cast(object->GetUserData().get()); + auto clrName = toClr(name); + PropertyInfo^ property; + + if (unmanagedWrapper->Properties->TryGetValue(clrName, property)) + { + auto wrappedObject = unmanagedWrapper->Get(); + + if (wrappedObject == nullptr) + { + exception = "Binding's CLR object is null."; + return true; + } + + auto clrValue = convertFromCef(value); + property->SetValue(wrappedObject, clrValue, nullptr); + + return true; + } + else + { + // Will probably never get here in reality, since V8 knows the name of the properties that exist on this + // object and will only call us for existant properties. + return false; + } } IMPLEMENT_REFCOUNTING(PropertyAccessor)