How can I get the HTML5 GeoLocation feature to work on GeckoFX v22 web browser control for WinForms using C#?

瘦欲@ 提交于 2019-12-10 21:50:34

问题


I wanted to implement a web browser control to Geo-location enable my WinForm desktop application.

I have successfully implemented the GeckoFX web browser in my WinForm project. The problem is when visiting a HTML5 Gelocation enabled website/address the "Allow/Deny access" popup does not appear.

As a result the Geo-location does not work. I have confirmed that Geo-location is enabled in preferences and have tested my WinForm using http://html5test.com and the control is listed as supporting Geo-location.

I have already tried to set permissions via the XPCom API for a specific domain so that the pop-up asking for permission would not be needed:

   //CREATE nsSTRING
            nsAUTF8String i = new nsAUTF8String("http://html5demos.com");

            //CREATE NEW URI
            var nsII = Xpcom.CreateInstance<nsIIOService>("@mozilla.org/network/io-service;1");
            nsIURI uri = nsII.NewURI(i, "Unicode", null);

            //CREATE PERMISSION MANAGER
            var instancePM = Xpcom.CreateInstance<nsIPermissionManager>("@mozilla.org/permissionmanager;1");

            //GEO PERMISSION SETTINGS
            uint permission = Convert.ToUInt32(1);
            uint expiretype = Convert.ToUInt32(0);
            long expireTime = (long)0;

            //ADD GEO PERMISSION SETTINGS  (THIS SHOULD ALLOW GEO LOCATION TO JUST RUN WITH NO PROMPT)
            instancePM.Add(uri, "geo", permission, expiretype, expireTime);

            //TEST PERMISSIONS http://html5demos.com 
            uint testResult = instancePM.TestExactPermission(uri, "geo"); //RETURN SCORRECT SETTING OF 1 = OK

This did return a tested value of 1 but still the Geo-location does not work.

I have already seen this stackoverflow question: Gecko for windows forms and geolocation. How to accept request for share my location?, but not really sure where to go from there.

I am sure I need to implement the call myself as the control is just the browser window and not all the other bits n bobs that make up a browser application. Does anyone have any suggestions or perhaps have already implemented Geo-location in GeckoFX using WinForms and C#?

Thanks Andre

来源:https://stackoverflow.com/questions/19348509/how-can-i-get-the-html5-geolocation-feature-to-work-on-geckofx-v22-web-browser-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!