| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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 /** | 5 /** |
| 6 * @typedef {{ | 6 * @typedef {{ |
| 7 * name: string, |
| 7 * shortName: string, | 8 * shortName: string, |
| 8 * packageName: string, | 9 * packageName: string, |
| 9 * shellApkVersion: number, | 10 * shellApkVersion: number, |
| 10 * versionCode: number | 11 * versionCode: number, |
| 12 * uri: string, |
| 13 * scope: string, |
| 14 * manifestUrl: string, |
| 15 * manifestStartUrl: string, |
| 16 * displayMode: string, |
| 17 * orientation: string, |
| 18 * themeColor: string, |
| 19 * backgroundColor: string, |
| 11 * }} | 20 * }} |
| 12 */ | 21 */ |
| 13 var WebApkInfo; | 22 var WebApkInfo; |
| 14 | 23 |
| 15 /** | 24 /** |
| 16 * Creates and returns an element (with |text| as content) assigning it the | 25 * Creates and returns an element (with |text| as content) assigning it the |
| 17 * |className| class. | 26 * |className| class. |
| 18 * | 27 * |
| 19 * @param {string} text Text to be shown in the span. | 28 * @param {string} text Text to be shown in the span. |
| 29 * @param {string} type Type of element to be added such as 'div'. |
| 20 * @param {string} className Class to be assigned to the new element. | 30 * @param {string} className Class to be assigned to the new element. |
| 21 * @return {Element} The created element. | 31 * @return {Element} The created element. |
| 22 */ | 32 */ |
| 23 function createSpanWithTextAndClass(text, className) { | 33 function createElementWithTextAndClass(text, type, className) { |
| 24 var element = createElementWithClassName('span', className); | 34 var element = createElementWithClassName(type, className); |
| 25 element.textContent = text; | 35 element.textContent = text; |
| 26 return element; | 36 return element; |
| 27 } | 37 } |
| 28 | 38 |
| 29 /** | 39 /** |
| 30 * Callback from the backend with the information of a WebAPK to display. | 40 * 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 | 41 * 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. | 42 * one will be appended at the end of the other. |
| 33 * | 43 * |
| 34 * @param {!Array<WebApkInfo>} webApkList List of objects with information about | 44 * @param {!Array<WebApkInfo>} webApkList List of objects with information about |
| 35 * WebAPKs installed. | 45 * WebAPKs installed. |
| 36 */ | 46 */ |
| 37 function returnWebApksInfo(webApkList) { | 47 function returnWebApksInfo(webApkList) { |
| 38 for (let webApkInfo of webApkList) { | 48 for (let webApkInfo of webApkList) { |
| 39 addWebApk(webApkInfo); | 49 addWebApk(webApkInfo); |
| 40 } | 50 } |
| 41 } | 51 } |
| 42 | 52 |
| 43 /** | 53 /** |
| 54 * @param {HTMLElement} webApkList List of elements which contain WebAPK |
| 55 * attributes. |
| 56 * @param {string} label Text that identifies the new element. |
| 57 * @param {string} value Text to set in the new element. |
| 58 */ |
| 59 function addWebApkField(webApkList, label, value) { |
| 60 var divElement = |
| 61 createElementWithTextAndClass(label, 'div', 'app-property-label'); |
| 62 divElement.appendChild( |
| 63 createElementWithTextAndClass(value, 'span', 'app-property-value')); |
| 64 webApkList.appendChild(divElement); |
| 65 } |
| 66 |
| 67 /** |
| 44 * Adds a new entry to the page with the information of a WebAPK. | 68 * Adds a new entry to the page with the information of a WebAPK. |
| 45 * | 69 * |
| 46 * @param {WebApkInfo} webApkInfo Information about an installed WebAPK. | 70 * @param {WebApkInfo} webApkInfo Information about an installed WebAPK. |
| 47 */ | 71 */ |
| 48 function addWebApk(webApkInfo) { | 72 function addWebApk(webApkInfo) { |
| 49 var webApkList = $('webapk-list'); | 73 /** @type {HTMLElement} */ var webApkList = $('webapk-list'); |
| 50 | 74 |
| 51 webApkList.appendChild( | 75 webApkList.appendChild( |
| 52 createSpanWithTextAndClass(webApkInfo.shortName, 'app-name')); | 76 createElementWithTextAndClass(webApkInfo.name, 'span', 'app-name')); |
| 53 | 77 |
| 54 webApkList.appendChild( | 78 webApkList.appendChild(createElementWithTextAndClass( |
| 55 createSpanWithTextAndClass('Package name: ', 'app-property-label')); | 79 'Short name: ', 'span', 'app-property-label')); |
| 56 webApkList.appendChild(document.createTextNode(webApkInfo.packageName)); | 80 webApkList.appendChild(document.createTextNode(webApkInfo.shortName)); |
| 57 | 81 |
| 58 webApkList.appendChild(document.createElement('br')); | 82 addWebApkField(webApkList, 'Package name: ', webApkInfo.packageName); |
| 59 webApkList.appendChild(createSpanWithTextAndClass( | 83 addWebApkField( |
| 60 'Shell APK version: ', 'app-property-label')); | 84 webApkList, 'Shell APK version: ', "" + webApkInfo.shellApkVersion); |
| 61 webApkList.appendChild(document.createTextNode(webApkInfo.shellApkVersion)); | 85 addWebApkField(webApkList, 'Version code: ', "" + webApkInfo.versionCode); |
| 62 | 86 addWebApkField(webApkList, 'URI: ', webApkInfo.uri); |
| 63 webApkList.appendChild(document.createElement('br')); | 87 addWebApkField(webApkList, 'Scope: ', webApkInfo.scope); |
| 64 webApkList.appendChild( | 88 addWebApkField(webApkList, 'Manifest URL: ', webApkInfo.manifestUrl); |
| 65 createSpanWithTextAndClass('Version code: ', 'app-property-label')); | 89 addWebApkField( |
| 66 webApkList.appendChild(document.createTextNode(webApkInfo.versionCode)); | 90 webApkList, 'Manifest Start URL: ', webApkInfo.manifestStartUrl); |
| 91 addWebApkField(webApkList, 'Display Mode: ', webApkInfo.displayMode); |
| 92 addWebApkField(webApkList, 'Orientation: ', webApkInfo.orientation); |
| 93 addWebApkField(webApkList, 'Theme color: ', webApkInfo.themeColor); |
| 94 addWebApkField(webApkList, 'Background color: ', webApkInfo.backgroundColor); |
| 67 } | 95 } |
| 68 | 96 |
| 69 document.addEventListener('DOMContentLoaded', function() { | 97 document.addEventListener('DOMContentLoaded', function() { |
| 70 chrome.send('requestWebApksInfo'); | 98 chrome.send('requestWebApksInfo'); |
| 71 }); | 99 }); |
| OLD | NEW |