admin
2020-06-10 a610f2ab6e543d2cb78c1ef212ac6a74ddc067d9
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
// Copyright © 2015 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 "JavascriptCallbackWrapper.h"
 
using namespace System::Collections::Concurrent;
 
namespace CefSharp
{
    namespace Internals
    {
        private ref class JavascriptCallbackRegistry
        {
        private:
            //Only access through Interlocked::Increment - used to generate unique callback Id's
            //Is static so ids are unique to this process, which is required until #1984 is implemented
            //and callbacks are disposed of properly between contexts
            static Int64 _lastId;
            int _browserId;
            ConcurrentDictionary<Int64, JavascriptCallbackWrapper^>^ _callbacks;
 
        internal:
            JavascriptCallbackWrapper^ FindWrapper(int64 id);
 
        public:
            JavascriptCallbackRegistry(int browserId) : _browserId(browserId)
            {
                _callbacks = gcnew ConcurrentDictionary<Int64, JavascriptCallbackWrapper^>();
            }
 
            ~JavascriptCallbackRegistry()
            {
                if (_callbacks != nullptr)
                {
                    for each (JavascriptCallbackWrapper^ callback in _callbacks->Values)
                    {
                        delete callback;
                    }
                    _callbacks->Clear();
                    _callbacks = nullptr;
                }
            }
 
            JavascriptCallback^ Register(const CefRefPtr<CefV8Context>& context, const CefRefPtr<CefV8Value>& value);
 
            void Deregister(Int64 id);
        };
    }
}