2014-08-29 10:53:50 +10:00
|
|
|
// Copyright © 2010-2014 The CefSharp Project. 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 "CefAppWrapper.h"
|
2014-09-12 00:40:33 +10:00
|
|
|
#include "CefBrowserWrapper.h"
|
2014-08-29 10:53:50 +10:00
|
|
|
#include "CefAppUnmanagedWrapper.h"
|
|
|
|
|
|
|
|
|
|
using namespace System;
|
|
|
|
|
using namespace System::Diagnostics;
|
|
|
|
|
using namespace System::Collections::Generic;
|
|
|
|
|
|
|
|
|
|
namespace CefSharp
|
|
|
|
|
{
|
|
|
|
|
CefRefPtr<CefRenderProcessHandler> CefAppUnmanagedWrapper::GetRenderProcessHandler()
|
|
|
|
|
{
|
|
|
|
|
return this;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// CefRenderProcessHandler
|
|
|
|
|
void CefAppUnmanagedWrapper::OnBrowserCreated(CefRefPtr<CefBrowser> browser)
|
|
|
|
|
{
|
|
|
|
|
auto wrapper = gcnew CefBrowserWrapper(browser);
|
2014-09-12 13:03:25 +10:00
|
|
|
_browserWrapper = wrapper;
|
2014-08-29 10:53:50 +10:00
|
|
|
_onBrowserCreated->Invoke(wrapper);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CefAppUnmanagedWrapper::OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context)
|
|
|
|
|
{
|
|
|
|
|
auto window = context->GetGlobal();
|
|
|
|
|
|
|
|
|
|
JavascriptRootObjectWrapper^ jswindow = _windowObject;
|
|
|
|
|
|
|
|
|
|
if (jswindow != nullptr)
|
|
|
|
|
{
|
|
|
|
|
jswindow->V8Value = window;
|
|
|
|
|
jswindow->Bind();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void CefAppUnmanagedWrapper::OnBrowserDestroyed(CefRefPtr<CefBrowser> browser)
|
|
|
|
|
{
|
2014-09-12 14:52:01 +10:00
|
|
|
_onBrowserDestroyed->Invoke(_browserWrapper);
|
|
|
|
|
|
2014-09-12 13:03:25 +10:00
|
|
|
if (!Object::ReferenceEquals(_browserWrapper, nullptr))
|
2014-08-29 10:53:50 +10:00
|
|
|
{
|
2014-09-12 13:03:25 +10:00
|
|
|
delete _browserWrapper;
|
|
|
|
|
_browserWrapper = nullptr;
|
2014-08-29 10:53:50 +10:00
|
|
|
}
|
|
|
|
|
};
|
2014-09-12 12:48:10 +10:00
|
|
|
|
|
|
|
|
void CefAppUnmanagedWrapper::Bind(JavascriptRootObject^ rootObject)
|
|
|
|
|
{
|
|
|
|
|
_windowObject = gcnew JavascriptRootObjectWrapper(rootObject);
|
|
|
|
|
};
|
2014-08-29 10:53:50 +10:00
|
|
|
}
|