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" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "chrome/browser/browser.h" | 12 #include "chrome/browser/browser.h" |
13 #include "chrome/browser/browser_list.h" | 13 #include "chrome/browser/browser_list.h" |
14 #include "chrome/browser/chromeos/cros/cros_library.h" | 14 #include "chrome/browser/chromeos/cros/cros_library.h" |
15 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
16 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
| 17 #include "chrome/browser/views/window.h" |
17 #include "gfx/canvas_skia.h" | 18 #include "gfx/canvas_skia.h" |
18 #include "gfx/skbitmap_operations.h" | 19 #include "gfx/skbitmap_operations.h" |
19 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
20 #include "grit/theme_resources.h" | 21 #include "grit/theme_resources.h" |
21 #include "net/base/escape.h" | 22 #include "net/base/escape.h" |
22 #include "views/window/window.h" | 23 #include "views/window/window.h" |
23 | 24 |
24 namespace chromeos { | 25 namespace chromeos { |
25 | 26 |
26 //////////////////////////////////////////////////////////////////////////////// | 27 //////////////////////////////////////////////////////////////////////////////// |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 cros->EnableEthernetNetworkDevice(!cros->ethernet_enabled()); | 100 cros->EnableEthernetNetworkDevice(!cros->ethernet_enabled()); |
100 } else if (flags & FLAG_TOGGLE_WIFI) { | 101 } else if (flags & FLAG_TOGGLE_WIFI) { |
101 cros->EnableWifiNetworkDevice(!cros->wifi_enabled()); | 102 cros->EnableWifiNetworkDevice(!cros->wifi_enabled()); |
102 } else if (flags & FLAG_TOGGLE_CELLULAR) { | 103 } else if (flags & FLAG_TOGGLE_CELLULAR) { |
103 cros->EnableCellularNetworkDevice(!cros->cellular_enabled()); | 104 cros->EnableCellularNetworkDevice(!cros->cellular_enabled()); |
104 } else if (flags & FLAG_TOGGLE_OFFLINE) { | 105 } else if (flags & FLAG_TOGGLE_OFFLINE) { |
105 cros->EnableOfflineMode(!cros->offline_mode()); | 106 cros->EnableOfflineMode(!cros->offline_mode()); |
106 } else if (flags & FLAG_OTHER_NETWORK) { | 107 } else if (flags & FLAG_OTHER_NETWORK) { |
107 NetworkConfigView* view = new NetworkConfigView(); | 108 NetworkConfigView* view = new NetworkConfigView(); |
108 view->set_browser_mode(IsBrowserMode()); | 109 view->set_browser_mode(IsBrowserMode()); |
109 views::Window* window = views::Window::CreateChromeWindow(GetNativeWindow(), | 110 views::Window* window = browser::CreateViewsWindow(GetNativeWindow(), |
110 gfx::Rect(), | 111 gfx::Rect(), |
111 view); | 112 view); |
112 window->SetIsAlwaysOnTop(true); | 113 window->SetIsAlwaysOnTop(true); |
113 window->Show(); | 114 window->Show(); |
114 view->SetLoginTextfieldFocus(); | 115 view->SetLoginTextfieldFocus(); |
115 } else if (flags & FLAG_ETHERNET) { | 116 } else if (flags & FLAG_ETHERNET) { |
116 if (cros->ethernet_connected()) { | 117 if (cros->ethernet_connected()) { |
117 if (CommandLine::ForCurrentProcess()->HasSwitch( | 118 if (CommandLine::ForCurrentProcess()->HasSwitch( |
118 switches::kEnableTabbedOptions)) { | 119 switches::kEnableTabbedOptions)) { |
119 ShowTabbedNetworkSettings(cros->ethernet_network()); | 120 ShowTabbedNetworkSettings(cros->ethernet_network()); |
120 } else { | 121 } else { |
121 NetworkConfigView* view = | 122 NetworkConfigView* view = |
122 new NetworkConfigView(cros->ethernet_network()); | 123 new NetworkConfigView(cros->ethernet_network()); |
123 view->set_browser_mode(IsBrowserMode()); | 124 view->set_browser_mode(IsBrowserMode()); |
124 views::Window* window = views::Window::CreateChromeWindow( | 125 views::Window* window = browser::CreateViewsWindow( |
125 GetNativeWindow(), gfx::Rect(), view); | 126 GetNativeWindow(), gfx::Rect(), view); |
126 window->SetIsAlwaysOnTop(true); | 127 window->SetIsAlwaysOnTop(true); |
127 window->Show(); | 128 window->Show(); |
128 } | 129 } |
129 } | 130 } |
130 } else if (flags & FLAG_WIFI) { | 131 } else if (flags & FLAG_WIFI) { |
131 WifiNetwork wifi; | 132 WifiNetwork wifi; |
132 bool wifi_exists = cros->FindWifiNetworkByPath( | 133 bool wifi_exists = cros->FindWifiNetworkByPath( |
133 menu_items_[index].wireless_path, &wifi); | 134 menu_items_[index].wireless_path, &wifi); |
134 if (!wifi_exists) { | 135 if (!wifi_exists) { |
135 // If we are attempting to connect to a network that no longer exists, | 136 // If we are attempting to connect to a network that no longer exists, |
136 // display a notification. | 137 // display a notification. |
137 // TODO(stevenjb): Show notification. | 138 // TODO(stevenjb): Show notification. |
138 } else if (wifi.name() == cros->wifi_name()) { | 139 } else if (wifi.name() == cros->wifi_name()) { |
139 if (cros->wifi_connected()) { | 140 if (cros->wifi_connected()) { |
140 if (CommandLine::ForCurrentProcess()->HasSwitch( | 141 if (CommandLine::ForCurrentProcess()->HasSwitch( |
141 switches::kEnableTabbedOptions)) { | 142 switches::kEnableTabbedOptions)) { |
142 ShowTabbedNetworkSettings(wifi); | 143 ShowTabbedNetworkSettings(wifi); |
143 } else { | 144 } else { |
144 // If we are already connected, open the config dialog. | 145 // If we are already connected, open the config dialog. |
145 NetworkConfigView* view = new NetworkConfigView(wifi, false); | 146 NetworkConfigView* view = new NetworkConfigView(wifi, false); |
146 view->set_browser_mode(IsBrowserMode()); | 147 view->set_browser_mode(IsBrowserMode()); |
147 views::Window* window = views::Window::CreateChromeWindow( | 148 views::Window* window = browser::CreateViewsWindow( |
148 GetNativeWindow(), gfx::Rect(), view); | 149 GetNativeWindow(), gfx::Rect(), view); |
149 window->SetIsAlwaysOnTop(true); | 150 window->SetIsAlwaysOnTop(true); |
150 window->Show(); | 151 window->Show(); |
151 } | 152 } |
152 } else { | 153 } else { |
153 // TODO(stevenjb): Connection in progress. Show dialog? | 154 // TODO(stevenjb): Connection in progress. Show dialog? |
154 } | 155 } |
155 } else { | 156 } else { |
156 // If wifi network is not encrypted, then directly connect. | 157 // If wifi network is not encrypted, then directly connect. |
157 // Otherwise, we open password dialog window. | 158 // Otherwise, we open password dialog window. |
158 if (!wifi.encrypted()) { | 159 if (!wifi.encrypted()) { |
159 cros->ConnectToWifiNetwork(wifi, std::string(), | 160 cros->ConnectToWifiNetwork(wifi, std::string(), |
160 std::string(), std::string()); | 161 std::string(), std::string()); |
161 } else { | 162 } else { |
162 NetworkConfigView* view = new NetworkConfigView(wifi, true); | 163 NetworkConfigView* view = new NetworkConfigView(wifi, true); |
163 view->set_browser_mode(IsBrowserMode()); | 164 view->set_browser_mode(IsBrowserMode()); |
164 views::Window* window = views::Window::CreateChromeWindow( | 165 views::Window* window = browser::CreateViewsWindow( |
165 GetNativeWindow(), gfx::Rect(), view); | 166 GetNativeWindow(), gfx::Rect(), view); |
166 window->SetIsAlwaysOnTop(true); | 167 window->SetIsAlwaysOnTop(true); |
167 window->Show(); | 168 window->Show(); |
168 view->SetLoginTextfieldFocus(); | 169 view->SetLoginTextfieldFocus(); |
169 } | 170 } |
170 } | 171 } |
171 } else if (flags & FLAG_CELLULAR) { | 172 } else if (flags & FLAG_CELLULAR) { |
172 CellularNetwork cellular; | 173 CellularNetwork cellular; |
173 bool cellular_exists = cros->FindCellularNetworkByPath( | 174 bool cellular_exists = cros->FindCellularNetworkByPath( |
174 menu_items_[index].wireless_path, &cellular); | 175 menu_items_[index].wireless_path, &cellular); |
175 | 176 |
176 if (!cellular_exists) { | 177 if (!cellular_exists) { |
177 // If we are attempting to connect to a network that no longer exists, | 178 // If we are attempting to connect to a network that no longer exists, |
178 // display a notification. | 179 // display a notification. |
179 // TODO(stevenjb): Show notification. | 180 // TODO(stevenjb): Show notification. |
180 } else if (cellular.name() == cros->cellular_name()) { | 181 } else if (cellular.name() == cros->cellular_name()) { |
181 // If clicked on a network that we are already connected to or we are | 182 // If clicked on a network that we are already connected to or we are |
182 // currently trying to connect to, then open config dialog. | 183 // currently trying to connect to, then open config dialog. |
183 if (cros->cellular_connected()) { | 184 if (cros->cellular_connected()) { |
184 if (CommandLine::ForCurrentProcess()->HasSwitch( | 185 if (CommandLine::ForCurrentProcess()->HasSwitch( |
185 switches::kEnableTabbedOptions)) { | 186 switches::kEnableTabbedOptions)) { |
186 ShowTabbedNetworkSettings(cellular); | 187 ShowTabbedNetworkSettings(cellular); |
187 } else { | 188 } else { |
188 NetworkConfigView* view = new NetworkConfigView(cellular); | 189 NetworkConfigView* view = new NetworkConfigView(cellular); |
189 view->set_browser_mode(IsBrowserMode()); | 190 view->set_browser_mode(IsBrowserMode()); |
190 views::Window* window = views::Window::CreateChromeWindow( | 191 views::Window* window = browser::CreateViewsWindow( |
191 GetNativeWindow(), gfx::Rect(), view); | 192 GetNativeWindow(), gfx::Rect(), view); |
192 window->SetIsAlwaysOnTop(true); | 193 window->SetIsAlwaysOnTop(true); |
193 window->Show(); | 194 window->Show(); |
194 } | 195 } |
195 } else { | 196 } else { |
196 // TODO(stevenjb): Connection in progress. Show dialog? | 197 // TODO(stevenjb): Connection in progress. Show dialog? |
197 } | 198 } |
198 } else { | 199 } else { |
199 cros->ConnectToCellularNetwork(cellular); | 200 cros->ConnectToCellularNetwork(cellular); |
200 } | 201 } |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 if (ShouldOpenButtonOptions()) { | 394 if (ShouldOpenButtonOptions()) { |
394 label = | 395 label = |
395 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_OPEN_OPTIONS_DIALOG); | 396 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_OPEN_OPTIONS_DIALOG); |
396 menu_items_.push_back(MenuItem(menus::MenuModel::TYPE_COMMAND, label, | 397 menu_items_.push_back(MenuItem(menus::MenuModel::TYPE_COMMAND, label, |
397 SkBitmap(), std::string(), FLAG_OPTIONS)); | 398 SkBitmap(), std::string(), FLAG_OPTIONS)); |
398 } | 399 } |
399 } | 400 } |
400 } | 401 } |
401 | 402 |
402 } // namespace chromeos | 403 } // namespace chromeos |
OLD | NEW |