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

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: 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
« no previous file with comments | « no previous file | Source/devtools/front_end/main/Main.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 /** 37 this._workspace = workspace;
38 * @type {!Object.<string, !Array.<!WebInspector.ConsoleMessage>>} 38
39 */ 39 /** @type {!Object.<string, !Array.<!WebInspector.ConsoleMessage>>} */
40 this._pendingConsoleMessages = {}; 40 this._pendingConsoleMessages = {};
41
42 /** @type {!Array.<!WebInspector.PresentationConsoleMessage>} */
41 this._presentationConsoleMessages = []; 43 this._presentationConsoleMessages = [];
42 this._workspace = workspace; 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();
apavlov 2014/08/17 21:32:05 This thing is never cleared.
vsevik 2014/08/18 05:53:07 It should be!
43 50
44 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.ConsoleMo del.Events.ConsoleCleared, this._consoleCleared, this); 51 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.ConsoleMo del.Events.ConsoleCleared, this._consoleCleared, this);
45 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.ConsoleMo del.Events.MessageAdded, this._onConsoleMessageAdded, this); 52 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.ConsoleMo del.Events.MessageAdded, this._onConsoleMessageAdded, this);
46 WebInspector.multitargetConsoleModel.messages().forEach(this._consoleMessage Added, this); 53 WebInspector.multitargetConsoleModel.messages().forEach(this._consoleMessage Added, this);
47 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.ParsedScriptSource, this._parsedScriptSource, this ); 54 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); 55 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); 56 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.GlobalObjectCleared, this._debuggerReset, this);
50 } 57 }
51 58
59 /**
60 * @enum {string}
61 */
62 WebInspector.PresentationConsoleMessageHelper.Events = {
63 ConsoleMessageAdded: "ConsoleMessageAdded",
64 ConsoleMessageRemoved: "ConsoleMessageRemoved",
65 ConsoleMessagesCleared: "ConsoleMessagesCleared",
66 }
67
52 WebInspector.PresentationConsoleMessageHelper.prototype = { 68 WebInspector.PresentationConsoleMessageHelper.prototype = {
53 /** 69 /**
70 * @param {!WebInspector.PresentationConsoleMessageHelper.Events} eventType
71 * @param {!WebInspector.UISourceCode} uiSourceCode
72 * @param {function(!WebInspector.Event)} listener
73 * @param {!Object=} thisObject
74 */
75 addConsoleMessageEventListener: function(eventType, uiSourceCode, listener, thisObject)
76 {
77 var target = this._uiSourceCodeToEventTarget.get(uiSourceCode);
78 if (!target) {
79 target = new WebInspector.Object();
80 this._uiSourceCodeToEventTarget.put(uiSourceCode, target);
81 }
82 target.addEventListener(eventType, listener, thisObject);
83 },
84
85 /**
86 * @param {!WebInspector.PresentationConsoleMessageHelper.Events} eventType
87 * @param {!WebInspector.UISourceCode} uiSourceCode
88 * @param {function(!WebInspector.Event)} listener
89 * @param {!Object=} thisObject
90 */
91 removeConsoleMessageEventListener: function(eventType, uiSourceCode, listene r, thisObject)
92 {
93 var target = this._uiSourceCodeToEventTarget.get(uiSourceCode);
94 if (!target)
95 return;
96 target.removeEventListener(eventType, listener, thisObject);
97 },
98
99 /**
100 * @param {!WebInspector.UISourceCode} uiSourceCode
101 * @return {!Array.<!WebInspector.PresentationConsoleMessage>}
102 */
103 consoleMessages: function(uiSourceCode)
104 {
105 return this._uiSourceCodeToMessages.get(uiSourceCode) || [];
106 },
107
108 /**
109 * @param {!WebInspector.PresentationConsoleMessageHelper.Events} eventType
110 * @param {!WebInspector.UISourceCode} uiSourceCode
111 * @param {!WebInspector.PresentationConsoleMessage=} message
112 */
113 _dispatchConsoleEvent: function(eventType, uiSourceCode, message)
114 {
115 var target = this._uiSourceCodeToEventTarget.get(uiSourceCode);
116 if (!target)
117 return;
118 target.dispatchEventToListeners(eventType, message);
119 },
120
121 /**
54 * @param {!WebInspector.Event} event 122 * @param {!WebInspector.Event} event
55 */ 123 */
56 _onConsoleMessageAdded: function(event) 124 _onConsoleMessageAdded: function(event)
57 { 125 {
58 var message = /** @type {!WebInspector.ConsoleMessage} */ (event.data); 126 var message = /** @type {!WebInspector.ConsoleMessage} */ (event.data);
59 this._consoleMessageAdded(message) 127 this._consoleMessageAdded(message)
60 }, 128 },
61 129
62 /** 130 /**
63 * @param {!WebInspector.ConsoleMessage} message 131 * @param {!WebInspector.ConsoleMessage} message
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 else 195 else
128 pendingMessages.push(message); 196 pendingMessages.push(message);
129 } 197 }
130 198
131 if (pendingMessages.length) 199 if (pendingMessages.length)
132 this._pendingConsoleMessages[script.sourceURL] = pendingMessages; 200 this._pendingConsoleMessages[script.sourceURL] = pendingMessages;
133 else 201 else
134 delete this._pendingConsoleMessages[script.sourceURL]; 202 delete this._pendingConsoleMessages[script.sourceURL];
135 }, 203 },
136 204
205 /**
206 * @param {!WebInspector.PresentationConsoleMessage} message
207 */
208 _presentationConsoleMessageAdded: function(message)
209 {
210 var uiSourceCode = message._uiLocation.uiSourceCode;
211 var messages = this._uiSourceCodeToMessages.get(uiSourceCode);
212 if (!messages) {
213 messages = [];
214 this._uiSourceCodeToMessages.put(uiSourceCode, messages);
215 }
216 messages.push(message);
217 this._dispatchConsoleEvent(WebInspector.PresentationConsoleMessageHelper .Events.ConsoleMessageAdded, uiSourceCode, message);
218 },
219
220 /**
221 * @param {!WebInspector.PresentationConsoleMessage} message
222 */
223 _presentationConsoleMessageRemoved: function(message)
224 {
225 var uiSourceCode = message._uiLocation.uiSourceCode;
226 var messages = this._uiSourceCodeToMessages.get(uiSourceCode);
227 if (!messages)
228 return;
229 messages.remove(message);
230 this._dispatchConsoleEvent(WebInspector.PresentationConsoleMessageHelper .Events.ConsoleMessageRemoved, uiSourceCode, message);
231 },
232
137 _consoleCleared: function() 233 _consoleCleared: function()
138 { 234 {
139 this._pendingConsoleMessages = {}; 235 this._pendingConsoleMessages = {};
140 for (var i = 0; i < this._presentationConsoleMessages.length; ++i) 236 for (var i = 0; i < this._presentationConsoleMessages.length; ++i)
141 this._presentationConsoleMessages[i].dispose(); 237 this._presentationConsoleMessages[i].dispose();
142 this._presentationConsoleMessages = []; 238 this._presentationConsoleMessages = [];
143 var uiSourceCodes = this._workspace.uiSourceCodes(); 239 var targets = this._uiSourceCodeToEventTarget.values();
144 for (var i = 0; i < uiSourceCodes.length; ++i) 240 for (var i = 0; i < targets.length; ++i)
145 uiSourceCodes[i].consoleMessagesCleared(); 241 targets[i].dispatchEventToListeners(WebInspector.PresentationConsole MessageHelper.Events.ConsoleMessagesCleared);
242 this._uiSourceCodeToMessages.clear();
146 }, 243 },
147 244
148 _debuggerReset: function() 245 _debuggerReset: function()
149 { 246 {
150 this._pendingConsoleMessages = {}; 247 this._pendingConsoleMessages = {};
151 this._presentationConsoleMessages = []; 248 this._presentationConsoleMessages = [];
152 } 249 }
153 } 250 }
154 251
155 /** 252 /**
156 * @constructor 253 * @constructor
157 * @implements {WebInspector.PresentationMessage}
158 * @param {!WebInspector.ConsoleMessage} message 254 * @param {!WebInspector.ConsoleMessage} message
159 * @param {!WebInspector.DebuggerModel.Location} rawLocation 255 * @param {!WebInspector.DebuggerModel.Location} rawLocation
160 */ 256 */
161 WebInspector.PresentationConsoleMessage = function(message, rawLocation) 257 WebInspector.PresentationConsoleMessage = function(message, rawLocation)
162 { 258 {
163 this.originalMessage = message; 259 this.originalMessage = message;
164 this._liveLocation = WebInspector.debuggerWorkspaceBinding.createLiveLocatio n(rawLocation, this._updateLocation.bind(this)); 260 this._liveLocation = WebInspector.debuggerWorkspaceBinding.createLiveLocatio n(rawLocation, this._updateLocation.bind(this));
165 } 261 }
166 262
167 WebInspector.PresentationConsoleMessage.prototype = { 263 WebInspector.PresentationConsoleMessage.prototype = {
168 /** 264 /**
169 * @param {!WebInspector.UILocation} uiLocation 265 * @param {!WebInspector.UILocation} uiLocation
170 */ 266 */
171 _updateLocation: function(uiLocation) 267 _updateLocation: function(uiLocation)
172 { 268 {
173 if (this._uiLocation) 269 if (this._uiLocation)
174 this._uiLocation.uiSourceCode.consoleMessageRemoved(this); 270 WebInspector.presentationConsoleMessageHelper._presentationConsoleMe ssageRemoved(this);
175 this._uiLocation = uiLocation; 271 this._uiLocation = uiLocation;
176 this._uiLocation.uiSourceCode.consoleMessageAdded(this); 272 WebInspector.presentationConsoleMessageHelper._presentationConsoleMessag eAdded(this);
177 }, 273 },
178 274
179 get lineNumber() 275 get lineNumber()
180 { 276 {
181 return this._uiLocation.lineNumber; 277 return this._uiLocation.lineNumber;
182 }, 278 },
183 279
184 dispose: function() 280 dispose: function()
185 { 281 {
186 this._liveLocation.dispose(); 282 this._liveLocation.dispose();
187 } 283 }
188 } 284 }
285
286 /** @type {!WebInspector.PresentationConsoleMessageHelper} */
287 WebInspector.presentationConsoleMessageHelper;
OLDNEW
« no previous file with comments | « no previous file | Source/devtools/front_end/main/Main.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698