From aa0970268fbf84fe0b2310cb208e13eb91d1486c Mon Sep 17 00:00:00 2001 From: amaitland Date: Sun, 11 Aug 2019 18:28:42 +1000 Subject: [PATCH] LegacyJavascriptBinding - Enabled field was overwritten when a popup was opened Popups don't transmit their own bound object information, _legacyBindingEnabled was being set to false --- .../CefAppUnmanagedWrapper.cpp | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.cpp b/CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.cpp index 005f85532..e2d0f9167 100644 --- a/CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.cpp +++ b/CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.cpp @@ -55,28 +55,34 @@ namespace CefSharp //Multiple CefBrowserWrappers created when opening popups _browserWrappers->TryAdd(browser->GetIdentifier(), wrapper); - _legacyBindingEnabled = extraInfo->GetBool("LegacyBindingEnabled"); - - if (_legacyBindingEnabled) + //For the main browser only we check LegacyBindingEnabled and + //load the objects. Popups don't send this information and checking + //will override the _legacyBindingEnabled field + if (!browser->IsPopup()) { - auto objects = extraInfo->GetList("LegacyBindingObjects"); - if (objects.get() && objects->IsValid()) - { - auto javascriptObjects = DeserializeJsObjects(objects, 0); + _legacyBindingEnabled = extraInfo->GetBool("LegacyBindingEnabled"); - for each (JavascriptObject^ obj in Enumerable::OfType(javascriptObjects)) + if (_legacyBindingEnabled) + { + auto objects = extraInfo->GetList("LegacyBindingObjects"); + if (objects.get() && objects->IsValid()) { - //Using LegacyBinding with multiple ChromiumWebBrowser instances that share the same - //render process and using LegacyBinding will cause problems for the limited caching implementation - //that exists at the moment, for now we'll remove an object if already exists, same behaviour - //as the new binding method. - //TODO: This should be removed when https://github.com/cefsharp/CefSharp/issues/2306 - //Is complete as objects will be stored at the browser level - if (_javascriptObjects->ContainsKey(obj->JavascriptName)) + auto javascriptObjects = DeserializeJsObjects(objects, 0); + + for each (JavascriptObject^ obj in Enumerable::OfType(javascriptObjects)) { - _javascriptObjects->Remove(obj->JavascriptName); + //Using LegacyBinding with multiple ChromiumWebBrowser instances that share the same + //render process and using LegacyBinding will cause problems for the limited caching implementation + //that exists at the moment, for now we'll remove an object if already exists, same behaviour + //as the new binding method. + //TODO: This should be removed when https://github.com/cefsharp/CefSharp/issues/2306 + //Is complete as objects will be stored at the browser level + if (_javascriptObjects->ContainsKey(obj->JavascriptName)) + { + _javascriptObjects->Remove(obj->JavascriptName); + } + _javascriptObjects->Add(obj->JavascriptName, obj); } - _javascriptObjects->Add(obj->JavascriptName, obj); } } }