WPF/WinForms/OffScreen - CanExecuteJavascriptInMainFrame incorrectly false after loading page with different origin

Proof of concept for a workaround. The frameId for the second OnContextReleased that arrives after the OnContextCreated from
the old render process strangely has a frameId greater than the new frameId

TODO: Unit tests

Issue #3021
This commit is contained in:
amaitland
2020-05-04 12:34:47 +10:00
parent 71a190dfe6
commit 1824a0334d
5 changed files with 60 additions and 6 deletions
+2 -2
View File
@@ -1048,7 +1048,7 @@ namespace CefSharp
{
if (frame->IsMain())
{
_browserControl->SetCanExecuteJavascriptOnMainFrame(true);
_browserControl->SetCanExecuteJavascriptOnMainFrame(frame->GetIdentifier(), true);
}
auto handler = _browserControl->RenderProcessMessageHandler;
@@ -1072,7 +1072,7 @@ namespace CefSharp
{
if (frame->IsMain())
{
_browserControl->SetCanExecuteJavascriptOnMainFrame(false);
_browserControl->SetCanExecuteJavascriptOnMainFrame(frame->GetIdentifier(), false);
}
auto handler = _browserControl->RenderProcessMessageHandler;
+19 -1
View File
@@ -50,6 +50,11 @@ namespace CefSharp.OffScreen
/// </summary>
private int disposeSignaled;
/// <summary>
/// Used as workaround for issue https://github.com/cefsharp/CefSharp/issues/3021
/// </summary>
private long canExecuteJavascriptInMainFrameId;
/// <summary>
/// Gets a value indicating whether this instance is disposed.
/// </summary>
@@ -906,8 +911,21 @@ namespace CefSharp.OffScreen
TooltipText = tooltipText;
}
void IWebBrowserInternal.SetCanExecuteJavascriptOnMainFrame(bool canExecute)
void IWebBrowserInternal.SetCanExecuteJavascriptOnMainFrame(long frameId, bool canExecute)
{
//When loading pages of a different origin the frameId changes
//For the first loading of a new origin the messages from the render process
//Arrive in a different order than expected, the OnContextCreated message
//arrives before the OnContextReleased, then the message for OnContextReleased
//incorrectly overrides the value
//https://github.com/cefsharp/CefSharp/issues/3021
if (frameId > canExecuteJavascriptInMainFrameId && !canExecute)
{
return;
}
canExecuteJavascriptInMainFrameId = frameId;
CanExecuteJavascriptInMainFrame = canExecute;
}
+19 -1
View File
@@ -87,6 +87,11 @@ namespace CefSharp.WinForms
/// </summary>
private Control parkingControl;
/// <summary>
/// Used as workaround for issue https://github.com/cefsharp/CefSharp/issues/3021
/// </summary>
private long canExecuteJavascriptInMainFrameId;
/// <summary>
/// Gets a value indicating whether this instance is disposed.
/// </summary>
@@ -909,8 +914,21 @@ namespace CefSharp.WinForms
}
}
void IWebBrowserInternal.SetCanExecuteJavascriptOnMainFrame(bool canExecute)
void IWebBrowserInternal.SetCanExecuteJavascriptOnMainFrame(long frameId, bool canExecute)
{
//When loading pages of a different origin the frameId changes
//For the first loading of a new origin the messages from the render process
//Arrive in a different order than expected, the OnContextCreated message
//arrives before the OnContextReleased, then the message for OnContextReleased
//incorrectly overrides the value
//https://github.com/cefsharp/CefSharp/issues/3021
if (frameId > canExecuteJavascriptInMainFrameId && !canExecute)
{
return;
}
canExecuteJavascriptInMainFrameId = frameId;
CanExecuteJavascriptInMainFrame = canExecute;
}
+19 -1
View File
@@ -146,6 +146,11 @@ namespace CefSharp.Wpf
/// </summary>
private int disposeSignaled;
/// <summary>
/// Used as workaround for issue https://github.com/cefsharp/CefSharp/issues/3021
/// </summary>
private long canExecuteJavascriptInMainFrameId;
/// <summary>
/// Gets a value indicating whether this instance is disposed.
/// </summary>
@@ -1251,8 +1256,21 @@ namespace CefSharp.Wpf
LoadError?.Invoke(this, args);
}
void IWebBrowserInternal.SetCanExecuteJavascriptOnMainFrame(bool canExecute)
void IWebBrowserInternal.SetCanExecuteJavascriptOnMainFrame(long frameId, bool canExecute)
{
//When loading pages of a different origin the frameId changes
//For the first loading of a new origin the messages from the render process
//Arrive in a different order than expected, the OnContextCreated message
//arrives before the OnContextReleased, then the message for OnContextReleased
//incorrectly overrides the value
//https://github.com/cefsharp/CefSharp/issues/3021
if (frameId > canExecuteJavascriptInMainFrameId && !canExecute)
{
return;
}
canExecuteJavascriptInMainFrameId = frameId;
CanExecuteJavascriptInMainFrame = canExecute;
}
+1 -1
View File
@@ -16,7 +16,7 @@ namespace CefSharp.Internals
void SetLoadingStateChange(LoadingStateChangedEventArgs args);
void SetTitle(TitleChangedEventArgs args);
void SetTooltipText(string tooltipText);
void SetCanExecuteJavascriptOnMainFrame(bool canExecute);
void SetCanExecuteJavascriptOnMainFrame(long frameId, bool canExecute);
void SetJavascriptMessageReceived(JavascriptMessageReceivedEventArgs args);
void OnFrameLoadStart(FrameLoadStartEventArgs args);