Пример #1
0
        bool IGeolocationHandler.OnRequestGeolocationPermission(IWebBrowser browserControl, IBrowser browser, string requestingUrl, int requestId, IGeolocationCallback callback)
        {
            //You can execute the callback inline
            //callback.Continue(true);
            //return true;

            //You can execute the callback in an `async` fashion
            //Open a message box on the `UI` thread and ask for user input.
            //You can open a form, or do whatever you like, just make sure you either
            //execute the callback or call `Dispose` as it's an `unmanaged` wrapper.
            var chromiumWebBrowser = (ChromiumWebBrowser)browserControl;
            chromiumWebBrowser.Dispatcher.BeginInvoke((Action)(() =>
            {
                //Callback wraps an unmanaged resource, so we'll make sure it's Disposed (calling Continue will also Dipose of the callback, it's safe to dispose multiple times).
                using (callback)
                {
                    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", MessageBoxButton.YesNo);

                    //Execute the callback, to allow/deny the request.
                    callback.Continue(result == MessageBoxResult.Yes);
                }
            }));

            //Yes we'd like to hadle this request ourselves.
            return true;
        }
Пример #2
0
        public bool OnRequestGeolocationPermission(IWebBrowser browserControl, IBrowser browser, string requestingUrl, int requestId, IGeolocationCallback callback)
        {
            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);
            
            callback.Continue(result == DialogResult.Yes);
            callback.Dispose();

            return result == DialogResult.Yes;
        }
Пример #3
0
        bool IGeolocationHandler.OnRequestGeolocationPermission(IWebBrowser browserControl, IBrowser browser, string requestingUrl, int requestId, IGeolocationCallback callback)
        {
            //The callback has been disposed, so we are unable to continue
            if(callback.IsDisposed)
            {
                return false;
            }

            using (callback)
            {
                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);

                callback.Continue(result == DialogResult.Yes);
                callback.Dispose();

                return result == DialogResult.Yes;
            }
        }
Пример #4
0
        public bool OnRequestGeolocationPermission(IWebBrowser browserControl, IBrowser browser, string requestingUrl, int requestId, IGeolocationCallback callback)
        {
            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);

            callback.Continue(result == DialogResult.Yes);
            callback.Dispose();

            return(result == DialogResult.Yes);
        }
        bool IGeolocationHandler.OnRequestGeolocationPermission(IWebBrowser browserControl, IBrowser browser, string requestingUrl, int requestId, IGeolocationCallback callback)
        {
            //The callback has been disposed, so we are unable to continue
            if (callback.IsDisposed)
            {
                return(false);
            }

            var control = (Control)browserControl;

            control.InvokeOnUiThreadIfRequired(delegate()
            {
                //Callback wraps a managed resource, so we'll wrap in a using statement so it's always disposed of.
                using (callback)
                {
                    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);

                    callback.Continue(result == DialogResult.Yes);
                }
            });

            //To cancel the request immediately we'd return false here, as we're returning true
            // the callback will be used to allow/deny the permission request.
            return(true);
        }
Пример #6
0
        bool IGeolocationHandler.OnRequestGeolocationPermission(IWebBrowser browserControl, IBrowser browser, string requestingUrl, int requestId, IGeolocationCallback callback)
        {
            //The callback has been disposed, so we are unable to continue
            if (callback.IsDisposed)
            {
                var handler = OnPermissionResult;
                handler?.Invoke(this, false);
                return(false);
            }

            var control = (Control)browserControl;

            control.InvokeOnUiThreadIfRequired(delegate {
                //Callback wraps a managed resource, so we'll wrap in a using statement so it's always disposed of.
                using (callback) {
                    var message = requestingUrl + "wants to use your computer's location.  Allow?";
                    var result  = MessageBox.Show(message, @"Geolocation", MessageBoxButtons.YesNo);
                    callback.Continue(result == DialogResult.Yes);
                    var handler = OnPermissionResult;
                    handler?.Invoke(this, result == DialogResult.Yes);
                }
            });

            //To cancel the request immediately we'd return false here, as we're returning true
            // the callback will be used to allow/deny the permission request.
            return(true);
        }
        bool IGeolocationHandler.OnRequestGeolocationPermission(IWebBrowser browserControl, IBrowser browser, string requestingUrl, int requestId, IGeolocationCallback callback)
        {
            //You can execute the callback inline
            //callback.Continue(true);
            //return true;

            //You can execute the callback in an `async` fashion
            //Open a message box on the `UI` thread and ask for user input.
            //You can open a form, or do whatever you like, just make sure you either
            //execute the callback or call `Dispose` as it's an `unmanaged` wrapper.
            var chromiumWebBrowser = (ChromiumWebBrowser)browserControl;

            chromiumWebBrowser.Dispatcher.BeginInvoke((Action)(() =>
            {
                //Callback wraps an unmanaged resource, so we'll make sure it's Disposed (calling Continue will also Dipose of the callback, it's safe to dispose multiple times).
                using (callback)
                {
                    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", MessageBoxButton.YesNo);

                    //Execute the callback, to allow/deny the request.
                    callback.Continue(result == MessageBoxResult.Yes);
                }
            }));

            //Yes we'd like to hadle this request ourselves.
            return(true);
        }
Пример #8
0
        bool IGeolocationHandler.OnRequestGeolocationPermission(IWebBrowser browserControl, IBrowser browser, string requestingUrl, int requestId, IGeolocationCallback callback)
        {
            //The callback has been disposed, so we are unable to continue
            if (callback.IsDisposed)
            {
                return(false);
            }

            using (callback)
            {
                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);

                callback.Continue(result == DialogResult.Yes);
                callback.Dispose();

                return(result == DialogResult.Yes);
            }
        }