Skip to content

Commit

Permalink
[AW][Trust Tokens] Register trust tokens component
Browse files Browse the repository at this point in the history
Register trust tokens component for installation in
ComponentUpdateService in WebView. Note that this only means
downloading the files on disk. Trust tokens config is still needed to
be fetched and loaded inside embedded WebView instances via
ComponentProviderService, this will be in following CLs.

See supporting component updater in WebView design doc for more
details: http://go/wv-component-updater

Bug: 1171762
Test: Manully launch AwComponentUpdateService and notice debug logs
Change-Id: Iad716b0b9ce79296fb818a4072b661225ab62cb5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2697148
Reviewed-by: Sorin Jianu <sorin@chromium.org>
Reviewed-by: Joshua Pawlicki <waffles@chromium.org>
Reviewed-by: Mugdha Lakhani <nator@chromium.org>
Commit-Queue: Hazem Ashmawy <hazems@chromium.org>
Cr-Commit-Position: refs/heads/master@{#855947}
  • Loading branch information
HazemSamir authored and Chromium LUCI CQ committed Feb 19, 2021
1 parent 53883a6 commit a711c86
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 4 deletions.
3 changes: 3 additions & 0 deletions android_webview/nonembedded/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <memory>
#include <string>
#include <utility>
#include <vector>

#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<AwComponentInstallerPolicyDelegate> 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<uint8_t> 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<base::DictionaryValue> manifest) {
delegate_->ComponentReady(version, install_dir, std::move(manifest));
}

} // namespace android_webview
Original file line number Diff line number Diff line change
@@ -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 <memory>
#include <string>
#include <vector>

#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<AwComponentInstallerPolicyDelegate> 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<base::DictionaryValue> manifest) override;

private:
std::unique_ptr<AwComponentInstallerPolicyDelegate> delegate_;
};

} // namespace android_webview

#endif // ANDROID_WEBVIEW_NONEMBEDDED_COMPONENT_UPDATER_INSTALLER_POLICIES_AW_TRUST_TOKEN_KEY_COMMITMENTS_COMPONENT_INSTALLER_POLICY_H_
15 changes: 13 additions & 2 deletions android_webview/nonembedded/component_updater/registration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,22 @@

#include "android_webview/nonembedded/component_updater/registration.h"

#include <memory>

#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<component_updater::ComponentInstaller>(
std::make_unique<AwTrustTokenKeyCommitmentsComponentInstallerPolicy>(
std::make_unique<AwComponentInstallerPolicyDelegate>()))
->Register(component_update_service, base::OnceClosure());
}

} // namespace android_webview
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ComponentUpdateService;
namespace android_webview {

void RegisterComponentsForUpdate(
component_updater::ComponentUpdateService* cus);
component_updater::ComponentUpdateService* component_update_service);

} // namespace android_webview

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class TrustTokenKeyCommitmentsComponentInstallerPolicy
TrustTokenKeyCommitmentsComponentInstallerPolicy& operator=(
const TrustTokenKeyCommitmentsComponentInstallerPolicy&) = delete;

protected:
void GetHash(std::vector<uint8_t>* hash) const override;

private:
FRIEND_TEST_ALL_PREFIXES(TrustTokenKeyCommitmentsComponentInstallerTest,
LoadsCommitments);
Expand All @@ -60,7 +63,6 @@ class TrustTokenKeyCommitmentsComponentInstallerPolicy
const base::FilePath& install_dir,
std::unique_ptr<base::DictionaryValue> manifest) override;
base::FilePath GetRelativeInstallDir() const override;
void GetHash(std::vector<uint8_t>* hash) const override;
std::string GetName() const override;
update_client::InstallerAttributes GetInstallerAttributes() const override;

Expand Down

0 comments on commit a711c86

Please sign in to comment.