Files
cefsharp/CefSharp.Core/Internals/JavascriptCallbackProxy.h
T
Alex Maitland b5a83f526e Enhancement - Pluggable Javascript Naming (#3141)
* Core - Move NameConverter to IJavascriptObjectRepository

- Move NameConverter property from BindingOptions to IJavascriptObjectRepository
- Remove BindingOptions.CamelCaseJavascriptNames

**Breaking Change**

Follow up to https://github.com/cefsharp/CefSharp/commit/898ca38e7a7261b3a42c33b2abf5eac6c022ddde

* Core - Javascript Binding Pluggable Naming Improvements

- Added some basic unit tests (more required)
- DefaultBinder now accepts a IJavascriptNameConverter passed into the constructor
  to allow for conversion of names

* Core - Replace WeakReference with WeakReference<T>
2020-07-27 20:13:16 +10:00

80 lines
2.5 KiB
C++

// 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->GetFrame(_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();
}
};
}
}