Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: chrome/browser/ui/webui/policy_material_design_ui.cc

Issue 1395073002: Policy Ui sends correct translations for risk tags. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Description corrected. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/webui/policy_material_design_ui.h"
6
7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/ui/webui/policy_ui_handler.h"
9 #include "chrome/common/url_constants.h"
10 #include "components/policy/core/common/policy_types.h"
11 #include "grit/components_strings.h"
12 #include "grit/policy_resources.h"
13 #include "grit/policy_resources_map.h"
14 #include "policy/policy_constants.h"
15 #include "policy/risk_tag.h"
16
17 namespace {
18
19 // Strings that map from policy::RiskTag enum to i18n string keys and their IDs.
20 // Their order has to follow the order of the policy::RiskTag enum.
21 const PolicyStringMap kPolicyRiskTags[policy::RISK_TAG_COUNT] = {
22 {"fullAdminAccess", IDS_POLICY_RISK_TAG_FULL_ADMIN_ACCESS},
23 {"systemSecurity", IDS_POLICY_RISK_TAG_SYSTEM_SECURITY},
24 {"websiteSharing", IDS_POLICY_RISK_TAG_WEBSITE_SHARING},
25 {"adminSharing", IDS_POLICY_RISK_TAG_ADMIN_SHARING},
26 {"filtering", IDS_POLICY_RISK_TAG_FILTERING},
27 {"localDataAccess", IDS_POLICY_RISK_TAG_LOCAL_DATA_ACCESS},
28 {"googleSharing", IDS_POLICY_RISK_TAG_GOOGLE_SHARING},
29 };
30
31 content::WebUIDataSource* CreatePolicyMaterialDesignUIHtmlSource() {
32 content::WebUIDataSource* source =
33 content::WebUIDataSource::Create(chrome::kChromeUIMdPolicyHost);
34 PolicyUIHandler::AddCommonLocalizedStringsToSource(source);
35 PolicyUIHandler::AddLocalizedPolicyStrings(
36 source, kPolicyRiskTags, static_cast<size_t>(policy::RISK_TAG_COUNT));
37 for (size_t i = 0; i < kPolicyResourcesSize; ++i) {
38 source->AddResourcePath(kPolicyResources[i].name,
39 kPolicyResources[i].value);
40 }
41 source->SetDefaultResource(IDR_MD_POLICY_HTML);
42 return source;
43 }
44
45 } // namespace
46
47 // The JavaScript message handler for the chrome://md-policy page.
48 class PolicyMaterialDesignUIHandler : public PolicyUIHandler {
49 public:
50 PolicyMaterialDesignUIHandler();
51 ~PolicyMaterialDesignUIHandler() override;
52
53 protected:
54 // PolicyUIHandler:
55 void AddPolicyName(const std::string& name,
56 base::DictionaryValue* names) const override;
57 void SendPolicyNames() const override;
58
59 private:
60 DISALLOW_COPY_AND_ASSIGN(PolicyMaterialDesignUIHandler);
61 };
62
63 PolicyMaterialDesignUIHandler::PolicyMaterialDesignUIHandler() {
64 }
65
66 PolicyMaterialDesignUIHandler::~PolicyMaterialDesignUIHandler() {
67 }
68
69 void PolicyMaterialDesignUIHandler::AddPolicyName(
70 const std::string& name, base::DictionaryValue* names) const {
71 scoped_ptr<base::ListValue> list(new base::ListValue());
72 const policy::RiskTag* tags = policy::GetChromePolicyDetails(name)->risk_tags;
73 for (size_t i = 0; i < policy::kMaxRiskTagCount; ++i) {
74 if (tags[i] != policy::RISK_TAG_NONE)
75 list->AppendString(kPolicyRiskTags[tags[i]].key);
76 }
77 names->Set(name, list.Pass());
78 }
79
80 void PolicyMaterialDesignUIHandler::SendPolicyNames() const {
81 base::ListValue tags;
82 for (size_t tag = 0; tag < policy::RISK_TAG_COUNT; ++tag)
83 tags.AppendString(kPolicyRiskTags[tag].key);
84
85 web_ui()->CallJavascriptFunction("policy.Page.setPolicyGroups", tags);
86 PolicyUIHandler::SendPolicyNames();
87 }
88
89 PolicyMaterialDesignUI::PolicyMaterialDesignUI(content::WebUI* web_ui) :
90 WebUIController(web_ui) {
91 web_ui->AddMessageHandler(new PolicyMaterialDesignUIHandler);
92 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui),
93 CreatePolicyMaterialDesignUIHtmlSource());
94 }
95
96 PolicyMaterialDesignUI::~PolicyMaterialDesignUI() {
97 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/policy_material_design_ui.h ('k') | chrome/browser/ui/webui/policy_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698