|
6856 | 6856 | });
|
6857 | 6857 | }
|
6858 | 6858 |
|
6859 |
| - function windowsPostGeolocationMessage (name, data) { |
6860 |
| - window.chrome.webview.postMessage({ |
6861 |
| - Feature: 'Geolocation', |
6862 |
| - Name: name, |
6863 |
| - Data: data |
6864 |
| - }); |
6865 |
| - } |
6866 |
| - |
6867 | 6859 | function signalPermissionStatus (permission, status) {
|
6868 | 6860 | windowsPostMessage('PermissionStatusMessage', { permission, status });
|
6869 | 6861 | console.debug(`Permission '${permission}' is ${status}`);
|
6870 | 6862 | }
|
6871 | 6863 |
|
6872 |
| - function registerPositionMessageHandler (args, messageId, geolocationActiveStatus) { |
6873 |
| - const successHandler = args[0]; |
6874 |
| - |
6875 |
| - const handler = function ({ data }) { |
6876 |
| - if (data?.id === messageId) { |
6877 |
| - window.chrome.webview.removeEventListener('message', handler); |
6878 |
| - signalPermissionStatus(Permission.Geolocation, geolocationActiveStatus); |
6879 |
| - if (Object.prototype.hasOwnProperty.call(data, 'errorCode')) { |
6880 |
| - if (args.length >= 2) { |
6881 |
| - const errorHandler = args[1]; |
6882 |
| - const error = { code: data.errorCode, message: data.errorMessage }; |
6883 |
| - errorHandler?.(error); |
6884 |
| - } |
6885 |
| - } else { |
6886 |
| - const rez = { |
6887 |
| - timestamp: data.timestamp, |
6888 |
| - coords: { |
6889 |
| - latitude: data.latitude, |
6890 |
| - longitude: data.longitude, |
6891 |
| - altitude: null, |
6892 |
| - altitudeAccuracy: null, |
6893 |
| - heading: null, |
6894 |
| - speed: null, |
6895 |
| - accuracy: data.accuracy |
6896 |
| - } |
6897 |
| - }; |
6898 |
| - |
6899 |
| - successHandler?.(rez); |
6900 |
| - } |
6901 |
| - } |
6902 |
| - }; |
6903 |
| - |
6904 |
| - window.chrome.webview.addEventListener('message', handler); |
6905 |
| - } |
6906 |
| - |
6907 |
| - let watchedPositionId = 0; |
6908 | 6864 | const watchedPositions = new Set();
|
6909 | 6865 | // proxy for navigator.geolocation.watchPosition -> show red geolocation indicator
|
6910 | 6866 | const watchPositionProxy = new DDGProxy(featureName, Geolocation.prototype, 'watchPosition', {
|
|
6914 | 6870 | throw new DOMException('Permission denied')
|
6915 | 6871 | }
|
6916 | 6872 |
|
6917 |
| - const messageId = crypto.randomUUID(); |
6918 |
| - registerPositionMessageHandler(args, messageId, Status.Active); |
6919 |
| - windowsPostGeolocationMessage('positionRequested', { id: messageId }); |
6920 |
| - watchedPositionId++; |
6921 |
| - watchedPositions.add(watchedPositionId); |
6922 |
| - return watchedPositionId |
| 6873 | + const successHandler = args[0]; |
| 6874 | + args[0] = function (position) { |
| 6875 | + signalPermissionStatus(Permission.Geolocation, Status.Active); |
| 6876 | + successHandler?.(position); |
| 6877 | + }; |
| 6878 | + const id = DDGReflect.apply(target, thisArg, args); |
| 6879 | + watchedPositions.add(id); |
| 6880 | + return id |
6923 | 6881 | }
|
6924 | 6882 | });
|
6925 | 6883 | watchPositionProxy.overload();
|
6926 | 6884 |
|
6927 | 6885 | // proxy for navigator.geolocation.clearWatch -> clear red geolocation indicator
|
6928 | 6886 | const clearWatchProxy = new DDGProxy(featureName, Geolocation.prototype, 'clearWatch', {
|
6929 | 6887 | apply (target, thisArg, args) {
|
| 6888 | + DDGReflect.apply(target, thisArg, args); |
6930 | 6889 | if (args[0] && watchedPositions.delete(args[0]) && watchedPositions.size === 0) {
|
6931 | 6890 | signalPermissionStatus(Permission.Geolocation, Status.Inactive);
|
6932 | 6891 | }
|
|
6937 | 6896 | // proxy for navigator.geolocation.getCurrentPosition -> normal geolocation indicator
|
6938 | 6897 | const getCurrentPositionProxy = new DDGProxy(featureName, Geolocation.prototype, 'getCurrentPosition', {
|
6939 | 6898 | apply (target, thisArg, args) {
|
6940 |
| - const messageId = crypto.randomUUID(); |
6941 |
| - registerPositionMessageHandler(args, messageId, Status.Accessed); |
6942 |
| - windowsPostGeolocationMessage('positionRequested', { id: messageId }); |
| 6899 | + const successHandler = args[0]; |
| 6900 | + args[0] = function (position) { |
| 6901 | + signalPermissionStatus(Permission.Geolocation, Status.Accessed); |
| 6902 | + successHandler?.(position); |
| 6903 | + }; |
| 6904 | + return DDGReflect.apply(target, thisArg, args) |
6943 | 6905 | }
|
6944 | 6906 | });
|
6945 | 6907 | getCurrentPositionProxy.overload();
|
|
0 commit comments