Remove unused resultString param, CefJSDialogCallback->Continue is used for multiple callbacks, in this case only the success param is required.

Change isReload to a normal param (was an out param), so the user can be notified correctly
Add some rough documentation to IJsDialogHandlerAdd some additional comments to JsDialogHandler for demonstrating code to users

Add JsDialogHandler that implements the default behavior
Assign in the WinForms example

Fix typo in IRequestHandler
This commit is contained in:
amaitland
2015-01-11 13:45:27 +10:00
committed by Alex Maitland
parent a4cdd5b04a
commit fce5f06362
6 changed files with 52 additions and 7 deletions
+3 -5
View File
@@ -455,14 +455,12 @@ namespace CefSharp
return false;
}
bool result;
bool handled = false;
bool allowUnload;
String^ resultString = nullptr;
handled = handler->OnJSBeforeUnload(_browserControl, StringUtils::ToClr(message_text), is_reload, resultString);
auto handled = handler->OnJSBeforeUnload(_browserControl, StringUtils::ToClr(message_text), is_reload, allowUnload);
if (handled)
{
callback->Continue(result, StringUtils::ToNative(resultString));
callback->Continue(allowUnload, CefString());
}
return handled;
+1
View File
@@ -85,6 +85,7 @@
<ItemGroup>
<Compile Include="BoundObject.cs" />
<Compile Include="DragHandler.cs" />
<Compile Include="JsDialogHandler.cs" />
<Compile Include="SubBoundObject.cs" />
<Compile Include="TempFileDialogHandler.cs" />
<Compile Include="CefExample.cs" />
+34
View File
@@ -0,0 +1,34 @@
namespace CefSharp.Example
{
public class JsDialogHandler : IJsDialogHandler
{
public bool OnJSAlert(IWebBrowser browser, string url, string message)
{
return false;
}
public bool OnJSConfirm(IWebBrowser browser, string url, string message, out bool retval)
{
retval = false;
return false;
}
public bool OnJSPrompt(IWebBrowser browser, string url, string message, string defaultValue, out bool retval, out string result)
{
retval = false;
result = null;
return false;
}
public bool OnJSBeforeUnload(IWebBrowser browser, string message, bool isReload, out bool allowUnload)
{
//NOTE: Setting allowUnload to false will cancel the unload request
allowUnload = false;
//NOTE: Returning false will trigger the default behaviour, you need to return true to handle yourself.
return false;
}
}
}
@@ -25,6 +25,7 @@ namespace CefSharp.WinForms.Example
browser.MenuHandler = new MenuHandler();
browser.RequestHandler = new RequestHandler();
browser.JsDialogHandler = new JsDialogHandler();
//browser.FocusHandler = new FocusHandler(browser, urlTextBox);
browser.NavStateChanged += OnBrowserNavStateChanged;
browser.ConsoleMessage += OnBrowserConsoleMessage;
+12 -1
View File
@@ -9,6 +9,17 @@ namespace CefSharp
bool OnJSAlert(IWebBrowser browser, string url, string message);
bool OnJSConfirm(IWebBrowser browser, string url, string message, out bool retval);
bool OnJSPrompt(IWebBrowser browser, string url, string message, string defaultValue, out bool retval, out string result);
bool OnJSBeforeUnload(IWebBrowser browser, string message, out bool isReload, out string result);
/// <summary>
/// When leaving the page a Javascript dialog is displayed asking for user confirmation.
/// Returning True allows you to implement a custom dialog or programatically handle.
/// To cancel the unload return True and set allowUnload to False.
/// </summary>
/// <param name="browser">the browser object</param>
/// <param name="message">message (optional)</param>
/// <param name="isReload">indicates a page reload</param>
/// <param name="allowUnload">True to allow unload, otherwise False</param>
/// <returns>Return false to use the default dialog implementation otherwise return true to handle</returns>
bool OnJSBeforeUnload(IWebBrowser browser, string message, bool isReload, out bool allowUnload);
}
}
+1 -1
View File
@@ -40,7 +40,7 @@ namespace CefSharp
/// <param name="browser">the browser object</param>
/// <param name="request">the request object - can be modified in this callback.</param>
/// <param name="response">the request object - can be modified in this callback.</param>
/// <returns>To cancel loading of the resource return true or false o allow the resource to load normally.</returns>
/// <returns>To cancel loading of the resource return true or false to allow the resource to load normally.</returns>
bool OnBeforeResourceLoad(IWebBrowser browser, IRequest request, IResponse response);
/// <summary>