Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ash/system/network/vpn_list_view.h" | 5 #include "ash/system/network/vpn_list_view.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "ash/ash_view_ids.h" | 11 #include "ash/ash_view_ids.h" |
| 12 #include "ash/resources/vector_icons/vector_icons.h" | 12 #include "ash/resources/vector_icons/vector_icons.h" |
| 13 #include "ash/shell.h" | 13 #include "ash/shell.h" |
| 14 #include "ash/shell_port.h" | 14 #include "ash/shell_port.h" |
| 15 #include "ash/strings/grit/ash_strings.h" | 15 #include "ash/strings/grit/ash_strings.h" |
| 16 #include "ash/system/network/network_icon.h" | 16 #include "ash/system/network/network_icon.h" |
| 17 #include "ash/system/network/network_icon_animation.h" | 17 #include "ash/system/network/network_icon_animation.h" |
| 18 #include "ash/system/network/network_icon_animation_observer.h" | 18 #include "ash/system/network/network_icon_animation_observer.h" |
| 19 #include "ash/system/network/network_state_list_detailed_view.h" | 19 #include "ash/system/network/network_state_list_detailed_view.h" |
| 20 #include "ash/system/network/vpn_list.h" | 20 #include "ash/system/network/vpn_list.h" |
| 21 #include "ash/system/tray/hover_highlight_view.h" | 21 #include "ash/system/tray/hover_highlight_view.h" |
| 22 #include "ash/system/tray/system_menu_button.h" | 22 #include "ash/system/tray/system_menu_button.h" |
| 23 #include "ash/system/tray/system_tray_controller.h" | 23 #include "ash/system/tray/system_tray_controller.h" |
| 24 #include "ash/system/tray/throbber_view.h" | 24 #include "ash/system/tray/throbber_view.h" |
| 25 #include "ash/system/tray/tray_constants.h" | 25 #include "ash/system/tray/tray_constants.h" |
| 26 #include "ash/system/tray/tray_popup_utils.h" | 26 #include "ash/system/tray/tray_popup_utils.h" |
| 27 #include "ash/system/tray/tri_view.h" | 27 #include "ash/system/tray/tri_view.h" |
| 28 #include "ash/system/tray/view_click_listener.h" | |
| 28 #include "base/bind.h" | 29 #include "base/bind.h" |
| 29 #include "base/bind_helpers.h" | 30 #include "base/bind_helpers.h" |
| 30 #include "base/logging.h" | 31 #include "base/logging.h" |
| 31 #include "base/strings/utf_string_conversions.h" | 32 #include "base/strings/utf_string_conversions.h" |
| 32 #include "base/values.h" | 33 #include "base/values.h" |
| 33 #include "chromeos/network/network_connect.h" | 34 #include "chromeos/network/network_connect.h" |
| 34 #include "chromeos/network/network_handler.h" | 35 #include "chromeos/network/network_handler.h" |
| 35 #include "chromeos/network/network_state.h" | 36 #include "chromeos/network/network_state.h" |
| 36 #include "chromeos/network/network_type_pattern.h" | 37 #include "chromeos/network/network_type_pattern.h" |
| 37 #include "third_party/cros_system_api/dbus/service_constants.h" | 38 #include "third_party/cros_system_api/dbus/service_constants.h" |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 60 return false; | 61 return false; |
| 61 const bool network_uses_third_party_provider = | 62 const bool network_uses_third_party_provider = |
| 62 network.vpn_provider_type() == shill::kProviderThirdPartyVpn; | 63 network.vpn_provider_type() == shill::kProviderThirdPartyVpn; |
| 63 if (!provider.third_party) | 64 if (!provider.third_party) |
| 64 return !network_uses_third_party_provider; | 65 return !network_uses_third_party_provider; |
| 65 return network_uses_third_party_provider && | 66 return network_uses_third_party_provider && |
| 66 network.third_party_vpn_provider_extension_id() == | 67 network.third_party_vpn_provider_extension_id() == |
| 67 provider.extension_id; | 68 provider.extension_id; |
| 68 } | 69 } |
| 69 | 70 |
| 70 // The base class of all list entries, a |HoverHighlightView| with no border. | |
| 71 class VPNListEntryBase : public HoverHighlightView { | |
| 72 public: | |
| 73 // When the user clicks the entry, the |parent|'s OnViewClicked() will be | |
| 74 // invoked. | |
| 75 explicit VPNListEntryBase(VPNListView* parent); | |
| 76 | |
| 77 private: | |
| 78 DISALLOW_COPY_AND_ASSIGN(VPNListEntryBase); | |
| 79 }; | |
| 80 | |
| 81 // A list entry that represents a VPN provider. | 71 // A list entry that represents a VPN provider. |
| 82 class VPNListProviderEntry : public views::ButtonListener, public views::View { | 72 class VPNListProviderEntry : public views::ButtonListener, public views::View { |
| 83 public: | 73 public: |
| 84 VPNListProviderEntry(ViewClickListener* parent, | 74 VPNListProviderEntry(const VPNProvider& vpn_provider, |
| 85 bool top_item, | 75 bool top_item, |
| 86 const std::string& name, | 76 const std::string& name, |
| 87 int button_accessible_name_id) | 77 int button_accessible_name_id) |
| 88 : parent_(parent) { | 78 : vpn_provider_(vpn_provider) { |
| 89 TrayPopupUtils::ConfigureAsStickyHeader(this); | 79 TrayPopupUtils::ConfigureAsStickyHeader(this); |
| 90 SetLayoutManager(new views::FillLayout); | 80 SetLayoutManager(new views::FillLayout); |
| 91 TriView* tri_view = TrayPopupUtils::CreateSubHeaderRowView(false); | 81 TriView* tri_view = TrayPopupUtils::CreateSubHeaderRowView(false); |
| 92 AddChildView(tri_view); | 82 AddChildView(tri_view); |
| 93 | 83 |
| 94 views::Label* label = TrayPopupUtils::CreateDefaultLabel(); | 84 views::Label* label = TrayPopupUtils::CreateDefaultLabel(); |
| 95 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::SUB_HEADER); | 85 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::SUB_HEADER); |
| 96 style.SetupLabel(label); | 86 style.SetupLabel(label); |
| 97 label->SetText(base::ASCIIToUTF16(name)); | 87 label->SetText(base::ASCIIToUTF16(name)); |
| 98 tri_view->AddView(TriView::Container::CENTER, label); | 88 tri_view->AddView(TriView::Container::CENTER, label); |
| 99 | 89 |
| 100 const SkColor image_color = GetNativeTheme()->GetSystemColor( | 90 const SkColor image_color = GetNativeTheme()->GetSystemColor( |
| 101 ui::NativeTheme::kColorId_ProminentButtonColor); | 91 ui::NativeTheme::kColorId_ProminentButtonColor); |
| 102 gfx::ImageSkia icon = | 92 gfx::ImageSkia icon = |
| 103 gfx::CreateVectorIcon(kSystemMenuAddConnectionIcon, image_color); | 93 gfx::CreateVectorIcon(kSystemMenuAddConnectionIcon, image_color); |
| 104 SystemMenuButton* add_vpn_button = | 94 SystemMenuButton* add_vpn_button = |
| 105 new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED, icon, | 95 new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED, icon, |
| 106 icon, button_accessible_name_id); | 96 icon, button_accessible_name_id); |
| 107 add_vpn_button->SetInkDropColor(image_color); | 97 add_vpn_button->SetInkDropColor(image_color); |
| 108 add_vpn_button->SetEnabled(true); | 98 add_vpn_button->SetEnabled(true); |
| 109 tri_view->AddView(TriView::Container::END, add_vpn_button); | 99 tri_view->AddView(TriView::Container::END, add_vpn_button); |
| 110 } | 100 } |
| 111 | 101 |
| 112 protected: | 102 protected: |
| 113 // views::ButtonListener: | 103 // views::ButtonListener: |
| 114 void ButtonPressed(views::Button* sender, const ui::Event& event) override { | 104 void ButtonPressed(views::Button* sender, const ui::Event& event) override { |
| 115 parent_->OnViewClicked(this); | 105 // If the user clicks on a provider entry, request that the "add network" |
| 106 // dialog for this provider be shown. | |
| 107 if (vpn_provider_.third_party) { | |
| 108 ShellPort::Get()->RecordUserMetricsAction( | |
| 109 UMA_STATUS_AREA_VPN_ADD_THIRD_PARTY_CLICKED); | |
| 110 Shell::Get()->system_tray_controller()->ShowThirdPartyVpnCreate( | |
| 111 vpn_provider_.extension_id); | |
| 112 } else { | |
| 113 ShellPort::Get()->RecordUserMetricsAction( | |
| 114 UMA_STATUS_AREA_VPN_ADD_BUILT_IN_CLICKED); | |
| 115 Shell::Get()->system_tray_controller()->ShowNetworkCreate( | |
| 116 shill::kTypeVPN); | |
| 117 } | |
| 118 return; | |
|
tdanderson
2017/05/03 18:31:39
Looks like an unnecessary return
mohsen
2017/05/03 19:14:27
Removed.
| |
| 116 } | 119 } |
| 117 | 120 |
| 118 private: | 121 private: |
| 119 // Our parent to handle events. | 122 const VPNProvider vpn_provider_; |
|
tdanderson
2017/05/03 18:31:39
& ?
mohsen
2017/05/03 19:14:27
The original provider struct is destructed after t
| |
| 120 ViewClickListener* parent_; | |
| 121 | 123 |
| 122 DISALLOW_COPY_AND_ASSIGN(VPNListProviderEntry); | 124 DISALLOW_COPY_AND_ASSIGN(VPNListProviderEntry); |
| 123 }; | 125 }; |
| 124 | 126 |
| 125 // A list entry that represents a network. If the network is currently | 127 // A list entry that represents a network. If the network is currently |
| 126 // connecting, the icon shown by this list entry will be animated. If the | 128 // connecting, the icon shown by this list entry will be animated. If the |
| 127 // network is currently connected, a disconnect button will be shown next to its | 129 // network is currently connected, a disconnect button will be shown next to its |
| 128 // name. | 130 // name. |
| 129 class VPNListNetworkEntry : public VPNListEntryBase, | 131 class VPNListNetworkEntry : public HoverHighlightView, |
| 130 public network_icon::AnimationObserver { | 132 public network_icon::AnimationObserver { |
| 131 public: | 133 public: |
| 132 VPNListNetworkEntry(VPNListView* parent, | 134 VPNListNetworkEntry(ViewClickListener* listener, |
| 133 const chromeos::NetworkState* network); | 135 const chromeos::NetworkState* network); |
| 134 ~VPNListNetworkEntry() override; | 136 ~VPNListNetworkEntry() override; |
| 135 | 137 |
| 136 // network_icon::AnimationObserver: | 138 // network_icon::AnimationObserver: |
| 137 void NetworkIconChanged() override; | 139 void NetworkIconChanged() override; |
| 138 | 140 |
| 139 // views::ButtonListener: | 141 // views::ButtonListener: |
| 140 void ButtonPressed(Button* sender, const ui::Event& event) override; | 142 void ButtonPressed(Button* sender, const ui::Event& event) override; |
| 141 | 143 |
| 142 private: | 144 private: |
| 143 void UpdateFromNetworkState(const chromeos::NetworkState* network); | 145 void UpdateFromNetworkState(const chromeos::NetworkState* network); |
| 144 void SetupConnectedItem(const base::string16& text, | 146 void SetupConnectedItem(const base::string16& text, |
| 145 const gfx::ImageSkia& image); | 147 const gfx::ImageSkia& image); |
| 146 void SetupConnectingItem(const base::string16& text, | 148 void SetupConnectingItem(const base::string16& text, |
| 147 const gfx::ImageSkia& image); | 149 const gfx::ImageSkia& image); |
| 148 | 150 |
| 149 const std::string guid_; | 151 const std::string guid_; |
| 150 | 152 |
| 151 views::LabelButton* disconnect_button_ = nullptr; | 153 views::LabelButton* disconnect_button_ = nullptr; |
| 152 | 154 |
| 153 DISALLOW_COPY_AND_ASSIGN(VPNListNetworkEntry); | 155 DISALLOW_COPY_AND_ASSIGN(VPNListNetworkEntry); |
| 154 }; | 156 }; |
| 155 | 157 |
| 156 VPNListEntryBase::VPNListEntryBase(VPNListView* parent) | 158 VPNListNetworkEntry::VPNListNetworkEntry(ViewClickListener* listener, |
| 157 : HoverHighlightView(parent) {} | |
| 158 | |
| 159 VPNListNetworkEntry::VPNListNetworkEntry(VPNListView* parent, | |
| 160 const chromeos::NetworkState* network) | 159 const chromeos::NetworkState* network) |
| 161 : VPNListEntryBase(parent), guid_(network->guid()) { | 160 : HoverHighlightView(listener), guid_(network->guid()) { |
| 162 UpdateFromNetworkState(network); | 161 UpdateFromNetworkState(network); |
| 163 } | 162 } |
| 164 | 163 |
| 165 VPNListNetworkEntry::~VPNListNetworkEntry() { | 164 VPNListNetworkEntry::~VPNListNetworkEntry() { |
| 166 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); | 165 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
| 167 } | 166 } |
| 168 | 167 |
| 169 void VPNListNetworkEntry::NetworkIconChanged() { | 168 void VPNListNetworkEntry::NetworkIconChanged() { |
| 170 UpdateFromNetworkState(chromeos::NetworkHandler::Get() | 169 UpdateFromNetworkState(chromeos::NetworkHandler::Get() |
| 171 ->network_state_handler() | 170 ->network_state_handler() |
| 172 ->GetNetworkStateFromGuid(guid_)); | 171 ->GetNetworkStateFromGuid(guid_)); |
| 173 } | 172 } |
| 174 | 173 |
| 175 void VPNListNetworkEntry::ButtonPressed(Button* sender, | 174 void VPNListNetworkEntry::ButtonPressed(Button* sender, |
| 176 const ui::Event& event) { | 175 const ui::Event& event) { |
| 177 if (sender != disconnect_button_) { | 176 if (sender != disconnect_button_) { |
| 178 VPNListEntryBase::ButtonPressed(sender, event); | 177 HoverHighlightView::ButtonPressed(sender, event); |
| 179 return; | 178 return; |
| 180 } | 179 } |
| 181 | 180 |
| 182 chromeos::NetworkConnect::Get()->DisconnectFromNetworkId(guid_); | 181 chromeos::NetworkConnect::Get()->DisconnectFromNetworkId(guid_); |
| 183 } | 182 } |
| 184 | 183 |
| 185 void VPNListNetworkEntry::UpdateFromNetworkState( | 184 void VPNListNetworkEntry::UpdateFromNetworkState( |
| 186 const chromeos::NetworkState* network) { | 185 const chromeos::NetworkState* network) { |
| 187 if (network && network->IsConnectingState()) | 186 if (network && network->IsConnectingState()) |
| 188 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); | 187 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 330 if (entry == network_view_guid_map_.end()) | 329 if (entry == network_view_guid_map_.end()) |
| 331 return false; | 330 return false; |
| 332 *guid = entry->second; | 331 *guid = entry->second; |
| 333 return true; | 332 return true; |
| 334 } | 333 } |
| 335 | 334 |
| 336 void VPNListView::OnVPNProvidersChanged() { | 335 void VPNListView::OnVPNProvidersChanged() { |
| 337 Update(); | 336 Update(); |
| 338 } | 337 } |
| 339 | 338 |
| 340 void VPNListView::OnViewClicked(views::View* sender) { | |
| 341 const auto& provider_iter = provider_view_map_.find(sender); | |
| 342 if (provider_iter != provider_view_map_.end()) { | |
| 343 // If the user clicks on a provider entry, request that the "add network" | |
| 344 // dialog for this provider be shown. | |
| 345 const VPNProvider& provider = provider_iter->second; | |
| 346 if (provider.third_party) { | |
| 347 ShellPort::Get()->RecordUserMetricsAction( | |
| 348 UMA_STATUS_AREA_VPN_ADD_THIRD_PARTY_CLICKED); | |
| 349 Shell::Get()->system_tray_controller()->ShowThirdPartyVpnCreate( | |
| 350 provider.extension_id); | |
| 351 } else { | |
| 352 ShellPort::Get()->RecordUserMetricsAction( | |
| 353 UMA_STATUS_AREA_VPN_ADD_BUILT_IN_CLICKED); | |
| 354 Shell::Get()->system_tray_controller()->ShowNetworkCreate( | |
| 355 shill::kTypeVPN); | |
| 356 } | |
| 357 return; | |
| 358 } | |
| 359 | |
| 360 // If the user clicked on a network entry, let the |delegate_| trigger a | |
| 361 // connection attempt (if the network is currently disconnected) or show a | |
| 362 // configuration dialog (if the network is currently connected or connecting). | |
| 363 detailed_view()->OnNetworkEntryClicked(sender); | |
| 364 } | |
| 365 | |
| 366 void VPNListView::AddNetwork(const chromeos::NetworkState* network) { | 339 void VPNListView::AddNetwork(const chromeos::NetworkState* network) { |
| 367 views::View* entry(new VPNListNetworkEntry(this, network)); | 340 views::View* entry(new VPNListNetworkEntry(detailed_view(), network)); |
| 368 container()->AddChildView(entry); | 341 container()->AddChildView(entry); |
| 369 network_view_guid_map_[entry] = network->guid(); | 342 network_view_guid_map_[entry] = network->guid(); |
| 370 list_empty_ = false; | 343 list_empty_ = false; |
| 371 } | 344 } |
| 372 | 345 |
| 373 void VPNListView::AddProviderAndNetworks( | 346 void VPNListView::AddProviderAndNetworks( |
| 374 const VPNProvider& vpn_provider, | 347 const VPNProvider& vpn_provider, |
| 375 const chromeos::NetworkStateHandler::NetworkStateList& networks) { | 348 const chromeos::NetworkStateHandler::NetworkStateList& networks) { |
| 376 // Add a visual separator, unless this is the topmost entry in the list. | 349 // Add a visual separator, unless this is the topmost entry in the list. |
| 377 if (!list_empty_) | 350 if (!list_empty_) |
| 378 container()->AddChildView(TrayPopupUtils::CreateListSubHeaderSeparator()); | 351 container()->AddChildView(TrayPopupUtils::CreateListSubHeaderSeparator()); |
| 379 std::string vpn_name = | 352 std::string vpn_name = |
| 380 vpn_provider.third_party | 353 vpn_provider.third_party |
| 381 ? vpn_provider.third_party_provider_name | 354 ? vpn_provider.third_party_provider_name |
| 382 : l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_VPN_BUILT_IN_PROVIDER); | 355 : l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_VPN_BUILT_IN_PROVIDER); |
| 383 | 356 |
| 384 // Add a list entry for the VPN provider. | 357 // Add a list entry for the VPN provider. |
| 385 views::View* provider_view = nullptr; | 358 views::View* provider_view = nullptr; |
| 386 provider_view = new VPNListProviderEntry(this, list_empty_, vpn_name, | 359 provider_view = new VPNListProviderEntry(vpn_provider, list_empty_, vpn_name, |
| 387 IDS_ASH_STATUS_TRAY_ADD_CONNECTION); | 360 IDS_ASH_STATUS_TRAY_ADD_CONNECTION); |
| 388 container()->AddChildView(provider_view); | 361 container()->AddChildView(provider_view); |
| 389 provider_view_map_[provider_view] = vpn_provider; | 362 provider_view_map_[provider_view] = vpn_provider; |
| 390 list_empty_ = false; | 363 list_empty_ = false; |
| 391 // Add the networks belonging to this provider, in the priority order returned | 364 // Add the networks belonging to this provider, in the priority order returned |
| 392 // by shill. | 365 // by shill. |
| 393 for (const chromeos::NetworkState* const& network : networks) { | 366 for (const chromeos::NetworkState* const& network : networks) { |
| 394 if (VpnProviderMatchesNetwork(vpn_provider, *network)) | 367 if (VpnProviderMatchesNetwork(vpn_provider, *network)) |
| 395 AddNetwork(network); | 368 AddNetwork(network); |
| 396 } | 369 } |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 416 } | 389 } |
| 417 } | 390 } |
| 418 | 391 |
| 419 // Add providers without any configured networks, in the order that the | 392 // Add providers without any configured networks, in the order that the |
| 420 // providers were returned by the extensions system. | 393 // providers were returned by the extensions system. |
| 421 for (const VPNProvider& provider : providers) | 394 for (const VPNProvider& provider : providers) |
| 422 AddProviderAndNetworks(provider, networks); | 395 AddProviderAndNetworks(provider, networks); |
| 423 } | 396 } |
| 424 | 397 |
| 425 } // namespace ash | 398 } // namespace ash |
| OLD | NEW |