mirror of
https://github.com/status-im/status-app.git
synced 2026-08-27 07:01:14 +00:00
A Tab opened to display a downloaded file is no longer a browsing Tab. `profileParams` gains an orthogonal `localPreview` flag; it selects a profile of its own — always off the record, never named — with no injected scripts, no web channel and no connector. The local-URL policy splits along the same line: browsing profiles reach no file:// at all (a local path in the address bar dead-ends), and only the preview profile reaches the downloads and player-page directories. The default profile, which backs views whose storage profile could not be created, carries the browsing policy either way. WebEngine views drop localContentCanAccessRemoteUrls everywhere and grant localContentCanAccessFileUrls to previews alone, so the player page can load the media beside it. Stack-target: PR 21853
79 lines
2.2 KiB
JavaScript
79 lines
2.2 KiB
JavaScript
.pragma library
|
|
|
|
function normalizeIcon(iconUrl) {
|
|
return iconUrl ? iconUrl.toString().replace("image://favicon/", "") : ""
|
|
}
|
|
|
|
function snapshotGrabSize(width, height, maxWidth, maxHeight) {
|
|
const w = Number(width) || 0
|
|
const h = Number(height) || 0
|
|
if (w <= 0 || h <= 0)
|
|
return Qt.size(maxWidth, maxHeight)
|
|
|
|
const scale = Math.min(maxWidth / w, maxHeight / h, 1)
|
|
return Qt.size(
|
|
Math.max(1, Math.round(w * scale)),
|
|
Math.max(1, Math.round(h * scale))
|
|
)
|
|
}
|
|
|
|
function findSavedTab(savedTabs, uid) {
|
|
if (!savedTabs || !uid)
|
|
return null
|
|
|
|
for (let i = 0; i < savedTabs.length; i++) {
|
|
const tab = savedTabs[i]
|
|
if (tab && tab.uuid === uid)
|
|
return tab
|
|
}
|
|
return null
|
|
}
|
|
|
|
function resolveTitle(liveTitle, persistedRecord) {
|
|
return liveTitle || (persistedRecord && persistedRecord.title) || ""
|
|
}
|
|
|
|
function resolveIcon(liveIconUrl, persistedRecord) {
|
|
return normalizeIcon(liveIconUrl) || (persistedRecord && persistedRecord.icon) || ""
|
|
}
|
|
|
|
function displayTitle(webView, persistedRecord, labels) {
|
|
const fallback = labels.emptyLabel || ""
|
|
if (!webView)
|
|
return fallback
|
|
|
|
const resolved = resolveTitle(webView.title || "", persistedRecord)
|
|
if (resolved)
|
|
return resolved
|
|
|
|
if (labels.isStartPage)
|
|
return labels.startPageLabel || fallback
|
|
|
|
return fallback
|
|
}
|
|
|
|
function buildTabDto(webView, savedTabs, determineRealURL) {
|
|
if (!webView || webView.offTheRecord)
|
|
return null
|
|
// A local preview is not a browsing Tab (ADR 0006 §8): the file it shows is
|
|
// no page to restore to. Its params are off the record as well, so this is
|
|
// belt and braces — and deliberately so, rather than leaning on that.
|
|
if (webView.profileParams && webView.profileParams.localPreview)
|
|
return null
|
|
|
|
const rawUrl = webView.url.toString()
|
|
const normalizedUrl = determineRealURL(rawUrl)
|
|
if (!normalizedUrl)
|
|
return null
|
|
|
|
const uid = webView.uid || ""
|
|
const persisted = findSavedTab(savedTabs, uid)
|
|
|
|
return {
|
|
uuid: uid,
|
|
url: normalizedUrl,
|
|
title: resolveTitle(webView.title || "", persisted),
|
|
icon: resolveIcon(webView.icon, persisted)
|
|
}
|
|
}
|