| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/chromeos/status/network_menu.h" | 5 #include "chrome/browser/chromeos/status/network_menu.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 } | 748 } |
| 749 | 749 |
| 750 // No networks available message. | 750 // No networks available message. |
| 751 if (menu_items_.empty()) { | 751 if (menu_items_.empty()) { |
| 752 label = l10n_util::GetStringFUTF16(IDS_STATUSBAR_NETWORK_MENU_ITEM_INDENT, | 752 label = l10n_util::GetStringFUTF16(IDS_STATUSBAR_NETWORK_MENU_ITEM_INDENT, |
| 753 l10n_util::GetStringUTF16(IDS_STATUSBAR_NO_NETWORKS_MESSAGE)); | 753 l10n_util::GetStringUTF16(IDS_STATUSBAR_NO_NETWORKS_MESSAGE)); |
| 754 menu_items_.push_back(MenuItem(ui::MenuModel::TYPE_COMMAND, label, | 754 menu_items_.push_back(MenuItem(ui::MenuModel::TYPE_COMMAND, label, |
| 755 SkBitmap(), std::string(), FLAG_DISABLED)); | 755 SkBitmap(), std::string(), FLAG_DISABLED)); |
| 756 } | 756 } |
| 757 | 757 |
| 758 // If we are logged in and there is a connected network, | 758 // If we are logged in and there is a connected network or a connected VPN, |
| 759 // add submenu for Private Networks. | 759 // add submenu for Private Networks. |
| 760 if (is_browser_mode) { | 760 if (is_browser_mode) { |
| 761 const Network* connected_network = cros->connected_network(); | 761 if (cros->connected_network() || cros->virtual_network_connected()) { |
| 762 if (connected_network) { | |
| 763 menu_items_.push_back(MenuItem()); // Separator | 762 menu_items_.push_back(MenuItem()); // Separator |
| 764 const SkBitmap* icon = NetworkMenuIcon::GetVpnBitmap(); | 763 const SkBitmap* icon = NetworkMenuIcon::GetVpnBitmap(); |
| 765 menu_items_.push_back(MenuItem( | 764 menu_items_.push_back(MenuItem( |
| 766 ui::MenuModel::TYPE_SUBMENU, | 765 ui::MenuModel::TYPE_SUBMENU, |
| 767 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_PRIVATE_NETWORKS), | 766 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_PRIVATE_NETWORKS), |
| 768 *icon, vpn_menu_model_.get(), FLAG_NONE)); | 767 *icon, vpn_menu_model_.get(), FLAG_NONE)); |
| 769 vpn_menu_model_->InitMenuItems( | 768 vpn_menu_model_->InitMenuItems( |
| 770 is_browser_mode, should_open_button_options); | 769 is_browser_mode, should_open_button_options); |
| 771 } | 770 } |
| 772 } | 771 } |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 853 //////////////////////////////////////////////////////////////////////////////// | 852 //////////////////////////////////////////////////////////////////////////////// |
| 854 // VPNMenuModel | 853 // VPNMenuModel |
| 855 | 854 |
| 856 void VPNMenuModel::InitMenuItems(bool is_browser_mode, | 855 void VPNMenuModel::InitMenuItems(bool is_browser_mode, |
| 857 bool should_open_button_options) { | 856 bool should_open_button_options) { |
| 858 // This gets called on initialization, so any changes should be reflected | 857 // This gets called on initialization, so any changes should be reflected |
| 859 // in CrosMock::SetNetworkLibraryStatusAreaExpectations(). | 858 // in CrosMock::SetNetworkLibraryStatusAreaExpectations(). |
| 860 | 859 |
| 861 menu_items_.clear(); | 860 menu_items_.clear(); |
| 862 | 861 |
| 863 // VPN only applies if there's a connected underlying network. | 862 // Populate our MenuItems with the current list of virtual networks. |
| 864 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | 863 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); |
| 865 const Network* connected_network = cros->connected_network(); | |
| 866 if (!connected_network) | |
| 867 return; | |
| 868 | |
| 869 // Populate our MenuItems with the current list of virtual networks. | |
| 870 const VirtualNetworkVector& virtual_networks = cros->virtual_networks(); | 864 const VirtualNetworkVector& virtual_networks = cros->virtual_networks(); |
| 871 const VirtualNetwork* active_vpn = cros->virtual_network(); | 865 const VirtualNetwork* active_vpn = cros->virtual_network(); |
| 872 | 866 |
| 873 bool separator_added = false; | 867 bool separator_added = false; |
| 874 string16 label; | 868 string16 label; |
| 875 | 869 |
| 876 for (size_t i = 0; i < virtual_networks.size(); ++i) { | 870 for (size_t i = 0; i < virtual_networks.size(); ++i) { |
| 877 const VirtualNetwork* vpn = virtual_networks[i]; | 871 const VirtualNetwork* vpn = virtual_networks[i]; |
| 878 if (vpn->connecting()) { | 872 if (vpn->connecting()) { |
| 879 label = l10n_util::GetStringFUTF16( | 873 label = l10n_util::GetStringFUTF16( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 900 const SkBitmap* icon = NetworkMenuIcon::GetBitmap(vpn); | 894 const SkBitmap* icon = NetworkMenuIcon::GetBitmap(vpn); |
| 901 menu_items_.push_back( | 895 menu_items_.push_back( |
| 902 MenuItem(ui::MenuModel::TYPE_COMMAND, | 896 MenuItem(ui::MenuModel::TYPE_COMMAND, |
| 903 label, *icon, vpn->service_path(), flag)); | 897 label, *icon, vpn->service_path(), flag)); |
| 904 } | 898 } |
| 905 | 899 |
| 906 // Add option to add/disconnect from vpn. | 900 // Add option to add/disconnect from vpn. |
| 907 if (!menu_items_.empty()) { // Add separator if menu is not empty. | 901 if (!menu_items_.empty()) { // Add separator if menu is not empty. |
| 908 menu_items_.push_back(MenuItem()); | 902 menu_items_.push_back(MenuItem()); |
| 909 } | 903 } |
| 910 menu_items_.push_back(MenuItem( | 904 // Can only connect to a VPN if we have a connected network. |
| 911 ui::MenuModel::TYPE_COMMAND, | 905 if (cros->connected_network()) { |
| 912 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_ADD_VPN), | 906 menu_items_.push_back(MenuItem( |
| 913 SkBitmap(), std::string(), FLAG_ADD_VPN)); | 907 ui::MenuModel::TYPE_COMMAND, |
| 908 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_ADD_VPN), |
| 909 SkBitmap(), std::string(), FLAG_ADD_VPN)); |
| 910 } |
| 911 // Show disconnect if we have an active VPN. |
| 914 if (active_vpn) { | 912 if (active_vpn) { |
| 915 menu_items_.push_back(MenuItem( | 913 menu_items_.push_back(MenuItem( |
| 916 ui::MenuModel::TYPE_COMMAND, | 914 ui::MenuModel::TYPE_COMMAND, |
| 917 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DISCONNECT_VPN), | 915 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DISCONNECT_VPN), |
| 918 SkBitmap(), std::string(), FLAG_DISCONNECT_VPN)); | 916 SkBitmap(), std::string(), FLAG_DISCONNECT_VPN)); |
| 919 } | 917 } |
| 920 } | 918 } |
| 921 | 919 |
| 922 int VPNMenuModel::GetCommandIdAt(int index) const { | 920 int VPNMenuModel::GetCommandIdAt(int index) const { |
| 923 return index + kVPNIndexMask; | 921 return index + kVPNIndexMask; |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1076 std::string page = StringPrintf( | 1074 std::string page = StringPrintf( |
| 1077 "%s?servicePath=%s&networkType=%d&networkName=%s", | 1075 "%s?servicePath=%s&networkType=%d&networkName=%s", |
| 1078 chrome::kInternetOptionsSubPage, | 1076 chrome::kInternetOptionsSubPage, |
| 1079 EscapeUrlEncodedData(network->service_path(), true).c_str(), | 1077 EscapeUrlEncodedData(network->service_path(), true).c_str(), |
| 1080 network->type(), | 1078 network->type(), |
| 1081 EscapeUrlEncodedData(network_name, false).c_str()); | 1079 EscapeUrlEncodedData(network_name, false).c_str()); |
| 1082 browser->ShowOptionsTab(page); | 1080 browser->ShowOptionsTab(page); |
| 1083 } | 1081 } |
| 1084 | 1082 |
| 1085 } // namespace chromeos | 1083 } // namespace chromeos |
| OLD | NEW |