Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(476)

Side by Side Diff: chrome/browser/resources/inspect/inspect.js

Issue 298993003: Show ServiceWorkers in chrome://inspect. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: incorporated kinuko's comment Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/resources/inspect/inspect.html ('k') | chrome/browser/ui/webui/inspect_ui.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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);
109 if (workers.length == 0) {
110 if (list) {
111 list.parentNode.removeChild(list);
112 }
113 return;
114 }
115 if (list) {
116 list.textContent = '';
117 } else {
118 list = document.createElement('div');
119 list.id = 'service-workers-list-' + partition_id;
120 list.className = 'list';
121 $('service-workers-list').appendChild(list);
122 }
123 for (var i = 0; i < workers.length; i++) {
124 var worker = workers[i];
125 worker.hasCustomInspectAction = true;
126 var row = addTargetToList(worker, list, ['scope', 'url']);
127 addActionLink(
128 row,
129 'inspect',
130 sendServiceWorkerCommand.bind(null,
131 'inspect',
132 worker.partition_path,
133 worker.scope),
134 false);
135 addActionLink(
136 row,
137 'terminate',
138 sendServiceWorkerCommand.bind(null,
139 'stop',
140 worker.partition_path,
141 worker.scope),
142 false);
143 }
144 }
145
90 function populateTargets(source, data) { 146 function populateTargets(source, data) {
91 if (source == 'renderers') 147 if (source == 'renderers')
92 populateWebContentsTargets(data); 148 populateWebContentsTargets(data);
93 else if (source == 'workers') 149 else if (source == 'workers')
94 populateWorkerTargets(data); 150 populateWorkerTargets(data);
95 else if (source == 'adb') 151 else if (source == 'adb')
96 populateRemoteTargets(data); 152 populateRemoteTargets(data);
97 else 153 else
98 console.error('Unknown source type: ' + source); 154 console.error('Unknown source type: ' + source);
99 } 155 }
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 subrow.className = 'subrow'; 557 subrow.className = 'subrow';
502 subrowBox.appendChild(subrow); 558 subrowBox.appendChild(subrow);
503 559
504 for (var j = 0; j < properties.length; j++) 560 for (var j = 0; j < properties.length; j++)
505 subrow.appendChild(formatValue(data, properties[j])); 561 subrow.appendChild(formatValue(data, properties[j]));
506 562
507 var actionBox = document.createElement('div'); 563 var actionBox = document.createElement('div');
508 actionBox.className = 'actions'; 564 actionBox.className = 'actions';
509 subrowBox.appendChild(actionBox); 565 subrowBox.appendChild(actionBox);
510 566
511 addActionLink(row, 'inspect', sendTargetCommand.bind(null, 'inspect', data), 567 if (!data.hasCustomInspectAction) {
512 data.hasNoUniqueId || data.adbAttachedForeign); 568 addActionLink(row, 'inspect', sendTargetCommand.bind(null, 'inspect', data),
569 data.hasNoUniqueId || data.adbAttachedForeign);
570 }
513 571
514 list.appendChild(row); 572 list.appendChild(row);
515 return row; 573 return row;
516 } 574 }
517 575
518 function addActionLink(row, text, handler, opt_disabled) { 576 function addActionLink(row, text, handler, opt_disabled) {
519 var link = document.createElement('span'); 577 var link = document.createElement('span');
520 link.classList.add('action'); 578 link.classList.add('action');
521 link.setAttribute('tabindex', 1); 579 link.setAttribute('tabindex', 1);
522 if (opt_disabled) 580 if (opt_disabled)
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 deviceSection.querySelector('.device-ports').textContent = ''; 926 deviceSection.querySelector('.device-ports').textContent = '';
869 } 927 }
870 928
871 Array.prototype.forEach.call( 929 Array.prototype.forEach.call(
872 document.querySelectorAll('.device'), clearPorts); 930 document.querySelectorAll('.device'), clearPorts);
873 } 931 }
874 932
875 document.addEventListener('DOMContentLoaded', onload); 933 document.addEventListener('DOMContentLoaded', onload);
876 934
877 window.addEventListener('hashchange', onHashChange); 935 window.addEventListener('hashchange', onHashChange);
OLDNEW
« no previous file with comments | « chrome/browser/resources/inspect/inspect.html ('k') | chrome/browser/ui/webui/inspect_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698