Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(323)

Side by Side Diff: chrome/browser/chromeos/status/network_menu.cc

Issue 3796008: Fixed some logic bugs in the Network Menu DOM UI (7343) (Closed)
Patch Set: Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/chromeos/status/network_menu.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 } else { 89 } else {
90 info->status = kNetworkStatusDisconnected; 90 info->status = kNetworkStatusDisconnected;
91 info->message = l10n_util::GetStringUTF8( 91 info->message = l10n_util::GetStringUTF8(
92 IDS_STATUSBAR_NETWORK_DEVICE_DISCONNECTED); 92 IDS_STATUSBAR_NETWORK_DEVICE_DISCONNECTED);
93 } 93 }
94 } else { 94 } else {
95 info->status = kNetworkStatusDisconnected; 95 info->status = kNetworkStatusDisconnected;
96 info->message = l10n_util::GetStringUTF8( 96 info->message = l10n_util::GetStringUTF8(
97 IDS_STATUSBAR_NETWORK_DEVICE_DISCONNECTED); 97 IDS_STATUSBAR_NETWORK_DEVICE_DISCONNECTED);
98 } 98 }
99 if (wifi.encrypted()) {
100 if (wifi.IsCertificateLoaded() ||
101 wifi.encryption() == SECURITY_8021X) {
102 info->need_passphrase = false;
103 } else {
104 info->need_passphrase = true;
105 }
106 } else {
107 info->need_passphrase = false;
108 }
99 info->ip_address = wifi.ip_address(); 109 info->ip_address = wifi.ip_address();
100 info->need_passphrase = wifi.encrypted();
101 info->remembered = wifi.favorite(); 110 info->remembered = wifi.favorite();
102 } else { 111 } else {
103 res = false; // Network not found, hide entry. 112 res = false; // Network not found, hide entry.
104 } 113 }
105 } else if (flags & FLAG_CELLULAR) { 114 } else if (flags & FLAG_CELLULAR) {
106 CellularNetwork cellular; 115 CellularNetwork cellular;
107 bool found = cros->FindCellularNetworkByPath( 116 bool found = cros->FindCellularNetworkByPath(
108 menu_items_[index].wireless_path, &cellular); 117 menu_items_[index].wireless_path, &cellular);
109 if (found) { 118 if (found) {
110 info->network_type = kNetworkTypeCellular; 119 info->network_type = kNetworkTypeCellular;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 IDS_STATUSBAR_NETWORK_DEVICE_DISCONNECTED); 153 IDS_STATUSBAR_NETWORK_DEVICE_DISCONNECTED);
145 info->network_type = kNetworkTypeOther; 154 info->network_type = kNetworkTypeOther;
146 info->need_passphrase = true; 155 info->need_passphrase = true;
147 info->remembered = true; 156 info->remembered = true;
148 } else { 157 } else {
149 // Not a network, e.g options, separator. 158 // Not a network, e.g options, separator.
150 } 159 }
151 return res; 160 return res;
152 } 161 }
153 162
154 void NetworkMenu::ConnectToNetworkAt(int index, 163 bool NetworkMenu::ConnectToNetworkAt(int index,
155 const std::string& passphrase, 164 const std::string& passphrase,
156 const std::string& identity) const { 165 const std::string& ssid,
166 int remember) const {
157 int flags = menu_items_[index].flags; 167 int flags = menu_items_[index].flags;
158 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); 168 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary();
159 if (flags & FLAG_WIFI) { 169 if (flags & FLAG_WIFI) {
160 WifiNetwork wifi; 170 WifiNetwork wifi;
161 bool found = cros->FindWifiNetworkByPath( 171 bool found = cros->FindWifiNetworkByPath(
162 menu_items_[index].wireless_path, &wifi); 172 menu_items_[index].wireless_path, &wifi);
163 if (found) { 173 if (found) {
164 // Connect or reconnect. 174 // Connect or reconnect.
175 if (remember >= 0)
176 wifi.set_favorite(remember ? true : false);
165 if (wifi.encrypted()) { 177 if (wifi.encrypted()) {
166 if (wifi.IsCertificateLoaded()) { 178 if (wifi.IsCertificateLoaded()) {
167 cros->ConnectToWifiNetwork(wifi, std::string(), 179 cros->ConnectToWifiNetwork(wifi, std::string(), std::string(),
168 std::string(), wifi.cert_path()); 180 wifi.cert_path());
181 } else if (wifi.encryption() == SECURITY_8021X) {
182 // Show the wifi settings/dialog to load/select a certificate.
183 ShowWifi(wifi, true);
169 } else { 184 } else {
170 // TODO(stevenjb): use passphrase/identity once provided. 185 cros->ConnectToWifiNetwork(wifi, passphrase, std::string(),
171 // cros->ConnectToWifiNetwork(wifi, passphrase, 186 std::string());
172 // identity, menu_items[index].path);
173 const bool kFocusLogin = true;
174 ShowNetworkConfigView(new NetworkConfigView(wifi, true), kFocusLogin);
175 } 187 }
176 } else { 188 } else {
177 cros->ConnectToWifiNetwork(wifi, std::string(), 189 cros->ConnectToWifiNetwork(wifi, std::string(), std::string(),
178 std::string(), std::string()); 190 std::string());
179 } 191 }
180 } 192 }
181 } else if (flags & FLAG_CELLULAR) { 193 } else if (flags & FLAG_CELLULAR) {
182 CellularNetwork cellular; 194 CellularNetwork cellular;
183 bool found = cros->FindCellularNetworkByPath( 195 bool found = cros->FindCellularNetworkByPath(
184 menu_items_[index].wireless_path, &cellular); 196 menu_items_[index].wireless_path, &cellular);
185 if (found) { 197 if (found) {
186 // Connect or reconnect. 198 // Connect or reconnect.
187 cros->ConnectToCellularNetwork(cellular); 199 cros->ConnectToCellularNetwork(cellular);
188 } 200 }
189 } else if (flags & FLAG_OTHER_NETWORK) { 201 } else if (flags & FLAG_OTHER_NETWORK) {
190 const bool kFocusLogin = true; 202 bool favorite = remember == 0 ? false : true; // default is true
191 ShowNetworkConfigView(new NetworkConfigView(), kFocusLogin); 203 cros->ConnectToWifiNetwork(ssid, passphrase, std::string(), std::string(),
204 favorite);
192 } 205 }
206 return true;
193 } 207 }
194 208
195 //////////////////////////////////////////////////////////////////////////////// 209 ////////////////////////////////////////////////////////////////////////////////
196 // NetworkMenu, menus::MenuModel implementation: 210 // NetworkMenu, menus::MenuModel implementation:
197 211
198 int NetworkMenu::GetItemCount() const { 212 int NetworkMenu::GetItemCount() const {
199 return static_cast<int>(menu_items_.size()); 213 return static_cast<int>(menu_items_.size());
200 } 214 }
201 215
202 menus::MenuModel::ItemType NetworkMenu::GetTypeAt(int index) const { 216 menus::MenuModel::ItemType NetworkMenu::GetTypeAt(int index) const {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 OpenButtonOptions(); 255 OpenButtonOptions();
242 } else if (flags & FLAG_TOGGLE_ETHERNET) { 256 } else if (flags & FLAG_TOGGLE_ETHERNET) {
243 cros->EnableEthernetNetworkDevice(!cros->ethernet_enabled()); 257 cros->EnableEthernetNetworkDevice(!cros->ethernet_enabled());
244 } else if (flags & FLAG_TOGGLE_WIFI) { 258 } else if (flags & FLAG_TOGGLE_WIFI) {
245 cros->EnableWifiNetworkDevice(!cros->wifi_enabled()); 259 cros->EnableWifiNetworkDevice(!cros->wifi_enabled());
246 } else if (flags & FLAG_TOGGLE_CELLULAR) { 260 } else if (flags & FLAG_TOGGLE_CELLULAR) {
247 cros->EnableCellularNetworkDevice(!cros->cellular_enabled()); 261 cros->EnableCellularNetworkDevice(!cros->cellular_enabled());
248 } else if (flags & FLAG_TOGGLE_OFFLINE) { 262 } else if (flags & FLAG_TOGGLE_OFFLINE) {
249 cros->EnableOfflineMode(!cros->offline_mode()); 263 cros->EnableOfflineMode(!cros->offline_mode());
250 } else if (flags & FLAG_OTHER_NETWORK) { 264 } else if (flags & FLAG_OTHER_NETWORK) {
251 const bool kFocusLogin = true; 265 ShowOther();
252 ShowNetworkConfigView(new NetworkConfigView(), kFocusLogin);
253 } else if (flags & FLAG_ETHERNET) { 266 } else if (flags & FLAG_ETHERNET) {
254 if (cros->ethernet_connected()) { 267 if (cros->ethernet_connected()) {
255 if (CommandLine::ForCurrentProcess()->HasSwitch( 268 ShowEthernet(cros->ethernet_network());
256 switches::kEnableTabbedOptions)) {
257 ShowTabbedNetworkSettings(cros->ethernet_network());
258 } else {
259 ShowNetworkConfigView(
260 new NetworkConfigView(cros->ethernet_network()), false);
261 }
262 } 269 }
263 } else if (flags & FLAG_WIFI) { 270 } else if (flags & FLAG_WIFI) {
264 WifiNetwork wifi; 271 WifiNetwork wifi;
265 bool wifi_exists = cros->FindWifiNetworkByPath( 272 bool wifi_exists = cros->FindWifiNetworkByPath(
266 menu_items_[index].wireless_path, &wifi); 273 menu_items_[index].wireless_path, &wifi);
267 if (!wifi_exists) { 274 if (!wifi_exists) {
268 // If we are attempting to connect to a network that no longer exists, 275 // If we are attempting to connect to a network that no longer exists,
269 // display a notification. 276 // display a notification.
270 // TODO(stevenjb): Show notification. 277 // TODO(stevenjb): Show notification.
271 } else if (wifi.name() == cros->wifi_name()) { 278 } else if (wifi.name() == cros->wifi_name()) {
272 if (cros->wifi_connected()) { 279 // Show the config settings for the active network.
273 // If we are already connected, show the config settings. 280 ShowWifi(wifi, false);
274 if (CommandLine::ForCurrentProcess()->HasSwitch(
275 switches::kEnableTabbedOptions)) {
276 ShowTabbedNetworkSettings(wifi);
277 } else {
278 ShowNetworkConfigView(new NetworkConfigView(wifi, false), false);
279 }
280 } else {
281 // TODO(stevenjb): Connection in progress. Show dialog?
282 }
283 } else { 281 } else {
284 // If wifi network is not encrypted, then directly connect. 282 ConnectToNetworkAt(index, std::string(), std::string(), -1);
285 // Otherwise, open the password dialog window.
286 if (!wifi.encrypted()) {
287 cros->ConnectToWifiNetwork(wifi, std::string(),
288 std::string(), std::string());
289 } else {
290 const bool kFocusLogin = true;
291 ShowNetworkConfigView(new NetworkConfigView(wifi, true), kFocusLogin);
292 }
293 } 283 }
294 } else if (flags & FLAG_CELLULAR) { 284 } else if (flags & FLAG_CELLULAR) {
295 CellularNetwork cellular; 285 CellularNetwork cellular;
296 bool cellular_exists = cros->FindCellularNetworkByPath( 286 bool cellular_exists = cros->FindCellularNetworkByPath(
297 menu_items_[index].wireless_path, &cellular); 287 menu_items_[index].wireless_path, &cellular);
298
299 if (!cellular_exists) { 288 if (!cellular_exists) {
300 // If we are attempting to connect to a network that no longer exists, 289 // If we are attempting to connect to a network that no longer exists,
301 // display a notification. 290 // display a notification.
302 // TODO(stevenjb): Show notification. 291 // TODO(stevenjb): Show notification.
303 } else if (cellular.name() == cros->cellular_name()) { 292 } else if (cellular.name() == cros->cellular_name()) {
304 // If clicked on a network that we are already connected to or we are 293 // Show the config settings for the cellular network.
305 // currently trying to connect to, then open config dialog. 294 ShowCellular(cellular, false);
306 if (cros->cellular_connected()) {
307 if (CommandLine::ForCurrentProcess()->HasSwitch(
308 switches::kEnableTabbedOptions)) {
309 ShowTabbedNetworkSettings(cellular);
310 } else {
311 ShowNetworkConfigView(new NetworkConfigView(cellular), false);
312 }
313 } else {
314 // TODO(stevenjb): Connection in progress. Show dialog?
315 }
316 } else { 295 } else {
317 cros->ConnectToCellularNetwork(cellular); 296 ConnectToNetworkAt(index, std::string(), std::string(), -1);
318 } 297 }
319 } 298 }
320 } 299 }
321 300
322 void NetworkMenu::SetFirstLevelMenuWidth(int width) { 301 void NetworkMenu::SetFirstLevelMenuWidth(int width) {
323 min_width_ = width; 302 min_width_ = width;
324 // This actually has no effect since menu is rebuilt before showing. 303 // This actually has no effect since menu is rebuilt before showing.
325 network_menu_->SetMinimumWidth(width); 304 network_menu_->SetMinimumWidth(width);
326 } 305 }
327 306
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 // Network settings. 497 // Network settings.
519 if (ShouldOpenButtonOptions()) { 498 if (ShouldOpenButtonOptions()) {
520 label = 499 label =
521 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_OPEN_OPTIONS_DIALOG); 500 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_OPEN_OPTIONS_DIALOG);
522 menu_items_.push_back(MenuItem(menus::MenuModel::TYPE_COMMAND, label, 501 menu_items_.push_back(MenuItem(menus::MenuModel::TYPE_COMMAND, label,
523 SkBitmap(), std::string(), FLAG_OPTIONS)); 502 SkBitmap(), std::string(), FLAG_OPTIONS));
524 } 503 }
525 } 504 }
526 } 505 }
527 506
528 void NetworkMenu::ShowTabbedNetworkSettings(const Network& network) { 507 void NetworkMenu::ShowTabbedNetworkSettings(const Network& network) const {
529 Browser* browser = BrowserList::GetLastActive(); 508 Browser* browser = BrowserList::GetLastActive();
530 if (!browser) 509 if (!browser)
531 return; 510 return;
532 std::string page = StringPrintf("%s?servicePath=%s&networkType=%d", 511 std::string page = StringPrintf("%s?servicePath=%s&networkType=%d",
533 chrome::kInternetOptionsSubPage, 512 chrome::kInternetOptionsSubPage,
534 EscapeUrlEncodedData(network.service_path()).c_str(), 513 EscapeUrlEncodedData(network.service_path()).c_str(),
535 network.type()); 514 network.type());
536 browser->ShowOptionsTab(page); 515 browser->ShowOptionsTab(page);
537 } 516 }
538 517
539 // TODO(stevenjb): deprecate this once all of the UI is embedded in the menu. 518 // TODO(stevenjb): deprecate this once we've committed to the embedded
519 // menu UI and fully deprecated NetworkConfigView.
540 void NetworkMenu::ShowNetworkConfigView(NetworkConfigView* view, 520 void NetworkMenu::ShowNetworkConfigView(NetworkConfigView* view,
541 bool focus_login) const { 521 bool focus_login) const {
542 view->set_browser_mode(IsBrowserMode()); 522 view->set_browser_mode(IsBrowserMode());
543 views::Window* window = browser::CreateViewsWindow( 523 views::Window* window = browser::CreateViewsWindow(
544 GetNativeWindow(), gfx::Rect(), view); 524 GetNativeWindow(), gfx::Rect(), view);
545 window->SetIsAlwaysOnTop(true); 525 window->SetIsAlwaysOnTop(true);
546 window->Show(); 526 window->Show();
547 if (focus_login) 527 if (focus_login)
548 view->SetLoginTextfieldFocus(); 528 view->SetLoginTextfieldFocus();
549 } 529 }
550 530
531 void NetworkMenu::ShowWifi(const WifiNetwork& wifi, bool focus_login) const{
532 if (CommandLine::ForCurrentProcess()->HasSwitch(
533 switches::kEnableTabbedOptions)) {
534 ShowTabbedNetworkSettings(wifi);
535 } else {
536 ShowNetworkConfigView(new NetworkConfigView(wifi, true), focus_login);
537 }
538 }
539
540 void NetworkMenu::ShowCellular(const CellularNetwork& cellular,
541 bool focus_login) const {
542 if (CommandLine::ForCurrentProcess()->HasSwitch(
543 switches::kEnableTabbedOptions)) {
544 ShowTabbedNetworkSettings(cellular);
545 } else {
546 ShowNetworkConfigView(new NetworkConfigView(cellular), focus_login);
547 }
548 }
549
550 void NetworkMenu::ShowEthernet(const EthernetNetwork& ethernet) const {
551 if (CommandLine::ForCurrentProcess()->HasSwitch(
552 switches::kEnableTabbedOptions)) {
553 ShowTabbedNetworkSettings(ethernet);
554 } else {
555 ShowNetworkConfigView(new NetworkConfigView(ethernet), false);
556 }
557 }
558
559 void NetworkMenu::ShowOther() const {
560 if (CommandLine::ForCurrentProcess()->HasSwitch(
561 switches::kEnableTabbedOptions)) {
562 Browser* browser = BrowserList::GetLastActive();
563 if (browser) {
564 std::string page = StringPrintf("%s?networkType=%d",
565 chrome::kInternetOptionsSubPage,
566 chromeos::TYPE_WIFI);
567 browser->ShowOptionsTab(page);
568 }
569 } else {
570 const bool kFocusLogin = true;
571 ShowNetworkConfigView(new NetworkConfigView(), kFocusLogin);
572 }
573 }
574
551 } // namespace chromeos 575 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/status/network_menu.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698