Skip to content

Commit 22c8905

Browse files
committed
Better scaling of the tab preview panel with privacy.resistFingerprinting=true #3698
1 parent 04cf13b commit 22c8905

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

webextensions/resources/module/tab-preview-frame.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ function preparePanel() {
421421
panel = createdPanel;
422422
}
423423

424-
function updatePanel({ previewTabId, title, url, tooltipHtml, hasPreview, previewURL, previewTabRect, offsetTop, align, rtl, scale, logging, animation, backgroundColor, borderColor, color } = {}) {
424+
function updatePanel({ previewTabId, title, url, tooltipHtml, hasPreview, previewURL, previewTabRect, offsetTop, align, rtl, scale, logging, animation, backgroundColor, borderColor, color, widthInOuterWorld } = {}) {
425425
if (!panel)
426426
return;
427427

@@ -432,7 +432,7 @@ function updatePanel({ previewTabId, title, url, tooltipHtml, hasPreview, previe
432432
hasPreview = hasLoadablePreviewURL;
433433

434434
if (logging)
435-
console.log('updatePanel ', { previewTabId, title, url, tooltipHtml, hasPreview, previewURL, previewTabRect, offsetTop, align, rtl, scale });
435+
console.log('updatePanel ', { previewTabId, title, url, tooltipHtml, hasPreview, previewURL, previewTabRect, offsetTop, align, rtl, scale, widthInOuterWorld });
436436

437437
panel.classList.add('updating');
438438
panel.classList.toggle('animation', animation);
@@ -452,13 +452,23 @@ function updatePanel({ previewTabId, title, url, tooltipHtml, hasPreview, previe
452452
// from both the sidebar and the content area, because all contents
453453
// of the browser window can be scaled on a high-DPI display by the
454454
// platform.
455-
scale = window.devicePixelRatio * (scale || 1);
455+
const isResistFingerprintingMode = window.mozInnerScreenY == 0 && window.screenY == 0;
456+
const devicePixelRatio = (widthInOuterWorld || window.innerWidth) / window.innerWidth;
457+
if (logging)
458+
console.log('updatePanel: isResistFingerprintingMode ', isResistFingerprintingMode, { devicePixelRatio });
459+
// But window.devicePixelRatio is not available if privacy.resistFingerprinting=true,
460+
// thus we need to calculate it based on tabs.Tab.width.
461+
scale = devicePixelRatio * (scale || 1);
456462
document.documentElement.style.setProperty('--tab-preview-panel-scale', scale);
457463
const panelWidth = Math.min(window.innerWidth, BASE_PANEL_WIDTH / scale);
458464
panel.style.setProperty('--panel-width', `${panelWidth}px`);
459465

460-
const offsetFromWindowEdge = (window.mozInnerScreenY - window.screenY) * scale;
461-
const sidebarContentsOffset = (offsetTop - offsetFromWindowEdge) / scale;
466+
const offsetFromWindowEdge = isResistFingerprintingMode ?
467+
0 :
468+
(window.mozInnerScreenY - window.screenY) * scale;
469+
const sidebarContentsOffset = isResistFingerprintingMode ?
470+
0 :
471+
(offsetTop - offsetFromWindowEdge) / scale;
462472

463473
if (previewTabRect) {
464474
const panelTopEdge = windowId ? previewTabRect.bottom : previewTabRect.top;

webextensions/sidebar/tab-preview-tooltip.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,18 +278,21 @@ async function sendTabPreviewMessage(tabId, message, deferredResultResolver) {
278278

279279
let frameId;
280280
let loadedInfo;
281+
let rawTab;
281282
try {
282-
const [gotFrameId, gotLoadedInfo] = await Promise.all([
283+
const [gotFrameId, gotLoadedInfo, gotRawTab] = await Promise.all([
283284
browser.tabs.sendMessage(tabId, {
284285
type: 'treestyletab:ask-tab-preview-frame-id',
285286
}).catch(_error => {}),
286287
DIRECT_PANEL_AVAILABLE_URLS_MATCHER.test(tab.url) && browser.tabs.sendMessage(tabId, {
287288
type: 'treestyletab:ask-tab-preview-frame-loaded',
288289
tabId,
289290
}).catch(_error => {}),
291+
browser.tabs.get(tabId),
290292
]);
291293
frameId = gotFrameId;
292294
loadedInfo = gotLoadedInfo;
295+
rawTab = gotRawTab;
293296
log(`sendTabPreviewMessage(${message.type}${retrying ? ', retrying' : ''}): response from the tab: `, { frameId, loadedInfo });
294297
if (!frameId &&
295298
(!loadedInfo ||
@@ -359,6 +362,7 @@ async function sendTabPreviewMessage(tabId, message, deferredResultResolver) {
359362
...message,
360363
...TabPreviewFrame.getColors(),
361364
...(promisedPreviewURL ? { previewURL: null } : {}),
365+
widthInOuterWorld: rawTab.width,
362366
animation: shouldApplyAnimation(),
363367
logging: configs.logFor['sidebar/tab-preview-tooltip'] && configs.debug,
364368
}, frameId ? { frameId } : {});
@@ -375,6 +379,7 @@ async function sendTabPreviewMessage(tabId, message, deferredResultResolver) {
375379
...message,
376380
previewURL,
377381
...TabPreviewFrame.getColors(),
382+
widthInOuterWorld: rawTab.width,
378383
animation: shouldApplyAnimation(),
379384
logging: configs.logFor['sidebar/tab-preview-tooltip'] && configs.debug,
380385
}, frameId ? { frameId } : {});

0 commit comments

Comments
 (0)