| 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 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 var WEBRTC_SERIAL = 'WEBRTC'; | 9 var WEBRTC_SERIAL = 'WEBRTC'; |
| 10 | 10 |
| 11 var queryParamsObject = {}; | 11 var queryParamsObject = {}; |
| 12 var browserInspector; |
| 13 var browserInspectorTitle; |
| 12 | 14 |
| 13 (function() { | 15 (function() { |
| 14 var queryParams = window.location.search; | 16 var queryParams = window.location.search; |
| 15 if (!queryParams) | 17 if (!queryParams) |
| 16 return; | 18 return; |
| 17 var params = queryParams.substring(1).split('&'); | 19 var params = queryParams.substring(1).split('&'); |
| 18 for (var i = 0; i < params.length; ++i) { | 20 for (var i = 0; i < params.length; ++i) { |
| 19 var pair = params[i].split('='); | 21 var pair = params[i].split('='); |
| 20 queryParamsObject[pair[0]] = pair[1]; | 22 queryParamsObject[pair[0]] = pair[1]; |
| 21 } | 23 } |
| 22 | 24 |
| 25 if ('trace' in queryParamsObject || 'tracing' in queryParamsObject) { |
| 26 browserInspector = 'chrome://tracing'; |
| 27 browserInspectorTitle = 'trace'; |
| 28 } else { |
| 29 browserInspector = queryParamsObject['browser-inspector']; |
| 30 browserInspectorTitle = 'inspect'; |
| 31 } |
| 23 })(); | 32 })(); |
| 24 | 33 |
| 25 function sendCommand(command, args) { | 34 function sendCommand(command, args) { |
| 26 chrome.send(command, Array.prototype.slice.call(arguments, 1)); | 35 chrome.send(command, Array.prototype.slice.call(arguments, 1)); |
| 27 } | 36 } |
| 28 | 37 |
| 29 function sendTargetCommand(command, target) { | 38 function sendTargetCommand(command, target) { |
| 30 sendCommand(command, target.source, target.id); | 39 sendCommand(command, target.source, target.id); |
| 31 } | 40 } |
| 32 | 41 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 } | 135 } |
| 127 | 136 |
| 128 function alreadyDisplayed(element, data) { | 137 function alreadyDisplayed(element, data) { |
| 129 var json = JSON.stringify(data); | 138 var json = JSON.stringify(data); |
| 130 if (element.cachedJSON == json) | 139 if (element.cachedJSON == json) |
| 131 return true; | 140 return true; |
| 132 element.cachedJSON = json; | 141 element.cachedJSON = json; |
| 133 return false; | 142 return false; |
| 134 } | 143 } |
| 135 | 144 |
| 145 function updateBrowserVisibility(browserSection) { |
| 146 var icon = browserSection.querySelector('.used-for-port-forwarding'); |
| 147 browserSection.hidden = !browserSection.querySelector('.open') && |
| 148 !browserSection.querySelector('.row') && |
| 149 !browserInspector && |
| 150 (!icon || icon.hidden); |
| 151 } |
| 152 |
| 136 function populateRemoteTargets(devices) { | 153 function populateRemoteTargets(devices) { |
| 137 if (!devices) | 154 if (!devices) |
| 138 return; | 155 return; |
| 139 | 156 |
| 140 if (window.modal) { | 157 if (window.modal) { |
| 141 window.holdDevices = devices; | 158 window.holdDevices = devices; |
| 142 return; | 159 return; |
| 143 } | 160 } |
| 144 | 161 |
| 145 function insertChildSortedById(parent, child) { | 162 function insertChildSortedById(parent, child) { |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 | 306 |
| 290 if (incompatibleVersion) { | 307 if (incompatibleVersion) { |
| 291 var warningSection = document.createElement('div'); | 308 var warningSection = document.createElement('div'); |
| 292 warningSection.className = 'warning'; | 309 warningSection.className = 'warning'; |
| 293 warningSection.textContent = | 310 warningSection.textContent = |
| 294 'You may need a newer version of desktop Chrome. ' + | 311 'You may need a newer version of desktop Chrome. ' + |
| 295 'Please try Chrome ' + browser.adbBrowserVersion + ' or later.'; | 312 'Please try Chrome ' + browser.adbBrowserVersion + ' or later.'; |
| 296 browserSection.appendChild(warningSection); | 313 browserSection.appendChild(warningSection); |
| 297 } | 314 } |
| 298 | 315 |
| 299 var browserInspector; | |
| 300 var browserInspectorTitle; | |
| 301 if ('trace' in queryParamsObject || 'tracing' in queryParamsObject) { | |
| 302 browserInspector = 'chrome://tracing'; | |
| 303 browserInspectorTitle = 'trace'; | |
| 304 } else { | |
| 305 browserInspector = queryParamsObject['browser-inspector']; | |
| 306 browserInspectorTitle = 'inspect'; | |
| 307 } | |
| 308 if (browserInspector) { | 316 if (browserInspector) { |
| 309 var link = document.createElement('span'); | 317 var link = document.createElement('span'); |
| 310 link.classList.add('action'); | 318 link.classList.add('action'); |
| 311 link.setAttribute('tabindex', 1); | 319 link.setAttribute('tabindex', 1); |
| 312 link.textContent = browserInspectorTitle; | 320 link.textContent = browserInspectorTitle; |
| 313 browserHeader.appendChild(link); | 321 browserHeader.appendChild(link); |
| 314 link.addEventListener( | 322 link.addEventListener( |
| 315 'click', | 323 'click', |
| 316 sendCommand.bind(null, 'inspect-browser', browser.source, | 324 sendCommand.bind(null, 'inspect-browser', browser.source, |
| 317 browser.id, browserInspector), false); | 325 browser.id, browserInspector), false); |
| 318 } | 326 } |
| 319 | 327 |
| 320 pageList = document.createElement('div'); | 328 pageList = document.createElement('div'); |
| 321 pageList.className = 'list pages'; | 329 pageList.className = 'list pages'; |
| 322 browserSection.appendChild(pageList); | 330 browserSection.appendChild(pageList); |
| 323 } | 331 } |
| 324 | 332 |
| 325 if (incompatibleVersion || alreadyDisplayed(browserSection, browser)) | 333 if (!incompatibleVersion && !alreadyDisplayed(browserSection, browser)) { |
| 326 continue; | 334 pageList.textContent = ''; |
| 327 | 335 for (var p = 0; p < browser.pages.length; p++) { |
| 328 pageList.textContent = ''; | 336 var page = browser.pages[p]; |
| 329 for (var p = 0; p < browser.pages.length; p++) { | 337 // Attached targets have no unique id until Chrome 26. For such |
| 330 var page = browser.pages[p]; | 338 // targets it is impossible to activate existing DevTools window. |
| 331 // Attached targets have no unique id until Chrome 26. For such targets | 339 page.hasNoUniqueId = page.attached && |
| 332 // it is impossible to activate existing DevTools window. | 340 majorChromeVersion && majorChromeVersion < MIN_VERSION_TARGET_ID; |
| 333 page.hasNoUniqueId = page.attached && | 341 var row = addTargetToList(page, pageList, ['name', 'url']); |
| 334 (majorChromeVersion && majorChromeVersion < MIN_VERSION_TARGET_ID); | 342 if (page['description']) |
| 335 var row = addTargetToList(page, pageList, ['name', 'url']); | 343 addWebViewDetails(row, page); |
| 336 if (page['description']) | 344 else |
| 337 addWebViewDetails(row, page); | 345 addFavicon(row, page); |
| 338 else | 346 if (majorChromeVersion >= MIN_VERSION_TAB_ACTIVATE) { |
| 339 addFavicon(row, page); | 347 addActionLink(row, 'focus tab', |
| 340 if (majorChromeVersion >= MIN_VERSION_TAB_ACTIVATE) { | 348 sendTargetCommand.bind(null, 'activate', page), false); |
| 341 addActionLink(row, 'focus tab', | 349 } |
| 342 sendTargetCommand.bind(null, 'activate', page), false); | 350 if (majorChromeVersion) { |
| 343 } | 351 addActionLink(row, 'reload', |
| 344 if (majorChromeVersion) { | 352 sendTargetCommand.bind(null, 'reload', page), page.attached); |
| 345 addActionLink(row, 'reload', | 353 } |
| 346 sendTargetCommand.bind(null, 'reload', page), page.attached); | 354 if (majorChromeVersion >= MIN_VERSION_TAB_CLOSE) { |
| 347 } | 355 addActionLink(row, 'close', |
| 348 if (majorChromeVersion >= MIN_VERSION_TAB_CLOSE) { | 356 sendTargetCommand.bind(null, 'close', page), false); |
| 349 addActionLink(row, 'close', | 357 } |
| 350 sendTargetCommand.bind(null, 'close', page), false); | |
| 351 } | 358 } |
| 352 } | 359 } |
| 360 updateBrowserVisibility(browserSection); |
| 353 } | 361 } |
| 354 } | 362 } |
| 355 } | 363 } |
| 356 | 364 |
| 357 function addToPagesList(data) { | 365 function addToPagesList(data) { |
| 358 var row = addTargetToList(data, $('pages-list'), ['name', 'url']); | 366 var row = addTargetToList(data, $('pages-list'), ['name', 'url']); |
| 359 addFavicon(row, data); | 367 addFavicon(row, data); |
| 360 if (data.guests) | 368 if (data.guests) |
| 361 addGuestViews(row, data.guests); | 369 addGuestViews(row, data.guests); |
| 362 } | 370 } |
| (...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 903 portNumber.textContent = ':' + port; | 911 portNumber.textContent = ':' + port; |
| 904 if (status > 0) | 912 if (status > 0) |
| 905 portNumber.textContent += '(' + status + ')'; | 913 portNumber.textContent += '(' + status + ')'; |
| 906 devicePorts.appendChild(portNumber); | 914 devicePorts.appendChild(portNumber); |
| 907 } | 915 } |
| 908 | 916 |
| 909 function updatePortForwardingInfo(browserSection) { | 917 function updatePortForwardingInfo(browserSection) { |
| 910 var icon = browserSection.querySelector('.used-for-port-forwarding'); | 918 var icon = browserSection.querySelector('.used-for-port-forwarding'); |
| 911 if (icon) | 919 if (icon) |
| 912 icon.hidden = (browserSection.id !== deviceStatus.browserId); | 920 icon.hidden = (browserSection.id !== deviceStatus.browserId); |
| 921 updateBrowserVisibility(browserSection); |
| 913 } | 922 } |
| 914 | 923 |
| 915 Array.prototype.forEach.call( | 924 Array.prototype.forEach.call( |
| 916 deviceSection.querySelectorAll('.browser'), updatePortForwardingInfo); | 925 deviceSection.querySelectorAll('.browser'), updatePortForwardingInfo); |
| 917 } | 926 } |
| 918 | 927 |
| 919 function clearPorts(deviceSection) { | 928 function clearPorts(deviceSection) { |
| 920 if (deviceSection.id in devicesStatusMap) | 929 if (deviceSection.id in devicesStatusMap) |
| 921 return; | 930 return; |
| 922 deviceSection.querySelector('.device-ports').textContent = ''; | 931 deviceSection.querySelector('.device-ports').textContent = ''; |
| 923 } | 932 } |
| 924 | 933 |
| 925 Array.prototype.forEach.call( | 934 Array.prototype.forEach.call( |
| 926 document.querySelectorAll('.device'), clearPorts); | 935 document.querySelectorAll('.device'), clearPorts); |
| 927 } | 936 } |
| 928 | 937 |
| 929 document.addEventListener('DOMContentLoaded', onload); | 938 document.addEventListener('DOMContentLoaded', onload); |
| 930 | 939 |
| 931 window.addEventListener('hashchange', onHashChange); | 940 window.addEventListener('hashchange', onHashChange); |
| OLD | NEW |