!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1 <?xml version="1.0"?>
2
3 <!DOCTYPE bindings SYSTEM "chrome://global/locale/console.dtd">
4
5 <bindings id="consoleBindings"
6 xmlns="http://www.mozilla.org/xbl"
7 xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
8 xmlns:xbl="http://www.mozilla.org/xbl">
9
10 <binding id="console-box" extends="xul:box">
11 <content>
12 <xul:stringbundle src="chrome://global/locale/console.properties" role="string-bundle"/>
13 <xul:vbox class="console-box-internal">
14 <xul:vbox class="console-rows" role="console-rows" xbl:inherits="dir=sortOrder"/>
15 </xul:vbox>
16 </content>
17
18 <implementation>
field_limit
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
19 <field name="limit" readonly="true">
20 250
21 </field>
field__showChromeErrors
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
22 <field name="_showChromeErrors">-1</field>
23
24 <property name="showChromeErrors">
get_showChromeErrors
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
25 <getter><![CDATA[
26 if (this._showChromeErrors != -1)
27 return this._showChromeErrors;
28 var pref = Components.classes['@mozilla.org/preferences-service;1'].getService();
29 pref = pref.QueryInterface(Components.interfaces.nsIPrefBranch);
30
31 try {
32 return this._showChromeErrors = pref.getBoolPref("javascript.options.showInConsole");
33 }
34 catch(ex) {
35 return this._showChromeErrors = false;
36 }
37 ]]></getter>
38 </property>
39
40 <property name="count" readonly="true">
get_count
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
41 <getter>return this.mCount</getter>
42 </property>
43
44 <property name="mode">
get_mode
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
45 <getter>return this.mMode;</getter>
set_mode
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
46 <setter><![CDATA[
47 if (this.mode != val) {
48 this.mMode = val || "All";
49 this.setAttribute("mode", this.mMode);
50 this.selectedItem = null;
51 }
52 return val;
53 ]]></setter>
54 </property>
55
56 <property name="sortOrder">
get_sortOrder
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
57 <getter>return this.getAttribute("sortOrder");</getter>
set_sortOrder
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
58 <setter>this.setAttribute("sortOrder", val); return val;</setter>
59 </property>
field_mSelectedItem
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
60 <field name="mSelectedItem">null</field>
61 <property name="selectedItem">
get_selectedItem
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
62 <getter>return this.mSelectedItem</getter>
set_selectedItem
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
63 <setter><![CDATA[
64 if (this.mSelectedItem)
65 this.mSelectedItem.removeAttribute("selected");
66
67 this.mSelectedItem = val;
68 if (val)
69 val.setAttribute("selected", "true");
70
71 // Update edit commands
72 window.updateCommands("focus");
73 return val;
74 ]]></setter>
75 </property>
76
77 <method name="init">
init
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
78 <body><![CDATA[
79 this.mCount = 0;
80
81 this.mConsoleListener = {
82 console: this,
observe
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
83 observe : function(aObject) { this.console.appendItem(aObject); }
84 };
85
86 this.mConsoleRowBox = document.getAnonymousElementByAttribute(this, "role", "console-rows");
87 this.mStrBundle = document.getAnonymousElementByAttribute(this, "role", "string-bundle");
88
89 try {
90 var isupports = Components.classes['@mozilla.org/consoleservice;1'].getService();
91 this.mCService = isupports.QueryInterface(Components.interfaces.nsIConsoleService);
92 this.mCService.registerListener(this.mConsoleListener);
93 } catch (ex) {
94 appendItem(
95 "Unable to display errors - couldn't get Console Service component. " +
96 "(Missing @mozilla.org/consoleservice;1)");
97 return;
98 }
99
100 this.mMode = this.getAttribute("mode") || "All";
101
102 this.appendInitialItems();
103 window.controllers.insertControllerAt(0, this._controller);
104 ]]></body>
105 </method>
106
107 <method name="destroy">
destroy
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
108 <body><![CDATA[
109 this.mCService.unregisterListener(this.mConsoleListener);
110 window.controllers.removeController(this._controller);
111 ]]></body>
112 </method>
113
114 <method name="appendInitialItems">
appendInitialItems
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
115 <body><![CDATA[
116 var out = {}; // Throwaway references to support 'out' parameters.
117 this.mCService.getMessageArray(out, {});
118 var messages = out.value;
119
120 // In case getMessageArray returns 0-length array as null
121 if (!messages)
122 messages = [];
123
124 var limit = messages.length - this.limit;
125 if (limit < 0) limit = 0;
126
127 // Checks if console ever been cleared
128 for (var i = messages.length - 1; i >= limit; --i)
129 if (!messages[i].message)
130 break;
131
132 // Populate with messages after latest "clear"
133 while (++i < messages.length)
134 this.appendItem(messages[i]);
135 ]]></body>
136 </method>
137
138 <method name="appendItem">
139 <parameter name="aObject"/>
appendItem
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
140 <body><![CDATA[
141 try {
142 // Try to QI it to a script error to get more info
143 var scriptError = aObject.QueryInterface(Components.interfaces.nsIScriptError);
144
145 // filter chrome urls
146 if (!this.showChromeErrors && scriptError.sourceName.substr(0, 9) == "chrome://")
147 return;
148
149 this.appendError(scriptError);
150 } catch (ex) {
151 try {
152 // Try to QI it to a console message
153 var msg = aObject.QueryInterface(Components.interfaces.nsIConsoleMessage);
154 if (msg.message)
155 this.appendMessage(msg.message);
156 else // observed a null/"clear" message
157 this.clearConsole();
158 } catch (ex2) {
159 // Give up and append the object itself as a string
160 this.appendMessage(aObject);
161 }
162 }
163 ]]></body>
164 </method>
165
166 <method name="appendError">
167 <parameter name="aObject"/>
appendError
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
168 <body><![CDATA[
169 var row = this.createConsoleRow();
170 var nsIScriptError = Components.interfaces.nsIScriptError;
171
172 // Is this error actually just a non-fatal warning?
173 var warning = aObject.flags & nsIScriptError.warningFlag != 0;
174
175 var typetext = warning ? "typeWarning" : "typeError";
176 row.setAttribute("typetext", this.mStrBundle.getString(typetext));
177 row.setAttribute("type", warning ? "warning" : "error");
178 row.setAttribute("msg", aObject.errorMessage);
179 row.setAttribute("category", aObject.category);
180 if (aObject.lineNumber || aObject.sourceName) {
181 row.setAttribute("href", aObject.sourceName);
182 row.setAttribute("line", aObject.lineNumber);
183 } else {
184 row.setAttribute("hideSource", "true");
185 }
186 if (aObject.sourceLine) {
187 row.setAttribute("code", aObject.sourceLine.replace(/\s/g, " "));
188 if (aObject.columnNumber) {
189 row.setAttribute("col", aObject.columnNumber);
190 row.setAttribute("errorDots", this.repeatChar(" ", aObject.columnNumber));
191 row.setAttribute("errorCaret", " ");
192 } else {
193 row.setAttribute("hideCaret", "true");
194 }
195 } else {
196 row.setAttribute("hideCode", "true");
197 }
198 this.appendConsoleRow(row);
199 ]]></body>
200 </method>
201
202 <method name="appendMessage">
203 <parameter name="aMessage"/>
204 <parameter name="aType"/>
appendMessage
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
205 <body><![CDATA[
206 var row = this.createConsoleRow();
207 row.setAttribute("type", aType || "message");
208 row.setAttribute("msg", aMessage);
209 this.appendConsoleRow(row);
210 ]]></body>
211 </method>
212
213 <method name="clear">
clear
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
214 <body><![CDATA[
215 // add a "clear" message (mainly for other listeners)
216 this.mCService.logStringMessage(null);
217 this.mCService.reset();
218 ]]></body>
219 </method>
220
221 <method name="copySelectedItem">
copySelectedItem
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
222 <body><![CDATA[
223 if (this.mSelectedItem) try {
224 const clipURI = "@mozilla.org/widget/clipboardhelper;1";
225 const clipI = Components.interfaces.nsIClipboardHelper;
226 var clipboard = Components.classes[clipURI].getService(clipI);
227
228 clipboard.copyString(this.mSelectedItem.toString());
229 } catch (ex) {
230 // Unable to copy anything, die quietly
231 }
232 ]]></body>
233 </method>
234
235 <method name="createConsoleRow">
createConsoleRow
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
236 <body><![CDATA[
237 var row = document.createElement("box");
238 row.setAttribute("class", "console-row");
239 row._IsConsoleRow = true;
240 row._ConsoleBox = this;
241 return row;
242 ]]></body>
243 </method>
244
245 <method name="appendConsoleRow">
246 <parameter name="aRow"/>
appendConsoleRow
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
247 <body><![CDATA[
248 this.mConsoleRowBox.appendChild(aRow);
249 if (++this.mCount > this.limit) this.deleteFirst();
250 ]]></body>
251 </method>
252
253 <method name="deleteFirst">
deleteFirst
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
254 <body><![CDATA[
255 var node = this.mConsoleRowBox.firstChild;
256 this.mConsoleRowBox.removeChild(node);
257 --this.mCount;
258 ]]></body>
259 </method>
260
261 <method name="clearConsole">
clearConsole
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
262 <body><![CDATA[
263 if (this.mCount == 0) // already clear
264 return;
265 this.mCount = 0;
266
267 var newRows = this.mConsoleRowBox.cloneNode(false);
268 this.mConsoleRowBox.parentNode.replaceChild(newRows, this.mConsoleRowBox);
269 this.mConsoleRowBox = newRows;
270 this.selectedItem = null;
271 ]]></body>
272 </method>
273
274 <!-- UTILITY FUNCTIONS -->
275
276 <method name="repeatChar">
277 <parameter name="aChar"/>
278 <parameter name="aCol"/>
repeatChar
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
279 <body><![CDATA[
280 if (--aCol <= 0)
281 return "";
282
283 for (var i = 2; i < aCol; i += i)
284 aChar += aChar;
285
286 return aChar + aChar.slice(0, aCol - aChar.length);
287 ]]></body>
288 </method>
289
constructor
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
290 <constructor> this.init(); </constructor>
destructor
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
291 <destructor> this.destroy(); </destructor>
292
293 <!-- Command controller for the copy command -->
field__controller
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
294 <field name="_controller"><![CDATA[({
295 _outer: this,
296
QueryInterface
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
297 QueryInterface: function(aIID) {
298 if (aIID.equals(Components.interfaces.nsIController) ||
299 aIID.equals(Components.interfaces.nsISupports))
300 return this;
301 throw Components.results.NS_NOINTERFACE;
302 },
303
supportsCommand
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
304 supportsCommand: function(aCommand) {
305 return aCommand == "cmd_copy";
306 },
307
isCommandEnabled
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
308 isCommandEnabled: function(aCommand) {
309 return aCommand == "cmd_copy" && this._outer.selectedItem;
310 },
311
doCommand
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
312 doCommand: function(aCommand) {
313 if (aCommand == "cmd_copy")
314 this._outer.copySelectedItem();
315 },
316
onEvent
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
317 onEvent: function() { }
318 });]]></field>
319 </implementation>
320
321 <handlers>
onmousedown
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
322 <handler event="mousedown"><![CDATA[
323 if (event.button == 0 || event.button == 2) {
324 var target = event.originalTarget;
325
326 while (target && !("_IsConsoleRow" in target))
327 target = target.parentNode;
328
329 if (target)
330 this.selectedItem = target;
331 }
332 ]]></handler>
333 </handlers>
334 </binding>
335
336 <binding id="error" extends="xul:box">
337 <content>
338 <xul:box class="console-row-internal-box" flex="1">
339 <xul:box class="console-row-icon" align="center" xbl:inherits="selected">
340 <xul:image class="console-icon" xbl:inherits="src,type"/>
341 </xul:box>
342 <xul:vbox class="console-row-content" xbl:inherits="selected" flex="1">
343 <xul:box class="console-row-msg" align="start">
344 <xul:label class="label" xbl:inherits="value=typetext"/>
345 <xul:description class="console-error-msg" xbl:inherits="xbl:text=msg" flex="1"/>
346 </xul:box>
347 <xul:box class="console-row-file" xbl:inherits="hidden=hideSource">
348 <xul:label class="label" value="&errFile.label;"/>
349 <xul:box class="console-error-source" xbl:inherits="href,line"/>
350 <xul:spacer flex="1"/>
351 <xul:hbox class="lineNumberRow" xbl:inherits="line">
352 <xul:label class="label" value="&errLine.label;"/>
353 <xul:label class="label" xbl:inherits="value=line"/>
354 </xul:hbox>
355 </xul:box>
356 <xul:vbox class="console-row-code" xbl:inherits="selected,hidden=hideCode">
357 <xul:label class="monospace console-code" xbl:inherits="value=code" crop="end"/>
358 <xul:box xbl:inherits="hidden=hideCaret">
359 <xul:label class="monospace console-dots" xbl:inherits="value=errorDots"/>
360 <xul:label class="monospace console-caret" xbl:inherits="value=errorCaret"/>
361 <xul:spacer flex="1"/>
362 </xul:box>
363 </xul:vbox>
364 </xul:vbox>
365 </xul:box>
366 </content>
367
368 <implementation>
369
370 <method name="toString">
toString
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
371 <body><![CDATA[
372 var msg = this.getAttribute("typetext") + " " + this.getAttribute("msg");
373
374 var strBundle = this._ConsoleBox.mStrBundle;
375
376 if (this.hasAttribute("line") && this.hasAttribute("href")) {
377 msg += "\n" + strBundle.getFormattedString("errFile",
378 [this.getAttribute("href")]) + "\n";
379 if (this.hasAttribute("col")) {
380 msg += strBundle.getFormattedString("errLineCol",
381 [this.getAttribute("line"), this.getAttribute("col")]);
382 } else
383 msg += strBundle.getFormattedString("errLine", [this.getAttribute("line")]);
384 }
385
386 if (this.hasAttribute("code"))
387 msg += "\n" + strBundle.getString("errCode") + "\n" + this.getAttribute("code");
388
389 return msg;
390 ]]></body>
391 </method>
392 </implementation>
393
394 </binding>
395
396 <binding id="message" extends="xul:box">
397 <content>
398 <xul:box class="console-internal-box" flex="1">
399 <xul:box class="console-row-icon" align="center">
400 <xul:image class="console-icon" xbl:inherits="src,type"/>
401 </xul:box>
402 <xul:vbox class="console-row-content" xbl:inherits="selected" flex="1">
403 <xul:vbox class="console-row-msg" flex="1">
404 <xul:description class="console-msg-text" xbl:inherits="xbl:text=msg"/>
405 </xul:vbox>
406 </xul:vbox>
407 </xul:box>
408 </content>
409
410 <implementation>
411 <method name="toString">
toString
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
412 <body><![CDATA[
413 return this.getAttribute("msg");
414 ]]></body>
415 </method>
416 </implementation>
417 </binding>
418
419 <binding id="console-error-source" extends="xul:box">
420 <content>
421 <xul:label class="text-link" xbl:inherits="href,value=href" crop="right"/>
422 </content>
423
424 <handlers>
onclick
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
425 <handler event="click" phase="capturing" button="0" preventdefault="true">
426 <![CDATA[
427 var url = this.getAttribute("href");
428 var line = getAttribute("line");
429 window.openDialog(
430 "chrome://global/content/viewSource.xul", "_blank",
431 "all,dialog=no", url, null, null, line, false);
432 ]]>
433 </handler>
434 </handlers>
435 </binding>
436
437 </bindings>