Commit 187bdb21 authored by Tien Mai's avatar Tien Mai Committed by Commit Bot

Add additional information to chrome://policy exported JSON.

A new key "chromeMetadata" will be added to the JSON exported by
the chrome://policy page. This new key will contain the following
information:

   "chromeMetadata": {
      "OS": "Windows 10 OS Version 1709 (Build 16299.1146)",
      "application": "Google Chrome",
      "revision": "3e139c3d-refs/heads/master@{#665955}",
      "version": "77.0.3815.0 (Developer Build) (64-bit)"
   }

Bug: 963506
Change-Id: I0b5fa3ef1904508285a94acbff45dde3fc232aa8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1642817Reviewed-by: default avatarJulian Pastarmov <pastarmovj@chromium.org>
Reviewed-by: default avatarEsmael El-Moslimany <aee@chromium.org>
Commit-Queue: Tien Mai <tienmai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#667197}
parent 16c50961
...@@ -53,6 +53,11 @@ using base::Value; ...@@ -53,6 +53,11 @@ using base::Value;
namespace em = enterprise_management; namespace em = enterprise_management;
namespace policy { namespace policy {
// Fills |policy_dump| with device specific information if this device is
// enterprise managed.
void FillIdentityFields(Value* policy_dump);
namespace { namespace {
// Maps known policy names to their schema. If a policy is not present, it is // Maps known policy names to their schema. If a policy is not present, it is
...@@ -508,6 +513,9 @@ Value GetAllPolicyValuesAsDictionary(content::BrowserContext* context, ...@@ -508,6 +513,9 @@ Value GetAllPolicyValuesAsDictionary(content::BrowserContext* context,
std::move(device_local_account_policies)); std::move(device_local_account_policies));
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
if (with_device_data)
FillIdentityFields(&all_policies);
return all_policies; return all_policies;
} }
...@@ -571,9 +579,7 @@ std::string GetAllPolicyValuesAsJSON(content::BrowserContext* context, ...@@ -571,9 +579,7 @@ std::string GetAllPolicyValuesAsJSON(content::BrowserContext* context,
Value all_policies = GetAllPolicyValuesAsDictionary( Value all_policies = GetAllPolicyValuesAsDictionary(
context, with_user_policies, false /* convert_values */, with_device_data, context, with_user_policies, false /* convert_values */, with_device_data,
is_pretty_print); is_pretty_print);
if (with_device_data) {
FillIdentityFields(&all_policies);
}
return DictionaryToJSONString(all_policies, is_pretty_print); return DictionaryToJSONString(all_policies, is_pretty_print);
} }
......
...@@ -2310,6 +2310,8 @@ jumbo_split_static_library("ui") { ...@@ -2310,6 +2310,8 @@ jumbo_split_static_library("ui") {
"webui/settings_utils_win.cc", "webui/settings_utils_win.cc",
"webui/version_handler_win.cc", "webui/version_handler_win.cc",
"webui/version_handler_win.h", "webui/version_handler_win.h",
"webui/version_util_win.cc",
"webui/version_util_win.h",
"webui/welcome/welcome_win10_handler.cc", "webui/welcome/welcome_win10_handler.cc",
"webui/welcome/welcome_win10_handler.h", "webui/welcome/welcome_win10_handler.h",
"webui/welcome/welcome_win10_ui.cc", "webui/welcome/welcome_win10_ui.cc",
......
...@@ -47,8 +47,8 @@ ...@@ -47,8 +47,8 @@
#include "ui/shell_dialogs/select_file_policy.h" #include "ui/shell_dialogs/select_file_policy.h"
#include "url/gurl.h" #include "url/gurl.h"
using testing::Return;
using testing::_; using testing::_;
using testing::Return;
namespace { namespace {
...@@ -142,6 +142,21 @@ std::vector<std::string> PopulateExpectedPolicy( ...@@ -142,6 +142,21 @@ std::vector<std::string> PopulateExpectedPolicy(
return expected_policy; return expected_policy;
} }
void SetChromeMetaData(base::DictionaryValue* expected) {
// Only set the expected keys and types and not the values since
// these can vary greatly on the platform, OS, architecture
// that is running.
constexpr char prefix[] = "chromeMetadata";
expected->SetPath({prefix, "application"}, base::Value(""));
expected->SetPath({prefix, "version"}, base::Value(""));
expected->SetPath({prefix, "revision"}, base::Value(""));
#if defined(OS_CHROMEOS)
expected->SetPath({prefix, "platform"}, base::Value(""));
#else
expected->SetPath({prefix, "OS"}, base::Value(""));
#endif
}
void SetExpectedPolicy(base::DictionaryValue* expected, void SetExpectedPolicy(base::DictionaryValue* expected,
const std::string& name, const std::string& name,
const std::string& level, const std::string& level,
...@@ -185,7 +200,7 @@ class PolicyUITest : public InProcessBrowserTest { ...@@ -185,7 +200,7 @@ class PolicyUITest : public InProcessBrowserTest {
const policy::PolicyNamespace& policy_namespace, const policy::PolicyNamespace& policy_namespace,
const policy::PolicyMap& policy); const policy::PolicyMap& policy);
void VerifyPolicies(const std::vector<std::vector<std::string> >& expected); void VerifyPolicies(const std::vector<std::vector<std::string>>& expected);
void VerifyExportingPolicies(const base::DictionaryValue& expected); void VerifyExportingPolicies(const base::DictionaryValue& expected);
...@@ -237,11 +252,9 @@ class TestSelectFileDialogFactory : public ui::SelectFileDialogFactory { ...@@ -237,11 +252,9 @@ class TestSelectFileDialogFactory : public ui::SelectFileDialogFactory {
} }
}; };
PolicyUITest::PolicyUITest() { PolicyUITest::PolicyUITest() {}
}
PolicyUITest::~PolicyUITest() { PolicyUITest::~PolicyUITest() {}
}
void PolicyUITest::SetUpInProcessBrowserTestFixture() { void PolicyUITest::SetUpInProcessBrowserTestFixture() {
EXPECT_CALL(provider_, IsInitializationComplete(_)) EXPECT_CALL(provider_, IsInitializationComplete(_))
...@@ -266,7 +279,7 @@ void PolicyUITest::UpdateProviderPolicyForNamespace( ...@@ -266,7 +279,7 @@ void PolicyUITest::UpdateProviderPolicyForNamespace(
} }
void PolicyUITest::VerifyPolicies( void PolicyUITest::VerifyPolicies(
const std::vector<std::vector<std::string> >& expected_policies) { const std::vector<std::vector<std::string>>& expected_policies) {
ui_test_utils::NavigateToURL(browser(), GURL("chrome://policy")); ui_test_utils::NavigateToURL(browser(), GURL("chrome://policy"));
// Retrieve the text contents of the policy table cells for all policies. // Retrieve the text contents of the policy table cells for all policies.
...@@ -289,8 +302,8 @@ void PolicyUITest::VerifyPolicies( ...@@ -289,8 +302,8 @@ void PolicyUITest::VerifyPolicies(
content::WebContents* contents = content::WebContents* contents =
browser()->tab_strip_model()->GetActiveWebContents(); browser()->tab_strip_model()->GetActiveWebContents();
std::string json; std::string json;
ASSERT_TRUE(content::ExecuteScriptAndExtractString(contents, javascript, ASSERT_TRUE(
&json)); content::ExecuteScriptAndExtractString(contents, javascript, &json));
std::unique_ptr<base::Value> value_ptr = std::unique_ptr<base::Value> value_ptr =
base::JSONReader::ReadDeprecated(json); base::JSONReader::ReadDeprecated(json);
const base::ListValue* actual_policies = NULL; const base::ListValue* actual_policies = NULL;
...@@ -344,6 +357,24 @@ void PolicyUITest::VerifyExportingPolicies( ...@@ -344,6 +357,24 @@ void PolicyUITest::VerifyExportingPolicies(
base::DictionaryValue* actual_policies = nullptr; base::DictionaryValue* actual_policies = nullptr;
EXPECT_TRUE(value_ptr->GetAsDictionary(&actual_policies)); EXPECT_TRUE(value_ptr->GetAsDictionary(&actual_policies));
// Since Chrome Metadata has a lot of variations based on platform, OS,
// architecture and version, it is difficult to test for exact values. Test
// instead that the same keys exist in the meta data and also that the type of
// all the keys is a string. The incoming |expected| value should already be
// filled with the expected keys.
base::Value* chrome_metadata = actual_policies->FindKeyOfType(
"chromeMetadata", base::Value::Type::DICTIONARY);
EXPECT_NE(chrome_metadata, nullptr);
base::DictionaryValue* chrome_metadata_dict = nullptr;
EXPECT_TRUE(chrome_metadata->GetAsDictionary(&chrome_metadata_dict));
// The |chrome_metadata| we compare against will have the actual values so
// those will be cleared to empty values so that the equals comparison below
// will just compare key existence and value types.
for (auto& key_value : *chrome_metadata_dict)
*(key_value.second) = base::Value(key_value.second->type());
// Check that this dictionary is the same as expected. // Check that this dictionary is the same as expected.
EXPECT_EQ(expected, *actual_policies); EXPECT_EQ(expected, *actual_policies);
} }
...@@ -353,6 +384,8 @@ IN_PROC_BROWSER_TEST_F(PolicyUITest, WritePoliciesToJSONFile) { ...@@ -353,6 +384,8 @@ IN_PROC_BROWSER_TEST_F(PolicyUITest, WritePoliciesToJSONFile) {
policy::PolicyMap values; policy::PolicyMap values;
base::DictionaryValue expected_values; base::DictionaryValue expected_values;
SetChromeMetaData(&expected_values);
base::ListValue popups_blocked_for_urls; base::ListValue popups_blocked_for_urls;
popups_blocked_for_urls.AppendString("aaa"); popups_blocked_for_urls.AppendString("aaa");
popups_blocked_for_urls.AppendString("bbb"); popups_blocked_for_urls.AppendString("bbb");
...@@ -441,15 +474,14 @@ IN_PROC_BROWSER_TEST_F(PolicyUITest, SendPolicyNames) { ...@@ -441,15 +474,14 @@ IN_PROC_BROWSER_TEST_F(PolicyUITest, SendPolicyNames) {
// Expect that the policy table contains all known policies in alphabetical // Expect that the policy table contains all known policies in alphabetical
// order and none of the policies have a set value. // order and none of the policies have a set value.
std::vector<std::vector<std::string> > expected_policies; std::vector<std::vector<std::string>> expected_policies;
policy::Schema chrome_schema = policy::Schema chrome_schema =
policy::Schema::Wrap(policy::GetChromeSchemaData()); policy::Schema::Wrap(policy::GetChromeSchemaData());
ASSERT_TRUE(chrome_schema.valid()); ASSERT_TRUE(chrome_schema.valid());
for (policy::Schema::Iterator it = chrome_schema.GetPropertiesIterator(); for (policy::Schema::Iterator it = chrome_schema.GetPropertiesIterator();
!it.IsAtEnd(); it.Advance()) { !it.IsAtEnd(); it.Advance()) {
expected_policies.push_back( expected_policies.push_back(PopulateExpectedPolicy(
PopulateExpectedPolicy( it.key(), std::string(), std::string(), nullptr, false));
it.key(), std::string(), std::string(), nullptr, false));
} }
// Retrieve the contents of the policy table from the UI and verify that it // Retrieve the contents of the policy table from the UI and verify that it
...@@ -504,7 +536,7 @@ IN_PROC_BROWSER_TEST_F(PolicyUITest, SendPolicyValues) { ...@@ -504,7 +536,7 @@ IN_PROC_BROWSER_TEST_F(PolicyUITest, SendPolicyValues) {
// * All known policies whose value has been set, in alphabetical order. // * All known policies whose value has been set, in alphabetical order.
// * The unknown policy. // * The unknown policy.
// * All known policies whose value has not been set, in alphabetical order. // * All known policies whose value has not been set, in alphabetical order.
std::vector<std::vector<std::string> > expected_policies; std::vector<std::vector<std::string>> expected_policies;
size_t first_unset_position = 0; size_t first_unset_position = 0;
policy::Schema chrome_schema = policy::Schema chrome_schema =
policy::Schema::Wrap(policy::GetChromeSchemaData()); policy::Schema::Wrap(policy::GetChromeSchemaData());
...@@ -519,17 +551,14 @@ IN_PROC_BROWSER_TEST_F(PolicyUITest, SendPolicyValues) { ...@@ -519,17 +551,14 @@ IN_PROC_BROWSER_TEST_F(PolicyUITest, SendPolicyValues) {
it == expected_values.end() ? std::string() : "Cloud"; it == expected_values.end() ? std::string() : "Cloud";
const policy::PolicyMap::Entry* metadata = values.Get(props.key()); const policy::PolicyMap::Entry* metadata = values.Get(props.key());
expected_policies.insert( expected_policies.insert(
metadata ? expected_policies.begin() + first_unset_position++ : metadata ? expected_policies.begin() + first_unset_position++
expected_policies.end(), : expected_policies.end(),
PopulateExpectedPolicy(props.key(), value, source, metadata, false)); PopulateExpectedPolicy(props.key(), value, source, metadata, false));
} }
expected_policies.insert( expected_policies.insert(
expected_policies.begin() + first_unset_position++, expected_policies.begin() + first_unset_position++,
PopulateExpectedPolicy(kUnknownPolicy, PopulateExpectedPolicy(kUnknownPolicy, expected_values[kUnknownPolicy],
expected_values[kUnknownPolicy], "Platform", values.Get(kUnknownPolicy), true));
"Platform",
values.Get(kUnknownPolicy),
true));
expected_policies.insert( expected_policies.insert(
expected_policies.begin() + first_unset_position++, expected_policies.begin() + first_unset_position++,
PopulateExpectedPolicy( PopulateExpectedPolicy(
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "base/task/task_traits.h" #include "base/task/task_traits.h"
#include "base/time/time.h" #include "base/time/time.h"
...@@ -32,6 +34,8 @@ ...@@ -32,6 +34,8 @@
#include "chrome/browser/policy/schema_registry_service.h" #include "chrome/browser/policy/schema_registry_service.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/localized_string.h" #include "chrome/browser/ui/webui/localized_string.h"
#include "chrome/common/channel_info.h"
#include "chrome/grit/chromium_strings.h"
#include "components/policy/core/browser/browser_policy_connector.h" #include "components/policy/core/browser/browser_policy_connector.h"
#include "components/policy/core/browser/cloud/message_util.h" #include "components/policy/core/browser/cloud/message_util.h"
#include "components/policy/core/browser/configuration_policy_handler_list.h" #include "components/policy/core/browser/configuration_policy_handler_list.h"
...@@ -54,6 +58,7 @@ ...@@ -54,6 +58,7 @@
#include "components/policy/policy_constants.h" #include "components/policy/policy_constants.h"
#include "components/policy/proto/device_management_backend.pb.h" #include "components/policy/proto/device_management_backend.pb.h"
#include "components/strings/grit/components_strings.h" #include "components/strings/grit/components_strings.h"
#include "components/version_info/version_info.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "extensions/buildflags/buildflags.h" #include "extensions/buildflags/buildflags.h"
#include "google_apis/gaia/gaia_auth_util.h" #include "google_apis/gaia/gaia_auth_util.h"
...@@ -61,6 +66,10 @@ ...@@ -61,6 +66,10 @@
#include "ui/base/l10n/time_format.h" #include "ui/base/l10n/time_format.h"
#include "ui/shell_dialogs/select_file_policy.h" #include "ui/shell_dialogs/select_file_policy.h"
#if defined(OS_ANDROID)
#include "chrome/browser/ui/android/android_about_app_info.h"
#endif
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
#include "chrome/browser/browser_process_platform_part.h" #include "chrome/browser/browser_process_platform_part.h"
#include "chrome/browser/chromeos/policy/active_directory_policy_manager.h" #include "chrome/browser/chromeos/policy/active_directory_policy_manager.h"
...@@ -69,11 +78,16 @@ ...@@ -69,11 +78,16 @@
#include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h"
#include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chromeos/dbus/util/version_loader.h"
#include "components/user_manager/user_manager.h" #include "components/user_manager/user_manager.h"
#else #else
#include "components/policy/core/common/cloud/user_cloud_policy_manager.h" #include "components/policy/core/common/cloud/user_cloud_policy_manager.h"
#endif #endif
#if defined(OS_WIN)
#include "chrome/browser/ui/webui/version_util_win.h"
#endif
#if BUILDFLAG(ENABLE_EXTENSIONS) #if BUILDFLAG(ENABLE_EXTENSIONS)
#include "extensions/browser/extension_registry.h" #include "extensions/browser/extension_registry.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
...@@ -145,12 +159,12 @@ void GetStatusFromCore(const policy::CloudPolicyCore* core, ...@@ -145,12 +159,12 @@ void GetStatusFromCore(const policy::CloudPolicyCore* core,
if (policy && policy->has_gaia_id()) if (policy && policy->has_gaia_id())
dict->SetString("gaiaId", policy->gaia_id()); dict->SetString("gaiaId", policy->gaia_id());
base::TimeDelta refresh_interval = base::TimeDelta refresh_interval = base::TimeDelta::FromMilliseconds(
base::TimeDelta::FromMilliseconds(refresh_scheduler ? refresh_scheduler
refresh_scheduler->GetActualRefreshDelay() : ? refresh_scheduler->GetActualRefreshDelay()
policy::CloudPolicyRefreshScheduler::kDefaultRefreshDelayMs); : policy::CloudPolicyRefreshScheduler::kDefaultRefreshDelayMs);
base::Time last_refresh_time = refresh_scheduler ? base::Time last_refresh_time =
refresh_scheduler->last_refresh() : base::Time(); refresh_scheduler ? refresh_scheduler->last_refresh() : base::Time();
bool no_error = store->status() == policy::CloudPolicyStore::STATUS_OK && bool no_error = store->status() == policy::CloudPolicyStore::STATUS_OK &&
client && client->status() == policy::DM_STATUS_SUCCESS; client && client->status() == policy::DM_STATUS_SUCCESS;
...@@ -160,16 +174,17 @@ void GetStatusFromCore(const policy::CloudPolicyCore* core, ...@@ -160,16 +174,17 @@ void GetStatusFromCore(const policy::CloudPolicyCore* core,
dict->SetString("status", status); dict->SetString("status", status);
dict->SetString("clientId", client_id); dict->SetString("clientId", client_id);
dict->SetString("username", username); dict->SetString("username", username);
dict->SetString("refreshInterval", dict->SetString(
ui::TimeFormat::Simple(ui::TimeFormat::FORMAT_DURATION, "refreshInterval",
ui::TimeFormat::LENGTH_SHORT, ui::TimeFormat::Simple(ui::TimeFormat::FORMAT_DURATION,
refresh_interval)); ui::TimeFormat::LENGTH_SHORT, refresh_interval));
dict->SetString("timeSinceLastRefresh", last_refresh_time.is_null() ? dict->SetString(
l10n_util::GetStringUTF16(IDS_POLICY_NEVER_FETCHED) : "timeSinceLastRefresh",
ui::TimeFormat::Simple(ui::TimeFormat::FORMAT_ELAPSED, last_refresh_time.is_null()
ui::TimeFormat::LENGTH_SHORT, ? l10n_util::GetStringUTF16(IDS_POLICY_NEVER_FETCHED)
base::Time::NowFromSystemTime() - : ui::TimeFormat::Simple(
last_refresh_time)); ui::TimeFormat::FORMAT_ELAPSED, ui::TimeFormat::LENGTH_SHORT,
base::Time::NowFromSystemTime() - last_refresh_time));
} }
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
...@@ -407,7 +422,8 @@ void PolicyStatusProvider::NotifyStatusChange() { ...@@ -407,7 +422,8 @@ void PolicyStatusProvider::NotifyStatusChange() {
} }
CloudPolicyCoreStatusProvider::CloudPolicyCoreStatusProvider( CloudPolicyCoreStatusProvider::CloudPolicyCoreStatusProvider(
policy::CloudPolicyCore* core) : core_(core) { policy::CloudPolicyCore* core)
: core_(core) {
core_->store()->AddObserver(this); core_->store()->AddObserver(this);
// TODO(bartfab): Add an observer that watches for client errors. Observing // TODO(bartfab): Add an observer that watches for client errors. Observing
// core_->client() directly is not safe as the client may be destroyed and // core_->client() directly is not safe as the client may be destroyed and
...@@ -551,8 +567,7 @@ void DeviceCloudPolicyStatusProviderChromeOS::GetStatus( ...@@ -551,8 +567,7 @@ void DeviceCloudPolicyStatusProviderChromeOS::GetStatus(
DeviceLocalAccountPolicyStatusProvider::DeviceLocalAccountPolicyStatusProvider( DeviceLocalAccountPolicyStatusProvider::DeviceLocalAccountPolicyStatusProvider(
const std::string& user_id, const std::string& user_id,
policy::DeviceLocalAccountPolicyService* service) policy::DeviceLocalAccountPolicyService* service)
: user_id_(user_id), : user_id_(user_id), service_(service) {
service_(service) {
service_->AddObserver(this); service_->AddObserver(this);
} }
...@@ -664,9 +679,7 @@ void DeviceActiveDirectoryPolicyStatusProvider::GetStatus( ...@@ -664,9 +679,7 @@ void DeviceActiveDirectoryPolicyStatusProvider::GetStatus(
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
PolicyUIHandler::PolicyUIHandler() PolicyUIHandler::PolicyUIHandler() : weak_factory_(this) {}
: weak_factory_(this) {
}
PolicyUIHandler::~PolicyUIHandler() { PolicyUIHandler::~PolicyUIHandler() {
GetPolicyService()->RemoveObserver(policy::POLICY_DOMAIN_CHROME, this); GetPolicyService()->RemoveObserver(policy::POLICY_DOMAIN_CHROME, this);
...@@ -684,7 +697,7 @@ PolicyUIHandler::~PolicyUIHandler() { ...@@ -684,7 +697,7 @@ PolicyUIHandler::~PolicyUIHandler() {
} }
void PolicyUIHandler::AddCommonLocalizedStringsToSource( void PolicyUIHandler::AddCommonLocalizedStringsToSource(
content::WebUIDataSource* source) { content::WebUIDataSource* source) {
AddLocalizedStringsBulk(source, policy::kPolicySources, AddLocalizedStringsBulk(source, policy::kPolicySources,
policy::POLICY_SOURCE_COUNT); policy::POLICY_SOURCE_COUNT);
...@@ -871,7 +884,7 @@ base::Value PolicyUIHandler::GetPolicyNames() const { ...@@ -871,7 +884,7 @@ base::Value PolicyUIHandler::GetPolicyNames() const {
extensions::ExtensionRegistry::Get(profile)->enabled_extensions()) { extensions::ExtensionRegistry::Get(profile)->enabled_extensions()) {
// Skip this extension if it's not an enterprise extension. // Skip this extension if it's not an enterprise extension.
if (!extension->manifest()->HasPath( if (!extension->manifest()->HasPath(
extensions::manifest_keys::kStorageManagedSchema)) extensions::manifest_keys::kStorageManagedSchema))
continue; continue;
auto extension_value = std::make_unique<base::DictionaryValue>(); auto extension_value = std::make_unique<base::DictionaryValue>();
extension_value->SetString("name", extension->name()); extension_value->SetString("name", extension->name());
...@@ -1002,10 +1015,61 @@ void DoWritePoliciesToJSONFile(const base::FilePath& path, ...@@ -1002,10 +1015,61 @@ void DoWritePoliciesToJSONFile(const base::FilePath& path,
void PolicyUIHandler::WritePoliciesToJSONFile( void PolicyUIHandler::WritePoliciesToJSONFile(
const base::FilePath& path) const { const base::FilePath& path) const {
std::string json_policies = policy::GetAllPolicyValuesAsJSON( constexpr bool is_pretty_print = true;
base::Value dict = policy::GetAllPolicyValuesAsDictionary(
web_ui()->GetWebContents()->GetBrowserContext(), web_ui()->GetWebContents()->GetBrowserContext(),
true /* with_user_policies */, false /* with_device_data */, true /* with_user_policies */, false /* convert_values */,
true /* is_pretty_print */); false /* with_device_data */, is_pretty_print);
base::Value chrome_metadata(base::Value::Type::DICTIONARY);
chrome_metadata.SetKey(
"application", base::Value(l10n_util::GetStringUTF8(IDS_PRODUCT_NAME)));
std::string cohort_name;
#if defined(OS_WIN)
base::string16 cohort_version_info =
version_utils::win::GetCohortVersionInfo();
if (!cohort_version_info.empty()) {
cohort_name = base::StringPrintf(
" %s", base::UTF16ToUTF8(cohort_version_info).c_str());
}
#endif
std::string channel_name = chrome::GetChannelName();
std::string version = base::StringPrintf(
"%s (%s)%s %s%s", version_info::GetVersionNumber().c_str(),
l10n_util::GetStringUTF8(version_info::IsOfficialBuild()
? IDS_VERSION_UI_OFFICIAL
: IDS_VERSION_UI_UNOFFICIAL)
.c_str(),
(channel_name.empty() ? "" : " " + channel_name).c_str(),
l10n_util::GetStringUTF8(sizeof(void*) == 8 ? IDS_VERSION_UI_64BIT
: IDS_VERSION_UI_32BIT)
.c_str(),
cohort_name.c_str());
chrome_metadata.SetKey("version", base::Value(version));
#if defined(OS_CHROMEOS)
chrome_metadata.SetKey("platform",
base::Value(chromeos::version_loader::GetVersion(
chromeos::version_loader::VERSION_FULL)));
#else
std::string os = version_info::GetOSType();
#if defined(OS_WIN)
os += " " + version_utils::win::GetFullWindowsVersion();
#elif defined(OS_ANDROID)
os += " " + AndroidAboutAppInfo::GetOsInfo();
#endif
chrome_metadata.SetKey("OS", base::Value(os));
#endif
chrome_metadata.SetKey("revision",
base::Value(version_info::GetLastChange()));
dict.SetKey("chromeMetadata", std::move(chrome_metadata));
std::string json_policies;
base::JSONWriter::WriteWithOptions(
dict, (is_pretty_print ? base::JSONWriter::OPTIONS_PRETTY_PRINT : 0),
&json_policies);
base::PostTaskWithTraits( base::PostTaskWithTraits(
FROM_HERE, FROM_HERE,
......
...@@ -8,74 +8,9 @@ ...@@ -8,74 +8,9 @@
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "base/win/windows_version.h" #include "base/win/windows_version.h"
#include "chrome/browser/ui/webui/version_util_win.h"
#include "content/public/browser/web_ui.h" #include "content/public/browser/web_ui.h"
namespace {
// Return the marketing version of Windows OS, this may return an empty string
// if values returned by base::win::OSinfo are not defined below.
std::string FullWindowsVersion() {
std::string version;
base::win::OSInfo* gi = base::win::OSInfo::GetInstance();
const int major = gi->version_number().major;
const int minor = gi->version_number().minor;
const int build = gi->version_number().build;
const int patch = gi->version_number().patch;
// Server or Desktop
const bool server =
gi->version_type() == base::win::VersionType::SUITE_SERVER;
// Service Pack
const std::string sp = gi->service_pack_str();
if (major == 10) {
version += (server) ? "Server OS" : "10 OS";
} else if (major == 6) {
switch (minor) {
case 0:
// Windows Vista or Server 2008
version += (server) ? "Server 2008 " : "Vista ";
version += sp;
break;
case 1:
// Windows 7 or Server 2008 R2
version += (server) ? "Server 2008 R2 " : "7 ";
version += sp;
break;
case 2:
// Windows 8 or Server 2012
version += (server) ? "Server 2012" : "8";
break;
case 3:
// Windows 8.1 or Server 2012 R2
version += (server) ? "Server 2012 R2" : "8.1";
break;
default:
// unknown version
return base::StringPrintf("unknown version 6.%d", minor);
}
} else if ((major == 5) && (minor > 0)) {
// Windows XP or Server 2003
version += (server) ? "Server 2003 " : "XP ";
version += sp;
} else {
// unknown version
return base::StringPrintf("unknown version %d.%d", major, minor);
}
const std::string release_id = gi->release_id();
if (!release_id.empty())
version += " Version " + release_id;
if (patch > 0)
version += base::StringPrintf(" (Build %d.%d)", build, patch);
else
version += base::StringPrintf(" (Build %d)", build);
return version;
}
} // namespace
VersionHandlerWindows::VersionHandlerWindows() : weak_factory_(this) {} VersionHandlerWindows::VersionHandlerWindows() : weak_factory_(this) {}
VersionHandlerWindows::~VersionHandlerWindows() {} VersionHandlerWindows::~VersionHandlerWindows() {}
...@@ -85,7 +20,7 @@ void VersionHandlerWindows::HandleRequestVersionInfo( ...@@ -85,7 +20,7 @@ void VersionHandlerWindows::HandleRequestVersionInfo(
// Start the asynchronous load of the versions. // Start the asynchronous load of the versions.
base::PostTaskWithTraitsAndReplyWithResult( base::PostTaskWithTraitsAndReplyWithResult(
FROM_HERE, {base::MayBlock(), base::TaskPriority::BEST_EFFORT}, FROM_HERE, {base::MayBlock(), base::TaskPriority::BEST_EFFORT},
base::BindOnce(&FullWindowsVersion), base::BindOnce(&version_utils::win::GetFullWindowsVersion),
base::BindOnce(&VersionHandlerWindows::OnVersion, base::BindOnce(&VersionHandlerWindows::OnVersion,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
...@@ -100,5 +35,5 @@ void VersionHandlerWindows::OnVersion(const std::string& version) { ...@@ -100,5 +35,5 @@ void VersionHandlerWindows::OnVersion(const std::string& version) {
// static // static
std::string VersionHandlerWindows::GetFullWindowsVersionForTesting() { std::string VersionHandlerWindows::GetFullWindowsVersionForTesting() {
return FullWindowsVersion(); return version_utils::win::GetFullWindowsVersion();
} }
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "chrome/browser/chrome_content_browser_client.h" #include "chrome/browser/chrome_content_browser_client.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/version_handler.h" #include "chrome/browser/ui/webui/version_handler.h"
#include "chrome/browser/ui/webui/version_util_win.h"
#include "chrome/common/channel_info.h" #include "chrome/common/channel_info.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
#include "chrome/grit/chromium_strings.h" #include "chrome/grit/chromium_strings.h"
...@@ -40,7 +41,6 @@ ...@@ -40,7 +41,6 @@
#if defined(OS_WIN) #if defined(OS_WIN)
#include "chrome/browser/ui/webui/version_handler_win.h" #include "chrome/browser/ui/webui/version_handler_win.h"
#include "chrome/install_static/install_details.h"
#endif #endif
using content::WebUIDataSource; using content::WebUIDataSource;
...@@ -138,15 +138,8 @@ WebUIDataSource* CreateVersionUIDataSource() { ...@@ -138,15 +138,8 @@ WebUIDataSource* CreateVersionUIDataSource() {
#endif #endif
#if defined(OS_WIN) #if defined(OS_WIN)
base::string16 update_cohort_name = html_source->AddString(version_ui::kUpdateCohortName,
install_static::InstallDetails::Get().update_cohort_name(); version_utils::win::GetCohortVersionInfo());
if (!update_cohort_name.empty()) {
html_source->AddString(version_ui::kUpdateCohortName,
l10n_util::GetStringFUTF16(
IDS_VERSION_UI_COHORT_NAME, update_cohort_name));
} else {
html_source->AddString(version_ui::kUpdateCohortName, std::string());
}
#endif // defined(OS_WIN) #endif // defined(OS_WIN)
html_source->AddString(version_ui::kSanitizer, version_info::GetSanitizerList()); html_source->AddString(version_ui::kSanitizer, version_info::GetSanitizerList());
......
// Copyright 2019 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/ui/webui/version_util_win.h"
#include "base/strings/stringprintf.h"
#include "base/win/windows_version.h"
#include "chrome/install_static/install_details.h"
#include "components/strings/grit/components_strings.h"
#include "ui/base/l10n/l10n_util.h"
namespace version_utils {
namespace win {
std::string GetFullWindowsVersion() {
std::string version;
base::win::OSInfo* gi = base::win::OSInfo::GetInstance();
const int major = gi->version_number().major;
const int minor = gi->version_number().minor;
const int build = gi->version_number().build;
const int patch = gi->version_number().patch;
// Server or Desktop
const bool server =
gi->version_type() == base::win::VersionType::SUITE_SERVER;
// Service Pack
const std::string sp = gi->service_pack_str();
if (major == 10) {
version += (server) ? "Server OS" : "10 OS";
} else if (major == 6) {
switch (minor) {
case 0:
// Windows Vista or Server 2008
version += (server) ? "Server 2008 " : "Vista ";
version += sp;
break;
case 1:
// Windows 7 or Server 2008 R2
version += (server) ? "Server 2008 R2 " : "7 ";
version += sp;
break;
case 2:
// Windows 8 or Server 2012
version += (server) ? "Server 2012" : "8";
break;
case 3:
// Windows 8.1 or Server 2012 R2
version += (server) ? "Server 2012 R2" : "8.1";
break;
default:
// unknown version
return base::StringPrintf("unknown version 6.%d", minor);
}
} else if ((major == 5) && (minor > 0)) {
// Windows XP or Server 2003
version += (server) ? "Server 2003 " : "XP ";
version += sp;
} else {
// unknown version
return base::StringPrintf("unknown version %d.%d", major, minor);
}
const std::string release_id = gi->release_id();
if (!release_id.empty())
version += " Version " + release_id;
if (patch > 0)
version += base::StringPrintf(" (Build %d.%d)", build, patch);
else
version += base::StringPrintf(" (Build %d)", build);
return version;
}
base::string16 GetCohortVersionInfo() {
base::string16 update_cohort_name =
install_static::InstallDetails::Get().update_cohort_name();
if (!update_cohort_name.empty()) {
return l10n_util::GetStringFUTF16(IDS_VERSION_UI_COHORT_NAME,
update_cohort_name);
}
return base::string16();
}
} // namespace win
} // namespace version_utils
// Copyright 2019 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_UI_WEBUI_VERSION_UTIL_WIN_H_
#define CHROME_BROWSER_UI_WEBUI_VERSION_UTIL_WIN_H_
#include <string>
#include "base/strings/string16.h"
namespace version_utils {
namespace win {
// Return the marketing version of Windows OS, this may return an empty string
// if values returned by base::win::OSinfo are not defined.
std::string GetFullWindowsVersion();
// Return a formatted version of the update cohort string
// IDS_VERSION_UI_COHORT_NAME filled with the update cohort of this Chromium
// install.
base::string16 GetCohortVersionInfo();
} // namespace win
} // namespace version_utils
#endif // CHROME_BROWSER_UI_WEBUI_VERSION_UTIL_WIN_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