1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/status/network_menu.h"
10 #include "ash/shell_delegate.h"
11 #include "ash/strings/grit/ash_strings.h"
12 #include "base/bind.h"
13 #include "base/logging.h"
14 #include "base/strings/stringprintf.h"
15 #include "base/strings/utf_string_conversions.h"
16 #include "chrome/browser/chromeos/mobile_config.h"
17 #include "chrome/browser/chromeos/options/network_config_view.h"
18 #include "chrome/browser/chromeos/sim_dialog_delegate.h"
19 #include "chrome/browser/chromeos/ui/choose_mobile_network_dialog.h"
20 #include "chrome/browser/defaults.h"
21 #include "chrome/browser/profiles/profile_manager.h"
22 #include "chrome/common/url_constants.h"
23 #include "chrome/grit/generated_resources.h"
24 #include "chromeos/network/device_state.h"
25 #include "chromeos/network/network_state.h"
26 #include "chromeos/network/network_state_handler.h"
27 #include "third_party/cros_system_api/dbus/service_constants.h"
28 #include "ui/base/l10n/l10n_util.h"
29 #include "ui/base/models/menu_model.h"
30 #include "ui/base/resource/resource_bundle.h"
31 #include "ui/chromeos/network/network_connect.h"
32 #include "ui/chromeos/network/network_icon.h"
33 #include "ui/chromeos/strings/grit/ui_chromeos_strings.h"
34 #include "ui/gfx/image/image_skia.h"
40 // Offsets for views menu ids (main menu and submenu ids use the same
42 const int kMainIndexMask
= 0x1000;
43 const int kMoreIndexMask
= 0x4000;
45 // Replace '&' in a string with "&&" to allow it to be a menu item label.
46 std::string
EscapeAmpersands(const std::string
& input
) {
47 std::string str
= input
;
48 size_t found
= str
.find('&');
49 while (found
!= std::string::npos
) {
50 str
.replace(found
, 1, "&&");
51 found
= str
.find('&', found
+ 2);
56 // Highlight any connected or connecting networks in the UI.
57 bool ShouldHighlightNetwork(const NetworkState
* network
) {
58 return network
->IsConnectedState() || network
->IsConnectingState();
61 void ToggleTechnology(const NetworkTypePattern
& technology
) {
62 NetworkStateHandler
* handler
= NetworkHandler::Get()->network_state_handler();
63 bool is_enabled
= handler
->IsTechnologyEnabled(technology
);
64 ui::NetworkConnect::Get()->SetTechnologyEnabled(technology
, !is_enabled
);
69 class NetworkMenuModel
: public ui::MenuModel
{
73 : type(ui::MenuModel::TYPE_SEPARATOR
),
77 MenuItem(ui::MenuModel::ItemType type
,
80 const std::string
& service_path
,
85 service_path(service_path
),
89 MenuItem(ui::MenuModel::ItemType type
,
92 NetworkMenuModel
* sub_menu_model
,
97 sub_menu_model(sub_menu_model
),
101 ui::MenuModel::ItemType type
;
102 base::string16 label
;
104 std::string service_path
;
105 NetworkMenuModel
* sub_menu_model
; // Weak ptr.
108 typedef std::vector
<MenuItem
> MenuItemVector
;
110 explicit NetworkMenuModel(const base::WeakPtr
<NetworkMenu
>& owner
)
112 ~NetworkMenuModel() override
{}
114 // Connect or reconnect to the network at |index|.
115 void ConnectToNetworkAt(int index
);
117 // Called by NetworkMenu::UpdateMenu to initialize menu items.
118 virtual void InitMenuItems(bool should_open_button_options
) = 0;
120 // Menu item field accessors.
121 const MenuItemVector
& menu_items() const { return menu_items_
; }
123 // ui::MenuModel implementation
124 // GetCommandIdAt() must be implemented by subclasses.
125 bool HasIcons() const override
;
126 int GetItemCount() const override
;
127 ui::MenuModel::ItemType
GetTypeAt(int index
) const override
;
128 ui::MenuSeparatorType
GetSeparatorTypeAt(int index
) const override
;
129 base::string16
GetLabelAt(int index
) const override
;
130 bool IsItemDynamicAt(int index
) const override
;
131 const gfx::FontList
* GetLabelFontListAt(int index
) const override
;
132 bool GetAcceleratorAt(int index
, ui::Accelerator
* accelerator
) const override
;
133 bool IsItemCheckedAt(int index
) const override
;
134 int GetGroupIdAt(int index
) const override
;
135 bool GetIconAt(int index
, gfx::Image
* icon
) override
;
136 ui::ButtonMenuItemModel
* GetButtonMenuItemAt(int index
) const override
;
137 bool IsEnabledAt(int index
) const override
;
138 bool IsVisibleAt(int index
) const override
;
139 ui::MenuModel
* GetSubmenuModelAt(int index
) const override
;
140 void HighlightChangedTo(int index
) override
;
141 void ActivatedAt(int index
) override
;
142 void SetMenuModelDelegate(ui::MenuModelDelegate
* delegate
) override
;
143 ui::MenuModelDelegate
* GetMenuModelDelegate() const override
;
148 FLAG_DISABLED
= 1 << 0,
149 FLAG_TOGGLE_WIFI
= 1 << 2,
150 FLAG_TOGGLE_MOBILE
= 1 << 3,
151 FLAG_ASSOCIATED
= 1 << 5,
152 FLAG_ETHERNET
= 1 << 6,
155 FLAG_CELLULAR
= 1 << 9,
156 FLAG_OPTIONS
= 1 << 10,
157 FLAG_ADD_WIFI
= 1 << 11,
158 FLAG_ADD_CELLULAR
= 1 << 12,
162 MenuItemVector menu_items_
;
164 // Weak pointer to NetworkMenu that owns this MenuModel.
165 base::WeakPtr
<NetworkMenu
> owner_
;
168 // Open a dialog to set up and connect to a network.
169 void ShowOther(const std::string
& type
) const;
171 DISALLOW_COPY_AND_ASSIGN(NetworkMenuModel
);
174 class MoreMenuModel
: public NetworkMenuModel
{
176 explicit MoreMenuModel(const base::WeakPtr
<NetworkMenu
> owner
)
177 : NetworkMenuModel(owner
) {}
178 ~MoreMenuModel() override
{}
180 // NetworkMenuModel implementation.
181 void InitMenuItems(bool should_open_button_options
) override
;
183 // ui::MenuModel implementation
184 int GetCommandIdAt(int index
) const override
;
187 DISALLOW_COPY_AND_ASSIGN(MoreMenuModel
);
190 class MainMenuModel
: public NetworkMenuModel
{
192 explicit MainMenuModel(const base::WeakPtr
<NetworkMenu
>& owner
)
193 : NetworkMenuModel(owner
),
194 more_menu_model_(new MoreMenuModel(owner
)) {
196 ~MainMenuModel() override
{}
198 // NetworkMenuModel implementation.
199 void InitMenuItems(bool should_open_button_options
) override
;
201 // ui::MenuModel implementation
202 int GetCommandIdAt(int index
) const override
;
205 void AddWirelessNetworkMenuItem(const NetworkState
* wifi_network
, int flag
);
206 void AddMessageItem(const base::string16
& msg
);
208 scoped_ptr
<MoreMenuModel
> more_menu_model_
;
210 DISALLOW_COPY_AND_ASSIGN(MainMenuModel
);
213 ////////////////////////////////////////////////////////////////////////////////
214 // NetworkMenuModel, public methods:
216 void NetworkMenuModel::ConnectToNetworkAt(int index
) {
217 const std::string
& service_path
= menu_items_
[index
].service_path
;
218 ui::NetworkConnect::Get()->ConnectToNetwork(service_path
);
221 ////////////////////////////////////////////////////////////////////////////////
222 // NetworkMenuModel, ui::MenuModel implementation:
224 bool NetworkMenuModel::HasIcons() const {
228 int NetworkMenuModel::GetItemCount() const {
229 return static_cast<int>(menu_items_
.size());
232 ui::MenuModel::ItemType
NetworkMenuModel::GetTypeAt(int index
) const {
233 return menu_items_
[index
].type
;
236 ui::MenuSeparatorType
NetworkMenuModel::GetSeparatorTypeAt(int index
) const {
237 return ui::NORMAL_SEPARATOR
;
240 base::string16
NetworkMenuModel::GetLabelAt(int index
) const {
241 return menu_items_
[index
].label
;
244 bool NetworkMenuModel::IsItemDynamicAt(int index
) const {
248 const gfx::FontList
* NetworkMenuModel::GetLabelFontListAt(int index
) const {
249 const gfx::FontList
* font_list
= NULL
;
250 if (menu_items_
[index
].flags
& FLAG_ASSOCIATED
) {
251 ui::ResourceBundle
* rb
= &ui::ResourceBundle::GetSharedInstance();
252 font_list
= &rb
->GetFontList(browser_defaults::kAssociatedNetworkFontStyle
);
258 bool NetworkMenuModel::GetAcceleratorAt(int index
,
259 ui::Accelerator
* accelerator
) const {
263 bool NetworkMenuModel::IsItemCheckedAt(int index
) const {
264 // All ui::MenuModel::TYPE_CHECK menu items are checked.
268 int NetworkMenuModel::GetGroupIdAt(int index
) const {
272 bool NetworkMenuModel::GetIconAt(int index
, gfx::Image
* icon
) {
273 if (!menu_items_
[index
].icon
.isNull()) {
274 *icon
= gfx::Image(menu_items_
[index
].icon
);
280 ui::ButtonMenuItemModel
* NetworkMenuModel::GetButtonMenuItemAt(
285 bool NetworkMenuModel::IsEnabledAt(int index
) const {
286 return !(menu_items_
[index
].flags
& FLAG_DISABLED
);
289 bool NetworkMenuModel::IsVisibleAt(int index
) const {
293 ui::MenuModel
* NetworkMenuModel::GetSubmenuModelAt(int index
) const {
294 return menu_items_
[index
].sub_menu_model
;
297 void NetworkMenuModel::HighlightChangedTo(int index
) {
300 void NetworkMenuModel::ActivatedAt(int index
) {
301 // When we are refreshing the menu, ignore menu item activation.
302 if (owner_
->refreshing_menu_
)
305 int flags
= menu_items_
[index
].flags
;
306 if (flags
& FLAG_OPTIONS
) {
307 owner_
->delegate()->OpenButtonOptions();
308 } else if (flags
& FLAG_TOGGLE_WIFI
) {
309 ToggleTechnology(NetworkTypePattern::WiFi());
310 } else if (flags
& FLAG_TOGGLE_MOBILE
) {
311 ToggleTechnology(NetworkTypePattern::Mobile());
312 } else if (flags
& FLAG_ETHERNET
) {
313 owner_
->delegate()->OnConnectToNetworkRequested();
314 } else if (flags
& (FLAG_WIFI
| FLAG_WIMAX
| FLAG_CELLULAR
)) {
315 ConnectToNetworkAt(index
);
316 owner_
->delegate()->OnConnectToNetworkRequested();
317 } else if (flags
& FLAG_ADD_WIFI
) {
318 ShowOther(shill::kTypeWifi
);
319 } else if (flags
& FLAG_ADD_CELLULAR
) {
320 ShowOther(shill::kTypeCellular
);
324 void NetworkMenuModel::SetMenuModelDelegate(ui::MenuModelDelegate
* delegate
) {
327 ui::MenuModelDelegate
* NetworkMenuModel::GetMenuModelDelegate() const {
331 ////////////////////////////////////////////////////////////////////////////////
332 // NetworkMenuModel, private methods:
334 void NetworkMenuModel::ShowOther(const std::string
& type
) const {
335 gfx::NativeWindow native_window
= owner_
->delegate()->GetNativeWindow();
336 if (type
== shill::kTypeCellular
)
337 ChooseMobileNetworkDialog::ShowDialog(native_window
);
339 NetworkConfigView::ShowForType(shill::kTypeWifi
, native_window
);
342 ////////////////////////////////////////////////////////////////////////////////
345 void MainMenuModel::AddWirelessNetworkMenuItem(const NetworkState
* network
,
347 base::string16 label
;
348 // Ampersand is a valid character in an SSID, but menu2 uses it to mark
349 // "mnemonics" for keyboard shortcuts.
350 std::string wifi_name
= EscapeAmpersands(network
->name());
351 if (network
->IsConnectingState()) {
352 label
= l10n_util::GetStringFUTF16(
353 IDS_STATUSBAR_NETWORK_DEVICE_STATUS
,
354 base::UTF8ToUTF16(wifi_name
),
355 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_CONNECTING
));
357 label
= base::UTF8ToUTF16(wifi_name
);
360 // We do not have convenient access to whether or not it might be possible
361 // to connect to a wireless network (e.g. whether certs are required), so all
362 // entries are enabled.
364 if (ShouldHighlightNetwork(network
))
365 flag
|= FLAG_ASSOCIATED
;
366 const gfx::ImageSkia icon
= ui::network_icon::GetImageForNetwork(
367 network
, ui::network_icon::ICON_TYPE_LIST
);
368 menu_items_
.push_back(
369 MenuItem(ui::MenuModel::TYPE_COMMAND
,
370 label
, icon
, network
->path(), flag
));
373 void MainMenuModel::AddMessageItem(const base::string16
& msg
) {
374 menu_items_
.push_back(MenuItem(
375 ui::MenuModel::TYPE_COMMAND
, msg
,
376 gfx::ImageSkia(), std::string(), FLAG_DISABLED
));
379 void MainMenuModel::InitMenuItems(bool should_open_button_options
) {
382 NetworkStateHandler
* handler
= NetworkHandler::Get()->network_state_handler();
384 // Populate our MenuItems with the current list of networks.
385 base::string16 label
;
388 // Only display an ethernet icon if enabled, and an ethernet network exists.
389 bool ethernet_enabled
=
390 handler
->IsTechnologyEnabled(NetworkTypePattern::Ethernet());
391 const NetworkState
* ethernet_network
=
392 handler
->FirstNetworkByType(NetworkTypePattern::Ethernet());
393 if (ethernet_enabled
&& ethernet_network
) {
394 bool ethernet_connecting
= ethernet_network
->IsConnectingState();
395 if (ethernet_connecting
) {
396 label
= l10n_util::GetStringFUTF16(
397 IDS_STATUSBAR_NETWORK_DEVICE_STATUS
,
398 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET
),
399 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_CONNECTING
));
401 label
= l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET
);
403 int flag
= FLAG_ETHERNET
;
404 if (ShouldHighlightNetwork(ethernet_network
))
405 flag
|= FLAG_ASSOCIATED
;
406 const gfx::ImageSkia icon
= ui::network_icon::GetImageForNetwork(
407 ethernet_network
, ui::network_icon::ICON_TYPE_LIST
);
408 menu_items_
.push_back(MenuItem(ui::MenuModel::TYPE_COMMAND
,
409 label
, icon
, std::string(), flag
));
412 // Get the list of all networks.
413 NetworkStateHandler::NetworkStateList network_list
;
414 handler
->GetVisibleNetworkList(&network_list
);
417 if (handler
->IsTechnologyEnabled(NetworkTypePattern::Cellular())) {
418 // List Cellular networks.
419 for (NetworkStateHandler::NetworkStateList::const_iterator iter
=
420 network_list
.begin(); iter
!= network_list
.end(); ++iter
) {
421 const NetworkState
* network
= *iter
;
422 if (network
->type() != shill::kTypeCellular
)
424 std::string activation_state
= network
->activation_state();
426 // This is only used in the login screen; do not show unactivated
428 if (activation_state
!= shill::kActivationStateActivated
)
431 // Ampersand is a valid character in a network name, but menu2 uses it
432 // to mark "mnemonics" for keyboard shortcuts. http://crosbug.com/14697
433 std::string network_name
= EscapeAmpersands(network
->name());
434 if (network
->IsConnectingState()) {
435 label
= l10n_util::GetStringFUTF16(
436 IDS_STATUSBAR_NETWORK_DEVICE_STATUS
,
437 base::UTF8ToUTF16(network_name
),
438 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_CONNECTING
));
440 label
= base::UTF8ToUTF16(network_name
);
443 int flag
= FLAG_CELLULAR
;
444 bool isActive
= ShouldHighlightNetwork(network
);
446 flag
|= FLAG_ASSOCIATED
;
447 const gfx::ImageSkia icon
= ui::network_icon::GetImageForNetwork(
448 network
, ui::network_icon::ICON_TYPE_LIST
);
449 menu_items_
.push_back(
450 MenuItem(ui::MenuModel::TYPE_COMMAND
,
451 label
, icon
, network
->path(), flag
));
454 // For GSM add cellular network scan.
455 const DeviceState
* cellular_device
=
456 handler
->GetDeviceStateByType(NetworkTypePattern::Cellular());
457 if (cellular_device
&& cellular_device
->support_network_scan()) {
458 const gfx::ImageSkia icon
=
459 ui::network_icon::GetImageForDisconnectedNetwork(
460 ui::network_icon::ICON_TYPE_LIST
, shill::kTypeCellular
);
461 menu_items_
.push_back(MenuItem(
462 ui::MenuModel::TYPE_COMMAND
,
463 l10n_util::GetStringUTF16(
464 IDS_OPTIONS_SETTINGS_OTHER_CELLULAR_NETWORKS
),
465 icon
, std::string(), FLAG_ADD_CELLULAR
));
468 int initializing_message_id
=
469 ui::network_icon::GetCellularUninitializedMsg();
470 if (initializing_message_id
) {
471 // Initializing cellular modem...
472 AddMessageItem(l10n_util::GetStringUTF16(initializing_message_id
));
477 if (handler
->IsTechnologyEnabled(NetworkTypePattern::Wimax())) {
478 // List Wimax networks.
479 for (NetworkStateHandler::NetworkStateList::const_iterator iter
=
480 network_list
.begin(); iter
!= network_list
.end(); ++iter
) {
481 const NetworkState
* network
= *iter
;
482 if (network
->type() != shill::kTypeWimax
)
484 AddWirelessNetworkMenuItem(network
, FLAG_WIMAX
);
489 if (handler
->IsTechnologyEnabled(NetworkTypePattern::WiFi())) {
490 // List Wifi networks.
491 int scanning_msg
= handler
->GetScanningByType(NetworkTypePattern::WiFi())
492 ? IDS_ASH_STATUS_TRAY_WIFI_SCANNING_MESSAGE
494 for (NetworkStateHandler::NetworkStateList::const_iterator iter
=
495 network_list
.begin(); iter
!= network_list
.end(); ++iter
) {
496 const NetworkState
* network
= *iter
;
497 if (network
->type() != shill::kTypeWifi
)
499 // Add 'Searching for Wi-Fi networks...' after connected networks.
500 if (scanning_msg
&& !network
->IsConnectedState()) {
501 AddMessageItem(l10n_util::GetStringUTF16(scanning_msg
));
504 AddWirelessNetworkMenuItem(network
, FLAG_WIFI
);
507 AddMessageItem(l10n_util::GetStringUTF16(scanning_msg
));
508 const gfx::ImageSkia icon
= ui::network_icon::GetImageForConnectedNetwork(
509 ui::network_icon::ICON_TYPE_LIST
, shill::kTypeWifi
);
510 menu_items_
.push_back(MenuItem(
511 ui::MenuModel::TYPE_COMMAND
,
512 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_OTHER_WIFI_NETWORKS
),
513 icon
, std::string(), FLAG_ADD_WIFI
));
516 if (menu_items_
.empty()) {
517 // No networks available (and not initializing cellular or wifi scanning)
518 AddMessageItem(l10n_util::GetStringFUTF16(
519 IDS_STATUSBAR_NETWORK_MENU_ITEM_INDENT
,
520 l10n_util::GetStringUTF16(IDS_STATUSBAR_NO_NETWORKS_MESSAGE
)));
523 // Enable / Disable Technology
524 NetworkStateHandler::TechnologyState wifi_state
=
525 handler
->GetTechnologyState(NetworkTypePattern::WiFi());
526 bool wifi_available
=
527 wifi_state
!= NetworkStateHandler::TECHNOLOGY_UNAVAILABLE
;
528 bool wifi_enabled
= wifi_state
== NetworkStateHandler::TECHNOLOGY_ENABLED
;
530 NetworkStateHandler::TechnologyState mobile_state
=
531 handler
->GetTechnologyState(NetworkTypePattern::Mobile());
532 bool mobile_available
=
533 mobile_state
!= NetworkStateHandler::TECHNOLOGY_UNAVAILABLE
;
534 bool mobile_enabled
= mobile_state
== NetworkStateHandler::TECHNOLOGY_ENABLED
;
536 // Do not show disable wifi or cellular during oobe.
537 bool show_toggle_wifi
= wifi_available
&&
538 (should_open_button_options
|| !wifi_enabled
);
539 bool show_toggle_mobile
= mobile_available
&&
540 (should_open_button_options
|| !mobile_enabled
);
542 if (show_toggle_wifi
|| show_toggle_mobile
) {
543 menu_items_
.push_back(MenuItem()); // Separator
545 if (show_toggle_wifi
) {
546 int id
= wifi_enabled
? IDS_STATUSBAR_NETWORK_DEVICE_DISABLE
:
547 IDS_STATUSBAR_NETWORK_DEVICE_ENABLE
;
548 label
= l10n_util::GetStringFUTF16(id
,
549 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_WIFI
));
550 int flag
= FLAG_TOGGLE_WIFI
;
551 if (wifi_state
== NetworkStateHandler::TECHNOLOGY_ENABLING
)
552 flag
|= FLAG_DISABLED
;
553 menu_items_
.push_back(MenuItem(ui::MenuModel::TYPE_COMMAND
, label
,
554 gfx::ImageSkia(), std::string(), flag
));
557 if (show_toggle_mobile
) {
558 const DeviceState
* mobile_device
=
559 handler
->GetDeviceStateByType(NetworkTypePattern::Mobile());
560 bool is_locked
= mobile_device
&& !mobile_device
->sim_lock_type().empty();
561 int id
= (mobile_enabled
&& !is_locked
)
562 ? IDS_STATUSBAR_NETWORK_DEVICE_DISABLE
563 : IDS_STATUSBAR_NETWORK_DEVICE_ENABLE
;
564 label
= l10n_util::GetStringFUTF16(id
,
565 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_CELLULAR
));
567 int flag
= FLAG_TOGGLE_MOBILE
;
568 if (mobile_state
== NetworkStateHandler::TECHNOLOGY_ENABLING
)
569 flag
|= FLAG_DISABLED
;
570 menu_items_
.push_back(MenuItem(ui::MenuModel::TYPE_COMMAND
, label
,
571 icon
, std::string(), flag
));
575 // Additional links like:
576 // * IP Address on active interface;
577 // * Hardware addresses for wifi and ethernet.
578 more_menu_model_
->InitMenuItems(should_open_button_options
);
579 if (!more_menu_model_
->menu_items().empty()) {
580 menu_items_
.push_back(MenuItem()); // Separator
581 menu_items_
.push_back(MenuItem(
582 ui::MenuModel::TYPE_SUBMENU
,
583 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_MORE
),
584 gfx::ImageSkia(), more_menu_model_
.get(), FLAG_NONE
));
588 int MainMenuModel::GetCommandIdAt(int index
) const {
589 return index
+ kMainIndexMask
;
592 ////////////////////////////////////////////////////////////////////////////////
595 void MoreMenuModel::InitMenuItems(bool should_open_button_options
) {
597 MenuItemVector link_items
;
598 MenuItemVector address_items
;
600 NetworkStateHandler
* handler
= NetworkHandler::Get()->network_state_handler();
601 const NetworkState
* default_network
= handler
->DefaultNetwork();
605 message_id
= IDS_STATUSBAR_NETWORK_OPEN_PROXY_SETTINGS_DIALOG
;
606 if (message_id
!= -1) {
607 link_items
.push_back(MenuItem(ui::MenuModel::TYPE_COMMAND
,
608 l10n_util::GetStringUTF16(message_id
),
614 if (default_network
) {
615 std::string ip_address
= default_network
->ip_address();
616 if (!ip_address
.empty()) {
617 address_items
.push_back(MenuItem(
618 ui::MenuModel::TYPE_COMMAND
, base::ASCIIToUTF16(ip_address
),
619 gfx::ImageSkia(), std::string(), FLAG_DISABLED
));
623 std::string ethernet_address
=
624 handler
->FormattedHardwareAddressForType(NetworkTypePattern::Ethernet());
625 if (!ethernet_address
.empty()) {
626 std::string label
= l10n_util::GetStringUTF8(
627 IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET
) + " " + ethernet_address
;
628 address_items
.push_back(MenuItem(
629 ui::MenuModel::TYPE_COMMAND
, base::UTF8ToUTF16(label
),
630 gfx::ImageSkia(), std::string(), FLAG_DISABLED
));
633 std::string wifi_address
=
634 handler
->FormattedHardwareAddressForType(NetworkTypePattern::WiFi());
635 if (!wifi_address
.empty()) {
636 std::string label
= l10n_util::GetStringUTF8(
637 IDS_STATUSBAR_NETWORK_DEVICE_WIFI
) + " " + wifi_address
;
638 address_items
.push_back(MenuItem(
639 ui::MenuModel::TYPE_COMMAND
, base::UTF8ToUTF16(label
),
640 gfx::ImageSkia(), std::string(), FLAG_DISABLED
));
643 menu_items_
= link_items
;
644 if (!menu_items_
.empty() && address_items
.size() > 1)
645 menu_items_
.push_back(MenuItem()); // Separator
646 menu_items_
.insert(menu_items_
.end(),
647 address_items
.begin(), address_items
.end());
650 int MoreMenuModel::GetCommandIdAt(int index
) const {
651 return index
+ kMoreIndexMask
;
654 ////////////////////////////////////////////////////////////////////////////////
657 NetworkMenu::Delegate::~Delegate() {
660 NetworkMenu::NetworkMenu(Delegate
* delegate
)
661 : delegate_(delegate
),
662 refreshing_menu_(false),
663 weak_pointer_factory_(this) {
664 main_menu_model_
.reset(new MainMenuModel(weak_pointer_factory_
.GetWeakPtr()));
667 NetworkMenu::~NetworkMenu() {
670 ui::MenuModel
* NetworkMenu::GetMenuModel() {
671 return main_menu_model_
.get();
674 void NetworkMenu::UpdateMenu() {
675 refreshing_menu_
= true;
676 main_menu_model_
->InitMenuItems(delegate_
->ShouldOpenButtonOptions());
677 refreshing_menu_
= false;
680 } // namespace chromeos