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 <map> |
9 #include <string> | 10 #include <string> |
10 #include <vector> | 11 #include <vector> |
11 | 12 |
12 #include "base/base64.h" | 13 #include "base/base64.h" |
13 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
14 #include "base/callback.h" | 15 #include "base/callback.h" |
15 #include "base/i18n/time_formatting.h" | 16 #include "base/i18n/time_formatting.h" |
16 #include "base/string16.h" | 17 #include "base/string16.h" |
17 #include "base/string_number_conversions.h" | 18 #include "base/string_number_conversions.h" |
18 #include "base/time.h" | 19 #include "base/time.h" |
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
992 true, | 993 true, |
993 chromeos::TYPE_WIFI, | 994 chromeos::TYPE_WIFI, |
994 false, | 995 false, |
995 chromeos::ACTIVATION_STATE_UNKNOWN, | 996 chromeos::ACTIVATION_STATE_UNKNOWN, |
996 false)); | 997 false)); |
997 } | 998 } |
998 | 999 |
999 return list; | 1000 return list; |
1000 } | 1001 } |
1001 | 1002 |
| 1003 std::string GetWifiUniqueIdentifier(const chromeos::WifiNetwork* wifi) { |
| 1004 return wifi->encryption() + "|" + wifi->name(); |
| 1005 } |
| 1006 |
1002 ListValue* InternetOptionsHandler::GetRememberedList() { | 1007 ListValue* InternetOptionsHandler::GetRememberedList() { |
1003 chromeos::NetworkLibrary* cros = | 1008 chromeos::NetworkLibrary* cros = |
1004 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | 1009 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); |
1005 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 1010 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
1006 ListValue* list = new ListValue(); | 1011 ListValue* list = new ListValue(); |
1007 | 1012 |
| 1013 const chromeos::WifiNetworkVector& remembered_wifi_networks = |
| 1014 cros->remembered_wifi_networks(); |
1008 const chromeos::WifiNetworkVector& wifi_networks = | 1015 const chromeos::WifiNetworkVector& wifi_networks = |
1009 cros->remembered_wifi_networks(); | 1016 cros->wifi_networks(); |
1010 for (chromeos::WifiNetworkVector::const_iterator it = | 1017 |
1011 wifi_networks.begin(); it != wifi_networks.end(); ++it) { | 1018 // The remembered networks from libcros/flimflam don't include the signal |
1012 SkBitmap icon = *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0_BLACK); | 1019 // strength, so fall back to the detected networks for this data. We |
1013 if ((*it)->encrypted()) { | 1020 // consider networks to be the same if they have the same name and encryption |
| 1021 // type, so create a map of detected networks indexed by name + encryption. |
| 1022 std::map<std::string, chromeos::WifiNetwork*> wifi_map; |
| 1023 for (chromeos::WifiNetworkVector::const_iterator it = wifi_networks.begin(); |
| 1024 it != wifi_networks.end(); ++it) { |
| 1025 wifi_map[GetWifiUniqueIdentifier(*it)] = *it; |
| 1026 } |
| 1027 |
| 1028 for (chromeos::WifiNetworkVector::const_iterator rit = |
| 1029 remembered_wifi_networks.begin(); |
| 1030 rit != remembered_wifi_networks.end(); ++rit) { |
| 1031 chromeos::WifiNetwork* wifi = *rit; |
| 1032 // Check if this remembered network has a matching detected network. |
| 1033 std::map<std::string, chromeos::WifiNetwork*>::const_iterator it = |
| 1034 wifi_map.find(GetWifiUniqueIdentifier(wifi)); |
| 1035 bool found = it != wifi_map.end(); |
| 1036 |
| 1037 // Don't show the active network in the remembered list. |
| 1038 if (found && (it->second)->connected()) |
| 1039 continue; |
| 1040 SkBitmap icon; |
| 1041 if (found) |
| 1042 icon = chromeos::NetworkMenu::IconForNetworkStrength(it->second, true); |
| 1043 else |
| 1044 icon = *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0_BLACK); |
| 1045 // Place the secure badge on the icon if the remembered network is |
| 1046 // encrypted (the matching detected network, if any, will have the same |
| 1047 // encrypted property by definition). |
| 1048 if (wifi->encrypted()) { |
1014 icon = chromeos::NetworkMenu::IconForDisplay(icon, | 1049 icon = chromeos::NetworkMenu::IconForDisplay(icon, |
1015 *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_SECURE)); | 1050 *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_SECURE)); |
1016 } | 1051 } |
1017 list->Append(GetNetwork( | 1052 list->Append(GetNetwork( |
1018 (*it)->service_path(), | 1053 wifi->service_path(), |
1019 icon, | 1054 icon, |
1020 (*it)->name(), | 1055 wifi->name(), |
1021 (*it)->connecting(), | 1056 wifi->connecting(), |
1022 (*it)->connected(), | 1057 wifi->connected(), |
1023 true, | 1058 true, |
1024 chromeos::TYPE_WIFI, | 1059 chromeos::TYPE_WIFI, |
1025 true, | 1060 true, |
1026 chromeos::ACTIVATION_STATE_UNKNOWN, | 1061 chromeos::ACTIVATION_STATE_UNKNOWN, |
1027 false)); | 1062 false)); |
1028 } | 1063 } |
1029 return list; | 1064 return list; |
1030 } | 1065 } |
1031 | 1066 |
1032 void InternetOptionsHandler::FillNetworkInfo( | 1067 void InternetOptionsHandler::FillNetworkInfo( |
1033 DictionaryValue* dictionary, chromeos::NetworkLibrary* cros) { | 1068 DictionaryValue* dictionary, chromeos::NetworkLibrary* cros) { |
1034 dictionary->SetBoolean("accessLocked", cros->IsLocked()); | 1069 dictionary->SetBoolean("accessLocked", cros->IsLocked()); |
1035 dictionary->Set("wiredList", GetWiredList()); | 1070 dictionary->Set("wiredList", GetWiredList()); |
1036 dictionary->Set("wirelessList", GetWirelessList()); | 1071 dictionary->Set("wirelessList", GetWirelessList()); |
1037 dictionary->Set("rememberedList", GetRememberedList()); | 1072 dictionary->Set("rememberedList", GetRememberedList()); |
1038 dictionary->SetBoolean("wifiAvailable", cros->wifi_available()); | 1073 dictionary->SetBoolean("wifiAvailable", cros->wifi_available()); |
1039 dictionary->SetBoolean("wifiEnabled", cros->wifi_enabled()); | 1074 dictionary->SetBoolean("wifiEnabled", cros->wifi_enabled()); |
1040 dictionary->SetBoolean("cellularAvailable", cros->cellular_available()); | 1075 dictionary->SetBoolean("cellularAvailable", cros->cellular_available()); |
1041 dictionary->SetBoolean("cellularEnabled", cros->cellular_enabled()); | 1076 dictionary->SetBoolean("cellularEnabled", cros->cellular_enabled()); |
1042 } | 1077 } |
OLD | NEW |