| 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 99ebb3e2bba09d7ba130336868c9d6caa7ea5c66..b412d6f0dc4e4fe059f5f5959f92f23343fbf68a 100644
|
| --- a/chrome/browser/ui/webui/policy_ui.cc
|
| +++ b/chrome/browser/ui/webui/policy_ui.cc
|
| @@ -4,9 +4,17 @@
|
|
|
| #include "chrome/browser/ui/webui/policy_ui.h"
|
|
|
| -#include "chrome/browser/policy/policy_status_info.h"
|
| +#include "base/i18n/time_formatting.h"
|
| +#include "base/utf_string_conversions.h"
|
| +#include "chrome/browser/browser_process.h"
|
| +#include "chrome/browser/chromeos/login/user_manager.h"
|
| +#include "chrome/browser/policy/browser_policy_connector.h"
|
| +#include "chrome/browser/policy/cloud_policy_cache_base.h"
|
| +#include "chrome/browser/prefs/pref_service.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
|
| +#include "chrome/common/pref_names.h"
|
| +#include "chrome/common/time_format.h"
|
| #include "chrome/common/url_constants.h"
|
| #include "content/browser/tab_contents/tab_contents.h"
|
| #include "grit/browser_resources.h"
|
| @@ -26,6 +34,8 @@ ChromeWebUIDataSource* CreatePolicyUIHTMLSource() {
|
| IDS_POLICY_USER_POLICIES);
|
| source->AddLocalizedString("enrollmentDomainText",
|
| IDS_POLICY_ENROLLMENT_DOMAIN);
|
| + source->AddLocalizedString("clientIdText", IDS_POLICY_CLIENT_ID);
|
| + source->AddLocalizedString("usernameText", IDS_POLICY_USERNAME);
|
| source->AddLocalizedString("lastFetchedText", IDS_POLICY_LAST_FETCHED);
|
| source->AddLocalizedString("fetchIntervalText", IDS_POLICY_FETCH_INTERVAL);
|
| source->AddLocalizedString("serverStatusText", IDS_POLICY_SERVER_STATUS);
|
| @@ -39,6 +49,8 @@ ChromeWebUIDataSource* CreatePolicyUIHTMLSource() {
|
| source->AddLocalizedString("policyValueTableHeader", IDS_POLICY_ENTRY_VALUE);
|
| source->AddLocalizedString("policyStatusTableHeader",
|
| IDS_POLICY_ENTRY_STATUS);
|
| + source->AddLocalizedString("showMoreText", IDS_POLICY_SHOW_MORE);
|
| + source->AddLocalizedString("hideText", IDS_POLICY_HIDE);
|
| source->set_json_path("strings.js");
|
|
|
| // Add required resources.
|
| @@ -57,20 +69,23 @@ ChromeWebUIDataSource* CreatePolicyUIHTMLSource() {
|
|
|
| PolicyUIHandler::PolicyUIHandler() {
|
| policy::ConfigurationPolicyReader* managed_platform =
|
| - ConfigurationPolicyReader::CreateManagedPlatformPolicyReader();
|
| + policy::ConfigurationPolicyReader::CreateManagedPlatformPolicyReader();
|
| policy::ConfigurationPolicyReader* managed_cloud =
|
| - ConfigurationPolicyReader::CreateManagedCloudPolicyReader();
|
| + policy::ConfigurationPolicyReader::CreateManagedCloudPolicyReader();
|
| policy::ConfigurationPolicyReader* recommended_platform =
|
| - ConfigurationPolicyReader::CreateRecommendedPlatformPolicyReader();
|
| + policy::ConfigurationPolicyReader::
|
| + CreateRecommendedPlatformPolicyReader();
|
| policy::ConfigurationPolicyReader* recommended_cloud =
|
| - ConfigurationPolicyReader::CreateRecommendedCloudPolicyReader();
|
| + policy::ConfigurationPolicyReader::CreateRecommendedCloudPolicyReader();
|
| policy_status_.reset(new policy::PolicyStatus(managed_platform,
|
| managed_cloud,
|
| recommended_platform,
|
| recommended_cloud));
|
| + policy_status_->AddObserver(this);
|
| }
|
|
|
| PolicyUIHandler::~PolicyUIHandler() {
|
| + policy_status_->RemoveObserver(this);
|
| }
|
|
|
| WebUIMessageHandler* PolicyUIHandler::Attach(WebUI* web_ui) {
|
| @@ -78,17 +93,149 @@ WebUIMessageHandler* PolicyUIHandler::Attach(WebUI* web_ui) {
|
| }
|
|
|
| void PolicyUIHandler::RegisterMessages() {
|
| - web_ui_->RegisterMessageCallback("requestPolicyData",
|
| - NewCallback(this, &PolicyUIHandler::HandleRequestPolicyData));
|
| + web_ui_->RegisterMessageCallback("requestData",
|
| + NewCallback(this, &PolicyUIHandler::HandleRequestData));
|
| + web_ui_->RegisterMessageCallback("fetchPolicy",
|
| + NewCallback(this, &PolicyUIHandler::HandleFetchPolicy));
|
| }
|
|
|
| -void PolicyUIHandler::HandleRequestPolicyData(const ListValue* args) {
|
| - bool any_policies_sent;
|
| - ListValue* list = policy_status_->GetPolicyStatusList(&any_policies_sent);
|
| +void PolicyUIHandler::OnPolicyValuesChanged() {
|
| + SendDataToUI(true);
|
| +}
|
| +
|
| +void PolicyUIHandler::HandleRequestData(const ListValue* args) {
|
| + SendDataToUI(false);
|
| +}
|
| +
|
| +void PolicyUIHandler::HandleFetchPolicy(const ListValue* args) {
|
| + if (FetchPolicyIfTokensAvailable())
|
| + SendDataToUI(true);
|
| +}
|
| +
|
| +void PolicyUIHandler::SendDataToUI(bool is_policy_update) {
|
| DictionaryValue results;
|
| + bool any_policies_set;
|
| + ListValue* list = policy_status_->GetPolicyStatusList(&any_policies_set);
|
| results.Set("policies", list);
|
| - results.SetBoolean("anyPoliciesSet", any_policies_sent);
|
| - web_ui_->CallJavascriptFunction("Policy.returnPolicyData", results);
|
| + results.SetBoolean("anyPoliciesSet", any_policies_set);
|
| + DictionaryValue* dict = GetStatusData();
|
| + results.Set("status", dict);
|
| + results.SetBoolean("isPolicyUpdate", is_policy_update);
|
| +
|
| + web_ui_->CallJavascriptFunction("Policy.returnData", results);
|
| +}
|
| +
|
| +DictionaryValue* PolicyUIHandler::GetStatusData() {
|
| + DictionaryValue* results = new DictionaryValue();
|
| + policy::BrowserPolicyConnector* connector =
|
| + g_browser_process->browser_policy_connector();
|
| +
|
| + policy::CloudPolicySubsystem* device_subsystem =
|
| + connector->device_cloud_policy_subsystem();
|
| + policy::CloudPolicySubsystem* user_subsystem =
|
| + connector->user_cloud_policy_subsystem();
|
| +
|
| + // If no CloudPolicySubsystem is available, the status section is not
|
| + // displayed and we can return here.
|
| + if (!device_subsystem || !user_subsystem) {
|
| + results->SetBoolean("displayStatusSection", false);
|
| + return results;
|
| + } else {
|
| + results->SetBoolean("displayStatusSection", true);
|
| + }
|
| +
|
| + // Get the server status message and the time at which policy was last fetched
|
| + // for both user and device policy from the appropriate CloudPolicySubsystem.
|
| + results->SetString("deviceStatusMessage",
|
| + CreateStatusMessageString(device_subsystem->error_details()));
|
| + results->SetString("deviceLastFetchTime", GetLastFetchTime(device_subsystem));
|
| + results->SetString("userStatusMessage",
|
| + CreateStatusMessageString(user_subsystem->error_details()));
|
| + results->SetString("userLastFetchTime", GetLastFetchTime(user_subsystem));
|
| +
|
| + // Get enterprise domain and username (only on ChromeOS).
|
| +#if defined (OS_CHROMEOS)
|
| + chromeos::UserManager::User user =
|
| + chromeos::UserManager::Get()->logged_in_user();
|
| + results->SetString("devicePolicyDomain",
|
| + ASCIIToUTF16(connector->GetEnterpriseDomain()));
|
| + results->SetString("user", ASCIIToUTF16(user.email()));
|
| +#else
|
| + results->SetString("devicePolicyDomain", string16());
|
| + results->SetString("user", string16());
|
| +#endif
|
| +
|
| + // Get the device ids for both user and device policy from the appropriate
|
| + // CloudPolicyDataStore.
|
| + results->SetString("deviceId",
|
| + GetDeviceId(connector->GetDeviceCloudPolicyDataStore()));
|
| + results->SetString("userId",
|
| + GetDeviceId(connector->GetUserCloudPolicyDataStore()));
|
| +
|
| + // Get the policy refresh rate for both user and device policy from the
|
| + // appropriate preference.
|
| + results->SetString("deviceFetchInterval",
|
| + GetPolicyFetchInterval(prefs::kDevicePolicyRefreshRate));
|
| + results->SetString("userFetchInterval",
|
| + GetPolicyFetchInterval(prefs::kUserPolicyRefreshRate));
|
| +
|
| + return results;
|
| +}
|
| +
|
| +bool PolicyUIHandler::FetchPolicyIfTokensAvailable() {
|
| + policy::BrowserPolicyConnector* connector =
|
| + g_browser_process->browser_policy_connector();
|
| + const policy::CloudPolicyDataStore* device_data_store =
|
| + connector->GetDeviceCloudPolicyDataStore();
|
| + const policy::CloudPolicyDataStore* user_data_store =
|
| + connector->GetUserCloudPolicyDataStore();
|
| +
|
| + bool fetch_device_policy =
|
| + device_data_store && !device_data_store->device_token().empty();
|
| + bool fetch_user_policy =
|
| + user_data_store && !user_data_store->device_token().empty();
|
| +
|
| + if (fetch_device_policy)
|
| + connector->FetchDevicePolicy();
|
| +
|
| + if (fetch_user_policy)
|
| + connector->FetchUserPolicy();
|
| +
|
| + return fetch_device_policy || fetch_user_policy;
|
| +}
|
| +
|
| +string16 PolicyUIHandler::GetLastFetchTime(
|
| + policy::CloudPolicySubsystem* subsystem) {
|
| + policy::CloudPolicyCacheBase* cache_base =
|
| + subsystem->GetCloudPolicyCacheBase();
|
| + base::TimeDelta time_delta =
|
| + base::Time::NowFromSystemTime() - cache_base->last_policy_refresh_time();
|
| +
|
| + return TimeFormat::TimeElapsed(time_delta);
|
| +}
|
| +
|
| +string16 PolicyUIHandler::GetDeviceId(
|
| + const policy::CloudPolicyDataStore* data_store) {
|
| + return data_store ? ASCIIToUTF16(data_store->device_id()) : string16();
|
| +}
|
| +
|
| +string16 PolicyUIHandler::GetPolicyFetchInterval(const char* refresh_pref) {
|
| + PrefService* prefs = g_browser_process->local_state();
|
| + return TimeFormat::TimeRemainingShort(
|
| + base::TimeDelta::FromMilliseconds(prefs->GetInteger(refresh_pref)));
|
| +}
|
| +
|
| +// static
|
| +string16 PolicyUIHandler::CreateStatusMessageString(
|
| + policy::CloudPolicySubsystem::ErrorDetails error_details) {
|
| + static string16 error_to_string[] = { ASCIIToUTF16("OK."),
|
| + ASCIIToUTF16("Network error."),
|
| + ASCIIToUTF16("Network error."),
|
| + ASCIIToUTF16("Bad DMToken."),
|
| + ASCIIToUTF16("Local error."),
|
| + ASCIIToUTF16("Signature mismatch.") };
|
| + DCHECK(static_cast<size_t>(error_details) < arraysize(error_to_string));
|
| + return error_to_string[error_details];
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
|
|