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") { | |
10 // This page is loaded from chrome://inspect. | |
11 window.addEventListener('message', onMessage.bind(this), false); | |
12 } | |
13 update(); | 9 update(); |
14 } | 10 } |
15 | 11 |
16 function onMessage(event) { | |
17 if (event.origin != 'chrome://inspect') { | |
18 return; | |
19 } | |
20 sendCommand(event.data.action, event.data.worker); | |
21 } | |
22 | |
23 function update() { | 12 function update() { |
24 chrome.send('GetOptions'); | 13 chrome.send('GetOptions'); |
25 chrome.send('getAllRegistrations'); | 14 chrome.send('getAllRegistrations'); |
26 } | 15 } |
27 | 16 |
28 function onOptions(options) { | 17 function onOptions(options) { |
29 var template; | 18 var template; |
30 var container = $('serviceworker-options'); | 19 var container = $('serviceworker-options'); |
31 if (container.childNodes) { | 20 if (container.childNodes) { |
32 template = container.childNodes[0]; | 21 template = container.childNodes[0]; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 // Fired from the backend after the command call has completed. | 67 // Fired from the backend after the command call has completed. |
79 function onOperationComplete(status, callbackId) { | 68 function onOperationComplete(status, callbackId) { |
80 var callback = commandCallbacks[callbackId]; | 69 var callback = commandCallbacks[callbackId]; |
81 delete commandCallbacks[callbackId]; | 70 delete commandCallbacks[callbackId]; |
82 if (callback) { | 71 if (callback) { |
83 callback(status); | 72 callback(status); |
84 } | 73 } |
85 update(); | 74 update(); |
86 } | 75 } |
87 | 76 |
88 // Send the active ServiceWorker information to chrome://inspect. | |
89 function sendToInspectPage(live_registrations, | |
90 partition_id) { | |
91 var workers = []; | |
92 live_registrations.forEach(function(registration) { | |
93 [registration.active, registration.waiting].forEach(function(version) { | |
94 if (!version || version.running_status != 'RUNNING') { | |
95 return; | |
96 } | |
97 workers.push({ | |
98 'scope': registration.scope, | |
99 'url': version.script_url, | |
100 'partition_id': partition_id, | |
101 'version_id': version.version_id, | |
102 'process_id': version.process_id, | |
103 'devtools_agent_route_id': | |
104 version.devtools_agent_route_id | |
105 }); | |
106 }); | |
107 }); | |
108 window.parent.postMessage( | |
109 {'partition_id': partition_id, 'workers': workers}, | |
110 'chrome://inspect'); | |
111 } | |
112 | |
113 var allLogMessages = {}; | 77 var allLogMessages = {}; |
114 // Set log for a worker version. | 78 // Set log for a worker version. |
115 function fillLogForVersion(partition_id, version) { | 79 function fillLogForVersion(partition_id, version) { |
116 if (!version) { | 80 if (!version) { |
117 return; | 81 return; |
118 } | 82 } |
119 if (!(partition_id in allLogMessages)) { | 83 if (!(partition_id in allLogMessages)) { |
120 allLogMessages[partition_id] = {}; | 84 allLogMessages[partition_id] = {}; |
121 } | 85 } |
122 var logMessages = allLogMessages[partition_id]; | 86 var logMessages = allLogMessages[partition_id]; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 } | 128 } |
165 }); | 129 }); |
166 } | 130 } |
167 | 131 |
168 // Fired once per partition from the backend. | 132 // Fired once per partition from the backend. |
169 function onPartitionData(live_registrations, | 133 function onPartitionData(live_registrations, |
170 live_versions, | 134 live_versions, |
171 stored_registrations, | 135 stored_registrations, |
172 partition_id, | 136 partition_id, |
173 partition_path) { | 137 partition_path) { |
174 if (window.location.hash == "#iframe") { | |
175 // This page is loaded from chrome://inspect. | |
176 sendToInspectPage(live_registrations, partition_id); | |
177 return; | |
178 } | |
179 var unregistered_registrations = []; | 138 var unregistered_registrations = []; |
180 var unregistered_versions = []; | 139 var unregistered_versions = []; |
181 getUnregisteredWorkers(stored_registrations, | 140 getUnregisteredWorkers(stored_registrations, |
182 live_registrations, | 141 live_registrations, |
183 live_versions, | 142 live_versions, |
184 unregistered_registrations, | 143 unregistered_registrations, |
185 unregistered_versions); | 144 unregistered_versions); |
186 var template; | 145 var template; |
187 var container = $('serviceworker-list'); | 146 var container = $('serviceworker-list'); |
188 // Existing templates are keyed by partition_id. This allows | 147 // Existing templates are keyed by partition_id. This allows |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 onWorkerStopped: onWorkerStopped, | 254 onWorkerStopped: onWorkerStopped, |
296 onErrorReported: onErrorReported, | 255 onErrorReported: onErrorReported, |
297 onConsoleMessageReported: onConsoleMessageReported, | 256 onConsoleMessageReported: onConsoleMessageReported, |
298 onVersionStateChanged: onVersionStateChanged, | 257 onVersionStateChanged: onVersionStateChanged, |
299 onRegistrationStored: onRegistrationStored, | 258 onRegistrationStored: onRegistrationStored, |
300 onRegistrationDeleted: onRegistrationDeleted, | 259 onRegistrationDeleted: onRegistrationDeleted, |
301 }; | 260 }; |
302 }); | 261 }); |
303 | 262 |
304 document.addEventListener('DOMContentLoaded', serviceworker.initialize); | 263 document.addEventListener('DOMContentLoaded', serviceworker.initialize); |
OLD | NEW |