diff --git a/CefSharp.Core.Runtime/Internals/ClientAdapter.cpp b/CefSharp.Core.Runtime/Internals/ClientAdapter.cpp index fc315ae0f..6a48a4668 100644 --- a/CefSharp.Core.Runtime/Internals/ClientAdapter.cpp +++ b/CefSharp.Core.Runtime/Internals/ClientAdapter.cpp @@ -1311,7 +1311,7 @@ namespace CefSharp //Call GetObjects with the list of names provided (will default to all if the list is empty //Previously we only sent a response if there were bound objects, now we always send //a response so the promise is resolved. - auto objs = objectRepository->GetObjects(names); + auto objs = objectRepository->GetObjects(StringUtils::ToClr(frame->GetURL()), names); auto msg = CefProcessMessage::Create(kJavascriptRootObjectResponse); auto responseArgList = msg->GetArgumentList(); diff --git a/CefSharp.Core.Runtime/ManagedCefBrowserAdapter.cpp b/CefSharp.Core.Runtime/ManagedCefBrowserAdapter.cpp index eb0d26102..47daea5dd 100644 --- a/CefSharp.Core.Runtime/ManagedCefBrowserAdapter.cpp +++ b/CefSharp.Core.Runtime/ManagedCefBrowserAdapter.cpp @@ -51,7 +51,7 @@ namespace CefSharp if (objectRepositorySettings->LegacyBindingEnabled) { - auto legacyBoundObjects = objectRepository->GetLegacyBoundObjects(); + auto legacyBoundObjects = objectRepository->GetLegacyBoundObjects(address); legacyBindingEnabled = objectRepository->HasBoundObjects; diff --git a/CefSharp.Test/JavascriptBinding/JavaScriptObjectRepositoryTests.cs b/CefSharp.Test/JavascriptBinding/JavaScriptObjectRepositoryTests.cs index c1679612f..848184596 100644 --- a/CefSharp.Test/JavascriptBinding/JavaScriptObjectRepositoryTests.cs +++ b/CefSharp.Test/JavascriptBinding/JavaScriptObjectRepositoryTests.cs @@ -41,7 +41,7 @@ public void ShouldRegisterJavascriptObjectBindWhenNamespaceIsNull() #endif Assert.True(javascriptObjectRepository.IsBound(name)); - var boundObjects = javascriptObjectRepository.GetObjects(new List { name }); + var boundObjects = javascriptObjectRepository.GetObjects("example.com", new List { name }); Assert.Single(boundObjects); var result = javascriptObjectRepository.TryCallMethod(boundObjects[0].Id, "getExampleString", new object[0]); @@ -74,7 +74,7 @@ public void ShouldRegisterJavascriptObjectPropertyBindWhenNamespaceIsNull() javascriptObjectRepository.Register(name, new NoNamespaceClass(), false, bindingOptions); Assert.True(javascriptObjectRepository.IsBound(name)); - var boundObjects = javascriptObjectRepository.GetObjects(new List { name }); + var boundObjects = javascriptObjectRepository.GetObjects("example.com", new List { name }); Assert.Single(boundObjects); object getResult, setResult = 100; diff --git a/CefSharp.Test/JavascriptBinding/JavascriptBindingTests.cs b/CefSharp.Test/JavascriptBinding/JavascriptBindingTests.cs index a0ceac4c6..3bfbdd13d 100644 --- a/CefSharp.Test/JavascriptBinding/JavascriptBindingTests.cs +++ b/CefSharp.Test/JavascriptBinding/JavascriptBindingTests.cs @@ -210,6 +210,7 @@ public async Task ShouldFireResolveObject() Assert.NotNull(evt); Assert.Equal("first", evt.Arguments.ObjectName); + Assert.Equal("https://cefsharp.example/HelloWorld.html", evt.Arguments.Url); } [Fact] diff --git a/CefSharp/Event/JavascriptBindingEventArgs.cs b/CefSharp/Event/JavascriptBindingEventArgs.cs index 955c735b8..9275a1af2 100644 --- a/CefSharp/Event/JavascriptBindingEventArgs.cs +++ b/CefSharp/Event/JavascriptBindingEventArgs.cs @@ -21,15 +21,22 @@ public class JavascriptBindingEventArgs : EventArgs /// public string ObjectName { get; private set; } + /// + /// URL of frame the call originated from. + /// + public string Url { get; private set; } + /// /// Constructor /// /// object repository + /// URL of frame the call originated from. /// object name - public JavascriptBindingEventArgs(IJavascriptObjectRepository objectRepository, string name) + public JavascriptBindingEventArgs(IJavascriptObjectRepository objectRepository, string url, string name) { ObjectRepository = objectRepository; ObjectName = name; + Url = url; } } } diff --git a/CefSharp/Internals/IJavascriptObjectRepositoryInternal.cs b/CefSharp/Internals/IJavascriptObjectRepositoryInternal.cs index 1069ebf52..d2e4ae3e7 100644 --- a/CefSharp/Internals/IJavascriptObjectRepositoryInternal.cs +++ b/CefSharp/Internals/IJavascriptObjectRepositoryInternal.cs @@ -19,8 +19,8 @@ public interface IJavascriptObjectRepositoryInternal : IJavascriptObjectReposito bool TrySetProperty(long objectId, string name, object value, out string exception); #endif bool IsBrowserInitialized { get; set; } - List GetObjects(List names = null); - List GetLegacyBoundObjects(); + List GetObjects(string url, List names = null); + List GetLegacyBoundObjects(string url); void ObjectsBound(List> objs); } } diff --git a/CefSharp/Internals/JavascriptObjectRepository.cs b/CefSharp/Internals/JavascriptObjectRepository.cs index 8136b9e50..af9fca0be 100644 --- a/CefSharp/Internals/JavascriptObjectRepository.cs +++ b/CefSharp/Internals/JavascriptObjectRepository.cs @@ -123,16 +123,16 @@ public bool IsBound(string name) return objects.Values.Any(x => x.Name == name); } - List IJavascriptObjectRepositoryInternal.GetLegacyBoundObjects() + List IJavascriptObjectRepositoryInternal.GetLegacyBoundObjects(string url) { - RaiseResolveObjectEvent(LegacyObjects); + RaiseResolveObjectEvent(url, LegacyObjects); return objects.Values.Where(x => x.RootObject).ToList(); } //Ideally this would internal, unfurtunately it's used in C++ //and it's hard to expose internals - List IJavascriptObjectRepositoryInternal.GetObjects(List names) + List IJavascriptObjectRepositoryInternal.GetObjects(string url, List names) { //If there are no objects names or the count is 0 then we will raise //the resolve event then return all objects that are registered, @@ -140,7 +140,7 @@ List IJavascriptObjectRepositoryInternal.GetObjects(List x.RootObject).ToList(); } @@ -149,7 +149,7 @@ List IJavascriptObjectRepositoryInternal.GetObjects(List