Skip to content

Commit 571a1db

Browse files
committed
Core - Further migration of extensions methods from IWebBrowser to IChromiumWebBrowserBase
- EvaluateScriptAsync can now be used from IChromiumWebBrowserBase, if also IWebBrowser then main frame check will occur as previous. Related to #3944
1 parent 288825d commit 571a1db

File tree

4 files changed

+14
-21
lines changed

4 files changed

+14
-21
lines changed

CefSharp.Core/WebBrowserExtensionsEx.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static class WebBrowserExtensionsEx
2323
/// <returns>
2424
/// <see cref="Task{NavigationEntry}"/> that when executed returns the current <see cref="NavigationEntry"/> or null
2525
/// </returns>
26-
public static Task<NavigationEntry> GetVisibleNavigationEntryAsync(this IWebBrowser browser)
26+
public static Task<NavigationEntry> GetVisibleNavigationEntryAsync(this IChromiumWebBrowserBase browser)
2727
{
2828
var host = browser.GetBrowserHost();
2929

CefSharp.Example/DevTools/DevToolsExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public static class DevToolsExtensions
1212
/// </summary>
1313
/// <param name="browser">the ChromiumWebBrowser</param>
1414
/// <returns>png encoded image as byte[]</returns>
15-
public static async Task<byte[]> CaptureScreenShotAsPng(this IWebBrowser chromiumWebBrowser)
15+
public static async Task<byte[]> CaptureScreenShotAsPng(this IChromiumWebBrowserBase chromiumWebBrowser)
1616
{
1717
//Make sure to dispose of our observer registration when done
1818
//If you need to make multiple calls then reuse the devtools client

CefSharp.WinForms/WebBrowserExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static class WebBrowserExtensions
2323
/// This will avoid the WM_Close message that CEF sends by default to the top level window.
2424
/// (Which closes your application). This method should generally only be used in the WinForms version.
2525
/// </summary>
26-
/// <param name="chromiumWebBrowser">the ChromiumWebBrowser instance</param>
26+
/// <param name="chromiumWebBrowser">the <see cref="ChromiumWebBrowser"/> or <see cref="ChromiumHostControl"/> instance.</param>
2727
/// <returns>If the function succeeds, the return value is true.</returns>
2828
/// <example>
2929
/// <code>
@@ -34,7 +34,7 @@ public static class WebBrowserExtensions
3434
/// });
3535
/// </code>
3636
/// </example>
37-
public static bool DestroyWindow(this IWebBrowser chromiumWebBrowser)
37+
public static bool DestroyWindow(this IChromiumWebBrowserBase chromiumWebBrowser)
3838
{
3939
if (!Cef.CurrentlyOnThread(CefThreadIds.TID_UI))
4040
{

CefSharp/WebBrowserExtensions.cs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,26 +1369,19 @@ private static string GetPromiseHandlerScript(string script, string javascriptBi
13691369
/// When false don't include a return statement e.g. 42;
13701370
/// </param>
13711371
/// <returns>
1372-
/// <see cref="Task{JavascriptResponse}"/> that can be awaited to perform the script execution.
1372+
/// <see cref="Task{JavascriptResponse}"/> that can be awaited to obtain the result of the script execution.
13731373
/// </returns>
1374-
public static Task<JavascriptResponse> EvaluateScriptAsync(this IWebBrowser browser, string script, TimeSpan? timeout = null, bool useImmediatelyInvokedFuncExpression = false)
1374+
public static Task<JavascriptResponse> EvaluateScriptAsync(this IChromiumWebBrowserBase browser, string script, TimeSpan? timeout = null, bool useImmediatelyInvokedFuncExpression = false)
13751375
{
1376-
if (timeout.HasValue && timeout.Value.TotalMilliseconds > UInt32.MaxValue)
1377-
{
1378-
throw new ArgumentOutOfRangeException("timeout", "Timeout greater than Maximum allowable value of " + UInt32.MaxValue);
1379-
}
1380-
1381-
if (browser.CanExecuteJavascriptInMainFrame == false)
1376+
if (browser is IWebBrowser b)
13821377
{
1383-
ThrowExceptionIfCanExecuteJavascriptInMainFrameFalse();
1378+
if (b.CanExecuteJavascriptInMainFrame == false)
1379+
{
1380+
ThrowExceptionIfCanExecuteJavascriptInMainFrameFalse();
1381+
}
13841382
}
13851383

1386-
using (var frame = browser.GetMainFrame())
1387-
{
1388-
ThrowExceptionIfFrameNull(frame);
1389-
1390-
return frame.EvaluateScriptAsync(script, timeout: timeout, useImmediatelyInvokedFuncExpression: useImmediatelyInvokedFuncExpression);
1391-
}
1384+
return browser.BrowserCore.EvaluateScriptAsync(script, timeout, useImmediatelyInvokedFuncExpression);
13921385
}
13931386

13941387
/// <summary>
@@ -1404,7 +1397,7 @@ public static Task<JavascriptResponse> EvaluateScriptAsync(this IWebBrowser brow
14041397
/// When false don't include a return statement e.g. 42;
14051398
/// </param>
14061399
/// <returns>
1407-
/// <see cref="Task{JavascriptResponse}"/> that can be awaited to perform the script execution.
1400+
/// <see cref="Task{JavascriptResponse}"/> that can be awaited to obtain the result of the script execution.
14081401
/// </returns>
14091402
public static Task<JavascriptResponse> EvaluateScriptAsync(this IBrowser browser, string script, TimeSpan? timeout = null, bool useImmediatelyInvokedFuncExpression = false)
14101403
{
@@ -1432,7 +1425,7 @@ public static Task<JavascriptResponse> EvaluateScriptAsync(this IBrowser browser
14321425
/// <param name="methodName">The javascript method name to execute.</param>
14331426
/// <param name="args">the arguments to be passed as params to the method.</param>
14341427
/// <returns>
1435-
/// <see cref="Task{JavascriptResponse}"/> that can be awaited to perform the script execution.
1428+
/// <see cref="Task{JavascriptResponse}"/> that can be awaited to obtain the result of the script execution.
14361429
/// </returns>
14371430
public static Task<JavascriptResponse> EvaluateScriptAsync(this IChromiumWebBrowserBase browser, string methodName, params object[] args)
14381431
{

0 commit comments

Comments
 (0)