From 3035828750f79776b5aa13019663316ecfb8f582 Mon Sep 17 00:00:00 2001 From: "xiyuan@chromium.org" Date: Tue, 12 Apr 2011 17:27:27 +0000 Subject: [ChromeOS] Append a "Managed by DOMAIN" text to version label on login screen. BUG=chromium-os:12558 TEST=Verify fix for chromium-os:12558 after chromium-os:11033 is done. Review URL: http://codereview.chromium.org/6803018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81266 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/app/generated_resources.grd | 3 + chrome/browser/chromeos/login/background_view.cc | 83 ++++++++++++++++++++--- chrome/browser/chromeos/login/background_view.h | 28 +++++++- chrome/browser/policy/browser_policy_connector.cc | 18 +++++ chrome/browser/policy/browser_policy_connector.h | 3 + 5 files changed, 122 insertions(+), 13 deletions(-) diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index f7b7a39..aeceee7 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -11774,6 +11774,9 @@ Keep your key file in a safe place. You will need it to create new versions of y Enter password + + Managed by $1yourdomain.com + Import bookmarks now... diff --git a/chrome/browser/chromeos/login/background_view.cc b/chrome/browser/chromeos/login/background_view.cc index 3a6a034..3467801 100644 --- a/chrome/browser/chromeos/login/background_view.cc +++ b/chrome/browser/chromeos/login/background_view.cc @@ -11,6 +11,7 @@ #include "base/string_util.h" #include "base/stringprintf.h" #include "base/utf_string_conversions.h" +#include "chrome/browser/browser_process.h" #include "chrome/browser/chromeos/login/helper.h" #include "chrome/browser/chromeos/login/login_utils.h" #include "chrome/browser/chromeos/login/oobe_progress_bar.h" @@ -23,6 +24,7 @@ #include "chrome/browser/chromeos/status/network_menu_button.h" #include "chrome/browser/chromeos/status/status_area_view.h" #include "chrome/browser/chromeos/wm_ipc.h" +#include "chrome/browser/policy/browser_policy_connector.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/ui/views/dom_view.h" #include "chrome/browser/ui/views/window.h" @@ -378,8 +380,19 @@ void BackgroundView::InitInfoLabels() { NewCallback(this, &BackgroundView::OnBootTimes)); } } else { - os_version_label_->SetText( - ASCIIToWide(CrosLibrary::Get()->load_error_string())); + UpdateVersionLabel(); + } + + policy::CloudPolicySubsystem* cloud_policy = + g_browser_process->browser_policy_connector()->cloud_policy_subsystem(); + if (cloud_policy) { + cloud_policy_registrar_.reset( + new policy::CloudPolicySubsystem::ObserverRegistrar( + cloud_policy, this)); + + // Ensure that we have up-to-date enterprise info in case enterprise policy + // is already fetched and has finished initialization. + UpdateEnterpriseInfo(); } } @@ -408,19 +421,61 @@ void BackgroundView::UpdateWindowType() { ¶ms); } -void BackgroundView::OnVersion( - VersionLoader::Handle handle, std::string version) { +void BackgroundView::UpdateVersionLabel() { + if (!CrosLibrary::Get()->EnsureLoaded()) { + os_version_label_->SetText( + ASCIIToWide(CrosLibrary::Get()->load_error_string())); + return; + } + + if (version_text_.empty()) + return; + // TODO(jungshik): Is string concatenation OK here? - std::string version_text = l10n_util::GetStringUTF8(IDS_PRODUCT_OS_NAME); - version_text += ' '; - version_text += l10n_util::GetStringUTF8(IDS_VERSION_FIELD_PREFIX); - version_text += ' '; - version_text += version; + std::string label_text = l10n_util::GetStringUTF8(IDS_PRODUCT_OS_NAME); + label_text += ' '; + label_text += l10n_util::GetStringUTF8(IDS_VERSION_FIELD_PREFIX); + label_text += ' '; + label_text += version_text_; + + if (!enterprise_domain_text_.empty()) { + label_text += ' '; + label_text += l10n_util::GetStringFUTF8( + IDS_LOGIN_MANAGED_BY_LABEL_FORMAT, + UTF8ToUTF16(enterprise_domain_text_)); + } // Workaround over incorrect width calculation in old fonts. // TODO(glotov): remove the following line when new fonts are used. - version_text += ' '; - os_version_label_->SetText(UTF8ToWide(version_text)); + label_text += ' '; + os_version_label_->SetText(UTF8ToWide(label_text)); +} + +void BackgroundView::UpdateEnterpriseInfo() { + policy::BrowserPolicyConnector* policy_connector = + g_browser_process->browser_policy_connector(); + if (!policy_connector->cloud_policy_subsystem() || + !policy_connector->IsEnterpriseManaged()) { + // No enterprise domain if there is no cloud policy or device is not + // enterprise managed. + SetEnterpriseDomain(""); + return; + } + + SetEnterpriseDomain(policy_connector->GetEnterpriseDomain()); +} + +void BackgroundView::SetEnterpriseDomain(const std::string& domain_name) { + if (domain_name != enterprise_domain_text_) { + enterprise_domain_text_ = domain_name; + UpdateVersionLabel(); + } +} + +void BackgroundView::OnVersion( + VersionLoader::Handle handle, std::string version) { + version_text_ = version; + UpdateVersionLabel(); } void BackgroundView::OnBootTimes( @@ -452,4 +507,10 @@ void BackgroundView::OnBootTimes( boot_times_label_->SetText(ASCIIToWide(boot_times_text)); } +void BackgroundView::OnPolicyStateChanged( + policy::CloudPolicySubsystem::PolicySubsystemState state, + policy::CloudPolicySubsystem::ErrorDetails error_details) { + UpdateEnterpriseInfo(); +} + } // namespace chromeos diff --git a/chrome/browser/chromeos/login/background_view.h b/chrome/browser/chromeos/login/background_view.h index d3d5e30..728fe59 100644 --- a/chrome/browser/chromeos/login/background_view.h +++ b/chrome/browser/chromeos/login/background_view.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -11,6 +11,7 @@ #include "chrome/browser/chromeos/login/login_html_dialog.h" #include "chrome/browser/chromeos/status/status_area_host.h" #include "chrome/browser/chromeos/version_loader.h" +#include "chrome/browser/policy/cloud_policy_subsystem.h" #include "views/view.h" namespace views { @@ -34,7 +35,8 @@ class StatusAreaView; // StatusAreaView. class BackgroundView : public views::View, public StatusAreaHost, - public chromeos::LoginHtmlDialog::Delegate { + public chromeos::LoginHtmlDialog::Delegate, + public policy::CloudPolicySubsystem::Observer { public: enum LoginStep { SELECT_NETWORK, @@ -128,12 +130,26 @@ class BackgroundView : public views::View, // after we've painted. void UpdateWindowType(); + // Update the version label. + void UpdateVersionLabel(); + + // Check and update enterprise domain. + void UpdateEnterpriseInfo(); + + // Set enterprise domain name. + void SetEnterpriseDomain(const std::string& domain_name); + // Callback from chromeos::VersionLoader giving the version. void OnVersion(VersionLoader::Handle handle, std::string version); // Callback from chromeos::InfoLoader giving the boot times. void OnBootTimes( BootTimesLoader::Handle handle, BootTimesLoader::BootTimes boot_times); + // policy::CloudPolicySubsystem::Observer methods: + void OnPolicyStateChanged( + policy::CloudPolicySubsystem::PolicySubsystemState state, + policy::CloudPolicySubsystem::ErrorDetails error_details); + // All of these variables could be NULL. StatusAreaView* status_area_; views::Label* os_version_label_; @@ -162,9 +178,17 @@ class BackgroundView : public views::View, // DOMView for rendering a webpage as a background. DOMView* background_area_; + // Information pieces for version label. + std::string version_text_; + std::string enterprise_domain_text_; + // Proxy settings dialog that can be invoked from network menu. scoped_ptr proxy_settings_dialog_; + // CloudPolicySubsysterm observer registrar + scoped_ptr + cloud_policy_registrar_; + DISALLOW_COPY_AND_ASSIGN(BackgroundView); }; diff --git a/chrome/browser/policy/browser_policy_connector.cc b/chrome/browser/policy/browser_policy_connector.cc index df75c9b..c186a8f 100644 --- a/chrome/browser/policy/browser_policy_connector.cc +++ b/chrome/browser/policy/browser_policy_connector.cc @@ -156,6 +156,24 @@ bool BrowserPolicyConnector::IsEnterpriseManaged() { #endif } +std::string BrowserPolicyConnector::GetEnterpriseDomain() { + std::string domain; + +#if defined(OS_CHROMEOS) + // TODO(xiyuan): Find a better way to get enterprise domain. + std::string username; + std::string auth_token; + if (identity_strategy_.get() && + identity_strategy_->GetCredentials(&username, &auth_token)) { + size_t pos = username.find('@'); + if (pos != std::string::npos) + domain = username.substr(pos + 1); + } +#endif + + return domain; +} + void BrowserPolicyConnector::StopAutoRetry() { if (cloud_policy_subsystem_.get()) cloud_policy_subsystem_->StopAutoRetry(); diff --git a/chrome/browser/policy/browser_policy_connector.h b/chrome/browser/policy/browser_policy_connector.h index 93995c8..0257aa8 100644 --- a/chrome/browser/policy/browser_policy_connector.h +++ b/chrome/browser/policy/browser_policy_connector.h @@ -61,6 +61,9 @@ class BrowserPolicyConnector : public NotificationObserver { // a local owner). bool IsEnterpriseManaged(); + // Returns the enterprise domain if device is managed. + std::string GetEnterpriseDomain(); + // Exposes the StopAutoRetry() method of the CloudPolicySubsystem managed // by this connector, which can be used to disable automatic // retrying behavior. -- cgit v1.1