| 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/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/chromeos/choose_mobile_network_dialog.h" | 13 #include "chrome/browser/chromeos/choose_mobile_network_dialog.h" |
| 14 #include "chrome/browser/chromeos/cros/cros_library.h" | 14 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 15 #include "chrome/browser/chromeos/mobile_config.h" | 15 #include "chrome/browser/chromeos/mobile_config.h" |
| 16 #include "chrome/browser/chromeos/options/network_config_view.h" | 16 #include "chrome/browser/chromeos/options/network_config_view.h" |
| 17 #include "chrome/browser/chromeos/sim_dialog_delegate.h" | 17 #include "chrome/browser/chromeos/sim_dialog_delegate.h" |
| 18 #include "chrome/browser/chromeos/status/network_menu_icon.h" | 18 #include "chrome/browser/chromeos/status/network_menu_icon.h" |
| 19 #include "chrome/browser/chromeos/status/status_area_view_chromeos.h" |
| 19 #include "chrome/browser/defaults.h" | 20 #include "chrome/browser/defaults.h" |
| 20 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
| 21 #include "chrome/browser/ui/browser_list.h" | 22 #include "chrome/browser/ui/browser_list.h" |
| 22 #include "chrome/browser/ui/views/window.h" | 23 #include "chrome/browser/ui/views/window.h" |
| 23 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
| 24 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
| 25 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 26 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
| 27 #include "grit/theme_resources.h" | 28 #include "grit/theme_resources.h" |
| 28 #include "net/base/escape.h" | 29 #include "net/base/escape.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 virtual ~NetworkMenuModel() {} | 128 virtual ~NetworkMenuModel() {} |
| 128 | 129 |
| 129 // Connect or reconnect to the network at |index|. | 130 // Connect or reconnect to the network at |index|. |
| 130 // If remember >= 0, set the favorite state of the network. | 131 // If remember >= 0, set the favorite state of the network. |
| 131 void ConnectToNetworkAt(int index, | 132 void ConnectToNetworkAt(int index, |
| 132 const std::string& passphrase, | 133 const std::string& passphrase, |
| 133 const std::string& ssid, | 134 const std::string& ssid, |
| 134 int remember) const; | 135 int remember) const; |
| 135 | 136 |
| 136 // Called by NetworkMenu::RunMenu to initialize list of menu items. | 137 // Called by NetworkMenu::RunMenu to initialize list of menu items. |
| 137 virtual void InitMenuItems(bool is_browser_mode, | 138 virtual void InitMenuItems(bool should_open_button_options) = 0; |
| 138 bool should_open_button_options) = 0; | |
| 139 | 139 |
| 140 // Menu item field accessors. | 140 // Menu item field accessors. |
| 141 const MenuItemVector& menu_items() const { return menu_items_; } | 141 const MenuItemVector& menu_items() const { return menu_items_; } |
| 142 | 142 |
| 143 // ui::MenuModel implementation | 143 // ui::MenuModel implementation |
| 144 // GetCommandIdAt() must be implemented by subclasses. | 144 // GetCommandIdAt() must be implemented by subclasses. |
| 145 virtual bool HasIcons() const OVERRIDE; | 145 virtual bool HasIcons() const OVERRIDE; |
| 146 virtual int GetItemCount() const OVERRIDE; | 146 virtual int GetItemCount() const OVERRIDE; |
| 147 virtual ui::MenuModel::ItemType GetTypeAt(int index) const OVERRIDE; | 147 virtual ui::MenuModel::ItemType GetTypeAt(int index) const OVERRIDE; |
| 148 virtual string16 GetLabelAt(int index) const OVERRIDE; | 148 virtual string16 GetLabelAt(int index) const OVERRIDE; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 DISALLOW_COPY_AND_ASSIGN(NetworkMenuModel); | 207 DISALLOW_COPY_AND_ASSIGN(NetworkMenuModel); |
| 208 }; | 208 }; |
| 209 | 209 |
| 210 | 210 |
| 211 class MoreMenuModel : public NetworkMenuModel { | 211 class MoreMenuModel : public NetworkMenuModel { |
| 212 public: | 212 public: |
| 213 explicit MoreMenuModel(NetworkMenu* owner) : NetworkMenuModel(owner) {} | 213 explicit MoreMenuModel(NetworkMenu* owner) : NetworkMenuModel(owner) {} |
| 214 virtual ~MoreMenuModel() {} | 214 virtual ~MoreMenuModel() {} |
| 215 | 215 |
| 216 // NetworkMenuModel implementation. | 216 // NetworkMenuModel implementation. |
| 217 virtual void InitMenuItems(bool is_browser_mode, | 217 virtual void InitMenuItems(bool should_open_button_options) OVERRIDE; |
| 218 bool should_open_button_options) OVERRIDE; | |
| 219 | 218 |
| 220 // ui::MenuModel implementation | 219 // ui::MenuModel implementation |
| 221 virtual int GetCommandIdAt(int index) const OVERRIDE; | 220 virtual int GetCommandIdAt(int index) const OVERRIDE; |
| 222 | 221 |
| 223 private: | 222 private: |
| 224 DISALLOW_COPY_AND_ASSIGN(MoreMenuModel); | 223 DISALLOW_COPY_AND_ASSIGN(MoreMenuModel); |
| 225 }; | 224 }; |
| 226 | 225 |
| 227 class VPNMenuModel : public NetworkMenuModel { | 226 class VPNMenuModel : public NetworkMenuModel { |
| 228 public: | 227 public: |
| 229 explicit VPNMenuModel(NetworkMenu* owner) : NetworkMenuModel(owner) {} | 228 explicit VPNMenuModel(NetworkMenu* owner) : NetworkMenuModel(owner) {} |
| 230 virtual ~VPNMenuModel() {} | 229 virtual ~VPNMenuModel() {} |
| 231 | 230 |
| 232 // NetworkMenuModel implementation. | 231 // NetworkMenuModel implementation. |
| 233 virtual void InitMenuItems(bool is_browser_mode, | 232 virtual void InitMenuItems(bool should_open_button_options) OVERRIDE; |
| 234 bool should_open_button_options) OVERRIDE; | |
| 235 | 233 |
| 236 // ui::MenuModel implementation | 234 // ui::MenuModel implementation |
| 237 virtual int GetCommandIdAt(int index) const OVERRIDE; | 235 virtual int GetCommandIdAt(int index) const OVERRIDE; |
| 238 | 236 |
| 239 private: | 237 private: |
| 240 DISALLOW_COPY_AND_ASSIGN(VPNMenuModel); | 238 DISALLOW_COPY_AND_ASSIGN(VPNMenuModel); |
| 241 }; | 239 }; |
| 242 | 240 |
| 243 class MainMenuModel : public NetworkMenuModel { | 241 class MainMenuModel : public NetworkMenuModel { |
| 244 public: | 242 public: |
| 245 explicit MainMenuModel(NetworkMenu* owner) | 243 explicit MainMenuModel(NetworkMenu* owner) |
| 246 : NetworkMenuModel(owner), | 244 : NetworkMenuModel(owner), |
| 247 vpn_menu_model_(new VPNMenuModel(owner)), | 245 vpn_menu_model_(new VPNMenuModel(owner)), |
| 248 more_menu_model_(new MoreMenuModel(owner)) { | 246 more_menu_model_(new MoreMenuModel(owner)) { |
| 249 } | 247 } |
| 250 virtual ~MainMenuModel() {} | 248 virtual ~MainMenuModel() {} |
| 251 | 249 |
| 252 // NetworkMenuModel implementation. | 250 // NetworkMenuModel implementation. |
| 253 virtual void InitMenuItems(bool is_browser_mode, | 251 virtual void InitMenuItems(bool should_open_button_options) OVERRIDE; |
| 254 bool should_open_button_options) OVERRIDE; | |
| 255 | 252 |
| 256 // ui::MenuModel implementation | 253 // ui::MenuModel implementation |
| 257 virtual int GetCommandIdAt(int index) const OVERRIDE; | 254 virtual int GetCommandIdAt(int index) const OVERRIDE; |
| 258 | 255 |
| 259 private: | 256 private: |
| 260 scoped_ptr<NetworkMenuModel> vpn_menu_model_; | 257 scoped_ptr<NetworkMenuModel> vpn_menu_model_; |
| 261 scoped_ptr<MoreMenuModel> more_menu_model_; | 258 scoped_ptr<MoreMenuModel> more_menu_model_; |
| 262 | 259 |
| 263 DISALLOW_COPY_AND_ASSIGN(MainMenuModel); | 260 DISALLOW_COPY_AND_ASSIGN(MainMenuModel); |
| 264 }; | 261 }; |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 ChooseMobileNetworkDialog::ShowDialog( | 496 ChooseMobileNetworkDialog::ShowDialog( |
| 500 owner_->delegate()->GetNativeWindow()); | 497 owner_->delegate()->GetNativeWindow()); |
| 501 } else { | 498 } else { |
| 502 ShowNetworkConfigView(new NetworkConfigView(type)); | 499 ShowNetworkConfigView(new NetworkConfigView(type)); |
| 503 } | 500 } |
| 504 } | 501 } |
| 505 | 502 |
| 506 //////////////////////////////////////////////////////////////////////////////// | 503 //////////////////////////////////////////////////////////////////////////////// |
| 507 // MainMenuModel | 504 // MainMenuModel |
| 508 | 505 |
| 509 void MainMenuModel::InitMenuItems(bool is_browser_mode, | 506 void MainMenuModel::InitMenuItems(bool should_open_button_options) { |
| 510 bool should_open_button_options) { | |
| 511 // This gets called on initialization, so any changes should be reflected | 507 // This gets called on initialization, so any changes should be reflected |
| 512 // in CrosMock::SetNetworkLibraryStatusAreaExpectations(). | 508 // in CrosMock::SetNetworkLibraryStatusAreaExpectations(). |
| 513 | 509 |
| 514 menu_items_.clear(); | 510 menu_items_.clear(); |
| 515 | 511 |
| 516 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | 512 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); |
| 517 if (cros->IsLocked()) { | 513 if (cros->IsLocked()) { |
| 518 menu_items_.push_back( | 514 menu_items_.push_back( |
| 519 MenuItem(ui::MenuModel::TYPE_COMMAND, | 515 MenuItem(ui::MenuModel::TYPE_COMMAND, |
| 520 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_LOCKED), | 516 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_LOCKED), |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 const CellularNetworkVector& cell_networks = cros->cellular_networks(); | 609 const CellularNetworkVector& cell_networks = cros->cellular_networks(); |
| 614 const CellularNetwork* active_cellular = cros->cellular_network(); | 610 const CellularNetwork* active_cellular = cros->cellular_network(); |
| 615 | 611 |
| 616 bool separator_added = false; | 612 bool separator_added = false; |
| 617 // List Cellular networks. | 613 // List Cellular networks. |
| 618 for (size_t i = 0; i < cell_networks.size(); ++i) { | 614 for (size_t i = 0; i < cell_networks.size(); ++i) { |
| 619 chromeos::ActivationState activation_state = | 615 chromeos::ActivationState activation_state = |
| 620 cell_networks[i]->activation_state(); | 616 cell_networks[i]->activation_state(); |
| 621 | 617 |
| 622 // If we are on the OOBE/login screen, do not show activating 3G option. | 618 // If we are on the OOBE/login screen, do not show activating 3G option. |
| 623 if (!is_browser_mode && activation_state != ACTIVATION_STATE_ACTIVATED) | 619 if (!StatusAreaViewChromeos::IsBrowserMode() && |
| 620 activation_state != ACTIVATION_STATE_ACTIVATED) |
| 624 continue; | 621 continue; |
| 625 | 622 |
| 626 // Ampersand is a valid character in a network name, but menu2 uses it | 623 // Ampersand is a valid character in a network name, but menu2 uses it |
| 627 // to mark "mnemonics" for keyboard shortcuts. http://crosbug.com/14697 | 624 // to mark "mnemonics" for keyboard shortcuts. http://crosbug.com/14697 |
| 628 std::string network_name = EscapeAmpersands(cell_networks[i]->name()); | 625 std::string network_name = EscapeAmpersands(cell_networks[i]->name()); |
| 629 if (activation_state == ACTIVATION_STATE_NOT_ACTIVATED || | 626 if (activation_state == ACTIVATION_STATE_NOT_ACTIVATED || |
| 630 activation_state == ACTIVATION_STATE_PARTIALLY_ACTIVATED) { | 627 activation_state == ACTIVATION_STATE_PARTIALLY_ACTIVATED) { |
| 631 label = l10n_util::GetStringFUTF16( | 628 label = l10n_util::GetStringFUTF16( |
| 632 IDS_STATUSBAR_NETWORK_DEVICE_ACTIVATE, | 629 IDS_STATUSBAR_NETWORK_DEVICE_ACTIVATE, |
| 633 UTF8ToUTF16(network_name)); | 630 UTF8ToUTF16(network_name)); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 MenuItem(ui::MenuModel::TYPE_COMMAND, | 677 MenuItem(ui::MenuModel::TYPE_COMMAND, |
| 681 label, SkBitmap(), | 678 label, SkBitmap(), |
| 682 std::string(), FLAG_DISABLED)); | 679 std::string(), FLAG_DISABLED)); |
| 683 } | 680 } |
| 684 } | 681 } |
| 685 } | 682 } |
| 686 const NetworkDevice* cellular_device = cros->FindCellularDevice(); | 683 const NetworkDevice* cellular_device = cros->FindCellularDevice(); |
| 687 if (cellular_device) { | 684 if (cellular_device) { |
| 688 // Add "View Account" with top up URL if we know that. | 685 // Add "View Account" with top up URL if we know that. |
| 689 MobileConfig* config = MobileConfig::GetInstance(); | 686 MobileConfig* config = MobileConfig::GetInstance(); |
| 690 if (is_browser_mode && config->IsReady()) { | 687 if (StatusAreaViewChromeos::IsBrowserMode() && config->IsReady()) { |
| 691 std::string carrier_id = cros->GetCellularHomeCarrierId(); | 688 std::string carrier_id = cros->GetCellularHomeCarrierId(); |
| 692 // If we don't have top up URL cached. | 689 // If we don't have top up URL cached. |
| 693 if (carrier_id != carrier_id_) { | 690 if (carrier_id != carrier_id_) { |
| 694 // Mark that we've checked this carrier ID. | 691 // Mark that we've checked this carrier ID. |
| 695 carrier_id_ = carrier_id; | 692 carrier_id_ = carrier_id; |
| 696 top_up_url_.clear(); | 693 top_up_url_.clear(); |
| 697 const MobileConfig::Carrier* carrier = config->GetCarrier(carrier_id); | 694 const MobileConfig::Carrier* carrier = config->GetCarrier(carrier_id); |
| 698 if (carrier && !carrier->top_up_url().empty()) | 695 if (carrier && !carrier->top_up_url().empty()) |
| 699 top_up_url_ = carrier->top_up_url(); | 696 top_up_url_ = carrier->top_up_url(); |
| 700 } | 697 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 725 // No networks available message. | 722 // No networks available message. |
| 726 if (menu_items_.empty()) { | 723 if (menu_items_.empty()) { |
| 727 label = l10n_util::GetStringFUTF16(IDS_STATUSBAR_NETWORK_MENU_ITEM_INDENT, | 724 label = l10n_util::GetStringFUTF16(IDS_STATUSBAR_NETWORK_MENU_ITEM_INDENT, |
| 728 l10n_util::GetStringUTF16(IDS_STATUSBAR_NO_NETWORKS_MESSAGE)); | 725 l10n_util::GetStringUTF16(IDS_STATUSBAR_NO_NETWORKS_MESSAGE)); |
| 729 menu_items_.push_back(MenuItem(ui::MenuModel::TYPE_COMMAND, label, | 726 menu_items_.push_back(MenuItem(ui::MenuModel::TYPE_COMMAND, label, |
| 730 SkBitmap(), std::string(), FLAG_DISABLED)); | 727 SkBitmap(), std::string(), FLAG_DISABLED)); |
| 731 } | 728 } |
| 732 | 729 |
| 733 // If we are logged in and there is a connected network or a connected VPN, | 730 // If we are logged in and there is a connected network or a connected VPN, |
| 734 // add submenu for Private Networks. | 731 // add submenu for Private Networks. |
| 735 if (is_browser_mode) { | 732 if (StatusAreaViewChromeos::IsBrowserMode()) { |
| 736 if (cros->connected_network() || cros->virtual_network_connected()) { | 733 if (cros->connected_network() || cros->virtual_network_connected()) { |
| 737 menu_items_.push_back(MenuItem()); // Separator | 734 menu_items_.push_back(MenuItem()); // Separator |
| 738 const SkBitmap icon = NetworkMenuIcon::GetVpnBitmap(); | 735 const SkBitmap icon = NetworkMenuIcon::GetVpnBitmap(); |
| 739 menu_items_.push_back(MenuItem( | 736 menu_items_.push_back(MenuItem( |
| 740 ui::MenuModel::TYPE_SUBMENU, | 737 ui::MenuModel::TYPE_SUBMENU, |
| 741 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_PRIVATE_NETWORKS), | 738 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_PRIVATE_NETWORKS), |
| 742 icon, vpn_menu_model_.get(), FLAG_NONE)); | 739 icon, vpn_menu_model_.get(), FLAG_NONE)); |
| 743 vpn_menu_model_->InitMenuItems( | 740 vpn_menu_model_->InitMenuItems(should_open_button_options); |
| 744 is_browser_mode, should_open_button_options); | |
| 745 } | 741 } |
| 746 } | 742 } |
| 747 | 743 |
| 748 bool show_wifi_scanning = wifi_available && cros->wifi_scanning(); | 744 bool show_wifi_scanning = wifi_available && cros->wifi_scanning(); |
| 749 // Do not show disable wifi during oobe | 745 // Do not show disable wifi during oobe |
| 750 bool show_toggle_wifi = wifi_available && | 746 bool show_toggle_wifi = wifi_available && |
| 751 (should_open_button_options || !wifi_enabled); | 747 (should_open_button_options || !wifi_enabled); |
| 752 // Do not show disable cellular during oobe | 748 // Do not show disable cellular during oobe |
| 753 bool show_toggle_cellular = cellular_available && | 749 bool show_toggle_cellular = cellular_available && |
| 754 (should_open_button_options || !cellular_enabled); | 750 (should_open_button_options || !cellular_enabled); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 808 // TODO(chocobo): Uncomment once we figure out how to do offline mode. | 804 // TODO(chocobo): Uncomment once we figure out how to do offline mode. |
| 809 // menu_items_.push_back(MenuItem(cros->offline_mode() ? | 805 // menu_items_.push_back(MenuItem(cros->offline_mode() ? |
| 810 // ui::MenuModel::TYPE_CHECK : ui::MenuModel::TYPE_COMMAND, | 806 // ui::MenuModel::TYPE_CHECK : ui::MenuModel::TYPE_COMMAND, |
| 811 // l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_OFFLINE_MODE), | 807 // l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_OFFLINE_MODE), |
| 812 // SkBitmap(), std::string(), FLAG_TOGGLE_OFFLINE)); | 808 // SkBitmap(), std::string(), FLAG_TOGGLE_OFFLINE)); |
| 813 | 809 |
| 814 // Additional links like: | 810 // Additional links like: |
| 815 // * Network settings; | 811 // * Network settings; |
| 816 // * IP Address on active interface; | 812 // * IP Address on active interface; |
| 817 // * Hardware addresses for wifi and ethernet. | 813 // * Hardware addresses for wifi and ethernet. |
| 818 more_menu_model_->InitMenuItems(is_browser_mode, should_open_button_options); | 814 more_menu_model_->InitMenuItems(should_open_button_options); |
| 819 if (!more_menu_model_->menu_items().empty()) { | 815 if (!more_menu_model_->menu_items().empty()) { |
| 820 menu_items_.push_back(MenuItem()); // Separator | 816 menu_items_.push_back(MenuItem()); // Separator |
| 821 if (is_browser_mode) { | 817 if (StatusAreaViewChromeos::IsBrowserMode()) { |
| 822 // In browser mode we do not want separate submenu, inline items. | 818 // In browser mode we do not want separate submenu, inline items. |
| 823 menu_items_.insert( | 819 menu_items_.insert( |
| 824 menu_items_.end(), | 820 menu_items_.end(), |
| 825 more_menu_model_->menu_items().begin(), | 821 more_menu_model_->menu_items().begin(), |
| 826 more_menu_model_->menu_items().end()); | 822 more_menu_model_->menu_items().end()); |
| 827 } else { | 823 } else { |
| 828 menu_items_.push_back(MenuItem( | 824 menu_items_.push_back(MenuItem( |
| 829 ui::MenuModel::TYPE_SUBMENU, | 825 ui::MenuModel::TYPE_SUBMENU, |
| 830 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_MORE), | 826 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_MORE), |
| 831 SkBitmap(), more_menu_model_.get(), FLAG_NONE)); | 827 SkBitmap(), more_menu_model_.get(), FLAG_NONE)); |
| 832 } | 828 } |
| 833 } | 829 } |
| 834 } | 830 } |
| 835 | 831 |
| 836 int MainMenuModel::GetCommandIdAt(int index) const { | 832 int MainMenuModel::GetCommandIdAt(int index) const { |
| 837 return index + kMainIndexMask; | 833 return index + kMainIndexMask; |
| 838 } | 834 } |
| 839 | 835 |
| 840 //////////////////////////////////////////////////////////////////////////////// | 836 //////////////////////////////////////////////////////////////////////////////// |
| 841 // VPNMenuModel | 837 // VPNMenuModel |
| 842 | 838 |
| 843 void VPNMenuModel::InitMenuItems(bool is_browser_mode, | 839 void VPNMenuModel::InitMenuItems(bool should_open_button_options) { |
| 844 bool should_open_button_options) { | |
| 845 // This gets called on initialization, so any changes should be reflected | 840 // This gets called on initialization, so any changes should be reflected |
| 846 // in CrosMock::SetNetworkLibraryStatusAreaExpectations(). | 841 // in CrosMock::SetNetworkLibraryStatusAreaExpectations(). |
| 847 | 842 |
| 848 menu_items_.clear(); | 843 menu_items_.clear(); |
| 849 | 844 |
| 850 // Populate our MenuItems with the current list of virtual networks. | 845 // Populate our MenuItems with the current list of virtual networks. |
| 851 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | 846 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); |
| 852 const VirtualNetworkVector& virtual_networks = cros->virtual_networks(); | 847 const VirtualNetworkVector& virtual_networks = cros->virtual_networks(); |
| 853 const VirtualNetwork* active_vpn = cros->virtual_network(); | 848 const VirtualNetwork* active_vpn = cros->virtual_network(); |
| 854 | 849 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 896 } | 891 } |
| 897 } | 892 } |
| 898 | 893 |
| 899 int VPNMenuModel::GetCommandIdAt(int index) const { | 894 int VPNMenuModel::GetCommandIdAt(int index) const { |
| 900 return index + kVPNIndexMask; | 895 return index + kVPNIndexMask; |
| 901 } | 896 } |
| 902 | 897 |
| 903 //////////////////////////////////////////////////////////////////////////////// | 898 //////////////////////////////////////////////////////////////////////////////// |
| 904 // MoreMenuModel | 899 // MoreMenuModel |
| 905 | 900 |
| 906 void MoreMenuModel::InitMenuItems( | 901 void MoreMenuModel::InitMenuItems(bool should_open_button_options) { |
| 907 bool is_browser_mode, bool should_open_button_options) { | |
| 908 // This gets called on initialization, so any changes should be reflected | 902 // This gets called on initialization, so any changes should be reflected |
| 909 // in CrosMock::SetNetworkLibraryStatusAreaExpectations(). | 903 // in CrosMock::SetNetworkLibraryStatusAreaExpectations(). |
| 910 | 904 |
| 911 menu_items_.clear(); | 905 menu_items_.clear(); |
| 912 MenuItemVector link_items; | 906 MenuItemVector link_items; |
| 913 MenuItemVector address_items; | 907 MenuItemVector address_items; |
| 914 | 908 |
| 915 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | 909 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); |
| 916 bool oobe = !should_open_button_options; // we don't show options for OOBE. | 910 bool oobe = !should_open_button_options; // we don't show options for OOBE. |
| 917 bool connected = cros->Connected(); // always call for test expectations. | 911 bool connected = cros->Connected(); // always call for test expectations. |
| 918 if (!oobe) { | 912 if (!oobe) { |
| 919 int message_id = -1; | 913 int message_id = -1; |
| 920 if (is_browser_mode) | 914 if (StatusAreaViewChromeos::IsBrowserMode()) |
| 921 message_id = IDS_STATUSBAR_NETWORK_OPEN_OPTIONS_DIALOG; | 915 message_id = IDS_STATUSBAR_NETWORK_OPEN_OPTIONS_DIALOG; |
| 922 else if (connected) | 916 else if (connected) |
| 923 message_id = IDS_STATUSBAR_NETWORK_OPEN_PROXY_SETTINGS_DIALOG; | 917 message_id = IDS_STATUSBAR_NETWORK_OPEN_PROXY_SETTINGS_DIALOG; |
| 924 if (message_id != -1) { | 918 if (message_id != -1) { |
| 925 link_items.push_back(MenuItem(ui::MenuModel::TYPE_COMMAND, | 919 link_items.push_back(MenuItem(ui::MenuModel::TYPE_COMMAND, |
| 926 l10n_util::GetStringUTF16(message_id), | 920 l10n_util::GetStringUTF16(message_id), |
| 927 SkBitmap(), std::string(), FLAG_OPTIONS)); | 921 SkBitmap(), std::string(), FLAG_OPTIONS)); |
| 928 } | 922 } |
| 929 } | 923 } |
| 930 | 924 |
| 931 if (connected) { | 925 if (connected) { |
| 932 std::string ip_address = cros->IPAddress(); | 926 std::string ip_address = cros->IPAddress(); |
| 933 if (!ip_address.empty()) { | 927 if (!ip_address.empty()) { |
| 934 address_items.push_back(MenuItem(ui::MenuModel::TYPE_COMMAND, | 928 address_items.push_back(MenuItem(ui::MenuModel::TYPE_COMMAND, |
| 935 ASCIIToUTF16(cros->IPAddress()), SkBitmap(), std::string(), | 929 ASCIIToUTF16(cros->IPAddress()), SkBitmap(), std::string(), |
| 936 FLAG_DISABLED)); | 930 FLAG_DISABLED)); |
| 937 } | 931 } |
| 938 } | 932 } |
| 939 | 933 |
| 940 if (!is_browser_mode) { | 934 if (!StatusAreaViewChromeos::IsBrowserMode()) { |
| 941 const NetworkDevice* ether = cros->FindEthernetDevice(); | 935 const NetworkDevice* ether = cros->FindEthernetDevice(); |
| 942 if (ether) { | 936 if (ether) { |
| 943 std::string hardware_address; | 937 std::string hardware_address; |
| 944 cros->GetIPConfigs(ether->device_path(), &hardware_address, | 938 cros->GetIPConfigs(ether->device_path(), &hardware_address, |
| 945 NetworkLibrary::FORMAT_COLON_SEPARATED_HEX); | 939 NetworkLibrary::FORMAT_COLON_SEPARATED_HEX); |
| 946 if (!hardware_address.empty()) { | 940 if (!hardware_address.empty()) { |
| 947 std::string label = l10n_util::GetStringUTF8( | 941 std::string label = l10n_util::GetStringUTF8( |
| 948 IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET) + " " + hardware_address; | 942 IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET) + " " + hardware_address; |
| 949 address_items.push_back(MenuItem(ui::MenuModel::TYPE_COMMAND, | 943 address_items.push_back(MenuItem(ui::MenuModel::TYPE_COMMAND, |
| 950 UTF8ToUTF16(label), SkBitmap(), std::string(), FLAG_DISABLED)); | 944 UTF8ToUTF16(label), SkBitmap(), std::string(), FLAG_DISABLED)); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 974 address_items.begin(), address_items.end()); | 968 address_items.begin(), address_items.end()); |
| 975 } | 969 } |
| 976 | 970 |
| 977 int MoreMenuModel::GetCommandIdAt(int index) const { | 971 int MoreMenuModel::GetCommandIdAt(int index) const { |
| 978 return index + kMoreIndexMask; | 972 return index + kMoreIndexMask; |
| 979 } | 973 } |
| 980 | 974 |
| 981 //////////////////////////////////////////////////////////////////////////////// | 975 //////////////////////////////////////////////////////////////////////////////// |
| 982 // NetworkMenu | 976 // NetworkMenu |
| 983 | 977 |
| 984 NetworkMenu::NetworkMenu(Delegate* delegate, bool is_browser_mode) | 978 NetworkMenu::NetworkMenu(Delegate* delegate) |
| 985 : delegate_(delegate), | 979 : delegate_(delegate), |
| 986 is_browser_mode_(is_browser_mode), | |
| 987 refreshing_menu_(false), | 980 refreshing_menu_(false), |
| 988 menu_item_view_(NULL), | 981 menu_item_view_(NULL), |
| 989 min_width_(kDefaultMinimumWidth) { | 982 min_width_(kDefaultMinimumWidth) { |
| 990 main_menu_model_.reset(new MainMenuModel(this)); | 983 main_menu_model_.reset(new MainMenuModel(this)); |
| 991 menu_model_adapter_.reset( | 984 menu_model_adapter_.reset( |
| 992 new views::MenuModelAdapter(main_menu_model_.get())); | 985 new views::MenuModelAdapter(main_menu_model_.get())); |
| 993 menu_item_view_ = new views::MenuItemView(menu_model_adapter_.get()); | 986 menu_item_view_ = new views::MenuItemView(menu_model_adapter_.get()); |
| 994 menu_item_view_->set_has_icons(true); | 987 menu_item_view_->set_has_icons(true); |
| 995 #if !defined(USE_AURA) | 988 #if !defined(USE_AURA) |
| 996 menu_item_view_->set_menu_position( | 989 menu_item_view_->set_menu_position( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1007 } | 1000 } |
| 1008 | 1001 |
| 1009 void NetworkMenu::CancelMenu() { | 1002 void NetworkMenu::CancelMenu() { |
| 1010 menu_runner_->Cancel(); | 1003 menu_runner_->Cancel(); |
| 1011 } | 1004 } |
| 1012 | 1005 |
| 1013 void NetworkMenu::UpdateMenu() { | 1006 void NetworkMenu::UpdateMenu() { |
| 1014 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1007 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1015 | 1008 |
| 1016 refreshing_menu_ = true; | 1009 refreshing_menu_ = true; |
| 1017 main_menu_model_->InitMenuItems( | 1010 main_menu_model_->InitMenuItems(delegate_->ShouldOpenButtonOptions()); |
| 1018 is_browser_mode(), delegate_->ShouldOpenButtonOptions()); | |
| 1019 | 1011 |
| 1020 menu_model_adapter_->BuildMenu(menu_item_view_); | 1012 menu_model_adapter_->BuildMenu(menu_item_view_); |
| 1021 SetMenuMargins(menu_item_view_, kTopMargin, kBottomMargin); | 1013 SetMenuMargins(menu_item_view_, kTopMargin, kBottomMargin); |
| 1022 menu_item_view_->ChildrenChanged(); | 1014 menu_item_view_->ChildrenChanged(); |
| 1023 | 1015 |
| 1024 refreshing_menu_ = false; | 1016 refreshing_menu_ = false; |
| 1025 } | 1017 } |
| 1026 | 1018 |
| 1027 void NetworkMenu::RunMenu(views::View* source) { | 1019 void NetworkMenu::RunMenu(views::View* source) { |
| 1028 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | 1020 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1053 std::string page = StringPrintf( | 1045 std::string page = StringPrintf( |
| 1054 "%s?servicePath=%s&networkType=%d&networkName=%s", | 1046 "%s?servicePath=%s&networkType=%d&networkName=%s", |
| 1055 chrome::kInternetOptionsSubPage, | 1047 chrome::kInternetOptionsSubPage, |
| 1056 net::EscapeUrlEncodedData(network->service_path(), true).c_str(), | 1048 net::EscapeUrlEncodedData(network->service_path(), true).c_str(), |
| 1057 network->type(), | 1049 network->type(), |
| 1058 net::EscapeUrlEncodedData(network_name, false).c_str()); | 1050 net::EscapeUrlEncodedData(network_name, false).c_str()); |
| 1059 browser->ShowOptionsTab(page); | 1051 browser->ShowOptionsTab(page); |
| 1060 } | 1052 } |
| 1061 | 1053 |
| 1062 } // namespace chromeos | 1054 } // namespace chromeos |
| OLD | NEW |