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

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

Issue 12586010: DevTools: extract ADB command classes, change objects' lifetimes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Win build fixed. Created 7 years, 9 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
« no previous file with comments | « chrome/browser/devtools/devtools_adb_bridge.cc ('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 /** 5 /**
6 * ADB Device representation. This class has static methods for querying for 6 * ADB Device representation. This class has static methods for querying for
7 * devices as well as instance methods for device manipulation. 7 * devices as well as instance methods for device manipulation.
8 * @param {string} deviceLine Raw device descriprion line. 8 * @param {string} deviceLine Raw device descriprion line.
9 * @constructor 9 * @constructor
10 */ 10 */
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 } catch (e) { 97 } catch (e) {
98 } 98 }
99 return null; 99 return null;
100 }; 100 };
101 101
102 /** 102 /**
103 * Discovers ADB devices. 103 * Discovers ADB devices.
104 * @return {?Object} ADB query result. 104 * @return {?Object} ADB query result.
105 * @private 105 * @private
106 */ 106 */
107 AdbDevice.adbDevices_ = function() { 107 AdbDevice.adbPages_ = function() {
108 var xhr = new XMLHttpRequest(); 108 var xhr = new XMLHttpRequest();
109 xhr.open('GET', 'adb-devices', false); 109 xhr.open('GET', 'adb-pages', false);
110 xhr.send(null); 110 xhr.send(null);
111 if (xhr.status !== 200) 111 if (xhr.status !== 200)
112 return null; 112 return null;
113 113
114 try { 114 try {
115 var result = JSON.parse(xhr.responseText); 115 return JSON.parse(xhr.responseText);
116 return result[0] ? null : result[1];
117 } catch (e) { 116 } catch (e) {
118 } 117 }
119 return null; 118 return null;
120 }; 119 };
121 120
122 /** 121 /**
123 * Returns next available (unmapped) port to use in forwarding. 122 * Returns next available (unmapped) port to use in forwarding.
124 * @param {Object<string,string>} forwards Forwards map. 123 * @param {Object<string,string>} forwards Forwards map.
125 * @return {number} Next available port. 124 * @return {number} Next available port.
126 * @private 125 * @private
(...skipping 30 matching lines...) Expand all
157 AdbDevice.prototype.targets = function() { 156 AdbDevice.prototype.targets = function() {
158 var pages = this.queryJson_('list'); 157 var pages = this.queryJson_('list');
159 var targets = []; 158 var targets = [];
160 for (var j = 0; pages && j < pages.length; j++) { 159 for (var j = 0; pages && j < pages.length; j++) {
161 var json = pages[j]; 160 var json = pages[j];
162 var target = {}; 161 var target = {};
163 target['type'] = 'mobile'; 162 target['type'] = 'mobile';
164 target['name'] = json['title']; 163 target['name'] = json['title'];
165 target['url'] = json['url']; 164 target['url'] = json['url'];
166 target['attached'] = !json['webSocketDebuggerUrl']; 165 target['attached'] = !json['webSocketDebuggerUrl'];
167 target['favicon_url'] = json['faviconUrl']; 166 target['faviconUrl'] = json['faviconUrl'];
168 target['inspect_url'] = json['devtoolsFrontendUrl']; 167 target['inspectUrl'] = json['devtoolsFrontendUrl'];
169 targets.push(target); 168 targets.push(target);
170 } 169 }
171 return targets; 170 return targets;
172 }; 171 };
173 172
174 /** 173 /**
175 * Issues synchronous json request against target device. 174 * Issues synchronous json request against target device.
176 * @param {string} query DevTools protocol /json query. 175 * @param {string} query DevTools protocol /json query.
177 * @return {?Object} Result object. 176 * @return {?Object} Result object.
178 * @private 177 * @private
(...skipping 19 matching lines...) Expand all
198 function requestData() { 197 function requestData() {
199 var xhr = new XMLHttpRequest(); 198 var xhr = new XMLHttpRequest();
200 xhr.open('GET', 'targets-data.json', false); 199 xhr.open('GET', 'targets-data.json', false);
201 xhr.send(null); 200 xhr.send(null);
202 if (xhr.status === 200) 201 if (xhr.status === 200)
203 return JSON.parse(xhr.responseText); 202 return JSON.parse(xhr.responseText);
204 return []; 203 return [];
205 } 204 }
206 205
207 function inspect(data) { 206 function inspect(data) {
208 if (data['inspect_url']) { 207 if (data['inspectUrl']) {
209 window.open(data['inspect_url'], undefined, 208 window.open(data['inspectUrl'], undefined,
210 'location=0,width=800,height=600'); 209 'location=0,width=800,height=600');
211 return; 210 return;
212 } 211 }
213 chrome.send('inspect', 212 chrome.send('inspect',
214 [String(data.processId), String(data.routeId)]); 213 [String(data.processId), String(data.routeId)]);
215 } 214 }
216 215
217 function terminate(data) { 216 function terminate(data) {
218 chrome.send('terminate', 217 chrome.send('terminate',
219 [String(data.processId), String(data.routeId)]); 218 [String(data.processId), String(data.routeId)]);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 var details = version['Browser'] || version['User-Agent']; 270 var details = version['Browser'] || version['User-Agent'];
272 sectionElement.textContent = device.model + ' (' + details + ')'; 271 sectionElement.textContent = device.model + ' (' + details + ')';
273 var listElement = document.createElement('div'); 272 var listElement = document.createElement('div');
274 listElement.id = 'device-' + device.serial; 273 listElement.id = 'device-' + device.serial;
275 listElement.className = 'list device'; 274 listElement.className = 'list device';
276 document.body.appendChild(sectionElement); 275 document.body.appendChild(sectionElement);
277 document.body.appendChild(listElement); 276 document.body.appendChild(listElement);
278 277
279 for (var j = 0; j < targets.length; j++) { 278 for (var j = 0; j < targets.length; j++) {
280 addTargetToList(targets[j], 'device-' + device.serial, 279 addTargetToList(targets[j], 'device-' + device.serial,
281 ['favicon_url', 'name', 'url']); 280 ['faviconUrl', 'name', 'url']);
282 } 281 }
283 } 282 }
284 setTimeout(populateDeviceLists, 1000); 283 setTimeout(populateDeviceLists, 1000);
285 } 284 }
286 285
287 function addToPagesList(data) { 286 function addToPagesList(data) {
288 addTargetToList(data, 'pages', ['favicon_url', 'name', 'url']); 287 addTargetToList(data, 'pages', ['faviconUrl', 'name', 'url']);
289 } 288 }
290 289
291 function addToExtensionsList(data) { 290 function addToExtensionsList(data) {
292 addTargetToList(data, 'extensions', ['name', 'url']); 291 addTargetToList(data, 'extensions', ['name', 'url']);
293 } 292 }
294 293
295 function addToWorkersList(data) { 294 function addToWorkersList(data) {
296 addTargetToList(data, 295 addTargetToList(data,
297 'workers', 296 'workers',
298 ['name', 'url', 'pid'], 297 ['name', 'url', 'pid'],
299 true); 298 true);
300 } 299 }
301 300
302 function addToOthersList(data) { 301 function addToOthersList(data) {
303 addTargetToList(data, 'others', ['url']); 302 addTargetToList(data, 'others', ['url']);
304 } 303 }
305 304
306 function formatValue(data, property) { 305 function formatValue(data, property) {
307 var value = data[property]; 306 var value = data[property];
308 307
309 if (property == 'favicon_url') { 308 if (property == 'faviconUrl') {
310 var faviconElement = document.createElement('img'); 309 var faviconElement = document.createElement('img');
311 if (value) 310 if (value)
312 faviconElement.src = value; 311 faviconElement.src = value;
313 return faviconElement; 312 return faviconElement;
314 } 313 }
315 314
316 var text = value ? String(value) : ''; 315 var text = value ? String(value) : '';
317 if (text.length > 100) 316 if (text.length > 100)
318 text = text.substring(0, 100) + '\u2026'; 317 text = text.substring(0, 100) + '\u2026';
319 318
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 link.setAttribute('href', '#'); 361 link.setAttribute('href', '#');
363 link.textContent = ' terminate '; 362 link.textContent = ' terminate ';
364 link.addEventListener( 363 link.addEventListener(
365 'click', 364 'click',
366 terminate.bind(this, data), 365 terminate.bind(this, data),
367 true); 366 true);
368 return link; 367 return link;
369 } 368 }
370 369
371 document.addEventListener('DOMContentLoaded', onload); 370 document.addEventListener('DOMContentLoaded', onload);
OLDNEW
« no previous file with comments | « chrome/browser/devtools/devtools_adb_bridge.cc ('k') | chrome/browser/ui/webui/inspect_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698