Skip to content

Commit 67b6fdb

Browse files
authored
Merge b059eb2 into 002edfb
2 parents 002edfb + b059eb2 commit 67b6fdb

2 files changed

Lines changed: 41 additions & 24 deletions

File tree

‎CefSharp.Core/ManagedCefBrowserAdapter.cpp‎

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,42 @@ void ManagedCefBrowserAdapter::CreateBrowser(IWindowInfo^ windowInfo, BrowserSet
4949
delete windowInfo;
5050
}
5151

52+
// NOTE: This was moved out of OnAfterBrowserCreated to prevent the System.ServiceModel assembly from being loaded when WCF is not enabled.
53+
__declspec(noinline) void ManagedCefBrowserAdapter::InitializeBrowserProcessServiceHost(IBrowser^ browser)
54+
{
55+
_browserProcessServiceHost = gcnew BrowserProcessServiceHost(_javaScriptObjectRepository, Process::GetCurrentProcess()->Id, browser->Identifier, _javascriptCallbackFactory);
56+
//NOTE: Attempt to solve timing issue where browser is opened and rapidly disposed. In some cases a call to Open throws
57+
// an exception about the process already being closed. Two relevant issues are #862 and #804.
58+
if (_browserProcessServiceHost->State == CommunicationState::Created)
59+
{
60+
try
61+
{
62+
_browserProcessServiceHost->Open();
63+
}
64+
catch (Exception^)
65+
{
66+
//Ignore exception as it's likely cause when the browser is closing
67+
}
68+
}
69+
}
70+
71+
// NOTE: This was moved out of ~ManagedCefBrowserAdapter to prevent the System.ServiceModel assembly from being loaded when WCF is not enabled.
72+
__declspec(noinline) void ManagedCefBrowserAdapter::DisposeBrowserProcessServiceHost()
73+
{
74+
if (_browserProcessServiceHost != nullptr)
75+
{
76+
if (CefSharpSettings::WcfTimeout > TimeSpan::Zero)
77+
{
78+
_browserProcessServiceHost->Close(CefSharpSettings::WcfTimeout);
79+
}
80+
else
81+
{
82+
_browserProcessServiceHost->Abort();
83+
}
84+
_browserProcessServiceHost = nullptr;
85+
}
86+
}
87+
5288
void ManagedCefBrowserAdapter::OnAfterBrowserCreated(IBrowser^ browser)
5389
{
5490
if (!_isDisposed)
@@ -61,20 +97,7 @@ void ManagedCefBrowserAdapter::OnAfterBrowserCreated(IBrowser^ browser)
6197

6298
if (CefSharpSettings::WcfEnabled)
6399
{
64-
_browserProcessServiceHost = gcnew BrowserProcessServiceHost(_javaScriptObjectRepository, Process::GetCurrentProcess()->Id, browser->Identifier, _javascriptCallbackFactory);
65-
//NOTE: Attempt to solve timing issue where browser is opened and rapidly disposed. In some cases a call to Open throws
66-
// an exception about the process already being closed. Two relevant issues are #862 and #804.
67-
if (_browserProcessServiceHost->State == CommunicationState::Created)
68-
{
69-
try
70-
{
71-
_browserProcessServiceHost->Open();
72-
}
73-
catch (Exception^)
74-
{
75-
//Ignore exception as it's likely cause when the browser is closing
76-
}
77-
}
100+
InitializeBrowserProcessServiceHost(browser);
78101
}
79102

80103
if (_webBrowserInternal != nullptr)

‎CefSharp.Core/ManagedCefBrowserAdapter.h‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ namespace CefSharp
3939

4040
private:
4141
void MethodInvocationComplete(Object^ sender, MethodInvocationCompleteArgs^ e);
42+
void InitializeBrowserProcessServiceHost(IBrowser^ browser);
43+
void DisposeBrowserProcessServiceHost();
4244

4345
internal:
4446
MCefRefPtr<ClientAdapter> GetClientAdapter();
@@ -93,17 +95,9 @@ namespace CefSharp
9395
_browserWrapper = nullptr;
9496
}
9597

96-
if (CefSharpSettings::WcfEnabled && _browserProcessServiceHost != nullptr)
98+
if (CefSharpSettings::WcfEnabled)
9799
{
98-
if (CefSharpSettings::WcfTimeout > TimeSpan::Zero)
99-
{
100-
_browserProcessServiceHost->Close(CefSharpSettings::WcfTimeout);
101-
}
102-
else
103-
{
104-
_browserProcessServiceHost->Abort();
105-
}
106-
_browserProcessServiceHost = nullptr;
100+
DisposeBrowserProcessServiceHost();
107101
}
108102

109103
_webBrowserInternal = nullptr;

0 commit comments

Comments
 (0)