| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/dom_ui/internet_options_handler.h" | 5 #include "chrome/browser/chromeos/dom_ui/internet_options_handler.h" |
| 6 | 6 |
| 7 #include <ctype.h> | 7 #include <ctype.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 output.push_back(':'); | 49 output.push_back(':'); |
| 50 } | 50 } |
| 51 output.push_back(toupper(address[i])); | 51 output.push_back(toupper(address[i])); |
| 52 } | 52 } |
| 53 return output; | 53 return output; |
| 54 } | 54 } |
| 55 | 55 |
| 56 } // namespace | 56 } // namespace |
| 57 | 57 |
| 58 InternetOptionsHandler::InternetOptionsHandler() { | 58 InternetOptionsHandler::InternetOptionsHandler() { |
| 59 chromeos::CrosLibrary::Get()->GetNetworkLibrary()->AddObserver(this); | 59 chromeos::NetworkLibrary* netlib = |
| 60 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); |
| 61 netlib->AddNetworkManagerObserver(this); |
| 62 netlib->AddCellularDataPlanObserver(this); |
| 63 MonitorActiveNetwork(netlib); |
| 60 } | 64 } |
| 61 | 65 |
| 62 InternetOptionsHandler::~InternetOptionsHandler() { | 66 InternetOptionsHandler::~InternetOptionsHandler() { |
| 63 chromeos::CrosLibrary::Get()->GetNetworkLibrary()->RemoveObserver(this); | 67 chromeos::NetworkLibrary *netlib = |
| 68 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); |
| 69 netlib->RemoveNetworkManagerObserver(this); |
| 70 netlib->RemoveCellularDataPlanObserver(this); |
| 71 netlib->RemoveObserverForAllNetworks(this); |
| 64 } | 72 } |
| 65 | 73 |
| 66 void InternetOptionsHandler::GetLocalizedValues( | 74 void InternetOptionsHandler::GetLocalizedValues( |
| 67 DictionaryValue* localized_strings) { | 75 DictionaryValue* localized_strings) { |
| 68 DCHECK(localized_strings); | 76 DCHECK(localized_strings); |
| 69 // Internet page - ChromeOS | 77 // Internet page - ChromeOS |
| 70 localized_strings->SetString("internetPage", | 78 localized_strings->SetString("internetPage", |
| 71 l10n_util::GetStringUTF16(IDS_OPTIONS_INTERNET_TAB_LABEL)); | 79 l10n_util::GetStringUTF16(IDS_OPTIONS_INTERNET_TAB_LABEL)); |
| 72 | 80 |
| 73 localized_strings->SetString("wired_title", | 81 localized_strings->SetString("wired_title", |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CUSTOMER_SUPPORT)); | 268 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CUSTOMER_SUPPORT)); |
| 261 | 269 |
| 262 localized_strings->SetString("enableWifi", | 270 localized_strings->SetString("enableWifi", |
| 263 l10n_util::GetStringFUTF16( | 271 l10n_util::GetStringFUTF16( |
| 264 IDS_STATUSBAR_NETWORK_DEVICE_ENABLE, | 272 IDS_STATUSBAR_NETWORK_DEVICE_ENABLE, |
| 265 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_WIFI))); | 273 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_WIFI))); |
| 266 localized_strings->SetString("disableWifi", | 274 localized_strings->SetString("disableWifi", |
| 267 l10n_util::GetStringFUTF16( | 275 l10n_util::GetStringFUTF16( |
| 268 IDS_STATUSBAR_NETWORK_DEVICE_DISABLE, | 276 IDS_STATUSBAR_NETWORK_DEVICE_DISABLE, |
| 269 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_WIFI))); | 277 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_WIFI))); |
| 270 localized_strings->SetString("enableCellular", | 278 localized_strings->SetString("enableCellular", |
| 271 l10n_util::GetStringFUTF16( | 279 l10n_util::GetStringFUTF16( |
| 272 IDS_STATUSBAR_NETWORK_DEVICE_ENABLE, | 280 IDS_STATUSBAR_NETWORK_DEVICE_ENABLE, |
| 273 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_CELLULAR))); | 281 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_CELLULAR))); |
| 274 localized_strings->SetString("disableCellular", | 282 localized_strings->SetString("disableCellular", |
| 275 l10n_util::GetStringFUTF16( | 283 l10n_util::GetStringFUTF16( |
| 276 IDS_STATUSBAR_NETWORK_DEVICE_DISABLE, | 284 IDS_STATUSBAR_NETWORK_DEVICE_DISABLE, |
| 277 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_CELLULAR))); | 285 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_CELLULAR))); |
| 278 localized_strings->SetString("generalNetworkingTitle", | 286 localized_strings->SetString("generalNetworkingTitle", |
| 279 l10n_util::GetStringUTF16( | 287 l10n_util::GetStringUTF16( |
| 280 IDS_OPTIONS_SETTINGS_INTERNET_CONTROL_TITLE)); | 288 IDS_OPTIONS_SETTINGS_INTERNET_CONTROL_TITLE)); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 | 358 |
| 351 void InternetOptionsHandler::BuyDataPlanCallback(const ListValue* args) { | 359 void InternetOptionsHandler::BuyDataPlanCallback(const ListValue* args) { |
| 352 if (!dom_ui_) | 360 if (!dom_ui_) |
| 353 return; | 361 return; |
| 354 Browser* browser = BrowserList::FindBrowserWithFeature( | 362 Browser* browser = BrowserList::FindBrowserWithFeature( |
| 355 dom_ui_->GetProfile(), Browser::FEATURE_TABSTRIP); | 363 dom_ui_->GetProfile(), Browser::FEATURE_TABSTRIP); |
| 356 if (browser) | 364 if (browser) |
| 357 browser->OpenMobilePlanTabAndActivate(); | 365 browser->OpenMobilePlanTabAndActivate(); |
| 358 } | 366 } |
| 359 | 367 |
| 360 void InternetOptionsHandler::NetworkChanged(chromeos::NetworkLibrary* cros) { | 368 void InternetOptionsHandler::RefreshNetworkData( |
| 361 if (!dom_ui_) | 369 chromeos::NetworkLibrary* cros) { |
| 362 return; | |
| 363 | |
| 364 DictionaryValue dictionary; | 370 DictionaryValue dictionary; |
| 365 dictionary.Set("wiredList", GetWiredList()); | 371 dictionary.Set("wiredList", GetWiredList()); |
| 366 dictionary.Set("wirelessList", GetWirelessList()); | 372 dictionary.Set("wirelessList", GetWirelessList()); |
| 367 dictionary.Set("rememberedList", GetRememberedList()); | 373 dictionary.Set("rememberedList", GetRememberedList()); |
| 368 dictionary.SetBoolean("wifiAvailable", cros->wifi_available()); | 374 dictionary.SetBoolean("wifiAvailable", cros->wifi_available()); |
| 369 dictionary.SetBoolean("wifiEnabled", cros->wifi_enabled()); | 375 dictionary.SetBoolean("wifiEnabled", cros->wifi_enabled()); |
| 370 dictionary.SetBoolean("cellularAvailable", cros->cellular_available()); | 376 dictionary.SetBoolean("cellularAvailable", cros->cellular_available()); |
| 371 dictionary.SetBoolean("cellularEnabled", cros->cellular_enabled()); | 377 dictionary.SetBoolean("cellularEnabled", cros->cellular_enabled()); |
| 372 dom_ui_->CallJavascriptFunction( | 378 dom_ui_->CallJavascriptFunction( |
| 373 L"options.InternetOptions.refreshNetworkData", dictionary); | 379 L"options.InternetOptions.refreshNetworkData", dictionary); |
| 374 } | 380 } |
| 375 | 381 |
| 376 void InternetOptionsHandler::CellularDataPlanChanged( | 382 void InternetOptionsHandler::OnNetworkManagerChanged( |
| 383 chromeos::NetworkLibrary* cros) { |
| 384 if (!dom_ui_) |
| 385 return; |
| 386 MonitorActiveNetwork(cros); |
| 387 RefreshNetworkData(cros); |
| 388 } |
| 389 |
| 390 void InternetOptionsHandler::OnNetworkChanged( |
| 391 chromeos::NetworkLibrary* cros, |
| 392 const chromeos::Network* network) { |
| 393 if (dom_ui_) |
| 394 RefreshNetworkData(cros); |
| 395 } |
| 396 |
| 397 // Add an observer for the active network, if any, so |
| 398 // that we can dynamically display the correct icon for |
| 399 // that network's signal strength. |
| 400 // TODO(ers) Ideally, on this page we'd monitor all networks for |
| 401 // signal strength changes, not just the active network. |
| 402 void InternetOptionsHandler::MonitorActiveNetwork( |
| 403 chromeos::NetworkLibrary* cros) { |
| 404 const chromeos::Network* network = cros->active_network(); |
| 405 if (active_network_.empty() || network == NULL || |
| 406 active_network_ != network->service_path()) { |
| 407 if (!active_network_.empty()) { |
| 408 cros->RemoveNetworkObserver(active_network_, this); |
| 409 } |
| 410 if (network != NULL) { |
| 411 cros->AddNetworkObserver(network->service_path(), this); |
| 412 } |
| 413 } |
| 414 if (network != NULL) |
| 415 active_network_ = network->service_path(); |
| 416 else |
| 417 active_network_ = ""; |
| 418 } |
| 419 |
| 420 void InternetOptionsHandler::OnCellularDataPlanChanged( |
| 377 chromeos::NetworkLibrary* obj) { | 421 chromeos::NetworkLibrary* obj) { |
| 378 if (!dom_ui_) | 422 if (!dom_ui_) |
| 379 return; | 423 return; |
| 380 chromeos::CellularNetwork* cellular = obj->cellular_network(); | 424 chromeos::CellularNetwork* cellular = obj->cellular_network(); |
| 381 if (!cellular) | 425 if (!cellular) |
| 382 return; | 426 return; |
| 383 const chromeos::CellularDataPlanVector& plans = cellular->GetDataPlans(); | 427 const chromeos::CellularDataPlanVector& plans = cellular->GetDataPlans(); |
| 384 DictionaryValue connection_plans; | 428 DictionaryValue connection_plans; |
| 385 ListValue* plan_list = new ListValue(); | 429 ListValue* plan_list = new ListValue(); |
| 386 for (chromeos::CellularDataPlanVector::const_iterator iter = plans.begin(); | 430 for (chromeos::CellularDataPlanVector::const_iterator iter = plans.begin(); |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 dictionary.SetBoolean("connecting", net->connecting()); | 617 dictionary.SetBoolean("connecting", net->connecting()); |
| 574 dictionary.SetBoolean("connected", net->connected()); | 618 dictionary.SetBoolean("connected", net->connected()); |
| 575 dictionary.SetString("connectionState", net->GetStateString()); | 619 dictionary.SetString("connectionState", net->GetStateString()); |
| 576 if (type == chromeos::TYPE_WIFI) { | 620 if (type == chromeos::TYPE_WIFI) { |
| 577 chromeos::WifiNetwork* wireless = | 621 chromeos::WifiNetwork* wireless = |
| 578 cros->FindWifiNetworkByPath(net->service_path()); | 622 cros->FindWifiNetworkByPath(net->service_path()); |
| 579 if (!wireless) { | 623 if (!wireless) { |
| 580 LOG(WARNING) << "Cannot find network " << net->service_path(); | 624 LOG(WARNING) << "Cannot find network " << net->service_path(); |
| 581 } else { | 625 } else { |
| 582 dictionary.SetString("ssid", wireless->name()); | 626 dictionary.SetString("ssid", wireless->name()); |
| 583 dictionary.SetBoolean("autoConnect",wireless->auto_connect()); | 627 dictionary.SetBoolean("autoConnect", wireless->auto_connect()); |
| 584 if (wireless->encrypted()) { | 628 if (wireless->encrypted()) { |
| 585 dictionary.SetBoolean("encrypted", true); | 629 dictionary.SetBoolean("encrypted", true); |
| 586 if (wireless->encryption() == chromeos::SECURITY_8021X) { | 630 if (wireless->encryption() == chromeos::SECURITY_8021X) { |
| 587 bool certificate_in_pkcs11 = | 631 bool certificate_in_pkcs11 = |
| 588 is_certificate_in_pkcs11(wireless->cert_path()); | 632 is_certificate_in_pkcs11(wireless->cert_path()); |
| 589 if (certificate_in_pkcs11) { | 633 if (certificate_in_pkcs11) { |
| 590 dictionary.SetBoolean("certInPkcs", true); | 634 dictionary.SetBoolean("certInPkcs", true); |
| 591 } else { | 635 } else { |
| 592 dictionary.SetBoolean("certInPkcs", false); | 636 dictionary.SetBoolean("certInPkcs", false); |
| 593 } | 637 } |
| 594 dictionary.SetString("certPath",wireless->cert_path()); | 638 dictionary.SetString("certPath", wireless->cert_path()); |
| 595 dictionary.SetString("ident",wireless->identity()); | 639 dictionary.SetString("ident", wireless->identity()); |
| 596 dictionary.SetBoolean("certNeeded", true); | 640 dictionary.SetBoolean("certNeeded", true); |
| 597 dictionary.SetString("certPass",wireless->passphrase()); | 641 dictionary.SetString("certPass", wireless->passphrase()); |
| 598 } else { | 642 } else { |
| 599 dictionary.SetBoolean("certNeeded", false); | 643 dictionary.SetBoolean("certNeeded", false); |
| 600 } | 644 } |
| 601 } else { | 645 } else { |
| 602 dictionary.SetBoolean("encrypted", false); | 646 dictionary.SetBoolean("encrypted", false); |
| 603 } | 647 } |
| 604 } | 648 } |
| 605 } else if (type == chromeos::TYPE_CELLULAR) { | 649 } else if (type == chromeos::TYPE_CELLULAR) { |
| 606 chromeos::CellularNetwork* cellular = | 650 chromeos::CellularNetwork* cellular = |
| 607 cros->FindCellularNetworkByPath(net->service_path()); | 651 cros->FindCellularNetworkByPath(net->service_path()); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 FormatHardwareAddress(hardware_address)); | 692 FormatHardwareAddress(hardware_address)); |
| 649 } | 693 } |
| 650 | 694 |
| 651 dom_ui_->CallJavascriptFunction( | 695 dom_ui_->CallJavascriptFunction( |
| 652 L"options.InternetOptions.showDetailedInfo", dictionary); | 696 L"options.InternetOptions.showDetailedInfo", dictionary); |
| 653 } | 697 } |
| 654 | 698 |
| 655 void InternetOptionsHandler::PopupWirelessPassword( | 699 void InternetOptionsHandler::PopupWirelessPassword( |
| 656 const chromeos::WifiNetwork* network) { | 700 const chromeos::WifiNetwork* network) { |
| 657 DictionaryValue dictionary; | 701 DictionaryValue dictionary; |
| 658 dictionary.SetString("servicePath",network->service_path()); | 702 dictionary.SetString("servicePath", network->service_path()); |
| 659 if (network->encryption() == chromeos::SECURITY_8021X) { | 703 if (network->encryption() == chromeos::SECURITY_8021X) { |
| 660 dictionary.SetBoolean("certNeeded", true); | 704 dictionary.SetBoolean("certNeeded", true); |
| 661 dictionary.SetString("ident", network->identity()); | 705 dictionary.SetString("ident", network->identity()); |
| 662 dictionary.SetString("cert", network->cert_path()); | 706 dictionary.SetString("cert", network->cert_path()); |
| 663 } else { | 707 } else { |
| 664 dictionary.SetBoolean("certNeeded", false); | 708 dictionary.SetBoolean("certNeeded", false); |
| 665 } | 709 } |
| 666 dom_ui_->CallJavascriptFunction( | 710 dom_ui_->CallJavascriptFunction( |
| 667 L"options.InternetOptions.showPasswordEntry", dictionary); | 711 L"options.InternetOptions.showPasswordEntry", dictionary); |
| 668 } | 712 } |
| 669 | 713 |
| 670 void InternetOptionsHandler::LoginCallback(const ListValue* args) { | 714 void InternetOptionsHandler::LoginCallback(const ListValue* args) { |
| 671 | |
| 672 std::string service_path; | 715 std::string service_path; |
| 673 std::string password; | 716 std::string password; |
| 674 | 717 |
| 675 if (args->GetSize() != 2 || | 718 if (args->GetSize() != 2 || |
| 676 !args->GetString(0, &service_path) || | 719 !args->GetString(0, &service_path) || |
| 677 !args->GetString(1, &password)) { | 720 !args->GetString(1, &password)) { |
| 678 NOTREACHED(); | 721 NOTREACHED(); |
| 679 return; | 722 return; |
| 680 } | 723 } |
| 681 | 724 |
| 682 chromeos::NetworkLibrary* cros = | 725 chromeos::NetworkLibrary* cros = |
| 683 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | 726 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); |
| 684 chromeos::WifiNetwork* network = cros->FindWifiNetworkByPath(service_path); | 727 chromeos::WifiNetwork* network = cros->FindWifiNetworkByPath(service_path); |
| 685 if (network) { | 728 if (network) { |
| 686 cros->ConnectToWifiNetwork( | 729 cros->ConnectToWifiNetwork( |
| 687 network, password, std::string(), std::string()); | 730 network, password, std::string(), std::string()); |
| 688 } else { | 731 } else { |
| 689 // Network disappeared while the user is connecting to it. | 732 // Network disappeared while the user is connecting to it. |
| 690 // TODO(chocobo): Display error message. | 733 // TODO(chocobo): Display error message. |
| 691 LOG(WARNING) << "Cannot find network to connect " << service_path; | 734 LOG(WARNING) << "Cannot find network to connect " << service_path; |
| 692 } | 735 } |
| 693 } | 736 } |
| 694 | 737 |
| 695 void InternetOptionsHandler::LoginCertCallback(const ListValue* args) { | 738 void InternetOptionsHandler::LoginCertCallback(const ListValue* args) { |
| 696 | |
| 697 std::string service_path; | 739 std::string service_path; |
| 698 std::string identity; | 740 std::string identity; |
| 699 std::string certpath; | 741 std::string certpath; |
| 700 if (args->GetSize() < 3 || | 742 if (args->GetSize() < 3 || |
| 701 !args->GetString(0, &service_path) || | 743 !args->GetString(0, &service_path) || |
| 702 !args->GetString(1, &certpath) || | 744 !args->GetString(1, &certpath) || |
| 703 !args->GetString(2, &identity)) { | 745 !args->GetString(2, &identity)) { |
| 704 return; | 746 return; |
| 705 } | 747 } |
| 706 chromeos::NetworkLibrary* cros = | 748 chromeos::NetworkLibrary* cros = |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 927 false, | 969 false, |
| 928 chromeos::ACTIVATION_STATE_UNKNOWN)); | 970 chromeos::ACTIVATION_STATE_UNKNOWN)); |
| 929 } | 971 } |
| 930 | 972 |
| 931 const chromeos::CellularNetworkVector cellular_networks = | 973 const chromeos::CellularNetworkVector cellular_networks = |
| 932 cros->cellular_networks(); | 974 cros->cellular_networks(); |
| 933 for (chromeos::CellularNetworkVector::const_iterator it = | 975 for (chromeos::CellularNetworkVector::const_iterator it = |
| 934 cellular_networks.begin(); it != cellular_networks.end(); ++it) { | 976 cellular_networks.begin(); it != cellular_networks.end(); ++it) { |
| 935 SkBitmap icon = chromeos::NetworkMenu::IconForNetworkStrength( | 977 SkBitmap icon = chromeos::NetworkMenu::IconForNetworkStrength( |
| 936 (*it)->strength(), true); | 978 (*it)->strength(), true); |
| 937 SkBitmap badge = *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_3G); | 979 SkBitmap badge = chromeos::NetworkMenu::BadgeForNetworkTechnology(*it); |
| 938 icon = chromeos::NetworkMenu::IconForDisplay(icon, badge); | 980 icon = chromeos::NetworkMenu::IconForDisplay(icon, badge); |
| 939 list->Append(GetNetwork( | 981 list->Append(GetNetwork( |
| 940 (*it)->service_path(), | 982 (*it)->service_path(), |
| 941 icon, | 983 icon, |
| 942 (*it)->name(), | 984 (*it)->name(), |
| 943 (*it)->connecting(), | 985 (*it)->connecting(), |
| 944 (*it)->connected(), | 986 (*it)->connected(), |
| 945 chromeos::TYPE_CELLULAR, | 987 chromeos::TYPE_CELLULAR, |
| 946 false, | 988 false, |
| 947 (*it)->activation_state())); | 989 (*it)->activation_state())); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 983 icon, | 1025 icon, |
| 984 (*it)->name(), | 1026 (*it)->name(), |
| 985 (*it)->connecting(), | 1027 (*it)->connecting(), |
| 986 (*it)->connected(), | 1028 (*it)->connected(), |
| 987 chromeos::TYPE_WIFI, | 1029 chromeos::TYPE_WIFI, |
| 988 true, | 1030 true, |
| 989 chromeos::ACTIVATION_STATE_UNKNOWN)); | 1031 chromeos::ACTIVATION_STATE_UNKNOWN)); |
| 990 } | 1032 } |
| 991 return list; | 1033 return list; |
| 992 } | 1034 } |
| OLD | NEW |