- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 3k
 
Feature - Configure property name that Cefsharp injects to window #3126
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
Conversation
… used for the property binding name.
… characters are used.
| 
           ❌ Build CefSharp 81.3.20-CI3513 failed (commit 775b8a2122 by @Geevo)  | 
    
| 
           ✅ Build CefSharp 81.3.20-CI3514 completed (commit fe27aa50bf by @Geevo)  | 
    
          
 I think this is an argument against adding properties to  I'm not sure exactly where they should go, possible a settings object should be added to the  Further comments inline.  | 
    
        
          
                CefSharp/CefSharpSettings.cs
              
                Outdated
          
        
      | /// | ||
| /// NOTE: There are two properties to be mindful of, this and <see cref="JavascriptBindingPropertyNameCamelCase"/> | ||
| /// </summary> | ||
| public static string JavascriptBindingPropertyName { get; set; } | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- We we need two properties for this? Camel case can be derived from the full name
 - What happens if both properties are exactly the same?
 
If they both end up being the same name we should only generate one set of objects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about exposing a single property and then manipulate the string to pascal/camel case on the first char of the property before injecting that way you can keep both objects and cater for either preference?
For example:
https://stackoverflow.com/a/36579722
Or simply leave it down to preference completely, and only have a single object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Single property sounds fine, if the first character is already lower we should only create one set of objects.
https://github.com/cefsharp/CefSharp/blob/master/CefSharp/Internals/JavascriptObjectRepository.cs#L543 should be refactored if we add an additional method for camel case conversion.
| 
           ✅ Build CefSharp 81.3.20-CI3521 completed (commit 73d0560774 by @Geevo)  | 
    
Add new property to JavascriptObjectRepository. Added IsFirstCharacterLowercase to StringCheck class Changed ManagedCefBrowserAdapter to retrieve property from JavascriptObjectRepository. Added if statement if property is already camelCase.
| 
           ✅ Build CefSharp 81.3.20-CI3523 completed (commit 5bceb04b57 by @Geevo)  | 
    
| 
           I think it maybe worth having a method to set the  Maybe also perhaps then have get only property with the last known set name.  | 
    
| 
           ✅ Build CefSharp 81.3.20-CI3524 completed (commit 5d11af8740 by @Geevo)  | 
    
Exposed JavascriptObjectRepositorySettings to IJavascriptObjectRepository.
| 
           ✅ Build CefSharp 81.3.20-CI3528 completed (commit efd719cfb5 by @Geevo)  | 
    
- Rename settings object to JavascriptBindingSettings - Validate JavascriptBindingSettings.JsBindingPropertyName in setter to provide immediate feedback - Add FreezableBase which throws exception when frozen (we can reuse this for some other settings classes) TODO: - Xml doc fill in the blanks - Add unit tests Follow on from cefsharp#3126
- Rename settings object to JavascriptBindingSettings - Validate JavascriptBindingSettings.JsBindingPropertyName in setter to provide immediate feedback - Add FreezableBase which throws exception when frozen (we can reuse this for some other settings classes) TODO: - Xml doc fill in the blanks - Add unit tests Follow on from cefsharp#3126
| 
           I've implemented #2977 which is the reason you'll see conflicting changes in this. 
 See a70abc4 for relevant commit. I've squashed your changes and they're included in the https://github.com/amaitland/CefSharp/commits/feature/jsbpropertyname branch with some additional changes 
 Still need to fill in all the  I'll finish the rest when I find some time.  | 
    
          
 Perhaps  As per your description above and definition of the  
 Nice touch of the Freezable base implementation 👍  | 
    
          
 Much better, thanks 👍 
 Borrowing the idea from   | 
    
- Rename settings object to JavascriptBindingSettings - Validate JavascriptBindingSettings.JsBindingGlobalObjectName in setter to provide immediate feedback - Add FreezableBase which throws exception when frozen (we can reuse this for some other settings classes) TODO: - Add unit tests Follow on from cefsharp#3126
- Rename settings object to JavascriptBindingSettings - Validate JavascriptBindingSettings.JsBindingGlobalObjectName in setter to provide immediate feedback - Add FreezableBase which throws exception when frozen (we can reuse this for some other settings classes) - Add some basic Unit Tests (More would be better) Follow on from cefsharp#3126
- Rename settings object to JavascriptBindingSettings - Validate JavascriptBindingSettings.JsBindingGlobalObjectName in setter to provide immediate feedback - Add FreezableBase which throws exception when frozen (we can reuse this for some other settings classes) - Add some basic Unit Tests (More would be better) Follow on from cefsharp#3126
- Rename settings object to JavascriptBindingSettings - Validate JavascriptBindingSettings.JsBindingGlobalObjectName in setter to provide immediate feedback - Add FreezableBase which throws exception when frozen (we can reuse this for some other settings classes) - Add some basic Unit Tests (More would be better) Follow on from #3126
| 
           Manually merged in 6669110 with additional changes in ae41e10 I ended up with the property named as  var settings = browser.JavascriptObjectRepository.Settings;
settings.JavascriptBindingApiGlobalObjectName = "customApi";I've only got a single very basic test so far ae41e10#diff-59940d85e6a445f319b6a2b0a08bdf9cR77 If anyone has problems then please provide a test case.  | 
    
Fixes: [#2831]
Summary:
I have added a new feature to the Javascript Binding implementation that gives the ability to configure custom property names for both normal and camelCase binding objects.
I've never written in C++ before so lots of reading in and around the wrapper to grasp an idea of how i would implement this so apologies in advanced if i have missed something with regards to anything unmanaged related, and of course i'm happy to try and change or refactor anything you're not happy with.
I've tried to make sure this doesn't cause anything breaking changes and default values are used if the properties are never configured.
Changes:
CefSharpSettingsand assigned them default valuesManagedCefBrowserAdapterto retrieve the properties fromCefSharpSettingsStringCheckclass/file (cs Internals) to validate the strings do not contain illegal charactersCefAppUnmanagedWrapperto receive the new properties via theextraInfoparameter onOnBrowserCreatedHow Has This Been Tested?
Obviously this is a tad bit trickier to test. I had to make changes to all the html code to reflect the new values i was testing with (changes not included in this PR).
Using WinForms Example for testing, i set custom values to the new properties
CefSharpSettings.JavascriptBindingPropertyNameandCefSharpSettings.JavascriptBindingPropertyNameCamelCaseand run theBinding Testaccordingly and didn't receive any errors.I tested with illegal characters to ensure an exception was thrown with an explanation as to why the exception was thrown.
I tested with VS 2019 Professional on Windows 10 (1809)
Types of changes
Checklist: