Commit Graph

6 Commits

Author SHA1 Message Date
luca-sonntag 00d57a555c Javascript Binding - Finalize JavascriptBindingApiAllowOrigins: Per-browser isolation and origin normalization (#5218)
* Javascript Binding - Add Ability to limit origins

* Move JS binding settings to CefBrowserWrapper and optimize origin validation

* Initialize origins to null

* Normalize allowed origins

* Optimize origin validation

* Add null check for origin compare

* Fix JavaScript Binding API settings for popups

Move the JS binding API configuration block out of the !browser->IsPopup() scope
in OnBrowserCreated. This ensures that IsJavascriptBindingApiAllowed() enforces
configured restrictions for popups as well.

* Fix possible null deref for JavascriptBindingApiAllowOrigins

In IsJavascriptBindingApiAllowed, added a null check for JavascriptBindingApiAllowOrigins
to prevent a potential null dereference if JavascriptBindingApiHasAllowOrigins is true
but the allowOrigins list itself was null.

* Simplify origin normalization and add null check

* Add more test cases

* Refactor IsJavascriptBindingApiAllowed signature

Refactored IsJavascriptBindingApiAllowed to accept a CefBrowserWrapper^ parameter directly, eliminating redundant lookups and improving clarity. Updated all call sites to pass the browser wrapper explicitly.

* Clarify summary for HasJavascriptBindingApiAllowOrigins

Clarify documentation for HasJavascriptBindingApiAllowOrigins method to specify zero or more origins

* Simplify origin comparison logic in CefAppUnmanagedWrapper

Refactored code to directly compare wide string origins using
_wcsicmp, removing unnecessary pointer casts and null checks.
This streamlines the logic and improves readability.

* Add tests for JavaScript binding API behavior across cross-origin navigation

---------

Co-authored-by: amaitland <307872+amaitland@users.noreply.github.com>
Co-authored-by: Luca Sonntag <luca.sonntag@cgm.com>
2026-03-22 07:35:54 +10:00
Alex Maitland 0386220e06 JavascriptBinding - Add JavascriptBindingSettings.JavascriptBindingApiEnabled property (#3571)
- The Javascript methods that CefSharp provides in relation to JavaScript Binding are
  created using a Global (window) Object. Settings this property allows you to disable
  the creation of this object. Features like EvaluateScriptAsPromiseAsync that rely on
  the creation of this object will no longer function.
2021-06-04 13:26:00 +10:00
Alex Maitland 04942dc358 Remove CefSharpSettings.LegacyJavascriptBindingEnabled
This is a breaking change

Resolves #3531
2021-04-30 13:12:23 +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 f11785e44b Core - Fix some compiler warnings 2020-08-18 18:08:09 +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