forked from cefsharp/CefSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JavascriptCallbackProxy.h
62 lines (51 loc) · 1.89 KB
/
JavascriptCallbackProxy.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
// Copyright © 2010-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 "Stdafx.h"
#include "include/cef_app.h"
#include "..\ManagedCefBrowserAdapter.h"
#include "Internals\CefSharpBrowserWrapper.h"
using namespace System::Threading::Tasks;
namespace CefSharp
{
namespace Internals
{
private ref class JavascriptCallbackProxy : public IJavascriptCallback
{
private:
WeakReference^ _browserAdapter;
JavascriptCallback^ _callback;
PendingTaskRepository<JavascriptResponse^>^ _pendingTasks;
bool _disposed;
CefRefPtr<CefProcessMessage> CreateDestroyMessage();
IBrowser^ GetBrowser();
void DisposedGuard();
public:
JavascriptCallbackProxy(JavascriptCallback^ callback, PendingTaskRepository<JavascriptResponse^>^ pendingTasks, WeakReference^ browserAdapter)
:_callback(callback), _pendingTasks(pendingTasks)
{
_browserAdapter = browserAdapter;
}
~JavascriptCallbackProxy()
{
this->!JavascriptCallbackProxy();
}
!JavascriptCallbackProxy()
{
auto browser = GetBrowser();
if (browser != nullptr && !browser->IsDisposed)
{
auto browserWrapper = static_cast<CefSharpBrowserWrapper^>(browser);
browserWrapper->SendProcessMessage(CefProcessId::PID_RENDERER, CreateDestroyMessage());
}
_disposed = true;
}
virtual Task<JavascriptResponse^>^ ExecuteAsync(cli::array<Object^>^ parameters);
virtual property bool IsDisposed
{
bool get();
}
};
}
}