diff --git a/android_webview/nonembedded/BUILD.gn b/android_webview/nonembedded/BUILD.gn index 865a11eb7995ee..7a987f782a21e1 100644 --- a/android_webview/nonembedded/BUILD.gn +++ b/android_webview/nonembedded/BUILD.gn @@ -123,6 +123,8 @@ source_set("nonembedded") { "component_updater/aw_component_update_service.h", "component_updater/aw_component_updater_configurator.cc", "component_updater/aw_component_updater_configurator.h", + "component_updater/installer_policies/aw_trust_token_key_commitments_component_installer_policy.cc", + "component_updater/installer_policies/aw_trust_token_key_commitments_component_installer_policy.h", "component_updater/registration.cc", "component_updater/registration.h", "webview_apk_application.cc", @@ -135,6 +137,7 @@ source_set("nonembedded") { "//base", "//base", "//components/component_updater", + "//components/component_updater/installer_policies", "//components/prefs", "//components/services/patch/content", "//components/services/unzip/content", diff --git a/android_webview/nonembedded/component_updater/installer_policies/aw_trust_token_key_commitments_component_installer_policy.cc b/android_webview/nonembedded/component_updater/installer_policies/aw_trust_token_key_commitments_component_installer_policy.cc new file mode 100644 index 00000000000000..75aa47a590f0b4 --- /dev/null +++ b/android_webview/nonembedded/component_updater/installer_policies/aw_trust_token_key_commitments_component_installer_policy.cc @@ -0,0 +1,53 @@ +// Copyright 2021 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "android_webview/nonembedded/component_updater/installer_policies/aw_trust_token_key_commitments_component_installer_policy.h" + +#include +#include +#include +#include + +#include "android_webview/nonembedded/component_updater/aw_component_installer_policy_delegate.h" +#include "base/callback.h" +#include "base/notreached.h" +#include "components/component_updater/component_installer.h" +#include "components/component_updater/installer_policies/trust_token_key_commitments_component_installer_policy.h" + +namespace android_webview { + +AwTrustTokenKeyCommitmentsComponentInstallerPolicy:: + AwTrustTokenKeyCommitmentsComponentInstallerPolicy( + std::unique_ptr delegate) + : component_updater::TrustTokenKeyCommitmentsComponentInstallerPolicy( + /* on_commitments_ready= */ base::BindRepeating( + [](const std::string& raw_commitments) { + // The inherited ComponentReady shouldn't be called because it + // assumes it runs in a browser context. + NOTREACHED(); + })), + delegate_(std::move(delegate)) {} + +AwTrustTokenKeyCommitmentsComponentInstallerPolicy:: + ~AwTrustTokenKeyCommitmentsComponentInstallerPolicy() = default; + +update_client::CrxInstaller::Result +AwTrustTokenKeyCommitmentsComponentInstallerPolicy::OnCustomInstall( + const base::DictionaryValue& manifest, + const base::FilePath& install_dir) { + std::vector hash; + GetHash(&hash); + return delegate_->OnCustomInstall(manifest, install_dir, hash); +} +void AwTrustTokenKeyCommitmentsComponentInstallerPolicy::OnCustomUninstall() { + delegate_->OnCustomUninstall(); +} +void AwTrustTokenKeyCommitmentsComponentInstallerPolicy::ComponentReady( + const base::Version& version, + const base::FilePath& install_dir, + std::unique_ptr manifest) { + delegate_->ComponentReady(version, install_dir, std::move(manifest)); +} + +} // namespace android_webview diff --git a/android_webview/nonembedded/component_updater/installer_policies/aw_trust_token_key_commitments_component_installer_policy.h b/android_webview/nonembedded/component_updater/installer_policies/aw_trust_token_key_commitments_component_installer_policy.h new file mode 100644 index 00000000000000..0e8106aa4412f2 --- /dev/null +++ b/android_webview/nonembedded/component_updater/installer_policies/aw_trust_token_key_commitments_component_installer_policy.h @@ -0,0 +1,55 @@ +// Copyright 2021 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef ANDROID_WEBVIEW_NONEMBEDDED_COMPONENT_UPDATER_INSTALLER_POLICIES_AW_TRUST_TOKEN_KEY_COMMITMENTS_COMPONENT_INSTALLER_POLICY_H_ +#define ANDROID_WEBVIEW_NONEMBEDDED_COMPONENT_UPDATER_INSTALLER_POLICIES_AW_TRUST_TOKEN_KEY_COMMITMENTS_COMPONENT_INSTALLER_POLICY_H_ + +#include +#include +#include + +#include "components/component_updater/installer_policies/trust_token_key_commitments_component_installer_policy.h" + +namespace base { +class DictionaryValue; +class FilePath; +class Version; +} // namespace base + +namespace android_webview { + +class AwComponentInstallerPolicyDelegate; + +// Provides an implementation for the policy methods that need custom +// implementation for WebView. These methods should always be delegated to the +// custom delegate object, inherited methods shouldn't be called if they need +// a browser context for execution. +class AwTrustTokenKeyCommitmentsComponentInstallerPolicy + : public component_updater:: + TrustTokenKeyCommitmentsComponentInstallerPolicy { + public: + explicit AwTrustTokenKeyCommitmentsComponentInstallerPolicy( + std::unique_ptr delegate); + ~AwTrustTokenKeyCommitmentsComponentInstallerPolicy() override; + + AwTrustTokenKeyCommitmentsComponentInstallerPolicy( + const AwTrustTokenKeyCommitmentsComponentInstallerPolicy&) = delete; + AwTrustTokenKeyCommitmentsComponentInstallerPolicy& operator=( + const AwTrustTokenKeyCommitmentsComponentInstallerPolicy&) = delete; + + update_client::CrxInstaller::Result OnCustomInstall( + const base::DictionaryValue& manifest, + const base::FilePath& install_dir) override; + void OnCustomUninstall() override; + void ComponentReady(const base::Version& version, + const base::FilePath& install_dir, + std::unique_ptr manifest) override; + + private: + std::unique_ptr delegate_; +}; + +} // namespace android_webview + +#endif // ANDROID_WEBVIEW_NONEMBEDDED_COMPONENT_UPDATER_INSTALLER_POLICIES_AW_TRUST_TOKEN_KEY_COMMITMENTS_COMPONENT_INSTALLER_POLICY_H_ diff --git a/android_webview/nonembedded/component_updater/registration.cc b/android_webview/nonembedded/component_updater/registration.cc index 0000137321555b..b278673ea078fb 100644 --- a/android_webview/nonembedded/component_updater/registration.cc +++ b/android_webview/nonembedded/component_updater/registration.cc @@ -4,11 +4,22 @@ #include "android_webview/nonembedded/component_updater/registration.h" +#include + +#include "android_webview/nonembedded/component_updater/aw_component_installer_policy_delegate.h" +#include "android_webview/nonembedded/component_updater/installer_policies/aw_trust_token_key_commitments_component_installer_policy.h" +#include "base/callback.h" +#include "base/memory/scoped_refptr.h" +#include "components/component_updater/component_installer.h" + namespace android_webview { void RegisterComponentsForUpdate( - component_updater::ComponentUpdateService* cus) { - // TODO(crbug.com/1171762) register trust tokens component + component_updater::ComponentUpdateService* component_update_service) { + base::MakeRefCounted( + std::make_unique( + std::make_unique())) + ->Register(component_update_service, base::OnceClosure()); } } // namespace android_webview diff --git a/android_webview/nonembedded/component_updater/registration.h b/android_webview/nonembedded/component_updater/registration.h index 0daa8c5fb4b24b..03f7aafe8ace86 100644 --- a/android_webview/nonembedded/component_updater/registration.h +++ b/android_webview/nonembedded/component_updater/registration.h @@ -12,7 +12,7 @@ class ComponentUpdateService; namespace android_webview { void RegisterComponentsForUpdate( - component_updater::ComponentUpdateService* cus); + component_updater::ComponentUpdateService* component_update_service); } // namespace android_webview diff --git a/components/component_updater/installer_policies/trust_token_key_commitments_component_installer_policy.h b/components/component_updater/installer_policies/trust_token_key_commitments_component_installer_policy.h index a373c13435aad4..897cbdb70e86da 100644 --- a/components/component_updater/installer_policies/trust_token_key_commitments_component_installer_policy.h +++ b/components/component_updater/installer_policies/trust_token_key_commitments_component_installer_policy.h @@ -41,6 +41,9 @@ class TrustTokenKeyCommitmentsComponentInstallerPolicy TrustTokenKeyCommitmentsComponentInstallerPolicy& operator=( const TrustTokenKeyCommitmentsComponentInstallerPolicy&) = delete; + protected: + void GetHash(std::vector* hash) const override; + private: FRIEND_TEST_ALL_PREFIXES(TrustTokenKeyCommitmentsComponentInstallerTest, LoadsCommitments); @@ -60,7 +63,6 @@ class TrustTokenKeyCommitmentsComponentInstallerPolicy const base::FilePath& install_dir, std::unique_ptr manifest) override; base::FilePath GetRelativeInstallDir() const override; - void GetHash(std::vector* hash) const override; std::string GetName() const override; update_client::InstallerAttributes GetInstallerAttributes() const override;