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

Side by Side Diff: chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc

Issue 1006553002: Add third-party VPN support to network details dialog (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@f_2_460428_add_ash_ui
Patch Set: Addressed comments. Created 5 years, 9 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/webui/options/chromeos/internet_options_handler.h" 5 #include "chrome/browser/ui/webui/options/chromeos/internet_options_handler.h"
6 6
7 #include <ctype.h> 7 #include <ctype.h>
8 8
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/bind_helpers.h" 15 #include "base/bind_helpers.h"
16 #include "base/command_line.h" 16 #include "base/command_line.h"
17 #include "base/memory/scoped_ptr.h"
17 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
18 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
19 #include "base/values.h" 20 #include "base/values.h"
20 #include "chrome/browser/browser_process.h" 21 #include "chrome/browser/browser_process.h"
21 #include "chrome/browser/chromeos/mobile_config.h" 22 #include "chrome/browser/chromeos/mobile_config.h"
22 #include "chrome/browser/chromeos/net/onc_utils.h" 23 #include "chrome/browser/chromeos/net/onc_utils.h"
23 #include "chrome/browser/chromeos/options/network_config_view.h" 24 #include "chrome/browser/chromeos/options/network_config_view.h"
24 #include "chrome/browser/chromeos/options/network_property_ui_data.h" 25 #include "chrome/browser/chromeos/options/network_property_ui_data.h"
26 #include "chrome/browser/chromeos/profiles/profile_helper.h"
25 #include "chrome/browser/chromeos/settings/cros_settings.h" 27 #include "chrome/browser/chromeos/settings/cros_settings.h"
26 #include "chrome/browser/chromeos/sim_dialog_delegate.h" 28 #include "chrome/browser/chromeos/sim_dialog_delegate.h"
27 #include "chrome/browser/chromeos/ui/choose_mobile_network_dialog.h" 29 #include "chrome/browser/chromeos/ui/choose_mobile_network_dialog.h"
28 #include "chrome/browser/chromeos/ui/mobile_config_ui.h" 30 #include "chrome/browser/chromeos/ui/mobile_config_ui.h"
29 #include "chrome/browser/chromeos/ui_proxy_config_service.h" 31 #include "chrome/browser/chromeos/ui_proxy_config_service.h"
30 #include "chrome/browser/profiles/profile.h" 32 #include "chrome/browser/profiles/profile.h"
31 #include "chrome/browser/ui/webui/chromeos/mobile_setup_dialog.h" 33 #include "chrome/browser/ui/webui/chromeos/mobile_setup_dialog.h"
32 #include "chrome/browser/ui/webui/options/chromeos/internet_options_handler_stri ngs.h" 34 #include "chrome/browser/ui/webui/options/chromeos/internet_options_handler_stri ngs.h"
33 #include "chromeos/chromeos_switches.h" 35 #include "chromeos/chromeos_switches.h"
34 #include "chromeos/login/login_state.h" 36 #include "chromeos/login/login_state.h"
35 #include "chromeos/network/device_state.h" 37 #include "chromeos/network/device_state.h"
36 #include "chromeos/network/managed_network_configuration_handler.h" 38 #include "chromeos/network/managed_network_configuration_handler.h"
37 #include "chromeos/network/network_connection_handler.h" 39 #include "chromeos/network/network_connection_handler.h"
38 #include "chromeos/network/network_device_handler.h" 40 #include "chromeos/network/network_device_handler.h"
39 #include "chromeos/network/network_event_log.h" 41 #include "chromeos/network/network_event_log.h"
40 #include "chromeos/network/network_ip_config.h" 42 #include "chromeos/network/network_ip_config.h"
41 #include "chromeos/network/network_profile.h" 43 #include "chromeos/network/network_profile.h"
42 #include "chromeos/network/network_profile_handler.h" 44 #include "chromeos/network/network_profile_handler.h"
43 #include "chromeos/network/network_state.h" 45 #include "chromeos/network/network_state.h"
44 #include "chromeos/network/network_state_handler.h" 46 #include "chromeos/network/network_state_handler.h"
45 #include "chromeos/network/network_util.h" 47 #include "chromeos/network/network_util.h"
46 #include "chromeos/network/onc/onc_signature.h" 48 #include "chromeos/network/onc/onc_signature.h"
47 #include "chromeos/network/onc/onc_translation_tables.h" 49 #include "chromeos/network/onc/onc_translation_tables.h"
48 #include "chromeos/network/onc/onc_translator.h" 50 #include "chromeos/network/onc/onc_translator.h"
49 #include "chromeos/network/onc/onc_utils.h" 51 #include "chromeos/network/onc/onc_utils.h"
50 #include "components/onc/onc_constants.h" 52 #include "components/onc/onc_constants.h"
53 #include "components/user_manager/user_manager.h"
51 #include "content/public/browser/web_contents.h" 54 #include "content/public/browser/web_contents.h"
52 #include "content/public/browser/web_ui.h" 55 #include "content/public/browser/web_ui.h"
56 #include "extensions/browser/api/vpn_provider/vpn_service.h"
57 #include "extensions/browser/api/vpn_provider/vpn_service_factory.h"
58 #include "extensions/browser/extension_registry.h"
59 #include "extensions/common/extension.h"
60 #include "extensions/common/extension_set.h"
61 #include "extensions/common/permissions/api_permission.h"
62 #include "extensions/common/permissions/permissions_data.h"
53 #include "third_party/cros_system_api/dbus/service_constants.h" 63 #include "third_party/cros_system_api/dbus/service_constants.h"
64 #include "ui/base/l10n/l10n_util.h"
54 #include "ui/base/webui/web_ui_util.h" 65 #include "ui/base/webui/web_ui_util.h"
55 #include "ui/chromeos/network/network_connect.h" 66 #include "ui/chromeos/network/network_connect.h"
67 #include "ui/chromeos/strings/grit/ui_chromeos_strings.h"
56 68
57 namespace chromeos { 69 namespace chromeos {
58 namespace options { 70 namespace options {
59 71
60 namespace { 72 namespace {
61 73
62 // Keys for the initial "localized" dictionary values. 74 // Keys for the initial "localized" dictionary values.
63 const char kLoggedInAsOwnerKey[] = "loggedInAsOwner"; 75 const char kLoggedInAsOwnerKey[] = "loggedInAsOwner";
64 const char kShowCarrierSelectKey[] = "showCarrierSelect"; 76 const char kShowCarrierSelectKey[] = "showCarrierSelect";
65 const char kNetworkDataKey[] = "networkData"; 77 const char kNetworkDataKey[] = "networkData";
66 78
67 // Keys for the network description dictionary passed to the web ui. Make sure 79 // Keys for the network description dictionary passed to the web ui. Make sure
68 // to keep the strings in sync with what the JavaScript side uses. 80 // to keep the strings in sync with what the JavaScript side uses.
69 const char kNetworkInfoKeyPolicyManaged[] = "policyManaged"; 81 const char kNetworkInfoKeyPolicyManaged[] = "policyManaged";
70 82
71 // Functions we call in JavaScript. 83 // Functions we call in JavaScript.
84 const char kSetVPNProvidersFunction[] = "options.VPNProviders.setProviders";
72 const char kRefreshNetworkDataFunction[] = 85 const char kRefreshNetworkDataFunction[] =
73 "options.network.NetworkList.refreshNetworkData"; 86 "options.network.NetworkList.refreshNetworkData";
74 const char kUpdateConnectionDataFunction[] = 87 const char kUpdateConnectionDataFunction[] =
75 "options.internet.DetailsInternetPage.updateConnectionData"; 88 "options.internet.DetailsInternetPage.updateConnectionData";
76 const char kUpdateCarrierFunction[] = 89 const char kUpdateCarrierFunction[] =
77 "options.internet.DetailsInternetPage.updateCarrier"; 90 "options.internet.DetailsInternetPage.updateCarrier";
78 91
79 // Setter methods called from JS that still need to be converted to match 92 // Setter methods called from JS that still need to be converted to match
80 // networkingPrivate methods. 93 // networkingPrivate methods.
81 const char kSetCarrierMessage[] = "setCarrier"; 94 const char kSetCarrierMessage[] = "setCarrier";
82 const char kShowMorePlanInfoMessage[] = "showMorePlanInfo"; 95 const char kShowMorePlanInfoMessage[] = "showMorePlanInfo";
83 const char kSimOperationMessage[] = "simOperation"; 96 const char kSimOperationMessage[] = "simOperation";
84 97
85 // TODO(stevenjb): Replace these with the matching networkingPrivate methods. 98 // TODO(stevenjb): Replace these with the matching networkingPrivate methods.
86 // crbug.com/279351. 99 // crbug.com/279351.
87 const char kStartConnectMessage[] = "startConnect"; 100 const char kStartConnectMessage[] = "startConnect";
88 101
89 // TODO(stevenjb): Deprecate this once we handle events in the JS. 102 // TODO(stevenjb): Deprecate this once we handle events in the JS.
90 const char kSetNetworkGuidMessage[] = "setNetworkGuid"; 103 const char kSetNetworkGuidMessage[] = "setNetworkGuid";
91 104
92 // TODO(stevenjb): Add these to networkingPrivate. 105 // TODO(stevenjb): Add these to networkingPrivate.
93 const char kRemoveNetworkMessage[] = "removeNetwork"; 106 const char kRemoveNetworkMessage[] = "removeNetwork";
94 107
95 // TODO(stevenjb): Deprecate these and integrate with settings Web UI. 108 // TODO(stevenjb): Deprecate these and integrate with settings Web UI.
96 const char kAddConnectionMessage[] = "addConnection"; 109 const char kAddConnectionMessage[] = "addConnection";
97 const char kConfigureNetworkMessage[] = "configureNetwork"; 110 const char kConfigureNetworkMessage[] = "configureNetwork";
98 const char kActivateNetworkMessage[] = "activateNetwork"; 111 const char kActivateNetworkMessage[] = "activateNetwork";
99 112
113 const char kLoadVPNProviders[] = "loadVPNProviders";
114
100 // These are strings used to communicate with JavaScript. 115 // These are strings used to communicate with JavaScript.
101 const char kTagCellularAvailable[] = "cellularAvailable"; 116 const char kTagCellularAvailable[] = "cellularAvailable";
102 const char kTagCellularEnabled[] = "cellularEnabled"; 117 const char kTagCellularEnabled[] = "cellularEnabled";
103 const char kTagCellularSimAbsent[] = "cellularSimAbsent"; 118 const char kTagCellularSimAbsent[] = "cellularSimAbsent";
104 const char kTagCellularSimLockType[] = "cellularSimLockType"; 119 const char kTagCellularSimLockType[] = "cellularSimLockType";
105 const char kTagCellularSupportsScan[] = "cellularSupportsScan"; 120 const char kTagCellularSupportsScan[] = "cellularSupportsScan";
106 const char kTagRememberedList[] = "rememberedList"; 121 const char kTagRememberedList[] = "rememberedList";
107 const char kTagSimOpChangePin[] = "changePin"; 122 const char kTagSimOpChangePin[] = "changePin";
108 const char kTagSimOpConfigure[] = "configure"; 123 const char kTagSimOpConfigure[] = "configure";
109 const char kTagSimOpSetLocked[] = "setLocked"; 124 const char kTagSimOpSetLocked[] = "setLocked";
110 const char kTagSimOpSetUnlocked[] = "setUnlocked"; 125 const char kTagSimOpSetUnlocked[] = "setUnlocked";
111 const char kTagSimOpUnlock[] = "unlock"; 126 const char kTagSimOpUnlock[] = "unlock";
127 const char kTagVPNProviderName[] = "name";
128 const char kTagVPNProviderExtensionID[] = "extensionID";
112 const char kTagVpnList[] = "vpnList"; 129 const char kTagVpnList[] = "vpnList";
113 const char kTagWifiAvailable[] = "wifiAvailable"; 130 const char kTagWifiAvailable[] = "wifiAvailable";
114 const char kTagWifiEnabled[] = "wifiEnabled"; 131 const char kTagWifiEnabled[] = "wifiEnabled";
115 const char kTagWimaxAvailable[] = "wimaxAvailable"; 132 const char kTagWimaxAvailable[] = "wimaxAvailable";
116 const char kTagWimaxEnabled[] = "wimaxEnabled"; 133 const char kTagWimaxEnabled[] = "wimaxEnabled";
117 const char kTagWiredList[] = "wiredList"; 134 const char kTagWiredList[] = "wiredList";
118 const char kTagWirelessList[] = "wirelessList"; 135 const char kTagWirelessList[] = "wirelessList";
119 136
120 // Pseudo-ONC chrome specific properties appended to the ONC dictionary. 137 // Pseudo-ONC chrome specific properties appended to the ONC dictionary.
121 const char kTagShowViewAccountButton[] = "showViewAccountButton"; 138 const char kTagShowViewAccountButton[] = "showViewAccountButton";
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 device->properties().GetStringWithoutPathExpansion(shill::kMdnProperty, 212 device->properties().GetStringWithoutPathExpansion(shill::kMdnProperty,
196 &mdn); 213 &mdn);
197 } 214 }
198 if (mdn.empty()) 215 if (mdn.empty())
199 return false; 216 return false;
200 } 217 }
201 218
202 return true; 219 return true;
203 } 220 }
204 221
222 bool IsVPNProvider(const extensions::Extension* extension) {
223 return extension->permissions_data()->HasAPIPermission(
224 extensions::APIPermission::kVpnProvider);
225 }
226
227 Profile* GetProfileForPrimaryUser() {
228 return chromeos::ProfileHelper::Get()->GetProfileByUser(
229 user_manager::UserManager::Get()->GetPrimaryUser());
230 }
231
232 extensions::ExtensionRegistry* GetExtensionRegistryForPrimaryUser() {
233 return extensions::ExtensionRegistry::Get(GetProfileForPrimaryUser());
234 }
235
236 scoped_ptr<base::DictionaryValue> BuildVPNProviderDictionary(
237 const std::string& name,
238 const std::string& third_party_provider_extension_id) {
239 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
240 dict->SetString(kTagVPNProviderName, name);
241 if (!third_party_provider_extension_id.empty()) {
242 dict->SetString(kTagVPNProviderExtensionID,
243 third_party_provider_extension_id);
244 }
245 return dict.Pass();
246 }
247
205 } // namespace 248 } // namespace
206 249
207 InternetOptionsHandler::InternetOptionsHandler() 250 InternetOptionsHandler::InternetOptionsHandler()
208 : weak_factory_(this) { 251 : weak_factory_(this) {
252 GetExtensionRegistryForPrimaryUser()->AddObserver(this);
209 NetworkHandler::Get()->network_state_handler()->AddObserver(this, FROM_HERE); 253 NetworkHandler::Get()->network_state_handler()->AddObserver(this, FROM_HERE);
210 } 254 }
211 255
212 InternetOptionsHandler::~InternetOptionsHandler() { 256 InternetOptionsHandler::~InternetOptionsHandler() {
213 if (NetworkHandler::IsInitialized()) { 257 if (NetworkHandler::IsInitialized()) {
214 NetworkHandler::Get()->network_state_handler()->RemoveObserver( 258 NetworkHandler::Get()->network_state_handler()->RemoveObserver(
215 this, FROM_HERE); 259 this, FROM_HERE);
216 } 260 }
261 GetExtensionRegistryForPrimaryUser()->RemoveObserver(this);
217 } 262 }
218 263
219 void InternetOptionsHandler::GetLocalizedValues( 264 void InternetOptionsHandler::GetLocalizedValues(
220 base::DictionaryValue* localized_strings) { 265 base::DictionaryValue* localized_strings) {
221 DCHECK(localized_strings); 266 DCHECK(localized_strings);
222 internet_options_strings::RegisterLocalizedStrings(localized_strings); 267 internet_options_strings::RegisterLocalizedStrings(localized_strings);
223 268
224 // TODO(stevenjb): Find a better way to populate initial data before 269 // TODO(stevenjb): Find a better way to populate initial data before
225 // InitializePage() gets called. 270 // InitializePage() gets called.
226 std::string owner; 271 std::string owner;
227 chromeos::CrosSettings::Get()->GetString(chromeos::kDeviceOwner, &owner); 272 chromeos::CrosSettings::Get()->GetString(chromeos::kDeviceOwner, &owner);
228 bool logged_in_as_owner = LoginState::Get()->GetLoggedInUserType() == 273 bool logged_in_as_owner = LoginState::Get()->GetLoggedInUserType() ==
229 LoginState::LOGGED_IN_USER_OWNER; 274 LoginState::LOGGED_IN_USER_OWNER;
230 localized_strings->SetBoolean(kLoggedInAsOwnerKey, logged_in_as_owner); 275 localized_strings->SetBoolean(kLoggedInAsOwnerKey, logged_in_as_owner);
231 localized_strings->SetBoolean( 276 localized_strings->SetBoolean(
232 kShowCarrierSelectKey, base::CommandLine::ForCurrentProcess()->HasSwitch( 277 kShowCarrierSelectKey, base::CommandLine::ForCurrentProcess()->HasSwitch(
233 chromeos::switches::kEnableCarrierSwitching)); 278 chromeos::switches::kEnableCarrierSwitching));
234 279
235 base::DictionaryValue* network_dictionary = new base::DictionaryValue; 280 base::DictionaryValue* network_dictionary = new base::DictionaryValue;
236 FillNetworkInfo(network_dictionary); 281 FillNetworkInfo(network_dictionary);
237 localized_strings->Set(kNetworkDataKey, network_dictionary); 282 localized_strings->Set(kNetworkDataKey, network_dictionary);
238 } 283 }
239 284
240 void InternetOptionsHandler::InitializePage() { 285 void InternetOptionsHandler::InitializePage() {
286 UpdateVPNProviders();
241 NetworkHandler::Get()->network_state_handler()->RequestScan(); 287 NetworkHandler::Get()->network_state_handler()->RequestScan();
242 RefreshNetworkData(); 288 RefreshNetworkData();
243 } 289 }
244 290
245 void InternetOptionsHandler::RegisterMessages() { 291 void InternetOptionsHandler::RegisterMessages() {
246 web_ui()->RegisterMessageCallback(kAddConnectionMessage, 292 web_ui()->RegisterMessageCallback(kAddConnectionMessage,
247 base::Bind(&InternetOptionsHandler::AddConnection, 293 base::Bind(&InternetOptionsHandler::AddConnection,
248 base::Unretained(this))); 294 base::Unretained(this)));
249 web_ui()->RegisterMessageCallback(kRemoveNetworkMessage, 295 web_ui()->RegisterMessageCallback(kRemoveNetworkMessage,
250 base::Bind(&InternetOptionsHandler::RemoveNetwork, 296 base::Bind(&InternetOptionsHandler::RemoveNetwork,
251 base::Unretained(this))); 297 base::Unretained(this)));
252 web_ui()->RegisterMessageCallback(kConfigureNetworkMessage, 298 web_ui()->RegisterMessageCallback(kConfigureNetworkMessage,
253 base::Bind(&InternetOptionsHandler::ConfigureNetwork, 299 base::Bind(&InternetOptionsHandler::ConfigureNetwork,
254 base::Unretained(this))); 300 base::Unretained(this)));
255 web_ui()->RegisterMessageCallback(kActivateNetworkMessage, 301 web_ui()->RegisterMessageCallback(kActivateNetworkMessage,
256 base::Bind(&InternetOptionsHandler::ActivateNetwork, 302 base::Bind(&InternetOptionsHandler::ActivateNetwork,
257 base::Unretained(this))); 303 base::Unretained(this)));
258 web_ui()->RegisterMessageCallback(kShowMorePlanInfoMessage, 304 web_ui()->RegisterMessageCallback(kShowMorePlanInfoMessage,
259 base::Bind(&InternetOptionsHandler::ShowMorePlanInfoCallback, 305 base::Bind(&InternetOptionsHandler::ShowMorePlanInfoCallback,
260 base::Unretained(this))); 306 base::Unretained(this)));
261 web_ui()->RegisterMessageCallback(kSetCarrierMessage, 307 web_ui()->RegisterMessageCallback(kSetCarrierMessage,
262 base::Bind(&InternetOptionsHandler::SetCarrierCallback, 308 base::Bind(&InternetOptionsHandler::SetCarrierCallback,
263 base::Unretained(this))); 309 base::Unretained(this)));
264 web_ui()->RegisterMessageCallback(kSimOperationMessage, 310 web_ui()->RegisterMessageCallback(kSimOperationMessage,
265 base::Bind(&InternetOptionsHandler::SimOperationCallback, 311 base::Bind(&InternetOptionsHandler::SimOperationCallback,
266 base::Unretained(this))); 312 base::Unretained(this)));
313 web_ui()->RegisterMessageCallback(
314 kLoadVPNProviders,
315 base::Bind(&InternetOptionsHandler::LoadVPNProvidersCallback,
316 base::Unretained(this)));
267 317
268 web_ui()->RegisterMessageCallback(kSetNetworkGuidMessage, 318 web_ui()->RegisterMessageCallback(kSetNetworkGuidMessage,
269 base::Bind(&InternetOptionsHandler::SetNetworkGuidCallback, 319 base::Bind(&InternetOptionsHandler::SetNetworkGuidCallback,
270 base::Unretained(this))); 320 base::Unretained(this)));
271 321
272 // networkingPrivate methods 322 // networkingPrivate methods
273 web_ui()->RegisterMessageCallback(kStartConnectMessage, 323 web_ui()->RegisterMessageCallback(kStartConnectMessage,
274 base::Bind(&InternetOptionsHandler::StartConnectCallback, 324 base::Bind(&InternetOptionsHandler::StartConnectCallback,
275 base::Unretained(this))); 325 base::Unretained(this)));
276 } 326 }
277 327
328 void InternetOptionsHandler::OnExtensionLoaded(
329 content::BrowserContext* browser_context,
330 const extensions::Extension* extension) {
331 if (IsVPNProvider(extension))
332 UpdateVPNProviders();
333 }
334
335 void InternetOptionsHandler::OnExtensionUnloaded(
336 content::BrowserContext* browser_context,
337 const extensions::Extension* extension,
338 extensions::UnloadedExtensionInfo::Reason reason) {
339 if (IsVPNProvider(extension))
340 UpdateVPNProviders();
341 }
342
343 void InternetOptionsHandler::OnShutdown(
344 extensions::ExtensionRegistry* registry) {
345 registry->RemoveObserver(this);
346 }
347
278 void InternetOptionsHandler::ShowMorePlanInfoCallback( 348 void InternetOptionsHandler::ShowMorePlanInfoCallback(
279 const base::ListValue* args) { 349 const base::ListValue* args) {
280 if (!web_ui()) 350 if (!web_ui())
281 return; 351 return;
282 std::string guid; 352 std::string guid;
283 if (args->GetSize() != 1 || !args->GetString(0, &guid)) { 353 if (args->GetSize() != 1 || !args->GetString(0, &guid)) {
284 NOTREACHED(); 354 NOTREACHED();
285 return; 355 return;
286 } 356 }
287 std::string service_path = ServicePathFromGuid(guid); 357 std::string service_path = ServicePathFromGuid(guid);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 NOTREACHED(); 451 NOTREACHED();
382 return; 452 return;
383 } 453 }
384 std::string service_path = ServicePathFromGuid(guid); 454 std::string service_path = ServicePathFromGuid(guid);
385 if (!service_path.empty()) 455 if (!service_path.empty())
386 ui::NetworkConnect::Get()->ConnectToNetwork(service_path); 456 ui::NetworkConnect::Get()->ConnectToNetwork(service_path);
387 } 457 }
388 458
389 //////////////////////////////////////////////////////////////////////////////// 459 ////////////////////////////////////////////////////////////////////////////////
390 460
461 void InternetOptionsHandler::UpdateVPNProviders() {
462 extensions::ExtensionRegistry* const registry =
463 GetExtensionRegistryForPrimaryUser();
464
465 base::ListValue vpn_providers;
466 const extensions::ExtensionSet& extensions = registry->enabled_extensions();
467 for (const auto& extension : extensions) {
468 if (IsVPNProvider(extension.get())) {
469 vpn_providers.Append(BuildVPNProviderDictionary(
470 extension->name(), extension->id()).release());
471 }
472 }
473 // Add the built-in OpenVPN/L2TP provider.
474 vpn_providers.Append(
475 BuildVPNProviderDictionary(
476 l10n_util::GetStringUTF8(IDS_NETWORK_VPN_BUILT_IN_PROVIDER),
477 std::string() /* third_party_provider_extension_id */).release());
478 web_ui()->CallJavascriptFunction(kSetVPNProvidersFunction, vpn_providers);
479 }
480
391 void InternetOptionsHandler::RefreshNetworkData() { 481 void InternetOptionsHandler::RefreshNetworkData() {
392 base::DictionaryValue dictionary; 482 base::DictionaryValue dictionary;
393 FillNetworkInfo(&dictionary); 483 FillNetworkInfo(&dictionary);
394 web_ui()->CallJavascriptFunction(kRefreshNetworkDataFunction, dictionary); 484 web_ui()->CallJavascriptFunction(kRefreshNetworkDataFunction, dictionary);
395 } 485 }
396 486
397 void InternetOptionsHandler::UpdateConnectionData( 487 void InternetOptionsHandler::UpdateConnectionData(
398 const std::string& service_path) { 488 const std::string& service_path) {
399 NetworkHandler::Get() 489 NetworkHandler::Get()
400 ->managed_network_configuration_handler() 490 ->managed_network_configuration_handler()
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 LOG(ERROR) << "Unsupported type for AddConnection"; 581 LOG(ERROR) << "Unsupported type for AddConnection";
492 } 582 }
493 } 583 }
494 584
495 void InternetOptionsHandler::ConfigureNetwork(const base::ListValue* args) { 585 void InternetOptionsHandler::ConfigureNetwork(const base::ListValue* args) {
496 std::string guid; 586 std::string guid;
497 if (args->GetSize() != 1 || !args->GetString(0, &guid)) { 587 if (args->GetSize() != 1 || !args->GetString(0, &guid)) {
498 NOTREACHED(); 588 NOTREACHED();
499 return; 589 return;
500 } 590 }
501 std::string service_path = ServicePathFromGuid(guid); 591 const std::string service_path = ServicePathFromGuid(guid);
502 if (!service_path.empty()) 592 if (service_path.empty())
503 NetworkConfigView::Show(service_path, GetNativeWindow()); 593 return;
594
595 const NetworkState* network = GetNetworkState(service_path);
596 if (!network)
597 return;
598
599 if (network->type() == shill::kTypeVPN &&
600 network->vpn_provider_type() == shill::kProviderThirdPartyVpn) {
601 // Request that the third-party VPN provider used by the |network| show a
602 // configuration dialog for it.
603 VpnServiceFactory::GetForBrowserContext(GetProfileForPrimaryUser())
604 ->SendShowConfigureDialogToExtension(
605 network->third_party_vpn_provider_extension_id(), network->name());
606 return;
607 }
608
609 NetworkConfigView::Show(service_path, GetNativeWindow());
504 } 610 }
505 611
506 void InternetOptionsHandler::ActivateNetwork(const base::ListValue* args) { 612 void InternetOptionsHandler::ActivateNetwork(const base::ListValue* args) {
507 std::string guid; 613 std::string guid;
508 if (args->GetSize() != 1 || !args->GetString(0, &guid)) { 614 if (args->GetSize() != 1 || !args->GetString(0, &guid)) {
509 NOTREACHED(); 615 NOTREACHED();
510 return; 616 return;
511 } 617 }
512 std::string service_path = ServicePathFromGuid(guid); 618 std::string service_path = ServicePathFromGuid(guid);
513 if (!service_path.empty()) 619 if (!service_path.empty())
514 ui::NetworkConnect::Get()->ActivateCellular(service_path); 620 ui::NetworkConnect::Get()->ActivateCellular(service_path);
515 } 621 }
516 622
517 void InternetOptionsHandler::RemoveNetwork(const base::ListValue* args) { 623 void InternetOptionsHandler::RemoveNetwork(const base::ListValue* args) {
518 std::string guid; 624 std::string guid;
519 if (args->GetSize() != 1 || !args->GetString(0, &guid)) { 625 if (args->GetSize() != 1 || !args->GetString(0, &guid)) {
520 NOTREACHED(); 626 NOTREACHED();
521 return; 627 return;
522 } 628 }
523 std::string service_path = ServicePathFromGuid(guid); 629 std::string service_path = ServicePathFromGuid(guid);
524 if (service_path.empty()) 630 if (service_path.empty())
525 return; 631 return;
526 NetworkHandler::Get() 632 NetworkHandler::Get()
527 ->managed_network_configuration_handler() 633 ->managed_network_configuration_handler()
528 ->RemoveConfiguration(service_path, base::Bind(&base::DoNothing), 634 ->RemoveConfiguration(service_path, base::Bind(&base::DoNothing),
529 base::Bind(&ShillError, "RemoveNetwork")); 635 base::Bind(&ShillError, "RemoveNetwork"));
530 } 636 }
531 637
638 void InternetOptionsHandler::LoadVPNProvidersCallback(
639 const base::ListValue* args) {
640 UpdateVPNProviders();
641 }
642
532 base::ListValue* InternetOptionsHandler::GetWiredList() { 643 base::ListValue* InternetOptionsHandler::GetWiredList() {
533 base::ListValue* list = new base::ListValue(); 644 base::ListValue* list = new base::ListValue();
534 const NetworkState* network = NetworkHandler::Get()->network_state_handler()-> 645 const NetworkState* network = NetworkHandler::Get()->network_state_handler()->
535 FirstNetworkByType(NetworkTypePattern::Ethernet()); 646 FirstNetworkByType(NetworkTypePattern::Ethernet());
536 if (!network) 647 if (!network)
537 return list; 648 return list;
538 list->Append(BuildNetworkDictionary(network, GetPrefs())); 649 list->Append(BuildNetworkDictionary(network, GetPrefs()));
539 return list; 650 return list;
540 } 651 }
541 652
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 dictionary->SetBoolean( 734 dictionary->SetBoolean(
624 kTagWimaxAvailable, 735 kTagWimaxAvailable,
625 handler->IsTechnologyAvailable(NetworkTypePattern::Wimax())); 736 handler->IsTechnologyAvailable(NetworkTypePattern::Wimax()));
626 dictionary->SetBoolean( 737 dictionary->SetBoolean(
627 kTagWimaxEnabled, 738 kTagWimaxEnabled,
628 handler->IsTechnologyEnabled(NetworkTypePattern::Wimax())); 739 handler->IsTechnologyEnabled(NetworkTypePattern::Wimax()));
629 } 740 }
630 741
631 } // namespace options 742 } // namespace options
632 } // namespace chromeos 743 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698