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

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

Issue 472353002: DevTools: Get rid of WebInspector.PresentationMessage interface (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Clear event targets map and handle ProjectRemoved Created 6 years, 4 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 | Annotate | Revision Log
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 16 matching lines...) Expand all
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 /** 31 /**
32 * @constructor 32 * @constructor
33 * @param {!WebInspector.Workspace} workspace 33 * @param {!WebInspector.Workspace} workspace
34 */ 34 */
35 WebInspector.PresentationConsoleMessageHelper = function(workspace) 35 WebInspector.PresentationConsoleMessageHelper = function(workspace)
36 { 36 {
37 /**
38 * @type {!Object.<string, !Array.<!WebInspector.ConsoleMessage>>}
39 */
40 this._pendingConsoleMessages = {};
41 this._presentationConsoleMessages = [];
42 this._workspace = workspace; 37 this._workspace = workspace;
43 38
39 /** @type {!Object.<string, !Array.<!WebInspector.ConsoleMessage>>} */
40 this._pendingConsoleMessages = {};
41
42 /** @type {!Array.<!WebInspector.PresentationConsoleMessage>} */
43 this._presentationConsoleMessages = [];
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);
44 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.ConsoleMo del.Events.ConsoleCleared, this._consoleCleared, this); 53 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.ConsoleMo del.Events.ConsoleCleared, this._consoleCleared, this);
45 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.ConsoleMo del.Events.MessageAdded, this._onConsoleMessageAdded, this); 54 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.ConsoleMo del.Events.MessageAdded, this._onConsoleMessageAdded, this);
46 WebInspector.multitargetConsoleModel.messages().forEach(this._consoleMessage Added, this); 55 WebInspector.multitargetConsoleModel.messages().forEach(this._consoleMessage Added, this);
47 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.ParsedScriptSource, this._parsedScriptSource, 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.FailedToParseScriptSource, this._parsedScriptSourc e, 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.GlobalObjectCleared, this._debuggerReset, this); 58 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.GlobalObjectCleared, this._debuggerReset, this);
50 } 59 }
51 60
61 /**
62 * @enum {string}
63 */
64 WebInspector.PresentationConsoleMessageHelper.Events = {
65 ConsoleMessageAdded: "ConsoleMessageAdded",
66 ConsoleMessageRemoved: "ConsoleMessageRemoved",
67 ConsoleMessagesCleared: "ConsoleMessagesCleared",
68 }
69
52 WebInspector.PresentationConsoleMessageHelper.prototype = { 70 WebInspector.PresentationConsoleMessageHelper.prototype = {
53 /** 71 /**
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.put(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 /**
54 * @param {!WebInspector.Event} event 147 * @param {!WebInspector.Event} event
55 */ 148 */
56 _onConsoleMessageAdded: function(event) 149 _onConsoleMessageAdded: function(event)
57 { 150 {
58 var message = /** @type {!WebInspector.ConsoleMessage} */ (event.data); 151 var message = /** @type {!WebInspector.ConsoleMessage} */ (event.data);
59 this._consoleMessageAdded(message) 152 this._consoleMessageAdded(message)
60 }, 153 },
61 154
62 /** 155 /**
63 * @param {!WebInspector.ConsoleMessage} message 156 * @param {!WebInspector.ConsoleMessage} message
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 else 220 else
128 pendingMessages.push(message); 221 pendingMessages.push(message);
129 } 222 }
130 223
131 if (pendingMessages.length) 224 if (pendingMessages.length)
132 this._pendingConsoleMessages[script.sourceURL] = pendingMessages; 225 this._pendingConsoleMessages[script.sourceURL] = pendingMessages;
133 else 226 else
134 delete this._pendingConsoleMessages[script.sourceURL]; 227 delete this._pendingConsoleMessages[script.sourceURL];
135 }, 228 },
136 229
230 /**
231 * @param {!WebInspector.PresentationConsoleMessage} message
232 */
233 _presentationConsoleMessageAdded: function(message)
234 {
235 var uiSourceCode = message._uiLocation.uiSourceCode;
236 var messages = this._uiSourceCodeToMessages.get(uiSourceCode);
237 if (!messages) {
238 messages = [];
239 this._uiSourceCodeToMessages.put(uiSourceCode, messages);
240 }
241 messages.push(message);
242 this._dispatchConsoleEvent(WebInspector.PresentationConsoleMessageHelper .Events.ConsoleMessageAdded, uiSourceCode, message);
243 },
244
245 /**
246 * @param {!WebInspector.PresentationConsoleMessage} message
247 */
248 _presentationConsoleMessageRemoved: function(message)
249 {
250 var uiSourceCode = message._uiLocation.uiSourceCode;
251 var messages = this._uiSourceCodeToMessages.get(uiSourceCode);
252 if (!messages)
253 return;
254 messages.remove(message);
255 this._dispatchConsoleEvent(WebInspector.PresentationConsoleMessageHelper .Events.ConsoleMessageRemoved, uiSourceCode, message);
256 },
257
137 _consoleCleared: function() 258 _consoleCleared: function()
138 { 259 {
139 this._pendingConsoleMessages = {}; 260 this._pendingConsoleMessages = {};
140 for (var i = 0; i < this._presentationConsoleMessages.length; ++i) 261 for (var i = 0; i < this._presentationConsoleMessages.length; ++i)
141 this._presentationConsoleMessages[i].dispose(); 262 this._presentationConsoleMessages[i].dispose();
142 this._presentationConsoleMessages = []; 263 this._presentationConsoleMessages = [];
143 var uiSourceCodes = this._workspace.uiSourceCodes(); 264 var targets = this._uiSourceCodeToEventTarget.values();
144 for (var i = 0; i < uiSourceCodes.length; ++i) 265 for (var i = 0; i < targets.length; ++i)
145 uiSourceCodes[i].consoleMessagesCleared(); 266 targets[i].dispatchEventToListeners(WebInspector.PresentationConsole MessageHelper.Events.ConsoleMessagesCleared);
267 this._uiSourceCodeToMessages.clear();
146 }, 268 },
147 269
148 _debuggerReset: function() 270 _debuggerReset: function()
149 { 271 {
150 this._pendingConsoleMessages = {}; 272 this._pendingConsoleMessages = {};
151 this._presentationConsoleMessages = []; 273 this._presentationConsoleMessages = [];
152 } 274 }
153 } 275 }
154 276
155 /** 277 /**
156 * @constructor 278 * @constructor
157 * @implements {WebInspector.PresentationMessage}
158 * @param {!WebInspector.ConsoleMessage} message 279 * @param {!WebInspector.ConsoleMessage} message
159 * @param {!WebInspector.DebuggerModel.Location} rawLocation 280 * @param {!WebInspector.DebuggerModel.Location} rawLocation
160 */ 281 */
161 WebInspector.PresentationConsoleMessage = function(message, rawLocation) 282 WebInspector.PresentationConsoleMessage = function(message, rawLocation)
162 { 283 {
163 this.originalMessage = message; 284 this.originalMessage = message;
164 this._liveLocation = WebInspector.debuggerWorkspaceBinding.createLiveLocatio n(rawLocation, this._updateLocation.bind(this)); 285 this._liveLocation = WebInspector.debuggerWorkspaceBinding.createLiveLocatio n(rawLocation, this._updateLocation.bind(this));
165 } 286 }
166 287
167 WebInspector.PresentationConsoleMessage.prototype = { 288 WebInspector.PresentationConsoleMessage.prototype = {
168 /** 289 /**
169 * @param {!WebInspector.UILocation} uiLocation 290 * @param {!WebInspector.UILocation} uiLocation
170 */ 291 */
171 _updateLocation: function(uiLocation) 292 _updateLocation: function(uiLocation)
172 { 293 {
173 if (this._uiLocation) 294 if (this._uiLocation)
174 this._uiLocation.uiSourceCode.consoleMessageRemoved(this); 295 WebInspector.presentationConsoleMessageHelper._presentationConsoleMe ssageRemoved(this);
175 this._uiLocation = uiLocation; 296 this._uiLocation = uiLocation;
176 this._uiLocation.uiSourceCode.consoleMessageAdded(this); 297 WebInspector.presentationConsoleMessageHelper._presentationConsoleMessag eAdded(this);
177 }, 298 },
178 299
179 get lineNumber() 300 get lineNumber()
180 { 301 {
181 return this._uiLocation.lineNumber; 302 return this._uiLocation.lineNumber;
182 }, 303 },
183 304
184 dispose: function() 305 dispose: function()
185 { 306 {
186 this._liveLocation.dispose(); 307 this._liveLocation.dispose();
187 } 308 }
188 } 309 }
310
311 /** @type {!WebInspector.PresentationConsoleMessageHelper} */
312 WebInspector.presentationConsoleMessageHelper;
OLDNEW
« no previous file with comments | « Source/devtools/front_end/bindings/DebuggerWorkspaceBinding.js ('k') | Source/devtools/front_end/main/Main.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698