chrome-devtools-frontend 1.0.980193 → 1.0.981004

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/front_end/core/common/ParsedURL.ts +37 -4
  2. package/front_end/core/platform/DevToolsPath.ts +3 -0
  3. package/front_end/core/sdk/CSSRule.ts +2 -2
  4. package/front_end/core/sdk/DOMDebuggerModel.ts +2 -2
  5. package/front_end/core/sdk/NetworkRequest.ts +1 -1
  6. package/front_end/core/sdk/SourceMap.ts +14 -5
  7. package/front_end/core/sdk/Target.ts +2 -2
  8. package/front_end/entrypoints/formatter_worker/FormatterWorker.ts +26 -17
  9. package/front_end/legacy_test_runner/bindings_test_runner/BindingsTestRunner.js +5 -0
  10. package/front_end/models/bindings/BreakpointManager.ts +0 -2
  11. package/front_end/models/bindings/ContentProviderBasedProject.ts +6 -4
  12. package/front_end/models/persistence/EditFileSystemView.ts +3 -1
  13. package/front_end/models/persistence/FileSystemWorkspaceBinding.ts +14 -9
  14. package/front_end/models/persistence/IsolatedFileSystem.ts +66 -40
  15. package/front_end/models/persistence/IsolatedFileSystemManager.ts +4 -3
  16. package/front_end/models/persistence/NetworkPersistenceManager.ts +6 -5
  17. package/front_end/models/persistence/PlatformFileSystem.ts +15 -10
  18. package/front_end/models/workspace/UISourceCode.ts +4 -2
  19. package/front_end/models/workspace/WorkspaceImpl.ts +9 -5
  20. package/front_end/panels/application/ServiceWorkerCacheViews.ts +1 -1
  21. package/front_end/panels/network/ResourceWebSocketFrameView.ts +1 -2
  22. package/front_end/panels/snippets/ScriptSnippetFileSystem.ts +25 -19
  23. package/front_end/panels/sources/NavigatorView.ts +9 -5
  24. package/front_end/panels/sources/SourcesNavigator.ts +2 -2
  25. package/front_end/ui/components/buttons/Button.ts +11 -1
  26. package/front_end/ui/components/buttons/button.css +31 -10
  27. package/front_end/ui/components/docs/button/basic.ts +47 -1
  28. package/front_end/ui/legacy/themeColors.css +4 -0
  29. package/package.json +1 -1
