Commit 59355922 authored by fqj's avatar fqj Committed by Commit bot

system tray ui change for AllowOnlyPolicyNetworksToConnect

This commit grays out unmanaged WiFis and button to joining other WiFis
when AllowOnlyPolicyNetworksToConnect is true after user logged in, as
well as adds the tooltip to tell users why.

BUG=208378

Review URL: https://codereview.chromium.org/1469733003

Cr-Commit-Position: refs/heads/master@{#361319}
parent d97c21a2
......@@ -27,6 +27,7 @@ component("ash") {
"//base/third_party/dynamic_annotations",
"//cc",
"//components/device_event_log",
"//components/onc",
"//components/signin/core/account_id",
"//components/user_manager",
"//components/wallpaper",
......
......@@ -945,6 +945,7 @@
'../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations',
'../cc/cc.gyp:cc',
'../components/components.gyp:device_event_log_component',
'../components/components.gyp:onc_component',
'../components/components.gyp:signin_core_account_id',
'../components/components.gyp:user_manager',
'../components/components.gyp:wallpaper',
......
......@@ -31,7 +31,9 @@
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "chromeos/chromeos_switches.h"
#include "chromeos/login/login_state.h"
#include "chromeos/network/device_state.h"
#include "chromeos/network/managed_network_configuration_handler.h"
#include "chromeos/network/network_state.h"
#include "chromeos/network/network_state_handler.h"
#include "grit/ash_resources.h"
......@@ -59,6 +61,7 @@
#include "ui/views/widget/widget.h"
using chromeos::DeviceState;
using chromeos::LoginState;
using chromeos::NetworkHandler;
using chromeos::NetworkState;
using chromeos::NetworkStateHandler;
......@@ -93,6 +96,23 @@ views::View* CreateInfoBubbleLine(const base::string16& text_label,
return view;
}
bool PolicyProhibitsUnmanaged() {
if (!LoginState::IsInitialized() || !LoginState::Get()->IsUserLoggedIn())
return false;
bool policy_prohibites_unmanaged = false;
const base::DictionaryValue* global_network_config =
NetworkHandler::Get()
->managed_network_configuration_handler()
->GetGlobalConfigFromPolicy(
std::string() /* no username hash, device policy */);
if (global_network_config) {
global_network_config->GetBooleanWithoutPathExpansion(
::onc::global_network_config::kAllowOnlyPolicyNetworksToConnect,
&policy_prohibites_unmanaged);
}
return policy_prohibites_unmanaged;
}
} // namespace
//------------------------------------------------------------------------------
......@@ -459,6 +479,11 @@ void NetworkStateListDetailedView::CreateNetworkExtra() {
other_wifi_ = new TrayPopupLabelButton(
this, rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_OTHER_WIFI));
bottom_row->AddChildView(other_wifi_);
if (PolicyProhibitsUnmanaged()) {
other_wifi_->SetEnabled(false);
other_wifi_->SetTooltipText(l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_NETWORK_PROHIBITED_OTHER));
}
turn_on_wifi_ = new TrayPopupLabelButton(
this, rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_TURN_ON_WIFI));
......@@ -785,6 +810,7 @@ views::View* NetworkStateListDetailedView::CreateViewForNetwork(
view->SetBorder(
views::Border::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, 0, 0));
views::View* controlled_icon = CreateControlledByExtensionView(info);
view->set_tooltip(info.tooltip);
if (controlled_icon)
view->AddChildView(controlled_icon);
return view;
......@@ -805,6 +831,7 @@ void NetworkStateListDetailedView::UpdateViewForNetwork(
HoverHighlightView* highlight = static_cast<HoverHighlightView*>(view);
highlight->AddIconAndLabel(info.image, info.label, info.highlight);
views::View* controlled_icon = CreateControlledByExtensionView(info);
highlight->set_tooltip(info.tooltip);
if (controlled_icon)
view->AddChildView(controlled_icon);
}
......
......@@ -49,6 +49,7 @@ component("ui_chromeos") {
"//chromeos:chromeos",
"//chromeos:power_manager_proto",
"//components/device_event_log",
"//components/onc",
"//skia",
"//ui/aura",
"//ui/base",
......
......@@ -26,6 +26,7 @@ struct UI_CHROMEOS_EXPORT NetworkInfo {
std::string service_path;
base::string16 label;
base::string16 tooltip;
gfx::ImageSkia image;
bool disable;
bool highlight;
......
......@@ -7,11 +7,14 @@
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/power_manager/power_supply_properties.pb.h"
#include "chromeos/dbus/power_manager_client.h"
#include "chromeos/login/login_state.h"
#include "chromeos/network/managed_network_configuration_handler.h"
#include "chromeos/network/network_state.h"
#include "chromeos/network/network_state_handler.h"
#include "chromeos/network/network_state_handler_observer.h"
#include "components/device_event_log/device_event_log.h"
#include "grit/ui_chromeos_strings.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/chromeos/network/network_icon.h"
#include "ui/chromeos/network/network_icon_animation.h"
......@@ -21,12 +24,40 @@
#include "ui/views/controls/label.h"
#include "ui/views/view.h"
using chromeos::LoginState;
using chromeos::NetworkHandler;
using chromeos::NetworkStateHandler;
using chromeos::ManagedNetworkConfigurationHandler;
using chromeos::NetworkTypePattern;
namespace ui {
namespace {
bool IsProhibitedByPolicy(const chromeos::NetworkState* network) {
if (!NetworkTypePattern::WiFi().MatchesType(network->type()))
return false;
if (!LoginState::IsInitialized() || !LoginState::Get()->IsUserLoggedIn())
return false;
ManagedNetworkConfigurationHandler* managed_configuration_handler =
NetworkHandler::Get()->managed_network_configuration_handler();
const base::DictionaryValue* global_network_config =
managed_configuration_handler->GetGlobalConfigFromPolicy(
std::string() /* no username hash, device policy */);
bool policy_prohibites_unmanaged = false;
if (global_network_config) {
global_network_config->GetBooleanWithoutPathExpansion(
::onc::global_network_config::kAllowOnlyPolicyNetworksToConnect,
&policy_prohibites_unmanaged);
}
if (!policy_prohibites_unmanaged)
return false;
return !managed_configuration_handler->FindPolicyByGuidAndProfile(
network->guid(), network->profile_path());
}
} // namespace
// NetworkListView:
NetworkListView::NetworkListView(NetworkListDelegate* delegate)
......@@ -83,12 +114,14 @@ void NetworkListView::UpdateNetworkIcons() {
// First, update state for all networks
bool animating = false;
for (size_t i = 0; i < network_list_.size(); ++i) {
NetworkInfo* info = network_list_[i];
const chromeos::NetworkState* network =
handler->GetNetworkState(info->service_path);
if (!network)
continue;
bool prohibited_by_policy = IsProhibitedByPolicy(network);
info->image =
network_icon::GetImageForNetwork(network, network_icon::ICON_TYPE_LIST);
info->label =
......@@ -96,7 +129,12 @@ void NetworkListView::UpdateNetworkIcons() {
info->highlight =
network->IsConnectedState() || network->IsConnectingState();
info->disable =
network->activation_state() == shill::kActivationStateActivating;
(network->activation_state() == shill::kActivationStateActivating) ||
prohibited_by_policy;
if (prohibited_by_policy) {
info->tooltip =
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_PROHIBITED);
}
if (!animating && network->IsConnectingState())
animating = true;
}
......
......@@ -50,6 +50,7 @@
'../../chromeos/chromeos.gyp:chromeos',
'../../chromeos/chromeos.gyp:power_manager_proto',
'../../components/components.gyp:device_event_log_component',
'../../components/components.gyp:onc_component',
'../../skia/skia.gyp:skia',
'../aura/aura.gyp:aura',
'../base/ime/ui_base_ime.gyp:ui_base_ime',
......
......@@ -150,6 +150,12 @@
<message name="IDS_ASH_STATUS_TRAY_NETWORK_NOT_CONNECTED" desc="Description in status area or network list when no network is connected.">
No network
</message>
<message name="IDS_ASH_STATUS_TRAY_NETWORK_PROHIBITED" desc="Tooltip in network list when no network is prohibited by policy.">
This network is disabled by your administrator.
</message>
<message name="IDS_ASH_STATUS_TRAY_NETWORK_PROHIBITED_OTHER" desc="Tooltip in network list for joining other network when connecting unmanaged network is prohibited">
Connecting to other networks is disabled by your administrator.
</message>
<message name="IDS_ASH_STATUS_TRAY_NO_NETWORKS" desc="The message to display in the network info bubble when it is otherwise empty.">
No network information available
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment