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

Unified Diff: chrome/browser/ui/webui/policy_ui.cc

Issue 17387002: Sending known policy names for extensions to chrome://policy page (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@anita-policies
Patch Set: Responding to Joao's comments on PS6 Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
« chrome/browser/resources/policy.js ('K') | « chrome/browser/resources/policy.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 7b25f19e17fa42badb2cc807e33701a65aa168ff..ac2d1020d82f7f91c98f7975c50c00329ce7dffb 100644
--- a/chrome/browser/ui/webui/policy_ui.cc
+++ b/chrome/browser/ui/webui/policy_ui.cc
@@ -26,8 +26,10 @@
#include "chrome/browser/policy/cloud/cloud_policy_validator.h"
#include "chrome/browser/policy/cloud/message_util.h"
#include "chrome/browser/policy/configuration_policy_handler_list.h"
+#include "chrome/browser/policy/policy_domain_descriptor.h"
#include "chrome/browser/policy/policy_error_map.h"
#include "chrome/browser/policy/policy_map.h"
+#include "chrome/browser/policy/policy_schema.h"
#include "chrome/browser/policy/policy_service.h"
#include "chrome/browser/policy/policy_types.h"
#include "chrome/browser/policy/profile_policy_connector.h"
@@ -39,6 +41,8 @@
#include "chrome/common/extensions/manifest.h"
#include "chrome/common/time_format.h"
#include "chrome/common/url_constants.h"
+#include "content/public/browser/notification_observer.h"
+#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h"
#include "content/public/browser/web_ui_message_handler.h"
@@ -263,12 +267,18 @@ class DeviceLocalAccountPolicyStatusProvider
#endif
// The JavaScript message handler for the chrome://policy page.
-class PolicyUIHandler : public content::WebUIMessageHandler,
+class PolicyUIHandler : public content::NotificationObserver,
+ public content::WebUIMessageHandler,
public policy::PolicyService::Observer {
public:
PolicyUIHandler();
virtual ~PolicyUIHandler();
+ // content::NotificationObserver implementation.
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE;
+
// content::WebUIMessageHandler implementation.
virtual void RegisterMessages() OVERRIDE;
@@ -316,6 +326,8 @@ class PolicyUIHandler : public content::WebUIMessageHandler,
scoped_ptr<CloudPolicyStatusProvider> user_status_provider_;
scoped_ptr<CloudPolicyStatusProvider> device_status_provider_;
+ content::NotificationRegistrar registrar_;
+
DISALLOW_COPY_AND_ASSIGN(PolicyUIHandler);
};
@@ -488,6 +500,13 @@ void PolicyUIHandler::RegisterMessages() {
GetPolicyService()->AddObserver(policy::POLICY_DOMAIN_CHROME, this);
GetPolicyService()->AddObserver(policy::POLICY_DOMAIN_EXTENSIONS, this);
+ registrar_.Add(this,
+ chrome::NOTIFICATION_EXTENSION_LOADED,
+ content::NotificationService::AllSources());
+ registrar_.Add(this,
+ chrome::NOTIFICATION_EXTENSION_UNLOADED,
+ content::NotificationService::AllSources());
+
web_ui()->RegisterMessageCallback(
"initialized",
base::Bind(&PolicyUIHandler::HandleInitialized, base::Unretained(this)));
@@ -497,6 +516,15 @@ void PolicyUIHandler::RegisterMessages() {
base::Unretained(this)));
}
+void PolicyUIHandler::Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ DCHECK(type == chrome::NOTIFICATION_EXTENSION_LOADED ||
+ type == chrome::NOTIFICATION_EXTENSION_UNLOADED);
+ SendPolicyNames();
+ SendPolicyValues();
+}
+
void PolicyUIHandler::OnPolicyUpdated(const policy::PolicyNamespace& ns,
const policy::PolicyMap& previous,
const policy::PolicyMap& current) {
@@ -505,12 +533,67 @@ void PolicyUIHandler::OnPolicyUpdated(const policy::PolicyNamespace& ns,
void PolicyUIHandler::SendPolicyNames() const {
base::DictionaryValue names;
+
+ // Add Chrome policy names.
+ base::DictionaryValue* chrome_policy_names = new base::DictionaryValue;
const policy::PolicyDefinitionList* list =
policy::GetChromePolicyDefinitionList();
for (const policy::PolicyDefinitionList::Entry* entry = list->begin;
entry != list->end; ++entry) {
- names.SetBoolean(entry->name, true);
+ chrome_policy_names->SetBoolean(entry->name, true);
+ }
+ names.Set("chromePolicyNames", chrome_policy_names);
+
+ // Add extension policy names.
+ base::DictionaryValue* extension_policy_names = new base::DictionaryValue;
+
+ // Get extensions.
James Hawkins 2013/06/20 18:18:52 High-level: Some of your code comments are borderl
anitawoodruff 2013/06/21 10:16:16 I take your point; I initially added these comment
James Hawkins 2013/06/21 14:54:25 Up to you.
+ extensions::ExtensionSystem* extension_system =
+ extensions::ExtensionSystem::Get(Profile::FromWebUI(web_ui()));
+ const ExtensionSet* extensions =
+ extension_system->extension_service()->extensions();
+
+ // Get the policy schema map.
James Hawkins 2013/06/20 18:18:52 Superfluous.
anitawoodruff 2013/06/21 10:16:16 Done.
+ scoped_refptr<const policy::PolicyDomainDescriptor> policy_domain_descriptor;
+ policy_domain_descriptor = GetPolicyService()->
+ GetPolicyDomainDescriptor(policy::POLICY_DOMAIN_EXTENSIONS);
+ const policy::PolicyDomainDescriptor::SchemaMap& schema_map =
+ policy_domain_descriptor->components();
+
+ // Add extension names and policies to the map.
James Hawkins 2013/06/20 18:18:52 Superfluous.
anitawoodruff 2013/06/21 10:16:16 Done.
+ for (ExtensionSet::const_iterator it = extensions->begin();
+ it != extensions->end(); ++it) {
+ const extensions::Extension* extension = *it;
+
+ // Skip this extension if it's a component extension.
James Hawkins 2013/06/20 18:18:52 Superfluous.
anitawoodruff 2013/06/21 10:16:16 Done.
+ if (extension->location() == extensions::Manifest::COMPONENT)
+ continue;
+
+ // Add extension name to map.
James Hawkins 2013/06/20 18:18:52 Superfluous.
anitawoodruff 2013/06/21 10:16:16 Done.
+ base::DictionaryValue* extension_value = new base::DictionaryValue;
+ extension_value->SetString("name", extension->name());
+
+ // Get extension's policy schema.
James Hawkins 2013/06/20 18:18:52 Superfluous.
anitawoodruff 2013/06/21 10:16:16 Done.
+ policy::PolicyDomainDescriptor::SchemaMap::const_iterator it =
+ schema_map.find(extension->id());
+ base::DictionaryValue* policy_names = new base::DictionaryValue;
+ if (it != schema_map.end()) {
+ // Get policy names from the extension's policy schema.
+ // Store in a map, not an array, for faster lookup on JS side.
+ const policy::PolicySchemaMap* policies = it->second->GetProperties();
+ policy::PolicySchemaMap::const_iterator it_policies;
+ for (it_policies = policies->begin(); it_policies != policies->end();
+ it_policies++) {
+ policy_names->SetBoolean(it_policies->first, true);
+ }
+ }
+ extension_value->Set("policyNames", policy_names);
+
+ // Add extension's entry to the map.
James Hawkins 2013/06/20 18:18:52 Superfluous.
anitawoodruff 2013/06/21 10:16:16 Done.
+ extension_policy_names->Set(extension->id(), extension_value);
}
+
+ names.Set("extensionPolicyNames", extension_policy_names);
web_ui()->CallJavascriptFunction("policy.Page.setPolicyNames", names);
}
@@ -538,22 +621,17 @@ void PolicyUIHandler::SendPolicyValues() const {
if (extension->location() == extensions::Manifest::COMPONENT)
continue;
- base::DictionaryValue* extension_value = new base::DictionaryValue;
-
- // Add name.
- extension_value->SetString("name", extension->name());
-
- // Add policies.
+ // Add policies values.
+ // Store in a map, not an array, for faster lookup on JS side.
base::DictionaryValue* extension_policies = new base::DictionaryValue;
policy::PolicyNamespace policy_namespace = policy::PolicyNamespace(
policy::POLICY_DOMAIN_EXTENSIONS, extension->id());
policy::PolicyErrorMap empty_error_map;
GetPolicyValues(GetPolicyService()->GetPolicies(policy_namespace),
&empty_error_map, extension_policies);
- extension_value->Set("policies", extension_policies);
// Add entry to the dictionary.
- extension_values->Set(extension->id(), extension_value);
+ extension_values->Set(extension->id(), extension_policies);
}
all_policies.Set("extensionPolicies", extension_values);
« chrome/browser/resources/policy.js ('K') | « chrome/browser/resources/policy.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698