| OLD | NEW |
| 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_handler.h" | 5 #include "chrome/browser/ui/webui/policy_ui_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 #include "components/policy/core/common/cloud/cloud_policy_validator.h" | 40 #include "components/policy/core/common/cloud/cloud_policy_validator.h" |
| 41 #include "components/policy/core/common/policy_details.h" | 41 #include "components/policy/core/common/policy_details.h" |
| 42 #include "components/policy/core/common/policy_types.h" | 42 #include "components/policy/core/common/policy_types.h" |
| 43 #include "components/policy/core/common/remote_commands/remote_commands_service.
h" | 43 #include "components/policy/core/common/remote_commands/remote_commands_service.
h" |
| 44 #include "components/policy/core/common/schema.h" | 44 #include "components/policy/core/common/schema.h" |
| 45 #include "components/policy/core/common/schema_map.h" | 45 #include "components/policy/core/common/schema_map.h" |
| 46 #include "components/policy/policy_constants.h" | 46 #include "components/policy/policy_constants.h" |
| 47 #include "components/policy/proto/device_management_backend.pb.h" | 47 #include "components/policy/proto/device_management_backend.pb.h" |
| 48 #include "components/strings/grit/components_strings.h" | 48 #include "components/strings/grit/components_strings.h" |
| 49 #include "content/public/browser/web_contents.h" | 49 #include "content/public/browser/web_contents.h" |
| 50 #include "extensions/features/features.h" |
| 50 #include "google_apis/gaia/gaia_auth_util.h" | 51 #include "google_apis/gaia/gaia_auth_util.h" |
| 51 #include "ui/base/l10n/l10n_util.h" | 52 #include "ui/base/l10n/l10n_util.h" |
| 52 #include "ui/base/l10n/time_format.h" | 53 #include "ui/base/l10n/time_format.h" |
| 53 | 54 |
| 54 #if defined(OS_CHROMEOS) | 55 #if defined(OS_CHROMEOS) |
| 55 #include "chrome/browser/browser_process_platform_part.h" | 56 #include "chrome/browser/browser_process_platform_part.h" |
| 56 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 57 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 57 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" | 58 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" |
| 58 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" | 59 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" |
| 59 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" | 60 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" |
| 60 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom
eos.h" | 61 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom
eos.h" |
| 61 #include "components/user_manager/user_manager.h" | 62 #include "components/user_manager/user_manager.h" |
| 62 #else | 63 #else |
| 63 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" | 64 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" |
| 64 #include "components/policy/core/common/cloud/user_cloud_policy_manager.h" | 65 #include "components/policy/core/common/cloud/user_cloud_policy_manager.h" |
| 65 #endif | 66 #endif |
| 66 | 67 |
| 67 #if defined(ENABLE_EXTENSIONS) | 68 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 68 #include "extensions/browser/extension_registry.h" | 69 #include "extensions/browser/extension_registry.h" |
| 69 #include "extensions/common/extension.h" | 70 #include "extensions/common/extension.h" |
| 70 #include "extensions/common/manifest.h" | 71 #include "extensions/common/manifest.h" |
| 71 #include "extensions/common/manifest_constants.h" | 72 #include "extensions/common/manifest_constants.h" |
| 72 #endif | 73 #endif |
| 73 | 74 |
| 74 namespace em = enterprise_management; | 75 namespace em = enterprise_management; |
| 75 | 76 |
| 76 namespace { | 77 namespace { |
| 77 | 78 |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 } | 421 } |
| 421 | 422 |
| 422 PolicyUIHandler::~PolicyUIHandler() { | 423 PolicyUIHandler::~PolicyUIHandler() { |
| 423 GetPolicyService()->RemoveObserver(policy::POLICY_DOMAIN_CHROME, this); | 424 GetPolicyService()->RemoveObserver(policy::POLICY_DOMAIN_CHROME, this); |
| 424 GetPolicyService()->RemoveObserver(policy::POLICY_DOMAIN_EXTENSIONS, this); | 425 GetPolicyService()->RemoveObserver(policy::POLICY_DOMAIN_EXTENSIONS, this); |
| 425 policy::SchemaRegistry* registry = | 426 policy::SchemaRegistry* registry = |
| 426 policy::SchemaRegistryServiceFactory::GetForContext( | 427 policy::SchemaRegistryServiceFactory::GetForContext( |
| 427 Profile::FromWebUI(web_ui())->GetOriginalProfile())->registry(); | 428 Profile::FromWebUI(web_ui())->GetOriginalProfile())->registry(); |
| 428 registry->RemoveObserver(this); | 429 registry->RemoveObserver(this); |
| 429 | 430 |
| 430 #if defined(ENABLE_EXTENSIONS) | 431 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 431 extensions::ExtensionRegistry::Get(Profile::FromWebUI(web_ui())) | 432 extensions::ExtensionRegistry::Get(Profile::FromWebUI(web_ui())) |
| 432 ->RemoveObserver(this); | 433 ->RemoveObserver(this); |
| 433 #endif | 434 #endif |
| 434 } | 435 } |
| 435 | 436 |
| 436 void PolicyUIHandler::AddLocalizedPolicyStrings( | 437 void PolicyUIHandler::AddLocalizedPolicyStrings( |
| 437 content::WebUIDataSource* source, | 438 content::WebUIDataSource* source, |
| 438 const PolicyStringMap* strings, | 439 const PolicyStringMap* strings, |
| 439 size_t count) { | 440 size_t count) { |
| 440 for (size_t i = 0; i < count; ++i) | 441 for (size_t i = 0; i < count; ++i) |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 if (!device_status_provider_.get()) | 505 if (!device_status_provider_.get()) |
| 505 device_status_provider_.reset(new CloudPolicyStatusProvider()); | 506 device_status_provider_.reset(new CloudPolicyStatusProvider()); |
| 506 | 507 |
| 507 base::Closure update_callback(base::Bind(&PolicyUIHandler::SendStatus, | 508 base::Closure update_callback(base::Bind(&PolicyUIHandler::SendStatus, |
| 508 base::Unretained(this))); | 509 base::Unretained(this))); |
| 509 user_status_provider_->SetStatusChangeCallback(update_callback); | 510 user_status_provider_->SetStatusChangeCallback(update_callback); |
| 510 device_status_provider_->SetStatusChangeCallback(update_callback); | 511 device_status_provider_->SetStatusChangeCallback(update_callback); |
| 511 GetPolicyService()->AddObserver(policy::POLICY_DOMAIN_CHROME, this); | 512 GetPolicyService()->AddObserver(policy::POLICY_DOMAIN_CHROME, this); |
| 512 GetPolicyService()->AddObserver(policy::POLICY_DOMAIN_EXTENSIONS, this); | 513 GetPolicyService()->AddObserver(policy::POLICY_DOMAIN_EXTENSIONS, this); |
| 513 | 514 |
| 514 #if defined(ENABLE_EXTENSIONS) | 515 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 515 extensions::ExtensionRegistry::Get(Profile::FromWebUI(web_ui())) | 516 extensions::ExtensionRegistry::Get(Profile::FromWebUI(web_ui())) |
| 516 ->AddObserver(this); | 517 ->AddObserver(this); |
| 517 #endif | 518 #endif |
| 518 policy::SchemaRegistry* registry = | 519 policy::SchemaRegistry* registry = |
| 519 policy::SchemaRegistryServiceFactory::GetForContext( | 520 policy::SchemaRegistryServiceFactory::GetForContext( |
| 520 Profile::FromWebUI(web_ui())->GetOriginalProfile())->registry(); | 521 Profile::FromWebUI(web_ui())->GetOriginalProfile())->registry(); |
| 521 registry->AddObserver(this); | 522 registry->AddObserver(this); |
| 522 | 523 |
| 523 web_ui()->RegisterMessageCallback( | 524 web_ui()->RegisterMessageCallback( |
| 524 "initialized", | 525 "initialized", |
| 525 base::Bind(&PolicyUIHandler::HandleInitialized, base::Unretained(this))); | 526 base::Bind(&PolicyUIHandler::HandleInitialized, base::Unretained(this))); |
| 526 web_ui()->RegisterMessageCallback( | 527 web_ui()->RegisterMessageCallback( |
| 527 "reloadPolicies", | 528 "reloadPolicies", |
| 528 base::Bind(&PolicyUIHandler::HandleReloadPolicies, | 529 base::Bind(&PolicyUIHandler::HandleReloadPolicies, |
| 529 base::Unretained(this))); | 530 base::Unretained(this))); |
| 530 } | 531 } |
| 531 | 532 |
| 532 #if defined(ENABLE_EXTENSIONS) | 533 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 533 void PolicyUIHandler::OnExtensionLoaded( | 534 void PolicyUIHandler::OnExtensionLoaded( |
| 534 content::BrowserContext* browser_context, | 535 content::BrowserContext* browser_context, |
| 535 const extensions::Extension* extension) { | 536 const extensions::Extension* extension) { |
| 536 SendPolicyNames(); | 537 SendPolicyNames(); |
| 537 SendPolicyValues(); | 538 SendPolicyValues(); |
| 538 } | 539 } |
| 539 | 540 |
| 540 void PolicyUIHandler::OnExtensionUnloaded( | 541 void PolicyUIHandler::OnExtensionUnloaded( |
| 541 content::BrowserContext* browser_context, | 542 content::BrowserContext* browser_context, |
| 542 const extensions::Extension* extension, | 543 const extensions::Extension* extension, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 // Add Chrome policy names. | 578 // Add Chrome policy names. |
| 578 base::DictionaryValue* chrome_policy_names = new base::DictionaryValue; | 579 base::DictionaryValue* chrome_policy_names = new base::DictionaryValue; |
| 579 policy::PolicyNamespace chrome_ns(policy::POLICY_DOMAIN_CHROME, ""); | 580 policy::PolicyNamespace chrome_ns(policy::POLICY_DOMAIN_CHROME, ""); |
| 580 const policy::Schema* chrome_schema = schema_map->GetSchema(chrome_ns); | 581 const policy::Schema* chrome_schema = schema_map->GetSchema(chrome_ns); |
| 581 for (policy::Schema::Iterator it = chrome_schema->GetPropertiesIterator(); | 582 for (policy::Schema::Iterator it = chrome_schema->GetPropertiesIterator(); |
| 582 !it.IsAtEnd(); it.Advance()) { | 583 !it.IsAtEnd(); it.Advance()) { |
| 583 AddPolicyName(it.key(), chrome_policy_names); | 584 AddPolicyName(it.key(), chrome_policy_names); |
| 584 } | 585 } |
| 585 names.Set("chromePolicyNames", chrome_policy_names); | 586 names.Set("chromePolicyNames", chrome_policy_names); |
| 586 | 587 |
| 587 #if defined(ENABLE_EXTENSIONS) | 588 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 588 // Add extension policy names. | 589 // Add extension policy names. |
| 589 base::DictionaryValue* extension_policy_names = new base::DictionaryValue; | 590 base::DictionaryValue* extension_policy_names = new base::DictionaryValue; |
| 590 | 591 |
| 591 for (const scoped_refptr<const extensions::Extension>& extension : | 592 for (const scoped_refptr<const extensions::Extension>& extension : |
| 592 extensions::ExtensionRegistry::Get(profile)->enabled_extensions()) { | 593 extensions::ExtensionRegistry::Get(profile)->enabled_extensions()) { |
| 593 // Skip this extension if it's not an enterprise extension. | 594 // Skip this extension if it's not an enterprise extension. |
| 594 if (!extension->manifest()->HasPath( | 595 if (!extension->manifest()->HasPath( |
| 595 extensions::manifest_keys::kStorageManagedSchema)) | 596 extensions::manifest_keys::kStorageManagedSchema)) |
| 596 continue; | 597 continue; |
| 597 base::DictionaryValue* extension_value = new base::DictionaryValue; | 598 base::DictionaryValue* extension_value = new base::DictionaryValue; |
| 598 extension_value->SetString("name", extension->name()); | 599 extension_value->SetString("name", extension->name()); |
| 599 const policy::Schema* schema = | 600 const policy::Schema* schema = |
| 600 schema_map->GetSchema(policy::PolicyNamespace( | 601 schema_map->GetSchema(policy::PolicyNamespace( |
| 601 policy::POLICY_DOMAIN_EXTENSIONS, extension->id())); | 602 policy::POLICY_DOMAIN_EXTENSIONS, extension->id())); |
| 602 base::DictionaryValue* policy_names = new base::DictionaryValue; | 603 base::DictionaryValue* policy_names = new base::DictionaryValue; |
| 603 if (schema && schema->valid()) { | 604 if (schema && schema->valid()) { |
| 604 // Get policy names from the extension's policy schema. | 605 // Get policy names from the extension's policy schema. |
| 605 // Store in a map, not an array, for faster lookup on JS side. | 606 // Store in a map, not an array, for faster lookup on JS side. |
| 606 for (policy::Schema::Iterator prop = schema->GetPropertiesIterator(); | 607 for (policy::Schema::Iterator prop = schema->GetPropertiesIterator(); |
| 607 !prop.IsAtEnd(); prop.Advance()) { | 608 !prop.IsAtEnd(); prop.Advance()) { |
| 608 policy_names->SetBoolean(prop.key(), true); | 609 policy_names->SetBoolean(prop.key(), true); |
| 609 } | 610 } |
| 610 } | 611 } |
| 611 extension_value->Set("policyNames", policy_names); | 612 extension_value->Set("policyNames", policy_names); |
| 612 extension_policy_names->Set(extension->id(), extension_value); | 613 extension_policy_names->Set(extension->id(), extension_value); |
| 613 } | 614 } |
| 614 names.Set("extensionPolicyNames", extension_policy_names); | 615 names.Set("extensionPolicyNames", extension_policy_names); |
| 615 #endif // defined(ENABLE_EXTENSIONS) | 616 #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
| 616 | 617 |
| 617 web_ui()->CallJavascriptFunctionUnsafe("policy.Page.setPolicyNames", names); | 618 web_ui()->CallJavascriptFunctionUnsafe("policy.Page.setPolicyNames", names); |
| 618 } | 619 } |
| 619 | 620 |
| 620 void PolicyUIHandler::SendPolicyValues() const { | 621 void PolicyUIHandler::SendPolicyValues() const { |
| 621 base::DictionaryValue all_policies; | 622 base::DictionaryValue all_policies; |
| 622 | 623 |
| 623 // Add Chrome policy values. | 624 // Add Chrome policy values. |
| 624 base::DictionaryValue* chrome_policies = new base::DictionaryValue; | 625 base::DictionaryValue* chrome_policies = new base::DictionaryValue; |
| 625 GetChromePolicyValues(chrome_policies); | 626 GetChromePolicyValues(chrome_policies); |
| 626 all_policies.Set("chromePolicies", chrome_policies); | 627 all_policies.Set("chromePolicies", chrome_policies); |
| 627 | 628 |
| 628 #if defined(ENABLE_EXTENSIONS) | 629 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 629 // Add extension policy values. | 630 // Add extension policy values. |
| 630 extensions::ExtensionRegistry* registry = | 631 extensions::ExtensionRegistry* registry = |
| 631 extensions::ExtensionRegistry::Get(Profile::FromWebUI(web_ui())); | 632 extensions::ExtensionRegistry::Get(Profile::FromWebUI(web_ui())); |
| 632 base::DictionaryValue* extension_values = new base::DictionaryValue; | 633 base::DictionaryValue* extension_values = new base::DictionaryValue; |
| 633 | 634 |
| 634 for (const scoped_refptr<const extensions::Extension>& extension : | 635 for (const scoped_refptr<const extensions::Extension>& extension : |
| 635 registry->enabled_extensions()) { | 636 registry->enabled_extensions()) { |
| 636 // Skip this extension if it's not an enterprise extension. | 637 // Skip this extension if it's not an enterprise extension. |
| 637 if (!extension->manifest()->HasPath( | 638 if (!extension->manifest()->HasPath( |
| 638 extensions::manifest_keys::kStorageManagedSchema)) | 639 extensions::manifest_keys::kStorageManagedSchema)) |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 743 } | 744 } |
| 744 | 745 |
| 745 void PolicyUIHandler::OnRefreshPoliciesDone() const { | 746 void PolicyUIHandler::OnRefreshPoliciesDone() const { |
| 746 web_ui()->CallJavascriptFunctionUnsafe("policy.Page.reloadPoliciesDone"); | 747 web_ui()->CallJavascriptFunctionUnsafe("policy.Page.reloadPoliciesDone"); |
| 747 } | 748 } |
| 748 | 749 |
| 749 policy::PolicyService* PolicyUIHandler::GetPolicyService() const { | 750 policy::PolicyService* PolicyUIHandler::GetPolicyService() const { |
| 750 return policy::ProfilePolicyConnectorFactory::GetForBrowserContext( | 751 return policy::ProfilePolicyConnectorFactory::GetForBrowserContext( |
| 751 web_ui()->GetWebContents()->GetBrowserContext())->policy_service(); | 752 web_ui()->GetWebContents()->GetBrowserContext())->policy_service(); |
| 752 } | 753 } |
| OLD | NEW |