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 { | |
Charlie Lee
2011/01/26 17:57:36
Sorry, I was talking about this open brace. It sho
| |
1005 return wifi->encryption() + "|" + wifi->name(); | |
1006 } | |
1007 | |
1002 ListValue* InternetOptionsHandler::GetRememberedList() { | 1008 ListValue* InternetOptionsHandler::GetRememberedList() { |
1003 chromeos::NetworkLibrary* cros = | 1009 chromeos::NetworkLibrary* cros = |
1004 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | 1010 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); |
1005 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 1011 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
1006 ListValue* list = new ListValue(); | 1012 ListValue* list = new ListValue(); |
1007 | 1013 |
1014 const chromeos::WifiNetworkVector& remembered_wifi_networks = | |
1015 cros->remembered_wifi_networks(); | |
1008 const chromeos::WifiNetworkVector& wifi_networks = | 1016 const chromeos::WifiNetworkVector& wifi_networks = |
1009 cros->remembered_wifi_networks(); | 1017 cros->wifi_networks(); |
1010 for (chromeos::WifiNetworkVector::const_iterator it = | 1018 |
1011 wifi_networks.begin(); it != wifi_networks.end(); ++it) { | 1019 // The remembered networks from libcros/flimflam don't include the signal |
1012 SkBitmap icon = *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0_BLACK); | 1020 // strength, so fall back to the detected networks for this data. We |
1013 if ((*it)->encrypted()) { | 1021 // consider networks to be the same if they have the same name and encryption |
1014 icon = chromeos::NetworkMenu::IconForDisplay(icon, | 1022 // type, so create a map of detected networks indexed by name + encryption. |
1023 std::map<std::string, chromeos::WifiNetwork*> wifi_map; | |
1024 for (chromeos::WifiNetworkVector::const_iterator it = wifi_networks.begin(); | |
1025 it != wifi_networks.end(); ++it) { | |
1026 wifi_map[GetWifiUniqueIdentifier(*it)] = *it; | |
1027 } | |
1028 | |
1029 for (chromeos::WifiNetworkVector::const_iterator rit = | |
1030 remembered_wifi_networks.begin(); | |
1031 rit != remembered_wifi_networks.end(); ++rit) { | |
1032 chromeos::WifiNetwork* wifi = *rit; | |
1033 // Check if this remembered network has a matching detected network. | |
1034 std::map<std::string, chromeos::WifiNetwork*>::const_iterator it = | |
1035 wifi_map.find(GetWifiUniqueIdentifier(wifi)); | |
1036 bool found = it != wifi_map.end(); | |
1037 | |
1038 // Don't show the active network in the remembered list. | |
1039 if (found && (it->second)->connected()) | |
1040 continue; | |
1041 SkBitmap icon; | |
1042 if (found) | |
1043 icon = chromeos::NetworkMenu::IconForNetworkStrength(it->second, true); | |
1044 else | |
1045 icon = *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0_BLACK); | |
1046 // Place the secure badge on the icon if the remembered network is | |
1047 // encrypted (the matching detected network, if any, will have the same | |
1048 // encrypted property by definition). | |
1049 if (wifi->encrypted()) { | |
1050 icon = chromeos::NetworkMenu::IconForDisplay( | |
1051 icon, | |
Charlie Lee
2011/01/26 17:57:36
nit: either move "icon," to the previous line, or
| |
1015 *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_SECURE)); | 1052 *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_SECURE)); |
1016 } | 1053 } |
1017 list->Append(GetNetwork( | 1054 list->Append(GetNetwork( |
1018 (*it)->service_path(), | 1055 wifi->service_path(), |
1019 icon, | 1056 icon, |
1020 (*it)->name(), | 1057 wifi->name(), |
1021 (*it)->connecting(), | 1058 wifi->connecting(), |
1022 (*it)->connected(), | 1059 wifi->connected(), |
1023 true, | 1060 true, |
1024 chromeos::TYPE_WIFI, | 1061 chromeos::TYPE_WIFI, |
1025 true, | 1062 true, |
1026 chromeos::ACTIVATION_STATE_UNKNOWN, | 1063 chromeos::ACTIVATION_STATE_UNKNOWN, |
1027 false)); | 1064 false)); |
1028 } | 1065 } |
1029 return list; | 1066 return list; |
1030 } | 1067 } |
1031 | 1068 |
1032 void InternetOptionsHandler::FillNetworkInfo( | 1069 void InternetOptionsHandler::FillNetworkInfo( |
1033 DictionaryValue* dictionary, chromeos::NetworkLibrary* cros) { | 1070 DictionaryValue* dictionary, chromeos::NetworkLibrary* cros) { |
1034 dictionary->SetBoolean("accessLocked", cros->IsLocked()); | 1071 dictionary->SetBoolean("accessLocked", cros->IsLocked()); |
1035 dictionary->Set("wiredList", GetWiredList()); | 1072 dictionary->Set("wiredList", GetWiredList()); |
1036 dictionary->Set("wirelessList", GetWirelessList()); | 1073 dictionary->Set("wirelessList", GetWirelessList()); |
1037 dictionary->Set("rememberedList", GetRememberedList()); | 1074 dictionary->Set("rememberedList", GetRememberedList()); |
1038 dictionary->SetBoolean("wifiAvailable", cros->wifi_available()); | 1075 dictionary->SetBoolean("wifiAvailable", cros->wifi_available()); |
1039 dictionary->SetBoolean("wifiEnabled", cros->wifi_enabled()); | 1076 dictionary->SetBoolean("wifiEnabled", cros->wifi_enabled()); |
1040 dictionary->SetBoolean("cellularAvailable", cros->cellular_available()); | 1077 dictionary->SetBoolean("cellularAvailable", cros->cellular_available()); |
1041 dictionary->SetBoolean("cellularEnabled", cros->cellular_enabled()); | 1078 dictionary->SetBoolean("cellularEnabled", cros->cellular_enabled()); |
1042 } | 1079 } |
OLD | NEW |