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

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

Issue 1564113003: DevTools: merge uisourcecode's url-alike members. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments addressed Created 4 years, 11 months 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 22 matching lines...) Expand all
33 * @constructor 33 * @constructor
34 * @extends {WebInspector.Object} 34 * @extends {WebInspector.Object}
35 * @implements {WebInspector.ContentProvider} 35 * @implements {WebInspector.ContentProvider}
36 * @param {!WebInspector.Project} project 36 * @param {!WebInspector.Project} project
37 * @param {string} url 37 * @param {string} url
38 * @param {!WebInspector.ResourceType} contentType 38 * @param {!WebInspector.ResourceType} contentType
39 */ 39 */
40 WebInspector.UISourceCode = function(project, url, contentType) 40 WebInspector.UISourceCode = function(project, url, contentType)
41 { 41 {
42 this._project = project; 42 this._project = project;
43 this._path = url; 43 this._url = url;
44 this._originURL = url;
45 44
46 var pathComponents = WebInspector.ParsedURL.splitURLIntoPathComponents(url); 45 var pathComponents = WebInspector.ParsedURL.splitURLIntoPathComponents(url);
47 this._host = pathComponents[0]; 46 this._origin = pathComponents[0];
48 this._parentPath = pathComponents.slice(0, -1).join("/"); 47 this._parentURL = pathComponents.slice(0, -1).join("/");
49 this._name = pathComponents[pathComponents.length - 1]; 48 this._name = pathComponents[pathComponents.length - 1];
50 49
51 this._contentType = contentType; 50 this._contentType = contentType;
52 /** @type {!Array.<function(?string)>} */ 51 /** @type {!Array.<function(?string)>} */
53 this._requestContentCallbacks = []; 52 this._requestContentCallbacks = [];
54 53
55 /** @type {!Array.<!WebInspector.Revision>} */ 54 /** @type {!Array.<!WebInspector.Revision>} */
56 this.history = []; 55 this.history = [];
57 this._hasUnsavedCommittedChanges = false; 56 this._hasUnsavedCommittedChanges = false;
58 57
(...skipping 10 matching lines...) Expand all
69 TitleChanged: "TitleChanged", 68 TitleChanged: "TitleChanged",
70 SourceMappingChanged: "SourceMappingChanged", 69 SourceMappingChanged: "SourceMappingChanged",
71 MessageAdded: "MessageAdded", 70 MessageAdded: "MessageAdded",
72 MessageRemoved: "MessageRemoved", 71 MessageRemoved: "MessageRemoved",
73 } 72 }
74 73
75 WebInspector.UISourceCode.prototype = { 74 WebInspector.UISourceCode.prototype = {
76 /** 75 /**
77 * @return {string} 76 * @return {string}
78 */ 77 */
79 path: function()
80 {
81 return this._path;
82 },
83
84 /**
85 * @return {string}
86 */
87 name: function() 78 name: function()
88 { 79 {
89 return this._name; 80 return this._name;
90 }, 81 },
91 82
92 /** 83 /**
93 * @return {string} 84 * @return {string}
94 */ 85 */
95 parentPath: function() 86 url: function()
96 { 87 {
97 return this._parentPath; 88 return this._url;
98 }, 89 },
99 90
100 /** 91 /**
101 * @return {string} 92 * @return {string}
102 */ 93 */
103 host: function() 94 parentURL: function()
104 { 95 {
105 return this._host; 96 return this._parentURL;
106 }, 97 },
107 98
108 /** 99 /**
100 * @return {string}
101 */
102 origin: function()
103 {
104 return this._origin;
105 },
106
107 /**
109 * @return {string} 108 * @return {string}
110 */ 109 */
111 fullDisplayName: function() 110 fullDisplayName: function()
112 { 111 {
113 return this._parentPath.replace(/^(?:https?|file)\:\/\//, "") + "/" + th is.displayName(true); 112 return this._parentURL.replace(/^(?:https?|file)\:\/\//, "") + "/" + thi s.displayName(true);
114 }, 113 },
115 114
116 /** 115 /**
117 * @param {boolean=} skipTrim 116 * @param {boolean=} skipTrim
118 * @return {string} 117 * @return {string}
119 */ 118 */
120 displayName: function(skipTrim) 119 displayName: function(skipTrim)
121 { 120 {
122 var displayName = this.name() || WebInspector.UIString("(index)"); 121 var displayName = this.name() || WebInspector.UIString("(index)");
123 return skipTrim ? displayName : displayName.trimEnd(100); 122 return skipTrim ? displayName : displayName.trimEnd(100);
124 }, 123 },
125 124
126 /** 125 /**
127 * @return {string}
128 */
129 uri: function()
130 {
131 return this._path;
132 },
133
134 /**
135 * @return {string}
136 */
137 originURL: function()
138 {
139 return this._originURL;
140 },
141
142 /**
143 * @return {boolean} 126 * @return {boolean}
144 */ 127 */
145 isFromServiceProject: function() 128 isFromServiceProject: function()
146 { 129 {
147 return WebInspector.Project.isServiceProject(this._project); 130 return WebInspector.Project.isServiceProject(this._project);
148 }, 131 },
149 132
150 /** 133 /**
151 * @return {boolean} 134 * @return {boolean}
152 */ 135 */
153 canRename: function() 136 canRename: function()
154 { 137 {
155 return this._project.canRename(); 138 return this._project.canRename();
156 }, 139 },
157 140
158 /** 141 /**
159 * @param {string} newName 142 * @param {string} newName
160 * @param {function(boolean)} callback 143 * @param {function(boolean)} callback
161 */ 144 */
162 rename: function(newName, callback) 145 rename: function(newName, callback)
163 { 146 {
164 this._project.rename(this, newName, innerCallback.bind(this)); 147 this._project.rename(this, newName, innerCallback.bind(this));
165 148
166 /** 149 /**
167 * @param {boolean} success 150 * @param {boolean} success
168 * @param {string=} newName 151 * @param {string=} newName
169 * @param {string=} newOriginURL 152 * @param {string=} newURL
170 * @param {!WebInspector.ResourceType=} newContentType 153 * @param {!WebInspector.ResourceType=} newContentType
171 * @this {WebInspector.UISourceCode} 154 * @this {WebInspector.UISourceCode}
172 */ 155 */
173 function innerCallback(success, newName, newOriginURL, newContentType) 156 function innerCallback(success, newName, newURL, newContentType)
174 { 157 {
175 if (success) 158 if (success)
176 this._updateName(/** @type {string} */ (newName), /** @type {str ing} */ (newOriginURL), /** @type {!WebInspector.ResourceType} */ (newContentTyp e)); 159 this._updateName(/** @type {string} */ (newName), /** @type {str ing} */ (newURL), /** @type {!WebInspector.ResourceType} */ (newContentType));
177 callback(success); 160 callback(success);
178 } 161 }
179 }, 162 },
180 163
181 remove: function() 164 remove: function()
182 { 165 {
183 this._project.deleteFile(this.path()); 166 this._project.deleteFile(this.url());
184 }, 167 },
185 168
186 /** 169 /**
187 * @param {string} name 170 * @param {string} name
188 * @param {string} originURL 171 * @param {string} url
189 * @param {!WebInspector.ResourceType=} contentType 172 * @param {!WebInspector.ResourceType=} contentType
190 */ 173 */
191 _updateName: function(name, originURL, contentType) 174 _updateName: function(name, url, contentType)
192 { 175 {
193 var oldURI = this.uri(); 176 var oldURĐ” = this.url();
194 this._path = this._path.substring(0, this._path.length - this._name.leng th) + name; 177 this._url = this._url.substring(0, this._url.length - this._name.length) + name;
195 this._name = name; 178 this._name = name;
196 if (originURL) 179 if (url)
197 this._originURL = originURL; 180 this._url = url;
198 if (contentType) 181 if (contentType)
199 this._contentType = contentType; 182 this._contentType = contentType;
200 this.dispatchEventToListeners(WebInspector.UISourceCode.Events.TitleChan ged, oldURI); 183 this.dispatchEventToListeners(WebInspector.UISourceCode.Events.TitleChan ged, oldURĐ”);
201 }, 184 },
202 185
203 /** 186 /**
204 * @override 187 * @override
205 * @return {string} 188 * @return {string}
206 */ 189 */
207 contentURL: function() 190 contentURL: function()
208 { 191 {
209 return this.originURL(); 192 return this.url();
210 }, 193 },
211 194
212 /** 195 /**
213 * @override 196 * @override
214 * @return {!WebInspector.ResourceType} 197 * @return {!WebInspector.ResourceType}
215 */ 198 */
216 contentType: function() 199 contentType: function()
217 { 200 {
218 return this._contentType; 201 return this._contentType;
219 }, 202 },
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 * @param {string} content 332 * @param {string} content
350 */ 333 */
351 _commitContent: function(content) 334 _commitContent: function(content)
352 { 335 {
353 var wasPersisted = false; 336 var wasPersisted = false;
354 if (this._project.canSetFileContent()) { 337 if (this._project.canSetFileContent()) {
355 this._project.setFileContent(this, content, function() { }); 338 this._project.setFileContent(this, content, function() { });
356 wasPersisted = true; 339 wasPersisted = true;
357 } else if (this._project.workspace().hasResourceContentTrackingExtension s()) { 340 } else if (this._project.workspace().hasResourceContentTrackingExtension s()) {
358 wasPersisted = true; 341 wasPersisted = true;
359 } else if (this._originURL && WebInspector.fileManager.isURLSaved(this._ originURL)) { 342 } else if (this._url && WebInspector.fileManager.isURLSaved(this._url)) {
360 WebInspector.fileManager.save(this._originURL, content, false, funct ion() { }); 343 WebInspector.fileManager.save(this._url, content, false, function() { });
361 WebInspector.fileManager.close(this._originURL); 344 WebInspector.fileManager.close(this._url);
362 wasPersisted = true; 345 wasPersisted = true;
363 } 346 }
364 this._contentCommitted(content, wasPersisted, true); 347 this._contentCommitted(content, wasPersisted, true);
365 }, 348 },
366 349
367 /** 350 /**
368 * @param {string} content 351 * @param {string} content
369 * @param {boolean} wasPersisted 352 * @param {boolean} wasPersisted
370 * @param {boolean} committedByUser 353 * @param {boolean} committedByUser
371 */ 354 */
(...skipping 12 matching lines...) Expand all
384 this._innerResetWorkingCopy(); 367 this._innerResetWorkingCopy();
385 this._hasUnsavedCommittedChanges = !wasPersisted; 368 this._hasUnsavedCommittedChanges = !wasPersisted;
386 this.dispatchEventToListeners(WebInspector.UISourceCode.Events.WorkingCo pyCommitted); 369 this.dispatchEventToListeners(WebInspector.UISourceCode.Events.WorkingCo pyCommitted);
387 this._project.workspace().dispatchEventToListeners(WebInspector.Workspac e.Events.WorkingCopyCommitted, { uiSourceCode: this, content: content }); 370 this._project.workspace().dispatchEventToListeners(WebInspector.Workspac e.Events.WorkingCopyCommitted, { uiSourceCode: this, content: content });
388 if (committedByUser) 371 if (committedByUser)
389 this._project.workspace().dispatchEventToListeners(WebInspector.Work space.Events.WorkingCopyCommittedByUser, { uiSourceCode: this, content: content }); 372 this._project.workspace().dispatchEventToListeners(WebInspector.Work space.Events.WorkingCopyCommittedByUser, { uiSourceCode: this, content: content });
390 }, 373 },
391 374
392 saveAs: function() 375 saveAs: function()
393 { 376 {
394 WebInspector.fileManager.save(this._originURL, this.workingCopy(), true, callback.bind(this)); 377 WebInspector.fileManager.save(this._url, this.workingCopy(), true, callb ack.bind(this));
395 WebInspector.fileManager.close(this._originURL); 378 WebInspector.fileManager.close(this._url);
396 379
397 /** 380 /**
398 * @param {boolean} accepted 381 * @param {boolean} accepted
399 * @this {WebInspector.UISourceCode} 382 * @this {WebInspector.UISourceCode}
400 */ 383 */
401 function callback(accepted) 384 function callback(accepted)
402 { 385 {
403 if (accepted) 386 if (accepted)
404 this._contentCommitted(this.workingCopy(), true, true); 387 this._contentCommitted(this.workingCopy(), true, true);
405 } 388 }
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 if (typeof this.lineNumber === "number") 656 if (typeof this.lineNumber === "number")
674 linkText += ":" + (this.lineNumber + 1); 657 linkText += ":" + (this.lineNumber + 1);
675 return linkText; 658 return linkText;
676 }, 659 },
677 660
678 /** 661 /**
679 * @return {string} 662 * @return {string}
680 */ 663 */
681 id: function() 664 id: function()
682 { 665 {
683 return this.uiSourceCode.project().id() + ":" + this.uiSourceCode.uri() + ":" + this.lineNumber + ":" + this.columnNumber; 666 return this.uiSourceCode.project().id() + ":" + this.uiSourceCode.url() + ":" + this.lineNumber + ":" + this.columnNumber;
684 }, 667 },
685 668
686 /** 669 /**
687 * @return {string} 670 * @return {string}
688 */ 671 */
689 toUIString: function() 672 toUIString: function()
690 { 673 {
691 return this.uiSourceCode.uri() + ":" + (this.lineNumber + 1); 674 return this.uiSourceCode.url() + ":" + (this.lineNumber + 1);
692 } 675 }
693 } 676 }
694 677
695 /** 678 /**
696 * @constructor 679 * @constructor
697 * @implements {WebInspector.ContentProvider} 680 * @implements {WebInspector.ContentProvider}
698 * @param {!WebInspector.UISourceCode} uiSourceCode 681 * @param {!WebInspector.UISourceCode} uiSourceCode
699 * @param {?string|undefined} content 682 * @param {?string|undefined} content
700 * @param {!Date} timestamp 683 * @param {!Date} timestamp
701 */ 684 */
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Rev isionApplied); 728 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Rev isionApplied);
746 this.requestContent(revert.bind(this)); 729 this.requestContent(revert.bind(this));
747 }, 730 },
748 731
749 /** 732 /**
750 * @override 733 * @override
751 * @return {string} 734 * @return {string}
752 */ 735 */
753 contentURL: function() 736 contentURL: function()
754 { 737 {
755 return this._uiSourceCode.originURL(); 738 return this._uiSourceCode.url();
756 }, 739 },
757 740
758 /** 741 /**
759 * @override 742 * @override
760 * @return {!WebInspector.ResourceType} 743 * @return {!WebInspector.ResourceType}
761 */ 744 */
762 contentType: function() 745 contentType: function()
763 { 746 {
764 return this._uiSourceCode.contentType(); 747 return this._uiSourceCode.contentType();
765 }, 748 },
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 isEqual: function(another) 847 isEqual: function(another)
865 { 848 {
866 return this._uiSourceCode === another._uiSourceCode && this.text() === a nother.text() && this.level() === another.level() && this.range().equal(another. range()); 849 return this._uiSourceCode === another._uiSourceCode && this.text() === a nother.text() && this.level() === another.level() && this.range().equal(another. range());
867 }, 850 },
868 851
869 remove: function() 852 remove: function()
870 { 853 {
871 this._uiSourceCode.removeMessage(this); 854 this._uiSourceCode.removeMessage(this);
872 } 855 }
873 } 856 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698