| Index: chrome/browser/ui/webui/policy_ui.cc
|
| diff --git a/chrome/browser/ui/webui/policy_ui.cc b/chrome/browser/ui/webui/policy_ui.cc
|
| index b0b861b8655127dee03a13816be05ca3e3b1f1ec..84dcf37094fa1a9bb7d6cd1a468bdb5a1c99f357 100644
|
| --- a/chrome/browser/ui/webui/policy_ui.cc
|
| +++ b/chrome/browser/ui/webui/policy_ui.cc
|
| @@ -5,6 +5,7 @@
|
| #include "chrome/browser/ui/webui/policy_ui.h"
|
|
|
| #include <stddef.h>
|
| +#include <string.h>
|
|
|
| #include "base/bind.h"
|
| #include "base/bind_helpers.h"
|
| @@ -34,6 +35,7 @@
|
| #include "components/policy/core/common/cloud/cloud_policy_refresh_scheduler.h"
|
| #include "components/policy/core/common/cloud/cloud_policy_store.h"
|
| #include "components/policy/core/common/cloud/cloud_policy_validator.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_service.h"
|
| @@ -49,8 +51,11 @@
|
| #include "google_apis/gaia/gaia_auth_util.h"
|
| #include "grit/browser_resources.h"
|
| #include "grit/components_strings.h"
|
| +#include "grit/policy_resources.h"
|
| +#include "grit/policy_resources_map.h"
|
| #include "policy/policy_constants.h"
|
| #include "policy/proto/device_management_backend.pb.h"
|
| +#include "policy/risk_tag.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
| #include "ui/base/l10n/time_format.h"
|
|
|
| @@ -79,30 +84,48 @@ namespace em = enterprise_management;
|
|
|
| namespace {
|
|
|
| -struct PolicySourceMap {
|
| +struct PolicyStringMap {
|
| const char* key;
|
| int string_id;
|
| };
|
|
|
| // Strings that map from PolicySource enum to i18n string keys and their IDs.
|
| -const PolicySourceMap kPolicySources[policy::POLICY_SOURCE_COUNT] = {
|
| +const PolicyStringMap kPolicySources[policy::POLICY_SOURCE_COUNT] = {
|
| {"sourceEnterpriseDefault", IDS_POLICY_SOURCE_ENTERPRISE_DEFAULT},
|
| {"sourceCloud", IDS_POLICY_SOURCE_CLOUD},
|
| {"sourceEnterpriseOverride", IDS_POLICY_SOURCE_ENTERPRISE_OVERRIDE},
|
| {"sourcePlatform", IDS_POLICY_SOURCE_PLATFORM}
|
| };
|
|
|
| -void AddLocalizedPoilcySourceStrings(content::WebUIDataSource* source) {
|
| - DCHECK_EQ(static_cast<size_t>(policy::POLICY_SOURCE_COUNT),
|
| - arraysize(kPolicySources));
|
| - for (size_t i = 0; i < arraysize(kPolicySources); ++i) {
|
| - source->AddLocalizedString(kPolicySources[i].key,
|
| - kPolicySources[i].string_id);
|
| - }
|
| +// Strings that map from policy::RiskTag enum to i18n string keys and their IDs.
|
| +const PolicyStringMap kPolicyRiskTags[policy::RISK_TAG_COUNT] = {
|
| + {"fullAdminAccess", IDS_POLICY_RISK_TAG_FULL_ADMIN_ACCESS},
|
| + {"systemSecurity", IDS_POLICY_RISK_TAG_SYSTEM_SECURITY},
|
| + {"websiteSharing", IDS_POLICY_RISK_TAG_WEBSITE_SHARING},
|
| + {"adminSharing", IDS_POLICY_RISK_TAG_ADMIN_SHARING},
|
| + {"filtering", IDS_POLICY_RISK_TAG_FILTERING},
|
| + {"localDataAccess", IDS_POLICY_RISK_TAG_LOCAL_DATA_ACCESS},
|
| + {"googleSharing", IDS_POLICY_RISK_TAG_GOOGLE_SHARING}
|
| +};
|
| +
|
| +void AddLocalizedPoilcyStrings(content::WebUIDataSource* source,
|
| + const PolicyStringMap* map,
|
| + size_t count) {
|
| + for (size_t i = 0; i < count; ++i)
|
| + source->AddLocalizedString(map[i].key, map[i].string_id);
|
| }
|
|
|
| void AddCommonLocalizedStringsToSource(content::WebUIDataSource* source) {
|
| + AddLocalizedPoilcyStrings(source, kPolicySources,
|
| + static_cast<size_t>(policy::POLICY_SOURCE_COUNT));
|
| source->AddLocalizedString("title", IDS_POLICY_TITLE);
|
| + source->SetJsonPath("strings.js");
|
| +}
|
| +
|
| +content::WebUIDataSource* CreatePolicyUIHTMLSource() {
|
| + content::WebUIDataSource* source =
|
| + content::WebUIDataSource::Create(chrome::kChromeUIPolicyHost);
|
| + AddCommonLocalizedStringsToSource(source);
|
| source->AddLocalizedString("filterPlaceholder",
|
| IDS_POLICY_FILTER_PLACEHOLDER);
|
| source->AddLocalizedString("reloadPolicies", IDS_POLICY_RELOAD_POLICIES);
|
| @@ -141,31 +164,27 @@ void AddCommonLocalizedStringsToSource(content::WebUIDataSource* source) {
|
| source->AddLocalizedString("unset", IDS_POLICY_UNSET);
|
| source->AddLocalizedString("unknown", IDS_POLICY_UNKNOWN);
|
| source->AddLocalizedString("notSpecified", IDS_POLICY_NOT_SPECIFIED);
|
| - AddLocalizedPoilcySourceStrings(source);
|
| -
|
| - source->SetJsonPath("strings.js");
|
| + AddLocalizedPoilcyStrings(source, kPolicyRiskTags,
|
| + static_cast<size_t>(policy::RISK_TAG_COUNT));
|
| + // Add required resources.
|
| + source->AddResourcePath("policy.css", IDR_POLICY_CSS);
|
| + source->AddResourcePath("policy.js", IDR_POLICY_JS);
|
| + source->AddResourcePath("uber_utils.js", IDR_UBER_UTILS_JS);
|
| + source->SetDefaultResource(IDR_POLICY_HTML);
|
| + return source;
|
| }
|
|
|
| content::WebUIDataSource* CreatePolicyMaterialDesignUIHTMLSource() {
|
| content::WebUIDataSource* source =
|
| content::WebUIDataSource::Create(chrome::kChromeUIMdPolicyHost);
|
| AddCommonLocalizedStringsToSource(source);
|
| + AddLocalizedPoilcyStrings(source, kPolicyRiskTags,
|
| + static_cast<size_t>(policy::RISK_TAG_COUNT));
|
| + for (size_t i = 0; i < kPolicyResourcesSize; ++i) {
|
| + source->AddResourcePath(kPolicyResources[i].name,
|
| + kPolicyResources[i].value);
|
| + }
|
| source->SetDefaultResource(IDR_MD_POLICY_HTML);
|
| -
|
| - return source;
|
| -}
|
| -
|
| -
|
| -content::WebUIDataSource* CreatePolicyUIHTMLSource() {
|
| - content::WebUIDataSource* source =
|
| - content::WebUIDataSource::Create(chrome::kChromeUIPolicyHost);
|
| - AddCommonLocalizedStringsToSource(source);
|
| - // Add required resources.
|
| - source->AddResourcePath("policy.css", IDR_POLICY_CSS);
|
| - source->AddResourcePath("policy.js", IDR_POLICY_JS);
|
| - source->AddResourcePath("uber_utils.js", IDR_UBER_UTILS_JS);
|
| - source->SetDefaultResource(IDR_POLICY_HTML);
|
| -
|
| return source;
|
| }
|
|
|
| @@ -419,10 +438,14 @@ class PolicyUIHandler : public content::WebUIMessageHandler,
|
| // policy::SchemaRegistry::Observer implementation.
|
| void OnSchemaRegistryUpdated(bool has_new_schemas) override;
|
|
|
| - private:
|
| + protected:
|
| + virtual void AddPolicyName(base::DictionaryValue* names,
|
| + const std::string& name) const;
|
| +
|
| // Send a dictionary containing the names of all known policies to the UI.
|
| - void SendPolicyNames() const;
|
| + virtual void SendPolicyNames() const;
|
|
|
| + private:
|
| // Send information about the current policy values to the UI. For each policy
|
| // whose value has been set, a dictionary containing the value and additional
|
| // metadata is sent.
|
| @@ -461,6 +484,22 @@ class PolicyUIHandler : public content::WebUIMessageHandler,
|
| DISALLOW_COPY_AND_ASSIGN(PolicyUIHandler);
|
| };
|
|
|
| +// The JavaScript message handler for the chrome://md-policy page.
|
| +class PolicyMaterialDesignUIHandler : public PolicyUIHandler {
|
| + public:
|
| + PolicyMaterialDesignUIHandler();
|
| + ~PolicyMaterialDesignUIHandler() override;
|
| +
|
| + protected:
|
| + // PolicyUIHandler:
|
| + void AddPolicyName(base::DictionaryValue* names,
|
| + const std::string& name) const override;
|
| + void SendPolicyNames() const override;
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(PolicyMaterialDesignUIHandler);
|
| +};
|
| +
|
| CloudPolicyStatusProvider::CloudPolicyStatusProvider() {
|
| }
|
|
|
| @@ -689,6 +728,11 @@ void PolicyUIHandler::OnPolicyUpdated(const policy::PolicyNamespace& ns,
|
| SendPolicyValues();
|
| }
|
|
|
| +void PolicyUIHandler::AddPolicyName(base::DictionaryValue* names,
|
| + const std::string& name) const {
|
| + names->SetBoolean(name, true);
|
| +}
|
| +
|
| void PolicyUIHandler::SendPolicyNames() const {
|
| base::DictionaryValue names;
|
|
|
| @@ -704,7 +748,7 @@ void PolicyUIHandler::SendPolicyNames() const {
|
| const policy::Schema* chrome_schema = schema_map->GetSchema(chrome_ns);
|
| for (policy::Schema::Iterator it = chrome_schema->GetPropertiesIterator();
|
| !it.IsAtEnd(); it.Advance()) {
|
| - chrome_policy_names->SetBoolean(it.key(), true);
|
| + AddPolicyName(chrome_policy_names, it.key());
|
| }
|
| names.Set("chromePolicyNames", chrome_policy_names);
|
|
|
| @@ -874,6 +918,31 @@ policy::PolicyService* PolicyUIHandler::GetPolicyService() const {
|
| web_ui()->GetWebContents()->GetBrowserContext())->policy_service();
|
| }
|
|
|
| +PolicyMaterialDesignUIHandler::PolicyMaterialDesignUIHandler() {
|
| +}
|
| +
|
| +PolicyMaterialDesignUIHandler::~PolicyMaterialDesignUIHandler() {
|
| +}
|
| +
|
| +void PolicyMaterialDesignUIHandler::AddPolicyName(
|
| + base::DictionaryValue* names, const std::string& name) const {
|
| + scoped_ptr<base::ListValue> list = make_scoped_ptr(new base::ListValue());
|
| + const policy::RiskTag* tags = policy::GetChromePolicyDetails(name)->risk_tags;
|
| + for (size_t i = 0; i < policy::kMaxRiskTagCount; ++i)
|
| + if (tags[i] != policy::RISK_TAG_NONE)
|
| + list->AppendString(kPolicyRiskTags[tags[i]].key);
|
| + names->Set(name, list.Pass());
|
| +}
|
| +
|
| +void PolicyMaterialDesignUIHandler::SendPolicyNames() const {
|
| + base::ListValue tags;
|
| + for (size_t tag = 0; tag < policy::RISK_TAG_COUNT; ++tag)
|
| + tags.AppendString(kPolicyRiskTags[tag].key);
|
| +
|
| + web_ui()->CallJavascriptFunction("policy.Page.setPolicyGroups", tags);
|
| + PolicyUIHandler::SendPolicyNames();
|
| +}
|
| +
|
| PolicyUI::PolicyUI(content::WebUI* web_ui) : WebUIController(web_ui) {
|
| web_ui->AddMessageHandler(new PolicyUIHandler);
|
| content::WebUIDataSource::Add(Profile::FromWebUI(web_ui),
|
| @@ -885,7 +954,7 @@ PolicyUI::~PolicyUI() {
|
|
|
| PolicyMaterialDesignUI::PolicyMaterialDesignUI(content::WebUI* web_ui) :
|
| WebUIController(web_ui) {
|
| - web_ui->AddMessageHandler(new PolicyUIHandler);
|
| + web_ui->AddMessageHandler(new PolicyMaterialDesignUIHandler);
|
| content::WebUIDataSource::Add(Profile::FromWebUI(web_ui),
|
| CreatePolicyMaterialDesignUIHTMLSource());
|
| }
|
|
|