Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc

Issue 561073002: Use ONC carrier info in JS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@issue_279351_internet_options_10a
Patch Set: Rebase Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/webui/options/chromeos/internet_options_handler.h" 5 #include "chrome/browser/ui/webui/options/chromeos/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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 const char kTagCellularEnabled[] = "cellularEnabled"; 116 const char kTagCellularEnabled[] = "cellularEnabled";
117 const char kTagCellularSupportsScan[] = "cellularSupportsScan"; 117 const char kTagCellularSupportsScan[] = "cellularSupportsScan";
118 const char kTagConfigure[] = "configure"; 118 const char kTagConfigure[] = "configure";
119 const char kTagConnect[] = "connect"; 119 const char kTagConnect[] = "connect";
120 const char kTagDeviceConnected[] = "deviceConnected"; 120 const char kTagDeviceConnected[] = "deviceConnected";
121 const char kTagDisconnect[] = "disconnect"; 121 const char kTagDisconnect[] = "disconnect";
122 const char kTagErrorMessage[] = "errorMessage"; 122 const char kTagErrorMessage[] = "errorMessage";
123 const char kTagForget[] = "forget"; 123 const char kTagForget[] = "forget";
124 const char kTagOptions[] = "options"; 124 const char kTagOptions[] = "options";
125 const char kTagRememberedList[] = "rememberedList"; 125 const char kTagRememberedList[] = "rememberedList";
126 const char kTagCarriers[] = "carriers";
127 const char kTagCurrentCarrierIndex[] = "currentCarrierIndex";
128 const char kTagShowViewAccountButton[] = "showViewAccountButton"; 126 const char kTagShowViewAccountButton[] = "showViewAccountButton";
129 const char kTagTrue[] = "true"; 127 const char kTagTrue[] = "true";
130 const char kTagVpnList[] = "vpnList"; 128 const char kTagVpnList[] = "vpnList";
131 const char kTagWifiAvailable[] = "wifiAvailable"; 129 const char kTagWifiAvailable[] = "wifiAvailable";
132 const char kTagWifiEnabled[] = "wifiEnabled"; 130 const char kTagWifiEnabled[] = "wifiEnabled";
133 const char kTagWimaxAvailable[] = "wimaxAvailable"; 131 const char kTagWimaxAvailable[] = "wimaxAvailable";
134 const char kTagWimaxEnabled[] = "wimaxEnabled"; 132 const char kTagWimaxEnabled[] = "wimaxEnabled";
135 const char kTagWiredList[] = "wiredList"; 133 const char kTagWiredList[] = "wiredList";
136 const char kTagWirelessList[] = "wirelessList"; 134 const char kTagWirelessList[] = "wirelessList";
137 135
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 180
183 std::string icon_url = ui::network_icon::GetImageUrlForNetwork( 181 std::string icon_url = ui::network_icon::GetImageUrlForNetwork(
184 network, ui::network_icon::ICON_TYPE_LIST, icon_scale_factor); 182 network, ui::network_icon::ICON_TYPE_LIST, icon_scale_factor);
185 183
186 network_info->SetString(kNetworkInfoKeyIconURL, icon_url); 184 network_info->SetString(kNetworkInfoKeyIconURL, icon_url);
187 network_info->SetString(kNetworkInfoKeyServicePath, network->path()); 185 network_info->SetString(kNetworkInfoKeyServicePath, network->path());
188 186
189 return network_info.release(); 187 return network_info.release();
190 } 188 }
191 189
192 // Given a list of supported carrier's by the device, return the index of 190 bool ShowViewAccountButton(const NetworkState* cellular) {
193 // the carrier the device is currently using. 191 if (cellular->activation_state() != shill::kActivationStateActivating &&
194 int FindCurrentCarrierIndex(const base::ListValue* carriers, 192 cellular->activation_state() != shill::kActivationStateActivated)
195 const DeviceState* device) { 193 return false;
196 DCHECK(carriers);
197 DCHECK(device);
198 bool gsm = (device->technology_family() == shill::kTechnologyFamilyGsm);
199 int index = 0;
200 for (base::ListValue::const_iterator it = carriers->begin();
201 it != carriers->end(); ++it, ++index) {
202 std::string value;
203 if (!(*it)->GetAsString(&value))
204 continue;
205 // For GSM devices the device name will be empty, so simply select
206 // the Generic UMTS carrier option if present.
207 if (gsm && (value == shill::kCarrierGenericUMTS))
208 return index;
209 // For other carriers, the service name will match the carrier name.
210 if (value == device->carrier())
211 return index;
212 }
213 return -1;
214 }
215 194
216 void PopulateCellularDetails(const NetworkState* cellular,
217 base::DictionaryValue* dictionary) {
218 dictionary->SetBoolean(kTagCarrierSelectFlag,
219 CommandLine::ForCurrentProcess()->HasSwitch(
220 chromeos::switches::kEnableCarrierSwitching));
221
222 // These default to empty and are only set if device != NULL.
223 std::string carrier_id;
224 std::string mdn;
225
226 // Device settings.
227 const DeviceState* device = 195 const DeviceState* device =
228 NetworkHandler::Get()->network_state_handler()->GetDeviceState( 196 NetworkHandler::Get()->network_state_handler()->GetDeviceState(
229 cellular->device_path()); 197 cellular->device_path());
230 if (device) {
231 const base::DictionaryValue& device_properties = device->properties();
232 198
233 carrier_id = device->home_provider_id(); 199 // If no online payment URL was provided by shill, Check to see if the
234 device_properties.GetStringWithoutPathExpansion(shill::kMdnProperty, &mdn); 200 // MobileConfig carrier indicates that "View Account" should be shown.
235 201 if (cellular->payment_url().empty()) {
236 const base::ListValue* supported_carriers; 202 if (!device || !MobileConfig::GetInstance()->IsReady())
237 if (device_properties.GetListWithoutPathExpansion( 203 return false;
238 shill::kSupportedCarriersProperty, &supported_carriers)) { 204 const MobileConfig::Carrier* carrier =
239 dictionary->Set(kTagCarriers, supported_carriers->DeepCopy()); 205 MobileConfig::GetInstance()->GetCarrier(device->home_provider_id());
240 dictionary->SetInteger( 206 if (!carrier || !carrier->show_portal_button())
241 kTagCurrentCarrierIndex, 207 return false;
242 FindCurrentCarrierIndex(supported_carriers, device));
243 } else {
244 // In case of any error, set the current carrier tag to -1 indicating
245 // to the JS code to fallback to a single carrier.
246 dictionary->SetInteger(kTagCurrentCarrierIndex, -1);
247 }
248 } 208 }
249 209
250 if (cellular->activation_state() == shill::kActivationStateActivating || 210 if (!cellular->IsConnectedState()) {
251 cellular->activation_state() == shill::kActivationStateActivated) { 211 // Disconnected LTE networks should show the button if we are online and
252 // TODO(stevenjb): Determine if we actually need this check. The payment url 212 // the device's MDN is set. This is to enable users to update their plan
253 // property is commented as 'Deprecated' in service_constants.h and appears 213 // if they are out of credits.
254 // to be unset in Shill, but we still reference it in mobile_setup.cc. 214 if (!NetworkHandler::Get()->network_state_handler()->DefaultNetwork())
255 bool may_show_portal_button = !cellular->payment_url().empty(); 215 return false;
216 const std::string& technology = cellular->network_technology();
217 if (technology != shill::kNetworkTechnologyLte &&
218 technology != shill::kNetworkTechnologyLteAdvanced)
219 return false;
220 std::string mdn;
221 if (device) {
222 device->properties().GetStringWithoutPathExpansion(shill::kMdnProperty,
223 &mdn);
224 }
225 if (mdn.empty())
226 return false;
227 }
256 228
257 // If no online payment URL was provided by shill, fall back to 229 return true;
258 // MobileConfig to determine if the "View Account" should be shown.
259 if (!may_show_portal_button && MobileConfig::GetInstance()->IsReady()) {
260 const MobileConfig::Carrier* carrier =
261 MobileConfig::GetInstance()->GetCarrier(carrier_id);
262 may_show_portal_button = carrier && carrier->show_portal_button();
263 }
264 if (may_show_portal_button) {
265 // The button should be shown for a LTE network even when the LTE network
266 // is not connected, but CrOS is online. This is done to enable users to
267 // update their plan even if they are out of credits.
268 // The button should not be shown when the device's mdn is not set,
269 // because the network's proper portal url cannot be generated without it
270 const NetworkState* default_network =
271 NetworkHandler::Get()->network_state_handler()->DefaultNetwork();
272 const std::string& technology = cellular->network_technology();
273 bool force_show_view_account_button =
274 (technology == shill::kNetworkTechnologyLte ||
275 technology == shill::kNetworkTechnologyLteAdvanced) &&
276 default_network && !mdn.empty();
277
278 // The button will trigger ShowMorePlanInfoCallback() which will open
279 // carrier specific portal.
280 if (cellular->IsConnectedState() || force_show_view_account_button)
281 dictionary->SetBoolean(kTagShowViewAccountButton, true);
282 }
283 }
284 } 230 }
285 231
286 scoped_ptr<base::DictionaryValue> PopulateConnectionDetails( 232 scoped_ptr<base::DictionaryValue> PopulateConnectionDetails(
287 const NetworkState* network, 233 const NetworkState* network,
288 const base::DictionaryValue& onc_properties) { 234 const base::DictionaryValue& onc_properties) {
289 scoped_ptr<base::DictionaryValue> dictionary(onc_properties.DeepCopy()); 235 scoped_ptr<base::DictionaryValue> dictionary(onc_properties.DeepCopy());
290 236
291 dictionary->SetString(kNetworkInfoKeyServicePath, network->path()); 237 dictionary->SetString(kNetworkInfoKeyServicePath, network->path());
292 dictionary->SetString( 238 dictionary->SetString(
293 kTagErrorMessage, 239 kTagErrorMessage,
294 ash::network_connect::ErrorString(network->error(), network->path())); 240 ash::network_connect::ErrorString(network->error(), network->path()));
295 241
296 const std::string& type = network->type(); 242 const std::string& type = network->type();
297 243
298 const NetworkState* connected_network = 244 const NetworkState* connected_network =
299 NetworkHandler::Get()->network_state_handler()->ConnectedNetworkByType( 245 NetworkHandler::Get()->network_state_handler()->ConnectedNetworkByType(
300 NetworkTypePattern::Primitive(type)); 246 NetworkTypePattern::Primitive(type));
301 dictionary->SetBoolean(kTagDeviceConnected, connected_network != NULL); 247 dictionary->SetBoolean(kTagDeviceConnected, connected_network != NULL);
302 248
303 if (type == shill::kTypeCellular) 249 if (type == shill::kTypeCellular) {
304 PopulateCellularDetails(network, dictionary.get()); 250 dictionary->SetBoolean(
305 251 kTagCarrierSelectFlag,
252 CommandLine::ForCurrentProcess()
253 ->HasSwitch(chromeos::switches::kEnableCarrierSwitching));
254 dictionary->SetBoolean(kTagShowViewAccountButton,
255 ShowViewAccountButton(network));
256 }
306 return dictionary.Pass(); 257 return dictionary.Pass();
307 } 258 }
308 259
309 // Helper methods for SetIPConfigProperties 260 // Helper methods for SetIPConfigProperties
310 bool AppendPropertyKeyIfPresent(const std::string& key, 261 bool AppendPropertyKeyIfPresent(const std::string& key,
311 const base::DictionaryValue& old_properties, 262 const base::DictionaryValue& old_properties,
312 std::vector<std::string>* property_keys) { 263 std::vector<std::string>* property_keys) {
313 if (old_properties.HasKey(key)) { 264 if (old_properties.HasKey(key)) {
314 property_keys->push_back(key); 265 property_keys->push_back(key);
315 return true; 266 return true;
(...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after
1118 dictionary->SetBoolean( 1069 dictionary->SetBoolean(
1119 kTagWimaxAvailable, 1070 kTagWimaxAvailable,
1120 handler->IsTechnologyAvailable(NetworkTypePattern::Wimax())); 1071 handler->IsTechnologyAvailable(NetworkTypePattern::Wimax()));
1121 dictionary->SetBoolean( 1072 dictionary->SetBoolean(
1122 kTagWimaxEnabled, 1073 kTagWimaxEnabled,
1123 handler->IsTechnologyEnabled(NetworkTypePattern::Wimax())); 1074 handler->IsTechnologyEnabled(NetworkTypePattern::Wimax()));
1124 } 1075 }
1125 1076
1126 } // namespace options 1077 } // namespace options
1127 } // namespace chromeos 1078 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/resources/options/chromeos/internet_detail.js ('k') | chromeos/dbus/fake_shill_manager_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698