Commit Graph

80 Commits

Author SHA1 Message Date
campersau fd87988c39 Move LegacyBindingEnabled / JavascriptBindingPropertyName to per browser settings (#5231)
* Move LegacyBindingEnabled / JavascriptBindingPropertyName to per browser settings

* Stricter test

---------

Co-authored-by: Alex Maitland <amaitland@users.noreply.github.com>
2026-04-30 21:25:18 +10:00
campersau 00c8aa5449 Allow JavaScript binding when browser wrapper cannot be found (#5229)
* Allow JavaScript binding when browser wrapper cannot be found

* Store JavascriptBindingSettings per Browser and never remove them

This avoids the issue that sometimes browsers are destroyed but then referenced again without them beeing created

* Use dict->Values
2026-04-10 18:00:04 +10:00
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
amaitland 8fd619c241 Core - Fix CPP compiler warnings 2026-02-22 07:58:30 +10:00
Alex Maitland 7b9e24db55 Core - Upgrade to stdcpp20 (#5215)
* Core - Upgrade to stdcpp20

- Set NOMINMAX
- Change compiler options
- Fix compiler errors

---------

Co-authored-by: amaitland <307872+amaitland@users.noreply.github.com>
2026-02-21 14:48:13 +10:00
Alex Maitland d78d01a2c4 Core - Rewrite RenderProcess to avoid using OnBrowserDestroyed for JS eval (#5197)
- JavascriptCallbackRegistry - Get BrowserId From V8Context
- Render Process - Rewrite to store root object wrapper by frame instead of per browser
-  Don't store JavascriptRootObjectWrapper in the browserWrapper as CEF is calling destroyed more than it should.
-  Revert "Tests - Simplify ShouldFailWhenIsObjectCachedCalledWithInvalidObjectName"

This reverts commit f8a81acf7a.

---------

Co-authored-by: amaitland <307872+amaitland@users.noreply.github.com>
2025-12-03 19:00:12 +10:00
Alex Maitland 8d7a169590 Change Frame identifier from Int64 to String (#4740)
* Change Frame identifier from Int64 to String

Issue https://github.com/cefsharp/CefSharp/issues/4737

* Fix SetCanExecuteJavascriptOnMainFrame frameId parsing

* Add tests

* NetCore Tests - Install missing packages
2024-03-09 06:55:27 +10:00
Alex Maitland 2a9b50640f Core - Change from cef type defs to C++11 defs
https://bitbucket.org/chromiumembedded/cef/commits/5042d7140822cd13b80990f61ce2d3865864a3d8
2023-07-16 09:31:55 +10:00
Alex Maitland d350cad52a Update to M93 (#3781)
* Upgrade to CEF 93.1.7+g9117d6a+chromium-93.0.4577.42 / Chromium 93.0.4577.42

- Core - Add basic ref counting implementation

IMPLEMENT_REFCOUNTING implementation uses atomic which
forces the VC++ compiler to compile as native which doesn't work for our managed ref classes.

    - Use InterlockedCompareExchange for custom ref count reads
    - Use InterlockedIncrement/InterlockedDecrement directly
    - There's no memory barrier for HasOneRef/HasAtLeastOneRef as the read of a LONG should happen in one operation
on 32/64 bit architectures (at least that's my understanding at this point in time).

    References:
    https://github.com/chromiumembedded/cef/blob/4472/include/base/internal/cef_atomicops_x86_msvc.h#L125
    https://github.com/chromiumembedded/cef/blob/4472/include/base/internal/cef_atomicops_arm64_msvc.h#L107
    https://github.com/chromiumembedded/cef/blob/4472/include/base/cef_atomic_ref_count.h#L114
    https://github.com/chromiumembedded/cef/blob/4472/include/cef_base.h#L91

-  Remove Microsoft.Net.Compilers package from projects
Now that we require a min of VS2019 to build there's no need for a custom compiler package
- Start removing VS2015/VC++2015 references
- Remove RegisterWidevineCdm
This is a breaking change. CEF will now automatically download the Widevine CDM component
Resolves #3767

- RequestContext.LoadExtension now uses managed to code spawn on CEF UI Thread
Avoid having to use cef_callback.h which was causing problems for x86 builds
2021-09-03 10:51:18 +10:00
Alex Maitland b24cd8e2d7 C++/CLI - Replace OVERRIDE with override
OVERRIDE was a CEF macro which has been removed, use standard compliant override

Issue #3636
2021-07-31 15:52:55 +10:00
Alex Maitland 20dad8aced Core - Crash opening popup window
Upstream changes mean that extraInfo can now be null (https://bitbucket.org/chromiumembedded/cef/issues/3123/convert-legacy-ipc-messages-to-mojo)
We currently only send extra Info for the main browser and not for popups.
Assign the _jsBindingPropertyName/_jsBindingPropertyNameCamelCase properties
by default and only update when the user has specified their own name.

It's not currently possible to have different naming in the same render process (was previously the case).

Issue #3670
2021-07-06 11:56:35 +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 e3e4c3fe35 BrowserSubprocess - Namespace cleanup
Possibly a few cases that were missed, this should be the bulk of the rename

Resolves #3253
2021-02-27 14:40:16 +10:00
amaitland 53f15f22eb Upgrade to CEF 85.3.6+gacfac2f+chromium-85.0.4183.102 / Chromium 85.0.4183.102
- Remove CefSettings.RegisterExtension (#3184)
- Add IRenderProcessHandler.OnWebKitInitialized
- Add Cef.RegisterExtension (Browser SubProcess specific implementation)

Resolves #3184
2020-09-16 13:49:37 +10:00
amaitland ae41e10d71 Core - Javascript Binding Configure Property Name
- 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
2020-05-30 19:28:50 +10:00
Geevo 66691105b4 Core - Added ability to configure/customize javascript binding property name. 2020-05-30 18:53:13 +10:00
amaitland e0268a3e2a Network Service - Register custom scheme in all process types
The network services requires that custom schemes be registered, previously we only registered them in render processes.

Add SubProcessApp to handle scheme registration
CefAppUnmanagedWrapper inherits SubProcessApp now

#2743
2019-07-04 20:47:42 +10:00
amaitland 73a156fdc5 Initial version 75 upgrade and NetworkService changes
Compiles, that's about it at this point, there are major CEF breaking changes, and lots to be addressed.

Browser Process (main process)
- Removed IResourceHandlerFactory as it no longer fits with the structure that CEF provides
- New IResourceRequestHandler interface added, not plumbed in yet
- CefSettings - Add RootCachePath and ApplicationClientIdForFileScanning

BrowserSubprocess (render process)
- SendProcessMessage was moved from CefBrowser to CefFrame
- OnBrowserCreated added extraInfo param

The BrowserSubprocess changes for this upgrade should be complete
2019-06-25 19:24:57 +10:00
Gilberto Stankiewicz db3839a285 Fix typos (#2750) 2019-04-26 12:19:34 +10:00
Alex Maitland 70de3a6d9c Add Initial IRenderProcessHandler.OnContextCreated/Released implementation (#2697)
* WinForms/WPF - Dispose of IFrame after calling LoadUrl

* BrowserProcess - Add initial implementation of IRenderProcessHandler.OnContextCreated/OnContextReleased

- IV8Context.Execute is the only method to be implemented so far (execute script without returning a result)
- Wrappers for CefFrame and CefBrowser have yet to be imported yet, still need to determine if they should be included individually or reference to CefSharp.Core added

* BrowserProcess - Add wrappers for Browser and Frame

Ultimately we should probably remove the CefSharp.BrowserSubprocess.Core project and move all the code into a folder/namespace within CefSharp.Core
This would allow us to share the a lot of existing code, major refactor required

* CefSharp.Common.props - Add CefSharpBrowserProcessCore32/64 properties

Make creating your own custom browser process easier

* BrowserProcess - Remove example and add comments about creating your own custom version
2019-03-20 20:33:10 +10:00
amaitland 11a8371e19 Rename CefExtension to V8Extension
Resolves #2612
2018-12-27 15:47:29 +10: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 7450d0d51b JSB - Remove use of CefRegisterExtension and change Promise creator to an anon function
Use CefV8Context::Eval to create the promise using an anonymous function

Attempt to resolve #2432 (though it actually seems upgrading to a newer version resolves the underlying problem)
2018-08-27 13:12:55 +10:00
João Neves 5a713fdf7d Support uncaught exception handling (#2244)
* Added support for uncaught javascript exception in Render Process Message Handler
* Fixed typo
* Added stack frame column numbers
* Code review
* Code review
* Update JavascriptException.cs
2018-03-07 10:21:31 +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
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
amaitland e5ecfde20f Upgrade version number to 57.0.0
Upgrade to cef.redist.x86.3.2987.1591
CefSchemeRegistrar::AddCustomScheme has new params - IsSecure and IsCorsEnabled
Also new CefRawPtr type is used for Scheme registra
2017-03-13 10:58:03 +10:00
Chris cd934267c6 Updated copyright year and made sure it used same format everywhere (#1966) 2017-03-06 08:44:37 +10:00
amaitland bae3c28e92 Update copyright to 2016 2016-01-11 14:11:30 +10:00
Rich McNeary a27a097df6 Change from EnableFocusedNodeChanged to FocusedNodeChangedEnabled to match the existing WindowlessRenderingEnabled setting property. 2016-01-05 07:30:23 -05:00
amaitland d33c41ec5d Remove unused include
No need to wrap bool in gcroot
Move command line parsing into c# land - can be reused in a few places.
Reduce code duplication in OnProcessMessageReceived - kOnFocusedNodeChanged handler
Minor changes for code consistency/formatting
2015-12-09 11:23:06 +10:00
Rich McNeary 443804084e Changed to specifically request FocusNodeChanged messages. 2015-12-08 09:04:22 -05:00
Rich McNeary 1fb54241f7 Add the OptionalMessages property to CefSettings. 2015-12-07 16:27:17 -05:00
Rich McNeary ae49a5385b Fix: tabs to spaces, if and for braces, use frame ID. 2015-12-07 09:48:57 -05:00
Rich McNeary ce79f71275 When OnFocusedNodeChanged data is passed from render to browser process. 2015-12-03 15:59:27 -05:00
amaitland 9aacd3cc61 VS2012 has problem with the auto keyboard in for each loops 2015-10-18 08:18:33 +10:00
amaitland 4dbc90333d CefAppWrapper no longer inherits from DisposableResource
No need for CefRenderProcess to keep a list of browsers any more, one less  thing to cleanup
2015-10-15 21:00:27 +10:00
amaitland 5869b20068 Change CefBrowserWrapper Dictionary to ConcurrentDictionary 2015-10-11 19:50:55 +10:00
amaitland b236d7711c Restructure code so JavascriptRootObject's are stored and can be used across multiple CefBrowserWrapper instances (popups in this context)
Code is now very much dependant on using --process-per-tab for this structure to work
2015-09-24 18:44:30 +10:00
amaitland e492c0d21e Fixes #1263
Pass in CefCustomScheme as command line argument, as they're registered correctly in all processes
2015-09-15 15:15:26 +10:00
amaitland 22fa4c3b10 Register custom schemes in render process
Fixes #1014
2015-08-03 12:30:58 +10:00
amaitland bec6fe4618 Formatting and naming fixups 2015-08-03 12:16:20 +10:00
amaitland 5a09a5ef35 Merge branch 'cefextensions' of https://github.com/arsher/CefSharp 2015-08-03 12:12:51 +10:00
David Serfozo 4fdca242d0 CefExtension modified to null-check JavascriptCode in constructor 2015-08-02 16:07:43 +02:00
David Serfozo c9b7366786 Extensions transmitted in OnRenderThreadCreated and registered after webkit initialization 2015-08-01 20:25:12 +02:00
cefsharp-ms 0333437917 fixed tabs again 2015-07-31 17:30:07 +02:00
cefsharp-ms c395f03ba2 jscallbackregistry lifecycle is managed by javascriptrootobjectwrapper, async methods too bound by javascriptrootobjectwrapper 2015-07-31 17:26:59 +02:00
cefsharp-ms dbf5e94293 updated kPromisCreatorScript field to be static const 2015-07-31 17:17:55 +02:00
cefsharp-ms 43acbbe3fc CefAppUnmanagedWrapper wrapped up a little bit 2015-07-31 17:17:22 +02:00
cefsharp-ms fc85d90877 added callback capability for async bound method with promises 2015-07-23 15:12:50 +02:00