Commit 92eeac91 authored by Martynas Sinkievic's avatar Martynas Sinkievic Committed by Commit Bot

[Autofill] Add component installer for regex data

Addition of a component installer used to download regex data for
Autofill.

Change-Id: I82bbbbdb7448399dc95c509fc14dc2f04d4232e5
Bug: 1121990
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2320837Reviewed-by: default avatarSorin Jianu <sorin@chromium.org>
Reviewed-by: default avatarChristoph Schwering <schwering@google.com>
Reviewed-by: default avatarMatthias Körber <koerber@google.com>
Commit-Queue: Martynas Sinkievič <marsin@google.com>
Cr-Commit-Position: refs/heads/master@{#813510}
parent 933d0eb8
......@@ -278,6 +278,8 @@ static_library("browser") {
"command_updater_impl.h",
"complex_tasks/task_tab_helper.cc",
"complex_tasks/task_tab_helper.h",
"component_updater/autofill_regex_component_installer.cc",
"component_updater/autofill_regex_component_installer.h",
"component_updater/autofill_states_component_installer.cc",
"component_updater/autofill_states_component_installer.h",
"component_updater/chrome_component_updater_configurator.cc",
......
// Copyright 2020 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 "chrome/browser/component_updater/autofill_regex_component_installer.h"
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "base/bind.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/stl_util.h"
#include "base/task/post_task.h"
#include "base/version.h"
#include "components/autofill/core/browser/pattern_provider/pattern_configuration_parser.h"
#include "components/component_updater/component_updater_paths.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
using component_updater::ComponentUpdateService;
namespace {
constexpr base::FilePath::CharType kAutofillRegexJsonFileName[] =
FILE_PATH_LITERAL("data.json");
// The SHA256 of the SubjectPublicKeyInfo used to sign the extension.
// The extension id is: PDAFIOLLNGONHOADBMDOEMAGNFPDPHBE
constexpr uint8_t kAutofillRegexPublicKeySHA256[32] = {
0xf3, 0x05, 0x8e, 0xbb, 0xd6, 0xed, 0x7e, 0x03, 0x1c, 0x3e, 0x4c,
0x06, 0xd5, 0xf3, 0xf7, 0x14, 0x93, 0x75, 0xf4, 0x24, 0x67, 0x4e,
0x61, 0x1e, 0xba, 0x5f, 0xf4, 0x29, 0x27, 0x0e, 0x1c, 0x1e};
constexpr char kAutofillRegexManifestName[] = "Autofill Regex Data";
void LoadRegexConfigurationFromDisk(const base::FilePath& json_path) {
if (json_path.empty())
return;
VLOG(1) << "Reading Download File Types from file: " << json_path.value();
std::string json_string;
if (!base::ReadFileToString(json_path, &json_string)) {
// The file won't exist on new installations, so this is not always an
// error.
VLOG(1) << "Failed reading from " << json_path.value();
return;
}
content::GetUIThreadTaskRunner(
{base::MayBlock(), base::TaskPriority::BEST_EFFORT})
->PostTask(
FROM_HERE,
base::BindOnce(&autofill::field_type_parsing::PopulateFromJsonString,
std::move(json_string)));
}
} // namespace
namespace component_updater {
bool AutofillRegexComponentInstallerPolicy::
SupportsGroupPolicyEnabledComponentUpdates() const {
return false;
}
bool AutofillRegexComponentInstallerPolicy::RequiresNetworkEncryption() const {
return false;
}
update_client::CrxInstaller::Result
AutofillRegexComponentInstallerPolicy::OnCustomInstall(
const base::DictionaryValue& manifest,
const base::FilePath& install_dir) {
return update_client::CrxInstaller::Result(0); // Nothing custom here.
}
void AutofillRegexComponentInstallerPolicy::OnCustomUninstall() {}
base::FilePath AutofillRegexComponentInstallerPolicy::GetInstalledPath(
const base::FilePath& base) {
return base.Append(kAutofillRegexJsonFileName);
}
void AutofillRegexComponentInstallerPolicy::ComponentReady(
const base::Version& version,
const base::FilePath& install_dir,
std::unique_ptr<base::DictionaryValue> manifest) {
VLOG(1) << "Component ready, version " << version.GetString() << " in "
<< install_dir.value();
base::ThreadPool::PostTask(
FROM_HERE, {base::MayBlock(), base::TaskPriority::BEST_EFFORT},
base::BindOnce(&LoadRegexConfigurationFromDisk,
GetInstalledPath(install_dir)));
}
// Called during startup and installation before ComponentReady().
bool AutofillRegexComponentInstallerPolicy::VerifyInstallation(
const base::DictionaryValue& manifest,
const base::FilePath& install_dir) const {
// Not doing any validation, it will be done during parsing.
return base::PathExists(GetInstalledPath(install_dir));
}
base::FilePath AutofillRegexComponentInstallerPolicy::GetRelativeInstallDir()
const {
return base::FilePath(FILE_PATH_LITERAL("AutofillRegex"));
}
void AutofillRegexComponentInstallerPolicy::GetHash(
std::vector<uint8_t>* hash) const {
hash->assign(std::begin(kAutofillRegexPublicKeySHA256),
std::end(kAutofillRegexPublicKeySHA256));
}
std::string AutofillRegexComponentInstallerPolicy::GetName() const {
return kAutofillRegexManifestName;
}
update_client::InstallerAttributes
AutofillRegexComponentInstallerPolicy::GetInstallerAttributes() const {
return update_client::InstallerAttributes();
}
std::vector<std::string> AutofillRegexComponentInstallerPolicy::GetMimeTypes()
const {
return std::vector<std::string>();
}
void RegisterAutofillRegexComponent(ComponentUpdateService* cus,
const base::FilePath& user_data_dir) {
VLOG(1) << "Registering Autofill Regex component.";
auto installer = base::MakeRefCounted<ComponentInstaller>(
std::make_unique<AutofillRegexComponentInstallerPolicy>());
installer->Register(cus, base::OnceClosure());
}
} // namespace component_updater
// Copyright 2020 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 CHROME_BROWSER_COMPONENT_UPDATER_AUTOFILL_REGEX_COMPONENT_INSTALLER_H_
#define CHROME_BROWSER_COMPONENT_UPDATER_AUTOFILL_REGEX_COMPONENT_INSTALLER_H_
#include <stdint.h>
#include <memory>
#include <string>
#include <vector>
#include "base/values.h"
#include "components/component_updater/component_installer.h"
namespace base {
class FilePath;
} // namespace base
namespace component_updater {
class ComponentUpdateService;
class AutofillRegexComponentInstallerPolicy : public ComponentInstallerPolicy {
public:
AutofillRegexComponentInstallerPolicy() = default;
~AutofillRegexComponentInstallerPolicy() override = default;
AutofillRegexComponentInstallerPolicy(
const AutofillRegexComponentInstallerPolicy&) = delete;
AutofillRegexComponentInstallerPolicy& operator=(
const AutofillRegexComponentInstallerPolicy&) = delete;
private:
// The following methods override ComponentInstallerPolicy.
bool SupportsGroupPolicyEnabledComponentUpdates() const override;
bool RequiresNetworkEncryption() const override;
update_client::CrxInstaller::Result OnCustomInstall(
const base::DictionaryValue& manifest,
const base::FilePath& install_dir) override;
void OnCustomUninstall() override;
bool VerifyInstallation(const base::DictionaryValue& manifest,
const base::FilePath& install_dir) const override;
void ComponentReady(const base::Version& version,
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;
std::vector<std::string> GetMimeTypes() const override;
static base::FilePath GetInstalledPath(const base::FilePath& base);
};
// Call once during startup to make the component update service aware of
// the File Type Policies component.
void RegisterAutofillRegexComponent(ComponentUpdateService* cus,
const base::FilePath& user_data_dir);
} // namespace component_updater
#endif // CHROME_BROWSER_COMPONENT_UPDATER_AUTOFILL_REGEX_COMPONENT_INSTALLER_H_
......@@ -9,6 +9,7 @@
#include "build/branding_buildflags.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/component_updater/autofill_regex_component_installer.h"
#include "chrome/browser/component_updater/autofill_states_component_installer.h"
#include "chrome/browser/component_updater/crl_set_component_installer.h"
#include "chrome/browser/component_updater/crowd_deny_component_installer.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment