// 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^ _pendingTasks; bool _disposed; CefRefPtr CreateDestroyMessage(); IBrowser^ GetBrowser(); void DisposedGuard(); public: JavascriptCallbackProxy(JavascriptCallback^ callback, PendingTaskRepository^ 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(browser); browserWrapper->SendProcessMessage(CefProcessId::PID_RENDERER, CreateDestroyMessage()); } _disposed = true; } virtual Task^ ExecuteAsync(cli::array^ parameters); virtual property bool IsDisposed { bool get(); } virtual property bool CanExecute { bool get(); } }; } }