@@ -70,17 +70,19 @@ const str_ = i18n.i18n.registerUIStrings('models/persistence/IsolatedFileSystem.
70
70
  const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
71
71
  export class IsolatedFileSystem extends PlatformFileSystem {
72
72
  private readonly manager: IsolatedFileSystemManager;
73
- private readonly embedderPathInternal: string;
73
+ private readonly embedderPathInternal: Platform.DevToolsPath.RawPathString;
74
74
  private readonly domFileSystem: FileSystem;
75
- private readonly excludedFoldersSetting: Common.Settings.Setting<{[path: string]: string[]}>;
76
- private excludedFoldersInternal: Set<string>;
77
- private readonly excludedEmbedderFolders: string[];
75
+ private readonly excludedFoldersSetting:
76
+ Common.Settings.Setting<{[path: Platform.DevToolsPath.UrlString]: Platform.DevToolsPath.EncodedPathString[]}>;
77
+ private excludedFoldersInternal: Set<Platform.DevToolsPath.EncodedPathString>;
78
+ private readonly excludedEmbedderFolders: Platform.DevToolsPath.RawPathString[];
78
79
  private readonly initialFilePathsInternal: Set<Platform.DevToolsPath.EncodedPathString>;
79
80
  private readonly initialGitFoldersInternal: Set<Platform.DevToolsPath.EncodedPathString>;
80
- private readonly fileLocks: Map<string, Promise<void>>;
81
+ private readonly fileLocks: Map<Platform.DevToolsPath.EncodedPathString, Promise<void>>;
81
82
 
82
83
  constructor(
83
- manager: IsolatedFileSystemManager, path: string, embedderPath: string, domFileSystem: FileSystem, type: string) {
84
+ manager: IsolatedFileSystemManager, path: Platform.DevToolsPath.UrlString,
85
+ embedderPath: Platform.DevToolsPath.RawPathString, domFileSystem: FileSystem, type: string) {
84
86
  super(path, type);
85
87
  this.manager = manager;
86
88
  this.embedderPathInternal = embedderPath;
@@ -96,7 +98,8 @@ export class IsolatedFileSystem extends PlatformFileSystem {
96
98
  }
97
99
 
98
100
  static async create(
99
- manager: IsolatedFileSystemManager, path: string, embedderPath: string, type: string, name: string,
101
+ manager: IsolatedFileSystemManager, path: Platform.DevToolsPath.UrlString,
102
+ embedderPath: Platform.DevToolsPath.RawPathString, type: string, name: string,
100
103
  rootURL: string): Promise<IsolatedFileSystem|null> {
101
104
  const domFileSystem = Host.InspectorFrontendHost.InspectorFrontendHostInstance.isolatedFileSystem(name, rootURL);
102
105
  if (!domFileSystem) {
@@ -115,18 +118,20 @@ export class IsolatedFileSystem extends PlatformFileSystem {
115
118
  return i18nString(UIStrings.fileSystemErrorS, {PH1: error.message});
116
119
  }
117
120
 
118
- private serializedFileOperation<T>(path: string, operation: () => Promise<T>): Promise<T> {
121
+ private serializedFileOperation<T>(path: Platform.DevToolsPath.EncodedPathString, operation: () => Promise<T>):
122
+ Promise<T> {
119
123
  const promise = Promise.resolve(this.fileLocks.get(path)).then(() => operation.call(null));
120
124
  this.fileLocks.set(path, promise as unknown as Promise<void>);
121
125
  return promise;
122
126
  }
123
127
 
124
- getMetadata(path: string): Promise<Metadata|null> {
128
+ getMetadata(path: Platform.DevToolsPath.EncodedPathString): Promise<Metadata|null> {
125
129
  let fulfill: (arg0: Metadata|null) => void;
126
130
  const promise = new Promise<Metadata|null>(f => {
127
131
  fulfill = f;
128
132
  });
129
- this.domFileSystem.root.getFile(decodeURIComponent(path), undefined, fileEntryLoaded, errorHandler);
133
+ this.domFileSystem.root.getFile(
134
+ Common.ParsedURL.ParsedURL.encodedPathToRawPathString(path), undefined, fileEntryLoaded, errorHandler);
130
135
  return promise;
131
136
 
132
137
  function fileEntryLoaded(entry: FileEntry): void {
@@ -148,7 +153,7 @@ export class IsolatedFileSystem extends PlatformFileSystem {
148
153
  return [...this.initialGitFoldersInternal];
149
154
  }
150
155
 
151
- embedderPath(): string {
156
+ embedderPath(): Platform.DevToolsPath.RawPathString {
152
157
  return this.embedderPathInternal;
153
158
  }
154
159
 
@@ -156,13 +161,14 @@ export class IsolatedFileSystem extends PlatformFileSystem {
156
161
  return new Promise(fulfill => {
157
162
  let pendingRequests = 1;
158
163
  const boundInnerCallback = innerCallback.bind(this);
159
- this.requestEntries('', boundInnerCallback);
164
+ this.requestEntries(Platform.DevToolsPath.EmptyRawPathString, boundInnerCallback);
160
165
 
161
166
  function innerCallback(this: IsolatedFileSystem, entries: FileEntry[]): void {
162
167
  for (let i = 0; i < entries.length; ++i) {
163
168
  const entry = entries[i];
164
169
  if (!entry.isDirectory) {
165
- if (this.isFileExcluded(entry.fullPath)) {
170
+ if (this.isFileExcluded(Common.ParsedURL.ParsedURL.rawPathToEncodedPathString(
171
+ entry.fullPath as Platform.DevToolsPath.RawPathString))) {
166
172
  continue;
167
173
  }
168
174
  this.initialFilePathsInternal.add(Common.ParsedURL.ParsedURL.rawPathToEncodedPathString(
@@ -174,14 +180,20 @@ export class IsolatedFileSystem extends PlatformFileSystem {
174
180
  entry.fullPath as Platform.DevToolsPath.RawPathString, 1, lastSlash);
175
181
  this.initialGitFoldersInternal.add(Common.ParsedURL.ParsedURL.rawPathToEncodedPathString(parentFolder));
176
182
  }
177
- if (this.isFileExcluded(entry.fullPath + '/')) {
178
- const url = Common.ParsedURL.ParsedURL.concatenate(this.path(), entry.fullPath);
183
+ if (this.isFileExcluded(Common.ParsedURL.ParsedURL.concatenate(
184
+ Common.ParsedURL.ParsedURL.rawPathToEncodedPathString(
185
+ entry.fullPath as Platform.DevToolsPath.RawPathString),
186
+ '/'))) {
187
+ const url = Common.ParsedURL.ParsedURL.concatenate(
188
+ this.path(),
189
+ Common.ParsedURL.ParsedURL.rawPathToEncodedPathString(
190
+ entry.fullPath as Platform.DevToolsPath.RawPathString));
179
191
  this.excludedEmbedderFolders.push(
180
192
  Common.ParsedURL.ParsedURL.urlToRawPathString(url, Host.Platform.isWin()));
181
193
  continue;
182
194
  }
183
195
  ++pendingRequests;
184
- this.requestEntries(entry.fullPath, boundInnerCallback);
196
+ this.requestEntries(entry.fullPath as Platform.DevToolsPath.RawPathString, boundInnerCallback);
185
197
  }
186
198
  }
187
199
  if ((--pendingRequests === 0)) {
@@ -191,7 +203,7 @@ export class IsolatedFileSystem extends PlatformFileSystem {
191
203
  });
192
204
  }
193
205
 
194
- private async createFoldersIfNotExist(folderPath: string): Promise<DirectoryEntry|null> {
206
+ private async createFoldersIfNotExist(folderPath: Platform.DevToolsPath.RawPathString): Promise<DirectoryEntry|null> {
195
207
  // Fast-path. If parent directory already exists we return it immidiatly.
196
208
  let dirEntry = await new Promise<DirectoryEntry|null>(
197
209
  resolve => this.domFileSystem.root.getDirectory(folderPath, undefined, resolve, () => resolve(null)));
@@ -220,13 +232,17 @@ export class IsolatedFileSystem extends PlatformFileSystem {
220
232
  });
221
233
  }
222
234
 
223
- async createFile(path: string, name: string|null): Promise<string|null> {
224
- const dirEntry = await this.createFoldersIfNotExist(decodeURIComponent(path));
235
+ async createFile(path: Platform.DevToolsPath.EncodedPathString, name: Platform.DevToolsPath.RawPathString|null):
236
+ Promise<Platform.DevToolsPath.EncodedPathString|null> {
237
+ const dirEntry = await this.createFoldersIfNotExist(Common.ParsedURL.ParsedURL.encodedPathToRawPathString(path));
225
238
  if (!dirEntry) {
226
239
  return null;
227
240
  }
228
241
  const fileEntry =
229
- await this.serializedFileOperation(path, createFileCandidate.bind(this, name || 'NewFile')) as FileEntry | null;
242
+ await this.serializedFileOperation(
243
+ path, createFileCandidate.bind(this, name || 'NewFile' as Platform.DevToolsPath.RawPathString)) as
244
+ FileEntry |
245
+ null;
230
246
  if (!fileEntry) {
231
247
  return null;
232
248
  }
@@ -234,9 +250,10 @@ export class IsolatedFileSystem extends PlatformFileSystem {
234
250
  Common.ParsedURL.ParsedURL.substr(fileEntry.fullPath as Platform.DevToolsPath.RawPathString, 1));
235
251
 
236
252
  function createFileCandidate(
237
- this: IsolatedFileSystem, name: string, newFileIndex?: number): Promise<FileEntry|null> {
253
+ this: IsolatedFileSystem, name: Platform.DevToolsPath.RawPathString,
254
+ newFileIndex?: number): Promise<FileEntry|null> {
238
255
  return new Promise(resolve => {
239
- const nameCandidate = name + (newFileIndex || '');
256
+ const nameCandidate = Common.ParsedURL.ParsedURL.concatenate(name, (newFileIndex || '').toString());
240
257
  (dirEntry as DirectoryEntry).getFile(nameCandidate, {create: true, exclusive: true}, resolve, error => {
241
258
  if (error.name === 'InvalidModificationError') {
242
259
  resolve(createFileCandidate.call(this, name, (newFileIndex ? newFileIndex + 1 : 1)));
@@ -252,13 +269,14 @@ export class IsolatedFileSystem extends PlatformFileSystem {
252
269
  }
253
270
  }
254
271
 
255
- deleteFile(path: string): Promise<boolean> {
272
+ deleteFile(path: Platform.DevToolsPath.EncodedPathString): Promise<boolean> {
256
273
  let resolveCallback: (arg0: boolean) => void;
257
274
  const promise = new Promise<boolean>(resolve => {
258
275
  resolveCallback = resolve;
259
276
  });
260
277
  this.domFileSystem.root.getFile(
261
- decodeURIComponent(path), undefined, fileEntryLoaded.bind(this), errorHandler.bind(this));
278
+ Common.ParsedURL.ParsedURL.encodedPathToRawPathString(path), undefined, fileEntryLoaded.bind(this),
279
+ errorHandler.bind(this));
262
280
  return promise;
263
281
 
264
282
  function fileEntryLoaded(this: IsolatedFileSystem, fileEntry: FileEntry): void {
@@ -279,9 +297,9 @@ export class IsolatedFileSystem extends PlatformFileSystem {
279
297
  }
280
298
  }
281
299
 
282
- requestFileBlob(path: string): Promise<Blob|null> {
300
+ requestFileBlob(path: Platform.DevToolsPath.EncodedPathString): Promise<Blob|null> {
283
301
  return new Promise(resolve => {
284
- this.domFileSystem.root.getFile(decodeURIComponent(path), undefined, entry => {
302
+ this.domFileSystem.root.getFile(Common.ParsedURL.ParsedURL.encodedPathToRawPathString(path), undefined, entry => {
285
303
  entry.file(resolve, errorHandler.bind(this));
286
304
  }, errorHandler.bind(this));
287
305
 
@@ -298,11 +316,13 @@ export class IsolatedFileSystem extends PlatformFileSystem {
298
316
  });
299
317
  }
300
318
 
301
- requestFileContent(path: string): Promise<TextUtils.ContentProvider.DeferredContent> {
319
+ requestFileContent(path: Platform.DevToolsPath.EncodedPathString):
320
+ Promise<TextUtils.ContentProvider.DeferredContent> {
302
321
  return this.serializedFileOperation(path, () => this.innerRequestFileContent(path));
303
322
  }
304
323
 
305
- private async innerRequestFileContent(path: string): Promise<TextUtils.ContentProvider.DeferredContent> {
324
+ private async innerRequestFileContent(path: Platform.DevToolsPath.EncodedPathString):
325
+ Promise<TextUtils.ContentProvider.DeferredContent> {
306
326
  const blob = await this.requestFileBlob(path);
307
327
  if (!blob) {
308
328
  return {content: null, error: i18nString(UIStrings.blobCouldNotBeLoaded), isEncoded: false};
@@ -341,7 +361,8 @@ export class IsolatedFileSystem extends PlatformFileSystem {
341
361
  return {isEncoded: encoded, content: encoded ? btoa(result) : result};
342
362
  }
343
363
 
344
- async setFileContent(path: string, content: string, isBase64: boolean): Promise<void> {
364
+ async setFileContent(path: Platform.DevToolsPath.EncodedPathString, content: string, isBase64: boolean):
365
+ Promise<void> {
345
366
  Host.userMetrics.actionTaken(Host.UserMetrics.Action.FileSavedInWorkspace);
346
367
  let callback: (event?: ProgressEvent<EventTarget>) => void;
347
368
  const innerSetFileContent = (): Promise<ProgressEvent<EventTarget>> => {
@@ -350,7 +371,8 @@ export class IsolatedFileSystem extends PlatformFileSystem {
350
371
  callback = x;
351
372
  });
352
373
  this.domFileSystem.root.getFile(
353
- decodeURIComponent(path), {create: true}, fileEntryLoaded.bind(this), errorHandler.bind(this));
374
+ Common.ParsedURL.ParsedURL.encodedPathToRawPathString(path), {create: true}, fileEntryLoaded.bind(this),
375
+ errorHandler.bind(this));
354
376
  return promise;
355
377
  };
356
378
 
@@ -385,8 +407,10 @@ export class IsolatedFileSystem extends PlatformFileSystem {
385
407
  }
386
408
  }
387
409
 
388
- renameFile(path: string, newName: string, callback: (arg0: boolean, arg1?: string|undefined) => void): void {
389
- newName = newName ? newName.trim() : newName;
410
+ renameFile(
411
+ path: Platform.DevToolsPath.EncodedPathString, newName: Platform.DevToolsPath.RawPathString,
412
+ callback: (arg0: boolean, arg1?: string|undefined) => void): void {
413
+ newName = newName ? Common.ParsedURL.ParsedURL.trim(newName) : newName;
390
414
  if (!newName || newName.indexOf('/') !== -1) {
391
415
  callback(false);
392
416
  return;
@@ -395,7 +419,8 @@ export class IsolatedFileSystem extends PlatformFileSystem {
395
419
  let dirEntry: DirectoryEntry;
396
420
 
397
421
  this.domFileSystem.root.getFile(
398
- decodeURIComponent(path), undefined, fileEntryLoaded.bind(this), errorHandler.bind(this));
422
+ Common.ParsedURL.ParsedURL.encodedPathToRawPathString(path), undefined, fileEntryLoaded.bind(this),
423
+ errorHandler.bind(this));
399
424
 
400
425
  function fileEntryLoaded(this: IsolatedFileSystem, entry: FileEntry): void {
401
426
  if (entry.name === newName) {
@@ -461,8 +486,8 @@ export class IsolatedFileSystem extends PlatformFileSystem {
461
486
  }
462
487
  }
463
488
 
464
- private requestEntries(path: string, callback: (arg0: Array<FileEntry>) => void): void {
465
- this.domFileSystem.root.getDirectory(decodeURIComponent(path), undefined, innerCallback.bind(this), errorHandler);
489
+ private requestEntries(path: Platform.DevToolsPath.RawPathString, callback: (arg0: Array<FileEntry>) => void): void {
490
+ this.domFileSystem.root.getDirectory(path, undefined, innerCallback.bind(this), errorHandler);
466
491
 
467
492
  function innerCallback(this: IsolatedFileSystem, dirEntry: DirectoryEntry): void {
468
493
  this.readDirectory(dirEntry, callback);
@@ -481,13 +506,13 @@ export class IsolatedFileSystem extends PlatformFileSystem {
481
506
  this.excludedFoldersSetting.set(settingValue);
482
507
  }
483
508
 
484
- addExcludedFolder(path: string): void {
509
+ addExcludedFolder(path: Platform.DevToolsPath.EncodedPathString): void {
485
510
  this.excludedFoldersInternal.add(path);
486
511
  this.saveExcludedFolders();
487
512
  this.manager.dispatchEventToListeners(Events.ExcludedFolderAdded, path);
488
513
  }
489
514
 
490
- removeExcludedFolder(path: string): void {
515
+ removeExcludedFolder(path: Platform.DevToolsPath.EncodedPathString): void {
491
516
  this.excludedFoldersInternal.delete(path);
492
517
  this.saveExcludedFolders();
493
518
  this.manager.dispatchEventToListeners(Events.ExcludedFolderRemoved, path);
@@ -499,12 +524,12 @@ export class IsolatedFileSystem extends PlatformFileSystem {
499
524
  this.excludedFoldersSetting.set(settingValue);
500
525
  }
501
526
 
502
- isFileExcluded(folderPath: string): boolean {
527
+ isFileExcluded(folderPath: Platform.DevToolsPath.EncodedPathString): boolean {
503
528
  if (this.excludedFoldersInternal.has(folderPath)) {
504
529
  return true;
505
530
  }
506
531
  const regex = (this.manager.workspaceFolderExcludePatternSetting() as Common.Settings.RegExpSetting).asRegExp();
507
- return Boolean(regex && regex.test(folderPath));
532
+ return Boolean(regex && regex.test(Common.ParsedURL.ParsedURL.encodedPathToRawPathString(folderPath)));
508
533
  }
509
534
 
510
535
  excludedFolders(): Set<string> {
@@ -535,10 +560,11 @@ export class IsolatedFileSystem extends PlatformFileSystem {
535
560
  return Common.ResourceType.ResourceType.mimeFromURL(path) || 'text/plain';
536
561
  }
537
562
 
538
- canExcludeFolder(path: string): boolean {
563
+ canExcludeFolder(path: Platform.DevToolsPath.EncodedPathString): boolean {
539
564
  return Boolean(path) && this.type() !== 'overrides';
540
565
  }
541
566
 
567
+ // path not typed as Branded Types as here we are interested in extention only
542
568
  contentType(path: string): Common.ResourceType.ResourceType {
543
569
  const extension = Common.ParsedURL.ParsedURL.extractExtension(path);
544
570
  if (STYLE_SHEET_EXTENSIONS.has(extension)) {
@@ -248,7 +248,8 @@ export class IsolatedFileSystemManager extends Common.ObjectWrapper.ObjectWrappe
248
248
  const filePath = Common.ParsedURL.ParsedURL.rawPathToUrlString(embedderPath);
249
249
  for (const fileSystemPath of this.fileSystemsInternal.keys()) {
250
250
  const fileSystem = this.fileSystemsInternal.get(fileSystemPath);
251
- if (fileSystem && fileSystem.isFileExcluded(embedderPath)) {
251
+ if (fileSystem &&
252
+ fileSystem.isFileExcluded(Common.ParsedURL.ParsedURL.rawPathToEncodedPathString(embedderPath))) {
252
253
  continue;
253
254
  }
254
255
  const pathPrefix = fileSystemPath.endsWith('/') ? fileSystemPath : fileSystemPath + '/';
@@ -348,8 +349,8 @@ export type EventTypes = {
348
349
  [Events.FileSystemAdded]: PlatformFileSystem,
349
350
  [Events.FileSystemRemoved]: PlatformFileSystem,
350
351
  [Events.FileSystemFilesChanged]: FilesChangedData,
351
- [Events.ExcludedFolderAdded]: string,
352
- [Events.ExcludedFolderRemoved]: string,
352
+ [Events.ExcludedFolderAdded]: Platform.DevToolsPath.EncodedPathString,
353
+ [Events.ExcludedFolderRemoved]: Platform.DevToolsPath.EncodedPathString,
353
354
  };
354
355
 
355
356
  let lastRequestId = 0;
@@ -185,9 +185,9 @@ export class NetworkPersistenceManager extends Common.ObjectWrapper.ObjectWrappe
185
185
  PersistenceImpl.instance().refreshAutomapping();
186
186
  }
187
187
 
188
- private encodedPathFromUrl(url: string): string {
188
+ private encodedPathFromUrl(url: Platform.DevToolsPath.UrlString): Platform.DevToolsPath.EncodedPathString {
189
189
  if (!this.activeInternal || !this.projectInternal) {
190
- return '';
190
+ return Platform.DevToolsPath.EmptyEncodedPathString;
191
191
  }
192
192
  let urlPath = Common.ParsedURL.ParsedURL.urlWithoutHash(url.replace(/^https?:\/\//, ''));
193
193
  if (urlPath.endsWith('/') && urlPath.indexOf('?') === -1) {
@@ -208,7 +208,7 @@ export class NetworkPersistenceManager extends Common.ObjectWrapper.ObjectWrappe
208
208
  shortFileName + Platform.StringUtilities.hashCode(encodedPath).toString(16) + extensionPart,
209
209
  ];
210
210
  }
211
- return encodedPathParts.join('/');
211
+ return Common.ParsedURL.ParsedURL.join(encodedPathParts as Platform.DevToolsPath.EncodedPathString[], '/');
212
212
 
213
213
  function encodeUrlPathToLocalPathParts(urlPath: string): string[] {
214
214
  const encodedParts = [];
@@ -310,7 +310,7 @@ export class NetworkPersistenceManager extends Common.ObjectWrapper.ObjectWrappe
310
310
  const encoded = await uiSourceCode.contentEncoded();
311
311
  const lastIndexOfSlash = encodedPath.lastIndexOf('/');
312
312
  const encodedFileName = encodedPath.substr(lastIndexOfSlash + 1);
313
- encodedPath = encodedPath.substr(0, lastIndexOfSlash);
313
+ encodedPath = Common.ParsedURL.ParsedURL.substr(encodedPath, 0, lastIndexOfSlash);
314
314
  if (this.projectInternal) {
315
315
  await this.projectInternal.createFile(encodedPath, encodedFileName, content, encoded);
316
316
  }
@@ -555,7 +555,8 @@ export class NetworkPersistenceManager extends Common.ObjectWrapper.ObjectWrappe
555
555
 
556
556
  handleHeaderInterception(interceptedRequest: SDK.NetworkManager.InterceptedRequest): Protocol.Fetch.HeaderEntry[] {
557
557
  let result: Protocol.Fetch.HeaderEntry[] = interceptedRequest.responseHeaders || [];
558
- const urlSegments = this.encodedPathFromUrl(interceptedRequest.request.url).split('/');
558
+ const urlSegments =
559
+ this.encodedPathFromUrl(interceptedRequest.request.url as Platform.DevToolsPath.UrlString).split('/');
559
560
  // Traverse the hierarchy of overrides from the most general to the most
560
561
  // specific. Check with empty string first to match overrides applying to
561
562
  // all domains.
@@ -23,7 +23,7 @@ export class PlatformFileSystem {
23
23
  this.typeInternal = type;
24
24
  }
25
25
 
26
- getMetadata(_path: string): Promise<{modificationTime: Date, size: number}|null> {
26
+ getMetadata(_path: Platform.DevToolsPath.EncodedPathString): Promise<{modificationTime: Date, size: number}|null> {
27
27
  return Promise.resolve(null);
28
28
  }
29
29
 
@@ -36,6 +36,7 @@ export class PlatformFileSystem {
36
36
  }
37
37
 
38
38
  path(): Platform.DevToolsPath.UrlString {
39
+ // TODO(crbug.com/1297535): Cast to UrlString will be removed when migration to branded types is complete.
39
40
  return this.pathInternal as Platform.DevToolsPath.UrlString;
40
41
  }
41
42
 
@@ -48,31 +49,35 @@ export class PlatformFileSystem {
48
49
  return this.typeInternal;
49
50
  }
50
51
 
51
- async createFile(_path: string, _name: string|null): Promise<string|null> {
52
+ async createFile(_path: Platform.DevToolsPath.EncodedPathString, _name: Platform.DevToolsPath.RawPathString|null):
53
+ Promise<Platform.DevToolsPath.EncodedPathString|null> {
52
54
  return Promise.resolve(null);
53
55
  }
54
56
 
55
- deleteFile(_path: string): Promise<boolean> {
57
+ deleteFile(_path: Platform.DevToolsPath.EncodedPathString): Promise<boolean> {
56
58
  return Promise.resolve(false);
57
59
  }
58
60
 
59
- requestFileBlob(_path: string): Promise<Blob|null> {
61
+ requestFileBlob(_path: Platform.DevToolsPath.EncodedPathString): Promise<Blob|null> {
60
62
  return Promise.resolve(null as Blob | null);
61
63
  }
62
64
 
63
- async requestFileContent(_path: string): Promise<TextUtils.ContentProvider.DeferredContent> {
65
+ async requestFileContent(_path: Platform.DevToolsPath.EncodedPathString):
66
+ Promise<TextUtils.ContentProvider.DeferredContent> {
64
67
  return {content: null, error: i18nString(UIStrings.unableToReadFilesWithThis), isEncoded: false};
65
68
  }
66
69
 
67
- setFileContent(_path: string, _content: string, _isBase64: boolean): void {
70
+ setFileContent(_path: Platform.DevToolsPath.EncodedPathString, _content: string, _isBase64: boolean): void {
68
71
  throw new Error('Not implemented');
69
72
  }
70
73
 
71
- renameFile(_path: string, _newName: string, callback: (arg0: boolean, arg1?: string|undefined) => void): void {
74
+ renameFile(
75
+ _path: Platform.DevToolsPath.EncodedPathString, _newName: Platform.DevToolsPath.RawPathString,
76
+ callback: (arg0: boolean, arg1?: string|undefined) => void): void {
72
77
  callback(false);
73
78
  }
74
79
 
75
- addExcludedFolder(_path: string): void {
80
+ addExcludedFolder(_path: Platform.DevToolsPath.EncodedPathString): void {
76
81
  }
77
82
 
78
83
  removeExcludedFolder(_path: string): void {
@@ -81,7 +86,7 @@ export class PlatformFileSystem {
81
86
  fileSystemRemoved(): void {
82
87
  }
83
88
 
84
- isFileExcluded(_folderPath: string): boolean {
89
+ isFileExcluded(_folderPath: Platform.DevToolsPath.EncodedPathString): boolean {
85
90
  return false;
86
91
  }
87
92
 
@@ -103,7 +108,7 @@ export class PlatformFileSystem {
103
108
  throw new Error('Not implemented');
104
109
  }
105
110
 
106
- canExcludeFolder(_path: string): boolean {
111
+ canExcludeFolder(_path: Platform.DevToolsPath.EncodedPathString): boolean {
107
112
  return false;
108
113
  }
109
114
 
@@ -51,6 +51,8 @@ const UIStrings = {
51
51
  const str_ = i18n.i18n.registerUIStrings('models/workspace/UISourceCode.ts', UIStrings);
52
52
  const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
53
53
 
54
+ // TODO(crbug.com/1297535): Casts to UrlString and RawPathString will be removed from this file when migration to branded types is complete.
55
+
54
56
  export class UISourceCode extends Common.ObjectWrapper.ObjectWrapper<EventTypes> implements
55
57
  TextUtils.ContentProvider.ContentProvider {
56
58
  private projectInternal: Project;
@@ -92,7 +94,7 @@ export class UISourceCode extends Common.ObjectWrapper.ObjectWrapper<EventTypes>
92
94
  }
93
95
  } else {
94
96
  this.originInternal = '';
95
- this.parentURLInternal = '' as Platform.DevToolsPath.UrlString;
97
+ this.parentURLInternal = Platform.DevToolsPath.EmptyUrlString;
96
98
  this.nameInternal = url;
97
99
  }
98
100
 
@@ -150,7 +152,7 @@ export class UISourceCode extends Common.ObjectWrapper.ObjectWrapper<EventTypes>
150
152
  return this.projectInternal.canRename();
151
153
  }
152
154
 
153
- rename(newName: string): Promise<boolean> {
155
+ rename(newName: Platform.DevToolsPath.RawPathString): Promise<boolean> {
154
156
  let fulfill: (arg0: boolean) => void;
155
157
  const promise = new Promise<boolean>(x => {
156
158
  fulfill = x;
@@ -29,6 +29,7 @@
29
29
  */
30
30
 
31
31
  import * as Common from '../../core/common/common.js';
32
+ import type * as Platform from '../../core/platform/platform.js';
32
33
  import type * as TextUtils from '../text_utils/text_utils.js';
33
34
 
34
35
  import type {UISourceCodeMetadata} from './UISourceCode.js';
@@ -56,11 +57,12 @@ export interface Project {
56
57
  mimeType(uiSourceCode: UISourceCode): string;
57
58
  canRename(): boolean;
58
59
  rename(
59
- uiSourceCode: UISourceCode, newName: string,
60
+ uiSourceCode: UISourceCode, newName: Platform.DevToolsPath.RawPathString,
60
61
  callback: (arg0: boolean, arg1?: string, arg2?: string, arg3?: Common.ResourceType.ResourceType) => void): void;
61
62
  excludeFolder(path: string): void;
62
- canExcludeFolder(path: string): boolean;
63
- createFile(path: string, name: string|null, content: string, isBase64?: boolean): Promise<UISourceCode|null>;
63
+ canExcludeFolder(path: Platform.DevToolsPath.EncodedPathString): boolean;
64
+ createFile(path: Platform.DevToolsPath.EncodedPathString, name: string|null, content: string, isBase64?: boolean):
65
+ Promise<UISourceCode|null>;
64
66
  canCreateFile(): boolean;
65
67
  deleteFile(uiSourceCode: UISourceCode): void;
66
68
  remove(): void;
@@ -209,8 +211,10 @@ export abstract class ProjectStore implements Project {
209
211
  abstract fullDisplayName(uiSourceCode: UISourceCode): string;
210
212
  abstract mimeType(uiSourceCode: UISourceCode): string;
211
213
  abstract canRename(): boolean;
212
- abstract canExcludeFolder(path: string): boolean;
213
- abstract createFile(path: string, name: string|null, content: string, isBase64?: boolean): Promise<UISourceCode|null>;
214
+ abstract canExcludeFolder(path: Platform.DevToolsPath.EncodedPathString): boolean;
215
+ abstract createFile(
216
+ path: Platform.DevToolsPath.EncodedPathString, name: string|null, content: string,
217
+ isBase64?: boolean): Promise<UISourceCode|null>;
214
218
  abstract canCreateFile(): boolean;
215
219
  abstract searchInFileContent(uiSourceCode: UISourceCode, query: string, caseSensitive: boolean, isRegex: boolean):
216
220
  Promise<TextUtils.ContentProvider.SearchMatch[]>;
@@ -382,7 +382,7 @@ export class ServiceWorkerCacheView extends UI.View.SimpleView {
382
382
  private createRequest(entry: Protocol.CacheStorage.DataEntry): SDK.NetworkRequest.NetworkRequest {
383
383
  const request = SDK.NetworkRequest.NetworkRequest.createWithoutBackendRequest(
384
384
  'cache-storage-' + entry.requestURL, entry.requestURL as Platform.DevToolsPath.UrlString,
385
- '' as Platform.DevToolsPath.UrlString, null);
385
+ Platform.DevToolsPath.EmptyUrlString, null);
386
386
  request.requestMethod = entry.requestMethod;
387
387
  request.setRequestHeaders(entry.requestHeaders);
388
388
  request.statusCode = entry.responseStatus;
@@ -462,8 +462,7 @@ export class ResourceWebSocketFrameNode extends DataGrid.SortableDataGrid.Sortab
462
462
  if (!this.binaryViewInternal) {
463
463
  if (this.dataTextInternal.length > 0) {
464
464
  this.binaryViewInternal = new BinaryResourceView(
465
- this.dataTextInternal, /* url */ '' as Platform.DevToolsPath.UrlString,
466
- Common.ResourceType.resourceTypes.WebSocket);
465
+ this.dataTextInternal, Platform.DevToolsPath.EmptyUrlString, Common.ResourceType.resourceTypes.WebSocket);
467
466
  }
468
467
  }
469
468
  return this.binaryViewInternal;
@@ -13,8 +13,6 @@ import type * as TextUtils from '../../models/text_utils/text_utils.js';
13
13
  import * as UI from '../../ui/legacy/legacy.js';
14
14
  import * as Workspace from '../../models/workspace/workspace.js';
15
15
 
16
- // TODO(crbug.com/1253323): Cast to EncodedPathString will be removed from this file when migration to branded types is complete.
17
-
18
16
  const UIStrings = {
19
17
  /**
20
18
  *@description Default snippet name when a new snippet is created in the Sources panel
@@ -30,12 +28,12 @@ const UIStrings = {
30
28
  const str_ = i18n.i18n.registerUIStrings('panels/snippets/ScriptSnippetFileSystem.ts', UIStrings);
31
29
  const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
32
30
 
33
- function escapeSnippetName(name: string): Platform.DevToolsPath.EncodedPathString {
34
- return Common.ParsedURL.ParsedURL.rawPathToEncodedPathString(name as Platform.DevToolsPath.RawPathString);
31
+ function escapeSnippetName(name: Platform.DevToolsPath.RawPathString): Platform.DevToolsPath.EncodedPathString {
32
+ return Common.ParsedURL.ParsedURL.rawPathToEncodedPathString(name);
35
33
  }
36
34
 
37
- function unescapeSnippetName(name: string): string {
38
- return Common.ParsedURL.ParsedURL.encodedPathToRawPathString(name as Platform.DevToolsPath.EncodedPathString);
35
+ function unescapeSnippetName(name: Platform.DevToolsPath.EncodedPathString): string {
36
+ return Common.ParsedURL.ParsedURL.encodedPathToRawPathString(name);
39
37
  }
40
38
 
41
39
  export class SnippetFileSystem extends Persistence.PlatformFileSystem.PlatformFileSystem {
@@ -53,11 +51,13 @@ export class SnippetFileSystem extends Persistence.PlatformFileSystem.PlatformFi
53
51
  return savedSnippets.map(snippet => escapeSnippetName(snippet.name));
54
52
  }
55
53
 
56
- async createFile(_path: string, _name: string|null): Promise<string|null> {
54
+ async createFile(_path: Platform.DevToolsPath.EncodedPathString, _name: Platform.DevToolsPath.RawPathString|null):
55
+ Promise<Platform.DevToolsPath.EncodedPathString|null> {
57
56
  const nextId = this.lastSnippetIdentifierSetting.get() + 1;
58
57
  this.lastSnippetIdentifierSetting.set(nextId);
59
58
 
60
- const snippetName = i18nString(UIStrings.scriptSnippet, {PH1: nextId});
59
+ const snippetName =
60
+ i18nString(UIStrings.scriptSnippet, {PH1: nextId}) as string as Platform.DevToolsPath.RawPathString;
61
61
  const snippets = this.snippetsSetting.get();
62
62
  snippets.push({name: snippetName, content: ''});
63
63
  this.snippetsSetting.set(snippets);
@@ -65,8 +65,8 @@ export class SnippetFileSystem extends Persistence.PlatformFileSystem.PlatformFi
65
65
  return escapeSnippetName(snippetName);
66
66
  }
67
67
 
68
- async deleteFile(path: string): Promise<boolean> {
69
- const name = unescapeSnippetName(path.substring(1));
68
+ async deleteFile(path: Platform.DevToolsPath.EncodedPathString): Promise<boolean> {
69
+ const name = unescapeSnippetName(Common.ParsedURL.ParsedURL.substring(path, 1));
70
70
  const allSnippets: Snippet[] = this.snippetsSetting.get();
71
71
  const snippets = allSnippets.filter(snippet => snippet.name !== name);
72
72
  if (allSnippets.length !== snippets.length) {
@@ -76,8 +76,9 @@ export class SnippetFileSystem extends Persistence.PlatformFileSystem.PlatformFi
76
76
  return false;
77
77
  }
78
78
 
79
- async requestFileContent(path: string): Promise<TextUtils.ContentProvider.DeferredContent> {
80
- const name = unescapeSnippetName(path.substring(1));
79
+ async requestFileContent(path: Platform.DevToolsPath.EncodedPathString):
80
+ Promise<TextUtils.ContentProvider.DeferredContent> {
81
+ const name = unescapeSnippetName(Common.ParsedURL.ParsedURL.substring(path, 1));
81
82
  const snippets: Snippet[] = this.snippetsSetting.get();
82
83
  const snippet = snippets.find(snippet => snippet.name === name);
83
84
  if (snippet) {
@@ -86,8 +87,9 @@ export class SnippetFileSystem extends Persistence.PlatformFileSystem.PlatformFi
86
87
  return {content: null, isEncoded: false, error: `A snippet with name '${name}' was not found`};
87
88
  }
88
89
 
89
- async setFileContent(path: string, content: string, _isBase64: boolean): Promise<boolean> {
90
- const name = unescapeSnippetName(path.substring(1));
90
+ async setFileContent(path: Platform.DevToolsPath.EncodedPathString, content: string, _isBase64: boolean):
91
+ Promise<boolean> {
92
+ const name = unescapeSnippetName(Common.ParsedURL.ParsedURL.substring(path, 1));
91
93
  const snippets: Snippet[] = this.snippetsSetting.get();
92
94
  const snippet = snippets.find(snippet => snippet.name === name);
93
95
  if (snippet) {
@@ -98,11 +100,13 @@ export class SnippetFileSystem extends Persistence.PlatformFileSystem.PlatformFi
98
100
  return false;
99
101
  }
100
102
 
101
- renameFile(path: string, newName: string, callback: (arg0: boolean, arg1?: string|undefined) => void): void {
102
- const name = unescapeSnippetName(path.substring(1));
103
+ renameFile(
104
+ path: Platform.DevToolsPath.EncodedPathString, newName: Platform.DevToolsPath.RawPathString,
105
+ callback: (arg0: boolean, arg1?: string|undefined) => void): void {
106
+ const name = unescapeSnippetName(Common.ParsedURL.ParsedURL.substring(path, 1));
103
107
  const snippets: Snippet[] = this.snippetsSetting.get();
104
108
  const snippet = snippets.find(snippet => snippet.name === name);
105
- newName = newName.trim();
109
+ newName = Common.ParsedURL.ParsedURL.trim(newName);
106
110
  if (!snippet || newName.length === 0 || snippets.find(snippet => snippet.name === newName)) {
107
111
  callback(false);
108
112
  return;
@@ -128,7 +132,9 @@ export class SnippetFileSystem extends Persistence.PlatformFileSystem.PlatformFi
128
132
  }
129
133
 
130
134
  tooltipForURL(url: Platform.DevToolsPath.UrlString): string {
131
- return i18nString(UIStrings.linkedTo, {PH1: unescapeSnippetName(url.substring(this.path().length))});
135
+ return i18nString(
136
+ UIStrings.linkedTo,
137
+ {PH1: unescapeSnippetName(Common.ParsedURL.ParsedURL.sliceUrlToEncodedPathString(url, this.path().length))});
132
138
  }
133
139
 
134
140
  supportsAutomapping(): boolean {
@@ -215,6 +221,6 @@ export function findSnippetsProject(): Workspace.Workspace.Project {
215
221
  return workspaceProject;
216
222
  }
217
223
  export interface Snippet {
218
- name: string;
224
+ name: Platform.DevToolsPath.RawPathString;
219
225
  content: string;
220
226
  }