From c1087dae9c1750d89aacb8fa64e50805e8691b1d Mon Sep 17 00:00:00 2001 From: Shane Osbourne Date: Thu, 16 Nov 2023 09:09:16 +0000 Subject: [PATCH] send height message on ios --- build/app/public/js/base.js | 474 ++++++++++++----------- shared/js/browser/ios-communication.js | 3 +- shared/js/browser/macos-communication.js | 10 +- 3 files changed, 245 insertions(+), 242 deletions(-) diff --git a/build/app/public/js/base.js b/build/app/public/js/base.js index 554d8f20..b2c0a66b 100644 --- a/build/app/public/js/base.js +++ b/build/app/public/js/base.js @@ -12397,13 +12397,13 @@ url: href }); }); + setupMutationObserver((height) => { + privacyDashboardSetSize({ height }); + }); } function setup2() { setupColorScheme(); setupShared(); - setupMutationObserver((height) => { - privacyDashboardSetSize({ height }); - }); } function firstRenderComplete() { const height = getContentHeight(); @@ -12465,17 +12465,200 @@ } }); + // shared/js/browser/windows-communication.js + var windows_communication_exports = {}; + __export(windows_communication_exports, { + OpenInNewTab: () => OpenInNewTab, + OpenSettings: () => OpenSettings, + SetSize: () => SetSize, + SubmitBrokenSiteReport: () => SubmitBrokenSiteReport, + backgroundMessage: () => backgroundMessage3, + fetch: () => fetch3, + firstRenderComplete: () => firstRenderComplete2, + getBackgroundTabData: () => getBackgroundTabData3, + handleIncomingMessage: () => handleIncomingMessage, + setup: () => setup3 + }); + function handleViewModelUpdate(viewModel) { + upgradedHttps2 = viewModel.upgradedHttps; + parentEntity2 = viewModel.parentEntity || {}; + permissionsData2 = viewModel.permissions || []; + certificateData2 = viewModel.certificates || []; + protections2 = viewModel.protections; + trackerBlockingData2 = createTabData(viewModel.tabUrl, upgradedHttps2, viewModel.protections, viewModel.rawRequestData); + trackerBlockingData2.cookiePromptManagementStatus = viewModel.cookiePromptManagementStatus; + if (trackerBlockingData2) + trackerBlockingData2.upgradedHttps = upgradedHttps2; + resolveInitialRender2(); + } + function windowsPostMessage(name, data) { + assert(typeof window.chrome.webview?.postMessage === "function"); + window.chrome.webview.postMessage({ + Feature: "PrivacyDashboard", + Name: name, + Data: data + }); + } + async function fetch3(message) { + if (message instanceof SubmitBrokenSiteReportMessage) { + SubmitBrokenSiteReport({ + category: message.category, + description: message.description + }); + return; + } + if (message instanceof OpenSettingsMessages) { + OpenSettings({ + target: message.target + }); + return; + } + if (message instanceof SetListsMessage) { + for (const listItem of message.lists) { + const { list, value } = listItem; + if (list !== "allowlisted") { + if (!window.__playwright) + console.warn("only `allowlisted` is currently supported on windows"); + continue; + } + const isProtected = value === false; + const eventOrigin = message.eventOrigin; + if (isProtected) { + windowsPostMessage("RemoveFromAllowListCommand", { eventOrigin }); + } else { + windowsPostMessage("AddToAllowListCommand", { eventOrigin }); + } + } + } + if (message instanceof UpdatePermissionMessage) { + windowsPostMessage("SetPermissionCommand", { + permission: message.id, + value: message.value + }); + } + } + function SubmitBrokenSiteReport(report2) { + windowsPostMessage("SubmitBrokenSiteReport", { + category: report2.category, + description: report2.description + }); + } + function OpenInNewTab(args) { + windowsPostMessage("OpenInNewTab", { + url: args.url + }); + } + function SetSize(payload) { + windowsPostMessage("SetSize", payload); + } + function OpenSettings(args) { + windowsPostMessage("OpenSettings", args); + } + function handleIncomingMessage(message) { + const parsed = eventShape.safeParse(message); + if (!parsed.success) { + console.error("cannot handle incoming message from event data", message); + console.error(parsed.error); + return; + } + switch (parsed.data.Name) { + case "VisibilityChanged": { + if (parsed.data.Data.isVisible === false) { + document.body.innerHTML = ""; + } + break; + } + case "ViewModelUpdated": { + handleViewModelUpdate(parsed.data.Data); + } + } + } + function setup3() { + if (!window.chrome.webview) { + console.error("window.chrome.webview not available"); + return; + } + setupColorScheme(); + assert(typeof window.chrome.webview?.addEventListener === "function", "window.chrome.webview.addEventListener is required"); + window.chrome.webview.addEventListener("message", (event) => { + handleIncomingMessage(event.data); + }); + setupMutationObserver((height) => { + SetSize({ height }); + }); + setupGlobalOpenerListener((href) => { + OpenInNewTab({ + url: href + }); + }); + } + function firstRenderComplete2() { + const height = getContentHeight(); + if (typeof height === "number") { + SetSize({ height }); + } + } + var channel3, backgroundMessage3, getBackgroundTabDataPromises2, trackerBlockingData2, permissionsData2, certificateData2, upgradedHttps2, protections2, isPendingUpdates2, parentEntity2, combineSources2, resolveInitialRender2, getBackgroundTabData3, eventShape; + var init_windows_communication = __esm({ + "shared/js/browser/windows-communication.js"() { + "use strict"; + init_lib(); + init_schema_parsers(); + init_utils(); + init_common(); + init_request_details(); + channel3 = null; + backgroundMessage3 = (backgroundModel) => { + channel3 = backgroundModel; + }; + getBackgroundTabDataPromises2 = []; + combineSources2 = () => ({ + tab: Object.assign( + {}, + trackerBlockingData2 || {}, + { + isPendingUpdates: isPendingUpdates2, + parentEntity: parentEntity2 + }, + permissionsData2 ? { permissions: permissionsData2 } : {}, + certificateData2 ? { certificate: certificateData2 } : {} + ) + }); + resolveInitialRender2 = function() { + const isUpgradedHttpsSet = typeof upgradedHttps2 === "boolean"; + const isIsProtectedSet = typeof protections2 !== "undefined"; + const isTrackerBlockingDataSet = typeof trackerBlockingData2 === "object"; + if (!isUpgradedHttpsSet || !isIsProtectedSet || !isTrackerBlockingDataSet) { + return; + } + getBackgroundTabDataPromises2.forEach((resolve) => resolve(combineSources2())); + channel3?.send("updateTabData"); + }; + getBackgroundTabData3 = () => { + return new Promise((resolve) => { + if (trackerBlockingData2) { + resolve(combineSources2()); + return; + } + getBackgroundTabDataPromises2.push(resolve); + }); + }; + eventShape = mod.discriminatedUnion("Name", [windowsIncomingViewModelSchema, windowsIncomingVisibilitySchema]); + } + }); + // shared/js/browser/ios-communication.js var ios_communication_exports = {}; __export(ios_communication_exports, { backgroundMessage: () => backgroundMessage2, - fetch: () => fetch3, + fetch: () => fetch4, + firstRenderComplete: () => firstRenderComplete2, getBackgroundTabData: () => getBackgroundTabData2, privacyDashboardClose: () => privacyDashboardClose, privacyDashboardShowReportBrokenSite: () => privacyDashboardShowReportBrokenSite, - setup: () => setup3 + setup: () => setup4 }); - function setup3() { + function setup4() { const setColorScheme = setupColorScheme(); window.onChangeTheme = function(themeName) { setColorScheme(themeName); @@ -12491,7 +12674,7 @@ invariant(window.webkit?.messageHandlers, "webkit.messageHandlers required"); window.webkit.messageHandlers.privacyDashboardShowReportBrokenSite.postMessage(args); } - async function fetch3(message) { + async function fetch4(message) { if (message instanceof CloseMessage) { privacyDashboardClose({}); return; @@ -12508,6 +12691,7 @@ init_tiny_invariant(); init_common(); init_macos_communication(); + init_windows_communication(); } }); @@ -12515,19 +12699,19 @@ var android_communication_exports = {}; __export(android_communication_exports, { PrivacyDashboardJavascriptInterface: () => PrivacyDashboardJavascriptInterface, - backgroundMessage: () => backgroundMessage3, - fetch: () => fetch4, - getBackgroundTabData: () => getBackgroundTabData3, + backgroundMessage: () => backgroundMessage4, + fetch: () => fetch5, + getBackgroundTabData: () => getBackgroundTabData4, onChangeConsentManaged: () => onChangeConsentManaged2, onChangeFeatureSettings: () => onChangeFeatureSettings, onChangeLocale: () => onChangeLocale2, onChangeProtectionStatus: () => onChangeProtectionStatus2, onChangeRequestData: () => onChangeRequestData2, - setup: () => setup4 + setup: () => setup5 }); function onChangeRequestData2(tabUrl, rawRequestData) { const requestData = requestDataSchema.safeParse(rawRequestData); - if (!protections2) { + if (!protections3) { console.error("protections status not set"); return; } @@ -12536,8 +12720,8 @@ console.log(requestData.error); return; } - trackerBlockingData2 = createTabData(tabUrl, upgradedHttps2, protections2, requestData.data); - resolveInitialRender2(); + trackerBlockingData3 = createTabData(tabUrl, upgradedHttps3, protections3, requestData.data); + resolveInitialRender3(); } function onChangeProtectionStatus2(protectionsStatus) { const parsed = protectionsStatusSchema.safeParse(protectionsStatus); @@ -12546,8 +12730,8 @@ console.error(parsed.error); return; } - protections2 = parsed.data; - resolveInitialRender2(); + protections3 = parsed.data; + resolveInitialRender3(); } function onChangeLocale2(payload) { const parsed = localeSettingsSchema.safeParse(payload); @@ -12557,7 +12741,7 @@ return; } locale2 = parsed.data.locale; - channel3?.send("updateTabData", { via: "onChangeLocale" }); + channel4?.send("updateTabData", { via: "onChangeLocale" }); } function onChangeFeatureSettings(payload) { const parsed = remoteFeatureSettingsSchema.safeParse(payload); @@ -12567,7 +12751,7 @@ return; } featureSettings = parsed.data; - channel3?.send("updateTabData", { via: "onChangeFeatureSettings" }); + channel4?.send("updateTabData", { via: "onChangeFeatureSettings" }); } function onChangeConsentManaged2(payload) { const parsed = cookiePromptManagementStatusSchema.safeParse(payload); @@ -12577,7 +12761,7 @@ return; } Object.assign(cookiePromptManagementStatus2, parsed.data); - channel3?.send("updateTabData"); + channel4?.send("updateTabData"); } async function fetchAndroid(message) { if (message instanceof SetListsMessage) { @@ -12605,7 +12789,7 @@ }); } } - function setup4() { + function setup5() { const setColorScheme = setupColorScheme(); window.onChangeTheme = function(themeName) { setColorScheme(themeName); @@ -12616,26 +12800,26 @@ window.onChangeConsentManaged = onChangeConsentManaged2; window.onChangeFeatureSettings = onChangeFeatureSettings; window.onChangeAllowedPermissions = function(data) { - permissionsData2 = data; - channel3?.send("updateTabData", { via: "onChangeAllowedPermissions" }); + permissionsData3 = data; + channel4?.send("updateTabData", { via: "onChangeAllowedPermissions" }); }; window.onChangeUpgradedHttps = function(data) { - upgradedHttps2 = data; - if (trackerBlockingData2) - trackerBlockingData2.upgradedHttps = upgradedHttps2; - resolveInitialRender2(); + upgradedHttps3 = data; + if (trackerBlockingData3) + trackerBlockingData3.upgradedHttps = upgradedHttps3; + resolveInitialRender3(); }; window.onChangeCertificateData = function(data) { - certificateData2 = data.secCertificateViewModels; - channel3?.send("updateTabData", { via: "onChangeCertificateData" }); + certificateData3 = data.secCertificateViewModels; + channel4?.send("updateTabData", { via: "onChangeCertificateData" }); }; window.onIsPendingUpdates = function(data) { - isPendingUpdates2 = data; - channel3?.send("updateTabData", { via: "onIsPendingUpdates" }); + isPendingUpdates3 = data; + channel4?.send("updateTabData", { via: "onIsPendingUpdates" }); }; window.onChangeParentEntity = function(data) { - parentEntity2 = data; - channel3?.send("updateTabData", { via: "onChangeParentEntity" }); + parentEntity3 = data; + channel4?.send("updateTabData", { via: "onChangeParentEntity" }); }; privacyDashboardApi = new PrivacyDashboardJavascriptInterface(); setupBlurOnLongPress(); @@ -12645,7 +12829,7 @@ }); }); } - var channel3, backgroundMessage3, getBackgroundTabDataPromises2, trackerBlockingData2, permissionsData2, certificateData2, upgradedHttps2, protections2, isPendingUpdates2, parentEntity2, cookiePromptManagementStatus2, locale2, featureSettings, combineSources2, resolveInitialRender2, PrivacyDashboardJavascriptInterface, privacyDashboardApi, getBackgroundTabDataAndroid, getBackgroundTabData3, fetch4; + var channel4, backgroundMessage4, getBackgroundTabDataPromises3, trackerBlockingData3, permissionsData3, certificateData3, upgradedHttps3, protections3, isPendingUpdates3, parentEntity3, cookiePromptManagementStatus2, locale2, featureSettings, combineSources3, resolveInitialRender3, PrivacyDashboardJavascriptInterface, privacyDashboardApi, getBackgroundTabDataAndroid, getBackgroundTabData4, fetch5; var init_android_communication = __esm({ "shared/js/browser/android-communication.js"() { "use strict"; @@ -12653,37 +12837,37 @@ init_utils(); init_common(); init_request_details(); - channel3 = null; - backgroundMessage3 = (backgroundModel) => { - channel3 = backgroundModel; + channel4 = null; + backgroundMessage4 = (backgroundModel) => { + channel4 = backgroundModel; }; - getBackgroundTabDataPromises2 = []; + getBackgroundTabDataPromises3 = []; cookiePromptManagementStatus2 = {}; - combineSources2 = () => ({ + combineSources3 = () => ({ tab: Object.assign( {}, - trackerBlockingData2 || {}, + trackerBlockingData3 || {}, { - isPendingUpdates: isPendingUpdates2, - parentEntity: parentEntity2, + isPendingUpdates: isPendingUpdates3, + parentEntity: parentEntity3, cookiePromptManagementStatus: cookiePromptManagementStatus2, locale: locale2 }, - permissionsData2 ? { permissions: permissionsData2 } : {}, - certificateData2 ? { certificate: certificateData2 } : {} + permissionsData3 ? { permissions: permissionsData3 } : {}, + certificateData3 ? { certificate: certificateData3 } : {} ), featureSettings }); - resolveInitialRender2 = function() { - const isUpgradedHttpsSet = typeof upgradedHttps2 === "boolean"; - const isIsProtectedSet = typeof protections2 !== "undefined"; - const isTrackerBlockingDataSet = typeof trackerBlockingData2 === "object"; + resolveInitialRender3 = function() { + const isUpgradedHttpsSet = typeof upgradedHttps3 === "boolean"; + const isIsProtectedSet = typeof protections3 !== "undefined"; + const isTrackerBlockingDataSet = typeof trackerBlockingData3 === "object"; const isLocaleSet = typeof locale2 === "string"; if (!isLocaleSet || !isUpgradedHttpsSet || !isIsProtectedSet || !isTrackerBlockingDataSet) { return; } - getBackgroundTabDataPromises2.forEach((resolve) => resolve(combineSources2())); - channel3?.send("updateTabData", { via: "resolveInitialRender" }); + getBackgroundTabDataPromises3.forEach((resolve) => resolve(combineSources3())); + channel4?.send("updateTabData", { via: "resolveInitialRender" }); }; PrivacyDashboardJavascriptInterface = class { /** @@ -12755,19 +12939,19 @@ }; getBackgroundTabDataAndroid = () => { return new Promise((resolve) => { - if (trackerBlockingData2) { - resolve(combineSources2()); + if (trackerBlockingData3) { + resolve(combineSources3()); return; } - getBackgroundTabDataPromises2.push(resolve); + getBackgroundTabDataPromises3.push(resolve); }); }; - getBackgroundTabData3 = new Proxy(getBackgroundTabDataAndroid, { + getBackgroundTabData4 = new Proxy(getBackgroundTabDataAndroid, { apply(target, thisArg, argArray) { return Reflect.apply(target, thisArg, argArray); } }); - fetch4 = new Proxy(fetchAndroid, { + fetch5 = new Proxy(fetchAndroid, { apply(target, thisArg, argArray) { return Reflect.apply(target, thisArg, argArray); } @@ -12775,188 +12959,6 @@ } }); - // shared/js/browser/windows-communication.js - var windows_communication_exports = {}; - __export(windows_communication_exports, { - OpenInNewTab: () => OpenInNewTab, - OpenSettings: () => OpenSettings, - SetSize: () => SetSize, - SubmitBrokenSiteReport: () => SubmitBrokenSiteReport, - backgroundMessage: () => backgroundMessage4, - fetch: () => fetch5, - firstRenderComplete: () => firstRenderComplete2, - getBackgroundTabData: () => getBackgroundTabData4, - handleIncomingMessage: () => handleIncomingMessage, - setup: () => setup5 - }); - function handleViewModelUpdate(viewModel) { - upgradedHttps3 = viewModel.upgradedHttps; - parentEntity3 = viewModel.parentEntity || {}; - permissionsData3 = viewModel.permissions || []; - certificateData3 = viewModel.certificates || []; - protections3 = viewModel.protections; - trackerBlockingData3 = createTabData(viewModel.tabUrl, upgradedHttps3, viewModel.protections, viewModel.rawRequestData); - trackerBlockingData3.cookiePromptManagementStatus = viewModel.cookiePromptManagementStatus; - if (trackerBlockingData3) - trackerBlockingData3.upgradedHttps = upgradedHttps3; - resolveInitialRender3(); - } - function windowsPostMessage(name, data) { - assert(typeof window.chrome.webview?.postMessage === "function"); - window.chrome.webview.postMessage({ - Feature: "PrivacyDashboard", - Name: name, - Data: data - }); - } - async function fetch5(message) { - if (message instanceof SubmitBrokenSiteReportMessage) { - SubmitBrokenSiteReport({ - category: message.category, - description: message.description - }); - return; - } - if (message instanceof OpenSettingsMessages) { - OpenSettings({ - target: message.target - }); - return; - } - if (message instanceof SetListsMessage) { - for (const listItem of message.lists) { - const { list, value } = listItem; - if (list !== "allowlisted") { - if (!window.__playwright) - console.warn("only `allowlisted` is currently supported on windows"); - continue; - } - const isProtected = value === false; - const eventOrigin = message.eventOrigin; - if (isProtected) { - windowsPostMessage("RemoveFromAllowListCommand", { eventOrigin }); - } else { - windowsPostMessage("AddToAllowListCommand", { eventOrigin }); - } - } - } - if (message instanceof UpdatePermissionMessage) { - windowsPostMessage("SetPermissionCommand", { - permission: message.id, - value: message.value - }); - } - } - function SubmitBrokenSiteReport(report2) { - windowsPostMessage("SubmitBrokenSiteReport", { - category: report2.category, - description: report2.description - }); - } - function OpenInNewTab(args) { - windowsPostMessage("OpenInNewTab", { - url: args.url - }); - } - function SetSize(payload) { - windowsPostMessage("SetSize", payload); - } - function OpenSettings(args) { - windowsPostMessage("OpenSettings", args); - } - function handleIncomingMessage(message) { - const parsed = eventShape.safeParse(message); - if (!parsed.success) { - console.error("cannot handle incoming message from event data", message); - console.error(parsed.error); - return; - } - switch (parsed.data.Name) { - case "VisibilityChanged": { - if (parsed.data.Data.isVisible === false) { - document.body.innerHTML = ""; - } - break; - } - case "ViewModelUpdated": { - handleViewModelUpdate(parsed.data.Data); - } - } - } - function setup5() { - if (!window.chrome.webview) { - console.error("window.chrome.webview not available"); - return; - } - setupColorScheme(); - assert(typeof window.chrome.webview?.addEventListener === "function", "window.chrome.webview.addEventListener is required"); - window.chrome.webview.addEventListener("message", (event) => { - handleIncomingMessage(event.data); - }); - setupMutationObserver((height) => { - SetSize({ height }); - }); - setupGlobalOpenerListener((href) => { - OpenInNewTab({ - url: href - }); - }); - } - function firstRenderComplete2() { - const height = getContentHeight(); - if (typeof height === "number") { - SetSize({ height }); - } - } - var channel4, backgroundMessage4, getBackgroundTabDataPromises3, trackerBlockingData3, permissionsData3, certificateData3, upgradedHttps3, protections3, isPendingUpdates3, parentEntity3, combineSources3, resolveInitialRender3, getBackgroundTabData4, eventShape; - var init_windows_communication = __esm({ - "shared/js/browser/windows-communication.js"() { - "use strict"; - init_lib(); - init_schema_parsers(); - init_utils(); - init_common(); - init_request_details(); - channel4 = null; - backgroundMessage4 = (backgroundModel) => { - channel4 = backgroundModel; - }; - getBackgroundTabDataPromises3 = []; - combineSources3 = () => ({ - tab: Object.assign( - {}, - trackerBlockingData3 || {}, - { - isPendingUpdates: isPendingUpdates3, - parentEntity: parentEntity3 - }, - permissionsData3 ? { permissions: permissionsData3 } : {}, - certificateData3 ? { certificate: certificateData3 } : {} - ) - }); - resolveInitialRender3 = function() { - const isUpgradedHttpsSet = typeof upgradedHttps3 === "boolean"; - const isIsProtectedSet = typeof protections3 !== "undefined"; - const isTrackerBlockingDataSet = typeof trackerBlockingData3 === "object"; - if (!isUpgradedHttpsSet || !isIsProtectedSet || !isTrackerBlockingDataSet) { - return; - } - getBackgroundTabDataPromises3.forEach((resolve) => resolve(combineSources3())); - channel4?.send("updateTabData"); - }; - getBackgroundTabData4 = () => { - return new Promise((resolve) => { - if (trackerBlockingData3) { - resolve(combineSources3()); - return; - } - getBackgroundTabDataPromises3.push(resolve); - }); - }; - eventShape = mod.discriminatedUnion("Name", [windowsIncomingViewModelSchema, windowsIncomingVisibilitySchema]); - } - }); - // shared/js/browser/utils/communication-mocks.mjs var init_communication_mocks = __esm({ "shared/js/browser/utils/communication-mocks.mjs"() { diff --git a/shared/js/browser/ios-communication.js b/shared/js/browser/ios-communication.js index fed3725f..442fa6fe 100644 --- a/shared/js/browser/ios-communication.js +++ b/shared/js/browser/ios-communication.js @@ -24,6 +24,7 @@ import invariant from 'tiny-invariant' import { CheckBrokenSiteReportHandledMessage, CloseMessage, setupColorScheme } from './common.js' import { backgroundMessage, getBackgroundTabData, fetch as macosFetch, setupShared } from './macos-communication.js' +import { firstRenderComplete } from './windows-communication.js' /** * iOS specific setup @@ -85,4 +86,4 @@ async function fetch(message) { return macosFetch(message) } -export { backgroundMessage, getBackgroundTabData, fetch } +export { backgroundMessage, getBackgroundTabData, fetch, firstRenderComplete } diff --git a/shared/js/browser/macos-communication.js b/shared/js/browser/macos-communication.js index 528c830e..a02fc6c1 100644 --- a/shared/js/browser/macos-communication.js +++ b/shared/js/browser/macos-communication.js @@ -332,6 +332,9 @@ export function setupShared() { url: href, }) }) + setupMutationObserver((height) => { + privacyDashboardSetSize({ height }) + }) } /** @@ -340,9 +343,6 @@ export function setupShared() { export function setup() { setupColorScheme() setupShared() - setupMutationObserver((height) => { - privacyDashboardSetSize({ height }) - }) } /** @@ -352,11 +352,11 @@ export function setup() { * @type {NonNullable} * @category Internal API */ -function firstRenderComplete() { +export function firstRenderComplete() { const height = getContentHeight() if (typeof height === 'number') { privacyDashboardSetSize({ height }) } } -export { fetch, backgroundMessage, getBackgroundTabData, firstRenderComplete } +export { fetch, backgroundMessage, getBackgroundTabData }