origin_trials_component_installer.cc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Copyright 2016 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 "components/component_updater/installer_policies/origin_trials_component_installer.h"
  5. #include <iterator>
  6. #include <utility>
  7. #include <vector>
  8. #include "base/bind.h"
  9. #include "base/callback.h"
  10. #include "base/command_line.h"
  11. #include "base/files/file_path.h"
  12. #include "base/memory/ref_counted.h"
  13. #include "base/path_service.h"
  14. #include "base/values.h"
  15. #include "components/component_updater/component_updater_paths.h"
  16. // The client-side configuration for the origin trial framework can be
  17. // overridden by an installed component named 'OriginTrials' (extension id
  18. // llkgjffcdpffmhiakmfcdcblohccpfmo. This component currently consists of just a
  19. // manifest.json file, which can contain a custom key named 'origin-trials'. The
  20. // value of this key is a dictionary:
  21. //
  22. // {
  23. // "public-key": "<base64-encoding of replacement public key>",
  24. // "disabled-features": [<list of features to disable>],
  25. // "disabled-tokens":
  26. // {
  27. // "signatures": [<list of token signatures to disable, base64-encoded>]
  28. // }
  29. // }
  30. //
  31. // If the component is not present in the user data directory, the default
  32. // configuration will be used.
  33. namespace component_updater {
  34. namespace {
  35. static const char kManifestOriginTrialsKey[] = "origin-trials";
  36. // Extension id is llkgjffcdpffmhiakmfcdcblohccpfmo
  37. const uint8_t kOriginTrialSha2Hash[] = {
  38. 0xbb, 0xa6, 0x95, 0x52, 0x3f, 0x55, 0xc7, 0x80, 0xac, 0x52, 0x32,
  39. 0x1b, 0xe7, 0x22, 0xf5, 0xce, 0x6a, 0xfd, 0x9c, 0x9e, 0xa9, 0x2a,
  40. 0x0b, 0x50, 0x60, 0x2b, 0x7f, 0x6c, 0x64, 0x80, 0x09, 0x04};
  41. } // namespace
  42. // static
  43. void OriginTrialsComponentInstallerPolicy::GetComponentHash(
  44. std::vector<uint8_t>* hash) {
  45. if (!hash)
  46. return;
  47. hash->assign(std::begin(kOriginTrialSha2Hash),
  48. std::end(kOriginTrialSha2Hash));
  49. }
  50. void OriginTrialsComponentInstallerPolicy::GetHash(
  51. std::vector<uint8_t>* hash) const {
  52. GetComponentHash(hash);
  53. }
  54. bool OriginTrialsComponentInstallerPolicy::VerifyInstallation(
  55. const base::Value& manifest,
  56. const base::FilePath& install_dir) const {
  57. // Test if the "origin-trials" key is present in the manifest.
  58. return !!manifest.FindKey(kManifestOriginTrialsKey);
  59. }
  60. bool OriginTrialsComponentInstallerPolicy::
  61. SupportsGroupPolicyEnabledComponentUpdates() const {
  62. return true;
  63. }
  64. bool OriginTrialsComponentInstallerPolicy::RequiresNetworkEncryption() const {
  65. return false;
  66. }
  67. update_client::CrxInstaller::Result
  68. OriginTrialsComponentInstallerPolicy::OnCustomInstall(
  69. const base::Value& manifest,
  70. const base::FilePath& install_dir) {
  71. return update_client::CrxInstaller::Result(0);
  72. }
  73. void OriginTrialsComponentInstallerPolicy::OnCustomUninstall() {}
  74. void OriginTrialsComponentInstallerPolicy::ComponentReady(
  75. const base::Version& version,
  76. const base::FilePath& install_dir,
  77. base::Value manifest) {}
  78. base::FilePath OriginTrialsComponentInstallerPolicy::GetRelativeInstallDir()
  79. const {
  80. return base::FilePath(FILE_PATH_LITERAL("OriginTrials"));
  81. }
  82. std::string OriginTrialsComponentInstallerPolicy::GetName() const {
  83. return "Origin Trials";
  84. }
  85. update_client::InstallerAttributes
  86. OriginTrialsComponentInstallerPolicy::GetInstallerAttributes() const {
  87. return update_client::InstallerAttributes();
  88. }
  89. } // namespace component_updater