Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / tools / test / reference_build / chrome_linux / resources / inspector / devices / DevicesView.js
1 WebInspector.DevicesView=function()
2 {WebInspector.VBox.call(this);this.registerRequiredCSS("devicesView.css");this.element.classList.add("devices");this._devicesHelp=this.element.createChild("div");this._devicesHelp.innerHTML=WebInspector.UIString("No devices detected. \
3         Please read the <a href=\"https://developers.google.com/chrome-developer\
4         -tools/docs/remote-debugging\"> remote debugging documentation</a> to \
5         verify your device is enabled for USB debugging.");this.element.createChild("div","devices-info").innerHTML=WebInspector.UIString("Click \"Try here\" button, to open the current page in the selected remote browser.");this._devicesList=this.element.createChild("div");this._devicesList.cellSpacing=0;};WebInspector.DevicesView.MinVersionNewTab=29;var Adb={};Adb.Browser;Adb.Device;WebInspector.DevicesView.Events={DevicesChanged:"DevicesChanged"};WebInspector.DevicesView.prototype={_onDevicesChanged:function(event)
6 {this._updateDeviceList((event.data));},_updateDeviceList:function(devices)
7 {function sanitizeForId(id)
8 {return id.replace(/[.:/\/ ]/g,"-");}
9 function alreadyDisplayed(element,data)
10 {var json=JSON.stringify(data);if(element.__cachedJSON===json)
11 return true;element.__cachedJSON=json;return false;}
12 function insertChildSortedById(parent,child)
13 {for(var sibling=parent.firstElementChild;sibling;sibling=sibling.nextElementSibling){if(sibling.id&&sibling.id>child.id){parent.insertBefore(child,sibling);return;}}
14 parent.appendChild(child);}
15 function removeObsolete(validIds,section)
16 {if(validIds.indexOf(section.id)<0)
17 section.remove();}
18 if(alreadyDisplayed(this._devicesList,devices))
19 return;var newDeviceIds=devices.map(function(device){return device.id;});Array.prototype.forEach.call(this._devicesList.querySelectorAll(".device"),removeObsolete.bind(null,newDeviceIds));this._devicesHelp.hidden=!!devices.length;for(var d=0;d<devices.length;d++){var device=devices[d];var deviceSection=this._devicesList.querySelector("#"+sanitizeForId(device.id));if(!deviceSection){deviceSection=this._devicesList.createChild("div","device");deviceSection.id=sanitizeForId(device.id);var deviceHeader=deviceSection.createChild("div","device-header");deviceHeader.createChild("div","device-name");var deviceSerial=deviceHeader.createChild("div","device-serial");deviceSerial.textContent="#"+device.adbSerial.toUpperCase();deviceSection.createChild("div","device-auth");}
20 if(alreadyDisplayed(deviceSection,device))
21 continue;deviceSection.querySelector(".device-name").textContent=device.adbModel;deviceSection.querySelector(".device-auth").textContent=device.adbConnected?"":WebInspector.UIString("Pending authentication: please accept debugging session on the device.");var browsers=device.browsers.filter(function(browser){return browser.adbBrowserChromeVersion;});var newBrowserIds=browsers.map(function(browser){return browser.id});Array.prototype.forEach.call(deviceSection.querySelectorAll(".browser"),removeObsolete.bind(null,newBrowserIds));for(var b=0;b<browsers.length;b++){var browser=browsers[b];var incompatibleVersion=browser.hasOwnProperty("compatibleVersion")&&!browser.compatibleVersion;var browserSection=deviceSection.querySelector("#"+sanitizeForId(browser.id));if(!browserSection){browserSection=document.createElementWithClass("div","browser");browserSection.id=sanitizeForId(browser.id);insertChildSortedById(deviceSection,browserSection);var browserName=browserSection.createChild("div","browser-name");browserName.textContent=browser.adbBrowserName;if(browser.adbBrowserVersion)
22 browserName.textContent+=" ("+browser.adbBrowserVersion+")";if(incompatibleVersion||browser.adbBrowserChromeVersion<WebInspector.DevicesView.MinVersionNewTab){var warningSection=browserSection.createChild("div","warning");warningSection.textContent=incompatibleVersion?WebInspector.UIString("You may need a newer version of desktop Chrome. Please try Chrome %s  or later.",browser.adbBrowserVersion):WebInspector.UIString("You may need a newer version of Chrome on your device. Please try Chrome %s or later.",WebInspector.DevicesView.MinVersionNewTab);}else{var newPageButton=browserSection.createChild("button","settings-tab-text-button");newPageButton.textContent=WebInspector.UIString("Try here");newPageButton.title=WebInspector.UIString("Inspect current page in this browser.");newPageButton.addEventListener("click",InspectorFrontendHost.openUrlOnRemoteDeviceAndInspect.bind(null,browser.id,WebInspector.resourceTreeModel.inspectedPageURL()),true);}}}}},willHide:function()
23 {WebInspector.inspectorFrontendEventSink.removeEventListener(WebInspector.DevicesView.Events.DevicesChanged,this._onDevicesChanged,this);},wasShown:function()
24 {WebInspector.inspectorFrontendEventSink.addEventListener(WebInspector.DevicesView.Events.DevicesChanged,this._onDevicesChanged,this);},__proto__:WebInspector.VBox.prototype};