about_version.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. // Copyright (c) 2011 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. // Note: The handle* functions below are called internally on promise
  5. // resolution, unlike the other return* functions, which are called
  6. // asynchronously by the host.
  7. // <if expr="is_ios">
  8. import 'chrome://resources/js/ios/web_ui.js';
  9. // </if>
  10. import './strings.m.js';
  11. import {addWebUIListener, sendWithPromise} from 'chrome://resources/js/cr.m.js';
  12. import {$} from 'chrome://resources/js/util.m.js';
  13. /**
  14. * Promise resolution handler for variations list and command line equivalent.
  15. * @param {{variationsList: !Array<string>, variationsCmd: string=}}
  16. */
  17. function handleVariationInfo({variationsList, variationsCmd}) {
  18. $('variations-section').hidden = !variationsList.length;
  19. for (const item of variationsList) {
  20. $('variations-list').appendChild(document.createTextNode(item));
  21. $('variations-list').appendChild(document.createElement('br'));
  22. }
  23. if (variationsCmd) {
  24. $('variations-cmd-section').hidden = !variationsCmd;
  25. $('variations-cmd').textContent = variationsCmd;
  26. }
  27. }
  28. /**
  29. * Promise resolution handler for the executable and profile paths to display.
  30. * @param {string} execPath The executable path to display.
  31. * @param {string} profilePath The profile path to display.
  32. */
  33. function handlePathInfo({execPath, profilePath}) {
  34. $('executable_path').textContent = execPath;
  35. $('profile_path').textContent = profilePath;
  36. }
  37. // <if expr="chromeos_ash or is_win">
  38. /**
  39. * Callback from the backend with the OS version to display.
  40. * @param {string} osVersion The OS version to display.
  41. */
  42. function returnOsVersion(osVersion) {
  43. $('os_version').textContent = osVersion;
  44. }
  45. // </if>
  46. // <if expr="chromeos_ash">
  47. /**
  48. * Callback from the backend with the firmware version to display.
  49. * @param {string} firmwareVersion
  50. */
  51. function returnOsFirmwareVersion(firmwareVersion) {
  52. $('firmware_version').textContent = firmwareVersion;
  53. }
  54. /**
  55. * Callback from the backend with the ARC Android SDK version to display.
  56. * @param {string} arcAndroidSdkVersion The ARC Android SDK version to display,
  57. * already localized.
  58. */
  59. function returnArcAndArcAndroidSdkVersions(arcAndroidSdkVersion) {
  60. $('arc_holder').hidden = false;
  61. $('arc_and_arc_android_sdk_versions').textContent = arcAndroidSdkVersion;
  62. }
  63. /**
  64. * Callback from chromeosInfoPrivate with the value of the customization ID.
  65. * @param {!{customizationId: string}} response
  66. */
  67. function returnCustomizationId(response) {
  68. if (!response.customizationId) {
  69. return;
  70. }
  71. $('customization_id_holder').hidden = false;
  72. $('customization_id').textContent = response.customizationId;
  73. }
  74. // </if>
  75. // <if expr="is_chromeos">
  76. /**
  77. * Callback from the backend to inform if Lacros is primary or not.
  78. * @param {string} isPrimary True if it is primary.
  79. */
  80. function returnLacrosPrimary(isPrimary) {
  81. $('os-link-container').hidden = !isPrimary;
  82. const crosUrlRedirectButton = $('os-link-href');
  83. if (crosUrlRedirectButton) {
  84. crosUrlRedirectButton.onclick = crosUrlVersionRedirect;
  85. }
  86. }
  87. /**
  88. * Called when the user clicks on the os-link-href button.
  89. */
  90. function crosUrlVersionRedirect() {
  91. chrome.send('crosUrlVersionRedirect');
  92. }
  93. // </if>
  94. function copyToClipboard() {
  95. navigator.clipboard.writeText($('copy-content').innerText);
  96. }
  97. // <if expr="chromeos_lacros">
  98. function copyOSContentToClipboard() {
  99. navigator.clipboard.writeText($('copy-os-content').innerText);
  100. }
  101. // </if>
  102. /* All the work we do onload. */
  103. function onLoadWork() {
  104. // <if expr="chromeos_ash or is_win">
  105. addWebUIListener('return-os-version', returnOsVersion);
  106. // </if>
  107. // <if expr="chromeos_ash">
  108. addWebUIListener('return-os-firmware-version', returnOsFirmwareVersion);
  109. addWebUIListener(
  110. 'return-arc-and-arc-android-sdk-versions',
  111. returnArcAndArcAndroidSdkVersions);
  112. // </if>
  113. // <if expr="is_chromeos">
  114. addWebUIListener('return-lacros-primary', returnLacrosPrimary);
  115. // </if>
  116. chrome.send('requestVersionInfo');
  117. const includeVariationsCmd = location.search.includes('show-variations-cmd');
  118. sendWithPromise('requestVariationInfo', includeVariationsCmd)
  119. .then(handleVariationInfo);
  120. sendWithPromise('requestPathInfo').then(handlePathInfo);
  121. // <if expr="chromeos_ash">
  122. $('arc_holder').hidden = true;
  123. chrome.chromeosInfoPrivate.get(['customizationId'], returnCustomizationId);
  124. // </if>
  125. if ($('sanitizer').textContent !== '') {
  126. $('sanitizer-section').hidden = false;
  127. }
  128. $('copy-to-clipboard').addEventListener('click', copyToClipboard);
  129. // <if expr="chromeos_lacros">
  130. $('copy-os-content-to-clipboard')
  131. .addEventListener('click', copyOSContentToClipboard);
  132. // </if>
  133. }
  134. document.addEventListener('DOMContentLoaded', onLoadWork);