-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
CefAppUnmanagedWrapper.h
90 lines (75 loc) · 4.36 KB
/
CefAppUnmanagedWrapper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// 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 "Stdafx.h"
#include "include/cef_base.h"
#include "SubProcessApp.h"
#include "CefBrowserWrapper.h"
#include "RegisterBoundObjectRegistry.h"
using namespace System::Collections::Generic;
using namespace CefSharp::RenderProcess;
namespace CefSharp
{
namespace BrowserSubprocess
{
// This class is the native subprocess level CEF object wrapper.
private class CefAppUnmanagedWrapper : SubProcessApp, CefRenderProcessHandler
{
private:
gcroot<IRenderProcessHandler^> _handler;
gcroot<Action<CefBrowserWrapper^>^> _onBrowserCreated;
gcroot<Action<CefBrowserWrapper^>^> _onBrowserDestroyed;
gcroot<ConcurrentDictionary<int, CefBrowserWrapper^>^> _browserWrappers;
bool _focusedNodeChangedEnabled;
bool _legacyBindingEnabled;
bool _jsBindingApiEnabled = true;
// The property names used to call bound objects
CefString _jsBindingPropertyName;
CefString _jsBindingPropertyNameCamelCase;
// The serialized registered object data waiting to be used.
gcroot<Dictionary<String^, JavascriptObject^>^> _javascriptObjects;
gcroot<RegisterBoundObjectRegistry^> _registerBoundObjectRegistry;
public:
static const CefString kPromiseCreatorScript;
CefAppUnmanagedWrapper(IRenderProcessHandler^ handler, List<CefCustomScheme^>^ schemes, bool enableFocusedNodeChanged, Action<CefBrowserWrapper^>^ onBrowserCreated, Action<CefBrowserWrapper^>^ onBrowserDestroyed) : SubProcessApp(schemes)
{
_handler = handler;
_onBrowserCreated = onBrowserCreated;
_onBrowserDestroyed = onBrowserDestroyed;
_browserWrappers = gcnew ConcurrentDictionary<int, CefBrowserWrapper^>();
_focusedNodeChangedEnabled = enableFocusedNodeChanged;
_javascriptObjects = gcnew Dictionary<String^, JavascriptObject^>();
_registerBoundObjectRegistry = gcnew RegisterBoundObjectRegistry();
_legacyBindingEnabled = false;
_jsBindingPropertyName = "CefSharp";
_jsBindingPropertyNameCamelCase = "cefSharp";
}
~CefAppUnmanagedWrapper()
{
if (!Object::ReferenceEquals(_browserWrappers, nullptr))
{
for each (CefBrowserWrapper ^ browser in Enumerable::OfType<CefBrowserWrapper^>(_browserWrappers))
{
delete browser;
}
_browserWrappers = nullptr;
}
delete _onBrowserCreated;
delete _onBrowserDestroyed;
}
CefBrowserWrapper^ FindBrowserWrapper(int browserId);
JavascriptRootObjectWrapper^ GetJsRootObjectWrapper(int browserId, CefString& frameId);
virtual DECL CefRefPtr<CefRenderProcessHandler> GetRenderProcessHandler() override;
virtual DECL void OnBrowserCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefDictionaryValue> extraInfo) override;
virtual DECL void OnBrowserDestroyed(CefRefPtr<CefBrowser> browser) override;
virtual DECL void OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context) override;
virtual DECL void OnContextReleased(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context) override;
virtual DECL bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefProcessId sourceProcessId, CefRefPtr<CefProcessMessage> message) override;
virtual DECL void OnWebKitInitialized() override;
virtual DECL void OnFocusedNodeChanged(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefDOMNode> node) override;
virtual DECL void OnUncaughtException(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context, CefRefPtr<CefV8Exception> exception, CefRefPtr<CefV8StackTrace> stackTrace) override;
IMPLEMENT_REFCOUNTINGM(CefAppUnmanagedWrapper);
};
}
}