SIGN IN SIGN UP
cefsharp / CefSharp UNCLAIMED

.NET (WPF and Windows Forms) bindings for the Chromium Embedded Framework

0 0 9 C#
// Copyright © 2014 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.
#pragma once
#include "include/cef_v8.h"
#include "JavascriptCallbackRegistry.h"
#ifndef NETCOREAPP
#include "JavascriptObjectWrapper.h"
#endif
#include "Async/JavascriptAsyncObjectWrapper.h"
using namespace System::Runtime::Serialization;
using namespace System::Linq;
using namespace System::Collections::Generic;
using namespace CefSharp::Internals::Async;
#ifndef NETCOREAPP
using namespace CefSharp::Internals::Wcf;
#endif
namespace CefSharp
{
// This wraps the transmitted registered objects
// by binding the meta-data to V8 JavaScript objects
// and installing callbacks for changes to those
// objects.
private ref class JavascriptRootObjectWrapper
{
private:
//Only access through Interlocked::Increment - used to generate unique callback Id's
//Is static so ids are unique to this process https://github.com/cefsharp/CefSharp/issues/2792
static int64 _lastCallback;
#ifndef NETCOREAPP
initonly List<JavascriptObjectWrapper^>^ _wrappedObjects;
#endif
2015-07-31 12:38:12 +02:00
initonly List<JavascriptAsyncObjectWrapper^>^ _wrappedAsyncObjects;
initonly Dictionary<int64, JavascriptAsyncMethodCallback^>^ _methodCallbacks;
#ifndef NETCOREAPP
IBrowserProcess^ _browserProcess;
#endif
// The entire set of possible JavaScript functions to
// call directly into.
2015-07-31 12:38:12 +02:00
JavascriptCallbackRegistry^ _callbackRegistry;
2015-07-31 12:38:12 +02:00
int64 SaveMethodCallback(JavascriptAsyncMethodCallback^ callback);
2015-07-31 12:38:12 +02:00
internal:
property JavascriptCallbackRegistry^ CallbackRegistry
{
CefSharp::Internals::JavascriptCallbackRegistry^ get();
2015-07-31 12:38:12 +02:00
}
public:
#ifdef NETCOREAPP
JavascriptRootObjectWrapper(int browserId)
#else
JavascriptRootObjectWrapper(int browserId, IBrowserProcess^ browserProcess)
#endif
{
#ifndef NETCOREAPP
_browserProcess = browserProcess;
_wrappedObjects = gcnew List<JavascriptObjectWrapper^>();
#endif
2015-07-31 12:38:12 +02:00
_wrappedAsyncObjects = gcnew List<JavascriptAsyncObjectWrapper^>();
_callbackRegistry = gcnew JavascriptCallbackRegistry(browserId);
_methodCallbacks = gcnew Dictionary<int64, JavascriptAsyncMethodCallback^>();
}
2015-07-31 12:38:12 +02:00
~JavascriptRootObjectWrapper()
{
if (_callbackRegistry != nullptr)
{
delete _callbackRegistry;
_callbackRegistry = nullptr;
}
#ifndef NETCOREAPP
2015-07-31 12:38:12 +02:00
for each (JavascriptObjectWrapper^ var in _wrappedObjects)
2015-08-03 10:37:09 +10:00
{
2015-07-31 12:38:12 +02:00
delete var;
2015-08-03 10:37:09 +10:00
}
2015-07-31 12:38:12 +02:00
_wrappedObjects->Clear();
#endif
2015-07-31 12:38:12 +02:00
for each (JavascriptAsyncObjectWrapper^ var in _wrappedAsyncObjects)
{
delete var;
}
_wrappedAsyncObjects->Clear();
2015-07-31 12:38:12 +02:00
for each(JavascriptAsyncMethodCallback^ var in _methodCallbacks->Values)
{
delete var;
}
_methodCallbacks->Clear();
}
2015-07-31 12:38:12 +02:00
bool TryGetAndRemoveMethodCallback(int64 id, JavascriptAsyncMethodCallback^% callback);
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
2018-01-22 10:24:25 +10:00
void Bind(ICollection<JavascriptObject^>^ objects, const CefRefPtr<CefV8Value>& v8Value);
};
}