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() { | 8 function initialize() { |
9 if (window.location.hash == "#iframe") { | 9 if (window.location.hash == "#iframe") { |
10 // This page is loaded from chrome://inspect. | 10 // This page is loaded from chrome://inspect. |
11 window.addEventListener('message', onMessage.bind(this), false); | 11 window.addEventListener('message', onMessage.bind(this), false); |
12 } | 12 } |
13 update(); | 13 update(); |
14 } | 14 } |
15 | 15 |
16 function onMessage(event) { | 16 function onMessage(event) { |
17 if (event.origin != 'chrome://inspect') { | 17 if (event.origin != 'chrome://inspect') { |
18 return; | 18 return; |
19 } | 19 } |
20 sendCommand(event.data.action, event.data.worker); | 20 sendCommand(event.data.action, event.data.worker); |
21 } | 21 } |
22 | 22 |
23 function update() { | 23 function update() { |
24 chrome.send('getAllRegistrations'); | 24 chrome.send('GetOptions'); |
| 25 chrome.send('getAllRegistrations'); |
| 26 } |
| 27 |
| 28 function onOptions(options) { |
| 29 var template; |
| 30 var container = $('serviceworker-options'); |
| 31 if (container.childNodes) { |
| 32 template = container.childNodes[0]; |
| 33 } |
| 34 if (!template) { |
| 35 template = jstGetTemplate('serviceworker-options-template'); |
| 36 container.appendChild(template); |
| 37 } |
| 38 jstProcess(new JsEvalContext(options), template); |
| 39 var inputs = container.querySelectorAll('input[type=\'checkbox\']'); |
| 40 for (var i = 0; i < inputs.length; ++i) { |
| 41 if (!inputs[i].hasClickEvent) { |
| 42 inputs[i].addEventListener('click', (function(event) { |
| 43 chrome.send('SetOption', |
| 44 [event.target.className, event.target.checked]); |
| 45 }).bind(this), false); |
| 46 inputs[i].hasClickEvent = true; |
| 47 } |
| 48 } |
25 } | 49 } |
26 | 50 |
27 function progressNodeFor(link) { | 51 function progressNodeFor(link) { |
28 return link.parentNode.querySelector('.operation-status'); | 52 return link.parentNode.querySelector('.operation-status'); |
29 } | 53 } |
30 | 54 |
31 // All commands are completed with 'onOperationComplete'. | 55 // All commands are completed with 'onOperationComplete'. |
32 var COMMANDS = ['stop', 'sync', 'inspect', 'unregister', 'start']; | 56 var COMMANDS = ['stop', 'sync', 'inspect', 'unregister', 'start']; |
33 function commandHandler(command) { | 57 function commandHandler(command) { |
34 return function(event) { | 58 return function(event) { |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 var logArea = logAreas[i]; | 281 var logArea = logAreas[i]; |
258 if (logArea.partition_id == partition_id && | 282 if (logArea.partition_id == partition_id && |
259 logArea.version_id == version_id) { | 283 logArea.version_id == version_id) { |
260 logArea.value += message; | 284 logArea.value += message; |
261 } | 285 } |
262 } | 286 } |
263 } | 287 } |
264 | 288 |
265 return { | 289 return { |
266 initialize: initialize, | 290 initialize: initialize, |
| 291 onOptions: onOptions, |
267 onOperationComplete: onOperationComplete, | 292 onOperationComplete: onOperationComplete, |
268 onPartitionData: onPartitionData, | 293 onPartitionData: onPartitionData, |
269 onWorkerStarted: onWorkerStarted, | 294 onWorkerStarted: onWorkerStarted, |
270 onWorkerStopped: onWorkerStopped, | 295 onWorkerStopped: onWorkerStopped, |
271 onErrorReported: onErrorReported, | 296 onErrorReported: onErrorReported, |
272 onConsoleMessageReported: onConsoleMessageReported, | 297 onConsoleMessageReported: onConsoleMessageReported, |
273 onVersionStateChanged: onVersionStateChanged, | 298 onVersionStateChanged: onVersionStateChanged, |
274 onRegistrationStored: onRegistrationStored, | 299 onRegistrationStored: onRegistrationStored, |
275 onRegistrationDeleted: onRegistrationDeleted, | 300 onRegistrationDeleted: onRegistrationDeleted, |
276 }; | 301 }; |
277 }); | 302 }); |
278 | 303 |
279 document.addEventListener('DOMContentLoaded', serviceworker.initialize); | 304 document.addEventListener('DOMContentLoaded', serviceworker.initialize); |
OLD | NEW |