Index: components/proximity_auth/webui/resources/log-buffer.js |
diff --git a/components/proximity_auth/webui/resources/log-buffer.js b/components/proximity_auth/webui/resources/log-buffer.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..71b393b5b961d13f0ccb4e4a8d29c3305662559f |
--- /dev/null |
+++ b/components/proximity_auth/webui/resources/log-buffer.js |
@@ -0,0 +1,74 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+Polymer('log-buffer', { |
+ publish: { |
+ /** |
+ * List of displayed logs. |
+ * @type {?Array.<{{ |
+ * text: string, |
+ * time: string, |
+ * file: string, |
+ * line: number, |
+ * severity: number, |
+ * }}>} LogMessage |
+ */ |
+ logs: null, |
+ }, |
+ |
+ /** |
+ * Called when an instance is created. |
+ */ |
+ created: function() { |
+ this.logs = []; |
+ // We assume that only one instance of log-buffer is ever created. |
+ LogBufferInterface = this; |
+ chrome.send('getLogMessages'); |
+ }, |
+ |
+ // Clears the native LogBuffer. |
+ clearLogs: function() { |
+ chrome.send('clearLogBuffer'); |
+ }, |
+ |
+ // Handles when a new log message is added. |
+ onLogMessageAdded: function(log) { |
+ this.logs.push(log); |
+ }, |
+ |
+ // Handles when the logs are cleared. |
+ onLogBufferCleared: function() { |
+ this.logs = []; |
+ }, |
+ |
+ // Handles when the logs are returned in response to the 'getLogMessages' |
+ // request. |
+ onGotLogMessages: function(logs) { |
+ this.logs = logs; |
+ } |
+}); |
+ |
+// Interface with the native WebUI component for LogBuffer events. The functions |
+// contained in this object will be invoked by the browser for each operation |
+// performed on the native LogBuffer. |
+LogBufferInterface = { |
+ /** |
+ * Called when a new log message is added. |
+ * @type {function(LogMessage)} |
+ */ |
+ onLogMessageAdded: function(log) {}, |
+ |
+ /** |
+ * Called when the log buffer is cleared. |
+ * @type {function()} |
+ */ |
+ onLogBufferCleared: function() {}, |
+ |
+ /** |
+ * Called in response to chrome.send('getLogMessages') with the log messages |
+ * currently in the buffer. |
+ * @type {function(Array.<LogMessage>)} |
+ */ |
+ onGotLogMessages: function(messages) {}, |
+}; |