Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 cr.define('chrome.supervised_user_internals', function() { | 5 cr.define('chrome.supervised_user_internals', function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 function initialize() { | 8 function initialize() { |
| 9 function submitURL(event) { | 9 function submitURL(event) { |
| 10 $('try-url-result').textContent = ''; | 10 $('try-url-result').textContent = ''; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 if (oldStr != '' && oldStr != newStr) { | 32 if (oldStr != '' && oldStr != newStr) { |
| 33 // Note the addListener function does not end up creating duplicate | 33 // Note the addListener function does not end up creating duplicate |
| 34 // listeners. There can be only one listener per event at a time. | 34 // listeners. There can be only one listener per event at a time. |
| 35 // See https://developer.mozilla.org/en/DOM/element.addEventListener | 35 // See https://developer.mozilla.org/en/DOM/element.addEventListener |
| 36 node.addEventListener('webkitAnimationEnd', clearHighlight, false); | 36 node.addEventListener('webkitAnimationEnd', clearHighlight, false); |
| 37 node.setAttribute('highlighted', ''); | 37 node.setAttribute('highlighted', ''); |
| 38 } | 38 } |
| 39 } | 39 } |
| 40 | 40 |
| 41 function receiveBasicInfo(info) { | 41 function receiveBasicInfo(info) { |
| 42 jstProcess(new JsEvalContext(info), $('info')); | 42 jstProcess(new JsEvalContext(info), $('basic-info')); |
| 43 | 43 |
| 44 // Hack: Schedule another refresh after a while. | 44 // Hack: Schedule another refresh after a while. |
| 45 // TODO(treib): Get rid of this once we're properly notified of all | 45 // TODO(treib): Get rid of this once we're properly notified of all |
| 46 // relevant changes. | 46 // relevant changes. |
| 47 setTimeout(function() { chrome.send('getBasicInfo'); }, 5000); | 47 setTimeout(function() { chrome.send('getBasicInfo'); }, 5000); |
| 48 } | 48 } |
| 49 | 49 |
| 50 function receiveUserSettings(settings) { | |
| 51 // The user settings are returned as an object, flatten them into a | |
| 52 // list of key/value pairs for easier consumption by the HTML template. | |
| 53 // This is not done recursively, values are passed as their JSON | |
| 54 // representation. | |
| 55 var keys = Object.keys(settings); | |
| 56 var kvpairs = []; | |
| 57 | |
| 58 for (var i = 0; i < keys.length; i++) { | |
| 59 kvpairs.push({ | |
|
Bernhard Bauer
2015/08/18 13:09:09
You could do this with Object.keys(settings).map(f
PEConn2
2015/08/18 14:02:58
Done.
| |
| 60 key: keys[i], | |
| 61 value: JSON.stringify(settings[keys[i]], null, 2) | |
| 62 }); | |
| 63 } | |
| 64 | |
| 65 jstProcess(new JsEvalContext({settings: kvpairs}), $('user-settings')); | |
| 66 } | |
| 67 | |
| 50 function receiveTryURLResult(result) { | 68 function receiveTryURLResult(result) { |
| 51 $('try-url-result').textContent = result; | 69 $('try-url-result').textContent = result; |
| 52 } | 70 } |
| 53 | 71 |
| 54 /** | 72 /** |
| 55 * Helper to determine if an element is scrolled to its bottom limit. | 73 * Helper to determine if an element is scrolled to its bottom limit. |
| 56 * @param {Element} elem element to check | 74 * @param {Element} elem element to check |
| 57 * @return {boolean} true if the element is scrolled to the bottom | 75 * @return {boolean} true if the element is scrolled to the bottom |
| 58 */ | 76 */ |
| 59 function isScrolledToBottom(elem) { | 77 function isScrolledToBottom(elem) { |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 88 | 106 |
| 89 if (shouldScrollDown) | 107 if (shouldScrollDown) |
| 90 scrollToBottom(container); | 108 scrollToBottom(container); |
| 91 } | 109 } |
| 92 | 110 |
| 93 // Return an object with all of the exports. | 111 // Return an object with all of the exports. |
| 94 return { | 112 return { |
| 95 initialize: initialize, | 113 initialize: initialize, |
| 96 highlightIfChanged: highlightIfChanged, | 114 highlightIfChanged: highlightIfChanged, |
| 97 receiveBasicInfo: receiveBasicInfo, | 115 receiveBasicInfo: receiveBasicInfo, |
| 116 receiveUserSettings: receiveUserSettings, | |
| 98 receiveTryURLResult: receiveTryURLResult, | 117 receiveTryURLResult: receiveTryURLResult, |
| 99 receiveFilteringResult: receiveFilteringResult, | 118 receiveFilteringResult: receiveFilteringResult, |
| 100 }; | 119 }; |
| 101 }); | 120 }); |
| 102 | 121 |
| 103 document.addEventListener('DOMContentLoaded', | 122 document.addEventListener('DOMContentLoaded', |
| 104 chrome.supervised_user_internals.initialize); | 123 chrome.supervised_user_internals.initialize); |
| OLD | NEW |