OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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('serviceworker', function() { | 5 cr.define('serviceworker', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
| 8 function initialize() { |
| 9 update(); |
| 10 } |
| 11 |
8 function update() { | 12 function update() { |
| 13 chrome.send('GetOptions'); |
9 chrome.send('getAllRegistrations'); | 14 chrome.send('getAllRegistrations'); |
10 } | 15 } |
11 | 16 |
| 17 function onOptions(options) { |
| 18 var template; |
| 19 var container = $('serviceworker-options'); |
| 20 if (container.childNodes) { |
| 21 template = container.childNodes[0]; |
| 22 } |
| 23 if (!template) { |
| 24 template = jstGetTemplate('serviceworker-options-template'); |
| 25 container.appendChild(template); |
| 26 } |
| 27 jstProcess(new JsEvalContext(options), template); |
| 28 var inputs = container.querySelectorAll('input[type=\'checkbox\']'); |
| 29 for (var i = 0; i < inputs.length; ++i) { |
| 30 if (!inputs[i].hasClickEvent) { |
| 31 inputs[i].addEventListener('click', (function(event) { |
| 32 chrome.send('SetOption', |
| 33 [event.target.className, event.target.checked]); |
| 34 }).bind(this), false); |
| 35 inputs[i].hasClickEvent = true; |
| 36 } |
| 37 } |
| 38 } |
| 39 |
12 function progressNodeFor(link) { | 40 function progressNodeFor(link) { |
13 return link.parentNode.querySelector('.operation-status'); | 41 return link.parentNode.querySelector('.operation-status'); |
14 } | 42 } |
15 | 43 |
16 // All commands are sent with the partition_path and scope, and | 44 // All commands are sent with the partition_path and scope, and |
17 // are all completed with 'onOperationComplete'. | 45 // are all completed with 'onOperationComplete'. |
18 var COMMANDS = ['unregister', 'start', 'stop', 'sync', 'inspect']; | 46 var COMMANDS = ['unregister', 'start', 'stop', 'sync', 'inspect']; |
19 function commandHandler(command) { | 47 function commandHandler(command) { |
20 return function(event) { | 48 return function(event) { |
21 var link = event.target; | 49 var link = event.target; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 for (var i = 0; i < logAreas.length; ++i) { | 185 for (var i = 0; i < logAreas.length; ++i) { |
158 var logArea = logAreas[i]; | 186 var logArea = logAreas[i]; |
159 if (logArea.partition_id == partition_id && | 187 if (logArea.partition_id == partition_id && |
160 logArea.version_id == version_id) { | 188 logArea.version_id == version_id) { |
161 logArea.value += message; | 189 logArea.value += message; |
162 } | 190 } |
163 } | 191 } |
164 } | 192 } |
165 | 193 |
166 return { | 194 return { |
| 195 initialize: initialize, |
167 update: update, | 196 update: update, |
| 197 onOptions: onOptions, |
168 onOperationComplete: onOperationComplete, | 198 onOperationComplete: onOperationComplete, |
169 onPartitionData: onPartitionData, | 199 onPartitionData: onPartitionData, |
170 onWorkerStarted: onWorkerStarted, | 200 onWorkerStarted: onWorkerStarted, |
171 onWorkerStopped: onWorkerStopped, | 201 onWorkerStopped: onWorkerStopped, |
172 onErrorReported: onErrorReported, | 202 onErrorReported: onErrorReported, |
173 onConsoleMessageReported: onConsoleMessageReported, | 203 onConsoleMessageReported: onConsoleMessageReported, |
174 onVersionStateChanged: onVersionStateChanged, | 204 onVersionStateChanged: onVersionStateChanged, |
175 onRegistrationStored: onRegistrationStored, | 205 onRegistrationStored: onRegistrationStored, |
176 onRegistrationDeleted: onRegistrationDeleted, | 206 onRegistrationDeleted: onRegistrationDeleted, |
177 }; | 207 }; |
178 }); | 208 }); |
179 | 209 |
180 document.addEventListener('DOMContentLoaded', serviceworker.update); | 210 document.addEventListener('DOMContentLoaded', serviceworker.initialize); |
OLD | NEW |