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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sources/ScriptFormatterEditorAction.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 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 /** 4 /**
5 * @implements {WebInspector.DebuggerSourceMapping} 5 * @implements {Bindings.DebuggerSourceMapping}
6 * @unrestricted 6 * @unrestricted
7 */ 7 */
8 WebInspector.FormatterScriptMapping = class { 8 Sources.FormatterScriptMapping = class {
9 /** 9 /**
10 * @param {!WebInspector.DebuggerModel} debuggerModel 10 * @param {!SDK.DebuggerModel} debuggerModel
11 * @param {!WebInspector.ScriptFormatterEditorAction} editorAction 11 * @param {!Sources.ScriptFormatterEditorAction} editorAction
12 */ 12 */
13 constructor(debuggerModel, editorAction) { 13 constructor(debuggerModel, editorAction) {
14 this._debuggerModel = debuggerModel; 14 this._debuggerModel = debuggerModel;
15 this._editorAction = editorAction; 15 this._editorAction = editorAction;
16 } 16 }
17 17
18 /** 18 /**
19 * @override 19 * @override
20 * @param {!WebInspector.DebuggerModel.Location} rawLocation 20 * @param {!SDK.DebuggerModel.Location} rawLocation
21 * @return {?WebInspector.UILocation} 21 * @return {?Workspace.UILocation}
22 */ 22 */
23 rawLocationToUILocation(rawLocation) { 23 rawLocationToUILocation(rawLocation) {
24 var debuggerModelLocation = /** @type {!WebInspector.DebuggerModel.Location} */ (rawLocation); 24 var debuggerModelLocation = /** @type {!SDK.DebuggerModel.Location} */ (rawL ocation);
25 var script = debuggerModelLocation.script(); 25 var script = debuggerModelLocation.script();
26 if (!script) 26 if (!script)
27 return null; 27 return null;
28 var uiSourceCode = this._editorAction._uiSourceCodes.get(script); 28 var uiSourceCode = this._editorAction._uiSourceCodes.get(script);
29 if (!uiSourceCode) 29 if (!uiSourceCode)
30 return null; 30 return null;
31 31
32 var formatData = this._editorAction._formatData.get(uiSourceCode); 32 var formatData = this._editorAction._formatData.get(uiSourceCode);
33 if (!formatData) 33 if (!formatData)
34 return null; 34 return null;
35 var mapping = formatData.mapping; 35 var mapping = formatData.mapping;
36 var lineNumber = debuggerModelLocation.lineNumber; 36 var lineNumber = debuggerModelLocation.lineNumber;
37 var columnNumber = debuggerModelLocation.columnNumber || 0; 37 var columnNumber = debuggerModelLocation.columnNumber || 0;
38 var formattedLocation = mapping.originalToFormatted(lineNumber, columnNumber ); 38 var formattedLocation = mapping.originalToFormatted(lineNumber, columnNumber );
39 return uiSourceCode.uiLocation(formattedLocation[0], formattedLocation[1]); 39 return uiSourceCode.uiLocation(formattedLocation[0], formattedLocation[1]);
40 } 40 }
41 41
42 /** 42 /**
43 * @override 43 * @override
44 * @param {!WebInspector.UISourceCode} uiSourceCode 44 * @param {!Workspace.UISourceCode} uiSourceCode
45 * @param {number} lineNumber 45 * @param {number} lineNumber
46 * @param {number} columnNumber 46 * @param {number} columnNumber
47 * @return {?WebInspector.DebuggerModel.Location} 47 * @return {?SDK.DebuggerModel.Location}
48 */ 48 */
49 uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber) { 49 uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber) {
50 var formatData = this._editorAction._formatData.get(uiSourceCode); 50 var formatData = this._editorAction._formatData.get(uiSourceCode);
51 if (!formatData) 51 if (!formatData)
52 return null; 52 return null;
53 var originalLocation = formatData.mapping.formattedToOriginal(lineNumber, co lumnNumber); 53 var originalLocation = formatData.mapping.formattedToOriginal(lineNumber, co lumnNumber);
54 for (var i = 0; i < formatData.scripts.length; ++i) { 54 for (var i = 0; i < formatData.scripts.length; ++i) {
55 if (formatData.scripts[i].debuggerModel === this._debuggerModel) 55 if (formatData.scripts[i].debuggerModel === this._debuggerModel)
56 return this._debuggerModel.createRawLocation(formatData.scripts[i], orig inalLocation[0], originalLocation[1]); 56 return this._debuggerModel.createRawLocation(formatData.scripts[i], orig inalLocation[0], originalLocation[1]);
57 } 57 }
58 return null; 58 return null;
59 } 59 }
60 60
61 /** 61 /**
62 * @override 62 * @override
63 * @return {boolean} 63 * @return {boolean}
64 */ 64 */
65 isIdentity() { 65 isIdentity() {
66 return false; 66 return false;
67 } 67 }
68 68
69 /** 69 /**
70 * @override 70 * @override
71 * @param {!WebInspector.UISourceCode} uiSourceCode 71 * @param {!Workspace.UISourceCode} uiSourceCode
72 * @param {number} lineNumber 72 * @param {number} lineNumber
73 * @return {boolean} 73 * @return {boolean}
74 */ 74 */
75 uiLineHasMapping(uiSourceCode, lineNumber) { 75 uiLineHasMapping(uiSourceCode, lineNumber) {
76 return true; 76 return true;
77 } 77 }
78 }; 78 };
79 79
80 /** 80 /**
81 * @unrestricted 81 * @unrestricted
82 */ 82 */
83 WebInspector.FormatterScriptMapping.FormatData = class { 83 Sources.FormatterScriptMapping.FormatData = class {
84 /** 84 /**
85 * @param {string} projectId 85 * @param {string} projectId
86 * @param {string} path 86 * @param {string} path
87 * @param {!WebInspector.FormatterSourceMapping} mapping 87 * @param {!Sources.FormatterSourceMapping} mapping
88 * @param {!Array.<!WebInspector.Script>} scripts 88 * @param {!Array.<!SDK.Script>} scripts
89 */ 89 */
90 constructor(projectId, path, mapping, scripts) { 90 constructor(projectId, path, mapping, scripts) {
91 this.projectId = projectId; 91 this.projectId = projectId;
92 this.path = path; 92 this.path = path;
93 this.mapping = mapping; 93 this.mapping = mapping;
94 this.scripts = scripts; 94 this.scripts = scripts;
95 } 95 }
96 }; 96 };
97 97
98 /** 98 /**
99 * @implements {WebInspector.SourcesView.EditorAction} 99 * @implements {Sources.SourcesView.EditorAction}
100 * @implements {WebInspector.TargetManager.Observer} 100 * @implements {SDK.TargetManager.Observer}
101 * @unrestricted 101 * @unrestricted
102 */ 102 */
103 WebInspector.ScriptFormatterEditorAction = class { 103 Sources.ScriptFormatterEditorAction = class {
104 constructor() { 104 constructor() {
105 this._projectId = 'formatter:'; 105 this._projectId = 'formatter:';
106 this._project = new WebInspector.ContentProviderBasedProject( 106 this._project = new Bindings.ContentProviderBasedProject(
107 WebInspector.workspace, this._projectId, WebInspector.projectTypes.Forma tter, 'formatter'); 107 Workspace.workspace, this._projectId, Workspace.projectTypes.Formatter, 'formatter');
108 108
109 /** @type {!Map.<!WebInspector.Script, !WebInspector.UISourceCode>} */ 109 /** @type {!Map.<!SDK.Script, !Workspace.UISourceCode>} */
110 this._uiSourceCodes = new Map(); 110 this._uiSourceCodes = new Map();
111 /** @type {!Map.<string, string>} */ 111 /** @type {!Map.<string, string>} */
112 this._formattedPaths = new Map(); 112 this._formattedPaths = new Map();
113 /** @type {!Map.<!WebInspector.UISourceCode, !WebInspector.FormatterScriptMa pping.FormatData>} */ 113 /** @type {!Map.<!Workspace.UISourceCode, !Sources.FormatterScriptMapping.Fo rmatData>} */
114 this._formatData = new Map(); 114 this._formatData = new Map();
115 115
116 /** @type {!Set.<string>} */ 116 /** @type {!Set.<string>} */
117 this._pathsToFormatOnLoad = new Set(); 117 this._pathsToFormatOnLoad = new Set();
118 118
119 /** @type {!Map.<!WebInspector.Target, !WebInspector.FormatterScriptMapping> } */ 119 /** @type {!Map.<!SDK.Target, !Sources.FormatterScriptMapping>} */
120 this._scriptMappingByTarget = new Map(); 120 this._scriptMappingByTarget = new Map();
121 this._workspace = WebInspector.workspace; 121 this._workspace = Workspace.workspace;
122 WebInspector.targetManager.observeTargets(this); 122 SDK.targetManager.observeTargets(this);
123 } 123 }
124 124
125 /** 125 /**
126 * @override 126 * @override
127 * @param {!WebInspector.Target} target 127 * @param {!SDK.Target} target
128 */ 128 */
129 targetAdded(target) { 129 targetAdded(target) {
130 var debuggerModel = WebInspector.DebuggerModel.fromTarget(target); 130 var debuggerModel = SDK.DebuggerModel.fromTarget(target);
131 if (!debuggerModel) 131 if (!debuggerModel)
132 return; 132 return;
133 this._scriptMappingByTarget.set(target, new WebInspector.FormatterScriptMapp ing(debuggerModel, this)); 133 this._scriptMappingByTarget.set(target, new Sources.FormatterScriptMapping(d ebuggerModel, this));
134 debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.GlobalObjec tCleared, this._debuggerReset, this); 134 debuggerModel.addEventListener(SDK.DebuggerModel.Events.GlobalObjectCleared, this._debuggerReset, this);
135 } 135 }
136 136
137 /** 137 /**
138 * @override 138 * @override
139 * @param {!WebInspector.Target} target 139 * @param {!SDK.Target} target
140 */ 140 */
141 targetRemoved(target) { 141 targetRemoved(target) {
142 var debuggerModel = WebInspector.DebuggerModel.fromTarget(target); 142 var debuggerModel = SDK.DebuggerModel.fromTarget(target);
143 if (!debuggerModel) 143 if (!debuggerModel)
144 return; 144 return;
145 this._scriptMappingByTarget.remove(target); 145 this._scriptMappingByTarget.remove(target);
146 this._cleanForTarget(target); 146 this._cleanForTarget(target);
147 debuggerModel.removeEventListener(WebInspector.DebuggerModel.Events.GlobalOb jectCleared, this._debuggerReset, this); 147 debuggerModel.removeEventListener(SDK.DebuggerModel.Events.GlobalObjectClear ed, this._debuggerReset, this);
148 } 148 }
149 149
150 /** 150 /**
151 * @param {!WebInspector.Event} event 151 * @param {!Common.Event} event
152 */ 152 */
153 _editorSelected(event) { 153 _editorSelected(event) {
154 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data); 154 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data);
155 this._updateButton(uiSourceCode); 155 this._updateButton(uiSourceCode);
156 156
157 var path = uiSourceCode.project().id() + ':' + uiSourceCode.url(); 157 var path = uiSourceCode.project().id() + ':' + uiSourceCode.url();
158 if (this._isFormatableScript(uiSourceCode) && this._pathsToFormatOnLoad.has( path) && 158 if (this._isFormatableScript(uiSourceCode) && this._pathsToFormatOnLoad.has( path) &&
159 !this._formattedPaths.get(path)) 159 !this._formattedPaths.get(path))
160 this._formatUISourceCodeScript(uiSourceCode); 160 this._formatUISourceCodeScript(uiSourceCode);
161 } 161 }
162 162
163 /** 163 /**
164 * @param {!WebInspector.Event} event 164 * @param {!Common.Event} event
165 */ 165 */
166 _editorClosed(event) { 166 _editorClosed(event) {
167 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data.uiS ourceCode); 167 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data.uiSour ceCode);
168 var wasSelected = /** @type {boolean} */ (event.data.wasSelected); 168 var wasSelected = /** @type {boolean} */ (event.data.wasSelected);
169 169
170 if (wasSelected) 170 if (wasSelected)
171 this._updateButton(null); 171 this._updateButton(null);
172 this._discardFormattedUISourceCodeScript(uiSourceCode); 172 this._discardFormattedUISourceCodeScript(uiSourceCode);
173 } 173 }
174 174
175 /** 175 /**
176 * @param {?WebInspector.UISourceCode} uiSourceCode 176 * @param {?Workspace.UISourceCode} uiSourceCode
177 */ 177 */
178 _updateButton(uiSourceCode) { 178 _updateButton(uiSourceCode) {
179 this._button.element.classList.toggle('hidden', !this._isFormatableScript(ui SourceCode)); 179 this._button.element.classList.toggle('hidden', !this._isFormatableScript(ui SourceCode));
180 } 180 }
181 181
182 /** 182 /**
183 * @override 183 * @override
184 * @param {!WebInspector.SourcesView} sourcesView 184 * @param {!Sources.SourcesView} sourcesView
185 * @return {!WebInspector.ToolbarButton} 185 * @return {!UI.ToolbarButton}
186 */ 186 */
187 button(sourcesView) { 187 button(sourcesView) {
188 if (this._button) 188 if (this._button)
189 return this._button; 189 return this._button;
190 190
191 this._sourcesView = sourcesView; 191 this._sourcesView = sourcesView;
192 this._sourcesView.addEventListener(WebInspector.SourcesView.Events.EditorSel ected, this._editorSelected.bind(this)); 192 this._sourcesView.addEventListener(Sources.SourcesView.Events.EditorSelected , this._editorSelected.bind(this));
193 this._sourcesView.addEventListener(WebInspector.SourcesView.Events.EditorClo sed, this._editorClosed.bind(this)); 193 this._sourcesView.addEventListener(Sources.SourcesView.Events.EditorClosed, this._editorClosed.bind(this));
194 194
195 this._button = new WebInspector.ToolbarButton(WebInspector.UIString('Pretty print'), 'largeicon-pretty-print'); 195 this._button = new UI.ToolbarButton(Common.UIString('Pretty print'), 'largei con-pretty-print');
196 this._button.addEventListener('click', this._toggleFormatScriptSource, this) ; 196 this._button.addEventListener('click', this._toggleFormatScriptSource, this) ;
197 this._updateButton(sourcesView.currentUISourceCode()); 197 this._updateButton(sourcesView.currentUISourceCode());
198 198
199 return this._button; 199 return this._button;
200 } 200 }
201 201
202 /** 202 /**
203 * @param {?WebInspector.UISourceCode} uiSourceCode 203 * @param {?Workspace.UISourceCode} uiSourceCode
204 * @return {boolean} 204 * @return {boolean}
205 */ 205 */
206 _isFormatableScript(uiSourceCode) { 206 _isFormatableScript(uiSourceCode) {
207 if (!uiSourceCode) 207 if (!uiSourceCode)
208 return false; 208 return false;
209 if (WebInspector.persistence.binding(uiSourceCode)) 209 if (Persistence.persistence.binding(uiSourceCode))
210 return false; 210 return false;
211 var supportedProjectTypes = [ 211 var supportedProjectTypes = [
212 WebInspector.projectTypes.Network, WebInspector.projectTypes.Debugger, Web Inspector.projectTypes.ContentScripts 212 Workspace.projectTypes.Network, Workspace.projectTypes.Debugger, Workspace .projectTypes.ContentScripts
213 ]; 213 ];
214 if (supportedProjectTypes.indexOf(uiSourceCode.project().type()) === -1) 214 if (supportedProjectTypes.indexOf(uiSourceCode.project().type()) === -1)
215 return false; 215 return false;
216 return uiSourceCode.contentType().hasScripts(); 216 return uiSourceCode.contentType().hasScripts();
217 } 217 }
218 218
219 _toggleFormatScriptSource() { 219 _toggleFormatScriptSource() {
220 var uiSourceCode = this._sourcesView.currentUISourceCode(); 220 var uiSourceCode = this._sourcesView.currentUISourceCode();
221 if (this._isFormatableScript(uiSourceCode)) 221 if (this._isFormatableScript(uiSourceCode))
222 this._formatUISourceCodeScript(uiSourceCode); 222 this._formatUISourceCodeScript(uiSourceCode);
223 } 223 }
224 224
225 /** 225 /**
226 * @param {!WebInspector.UISourceCode} uiSourceCode 226 * @param {!Workspace.UISourceCode} uiSourceCode
227 * @param {!WebInspector.UISourceCode} formattedUISourceCode 227 * @param {!Workspace.UISourceCode} formattedUISourceCode
228 * @param {!WebInspector.FormatterSourceMapping} mapping 228 * @param {!Sources.FormatterSourceMapping} mapping
229 * @private 229 * @private
230 */ 230 */
231 _showIfNeeded(uiSourceCode, formattedUISourceCode, mapping) { 231 _showIfNeeded(uiSourceCode, formattedUISourceCode, mapping) {
232 if (uiSourceCode !== this._sourcesView.currentUISourceCode()) 232 if (uiSourceCode !== this._sourcesView.currentUISourceCode())
233 return; 233 return;
234 var sourceFrame = this._sourcesView.viewForFile(uiSourceCode); 234 var sourceFrame = this._sourcesView.viewForFile(uiSourceCode);
235 var start = [0, 0]; 235 var start = [0, 0];
236 if (sourceFrame) { 236 if (sourceFrame) {
237 var selection = sourceFrame.selection(); 237 var selection = sourceFrame.selection();
238 start = mapping.originalToFormatted(selection.startLine, selection.startCo lumn); 238 start = mapping.originalToFormatted(selection.startLine, selection.startCo lumn);
239 } 239 }
240 this._sourcesView.showSourceLocation(formattedUISourceCode, start[0], start[ 1]); 240 this._sourcesView.showSourceLocation(formattedUISourceCode, start[0], start[ 1]);
241 this._updateButton(formattedUISourceCode); 241 this._updateButton(formattedUISourceCode);
242 } 242 }
243 243
244 /** 244 /**
245 * @param {!WebInspector.UISourceCode} formattedUISourceCode 245 * @param {!Workspace.UISourceCode} formattedUISourceCode
246 */ 246 */
247 _discardFormattedUISourceCodeScript(formattedUISourceCode) { 247 _discardFormattedUISourceCodeScript(formattedUISourceCode) {
248 var formatData = this._formatData.get(formattedUISourceCode); 248 var formatData = this._formatData.get(formattedUISourceCode);
249 if (!formatData) 249 if (!formatData)
250 return; 250 return;
251 251
252 this._formatData.remove(formattedUISourceCode); 252 this._formatData.remove(formattedUISourceCode);
253 var path = formatData.projectId + ':' + formatData.path; 253 var path = formatData.projectId + ':' + formatData.path;
254 this._formattedPaths.remove(path); 254 this._formattedPaths.remove(path);
255 this._pathsToFormatOnLoad.delete(path); 255 this._pathsToFormatOnLoad.delete(path);
256 for (var i = 0; i < formatData.scripts.length; ++i) { 256 for (var i = 0; i < formatData.scripts.length; ++i) {
257 this._uiSourceCodes.remove(formatData.scripts[i]); 257 this._uiSourceCodes.remove(formatData.scripts[i]);
258 WebInspector.debuggerWorkspaceBinding.popSourceMapping(formatData.scripts[ i]); 258 Bindings.debuggerWorkspaceBinding.popSourceMapping(formatData.scripts[i]);
259 } 259 }
260 this._project.removeFile(formattedUISourceCode.url()); 260 this._project.removeFile(formattedUISourceCode.url());
261 } 261 }
262 262
263 /** 263 /**
264 * @param {!WebInspector.Target} target 264 * @param {!SDK.Target} target
265 */ 265 */
266 _cleanForTarget(target) { 266 _cleanForTarget(target) {
267 var uiSourceCodes = this._formatData.keysArray(); 267 var uiSourceCodes = this._formatData.keysArray();
268 for (var i = 0; i < uiSourceCodes.length; ++i) { 268 for (var i = 0; i < uiSourceCodes.length; ++i) {
269 WebInspector.debuggerWorkspaceBinding.setSourceMapping(target, uiSourceCod es[i], null); 269 Bindings.debuggerWorkspaceBinding.setSourceMapping(target, uiSourceCodes[i ], null);
270 var formatData = this._formatData.get(uiSourceCodes[i]); 270 var formatData = this._formatData.get(uiSourceCodes[i]);
271 var scripts = []; 271 var scripts = [];
272 for (var j = 0; j < formatData.scripts.length; ++j) { 272 for (var j = 0; j < formatData.scripts.length; ++j) {
273 if (formatData.scripts[j].target() === target) 273 if (formatData.scripts[j].target() === target)
274 this._uiSourceCodes.remove(formatData.scripts[j]); 274 this._uiSourceCodes.remove(formatData.scripts[j]);
275 else 275 else
276 scripts.push(formatData.scripts[j]); 276 scripts.push(formatData.scripts[j]);
277 } 277 }
278 278
279 if (scripts.length) 279 if (scripts.length)
280 formatData.scripts = scripts; 280 formatData.scripts = scripts;
281 else { 281 else {
282 this._formattedPaths.remove(formatData.projectId + ':' + formatData.path ); 282 this._formattedPaths.remove(formatData.projectId + ':' + formatData.path );
283 this._formatData.remove(uiSourceCodes[i]); 283 this._formatData.remove(uiSourceCodes[i]);
284 this._project.removeFile(uiSourceCodes[i].url()); 284 this._project.removeFile(uiSourceCodes[i].url());
285 } 285 }
286 } 286 }
287 } 287 }
288 288
289 /** 289 /**
290 * @param {!WebInspector.Event} event 290 * @param {!Common.Event} event
291 */ 291 */
292 _debuggerReset(event) { 292 _debuggerReset(event) {
293 var debuggerModel = /** @type {!WebInspector.DebuggerModel} */ (event.target ); 293 var debuggerModel = /** @type {!SDK.DebuggerModel} */ (event.target);
294 this._cleanForTarget(debuggerModel.target()); 294 this._cleanForTarget(debuggerModel.target());
295 } 295 }
296 296
297 /** 297 /**
298 * @param {!WebInspector.UISourceCode} uiSourceCode 298 * @param {!Workspace.UISourceCode} uiSourceCode
299 * @return {!Array.<!WebInspector.Script>} 299 * @return {!Array.<!SDK.Script>}
300 */ 300 */
301 _scriptsForUISourceCode(uiSourceCode) { 301 _scriptsForUISourceCode(uiSourceCode) {
302 /** 302 /**
303 * @param {!WebInspector.Script} script 303 * @param {!SDK.Script} script
304 * @return {boolean} 304 * @return {boolean}
305 */ 305 */
306 function isInlineScript(script) { 306 function isInlineScript(script) {
307 return script.isInlineScript() && !script.hasSourceURL; 307 return script.isInlineScript() && !script.hasSourceURL;
308 } 308 }
309 309
310 if (uiSourceCode.contentType() === WebInspector.resourceTypes.Document) { 310 if (uiSourceCode.contentType() === Common.resourceTypes.Document) {
311 var scripts = []; 311 var scripts = [];
312 var debuggerModels = WebInspector.DebuggerModel.instances(); 312 var debuggerModels = SDK.DebuggerModel.instances();
313 for (var i = 0; i < debuggerModels.length; ++i) 313 for (var i = 0; i < debuggerModels.length; ++i)
314 scripts.pushAll(debuggerModels[i].scriptsForSourceURL(uiSourceCode.url() )); 314 scripts.pushAll(debuggerModels[i].scriptsForSourceURL(uiSourceCode.url() ));
315 return scripts.filter(isInlineScript); 315 return scripts.filter(isInlineScript);
316 } 316 }
317 if (uiSourceCode.contentType().isScript()) { 317 if (uiSourceCode.contentType().isScript()) {
318 var rawLocations = WebInspector.debuggerWorkspaceBinding.uiLocationToRawLo cations(uiSourceCode, 0, 0); 318 var rawLocations = Bindings.debuggerWorkspaceBinding.uiLocationToRawLocati ons(uiSourceCode, 0, 0);
319 return rawLocations.map(function(rawLocation) { 319 return rawLocations.map(function(rawLocation) {
320 return rawLocation.script(); 320 return rawLocation.script();
321 }); 321 });
322 } 322 }
323 return []; 323 return [];
324 } 324 }
325 325
326 /** 326 /**
327 * @param {!WebInspector.UISourceCode} uiSourceCode 327 * @param {!Workspace.UISourceCode} uiSourceCode
328 */ 328 */
329 _formatUISourceCodeScript(uiSourceCode) { 329 _formatUISourceCodeScript(uiSourceCode) {
330 var formattedPath = this._formattedPaths.get(uiSourceCode.project().id() + ' :' + uiSourceCode.url()); 330 var formattedPath = this._formattedPaths.get(uiSourceCode.project().id() + ' :' + uiSourceCode.url());
331 if (formattedPath) { 331 if (formattedPath) {
332 var uiSourceCodePath = formattedPath; 332 var uiSourceCodePath = formattedPath;
333 var formattedUISourceCode = this._workspace.uiSourceCode(this._projectId, uiSourceCodePath); 333 var formattedUISourceCode = this._workspace.uiSourceCode(this._projectId, uiSourceCodePath);
334 var formatData = formattedUISourceCode ? this._formatData.get(formattedUIS ourceCode) : null; 334 var formatData = formattedUISourceCode ? this._formatData.get(formattedUIS ourceCode) : null;
335 if (formatData) 335 if (formatData)
336 this._showIfNeeded( 336 this._showIfNeeded(
337 uiSourceCode, /** @type {!WebInspector.UISourceCode} */ (formattedUI SourceCode), formatData.mapping); 337 uiSourceCode, /** @type {!Workspace.UISourceCode} */ (formattedUISou rceCode), formatData.mapping);
338 return; 338 return;
339 } 339 }
340 340
341 uiSourceCode.requestContent().then(contentLoaded.bind(this)); 341 uiSourceCode.requestContent().then(contentLoaded.bind(this));
342 342
343 /** 343 /**
344 * @this {WebInspector.ScriptFormatterEditorAction} 344 * @this {Sources.ScriptFormatterEditorAction}
345 * @param {?string} content 345 * @param {?string} content
346 */ 346 */
347 function contentLoaded(content) { 347 function contentLoaded(content) {
348 var highlighterType = WebInspector.NetworkProject.uiSourceCodeMimeType(uiS ourceCode); 348 var highlighterType = Bindings.NetworkProject.uiSourceCodeMimeType(uiSourc eCode);
349 WebInspector.Formatter.format( 349 Sources.Formatter.format(
350 uiSourceCode.contentType(), highlighterType, content || '', innerCallb ack.bind(this)); 350 uiSourceCode.contentType(), highlighterType, content || '', innerCallb ack.bind(this));
351 } 351 }
352 352
353 /** 353 /**
354 * @this {WebInspector.ScriptFormatterEditorAction} 354 * @this {Sources.ScriptFormatterEditorAction}
355 * @param {string} formattedContent 355 * @param {string} formattedContent
356 * @param {!WebInspector.FormatterSourceMapping} formatterMapping 356 * @param {!Sources.FormatterSourceMapping} formatterMapping
357 */ 357 */
358 function innerCallback(formattedContent, formatterMapping) { 358 function innerCallback(formattedContent, formatterMapping) {
359 var scripts = this._scriptsForUISourceCode(uiSourceCode); 359 var scripts = this._scriptsForUISourceCode(uiSourceCode);
360 var formattedURL = uiSourceCode.url() + ':formatted'; 360 var formattedURL = uiSourceCode.url() + ':formatted';
361 var contentProvider = 361 var contentProvider =
362 WebInspector.StaticContentProvider.fromString(formattedURL, uiSourceCo de.contentType(), formattedContent); 362 Common.StaticContentProvider.fromString(formattedURL, uiSourceCode.con tentType(), formattedContent);
363 var formattedUISourceCode = this._project.addContentProvider(formattedURL, contentProvider); 363 var formattedUISourceCode = this._project.addContentProvider(formattedURL, contentProvider);
364 var formattedPath = formattedUISourceCode.url(); 364 var formattedPath = formattedUISourceCode.url();
365 var formatData = new WebInspector.FormatterScriptMapping.FormatData( 365 var formatData = new Sources.FormatterScriptMapping.FormatData(
366 uiSourceCode.project().id(), uiSourceCode.url(), formatterMapping, scr ipts); 366 uiSourceCode.project().id(), uiSourceCode.url(), formatterMapping, scr ipts);
367 this._formatData.set(formattedUISourceCode, formatData); 367 this._formatData.set(formattedUISourceCode, formatData);
368 var path = uiSourceCode.project().id() + ':' + uiSourceCode.url(); 368 var path = uiSourceCode.project().id() + ':' + uiSourceCode.url();
369 this._formattedPaths.set(path, formattedPath); 369 this._formattedPaths.set(path, formattedPath);
370 this._pathsToFormatOnLoad.add(path); 370 this._pathsToFormatOnLoad.add(path);
371 for (var i = 0; i < scripts.length; ++i) { 371 for (var i = 0; i < scripts.length; ++i) {
372 this._uiSourceCodes.set(scripts[i], formattedUISourceCode); 372 this._uiSourceCodes.set(scripts[i], formattedUISourceCode);
373 var scriptMapping = 373 var scriptMapping =
374 /** @type {!WebInspector.FormatterScriptMapping} */ (this._scriptMap pingByTarget.get(scripts[i].target())); 374 /** @type {!Sources.FormatterScriptMapping} */ (this._scriptMappingB yTarget.get(scripts[i].target()));
375 WebInspector.debuggerWorkspaceBinding.pushSourceMapping(scripts[i], scri ptMapping); 375 Bindings.debuggerWorkspaceBinding.pushSourceMapping(scripts[i], scriptMa pping);
376 } 376 }
377 377
378 var targets = WebInspector.targetManager.targets(); 378 var targets = SDK.targetManager.targets();
379 for (var i = 0; i < targets.length; ++i) { 379 for (var i = 0; i < targets.length; ++i) {
380 var scriptMapping = 380 var scriptMapping =
381 /** @type {!WebInspector.FormatterScriptMapping} */ (this._scriptMap pingByTarget.get(targets[i])); 381 /** @type {!Sources.FormatterScriptMapping} */ (this._scriptMappingB yTarget.get(targets[i]));
382 WebInspector.debuggerWorkspaceBinding.setSourceMapping(targets[i], forma ttedUISourceCode, scriptMapping); 382 Bindings.debuggerWorkspaceBinding.setSourceMapping(targets[i], formatted UISourceCode, scriptMapping);
383 } 383 }
384 this._showIfNeeded(uiSourceCode, formattedUISourceCode, formatterMapping); 384 this._showIfNeeded(uiSourceCode, formattedUISourceCode, formatterMapping);
385 } 385 }
386 } 386 }
387 }; 387 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698