Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(512)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/workspace/UISourceCode.js

Issue 2493373002: DevTools: rename WebInspector into modules. (Closed)
Patch Set: for bots Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 10 matching lines...) Expand all
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 /** 30 /**
31 * @implements {WebInspector.ContentProvider} 31 * @implements {Common.ContentProvider}
32 * @unrestricted 32 * @unrestricted
33 */ 33 */
34 WebInspector.UISourceCode = class extends WebInspector.Object { 34 Workspace.UISourceCode = class extends Common.Object {
35 /** 35 /**
36 * @param {!WebInspector.Project} project 36 * @param {!Workspace.Project} project
37 * @param {string} url 37 * @param {string} url
38 * @param {!WebInspector.ResourceType} contentType 38 * @param {!Common.ResourceType} contentType
39 */ 39 */
40 constructor(project, url, contentType) { 40 constructor(project, url, contentType) {
41 super(); 41 super();
42 this._project = project; 42 this._project = project;
43 this._url = url; 43 this._url = url;
44 44
45 var parsedURL = url.asParsedURL(); 45 var parsedURL = url.asParsedURL();
46 if (parsedURL) { 46 if (parsedURL) {
47 this._origin = parsedURL.securityOrigin(); 47 this._origin = parsedURL.securityOrigin();
48 this._parentURL = this._origin + parsedURL.folderPathComponents; 48 this._parentURL = this._origin + parsedURL.folderPathComponents;
49 this._name = parsedURL.lastPathComponent; 49 this._name = parsedURL.lastPathComponent;
50 if (parsedURL.queryParams) 50 if (parsedURL.queryParams)
51 this._name += '?' + parsedURL.queryParams; 51 this._name += '?' + parsedURL.queryParams;
52 } else { 52 } else {
53 this._origin = ''; 53 this._origin = '';
54 this._parentURL = ''; 54 this._parentURL = '';
55 this._name = url; 55 this._name = url;
56 } 56 }
57 57
58 this._contentType = contentType; 58 this._contentType = contentType;
59 /** @type {?function(?string)} */ 59 /** @type {?function(?string)} */
60 this._requestContentCallback = null; 60 this._requestContentCallback = null;
61 /** @type {?Promise<?string>} */ 61 /** @type {?Promise<?string>} */
62 this._requestContentPromise = null; 62 this._requestContentPromise = null;
63 /** @type {!Map<string, !Map<number, !WebInspector.UISourceCode.LineMarker>> } */ 63 /** @type {!Map<string, !Map<number, !Workspace.UISourceCode.LineMarker>>} * /
64 this._lineDecorations = new Map(); 64 this._lineDecorations = new Map();
65 65
66 /** @type {!Array.<!WebInspector.Revision>} */ 66 /** @type {!Array.<!Workspace.Revision>} */
67 this.history = []; 67 this.history = [];
68 68
69 /** @type {!Array<!WebInspector.UISourceCode.Message>} */ 69 /** @type {!Array<!Workspace.UISourceCode.Message>} */
70 this._messages = []; 70 this._messages = [];
71 } 71 }
72 72
73 /** 73 /**
74 * @return {!Promise<?WebInspector.UISourceCodeMetadata>} 74 * @return {!Promise<?Workspace.UISourceCodeMetadata>}
75 */ 75 */
76 requestMetadata() { 76 requestMetadata() {
77 return this._project.requestMetadata(this); 77 return this._project.requestMetadata(this);
78 } 78 }
79 79
80 /** 80 /**
81 * @return {string} 81 * @return {string}
82 */ 82 */
83 name() { 83 name() {
84 return this._name; 84 return this._name;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 } 116 }
117 return parentPath + '/' + this.displayName(true); 117 return parentPath + '/' + this.displayName(true);
118 } 118 }
119 119
120 /** 120 /**
121 * @param {boolean=} skipTrim 121 * @param {boolean=} skipTrim
122 * @return {string} 122 * @return {string}
123 */ 123 */
124 displayName(skipTrim) { 124 displayName(skipTrim) {
125 if (!this._name) 125 if (!this._name)
126 return WebInspector.UIString('(index)'); 126 return Common.UIString('(index)');
127 var name = this._name; 127 var name = this._name;
128 try { 128 try {
129 name = decodeURI(name); 129 name = decodeURI(name);
130 } catch (e) { 130 } catch (e) {
131 } 131 }
132 return skipTrim ? name : name.trimEnd(100); 132 return skipTrim ? name : name.trimEnd(100);
133 } 133 }
134 134
135 /** 135 /**
136 * @return {boolean} 136 * @return {boolean}
137 */ 137 */
138 isFromServiceProject() { 138 isFromServiceProject() {
139 return WebInspector.Project.isServiceProject(this._project); 139 return Workspace.Project.isServiceProject(this._project);
140 } 140 }
141 141
142 /** 142 /**
143 * @return {boolean} 143 * @return {boolean}
144 */ 144 */
145 canRename() { 145 canRename() {
146 return this._project.canRename(); 146 return this._project.canRename();
147 } 147 }
148 148
149 /** 149 /**
150 * @param {string} newName 150 * @param {string} newName
151 * @param {function(boolean)} callback 151 * @param {function(boolean)} callback
152 */ 152 */
153 rename(newName, callback) { 153 rename(newName, callback) {
154 this._project.rename(this, newName, innerCallback.bind(this)); 154 this._project.rename(this, newName, innerCallback.bind(this));
155 155
156 /** 156 /**
157 * @param {boolean} success 157 * @param {boolean} success
158 * @param {string=} newName 158 * @param {string=} newName
159 * @param {string=} newURL 159 * @param {string=} newURL
160 * @param {!WebInspector.ResourceType=} newContentType 160 * @param {!Common.ResourceType=} newContentType
161 * @this {WebInspector.UISourceCode} 161 * @this {Workspace.UISourceCode}
162 */ 162 */
163 function innerCallback(success, newName, newURL, newContentType) { 163 function innerCallback(success, newName, newURL, newContentType) {
164 if (success) 164 if (success)
165 this._updateName( 165 this._updateName(
166 /** @type {string} */ (newName), /** @type {string} */ (newURL), 166 /** @type {string} */ (newName), /** @type {string} */ (newURL),
167 /** @type {!WebInspector.ResourceType} */ (newContentType)); 167 /** @type {!Common.ResourceType} */ (newContentType));
168 callback(success); 168 callback(success);
169 } 169 }
170 } 170 }
171 171
172 remove() { 172 remove() {
173 this._project.deleteFile(this.url()); 173 this._project.deleteFile(this.url());
174 } 174 }
175 175
176 /** 176 /**
177 * @param {string} name 177 * @param {string} name
178 * @param {string} url 178 * @param {string} url
179 * @param {!WebInspector.ResourceType=} contentType 179 * @param {!Common.ResourceType=} contentType
180 */ 180 */
181 _updateName(name, url, contentType) { 181 _updateName(name, url, contentType) {
182 var oldURL = this.url(); 182 var oldURL = this.url();
183 this._url = this._url.substring(0, this._url.length - this._name.length) + n ame; 183 this._url = this._url.substring(0, this._url.length - this._name.length) + n ame;
184 this._name = name; 184 this._name = name;
185 if (url) 185 if (url)
186 this._url = url; 186 this._url = url;
187 if (contentType) 187 if (contentType)
188 this._contentType = contentType; 188 this._contentType = contentType;
189 this.dispatchEventToListeners(WebInspector.UISourceCode.Events.TitleChanged, oldURL); 189 this.dispatchEventToListeners(Workspace.UISourceCode.Events.TitleChanged, ol dURL);
190 } 190 }
191 191
192 /** 192 /**
193 * @override 193 * @override
194 * @return {string} 194 * @return {string}
195 */ 195 */
196 contentURL() { 196 contentURL() {
197 return this.url(); 197 return this.url();
198 } 198 }
199 199
200 /** 200 /**
201 * @override 201 * @override
202 * @return {!WebInspector.ResourceType} 202 * @return {!Common.ResourceType}
203 */ 203 */
204 contentType() { 204 contentType() {
205 return this._contentType; 205 return this._contentType;
206 } 206 }
207 207
208 /** 208 /**
209 * @return {!WebInspector.Project} 209 * @return {!Workspace.Project}
210 */ 210 */
211 project() { 211 project() {
212 return this._project; 212 return this._project;
213 } 213 }
214 214
215 /** 215 /**
216 * @override 216 * @override
217 * @return {!Promise<?string>} 217 * @return {!Promise<?string>}
218 */ 218 */
219 requestContent() { 219 requestContent() {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 this._pushCheckContentUpdatedCallback(callback); 266 this._pushCheckContentUpdatedCallback(callback);
267 267
268 if (this._checkingContent) 268 if (this._checkingContent)
269 return; 269 return;
270 270
271 this._checkingContent = true; 271 this._checkingContent = true;
272 this._project.requestFileContent(this, contentLoaded.bind(this)); 272 this._project.requestFileContent(this, contentLoaded.bind(this));
273 273
274 /** 274 /**
275 * @param {?string} updatedContent 275 * @param {?string} updatedContent
276 * @this {WebInspector.UISourceCode} 276 * @this {Workspace.UISourceCode}
277 */ 277 */
278 function contentLoaded(updatedContent) { 278 function contentLoaded(updatedContent) {
279 if (updatedContent === null) { 279 if (updatedContent === null) {
280 var workingCopy = this.workingCopy(); 280 var workingCopy = this.workingCopy();
281 this._contentCommitted('', false); 281 this._contentCommitted('', false);
282 this.setWorkingCopy(workingCopy); 282 this.setWorkingCopy(workingCopy);
283 this._terminateContentCheck(); 283 this._terminateContentCheck();
284 return; 284 return;
285 } 285 }
286 if (typeof this._lastAcceptedContent === 'string' && this._lastAcceptedCon tent === updatedContent) { 286 if (typeof this._lastAcceptedContent === 'string' && this._lastAcceptedCon tent === updatedContent) {
287 this._terminateContentCheck(); 287 this._terminateContentCheck();
288 return; 288 return;
289 } 289 }
290 290
291 if (this._content === updatedContent) { 291 if (this._content === updatedContent) {
292 delete this._lastAcceptedContent; 292 delete this._lastAcceptedContent;
293 this._terminateContentCheck(); 293 this._terminateContentCheck();
294 return; 294 return;
295 } 295 }
296 296
297 if (!this.isDirty() || this._workingCopy === updatedContent) { 297 if (!this.isDirty() || this._workingCopy === updatedContent) {
298 this._contentCommitted(updatedContent, false); 298 this._contentCommitted(updatedContent, false);
299 this._terminateContentCheck(); 299 this._terminateContentCheck();
300 return; 300 return;
301 } 301 }
302 302
303 var shouldUpdate = 303 var shouldUpdate =
304 window.confirm(WebInspector.UIString('This file was changed externally . Would you like to reload it?')); 304 window.confirm(Common.UIString('This file was changed externally. Woul d you like to reload it?'));
305 if (shouldUpdate) 305 if (shouldUpdate)
306 this._contentCommitted(updatedContent, false); 306 this._contentCommitted(updatedContent, false);
307 else 307 else
308 this._lastAcceptedContent = updatedContent; 308 this._lastAcceptedContent = updatedContent;
309 this._terminateContentCheck(); 309 this._terminateContentCheck();
310 } 310 }
311 } 311 }
312 312
313 forceLoadOnCheckContent() { 313 forceLoadOnCheckContent() {
314 this._forceLoadOnCheckContent = true; 314 this._forceLoadOnCheckContent = true;
315 } 315 }
316 316
317 /** 317 /**
318 * @return {!Promise<?string>} 318 * @return {!Promise<?string>}
319 */ 319 */
320 requestOriginalContent() { 320 requestOriginalContent() {
321 var callback; 321 var callback;
322 var promise = new Promise(fulfill => callback = fulfill); 322 var promise = new Promise(fulfill => callback = fulfill);
323 this._project.requestFileContent(this, callback); 323 this._project.requestFileContent(this, callback);
324 return promise; 324 return promise;
325 } 325 }
326 326
327 /** 327 /**
328 * @param {string} content 328 * @param {string} content
329 */ 329 */
330 _commitContent(content) { 330 _commitContent(content) {
331 if (this._project.canSetFileContent()) { 331 if (this._project.canSetFileContent()) {
332 this._project.setFileContent(this, content, function() {}); 332 this._project.setFileContent(this, content, function() {});
333 } else if (this._url && WebInspector.fileManager.isURLSaved(this._url)) { 333 } else if (this._url && Workspace.fileManager.isURLSaved(this._url)) {
334 WebInspector.fileManager.save(this._url, content, false, function() {}); 334 Workspace.fileManager.save(this._url, content, false, function() {});
335 WebInspector.fileManager.close(this._url); 335 Workspace.fileManager.close(this._url);
336 } 336 }
337 this._contentCommitted(content, true); 337 this._contentCommitted(content, true);
338 } 338 }
339 339
340 /** 340 /**
341 * @param {string} content 341 * @param {string} content
342 * @param {boolean} committedByUser 342 * @param {boolean} committedByUser
343 */ 343 */
344 _contentCommitted(content, committedByUser) { 344 _contentCommitted(content, committedByUser) {
345 delete this._lastAcceptedContent; 345 delete this._lastAcceptedContent;
346 this._content = content; 346 this._content = content;
347 this._contentLoaded = true; 347 this._contentLoaded = true;
348 348
349 var lastRevision = this.history.length ? this.history[this.history.length - 1] : null; 349 var lastRevision = this.history.length ? this.history[this.history.length - 1] : null;
350 if (!lastRevision || lastRevision._content !== this._content) { 350 if (!lastRevision || lastRevision._content !== this._content) {
351 var revision = new WebInspector.Revision(this, this._content, new Date()); 351 var revision = new Workspace.Revision(this, this._content, new Date());
352 this.history.push(revision); 352 this.history.push(revision);
353 } 353 }
354 354
355 this._innerResetWorkingCopy(); 355 this._innerResetWorkingCopy();
356 this.dispatchEventToListeners(WebInspector.UISourceCode.Events.WorkingCopyCo mmitted, {content: content}); 356 this.dispatchEventToListeners(Workspace.UISourceCode.Events.WorkingCopyCommi tted, {content: content});
357 this._project.workspace().dispatchEventToListeners( 357 this._project.workspace().dispatchEventToListeners(
358 WebInspector.Workspace.Events.WorkingCopyCommitted, {uiSourceCode: this, content: content}); 358 Workspace.Workspace.Events.WorkingCopyCommitted, {uiSourceCode: this, co ntent: content});
359 if (committedByUser) 359 if (committedByUser)
360 this._project.workspace().dispatchEventToListeners( 360 this._project.workspace().dispatchEventToListeners(
361 WebInspector.Workspace.Events.WorkingCopyCommittedByUser, {uiSourceCod e: this, content: content}); 361 Workspace.Workspace.Events.WorkingCopyCommittedByUser, {uiSourceCode: this, content: content});
362 } 362 }
363 363
364 saveAs() { 364 saveAs() {
365 WebInspector.fileManager.save(this._url, this.workingCopy(), true, callback. bind(this)); 365 Workspace.fileManager.save(this._url, this.workingCopy(), true, callback.bin d(this));
366 WebInspector.fileManager.close(this._url); 366 Workspace.fileManager.close(this._url);
367 367
368 /** 368 /**
369 * @param {boolean} accepted 369 * @param {boolean} accepted
370 * @this {WebInspector.UISourceCode} 370 * @this {Workspace.UISourceCode}
371 */ 371 */
372 function callback(accepted) { 372 function callback(accepted) {
373 if (accepted) 373 if (accepted)
374 this._contentCommitted(this.workingCopy(), true); 374 this._contentCommitted(this.workingCopy(), true);
375 } 375 }
376 } 376 }
377 377
378 /** 378 /**
379 * @param {string} content 379 * @param {string} content
380 */ 380 */
381 addRevision(content) { 381 addRevision(content) {
382 this._commitContent(content); 382 this._commitContent(content);
383 } 383 }
384 384
385 /** 385 /**
386 * @return {!Promise} 386 * @return {!Promise}
387 */ 387 */
388 revertToOriginal() { 388 revertToOriginal() {
389 /** 389 /**
390 * @this {WebInspector.UISourceCode} 390 * @this {Workspace.UISourceCode}
391 * @param {?string} content 391 * @param {?string} content
392 */ 392 */
393 function callback(content) { 393 function callback(content) {
394 if (typeof content !== 'string') 394 if (typeof content !== 'string')
395 return; 395 return;
396 396
397 this.addRevision(content); 397 this.addRevision(content);
398 } 398 }
399 399
400 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Revisio nApplied); 400 Host.userMetrics.actionTaken(Host.UserMetrics.Action.RevisionApplied);
401 return this.requestOriginalContent().then(callback.bind(this)); 401 return this.requestOriginalContent().then(callback.bind(this));
402 } 402 }
403 403
404 /** 404 /**
405 * @param {function(!WebInspector.UISourceCode)} callback 405 * @param {function(!Workspace.UISourceCode)} callback
406 */ 406 */
407 revertAndClearHistory(callback) { 407 revertAndClearHistory(callback) {
408 /** 408 /**
409 * @this {WebInspector.UISourceCode} 409 * @this {Workspace.UISourceCode}
410 * @param {?string} content 410 * @param {?string} content
411 */ 411 */
412 function revert(content) { 412 function revert(content) {
413 if (typeof content !== 'string') 413 if (typeof content !== 'string')
414 return; 414 return;
415 415
416 this.addRevision(content); 416 this.addRevision(content);
417 this.history = []; 417 this.history = [];
418 callback(this); 418 callback(this);
419 } 419 }
420 420
421 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Revisio nApplied); 421 Host.userMetrics.actionTaken(Host.UserMetrics.Action.RevisionApplied);
422 this.requestOriginalContent().then(revert.bind(this)); 422 this.requestOriginalContent().then(revert.bind(this));
423 } 423 }
424 424
425 /** 425 /**
426 * @return {string} 426 * @return {string}
427 */ 427 */
428 workingCopy() { 428 workingCopy() {
429 if (this._workingCopyGetter) { 429 if (this._workingCopyGetter) {
430 this._workingCopy = this._workingCopyGetter(); 430 this._workingCopy = this._workingCopyGetter();
431 delete this._workingCopyGetter; 431 delete this._workingCopyGetter;
432 } 432 }
433 if (this.isDirty()) 433 if (this.isDirty())
434 return this._workingCopy; 434 return this._workingCopy;
435 return this._content; 435 return this._content;
436 } 436 }
437 437
438 resetWorkingCopy() { 438 resetWorkingCopy() {
439 this._innerResetWorkingCopy(); 439 this._innerResetWorkingCopy();
440 this.dispatchEventToListeners(WebInspector.UISourceCode.Events.WorkingCopyCh anged); 440 this.dispatchEventToListeners(Workspace.UISourceCode.Events.WorkingCopyChang ed);
441 } 441 }
442 442
443 _innerResetWorkingCopy() { 443 _innerResetWorkingCopy() {
444 delete this._workingCopy; 444 delete this._workingCopy;
445 delete this._workingCopyGetter; 445 delete this._workingCopyGetter;
446 } 446 }
447 447
448 /** 448 /**
449 * @param {string} newWorkingCopy 449 * @param {string} newWorkingCopy
450 */ 450 */
451 setWorkingCopy(newWorkingCopy) { 451 setWorkingCopy(newWorkingCopy) {
452 this._workingCopy = newWorkingCopy; 452 this._workingCopy = newWorkingCopy;
453 delete this._workingCopyGetter; 453 delete this._workingCopyGetter;
454 this.dispatchEventToListeners(WebInspector.UISourceCode.Events.WorkingCopyCh anged); 454 this.dispatchEventToListeners(Workspace.UISourceCode.Events.WorkingCopyChang ed);
455 this._project.workspace().dispatchEventToListeners( 455 this._project.workspace().dispatchEventToListeners(
456 WebInspector.Workspace.Events.WorkingCopyChanged, {uiSourceCode: this}); 456 Workspace.Workspace.Events.WorkingCopyChanged, {uiSourceCode: this});
457 } 457 }
458 458
459 setWorkingCopyGetter(workingCopyGetter) { 459 setWorkingCopyGetter(workingCopyGetter) {
460 this._workingCopyGetter = workingCopyGetter; 460 this._workingCopyGetter = workingCopyGetter;
461 this.dispatchEventToListeners(WebInspector.UISourceCode.Events.WorkingCopyCh anged); 461 this.dispatchEventToListeners(Workspace.UISourceCode.Events.WorkingCopyChang ed);
462 this._project.workspace().dispatchEventToListeners( 462 this._project.workspace().dispatchEventToListeners(
463 WebInspector.Workspace.Events.WorkingCopyChanged, {uiSourceCode: this}); 463 Workspace.Workspace.Events.WorkingCopyChanged, {uiSourceCode: this});
464 } 464 }
465 465
466 removeWorkingCopyGetter() { 466 removeWorkingCopyGetter() {
467 if (!this._workingCopyGetter) 467 if (!this._workingCopyGetter)
468 return; 468 return;
469 this._workingCopy = this._workingCopyGetter(); 469 this._workingCopy = this._workingCopyGetter();
470 delete this._workingCopyGetter; 470 delete this._workingCopyGetter;
471 } 471 }
472 472
473 commitWorkingCopy() { 473 commitWorkingCopy() {
474 if (this.isDirty()) 474 if (this.isDirty())
475 this._commitContent(this.workingCopy()); 475 this._commitContent(this.workingCopy());
476 } 476 }
477 477
478 /** 478 /**
479 * @return {boolean} 479 * @return {boolean}
480 */ 480 */
481 isDirty() { 481 isDirty() {
482 return typeof this._workingCopy !== 'undefined' || typeof this._workingCopyG etter !== 'undefined'; 482 return typeof this._workingCopy !== 'undefined' || typeof this._workingCopyG etter !== 'undefined';
483 } 483 }
484 484
485 /** 485 /**
486 * @return {string} 486 * @return {string}
487 */ 487 */
488 extension() { 488 extension() {
489 return WebInspector.ParsedURL.extractExtension(this._name); 489 return Common.ParsedURL.extractExtension(this._name);
490 } 490 }
491 491
492 /** 492 /**
493 * @return {?string} 493 * @return {?string}
494 */ 494 */
495 content() { 495 content() {
496 return this._content; 496 return this._content;
497 } 497 }
498 498
499 /** 499 /**
500 * @override 500 * @override
501 * @param {string} query 501 * @param {string} query
502 * @param {boolean} caseSensitive 502 * @param {boolean} caseSensitive
503 * @param {boolean} isRegex 503 * @param {boolean} isRegex
504 * @param {function(!Array.<!WebInspector.ContentProvider.SearchMatch>)} callb ack 504 * @param {function(!Array.<!Common.ContentProvider.SearchMatch>)} callback
505 */ 505 */
506 searchInContent(query, caseSensitive, isRegex, callback) { 506 searchInContent(query, caseSensitive, isRegex, callback) {
507 var content = this.content(); 507 var content = this.content();
508 if (!content) { 508 if (!content) {
509 this._project.searchInFileContent(this, query, caseSensitive, isRegex, cal lback); 509 this._project.searchInFileContent(this, query, caseSensitive, isRegex, cal lback);
510 return; 510 return;
511 } 511 }
512 512
513 // searchInContent should call back later. 513 // searchInContent should call back later.
514 setTimeout(doSearch.bind(null, content), 0); 514 setTimeout(doSearch.bind(null, content), 0);
515 515
516 /** 516 /**
517 * @param {string} content 517 * @param {string} content
518 */ 518 */
519 function doSearch(content) { 519 function doSearch(content) {
520 callback(WebInspector.ContentProvider.performSearchInContent(content, quer y, caseSensitive, isRegex)); 520 callback(Common.ContentProvider.performSearchInContent(content, query, cas eSensitive, isRegex));
521 } 521 }
522 } 522 }
523 523
524 /** 524 /**
525 * @param {?string} content 525 * @param {?string} content
526 */ 526 */
527 _fireContentAvailable(content) { 527 _fireContentAvailable(content) {
528 this._contentLoaded = true; 528 this._contentLoaded = true;
529 this._content = content; 529 this._content = content;
530 530
531 var callback = this._requestContentCallback; 531 var callback = this._requestContentCallback;
532 this._requestContentCallback = null; 532 this._requestContentCallback = null;
533 this._requestContentPromise = null; 533 this._requestContentPromise = null;
534 534
535 callback.call(null, content); 535 callback.call(null, content);
536 } 536 }
537 537
538 /** 538 /**
539 * @return {boolean} 539 * @return {boolean}
540 */ 540 */
541 contentLoaded() { 541 contentLoaded() {
542 return this._contentLoaded; 542 return this._contentLoaded;
543 } 543 }
544 544
545 /** 545 /**
546 * @param {number} lineNumber 546 * @param {number} lineNumber
547 * @param {number=} columnNumber 547 * @param {number=} columnNumber
548 * @return {!WebInspector.UILocation} 548 * @return {!Workspace.UILocation}
549 */ 549 */
550 uiLocation(lineNumber, columnNumber) { 550 uiLocation(lineNumber, columnNumber) {
551 if (typeof columnNumber === 'undefined') 551 if (typeof columnNumber === 'undefined')
552 columnNumber = 0; 552 columnNumber = 0;
553 return new WebInspector.UILocation(this, lineNumber, columnNumber); 553 return new Workspace.UILocation(this, lineNumber, columnNumber);
554 } 554 }
555 555
556 /** 556 /**
557 * @return {!Array<!WebInspector.UISourceCode.Message>} 557 * @return {!Array<!Workspace.UISourceCode.Message>}
558 */ 558 */
559 messages() { 559 messages() {
560 return this._messages.slice(); 560 return this._messages.slice();
561 } 561 }
562 562
563 /** 563 /**
564 * @param {!WebInspector.UISourceCode.Message.Level} level 564 * @param {!Workspace.UISourceCode.Message.Level} level
565 * @param {string} text 565 * @param {string} text
566 * @param {number} lineNumber 566 * @param {number} lineNumber
567 * @param {number=} columnNumber 567 * @param {number=} columnNumber
568 * @return {!WebInspector.UISourceCode.Message} message 568 * @return {!Workspace.UISourceCode.Message} message
569 */ 569 */
570 addLineMessage(level, text, lineNumber, columnNumber) { 570 addLineMessage(level, text, lineNumber, columnNumber) {
571 return this.addMessage( 571 return this.addMessage(
572 level, text, new WebInspector.TextRange(lineNumber, columnNumber || 0, l ineNumber, columnNumber || 0)); 572 level, text, new Common.TextRange(lineNumber, columnNumber || 0, lineNum ber, columnNumber || 0));
573 } 573 }
574 574
575 /** 575 /**
576 * @param {!WebInspector.UISourceCode.Message.Level} level 576 * @param {!Workspace.UISourceCode.Message.Level} level
577 * @param {string} text 577 * @param {string} text
578 * @param {!WebInspector.TextRange} range 578 * @param {!Common.TextRange} range
579 * @return {!WebInspector.UISourceCode.Message} message 579 * @return {!Workspace.UISourceCode.Message} message
580 */ 580 */
581 addMessage(level, text, range) { 581 addMessage(level, text, range) {
582 var message = new WebInspector.UISourceCode.Message(this, level, text, range ); 582 var message = new Workspace.UISourceCode.Message(this, level, text, range);
583 this._messages.push(message); 583 this._messages.push(message);
584 this.dispatchEventToListeners(WebInspector.UISourceCode.Events.MessageAdded, message); 584 this.dispatchEventToListeners(Workspace.UISourceCode.Events.MessageAdded, me ssage);
585 return message; 585 return message;
586 } 586 }
587 587
588 /** 588 /**
589 * @param {!WebInspector.UISourceCode.Message} message 589 * @param {!Workspace.UISourceCode.Message} message
590 */ 590 */
591 removeMessage(message) { 591 removeMessage(message) {
592 if (this._messages.remove(message)) 592 if (this._messages.remove(message))
593 this.dispatchEventToListeners(WebInspector.UISourceCode.Events.MessageRemo ved, message); 593 this.dispatchEventToListeners(Workspace.UISourceCode.Events.MessageRemoved , message);
594 } 594 }
595 595
596 removeAllMessages() { 596 removeAllMessages() {
597 var messages = this._messages; 597 var messages = this._messages;
598 this._messages = []; 598 this._messages = [];
599 for (var message of messages) 599 for (var message of messages)
600 this.dispatchEventToListeners(WebInspector.UISourceCode.Events.MessageRemo ved, message); 600 this.dispatchEventToListeners(Workspace.UISourceCode.Events.MessageRemoved , message);
601 } 601 }
602 602
603 /** 603 /**
604 * @param {number} lineNumber 604 * @param {number} lineNumber
605 * @param {string} type 605 * @param {string} type
606 * @param {?} data 606 * @param {?} data
607 */ 607 */
608 addLineDecoration(lineNumber, type, data) { 608 addLineDecoration(lineNumber, type, data) {
609 var markers = this._lineDecorations.get(type); 609 var markers = this._lineDecorations.get(type);
610 if (!markers) { 610 if (!markers) {
611 markers = new Map(); 611 markers = new Map();
612 this._lineDecorations.set(type, markers); 612 this._lineDecorations.set(type, markers);
613 } 613 }
614 var marker = new WebInspector.UISourceCode.LineMarker(lineNumber, type, data ); 614 var marker = new Workspace.UISourceCode.LineMarker(lineNumber, type, data);
615 markers.set(lineNumber, marker); 615 markers.set(lineNumber, marker);
616 this.dispatchEventToListeners(WebInspector.UISourceCode.Events.LineDecoratio nAdded, marker); 616 this.dispatchEventToListeners(Workspace.UISourceCode.Events.LineDecorationAd ded, marker);
617 } 617 }
618 618
619 /** 619 /**
620 * @param {number} lineNumber 620 * @param {number} lineNumber
621 * @param {string} type 621 * @param {string} type
622 */ 622 */
623 removeLineDecoration(lineNumber, type) { 623 removeLineDecoration(lineNumber, type) {
624 var markers = this._lineDecorations.get(type); 624 var markers = this._lineDecorations.get(type);
625 if (!markers) 625 if (!markers)
626 return; 626 return;
627 var marker = markers.get(lineNumber); 627 var marker = markers.get(lineNumber);
628 if (!marker) 628 if (!marker)
629 return; 629 return;
630 markers.delete(lineNumber); 630 markers.delete(lineNumber);
631 this.dispatchEventToListeners(WebInspector.UISourceCode.Events.LineDecoratio nRemoved, marker); 631 this.dispatchEventToListeners(Workspace.UISourceCode.Events.LineDecorationRe moved, marker);
632 if (!markers.size) 632 if (!markers.size)
633 this._lineDecorations.delete(type); 633 this._lineDecorations.delete(type);
634 } 634 }
635 635
636 /** 636 /**
637 * @param {string} type 637 * @param {string} type
638 */ 638 */
639 removeAllLineDecorations(type) { 639 removeAllLineDecorations(type) {
640 var markers = this._lineDecorations.get(type); 640 var markers = this._lineDecorations.get(type);
641 if (!markers) 641 if (!markers)
642 return; 642 return;
643 this._lineDecorations.delete(type); 643 this._lineDecorations.delete(type);
644 markers.forEach(marker => { 644 markers.forEach(marker => {
645 this.dispatchEventToListeners(WebInspector.UISourceCode.Events.LineDecorat ionRemoved, marker); 645 this.dispatchEventToListeners(Workspace.UISourceCode.Events.LineDecoration Removed, marker);
646 }); 646 });
647 } 647 }
648 648
649 /** 649 /**
650 * @param {string} type 650 * @param {string} type
651 * @return {?Map<number, !WebInspector.UISourceCode.LineMarker>} 651 * @return {?Map<number, !Workspace.UISourceCode.LineMarker>}
652 */ 652 */
653 lineDecorations(type) { 653 lineDecorations(type) {
654 return this._lineDecorations.get(type) || null; 654 return this._lineDecorations.get(type) || null;
655 } 655 }
656 }; 656 };
657 657
658 /** @enum {symbol} */ 658 /** @enum {symbol} */
659 WebInspector.UISourceCode.Events = { 659 Workspace.UISourceCode.Events = {
660 WorkingCopyChanged: Symbol('WorkingCopyChanged'), 660 WorkingCopyChanged: Symbol('WorkingCopyChanged'),
661 WorkingCopyCommitted: Symbol('WorkingCopyCommitted'), 661 WorkingCopyCommitted: Symbol('WorkingCopyCommitted'),
662 TitleChanged: Symbol('TitleChanged'), 662 TitleChanged: Symbol('TitleChanged'),
663 SourceMappingChanged: Symbol('SourceMappingChanged'), 663 SourceMappingChanged: Symbol('SourceMappingChanged'),
664 MessageAdded: Symbol('MessageAdded'), 664 MessageAdded: Symbol('MessageAdded'),
665 MessageRemoved: Symbol('MessageRemoved'), 665 MessageRemoved: Symbol('MessageRemoved'),
666 LineDecorationAdded: Symbol('LineDecorationAdded'), 666 LineDecorationAdded: Symbol('LineDecorationAdded'),
667 LineDecorationRemoved: Symbol('LineDecorationRemoved') 667 LineDecorationRemoved: Symbol('LineDecorationRemoved')
668 }; 668 };
669 669
670 /** 670 /**
671 * @unrestricted 671 * @unrestricted
672 */ 672 */
673 WebInspector.UILocation = class { 673 Workspace.UILocation = class {
674 /** 674 /**
675 * @param {!WebInspector.UISourceCode} uiSourceCode 675 * @param {!Workspace.UISourceCode} uiSourceCode
676 * @param {number} lineNumber 676 * @param {number} lineNumber
677 * @param {number} columnNumber 677 * @param {number} columnNumber
678 */ 678 */
679 constructor(uiSourceCode, lineNumber, columnNumber) { 679 constructor(uiSourceCode, lineNumber, columnNumber) {
680 this.uiSourceCode = uiSourceCode; 680 this.uiSourceCode = uiSourceCode;
681 this.lineNumber = lineNumber; 681 this.lineNumber = lineNumber;
682 this.columnNumber = columnNumber; 682 this.columnNumber = columnNumber;
683 } 683 }
684 684
685 /** 685 /**
(...skipping 15 matching lines...) Expand all
701 } 701 }
702 702
703 /** 703 /**
704 * @return {string} 704 * @return {string}
705 */ 705 */
706 toUIString() { 706 toUIString() {
707 return this.uiSourceCode.url() + ':' + (this.lineNumber + 1); 707 return this.uiSourceCode.url() + ':' + (this.lineNumber + 1);
708 } 708 }
709 709
710 /** 710 /**
711 * @param {!WebInspector.UILocation} location1 711 * @param {!Workspace.UILocation} location1
712 * @param {!WebInspector.UILocation} location2 712 * @param {!Workspace.UILocation} location2
713 * @return {number} 713 * @return {number}
714 */ 714 */
715 static comparator(location1, location2) { 715 static comparator(location1, location2) {
716 return location1.compareTo(location2); 716 return location1.compareTo(location2);
717 } 717 }
718 718
719 /** 719 /**
720 * @param {!WebInspector.UILocation} other 720 * @param {!Workspace.UILocation} other
721 * @return {number} 721 * @return {number}
722 */ 722 */
723 compareTo(other) { 723 compareTo(other) {
724 if (this.uiSourceCode.url() !== other.uiSourceCode.url()) 724 if (this.uiSourceCode.url() !== other.uiSourceCode.url())
725 return this.uiSourceCode.url() > other.uiSourceCode.url() ? 1 : -1; 725 return this.uiSourceCode.url() > other.uiSourceCode.url() ? 1 : -1;
726 if (this.lineNumber !== other.lineNumber) 726 if (this.lineNumber !== other.lineNumber)
727 return this.lineNumber - other.lineNumber; 727 return this.lineNumber - other.lineNumber;
728 return this.columnNumber - other.columnNumber; 728 return this.columnNumber - other.columnNumber;
729 } 729 }
730 }; 730 };
731 731
732 /** 732 /**
733 * @implements {WebInspector.ContentProvider} 733 * @implements {Common.ContentProvider}
734 * @unrestricted 734 * @unrestricted
735 */ 735 */
736 WebInspector.Revision = class { 736 Workspace.Revision = class {
737 /** 737 /**
738 * @param {!WebInspector.UISourceCode} uiSourceCode 738 * @param {!Workspace.UISourceCode} uiSourceCode
739 * @param {?string|undefined} content 739 * @param {?string|undefined} content
740 * @param {!Date} timestamp 740 * @param {!Date} timestamp
741 */ 741 */
742 constructor(uiSourceCode, content, timestamp) { 742 constructor(uiSourceCode, content, timestamp) {
743 this._uiSourceCode = uiSourceCode; 743 this._uiSourceCode = uiSourceCode;
744 this._content = content; 744 this._content = content;
745 this._timestamp = timestamp; 745 this._timestamp = timestamp;
746 } 746 }
747 747
748 /** 748 /**
749 * @return {!WebInspector.UISourceCode} 749 * @return {!Workspace.UISourceCode}
750 */ 750 */
751 get uiSourceCode() { 751 get uiSourceCode() {
752 return this._uiSourceCode; 752 return this._uiSourceCode;
753 } 753 }
754 754
755 /** 755 /**
756 * @return {!Date} 756 * @return {!Date}
757 */ 757 */
758 get timestamp() { 758 get timestamp() {
759 return this._timestamp; 759 return this._timestamp;
760 } 760 }
761 761
762 /** 762 /**
763 * @return {?string} 763 * @return {?string}
764 */ 764 */
765 get content() { 765 get content() {
766 return this._content || null; 766 return this._content || null;
767 } 767 }
768 768
769 /** 769 /**
770 * @return {!Promise} 770 * @return {!Promise}
771 */ 771 */
772 revertToThis() { 772 revertToThis() {
773 /** 773 /**
774 * @param {?string} content 774 * @param {?string} content
775 * @this {WebInspector.Revision} 775 * @this {Workspace.Revision}
776 */ 776 */
777 function revert(content) { 777 function revert(content) {
778 if (content && this._uiSourceCode._content !== content) 778 if (content && this._uiSourceCode._content !== content)
779 this._uiSourceCode.addRevision(content); 779 this._uiSourceCode.addRevision(content);
780 } 780 }
781 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Revisio nApplied); 781 Host.userMetrics.actionTaken(Host.UserMetrics.Action.RevisionApplied);
782 return this.requestContent().then(revert.bind(this)); 782 return this.requestContent().then(revert.bind(this));
783 } 783 }
784 784
785 /** 785 /**
786 * @override 786 * @override
787 * @return {string} 787 * @return {string}
788 */ 788 */
789 contentURL() { 789 contentURL() {
790 return this._uiSourceCode.url(); 790 return this._uiSourceCode.url();
791 } 791 }
792 792
793 /** 793 /**
794 * @override 794 * @override
795 * @return {!WebInspector.ResourceType} 795 * @return {!Common.ResourceType}
796 */ 796 */
797 contentType() { 797 contentType() {
798 return this._uiSourceCode.contentType(); 798 return this._uiSourceCode.contentType();
799 } 799 }
800 800
801 /** 801 /**
802 * @override 802 * @override
803 * @return {!Promise<?string>} 803 * @return {!Promise<?string>}
804 */ 804 */
805 requestContent() { 805 requestContent() {
806 return Promise.resolve(/** @type {?string} */ (this._content || '')); 806 return Promise.resolve(/** @type {?string} */ (this._content || ''));
807 } 807 }
808 808
809 /** 809 /**
810 * @override 810 * @override
811 * @param {string} query 811 * @param {string} query
812 * @param {boolean} caseSensitive 812 * @param {boolean} caseSensitive
813 * @param {boolean} isRegex 813 * @param {boolean} isRegex
814 * @param {function(!Array.<!WebInspector.ContentProvider.SearchMatch>)} callb ack 814 * @param {function(!Array.<!Common.ContentProvider.SearchMatch>)} callback
815 */ 815 */
816 searchInContent(query, caseSensitive, isRegex, callback) { 816 searchInContent(query, caseSensitive, isRegex, callback) {
817 callback([]); 817 callback([]);
818 } 818 }
819 }; 819 };
820 820
821 /** 821 /**
822 * @unrestricted 822 * @unrestricted
823 */ 823 */
824 WebInspector.UISourceCode.Message = class { 824 Workspace.UISourceCode.Message = class {
825 /** 825 /**
826 * @param {!WebInspector.UISourceCode} uiSourceCode 826 * @param {!Workspace.UISourceCode} uiSourceCode
827 * @param {!WebInspector.UISourceCode.Message.Level} level 827 * @param {!Workspace.UISourceCode.Message.Level} level
828 * @param {string} text 828 * @param {string} text
829 * @param {!WebInspector.TextRange} range 829 * @param {!Common.TextRange} range
830 */ 830 */
831 constructor(uiSourceCode, level, text, range) { 831 constructor(uiSourceCode, level, text, range) {
832 this._uiSourceCode = uiSourceCode; 832 this._uiSourceCode = uiSourceCode;
833 this._level = level; 833 this._level = level;
834 this._text = text; 834 this._text = text;
835 this._range = range; 835 this._range = range;
836 } 836 }
837 837
838 /** 838 /**
839 * @return {!WebInspector.UISourceCode} 839 * @return {!Workspace.UISourceCode}
840 */ 840 */
841 uiSourceCode() { 841 uiSourceCode() {
842 return this._uiSourceCode; 842 return this._uiSourceCode;
843 } 843 }
844 844
845 /** 845 /**
846 * @return {!WebInspector.UISourceCode.Message.Level} 846 * @return {!Workspace.UISourceCode.Message.Level}
847 */ 847 */
848 level() { 848 level() {
849 return this._level; 849 return this._level;
850 } 850 }
851 851
852 /** 852 /**
853 * @return {string} 853 * @return {string}
854 */ 854 */
855 text() { 855 text() {
856 return this._text; 856 return this._text;
857 } 857 }
858 858
859 /** 859 /**
860 * @return {!WebInspector.TextRange} 860 * @return {!Common.TextRange}
861 */ 861 */
862 range() { 862 range() {
863 return this._range; 863 return this._range;
864 } 864 }
865 865
866 /** 866 /**
867 * @return {number} 867 * @return {number}
868 */ 868 */
869 lineNumber() { 869 lineNumber() {
870 return this._range.startLine; 870 return this._range.startLine;
871 } 871 }
872 872
873 /** 873 /**
874 * @return {(number|undefined)} 874 * @return {(number|undefined)}
875 */ 875 */
876 columnNumber() { 876 columnNumber() {
877 return this._range.startColumn; 877 return this._range.startColumn;
878 } 878 }
879 879
880 /** 880 /**
881 * @param {!WebInspector.UISourceCode.Message} another 881 * @param {!Workspace.UISourceCode.Message} another
882 * @return {boolean} 882 * @return {boolean}
883 */ 883 */
884 isEqual(another) { 884 isEqual(another) {
885 return this._uiSourceCode === another._uiSourceCode && this.text() === anoth er.text() && 885 return this._uiSourceCode === another._uiSourceCode && this.text() === anoth er.text() &&
886 this.level() === another.level() && this.range().equal(another.range()); 886 this.level() === another.level() && this.range().equal(another.range());
887 } 887 }
888 888
889 remove() { 889 remove() {
890 this._uiSourceCode.removeMessage(this); 890 this._uiSourceCode.removeMessage(this);
891 } 891 }
892 }; 892 };
893 893
894 /** 894 /**
895 * @enum {string} 895 * @enum {string}
896 */ 896 */
897 WebInspector.UISourceCode.Message.Level = { 897 Workspace.UISourceCode.Message.Level = {
898 Error: 'Error', 898 Error: 'Error',
899 Warning: 'Warning' 899 Warning: 'Warning'
900 }; 900 };
901 901
902 /** 902 /**
903 * @unrestricted 903 * @unrestricted
904 */ 904 */
905 WebInspector.UISourceCode.LineMarker = class { 905 Workspace.UISourceCode.LineMarker = class {
906 /** 906 /**
907 * @param {number} line 907 * @param {number} line
908 * @param {string} type 908 * @param {string} type
909 * @param {?} data 909 * @param {?} data
910 */ 910 */
911 constructor(line, type, data) { 911 constructor(line, type, data) {
912 this._line = line; 912 this._line = line;
913 this._type = type; 913 this._type = type;
914 this._data = data; 914 this._data = data;
915 } 915 }
(...skipping 16 matching lines...) Expand all
932 * @return {*} 932 * @return {*}
933 */ 933 */
934 data() { 934 data() {
935 return this._data; 935 return this._data;
936 } 936 }
937 }; 937 };
938 938
939 /** 939 /**
940 * @unrestricted 940 * @unrestricted
941 */ 941 */
942 WebInspector.UISourceCodeMetadata = class { 942 Workspace.UISourceCodeMetadata = class {
943 /** 943 /**
944 * @param {?Date} modificationTime 944 * @param {?Date} modificationTime
945 * @param {?number} contentSize 945 * @param {?number} contentSize
946 */ 946 */
947 constructor(modificationTime, contentSize) { 947 constructor(modificationTime, contentSize) {
948 this.modificationTime = modificationTime; 948 this.modificationTime = modificationTime;
949 this.contentSize = contentSize; 949 this.contentSize = contentSize;
950 } 950 }
951 }; 951 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698