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
This commit is contained in:
Alex Maitland
2018-01-22 10:24:25 +10:00
committed by amaitland
parent 4cb81d4b99
commit 44fdfa94c8
39 changed files with 1077 additions and 185 deletions
@@ -26,8 +26,9 @@ namespace CefSharp
jsObject->Id = GetInt64(list, 0);
jsObject->Name = StringUtils::ToClr(list->GetString(1));
jsObject->JavascriptName = StringUtils::ToClr(list->GetString(2));
jsObject->IsAsync = list->GetBool(3);
auto methodList = list->GetList(3);
auto methodList = list->GetList(4);
auto methodCount = methodList->GetInt(0);
auto k = 1;
for (auto j = 0; j < methodCount; j++)
@@ -42,7 +43,7 @@ namespace CefSharp
jsObject->Methods->Add(jsMethod);
}
auto propertyList = list->GetList(4);
auto propertyList = list->GetList(5);
auto propertyCount = propertyList->GetInt(0);
k = 1;
for (auto j = 0; j < propertyCount; j++)
@@ -63,13 +64,13 @@ namespace CefSharp
return jsObject;
}
JavascriptRootObject^ DeserializeJsRootObject(const CefRefPtr<CefListValue>& list, int index)
List<JavascriptObject^>^ DeserializeJsObjects(const CefRefPtr<CefListValue>& list, int index)
{
auto result = gcnew JavascriptRootObject();
auto result = gcnew List<JavascriptObject^>();
auto subList = list->GetList(index);
for (auto i = 0; i < subList->GetSize(); i++)
{
result->MemberObjects->Add(DeserializeJsObject(subList, i));
result->Add(DeserializeJsObject(subList, i));
}
return result;