aw_package_names_allowlist_component_installer_policy.cc 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Copyright 2021 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. #include "android_webview/nonembedded/component_updater/installer_policies/aw_package_names_allowlist_component_installer_policy.h"
  5. #include <cstdint>
  6. #include <memory>
  7. #include <string>
  8. #include <utility>
  9. #include <vector>
  10. #include "android_webview/common/components/aw_apps_package_names_allowlist_component_utils.h"
  11. #include "android_webview/nonembedded/component_updater/aw_component_installer_policy.h"
  12. #include "base/files/file_path.h"
  13. #include "base/files/file_util.h"
  14. #include "base/memory/ref_counted.h"
  15. #include "base/memory/scoped_refptr.h"
  16. #include "base/path_service.h"
  17. #include "base/values.h"
  18. #include "base/version.h"
  19. #include "components/component_updater/component_installer.h"
  20. #include "components/component_updater/component_updater_paths.h"
  21. namespace {
  22. const char kWebViewAppsPackageNamesAllowlistName[] =
  23. "WebViewAppsPackageNamesAllowlist";
  24. } // namespace
  25. namespace android_webview {
  26. AwPackageNamesAllowlistComponentInstallerPolicy::
  27. AwPackageNamesAllowlistComponentInstallerPolicy() = default;
  28. AwPackageNamesAllowlistComponentInstallerPolicy::
  29. ~AwPackageNamesAllowlistComponentInstallerPolicy() = default;
  30. update_client::CrxInstaller::Result
  31. AwPackageNamesAllowlistComponentInstallerPolicy::OnCustomInstall(
  32. const base::Value& manifest,
  33. const base::FilePath& install_dir) {
  34. // Nothing custom here.
  35. return update_client::CrxInstaller::Result(/* error = */ 0);
  36. }
  37. void RegisterWebViewAppsPackageNamesAllowlistComponent(
  38. base::OnceCallback<bool(const component_updater::ComponentRegistration&)>
  39. register_callback,
  40. base::OnceClosure registration_finished) {
  41. base::MakeRefCounted<component_updater::ComponentInstaller>(
  42. std::make_unique<AwPackageNamesAllowlistComponentInstallerPolicy>())
  43. ->Register(std::move(register_callback),
  44. std::move(registration_finished));
  45. }
  46. bool AwPackageNamesAllowlistComponentInstallerPolicy::
  47. SupportsGroupPolicyEnabledComponentUpdates() const {
  48. return true;
  49. }
  50. bool AwPackageNamesAllowlistComponentInstallerPolicy::
  51. RequiresNetworkEncryption() const {
  52. return false;
  53. }
  54. bool AwPackageNamesAllowlistComponentInstallerPolicy::VerifyInstallation(
  55. const base::Value& manifest,
  56. const base::FilePath& install_dir) const {
  57. return true;
  58. }
  59. base::FilePath
  60. AwPackageNamesAllowlistComponentInstallerPolicy::GetRelativeInstallDir() const {
  61. return base::FilePath(FILE_PATH_LITERAL("WebViewAppsPackageNamesAllowlist"));
  62. }
  63. void AwPackageNamesAllowlistComponentInstallerPolicy::GetHash(
  64. std::vector<uint8_t>* hash) const {
  65. GetWebViewAppsPackageNamesAllowlistPublicKeyHash(hash);
  66. }
  67. std::string AwPackageNamesAllowlistComponentInstallerPolicy::GetName() const {
  68. return kWebViewAppsPackageNamesAllowlistName;
  69. }
  70. update_client::InstallerAttributes
  71. AwPackageNamesAllowlistComponentInstallerPolicy::GetInstallerAttributes()
  72. const {
  73. return update_client::InstallerAttributes();
  74. }
  75. } // namespace android_webview