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

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

Issue 22536006: chrome://inspect: Better support for multiple browsers and older versions of mobile Chrome (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]);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 return; 89 return;
90 90
91 function alreadyDisplayed(element, data) { 91 function alreadyDisplayed(element, data) {
92 var json = JSON.stringify(data); 92 var json = JSON.stringify(data);
93 if (element.cachedJSON == json) 93 if (element.cachedJSON == json)
94 return true; 94 return true;
95 element.cachedJSON = json; 95 element.cachedJSON = json;
96 return false; 96 return false;
97 } 97 }
98 98
99 function insertChildSortedById(parent, child) {
100 for (var sibling = parent.firstElementChild;
101 sibling;
102 sibling = sibling.nextElementSibling) {
103 if (sibling.id > child.id) {
104 parent.insertBefore(child, sibling);
105 return;
106 }
107 }
108 parent.appendChild(child);
109 }
110
99 var deviceList = $('devices'); 111 var deviceList = $('devices');
100 if (alreadyDisplayed(deviceList, devices)) 112 if (alreadyDisplayed(deviceList, devices))
101 return; 113 return;
102 114
103 function removeObsolete(validIds, section) { 115 function removeObsolete(validIds, section) {
104 if (validIds.indexOf(section.id) < 0) 116 if (validIds.indexOf(section.id) < 0)
105 section.remove(); 117 section.remove();
106 } 118 }
107 119
108 var newDeviceIds = devices.map(function(d) { return d.adbGlobalId }); 120 var newDeviceIds = devices.map(function(d) { return d.adbGlobalId });
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 190
179 var newBrowserIds = 191 var newBrowserIds =
180 device.browsers.map(function(b) { return b.adbGlobalId }); 192 device.browsers.map(function(b) { return b.adbGlobalId });
181 Array.prototype.forEach.call( 193 Array.prototype.forEach.call(
182 browserList.querySelectorAll('.browser'), 194 browserList.querySelectorAll('.browser'),
183 removeObsolete.bind(null, newBrowserIds)); 195 removeObsolete.bind(null, newBrowserIds));
184 196
185 for (var b = 0; b < device.browsers.length; b++) { 197 for (var b = 0; b < device.browsers.length; b++) {
186 var browser = device.browsers[b]; 198 var browser = device.browsers[b];
187 199
200 var isChrome =
201 browser.adbBrowserName && browser.adbBrowserName.match(/^Chrome/);
202
188 var pageList; 203 var pageList;
189 var browserSection = $(browser.adbGlobalId); 204 var browserSection = $(browser.adbGlobalId);
190 if (browserSection) { 205 if (browserSection) {
191 pageList = browserSection.querySelector('.pages'); 206 pageList = browserSection.querySelector('.pages');
192 } else { 207 } else {
193 browserSection = document.createElement('div'); 208 browserSection = document.createElement('div');
194 browserSection.id = browser.adbGlobalId; 209 browserSection.id = browser.adbGlobalId;
195 browserSection.className = 'browser'; 210 browserSection.className = 'browser';
196 browserList.appendChild(browserSection); 211 insertChildSortedById(browserList, browserSection);
197 212
198 var browserHeader = document.createElement('div'); 213 var browserHeader = document.createElement('div');
199 browserHeader.className = 'browser-header'; 214 browserHeader.className = 'browser-header';
200 browserHeader.textContent = browser.adbBrowserName; 215 browserHeader.textContent = browser.adbBrowserName;
216 var majorChromeVersion = 0;
217 if (browser.adbBrowserVersion) {
218 browserHeader.textContent += ' (' + browser.adbBrowserVersion + ')';
219 var match = browser.adbBrowserVersion.match(/^Chrome\/(\d+)\./);
220 if (match)
221 majorChromeVersion = parseInt(match[1]);
222 }
201 browserSection.appendChild(browserHeader); 223 browserSection.appendChild(browserHeader);
202 224
203 var newPage = document.createElement('div'); 225 if (isChrome && majorChromeVersion >= 29) {
204 newPage.className = 'open'; 226 var newPage = document.createElement('div');
227 newPage.className = 'open';
205 228
206 var newPageUrl = document.createElement('input'); 229 var newPageUrl = document.createElement('input');
207 newPageUrl.type = 'text'; 230 newPageUrl.type = 'text';
208 newPageUrl.placeholder = 'Open tab with url'; 231 newPageUrl.placeholder = 'Open tab with url';
209 newPage.appendChild(newPageUrl); 232 newPage.appendChild(newPageUrl);
210 233
211 var openHandler = function(browserId, input) { 234 var openHandler = function(browserId, input) {
212 open(browserId, input.value || 'about:blank'); 235 open(browserId, input.value || 'about:blank');
213 input.value = ''; 236 input.value = '';
214 }.bind(null, browser.adbGlobalId, newPageUrl); 237 }.bind(null, browser.adbGlobalId, newPageUrl);
215 newPageUrl.addEventListener('keyup', function(handler, event) { 238 newPageUrl.addEventListener('keyup', function(handler, event) {
216 if (event.keyIdentifier == 'Enter' && event.target.value) 239 if (event.keyIdentifier == 'Enter' && event.target.value)
217 handler(); 240 handler();
218 }.bind(null, openHandler), true); 241 }.bind(null, openHandler), true);
219 242
220 var newPageButton = document.createElement('button'); 243 var newPageButton = document.createElement('button');
221 newPageButton.textContent = 'Open'; 244 newPageButton.textContent = 'Open';
222 newPage.appendChild(newPageButton); 245 newPage.appendChild(newPageButton);
223 newPageButton.addEventListener('click', openHandler, true); 246 newPageButton.addEventListener('click', openHandler, true);
224 247
225 browserSection.appendChild(newPage); 248 browserSection.appendChild(newPage);
249 }
226 250
227 pageList = document.createElement('div'); 251 pageList = document.createElement('div');
228 pageList.className = 'list pages'; 252 pageList.className = 'list pages';
229 browserSection.appendChild(pageList); 253 browserSection.appendChild(pageList);
230 } 254 }
231 255
232 if (alreadyDisplayed(browserSection, browser)) 256 if (alreadyDisplayed(browserSection, browser))
233 continue; 257 continue;
234 258
235 pageList.textContent = ''; 259 pageList.textContent = '';
236 for (var p = 0; p < browser.pages.length; p++) { 260 for (var p = 0; p < browser.pages.length; p++) {
237 var page = browser.pages[p]; 261 var page = browser.pages[p];
238 var row = addTargetToList( 262 var row = addTargetToList(
239 page, pageList, ['faviconUrl', 'name', 'url']); 263 page, pageList, ['faviconUrl', 'name', 'url']);
240 row.appendChild(createActionLink( 264 if (isChrome) {
241 'reload', reload.bind(null, page), page.attached)); 265 row.appendChild(createActionLink(
242 row.appendChild(createActionLink( 266 'reload', reload.bind(null, page), page.attached));
243 'close', terminate.bind(null, page), page.attached)); 267 row.appendChild(createActionLink(
268 'close', terminate.bind(null, page), page.attached));
269 }
244 } 270 }
245 } 271 }
246 } 272 }
247 } 273 }
248 274
249 function addToPagesList(data) { 275 function addToPagesList(data) {
250 addTargetToList(data, $('pages'), ['faviconUrl', 'name', 'url']); 276 addTargetToList(data, $('pages'), ['faviconUrl', 'name', 'url']);
251 } 277 }
252 278
253 function addToExtensionsList(data) { 279 function addToExtensionsList(data) {
(...skipping 10 matching lines...) Expand all
264 'terminate', terminate.bind(null, data), data.attached)); 290 'terminate', terminate.bind(null, data), data.attached));
265 } 291 }
266 292
267 function addToOthersList(data) { 293 function addToOthersList(data) {
268 addTargetToList(data, $('others'), ['url']); 294 addTargetToList(data, $('others'), ['url']);
269 } 295 }
270 296
271 function formatValue(data, property) { 297 function formatValue(data, property) {
272 var value = data[property]; 298 var value = data[property];
273 299
300 if (property == 'name' && value == '') {
301 value = 'untitled';
302 }
303
274 if (property == 'faviconUrl') { 304 if (property == 'faviconUrl') {
275 var faviconElement = document.createElement('img'); 305 var faviconElement = document.createElement('img');
276 if (value) 306 if (value)
277 faviconElement.src = value; 307 faviconElement.src = value;
278 return faviconElement; 308 return faviconElement;
279 } 309 }
280 310
281 var text = value ? String(value) : ''; 311 var text = value ? String(value) : '';
282 if (text.length > 100) 312 if (text.length > 100)
283 text = text.substring(0, 100) + '\u2026'; 313 text = text.substring(0, 100) + '\u2026';
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 if (line.querySelector('.invalid')) 574 if (line.querySelector('.invalid'))
545 return; 575 return;
546 line.classList.remove('fresh'); 576 line.classList.remove('fresh');
547 var freshLine = createEmptyConfigLine(); 577 var freshLine = createEmptyConfigLine();
548 line.parentNode.appendChild(freshLine); 578 line.parentNode.appendChild(freshLine);
549 if (opt_selectNew) 579 if (opt_selectNew)
550 freshLine.querySelector('.port').focus(); 580 freshLine.querySelector('.port').focus();
551 } 581 }
552 582
553 document.addEventListener('DOMContentLoaded', onload); 583 document.addEventListener('DOMContentLoaded', onload);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698