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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/bindings/PresentationConsoleMessageHelper.js

Issue 1403373013: DevTools: move ui messages from SourceFrame to UISourceCodeFrame (step2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 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 24 matching lines...) Expand all
35 WebInspector.PresentationConsoleMessageHelper = function(workspace) 35 WebInspector.PresentationConsoleMessageHelper = function(workspace)
36 { 36 {
37 this._workspace = workspace; 37 this._workspace = workspace;
38 38
39 /** @type {!Object.<string, !Array.<!WebInspector.ConsoleMessage>>} */ 39 /** @type {!Object.<string, !Array.<!WebInspector.ConsoleMessage>>} */
40 this._pendingConsoleMessages = {}; 40 this._pendingConsoleMessages = {};
41 41
42 /** @type {!Array.<!WebInspector.PresentationConsoleMessage>} */ 42 /** @type {!Array.<!WebInspector.PresentationConsoleMessage>} */
43 this._presentationConsoleMessages = []; 43 this._presentationConsoleMessages = [];
44 44
45 /** @type {!Map.<!WebInspector.UISourceCode, !Array.<!WebInspector.Presentat ionConsoleMessage>>} */
46 this._uiSourceCodeToMessages = new Map();
47
48 /** @type {!Map.<!WebInspector.UISourceCode, !WebInspector.Object>} */
49 this._uiSourceCodeToEventTarget = new Map();
50
51 workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeRemoved , this._uiSourceCodeRemoved, this);
52 workspace.addEventListener(WebInspector.Workspace.Events.ProjectRemoved, thi s._projectRemoved, this);
53 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.ConsoleMo del.Events.ConsoleCleared, this._consoleCleared, this); 45 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.ConsoleMo del.Events.ConsoleCleared, this._consoleCleared, this);
54 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.ConsoleMo del.Events.MessageAdded, this._onConsoleMessageAdded, this); 46 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.ConsoleMo del.Events.MessageAdded, this._onConsoleMessageAdded, this);
55 WebInspector.multitargetConsoleModel.messages().forEach(this._consoleMessage Added, this); 47 WebInspector.multitargetConsoleModel.messages().forEach(this._consoleMessage Added, this);
56 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.ParsedScriptSource, this._parsedScriptSource, this ); 48 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.ParsedScriptSource, this._parsedScriptSource, this );
57 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.FailedToParseScriptSource, this._parsedScriptSourc e, this); 49 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.FailedToParseScriptSource, this._parsedScriptSourc e, this);
58 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.GlobalObjectCleared, this._debuggerReset, this); 50 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.GlobalObjectCleared, this._debuggerReset, this);
59 } 51 }
60 52
61 /**
62 * @enum {string}
63 */
64 WebInspector.PresentationConsoleMessageHelper.Events = {
65 ConsoleMessageAdded: "ConsoleMessageAdded",
66 ConsoleMessageRemoved: "ConsoleMessageRemoved",
67 ConsoleMessagesCleared: "ConsoleMessagesCleared",
68 }
69
70 WebInspector.PresentationConsoleMessageHelper.prototype = { 53 WebInspector.PresentationConsoleMessageHelper.prototype = {
71 /** 54 /**
72 * @param {!WebInspector.PresentationConsoleMessageHelper.Events} eventType
73 * @param {!WebInspector.UISourceCode} uiSourceCode
74 * @param {function(!WebInspector.Event)} listener
75 * @param {!Object=} thisObject
76 */
77 addConsoleMessageEventListener: function(eventType, uiSourceCode, listener, thisObject)
78 {
79 var target = this._uiSourceCodeToEventTarget.get(uiSourceCode);
80 if (!target) {
81 target = new WebInspector.Object();
82 this._uiSourceCodeToEventTarget.set(uiSourceCode, target);
83 }
84 target.addEventListener(eventType, listener, thisObject);
85 },
86
87 /**
88 * @param {!WebInspector.PresentationConsoleMessageHelper.Events} eventType
89 * @param {!WebInspector.UISourceCode} uiSourceCode
90 * @param {function(!WebInspector.Event)} listener
91 * @param {!Object=} thisObject
92 */
93 removeConsoleMessageEventListener: function(eventType, uiSourceCode, listene r, thisObject)
94 {
95 var target = this._uiSourceCodeToEventTarget.get(uiSourceCode);
96 if (!target)
97 return;
98 target.removeEventListener(eventType, listener, thisObject);
99 },
100
101 /**
102 * @param {!WebInspector.UISourceCode} uiSourceCode
103 * @return {!Array.<!WebInspector.PresentationConsoleMessage>}
104 */
105 consoleMessages: function(uiSourceCode)
106 {
107 return this._uiSourceCodeToMessages.get(uiSourceCode) || [];
108 },
109
110 /**
111 * @param {!WebInspector.PresentationConsoleMessageHelper.Events} eventType
112 * @param {!WebInspector.UISourceCode} uiSourceCode
113 * @param {!WebInspector.PresentationConsoleMessage=} message
114 */
115 _dispatchConsoleEvent: function(eventType, uiSourceCode, message)
116 {
117 var target = this._uiSourceCodeToEventTarget.get(uiSourceCode);
118 if (!target)
119 return;
120 target.dispatchEventToListeners(eventType, message);
121 },
122
123 /**
124 * @param {!WebInspector.Event} event
125 */
126 _uiSourceCodeRemoved: function(event)
127 {
128 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data );
129 this._uiSourceCodeToEventTarget.remove(uiSourceCode);
130 this._uiSourceCodeToMessages.remove(uiSourceCode);
131 },
132
133 /**
134 * @param {!WebInspector.Event} event
135 */
136 _projectRemoved: function(event)
137 {
138 var project = /** @type {!WebInspector.Project} */ (event.data);
139 var uiSourceCodes = project.uiSourceCodes();
140 for (var i = 0; i < uiSourceCodes.length; ++i) {
141 this._uiSourceCodeToEventTarget.remove(uiSourceCodes[i]);
142 this._uiSourceCodeToMessages.remove(uiSourceCodes[i]);
143 }
144 },
145
146 /**
147 * @param {!WebInspector.Event} event 55 * @param {!WebInspector.Event} event
148 */ 56 */
149 _onConsoleMessageAdded: function(event) 57 _onConsoleMessageAdded: function(event)
150 { 58 {
151 var message = /** @type {!WebInspector.ConsoleMessage} */ (event.data); 59 var message = /** @type {!WebInspector.ConsoleMessage} */ (event.data);
152 this._consoleMessageAdded(message); 60 this._consoleMessageAdded(message);
153 }, 61 },
154 62
155 /** 63 /**
156 * @param {!WebInspector.ConsoleMessage} message 64 * @param {!WebInspector.ConsoleMessage} message
(...skipping 29 matching lines...) Expand all
186 return debuggerModel.createRawLocationByURL(message.url || "", lineNumbe r, columnNumber); 94 return debuggerModel.createRawLocationByURL(message.url || "", lineNumbe r, columnNumber);
187 }, 95 },
188 96
189 /** 97 /**
190 * @param {!WebInspector.ConsoleMessage} message 98 * @param {!WebInspector.ConsoleMessage} message
191 * @param {!WebInspector.DebuggerModel.Location} rawLocation 99 * @param {!WebInspector.DebuggerModel.Location} rawLocation
192 */ 100 */
193 _addConsoleMessageToScript: function(message, rawLocation) 101 _addConsoleMessageToScript: function(message, rawLocation)
194 { 102 {
195 this._presentationConsoleMessages.push(new WebInspector.PresentationCons oleMessage(message, rawLocation)); 103 this._presentationConsoleMessages.push(new WebInspector.PresentationCons oleMessage(message, rawLocation));
104 debugger;
dgozman 2015/10/27 21:43:49 straw debugger
pfeldman 2015/10/27 22:35:17 Done.
196 }, 105 },
197 106
198 /** 107 /**
199 * @param {!WebInspector.ConsoleMessage} message 108 * @param {!WebInspector.ConsoleMessage} message
200 */ 109 */
201 _addPendingConsoleMessage: function(message) 110 _addPendingConsoleMessage: function(message)
202 { 111 {
203 if (!message.url) 112 if (!message.url)
204 return; 113 return;
205 if (!this._pendingConsoleMessages[message.url]) 114 if (!this._pendingConsoleMessages[message.url])
(...skipping 23 matching lines...) Expand all
229 else 138 else
230 pendingMessages.push(message); 139 pendingMessages.push(message);
231 } 140 }
232 141
233 if (pendingMessages.length) 142 if (pendingMessages.length)
234 this._pendingConsoleMessages[script.sourceURL] = pendingMessages; 143 this._pendingConsoleMessages[script.sourceURL] = pendingMessages;
235 else 144 else
236 delete this._pendingConsoleMessages[script.sourceURL]; 145 delete this._pendingConsoleMessages[script.sourceURL];
237 }, 146 },
238 147
239 /**
240 * @param {!WebInspector.PresentationConsoleMessage} message
241 */
242 _presentationConsoleMessageAdded: function(message)
243 {
244 var uiSourceCode = message._uiLocation.uiSourceCode;
245 var messages = this._uiSourceCodeToMessages.get(uiSourceCode);
246 if (!messages) {
247 messages = [];
248 this._uiSourceCodeToMessages.set(uiSourceCode, messages);
249 }
250 messages.push(message);
251 this._dispatchConsoleEvent(WebInspector.PresentationConsoleMessageHelper .Events.ConsoleMessageAdded, uiSourceCode, message);
252 },
253
254 /**
255 * @param {!WebInspector.PresentationConsoleMessage} message
256 */
257 _presentationConsoleMessageRemoved: function(message)
258 {
259 var uiSourceCode = message._uiLocation.uiSourceCode;
260 var messages = this._uiSourceCodeToMessages.get(uiSourceCode);
261 if (!messages)
262 return;
263 messages.remove(message);
264 this._dispatchConsoleEvent(WebInspector.PresentationConsoleMessageHelper .Events.ConsoleMessageRemoved, uiSourceCode, message);
265 },
266
267 _consoleCleared: function() 148 _consoleCleared: function()
268 { 149 {
269 this._pendingConsoleMessages = {}; 150 this._pendingConsoleMessages = {};
270 for (var i = 0; i < this._presentationConsoleMessages.length; ++i) 151 for (var i = 0; i < this._presentationConsoleMessages.length; ++i)
271 this._presentationConsoleMessages[i].dispose(); 152 this._presentationConsoleMessages[i].dispose();
272 this._presentationConsoleMessages = []; 153 this._presentationConsoleMessages = [];
273 var targets = this._uiSourceCodeToEventTarget.valuesArray();
274 for (var i = 0; i < targets.length; ++i)
275 targets[i].dispatchEventToListeners(WebInspector.PresentationConsole MessageHelper.Events.ConsoleMessagesCleared);
276 this._uiSourceCodeToMessages.clear();
277 }, 154 },
278 155
279 _debuggerReset: function() 156 _debuggerReset: function()
280 { 157 {
281 this._consoleCleared(); 158 this._consoleCleared();
282 } 159 }
283 } 160 }
284 161
285 /** 162 /**
286 * @constructor 163 * @constructor
287 * @param {!WebInspector.ConsoleMessage} message 164 * @param {!WebInspector.ConsoleMessage} message
288 * @param {!WebInspector.DebuggerModel.Location} rawLocation 165 * @param {!WebInspector.DebuggerModel.Location} rawLocation
289 */ 166 */
290 WebInspector.PresentationConsoleMessage = function(message, rawLocation) 167 WebInspector.PresentationConsoleMessage = function(message, rawLocation)
291 { 168 {
292 this.originalMessage = message; 169 this._text = message.messageText;
170 this._level = message.level === WebInspector.ConsoleMessage.MessageLevel.Err or ? WebInspector.UISourceCode.Message.Level.Error : WebInspector.UISourceCode.M essage.Level.Warning;
293 this._liveLocation = WebInspector.debuggerWorkspaceBinding.createLiveLocatio n(rawLocation, this._updateLocation.bind(this)); 171 this._liveLocation = WebInspector.debuggerWorkspaceBinding.createLiveLocatio n(rawLocation, this._updateLocation.bind(this));
294 } 172 }
295 173
296 WebInspector.PresentationConsoleMessage.prototype = { 174 WebInspector.PresentationConsoleMessage.prototype = {
297 /** 175 /**
298 * @param {!WebInspector.UILocation} uiLocation 176 * @param {!WebInspector.UILocation} uiLocation
299 */ 177 */
300 _updateLocation: function(uiLocation) 178 _updateLocation: function(uiLocation)
301 { 179 {
302 if (this._uiLocation) 180 if (this._uiMessage)
303 WebInspector.presentationConsoleMessageHelper._presentationConsoleMe ssageRemoved(this); 181 this._uiMessage.remove();
304 this._uiLocation = uiLocation; 182 this._uiMessage = uiLocation.uiSourceCode.addMessage(this._level, this._ text, uiLocation.lineNumber, uiLocation.columnNumber);
305 WebInspector.presentationConsoleMessageHelper._presentationConsoleMessag eAdded(this);
306 },
307
308 /**
309 * @return {number}
310 */
311 lineNumber: function()
312 {
313 return this._uiLocation.lineNumber;
314 },
315
316 /**
317 * @return {number}
318 */
319 columnNumber: function()
320 {
321 return this._uiLocation.columnNumber;
322 }, 183 },
323 184
324 dispose: function() 185 dispose: function()
325 { 186 {
326 this._liveLocation.dispose(); 187 this._liveLocation.dispose();
188 if (this._uiMessage)
189 this._uiMessage.remove();
327 } 190 }
328 } 191 }
329 192
330 /** @type {!WebInspector.PresentationConsoleMessageHelper} */ 193 /** @type {!WebInspector.PresentationConsoleMessageHelper} */
331 WebInspector.presentationConsoleMessageHelper; 194 WebInspector.presentationConsoleMessageHelper;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698