OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 var MIN_VERSION_TAB_CLOSE = 25; | 5 var MIN_VERSION_TAB_CLOSE = 25; |
6 var MIN_VERSION_TARGET_ID = 26; | 6 var MIN_VERSION_TARGET_ID = 26; |
7 var MIN_VERSION_NEW_TAB = 29; | 7 var MIN_VERSION_NEW_TAB = 29; |
8 var MIN_VERSION_TAB_ACTIVATE = 30; | 8 var MIN_VERSION_TAB_ACTIVATE = 30; |
9 | 9 |
10 var queryParamsObject = {}; | 10 var queryParamsObject = {}; |
(...skipping 11 matching lines...) Expand all Loading... | |
22 })(); | 22 })(); |
23 | 23 |
24 function sendCommand(command, args) { | 24 function sendCommand(command, args) { |
25 chrome.send(command, Array.prototype.slice.call(arguments, 1)); | 25 chrome.send(command, Array.prototype.slice.call(arguments, 1)); |
26 } | 26 } |
27 | 27 |
28 function sendTargetCommand(command, target) { | 28 function sendTargetCommand(command, target) { |
29 sendCommand(command, target.source, target.id); | 29 sendCommand(command, target.source, target.id); |
30 } | 30 } |
31 | 31 |
32 function sendServiceWorkerCommand(action, partition_path, scope) { | |
33 $('serviceworker-internals').contentWindow.postMessage({ | |
34 'action': action, | |
35 'partition_path': partition_path, | |
36 'scope': scope | |
37 },'chrome://serviceworker-internals'); | |
38 } | |
39 | |
32 function removeChildren(element_id) { | 40 function removeChildren(element_id) { |
33 var element = $(element_id); | 41 var element = $(element_id); |
34 element.textContent = ''; | 42 element.textContent = ''; |
35 } | 43 } |
36 | 44 |
37 function onload() { | 45 function onload() { |
38 var tabContents = document.querySelectorAll('#content > div'); | 46 var tabContents = document.querySelectorAll('#content > div'); |
39 for (var i = 0; i != tabContents.length; i++) { | 47 for (var i = 0; i != tabContents.length; i++) { |
40 var tabContent = tabContents[i]; | 48 var tabContent = tabContents[i]; |
41 var tabName = tabContent.querySelector('.content-header').textContent; | 49 var tabName = tabContent.querySelector('.content-header').textContent; |
42 | 50 |
43 var tabHeader = document.createElement('div'); | 51 var tabHeader = document.createElement('div'); |
44 tabHeader.className = 'tab-header'; | 52 tabHeader.className = 'tab-header'; |
45 var button = document.createElement('button'); | 53 var button = document.createElement('button'); |
46 button.textContent = tabName; | 54 button.textContent = tabName; |
47 tabHeader.appendChild(button); | 55 tabHeader.appendChild(button); |
48 tabHeader.addEventListener('click', selectTab.bind(null, tabContent.id)); | 56 tabHeader.addEventListener('click', selectTab.bind(null, tabContent.id)); |
49 $('navigation').appendChild(tabHeader); | 57 $('navigation').appendChild(tabHeader); |
50 } | 58 } |
51 onHashChange(); | 59 onHashChange(); |
52 initSettings(); | 60 initSettings(); |
53 sendCommand('init-ui'); | 61 sendCommand('init-ui'); |
62 window.addEventListener('message', onMessage.bind(this), false); | |
63 } | |
64 | |
65 function onMessage(event) { | |
66 if (event.origin != 'chrome://serviceworker-internals') { | |
67 return; | |
68 } | |
69 populateServiceWorkers(event.data.partition_id, | |
70 event.data.workers); | |
54 } | 71 } |
55 | 72 |
56 function onHashChange() { | 73 function onHashChange() { |
57 var hash = window.location.hash.slice(1).toLowerCase(); | 74 var hash = window.location.hash.slice(1).toLowerCase(); |
58 if (!selectTab(hash)) | 75 if (!selectTab(hash)) |
59 selectTab('devices'); | 76 selectTab('devices'); |
60 } | 77 } |
61 | 78 |
62 /** | 79 /** |
63 * @param {string} id Tab id. | 80 * @param {string} id Tab id. |
(...skipping 16 matching lines...) Expand all Loading... | |
80 tabContent.classList.remove('selected'); | 97 tabContent.classList.remove('selected'); |
81 tabHeader.classList.remove('selected'); | 98 tabHeader.classList.remove('selected'); |
82 } | 99 } |
83 } | 100 } |
84 if (!found) | 101 if (!found) |
85 return false; | 102 return false; |
86 window.location.hash = id; | 103 window.location.hash = id; |
87 return true; | 104 return true; |
88 } | 105 } |
89 | 106 |
107 function populateServiceWorkers(partition_id, workers) { | |
108 var list = $('service-workers-list-' + partition_id); | |
Vladislav Kaznacheev
2014/05/23 11:03:28
Do partitions ever go away? This code can only add
horo
2014/05/23 11:21:34
Done.
Added removeChild().
| |
109 if (list) { | |
110 list.textContent = ''; | |
111 } else { | |
112 list = document.createElement('div'); | |
113 list.id = 'service-workers-list-' + partition_id; | |
114 list.className = 'list'; | |
115 $('service-workers-list').appendChild(list); | |
116 } | |
117 for (var i = 0; i < workers.length; i++) { | |
118 var worker = workers[i]; | |
119 worker.hasCustomInspectAction = true; | |
120 var row = addTargetToList(worker, list, ['scope', 'url']); | |
121 addActionLink( | |
122 row, | |
123 'inspect', | |
124 sendServiceWorkerCommand.bind(null, | |
125 'inspect', | |
126 worker.partition_path, | |
127 worker.scope), | |
128 false); | |
129 addActionLink( | |
130 row, | |
131 'terminate', | |
132 sendServiceWorkerCommand.bind(null, | |
133 'stop', | |
134 worker.partition_path, | |
135 worker.scope), | |
136 false); | |
137 } | |
138 } | |
139 | |
90 function populateTargets(source, data) { | 140 function populateTargets(source, data) { |
91 if (source == 'renderers') | 141 if (source == 'renderers') |
92 populateWebContentsTargets(data); | 142 populateWebContentsTargets(data); |
93 else if (source == 'workers') | 143 else if (source == 'workers') |
94 populateWorkerTargets(data); | 144 populateWorkerTargets(data); |
95 else if (source == 'adb') | 145 else if (source == 'adb') |
96 populateRemoteTargets(data); | 146 populateRemoteTargets(data); |
97 else | 147 else |
98 console.error('Unknown source type: ' + source); | 148 console.error('Unknown source type: ' + source); |
99 } | 149 } |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
501 subrow.className = 'subrow'; | 551 subrow.className = 'subrow'; |
502 subrowBox.appendChild(subrow); | 552 subrowBox.appendChild(subrow); |
503 | 553 |
504 for (var j = 0; j < properties.length; j++) | 554 for (var j = 0; j < properties.length; j++) |
505 subrow.appendChild(formatValue(data, properties[j])); | 555 subrow.appendChild(formatValue(data, properties[j])); |
506 | 556 |
507 var actionBox = document.createElement('div'); | 557 var actionBox = document.createElement('div'); |
508 actionBox.className = 'actions'; | 558 actionBox.className = 'actions'; |
509 subrowBox.appendChild(actionBox); | 559 subrowBox.appendChild(actionBox); |
510 | 560 |
511 addActionLink(row, 'inspect', sendTargetCommand.bind(null, 'inspect', data), | 561 if (!data.hasCustomInspectAction) { |
512 data.hasNoUniqueId || data.adbAttachedForeign); | 562 addActionLink(row, 'inspect', sendTargetCommand.bind(null, 'inspect', data), |
563 data.hasNoUniqueId || data.adbAttachedForeign); | |
564 } | |
513 | 565 |
514 list.appendChild(row); | 566 list.appendChild(row); |
515 return row; | 567 return row; |
516 } | 568 } |
517 | 569 |
518 function addActionLink(row, text, handler, opt_disabled) { | 570 function addActionLink(row, text, handler, opt_disabled) { |
519 var link = document.createElement('span'); | 571 var link = document.createElement('span'); |
520 link.classList.add('action'); | 572 link.classList.add('action'); |
521 link.setAttribute('tabindex', 1); | 573 link.setAttribute('tabindex', 1); |
522 if (opt_disabled) | 574 if (opt_disabled) |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
868 deviceSection.querySelector('.device-ports').textContent = ''; | 920 deviceSection.querySelector('.device-ports').textContent = ''; |
869 } | 921 } |
870 | 922 |
871 Array.prototype.forEach.call( | 923 Array.prototype.forEach.call( |
872 document.querySelectorAll('.device'), clearPorts); | 924 document.querySelectorAll('.device'), clearPorts); |
873 } | 925 } |
874 | 926 |
875 document.addEventListener('DOMContentLoaded', onload); | 927 document.addEventListener('DOMContentLoaded', onload); |
876 | 928 |
877 window.addEventListener('hashchange', onHashChange); | 929 window.addEventListener('hashchange', onHashChange); |
OLD | NEW |