Skip to content

Commit a702323

Browse files
OrKoNDevtools-frontend LUCI CQ
authored andcommitted
[Recorder] Confirm recording import the first time
Uses the same pattern that is used to confirm pasting. Fixed: 402071098 Bug: 401927528 Change-Id: I1317fa81bff3cb5a17e4923596e10af05350fb82 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6343138 Commit-Queue: Alex Rudenko <[email protected]> Reviewed-by: Wolfgang Beyer <[email protected]>
1 parent 7f154a2 commit a702323

File tree

3 files changed

+68
-4
lines changed

3 files changed

+68
-4
lines changed

front_end/panels/recorder/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ devtools_module("recorder") {
2121
deps = [
2222
"../../core/common:bundle",
2323
"../../core/platform:bundle",
24+
"../../core/root:bundle",
2425
"../../models/extensions:bundle",
2526
"../../models/trace:bundle",
27+
"../../panels/common:bundle",
2628
"../../panels/emulation:bundle",
2729
"../../panels/timeline:bundle",
2830
"../../services/tracing:bundle",

front_end/panels/recorder/RecorderController.ts

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import * as Common from '../../core/common/common.js';
66
import * as Host from '../../core/host/host.js';
77
import * as i18n from '../../core/i18n/i18n.js';
88
import * as Platform from '../../core/platform/platform.js';
9+
import * as Root from '../../core/root/root.js';
910
import * as SDK from '../../core/sdk/sdk.js';
1011
import * as Bindings from '../../models/bindings/bindings.js';
1112
import * as PublicExtensions from '../../models/extensions/extensions.js';
1213
import type * as Trace from '../../models/trace/trace.js';
14+
import * as PanelCommon from '../../panels/common/common.js';
1315
import * as Emulation from '../../panels/emulation/emulation.js';
1416
import * as Timeline from '../../panels/timeline/timeline.js';
1517
import * as Tracing from '../../services/tracing/tracing.js';
@@ -119,7 +121,27 @@ const UIStrings = {
119121
/**
120122
* @description Link text to forward to a documentation page on the recorder.
121123
*/
122-
learnMore: 'Learn more'
124+
learnMore: 'Learn more',
125+
/**
126+
*@description Headline of warning shown to users when users import a recording into DevTools Recorder.
127+
*/
128+
doYouTrustThisCode: 'Do you trust this recording?',
129+
/**
130+
*@description Warning shown to users when imports code into DevTools Recorder.
131+
*@example {allow importing} PH1
132+
*/
133+
doNotImport:
134+
'Don\'t import recordings you do not understand or have not reviewed yourself into DevTools. This could allow attackers to steal your identity or take control of your computer. Please type \'\'{PH1}\'\' below to allow importing.',
135+
/**
136+
*@description Text a user needs to type in order to confirm that they
137+
*are aware of the danger of import code into the DevTools Recorder.
138+
*/
139+
allowImporting: 'allow importing',
140+
/**
141+
*@description Input box placeholder which instructs the user to type 'allow pasing' into the input box.
142+
*@example {allow importing} PH1
143+
*/
144+
typeAllowImporting: 'Type \'\'{PH1}\'\'',
123145
} as const;
124146
const str_ = i18n.i18n.registerUIStrings('panels/recorder/RecorderController.ts', UIStrings);
125147
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
@@ -224,6 +246,11 @@ export class RecorderController extends LitElement {
224246
#recorderSettings = new Models.RecorderSettings.RecorderSettings();
225247
#shortcutHelper = new Models.RecorderShortcutHelper.RecorderShortcutHelper();
226248

249+
#disableRecorderImportWarningSetting = Common.Settings.Settings.instance().createSetting(
250+
'disable-recorder-import-warning', false, Common.Settings.SettingStorageType.SYNCED);
251+
#selfXssWarningDisabledSetting = Common.Settings.Settings.instance().createSetting(
252+
'disable-self-xss-warning', false, Common.Settings.SettingStorageType.SYNCED);
253+
227254
constructor() {
228255
super();
229256

@@ -967,11 +994,43 @@ export class RecorderController extends LitElement {
967994
?.click();
968995
}
969996

970-
#onImportRecording(event: Event): void {
997+
async #acknowledgeImportNotice(): Promise<boolean> {
998+
if (this.#disableRecorderImportWarningSetting.get()) {
999+
return true;
1000+
}
1001+
1002+
if (Root.Runtime.Runtime.queryParam('isChromeForTesting') ||
1003+
Root.Runtime.Runtime.queryParam('disableSelfXssWarnings') || this.#selfXssWarningDisabledSetting.get()) {
1004+
return true;
1005+
}
1006+
1007+
const result = await PanelCommon.TypeToAllowDialog.show({
1008+
jslogContext: {
1009+
input: 'confirm-import-recording-input',
1010+
dialog: 'confirm-import-recording-dialog',
1011+
},
1012+
message: i18nString(UIStrings.doNotImport, {PH1: i18nString(UIStrings.allowImporting)}),
1013+
header: i18nString(UIStrings.doYouTrustThisCode),
1014+
typePhrase: i18nString(UIStrings.allowImporting),
1015+
inputPlaceholder: i18nString(UIStrings.typeAllowImporting, {PH1: i18nString(UIStrings.allowImporting)}),
1016+
});
1017+
1018+
if (result) {
1019+
this.#disableRecorderImportWarningSetting.set(true);
1020+
}
1021+
1022+
return result;
1023+
}
1024+
1025+
async #onImportRecording(event: Event): Promise<void> {
9711026
event.stopPropagation();
1027+
9721028
this.#clearError();
973-
this.#fileSelector = UI.UIUtils.createFileSelectorElement(this.#importFile.bind(this));
974-
this.#fileSelector.click();
1029+
1030+
if (await this.#acknowledgeImportNotice()) {
1031+
this.#fileSelector = UI.UIUtils.createFileSelectorElement(this.#importFile.bind(this));
1032+
this.#fileSelector.click();
1033+
}
9751034
}
9761035

9771036
async #onPlayRecordingByName(event: Components.RecordingListView.PlayRecordingEvent): Promise<void> {

front_end/ui/visual_logging/KnownContextValues.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,8 @@ export const knownContextValues = new Set([
791791
'conditional-breakpoint',
792792
'configure',
793793
'confirm',
794+
'confirm-import-recording-dialog',
795+
'confirm-import-recording-input',
794796
'connection',
795797
'connection-id',
796798
'consent-onboarding',
@@ -1196,6 +1198,7 @@ export const knownContextValues = new Set([
11961198
'disable-file-breakpoints',
11971199
'disable-locale-info-bar',
11981200
'disable-paused-state-overlay',
1201+
'disable-recorder-import-warning',
11991202
'disable-self-xss-warning',
12001203
'disabled',
12011204
'disallowed-select-descendants-details',

0 commit comments

Comments
 (0)