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

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: review comments addressed 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 else 137 else
230 pendingMessages.push(message); 138 pendingMessages.push(message);
231 } 139 }
232 140
233 if (pendingMessages.length) 141 if (pendingMessages.length)
234 this._pendingConsoleMessages[script.sourceURL] = pendingMessages; 142 this._pendingConsoleMessages[script.sourceURL] = pendingMessages;
235 else 143 else
236 delete this._pendingConsoleMessages[script.sourceURL]; 144 delete this._pendingConsoleMessages[script.sourceURL];
237 }, 145 },
238 146
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() 147 _consoleCleared: function()
268 { 148 {
269 this._pendingConsoleMessages = {}; 149 this._pendingConsoleMessages = {};
270 for (var i = 0; i < this._presentationConsoleMessages.length; ++i) 150 for (var i = 0; i < this._presentationConsoleMessages.length; ++i)
271 this._presentationConsoleMessages[i].dispose(); 151 this._presentationConsoleMessages[i].dispose();
272 this._presentationConsoleMessages = []; 152 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 }, 153 },
278 154
279 _debuggerReset: function() 155 _debuggerReset: function()
280 { 156 {
281 this._consoleCleared(); 157 this._consoleCleared();
282 } 158 }
283 } 159 }
284 160
285 /** 161 /**
286 * @constructor 162 * @constructor
287 * @param {!WebInspector.ConsoleMessage} message 163 * @param {!WebInspector.ConsoleMessage} message
288 * @param {!WebInspector.DebuggerModel.Location} rawLocation 164 * @param {!WebInspector.DebuggerModel.Location} rawLocation
289 */ 165 */
290 WebInspector.PresentationConsoleMessage = function(message, rawLocation) 166 WebInspector.PresentationConsoleMessage = function(message, rawLocation)
291 { 167 {
292 this.originalMessage = message; 168 this._text = message.messageText;
169 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)); 170 this._liveLocation = WebInspector.debuggerWorkspaceBinding.createLiveLocatio n(rawLocation, this._updateLocation.bind(this));
294 } 171 }
295 172
296 WebInspector.PresentationConsoleMessage.prototype = { 173 WebInspector.PresentationConsoleMessage.prototype = {
297 /** 174 /**
298 * @param {!WebInspector.UILocation} uiLocation 175 * @param {!WebInspector.UILocation} uiLocation
299 */ 176 */
300 _updateLocation: function(uiLocation) 177 _updateLocation: function(uiLocation)
301 { 178 {
302 if (this._uiLocation) 179 if (this._uiMessage)
303 WebInspector.presentationConsoleMessageHelper._presentationConsoleMe ssageRemoved(this); 180 this._uiMessage.remove();
304 this._uiLocation = uiLocation; 181 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 }, 182 },
323 183
324 dispose: function() 184 dispose: function()
325 { 185 {
326 this._liveLocation.dispose(); 186 this._liveLocation.dispose();
187 if (this._uiMessage)
188 this._uiMessage.remove();
327 } 189 }
328 } 190 }
329 191
330 /** @type {!WebInspector.PresentationConsoleMessageHelper} */ 192 /** @type {!WebInspector.PresentationConsoleMessageHelper} */
331 WebInspector.presentationConsoleMessageHelper; 193 WebInspector.presentationConsoleMessageHelper;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698