From 37a364c0ade2c544dda594642da0be74dde2ebbb Mon Sep 17 00:00:00 2001 From: amaitland Date: Thu, 12 Jul 2018 20:31:31 +1000 Subject: [PATCH] Add IJavascriptObjectRepository.UnRegister Allows for an object to be removed from the repository, doesn't unbind the object from javascript though --- CefSharp/IJavascriptObjectRepository.cs | 7 +++++++ CefSharp/Internals/JavascriptObjectRepository.cs | 15 +++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/CefSharp/IJavascriptObjectRepository.cs b/CefSharp/IJavascriptObjectRepository.cs index cf9f1c152..8ec5b3b58 100644 --- a/CefSharp/IJavascriptObjectRepository.cs +++ b/CefSharp/IJavascriptObjectRepository.cs @@ -35,6 +35,13 @@ namespace CefSharp /// and other advanced options though this class. void Register(string name, object objectToBind, bool isAsync = false, BindingOptions options = null); /// + /// UnRegister a bound object from the repository. If you unregister an object that is currently + /// bound in JavaScript then the method/property calls will fail. + /// + /// object name + /// returns true if the object was successfully unbound otherwise false. + bool UnRegister(string name); + /// /// Has bound objects /// bool HasBoundObjects { get; } diff --git a/CefSharp/Internals/JavascriptObjectRepository.cs b/CefSharp/Internals/JavascriptObjectRepository.cs index 6169c2047..e9981e41a 100644 --- a/CefSharp/Internals/JavascriptObjectRepository.cs +++ b/CefSharp/Internals/JavascriptObjectRepository.cs @@ -160,6 +160,21 @@ namespace CefSharp.Internals AnalyseObjectForBinding(jsObject, analyseMethods: true, analyseProperties: !isAsync, readPropertyValue: false, camelCaseJavascriptNames: camelCaseJavascriptNames); } + public bool UnRegister(string name) + { + foreach (var kvp in objects) + { + if(string.Equals(kvp.Value.Name, name, StringComparison.OrdinalIgnoreCase)) + { + objects.Remove(kvp.Key); + + return true; + } + } + + return false; + } + internal bool TryCallMethod(long objectId, string name, object[] parameters, out object result, out string exception) { exception = "";