trust and remember Change-Id: I3bc6fe1eb4fd19c13a46949fe34b9a3b6dac8f80
diff --git a/ui/src/frontend/post_message_handler.ts b/ui/src/frontend/post_message_handler.ts index d7bfc84..591cdbc 100644 --- a/ui/src/frontend/post_message_handler.ts +++ b/ui/src/frontend/post_message_handler.ts
@@ -103,7 +103,7 @@ // Saves the given hostname as a trusted origin. // This is used for user convenience: if it fails for any reason, it's not a // big deal. -function saveUserTrustedOrigin(hostname: string) { +export function saveUserTrustedOrigin(hostname: string) { const s = window.localStorage.getItem(TRUSTED_ORIGINS_KEY); let origins: string[]; try {
diff --git a/ui/src/frontend/trace_url_handler.ts b/ui/src/frontend/trace_url_handler.ts index 28d3c5c..656d01f 100644 --- a/ui/src/frontend/trace_url_handler.ts +++ b/ui/src/frontend/trace_url_handler.ts
@@ -20,6 +20,7 @@ import {Route, Router} from '../core/router'; import {taskTracker} from './task_tracker'; import {AppImpl} from '../core/app_impl'; +import {isTrustedOrigin, saveUserTrustedOrigin} from './post_message_handler'; function getCurrentTraceUrl(): undefined | string { const source = AppImpl.instance.trace?.traceInfo.source; @@ -244,7 +245,17 @@ function promptDataUrlTrust(url: string) { const origin = document.referrer ? new URL(document.referrer).origin : 'null'; - const originTxt = origin === 'null' ? 'An unknown origin' : origin; + const open = () => { + AppImpl.instance.openTraceFromUrl(url); + }; + + if (isTrustedOrigin(origin)) { + open(); + return; + } + + const originUnknown = origin === 'null'; + const originTxt = originUnknown ? 'An unknown origin' : origin; showModal({ title: 'Open trace?', content: m( @@ -254,14 +265,19 @@ ), buttons: [ {text: 'No', primary: true}, - { - text: 'Yes', - primary: false, - action: () => { - AppImpl.instance.openTraceFromUrl(url); - }, - }, - ], + {text: 'Yes', primary: false, action: open}, + ].concat( + originUnknown + ? [] + : { + text: 'Always trust', + primary: false, + action: () => { + saveUserTrustedOrigin(origin); + open(); + }, + }, + ), }); }