mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-04 10:22:55 +00:00
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:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user