| 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" |
| 10 #include "base/stringprintf.h" |
| 9 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/browser.h" |
| 13 #include "chrome/browser/browser_list.h" |
| 10 #include "chrome/browser/chromeos/cros/cros_library.h" | 14 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 15 #include "chrome/common/chrome_switches.h" |
| 16 #include "chrome/common/url_constants.h" |
| 11 #include "gfx/canvas_skia.h" | 17 #include "gfx/canvas_skia.h" |
| 12 #include "gfx/skbitmap_operations.h" | 18 #include "gfx/skbitmap_operations.h" |
| 13 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
| 14 #include "grit/theme_resources.h" | 20 #include "grit/theme_resources.h" |
| 21 #include "net/base/escape.h" |
| 15 #include "views/window/window.h" | 22 #include "views/window/window.h" |
| 16 | 23 |
| 17 namespace chromeos { | 24 namespace chromeos { |
| 18 | 25 |
| 19 //////////////////////////////////////////////////////////////////////////////// | 26 //////////////////////////////////////////////////////////////////////////////// |
| 20 // NetworkMenu | 27 // NetworkMenu |
| 21 | 28 |
| 22 // static | 29 // static |
| 23 const int NetworkMenu::kNumWifiImages = 9; | 30 const int NetworkMenu::kNumWifiImages = 9; |
| 24 | 31 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 *icon = menu_items_[index].icon; | 68 *icon = menu_items_[index].icon; |
| 62 return true; | 69 return true; |
| 63 } | 70 } |
| 64 return false; | 71 return false; |
| 65 } | 72 } |
| 66 | 73 |
| 67 bool NetworkMenu::IsEnabledAt(int index) const { | 74 bool NetworkMenu::IsEnabledAt(int index) const { |
| 68 return !(menu_items_[index].flags & FLAG_DISABLED); | 75 return !(menu_items_[index].flags & FLAG_DISABLED); |
| 69 } | 76 } |
| 70 | 77 |
| 78 void NetworkMenu::ShowTabbedNetworkSettings(const Network& network) { |
| 79 Browser* browser = BrowserList::GetLastActive(); |
| 80 if (!browser) |
| 81 return; |
| 82 std::string page = StringPrintf("%s?servicePath=%s&networkType=%d", |
| 83 chrome::kInternetOptionsSubPage, |
| 84 EscapeUrlEncodedData(network.service_path()).c_str(), |
| 85 network.type()); |
| 86 browser->ShowOptionsTab(page); |
| 87 } |
| 88 |
| 71 void NetworkMenu::ActivatedAt(int index) { | 89 void NetworkMenu::ActivatedAt(int index) { |
| 72 // When we are refreshing the menu, ignore menu item activation. | 90 // When we are refreshing the menu, ignore menu item activation. |
| 73 if (refreshing_menu_) | 91 if (refreshing_menu_) |
| 74 return; | 92 return; |
| 75 | 93 |
| 76 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | 94 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); |
| 77 int flags = menu_items_[index].flags; | 95 int flags = menu_items_[index].flags; |
| 78 if (flags & FLAG_OPTIONS) { | 96 if (flags & FLAG_OPTIONS) { |
| 79 OpenButtonOptions(); | 97 OpenButtonOptions(); |
| 80 } else if (flags & FLAG_TOGGLE_ETHERNET) { | 98 } else if (flags & FLAG_TOGGLE_ETHERNET) { |
| 81 cros->EnableEthernetNetworkDevice(!cros->ethernet_enabled()); | 99 cros->EnableEthernetNetworkDevice(!cros->ethernet_enabled()); |
| 82 } else if (flags & FLAG_TOGGLE_WIFI) { | 100 } else if (flags & FLAG_TOGGLE_WIFI) { |
| 83 cros->EnableWifiNetworkDevice(!cros->wifi_enabled()); | 101 cros->EnableWifiNetworkDevice(!cros->wifi_enabled()); |
| 84 } else if (flags & FLAG_TOGGLE_CELLULAR) { | 102 } else if (flags & FLAG_TOGGLE_CELLULAR) { |
| 85 cros->EnableCellularNetworkDevice(!cros->cellular_enabled()); | 103 cros->EnableCellularNetworkDevice(!cros->cellular_enabled()); |
| 86 } else if (flags & FLAG_TOGGLE_OFFLINE) { | 104 } else if (flags & FLAG_TOGGLE_OFFLINE) { |
| 87 cros->EnableOfflineMode(!cros->offline_mode()); | 105 cros->EnableOfflineMode(!cros->offline_mode()); |
| 88 } else if (flags & FLAG_OTHER_NETWORK) { | 106 } else if (flags & FLAG_OTHER_NETWORK) { |
| 89 NetworkConfigView* view = new NetworkConfigView(); | 107 NetworkConfigView* view = new NetworkConfigView(); |
| 90 view->set_browser_mode(IsBrowserMode()); | 108 view->set_browser_mode(IsBrowserMode()); |
| 91 views::Window* window = views::Window::CreateChromeWindow(GetNativeWindow(), | 109 views::Window* window = views::Window::CreateChromeWindow(GetNativeWindow(), |
| 92 gfx::Rect(), | 110 gfx::Rect(), |
| 93 view); | 111 view); |
| 94 window->SetIsAlwaysOnTop(true); | 112 window->SetIsAlwaysOnTop(true); |
| 95 window->Show(); | 113 window->Show(); |
| 96 view->SetLoginTextfieldFocus(); | 114 view->SetLoginTextfieldFocus(); |
| 97 } else if (flags & FLAG_ETHERNET) { | 115 } else if (flags & FLAG_ETHERNET) { |
| 98 if (cros->ethernet_connected()) { | 116 if (cros->ethernet_connected()) { |
| 99 NetworkConfigView* view = new NetworkConfigView(cros->ethernet_network()); | 117 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 100 view->set_browser_mode(IsBrowserMode()); | 118 switches::kEnableTabbedOptions)) { |
| 101 views::Window* window = views::Window::CreateChromeWindow( | 119 ShowTabbedNetworkSettings(cros->ethernet_network()); |
| 102 GetNativeWindow(), gfx::Rect(), view); | 120 } else { |
| 103 window->SetIsAlwaysOnTop(true); | 121 NetworkConfigView* view = |
| 104 window->Show(); | 122 new NetworkConfigView(cros->ethernet_network()); |
| 123 view->set_browser_mode(IsBrowserMode()); |
| 124 views::Window* window = views::Window::CreateChromeWindow( |
| 125 GetNativeWindow(), gfx::Rect(), view); |
| 126 window->SetIsAlwaysOnTop(true); |
| 127 window->Show(); |
| 128 } |
| 105 } | 129 } |
| 106 } else if (flags & FLAG_WIFI) { | 130 } else if (flags & FLAG_WIFI) { |
| 107 WifiNetwork wifi; | 131 WifiNetwork wifi; |
| 108 bool wifi_exists = cros->FindWifiNetworkByPath( | 132 bool wifi_exists = cros->FindWifiNetworkByPath( |
| 109 menu_items_[index].wireless_path, &wifi); | 133 menu_items_[index].wireless_path, &wifi); |
| 110 if (!wifi_exists) { | 134 if (!wifi_exists) { |
| 111 // If we are attempting to connect to a network that no longer exists, | 135 // If we are attempting to connect to a network that no longer exists, |
| 112 // display a notification. | 136 // display a notification. |
| 113 // TODO(stevenjb): Show notification. | 137 // TODO(stevenjb): Show notification. |
| 114 } else if (wifi.name() == cros->wifi_name()) { | 138 } else if (wifi.name() == cros->wifi_name()) { |
| 115 if (cros->wifi_connected()) { | 139 if (cros->wifi_connected()) { |
| 116 // If we are already connected, open the config dialog. | 140 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 117 NetworkConfigView* view = new NetworkConfigView(wifi, false); | 141 switches::kEnableTabbedOptions)) { |
| 118 view->set_browser_mode(IsBrowserMode()); | 142 ShowTabbedNetworkSettings(wifi); |
| 119 views::Window* window = views::Window::CreateChromeWindow( | 143 } else { |
| 120 GetNativeWindow(), gfx::Rect(), view); | 144 // If we are already connected, open the config dialog. |
| 121 window->SetIsAlwaysOnTop(true); | 145 NetworkConfigView* view = new NetworkConfigView(wifi, false); |
| 122 window->Show(); | 146 view->set_browser_mode(IsBrowserMode()); |
| 147 views::Window* window = views::Window::CreateChromeWindow( |
| 148 GetNativeWindow(), gfx::Rect(), view); |
| 149 window->SetIsAlwaysOnTop(true); |
| 150 window->Show(); |
| 151 } |
| 123 } else { | 152 } else { |
| 124 // TODO(stevenjb): Connection in progress. Show dialog? | 153 // TODO(stevenjb): Connection in progress. Show dialog? |
| 125 } | 154 } |
| 126 } else { | 155 } else { |
| 127 // If wifi network is not encrypted, then directly connect. | 156 // If wifi network is not encrypted, then directly connect. |
| 128 // Otherwise, we open password dialog window. | 157 // Otherwise, we open password dialog window. |
| 129 if (!wifi.encrypted()) { | 158 if (!wifi.encrypted()) { |
| 130 cros->ConnectToWifiNetwork(wifi, std::string(), | 159 cros->ConnectToWifiNetwork(wifi, std::string(), |
| 131 std::string(), std::string()); | 160 std::string(), std::string()); |
| 132 } else { | 161 } else { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 145 menu_items_[index].wireless_path, &cellular); | 174 menu_items_[index].wireless_path, &cellular); |
| 146 | 175 |
| 147 if (!cellular_exists) { | 176 if (!cellular_exists) { |
| 148 // If we are attempting to connect to a network that no longer exists, | 177 // If we are attempting to connect to a network that no longer exists, |
| 149 // display a notification. | 178 // display a notification. |
| 150 // TODO(stevenjb): Show notification. | 179 // TODO(stevenjb): Show notification. |
| 151 } else if (cellular.name() == cros->cellular_name()) { | 180 } else if (cellular.name() == cros->cellular_name()) { |
| 152 // If clicked on a network that we are already connected to or we are | 181 // If clicked on a network that we are already connected to or we are |
| 153 // currently trying to connect to, then open config dialog. | 182 // currently trying to connect to, then open config dialog. |
| 154 if (cros->cellular_connected()) { | 183 if (cros->cellular_connected()) { |
| 155 NetworkConfigView* view = new NetworkConfigView(cellular); | 184 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 156 view->set_browser_mode(IsBrowserMode()); | 185 switches::kEnableTabbedOptions)) { |
| 157 views::Window* window = views::Window::CreateChromeWindow( | 186 ShowTabbedNetworkSettings(cellular); |
| 158 GetNativeWindow(), gfx::Rect(), view); | 187 } else { |
| 159 window->SetIsAlwaysOnTop(true); | 188 NetworkConfigView* view = new NetworkConfigView(cellular); |
| 160 window->Show(); | 189 view->set_browser_mode(IsBrowserMode()); |
| 190 views::Window* window = views::Window::CreateChromeWindow( |
| 191 GetNativeWindow(), gfx::Rect(), view); |
| 192 window->SetIsAlwaysOnTop(true); |
| 193 window->Show(); |
| 194 } |
| 161 } else { | 195 } else { |
| 162 // TODO(stevenjb): Connection in progress. Show dialog? | 196 // TODO(stevenjb): Connection in progress. Show dialog? |
| 163 } | 197 } |
| 164 } else { | 198 } else { |
| 165 cros->ConnectToCellularNetwork(cellular); | 199 cros->ConnectToCellularNetwork(cellular); |
| 166 } | 200 } |
| 167 } | 201 } |
| 168 } | 202 } |
| 169 | 203 |
| 170 void NetworkMenu::SetFirstLevelMenuWidth(int width) { | 204 void NetworkMenu::SetFirstLevelMenuWidth(int width) { |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 if (ShouldOpenButtonOptions()) { | 393 if (ShouldOpenButtonOptions()) { |
| 360 label = | 394 label = |
| 361 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_OPEN_OPTIONS_DIALOG); | 395 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_OPEN_OPTIONS_DIALOG); |
| 362 menu_items_.push_back(MenuItem(menus::MenuModel::TYPE_COMMAND, label, | 396 menu_items_.push_back(MenuItem(menus::MenuModel::TYPE_COMMAND, label, |
| 363 SkBitmap(), std::string(), FLAG_OPTIONS)); | 397 SkBitmap(), std::string(), FLAG_OPTIONS)); |
| 364 } | 398 } |
| 365 } | 399 } |
| 366 } | 400 } |
| 367 | 401 |
| 368 } // namespace chromeos | 402 } // namespace chromeos |
| OLD | NEW |