OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 | 88 |
89 bool NetworkMenu::GetNetworkAt(int index, NetworkInfo* info) const { | 89 bool NetworkMenu::GetNetworkAt(int index, NetworkInfo* info) const { |
90 DCHECK(info); | 90 DCHECK(info); |
91 bool res = true; // True unless a network doesn't exist. | 91 bool res = true; // True unless a network doesn't exist. |
92 int flags = menu_items_[index].flags; | 92 int flags = menu_items_[index].flags; |
93 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | 93 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); |
94 if (flags & FLAG_ETHERNET) { | 94 if (flags & FLAG_ETHERNET) { |
95 info->network_type = kNetworkTypeEthernet; | 95 info->network_type = kNetworkTypeEthernet; |
96 if (cros->ethernet_connected()) { | 96 if (cros->ethernet_connected()) { |
97 info->status = kNetworkStatusConnected; | 97 info->status = kNetworkStatusConnected; |
98 info->ip_address = cros->ethernet_network().ip_address(); | 98 info->ip_address = cros->ethernet_network() ? |
| 99 cros->ethernet_network()->ip_address() : std::string(); |
99 } | 100 } |
100 info->need_passphrase = false; | 101 info->need_passphrase = false; |
101 info->remembered = true; | 102 info->remembered = true; |
102 } else if (flags & FLAG_WIFI) { | 103 } else if (flags & FLAG_WIFI) { |
103 WifiNetwork wifi; | 104 WifiNetwork* wifi = cros->FindWifiNetworkByPath( |
104 bool found = cros->FindWifiNetworkByPath( | 105 menu_items_[index].wireless_path); |
105 menu_items_[index].wireless_path, &wifi); | 106 if (wifi) { |
106 if (found) { | |
107 info->network_type = kNetworkTypeWifi; | 107 info->network_type = kNetworkTypeWifi; |
108 if (wifi.service_path() == cros->wifi_network().service_path()) { | 108 if (cros->wifi_network() && |
| 109 wifi->service_path() == cros->wifi_network()->service_path()) { |
109 if (cros->wifi_connected()) { | 110 if (cros->wifi_connected()) { |
110 info->status = kNetworkStatusConnected; | 111 info->status = kNetworkStatusConnected; |
111 info->message = l10n_util::GetStringUTF8( | 112 info->message = l10n_util::GetStringUTF8( |
112 IDS_STATUSBAR_NETWORK_DEVICE_CONNECTED); | 113 IDS_STATUSBAR_NETWORK_DEVICE_CONNECTED); |
113 } else if (cros->wifi_connecting()) { | 114 } else if (cros->wifi_connecting()) { |
114 info->status = kNetworkStatusConnecting; | 115 info->status = kNetworkStatusConnecting; |
115 info->message = l10n_util::GetStringUTF8( | 116 info->message = l10n_util::GetStringUTF8( |
116 IDS_STATUSBAR_NETWORK_DEVICE_CONNECTING); | 117 IDS_STATUSBAR_NETWORK_DEVICE_CONNECTING); |
117 } else if (wifi.state() == STATE_FAILURE) { | 118 } else if (wifi->state() == STATE_FAILURE) { |
118 info->status = kNetworkStatusError; | 119 info->status = kNetworkStatusError; |
119 info->message = wifi.GetErrorString(); | 120 info->message = wifi->GetErrorString(); |
120 } else { | 121 } else { |
121 info->status = kNetworkStatusDisconnected; | 122 info->status = kNetworkStatusDisconnected; |
122 info->message = l10n_util::GetStringUTF8( | 123 info->message = l10n_util::GetStringUTF8( |
123 IDS_STATUSBAR_NETWORK_DEVICE_DISCONNECTED); | 124 IDS_STATUSBAR_NETWORK_DEVICE_DISCONNECTED); |
124 } | 125 } |
125 } else { | 126 } else { |
126 info->status = kNetworkStatusDisconnected; | 127 info->status = kNetworkStatusDisconnected; |
127 info->message = l10n_util::GetStringUTF8( | 128 info->message = l10n_util::GetStringUTF8( |
128 IDS_STATUSBAR_NETWORK_DEVICE_DISCONNECTED); | 129 IDS_STATUSBAR_NETWORK_DEVICE_DISCONNECTED); |
129 } | 130 } |
130 if (wifi.encrypted()) { | 131 if (wifi->encrypted()) { |
131 info->need_passphrase = true; | 132 info->need_passphrase = true; |
132 if (wifi.IsCertificateLoaded() || | 133 if (wifi->IsCertificateLoaded() || |
133 wifi.encryption() == SECURITY_8021X) { | 134 wifi->encryption() == SECURITY_8021X) { |
134 info->need_passphrase = false; | 135 info->need_passphrase = false; |
135 } | 136 } |
136 if (wifi.favorite()) { | 137 if (wifi->favorite()) { |
137 info->passphrase = wifi.passphrase(); | 138 info->passphrase = wifi->passphrase(); |
138 info->need_passphrase = false; | 139 info->need_passphrase = false; |
139 } | 140 } |
140 } else { | 141 } else { |
141 info->need_passphrase = false; | 142 info->need_passphrase = false; |
142 } | 143 } |
143 info->ip_address = wifi.ip_address(); | 144 info->ip_address = wifi->ip_address(); |
144 info->remembered = wifi.favorite(); | 145 info->remembered = wifi->favorite(); |
145 } else { | 146 } else { |
146 res = false; // Network not found, hide entry. | 147 res = false; // Network not found, hide entry. |
147 } | 148 } |
148 } else if (flags & FLAG_CELLULAR) { | 149 } else if (flags & FLAG_CELLULAR) { |
149 CellularNetwork cellular; | 150 CellularNetwork* cellular = cros->FindCellularNetworkByPath( |
150 bool found = cros->FindCellularNetworkByPath( | 151 menu_items_[index].wireless_path); |
151 menu_items_[index].wireless_path, &cellular); | 152 if (cellular) { |
152 if (found) { | |
153 info->network_type = kNetworkTypeCellular; | 153 info->network_type = kNetworkTypeCellular; |
154 if (cellular.service_path() == | 154 if (cros->cellular_network() && cellular->service_path() == |
155 cros->cellular_network().service_path()) { | 155 cros->cellular_network()->service_path()) { |
156 if (cros->cellular_connected()) { | 156 if (cros->cellular_connected()) { |
157 info->status = kNetworkStatusConnected; | 157 info->status = kNetworkStatusConnected; |
158 info->message = l10n_util::GetStringUTF8( | 158 info->message = l10n_util::GetStringUTF8( |
159 IDS_STATUSBAR_NETWORK_DEVICE_CONNECTED); | 159 IDS_STATUSBAR_NETWORK_DEVICE_CONNECTED); |
160 } else if (cros->cellular_connecting()) { | 160 } else if (cros->cellular_connecting()) { |
161 // TODO(stevenjb): Eliminate status message, or localize properly. | 161 // TODO(stevenjb): Eliminate status message, or localize properly. |
162 info->status = kNetworkStatusConnecting; | 162 info->status = kNetworkStatusConnecting; |
163 info->message = l10n_util::GetStringUTF8( | 163 info->message = l10n_util::GetStringUTF8( |
164 IDS_STATUSBAR_NETWORK_DEVICE_CONNECTING) | 164 IDS_STATUSBAR_NETWORK_DEVICE_CONNECTING) |
165 + ": " + cellular.GetStateString(); | 165 + ": " + cellular->GetStateString(); |
166 } else if (cellular.state() == STATE_FAILURE) { | 166 } else if (cellular->state() == STATE_FAILURE) { |
167 info->status = kNetworkStatusError; | 167 info->status = kNetworkStatusError; |
168 info->message = cellular.GetErrorString(); | 168 info->message = cellular->GetErrorString(); |
169 } else { | 169 } else { |
170 info->status = kNetworkStatusDisconnected; | 170 info->status = kNetworkStatusDisconnected; |
171 info->message = l10n_util::GetStringUTF8( | 171 info->message = l10n_util::GetStringUTF8( |
172 IDS_STATUSBAR_NETWORK_DEVICE_DISCONNECTED); | 172 IDS_STATUSBAR_NETWORK_DEVICE_DISCONNECTED); |
173 } | 173 } |
174 } else { | 174 } else { |
175 info->status = kNetworkStatusDisconnected; | 175 info->status = kNetworkStatusDisconnected; |
176 info->message = l10n_util::GetStringUTF8( | 176 info->message = l10n_util::GetStringUTF8( |
177 IDS_STATUSBAR_NETWORK_DEVICE_DISCONNECTED); | 177 IDS_STATUSBAR_NETWORK_DEVICE_DISCONNECTED); |
178 } | 178 } |
179 info->ip_address = cellular.ip_address(); | 179 info->ip_address = cellular->ip_address(); |
180 info->need_passphrase = false; | 180 info->need_passphrase = false; |
181 info->remembered = true; | 181 info->remembered = true; |
182 } else { | 182 } else { |
183 res = false; // Network not found, hide entry. | 183 res = false; // Network not found, hide entry. |
184 } | 184 } |
185 } else if (flags & FLAG_OTHER_NETWORK) { | 185 } else if (flags & FLAG_OTHER_NETWORK) { |
186 info->status = kNetworkStatusDisconnected; | 186 info->status = kNetworkStatusDisconnected; |
187 info->message = l10n_util::GetStringUTF8( | 187 info->message = l10n_util::GetStringUTF8( |
188 IDS_STATUSBAR_NETWORK_DEVICE_DISCONNECTED); | 188 IDS_STATUSBAR_NETWORK_DEVICE_DISCONNECTED); |
189 info->network_type = kNetworkTypeOther; | 189 info->network_type = kNetworkTypeOther; |
190 info->need_passphrase = true; | 190 info->need_passphrase = true; |
191 info->remembered = true; | 191 info->remembered = true; |
192 } else { | 192 } else { |
193 // Not a network, e.g options, separator. | 193 // Not a network, e.g options, separator. |
194 } | 194 } |
195 return res; | 195 return res; |
196 } | 196 } |
197 | 197 |
198 bool NetworkMenu::ConnectToNetworkAt(int index, | 198 bool NetworkMenu::ConnectToNetworkAt(int index, |
199 const std::string& passphrase, | 199 const std::string& passphrase, |
200 const std::string& ssid, | 200 const std::string& ssid, |
201 int remember) const { | 201 int remember) const { |
202 int flags = menu_items_[index].flags; | 202 int flags = menu_items_[index].flags; |
203 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | 203 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); |
204 if (flags & FLAG_WIFI) { | 204 if (flags & FLAG_WIFI) { |
205 WifiNetwork wifi; | 205 WifiNetwork* wifi = cros->FindWifiNetworkByPath( |
206 bool found = cros->FindWifiNetworkByPath( | 206 menu_items_[index].wireless_path); |
207 menu_items_[index].wireless_path, &wifi); | 207 if (wifi) { |
208 if (found) { | |
209 // Connect or reconnect. | 208 // Connect or reconnect. |
210 if (remember >= 0) | 209 if (remember >= 0) |
211 wifi.set_favorite(remember ? true : false); | 210 wifi->set_favorite(remember ? true : false); |
212 if (wifi.encrypted()) { | 211 if (wifi->encrypted()) { |
213 if (wifi.IsCertificateLoaded()) { | 212 if (wifi->IsCertificateLoaded()) { |
214 cros->ConnectToWifiNetwork(wifi, std::string(), std::string(), | 213 cros->ConnectToWifiNetwork(wifi, std::string(), std::string(), |
215 wifi.cert_path()); | 214 wifi->cert_path()); |
216 } else if (wifi.encryption() == SECURITY_8021X) { | 215 } else if (wifi->encryption() == SECURITY_8021X) { |
217 // Show the wifi settings/dialog to load/select a certificate. | 216 // Show the wifi settings/dialog to load/select a certificate. |
218 ShowWifi(wifi, true); | 217 ShowWifi(wifi, true); |
219 } else { | 218 } else { |
220 if (MenuUI::IsEnabled()) { | 219 if (MenuUI::IsEnabled()) { |
221 cros->ConnectToWifiNetwork(wifi, passphrase, std::string(), | 220 cros->ConnectToWifiNetwork(wifi, passphrase, std::string(), |
222 std::string()); | 221 std::string()); |
223 } else { | 222 } else { |
224 ShowWifi(wifi, true); | 223 ShowWifi(wifi, true); |
225 } | 224 } |
226 } | 225 } |
227 } else { | 226 } else { |
228 cros->ConnectToWifiNetwork(wifi, std::string(), std::string(), | 227 cros->ConnectToWifiNetwork(wifi, std::string(), std::string(), |
229 std::string()); | 228 std::string()); |
230 } | 229 } |
231 } | 230 } |
232 } else if (flags & FLAG_CELLULAR) { | 231 } else if (flags & FLAG_CELLULAR) { |
233 CellularNetwork cellular; | 232 CellularNetwork* cellular = cros->FindCellularNetworkByPath( |
234 bool found = cros->FindCellularNetworkByPath( | 233 menu_items_[index].wireless_path); |
235 menu_items_[index].wireless_path, &cellular); | 234 if (cellular) { |
236 if (found) { | 235 // TODO(zelidrag): Start activation process if needed. |
237 // Connect or reconnect. | 236 // Connect or reconnect. |
238 cros->ConnectToCellularNetwork(cellular); | 237 cros->ConnectToCellularNetwork(cellular); |
239 } | 238 } |
240 } else if (flags & FLAG_OTHER_NETWORK) { | 239 } else if (flags & FLAG_OTHER_NETWORK) { |
241 bool favorite = remember == 0 ? false : true; // default is true | 240 bool favorite = remember == 0 ? false : true; // default is true |
242 cros->ConnectToWifiNetwork(ssid, passphrase, std::string(), std::string(), | 241 cros->ConnectToWifiNetwork(ssid, passphrase, std::string(), std::string(), |
243 favorite); | 242 favorite); |
244 } | 243 } |
245 return true; | 244 return true; |
246 } | 245 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 cros->EnableCellularNetworkDevice(!cros->cellular_enabled()); | 299 cros->EnableCellularNetworkDevice(!cros->cellular_enabled()); |
301 } else if (flags & FLAG_TOGGLE_OFFLINE) { | 300 } else if (flags & FLAG_TOGGLE_OFFLINE) { |
302 cros->EnableOfflineMode(!cros->offline_mode()); | 301 cros->EnableOfflineMode(!cros->offline_mode()); |
303 } else if (flags & FLAG_OTHER_NETWORK) { | 302 } else if (flags & FLAG_OTHER_NETWORK) { |
304 ShowOther(); | 303 ShowOther(); |
305 } else if (flags & FLAG_ETHERNET) { | 304 } else if (flags & FLAG_ETHERNET) { |
306 if (cros->ethernet_connected()) { | 305 if (cros->ethernet_connected()) { |
307 ShowEthernet(cros->ethernet_network()); | 306 ShowEthernet(cros->ethernet_network()); |
308 } | 307 } |
309 } else if (flags & FLAG_WIFI) { | 308 } else if (flags & FLAG_WIFI) { |
310 WifiNetwork wifi; | 309 WifiNetwork* wifi = cros->FindWifiNetworkByPath( |
311 bool wifi_exists = cros->FindWifiNetworkByPath( | 310 menu_items_[index].wireless_path); |
312 menu_items_[index].wireless_path, &wifi); | 311 if (!wifi) { |
313 if (!wifi_exists) { | |
314 // If we are attempting to connect to a network that no longer exists, | 312 // If we are attempting to connect to a network that no longer exists, |
315 // display a notification. | 313 // display a notification. |
316 // TODO(stevenjb): Show notification. | 314 // TODO(stevenjb): Show notification. |
317 } else if (wifi.service_path() == cros->wifi_network().service_path()) { | 315 } else if (cros->wifi_network() && |
| 316 wifi->service_path() == cros->wifi_network()->service_path()) { |
318 // Show the config settings for the active network. | 317 // Show the config settings for the active network. |
319 ShowWifi(wifi, false); | 318 ShowWifi(wifi, false); |
320 } else { | 319 } else { |
321 ConnectToNetworkAt(index, std::string(), std::string(), -1); | 320 ConnectToNetworkAt(index, std::string(), std::string(), -1); |
322 } | 321 } |
323 } else if (flags & FLAG_CELLULAR) { | 322 } else if (flags & FLAG_CELLULAR) { |
324 CellularNetwork cellular; | 323 CellularNetwork* cellular = cros->FindCellularNetworkByPath( |
325 bool cellular_exists = cros->FindCellularNetworkByPath( | 324 menu_items_[index].wireless_path); |
326 menu_items_[index].wireless_path, &cellular); | 325 if (!cellular) { |
327 if (!cellular_exists) { | |
328 // If we are attempting to connect to a network that no longer exists, | 326 // If we are attempting to connect to a network that no longer exists, |
329 // display a notification. | 327 // display a notification. |
330 // TODO(stevenjb): Show notification. | 328 // TODO(stevenjb): Show notification. |
331 } else if (cellular.activation_state() != ACTIVATION_STATE_ACTIVATED) { | 329 } else if (cellular->activation_state() != ACTIVATION_STATE_ACTIVATED) { |
332 ActivateCellular(cellular); | 330 ActivateCellular(cellular); |
333 } else if (cellular.service_path() == | 331 } else if (cellular->service_path() == |
334 cros->cellular_network().service_path()) { | 332 cros->cellular_network()->service_path()) { |
335 // Show the config settings for the cellular network. | 333 // Show the config settings for the cellular network. |
336 ShowCellular(cellular, false); | 334 ShowCellular(cellular, false); |
337 } else { | 335 } else { |
338 ConnectToNetworkAt(index, std::string(), std::string(), -1); | 336 ConnectToNetworkAt(index, std::string(), std::string(), -1); |
339 } | 337 } |
340 } | 338 } |
341 } | 339 } |
342 | 340 |
343 void NetworkMenu::SetFirstLevelMenuWidth(int width) { | 341 void NetworkMenu::SetFirstLevelMenuWidth(int width) { |
344 min_width_ = width; | 342 min_width_ = width; |
(...skipping 15 matching lines...) Expand all Loading... |
360 // static | 358 // static |
361 SkBitmap NetworkMenu::IconForNetworkStrength(int strength, bool black) { | 359 SkBitmap NetworkMenu::IconForNetworkStrength(int strength, bool black) { |
362 // Compose wifi icon by superimposing various icons. | 360 // Compose wifi icon by superimposing various icons. |
363 int index = static_cast<int>(strength / 100.0 * | 361 int index = static_cast<int>(strength / 100.0 * |
364 nextafter(static_cast<float>(kNumWifiImages), 0)); | 362 nextafter(static_cast<float>(kNumWifiImages), 0)); |
365 index = std::max(std::min(index, kNumWifiImages - 1), 0); | 363 index = std::max(std::min(index, kNumWifiImages - 1), 0); |
366 const int* images = black ? kBarsImagesBlack : kBarsImages; | 364 const int* images = black ? kBarsImagesBlack : kBarsImages; |
367 return *ResourceBundle::GetSharedInstance().GetBitmapNamed(images[index]); | 365 return *ResourceBundle::GetSharedInstance().GetBitmapNamed(images[index]); |
368 } | 366 } |
369 | 367 |
370 SkBitmap NetworkMenu::IconForNetworkStrength(CellularNetwork cellular) { | 368 SkBitmap NetworkMenu::IconForNetworkStrength(const CellularNetwork* cellular) { |
| 369 DCHECK(cellular); |
371 // Compose wifi icon by superimposing various icons. | 370 // Compose wifi icon by superimposing various icons. |
372 int index = static_cast<int>(cellular.strength() / 100.0 * | 371 int index = static_cast<int>(cellular->strength() / 100.0 * |
373 nextafter(static_cast<float>(kNumWifiImages), 0)); | 372 nextafter(static_cast<float>(kNumWifiImages), 0)); |
374 index = std::max(std::min(index, kNumWifiImages - 1), 0); | 373 index = std::max(std::min(index, kNumWifiImages - 1), 0); |
375 const int* images = kBarsImages; | 374 const int* images = kBarsImages; |
376 switch (cellular.data_left()) { | 375 switch (cellular->data_left()) { |
377 case CellularNetwork::DATA_NONE: | 376 case CellularNetwork::DATA_NONE: |
378 case CellularNetwork::DATA_VERY_LOW: | 377 case CellularNetwork::DATA_VERY_LOW: |
379 images = kBarsImagesVLowData; | 378 images = kBarsImagesVLowData; |
380 break; | 379 break; |
381 case CellularNetwork::DATA_LOW: | 380 case CellularNetwork::DATA_LOW: |
382 images = kBarsImagesLowData; | 381 images = kBarsImagesLowData; |
383 break; | 382 break; |
384 case CellularNetwork::DATA_NORMAL: | 383 case CellularNetwork::DATA_NORMAL: |
385 images = kBarsImages; | 384 images = kBarsImages; |
386 break; | 385 break; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 flag |= FLAG_ASSOCIATED; | 454 flag |= FLAG_ASSOCIATED; |
456 menu_items_.push_back( | 455 menu_items_.push_back( |
457 MenuItem(menus::MenuModel::TYPE_COMMAND, label, | 456 MenuItem(menus::MenuModel::TYPE_COMMAND, label, |
458 IconForDisplay(icon, badge), std::string(), flag)); | 457 IconForDisplay(icon, badge), std::string(), flag)); |
459 } | 458 } |
460 | 459 |
461 // Wifi Networks | 460 // Wifi Networks |
462 bool wifi_available = cros->wifi_available(); | 461 bool wifi_available = cros->wifi_available(); |
463 if (wifi_available) { | 462 if (wifi_available) { |
464 const WifiNetworkVector& wifi_networks = cros->wifi_networks(); | 463 const WifiNetworkVector& wifi_networks = cros->wifi_networks(); |
465 const WifiNetwork& active_wifi = cros->wifi_network(); | 464 const WifiNetwork* active_wifi = cros->wifi_network(); |
466 | 465 |
467 if (wifi_networks.size() > 0) { | 466 if (wifi_networks.size() > 0) { |
468 no_networks = false; | 467 no_networks = false; |
469 // Separator | 468 // Separator |
470 menu_items_.push_back(MenuItem()); | 469 menu_items_.push_back(MenuItem()); |
471 } | 470 } |
472 // List Wifi networks. | 471 // List Wifi networks. |
473 for (size_t i = 0; i < wifi_networks.size(); ++i) { | 472 for (size_t i = 0; i < wifi_networks.size(); ++i) { |
474 if (wifi_networks[i].connecting()) { | 473 if (wifi_networks[i]->connecting()) { |
475 label = l10n_util::GetStringFUTF16( | 474 label = l10n_util::GetStringFUTF16( |
476 IDS_STATUSBAR_NETWORK_DEVICE_STATUS, | 475 IDS_STATUSBAR_NETWORK_DEVICE_STATUS, |
477 ASCIIToUTF16(wifi_networks[i].name()), | 476 ASCIIToUTF16(wifi_networks[i]->name()), |
478 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_CONNECTING)); | 477 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_CONNECTING)); |
479 } else { | 478 } else { |
480 label = ASCIIToUTF16(wifi_networks[i].name()); | 479 label = ASCIIToUTF16(wifi_networks[i]->name()); |
481 } | 480 } |
482 SkBitmap icon = IconForNetworkStrength(wifi_networks[i].strength(), true); | 481 SkBitmap icon = IconForNetworkStrength(wifi_networks[i]->strength(), |
483 SkBitmap badge = wifi_networks[i].encrypted() ? | 482 true); |
| 483 SkBitmap badge = wifi_networks[i]->encrypted() ? |
484 *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_SECURE) : SkBitmap(); | 484 *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_SECURE) : SkBitmap(); |
485 int flag = FLAG_WIFI; | 485 int flag = FLAG_WIFI; |
486 if (wifi_networks[i].service_path() == active_wifi.service_path()) | 486 if (active_wifi |
| 487 && wifi_networks[i]->service_path() == active_wifi->service_path()) |
487 flag |= FLAG_ASSOCIATED; | 488 flag |= FLAG_ASSOCIATED; |
488 menu_items_.push_back( | 489 menu_items_.push_back( |
489 MenuItem(menus::MenuModel::TYPE_COMMAND, label, | 490 MenuItem(menus::MenuModel::TYPE_COMMAND, label, |
490 IconForDisplay(icon, badge), | 491 IconForDisplay(icon, badge), |
491 wifi_networks[i].service_path(), flag)); | 492 wifi_networks[i]->service_path(), flag)); |
492 } | 493 } |
493 } | 494 } |
494 | 495 |
495 // Cellular Networks | 496 // Cellular Networks |
496 bool cellular_available = cros->cellular_available(); | 497 bool cellular_available = cros->cellular_available(); |
497 if (cellular_available) { | 498 if (cellular_available) { |
498 const CellularNetworkVector& cell_networks = cros->cellular_networks(); | 499 const CellularNetworkVector& cell_networks = cros->cellular_networks(); |
499 const CellularNetwork& active_cellular = cros->cellular_network(); | 500 const CellularNetwork* active_cellular = cros->cellular_network(); |
500 | 501 |
501 if (cell_networks.size() > 0) { | 502 if (cell_networks.size() > 0) { |
502 no_networks = false; | 503 no_networks = false; |
503 // Separator | 504 // Separator |
504 menu_items_.push_back(MenuItem()); | 505 menu_items_.push_back(MenuItem()); |
505 } | 506 } |
506 // List Cellular networks. | 507 // List Cellular networks. |
507 for (size_t i = 0; i < cell_networks.size(); ++i) { | 508 for (size_t i = 0; i < cell_networks.size(); ++i) { |
508 chromeos::ActivationState activation_state = | 509 chromeos::ActivationState activation_state = |
509 cell_networks[i].activation_state(); | 510 cell_networks[i]->activation_state(); |
510 if (activation_state == ACTIVATION_STATE_NOT_ACTIVATED) { | 511 if (activation_state == ACTIVATION_STATE_NOT_ACTIVATED) { |
511 label = l10n_util::GetStringFUTF16( | 512 label = l10n_util::GetStringFUTF16( |
512 IDS_STATUSBAR_NETWORK_DEVICE_ACTIVATE, | 513 IDS_STATUSBAR_NETWORK_DEVICE_ACTIVATE, |
513 ASCIIToUTF16(cell_networks[i].name())); | 514 ASCIIToUTF16(cell_networks[i]->name())); |
514 } else if (activation_state == ACTIVATION_STATE_PARTIALLY_ACTIVATED || | 515 } else if (activation_state == ACTIVATION_STATE_PARTIALLY_ACTIVATED || |
515 activation_state == ACTIVATION_STATE_ACTIVATING) { | 516 activation_state == ACTIVATION_STATE_ACTIVATING) { |
516 label = l10n_util::GetStringFUTF16( | 517 label = l10n_util::GetStringFUTF16( |
517 IDS_STATUSBAR_NETWORK_DEVICE_STATUS, | 518 IDS_STATUSBAR_NETWORK_DEVICE_STATUS, |
518 ASCIIToUTF16(cell_networks[i].name()), | 519 ASCIIToUTF16(cell_networks[i]->name()), |
519 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ACTIVATING)); | 520 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ACTIVATING)); |
520 } else if (cell_networks[i].connecting()) { | 521 } else if (cell_networks[i]->connecting()) { |
521 label = l10n_util::GetStringFUTF16( | 522 label = l10n_util::GetStringFUTF16( |
522 IDS_STATUSBAR_NETWORK_DEVICE_STATUS, | 523 IDS_STATUSBAR_NETWORK_DEVICE_STATUS, |
523 ASCIIToUTF16(cell_networks[i].name()), | 524 ASCIIToUTF16(cell_networks[i]->name()), |
524 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_CONNECTING)); | 525 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_CONNECTING)); |
525 } else { | 526 } else { |
526 label = ASCIIToUTF16(cell_networks[i].name()); | 527 label = ASCIIToUTF16(cell_networks[i]->name()); |
527 } | 528 } |
528 SkBitmap icon = IconForNetworkStrength(cell_networks[i].strength(), true); | 529 SkBitmap icon = IconForNetworkStrength(cell_networks[i]->strength(), |
| 530 true); |
529 // TODO(chocobo): Check cellular network 3g/edge. | 531 // TODO(chocobo): Check cellular network 3g/edge. |
530 SkBitmap badge = *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_3G); | 532 SkBitmap badge = *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_3G); |
531 // SkBitmap badge = *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_EDGE); | 533 // SkBitmap badge = *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_EDGE); |
532 int flag = FLAG_CELLULAR; | 534 int flag = FLAG_CELLULAR; |
533 if (cell_networks[i].service_path() == active_cellular.service_path() && | 535 if (active_cellular && |
534 (cell_networks[i].connecting() || cell_networks[i].connected())) | 536 cell_networks[i]->service_path() == |
| 537 active_cellular->service_path() && |
| 538 (cell_networks[i]->connecting() || cell_networks[i]->connected())) |
535 flag |= FLAG_ASSOCIATED; | 539 flag |= FLAG_ASSOCIATED; |
536 menu_items_.push_back( | 540 menu_items_.push_back( |
537 MenuItem(menus::MenuModel::TYPE_COMMAND, label, | 541 MenuItem(menus::MenuModel::TYPE_COMMAND, label, |
538 IconForDisplay(icon, badge), | 542 IconForDisplay(icon, badge), |
539 cell_networks[i].service_path(), flag)); | 543 cell_networks[i]->service_path(), flag)); |
540 } | 544 } |
541 } | 545 } |
542 | 546 |
543 // No networks available message. | 547 // No networks available message. |
544 if (no_networks) { | 548 if (no_networks) { |
545 label = l10n_util::GetStringFUTF16(IDS_STATUSBAR_NETWORK_MENU_ITEM_INDENT, | 549 label = l10n_util::GetStringFUTF16(IDS_STATUSBAR_NETWORK_MENU_ITEM_INDENT, |
546 l10n_util::GetStringUTF16(IDS_STATUSBAR_NO_NETWORKS_MESSAGE)); | 550 l10n_util::GetStringUTF16(IDS_STATUSBAR_NO_NETWORKS_MESSAGE)); |
547 menu_items_.push_back(MenuItem(menus::MenuModel::TYPE_COMMAND, label, | 551 menu_items_.push_back(MenuItem(menus::MenuModel::TYPE_COMMAND, label, |
548 SkBitmap(), std::string(), FLAG_DISABLED)); | 552 SkBitmap(), std::string(), FLAG_DISABLED)); |
549 } | 553 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 // Separator. | 601 // Separator. |
598 menu_items_.push_back(MenuItem()); | 602 menu_items_.push_back(MenuItem()); |
599 | 603 |
600 label = | 604 label = |
601 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_OPEN_OPTIONS_DIALOG); | 605 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_OPEN_OPTIONS_DIALOG); |
602 menu_items_.push_back(MenuItem(menus::MenuModel::TYPE_COMMAND, label, | 606 menu_items_.push_back(MenuItem(menus::MenuModel::TYPE_COMMAND, label, |
603 SkBitmap(), std::string(), FLAG_OPTIONS)); | 607 SkBitmap(), std::string(), FLAG_OPTIONS)); |
604 } | 608 } |
605 } | 609 } |
606 | 610 |
607 void NetworkMenu::ShowTabbedNetworkSettings(const Network& network) const { | 611 void NetworkMenu::ShowTabbedNetworkSettings(const Network* network) const { |
| 612 DCHECK(network); |
608 Browser* browser = BrowserList::GetLastActive(); | 613 Browser* browser = BrowserList::GetLastActive(); |
609 if (!browser) | 614 if (!browser) |
610 return; | 615 return; |
611 std::string page = StringPrintf("%s?servicePath=%s&networkType=%d", | 616 std::string page = StringPrintf("%s?servicePath=%s&networkType=%d", |
612 chrome::kInternetOptionsSubPage, | 617 chrome::kInternetOptionsSubPage, |
613 EscapeUrlEncodedData(network.service_path()).c_str(), | 618 EscapeUrlEncodedData(network->service_path()).c_str(), |
614 network.type()); | 619 network->type()); |
615 browser->ShowOptionsTab(page); | 620 browser->ShowOptionsTab(page); |
616 } | 621 } |
617 | 622 |
618 // TODO(stevenjb): deprecate this once we've committed to tabbed settings | 623 // TODO(stevenjb): deprecate this once we've committed to tabbed settings |
619 // and the embedded menu UI (and fully deprecated NetworkConfigView). | 624 // and the embedded menu UI (and fully deprecated NetworkConfigView). |
620 // Meanwhile, if MenuUI::IsEnabled() is true, always show the settings UI, | 625 // Meanwhile, if MenuUI::IsEnabled() is true, always show the settings UI, |
621 // otherwise show NetworkConfigView only to get passwords when not connected. | 626 // otherwise show NetworkConfigView only to get passwords when not connected. |
622 void NetworkMenu::ShowNetworkConfigView(NetworkConfigView* view, | 627 void NetworkMenu::ShowNetworkConfigView(NetworkConfigView* view, |
623 bool focus_login) const { | 628 bool focus_login) const { |
624 view->set_browser_mode(IsBrowserMode()); | 629 view->set_browser_mode(IsBrowserMode()); |
625 views::Window* window = browser::CreateViewsWindow( | 630 views::Window* window = browser::CreateViewsWindow( |
626 GetNativeWindow(), gfx::Rect(), view); | 631 GetNativeWindow(), gfx::Rect(), view); |
627 window->SetIsAlwaysOnTop(true); | 632 window->SetIsAlwaysOnTop(true); |
628 window->Show(); | 633 window->Show(); |
629 if (focus_login) | 634 if (focus_login) |
630 view->SetLoginTextfieldFocus(); | 635 view->SetLoginTextfieldFocus(); |
631 } | 636 } |
632 | 637 |
633 void NetworkMenu::ShowWifi(const WifiNetwork& wifi, bool focus_login) const{ | 638 void NetworkMenu::ShowWifi(const WifiNetwork* wifi, bool focus_login) const{ |
| 639 DCHECK(wifi); |
634 if (use_settings_ui_ && | 640 if (use_settings_ui_ && |
635 (MenuUI::IsEnabled() || wifi.connected() || wifi.connecting())) { | 641 (MenuUI::IsEnabled() || wifi->connected() || wifi->connecting())) { |
636 ShowTabbedNetworkSettings(wifi); | 642 ShowTabbedNetworkSettings(wifi); |
637 } else { | 643 } else { |
638 ShowNetworkConfigView(new NetworkConfigView(wifi, true), focus_login); | 644 ShowNetworkConfigView(new NetworkConfigView(wifi, true), focus_login); |
639 } | 645 } |
640 } | 646 } |
641 | 647 |
642 void NetworkMenu::ShowCellular(const CellularNetwork& cellular, | 648 void NetworkMenu::ShowCellular(const CellularNetwork* cellular, |
643 bool focus_login) const { | 649 bool focus_login) const { |
| 650 DCHECK(cellular); |
644 if (use_settings_ui_ && | 651 if (use_settings_ui_ && |
645 (MenuUI::IsEnabled() || cellular.connected() || cellular.connecting())) { | 652 (MenuUI::IsEnabled() || cellular->connected() || |
| 653 cellular->connecting())) { |
646 ShowTabbedNetworkSettings(cellular); | 654 ShowTabbedNetworkSettings(cellular); |
647 } else { | 655 } else { |
648 ShowNetworkConfigView(new NetworkConfigView(cellular), focus_login); | 656 ShowNetworkConfigView(new NetworkConfigView(cellular), focus_login); |
649 } | 657 } |
650 } | 658 } |
651 | 659 |
652 void NetworkMenu::ActivateCellular(const CellularNetwork& cellular) const { | 660 void NetworkMenu::ActivateCellular(const CellularNetwork* cellular) const { |
| 661 DCHECK(cellular); |
653 Browser* browser = BrowserList::GetLastActive(); | 662 Browser* browser = BrowserList::GetLastActive(); |
654 // TODO?(stevenjb) : specify which service to activate. | 663 // TODO?(stevenjb) : specify which service to activate. |
655 browser->ShowSingletonTab(GURL(chrome::kChromeUIMobileSetupURL)); | 664 browser->ShowSingletonTab(GURL(chrome::kChromeUIMobileSetupURL)); |
656 } | 665 } |
657 | 666 |
658 void NetworkMenu::ShowEthernet(const EthernetNetwork& ethernet) const { | 667 void NetworkMenu::ShowEthernet(const EthernetNetwork* ethernet) const { |
| 668 DCHECK(ethernet); |
659 if (use_settings_ui_ && | 669 if (use_settings_ui_ && |
660 (MenuUI::IsEnabled() || ethernet.connected() || ethernet.connecting())) { | 670 (MenuUI::IsEnabled() || ethernet->connected() || |
| 671 ethernet->connecting())) { |
661 ShowTabbedNetworkSettings(ethernet); | 672 ShowTabbedNetworkSettings(ethernet); |
662 } else { | 673 } else { |
663 ShowNetworkConfigView(new NetworkConfigView(ethernet), false); | 674 ShowNetworkConfigView(new NetworkConfigView(ethernet), false); |
664 } | 675 } |
665 } | 676 } |
666 | 677 |
667 void NetworkMenu::ShowOther() const { | 678 void NetworkMenu::ShowOther() const { |
668 if (use_settings_ui_ && MenuUI::IsEnabled()) { | 679 if (use_settings_ui_ && MenuUI::IsEnabled()) { |
669 Browser* browser = BrowserList::GetLastActive(); | 680 Browser* browser = BrowserList::GetLastActive(); |
670 if (browser) { | 681 if (browser) { |
671 std::string page = StringPrintf("%s?networkType=%d", | 682 std::string page = StringPrintf("%s?networkType=%d", |
672 chrome::kInternetOptionsSubPage, | 683 chrome::kInternetOptionsSubPage, |
673 chromeos::TYPE_WIFI); | 684 chromeos::TYPE_WIFI); |
674 browser->ShowOptionsTab(page); | 685 browser->ShowOptionsTab(page); |
675 } | 686 } |
676 } else { | 687 } else { |
677 const bool kFocusLogin = true; | 688 const bool kFocusLogin = true; |
678 ShowNetworkConfigView(new NetworkConfigView(), kFocusLogin); | 689 ShowNetworkConfigView(new NetworkConfigView(), kFocusLogin); |
679 } | 690 } |
680 } | 691 } |
681 | 692 |
682 } // namespace chromeos | 693 } // namespace chromeos |
OLD | NEW |