OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 /** |
| 6 * @typedef {{ |
| 7 * shortName: string, |
| 8 * packageName: string, |
| 9 * shellApkVersion: number, |
| 10 * versionCode: number |
| 11 * }} |
| 12 */ |
| 13 var WebApkInfo; |
| 14 |
| 15 /** |
| 16 * Creates and returns an element (with |text| as content) assigning it the |
| 17 * |className| class. |
| 18 * |
| 19 * @param {string} text Text to be shown in the span. |
| 20 * @param {string} className Class to be assigned to the new element. |
| 21 * @return {Element} The created element. |
| 22 */ |
| 23 function createSpanWithTextAndClass(text, className) { |
| 24 var element = createElementWithClassName('span', className); |
| 25 element.textContent = text; |
| 26 return element; |
| 27 } |
| 28 |
| 29 /** |
| 30 * Callback from the backend with the information of a WebAPK to display. |
| 31 * This will be called once for each WebAPK available on the device and each |
| 32 * one will be appended at the end of the other. |
| 33 * |
| 34 * @param {!Array<WebApkInfo>} webApkList List of objects with information about |
| 35 * WebAPKs installed. |
| 36 */ |
| 37 function returnWebApksInfo(webApkList) { |
| 38 for (let webApkInfo of webApkList) { |
| 39 addWebApk(webApkInfo); |
| 40 } |
| 41 } |
| 42 |
| 43 /** |
| 44 * Adds a new entry to the page with the information of a WebAPK. |
| 45 * |
| 46 * @param {WebApkInfo} webApkInfo Information about an installed WebAPK. |
| 47 */ |
| 48 function addWebApk(webApkInfo) { |
| 49 var webApkList = $('webapk-list'); |
| 50 |
| 51 webApkList.appendChild( |
| 52 createSpanWithTextAndClass(webApkInfo.shortName, 'app-name')); |
| 53 |
| 54 webApkList.appendChild( |
| 55 createSpanWithTextAndClass('Package name: ', 'app-property-label')); |
| 56 webApkList.appendChild(document.createTextNode(webApkInfo.packageName)); |
| 57 |
| 58 webApkList.appendChild(document.createElement('br')); |
| 59 webApkList.appendChild(createSpanWithTextAndClass( |
| 60 'Shell APK version: ', 'app-property-label')); |
| 61 webApkList.appendChild(document.createTextNode(webApkInfo.shellApkVersion)); |
| 62 |
| 63 webApkList.appendChild(document.createElement('br')); |
| 64 webApkList.appendChild( |
| 65 createSpanWithTextAndClass('Version code: ', 'app-property-label')); |
| 66 webApkList.appendChild(document.createTextNode(webApkInfo.versionCode)); |
| 67 } |
| 68 |
| 69 document.addEventListener('DOMContentLoaded', function() { |
| 70 chrome.send('requestWebApksInfo'); |
| 71 }); |
OLD | NEW |