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

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

Issue 22277007: chrome://inspect: Add "open", "close" and "reload" actions to Devices tab (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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 | Annotate | Revision Log
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 function inspect(data) { 5 function inspect(data) {
6 chrome.send('inspect', [data]); 6 chrome.send('inspect', [data]);
7 } 7 }
8 8
9 function terminate(data) { 9 function terminate(data) {
10 chrome.send('terminate', [data]); 10 chrome.send('terminate', [data]);
11 } 11 }
12 12
13 function reload(data) {
14 chrome.send('reload', [data]);
15 }
16
17 function open(browserId, url) {
18 chrome.send('open', [browserId, url]);
19 }
20
13 function removeChildren(element_id) { 21 function removeChildren(element_id) {
14 var element = $(element_id); 22 var element = $(element_id);
15 element.textContent = ''; 23 element.textContent = '';
16 } 24 }
17 25
18 function onload() { 26 function onload() {
19 var tabContents = document.querySelectorAll('#content > div'); 27 var tabContents = document.querySelectorAll('#content > div');
20 for (var i = 0; i != tabContents.length; i++) { 28 for (var i = 0; i != tabContents.length; i++) {
21 var tabContent = tabContents[i]; 29 var tabContent = tabContents[i];
22 var tabName = tabContent.querySelector('.content-header').textContent; 30 var tabName = tabContent.querySelector('.content-header').textContent;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 addToWorkersList(data[i]); 84 addToWorkersList(data[i]);
77 } 85 }
78 86
79 function populateDeviceLists(devices) { 87 function populateDeviceLists(devices) {
80 var devicesDigest = JSON.stringify(devices); 88 var devicesDigest = JSON.stringify(devices);
81 if (!devices || devicesDigest == window.devicesDigest) 89 if (!devices || devicesDigest == window.devicesDigest)
82 return; 90 return;
83 91
84 window.devicesDigest = devicesDigest; 92 window.devicesDigest = devicesDigest;
85 93
86 var containerElement = $('devices'); 94 function removeObsolete(validIds, section) {
87 containerElement.textContent = ''; 95 if (validIds.indexOf(section.id) < 0)
96 section.remove();
97 }
88 98
89 // Populate with new entries 99 var deviceList = $('devices');
100
101 var newDeviceIds = devices.map(function(d) { return d.adbGlobalId });
102 Array.prototype.forEach.call(
103 deviceList.querySelectorAll('.device'),
104 removeObsolete.bind(null, newDeviceIds));
105
90 for (var d = 0; d < devices.length; d++) { 106 for (var d = 0; d < devices.length; d++) {
91 var device = devices[d]; 107 var device = devices[d];
92 108
93 var deviceHeader = document.createElement('div'); 109 var browserList;
94 deviceHeader.className = 'section'; 110 var deviceSection = $(device.adbGlobalId);
95 deviceHeader.textContent = device.adbModel; 111 if (deviceSection) {
96 containerElement.appendChild(deviceHeader); 112 browserList = deviceSection.querySelector('.browsers');
113 } else {
114 deviceSection = document.createElement('div');
115 deviceSection.id = device.adbGlobalId;
116 deviceSection.className = 'device list';
117 deviceList.appendChild(deviceSection);
97 118
98 var deviceContent = document.createElement('div'); 119 var deviceHeader = document.createElement('div');
99 deviceContent.className = 'list'; 120 deviceHeader.className = 'section';
100 containerElement.appendChild(deviceContent); 121 deviceHeader.textContent = device.adbModel;
122 deviceSection.appendChild(deviceHeader);
123
124 browserList = document.createElement('div');
125 browserList.className = 'browsers';
126 deviceSection.appendChild(browserList);
127 }
128
129 var newBrowserIds =
130 device.browsers.map(function(b) { return b.adbGlobalId });
131 Array.prototype.forEach.call(
132 browserList.querySelectorAll('.browser'),
133 removeObsolete.bind(null, newBrowserIds));
101 134
102 for (var b = 0; b < device.browsers.length; b++) { 135 for (var b = 0; b < device.browsers.length; b++) {
103 var browser = device.browsers[b]; 136 var browser = device.browsers[b];
104 137
105 var browserHeader = document.createElement('div'); 138 var pageList;
106 browserHeader.className = 'small-section'; 139 var browserSection = $(browser.adbGlobalId);
107 browserHeader.textContent = browser.adbBrowserName; 140 if (browserSection) {
108 deviceContent.appendChild(browserHeader); 141 pageList = browserSection.querySelector('.pages');
142 pageList.textContent = '';
143 } else {
144 browserSection = document.createElement('div');
145 browserSection.id = browser.adbGlobalId;
146 browserSection.className = 'browser';
147 browserList.appendChild(browserSection);
109 148
110 var browserPages = document.createElement('div'); 149 var browserHeader = document.createElement('div');
111 browserPages.className = 'list package'; 150 browserHeader.className = 'small-section';
112 deviceContent.appendChild(browserPages); 151 browserHeader.textContent = browser.adbBrowserName;
152 browserSection.appendChild(browserHeader);
153
154 var newPage = document.createElement('div');
155 newPage.className = 'open';
156
157 var newPageUrl = document.createElement('input');
158 newPageUrl.type = 'text';
159 newPageUrl.placeholder = 'Open tab with url';
160 newPage.appendChild(newPageUrl);
161
162 var openHandler = function(browserId, input) {
163 open(browserId, input.value || 'about:blank');
164 input.value = '';
165 }.bind(null, browser.adbGlobalId, newPageUrl);
166 newPageUrl.addEventListener('keyup', function(handler, event) {
167 if (event.keyIdentifier == 'Enter' && event.target.value)
168 handler();
169 }.bind(null, openHandler), true);
170
171 var newPageButton = document.createElement('button');
172 newPageButton.textContent = 'Open';
173 newPage.appendChild(newPageButton);
174 newPageButton.addEventListener('click', openHandler, true);
175
176 browserSection.appendChild(newPage);
177
178 pageList = document.createElement('div');
179 pageList.className = 'list pages';
180 browserSection.appendChild(pageList);
181 }
113 182
114 for (var p = 0; p < browser.pages.length; p++) { 183 for (var p = 0; p < browser.pages.length; p++) {
115 addTargetToList( 184 var page = browser.pages[p];
116 browser.pages[p], browserPages, ['faviconUrl', 'name', 'url']); 185 var row = addTargetToList(
186 page, pageList, ['faviconUrl', 'name', 'url']);
187 row.appendChild(createActionLink('reload', reload.bind(null, page)));
188 row.appendChild(createActionLink('close', terminate.bind(null, page)));
117 } 189 }
118 } 190 }
119 } 191 }
120 } 192 }
121 193
122 function addToPagesList(data) { 194 function addToPagesList(data) {
123 addTargetToList(data, $('pages'), ['faviconUrl', 'name', 'url']); 195 addTargetToList(data, $('pages'), ['faviconUrl', 'name', 'url']);
124 } 196 }
125 197
126 function addToExtensionsList(data) { 198 function addToExtensionsList(data) {
127 addTargetToList(data, $('extensions'), ['name', 'url']); 199 addTargetToList(data, $('extensions'), ['name', 'url']);
128 } 200 }
129 201
130 function addToAppsList(data) { 202 function addToAppsList(data) {
131 addTargetToList(data, $('apps'), ['name', 'url']); 203 addTargetToList(data, $('apps'), ['name', 'url']);
132 } 204 }
133 205
134 function addToWorkersList(data) { 206 function addToWorkersList(data) {
135 addTargetToList(data, 207 var row = addTargetToList(data, $('workers'), ['name', 'url', 'pid']);
136 $('workers'), 208 row.appendChild(createActionLink(
137 ['name', 'url', 'pid'], 209 'terminate', terminate.bind(null, data), data.attached));
138 true);
139 } 210 }
140 211
141 function addToOthersList(data) { 212 function addToOthersList(data) {
142 addTargetToList(data, $('others'), ['url']); 213 addTargetToList(data, $('others'), ['url']);
143 } 214 }
144 215
145 function formatValue(data, property) { 216 function formatValue(data, property) {
146 var value = data[property]; 217 var value = data[property];
147 218
148 if (property == 'faviconUrl') { 219 if (property == 'faviconUrl') {
149 var faviconElement = document.createElement('img'); 220 var faviconElement = document.createElement('img');
150 if (value) 221 if (value)
151 faviconElement.src = value; 222 faviconElement.src = value;
152 return faviconElement; 223 return faviconElement;
153 } 224 }
154 225
155 var text = value ? String(value) : ''; 226 var text = value ? String(value) : '';
156 if (text.length > 100) 227 if (text.length > 100)
157 text = text.substring(0, 100) + '\u2026'; 228 text = text.substring(0, 100) + '\u2026';
158 229
159 if (property == 'pid') 230 if (property == 'pid')
160 text = 'Pid:' + text; 231 text = 'Pid:' + text;
161 232
162 var span = document.createElement('span'); 233 var span = document.createElement('span');
163 span.textContent = ' ' + text + ' '; 234 span.textContent = ' ' + text + ' ';
164 span.className = property; 235 span.className = property;
165 return span; 236 return span;
166 } 237 }
167 238
168 function addTargetToList(data, list, properties, canTerminate) { 239 function addTargetToList(data, list, properties) {
169 var row = document.createElement('div'); 240 var row = document.createElement('div');
170 row.className = 'row'; 241 row.className = 'row';
171 for (var j = 0; j < properties.length; j++) 242 for (var j = 0; j < properties.length; j++)
172 row.appendChild(formatValue(data, properties[j])); 243 row.appendChild(formatValue(data, properties[j]));
173 244
174 row.appendChild(createInspectElement(data)); 245 row.appendChild(createActionLink('inspect', inspect.bind(null, data)));
175
176 if (canTerminate)
177 row.appendChild(createTerminateElement(data));
178 246
179 row.processId = data.processId; 247 row.processId = data.processId;
180 row.routeId = data.routeId; 248 row.routeId = data.routeId;
181 249
182 list.appendChild(row); 250 list.appendChild(row);
251 return row;
183 } 252 }
184 253
185 function createInspectElement(data) { 254 function createActionLink(text, handler, opt_disabled) {
186 var link = document.createElement('a'); 255 var link = document.createElement('a');
256 if (opt_disabled)
257 link.disabled = true;
258
187 link.setAttribute('href', '#'); 259 link.setAttribute('href', '#');
188 link.textContent = ' inspect '; 260 link.textContent = text;
189 link.addEventListener( 261 link.addEventListener('click', handler, true);
190 'click',
191 inspect.bind(this, data),
192 true);
193 return link; 262 return link;
194 } 263 }
195 264
196 function createTerminateElement(data) {
197 var link = document.createElement('a');
198 if (data.attached)
199 link.disabled = true;
200
201 link.setAttribute('href', '#');
202 link.textContent = ' terminate ';
203 link.addEventListener(
204 'click',
205 terminate.bind(this, data),
206 true);
207 return link;
208 }
209
210 265
211 function initPortForwarding() { 266 function initPortForwarding() {
212 $('port-forwarding-enable').addEventListener('change', enablePortForwarding); 267 $('port-forwarding-enable').addEventListener('change', enablePortForwarding);
213 268
214 $('port-forwarding-config-open').addEventListener( 269 $('port-forwarding-config-open').addEventListener(
215 'click', openPortForwardingConfig); 270 'click', openPortForwardingConfig);
216 $('port-forwarding-config-close').addEventListener( 271 $('port-forwarding-config-close').addEventListener(
217 'click', closePortForwardingConfig); 272 'click', closePortForwardingConfig);
218 $('port-forwarding-config-done').addEventListener( 273 $('port-forwarding-config-done').addEventListener(
219 'click', commitPortForwardingConfig); 274 'click', commitPortForwardingConfig);
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 if (line.querySelector('.invalid')) 487 if (line.querySelector('.invalid'))
433 return; 488 return;
434 line.classList.remove('fresh'); 489 line.classList.remove('fresh');
435 var freshLine = createEmptyConfigLine(); 490 var freshLine = createEmptyConfigLine();
436 line.parentNode.appendChild(freshLine); 491 line.parentNode.appendChild(freshLine);
437 if (opt_selectNew) 492 if (opt_selectNew)
438 freshLine.querySelector('.port').focus(); 493 freshLine.querySelector('.port').focus();
439 } 494 }
440 495
441 document.addEventListener('DOMContentLoaded', onload); 496 document.addEventListener('DOMContentLoaded', onload);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698