Commit 10433939 authored by Yann Dago's avatar Yann Dago Committed by Commit Bot

Policy WebUI: Show Google Update policies

Use the IPolicyStatus COM interface to fetch the Google Update policies
and show then on chrome://policy
Visual: http://screen/GipT81x0igj

Bug: 1033573
Change-Id: Ib41c17b977fc6bfef40f2d8fb78333786ad167ac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2032796Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarJulian Pastarmov <pastarmovj@chromium.org>
Reviewed-by: default avatarGreg Thompson <grt@chromium.org>
Commit-Queue: Yann Dago <ydago@chromium.org>
Cr-Commit-Position: refs/heads/master@{#744298}
parent 181802cc
...@@ -4034,6 +4034,8 @@ jumbo_static_library("browser") { ...@@ -4034,6 +4034,8 @@ jumbo_static_library("browser") {
sources += [ sources += [
"component_updater/third_party_module_list_component_installer_win.cc", "component_updater/third_party_module_list_component_installer_win.cc",
"component_updater/third_party_module_list_component_installer_win.h", "component_updater/third_party_module_list_component_installer_win.h",
"google/google_update_policy_fetcher_win.cc",
"google/google_update_policy_fetcher_win.h",
"google/google_update_win.cc", "google/google_update_win.cc",
"google/google_update_win.h", "google/google_update_win.h",
"win/conflicts/incompatible_applications_updater.cc", "win/conflicts/incompatible_applications_updater.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/google/google_update_policy_fetcher_win.h"
#include <wrl/client.h>
#include <utility>
#include "base/numerics/safe_conversions.h"
#include "base/win/com_init_util.h"
#include "base/win/scoped_bstr.h"
#include "chrome/install_static/install_util.h"
#include "components/policy/core/common/policy_map.h"
#include "components/policy/core/common/policy_types.h"
#include "google_update/google_update_idl.h"
namespace {
constexpr char kAutoUpdateCheckPeriodMinutes[] = "AutoUpdateCheckPeriodMinutes";
constexpr char kDownloadPreference[] = "DownloadPreference";
constexpr char kInstallPolicy[] = "InstallPolicy";
constexpr char kUpdatePolicy[] = "UpdatePolicy";
constexpr char kUpdatesSuppressedDurationMin[] = "UpdatesSuppressedDurationMin";
constexpr char kUpdatesSuppressedStartHour[] = "UpdatesSuppressedStartHour";
constexpr char kUpdatesSuppressedStartMinute[] = "UpdatesSuppressedStartMinute";
constexpr char kRollbackToTargetVersion[] = "RollbackToTargetVersion";
constexpr char kTargetVersionPrefix[] = "TargetVersionPrefix";
// Adds the |value| of |policy_name| to |policies| using a "Mandatory" level,
// "Machine" scope and "Platform" source.
void AddPolicy(const char* policy_name,
std::unique_ptr<base::Value> value,
policy::PolicyMap* policies) {
DCHECK(policies);
policies->Set(policy_name, policy::POLICY_LEVEL_MANDATORY,
policy::POLICY_SCOPE_MACHINE, policy::POLICY_SOURCE_PLATFORM,
std::move(value), nullptr);
}
} // namespace
base::Value GetGoogleUpdatePolicyNames() {
base::Value names(base::Value::Type::LIST);
names.Append(base::Value(kAutoUpdateCheckPeriodMinutes));
names.Append(base::Value(kDownloadPreference));
names.Append(base::Value(kInstallPolicy));
names.Append(base::Value(kUpdatePolicy));
names.Append(base::Value(kUpdatesSuppressedDurationMin));
names.Append(base::Value(kUpdatesSuppressedStartHour));
names.Append(base::Value(kUpdatesSuppressedStartMinute));
names.Append(base::Value(kRollbackToTargetVersion));
names.Append(base::Value(kTargetVersionPrefix));
return names;
}
std::unique_ptr<policy::PolicyMap> GetGoogleUpdatePolicies() {
base::win::AssertComInitialized();
Microsoft::WRL::ComPtr<IPolicyStatus> policy_status;
HRESULT last_com_res =
::CoCreateInstance(CLSID_PolicyStatusClass, nullptr, CLSCTX_ALL,
IID_PPV_ARGS(&policy_status));
// If IPolicyStatus could not be instantiated, assume the updater is not
// configured yet to return the policies.
if (FAILED(last_com_res))
return nullptr;
auto policies = std::make_unique<policy::PolicyMap>();
base::win::ScopedBstr app_id(install_static::GetAppGuid());
DWORD auto_update_check_period_minutes;
last_com_res = policy_status->get_lastCheckPeriodMinutes(
&auto_update_check_period_minutes);
if (SUCCEEDED(last_com_res)) {
AddPolicy(kAutoUpdateCheckPeriodMinutes,
std::make_unique<base::Value>(
base::saturated_cast<int>(auto_update_check_period_minutes)),
policies.get());
}
base::win::ScopedBstr download_preference_group_policy;
last_com_res = policy_status->get_downloadPreferenceGroupPolicy(
download_preference_group_policy.Receive());
if (SUCCEEDED(last_com_res) &&
download_preference_group_policy.Length() > 0) {
AddPolicy(
kDownloadPreference,
std::make_unique<base::Value>(download_preference_group_policy.Get()),
policies.get());
}
DWORD effective_policy_for_app_installs;
last_com_res = policy_status->get_effectivePolicyForAppInstalls(
app_id.Get(), &effective_policy_for_app_installs);
if (SUCCEEDED(last_com_res)) {
AddPolicy(kInstallPolicy,
std::make_unique<base::Value>(
base::saturated_cast<int>(effective_policy_for_app_installs)),
policies.get());
}
DWORD effective_policy_for_app_updates;
last_com_res = policy_status->get_effectivePolicyForAppUpdates(
app_id.Get(), &effective_policy_for_app_updates);
if (SUCCEEDED(last_com_res)) {
AddPolicy(kUpdatePolicy,
std::make_unique<base::Value>(
base::saturated_cast<int>(effective_policy_for_app_updates)),
policies.get());
}
DWORD updates_suppressed_duration;
DWORD updates_suppressed_start_hour;
DWORD updates_suppressed_start_minute;
VARIANT_BOOL are_updates_suppressed;
last_com_res = policy_status->get_updatesSuppressedTimes(
&updates_suppressed_start_hour, &updates_suppressed_start_minute,
&updates_suppressed_duration, &are_updates_suppressed);
if (SUCCEEDED(last_com_res)) {
AddPolicy(kUpdatesSuppressedDurationMin,
std::make_unique<base::Value>(
base::saturated_cast<int>(updates_suppressed_duration)),
policies.get());
AddPolicy(kUpdatesSuppressedStartHour,
std::make_unique<base::Value>(
base::saturated_cast<int>(updates_suppressed_start_hour)),
policies.get());
AddPolicy(kUpdatesSuppressedStartMinute,
std::make_unique<base::Value>(
base::saturated_cast<int>(updates_suppressed_start_minute)),
policies.get());
}
VARIANT_BOOL is_rollback_to_target_version_allowed;
last_com_res = policy_status->get_isRollbackToTargetVersionAllowed(
app_id.Get(), &is_rollback_to_target_version_allowed);
if (SUCCEEDED(last_com_res)) {
AddPolicy(kRollbackToTargetVersion,
std::make_unique<base::Value>(
is_rollback_to_target_version_allowed == VARIANT_TRUE),
policies.get());
}
base::win::ScopedBstr target_version_prefix;
last_com_res = policy_status->get_targetVersionPrefix(
app_id.Get(), target_version_prefix.Receive());
if (SUCCEEDED(last_com_res) && target_version_prefix.Length() > 0) {
AddPolicy(kTargetVersionPrefix,
std::make_unique<base::Value>(target_version_prefix.Get()),
policies.get());
}
return policies;
}
// 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_GOOGLE_GOOGLE_UPDATE_POLICY_FETCHER_WIN_H_
#define CHROME_BROWSER_GOOGLE_GOOGLE_UPDATE_POLICY_FETCHER_WIN_H_
#include <memory>
#include "base/values.h"
namespace policy {
class PolicyMap;
}
// Returns a list of all the Google Update policies available through the
// IPolicyStatus COM interface.
base::Value GetGoogleUpdatePolicyNames();
// Fetches all the Google Update Policies available through the IPolicyStatus
// COM interface. Only the policies that have been set are returned by this
// function. This function returns null if the fetch fails because IPolicyStatus
// could not be instantiated. This function must run on a COM STA thread because
// it makes some COM calls.
std::unique_ptr<policy::PolicyMap> GetGoogleUpdatePolicies();
#endif // CHROME_BROWSER_GOOGLE_GOOGLE_UPDATE_POLICY_FETCHER_WIN_H_
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
#include "components/policy/core/common/cloud/machine_level_user_cloud_policy_manager.h" #include "components/policy/core/common/cloud/machine_level_user_cloud_policy_manager.h"
#include "components/policy/core/common/cloud/machine_level_user_cloud_policy_store.h" #include "components/policy/core/common/cloud/machine_level_user_cloud_policy_store.h"
#include "components/policy/core/common/policy_details.h" #include "components/policy/core/common/policy_details.h"
#include "components/policy/core/common/policy_map.h"
#include "components/policy/core/common/policy_namespace.h" #include "components/policy/core/common/policy_namespace.h"
#include "components/policy/core/common/policy_scheduler.h" #include "components/policy/core/common/policy_scheduler.h"
#include "components/policy/core/common/policy_types.h" #include "components/policy/core/common/policy_types.h"
...@@ -103,6 +104,12 @@ ...@@ -103,6 +104,12 @@
#include "extensions/common/manifest_constants.h" #include "extensions/common/manifest_constants.h"
#endif #endif
#if defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
#include "chrome/browser/google/google_update_policy_fetcher_win.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#endif // defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
namespace em = enterprise_management; namespace em = enterprise_management;
namespace { namespace {
...@@ -808,6 +815,18 @@ void PolicyUIHandler::RegisterMessages() { ...@@ -808,6 +815,18 @@ void PolicyUIHandler::RegisterMessages() {
#endif // !defined(OS_ANDROID) #endif // !defined(OS_ANDROID)
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
#if defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
base::PostTaskAndReplyWithResult(
base::CreateCOMSTATaskRunner(
{base::TaskPriority::USER_BLOCKING,
base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN, base::MayBlock(),
base::ThreadPool()})
.get(),
FROM_HERE, base::BindOnce(&GetGoogleUpdatePolicies),
base::BindOnce(&PolicyUIHandler::SetUpdaterPolicies,
weak_factory_.GetWeakPtr()));
#endif // defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
if (!user_status_provider_.get()) if (!user_status_provider_.get())
user_status_provider_ = std::make_unique<PolicyStatusProvider>(); user_status_provider_ = std::make_unique<PolicyStatusProvider>();
if (!device_status_provider_.get()) if (!device_status_provider_.get())
...@@ -876,7 +895,7 @@ void PolicyUIHandler::OnPolicyUpdated(const policy::PolicyNamespace& ns, ...@@ -876,7 +895,7 @@ void PolicyUIHandler::OnPolicyUpdated(const policy::PolicyNamespace& ns,
} }
base::Value PolicyUIHandler::GetPolicyNames() const { base::Value PolicyUIHandler::GetPolicyNames() const {
base::DictionaryValue names; base::Value names(base::Value::Type::DICTIONARY);
Profile* profile = Profile::FromWebUI(web_ui()); Profile* profile = Profile::FromWebUI(web_ui());
policy::SchemaRegistry* registry = profile->GetOriginalProfile() policy::SchemaRegistry* registry = profile->GetOriginalProfile()
->GetPolicySchemaRegistryService() ->GetPolicySchemaRegistryService()
...@@ -884,17 +903,26 @@ base::Value PolicyUIHandler::GetPolicyNames() const { ...@@ -884,17 +903,26 @@ base::Value PolicyUIHandler::GetPolicyNames() const {
scoped_refptr<policy::SchemaMap> schema_map = registry->schema_map(); scoped_refptr<policy::SchemaMap> schema_map = registry->schema_map();
// Add Chrome policy names. // Add Chrome policy names.
auto chrome_policy_names = std::make_unique<base::ListValue>(); base::Value chrome_policy_names(base::Value::Type::LIST);
policy::PolicyNamespace chrome_ns(policy::POLICY_DOMAIN_CHROME, ""); policy::PolicyNamespace chrome_ns(policy::POLICY_DOMAIN_CHROME, "");
const policy::Schema* chrome_schema = schema_map->GetSchema(chrome_ns); const policy::Schema* chrome_schema = schema_map->GetSchema(chrome_ns);
for (auto it = chrome_schema->GetPropertiesIterator(); !it.IsAtEnd(); for (auto it = chrome_schema->GetPropertiesIterator(); !it.IsAtEnd();
it.Advance()) { it.Advance()) {
chrome_policy_names->Append(base::Value(it.key())); chrome_policy_names.Append(base::Value(it.key()));
}
base::Value chrome_values(base::Value::Type::DICTIONARY);
chrome_values.SetStringKey("name", "Chrome Policies");
chrome_values.SetKey("policyNames", std::move(chrome_policy_names));
names.SetKey("chrome", std::move(chrome_values));
#if defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
if (updater_policies_) {
base::Value updater_policies(base::Value::Type::DICTIONARY);
updater_policies.SetStringKey("name", "Updater Policies");
updater_policies.SetKey("policyNames", GetGoogleUpdatePolicyNames());
names.SetKey("updater", std::move(updater_policies));
} }
auto chrome_values = std::make_unique<base::DictionaryValue>(); #endif // defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
chrome_values->SetString("name", "Chrome Policies");
chrome_values->SetList("policyNames", std::move(chrome_policy_names));
names.Set("chrome", std::move(chrome_values));
#if BUILDFLAG(ENABLE_EXTENSIONS) #if BUILDFLAG(ENABLE_EXTENSIONS)
// Add extension policy names. // Add extension policy names.
...@@ -906,20 +934,31 @@ base::Value PolicyUIHandler::GetPolicyNames() const { ...@@ -906,20 +934,31 @@ base::Value PolicyUIHandler::GetPolicyNames() const {
#endif // BUILDFLAG(ENABLE_EXTENSIONS) #endif // BUILDFLAG(ENABLE_EXTENSIONS)
return std::move(names); return names;
} }
base::Value PolicyUIHandler::GetPolicyValues() const { base::Value PolicyUIHandler::GetPolicyValues() const {
auto client = std::make_unique<policy::ChromePolicyConversionsClient>( auto client = std::make_unique<policy::ChromePolicyConversionsClient>(
web_ui()->GetWebContents()->GetBrowserContext()); web_ui()->GetWebContents()->GetBrowserContext());
#if defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
if (updater_policies_) {
return policy::ArrayPolicyConversions(std::move(client))
.EnableConvertValues(true)
.WithUpdaterPolicies(updater_policies_->DeepCopy())
.ToValue();
}
#endif // defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
return policy::ArrayPolicyConversions(std::move(client)) return policy::ArrayPolicyConversions(std::move(client))
.EnableConvertValues(true) .EnableConvertValues(true)
.ToValue(); .ToValue();
} }
void PolicyUIHandler::AddExtensionPolicyNames( void PolicyUIHandler::AddExtensionPolicyNames(
base::DictionaryValue* names, base::Value* names,
policy::PolicyDomain policy_domain) const { policy::PolicyDomain policy_domain) const {
DCHECK(names->is_dict());
#if BUILDFLAG(ENABLE_EXTENSIONS) #if BUILDFLAG(ENABLE_EXTENSIONS)
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
...@@ -949,21 +988,21 @@ void PolicyUIHandler::AddExtensionPolicyNames( ...@@ -949,21 +988,21 @@ void PolicyUIHandler::AddExtensionPolicyNames(
extensions::manifest_keys::kStorageManagedSchema)) { extensions::manifest_keys::kStorageManagedSchema)) {
continue; continue;
} }
auto extension_value = std::make_unique<base::DictionaryValue>(); base::Value extension_value(base::Value::Type::DICTIONARY);
extension_value->SetString("name", extension->name()); extension_value.SetStringKey("name", extension->name());
const policy::Schema* schema = schema_map->GetSchema( const policy::Schema* schema = schema_map->GetSchema(
policy::PolicyNamespace(policy_domain, extension->id())); policy::PolicyNamespace(policy_domain, extension->id()));
auto policy_names = std::make_unique<base::ListValue>(); base::Value policy_names(base::Value::Type::LIST);
if (schema && schema->valid()) { if (schema && schema->valid()) {
// Get policy names from the extension's policy schema. // Get policy names from the extension's policy schema.
// Store in a map, not an array, for faster lookup on JS side. // Store in a map, not an array, for faster lookup on JS side.
for (auto prop = schema->GetPropertiesIterator(); !prop.IsAtEnd(); for (auto prop = schema->GetPropertiesIterator(); !prop.IsAtEnd();
prop.Advance()) { prop.Advance()) {
policy_names->Append(base::Value(prop.key())); policy_names.Append(base::Value(prop.key()));
} }
} }
extension_value->Set("policyNames", std::move(policy_names)); extension_value.SetKey("policyNames", std::move(policy_names));
names->Set(extension->id(), std::move(extension_value)); names->SetKey(extension->id(), std::move(extension_value));
} }
#endif // BUILDFLAG(ENABLE_EXTENSIONS) #endif // BUILDFLAG(ENABLE_EXTENSIONS)
} }
...@@ -1151,6 +1190,15 @@ void PolicyUIHandler::SendPolicies() { ...@@ -1151,6 +1190,15 @@ void PolicyUIHandler::SendPolicies() {
FireWebUIListener("policies-updated", GetPolicyNames(), GetPolicyValues()); FireWebUIListener("policies-updated", GetPolicyNames(), GetPolicyValues());
} }
#if defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
void PolicyUIHandler::SetUpdaterPolicies(
std::unique_ptr<policy::PolicyMap> updater_policies) {
updater_policies_ = std::move(updater_policies);
if (updater_policies_)
SendPolicies();
}
#endif // defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
void PolicyUIHandler::OnRefreshPoliciesDone() { void PolicyUIHandler::OnRefreshPoliciesDone() {
SendPolicies(); SendPolicies();
SendStatus(); SendStatus();
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/values.h" #include "base/values.h"
#include "build/branding_buildflags.h"
#include "build/build_config.h"
#include "components/policy/core/browser/policy_error_map.h" #include "components/policy/core/browser/policy_error_map.h"
#include "components/policy/core/common/policy_map.h" #include "components/policy/core/common/policy_map.h"
#include "components/policy/core/common/policy_namespace.h" #include "components/policy/core/common/policy_namespace.h"
...@@ -31,6 +33,10 @@ ...@@ -31,6 +33,10 @@
class PolicyStatusProvider; class PolicyStatusProvider;
namespace policy {
class PolicyMap;
}
// The JavaScript message handler for the chrome://policy page. // The JavaScript message handler for the chrome://policy page.
class PolicyUIHandler : public content::WebUIMessageHandler, class PolicyUIHandler : public content::WebUIMessageHandler,
#if BUILDFLAG(ENABLE_EXTENSIONS) #if BUILDFLAG(ENABLE_EXTENSIONS)
...@@ -77,7 +83,7 @@ class PolicyUIHandler : public content::WebUIMessageHandler, ...@@ -77,7 +83,7 @@ class PolicyUIHandler : public content::WebUIMessageHandler,
base::Value GetPolicyNames() const; base::Value GetPolicyNames() const;
base::Value GetPolicyValues() const; base::Value GetPolicyValues() const;
void AddExtensionPolicyNames(base::DictionaryValue* names, void AddExtensionPolicyNames(base::Value* names,
policy::PolicyDomain policy_domain) const; policy::PolicyDomain policy_domain) const;
void HandleExportPoliciesJson(const base::ListValue* args); void HandleExportPoliciesJson(const base::ListValue* args);
...@@ -89,6 +95,12 @@ class PolicyUIHandler : public content::WebUIMessageHandler, ...@@ -89,6 +95,12 @@ class PolicyUIHandler : public content::WebUIMessageHandler,
// metadata is sent. // metadata is sent.
void SendPolicies(); void SendPolicies();
#if defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
// Sets |updater_policies_| in this instance and refreshes the UI via
// SendPolicies.
void SetUpdaterPolicies(std::unique_ptr<policy::PolicyMap> updater_policies);
#endif // defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
// Send the status of cloud policy to the UI. For each scope that has cloud // Send the status of cloud policy to the UI. For each scope that has cloud
// policy enabled (device and/or user), a dictionary containing status // policy enabled (device and/or user), a dictionary containing status
// information is sent. // information is sent.
...@@ -111,6 +123,10 @@ class PolicyUIHandler : public content::WebUIMessageHandler, ...@@ -111,6 +123,10 @@ class PolicyUIHandler : public content::WebUIMessageHandler,
std::unique_ptr<PolicyStatusProvider> device_status_provider_; std::unique_ptr<PolicyStatusProvider> device_status_provider_;
std::unique_ptr<PolicyStatusProvider> machine_status_provider_; std::unique_ptr<PolicyStatusProvider> machine_status_provider_;
#if defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
std::unique_ptr<policy::PolicyMap> updater_policies_;
#endif // defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
base::WeakPtrFactory<PolicyUIHandler> weak_factory_{this}; base::WeakPtrFactory<PolicyUIHandler> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(PolicyUIHandler); DISALLOW_COPY_AND_ASSIGN(PolicyUIHandler);
......
...@@ -50,6 +50,7 @@ if (is_component_build) { ...@@ -50,6 +50,7 @@ if (is_component_build) {
"//components/policy/core/common", "//components/policy/core/common",
] ]
public_deps = [ public_deps = [
"//build:branding_buildflags",
"//components/policy/core/browser:internal", "//components/policy/core/browser:internal",
"//components/policy/core/common:internal", "//components/policy/core/common:internal",
] ]
......
...@@ -49,6 +49,7 @@ jumbo_source_set("internal") { ...@@ -49,6 +49,7 @@ jumbo_source_set("internal") {
public_deps = [ "//base" ] public_deps = [ "//base" ]
deps = [ deps = [
"//base/third_party/dynamic_annotations", "//base/third_party/dynamic_annotations",
"//build:branding_buildflags",
"//components/google/core/common", "//components/google/core/common",
"//components/keyed_service/core", "//components/keyed_service/core",
"//components/pref_registry", "//components/pref_registry",
......
...@@ -35,6 +35,14 @@ PolicyConversions::PolicyConversions( ...@@ -35,6 +35,14 @@ PolicyConversions::PolicyConversions(
PolicyConversions::~PolicyConversions() = default; PolicyConversions::~PolicyConversions() = default;
#if defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
PolicyConversions& PolicyConversions::WithUpdaterPolicies(
std::unique_ptr<PolicyMap> policies) {
client()->SetUpdaterPolicies(std::move(policies));
return *this;
}
#endif // defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
PolicyConversions& PolicyConversions::EnableConvertTypes(bool enabled) { PolicyConversions& PolicyConversions::EnableConvertTypes(bool enabled) {
client_->EnableConvertTypes(enabled); client_->EnableConvertTypes(enabled);
return *this; return *this;
...@@ -91,6 +99,11 @@ Value DictionaryPolicyConversions::ToValue() { ...@@ -91,6 +99,11 @@ Value DictionaryPolicyConversions::ToValue() {
#endif // BUILDFLAG(ENABLE_EXTENSIONS) #endif // BUILDFLAG(ENABLE_EXTENSIONS)
} }
#if defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
if (client()->HasUpdaterPolicies())
all_policies.SetKey("updaterPolicies", client()->GetUpdaterPolicies());
#endif
#if BUILDFLAG(ENABLE_EXTENSIONS) && defined(OS_CHROMEOS) #if BUILDFLAG(ENABLE_EXTENSIONS) && defined(OS_CHROMEOS)
all_policies.SetKey("loginScreenExtensionPolicies", all_policies.SetKey("loginScreenExtensionPolicies",
GetExtensionPolicies(POLICY_DOMAIN_SIGNIN_EXTENSIONS)); GetExtensionPolicies(POLICY_DOMAIN_SIGNIN_EXTENSIONS));
...@@ -144,6 +157,11 @@ Value ArrayPolicyConversions::ToValue() { ...@@ -144,6 +157,11 @@ Value ArrayPolicyConversions::ToValue() {
if (client()->HasUserPolicies()) { if (client()->HasUserPolicies()) {
all_policies.Append(GetChromePolicies()); all_policies.Append(GetChromePolicies());
#if defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
if (client()->HasUpdaterPolicies())
all_policies.Append(GetUpdaterPolicies());
#endif
#if BUILDFLAG(ENABLE_EXTENSIONS) #if BUILDFLAG(ENABLE_EXTENSIONS)
for (auto& policy : for (auto& policy :
client()->GetExtensionPolicies(POLICY_DOMAIN_EXTENSIONS).TakeList()) { client()->GetExtensionPolicies(POLICY_DOMAIN_EXTENSIONS).TakeList()) {
...@@ -174,8 +192,19 @@ Value ArrayPolicyConversions::ToValue() { ...@@ -174,8 +192,19 @@ Value ArrayPolicyConversions::ToValue() {
return all_policies; return all_policies;
} }
#if defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
Value ArrayPolicyConversions::GetUpdaterPolicies() {
Value chrome_policies_data(Value::Type::DICTIONARY);
chrome_policies_data.SetKey("name", Value("Updater Policies"));
chrome_policies_data.SetKey("id", Value("updater"));
chrome_policies_data.SetKey("policies", client()->GetUpdaterPolicies());
return chrome_policies_data;
}
#endif // defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
Value ArrayPolicyConversions::GetChromePolicies() { Value ArrayPolicyConversions::GetChromePolicies() {
Value chrome_policies_data(Value::Type::DICTIONARY); Value chrome_policies_data(Value::Type::DICTIONARY);
chrome_policies_data.SetKey("id", Value("chrome"));
chrome_policies_data.SetKey("name", Value("Chrome Policies")); chrome_policies_data.SetKey("name", Value("Chrome Policies"));
chrome_policies_data.SetKey("policies", client()->GetChromePolicies()); chrome_policies_data.SetKey("policies", client()->GetChromePolicies());
return chrome_policies_data; return chrome_policies_data;
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include <string> #include <string>
#include "base/values.h" #include "base/values.h"
#include "build/branding_buildflags.h"
#include "build/build_config.h"
#include "components/policy/core/common/policy_map.h" #include "components/policy/core/common/policy_map.h"
#include "components/policy/core/common/policy_namespace.h" #include "components/policy/core/common/policy_namespace.h"
#include "components/policy/core/common/policy_types.h" #include "components/policy/core/common/policy_types.h"
...@@ -50,6 +52,11 @@ class POLICY_EXPORT PolicyConversions { ...@@ -50,6 +52,11 @@ class POLICY_EXPORT PolicyConversions {
// Enabled by default. // Enabled by default.
PolicyConversions& EnableUserPolicies(bool enabled); PolicyConversions& EnableUserPolicies(bool enabled);
#if defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
// Sets the updater policies.
PolicyConversions& WithUpdaterPolicies(std::unique_ptr<PolicyMap> policies);
#endif // defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
// Returns the policy data as a base::Value object. // Returns the policy data as a base::Value object.
virtual base::Value ToValue() = 0; virtual base::Value ToValue() = 0;
...@@ -94,6 +101,10 @@ class POLICY_EXPORT ArrayPolicyConversions : public PolicyConversions { ...@@ -94,6 +101,10 @@ class POLICY_EXPORT ArrayPolicyConversions : public PolicyConversions {
private: private:
base::Value GetChromePolicies(); base::Value GetChromePolicies();
#if defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
base::Value GetUpdaterPolicies();
#endif // defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
DISALLOW_COPY_AND_ASSIGN(ArrayPolicyConversions); DISALLOW_COPY_AND_ASSIGN(ArrayPolicyConversions);
}; };
......
...@@ -54,6 +54,13 @@ void PolicyConversionsClient::EnableUserPolicies(bool enabled) { ...@@ -54,6 +54,13 @@ void PolicyConversionsClient::EnableUserPolicies(bool enabled) {
user_policies_enabled_ = enabled; user_policies_enabled_ = enabled;
} }
#if defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
void PolicyConversionsClient::SetUpdaterPolicies(
std::unique_ptr<PolicyMap> policies) {
updater_policies_ = std::move(policies);
}
#endif // defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
std::string PolicyConversionsClient::ConvertValueToJSON( std::string PolicyConversionsClient::ConvertValueToJSON(
const Value& value) const { const Value& value) const {
std::string json_string; std::string json_string;
...@@ -270,4 +277,17 @@ bool PolicyConversionsClient::GetUserPoliciesEnabled() const { ...@@ -270,4 +277,17 @@ bool PolicyConversionsClient::GetUserPoliciesEnabled() const {
return user_policies_enabled_; return user_policies_enabled_;
} }
#if defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
Value PolicyConversionsClient::GetUpdaterPolicies() {
return updater_policies_.get()
? GetPolicyValues(*updater_policies_, nullptr, base::nullopt)
: base::Value(base::Value::Type::DICTIONARY);
}
bool PolicyConversionsClient::PolicyConversionsClient::HasUpdaterPolicies()
const {
return !!updater_policies_;
}
#endif // defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
} // namespace policy } // namespace policy
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#include "base/containers/flat_map.h" #include "base/containers/flat_map.h"
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
#include "base/values.h" #include "base/values.h"
#include "build/branding_buildflags.h"
#include "build/build_config.h"
#include "components/policy/core/browser/policy_conversions.h" #include "components/policy/core/browser/policy_conversions.h"
#include "components/policy/core/common/schema.h" #include "components/policy/core/common/schema.h"
#include "components/policy/policy_export.h" #include "components/policy/policy_export.h"
...@@ -58,6 +60,15 @@ class POLICY_EXPORT PolicyConversionsClient { ...@@ -58,6 +60,15 @@ class POLICY_EXPORT PolicyConversionsClient {
// Enabled by default. // Enabled by default.
void EnableUserPolicies(bool enabled); void EnableUserPolicies(bool enabled);
#if defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
// Sets the updater policies.
void SetUpdaterPolicies(std::unique_ptr<PolicyMap> policies);
// Returns true if this client is able to return information on the updater's
// policies.
bool HasUpdaterPolicies() const;
base::Value GetUpdaterPolicies();
#endif // defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
// Converts the given |value| to JSON, respecting the configuration // Converts the given |value| to JSON, respecting the configuration
// preferences that were set on this client. // preferences that were set on this client.
std::string ConvertValueToJSON(const base::Value& value) const; std::string ConvertValueToJSON(const base::Value& value) const;
...@@ -137,6 +148,10 @@ class POLICY_EXPORT PolicyConversionsClient { ...@@ -137,6 +148,10 @@ class POLICY_EXPORT PolicyConversionsClient {
bool GetUserPoliciesEnabled() const; bool GetUserPoliciesEnabled() const;
private: private:
#if defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
std::unique_ptr<PolicyMap> updater_policies_;
#endif // BUILDFLAG(GOOGLE_CHROME_BRANDING) && defined(OS_WIN)
bool convert_types_enabled_ = true; bool convert_types_enabled_ = true;
bool convert_values_enabled_ = false; bool convert_values_enabled_ = false;
bool device_local_account_policies_enabled_ = false; bool device_local_account_policies_enabled_ = false;
......
...@@ -50,6 +50,7 @@ cr.define('policy', function() { ...@@ -50,6 +50,7 @@ cr.define('policy', function() {
/** /**
* @typedef {{ * @typedef {{
* id: ?string, * id: ?string,
* isExtension?: boolean,
* name: string, * name: string,
* policies: !Array<!Policy> * policies: !Array<!Policy>
* }} * }}
...@@ -496,8 +497,7 @@ cr.define('policy', function() { ...@@ -496,8 +497,7 @@ cr.define('policy', function() {
onPoliciesReceived_(policyNames, policyValues) { onPoliciesReceived_(policyNames, policyValues) {
/** @type {Array<!PolicyTableModel>} */ /** @type {Array<!PolicyTableModel>} */
const policyGroups = policyValues.map(value => { const policyGroups = policyValues.map(value => {
const knownPolicyNames = const knownPolicyNames = policyNames[value.id].policyNames;
(policyNames[value.id] || policyNames.chrome).policyNames;
const knownPolicyNamesSet = new Set(knownPolicyNames); const knownPolicyNamesSet = new Set(knownPolicyNames);
const receivedPolicyNames = Object.keys(value.policies); const receivedPolicyNames = Object.keys(value.policies);
const allPolicyNames = const allPolicyNames =
...@@ -518,7 +518,7 @@ cr.define('policy', function() { ...@@ -518,7 +518,7 @@ cr.define('policy', function() {
name: value.forSigninScreen ? name: value.forSigninScreen ?
`${value.name} [${loadTimeData.getString('signinProfile')}]` : `${value.name} [${loadTimeData.getString('signinProfile')}]` :
value.name, value.name,
id: value.id, id: value.isExtension ? value.id : null,
policies policies
}; };
}); });
......
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