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 "app/l10n_util.h" | 13 #include "app/l10n_util.h" |
13 #include "app/resource_bundle.h" | 14 #include "app/resource_bundle.h" |
14 #include "base/base64.h" | 15 #include "base/base64.h" |
15 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
16 #include "base/callback.h" | 17 #include "base/callback.h" |
17 #include "base/i18n/time_formatting.h" | 18 #include "base/i18n/time_formatting.h" |
18 #include "base/string16.h" | 19 #include "base/string16.h" |
19 #include "base/string_number_conversions.h" | 20 #include "base/string_number_conversions.h" |
20 #include "base/time.h" | 21 #include "base/time.h" |
21 #include "base/utf_string_conversions.h" | 22 #include "base/utf_string_conversions.h" |
22 #include "base/values.h" | 23 #include "base/values.h" |
23 #include "chrome/browser/browser_list.h" | 24 #include "chrome/browser/browser_list.h" |
24 #include "chrome/browser/browser_window.h" | 25 #include "chrome/browser/browser_window.h" |
25 #include "chrome/browser/chromeos/cros/cros_library.h" | 26 #include "chrome/browser/chromeos/cros/cros_library.h" |
26 #include "chrome/browser/chromeos/login/ownership_service.h" | 27 #include "chrome/browser/chromeos/login/ownership_service.h" |
27 #include "chrome/browser/chromeos/status/network_menu.h" | 28 #include "chrome/browser/chromeos/status/network_menu.h" |
28 #include "chrome/browser/dom_ui/dom_ui_util.h" | 29 #include "chrome/browser/dom_ui/dom_ui_util.h" |
29 #include "chrome/browser/ui/browser.h" | 30 #include "chrome/browser/ui/browser.h" |
30 #include "chrome/browser/ui/views/window.h" | 31 #include "chrome/browser/ui/views/window.h" |
31 #include "chrome/common/time_format.h" | 32 #include "chrome/common/time_format.h" |
32 #include "grit/browser_resources.h" | 33 #include "grit/browser_resources.h" |
33 #include "grit/chromium_strings.h" | 34 #include "grit/chromium_strings.h" |
34 #include "grit/generated_resources.h" | 35 #include "grit/generated_resources.h" |
35 #include "grit/locale_settings.h" | 36 #include "grit/locale_settings.h" |
36 #include "grit/theme_resources.h" | 37 #include "grit/theme_resources.h" |
38 #include "net/base/escape.h" | |
37 #include "views/window/window.h" | 39 #include "views/window/window.h" |
38 #include "third_party/skia/include/core/SkBitmap.h" | 40 #include "third_party/skia/include/core/SkBitmap.h" |
39 | 41 |
40 static const char kOtherNetworksFakePath[] = "?"; | 42 static const char kOtherNetworksFakePath[] = "?"; |
41 | 43 |
42 namespace { | 44 namespace { |
43 | 45 |
44 // Format the hardware address like "0011AA22BB33" => "00:11:AA:22:BB:33". | 46 // Format the hardware address like "0011AA22BB33" => "00:11:AA:22:BB:33". |
45 std::string FormatHardwareAddress(const std::string& address) { | 47 std::string FormatHardwareAddress(const std::string& address) { |
46 std::string output; | 48 std::string output; |
(...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
989 true, | 991 true, |
990 chromeos::TYPE_WIFI, | 992 chromeos::TYPE_WIFI, |
991 false, | 993 false, |
992 chromeos::ACTIVATION_STATE_UNKNOWN, | 994 chromeos::ACTIVATION_STATE_UNKNOWN, |
993 false)); | 995 false)); |
994 } | 996 } |
995 | 997 |
996 return list; | 998 return list; |
997 } | 999 } |
998 | 1000 |
1001 std::string GetWifiNetworkKey(const chromeos::WifiNetwork* wifi) | |
Charlie Lee
2011/01/25 17:56:07
parenthesis should be on the same line. also, I su
falken
2011/01/26 05:49:20
I see what you mean about network key. I don't un
| |
1002 { | |
1003 std::stringstream ss; | |
1004 ss << wifi->encryption() << "|" << EscapePath(wifi->name()); | |
stevenjb
2011/01/25 18:36:55
stringsteam is unnecessary, and I'm not clear why
falken
2011/01/26 05:49:20
Oops, for some reason I was thinking we had to esc
| |
1005 return ss.str(); | |
1006 } | |
1007 | |
999 ListValue* InternetOptionsHandler::GetRememberedList() { | 1008 ListValue* InternetOptionsHandler::GetRememberedList() { |
1000 chromeos::NetworkLibrary* cros = | 1009 chromeos::NetworkLibrary* cros = |
1001 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | 1010 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); |
1002 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 1011 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
1003 ListValue* list = new ListValue(); | 1012 ListValue* list = new ListValue(); |
1004 | 1013 |
1014 const chromeos::WifiNetworkVector& remembered_wifi_networks = | |
1015 cros->remembered_wifi_networks(); | |
1005 const chromeos::WifiNetworkVector& wifi_networks = | 1016 const chromeos::WifiNetworkVector& wifi_networks = |
1006 cros->remembered_wifi_networks(); | 1017 cros->wifi_networks(); |
1007 for (chromeos::WifiNetworkVector::const_iterator it = | 1018 |
1008 wifi_networks.begin(); it != wifi_networks.end(); ++it) { | 1019 // The remembered networks from libcros/flimflam don't include the signal |
1009 SkBitmap icon = *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0_BLACK); | 1020 // strength, so fall back to the detected networks for this data. We |
1010 if ((*it)->encrypted()) { | 1021 // consider networks to be the same if they have the same name and encryption |
1011 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) { | |
Charlie Lee
2011/01/25 17:56:07
I believe the ; should be at the end of the previo
| |
1026 wifi_map[GetWifiNetworkKey(*it)] = *it; | |
1027 } | |
1028 | |
1029 for (chromeos::WifiNetworkVector::const_iterator rit = | |
1030 remembered_wifi_networks.begin(); rit != remembered_wifi_networks.end(); | |
1031 ++rit) { | |
stevenjb
2011/01/25 18:36:55
Either put the second clause on its own line and f
| |
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(GetWifiNetworkKey(*rit)); | |
stevenjb
2011/01/25 18:36:55
= should be on first line.
| |
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 ((*rit)->encrypted()) { | |
stevenjb
2011/01/25 18:36:55
nit: since (*rit) is used a bunch here, might be m
| |
1049 icon = chromeos::NetworkMenu::IconForDisplay(icon, | |
Charlie Lee
2011/01/25 17:56:07
spacing
| |
1012 *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_SECURE)); | 1050 *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_SECURE)); |
1013 } | 1051 } |
1014 list->Append(GetNetwork( | 1052 list->Append(GetNetwork( |
1015 (*it)->service_path(), | 1053 (*rit)->service_path(), |
1016 icon, | 1054 icon, |
1017 (*it)->name(), | 1055 (*rit)->name(), |
1018 (*it)->connecting(), | 1056 (*rit)->connecting(), |
1019 (*it)->connected(), | 1057 (*rit)->connected(), |
1020 true, | 1058 true, |
1021 chromeos::TYPE_WIFI, | 1059 chromeos::TYPE_WIFI, |
1022 true, | 1060 true, |
1023 chromeos::ACTIVATION_STATE_UNKNOWN, | 1061 chromeos::ACTIVATION_STATE_UNKNOWN, |
1024 false)); | 1062 false)); |
1025 } | 1063 } |
1026 return list; | 1064 return list; |
1027 } | 1065 } |
1028 | 1066 |
1029 void InternetOptionsHandler::FillNetworkInfo( | 1067 void InternetOptionsHandler::FillNetworkInfo( |
1030 DictionaryValue* dictionary, chromeos::NetworkLibrary* cros) { | 1068 DictionaryValue* dictionary, chromeos::NetworkLibrary* cros) { |
1031 dictionary->Set("wiredList", GetWiredList()); | 1069 dictionary->Set("wiredList", GetWiredList()); |
1032 dictionary->Set("wirelessList", GetWirelessList()); | 1070 dictionary->Set("wirelessList", GetWirelessList()); |
1033 dictionary->Set("rememberedList", GetRememberedList()); | 1071 dictionary->Set("rememberedList", GetRememberedList()); |
1034 dictionary->SetBoolean("wifiAvailable", cros->wifi_available()); | 1072 dictionary->SetBoolean("wifiAvailable", cros->wifi_available()); |
1035 dictionary->SetBoolean("wifiEnabled", cros->wifi_enabled()); | 1073 dictionary->SetBoolean("wifiEnabled", cros->wifi_enabled()); |
1036 dictionary->SetBoolean("cellularAvailable", cros->cellular_available()); | 1074 dictionary->SetBoolean("cellularAvailable", cros->cellular_available()); |
1037 dictionary->SetBoolean("cellularEnabled", cros->cellular_enabled()); | 1075 dictionary->SetBoolean("cellularEnabled", cros->cellular_enabled()); |
1038 } | 1076 } |
OLD | NEW |