From a30427ea159305a4d8803ad4106233d51bdeacc0 Mon Sep 17 00:00:00 2001 From: Nicolas Cazottes Date: Sat, 17 Dec 2022 09:23:36 +0000 Subject: [PATCH 1/2] Redo of PR 14379 commits --- src/panels/lovelace/cards/hui-iframe-card.ts | 8 +++++++- src/panels/lovelace/cards/types.ts | 1 + .../editor/config-elements/hui-iframe-card-editor.ts | 4 +++- src/translations/en.json | 1 + 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/panels/lovelace/cards/hui-iframe-card.ts b/src/panels/lovelace/cards/hui-iframe-card.ts index 0ce53d5cef2b..bea0f9ab6163 100644 --- a/src/panels/lovelace/cards/hui-iframe-card.ts +++ b/src/panels/lovelace/cards/hui-iframe-card.ts @@ -21,6 +21,7 @@ export class HuiIframeCard extends LitElement implements LovelaceCard { type: "iframe", url: "https://www.home-assistant.io", aspect_ratio: "50%", + allow_open_top_navigation: false, }; } @@ -80,6 +81,11 @@ export class HuiIframeCard extends LitElement implements LovelaceCard { `; } + let sandbox_user_params = ""; + if (this._config.allow_open_top_navigation) { + sandbox_user_params += "allow-top-navigation-by-user-activation"; + } + return html`
diff --git a/src/panels/lovelace/cards/types.ts b/src/panels/lovelace/cards/types.ts index 5ab627b46626..4f2f6ad16b79 100644 --- a/src/panels/lovelace/cards/types.ts +++ b/src/panels/lovelace/cards/types.ts @@ -247,6 +247,7 @@ export interface HumidifierCardConfig extends LovelaceCardConfig { } export interface IframeCardConfig extends LovelaceCardConfig { + allow_open_top_navigation?: boolean; aspect_ratio?: string; title?: string; url: string; diff --git a/src/panels/lovelace/editor/config-elements/hui-iframe-card-editor.ts b/src/panels/lovelace/editor/config-elements/hui-iframe-card-editor.ts index 8e53668e2938..eb373eae6440 100644 --- a/src/panels/lovelace/editor/config-elements/hui-iframe-card-editor.ts +++ b/src/panels/lovelace/editor/config-elements/hui-iframe-card-editor.ts @@ -1,7 +1,7 @@ import "../../../../components/ha-form/ha-form"; import { html, LitElement, TemplateResult } from "lit"; import { customElement, property, state } from "lit/decorators"; -import { assert, assign, object, optional, string } from "superstruct"; +import { assert, assign, boolean, object, optional, string } from "superstruct"; import { fireEvent } from "../../../../common/dom/fire_event"; import type { SchemaUnion } from "../../../../components/ha-form/types"; import type { HomeAssistant } from "../../../../types"; @@ -15,6 +15,7 @@ const cardConfigStruct = assign( title: optional(string()), url: optional(string()), aspect_ratio: optional(string()), + allow_open_top_navigation: optional(boolean()), }) ); @@ -26,6 +27,7 @@ const SCHEMA = [ schema: [ { name: "url", required: true, selector: { text: {} } }, { name: "aspect_ratio", selector: { text: {} } }, + { name: "allow_open_top_navigation", selector: { boolean: {} } }, ], }, ] as const; diff --git a/src/translations/en.json b/src/translations/en.json index 5cc1fd033d14..43a1f51935ac 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -4202,6 +4202,7 @@ "description": "The Light card allows you to change the brightness of the light." }, "generic": { + "allow_open_top_navigation": "Allow open iframe links", "aspect_ratio": "Aspect Ratio", "attribute": "Attribute", "camera_image": "Camera Entity", From a64e036588dca9142a0a836e20a99dbf6cf1b985 Mon Sep 17 00:00:00 2001 From: Nicolas Cazottes Date: Mon, 23 Jan 2023 21:26:00 +0000 Subject: [PATCH 2/2] Remove config dialog as PR review --- src/panels/lovelace/cards/hui-iframe-card.ts | 1 - .../lovelace/editor/config-elements/hui-iframe-card-editor.ts | 1 - src/translations/en.json | 1 - 3 files changed, 3 deletions(-) diff --git a/src/panels/lovelace/cards/hui-iframe-card.ts b/src/panels/lovelace/cards/hui-iframe-card.ts index bea0f9ab6163..0ec7c3d88820 100644 --- a/src/panels/lovelace/cards/hui-iframe-card.ts +++ b/src/panels/lovelace/cards/hui-iframe-card.ts @@ -21,7 +21,6 @@ export class HuiIframeCard extends LitElement implements LovelaceCard { type: "iframe", url: "https://www.home-assistant.io", aspect_ratio: "50%", - allow_open_top_navigation: false, }; } diff --git a/src/panels/lovelace/editor/config-elements/hui-iframe-card-editor.ts b/src/panels/lovelace/editor/config-elements/hui-iframe-card-editor.ts index eb373eae6440..43d72233081f 100644 --- a/src/panels/lovelace/editor/config-elements/hui-iframe-card-editor.ts +++ b/src/panels/lovelace/editor/config-elements/hui-iframe-card-editor.ts @@ -27,7 +27,6 @@ const SCHEMA = [ schema: [ { name: "url", required: true, selector: { text: {} } }, { name: "aspect_ratio", selector: { text: {} } }, - { name: "allow_open_top_navigation", selector: { boolean: {} } }, ], }, ] as const; diff --git a/src/translations/en.json b/src/translations/en.json index d346c10e6581..6b6201928ef3 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -4177,7 +4177,6 @@ }, "generic": { "alt_text": "Alternative Text", - "allow_open_top_navigation": "Allow open iframe links", "aspect_ratio": "Aspect Ratio", "attribute": "Attribute", "camera_image": "Camera Entity",