96 Commits

Author SHA1 Message Date
Alex Maitland 3a749c0bf2 Javascript Binding - Add Url to JavascriptBindingEventArgs (#5021)
Co-authored-by: amaitland <307872+amaitland@users.noreply.github.com>
2025-02-01 06:47:42 +10:00
Alex Maitland a4db645e5b Core - Xml Doc fixes 2023-03-12 11:09:48 +10:00
Alex Maitland 2ead423380 Core - Improve JavascriptObjectRepository.TryCallMethod Object Not Found error message
- Add method name and param count

Resolves #4209
2022-08-21 13:44:34 +10:00
Santosh M Ghanti 9e0236876c Sync Javascript Binding - Add support for property interception (#3935)
* Core - added support for property interceptor

* Incorporated the review comments

* Incorporated the review comments 2

* Review comments exclude trygetproperty and trysetproperty for .netcore app

* Added the unit test cases for trygetproperty and trysetproperty

* Fixed .net core app build failure

* Added the separate test case for property interceptor

Co-authored-by: sghanti <santosh_ghanti@intuit.com>
2022-02-14 13:58:35 +10:00
Alex Maitland b994264160 Core - JavascriptObjectRepository improve xml doc 2021-04-06 13:13:03 +10:00
pedoc 893d03221f Javascript Binding - Allow binding to classes in the global namespace (#3467)
* fix IsComplexType NullReferenceException

Sometimes, the registered Javascript object does not have a namespace, at this time this function will throw a ```NullReferenceException```.

* add unit test for IsComplexType

* Simplify and remove useless code

* Update CefSharp/Internals/JavascriptObjectRepository.cs

Co-authored-by: campersau <buchholz.bastian@googlemail.com>

Co-authored-by: Alex Maitland <amaitland@users.noreply.github.com>
Co-authored-by: campersau <buchholz.bastian@googlemail.com>
2021-04-05 10:29:42 +10:00
Alex Maitland ab8223d4b9 Core - Add IAsyncMethodInterceptor (#3296)
Core - Add IAsyncMethodInterceptor
  - Add IAsyncMethodInterceptor
    Extension of IMethodInterceptor to allow for easier evaluation of async taskScheduler
  - Add Additional unit tests
  - Add JavascriptBindingSettings.AlwaysInterceptAsynchronously for cases where you'd like all method calls to use 
    IAsyncMethodInterceptor.InterceptAsync

Follow up to PR #3291

Co-authored-by: Andrew Sampson <andrew@rainway.com>
Co-authored-by: Emily Hudson <emily33901@gmail.com>
2021-01-09 13:17:50 +10:00
amaitland 55af252d91 Core - Refactor JavascriptObjectRepository to IJavascriptObjectRepositoryInternal
Basic refactoring in preparation for allowing users(advanced) to provide their own custom JavascriptObjectRepository implementation
2020-11-25 15:23:29 +10:00
Alex Maitland b5a83f526e Enhancement - Pluggable Javascript Naming (#3141)
* Core - Move NameConverter to IJavascriptObjectRepository

- Move NameConverter property from BindingOptions to IJavascriptObjectRepository
- Remove BindingOptions.CamelCaseJavascriptNames

**Breaking Change**

Follow up to https://github.com/cefsharp/CefSharp/commit/898ca38e7a7261b3a42c33b2abf5eac6c022ddde

* Core - Javascript Binding Pluggable Naming Improvements

- Added some basic unit tests (more required)
- DefaultBinder now accepts a IJavascriptNameConverter passed into the constructor
  to allow for conversion of names

* Core - Replace WeakReference with WeakReference<T>
2020-07-27 20:13:16 +10:00
amaitland e8cf336bf3 Net Core - Support for compiling with .Net Core 3.1
- Make Wpf/WinForms/OffScreen projects target AnyCPU
Only the VC++ projects are platform specific now.
- Remove BrowserSubProcess project reference
Not needed as we now have a standalone exe
- Add OffScreen example
- Add WPF Example project
- Fix some compile errors for main solution
- Add BrowserSubProcess executable
- JavascriptObjectRepository remove isAsync param
Rather than throw exception remove the option
- BrowserSubprocess Exclude the WCF specific code from the netCore project
- Add some ifdef/ifndef to exclude the WCF specific implementation
- Move WCF implementation into separate namespace
2020-07-23 15:23:45 +10:00
Konstantin Preißer 5e89f71a44 Add new projects targeting .NET Core 3.1 (#3181)
* Add .NET Core 3.1 projects for CefSharp, CefSharp.Core, CefSharp.BrowserSubprocess.Core, CefSharp.WinForms, CefSharp.Wpf, CefSharp.OffScreen.

Contributes to CefSharp#2796

* - Remove dependencies to "opengl32.lib" and "glu32.lib" which aren't available for ARM64 and don't seem to be needed.
- Clean up project files.

* Switch project CefSharp.netcore.csproj to AnyCPU as it doesn't require different builds for each platform.

* Remove WindowsTargetPlatformVersion property as that is declared in CefSharp.props.

* Use "bin.netcore" and "obj.netcore" as [intermediate] output path for the .NET Core projects, to allow side-by-side builds with the .NET Framework projects.

* Output documentation files.

* Add CefSharp.Example.netcore and CefSharp.WinForms.Example.netcore.

* Follow-up: Remove properties from the example projects that are also not used in the corresponding .NET Framework projects.
2020-07-23 15:21:14 +10:00
amaitland 898ca38e7a Core - Add BindingOptions.NameConverter
- Allows for the user to provide their own IJavascriptNameConverter implementation
- Defaults to using the CamelCaseJavascriptNameConverter (which is exactly the same very basic
naming conversion used by default currently).
- If CamelCaseJavascriptNames is false then no conversion is used

Naming is now separate from the JavascriptObjectRepository and can be tested in isolation.
2020-05-30 20:02:56 +10:00
amaitland a70abc4437 Core - LegacyBinding is now configured per browser
Previously it was global set using CefSharpSettings.LegacyJavascriptBindingEnabled

Now it's configured through IJavascriptObjectRepository.Settings.LegacyBindingEnabled
which defaults to CefSharpSettings.LegacyJavascriptBindingEnabled (until it's removed).

IJavascriptObjectRepository.ResolveObject is raised with LegacyObjects as the name
to allow for easier binding of objects.

Issue #2977
2020-05-23 14:15:33 +10:00
João Neves e81a3ed316 Fixed crash accessing js objects dictionary concurrently 2019-11-03 12:50:02 +10:00
amaitland 3199872247 JSB - Pass params to IMethodInterceptor.Intercept
Breaking change

Resolves #2909
2019-09-27 08:17:43 +10:00
amaitland 8717167b76 JavascriptObjectRepository - Pass all params into IBinder.Bind not just dictionary/list
Previously only IDictionary<string, object>, IList<object> were passed, now all params are passed to allow for type conversion (Issue #2906)

Binding now occurs before missing params are added (they weren't passed to the binder previously, so this doesn't change the behaviour

This is a breaking change.

Resolves #2908
2019-09-27 08:00:06 +10:00
amaitland 1c73a64099 JavascriptObjectRepository - Only return Root objects (toplevel/parent objects)
GetObjects was returning all objects, even those that are sub objects
2019-06-25 19:24:57 +10:00
Chris 30ee538ce0 Added EditorConfig (#2514) 2018-09-17 00:46:21 +02:00
Chris bef5dd37c4 Maintenance - Fixed formatting, file encoding, and copyright year (#2504)
* Applied formatting

* Fixed file encoding + Updated copyright year

* Updated License

* Fixed more file encoding

* Copyright notice now shows the year the file was created
2018-09-10 10:41:13 +10:00
amaitland 4c3b0652b0 JavascriptObjectRepository - Throw exception if trying to Register .Net built in type
Also Simplify some code as per VS suggestion

Resolves #2466
2018-07-23 09:52:30 +10:00
amaitland 5b15ed01bd Add IJavascriptObjectRepository.UnRegisterAll
UnRegisterAll all bound objects - does not unbind them from the JS context
2018-07-13 10:13:08 +10:00
amaitland 37a364c0ad Add IJavascriptObjectRepository.UnRegister
Allows for an object to be removed from the repository, doesn't unbind the object from javascript though
2018-07-12 20:31:31 +10:00
amaitland 0a849a8976 JSB - Add EnsureObjectBoundAsync method
To support this use case added IJavascriptObjectRepository.ObjectsBoundInJavascript (called a single time with names of all objects bound)

Implements the idea put forward in #2362
2018-05-09 13:16:07 +10:00
amaitland 8f7692ae6e JSB - Add JavascriptBindingCompleteEventArgs and config options to CefSharp.BindObjectAsync
CefSharp.BindObjectAsync can now take an optional config object as first param
Include additional information when binding complete
Add option for cefSharp.bindObjectAsync (starting with lowercase latters)
Add new syntax options - not entirely complete, no variant for the options object
Add ignore cache option
2018-04-27 16:40:39 +10:00
amaitland d99d6d87fe Set event handlers to null in Dispose
Not all event handlers were set to null on Dispose in ChromiumWebBrowser instances and JavascriptObjectRepository

Resolves #2307
2018-04-13 16:18:57 +10:00
amaitland 3175968339 Fix Async JSB unable to return class
Added note about memory leak
Added Test case to validate fix
2018-03-05 14:02:59 +10:00
amaitland 1b00c277b8 JSB Add Caching
Bound object meta data is cached within a render process
CefSharp.IsObjectCached - JS method to test if object cached
CefSharp.RemoveObjectFromCache - JS method to remove object from cache

If a request is made for multiple objects with not all of them being cached then a IPC message is sent.
When all objects already bound return response object for consistency
FindBrowserWrapper signature change - it's really not safe to throw a managed exception in the middle of unmanaged code, changed to logging and null checking
JavascriptObjectRepository - Add All Constant - Used when All objects are requested for binding (objects can also be requested by name)

TODO: Add a JS library to improve user experience when dealing with cached objects
2018-01-30 10:16:28 +10:00
amaitland 2b49105b6f JSB - Fix bug where properties weren't being analysed for sync bound objects
Added test case
Reordered method to make it more logical, used named properties so it's clear what's being set.
Add TODO for unresolved object event
2018-01-29 10:15:01 +10:00
amaitland 7c699e3ec6 IJavascriptObjectRepositry - Add ObjectBoundInJavascript event
Executed on the thread pool when objects are bound in JS
2018-01-22 12:19:43 +10:00
amaitland 679cdb5b11 JSB ResolveObject WcfEnabled = false throw exception if attempt to register sync object
Update the examples to use newer Register method as Legacy options is disabled by default
2018-01-22 11:02:23 +10:00
Alex Maitland 9b01b69d2f Implement Javascript Binding v2 (#2247)
* JSB Rewrite - Add CefSharp.RegisterBoundObject javascript method

To get around the problem of IPC timing, I've reversed the communication, now it's the render process requesting
the bound objects, the implementation is incomplete at this stage, more just a basic proof of concept

Rewrite BindingTest.html using QUnit
One of the tests doesn't map correctly as it requires def user interaction

TODO:

- Get objects by name
- Rename Messages.h values that relate to this change so they are more descriptive
- Better error handling
- Caching of objects within a render process
- Investigate global context options, don't think it's possible to call an async method directly in the global context

# Conflicts:
#	CefSharp.Example/Resources/BindingTest.html

* JSB Improve Request/Response message names

* BindingTest.html - Output stress test results

* Remove JavascriptRootObject was leftover from time we used WCF to transmit objects

* JavascriptObjectRepository - Objects are now sent in the same list with an IsAsync flag

Separation when sending over IPC with two unique lists isn't necessary

* JavascriptObjectRepository - Return objects by name or return all by default

Untabify CefAppUnmanagedWrapper.cpp
Add minor comment to CefBrowserWrapper for a reminder that we use Frame Identifier as dictionary key

* Add //TODO: JSB comments for work that's left to be done

Ideally within a render process we cache bound objects once they've been communicated,
It would also be nice to make multiple binding requests so objects can later be added dynamically

* JSB Allow multiple calls to CefSharp.RegisterBoundObject

Update BindingTest.html to name two distinct calls to different bound objects

* JSB - Add some notes about caching, no working implementation yet

* JSB - Dynamically Register object on Request

* JSB Add ability to unbind an object and rename RegisterBoundObject to BindObjectAsync

# Conflicts:
#	CefSharp.Example/Resources/BindingTest.html

* JSB BindObjectAsync - if objects already bound then return false

* JSB - Ignore Indexer properties

Were previously throwing an exception

* JSB - Add LegacyJavascriptBindingEnabled option so preserve existing behaviour

This is only useful for SPA application and those that only navigate to pages
hosting within a single domain. Any sort of cross-site navigation and a new
render process will be spawned and objects won't be bound automatically
(You can use the new methods to request they're bound yourself, at least in theory,
more testing required on this)

* Add LegacyBindingTest.html

Current disabled by default. To enable uncomment CefSharpSettings.LegacyJavascriptBindingEnabled = true;
in CefExample.cs

* RegisterJsObject and RegisterAsyncJsObject can now only be used when CefSharpSettings.LegacyJavascriptBindingEnabled = true

See https://github.com/cefsharp/CefSharp/issues/2246 for details
2018-01-22 10:24:25 +10:00
João Neves b1b8f43859 Dont discard null Values from arrays (#2218)
* Don't discard arrays that contain null values
* Revert unintended change in this branch
* Added qunit test
* Code review and added new tests
2018-01-18 11:46:58 +10:00
amaitland 7a0b06ad0b JSB Add support for dynamic keyword (using ExpandoObject)
As ExpandoObject implements IDictionary we can use it interchangeable with only minor breaking changes.
Those expecting Dictionary<string, object> should change to IDictionary<string, object> or ExpandoObject for their param types
This will also impact anyone who has implemented their own custom IBinder
I'd suggest changing the type checking from explicitly checking Dictionary<string, object> to use Type.IsAssignableFrom or another method of comparison
DefaultBinder binder has been updated to accommodate ExpandoObject (now being returned by ObjectsSerialization.cpp)
Add new async binding for testing new assignment method
Rewrite some of the async bound object tests to use await and let - modernize them
2017-12-21 13:00:36 +10:00
ieremyashev f029a22f45 Fix return value serialization for async JS bindings (#2167) 2017-10-24 09:48:58 +11:00
João Neves 402b2b9980 Add BindingOptions.MethodInterceptor (#2015)
* Added managed methods interception mechanism
* Introduced requested changes (improved comments and namming)
2017-06-01 10:58:43 +10:00
João Neves bc83d6c247 Allow calling managed methods from objects bound with RegisterAsyncJsObject that return arrays of structs (#1981)
* Fixed problem when calling CefV8Value::CreateArray. Needs prior call to V8 context enter
* Call callback dispose in case of failure
* Support serialization of struct arrays to JS side
* Fixed formatting
2017-03-13 21:37:55 +10:00
Chris cd934267c6 Updated copyright year and made sure it used same format everywhere (#1966) 2017-03-06 08:44:37 +10:00
Alex Maitland d4feffb554 Feature - Add IBinder (#1749)
* Add basic ModelBinding which was imported from NancyFx framework - more can be stripped out that's unused

* Add IBinder as a param when registering an object for binding
Binding is disabled by default

* Add license and remove unused using statements

* Make bind method virtual to allow for overriding
Make methods protected

* Add very basic collection support - only primitive types supported for now.
Remove unused exceptions

* Support binding a list of sub objects

* Add null check for null params

* Add BindingOptions class - remove binder and CamelCaseJavascriptNames properties - allow for additional options in the future
Breaking change.

* Add support for List<object> binding type
2016-07-20 13:38:24 +10:00
amaitland c9944c981a Split paramArray and missing arg logic out into two if statements. Previously null was being replaced by Type.Missing.
Two seperate if statement branches allows for a method that has options params and a param array

Resolve #1673
2016-04-29 18:10:43 +10:00
Akash Jana d0e74f819f Fix Issue #1582, Use ToLowerInvariant while converting Function names to avoid culture specific conversion. 2016-04-17 19:17:09 -07:00
amaitland 4de3a1795d Remove DisposableResource - only class implementing it was JavascriptObjectRepository and it didn't override the InternalDispose method 2016-04-15 15:42:40 +10:00
amaitland 669404f74c Change new paramAray test methods in BindingTest.html to execute immediately (same as all the majority)
Revert changes to NuGet.config
Remove unused using statement from ScriptedMethodsBoundObject
Rename JavascriptMethod.Parameters to just JavascriptMethod.Parameters (it's in the context of the method so naming was redundant)
Pre compute HasParamArray for minor (very minor) performance improvement - relevant when executing method many times in a tight loop
2016-04-05 17:03:33 +10:00
Chris Bardsley d3d6907dac Refactored changes from build#1644 to account for discussed changes. 2016-04-04 21:44:22 -07:00
Chris Bardsley b628199ee9 Fix for C# paramArray and refactor on arguments mismatch 2016-03-23 21:17:47 -07:00
amaitland bae3c28e92 Update copyright to 2016 2016-01-11 14:11:30 +10:00
illfang aad399ba5f detailed exception string generation for exceptions in injected native functions / properties 2015-09-08 10:49:33 +09:00
cefsharp-ms 38fe85cf71 TargetInvocationException is converted properly in JavascriptObjectRepository.TryCallMethod 2015-09-04 13:31:23 +02:00
amaitland 65d44b3962 Only send register IPC message of there are is a bound object 2015-08-18 09:29:50 +10:00
amaitland 74d987a02d Switch to Interlocked.Increment for Id generation
Add missing xml comment
2015-08-03 10:59:31 +10:00
cefsharp-ms a99e020138 added option to register async js objects with only method bindings 2015-07-23 15:10:28 +02:00