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

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

Issue 1304843004: Add source column to chrome://policy showing the origins of policies. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed another test. Created 5 years, 3 months 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/policy_ui.h" 5 #include "chrome/browser/ui/webui/policy_ui.h"
6 6
7 #include <stddef.h>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
9 #include "base/callback.h" 11 #include "base/callback.h"
10 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
11 #include "base/json/json_writer.h" 13 #include "base/json/json_writer.h"
12 #include "base/logging.h" 14 #include "base/logging.h"
13 #include "base/memory/scoped_ptr.h" 15 #include "base/macros.h"
14 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
15 #include "base/strings/string16.h" 17 #include "base/strings/string16.h"
16 #include "base/time/time.h" 18 #include "base/time/time.h"
17 #include "base/values.h" 19 #include "base/values.h"
18 #include "chrome/browser/browser_process.h" 20 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/policy/profile_policy_connector.h" 21 #include "chrome/browser/policy/profile_policy_connector.h"
20 #include "chrome/browser/policy/profile_policy_connector_factory.h" 22 #include "chrome/browser/policy/profile_policy_connector_factory.h"
21 #include "chrome/browser/policy/schema_registry_service.h" 23 #include "chrome/browser/policy/schema_registry_service.h"
22 #include "chrome/browser/policy/schema_registry_service_factory.h" 24 #include "chrome/browser/policy/schema_registry_service_factory.h"
23 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 #include "extensions/browser/extension_registry_observer.h" 72 #include "extensions/browser/extension_registry_observer.h"
71 #include "extensions/common/extension.h" 73 #include "extensions/common/extension.h"
72 #include "extensions/common/manifest.h" 74 #include "extensions/common/manifest.h"
73 #include "extensions/common/manifest_constants.h" 75 #include "extensions/common/manifest_constants.h"
74 #endif 76 #endif
75 77
76 namespace em = enterprise_management; 78 namespace em = enterprise_management;
77 79
78 namespace { 80 namespace {
79 81
82 struct PolicySourceMap {
83 const char* key;
84 int string_id;
85 };
86
87 // Strings that map from PolicySource enum to i18n string keys and their IDs.
88 const PolicySourceMap kPolicySources[policy::POLICY_SOURCE_COUNT] = {
89 {"sourceEnterpriseDefault", IDS_POLICY_SOURCE_ENTERPRISE_DEFAULT},
90 {"sourceCloud", IDS_POLICY_SOURCE_CLOUD},
91 {"sourceEnterpriseOverride", IDS_POLICY_SOURCE_ENTERPRISE_OVERRIDE},
92 {"sourcePlatform", IDS_POLICY_SOURCE_PLATFORM}
93 };
94
95 void AddLocalizedPoilcySourceStrings(content::WebUIDataSource* source) {
96 DCHECK_EQ(static_cast<size_t>(policy::POLICY_SOURCE_COUNT),
97 arraysize(kPolicySources));
98 for (size_t i = 0; i < arraysize(kPolicySources); ++i) {
99 source->AddLocalizedString(kPolicySources[i].key,
100 kPolicySources[i].string_id);
101 }
102 }
103
80 content::WebUIDataSource* CreatePolicyUIHTMLSource() { 104 content::WebUIDataSource* CreatePolicyUIHTMLSource() {
81 content::WebUIDataSource* source = 105 content::WebUIDataSource* source =
82 content::WebUIDataSource::Create(chrome::kChromeUIPolicyHost); 106 content::WebUIDataSource::Create(chrome::kChromeUIPolicyHost);
83 107
84 // Localized strings. 108 // Localized strings.
85 source->AddLocalizedString("title", IDS_POLICY_TITLE); 109 source->AddLocalizedString("title", IDS_POLICY_TITLE);
86 source->AddLocalizedString("filterPlaceholder", 110 source->AddLocalizedString("filterPlaceholder",
87 IDS_POLICY_FILTER_PLACEHOLDER); 111 IDS_POLICY_FILTER_PLACEHOLDER);
88 source->AddLocalizedString("reloadPolicies", IDS_POLICY_RELOAD_POLICIES); 112 source->AddLocalizedString("reloadPolicies", IDS_POLICY_RELOAD_POLICIES);
89 source->AddLocalizedString("status", IDS_POLICY_STATUS); 113 source->AddLocalizedString("status", IDS_POLICY_STATUS);
(...skipping 11 matching lines...) Expand all
101 source->AddLocalizedString("labelRefreshInterval", 125 source->AddLocalizedString("labelRefreshInterval",
102 IDS_POLICY_LABEL_REFRESH_INTERVAL); 126 IDS_POLICY_LABEL_REFRESH_INTERVAL);
103 source->AddLocalizedString("labelStatus", IDS_POLICY_LABEL_STATUS); 127 source->AddLocalizedString("labelStatus", IDS_POLICY_LABEL_STATUS);
104 source->AddLocalizedString("showUnset", IDS_POLICY_SHOW_UNSET); 128 source->AddLocalizedString("showUnset", IDS_POLICY_SHOW_UNSET);
105 source->AddLocalizedString("noPoliciesSet", IDS_POLICY_NO_POLICIES_SET); 129 source->AddLocalizedString("noPoliciesSet", IDS_POLICY_NO_POLICIES_SET);
106 source->AddLocalizedString("headerScope", IDS_POLICY_HEADER_SCOPE); 130 source->AddLocalizedString("headerScope", IDS_POLICY_HEADER_SCOPE);
107 source->AddLocalizedString("headerLevel", IDS_POLICY_HEADER_LEVEL); 131 source->AddLocalizedString("headerLevel", IDS_POLICY_HEADER_LEVEL);
108 source->AddLocalizedString("headerName", IDS_POLICY_HEADER_NAME); 132 source->AddLocalizedString("headerName", IDS_POLICY_HEADER_NAME);
109 source->AddLocalizedString("headerValue", IDS_POLICY_HEADER_VALUE); 133 source->AddLocalizedString("headerValue", IDS_POLICY_HEADER_VALUE);
110 source->AddLocalizedString("headerStatus", IDS_POLICY_HEADER_STATUS); 134 source->AddLocalizedString("headerStatus", IDS_POLICY_HEADER_STATUS);
135 source->AddLocalizedString("headerSource", IDS_POLICY_HEADER_SOURCE);
111 source->AddLocalizedString("showExpandedValue", 136 source->AddLocalizedString("showExpandedValue",
112 IDS_POLICY_SHOW_EXPANDED_VALUE); 137 IDS_POLICY_SHOW_EXPANDED_VALUE);
113 source->AddLocalizedString("hideExpandedValue", 138 source->AddLocalizedString("hideExpandedValue",
114 IDS_POLICY_HIDE_EXPANDED_VALUE); 139 IDS_POLICY_HIDE_EXPANDED_VALUE);
115 source->AddLocalizedString("scopeUser", IDS_POLICY_SCOPE_USER); 140 source->AddLocalizedString("scopeUser", IDS_POLICY_SCOPE_USER);
116 source->AddLocalizedString("scopeDevice", IDS_POLICY_SCOPE_DEVICE); 141 source->AddLocalizedString("scopeDevice", IDS_POLICY_SCOPE_DEVICE);
117 source->AddLocalizedString("levelRecommended", IDS_POLICY_LEVEL_RECOMMENDED); 142 source->AddLocalizedString("levelRecommended", IDS_POLICY_LEVEL_RECOMMENDED);
118 source->AddLocalizedString("levelMandatory", IDS_POLICY_LEVEL_MANDATORY); 143 source->AddLocalizedString("levelMandatory", IDS_POLICY_LEVEL_MANDATORY);
119 source->AddLocalizedString("ok", IDS_POLICY_OK); 144 source->AddLocalizedString("ok", IDS_POLICY_OK);
120 source->AddLocalizedString("unset", IDS_POLICY_UNSET); 145 source->AddLocalizedString("unset", IDS_POLICY_UNSET);
121 source->AddLocalizedString("unknown", IDS_POLICY_UNKNOWN); 146 source->AddLocalizedString("unknown", IDS_POLICY_UNKNOWN);
122 source->AddLocalizedString("notSpecified", IDS_POLICY_NOT_SPECIFIED); 147 source->AddLocalizedString("notSpecified", IDS_POLICY_NOT_SPECIFIED);
148 AddLocalizedPoilcySourceStrings(source);
123 149
124 source->SetJsonPath("strings.js"); 150 source->SetJsonPath("strings.js");
125 151
126 // Add required resources. 152 // Add required resources.
127 source->AddResourcePath("policy.css", IDR_POLICY_CSS); 153 source->AddResourcePath("policy.css", IDR_POLICY_CSS);
128 source->AddResourcePath("policy.js", IDR_POLICY_JS); 154 source->AddResourcePath("policy.js", IDR_POLICY_JS);
129 source->AddResourcePath("uber_utils.js", IDR_UBER_UTILS_JS); 155 source->AddResourcePath("uber_utils.js", IDR_UBER_UTILS_JS);
130 source->SetDefaultResource(IDR_POLICY_HTML); 156 source->SetDefaultResource(IDR_POLICY_HTML);
131 157
132 return source; 158 return source;
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 base::DictionaryValue* value = new base::DictionaryValue; 771 base::DictionaryValue* value = new base::DictionaryValue;
746 value->Set("value", CopyAndConvert(entry->second.value).release()); 772 value->Set("value", CopyAndConvert(entry->second.value).release());
747 if (entry->second.scope == policy::POLICY_SCOPE_USER) 773 if (entry->second.scope == policy::POLICY_SCOPE_USER)
748 value->SetString("scope", "user"); 774 value->SetString("scope", "user");
749 else 775 else
750 value->SetString("scope", "machine"); 776 value->SetString("scope", "machine");
751 if (entry->second.level == policy::POLICY_LEVEL_RECOMMENDED) 777 if (entry->second.level == policy::POLICY_LEVEL_RECOMMENDED)
752 value->SetString("level", "recommended"); 778 value->SetString("level", "recommended");
753 else 779 else
754 value->SetString("level", "mandatory"); 780 value->SetString("level", "mandatory");
781 value->SetString("source", kPolicySources[entry->second.source].key);
755 base::string16 error = errors->GetErrors(entry->first); 782 base::string16 error = errors->GetErrors(entry->first);
756 if (!error.empty()) 783 if (!error.empty())
757 value->SetString("error", error); 784 value->SetString("error", error);
758 values->Set(entry->first, value); 785 values->Set(entry->first, value);
759 } 786 }
760 } 787 }
761 788
762 void PolicyUIHandler::GetChromePolicyValues( 789 void PolicyUIHandler::GetChromePolicyValues(
763 base::DictionaryValue* values) const { 790 base::DictionaryValue* values) const {
764 policy::PolicyService* policy_service = GetPolicyService(); 791 policy::PolicyService* policy_service = GetPolicyService();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 } 864 }
838 865
839 PolicyUI::PolicyUI(content::WebUI* web_ui) : WebUIController(web_ui) { 866 PolicyUI::PolicyUI(content::WebUI* web_ui) : WebUIController(web_ui) {
840 web_ui->AddMessageHandler(new PolicyUIHandler); 867 web_ui->AddMessageHandler(new PolicyUIHandler);
841 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), 868 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui),
842 CreatePolicyUIHTMLSource()); 869 CreatePolicyUIHTMLSource());
843 } 870 }
844 871
845 PolicyUI::~PolicyUI() { 872 PolicyUI::~PolicyUI() {
846 } 873 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/preferences_browsertest.cc ('k') | chrome/browser/ui/webui/policy_ui_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698