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

Side by Side Diff: Source/devtools/front_end/ConsoleModel.js

Issue 206253005: DevTools: Get rid of WebInspector.ConsoleModel.UIDelegate (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 9 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 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 30 matching lines...) Expand all
41 this.errors = 0; 41 this.errors = 0;
42 this._interruptRepeatCount = false; 42 this._interruptRepeatCount = false;
43 this._target = target; 43 this._target = target;
44 this._consoleAgent = target.consoleAgent(); 44 this._consoleAgent = target.consoleAgent();
45 target.registerConsoleDispatcher(new WebInspector.ConsoleDispatcher(this)); 45 target.registerConsoleDispatcher(new WebInspector.ConsoleDispatcher(this));
46 } 46 }
47 47
48 WebInspector.ConsoleModel.Events = { 48 WebInspector.ConsoleModel.Events = {
49 ConsoleCleared: "console-cleared", 49 ConsoleCleared: "console-cleared",
50 MessageAdded: "console-message-added", 50 MessageAdded: "console-message-added",
51 RepeatCountUpdated: "repeat-count-updated" 51 RepeatCountUpdated: "repeat-count-updated",
52 EvaluationResultMessageAdded: "evaluation-result-message-added",
vsevik 2014/03/20 13:22:46 Let's name it CommandEvaluated and include origina
sergeyv 2014/03/20 13:34:03 Done.
52 } 53 }
53 54
54 WebInspector.ConsoleModel.prototype = { 55 WebInspector.ConsoleModel.prototype = {
55 enableAgent: function() 56 enableAgent: function()
56 { 57 {
57 if (WebInspector.settings.monitoringXHREnabled.get()) 58 if (WebInspector.settings.monitoringXHREnabled.get())
58 this._consoleAgent.setMonitoringXHREnabled(true); 59 this._consoleAgent.setMonitoringXHREnabled(true);
59 60
60 this._enablingConsole = true; 61 this._enablingConsole = true;
61 62
62 /** 63 /**
63 * @this {WebInspector.ConsoleModel} 64 * @this {WebInspector.ConsoleModel}
64 */ 65 */
65 function callback() 66 function callback()
66 { 67 {
67 delete this._enablingConsole; 68 delete this._enablingConsole;
68 } 69 }
69 this._consoleAgent.enable(callback.bind(this)); 70 this._consoleAgent.enable(callback.bind(this));
70 }, 71 },
71 72
72 /** 73 /**
73 * @return {boolean} 74 * @return {boolean}
74 */ 75 */
75 enablingConsole: function() 76 enablingConsole: function()
76 { 77 {
77 return !!this._enablingConsole; 78 return !!this._enablingConsole;
78 }, 79 },
79 80
80 /** 81 /**
81 * @param {!WebInspector.ConsoleModel.UIDelegate} delegate
82 */
83 setUIDelegate: function(delegate)
84 {
85 this._uiDelegate = delegate;
86 },
87
88 /**
89 * @param {!WebInspector.ConsoleMessage} msg 82 * @param {!WebInspector.ConsoleMessage} msg
90 * @param {boolean=} isFromBackend 83 * @param {boolean=} isFromBackend
91 */ 84 */
92 addMessage: function(msg, isFromBackend) 85 addMessage: function(msg, isFromBackend)
93 { 86 {
94 if (isFromBackend && WebInspector.SourceMap.hasSourceMapRequestHeader(ms g.request)) 87 if (isFromBackend && WebInspector.SourceMap.hasSourceMapRequestHeader(ms g.request))
95 return; 88 return;
96 89
97 msg.index = this.messages.length; 90 msg.index = this.messages.length;
98 this.messages.push(msg); 91 this.messages.push(msg);
99 this._incrementErrorWarningCount(msg); 92 this._incrementErrorWarningCount(msg);
100 93
101 if (isFromBackend) 94 if (isFromBackend)
102 this._previousMessage = msg; 95 this._previousMessage = msg;
103 96
104 this._interruptRepeatCount = !isFromBackend; 97 this._interruptRepeatCount = !isFromBackend;
105 98
106 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.MessageAd ded, msg); 99 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.MessageAd ded, msg);
107 }, 100 },
108 101
109 /** 102 /**
110 * @param {string} text 103 * @param {string} text
111 * @param {?string} newPromptText
112 * @param {boolean} useCommandLineAPI 104 * @param {boolean} useCommandLineAPI
113 */ 105 */
114 evaluateCommand: function(text, newPromptText, useCommandLineAPI) 106 evaluateCommand: function(text, useCommandLineAPI)
115 { 107 {
116 if (!this._uiDelegate) 108 this.show();
117 this.show();
118 109
119 var commandMessage = new WebInspector.ConsoleMessage(WebInspector.Consol eMessage.MessageSource.JS, null, text, WebInspector.ConsoleMessage.MessageType.C ommand); 110 var commandMessage = new WebInspector.ConsoleMessage(WebInspector.Consol eMessage.MessageSource.JS, null, text, WebInspector.ConsoleMessage.MessageType.C ommand);
120 this.addMessage(commandMessage); 111 this.addMessage(commandMessage);
121 112
122 if (newPromptText !== null)
123 this._uiDelegate.setPromptText(newPromptText);
124
125 /** 113 /**
126 * @param {?WebInspector.RemoteObject} result 114 * @param {?WebInspector.RemoteObject} result
127 * @param {boolean} wasThrown 115 * @param {boolean} wasThrown
128 * @param {?RuntimeAgent.RemoteObject=} valueResult 116 * @param {?RuntimeAgent.RemoteObject=} valueResult
129 * @this {WebInspector.ConsoleModel} 117 * @this {WebInspector.ConsoleModel}
130 */ 118 */
131 function printResult(result, wasThrown, valueResult) 119 function printResult(result, wasThrown, valueResult)
132 { 120 {
133 if (!result) 121 if (!result)
134 return; 122 return;
135 123
136 this._uiDelegate.printEvaluationResult(result, wasThrown, text, comm andMessage); 124 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.Evalu ationResultMessageAdded, {result: result, wasThrown: wasThrown, text: text, comm andMessage: commandMessage});
137 } 125 }
138 this._target.runtimeModel.evaluate(text, "console", useCommandLineAPI, f alse, false, true, printResult.bind(this)); 126 this._target.runtimeModel.evaluate(text, "console", useCommandLineAPI, f alse, false, true, printResult.bind(this));
139 127
140 WebInspector.userMetrics.ConsoleEvaluated.record(); 128 WebInspector.userMetrics.ConsoleEvaluated.record();
141 }, 129 },
142 130
143 show: function() 131 show: function()
144 { 132 {
145 WebInspector.Revealer.reveal(this); 133 WebInspector.Revealer.reveal(this);
146 }, 134 },
147 135
148 /** 136 /**
149 * @param {string} expression 137 * @param {string} expression
150 */ 138 */
151 evaluate: function(expression) 139 evaluate: function(expression)
152 { 140 {
153 this.evaluateCommand(expression, null, false); 141 this.evaluateCommand(expression, false);
154 }, 142 },
155 143
156 /** 144 /**
157 * @param {string} messageText 145 * @param {string} messageText
158 * @param {!WebInspector.ConsoleMessage.MessageLevel=} messageLevel 146 * @param {!WebInspector.ConsoleMessage.MessageLevel=} messageLevel
159 * @param {boolean=} showConsole 147 * @param {boolean=} showConsole
160 */ 148 */
161 log: function(messageText, messageLevel, showConsole) 149 log: function(messageText, messageLevel, showConsole)
162 { 150 {
163 var message = new WebInspector.ConsoleMessage( 151 var message = new WebInspector.ConsoleMessage(
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 msgCopy.repeatCount = (count - prevRepeatCount) || 1; 222 msgCopy.repeatCount = (count - prevRepeatCount) || 1;
235 msgCopy.repeatDelta = msgCopy.repeatCount; 223 msgCopy.repeatDelta = msgCopy.repeatCount;
236 this.addMessage(msgCopy, true); 224 this.addMessage(msgCopy, true);
237 } 225 }
238 }, 226 },
239 227
240 __proto__: WebInspector.Object.prototype 228 __proto__: WebInspector.Object.prototype
241 } 229 }
242 230
243 /** 231 /**
244 * @interface
245 */
246 WebInspector.ConsoleModel.UIDelegate = function() { }
247
248 WebInspector.ConsoleModel.UIDelegate.prototype = {
249 /**
250 * @param {string} text
251 */
252 setPromptText: function(text) { },
253
254 /**
255 * @param {?WebInspector.RemoteObject} result
256 * @param {boolean} wasThrown
257 * @param {string} promptText
258 * @param {!WebInspector.ConsoleMessage} commandMessage
259 */
260 printEvaluationResult: function(result, wasThrown, promptText, commandMessag e) { }
261 }
262
263 /**
264 * @constructor 232 * @constructor
265 * @param {string} source 233 * @param {string} source
266 * @param {?string} level 234 * @param {?string} level
267 * @param {string} messageText 235 * @param {string} messageText
268 * @param {string=} type 236 * @param {string=} type
269 * @param {?string=} url 237 * @param {?string=} url
270 * @param {number=} line 238 * @param {number=} line
271 * @param {number=} column 239 * @param {number=} column
272 * @param {number=} repeatCount 240 * @param {number=} repeatCount
273 * @param {!NetworkAgent.RequestId=} requestId 241 * @param {!NetworkAgent.RequestId=} requestId
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 { 420 {
453 if (!WebInspector.settings.preserveConsoleLog.get()) 421 if (!WebInspector.settings.preserveConsoleLog.get())
454 this._console.clearMessages(); 422 this._console.clearMessages();
455 } 423 }
456 } 424 }
457 425
458 /** 426 /**
459 * @type {!WebInspector.ConsoleModel} 427 * @type {!WebInspector.ConsoleModel}
460 */ 428 */
461 WebInspector.console; 429 WebInspector.console;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698