Skip to content

Commit 92a2a61

Browse files
committed
IGeolocationHandler.OnRequestGeolocationPermission - improve comment
GeolocationHandler Example - upgrade to properly use the callback.
1 parent 15b55a4 commit 92a2a61

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

CefSharp.WinForms.Example/Handlers/GeolocationHandler.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,22 @@ bool IGeolocationHandler.OnRequestGeolocationPermission(IWebBrowser browserContr
1717
return false;
1818
}
1919

20-
using (callback)
20+
var control = (Control)browserControl;
21+
22+
control.InvokeOnUiThreadIfRequired(delegate()
2123
{
22-
var result = MessageBox.Show(String.Format("{0} wants to use your computer's location. Allow? ** You must set your Google API key in CefExample.Init() for this to work. **", requestingUrl), "Geolocation", MessageBoxButtons.YesNo);
24+
//Callback wraps a managed resource, so we'll wrap in a using statement so it's always disposed of.
25+
using (callback)
26+
{
27+
var result = MessageBox.Show(string.Format("{0} wants to use your computer's location. Allow? ** You must set your Google API key in CefExample.Init() for this to work. **", requestingUrl), "Geolocation", MessageBoxButtons.YesNo);
2328

24-
callback.Continue(result == DialogResult.Yes);
25-
callback.Dispose();
29+
callback.Continue(result == DialogResult.Yes);
30+
}
31+
});
2632

27-
return result == DialogResult.Yes;
28-
}
33+
//To cancel the request immediately we'd return false here, as we're returning true
34+
// the callback will be used to allow/deny the permission request.
35+
return true;
2936
}
3037

3138
void IGeolocationHandler.OnCancelGeolocationPermission(IWebBrowser browserControl, IBrowser browser, int requestId)

CefSharp/IGeolocationHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public interface IGeolocationHandler
1818
/// <param name="requestingUrl">the URL requesting permission</param>
1919
/// <param name="requestId">the unique ID for the permission request</param>
2020
/// <param name="callback">Callback interface used for asynchronous continuation of geolocation permission requests.</param>
21-
/// <returns>true to allow the request and false to deny</returns>
21+
/// <returns>Return true and call IGeolocationCallback.Continue() either in this method or at a later time to continue or cancel the request. Return false to cancel the request immediately.</returns>
2222
bool OnRequestGeolocationPermission(IWebBrowser browserControl, IBrowser browser, string requestingUrl, int requestId, IGeolocationCallback callback);
2323

2424
/// <summary>

0 commit comments

Comments
 (0)