Chromium Code Reviews| 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. |
|
Dan Beam
2017/02/28 17:40:52
you need to add a @param for type
gonzalon
2017/02/28 17:56:50
Done.
| |
| 20 * @param {string} className Class to be assigned to the new element. | 29 * @param {string} className Class to be assigned to the new element. |
| 21 * @return {Element} The created element. | 30 * @return {Element} The created element. |
| 22 */ | 31 */ |
| 23 function createSpanWithTextAndClass(text, className) { | 32 function createElementWithTextAndClass(text, type, className) { |
| 24 var element = createElementWithClassName('span', className); | 33 var element = createElementWithClassName(type, className); |
| 25 element.textContent = text; | 34 element.textContent = text; |
| 26 return element; | 35 return element; |
| 27 } | 36 } |
| 28 | 37 |
| 29 /** | 38 /** |
| 30 * Callback from the backend with the information of a WebAPK to display. | 39 * 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 | 40 * 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. | 41 * one will be appended at the end of the other. |
| 33 * | 42 * |
| 34 * @param {!Array<WebApkInfo>} webApkList List of objects with information about | 43 * @param {!Array<WebApkInfo>} webApkList List of objects with information about |
| 35 * WebAPKs installed. | 44 * WebAPKs installed. |
| 36 */ | 45 */ |
| 37 function returnWebApksInfo(webApkList) { | 46 function returnWebApksInfo(webApkList) { |
| 38 for (let webApkInfo of webApkList) { | 47 for (let webApkInfo of webApkList) { |
| 39 addWebApk(webApkInfo); | 48 addWebApk(webApkInfo); |
| 40 } | 49 } |
| 41 } | 50 } |
| 42 | 51 |
| 43 /** | 52 /** |
| 53 * @param {!Array<Element>} webApkList List of elements which contain WebAPK | |
| 54 * attributes. | |
| 55 * @param {string} label Text that identifies the new element. | |
| 56 * @param {string} value Text to set in the new element. | |
| 57 */ | |
| 58 function addWebApkField(webApkList, label, value) { | |
| 59 divElement = createElementWithTextAndClass( | |
| 60 label, 'div', 'app-property-label'); | |
|
Dan Beam
2017/02/28 17:40:52
this indent is slightly off, maybe run `git cl for
gonzalon
2017/02/28 17:56:50
I didn't know the '--js' option existed, I was won
| |
| 61 divElement.appendChild( | |
| 62 createElementWithTextAndClass(value, 'span', 'app-property-value')); | |
| 63 webApkList.appendChild(divElement); | |
| 64 } | |
| 65 | |
| 66 /** | |
| 44 * Adds a new entry to the page with the information of a WebAPK. | 67 * Adds a new entry to the page with the information of a WebAPK. |
| 45 * | 68 * |
| 46 * @param {WebApkInfo} webApkInfo Information about an installed WebAPK. | 69 * @param {WebApkInfo} webApkInfo Information about an installed WebAPK. |
| 47 */ | 70 */ |
| 48 function addWebApk(webApkInfo) { | 71 function addWebApk(webApkInfo) { |
| 49 var webApkList = $('webapk-list'); | 72 var webApkList = $('webapk-list'); |
| 50 | 73 |
| 51 webApkList.appendChild( | 74 webApkList.appendChild( |
| 52 createSpanWithTextAndClass(webApkInfo.shortName, 'app-name')); | 75 createElementWithTextAndClass(webApkInfo.name, 'span', 'app-name')); |
| 53 | 76 |
| 54 webApkList.appendChild( | 77 webApkList.appendChild(createElementWithTextAndClass( |
| 55 createSpanWithTextAndClass('Package name: ', 'app-property-label')); | 78 'Short name: ', 'span', 'app-property-label')); |
| 56 webApkList.appendChild(document.createTextNode(webApkInfo.packageName)); | 79 webApkList.appendChild(document.createTextNode(webApkInfo.shortName)); |
| 57 | 80 |
| 58 webApkList.appendChild(document.createElement('br')); | 81 addWebApkField(webApkList, 'Package name: ', webApkInfo.packageName); |
| 59 webApkList.appendChild(createSpanWithTextAndClass( | 82 addWebApkField(webApkList, 'Shell APK version: ', webApkInfo.shellApkVersion); |
| 60 'Shell APK version: ', 'app-property-label')); | 83 addWebApkField(webApkList, 'Version code: ', webApkInfo.versionCode); |
| 61 webApkList.appendChild(document.createTextNode(webApkInfo.shellApkVersion)); | 84 addWebApkField(webApkList, 'URI: ', webApkInfo.uri); |
| 62 | 85 addWebApkField(webApkList, 'Scope: ', webApkInfo.scope); |
| 63 webApkList.appendChild(document.createElement('br')); | 86 addWebApkField(webApkList, 'Manifest URL: ', webApkInfo.manifestUrl); |
| 64 webApkList.appendChild( | 87 addWebApkField(webApkList, |
| 65 createSpanWithTextAndClass('Version code: ', 'app-property-label')); | 88 'Manifest Start URL: ', webApkInfo.manifestStartUrl); |
| 66 webApkList.appendChild(document.createTextNode(webApkInfo.versionCode)); | 89 addWebApkField(webApkList, 'Display Mode: ', webApkInfo.displayMode); |
| 90 addWebApkField(webApkList, 'Orientation: ', webApkInfo.orientation); | |
| 91 addWebApkField(webApkList, 'Theme color: ', webApkInfo.themeColor); | |
| 92 addWebApkField(webApkList, 'Background color: ', webApkInfo.backgroundColor); | |
| 67 } | 93 } |
| 68 | 94 |
| 69 document.addEventListener('DOMContentLoaded', function() { | 95 document.addEventListener('DOMContentLoaded', function() { |
| 70 chrome.send('requestWebApksInfo'); | 96 chrome.send('requestWebApksInfo'); |
| 71 }); | 97 }); |
| OLD | NEW |