Chromium Code Reviews| 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 17 matching lines...) Expand all Loading... | |
| 28 #include "views/controls/button/menu_button.h" | 28 #include "views/controls/button/menu_button.h" |
| 29 #include "views/controls/menu/menu_item_view.h" | 29 #include "views/controls/menu/menu_item_view.h" |
| 30 #include "views/controls/menu/submenu_view.h" | 30 #include "views/controls/menu/submenu_view.h" |
| 31 #include "views/widget/widget.h" | 31 #include "views/widget/widget.h" |
| 32 #include "views/window/window.h" | 32 #include "views/window/window.h" |
| 33 | 33 |
| 34 using views::MenuItemView; | 34 using views::MenuItemView; |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 | 37 |
| 38 // Offset for VPN menu items. | 38 // Offsets for submenus items. |
| 39 const int kVPNCommandIndexOffset = 10000; | 39 const int kVPNCommandIndexOffset = 10000; |
| 40 const int kMoreCommandIndexOffset = 20000; | |
| 40 | 41 |
| 41 } // namespace | 42 } // namespace |
| 42 | 43 |
| 43 namespace chromeos { | 44 namespace chromeos { |
| 44 | 45 |
| 45 class NetworkMenuModel : public views::MenuDelegate { | 46 class NetworkMenuModel : public views::MenuDelegate { |
| 46 public: | 47 public: |
| 47 struct NetworkInfo { | 48 struct NetworkInfo { |
| 48 NetworkInfo() : | 49 NetworkInfo() : |
| 49 need_passphrase(false), remembered(true), auto_connect(true) {} | 50 need_passphrase(false), remembered(true), auto_connect(true) {} |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 62 // true if the network is currently remembered. | 63 // true if the network is currently remembered. |
| 63 bool remembered; | 64 bool remembered; |
| 64 // true if the network is auto connect (meaningful for Wifi only). | 65 // true if the network is auto connect (meaningful for Wifi only). |
| 65 bool auto_connect; | 66 bool auto_connect; |
| 66 }; | 67 }; |
| 67 | 68 |
| 68 explicit NetworkMenuModel(NetworkMenu* owner) : owner_(owner) {} | 69 explicit NetworkMenuModel(NetworkMenu* owner) : owner_(owner) {} |
| 69 virtual ~NetworkMenuModel() {} | 70 virtual ~NetworkMenuModel() {} |
| 70 | 71 |
| 71 // views::MenuDelegate implementation ---------------------------------------- | 72 // views::MenuDelegate implementation ---------------------------------------- |
| 72 | |
| 73 virtual const gfx::Font& GetLabelFont(int id) const OVERRIDE; | 73 virtual const gfx::Font& GetLabelFont(int id) const OVERRIDE; |
| 74 virtual bool IsItemChecked(int id) const OVERRIDE; | 74 virtual bool IsItemChecked(int id) const OVERRIDE; |
| 75 virtual bool IsCommandEnabled(int id) const OVERRIDE; | 75 virtual bool IsCommandEnabled(int id) const OVERRIDE; |
| 76 virtual void ExecuteCommand(int id) OVERRIDE; | 76 virtual void ExecuteCommand(int id) OVERRIDE; |
| 77 | 77 |
| 78 // Connect or reconnect to the network at |index|. | 78 // Connect or reconnect to the network at |index|. |
| 79 // If remember >= 0, set the favorite state of the network. | 79 // If remember >= 0, set the favorite state of the network. |
| 80 // Returns true if a connect occurred (e.g. menu should be closed). | 80 // Returns true if a connect occurred (e.g. menu should be closed). |
| 81 bool ConnectToNetworkAt(int index, | 81 bool ConnectToNetworkAt(int index, |
| 82 const std::string& passphrase, | 82 const std::string& passphrase, |
| 83 const std::string& ssid, | 83 const std::string& ssid, |
| 84 int remember) const; | 84 int remember) const; |
| 85 | 85 |
| 86 // Called by NetworkMenu::RunMenu to initialize list of menu items. | 86 // Called by NetworkMenu::RunMenu to initialize list of menu items. |
| 87 virtual void InitMenuItems(bool is_browser_mode, | 87 virtual void InitMenuItems(bool is_browser_mode, |
| 88 bool should_open_button_options) {} | 88 bool should_open_button_options) {} |
| 89 | 89 |
| 90 // PopulateMenu() clears and reinstalls the menu items defined in this | 90 // PopulateMenu() clears and reinstalls the menu items defined in this |
| 91 // instance by calling PopulateMenuItem() on each one. Subclasses with | 91 // instance by calling PopulateMenuItem() on each one. Subclasses with |
| 92 // submenus should override PopulateMenuItem(), deferring to the base | 92 // submenus should override PopulateMenuItem(), deferring to the base |
| 93 // class implementation for non-submenu items and calling PopulateMenu() | 93 // class implementation for non-submenu items and calling PopulateMenu() |
| 94 // for the submenu after adding it. | 94 // for the submenu after adding it. |
| 95 virtual void PopulateMenu(views::MenuItemView* menu); | 95 virtual void PopulateMenu(views::MenuItemView* menu); |
| 96 virtual void PopulateMenuItem( | 96 virtual void PopulateMenuItem( |
| 97 views::MenuItemView* menu, | 97 views::MenuItemView* menu, int index, int command_id); |
| 98 int index, | |
| 99 int command_id); | |
| 100 | 98 |
| 101 protected: | 99 protected: |
| 102 enum MenuItemFlags { | 100 enum MenuItemFlags { |
| 101 FLAG_NONE = 0, | |
| 103 FLAG_DISABLED = 1 << 0, | 102 FLAG_DISABLED = 1 << 0, |
| 104 FLAG_TOGGLE_ETHERNET = 1 << 1, | 103 FLAG_TOGGLE_ETHERNET = 1 << 1, |
| 105 FLAG_TOGGLE_WIFI = 1 << 2, | 104 FLAG_TOGGLE_WIFI = 1 << 2, |
| 106 FLAG_TOGGLE_CELLULAR = 1 << 3, | 105 FLAG_TOGGLE_CELLULAR = 1 << 3, |
| 107 FLAG_TOGGLE_OFFLINE = 1 << 4, | 106 FLAG_TOGGLE_OFFLINE = 1 << 4, |
| 108 FLAG_ASSOCIATED = 1 << 5, | 107 FLAG_ASSOCIATED = 1 << 5, |
| 109 FLAG_ETHERNET = 1 << 6, | 108 FLAG_ETHERNET = 1 << 6, |
| 110 FLAG_WIFI = 1 << 7, | 109 FLAG_WIFI = 1 << 7, |
| 111 FLAG_CELLULAR = 1 << 8, | 110 FLAG_CELLULAR = 1 << 8, |
| 112 FLAG_PRIVATE_NETWORKS = 1 << 9, | 111 FLAG_OPTIONS = 1 << 9, |
| 113 FLAG_OPTIONS = 1 << 10, | 112 FLAG_ADD_WIFI = 1 << 10, |
| 114 FLAG_ADD_WIFI = 1 << 11, | 113 FLAG_ADD_CELLULAR = 1 << 11, |
| 115 FLAG_ADD_CELLULAR = 1 << 12, | 114 FLAG_VPN = 1 << 12, |
| 116 FLAG_VPN = 1 << 13, | 115 FLAG_ADD_VPN = 1 << 13, |
| 117 FLAG_ADD_VPN = 1 << 14, | 116 FLAG_DISCONNECT_VPN = 1 << 14, |
| 118 FLAG_DISCONNECT_VPN = 1 << 15, | |
| 119 }; | 117 }; |
| 120 | 118 |
| 121 struct MenuItem { | 119 struct MenuItem { |
| 122 MenuItem() | 120 MenuItem() |
| 123 : type(ui::MenuModel::TYPE_SEPARATOR), | 121 : type(ui::MenuModel::TYPE_SEPARATOR), |
| 124 sub_menu_model(NULL), | 122 sub_menu_model(NULL), |
| 125 flags(0) {} | 123 flags(0) {} |
| 126 MenuItem(ui::MenuModel::ItemType type, string16 label, SkBitmap icon, | 124 MenuItem(ui::MenuModel::ItemType type, string16 label, SkBitmap icon, |
| 127 const std::string& service_path, int flags) | 125 const std::string& service_path, int flags) |
| 128 : type(type), | 126 : type(type), |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 // Show a NetworkConfigView modal dialog instance. | 158 // Show a NetworkConfigView modal dialog instance. |
| 161 void ShowNetworkConfigView(NetworkConfigView* view) const; | 159 void ShowNetworkConfigView(NetworkConfigView* view) const; |
| 162 | 160 |
| 163 void ActivateCellular(const CellularNetwork* cellular) const; | 161 void ActivateCellular(const CellularNetwork* cellular) const; |
| 164 void ShowOther(ConnectionType type) const; | 162 void ShowOther(ConnectionType type) const; |
| 165 void ShowOtherCellular() const; | 163 void ShowOtherCellular() const; |
| 166 | 164 |
| 167 DISALLOW_COPY_AND_ASSIGN(NetworkMenuModel); | 165 DISALLOW_COPY_AND_ASSIGN(NetworkMenuModel); |
| 168 }; | 166 }; |
| 169 | 167 |
| 168 class MoreMenuModel : public NetworkMenuModel { | |
| 169 public: | |
| 170 explicit MoreMenuModel(NetworkMenu* owner); | |
| 171 virtual ~MoreMenuModel() {} | |
| 172 | |
| 173 // NetworkMenuModel implementation ------------------------------------------- | |
| 174 virtual void InitMenuItems( | |
| 175 bool is_browser_mode, bool should_open_button_options) OVERRIDE; | |
| 176 virtual void PopulateMenuItem( | |
| 177 views::MenuItemView* menu, int index, int command_id) OVERRIDE; | |
| 178 | |
| 179 private: | |
| 180 friend class MainMenuModel; | |
| 181 DISALLOW_COPY_AND_ASSIGN(MoreMenuModel); | |
| 182 }; | |
| 183 | |
| 184 class VPNMenuModel : public NetworkMenuModel { | |
| 185 public: | |
| 186 explicit VPNMenuModel(NetworkMenu* owner); | |
| 187 virtual ~VPNMenuModel() {} | |
| 188 | |
| 189 // NetworkMenuModel implementation. | |
| 190 virtual void InitMenuItems( | |
| 191 bool is_browser_mode, bool should_open_button_options) OVERRIDE; | |
| 192 virtual void PopulateMenuItem( | |
| 193 views::MenuItemView* menu, int index, int command_id) OVERRIDE; | |
| 194 | |
| 195 static SkBitmap IconForDisplay(const Network* network); | |
| 196 | |
| 197 private: | |
| 198 DISALLOW_COPY_AND_ASSIGN(VPNMenuModel); | |
| 199 }; | |
| 200 | |
| 170 class MainMenuModel : public NetworkMenuModel { | 201 class MainMenuModel : public NetworkMenuModel { |
| 171 public: | 202 public: |
| 172 explicit MainMenuModel(NetworkMenu* owner); | 203 explicit MainMenuModel(NetworkMenu* owner); |
| 173 virtual ~MainMenuModel() {} | 204 virtual ~MainMenuModel() {} |
| 174 | 205 |
| 175 // NetworkMenuModel implementation ------------------------------------------- | 206 // NetworkMenuModel implementation. |
| 176 virtual void InitMenuItems(bool is_browser_mode, | 207 virtual void InitMenuItems(bool is_browser_mode, |
| 177 bool should_open_button_options) OVERRIDE; | 208 bool should_open_button_options); |
| 178 virtual void PopulateMenuItem(views::MenuItemView* menu, | 209 virtual void PopulateMenuItem(views::MenuItemView* menu, |
| 179 int index, | 210 int index, |
| 180 int command_id) OVERRIDE; | 211 int command_id) OVERRIDE; |
| 181 | 212 |
| 182 // MenuDelegate implementaion ------------------------------------------------ | 213 // MenuDelegate implementaion ------------------------------------------------ |
| 183 virtual const gfx::Font& GetLabelFont(int id) const OVERRIDE; | 214 virtual const gfx::Font& GetLabelFont(int id) const OVERRIDE; |
| 184 virtual bool IsItemChecked(int id) const OVERRIDE; | 215 virtual bool IsItemChecked(int id) const OVERRIDE; |
| 185 virtual bool IsCommandEnabled(int id) const OVERRIDE; | 216 virtual bool IsCommandEnabled(int id) const OVERRIDE; |
| 186 virtual void ExecuteCommand(int id) OVERRIDE; | 217 virtual void ExecuteCommand(int id) OVERRIDE; |
| 187 | 218 |
| 188 private: | 219 private: |
| 189 scoped_ptr<NetworkMenuModel> vpn_menu_model_; | 220 scoped_ptr<NetworkMenuModel> vpn_menu_model_; |
| 221 scoped_ptr<MoreMenuModel> more_menu_model_; | |
| 190 | 222 |
| 191 DISALLOW_COPY_AND_ASSIGN(MainMenuModel); | 223 DISALLOW_COPY_AND_ASSIGN(MainMenuModel); |
| 192 }; | 224 }; |
| 193 | 225 |
| 194 class VPNMenuModel : public NetworkMenuModel { | |
| 195 public: | |
| 196 explicit VPNMenuModel(NetworkMenu* owner); | |
| 197 virtual ~VPNMenuModel() {} | |
| 198 | |
| 199 // NetworkMenuModel implementation. | |
| 200 virtual void InitMenuItems(bool is_browser_mode, | |
| 201 bool should_open_button_options); | |
| 202 virtual void PopulateMenuItem( | |
| 203 views::MenuItemView* menu, | |
| 204 int index, | |
| 205 int command_id) OVERRIDE; | |
| 206 | |
| 207 static SkBitmap IconForDisplay(const Network* network); | |
| 208 | |
| 209 private: | |
| 210 DISALLOW_COPY_AND_ASSIGN(VPNMenuModel); | |
| 211 }; | |
| 212 | |
| 213 // NetworkMenuModel, public methods: ------------------------------------------- | 226 // NetworkMenuModel, public methods: ------------------------------------------- |
| 214 | 227 |
| 215 bool NetworkMenuModel::ConnectToNetworkAt(int index, | 228 bool NetworkMenuModel::ConnectToNetworkAt(int index, |
| 216 const std::string& passphrase, | 229 const std::string& passphrase, |
| 217 const std::string& ssid, | 230 const std::string& ssid, |
| 218 int auto_connect) const { | 231 int auto_connect) const { |
| 219 int flags = menu_items_[index].flags; | 232 int flags = menu_items_[index].flags; |
| 220 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | 233 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); |
| 221 const std::string& service_path = menu_items_[index].service_path; | 234 const std::string& service_path = menu_items_[index].service_path; |
| 222 if (flags & FLAG_WIFI) { | 235 if (flags & FLAG_WIFI) { |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 368 ConnectToNetworkAt(id, std::string(), std::string(), -1); | 381 ConnectToNetworkAt(id, std::string(), std::string(), -1); |
| 369 } else if (flags & FLAG_DISCONNECT_VPN) { | 382 } else if (flags & FLAG_DISCONNECT_VPN) { |
| 370 const VirtualNetwork* active_vpn = cros->virtual_network(); | 383 const VirtualNetwork* active_vpn = cros->virtual_network(); |
| 371 if (active_vpn) | 384 if (active_vpn) |
| 372 cros->DisconnectFromNetwork(active_vpn); | 385 cros->DisconnectFromNetwork(active_vpn); |
| 373 } | 386 } |
| 374 } | 387 } |
| 375 | 388 |
| 376 void NetworkMenuModel::PopulateMenu(views::MenuItemView* menu) { | 389 void NetworkMenuModel::PopulateMenu(views::MenuItemView* menu) { |
| 377 menu->CreateSubmenu()->RemoveAllChildViews(true); | 390 menu->CreateSubmenu()->RemoveAllChildViews(true); |
| 378 const int menu_items_count = static_cast<int>(menu_items_.size()); | 391 for (size_t i = 0; i < menu_items_.size(); ++i) |
| 379 for (int i = 0; i < menu_items_count; ++i) | |
| 380 PopulateMenuItem(menu, i, i); | 392 PopulateMenuItem(menu, i, i); |
| 381 | |
| 382 menu->ChildrenChanged(); | 393 menu->ChildrenChanged(); |
| 383 } | 394 } |
| 384 | 395 |
| 385 void NetworkMenuModel::PopulateMenuItem( | 396 void NetworkMenuModel::PopulateMenuItem( |
| 386 views::MenuItemView* menu, | 397 views::MenuItemView* menu, int index, int command_id) { |
| 387 int index, | |
| 388 int command_id) { | |
| 389 DCHECK_GT(static_cast<int>(menu_items_.size()), index); | 398 DCHECK_GT(static_cast<int>(menu_items_.size()), index); |
| 390 const MenuItem& item = menu_items_[index]; | 399 const MenuItem& item = menu_items_[index]; |
| 391 switch (item.type) { | 400 switch (item.type) { |
| 392 case ui::MenuModel::TYPE_SEPARATOR: | 401 case ui::MenuModel::TYPE_SEPARATOR: |
| 393 menu->AppendSeparator(); | 402 menu->AppendSeparator(); |
| 394 break; | 403 break; |
| 395 case ui::MenuModel::TYPE_COMMAND: | 404 case ui::MenuModel::TYPE_COMMAND: |
| 396 if (item.icon.empty()) { | 405 if (item.icon.empty()) { |
| 397 menu->AppendMenuItemWithLabel(command_id, UTF16ToWide(item.label)); | 406 menu->AppendMenuItemWithLabel(command_id, UTF16ToWide(item.label)); |
| 398 } else { | 407 } else { |
| 399 menu->AppendMenuItemWithIcon( | 408 menu->AppendMenuItemWithIcon( |
| 400 command_id, | 409 command_id, UTF16ToWide(item.label), item.icon); |
| 401 UTF16ToWide(item.label), | |
| 402 item.icon); | |
| 403 } | 410 } |
| 404 break; | 411 break; |
| 405 default: | 412 default: |
| 406 // Submenus should be handled by subclasses. | 413 // Submenus should be handled by subclasses. |
| 407 NOTREACHED(); | 414 NOTREACHED(); |
| 408 } | 415 } |
| 409 } | 416 } |
| 410 | 417 |
| 411 // NetworkMenuModel, private methods: ------------------------------------------ | 418 // NetworkMenuModel, private methods: ------------------------------------------ |
| 412 | 419 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 445 ShowNetworkConfigView(new NetworkConfigView(type)); | 452 ShowNetworkConfigView(new NetworkConfigView(type)); |
| 446 } | 453 } |
| 447 | 454 |
| 448 void NetworkMenuModel::ShowOtherCellular() const { | 455 void NetworkMenuModel::ShowOtherCellular() const { |
| 449 ChooseMobileNetworkDialog::ShowDialog(owner_->GetNativeWindow()); | 456 ChooseMobileNetworkDialog::ShowDialog(owner_->GetNativeWindow()); |
| 450 } | 457 } |
| 451 | 458 |
| 452 // MainMenuModel --------------------------------------------------------------- | 459 // MainMenuModel --------------------------------------------------------------- |
| 453 | 460 |
| 454 MainMenuModel::MainMenuModel(NetworkMenu* owner) | 461 MainMenuModel::MainMenuModel(NetworkMenu* owner) |
| 455 : NetworkMenuModel(owner) { | 462 : NetworkMenuModel(owner), |
| 456 vpn_menu_model_.reset(new VPNMenuModel(owner)); | 463 vpn_menu_model_(new VPNMenuModel(owner)), |
| 464 more_menu_model_(new MoreMenuModel(owner)) { | |
| 457 } | 465 } |
| 458 | 466 |
| 459 // MainMenuModel, NetworkMenuModel implementation: ----------------------------- | 467 // MainMenuModel, NetworkMenuModel implementation: ----------------------------- |
| 460 | 468 |
| 461 void MainMenuModel::InitMenuItems(bool is_browser_mode, | 469 void MainMenuModel::InitMenuItems(bool is_browser_mode, |
| 462 bool should_open_button_options) { | 470 bool should_open_button_options) { |
| 463 // This gets called on initialization, so any changes should be reflected | 471 // This gets called on initialization, so any changes should be reflected |
| 464 // in CrosMock::SetNetworkLibraryStatusAreaExpectations(). | 472 // in CrosMock::SetNetworkLibraryStatusAreaExpectations(). |
| 465 | 473 |
| 466 menu_items_.clear(); | 474 menu_items_.clear(); |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 666 | 674 |
| 667 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableVPN)) { | 675 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableVPN)) { |
| 668 // If there's a connected network, add submenu for Private Networks. | 676 // If there's a connected network, add submenu for Private Networks. |
| 669 const Network* connected_network = cros->connected_network(); | 677 const Network* connected_network = cros->connected_network(); |
| 670 if (connected_network) { | 678 if (connected_network) { |
| 671 menu_items_.push_back(MenuItem()); // Separator | 679 menu_items_.push_back(MenuItem()); // Separator |
| 672 menu_items_.push_back(MenuItem( | 680 menu_items_.push_back(MenuItem( |
| 673 ui::MenuModel::TYPE_SUBMENU, | 681 ui::MenuModel::TYPE_SUBMENU, |
| 674 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_PRIVATE_NETWORKS), | 682 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_PRIVATE_NETWORKS), |
| 675 VPNMenuModel::IconForDisplay(connected_network), | 683 VPNMenuModel::IconForDisplay(connected_network), |
| 676 vpn_menu_model_.get(), FLAG_PRIVATE_NETWORKS)); | 684 vpn_menu_model_.get(), FLAG_NONE)); |
| 677 } | 685 } |
| 678 } | 686 } |
| 679 | 687 |
| 680 // Enable / disable wireless. | 688 // Enable / disable wireless. |
| 681 if (wifi_available || cellular_available) { | 689 if (wifi_available || cellular_available) { |
| 682 menu_items_.push_back(MenuItem()); // Separator | 690 menu_items_.push_back(MenuItem()); // Separator |
| 683 | 691 |
| 684 if (wifi_available) { | 692 if (wifi_available) { |
| 685 // Add 'Scanning...' | 693 // Add 'Scanning...' |
| 686 if (cros->wifi_scanning()) { | 694 if (cros->wifi_scanning()) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 719 } | 727 } |
| 720 } | 728 } |
| 721 | 729 |
| 722 // Offline mode. | 730 // Offline mode. |
| 723 // TODO(chocobo): Uncomment once we figure out how to do offline mode. | 731 // TODO(chocobo): Uncomment once we figure out how to do offline mode. |
| 724 // menu_items_.push_back(MenuItem(cros->offline_mode() ? | 732 // menu_items_.push_back(MenuItem(cros->offline_mode() ? |
| 725 // ui::MenuModel::TYPE_CHECK : ui::MenuModel::TYPE_COMMAND, | 733 // ui::MenuModel::TYPE_CHECK : ui::MenuModel::TYPE_COMMAND, |
| 726 // l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_OFFLINE_MODE), | 734 // l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_OFFLINE_MODE), |
| 727 // SkBitmap(), std::string(), FLAG_TOGGLE_OFFLINE)); | 735 // SkBitmap(), std::string(), FLAG_TOGGLE_OFFLINE)); |
| 728 | 736 |
| 729 bool connected = cros->Connected(); // always call for test expectations. | 737 // Additional links like: |
| 730 bool oobe = !should_open_button_options; // we don't show options for OOBE. | 738 // * Network settings; |
| 731 // Network settings. (And IP Address) | 739 // * IP Address on active interface; |
| 732 if (!oobe) { | 740 // * Hardware addresses for wifi and ethernet. |
| 733 menu_items_.push_back(MenuItem()); // Separator | 741 menu_items_.push_back(MenuItem()); // Separator |
| 734 | 742 more_menu_model_->InitMenuItems( |
| 735 if (connected) { | 743 is_browser_mode, should_open_button_options); |
| 736 std::string ip_address = cros->IPAddress(); | 744 if (is_browser_mode) { |
| 737 if (!ip_address.empty()) { | 745 menu_items_.insert( |
| 738 menu_items_.push_back(MenuItem(ui::MenuModel::TYPE_COMMAND, | 746 menu_items_.end(), |
| 739 ASCIIToUTF16(cros->IPAddress()), SkBitmap(), std::string(), | 747 more_menu_model_->menu_items_.begin(), |
| 740 FLAG_DISABLED)); | 748 more_menu_model_->menu_items_.end()); |
| 741 } | 749 } else { |
| 750 if (!more_menu_model_->menu_items_.empty()) { | |
| 751 menu_items_.push_back(MenuItem( | |
| 752 ui::MenuModel::TYPE_SUBMENU, | |
| 753 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_MORE), | |
| 754 SkBitmap(), more_menu_model_.get(), FLAG_NONE)); | |
| 742 } | 755 } |
| 743 | |
| 744 label = l10n_util::GetStringUTF16(is_browser_mode ? | |
| 745 IDS_STATUSBAR_NETWORK_OPEN_OPTIONS_DIALOG : | |
| 746 IDS_STATUSBAR_NETWORK_OPEN_PROXY_SETTINGS_DIALOG); | |
| 747 menu_items_.push_back(MenuItem(ui::MenuModel::TYPE_COMMAND, label, | |
| 748 SkBitmap(), std::string(), FLAG_OPTIONS)); | |
| 749 } | 756 } |
| 750 | 757 |
| 751 // Recursively call each submenu to populate its own menu items. | 758 // Recursively call each submenu to populate its own menu items. |
| 752 for (size_t i = 0; i < menu_items_.size(); ++i) { | 759 for (size_t i = 0; i < menu_items_.size(); ++i) { |
| 753 if (menu_items_[i].type == ui::MenuModel::TYPE_SUBMENU && | 760 if (menu_items_[i].type == ui::MenuModel::TYPE_SUBMENU) { |
| 754 menu_items_[i].sub_menu_model) { | 761 NetworkMenuModel* model = menu_items_[i].sub_menu_model; |
| 762 if (model == NULL) | |
| 763 continue; | |
| 764 if (model == more_menu_model_.get()) { | |
| 765 // This submenu is already initialized. | |
| 766 continue; | |
| 767 } | |
| 755 menu_items_[i].sub_menu_model->InitMenuItems(is_browser_mode, | 768 menu_items_[i].sub_menu_model->InitMenuItems(is_browser_mode, |
| 756 should_open_button_options); | 769 should_open_button_options); |
| 757 } | 770 } |
| 758 } | 771 } |
| 759 } | 772 } |
| 760 | 773 |
| 761 // MainMenuModel, views::MenuDelegate implementation --------------------------- | 774 // MainMenuModel, views::MenuDelegate implementation --------------------------- |
| 762 | 775 |
| 763 const gfx::Font& MainMenuModel::GetLabelFont(int id) const { | 776 const gfx::Font& MainMenuModel::GetLabelFont(int id) const { |
| 764 if (id >= kVPNCommandIndexOffset) | 777 DCHECK(kMoreCommandIndexOffset > kVPNCommandIndexOffset); |
| 778 if (id >= kMoreCommandIndexOffset) | |
| 779 return more_menu_model_->GetLabelFont(id - kMoreCommandIndexOffset); | |
| 780 else if (id >= kVPNCommandIndexOffset) | |
| 765 return vpn_menu_model_->GetLabelFont(id - kVPNCommandIndexOffset); | 781 return vpn_menu_model_->GetLabelFont(id - kVPNCommandIndexOffset); |
| 766 else | 782 else |
| 767 return NetworkMenuModel::GetLabelFont(id); | 783 return NetworkMenuModel::GetLabelFont(id); |
| 768 } | 784 } |
| 769 | 785 |
| 770 bool MainMenuModel::IsItemChecked(int id) const { | 786 bool MainMenuModel::IsItemChecked(int id) const { |
| 771 if (id >= kVPNCommandIndexOffset) | 787 DCHECK(kMoreCommandIndexOffset > kVPNCommandIndexOffset); |
| 788 if (id >= kMoreCommandIndexOffset) | |
| 789 return more_menu_model_->IsItemChecked(id - kMoreCommandIndexOffset); | |
| 790 else if (id >= kVPNCommandIndexOffset) | |
| 772 return vpn_menu_model_->IsItemChecked(id - kVPNCommandIndexOffset); | 791 return vpn_menu_model_->IsItemChecked(id - kVPNCommandIndexOffset); |
| 773 else | 792 else |
| 774 return NetworkMenuModel::IsItemChecked(id); | 793 return NetworkMenuModel::IsItemChecked(id); |
| 775 } | 794 } |
| 776 | 795 |
| 777 bool MainMenuModel::IsCommandEnabled(int id) const { | 796 bool MainMenuModel::IsCommandEnabled(int id) const { |
| 778 if (id >= kVPNCommandIndexOffset) | 797 DCHECK(kMoreCommandIndexOffset > kVPNCommandIndexOffset); |
| 798 if (id >= kMoreCommandIndexOffset) | |
| 799 return more_menu_model_->IsCommandEnabled(id - kMoreCommandIndexOffset); | |
| 800 else if (id >= kVPNCommandIndexOffset) | |
| 779 return vpn_menu_model_->IsCommandEnabled(id - kVPNCommandIndexOffset); | 801 return vpn_menu_model_->IsCommandEnabled(id - kVPNCommandIndexOffset); |
| 780 else | 802 else |
| 781 return NetworkMenuModel::IsCommandEnabled(id); | 803 return NetworkMenuModel::IsCommandEnabled(id); |
| 782 } | 804 } |
| 783 | 805 |
| 784 void MainMenuModel::ExecuteCommand(int id) { | 806 void MainMenuModel::ExecuteCommand(int id) { |
| 785 if (id >= kVPNCommandIndexOffset) | 807 DCHECK(kMoreCommandIndexOffset > kVPNCommandIndexOffset); |
| 808 if (id >= kMoreCommandIndexOffset) | |
| 809 more_menu_model_->ExecuteCommand(id - kMoreCommandIndexOffset); | |
| 810 else if (id >= kVPNCommandIndexOffset) | |
| 786 vpn_menu_model_->ExecuteCommand(id - kVPNCommandIndexOffset); | 811 vpn_menu_model_->ExecuteCommand(id - kVPNCommandIndexOffset); |
| 787 else | 812 else |
| 788 NetworkMenuModel::ExecuteCommand(id); | 813 NetworkMenuModel::ExecuteCommand(id); |
| 789 } | 814 } |
| 790 | 815 |
| 791 // MainMenuModel, NetworkMenuModel implementation: ----------------------------- | 816 // MainMenuModel, NetworkMenuModel implementation: ----------------------------- |
| 792 | 817 |
| 793 void MainMenuModel::PopulateMenuItem( | 818 void MainMenuModel::PopulateMenuItem( |
| 794 views::MenuItemView* menu, | 819 views::MenuItemView* menu, int index, int command_id) { |
| 795 int index, | |
| 796 int command_id) { | |
| 797 DCHECK_GT(static_cast<int>(menu_items_.size()), index); | 820 DCHECK_GT(static_cast<int>(menu_items_.size()), index); |
| 798 const MenuItem& item = menu_items_[index]; | 821 const MenuItem& item = menu_items_[index]; |
| 799 if (item.type == ui::MenuModel::TYPE_SUBMENU) { | 822 if (item.type == ui::MenuModel::TYPE_SUBMENU) { |
| 800 views::MenuItemView* vpn_menu = NULL; | 823 views::MenuItemView* sub_menu = NULL; |
| 801 if (item.icon.empty()) { | 824 if (item.icon.empty()) { |
| 802 vpn_menu = menu->AppendSubMenu(command_id, UTF16ToWide(item.label)); | 825 sub_menu = menu->AppendSubMenu(command_id, UTF16ToWide(item.label)); |
| 803 } else { | 826 } else { |
| 804 vpn_menu = menu->AppendSubMenuWithIcon( | 827 sub_menu = menu->AppendSubMenuWithIcon( |
| 805 command_id, | 828 command_id, UTF16ToWide(item.label), item.icon); |
| 806 UTF16ToWide(item.label), | |
| 807 item.icon); | |
| 808 } | 829 } |
| 809 vpn_menu_model_->PopulateMenu(vpn_menu); | 830 item.sub_menu_model->PopulateMenu(sub_menu); |
| 810 } else { | 831 } else { |
| 811 NetworkMenuModel::PopulateMenuItem(menu, index, command_id); | 832 NetworkMenuModel::PopulateMenuItem(menu, index, command_id); |
| 812 } | 833 } |
| 813 } | 834 } |
| 814 | 835 |
| 815 // VPNMenuModel ---------------------------------------------------------------- | 836 // VPNMenuModel ---------------------------------------------------------------- |
| 816 | 837 |
| 817 VPNMenuModel::VPNMenuModel(NetworkMenu* owner) | 838 VPNMenuModel::VPNMenuModel(NetworkMenu* owner) |
| 818 : NetworkMenuModel(owner) { | 839 : NetworkMenuModel(owner) { |
| 819 } | 840 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 879 SkBitmap(), std::string(), FLAG_ADD_VPN)); | 900 SkBitmap(), std::string(), FLAG_ADD_VPN)); |
| 880 if (active_vpn) { | 901 if (active_vpn) { |
| 881 menu_items_.push_back(MenuItem( | 902 menu_items_.push_back(MenuItem( |
| 882 ui::MenuModel::TYPE_COMMAND, | 903 ui::MenuModel::TYPE_COMMAND, |
| 883 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DISCONNECT_VPN), | 904 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DISCONNECT_VPN), |
| 884 SkBitmap(), std::string(), FLAG_DISCONNECT_VPN)); | 905 SkBitmap(), std::string(), FLAG_DISCONNECT_VPN)); |
| 885 } | 906 } |
| 886 } | 907 } |
| 887 | 908 |
| 888 void VPNMenuModel::PopulateMenuItem( | 909 void VPNMenuModel::PopulateMenuItem( |
| 889 views::MenuItemView* menu, | 910 views::MenuItemView* menu, int index, int command_id) { |
| 890 int index, | |
| 891 int command_id) { | |
| 892 NetworkMenuModel::PopulateMenuItem( | 911 NetworkMenuModel::PopulateMenuItem( |
| 893 menu, | 912 menu, index, command_id + kVPNCommandIndexOffset); |
| 894 index, | |
| 895 command_id + kVPNCommandIndexOffset); | |
| 896 } | 913 } |
| 897 | 914 |
| 898 // static | 915 // static |
| 899 SkBitmap VPNMenuModel::IconForDisplay(const Network* network) { | 916 SkBitmap VPNMenuModel::IconForDisplay(const Network* network) { |
| 900 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 917 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 901 const SkBitmap* icon = NULL; | 918 const SkBitmap* icon = NULL; |
| 902 const SkBitmap* bottom_right_badge = NULL; | 919 const SkBitmap* bottom_right_badge = NULL; |
| 903 const SkBitmap* top_left_badge = NULL; | 920 const SkBitmap* top_left_badge = NULL; |
| 904 // We know for sure |network| is the active network, so no more checking | 921 // We know for sure |network| is the active network, so no more checking |
| 905 // is needed by BadgeForPrivateNetworkStatus, hence pass in NULL. | 922 // is needed by BadgeForPrivateNetworkStatus, hence pass in NULL. |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 925 default: | 942 default: |
| 926 LOG(WARNING) << "VPN not handled for connection type " << network->type(); | 943 LOG(WARNING) << "VPN not handled for connection type " << network->type(); |
| 927 return SkBitmap(); | 944 return SkBitmap(); |
| 928 } | 945 } |
| 929 | 946 |
| 930 return NetworkMenu::IconForDisplay(icon, bottom_right_badge, top_left_badge, | 947 return NetworkMenu::IconForDisplay(icon, bottom_right_badge, top_left_badge, |
| 931 bottom_left_badge); | 948 bottom_left_badge); |
| 932 } | 949 } |
| 933 | 950 |
| 934 //////////////////////////////////////////////////////////////////////////////// | 951 //////////////////////////////////////////////////////////////////////////////// |
| 952 // MoreMenuModel | |
| 953 | |
| 954 MoreMenuModel::MoreMenuModel(NetworkMenu* owner) | |
| 955 : NetworkMenuModel(owner) { | |
| 956 } | |
| 957 | |
| 958 void MoreMenuModel::InitMenuItems( | |
| 959 bool is_browser_mode, bool should_open_button_options) { | |
| 960 // This gets called on initialization, so any changes should be reflected | |
| 961 // in CrosMock::SetNetworkLibraryStatusAreaExpectations(). | |
| 962 | |
| 963 menu_items_.clear(); | |
| 964 MenuItemVector link_items_; | |
|
stevenjb
2011/04/25 17:54:27
'link_items' for local variable name
Denis Lagno
2011/04/26 15:54:58
Done.
| |
| 965 MenuItemVector address_items_; | |
|
stevenjb
2011/04/25 17:54:27
'address_items' for local variable name
Denis Lagno
2011/04/26 15:54:58
Done.
| |
| 966 | |
| 967 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | |
| 968 bool oobe = !should_open_button_options; // we don't show options for OOBE. | |
| 969 if (!oobe) { | |
| 970 string16 label = l10n_util::GetStringUTF16(is_browser_mode ? | |
| 971 IDS_STATUSBAR_NETWORK_OPEN_OPTIONS_DIALOG : | |
| 972 IDS_STATUSBAR_NETWORK_OPEN_PROXY_SETTINGS_DIALOG); | |
| 973 link_items_.push_back(MenuItem(ui::MenuModel::TYPE_COMMAND, label, | |
| 974 SkBitmap(), std::string(), FLAG_OPTIONS)); | |
| 975 } | |
| 976 | |
| 977 bool connected = cros->Connected(); // always call for test expectations. | |
| 978 if (connected) { | |
| 979 std::string ip_address = cros->IPAddress(); | |
| 980 if (!ip_address.empty()) { | |
| 981 address_items_.push_back(MenuItem(ui::MenuModel::TYPE_COMMAND, | |
| 982 ASCIIToUTF16(cros->IPAddress()), SkBitmap(), std::string(), | |
| 983 FLAG_DISABLED)); | |
| 984 } | |
| 985 } | |
| 986 | |
| 987 if (!is_browser_mode) { | |
| 988 if (cros->wifi_enabled()) { | |
| 989 NetworkDeviceVector wifi = cros->FindWifiDevices(); | |
| 990 for (size_t i = 0; i < wifi.size(); ++i) { | |
| 991 std::string hardware_address; | |
| 992 cros->GetIPConfigs(wifi[i]->device_path(), | |
| 993 &hardware_address, NetworkLibrary::FORMAT_COLON_SEPARATED_HEX); | |
| 994 if (!hardware_address.empty()) { | |
| 995 std::string label = l10n_util::GetStringUTF8( | |
| 996 IDS_STATUSBAR_NETWORK_DEVICE_WIFI) + " " + hardware_address; | |
| 997 address_items_.push_back(MenuItem(ui::MenuModel::TYPE_COMMAND, | |
| 998 UTF8ToUTF16(label), SkBitmap(), std::string(), FLAG_DISABLED)); | |
| 999 } | |
| 1000 } | |
| 1001 } | |
| 1002 | |
| 1003 NetworkDeviceVector ether = cros->FindEthernetDevices(); | |
| 1004 for (size_t i = 0; i < ether.size(); ++i) { | |
| 1005 std::string hardware_address; | |
| 1006 cros->GetIPConfigs(ether[i]->device_path(), &hardware_address, | |
| 1007 NetworkLibrary::FORMAT_COLON_SEPARATED_HEX); | |
| 1008 if (!hardware_address.empty()) { | |
| 1009 std::string label = l10n_util::GetStringUTF8( | |
| 1010 IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET) + " " + hardware_address; | |
| 1011 address_items_.push_back(MenuItem(ui::MenuModel::TYPE_COMMAND, | |
| 1012 UTF8ToUTF16(label), SkBitmap(), std::string(), FLAG_DISABLED)); | |
| 1013 } | |
| 1014 } | |
|
stevenjb
2011/04/25 17:54:27
Since we list ethernet networks first, shouldn't w
Denis Lagno
2011/04/26 15:54:58
Done.
| |
| 1015 } | |
| 1016 | |
| 1017 menu_items_.swap(link_items_); | |
|
stevenjb
2011/04/25 17:54:27
manu_items_ = link_items; (no need for swap)
Denis Lagno
2011/04/26 15:54:58
Done.
| |
| 1018 if (!menu_items_.empty() && address_items_.size() > 1) | |
| 1019 menu_items_.push_back(MenuItem()); // Separator | |
| 1020 menu_items_.insert(menu_items_.end(), | |
| 1021 address_items_.begin(), address_items_.end()); | |
| 1022 } | |
| 1023 | |
| 1024 void MoreMenuModel::PopulateMenuItem( | |
| 1025 views::MenuItemView* menu, int index, int command_id) { | |
| 1026 NetworkMenuModel::PopulateMenuItem( | |
| 1027 menu, index, command_id + kMoreCommandIndexOffset); | |
| 1028 } | |
| 1029 | |
| 1030 //////////////////////////////////////////////////////////////////////////////// | |
| 935 // NetworkMenu | 1031 // NetworkMenu |
| 936 | 1032 |
| 937 // static | 1033 // static |
| 938 const int NetworkMenu::kNumBarsImages = 4; | 1034 const int NetworkMenu::kNumBarsImages = 4; |
| 939 | 1035 |
| 940 // NOTE: Use an array rather than just calculating a resource number to avoid | 1036 // NOTE: Use an array rather than just calculating a resource number to avoid |
| 941 // creating implicit ordering dependencies on the resource values. | 1037 // creating implicit ordering dependencies on the resource values. |
| 942 // static | 1038 // static |
| 943 const int NetworkMenu::kBarsImages[kNumBarsImages] = { | 1039 const int NetworkMenu::kBarsImages[kNumBarsImages] = { |
| 944 IDR_STATUSBAR_NETWORK_BARS1, | 1040 IDR_STATUSBAR_NETWORK_BARS1, |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 972 | 1068 |
| 973 // static | 1069 // static |
| 974 const int NetworkMenu::kNumAnimatingImages = 10; | 1070 const int NetworkMenu::kNumAnimatingImages = 10; |
| 975 | 1071 |
| 976 // static | 1072 // static |
| 977 SkBitmap NetworkMenu::kAnimatingImages[kNumAnimatingImages]; | 1073 SkBitmap NetworkMenu::kAnimatingImages[kNumAnimatingImages]; |
| 978 | 1074 |
| 979 // static | 1075 // static |
| 980 SkBitmap NetworkMenu::kAnimatingImagesBlack[kNumAnimatingImages]; | 1076 SkBitmap NetworkMenu::kAnimatingImagesBlack[kNumAnimatingImages]; |
| 981 | 1077 |
| 982 NetworkMenu::NetworkMenu() | 1078 NetworkMenu::NetworkMenu() : min_width_(-1) { |
| 983 : min_width_(-1) { | |
| 984 main_menu_model_.reset(new MainMenuModel(this)); | 1079 main_menu_model_.reset(new MainMenuModel(this)); |
| 985 network_menu_.reset(new views::MenuItemView(main_menu_model_.get())); | 1080 network_menu_.reset(new views::MenuItemView(main_menu_model_.get())); |
| 986 network_menu_->set_has_icons(true); | 1081 network_menu_->set_has_icons(true); |
| 987 } | 1082 } |
| 988 | 1083 |
| 989 NetworkMenu::~NetworkMenu() { | 1084 NetworkMenu::~NetworkMenu() { |
| 990 } | 1085 } |
| 991 | 1086 |
| 992 void NetworkMenu::SetFirstLevelMenuWidth(int width) { | 1087 void NetworkMenu::SetFirstLevelMenuWidth(int width) { |
| 993 min_width_ = width; | 1088 min_width_ = width; |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1222 gfx::Rect bounds(screen_loc, source->size()); | 1317 gfx::Rect bounds(screen_loc, source->size()); |
| 1223 network_menu_->RunMenuAt( | 1318 network_menu_->RunMenuAt( |
| 1224 window, | 1319 window, |
| 1225 GetMenuButton(), | 1320 GetMenuButton(), |
| 1226 bounds, | 1321 bounds, |
| 1227 base::i18n::IsRTL() ? MenuItemView::TOPLEFT : MenuItemView::TOPRIGHT, | 1322 base::i18n::IsRTL() ? MenuItemView::TOPLEFT : MenuItemView::TOPRIGHT, |
| 1228 true); | 1323 true); |
| 1229 } | 1324 } |
| 1230 | 1325 |
| 1231 } // namespace chromeos | 1326 } // namespace chromeos |
| 1327 | |
| 1328 | |
| OLD | NEW |