OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/webui/internet_options_handler.h" | 5 #include "chrome/browser/chromeos/webui/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> |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 } | 393 } |
394 | 394 |
395 // Monitor wireless networks for changes. It is only necessary | 395 // Monitor wireless networks for changes. It is only necessary |
396 // to set up individual observers for the cellular networks | 396 // to set up individual observers for the cellular networks |
397 // (if any) and for the connected Wi-Fi network (if any). The | 397 // (if any) and for the connected Wi-Fi network (if any). The |
398 // only change we are interested in for Wi-Fi networks is signal | 398 // only change we are interested in for Wi-Fi networks is signal |
399 // strength. For non-connected Wi-Fi networks, all information is | 399 // strength. For non-connected Wi-Fi networks, all information is |
400 // reported via scan results, which trigger network manager | 400 // reported via scan results, which trigger network manager |
401 // updates. Only the connected Wi-Fi network has changes reported | 401 // updates. Only the connected Wi-Fi network has changes reported |
402 // via service property updates. | 402 // via service property updates. |
403 void InternetOptionsHandler::MonitorNetworks( chromeos::NetworkLibrary* cros) { | 403 void InternetOptionsHandler::MonitorNetworks(chromeos::NetworkLibrary* cros) { |
404 cros->RemoveObserverForAllNetworks(this); | 404 cros->RemoveObserverForAllNetworks(this); |
405 const chromeos::WifiNetwork* wifi_network = cros->wifi_network(); | 405 const chromeos::WifiNetwork* wifi_network = cros->wifi_network(); |
406 if (wifi_network != NULL) | 406 if (wifi_network != NULL) |
407 cros->AddNetworkObserver(wifi_network->service_path(), this); | 407 cros->AddNetworkObserver(wifi_network->service_path(), this); |
408 // Always monitor the cellular networks, if any, so that changes | 408 // Always monitor the cellular networks, if any, so that changes |
409 // in network technology, roaming status, and signal strength | 409 // in network technology, roaming status, and signal strength |
410 // will be shown. | 410 // will be shown. |
411 const chromeos::CellularNetworkVector& cell_networks = | 411 const chromeos::CellularNetworkVector& cell_networks = |
412 cros->cellular_networks(); | 412 cros->cellular_networks(); |
413 for (size_t i = 0; i < cell_networks.size(); ++i) { | 413 for (size_t i = 0; i < cell_networks.size(); ++i) { |
(...skipping 15 matching lines...) Expand all Loading... |
429 for (chromeos::CellularDataPlanVector::const_iterator iter = plans.begin(); | 429 for (chromeos::CellularDataPlanVector::const_iterator iter = plans.begin(); |
430 iter != plans.end(); | 430 iter != plans.end(); |
431 ++iter) { | 431 ++iter) { |
432 plan_list->Append(CellularDataPlanToDictionary(*iter)); | 432 plan_list->Append(CellularDataPlanToDictionary(*iter)); |
433 } | 433 } |
434 connection_plans.SetString("servicePath", cellular->service_path()); | 434 connection_plans.SetString("servicePath", cellular->service_path()); |
435 connection_plans.SetBoolean("needsPlan", cellular->needs_new_plan()); | 435 connection_plans.SetBoolean("needsPlan", cellular->needs_new_plan()); |
436 connection_plans.SetBoolean("activated", | 436 connection_plans.SetBoolean("activated", |
437 cellular->activation_state() == chromeos::ACTIVATION_STATE_ACTIVATED); | 437 cellular->activation_state() == chromeos::ACTIVATION_STATE_ACTIVATED); |
438 connection_plans.Set("plans", plan_list); | 438 connection_plans.Set("plans", plan_list); |
| 439 SetActivationButtonVisibility(cellular, &connection_plans); |
439 web_ui_->CallJavascriptFunction( | 440 web_ui_->CallJavascriptFunction( |
440 L"options.InternetOptions.updateCellularPlans", connection_plans); | 441 L"options.InternetOptions.updateCellularPlans", connection_plans); |
441 } | 442 } |
442 | 443 |
443 DictionaryValue* InternetOptionsHandler::CellularDataPlanToDictionary( | 444 DictionaryValue* InternetOptionsHandler::CellularDataPlanToDictionary( |
444 const chromeos::CellularDataPlan* plan) { | 445 const chromeos::CellularDataPlan* plan) { |
445 DictionaryValue* plan_dict = new DictionaryValue(); | 446 DictionaryValue* plan_dict = new DictionaryValue(); |
446 plan_dict->SetInteger("planType", plan->plan_type); | 447 plan_dict->SetInteger("planType", plan->plan_type); |
447 plan_dict->SetString("name", plan->plan_name); | 448 plan_dict->SetString("name", plan->plan_name); |
448 plan_dict->SetString("planSummary", plan->GetPlanDesciption()); | 449 plan_dict->SetString("planSummary", plan->GetPlanDesciption()); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 dictionary.SetBoolean("connecting", net->connecting()); | 554 dictionary.SetBoolean("connecting", net->connecting()); |
554 dictionary.SetBoolean("connected", net->connected()); | 555 dictionary.SetBoolean("connected", net->connected()); |
555 dictionary.SetString("connectionState", net->GetStateString()); | 556 dictionary.SetString("connectionState", net->GetStateString()); |
556 | 557 |
557 if (type == chromeos::TYPE_WIFI) { | 558 if (type == chromeos::TYPE_WIFI) { |
558 chromeos::WifiNetwork* wifi = | 559 chromeos::WifiNetwork* wifi = |
559 cros->FindWifiNetworkByPath(net->service_path()); | 560 cros->FindWifiNetworkByPath(net->service_path()); |
560 if (!wifi) { | 561 if (!wifi) { |
561 LOG(WARNING) << "Cannot find network " << net->service_path(); | 562 LOG(WARNING) << "Cannot find network " << net->service_path(); |
562 } else { | 563 } else { |
563 PopulateWifiDetails(&dictionary, wifi); | 564 PopulateWifiDetails(wifi, &dictionary); |
564 } | 565 } |
565 } else if (type == chromeos::TYPE_CELLULAR) { | 566 } else if (type == chromeos::TYPE_CELLULAR) { |
566 chromeos::CellularNetwork* cellular = | 567 chromeos::CellularNetwork* cellular = |
567 cros->FindCellularNetworkByPath(net->service_path()); | 568 cros->FindCellularNetworkByPath(net->service_path()); |
568 if (!cellular) { | 569 if (!cellular) { |
569 LOG(WARNING) << "Cannot find network " << net->service_path(); | 570 LOG(WARNING) << "Cannot find network " << net->service_path(); |
570 } else { | 571 } else { |
571 PopulateCellularDetails(&dictionary, cellular); | 572 PopulateCellularDetails(cellular, &dictionary); |
572 } | 573 } |
573 } | 574 } |
574 | 575 |
575 web_ui_->CallJavascriptFunction( | 576 web_ui_->CallJavascriptFunction( |
576 L"options.InternetOptions.showDetailedInfo", dictionary); | 577 L"options.InternetOptions.showDetailedInfo", dictionary); |
577 } | 578 } |
578 | 579 |
579 void InternetOptionsHandler::PopulateWifiDetails( | 580 void InternetOptionsHandler::PopulateWifiDetails( |
580 DictionaryValue* dictionary, | 581 const chromeos::WifiNetwork* wifi, |
581 const chromeos::WifiNetwork* wifi) { | 582 DictionaryValue* dictionary) { |
582 dictionary->SetString("ssid", wifi->name()); | 583 dictionary->SetString("ssid", wifi->name()); |
583 dictionary->SetBoolean("autoConnect", wifi->auto_connect()); | 584 dictionary->SetBoolean("autoConnect", wifi->auto_connect()); |
584 if (wifi->encrypted()) { | 585 if (wifi->encrypted()) { |
585 dictionary->SetBoolean("encrypted", true); | 586 dictionary->SetBoolean("encrypted", true); |
586 if (wifi->encryption() == chromeos::SECURITY_8021X) { | 587 if (wifi->encryption() == chromeos::SECURITY_8021X) { |
587 bool certificate_in_pkcs11 = | 588 bool certificate_in_pkcs11 = |
588 IsCertificateInPkcs11(wifi->cert_path()); | 589 IsCertificateInPkcs11(wifi->cert_path()); |
589 if (certificate_in_pkcs11) { | 590 if (certificate_in_pkcs11) { |
590 dictionary->SetBoolean("certInPkcs", true); | 591 dictionary->SetBoolean("certInPkcs", true); |
591 } else { | 592 } else { |
592 dictionary->SetBoolean("certInPkcs", false); | 593 dictionary->SetBoolean("certInPkcs", false); |
593 } | 594 } |
594 dictionary->SetString("certPath", wifi->cert_path()); | 595 dictionary->SetString("certPath", wifi->cert_path()); |
595 dictionary->SetString("ident", wifi->identity()); | 596 dictionary->SetString("ident", wifi->identity()); |
596 dictionary->SetBoolean("certNeeded", true); | 597 dictionary->SetBoolean("certNeeded", true); |
597 dictionary->SetString("certPass", wifi->passphrase()); | 598 dictionary->SetString("certPass", wifi->passphrase()); |
598 } else { | 599 } else { |
599 dictionary->SetBoolean("certNeeded", false); | 600 dictionary->SetBoolean("certNeeded", false); |
600 } | 601 } |
601 } else { | 602 } else { |
602 dictionary->SetBoolean("encrypted", false); | 603 dictionary->SetBoolean("encrypted", false); |
603 } | 604 } |
604 } | 605 } |
605 | 606 |
606 void InternetOptionsHandler::PopulateCellularDetails( | 607 void InternetOptionsHandler::PopulateCellularDetails( |
607 DictionaryValue* dictionary, | 608 const chromeos::CellularNetwork* cellular, |
608 const chromeos::CellularNetwork* cellular) { | 609 DictionaryValue* dictionary) { |
609 // Cellular network / connection settings. | 610 // Cellular network / connection settings. |
610 dictionary->SetString("serviceName", cellular->service_name()); | 611 dictionary->SetString("serviceName", cellular->service_name()); |
611 dictionary->SetString("networkTechnology", | 612 dictionary->SetString("networkTechnology", |
612 cellular->GetNetworkTechnologyString()); | 613 cellular->GetNetworkTechnologyString()); |
613 dictionary->SetString("operatorName", cellular->operator_name()); | 614 dictionary->SetString("operatorName", cellular->operator_name()); |
614 dictionary->SetString("operatorCode", cellular->operator_code()); | 615 dictionary->SetString("operatorCode", cellular->operator_code()); |
615 dictionary->SetString("activationState", | 616 dictionary->SetString("activationState", |
616 cellular->GetActivationStateString()); | 617 cellular->GetActivationStateString()); |
617 dictionary->SetString("roamingState", | 618 dictionary->SetString("roamingState", |
618 cellular->GetRoamingStateString()); | 619 cellular->GetRoamingStateString()); |
619 dictionary->SetString("restrictedPool", | 620 dictionary->SetString("restrictedPool", |
620 cellular->restricted_pool() ? | 621 cellular->restricted_pool() ? |
621 l10n_util::GetStringUTF8( | 622 l10n_util::GetStringUTF8( |
622 IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL) : | 623 IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL) : |
623 l10n_util::GetStringUTF8( | 624 l10n_util::GetStringUTF8( |
624 IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL)); | 625 IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL)); |
625 dictionary->SetString("errorState", cellular->GetErrorString()); | 626 dictionary->SetString("errorState", cellular->GetErrorString()); |
626 dictionary->SetString("supportUrl", cellular->payment_url()); | 627 dictionary->SetString("supportUrl", cellular->payment_url()); |
| 628 dictionary->SetBoolean("needsPlan", cellular->needs_new_plan()); |
627 | 629 |
628 // Device settings. | 630 // Device settings. |
629 dictionary->SetString("manufacturer", cellular->manufacturer()); | 631 dictionary->SetString("manufacturer", cellular->manufacturer()); |
630 dictionary->SetString("modelId", cellular->model_id()); | 632 dictionary->SetString("modelId", cellular->model_id()); |
631 dictionary->SetString("firmwareRevision", cellular->firmware_revision()); | 633 dictionary->SetString("firmwareRevision", cellular->firmware_revision()); |
632 dictionary->SetString("hardwareRevision", cellular->hardware_revision()); | 634 dictionary->SetString("hardwareRevision", cellular->hardware_revision()); |
633 dictionary->SetString("lastUpdate", cellular->last_update()); | 635 dictionary->SetString("lastUpdate", cellular->last_update()); |
634 dictionary->SetString("prlVersion", StringPrintf("%u", | 636 dictionary->SetString("prlVersion", StringPrintf("%u", |
635 cellular->prl_version())); | 637 cellular->prl_version())); |
636 dictionary->SetString("meid", cellular->meid()); | 638 dictionary->SetString("meid", cellular->meid()); |
637 dictionary->SetString("imei", cellular->imei()); | 639 dictionary->SetString("imei", cellular->imei()); |
638 dictionary->SetString("mdn", cellular->mdn()); | 640 dictionary->SetString("mdn", cellular->mdn()); |
639 dictionary->SetString("imsi", cellular->imsi()); | 641 dictionary->SetString("imsi", cellular->imsi()); |
640 dictionary->SetString("esn", cellular->esn()); | 642 dictionary->SetString("esn", cellular->esn()); |
641 dictionary->SetString("min", cellular->min()); | 643 dictionary->SetString("min", cellular->min()); |
642 | 644 |
643 dictionary->SetBoolean("gsm", cellular->is_gsm()); | 645 dictionary->SetBoolean("gsm", cellular->is_gsm()); |
| 646 |
| 647 SetActivationButtonVisibility(cellular, dictionary); |
| 648 } |
| 649 |
| 650 void InternetOptionsHandler::SetActivationButtonVisibility( |
| 651 const chromeos::CellularNetwork* cellular, |
| 652 DictionaryValue* dictionary) { |
| 653 if (cellular->needs_new_plan()) { |
| 654 dictionary->SetBoolean("showBuyButton", true); |
| 655 } else if (cellular->activation_state() != |
| 656 chromeos::ACTIVATION_STATE_ACTIVATING && |
| 657 cellular->activation_state() != |
| 658 chromeos::ACTIVATION_STATE_ACTIVATED) { |
| 659 dictionary->SetBoolean("showActivateButton", true); |
| 660 } |
644 } | 661 } |
645 | 662 |
646 void InternetOptionsHandler::LoginCallback(const ListValue* args) { | 663 void InternetOptionsHandler::LoginCallback(const ListValue* args) { |
647 std::string service_path; | 664 std::string service_path; |
648 std::string password; | 665 std::string password; |
649 | 666 |
650 if (args->GetSize() != 2 || | 667 if (args->GetSize() != 2 || |
651 !args->GetString(0, &service_path) || | 668 !args->GetString(0, &service_path) || |
652 !args->GetString(1, &password)) { | 669 !args->GetString(1, &password)) { |
653 NOTREACHED(); | 670 NOTREACHED(); |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1071 DictionaryValue* dictionary, chromeos::NetworkLibrary* cros) { | 1088 DictionaryValue* dictionary, chromeos::NetworkLibrary* cros) { |
1072 dictionary->SetBoolean("accessLocked", cros->IsLocked()); | 1089 dictionary->SetBoolean("accessLocked", cros->IsLocked()); |
1073 dictionary->Set("wiredList", GetWiredList()); | 1090 dictionary->Set("wiredList", GetWiredList()); |
1074 dictionary->Set("wirelessList", GetWirelessList()); | 1091 dictionary->Set("wirelessList", GetWirelessList()); |
1075 dictionary->Set("rememberedList", GetRememberedList()); | 1092 dictionary->Set("rememberedList", GetRememberedList()); |
1076 dictionary->SetBoolean("wifiAvailable", cros->wifi_available()); | 1093 dictionary->SetBoolean("wifiAvailable", cros->wifi_available()); |
1077 dictionary->SetBoolean("wifiEnabled", cros->wifi_enabled()); | 1094 dictionary->SetBoolean("wifiEnabled", cros->wifi_enabled()); |
1078 dictionary->SetBoolean("cellularAvailable", cros->cellular_available()); | 1095 dictionary->SetBoolean("cellularAvailable", cros->cellular_available()); |
1079 dictionary->SetBoolean("cellularEnabled", cros->cellular_enabled()); | 1096 dictionary->SetBoolean("cellularEnabled", cros->cellular_enabled()); |
1080 } | 1097 } |
OLD | NEW |