From dcd56c27eb6c2416ab2d8a43550efd86ca08f02f Mon Sep 17 00:00:00 2001 From: Bill Tutt Date: Sat, 2 May 2015 02:36:10 -0400 Subject: [PATCH] Add some descriptive comments about what some of the subprocess classes do. --- .../CefAppUnmanagedWrapper.h | 1 + .../CefAppWrapper.h | 1 + .../CefBrowserWrapper.h | 10 +++++++- .../JavascriptRootObjectWrapper.h | 9 ++++++++ CefSharp/Internals/JavascriptObject.cs | 6 +++++ .../Internals/JavascriptObjectRepository.cs | 23 +++++++++++++++++++ 6 files changed, 49 insertions(+), 1 deletion(-) diff --git a/CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.h b/CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.h index a4724d2b7..2d4c179e4 100644 --- a/CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.h +++ b/CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.h @@ -15,6 +15,7 @@ using namespace System::Collections::Generic; namespace CefSharp { + // This class is the native subprocess level CEF object wrapper. private class CefAppUnmanagedWrapper : CefApp, CefRenderProcessHandler { private: diff --git a/CefSharp.BrowserSubprocess.Core/CefAppWrapper.h b/CefSharp.BrowserSubprocess.Core/CefAppWrapper.h index 9b690dd44..7c31f60f1 100644 --- a/CefSharp.BrowserSubprocess.Core/CefAppWrapper.h +++ b/CefSharp.BrowserSubprocess.Core/CefAppWrapper.h @@ -15,6 +15,7 @@ using namespace System::Collections::Generic; namespace CefSharp { + // Wrap CefAppUnmangedWrapper in a nice managed wrapper public ref class CefAppWrapper abstract : public DisposableResource { private: diff --git a/CefSharp.BrowserSubprocess.Core/CefBrowserWrapper.h b/CefSharp.BrowserSubprocess.Core/CefBrowserWrapper.h index 3696ba1d4..f9714e002 100644 --- a/CefSharp.BrowserSubprocess.Core/CefBrowserWrapper.h +++ b/CefSharp.BrowserSubprocess.Core/CefBrowserWrapper.h @@ -20,7 +20,8 @@ using namespace System::Threading::Tasks; namespace CefSharp { - // "Master class" for wrapping everything that the CefSubprocess needs. + // "Master class" for wrapping everything that the Cef Subprocess needs + // for ONE CefBrowser. public ref class CefBrowserWrapper : DisposableResource { @@ -35,13 +36,20 @@ namespace CefSharp property int BrowserId; property bool IsPopup; + + // This allows us to create the WCF proxies back to our parent process. property DuplexChannelFactory^ ChannelFactory; + + // The serialized registered object data waiting to be used. property JavascriptRootObject^ JavascriptRootObject; + property JavascriptRootObjectWrapper^ JavascriptRootObjectWrapper { CefSharp::JavascriptRootObjectWrapper^ get(); void set(CefSharp::JavascriptRootObjectWrapper^ value); }; + + // The WCF proxy to the parent process. property IBrowserProcess^ BrowserProcess; JavascriptResponse^ EvaluateScriptInContext(CefRefPtr context, CefString script); diff --git a/CefSharp.BrowserSubprocess.Core/JavascriptRootObjectWrapper.h b/CefSharp.BrowserSubprocess.Core/JavascriptRootObjectWrapper.h index 00069292f..857725860 100644 --- a/CefSharp.BrowserSubprocess.Core/JavascriptRootObjectWrapper.h +++ b/CefSharp.BrowserSubprocess.Core/JavascriptRootObjectWrapper.h @@ -16,6 +16,10 @@ using namespace CefSharp::Internals; 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. public ref class JavascriptRootObjectWrapper { private: @@ -24,7 +28,12 @@ namespace CefSharp IBrowserProcess^ _browserProcess; internal: + // TODO: Is this member variable necessary? + // We only use it to call a static method on CefV8Value atm. MCefRefPtr V8Value; + + // The entire set of possible JavaScript functions to + // call directly into. JavascriptCallbackRegistry^ CallbackRegistry; public: diff --git a/CefSharp/Internals/JavascriptObject.cs b/CefSharp/Internals/JavascriptObject.cs index 2d6824ce7..bf3d2ad25 100644 --- a/CefSharp/Internals/JavascriptObject.cs +++ b/CefSharp/Internals/JavascriptObject.cs @@ -7,6 +7,12 @@ using System.Runtime.Serialization; namespace CefSharp.Internals { + /// + /// This maps the registered objects in the browser process + /// to the reflection data necessary to update the objects, + /// and mapping information to how the object/method/proprerty + /// will be exposed to JavaScript. + /// [DataContract] public class JavascriptObject //: DynamicObject maybe later { diff --git a/CefSharp/Internals/JavascriptObjectRepository.cs b/CefSharp/Internals/JavascriptObjectRepository.cs index af56a4068..30ed8a559 100644 --- a/CefSharp/Internals/JavascriptObjectRepository.cs +++ b/CefSharp/Internals/JavascriptObjectRepository.cs @@ -9,12 +9,35 @@ using System.Reflection; namespace CefSharp.Internals { + /// + /// This class manages the registration of objects in the browser + /// process to be exposed to JavaScript in the renderer process. + /// Registration performs method, parameter, property type analysis + /// of the registered objects into meta-data tied to reflection data + /// for later use. + /// + /// This class also is the adaptation layer between the BrowserProcessService + /// and the registered objects. This means when the renderer wants to call an + /// exposed method, get a property of an object, or + /// set a property of an object in the browser process, that this + /// class does deals with the previously created meta-data and invokes the correct + /// behavior via reflection APIs. + /// + /// All of the registered objects are tracked via meta-data for the objects + /// expressed starting with the JavaScriptObject type. + /// public class JavascriptObjectRepository : DisposableResource { private static long lastId; private static readonly object Lock = new object(); + // A hash from assigned object ids to the objects, + // this is done to speed up finding the object in O(1) time + // instead of traversing the JavaScriptRootObject tree. private readonly Dictionary objects = new Dictionary(); + + // This is the root of the objects that get serialized to the child + // process. public JavascriptRootObject RootObject { get; private set; } public JavascriptObjectRepository()