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

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

Issue 9814030: get rid of old options pages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more fixes Created 8 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/webui/options/chromeos/internet_options_handler.h"
6
7 #include <ctype.h>
8
9 #include <map>
10 #include <string>
11 #include <vector>
12
13 #include "base/base64.h"
14 #include "base/basictypes.h"
15 #include "base/bind.h"
16 #include "base/bind_helpers.h"
17 #include "base/command_line.h"
18 #include "base/i18n/time_formatting.h"
19 #include "base/string16.h"
20 #include "base/string_number_conversions.h"
21 #include "base/stringprintf.h"
22 #include "base/time.h"
23 #include "base/utf_string_conversions.h"
24 #include "base/values.h"
25 #include "chrome/browser/browser_process.h"
26 #include "chrome/browser/chromeos/choose_mobile_network_dialog.h"
27 #include "chrome/browser/chromeos/cros/cros_library.h"
28 #include "chrome/browser/chromeos/cros/network_library.h"
29 #include "chrome/browser/chromeos/cros/onc_constants.h"
30 #include "chrome/browser/chromeos/cros_settings.h"
31 #include "chrome/browser/chromeos/mobile_config.h"
32 #include "chrome/browser/chromeos/options/network_config_view.h"
33 #include "chrome/browser/chromeos/proxy_config_service_impl.h"
34 #include "chrome/browser/chromeos/sim_dialog_delegate.h"
35 #include "chrome/browser/chromeos/status/network_menu_icon.h"
36 #include "chrome/browser/net/pref_proxy_config_tracker.h"
37 #include "chrome/browser/profiles/profile.h"
38 #include "chrome/browser/ui/browser.h"
39 #include "chrome/browser/ui/browser_list.h"
40 #include "chrome/browser/ui/browser_window.h"
41 #include "chrome/browser/ui/dialog_style.h"
42 #include "chrome/browser/ui/views/window.h"
43 #include "chrome/browser/ui/webui/web_ui_util.h"
44 #include "chrome/common/chrome_notification_types.h"
45 #include "chrome/common/chrome_switches.h"
46 #include "chrome/common/time_format.h"
47 #include "content/public/browser/notification_service.h"
48 #include "content/public/browser/web_ui.h"
49 #include "grit/chromium_strings.h"
50 #include "grit/generated_resources.h"
51 #include "grit/locale_settings.h"
52 #include "grit/theme_resources.h"
53 #include "third_party/skia/include/core/SkBitmap.h"
54 #include "ui/base/l10n/l10n_util.h"
55 #include "ui/base/resource/resource_bundle.h"
56 #include "ui/views/widget/widget.h"
57
58 namespace {
59
60 static const char kOtherNetworksFakePath[] = "?";
61
62 // Keys for the network description dictionary passed to the web ui. Make sure
63 // to keep the strings in sync with what the Javascript side uses.
64 const char kNetworkInfoKeyActivationState[] = "activation_state";
65 const char kNetworkInfoKeyConnectable[] = "connectable";
66 const char kNetworkInfoKeyConnected[] = "connected";
67 const char kNetworkInfoKeyConnecting[] = "connecting";
68 const char kNetworkInfoKeyIconURL[] = "iconURL";
69 const char kNetworkInfoKeyNeedsNewPlan[] = "needs_new_plan";
70 const char kNetworkInfoKeyNetworkName[] = "networkName";
71 const char kNetworkInfoKeyNetworkStatus[] = "networkStatus";
72 const char kNetworkInfoKeyNetworkType[] = "networkType";
73 const char kNetworkInfoKeyRemembered[] = "remembered";
74 const char kNetworkInfoKeyServicePath[] = "servicePath";
75 const char kNetworkInfoKeyPolicyManaged[] = "policyManaged";
76
77 // A helper class for building network information dictionaries to be sent to
78 // the webui code.
79 class NetworkInfoDictionary {
80 public:
81 // Initializes the dictionary with default values.
82 NetworkInfoDictionary();
83
84 // Copies in service path, connect{ing|ed|able} flags and connection type from
85 // the provided network object. Also chooses an appropriate icon based on the
86 // network type.
87 explicit NetworkInfoDictionary(const chromeos::Network* network);
88
89 // Initializes a remembered network entry, pulling information from the passed
90 // network object and the corresponding remembered network object. |network|
91 // may be NULL.
92 NetworkInfoDictionary(const chromeos::Network* network,
93 const chromeos::Network* remembered);
94
95 // Setters for filling in information.
96 void set_service_path(const std::string& service_path) {
97 service_path_ = service_path;
98 }
99 void set_icon(const SkBitmap& icon) {
100 icon_url_ = icon.isNull() ? "" : web_ui_util::GetImageDataUrl(icon);
101 }
102 void set_name(const std::string& name) {
103 name_ = name;
104 }
105 void set_connecting(bool connecting) {
106 connecting_ = connecting;
107 }
108 void set_connected(bool connected) {
109 connected_ = connected;
110 }
111 void set_connectable(bool connectable) {
112 connectable_ = connectable;
113 }
114 void set_connection_type(chromeos::ConnectionType connection_type) {
115 connection_type_ = connection_type;
116 }
117 void set_remembered(bool remembered) {
118 remembered_ = remembered;
119 }
120 void set_shared(bool shared) {
121 shared_ = shared;
122 }
123 void set_activation_state(chromeos::ActivationState activation_state) {
124 activation_state_ = activation_state;
125 }
126 void set_needs_new_plan(bool needs_new_plan) {
127 needs_new_plan_ = needs_new_plan;
128 }
129 void set_policy_managed(bool policy_managed) {
130 policy_managed_ = policy_managed;
131 }
132
133 // Builds the DictionaryValue representation from the previously set
134 // parameters. Ownership of the returned pointer is transferred to the caller.
135 DictionaryValue* BuildDictionary();
136
137 private:
138 // Values to be filled into the dictionary.
139 std::string service_path_;
140 std::string icon_url_;
141 std::string name_;
142 bool connecting_;
143 bool connected_;
144 bool connectable_;
145 chromeos::ConnectionType connection_type_;
146 bool remembered_;
147 bool shared_;
148 chromeos::ActivationState activation_state_;
149 bool needs_new_plan_;
150 bool policy_managed_;
151
152 DISALLOW_COPY_AND_ASSIGN(NetworkInfoDictionary);
153 };
154
155 NetworkInfoDictionary::NetworkInfoDictionary() {
156 set_connecting(false);
157 set_connected(false);
158 set_connectable(false);
159 set_remembered(false);
160 set_shared(false);
161 set_activation_state(chromeos::ACTIVATION_STATE_UNKNOWN);
162 set_needs_new_plan(false);
163 set_policy_managed(false);
164 }
165
166 NetworkInfoDictionary::NetworkInfoDictionary(const chromeos::Network* network) {
167 set_service_path(network->service_path());
168 set_icon(chromeos::NetworkMenuIcon::GetBitmap(network,
169 chromeos::NetworkMenuIcon::SIZE_SMALL));
170 set_name(network->name());
171 set_connecting(network->connecting());
172 set_connected(network->connected());
173 set_connectable(network->connectable());
174 set_connection_type(network->type());
175 set_remembered(false);
176 set_shared(false);
177 set_needs_new_plan(false);
178 set_policy_managed(chromeos::NetworkUIData::IsManaged(network->ui_data()));
179 }
180
181 NetworkInfoDictionary::NetworkInfoDictionary(
182 const chromeos::Network* network,
183 const chromeos::Network* remembered) {
184 set_service_path(remembered->service_path());
185 set_icon(chromeos::NetworkMenuIcon::GetBitmap(
186 network ? network : remembered, chromeos::NetworkMenuIcon::SIZE_SMALL));
187 set_name(remembered->name());
188 set_connecting(network ? network->connecting() : false);
189 set_connected(network ? network->connected() : false);
190 set_connectable(true);
191 set_connection_type(remembered->type());
192 set_remembered(true);
193 set_shared(remembered->profile_type() == chromeos::PROFILE_SHARED);
194 set_needs_new_plan(false);
195 set_policy_managed(chromeos::NetworkUIData::IsManaged(remembered->ui_data()));
196 }
197
198 DictionaryValue* NetworkInfoDictionary::BuildDictionary() {
199 std::string status;
200
201 if (remembered_) {
202 if (shared_)
203 status = l10n_util::GetStringUTF8(IDS_OPTIONS_SETTINGS_SHARED_NETWORK);
204 } else {
205 // 802.1X networks can be connected but not have saved credentials, and
206 // hence be "not configured". Give preference to the "connected" and
207 // "connecting" states. http://crosbug.com/14459
208 int connection_state = IDS_STATUSBAR_NETWORK_DEVICE_DISCONNECTED;
209 if (connected_)
210 connection_state = IDS_STATUSBAR_NETWORK_DEVICE_CONNECTED;
211 else if (connecting_)
212 connection_state = IDS_STATUSBAR_NETWORK_DEVICE_CONNECTING;
213 else if (!connectable_)
214 connection_state = IDS_STATUSBAR_NETWORK_DEVICE_NOT_CONFIGURED;
215 status = l10n_util::GetStringUTF8(connection_state);
216 if (connection_type_ == chromeos::TYPE_CELLULAR) {
217 if (needs_new_plan_) {
218 status = l10n_util::GetStringUTF8(IDS_OPTIONS_SETTINGS_NO_PLAN_LABEL);
219 } else if (activation_state_ != chromeos::ACTIVATION_STATE_ACTIVATED) {
220 status.append(" / ");
221 status.append(chromeos::CellularNetwork::ActivationStateToString(
222 activation_state_));
223 }
224 }
225 }
226
227 scoped_ptr<DictionaryValue> network_info(new DictionaryValue());
228 network_info->SetInteger(kNetworkInfoKeyActivationState,
229 static_cast<int>(activation_state_));
230 network_info->SetBoolean(kNetworkInfoKeyConnectable, connectable_);
231 network_info->SetBoolean(kNetworkInfoKeyConnected, connected_);
232 network_info->SetBoolean(kNetworkInfoKeyConnecting, connecting_);
233 network_info->SetString(kNetworkInfoKeyIconURL, icon_url_);
234 network_info->SetBoolean(kNetworkInfoKeyNeedsNewPlan, needs_new_plan_);
235 network_info->SetString(kNetworkInfoKeyNetworkName, name_);
236 network_info->SetString(kNetworkInfoKeyNetworkStatus, status);
237 network_info->SetInteger(kNetworkInfoKeyNetworkType,
238 static_cast<int>(connection_type_));
239 network_info->SetBoolean(kNetworkInfoKeyRemembered, remembered_);
240 network_info->SetString(kNetworkInfoKeyServicePath, service_path_);
241 network_info->SetBoolean(kNetworkInfoKeyPolicyManaged, policy_managed_);
242
243 return network_info.release();
244 }
245
246 } // namespace
247
248 InternetOptionsHandler::InternetOptionsHandler() {
249 registrar_.Add(this, chrome::NOTIFICATION_REQUIRE_PIN_SETTING_CHANGE_ENDED,
250 content::NotificationService::AllSources());
251 registrar_.Add(this, chrome::NOTIFICATION_ENTER_PIN_ENDED,
252 content::NotificationService::AllSources());
253 cros_ = chromeos::CrosLibrary::Get()->GetNetworkLibrary();
254 if (cros_) {
255 cros_->AddNetworkManagerObserver(this);
256 cros_->AddCellularDataPlanObserver(this);
257 MonitorNetworks();
258 }
259 }
260
261 InternetOptionsHandler::~InternetOptionsHandler() {
262 if (cros_) {
263 cros_->RemoveNetworkManagerObserver(this);
264 cros_->RemoveCellularDataPlanObserver(this);
265 cros_->RemoveObserverForAllNetworks(this);
266 }
267 }
268
269 void InternetOptionsHandler::GetLocalizedValues(
270 DictionaryValue* localized_strings) {
271 DCHECK(localized_strings);
272
273 RegisterTitle(localized_strings, "internetPage",
274 IDS_OPTIONS_INTERNET_TAB_LABEL);
275
276 localized_strings->SetString("wired_title",
277 l10n_util::GetStringUTF16(
278 IDS_OPTIONS_SETTINGS_SECTION_TITLE_WIRED_NETWORK));
279 localized_strings->SetString("wireless_title",
280 l10n_util::GetStringUTF16(
281 IDS_OPTIONS_SETTINGS_SECTION_TITLE_WIRELESS_NETWORK));
282 localized_strings->SetString("vpn_title",
283 l10n_util::GetStringUTF16(
284 IDS_OPTIONS_SETTINGS_SECTION_TITLE_VIRTUAL_NETWORK));
285 localized_strings->SetString("remembered_title",
286 l10n_util::GetStringUTF16(
287 IDS_OPTIONS_SETTINGS_SECTION_TITLE_REMEMBERED_NETWORK));
288
289 localized_strings->SetString("connect_button",
290 l10n_util::GetStringUTF16(
291 IDS_OPTIONS_SETTINGS_CONNECT));
292 localized_strings->SetString("disconnect_button",
293 l10n_util::GetStringUTF16(
294 IDS_OPTIONS_SETTINGS_DISCONNECT));
295 localized_strings->SetString("options_button",
296 l10n_util::GetStringUTF16(
297 IDS_OPTIONS_SETTINGS_OPTIONS));
298 localized_strings->SetString("forget_button",
299 l10n_util::GetStringUTF16(
300 IDS_OPTIONS_SETTINGS_FORGET));
301 localized_strings->SetString("activate_button",
302 l10n_util::GetStringUTF16(
303 IDS_OPTIONS_SETTINGS_ACTIVATE));
304 localized_strings->SetString("buyplan_button",
305 l10n_util::GetStringUTF16(
306 IDS_OPTIONS_SETTINGS_BUY_PLAN));
307 localized_strings->SetString("view_account_button",
308 l10n_util::GetStringUTF16(
309 IDS_STATUSBAR_NETWORK_VIEW_ACCOUNT));
310
311 localized_strings->SetString("changeProxyButton",
312 l10n_util::GetStringUTF16(
313 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CHANGE_PROXY_BUTTON));
314
315 localized_strings->SetString("managedNetwork",
316 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_MANAGED_NETWORK));
317
318 localized_strings->SetString("wifiNetworkTabLabel",
319 l10n_util::GetStringUTF16(
320 IDS_OPTIONS_SETTINGS_INTERNET_TAB_WIFI));
321 localized_strings->SetString("vpnTabLabel",
322 l10n_util::GetStringUTF16(
323 IDS_OPTIONS_SETTINGS_INTERNET_TAB_VPN));
324 localized_strings->SetString("cellularPlanTabLabel",
325 l10n_util::GetStringUTF16(
326 IDS_OPTIONS_SETTINGS_INTERNET_TAB_PLAN));
327 localized_strings->SetString("cellularConnTabLabel",
328 l10n_util::GetStringUTF16(
329 IDS_OPTIONS_SETTINGS_INTERNET_TAB_CONNECTION));
330 localized_strings->SetString("cellularDeviceTabLabel",
331 l10n_util::GetStringUTF16(
332 IDS_OPTIONS_SETTINGS_INTERNET_TAB_DEVICE));
333 localized_strings->SetString("networkTabLabel",
334 l10n_util::GetStringUTF16(
335 IDS_OPTIONS_SETTINGS_INTERNET_TAB_NETWORK));
336 localized_strings->SetString("securityTabLabel",
337 l10n_util::GetStringUTF16(
338 IDS_OPTIONS_SETTINGS_INTERNET_TAB_SECURITY));
339
340 localized_strings->SetString("useDHCP",
341 l10n_util::GetStringUTF16(
342 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_USE_DHCP));
343 localized_strings->SetString("useStaticIP",
344 l10n_util::GetStringUTF16(
345 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_USE_STATIC_IP));
346 localized_strings->SetString("connectionState",
347 l10n_util::GetStringUTF16(
348 IDS_OPTIONS_SETTINGS_INTERNET_CONNECTION_STATE));
349 localized_strings->SetString("inetAddress",
350 l10n_util::GetStringUTF16(
351 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_ADDRESS));
352 localized_strings->SetString("inetSubnetAddress",
353 l10n_util::GetStringUTF16(
354 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SUBNETMASK));
355 localized_strings->SetString("inetGateway",
356 l10n_util::GetStringUTF16(
357 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_GATEWAY));
358 localized_strings->SetString("inetDns",
359 l10n_util::GetStringUTF16(
360 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_DNSSERVER));
361 localized_strings->SetString("hardwareAddress",
362 l10n_util::GetStringUTF16(
363 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_HARDWARE_ADDRESS));
364
365 // Wifi Tab.
366 localized_strings->SetString("accessLockedMsg",
367 l10n_util::GetStringUTF16(
368 IDS_STATUSBAR_NETWORK_LOCKED));
369 localized_strings->SetString("inetSsid",
370 l10n_util::GetStringUTF16(
371 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_NETWORK_ID));
372 localized_strings->SetString("inetPassProtected",
373 l10n_util::GetStringUTF16(
374 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_NET_PROTECTED));
375 localized_strings->SetString("inetNetworkShared",
376 l10n_util::GetStringUTF16(
377 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_NETWORK_SHARED));
378 localized_strings->SetString("inetPreferredNetwork",
379 l10n_util::GetStringUTF16(
380 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PREFER_NETWORK));
381 localized_strings->SetString("inetAutoConnectNetwork",
382 l10n_util::GetStringUTF16(
383 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_AUTO_CONNECT));
384 localized_strings->SetString("inetLogin",
385 l10n_util::GetStringUTF16(
386 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_LOGIN));
387 localized_strings->SetString("inetShowPass",
388 l10n_util::GetStringUTF16(
389 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SHOWPASSWORD));
390 localized_strings->SetString("inetPassPrompt",
391 l10n_util::GetStringUTF16(
392 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PASSWORD));
393 localized_strings->SetString("inetSsidPrompt",
394 l10n_util::GetStringUTF16(
395 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SSID));
396 localized_strings->SetString("inetStatus",
397 l10n_util::GetStringUTF16(
398 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_STATUS_TITLE));
399 localized_strings->SetString("inetConnect",
400 l10n_util::GetStringUTF16(
401 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CONNECT_TITLE));
402
403 // VPN Tab.
404 localized_strings->SetString("inetServiceName",
405 l10n_util::GetStringUTF16(
406 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_SERVICE_NAME));
407 localized_strings->SetString("inetServerHostname",
408 l10n_util::GetStringUTF16(
409 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_SERVER_HOSTNAME));
410 localized_strings->SetString("inetProviderType",
411 l10n_util::GetStringUTF16(
412 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_PROVIDER_TYPE));
413 localized_strings->SetString("inetUsername",
414 l10n_util::GetStringUTF16(
415 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_USERNAME));
416
417 // Cellular Tab.
418 localized_strings->SetString("serviceName",
419 l10n_util::GetStringUTF16(
420 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_SERVICE_NAME));
421 localized_strings->SetString("networkTechnology",
422 l10n_util::GetStringUTF16(
423 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_NETWORK_TECHNOLOGY));
424 localized_strings->SetString("operatorName",
425 l10n_util::GetStringUTF16(
426 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_OPERATOR));
427 localized_strings->SetString("operatorCode",
428 l10n_util::GetStringUTF16(
429 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_OPERATOR_CODE));
430 localized_strings->SetString("activationState",
431 l10n_util::GetStringUTF16(
432 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_ACTIVATION_STATE));
433 localized_strings->SetString("roamingState",
434 l10n_util::GetStringUTF16(
435 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_ROAMING_STATE));
436 localized_strings->SetString("restrictedPool",
437 l10n_util::GetStringUTF16(
438 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_RESTRICTED_POOL));
439 localized_strings->SetString("errorState",
440 l10n_util::GetStringUTF16(
441 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_ERROR_STATE));
442 localized_strings->SetString("manufacturer",
443 l10n_util::GetStringUTF16(
444 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_MANUFACTURER));
445 localized_strings->SetString("modelId",
446 l10n_util::GetStringUTF16(
447 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_MODEL_ID));
448 localized_strings->SetString("firmwareRevision",
449 l10n_util::GetStringUTF16(
450 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_FIRMWARE_REVISION));
451 localized_strings->SetString("hardwareRevision",
452 l10n_util::GetStringUTF16(
453 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_HARDWARE_REVISION));
454 localized_strings->SetString("prlVersion",
455 l10n_util::GetStringUTF16(
456 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_PRL_VERSION));
457 localized_strings->SetString("cellularApnLabel",
458 l10n_util::GetStringUTF16(
459 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_APN));
460 localized_strings->SetString("cellularApnOther",
461 l10n_util::GetStringUTF16(
462 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_APN_OTHER));
463 localized_strings->SetString("cellularApnUsername",
464 l10n_util::GetStringUTF16(
465 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_APN_USERNAME));
466 localized_strings->SetString("cellularApnPassword",
467 l10n_util::GetStringUTF16(
468 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_APN_PASSWORD));
469 localized_strings->SetString("cellularApnUseDefault",
470 l10n_util::GetStringUTF16(
471 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_APN_CLEAR));
472 localized_strings->SetString("cellularApnSet",
473 l10n_util::GetStringUTF16(
474 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_APN_SET));
475 localized_strings->SetString("cellularApnCancel",
476 l10n_util::GetStringUTF16(
477 IDS_CANCEL));
478
479 localized_strings->SetString("accessSecurityTabLink",
480 l10n_util::GetStringUTF16(
481 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_ACCESS_SECURITY_TAB));
482 localized_strings->SetString("lockSimCard",
483 l10n_util::GetStringUTF16(
484 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_LOCK_SIM_CARD));
485 localized_strings->SetString("changePinButton",
486 l10n_util::GetStringUTF16(
487 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_CHANGE_PIN_BUTTON));
488
489 localized_strings->SetString("planName",
490 l10n_util::GetStringUTF16(
491 IDS_OPTIONS_SETTINGS_INTERNET_CELL_PLAN_NAME));
492 localized_strings->SetString("planLoading",
493 l10n_util::GetStringUTF16(
494 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_LOADING_PLAN));
495 localized_strings->SetString("noPlansFound",
496 l10n_util::GetStringUTF16(
497 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_NO_PLANS_FOUND));
498 localized_strings->SetString("purchaseMore",
499 l10n_util::GetStringUTF16(
500 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PURCHASE_MORE));
501 localized_strings->SetString("dataRemaining",
502 l10n_util::GetStringUTF16(
503 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_DATA_REMAINING));
504 localized_strings->SetString("planExpires",
505 l10n_util::GetStringUTF16(
506 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_EXPIRES));
507 localized_strings->SetString("showPlanNotifications",
508 l10n_util::GetStringUTF16(
509 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SHOW_MOBILE_NOTIFICATION));
510 localized_strings->SetString("autoconnectCellular",
511 l10n_util::GetStringUTF16(
512 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_AUTO_CONNECT));
513 localized_strings->SetString("customerSupport",
514 l10n_util::GetStringUTF16(
515 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CUSTOMER_SUPPORT));
516
517 localized_strings->SetString("enableWifi",
518 l10n_util::GetStringFUTF16(
519 IDS_STATUSBAR_NETWORK_DEVICE_ENABLE,
520 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_WIFI)));
521 localized_strings->SetString("disableWifi",
522 l10n_util::GetStringFUTF16(
523 IDS_STATUSBAR_NETWORK_DEVICE_DISABLE,
524 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_WIFI)));
525 localized_strings->SetString("enableCellular",
526 l10n_util::GetStringFUTF16(
527 IDS_STATUSBAR_NETWORK_DEVICE_ENABLE,
528 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_CELLULAR)));
529 localized_strings->SetString("disableCellular",
530 l10n_util::GetStringFUTF16(
531 IDS_STATUSBAR_NETWORK_DEVICE_DISABLE,
532 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_CELLULAR)));
533 localized_strings->SetString("useSharedProxies",
534 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_USE_SHARED_PROXIES));
535 localized_strings->SetString("enableDataRoaming",
536 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_ENABLE_DATA_ROAMING));
537 localized_strings->SetString("generalNetworkingTitle",
538 l10n_util::GetStringUTF16(
539 IDS_OPTIONS_SETTINGS_INTERNET_CONTROL_TITLE));
540 localized_strings->SetString("detailsInternetDismiss",
541 l10n_util::GetStringUTF16(IDS_CLOSE));
542 localized_strings->SetString("ownerOnly", l10n_util::GetStringUTF16(
543 IDS_OPTIONS_ACCOUNTS_OWNER_ONLY));
544 std::string owner;
545 chromeos::CrosSettings::Get()->GetString(chromeos::kDeviceOwner, &owner);
546 localized_strings->SetString("ownerUserId", UTF8ToUTF16(owner));
547
548 FillNetworkInfo(localized_strings);
549 }
550
551 void InternetOptionsHandler::InitializeHandler() {
552 cros_->RequestNetworkScan();
553 }
554
555 void InternetOptionsHandler::RegisterMessages() {
556 // Setup handlers specific to this panel.
557 web_ui()->RegisterMessageCallback("buttonClickCallback",
558 base::Bind(&InternetOptionsHandler::ButtonClickCallback,
559 base::Unretained(this)));
560 web_ui()->RegisterMessageCallback("refreshCellularPlan",
561 base::Bind(&InternetOptionsHandler::RefreshCellularPlanCallback,
562 base::Unretained(this)));
563 web_ui()->RegisterMessageCallback("setPreferNetwork",
564 base::Bind(&InternetOptionsHandler::SetPreferNetworkCallback,
565 base::Unretained(this)));
566 web_ui()->RegisterMessageCallback("setAutoConnect",
567 base::Bind(&InternetOptionsHandler::SetAutoConnectCallback,
568 base::Unretained(this)));
569 web_ui()->RegisterMessageCallback("setIPConfig",
570 base::Bind(&InternetOptionsHandler::SetIPConfigCallback,
571 base::Unretained(this)));
572 web_ui()->RegisterMessageCallback("enableWifi",
573 base::Bind(&InternetOptionsHandler::EnableWifiCallback,
574 base::Unretained(this)));
575 web_ui()->RegisterMessageCallback("disableWifi",
576 base::Bind(&InternetOptionsHandler::DisableWifiCallback,
577 base::Unretained(this)));
578 web_ui()->RegisterMessageCallback("enableCellular",
579 base::Bind(&InternetOptionsHandler::EnableCellularCallback,
580 base::Unretained(this)));
581 web_ui()->RegisterMessageCallback("disableCellular",
582 base::Bind(&InternetOptionsHandler::DisableCellularCallback,
583 base::Unretained(this)));
584 web_ui()->RegisterMessageCallback("buyDataPlan",
585 base::Bind(&InternetOptionsHandler::BuyDataPlanCallback,
586 base::Unretained(this)));
587 web_ui()->RegisterMessageCallback("showMorePlanInfo",
588 base::Bind(&InternetOptionsHandler::ShowMorePlanInfoCallback,
589 base::Unretained(this)));
590 web_ui()->RegisterMessageCallback("setApn",
591 base::Bind(&InternetOptionsHandler::SetApnCallback,
592 base::Unretained(this)));
593 web_ui()->RegisterMessageCallback("setSimCardLock",
594 base::Bind(&InternetOptionsHandler::SetSimCardLockCallback,
595 base::Unretained(this)));
596 web_ui()->RegisterMessageCallback("changePin",
597 base::Bind(&InternetOptionsHandler::ChangePinCallback,
598 base::Unretained(this)));
599 }
600
601 void InternetOptionsHandler::EnableWifiCallback(const ListValue* args) {
602 cros_->EnableWifiNetworkDevice(true);
603 }
604
605 void InternetOptionsHandler::DisableWifiCallback(const ListValue* args) {
606 cros_->EnableWifiNetworkDevice(false);
607 }
608
609 void InternetOptionsHandler::EnableCellularCallback(const ListValue* args) {
610 const chromeos::NetworkDevice* cellular = cros_->FindCellularDevice();
611 if (!cellular) {
612 LOG(ERROR) << "Didn't find cellular device, it should have been available.";
613 cros_->EnableCellularNetworkDevice(true);
614 } else if (cellular->sim_lock_state() == chromeos::SIM_UNLOCKED ||
615 cellular->sim_lock_state() == chromeos::SIM_UNKNOWN) {
616 cros_->EnableCellularNetworkDevice(true);
617 } else {
618 chromeos::SimDialogDelegate::ShowDialog(GetNativeWindow(),
619 chromeos::SimDialogDelegate::SIM_DIALOG_UNLOCK);
620 }
621 }
622
623 void InternetOptionsHandler::DisableCellularCallback(const ListValue* args) {
624 cros_->EnableCellularNetworkDevice(false);
625 }
626
627 void InternetOptionsHandler::ShowMorePlanInfoCallback(const ListValue* args) {
628 if (!web_ui())
629 return;
630 Browser* browser = BrowserList::FindBrowserWithFeature(
631 Profile::FromWebUI(web_ui()), Browser::FEATURE_TABSTRIP);
632 if (!browser)
633 return;
634
635 const chromeos::CellularNetwork* cellular = cros_->cellular_network();
636 if (!cellular)
637 return;
638
639 browser->OpenURL(content::OpenURLParams(
640 cellular->GetAccountInfoUrl(), content::Referrer(),
641 NEW_FOREGROUND_TAB,
642 content::PAGE_TRANSITION_LINK, false));
643 }
644
645 void InternetOptionsHandler::BuyDataPlanCallback(const ListValue* args) {
646 if (!web_ui())
647 return;
648 Browser* browser = BrowserList::FindBrowserWithFeature(
649 Profile::FromWebUI(web_ui()), Browser::FEATURE_TABSTRIP);
650 if (browser)
651 browser->OpenMobilePlanTabAndActivate();
652 }
653
654 void InternetOptionsHandler::SetApnCallback(const ListValue* args) {
655 std::string service_path;
656 std::string apn;
657 std::string username;
658 std::string password;
659 if (args->GetSize() != 4 ||
660 !args->GetString(0, &service_path) ||
661 !args->GetString(1, &apn) ||
662 !args->GetString(2, &username) ||
663 !args->GetString(3, &password)) {
664 NOTREACHED();
665 return;
666 }
667
668 chromeos::CellularNetwork* network =
669 cros_->FindCellularNetworkByPath(service_path);
670 if (network) {
671 network->SetApn(chromeos::CellularApn(
672 apn, network->apn().network_id, username, password));
673 }
674 }
675
676 void InternetOptionsHandler::SetSimCardLockCallback(const ListValue* args) {
677 bool require_pin_new_value;
678 if (!args->GetBoolean(0, &require_pin_new_value)) {
679 NOTREACHED();
680 return;
681 }
682 // 1. Bring up SIM unlock dialog, pass new RequirePin setting in URL.
683 // 2. Dialog will ask for current PIN in any case.
684 // 3. If card is locked it will first call PIN unlock operation
685 // 4. Then it will call Set RequirePin, passing the same PIN.
686 // 5. We'll get notified by REQUIRE_PIN_SETTING_CHANGE_ENDED notification.
687 chromeos::SimDialogDelegate::SimDialogMode mode;
688 if (require_pin_new_value)
689 mode = chromeos::SimDialogDelegate::SIM_DIALOG_SET_LOCK_ON;
690 else
691 mode = chromeos::SimDialogDelegate::SIM_DIALOG_SET_LOCK_OFF;
692 chromeos::SimDialogDelegate::ShowDialog(GetNativeWindow(), mode);
693 }
694
695 void InternetOptionsHandler::ChangePinCallback(const ListValue* args) {
696 chromeos::SimDialogDelegate::ShowDialog(GetNativeWindow(),
697 chromeos::SimDialogDelegate::SIM_DIALOG_CHANGE_PIN);
698 }
699
700 void InternetOptionsHandler::RefreshNetworkData() {
701 DictionaryValue dictionary;
702 FillNetworkInfo(&dictionary);
703 web_ui()->CallJavascriptFunction(
704 "options.InternetOptions.refreshNetworkData", dictionary);
705 }
706
707 void InternetOptionsHandler::OnNetworkManagerChanged(
708 chromeos::NetworkLibrary* cros) {
709 if (!web_ui())
710 return;
711 MonitorNetworks();
712 RefreshNetworkData();
713 }
714
715 void InternetOptionsHandler::OnNetworkChanged(
716 chromeos::NetworkLibrary* cros,
717 const chromeos::Network* network) {
718 if (web_ui())
719 RefreshNetworkData();
720 }
721
722 // Monitor wireless networks for changes. It is only necessary
723 // to set up individual observers for the cellular networks
724 // (if any) and for the connected Wi-Fi network (if any). The
725 // only change we are interested in for Wi-Fi networks is signal
726 // strength. For non-connected Wi-Fi networks, all information is
727 // reported via scan results, which trigger network manager
728 // updates. Only the connected Wi-Fi network has changes reported
729 // via service property updates.
730 void InternetOptionsHandler::MonitorNetworks() {
731 cros_->RemoveObserverForAllNetworks(this);
732 const chromeos::WifiNetwork* wifi_network = cros_->wifi_network();
733 if (wifi_network)
734 cros_->AddNetworkObserver(wifi_network->service_path(), this);
735 // Always monitor the cellular networks, if any, so that changes
736 // in network technology, roaming status, and signal strength
737 // will be shown.
738 const chromeos::CellularNetworkVector& cell_networks =
739 cros_->cellular_networks();
740 for (size_t i = 0; i < cell_networks.size(); ++i) {
741 chromeos::CellularNetwork* cell_network = cell_networks[i];
742 cros_->AddNetworkObserver(cell_network->service_path(), this);
743 }
744 const chromeos::VirtualNetwork* virtual_network = cros_->virtual_network();
745 if (virtual_network)
746 cros_->AddNetworkObserver(virtual_network->service_path(), this);
747 }
748
749 void InternetOptionsHandler::OnCellularDataPlanChanged(
750 chromeos::NetworkLibrary* cros) {
751 if (!web_ui())
752 return;
753 const chromeos::CellularNetwork* cellular = cros_->cellular_network();
754 if (!cellular)
755 return;
756 const chromeos::CellularDataPlanVector* plans =
757 cros_->GetDataPlans(cellular->service_path());
758 DictionaryValue connection_plans;
759 ListValue* plan_list = new ListValue();
760 if (plans) {
761 for (chromeos::CellularDataPlanVector::const_iterator iter = plans->begin();
762 iter != plans->end(); ++iter) {
763 plan_list->Append(CellularDataPlanToDictionary(*iter));
764 }
765 }
766 connection_plans.SetString("servicePath", cellular->service_path());
767 connection_plans.SetBoolean("needsPlan", cellular->needs_new_plan());
768 connection_plans.SetBoolean("activated",
769 cellular->activation_state() == chromeos::ACTIVATION_STATE_ACTIVATED);
770 connection_plans.Set("plans", plan_list);
771 SetActivationButtonVisibility(cellular,
772 &connection_plans,
773 cros_->GetCellularHomeCarrierId());
774 web_ui()->CallJavascriptFunction(
775 "options.InternetOptions.updateCellularPlans", connection_plans);
776 }
777
778
779 void InternetOptionsHandler::Observe(
780 int type,
781 const content::NotificationSource& source,
782 const content::NotificationDetails& details) {
783 OptionsPageUIHandler::Observe(type, source, details);
784 if (type == chrome::NOTIFICATION_REQUIRE_PIN_SETTING_CHANGE_ENDED) {
785 base::FundamentalValue require_pin(*content::Details<bool>(details).ptr());
786 web_ui()->CallJavascriptFunction(
787 "options.InternetOptions.updateSecurityTab", require_pin);
788 } else if (type == chrome::NOTIFICATION_ENTER_PIN_ENDED) {
789 // We make an assumption (which is valid for now) that the SIM
790 // unlock dialog is put up only when the user is trying to enable
791 // mobile data.
792 bool cancelled = *content::Details<bool>(details).ptr();
793 if (cancelled) {
794 base::DictionaryValue dictionary;
795 FillNetworkInfo(&dictionary);
796 web_ui()->CallJavascriptFunction(
797 "options.InternetOptions.setupAttributes", dictionary);
798 }
799 // The case in which the correct PIN was entered and the SIM is
800 // now unlocked is handled in NetworkMenuButton.
801 }
802 }
803
804 DictionaryValue* InternetOptionsHandler::CellularDataPlanToDictionary(
805 const chromeos::CellularDataPlan* plan) {
806 DictionaryValue* plan_dict = new DictionaryValue();
807 plan_dict->SetInteger("planType", plan->plan_type);
808 plan_dict->SetString("name", plan->plan_name);
809 plan_dict->SetString("planSummary", plan->GetPlanDesciption());
810 plan_dict->SetString("dataRemaining", plan->GetDataRemainingDesciption());
811 plan_dict->SetString("planExpires", plan->GetPlanExpiration());
812 plan_dict->SetString("warning", plan->GetRemainingWarning());
813 return plan_dict;
814 }
815
816 void InternetOptionsHandler::SetPreferNetworkCallback(const ListValue* args) {
817 std::string service_path;
818 std::string prefer_network_str;
819
820 if (args->GetSize() < 2 ||
821 !args->GetString(0, &service_path) ||
822 !args->GetString(1, &prefer_network_str)) {
823 NOTREACHED();
824 return;
825 }
826
827 chromeos::Network* network = cros_->FindNetworkByPath(service_path);
828 if (!network)
829 return;
830
831 bool prefer_network = prefer_network_str == "true";
832 if (prefer_network != network->preferred())
833 network->SetPreferred(prefer_network);
834 }
835
836 void InternetOptionsHandler::SetAutoConnectCallback(const ListValue* args) {
837 std::string service_path;
838 std::string auto_connect_str;
839
840 if (args->GetSize() < 2 ||
841 !args->GetString(0, &service_path) ||
842 !args->GetString(1, &auto_connect_str)) {
843 NOTREACHED();
844 return;
845 }
846
847 chromeos::Network* network = cros_->FindNetworkByPath(service_path);
848 if (!network)
849 return;
850
851 bool auto_connect = auto_connect_str == "true";
852 if (auto_connect != network->auto_connect())
853 network->SetAutoConnect(auto_connect);
854 }
855
856 void InternetOptionsHandler::SetIPConfigCallback(const ListValue* args) {
857 std::string service_path;
858 std::string dhcp_str;
859 std::string address;
860 std::string netmask;
861 std::string gateway;
862 std::string name_servers;
863
864 if (args->GetSize() < 6 ||
865 !args->GetString(0, &service_path) ||
866 !args->GetString(1, &dhcp_str) ||
867 !args->GetString(2, &address) ||
868 !args->GetString(3, &netmask) ||
869 !args->GetString(4, &gateway) ||
870 !args->GetString(5, &name_servers)) {
871 NOTREACHED();
872 return;
873 }
874
875 chromeos::Network* network = cros_->FindNetworkByPath(service_path);
876 if (!network)
877 return;
878
879 cros_->SetIPConfig(chromeos::NetworkIPConfig(network->device_path(),
880 dhcp_str == "true" ? chromeos::IPCONFIG_TYPE_DHCP :
881 chromeos::IPCONFIG_TYPE_IPV4,
882 address, netmask, gateway, name_servers));
883 }
884
885 void InternetOptionsHandler::PopulateDictionaryDetails(
886 const chromeos::Network* network) {
887 DCHECK(network);
888
889 if (web_ui()) {
890 Profile::FromWebUI(web_ui())->GetProxyConfigTracker()->UISetCurrentNetwork(
891 network->service_path());
892 }
893
894 const base::DictionaryValue* ui_data = network->ui_data();
895 const base::DictionaryValue* onc =
896 cros_->FindOncForNetwork(network->unique_id());
897
898 DictionaryValue dictionary;
899 std::string hardware_address;
900 chromeos::NetworkIPConfigVector ipconfigs = cros_->GetIPConfigs(
901 network->device_path(), &hardware_address,
902 chromeos::NetworkLibrary::FORMAT_COLON_SEPARATED_HEX);
903 if (!hardware_address.empty())
904 dictionary.SetString("hardwareAddress", hardware_address);
905
906 scoped_ptr<DictionaryValue> ipconfig_dhcp;
907 scoped_ptr<DictionaryValue> ipconfig_static;
908 for (chromeos::NetworkIPConfigVector::const_iterator it = ipconfigs.begin();
909 it != ipconfigs.end(); ++it) {
910 const chromeos::NetworkIPConfig& ipconfig = *it;
911 scoped_ptr<DictionaryValue> ipconfig_dict(new DictionaryValue());
912 ipconfig_dict->SetString("address", ipconfig.address);
913 ipconfig_dict->SetString("subnetAddress", ipconfig.netmask);
914 ipconfig_dict->SetString("gateway", ipconfig.gateway);
915 ipconfig_dict->SetString("dns", ipconfig.name_servers);
916 if (ipconfig.type == chromeos::IPCONFIG_TYPE_DHCP)
917 ipconfig_dhcp.reset(ipconfig_dict.release());
918 else if (ipconfig.type == chromeos::IPCONFIG_TYPE_IPV4)
919 ipconfig_static.reset(ipconfig_dict.release());
920 }
921
922 chromeos::NetworkPropertyUIData ipconfig_dhcp_ui_data(ui_data);
923 SetValueDictionary(&dictionary, "ipconfigDHCP", ipconfig_dhcp.release(),
924 ipconfig_dhcp_ui_data);
925 chromeos::NetworkPropertyUIData ipconfig_static_ui_data(ui_data);
926 SetValueDictionary(&dictionary, "ipconfigStatic", ipconfig_static.release(),
927 ipconfig_static_ui_data);
928
929 chromeos::ConnectionType type = network->type();
930 dictionary.SetInteger("type", type);
931 dictionary.SetString("servicePath", network->service_path());
932 dictionary.SetBoolean("connecting", network->connecting());
933 dictionary.SetBoolean("connected", network->connected());
934 dictionary.SetString("connectionState", network->GetStateString());
935
936 // Only show proxy for remembered networks.
937 chromeos::NetworkProfileType network_profile = network->profile_type();
938 dictionary.SetBoolean("showProxy", network_profile != chromeos::PROFILE_NONE);
939
940 // Hide the dhcp/static radio if not ethernet or wifi (or if not enabled)
941 bool staticIPConfig = CommandLine::ForCurrentProcess()->HasSwitch(
942 switches::kEnableStaticIPConfig);
943 dictionary.SetBoolean("showStaticIPConfig", staticIPConfig &&
944 (type == chromeos::TYPE_WIFI || type == chromeos::TYPE_ETHERNET));
945
946 chromeos::NetworkPropertyUIData preferred_ui_data(ui_data);
947 if (network_profile == chromeos::PROFILE_USER) {
948 dictionary.SetBoolean("showPreferred", true);
949 SetValueDictionary(&dictionary, "preferred",
950 Value::CreateBooleanValue(network->preferred()),
951 preferred_ui_data);
952 } else {
953 dictionary.SetBoolean("showPreferred", false);
954 SetValueDictionary(&dictionary, "preferred",
955 Value::CreateBooleanValue(network->preferred()),
956 preferred_ui_data);
957 }
958 chromeos::NetworkPropertyUIData auto_connect_ui_data(ui_data);
959 if (type == chromeos::TYPE_WIFI)
960 auto_connect_ui_data.ParseOncProperty(
961 ui_data, onc,
962 base::StringPrintf("%s.%s",
963 chromeos::onc::kWiFi,
964 chromeos::onc::wifi::kAutoConnect));
965 SetValueDictionary(&dictionary, "autoConnect",
966 Value::CreateBooleanValue(network->auto_connect()),
967 auto_connect_ui_data);
968
969 if (type == chromeos::TYPE_WIFI) {
970 dictionary.SetBoolean("deviceConnected", cros_->wifi_connected());
971 const chromeos::WifiNetwork* wifi =
972 cros_->FindWifiNetworkByPath(network->service_path());
973 if (!wifi) {
974 LOG(WARNING) << "Cannot find network " << network->service_path();
975 } else {
976 PopulateWifiDetails(wifi, &dictionary);
977 }
978 } else if (type == chromeos::TYPE_CELLULAR) {
979 dictionary.SetBoolean("deviceConnected", cros_->cellular_connected());
980 const chromeos::CellularNetwork* cellular =
981 cros_->FindCellularNetworkByPath(network->service_path());
982 if (!cellular) {
983 LOG(WARNING) << "Cannot find network " << network->service_path();
984 } else {
985 PopulateCellularDetails(cellular, &dictionary);
986 }
987 } else if (type == chromeos::TYPE_VPN) {
988 dictionary.SetBoolean("deviceConnected",
989 cros_->virtual_network_connected());
990 const chromeos::VirtualNetwork* vpn =
991 cros_->FindVirtualNetworkByPath(network->service_path());
992 if (!vpn) {
993 LOG(WARNING) << "Cannot find network " << network->service_path();
994 } else {
995 PopulateVPNDetails(vpn, &dictionary);
996 }
997 } else if (type == chromeos::TYPE_ETHERNET) {
998 dictionary.SetBoolean("deviceConnected", cros_->ethernet_connected());
999 }
1000
1001 web_ui()->CallJavascriptFunction(
1002 "options.InternetOptions.showDetailedInfo", dictionary);
1003 }
1004
1005 void InternetOptionsHandler::PopulateWifiDetails(
1006 const chromeos::WifiNetwork* wifi,
1007 DictionaryValue* dictionary) {
1008 dictionary->SetString("ssid", wifi->name());
1009 bool remembered = (wifi->profile_type() != chromeos::PROFILE_NONE);
1010 dictionary->SetBoolean("remembered", remembered);
1011 dictionary->SetBoolean("encrypted", wifi->encrypted());
1012 bool shared = wifi->profile_type() == chromeos::PROFILE_SHARED;
1013 dictionary->SetBoolean("shared", shared);
1014 }
1015
1016 DictionaryValue* InternetOptionsHandler::CreateDictionaryFromCellularApn(
1017 const chromeos::CellularApn& apn) {
1018 DictionaryValue* dictionary = new DictionaryValue();
1019 dictionary->SetString("apn", apn.apn);
1020 dictionary->SetString("networkId", apn.network_id);
1021 dictionary->SetString("username", apn.username);
1022 dictionary->SetString("password", apn.password);
1023 dictionary->SetString("name", apn.name);
1024 dictionary->SetString("localizedName", apn.localized_name);
1025 dictionary->SetString("language", apn.language);
1026 return dictionary;
1027 }
1028
1029 void InternetOptionsHandler::PopulateCellularDetails(
1030 const chromeos::CellularNetwork* cellular,
1031 DictionaryValue* dictionary) {
1032 // Cellular network / connection settings.
1033 dictionary->SetString("serviceName", cellular->name());
1034 dictionary->SetString("networkTechnology",
1035 cellular->GetNetworkTechnologyString());
1036 dictionary->SetString("operatorName", cellular->operator_name());
1037 dictionary->SetString("operatorCode", cellular->operator_code());
1038 dictionary->SetString("activationState",
1039 cellular->GetActivationStateString());
1040 dictionary->SetString("roamingState",
1041 cellular->GetRoamingStateString());
1042 dictionary->SetString("restrictedPool",
1043 cellular->restricted_pool() ?
1044 l10n_util::GetStringUTF8(
1045 IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL) :
1046 l10n_util::GetStringUTF8(
1047 IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL));
1048 dictionary->SetString("errorState", cellular->GetErrorString());
1049 dictionary->SetString("supportUrl", cellular->payment_url());
1050 dictionary->SetBoolean("needsPlan", cellular->needs_new_plan());
1051
1052 dictionary->Set("apn", CreateDictionaryFromCellularApn(cellular->apn()));
1053 dictionary->Set("lastGoodApn",
1054 CreateDictionaryFromCellularApn(cellular->last_good_apn()));
1055
1056 // Device settings.
1057 const chromeos::NetworkDevice* device =
1058 cros_->FindNetworkDeviceByPath(cellular->device_path());
1059 if (device) {
1060 chromeos::NetworkPropertyUIData cellular_propety_ui_data(
1061 cellular->ui_data());
1062 dictionary->SetString("manufacturer", device->manufacturer());
1063 dictionary->SetString("modelId", device->model_id());
1064 dictionary->SetString("firmwareRevision", device->firmware_revision());
1065 dictionary->SetString("hardwareRevision", device->hardware_revision());
1066 dictionary->SetString("prlVersion",
1067 base::StringPrintf("%u", device->prl_version()));
1068 dictionary->SetString("meid", device->meid());
1069 dictionary->SetString("imei", device->imei());
1070 dictionary->SetString("mdn", device->mdn());
1071 dictionary->SetString("imsi", device->imsi());
1072 dictionary->SetString("esn", device->esn());
1073 dictionary->SetString("min", device->min());
1074 dictionary->SetBoolean("gsm",
1075 device->technology_family() == chromeos::TECHNOLOGY_FAMILY_GSM);
1076 SetValueDictionary(
1077 dictionary, "simCardLockEnabled",
1078 Value::CreateBooleanValue(
1079 device->sim_pin_required() == chromeos::SIM_PIN_REQUIRED),
1080 cellular_propety_ui_data);
1081
1082 chromeos::MobileConfig* config = chromeos::MobileConfig::GetInstance();
1083 if (config->IsReady()) {
1084 const std::string& carrier_id = cros_->GetCellularHomeCarrierId();
1085 const chromeos::MobileConfig::Carrier* carrier =
1086 config->GetCarrier(carrier_id);
1087 if (carrier && !carrier->top_up_url().empty())
1088 dictionary->SetString("carrierUrl", carrier->top_up_url());
1089 }
1090
1091 const chromeos::CellularApnList& apn_list = device->provider_apn_list();
1092 ListValue* apn_list_value = new ListValue();
1093 for (chromeos::CellularApnList::const_iterator it = apn_list.begin();
1094 it != apn_list.end(); ++it) {
1095 apn_list_value->Append(CreateDictionaryFromCellularApn(*it));
1096 }
1097 SetValueDictionary(dictionary, "providerApnList", apn_list_value,
1098 cellular_propety_ui_data);
1099 }
1100
1101 SetActivationButtonVisibility(cellular,
1102 dictionary,
1103 cros_->GetCellularHomeCarrierId());
1104 }
1105
1106 void InternetOptionsHandler::PopulateVPNDetails(
1107 const chromeos::VirtualNetwork* vpn,
1108 DictionaryValue* dictionary) {
1109 dictionary->SetString("service_name", vpn->name());
1110 bool remembered = (vpn->profile_type() != chromeos::PROFILE_NONE);
1111 dictionary->SetBoolean("remembered", remembered);
1112 dictionary->SetString("server_hostname", vpn->server_hostname());
1113 dictionary->SetString("provider_type", vpn->GetProviderTypeString());
1114 dictionary->SetString("username", vpn->username());
1115 }
1116
1117 void InternetOptionsHandler::SetActivationButtonVisibility(
1118 const chromeos::CellularNetwork* cellular,
1119 DictionaryValue* dictionary,
1120 const std::string& carrier_id) {
1121 if (cellular->needs_new_plan()) {
1122 dictionary->SetBoolean("showBuyButton", true);
1123 } else if (cellular->activation_state() !=
1124 chromeos::ACTIVATION_STATE_ACTIVATING &&
1125 cellular->activation_state() !=
1126 chromeos::ACTIVATION_STATE_ACTIVATED) {
1127 dictionary->SetBoolean("showActivateButton", true);
1128 } else {
1129 const chromeos::MobileConfig::Carrier* carrier =
1130 chromeos::MobileConfig::GetInstance()->GetCarrier(carrier_id);
1131 if (carrier && carrier->show_portal_button()) {
1132 // This will trigger BuyDataPlanCallback() so that
1133 // chrome://mobilesetup/ will open carrier specific portal.
1134 dictionary->SetBoolean("showViewAccountButton", true);
1135 }
1136 }
1137 }
1138
1139 void InternetOptionsHandler::CreateModalPopup(views::WidgetDelegate* view) {
1140 views::Widget* window = browser::CreateViewsWindow(GetNativeWindow(),
1141 view,
1142 STYLE_GENERIC);
1143 window->SetAlwaysOnTop(true);
1144 window->Show();
1145 }
1146
1147 gfx::NativeWindow InternetOptionsHandler::GetNativeWindow() const {
1148 // TODO(beng): This is an improper direct dependency on Browser. Route this
1149 // through some sort of delegate.
1150 Browser* browser =
1151 BrowserList::FindBrowserWithProfile(Profile::FromWebUI(web_ui()));
1152 return browser->window()->GetNativeHandle();
1153 }
1154
1155 void InternetOptionsHandler::ButtonClickCallback(const ListValue* args) {
1156 std::string str_type;
1157 std::string service_path;
1158 std::string command;
1159 if (args->GetSize() != 3 ||
1160 !args->GetString(0, &str_type) ||
1161 !args->GetString(1, &service_path) ||
1162 !args->GetString(2, &command)) {
1163 NOTREACHED();
1164 return;
1165 }
1166
1167 int type = atoi(str_type.c_str());
1168 if (type == chromeos::TYPE_ETHERNET) {
1169 const chromeos::EthernetNetwork* ether = cros_->ethernet_network();
1170 if (ether)
1171 PopulateDictionaryDetails(ether);
1172 } else if (type == chromeos::TYPE_WIFI) {
1173 HandleWifiButtonClick(service_path, command);
1174 } else if (type == chromeos::TYPE_CELLULAR) {
1175 HandleCellularButtonClick(service_path, command);
1176 } else if (type == chromeos::TYPE_VPN) {
1177 HandleVPNButtonClick(service_path, command);
1178 } else {
1179 NOTREACHED();
1180 }
1181 }
1182
1183 void InternetOptionsHandler::HandleWifiButtonClick(
1184 const std::string& service_path,
1185 const std::string& command) {
1186 chromeos::WifiNetwork* wifi = NULL;
1187 if (command == "forget") {
1188 cros_->ForgetNetwork(service_path);
1189 } else if (service_path == kOtherNetworksFakePath) {
1190 // Other wifi networks.
1191 CreateModalPopup(new chromeos::NetworkConfigView(chromeos::TYPE_WIFI));
1192 } else if ((wifi = cros_->FindWifiNetworkByPath(service_path))) {
1193 if (command == "connect") {
1194 // Connect to wifi here. Open password page if appropriate.
1195 if (wifi->IsPassphraseRequired()) {
1196 CreateModalPopup(new chromeos::NetworkConfigView(wifi));
1197 } else {
1198 cros_->ConnectToWifiNetwork(wifi);
1199 }
1200 } else if (command == "disconnect") {
1201 cros_->DisconnectFromNetwork(wifi);
1202 } else if (command == "options") {
1203 PopulateDictionaryDetails(wifi);
1204 }
1205 }
1206 }
1207
1208 void InternetOptionsHandler::HandleCellularButtonClick(
1209 const std::string& service_path,
1210 const std::string& command) {
1211 chromeos::CellularNetwork* cellular = NULL;
1212 if (service_path == kOtherNetworksFakePath) {
1213 chromeos::ChooseMobileNetworkDialog::ShowDialog(GetNativeWindow());
1214 } else if ((cellular = cros_->FindCellularNetworkByPath(service_path))) {
1215 if (command == "connect") {
1216 cros_->ConnectToCellularNetwork(cellular);
1217 } else if (command == "disconnect") {
1218 cros_->DisconnectFromNetwork(cellular);
1219 } else if (command == "activate") {
1220 Browser* browser = BrowserList::GetLastActive();
1221 if (browser)
1222 browser->OpenMobilePlanTabAndActivate();
1223 } else if (command == "options") {
1224 PopulateDictionaryDetails(cellular);
1225 }
1226 }
1227 }
1228
1229 void InternetOptionsHandler::HandleVPNButtonClick(
1230 const std::string& service_path,
1231 const std::string& command) {
1232 chromeos::VirtualNetwork* network = NULL;
1233 if (command == "forget") {
1234 cros_->ForgetNetwork(service_path);
1235 } else if (service_path == kOtherNetworksFakePath) {
1236 // TODO(altimofeev): verify if service_path in condition is correct.
1237 // Other VPN networks.
1238 CreateModalPopup(new chromeos::NetworkConfigView(chromeos::TYPE_VPN));
1239 } else if ((network = cros_->FindVirtualNetworkByPath(service_path))) {
1240 if (command == "connect") {
1241 // Connect to VPN here. Open password page if appropriate.
1242 if (network->NeedMoreInfoToConnect()) {
1243 CreateModalPopup(new chromeos::NetworkConfigView(network));
1244 } else {
1245 cros_->ConnectToVirtualNetwork(network);
1246 }
1247 } else if (command == "disconnect") {
1248 cros_->DisconnectFromNetwork(network);
1249 } else if (command == "options") {
1250 PopulateDictionaryDetails(network);
1251 }
1252 }
1253 }
1254
1255 void InternetOptionsHandler::RefreshCellularPlanCallback(
1256 const ListValue* args) {
1257 std::string service_path;
1258 if (args->GetSize() != 1 ||
1259 !args->GetString(0, &service_path)) {
1260 NOTREACHED();
1261 return;
1262 }
1263 const chromeos::CellularNetwork* cellular =
1264 cros_->FindCellularNetworkByPath(service_path);
1265 if (cellular)
1266 cellular->RefreshDataPlansIfNeeded();
1267 }
1268
1269 ListValue* InternetOptionsHandler::GetWiredList() {
1270 ListValue* list = new ListValue();
1271
1272 // If ethernet is not enabled, then don't add anything.
1273 if (cros_->ethernet_enabled()) {
1274 const chromeos::EthernetNetwork* ethernet_network =
1275 cros_->ethernet_network();
1276 if (ethernet_network) {
1277 NetworkInfoDictionary network_dict(ethernet_network);
1278 network_dict.set_name(
1279 l10n_util::GetStringUTF8(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET)),
1280 list->Append(network_dict.BuildDictionary());
1281 }
1282 }
1283 return list;
1284 }
1285
1286 ListValue* InternetOptionsHandler::GetWirelessList() {
1287 ListValue* list = new ListValue();
1288
1289 const chromeos::WifiNetworkVector& wifi_networks = cros_->wifi_networks();
1290 for (chromeos::WifiNetworkVector::const_iterator it =
1291 wifi_networks.begin(); it != wifi_networks.end(); ++it) {
1292 NetworkInfoDictionary network_dict(*it);
1293 network_dict.set_connectable(cros_->CanConnectToNetwork(*it));
1294 list->Append(network_dict.BuildDictionary());
1295 }
1296
1297 // Add "Other WiFi network..." if wifi is enabled.
1298 if (cros_->wifi_enabled()) {
1299 NetworkInfoDictionary network_dict;
1300 network_dict.set_service_path(kOtherNetworksFakePath);
1301 network_dict.set_icon(
1302 chromeos::NetworkMenuIcon::GetConnectedBitmap(
1303 chromeos::NetworkMenuIcon::ARCS,
1304 chromeos::NetworkMenuIcon::SIZE_SMALL));
1305 network_dict.set_name(
1306 l10n_util::GetStringUTF8(IDS_OPTIONS_SETTINGS_OTHER_WIFI_NETWORKS));
1307 network_dict.set_connectable(true);
1308 network_dict.set_connection_type(chromeos::TYPE_WIFI);
1309 list->Append(network_dict.BuildDictionary());
1310 }
1311
1312 const chromeos::CellularNetworkVector cellular_networks =
1313 cros_->cellular_networks();
1314 for (chromeos::CellularNetworkVector::const_iterator it =
1315 cellular_networks.begin(); it != cellular_networks.end(); ++it) {
1316 NetworkInfoDictionary network_dict(*it);
1317 network_dict.set_connectable(cros_->CanConnectToNetwork(*it));
1318 network_dict.set_activation_state((*it)->activation_state());
1319 network_dict.set_needs_new_plan(
1320 (*it)->SupportsDataPlan() && (*it)->restricted_pool());
1321 list->Append(network_dict.BuildDictionary());
1322 }
1323
1324 const chromeos::NetworkDevice* cellular_device = cros_->FindCellularDevice();
1325 if (cellular_device && cellular_device->support_network_scan() &&
1326 cros_->cellular_enabled()) {
1327 NetworkInfoDictionary network_dict;
1328 network_dict.set_service_path(kOtherNetworksFakePath);
1329 network_dict.set_icon(
1330 chromeos::NetworkMenuIcon::GetDisconnectedBitmap(
1331 chromeos::NetworkMenuIcon::BARS,
1332 chromeos::NetworkMenuIcon::SIZE_SMALL));
1333 network_dict.set_name(
1334 l10n_util::GetStringUTF8(IDS_OPTIONS_SETTINGS_OTHER_CELLULAR_NETWORKS));
1335 network_dict.set_connectable(true);
1336 network_dict.set_connection_type(chromeos::TYPE_CELLULAR);
1337 network_dict.set_activation_state(chromeos::ACTIVATION_STATE_ACTIVATED);
1338 list->Append(network_dict.BuildDictionary());
1339 }
1340
1341 return list;
1342 }
1343
1344 ListValue* InternetOptionsHandler::GetVPNList() {
1345 ListValue* list = new ListValue();
1346
1347 const chromeos::VirtualNetworkVector& virtual_networks =
1348 cros_->virtual_networks();
1349 for (chromeos::VirtualNetworkVector::const_iterator it =
1350 virtual_networks.begin(); it != virtual_networks.end(); ++it) {
1351 NetworkInfoDictionary network_dict(*it);
1352 network_dict.set_connectable(cros_->CanConnectToNetwork(*it));
1353 list->Append(network_dict.BuildDictionary());
1354 }
1355
1356 return list;
1357 }
1358
1359 ListValue* InternetOptionsHandler::GetRememberedList() {
1360 ListValue* list = new ListValue();
1361
1362 for (chromeos::WifiNetworkVector::const_iterator rit =
1363 cros_->remembered_wifi_networks().begin();
1364 rit != cros_->remembered_wifi_networks().end(); ++rit) {
1365 chromeos::WifiNetwork* remembered = *rit;
1366 chromeos::WifiNetwork* wifi = static_cast<chromeos::WifiNetwork*>(
1367 cros_->FindNetworkByUniqueId(remembered->unique_id()));
1368
1369 NetworkInfoDictionary network_dict(wifi, remembered);
1370 list->Append(network_dict.BuildDictionary());
1371 }
1372
1373 for (chromeos::VirtualNetworkVector::const_iterator rit =
1374 cros_->remembered_virtual_networks().begin();
1375 rit != cros_->remembered_virtual_networks().end(); ++rit) {
1376 chromeos::VirtualNetwork* remembered = *rit;
1377 chromeos::VirtualNetwork* vpn = static_cast<chromeos::VirtualNetwork*>(
1378 cros_->FindNetworkByUniqueId(remembered->unique_id()));
1379
1380 NetworkInfoDictionary network_dict(vpn, remembered);
1381 list->Append(network_dict.BuildDictionary());
1382 }
1383
1384 return list;
1385 }
1386
1387 void InternetOptionsHandler::FillNetworkInfo(DictionaryValue* dictionary) {
1388 dictionary->SetBoolean("accessLocked", cros_->IsLocked());
1389 dictionary->Set("wiredList", GetWiredList());
1390 dictionary->Set("wirelessList", GetWirelessList());
1391 dictionary->Set("vpnList", GetVPNList());
1392 dictionary->Set("rememberedList", GetRememberedList());
1393 dictionary->SetBoolean("wifiAvailable", cros_->wifi_available());
1394 dictionary->SetBoolean("wifiBusy", cros_->wifi_busy());
1395 dictionary->SetBoolean("wifiEnabled", cros_->wifi_enabled());
1396 dictionary->SetBoolean("cellularAvailable", cros_->cellular_available());
1397 dictionary->SetBoolean("cellularBusy", cros_->cellular_busy());
1398 dictionary->SetBoolean("cellularEnabled", cros_->cellular_enabled());
1399 }
1400
1401 void InternetOptionsHandler::SetValueDictionary(
1402 DictionaryValue* settings,
1403 const char* key,
1404 base::Value* value,
1405 const chromeos::NetworkPropertyUIData& ui_data) {
1406 DictionaryValue* value_dict = new DictionaryValue();
1407 // DictionaryValue::Set() takes ownership of |value|.
1408 if (value)
1409 value_dict->Set("value", value);
1410 const base::Value* default_value = ui_data.default_value();
1411 if (default_value)
1412 value_dict->Set("default", default_value->DeepCopy());
1413 if (ui_data.managed())
1414 value_dict->SetString("controlledBy", "policy");
1415 else if (ui_data.recommended())
1416 value_dict->SetString("controlledBy", "recommended");
1417 settings->Set(key, value_dict);
1418 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698