OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 Polymer('log-buffer', { |
| 6 publish: { |
| 7 /** |
| 8 * List of displayed logs. |
| 9 * @type {?Array.<{{ |
| 10 * text: string, |
| 11 * time: string, |
| 12 * file: string, |
| 13 * line: number, |
| 14 * severity: number, |
| 15 * }}>} LogMessage |
| 16 */ |
| 17 logs: null, |
| 18 }, |
| 19 |
| 20 /** |
| 21 * Called when an instance is created. |
| 22 */ |
| 23 created: function() { |
| 24 this.logs = []; |
| 25 // We assume that only one instance of log-buffer is ever created. |
| 26 LogBufferInterface = this; |
| 27 chrome.send('getLogMessages'); |
| 28 }, |
| 29 |
| 30 // Clears the native LogBuffer. |
| 31 clearLogs: function() { |
| 32 chrome.send('clearLogBuffer'); |
| 33 }, |
| 34 |
| 35 // Handles when a new log message is added. |
| 36 onLogMessageAdded: function(log) { |
| 37 this.logs.push(log); |
| 38 }, |
| 39 |
| 40 // Handles when the logs are cleared. |
| 41 onLogBufferCleared: function() { |
| 42 this.logs = []; |
| 43 }, |
| 44 |
| 45 // Handles when the logs are returned in response to the 'getLogMessages' |
| 46 // request. |
| 47 onGotLogMessages: function(logs) { |
| 48 this.logs = logs; |
| 49 } |
| 50 }); |
| 51 |
| 52 // Interface with the native WebUI component for LogBuffer events. The functions |
| 53 // contained in this object will be invoked by the browser for each operation |
| 54 // performed on the native LogBuffer. |
| 55 LogBufferInterface = { |
| 56 /** |
| 57 * Called when a new log message is added. |
| 58 * @type {function(LogMessage)} |
| 59 */ |
| 60 onLogMessageAdded: function(log) {}, |
| 61 |
| 62 /** |
| 63 * Called when the log buffer is cleared. |
| 64 * @type {function()} |
| 65 */ |
| 66 onLogBufferCleared: function() {}, |
| 67 |
| 68 /** |
| 69 * Called in response to chrome.send('getLogMessages') with the log messages |
| 70 * currently in the buffer. |
| 71 * @type {function(Array.<LogMessage>)} |
| 72 */ |
| 73 onGotLogMessages: function(messages) {}, |
| 74 }; |
OLD | NEW |