empty_component_loader_policy.cc 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2022 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/browser/component_updater/loader_policies/empty_component_loader_policy.h"
  5. #include <stdint.h>
  6. #include <memory>
  7. #include <string>
  8. #include <utility>
  9. #include <vector>
  10. #include "android_webview/common/aw_features.h"
  11. #include "base/containers/flat_map.h"
  12. #include "base/feature_list.h"
  13. #include "base/files/scoped_file.h"
  14. #include "base/values.h"
  15. #include "base/version.h"
  16. #include "components/component_updater/android/component_loader_policy.h"
  17. namespace android_webview {
  18. namespace {
  19. // Persisted to logs, should never change.
  20. constexpr char kEmptyComponentLoaderPolicyMetricsSuffix[] =
  21. "WebViewEmptyComponent";
  22. // A fake SHA256 PublicKey of jebgalgnebhfojomionfpkfelancnnkf
  23. const uint8_t kFakePublicKeySHA256[32] = {
  24. 0x94, 0x16, 0x0b, 0x6d, 0x41, 0x75, 0xe9, 0xec, 0x8e, 0xd5, 0xfa,
  25. 0x54, 0xb0, 0xd2, 0xdd, 0xa5, 0x6e, 0x05, 0x6b, 0xe8, 0x73, 0x47,
  26. 0xf6, 0xc4, 0x11, 0x9f, 0xbc, 0xb3, 0x09, 0xb3, 0x5b, 0x40};
  27. } // namespace
  28. void EmptyComponentLoaderPolicy::ComponentLoaded(
  29. const base::Version& /*version*/,
  30. base::flat_map<std::string, base::ScopedFD>& /*fd_map*/,
  31. std::unique_ptr<base::DictionaryValue> /*manifest*/) {}
  32. void EmptyComponentLoaderPolicy::ComponentLoadFailed(
  33. component_updater::ComponentLoadResult /*error*/) {}
  34. void EmptyComponentLoaderPolicy::GetHash(std::vector<uint8_t>* hash) const {
  35. hash->assign(kFakePublicKeySHA256,
  36. kFakePublicKeySHA256 + std::size(kFakePublicKeySHA256));
  37. }
  38. std::string EmptyComponentLoaderPolicy::GetMetricsSuffix() const {
  39. return kEmptyComponentLoaderPolicyMetricsSuffix;
  40. }
  41. void LoadEmptyComponent(
  42. component_updater::ComponentLoaderPolicyVector& policies) {
  43. if (!base::FeatureList::IsEnabled(
  44. android_webview::features::kWebViewEmptyComponentLoaderPolicy)) {
  45. return;
  46. }
  47. policies.push_back(std::make_unique<EmptyComponentLoaderPolicy>());
  48. }
  49. } // namespace android_webview