Type all URL and path variables in FileManager to Branded Types
Bug: 1299780
Change-Id: I65c083c166ea4e57938f14e4d9ff3b96b2c03083
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3484197
Reviewed-by: Simon Zünd <[email protected]>
Reviewed-by: Eric Leese <[email protected]>
Commit-Queue: Kateryna Prokopenko <[email protected]>
diff --git a/front_end/panels/application/BackgroundServiceView.ts b/front_end/panels/application/BackgroundServiceView.ts
index ee1b2c0..bb3242d 100644
--- a/front_end/panels/application/BackgroundServiceView.ts
+++ b/front_end/panels/application/BackgroundServiceView.ts
@@ -457,7 +457,8 @@
* Saves all currently displayed events in a file (JSON format).
*/
private async saveToFile(): Promise<void> {
- const fileName = `${this.serviceName}-${Platform.DateUtilities.toISO8601Compact(new Date())}.json`;
+ const fileName = `${this.serviceName}-${Platform.DateUtilities.toISO8601Compact(new Date())}.json` as
+ Platform.DevToolsPath.RawPathString;
const stream = new Bindings.FileUtils.FileOutputStream();
const accepted = await stream.open(fileName);
diff --git a/front_end/panels/console/ConsoleView.ts b/front_end/panels/console/ConsoleView.ts
index 66efa5b..907b72a 100644
--- a/front_end/panels/console/ConsoleView.ts
+++ b/front_end/panels/console/ConsoleView.ts
@@ -1076,7 +1076,9 @@
private async saveConsole(): Promise<void> {
const url = (SDK.TargetManager.TargetManager.instance().mainTarget() as SDK.Target.Target).inspectedURL();
const parsedURL = Common.ParsedURL.ParsedURL.fromString(url);
- const filename = Platform.StringUtilities.sprintf('%s-%d.log', parsedURL ? parsedURL.host : 'console', Date.now());
+ const filename =
+ Platform.StringUtilities.sprintf('%s-%d.log', parsedURL ? parsedURL.host : 'console', Date.now()) as
+ Platform.DevToolsPath.RawPathString;
const stream = new Bindings.FileUtils.FileOutputStream();
const progressIndicator = new UI.ProgressIndicator.ProgressIndicator();
diff --git a/front_end/panels/coverage/CoverageView.ts b/front_end/panels/coverage/CoverageView.ts
index f2c9cea..edb8fca 100644
--- a/front_end/panels/coverage/CoverageView.ts
+++ b/front_end/panels/coverage/CoverageView.ts
@@ -506,7 +506,8 @@
private async exportReport(): Promise<void> {
const fos = new Bindings.FileUtils.FileOutputStream();
- const fileName = `Coverage-${Platform.DateUtilities.toISO8601Compact(new Date())}.json`;
+ const fileName =
+ `Coverage-${Platform.DateUtilities.toISO8601Compact(new Date())}.json` as Platform.DevToolsPath.RawPathString;
const accepted = await fos.open(fileName);
if (!accepted) {
return;
diff --git a/front_end/panels/emulation/DeviceModeToolbar.ts b/front_end/panels/emulation/DeviceModeToolbar.ts
index 0192d8d..ce15def 100644
--- a/front_end/panels/emulation/DeviceModeToolbar.ts
+++ b/front_end/panels/emulation/DeviceModeToolbar.ts
@@ -6,6 +6,7 @@
import * as Host from '../../core/host/host.js';
import * as i18n from '../../core/i18n/i18n.js';
import * as Root from '../../core/root/root.js';
+import type * as Platform from '../../core/platform/platform.js';
import * as EmulationModel from '../../models/emulation/emulation.js';
import * as UI from '../../ui/legacy/legacy.js';
import * as MobileThrottling from '../mobile_throttling/mobile_throttling.js';
@@ -389,7 +390,7 @@
private experimentalClicked(): void {
Host.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(
- 'chrome://flags/#enable-experimental-web-platform-features');
+ 'chrome://flags/#enable-experimental-web-platform-features' as Platform.DevToolsPath.UrlString);
}
private fillOptionsToolbar(toolbar: UI.Toolbar.Toolbar): void {
diff --git a/front_end/panels/input/InputTimeline.ts b/front_end/panels/input/InputTimeline.ts
index ec42297..bc8a649 100644
--- a/front_end/panels/input/InputTimeline.ts
+++ b/front_end/panels/input/InputTimeline.ts
@@ -182,7 +182,8 @@
return;
}
- const fileName = `InputProfile-${Platform.DateUtilities.toISO8601Compact(new Date())}.json`;
+ const fileName = `InputProfile-${Platform.DateUtilities.toISO8601Compact(new Date())}.json` as
+ Platform.DevToolsPath.RawPathString;
const stream = new Bindings.FileUtils.FileOutputStream();
const accepted = await stream.open(fileName);
diff --git a/front_end/panels/lighthouse/LighthouseReportRenderer.ts b/front_end/panels/lighthouse/LighthouseReportRenderer.ts
index d341214..f9755b4 100644
--- a/front_end/panels/lighthouse/LighthouseReportRenderer.ts
+++ b/front_end/panels/lighthouse/LighthouseReportRenderer.ts
@@ -184,7 +184,7 @@
const sanitizedDomain = domain.replace(/[^a-z0-9.-]+/gi, '_');
const timestamp = Platform.DateUtilities.toISO8601Compact(new Date(this.json.fetchTime));
const ext = blob.type.match('json') ? '.json' : '.html';
- const basename = `${sanitizedDomain}-${timestamp}${ext}`;
+ const basename = `${sanitizedDomain}-${timestamp}${ext}` as Platform.DevToolsPath.RawPathString;
const text = await blob.text();
void Workspace.FileManager.FileManager.instance().save(basename, text, true /* forceSaveAs */);
}
diff --git a/front_end/panels/network/NetworkLogView.ts b/front_end/panels/network/NetworkLogView.ts
index ebd4121..da7b8c0 100644
--- a/front_end/panels/network/NetworkLogView.ts
+++ b/front_end/panels/network/NetworkLogView.ts
@@ -1673,10 +1673,10 @@
}
const url = mainTarget.inspectedURL();
const parsedURL = Common.ParsedURL.ParsedURL.fromString(url);
- const filename = parsedURL ? parsedURL.host : 'network-log';
+ const filename = (parsedURL ? parsedURL.host : 'network-log') as Platform.DevToolsPath.RawPathString;
const stream = new Bindings.FileUtils.FileOutputStream();
- if (!await stream.open(filename + '.har')) {
+ if (!await stream.open(Common.ParsedURL.ParsedURL.concatenate(filename, '.har'))) {
return;
}
diff --git a/front_end/panels/profiler/HeapSnapshotView.ts b/front_end/panels/profiler/HeapSnapshotView.ts
index 6e2d6e0..e7a08c5 100644
--- a/front_end/panels/profiler/HeapSnapshotView.ts
+++ b/front_end/panels/profiler/HeapSnapshotView.ts
@@ -1557,7 +1557,7 @@
onTempFileReady: (() => void)|null;
failedToCreateTempFile?: boolean;
wasDisposed?: boolean;
- fileName?: string;
+ fileName?: Platform.DevToolsPath.RawPathString;
constructor(
heapProfilerModel: SDK.HeapProfilerModel.HeapProfilerModel|null, type: HeapSnapshotProfileType, title?: string) {
@@ -1713,7 +1713,8 @@
saveToFile(): void {
const fileOutputStream = new Bindings.FileUtils.FileOutputStream();
this.fileName = this.fileName ||
- 'Heap-' + Platform.DateUtilities.toISO8601Compact(new Date()) + this.profileType().fileExtension();
+ 'Heap-' + Platform.DateUtilities.toISO8601Compact(new Date()) + this.profileType().fileExtension() as
+ Platform.DevToolsPath.RawPathString;
const onOpen = async(accepted: boolean): Promise<void> => {
if (!accepted) {
return;
diff --git a/front_end/panels/profiler/ProfileView.ts b/front_end/panels/profiler/ProfileView.ts
index aa62a57..3c02c68 100644
--- a/front_end/panels/profiler/ProfileView.ts
+++ b/front_end/panels/profiler/ProfileView.ts
@@ -549,7 +549,7 @@
export class WritableProfileHeader extends ProfileHeader implements Common.StringOutputStream.OutputStream {
readonly debuggerModel: SDK.DebuggerModel.DebuggerModel|null;
- fileName?: string;
+ fileName?: Platform.DevToolsPath.RawPathString;
jsonifiedProfile?: string|null;
profile?: Protocol.Profiler.Profile;
protocolProfileInternal?: Protocol.Profiler.Profile;
@@ -599,7 +599,7 @@
const now = Platform.DateUtilities.toISO8601Compact(new Date());
const fileExtension = this.profileType().fileExtension();
- this.fileName = `${this.profileType().typeName()}-${now}${fileExtension}`;
+ this.fileName = `${this.profileType().typeName()}-${now}${fileExtension}` as Platform.DevToolsPath.RawPathString;
}
const accepted = await fileOutputStream.open(this.fileName);
diff --git a/front_end/panels/protocol_monitor/ProtocolMonitor.ts b/front_end/panels/protocol_monitor/ProtocolMonitor.ts
index 3f8dee4..11440ec 100644
--- a/front_end/panels/protocol_monitor/ProtocolMonitor.ts
+++ b/front_end/panels/protocol_monitor/ProtocolMonitor.ts
@@ -247,7 +247,8 @@
const [domain, method] = String(methodColumn.value).split('.');
const type = typeColumn.value === 'sent' ? 'method' : 'event';
Host.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(
- `https://chromedevtools.github.io/devtools-protocol/tot/${domain}#${type}-${method}`);
+ `https://chromedevtools.github.io/devtools-protocol/tot/${domain}#${type}-${method}` as
+ Platform.DevToolsPath.UrlString);
});
},
},
@@ -466,7 +467,8 @@
private async saveAsFile(): Promise<void> {
const now = new Date();
- const fileName = 'ProtocolMonitor-' + Platform.DateUtilities.toISO8601Compact(now) + '.json';
+ const fileName = 'ProtocolMonitor-' + Platform.DateUtilities.toISO8601Compact(now) + '.json' as
+ Platform.DevToolsPath.RawPathString;
const stream = new Bindings.FileUtils.FileOutputStream();
const accepted = await stream.open(fileName);
diff --git a/front_end/panels/screencast/ScreencastView.ts b/front_end/panels/screencast/ScreencastView.ts
index d6e02a2..a19eccc 100644
--- a/front_end/panels/screencast/ScreencastView.ts
+++ b/front_end/panels/screencast/ScreencastView.ts
@@ -32,6 +32,7 @@
import * as Host from '../../core/host/host.js';
import * as i18n from '../../core/i18n/i18n.js';
import * as SDK from '../../core/sdk/sdk.js';
+import type * as Platform from '../../core/platform/platform.js';
import * as Protocol from '../../generated/protocol.js';
import * as UI from '../../ui/legacy/legacy.js';
@@ -743,7 +744,9 @@
if (match) {
url = match[1];
}
- Host.InspectorFrontendHost.InspectorFrontendHostInstance.inspectedURLChanged(url);
+ // TODO(crbug.com/1253323): Cast to UrlString will be removed when migration to branded types is complete.
+ Host.InspectorFrontendHost.InspectorFrontendHostInstance.inspectedURLChanged(
+ url as Platform.DevToolsPath.UrlString);
this.navigationUrl.value = decodeURI(url);
}
diff --git a/front_end/panels/settings/SettingsScreen.ts b/front_end/panels/settings/SettingsScreen.ts
index 2c145b7..9f1a307 100644
--- a/front_end/panels/settings/SettingsScreen.ts
+++ b/front_end/panels/settings/SettingsScreen.ts
@@ -32,6 +32,7 @@
import * as Host from '../../core/host/host.js';
import * as i18n from '../../core/i18n/i18n.js';
import * as Root from '../../core/root/root.js';
+import type * as Platform from '../../core/platform/platform.js';
import * as IconButton from '../../ui/components/icon_button/icon_button.js';
import * as Components from '../../ui/legacy/components/utils/utils.js';
import * as UI from '../../ui/legacy/legacy.js';
@@ -508,9 +509,11 @@
case 'settings.show':
void SettingsScreen.showSettingsScreen({focusTabHeader: true} as ShowSettingsScreenOptions);
return true;
+ // TODO(crbug.com/1253323): Cast to UrlString will be removed when migration to branded types is complete.
case 'settings.documentation':
Host.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(
- UI.UIUtils.addReferrerToURL('https://developer.chrome.com/docs/devtools/'));
+ UI.UIUtils.addReferrerToURL('https://developer.chrome.com/docs/devtools/') as
+ Platform.DevToolsPath.UrlString);
return true;
case 'settings.shortcuts':
void SettingsScreen.showSettingsScreen({name: 'keybinds', focusTabHeader: true});
diff --git a/front_end/panels/timeline/TimelinePanel.ts b/front_end/panels/timeline/TimelinePanel.ts
index f0a7564..d064581 100644
--- a/front_end/panels/timeline/TimelinePanel.ts
+++ b/front_end/panels/timeline/TimelinePanel.ts
@@ -636,7 +636,8 @@
}
const now = new Date();
- const fileName = 'Profile-' + Platform.DateUtilities.toISO8601Compact(now) + '.json';
+ const fileName =
+ 'Profile-' + Platform.DateUtilities.toISO8601Compact(now) + '.json' as Platform.DevToolsPath.RawPathString;
const stream = new Bindings.FileUtils.FileOutputStream();
const accepted = await stream.open(fileName);