public static void TriggerCallback(string json) { if (_callback != null) { _callback(PermissionRequestResult.FromJson(Json.Deserialize(json) as Dictionary <string, object>)); } }
static AccessState FromResult(PermissionRequestResult results, LocationPermissionType locType) { AccessState status; var coarse = results.IsGranted(P.AccessCoarseLocation); if (locType != LocationPermissionType.Coarse) { var fine = results.IsGranted(P.AccessFineLocation); if (!coarse && !fine) { status = AccessState.Denied; } else if (fine) { status = AccessState.Available; } else if (locType == LocationPermissionType.FineRequired) { status = AccessState.Denied; } else { status = AccessState.Restricted; } } else { status = coarse ? AccessState.Available : AccessState.Denied; } return(status); }
public static PermissionRequestResult FromJson(Dictionary <string, object> serialized) { var result = new PermissionRequestResult { Permission = serialized.GetStr("permission"), ShouldShowRequestPermissionRationale = (bool)serialized["shouldShowRequestPermissionRationale"], Status = (PermissionStatus)(int)(long)serialized["result"] }; return(result); }
public static void OnRequestPermissionsResult(string message) { if (_onRequestPermissionsResults != null) { var dic = Json.Deserialize(message) as Dictionary <string, object>; var resultsArr = dic["result"] as List <object>; var permissionResults = new PermissionRequestResult[resultsArr.Count]; for (int i = 0; i < resultsArr.Count; i++) { var parsed = PermissionRequestResult.FromJson(resultsArr[i] as Dictionary <string, object>); permissionResults[i] = parsed; } _onRequestPermissionsResults(permissionResults); _onRequestPermissionsResults = null; } }
// ReSharper disable once InconsistentNaming // ReSharper disable once UnusedMember.Local void onRequestPermissionsResults(AndroidJavaObject results) { int size = results.CallInt("size"); var requestResults = new PermissionRequestResult[size]; for (int i = 0; i < size; i++) { var resultAJO = results.CallAJO("get", i); string permission = resultAJO.CallStr("getPermission"); bool shouldShowRequestPermissionRationale = resultAJO.CallBool("isShouldShowRequestPermissionRationale"); var status = (PermissionStatus)resultAJO.CallInt("getResult"); requestResults[i] = new PermissionRequestResult(permission, shouldShowRequestPermissionRationale, status); } if (_onResult != null) { GoodiesSceneHelper.Queue(() => _onResult(requestResults)); } results.Dispose(); }
/// <summary> /// Default entry into managed code. /// </summary> /// <param name="__dirname">The directory name of the current module. This the same as the path.dirname() of the __filename.</param> /// <returns></returns> public async Task <object> Invoke(string __dirname) { if (console == null) { console = await WebSharpJs.NodeJS.Console.Instance(); } try { app = await App.Instance(); // We use app.IsReady instead of listening for the 'ready'event. // By the time we get here from the main.js module the 'ready' event has // already fired. if (await app.IsReady()) { windowId = await CreateWindow(__dirname); // Get our session try { session = await Session.FromPartition("partition:nameofpartition"); } catch (Exception sexc) { await console.Log($"logging: {sexc.Message}"); var web = await mainWindow.GetWebContents(); session = await web.GetSession(); } if (session != null) { await session.SetPermissionRequestHandler( new ScriptObjectCallback <WebContents, string, Func <object, Task <object> > >( async(callbackResult) => { var permissionResult = new PermissionRequestResult(callbackResult); var url = await permissionResult.WebContents.GetURL(); await console.Log($"Received permission request from {url} for access to \"{permissionResult.Permission}\"."); if (permissionResult.Permission == Permission.PointerLock) { permissionResult.Callback(await GrantAccess(permissionResult.Permission)); } else { permissionResult.Callback(true); } } ) ); } } await console.Log($"Loading: file://{__dirname}/index.html"); } catch (Exception exc) { await console.Log($"extension exception: {exc.Message}"); } return(windowId); }
async Task <int> CreateWindow(string __dirname) { // Create the browser window. mainWindow = await BrowserWindow.Create(); // Get our session try { session = await Session.FromPartition("partition:nameofpartition"); } catch (Exception sexc) { await console.Log($"logging: {sexc.Message}"); var web = await mainWindow.GetWebContents(); //.ContinueWith( // async (t) => // { // session = await t.Result?.GetSession(); // } // ); session = await web.GetSession(); } if (session != null) { await console.Log(session); await session.SetPermissionRequestHandler( new ScriptObjectCallback <WebContents, string, Func <object, Task <object> > >( async(callbackResult) => { var permissionResult = new PermissionRequestResult(callbackResult); var url = await permissionResult.WebContents.GetURL(); await console.Log($"Received permission request from {url} for access to \"{permissionResult.Permission}\"."); if (url == "https://html5demos.com/geo/" && permissionResult.Permission == "geolocation") { permissionResult.Callback(await GrantAccess(url, permissionResult.Permission)); } else { permissionResult.Callback(true); } } ) ); } // and load the index.html of the app. await mainWindow.LoadURL("https://html5demos.com/geo/"); // Open the DevTools //await mainWindow.GetWebContents().ContinueWith( // (t) => { t.Result?.OpenDevTools(DevToolsMode.Bottom); } //); return(await mainWindow.GetId()); }