-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JavascriptCallbackProxy.h
79 lines (66 loc) · 2.58 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// 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 "Stdafx.h"
#include "include/cef_app.h"
#include "..\ManagedCefBrowserAdapter.h"
#include "Internals\CefBrowserWrapper.h"
using namespace System::Threading::Tasks;
using namespace CefSharp::JavascriptBinding;
namespace CefSharp
{
namespace Internals
{
private ref class JavascriptCallbackProxy : public IJavascriptCallback
{
private:
WeakReference<IBrowserAdapter^>^ _browserAdapter;
JavascriptCallback^ _callback;
PendingTaskRepository<JavascriptResponse^>^ _pendingTasks;
bool _disposed;
CefRefPtr<CefProcessMessage> CreateDestroyMessage();
IBrowser^ GetBrowser();
IJavascriptNameConverter^ GetJavascriptNameConverter();
void DisposedGuard();
public:
JavascriptCallbackProxy(JavascriptCallback^ callback, PendingTaskRepository<JavascriptResponse^>^ pendingTasks, WeakReference<IBrowserAdapter^>^ browserAdapter)
:_callback(callback), _pendingTasks(pendingTasks), _disposed(false)
{
_browserAdapter = browserAdapter;
}
~JavascriptCallbackProxy()
{
this->!JavascriptCallbackProxy();
}
!JavascriptCallbackProxy()
{
auto browser = GetBrowser();
if (browser != nullptr && !browser->IsDisposed)
{
auto browserWrapper = static_cast<CefBrowserWrapper^>(browser)->Browser;
auto frame = browserWrapper->GetFrameByIdentifier(StringUtils::ToNative(_callback->FrameId));
if (frame.get() && frame->IsValid())
{
frame->SendProcessMessage(CefProcessId::PID_RENDERER, CreateDestroyMessage());
}
}
_disposed = true;
}
virtual Task<JavascriptResponse^>^ ExecuteAsync(cli::array<Object^>^ parameters);
virtual Task<JavascriptResponse^>^ ExecuteWithTimeoutAsync(Nullable<TimeSpan> timeout, cli::array<Object^>^ parameters);
virtual property Int64 Id
{
Int64 get();
}
virtual property bool IsDisposed
{
bool get();
}
virtual property bool CanExecute
{
bool get();
}
};
}
}