Chromium Code Reviews| Index: chrome/browser/chromeos/status/network_menu.cc |
| diff --git a/chrome/browser/chromeos/status/network_menu.cc b/chrome/browser/chromeos/status/network_menu.cc |
| index 6fdc441ee887229be8671b3c23e4b65024f29bd4..02bff3997d6740bb806bb8d99ba3141d689b7d40 100644 |
| --- a/chrome/browser/chromeos/status/network_menu.cc |
| +++ b/chrome/browser/chromeos/status/network_menu.cc |
| @@ -35,8 +35,9 @@ using views::MenuItemView; |
| namespace { |
| -// Offset for VPN menu items. |
| +// Offsets for submenus items. |
| const int kVPNCommandIndexOffset = 10000; |
| +const int kMoreCommandIndexOffset = 20000; |
| } // namespace |
| @@ -69,7 +70,6 @@ class NetworkMenuModel : public views::MenuDelegate { |
| virtual ~NetworkMenuModel() {} |
| // views::MenuDelegate implementation ---------------------------------------- |
| - |
| virtual const gfx::Font& GetLabelFont(int id) const OVERRIDE; |
| virtual bool IsItemChecked(int id) const OVERRIDE; |
| virtual bool IsCommandEnabled(int id) const OVERRIDE; |
| @@ -94,12 +94,11 @@ class NetworkMenuModel : public views::MenuDelegate { |
| // for the submenu after adding it. |
| virtual void PopulateMenu(views::MenuItemView* menu); |
| virtual void PopulateMenuItem( |
| - views::MenuItemView* menu, |
| - int index, |
| - int command_id); |
| + views::MenuItemView* menu, int index, int command_id); |
| protected: |
| enum MenuItemFlags { |
| + FLAG_NONE = 0, |
| FLAG_DISABLED = 1 << 0, |
| FLAG_TOGGLE_ETHERNET = 1 << 1, |
| FLAG_TOGGLE_WIFI = 1 << 2, |
| @@ -109,13 +108,12 @@ class NetworkMenuModel : public views::MenuDelegate { |
| FLAG_ETHERNET = 1 << 6, |
| FLAG_WIFI = 1 << 7, |
| FLAG_CELLULAR = 1 << 8, |
| - FLAG_PRIVATE_NETWORKS = 1 << 9, |
| - FLAG_OPTIONS = 1 << 10, |
| - FLAG_ADD_WIFI = 1 << 11, |
| - FLAG_ADD_CELLULAR = 1 << 12, |
| - FLAG_VPN = 1 << 13, |
| - FLAG_ADD_VPN = 1 << 14, |
| - FLAG_DISCONNECT_VPN = 1 << 15, |
| + FLAG_OPTIONS = 1 << 9, |
| + FLAG_ADD_WIFI = 1 << 10, |
| + FLAG_ADD_CELLULAR = 1 << 11, |
| + FLAG_VPN = 1 << 12, |
| + FLAG_ADD_VPN = 1 << 13, |
| + FLAG_DISCONNECT_VPN = 1 << 14, |
| }; |
| struct MenuItem { |
| @@ -167,14 +165,47 @@ class NetworkMenuModel : public views::MenuDelegate { |
| DISALLOW_COPY_AND_ASSIGN(NetworkMenuModel); |
| }; |
| +class MoreMenuModel : public NetworkMenuModel { |
| + public: |
| + explicit MoreMenuModel(NetworkMenu* owner); |
| + virtual ~MoreMenuModel() {} |
| + |
| + // NetworkMenuModel implementation ------------------------------------------- |
| + virtual void InitMenuItems( |
| + bool is_browser_mode, bool should_open_button_options) OVERRIDE; |
| + virtual void PopulateMenuItem( |
| + views::MenuItemView* menu, int index, int command_id) OVERRIDE; |
| + |
| + private: |
| + friend class MainMenuModel; |
| + DISALLOW_COPY_AND_ASSIGN(MoreMenuModel); |
| +}; |
| + |
| +class VPNMenuModel : public NetworkMenuModel { |
| + public: |
| + explicit VPNMenuModel(NetworkMenu* owner); |
| + virtual ~VPNMenuModel() {} |
| + |
| + // NetworkMenuModel implementation. |
| + virtual void InitMenuItems( |
| + bool is_browser_mode, bool should_open_button_options) OVERRIDE; |
| + virtual void PopulateMenuItem( |
| + views::MenuItemView* menu, int index, int command_id) OVERRIDE; |
| + |
| + static SkBitmap IconForDisplay(const Network* network); |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(VPNMenuModel); |
| +}; |
| + |
| class MainMenuModel : public NetworkMenuModel { |
| public: |
| explicit MainMenuModel(NetworkMenu* owner); |
| virtual ~MainMenuModel() {} |
| - // NetworkMenuModel implementation ------------------------------------------- |
| + // NetworkMenuModel implementation. |
| virtual void InitMenuItems(bool is_browser_mode, |
| - bool should_open_button_options) OVERRIDE; |
| + bool should_open_button_options); |
| virtual void PopulateMenuItem(views::MenuItemView* menu, |
| int index, |
| int command_id) OVERRIDE; |
| @@ -187,29 +218,11 @@ class MainMenuModel : public NetworkMenuModel { |
| private: |
| scoped_ptr<NetworkMenuModel> vpn_menu_model_; |
| + scoped_ptr<MoreMenuModel> more_menu_model_; |
| DISALLOW_COPY_AND_ASSIGN(MainMenuModel); |
| }; |
| -class VPNMenuModel : public NetworkMenuModel { |
| - public: |
| - explicit VPNMenuModel(NetworkMenu* owner); |
| - virtual ~VPNMenuModel() {} |
| - |
| - // NetworkMenuModel implementation. |
| - virtual void InitMenuItems(bool is_browser_mode, |
| - bool should_open_button_options); |
| - virtual void PopulateMenuItem( |
| - views::MenuItemView* menu, |
| - int index, |
| - int command_id) OVERRIDE; |
| - |
| - static SkBitmap IconForDisplay(const Network* network); |
| - |
| - private: |
| - DISALLOW_COPY_AND_ASSIGN(VPNMenuModel); |
| -}; |
| - |
| // NetworkMenuModel, public methods: ------------------------------------------- |
| bool NetworkMenuModel::ConnectToNetworkAt(int index, |
| @@ -375,17 +388,13 @@ void NetworkMenuModel::ExecuteCommand(int id) { |
| void NetworkMenuModel::PopulateMenu(views::MenuItemView* menu) { |
| menu->CreateSubmenu()->RemoveAllChildViews(true); |
| - const int menu_items_count = static_cast<int>(menu_items_.size()); |
| - for (int i = 0; i < menu_items_count; ++i) |
| + for (size_t i = 0; i < menu_items_.size(); ++i) |
| PopulateMenuItem(menu, i, i); |
| - |
| menu->ChildrenChanged(); |
| } |
| void NetworkMenuModel::PopulateMenuItem( |
| - views::MenuItemView* menu, |
| - int index, |
| - int command_id) { |
| + views::MenuItemView* menu, int index, int command_id) { |
| DCHECK_GT(static_cast<int>(menu_items_.size()), index); |
| const MenuItem& item = menu_items_[index]; |
| switch (item.type) { |
| @@ -397,9 +406,7 @@ void NetworkMenuModel::PopulateMenuItem( |
| menu->AppendMenuItemWithLabel(command_id, UTF16ToWide(item.label)); |
| } else { |
| menu->AppendMenuItemWithIcon( |
| - command_id, |
| - UTF16ToWide(item.label), |
| - item.icon); |
| + command_id, UTF16ToWide(item.label), item.icon); |
| } |
| break; |
| default: |
| @@ -452,8 +459,9 @@ void NetworkMenuModel::ShowOtherCellular() const { |
| // MainMenuModel --------------------------------------------------------------- |
| MainMenuModel::MainMenuModel(NetworkMenu* owner) |
| - : NetworkMenuModel(owner) { |
| - vpn_menu_model_.reset(new VPNMenuModel(owner)); |
| + : NetworkMenuModel(owner), |
| + vpn_menu_model_(new VPNMenuModel(owner)), |
| + more_menu_model_(new MoreMenuModel(owner)) { |
| } |
| // MainMenuModel, NetworkMenuModel implementation: ----------------------------- |
| @@ -673,7 +681,7 @@ void MainMenuModel::InitMenuItems(bool is_browser_mode, |
| ui::MenuModel::TYPE_SUBMENU, |
| l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_PRIVATE_NETWORKS), |
| VPNMenuModel::IconForDisplay(connected_network), |
| - vpn_menu_model_.get(), FLAG_PRIVATE_NETWORKS)); |
| + vpn_menu_model_.get(), FLAG_NONE)); |
| } |
| } |
| @@ -726,32 +734,37 @@ void MainMenuModel::InitMenuItems(bool is_browser_mode, |
| // l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_OFFLINE_MODE), |
| // SkBitmap(), std::string(), FLAG_TOGGLE_OFFLINE)); |
| - bool connected = cros->Connected(); // always call for test expectations. |
| - bool oobe = !should_open_button_options; // we don't show options for OOBE. |
| - // Network settings. (And IP Address) |
| - if (!oobe) { |
| - menu_items_.push_back(MenuItem()); // Separator |
| - |
| - if (connected) { |
| - std::string ip_address = cros->IPAddress(); |
| - if (!ip_address.empty()) { |
| - menu_items_.push_back(MenuItem(ui::MenuModel::TYPE_COMMAND, |
| - ASCIIToUTF16(cros->IPAddress()), SkBitmap(), std::string(), |
| - FLAG_DISABLED)); |
| - } |
| + // Additional links like: |
| + // * Network settings; |
| + // * IP Address on active interface; |
| + // * Hardware addresses for wifi and ethernet. |
| + menu_items_.push_back(MenuItem()); // Separator |
| + more_menu_model_->InitMenuItems( |
| + is_browser_mode, should_open_button_options); |
| + if (is_browser_mode) { |
| + menu_items_.insert( |
| + menu_items_.end(), |
| + more_menu_model_->menu_items_.begin(), |
| + more_menu_model_->menu_items_.end()); |
| + } else { |
| + if (!more_menu_model_->menu_items_.empty()) { |
| + menu_items_.push_back(MenuItem( |
| + ui::MenuModel::TYPE_SUBMENU, |
| + l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_MORE), |
| + SkBitmap(), more_menu_model_.get(), FLAG_NONE)); |
| } |
| - |
| - label = l10n_util::GetStringUTF16(is_browser_mode ? |
| - IDS_STATUSBAR_NETWORK_OPEN_OPTIONS_DIALOG : |
| - IDS_STATUSBAR_NETWORK_OPEN_PROXY_SETTINGS_DIALOG); |
| - menu_items_.push_back(MenuItem(ui::MenuModel::TYPE_COMMAND, label, |
| - SkBitmap(), std::string(), FLAG_OPTIONS)); |
| } |
| // Recursively call each submenu to populate its own menu items. |
| for (size_t i = 0; i < menu_items_.size(); ++i) { |
| - if (menu_items_[i].type == ui::MenuModel::TYPE_SUBMENU && |
| - menu_items_[i].sub_menu_model) { |
| + if (menu_items_[i].type == ui::MenuModel::TYPE_SUBMENU) { |
| + NetworkMenuModel* model = menu_items_[i].sub_menu_model; |
| + if (model == NULL) |
| + continue; |
| + if (model == more_menu_model_.get()) { |
| + // This submenu is already initialized. |
| + continue; |
| + } |
| menu_items_[i].sub_menu_model->InitMenuItems(is_browser_mode, |
| should_open_button_options); |
| } |
| @@ -761,28 +774,40 @@ void MainMenuModel::InitMenuItems(bool is_browser_mode, |
| // MainMenuModel, views::MenuDelegate implementation --------------------------- |
| const gfx::Font& MainMenuModel::GetLabelFont(int id) const { |
| - if (id >= kVPNCommandIndexOffset) |
| + DCHECK(kMoreCommandIndexOffset > kVPNCommandIndexOffset); |
| + if (id >= kMoreCommandIndexOffset) |
| + return more_menu_model_->GetLabelFont(id - kMoreCommandIndexOffset); |
| + else if (id >= kVPNCommandIndexOffset) |
| return vpn_menu_model_->GetLabelFont(id - kVPNCommandIndexOffset); |
| else |
| return NetworkMenuModel::GetLabelFont(id); |
| } |
| bool MainMenuModel::IsItemChecked(int id) const { |
| - if (id >= kVPNCommandIndexOffset) |
| + DCHECK(kMoreCommandIndexOffset > kVPNCommandIndexOffset); |
| + if (id >= kMoreCommandIndexOffset) |
| + return more_menu_model_->IsItemChecked(id - kMoreCommandIndexOffset); |
| + else if (id >= kVPNCommandIndexOffset) |
| return vpn_menu_model_->IsItemChecked(id - kVPNCommandIndexOffset); |
| else |
| return NetworkMenuModel::IsItemChecked(id); |
| } |
| bool MainMenuModel::IsCommandEnabled(int id) const { |
| - if (id >= kVPNCommandIndexOffset) |
| + DCHECK(kMoreCommandIndexOffset > kVPNCommandIndexOffset); |
| + if (id >= kMoreCommandIndexOffset) |
| + return more_menu_model_->IsCommandEnabled(id - kMoreCommandIndexOffset); |
| + else if (id >= kVPNCommandIndexOffset) |
| return vpn_menu_model_->IsCommandEnabled(id - kVPNCommandIndexOffset); |
| else |
| return NetworkMenuModel::IsCommandEnabled(id); |
| } |
| void MainMenuModel::ExecuteCommand(int id) { |
| - if (id >= kVPNCommandIndexOffset) |
| + DCHECK(kMoreCommandIndexOffset > kVPNCommandIndexOffset); |
| + if (id >= kMoreCommandIndexOffset) |
| + more_menu_model_->ExecuteCommand(id - kMoreCommandIndexOffset); |
| + else if (id >= kVPNCommandIndexOffset) |
| vpn_menu_model_->ExecuteCommand(id - kVPNCommandIndexOffset); |
| else |
| NetworkMenuModel::ExecuteCommand(id); |
| @@ -791,22 +816,18 @@ void MainMenuModel::ExecuteCommand(int id) { |
| // MainMenuModel, NetworkMenuModel implementation: ----------------------------- |
| void MainMenuModel::PopulateMenuItem( |
| - views::MenuItemView* menu, |
| - int index, |
| - int command_id) { |
| + views::MenuItemView* menu, int index, int command_id) { |
| DCHECK_GT(static_cast<int>(menu_items_.size()), index); |
| const MenuItem& item = menu_items_[index]; |
| if (item.type == ui::MenuModel::TYPE_SUBMENU) { |
| - views::MenuItemView* vpn_menu = NULL; |
| + views::MenuItemView* sub_menu = NULL; |
| if (item.icon.empty()) { |
| - vpn_menu = menu->AppendSubMenu(command_id, UTF16ToWide(item.label)); |
| + sub_menu = menu->AppendSubMenu(command_id, UTF16ToWide(item.label)); |
| } else { |
| - vpn_menu = menu->AppendSubMenuWithIcon( |
| - command_id, |
| - UTF16ToWide(item.label), |
| - item.icon); |
| + sub_menu = menu->AppendSubMenuWithIcon( |
| + command_id, UTF16ToWide(item.label), item.icon); |
| } |
| - vpn_menu_model_->PopulateMenu(vpn_menu); |
| + item.sub_menu_model->PopulateMenu(sub_menu); |
| } else { |
| NetworkMenuModel::PopulateMenuItem(menu, index, command_id); |
| } |
| @@ -886,13 +907,9 @@ void VPNMenuModel::InitMenuItems(bool is_browser_mode, |
| } |
| void VPNMenuModel::PopulateMenuItem( |
| - views::MenuItemView* menu, |
| - int index, |
| - int command_id) { |
| + views::MenuItemView* menu, int index, int command_id) { |
| NetworkMenuModel::PopulateMenuItem( |
| - menu, |
| - index, |
| - command_id + kVPNCommandIndexOffset); |
| + menu, index, command_id + kVPNCommandIndexOffset); |
| } |
| // static |
| @@ -932,6 +949,85 @@ SkBitmap VPNMenuModel::IconForDisplay(const Network* network) { |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| +// MoreMenuModel |
| + |
| +MoreMenuModel::MoreMenuModel(NetworkMenu* owner) |
| + : NetworkMenuModel(owner) { |
| +} |
| + |
| +void MoreMenuModel::InitMenuItems( |
| + bool is_browser_mode, bool should_open_button_options) { |
| + // This gets called on initialization, so any changes should be reflected |
| + // in CrosMock::SetNetworkLibraryStatusAreaExpectations(). |
| + |
| + menu_items_.clear(); |
| + 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.
|
| + 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.
|
| + |
| + NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); |
| + bool oobe = !should_open_button_options; // we don't show options for OOBE. |
| + if (!oobe) { |
| + string16 label = l10n_util::GetStringUTF16(is_browser_mode ? |
| + IDS_STATUSBAR_NETWORK_OPEN_OPTIONS_DIALOG : |
| + IDS_STATUSBAR_NETWORK_OPEN_PROXY_SETTINGS_DIALOG); |
| + link_items_.push_back(MenuItem(ui::MenuModel::TYPE_COMMAND, label, |
| + SkBitmap(), std::string(), FLAG_OPTIONS)); |
| + } |
| + |
| + bool connected = cros->Connected(); // always call for test expectations. |
| + if (connected) { |
| + std::string ip_address = cros->IPAddress(); |
| + if (!ip_address.empty()) { |
| + address_items_.push_back(MenuItem(ui::MenuModel::TYPE_COMMAND, |
| + ASCIIToUTF16(cros->IPAddress()), SkBitmap(), std::string(), |
| + FLAG_DISABLED)); |
| + } |
| + } |
| + |
| + if (!is_browser_mode) { |
| + if (cros->wifi_enabled()) { |
| + NetworkDeviceVector wifi = cros->FindWifiDevices(); |
| + for (size_t i = 0; i < wifi.size(); ++i) { |
| + std::string hardware_address; |
| + cros->GetIPConfigs(wifi[i]->device_path(), |
| + &hardware_address, NetworkLibrary::FORMAT_COLON_SEPARATED_HEX); |
| + if (!hardware_address.empty()) { |
| + std::string label = l10n_util::GetStringUTF8( |
| + IDS_STATUSBAR_NETWORK_DEVICE_WIFI) + " " + hardware_address; |
| + address_items_.push_back(MenuItem(ui::MenuModel::TYPE_COMMAND, |
| + UTF8ToUTF16(label), SkBitmap(), std::string(), FLAG_DISABLED)); |
| + } |
| + } |
| + } |
| + |
| + NetworkDeviceVector ether = cros->FindEthernetDevices(); |
| + for (size_t i = 0; i < ether.size(); ++i) { |
| + std::string hardware_address; |
| + cros->GetIPConfigs(ether[i]->device_path(), &hardware_address, |
| + NetworkLibrary::FORMAT_COLON_SEPARATED_HEX); |
| + if (!hardware_address.empty()) { |
| + std::string label = l10n_util::GetStringUTF8( |
| + IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET) + " " + hardware_address; |
| + address_items_.push_back(MenuItem(ui::MenuModel::TYPE_COMMAND, |
| + UTF8ToUTF16(label), SkBitmap(), std::string(), FLAG_DISABLED)); |
| + } |
| + } |
|
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.
|
| + } |
| + |
| + 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.
|
| + if (!menu_items_.empty() && address_items_.size() > 1) |
| + menu_items_.push_back(MenuItem()); // Separator |
| + menu_items_.insert(menu_items_.end(), |
| + address_items_.begin(), address_items_.end()); |
| +} |
| + |
| +void MoreMenuModel::PopulateMenuItem( |
| + views::MenuItemView* menu, int index, int command_id) { |
| + NetworkMenuModel::PopulateMenuItem( |
| + menu, index, command_id + kMoreCommandIndexOffset); |
| +} |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| // NetworkMenu |
| // static |
| @@ -979,8 +1075,7 @@ SkBitmap NetworkMenu::kAnimatingImages[kNumAnimatingImages]; |
| // static |
| SkBitmap NetworkMenu::kAnimatingImagesBlack[kNumAnimatingImages]; |
| -NetworkMenu::NetworkMenu() |
| - : min_width_(-1) { |
| +NetworkMenu::NetworkMenu() : min_width_(-1) { |
| main_menu_model_.reset(new MainMenuModel(this)); |
| network_menu_.reset(new views::MenuItemView(main_menu_model_.get())); |
| network_menu_->set_has_icons(true); |
| @@ -1229,3 +1324,5 @@ void NetworkMenu::RunMenu(views::View* source, const gfx::Point& pt) { |
| } |
| } // namespace chromeos |
| + |
| + |