diff --git a/CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.h b/CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.h index 9f4bef3c9..04be3c8d0 100644 --- a/CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.h +++ b/CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.h @@ -35,7 +35,7 @@ namespace CefSharp CefString _jsBindingPropertyNameCamelCase; // The serialized registered object data waiting to be used. - gcroot _javascriptObjectCache; + gcroot _javascriptObjectCache; gcroot _registerBoundObjectRegistry; @@ -49,7 +49,7 @@ namespace CefSharp _onBrowserDestroyed = onBrowserDestroyed; _browserWrappers = gcnew ConcurrentDictionary(); _focusedNodeChangedEnabled = enableFocusedNodeChanged; - _javascriptObjectCache = gcnew JavaScriptObjectCache(); + _javascriptObjectCache = gcnew LegacyJavaScriptObjectCache(); _registerBoundObjectRegistry = gcnew RegisterBoundObjectRegistry(); _legacyBindingEnabled = false; _jsBindingPropertyName = "CefSharp"; diff --git a/CefSharp/Internals/IJavaScriptObjectCache.cs b/CefSharp/Internals/IJavaScriptObjectCache.cs new file mode 100644 index 000000000..16ba92111 --- /dev/null +++ b/CefSharp/Internals/IJavaScriptObjectCache.cs @@ -0,0 +1,42 @@ +// Copyright © 2023 The CefSharp Authors. All rights reserved. +// +// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. + +using System.Collections.Generic; + +namespace CefSharp.Internals +{ + /// + /// Render Process JavaScript Binding (JSB) object cache + /// + public interface IJavaScriptObjectCache + { + /// + /// Remove the Browser specific Cache + /// + /// browser Id + void ClearCache(int browserId); + /// + /// Gets the browser specific cache (dictionary) based on it's Id + /// + /// browser Id + /// Dictionary of cache 's. + /// + Dictionary GetCache(int browserId); + /// + /// Gets a collection of s + /// for the given + /// + /// browser Id + /// Collection of current bound objects for the browser + /// + ICollection GetCacheValues(int browserId); + /// + /// Insert or Update the within the Cache + /// + /// browser id + /// JavaScript object + /// + void InsertOrUpdate(int browserId, IList javascriptObjects); + } +} diff --git a/CefSharp/Internals/LegacyJavaScriptObjectCache.cs b/CefSharp/Internals/LegacyJavaScriptObjectCache.cs new file mode 100644 index 000000000..704a73039 --- /dev/null +++ b/CefSharp/Internals/LegacyJavaScriptObjectCache.cs @@ -0,0 +1,50 @@ +// Copyright © 2023 The CefSharp Authors. All rights reserved. +// +// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. + +using System.Collections.Generic; + +namespace CefSharp.Internals +{ + /// + /// Render Process JavaScript Binding (JSB) object cache + /// Legacy Behaviour, objects are cache per process. + /// + public class LegacyJavaScriptObjectCache : IJavaScriptObjectCache + { + private readonly Dictionary cache + = new Dictionary(); + + /// + public void ClearCache(int browserId) + { + // NO OP + } + + /// + public void InsertOrUpdate(int browserId, IList javascriptObjects) + { + foreach (var obj in javascriptObjects) + { + if (cache.ContainsKey(obj.Name)) + { + cache.Remove(obj.Name); + } + + cache.Add(obj.Name, obj); + } + } + + /// + public ICollection GetCacheValues(int browserId) + { + return cache.Values; + } + + /// + public Dictionary GetCache(int browserId) + { + return cache; + } + } +} diff --git a/CefSharp/RenderProcess/JavaScriptObjectCache.cs b/CefSharp/Internals/PerBrowserJavaScriptObjectCache.cs similarity index 53% rename from CefSharp/RenderProcess/JavaScriptObjectCache.cs rename to CefSharp/Internals/PerBrowserJavaScriptObjectCache.cs index 2e6eae258..2cb8fd061 100644 --- a/CefSharp/RenderProcess/JavaScriptObjectCache.cs +++ b/CefSharp/Internals/PerBrowserJavaScriptObjectCache.cs @@ -4,35 +4,26 @@ using System; using System.Collections.Generic; -using CefSharp.Internals; -namespace CefSharp.RenderProcess +namespace CefSharp.Internals { /// - /// JavaScriptObjectCache is used in the RenderProcess to cache - /// JavaScript bound objects at a CefBrowser level + /// Render Process JavaScript Binding (JSB) object cache + /// Stores bound objects per CefBrowser. /// - public class JavaScriptObjectCache + public class PerBrowserJavaScriptObjectCache : IJavaScriptObjectCache { private readonly Dictionary> cache = new Dictionary>(); - /// - /// Remove the Browser specific Cache - /// - /// browser Id + /// public void ClearCache(int browserId) { cache.Remove(browserId); } - /// - /// Insert or Update the within the Cache - /// - /// browser id - /// JavaScript object - /// - public void InsertOrUpdate(int browserId, IList javascriptObjects) + /// + public void InsertOrUpdate(int browserId, IList javascriptObjects) { var dict = GetCacheInternal(browserId); @@ -47,13 +38,7 @@ namespace CefSharp.RenderProcess } } - /// - /// Gets a collection of s - /// for the given - /// - /// browser Id - /// Collection of current bound objects for the browser - /// + /// public ICollection GetCacheValues(int browserId) { if (cache.TryGetValue(browserId, out var dict)) @@ -64,12 +49,7 @@ namespace CefSharp.RenderProcess return new List(); } - /// - /// Gets the browser specific cache (dictionary) based on it's Id - /// - /// browser Id - /// Dictionary of cache 's. - /// + /// public Dictionary GetCache(int browserId) { var dict = GetCacheInternal(browserId);