Skip to content

Commit 3d8f265

Browse files
Fix Windows browser permission status (fixed newlines) (#237)
Asana link: https://app.asana.com/0/1201048563534612/1203828598590983/f Description: Removed the previous commit from geolocation permissions - we decided not using native code to inject location data Set the platform to 'windows' in the windows-specific code. * Removed an unneeded windows geolocation commit. * Rebased on the newest main * line ending fixes * Rebuilt with updated packages
1 parent fb1eda3 commit 3d8f265

File tree

9 files changed

+112
-374
lines changed

9 files changed

+112
-374
lines changed

Sources/ContentScopeScripts/dist/contentScope.js

Lines changed: 15 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6856,55 +6856,11 @@
68566856
});
68576857
}
68586858

6859-
function windowsPostGeolocationMessage (name, data) {
6860-
window.chrome.webview.postMessage({
6861-
Feature: 'Geolocation',
6862-
Name: name,
6863-
Data: data
6864-
});
6865-
}
6866-
68676859
function signalPermissionStatus (permission, status) {
68686860
windowsPostMessage('PermissionStatusMessage', { permission, status });
68696861
console.debug(`Permission '${permission}' is ${status}`);
68706862
}
68716863

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;
69086864
const watchedPositions = new Set();
69096865
// proxy for navigator.geolocation.watchPosition -> show red geolocation indicator
69106866
const watchPositionProxy = new DDGProxy(featureName, Geolocation.prototype, 'watchPosition', {
@@ -6914,19 +6870,22 @@
69146870
throw new DOMException('Permission denied')
69156871
}
69166872

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
69236881
}
69246882
});
69256883
watchPositionProxy.overload();
69266884

69276885
// proxy for navigator.geolocation.clearWatch -> clear red geolocation indicator
69286886
const clearWatchProxy = new DDGProxy(featureName, Geolocation.prototype, 'clearWatch', {
69296887
apply (target, thisArg, args) {
6888+
DDGReflect.apply(target, thisArg, args);
69306889
if (args[0] && watchedPositions.delete(args[0]) && watchedPositions.size === 0) {
69316890
signalPermissionStatus(Permission.Geolocation, Status.Inactive);
69326891
}
@@ -6937,9 +6896,12 @@
69376896
// proxy for navigator.geolocation.getCurrentPosition -> normal geolocation indicator
69386897
const getCurrentPositionProxy = new DDGProxy(featureName, Geolocation.prototype, 'getCurrentPosition', {
69396898
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)
69436905
}
69446906
});
69456907
getCurrentPositionProxy.overload();

build/android/contentScope.js

Lines changed: 15 additions & 53 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/chrome-mv3/inject.js

Lines changed: 15 additions & 53 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/chrome/inject.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)