Skip to content

Commit

Permalink
Merge b059eb2 into 002edfb
Browse files Browse the repository at this point in the history
  • Loading branch information
slozier authored May 13, 2019
2 parents 002edfb + b059eb2 commit 67b6fdb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 24 deletions.
51 changes: 37 additions & 14 deletions CefSharp.Core/ManagedCefBrowserAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,42 @@ void ManagedCefBrowserAdapter::CreateBrowser(IWindowInfo^ windowInfo, BrowserSet
delete windowInfo;
}

// NOTE: This was moved out of OnAfterBrowserCreated to prevent the System.ServiceModel assembly from being loaded when WCF is not enabled.
__declspec(noinline) void ManagedCefBrowserAdapter::InitializeBrowserProcessServiceHost(IBrowser^ browser)
{
_browserProcessServiceHost = gcnew BrowserProcessServiceHost(_javaScriptObjectRepository, Process::GetCurrentProcess()->Id, browser->Identifier, _javascriptCallbackFactory);
//NOTE: Attempt to solve timing issue where browser is opened and rapidly disposed. In some cases a call to Open throws
// an exception about the process already being closed. Two relevant issues are #862 and #804.
if (_browserProcessServiceHost->State == CommunicationState::Created)
{
try
{
_browserProcessServiceHost->Open();
}
catch (Exception^)
{
//Ignore exception as it's likely cause when the browser is closing
}
}
}

// NOTE: This was moved out of ~ManagedCefBrowserAdapter to prevent the System.ServiceModel assembly from being loaded when WCF is not enabled.
__declspec(noinline) void ManagedCefBrowserAdapter::DisposeBrowserProcessServiceHost()
{
if (_browserProcessServiceHost != nullptr)
{
if (CefSharpSettings::WcfTimeout > TimeSpan::Zero)
{
_browserProcessServiceHost->Close(CefSharpSettings::WcfTimeout);
}
else
{
_browserProcessServiceHost->Abort();
}
_browserProcessServiceHost = nullptr;
}
}

void ManagedCefBrowserAdapter::OnAfterBrowserCreated(IBrowser^ browser)
{
if (!_isDisposed)
Expand All @@ -61,20 +97,7 @@ void ManagedCefBrowserAdapter::OnAfterBrowserCreated(IBrowser^ browser)

if (CefSharpSettings::WcfEnabled)
{
_browserProcessServiceHost = gcnew BrowserProcessServiceHost(_javaScriptObjectRepository, Process::GetCurrentProcess()->Id, browser->Identifier, _javascriptCallbackFactory);
//NOTE: Attempt to solve timing issue where browser is opened and rapidly disposed. In some cases a call to Open throws
// an exception about the process already being closed. Two relevant issues are #862 and #804.
if (_browserProcessServiceHost->State == CommunicationState::Created)
{
try
{
_browserProcessServiceHost->Open();
}
catch (Exception^)
{
//Ignore exception as it's likely cause when the browser is closing
}
}
InitializeBrowserProcessServiceHost(browser);
}

if (_webBrowserInternal != nullptr)
Expand Down
14 changes: 4 additions & 10 deletions CefSharp.Core/ManagedCefBrowserAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ namespace CefSharp

private:
void MethodInvocationComplete(Object^ sender, MethodInvocationCompleteArgs^ e);
void InitializeBrowserProcessServiceHost(IBrowser^ browser);
void DisposeBrowserProcessServiceHost();

internal:
MCefRefPtr<ClientAdapter> GetClientAdapter();
Expand Down Expand Up @@ -93,17 +95,9 @@ namespace CefSharp
_browserWrapper = nullptr;
}

if (CefSharpSettings::WcfEnabled && _browserProcessServiceHost != nullptr)
if (CefSharpSettings::WcfEnabled)
{
if (CefSharpSettings::WcfTimeout > TimeSpan::Zero)
{
_browserProcessServiceHost->Close(CefSharpSettings::WcfTimeout);
}
else
{
_browserProcessServiceHost->Abort();
}
_browserProcessServiceHost = nullptr;
DisposeBrowserProcessServiceHost();
}

_webBrowserInternal = nullptr;
Expand Down

0 comments on commit 67b6fdb

Please sign in to comment.