OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/options/network_connect.h" | 5 #include "chrome/browser/chromeos/options/network_connect.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/shell_delegate.h" | 8 #include "ash/shell_delegate.h" |
9 #include "ash/system/chromeos/network/network_connect.h" | 9 #include "ash/system/chromeos/network/network_connect.h" |
10 #include "ash/system/chromeos/network/network_observer.h" | 10 #include "ash/system/chromeos/network/network_observer.h" |
11 #include "ash/system/tray/system_tray_notifier.h" | 11 #include "ash/system/tray/system_tray_notifier.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/stringprintf.h" |
13 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
14 #include "chrome/browser/chromeos/cros/cros_library.h" | 15 #include "chrome/browser/chromeos/cros/cros_library.h" |
15 #include "chrome/browser/chromeos/cros/network_library.h" | 16 #include "chrome/browser/chromeos/cros/network_library.h" |
16 #include "chrome/browser/chromeos/enrollment_dialog_view.h" | 17 #include "chrome/browser/chromeos/enrollment_dialog_view.h" |
17 #include "chrome/browser/chromeos/options/network_config_view.h" | 18 #include "chrome/browser/chromeos/options/network_config_view.h" |
18 #include "chrome/browser/profiles/profile_manager.h" | 19 #include "chrome/browser/profiles/profile_manager.h" |
| 20 #include "chrome/browser/ui/browser_finder.h" |
| 21 #include "chrome/browser/ui/chrome_pages.h" |
19 #include "chrome/browser/ui/webui/chromeos/mobile_setup_dialog.h" | 22 #include "chrome/browser/ui/webui/chromeos/mobile_setup_dialog.h" |
| 23 #include "chrome/common/url_constants.h" |
20 #include "chromeos/chromeos_switches.h" | 24 #include "chromeos/chromeos_switches.h" |
| 25 #include "content/public/browser/user_metrics.h" |
21 #include "grit/generated_resources.h" | 26 #include "grit/generated_resources.h" |
| 27 #include "net/base/escape.h" |
22 #include "third_party/cros_system_api/dbus/service_constants.h" | 28 #include "third_party/cros_system_api/dbus/service_constants.h" |
23 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
24 | 30 |
25 namespace chromeos { | 31 namespace chromeos { |
26 namespace network_connect { | 32 namespace network_connect { |
27 | 33 |
28 namespace { | 34 namespace { |
29 | 35 |
30 void DoConnect(Network* network, gfx::NativeWindow parent_window) { | 36 void DoConnect(Network* network, gfx::NativeWindow parent_window) { |
31 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | 37 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 Network* network = cros->FindNetworkByPath(service_path); | 134 Network* network = cros->FindNetworkByPath(service_path); |
129 if (!network) | 135 if (!network) |
130 return NETWORK_NOT_FOUND; | 136 return NETWORK_NOT_FOUND; |
131 | 137 |
132 if (network->connecting_or_connected()) | 138 if (network->connecting_or_connected()) |
133 return CONNECT_NOT_STARTED; | 139 return CONNECT_NOT_STARTED; |
134 | 140 |
135 if (network->type() == TYPE_ETHERNET) | 141 if (network->type() == TYPE_ETHERNET) |
136 return CONNECT_NOT_STARTED; // Normally this shouldn't happen | 142 return CONNECT_NOT_STARTED; // Normally this shouldn't happen |
137 | 143 |
138 if (network->type() == TYPE_WIFI) { | 144 if (network->type() == TYPE_WIFI || network->type() == TYPE_VPN) { |
139 WifiNetwork* wifi = static_cast<WifiNetwork*>(network); | 145 network->SetEnrollmentDelegate(chromeos::CreateEnrollmentDelegate( |
140 wifi->SetEnrollmentDelegate( | 146 parent_window, network->name(), ProfileManager::GetLastUsedProfile())); |
141 chromeos::CreateEnrollmentDelegate( | 147 network->AttemptConnection(base::Bind(&DoConnect, network, parent_window)); |
142 parent_window, | |
143 wifi->name(), | |
144 ProfileManager::GetLastUsedProfile())); | |
145 wifi->AttemptConnection(base::Bind(&DoConnect, wifi, parent_window)); | |
146 return CONNECT_STARTED; | 148 return CONNECT_STARTED; |
147 } | 149 } |
148 | 150 |
149 if (network->type() == TYPE_WIMAX) { | 151 if (network->type() == TYPE_WIMAX) { |
150 WimaxNetwork* wimax = static_cast<WimaxNetwork*>(network); | 152 WimaxNetwork* wimax = static_cast<WimaxNetwork*>(network); |
151 wimax->AttemptConnection(base::Bind(&DoConnect, wimax, parent_window)); | 153 wimax->AttemptConnection(base::Bind(&DoConnect, wimax, parent_window)); |
152 return CONNECT_STARTED; | 154 return CONNECT_STARTED; |
153 } | 155 } |
154 | 156 |
155 if (network->type() == TYPE_CELLULAR) { | 157 if (network->type() == TYPE_CELLULAR) { |
156 CellularNetwork* cellular = static_cast<CellularNetwork*>(network); | 158 CellularNetwork* cellular = static_cast<CellularNetwork*>(network); |
157 if (cellular->NeedsActivation() || cellular->out_of_credits()) { | 159 if (cellular->NeedsActivation() || cellular->out_of_credits()) { |
158 ActivateCellular(service_path); | 160 ActivateCellular(service_path); |
159 return CONNECT_STARTED; | 161 return CONNECT_STARTED; |
160 } | 162 } |
161 if (cellular->activation_state() == ACTIVATION_STATE_ACTIVATING) | 163 if (cellular->activation_state() == ACTIVATION_STATE_ACTIVATING) |
162 return CONNECT_NOT_STARTED; | 164 return CONNECT_NOT_STARTED; |
163 cros->ConnectToCellularNetwork(cellular); | 165 cros->ConnectToCellularNetwork(cellular); |
164 return CONNECT_STARTED; | 166 return CONNECT_STARTED; |
165 } | 167 } |
166 | 168 |
167 if (network->type() == TYPE_VPN) { | |
168 VirtualNetwork* vpn = static_cast<VirtualNetwork*>(network); | |
169 vpn->SetEnrollmentDelegate( | |
170 chromeos::CreateEnrollmentDelegate( | |
171 parent_window, | |
172 vpn->name(), | |
173 ProfileManager::GetLastUsedProfile())); | |
174 vpn->AttemptConnection(base::Bind(&DoConnect, vpn, parent_window)); | |
175 return CONNECT_STARTED; | |
176 } | |
177 | |
178 NOTREACHED(); | 169 NOTREACHED(); |
179 return CONNECT_NOT_STARTED; | 170 return CONNECT_NOT_STARTED; |
180 } | 171 } |
181 | 172 |
| 173 void HandleUnconfiguredNetwork(const std::string& service_path, |
| 174 gfx::NativeWindow parent_window) { |
| 175 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); |
| 176 Network* network = cros->FindNetworkByPath(service_path); |
| 177 if (!network) { |
| 178 LOG(WARNING) << "Unknown network: " << service_path; |
| 179 return; |
| 180 } |
| 181 |
| 182 if (network->type() == TYPE_WIFI || network->type() == TYPE_VPN) { |
| 183 network->SetEnrollmentDelegate(chromeos::CreateEnrollmentDelegate( |
| 184 parent_window, network->name(), ProfileManager::GetLastUsedProfile())); |
| 185 // This will connect to the network only if the network just needs to have |
| 186 // its certificate configured. Otherwise it will show an enrollment dialog |
| 187 // if available, or call NetworkConfigView::Show(). |
| 188 network->AttemptConnection( |
| 189 base::Bind(&NetworkConfigView::Show, network, parent_window)); |
| 190 return; |
| 191 } |
| 192 |
| 193 if (network->type() == TYPE_WIMAX) { |
| 194 NetworkConfigView::Show(network, parent_window); |
| 195 return; |
| 196 } |
| 197 |
| 198 if (network->type() == TYPE_CELLULAR) { |
| 199 CellularNetwork* cellular = static_cast<CellularNetwork*>(network); |
| 200 if (cellular->NeedsActivation()) { |
| 201 ActivateCellular(service_path); |
| 202 return; |
| 203 } else if (cellular->out_of_credits()) { |
| 204 ShowMobileSetup(service_path); |
| 205 return; |
| 206 } |
| 207 } |
| 208 |
| 209 // No special configure or setup for |service_path|, show the settings UI. |
| 210 std::string page = chrome::kInternetOptionsSubPage; |
| 211 std::string name = network->name(); |
| 212 if (name.empty() && network->type() == TYPE_ETHERNET) |
| 213 name = l10n_util::GetStringUTF8(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET); |
| 214 page += base::StringPrintf( |
| 215 "?servicePath=%s&networkType=%d&networkName=%s", |
| 216 net::EscapeUrlEncodedData(service_path, true).c_str(), |
| 217 network->type(), |
| 218 net::EscapeUrlEncodedData(name, false).c_str()); |
| 219 content::RecordAction( |
| 220 content::UserMetricsAction("OpenInternetOptionsDialog")); |
| 221 Browser* browser = chrome::FindOrCreateTabbedBrowser( |
| 222 ProfileManager::GetDefaultProfileOrOffTheRecord(), |
| 223 chrome::HOST_DESKTOP_TYPE_ASH); |
| 224 chrome::ShowSettingsSubPage(browser, page); |
| 225 } |
| 226 |
182 } // namespace network_connect | 227 } // namespace network_connect |
183 } // namespace chromeos | 228 } // namespace chromeos |
OLD | NEW |