| 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 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 Loading... |
| 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 Loading... |
| 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 = browser.adbBrowserProduct && |
| 201 browser.adbBrowserProduct.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.adbBrowserProduct; |
| 216 var majorChromeVersion = 0; |
| 217 if (browser.adbBrowserVersion) { |
| 218 browserHeader.textContent += ' (' + browser.adbBrowserVersion + ')'; |
| 219 if (isChrome) { |
| 220 var match = browser.adbBrowserVersion.match(/^(\d+)/); |
| 221 if (match) |
| 222 majorChromeVersion = parseInt(match[1]); |
| 223 } |
| 224 } |
| 201 browserSection.appendChild(browserHeader); | 225 browserSection.appendChild(browserHeader); |
| 202 | 226 |
| 203 var newPage = document.createElement('div'); | 227 if (majorChromeVersion >= 29) { |
| 204 newPage.className = 'open'; | 228 var newPage = document.createElement('div'); |
| 229 newPage.className = 'open'; |
| 205 | 230 |
| 206 var newPageUrl = document.createElement('input'); | 231 var newPageUrl = document.createElement('input'); |
| 207 newPageUrl.type = 'text'; | 232 newPageUrl.type = 'text'; |
| 208 newPageUrl.placeholder = 'Open tab with url'; | 233 newPageUrl.placeholder = 'Open tab with url'; |
| 209 newPage.appendChild(newPageUrl); | 234 newPage.appendChild(newPageUrl); |
| 210 | 235 |
| 211 var openHandler = function(browserId, input) { | 236 var openHandler = function(browserId, input) { |
| 212 open(browserId, input.value || 'about:blank'); | 237 open(browserId, input.value || 'about:blank'); |
| 213 input.value = ''; | 238 input.value = ''; |
| 214 }.bind(null, browser.adbGlobalId, newPageUrl); | 239 }.bind(null, browser.adbGlobalId, newPageUrl); |
| 215 newPageUrl.addEventListener('keyup', function(handler, event) { | 240 newPageUrl.addEventListener('keyup', function(handler, event) { |
| 216 if (event.keyIdentifier == 'Enter' && event.target.value) | 241 if (event.keyIdentifier == 'Enter' && event.target.value) |
| 217 handler(); | 242 handler(); |
| 218 }.bind(null, openHandler), true); | 243 }.bind(null, openHandler), true); |
| 219 | 244 |
| 220 var newPageButton = document.createElement('button'); | 245 var newPageButton = document.createElement('button'); |
| 221 newPageButton.textContent = 'Open'; | 246 newPageButton.textContent = 'Open'; |
| 222 newPage.appendChild(newPageButton); | 247 newPage.appendChild(newPageButton); |
| 223 newPageButton.addEventListener('click', openHandler, true); | 248 newPageButton.addEventListener('click', openHandler, true); |
| 224 | 249 |
| 225 browserSection.appendChild(newPage); | 250 browserSection.appendChild(newPage); |
| 251 } |
| 226 | 252 |
| 227 pageList = document.createElement('div'); | 253 pageList = document.createElement('div'); |
| 228 pageList.className = 'list pages'; | 254 pageList.className = 'list pages'; |
| 229 browserSection.appendChild(pageList); | 255 browserSection.appendChild(pageList); |
| 230 } | 256 } |
| 231 | 257 |
| 232 if (alreadyDisplayed(browserSection, browser)) | 258 if (alreadyDisplayed(browserSection, browser)) |
| 233 continue; | 259 continue; |
| 234 | 260 |
| 235 pageList.textContent = ''; | 261 pageList.textContent = ''; |
| 236 for (var p = 0; p < browser.pages.length; p++) { | 262 for (var p = 0; p < browser.pages.length; p++) { |
| 237 var page = browser.pages[p]; | 263 var page = browser.pages[p]; |
| 238 var row = addTargetToList( | 264 var row = addTargetToList( |
| 239 page, pageList, ['faviconUrl', 'name', 'url']); | 265 page, pageList, ['faviconUrl', 'name', 'url']); |
| 240 row.appendChild(createActionLink( | 266 if (isChrome) { |
| 241 'reload', reload.bind(null, page), page.attached)); | 267 row.appendChild(createActionLink( |
| 242 row.appendChild(createActionLink( | 268 'reload', reload.bind(null, page), page.attached)); |
| 243 'close', terminate.bind(null, page), page.attached)); | 269 row.appendChild(createActionLink( |
| 270 'close', terminate.bind(null, page), page.attached)); |
| 271 } |
| 244 } | 272 } |
| 245 } | 273 } |
| 246 } | 274 } |
| 247 } | 275 } |
| 248 | 276 |
| 249 function addToPagesList(data) { | 277 function addToPagesList(data) { |
| 250 addTargetToList(data, $('pages'), ['faviconUrl', 'name', 'url']); | 278 addTargetToList(data, $('pages'), ['faviconUrl', 'name', 'url']); |
| 251 } | 279 } |
| 252 | 280 |
| 253 function addToExtensionsList(data) { | 281 function addToExtensionsList(data) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 264 'terminate', terminate.bind(null, data), data.attached)); | 292 'terminate', terminate.bind(null, data), data.attached)); |
| 265 } | 293 } |
| 266 | 294 |
| 267 function addToOthersList(data) { | 295 function addToOthersList(data) { |
| 268 addTargetToList(data, $('others'), ['url']); | 296 addTargetToList(data, $('others'), ['url']); |
| 269 } | 297 } |
| 270 | 298 |
| 271 function formatValue(data, property) { | 299 function formatValue(data, property) { |
| 272 var value = data[property]; | 300 var value = data[property]; |
| 273 | 301 |
| 302 if (property == 'name' && value == '') { |
| 303 value = 'untitled'; |
| 304 } |
| 305 |
| 274 if (property == 'faviconUrl') { | 306 if (property == 'faviconUrl') { |
| 275 var faviconElement = document.createElement('img'); | 307 var faviconElement = document.createElement('img'); |
| 276 if (value) | 308 if (value) |
| 277 faviconElement.src = value; | 309 faviconElement.src = value; |
| 278 return faviconElement; | 310 return faviconElement; |
| 279 } | 311 } |
| 280 | 312 |
| 281 var text = value ? String(value) : ''; | 313 var text = value ? String(value) : ''; |
| 282 if (text.length > 100) | 314 if (text.length > 100) |
| 283 text = text.substring(0, 100) + '\u2026'; | 315 text = text.substring(0, 100) + '\u2026'; |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 if (line.querySelector('.invalid')) | 576 if (line.querySelector('.invalid')) |
| 545 return; | 577 return; |
| 546 line.classList.remove('fresh'); | 578 line.classList.remove('fresh'); |
| 547 var freshLine = createEmptyConfigLine(); | 579 var freshLine = createEmptyConfigLine(); |
| 548 line.parentNode.appendChild(freshLine); | 580 line.parentNode.appendChild(freshLine); |
| 549 if (opt_selectNew) | 581 if (opt_selectNew) |
| 550 freshLine.querySelector('.port').focus(); | 582 freshLine.querySelector('.port').focus(); |
| 551 } | 583 } |
| 552 | 584 |
| 553 document.addEventListener('DOMContentLoaded', onload); | 585 document.addEventListener('DOMContentLoaded', onload); |
| OLD | NEW |