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

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

Issue 23441025: Clean up NetworkState members (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 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 | Annotate | Revision Log
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/chromeos/mobile_setup_ui.h" 5 #include "chrome/browser/ui/webui/chromeos/mobile_setup_ui.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/json/json_writer.h" 13 #include "base/json/json_writer.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/memory/ref_counted_memory.h" 15 #include "base/memory/ref_counted_memory.h"
16 #include "base/memory/weak_ptr.h"
16 #include "base/message_loop/message_loop.h" 17 #include "base/message_loop/message_loop.h"
17 #include "base/metrics/histogram.h" 18 #include "base/metrics/histogram.h"
18 #include "base/strings/string_piece.h" 19 #include "base/strings/string_piece.h"
19 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
20 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
21 #include "base/values.h" 22 #include "base/values.h"
22 #include "chrome/browser/chromeos/mobile/mobile_activator.h" 23 #include "chrome/browser/chromeos/mobile/mobile_activator.h"
23 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/ui/browser_list.h" 25 #include "chrome/browser/ui/browser_list.h"
25 #include "chrome/common/pref_names.h" 26 #include "chrome/common/pref_names.h"
26 #include "chrome/common/render_messages.h" 27 #include "chrome/common/render_messages.h"
27 #include "chrome/common/url_constants.h" 28 #include "chrome/common/url_constants.h"
28 #include "chromeos/network/device_state.h" 29 #include "chromeos/network/device_state.h"
30 #include "chromeos/network/network_configuration_handler.h"
31 #include "chromeos/network/network_event_log.h"
29 #include "chromeos/network/network_state.h" 32 #include "chromeos/network/network_state.h"
30 #include "chromeos/network/network_state_handler.h" 33 #include "chromeos/network/network_state_handler.h"
31 #include "chromeos/network/network_state_handler_observer.h" 34 #include "chromeos/network/network_state_handler_observer.h"
32 #include "content/public/browser/browser_thread.h" 35 #include "content/public/browser/browser_thread.h"
33 #include "content/public/browser/render_view_host_observer.h" 36 #include "content/public/browser/render_view_host_observer.h"
34 #include "content/public/browser/url_data_source.h" 37 #include "content/public/browser/url_data_source.h"
35 #include "content/public/browser/web_contents.h" 38 #include "content/public/browser/web_contents.h"
36 #include "content/public/browser/web_ui.h" 39 #include "content/public/browser/web_ui.h"
37 #include "content/public/browser/web_ui_message_handler.h" 40 #include "content/public/browser/web_ui_message_handler.h"
38 #include "grit/browser_resources.h" 41 #include "grit/browser_resources.h"
(...skipping 28 matching lines...) Expand all
67 "mobile.MobileSetup.deviceStateChanged"; 70 "mobile.MobileSetup.deviceStateChanged";
68 const char kJsPortalFrameLoadFailedCallback[] = 71 const char kJsPortalFrameLoadFailedCallback[] =
69 "mobile.MobileSetup.portalFrameLoadError"; 72 "mobile.MobileSetup.portalFrameLoadError";
70 const char kJsPortalFrameLoadCompletedCallback[] = 73 const char kJsPortalFrameLoadCompletedCallback[] =
71 "mobile.MobileSetup.portalFrameLoadCompleted"; 74 "mobile.MobileSetup.portalFrameLoadCompleted";
72 const char kJsGetDeviceInfoCallback[] = 75 const char kJsGetDeviceInfoCallback[] =
73 "mobile.MobileSetupPortal.onGotDeviceInfo"; 76 "mobile.MobileSetupPortal.onGotDeviceInfo";
74 const char kJsConnectivityChangedCallback[] = 77 const char kJsConnectivityChangedCallback[] =
75 "mobile.MobileSetupPortal.onConnectivityChanged"; 78 "mobile.MobileSetupPortal.onConnectivityChanged";
76 79
80 void DataRequestFailed(
81 const std::string& service_path,
82 const content::URLDataSource::GotDataCallback& callback) {
83 NET_LOG_ERROR("Data Request Failed for Mobile Setup", service_path);
84 scoped_refptr<base::RefCountedBytes> html_bytes(new base::RefCountedBytes);
85 callback.Run(html_bytes.get());
86 }
87
88 // Converts the network properties into a JS object.
89 void GetDeviceInfo(const DictionaryValue& properties, DictionaryValue* value) {
90 std::string name;
91 properties.GetStringWithoutPathExpansion(
92 flimflam::kNameProperty, &name);
93 bool activate_over_non_cellular_networks = false;
94 properties.GetBooleanWithoutPathExpansion(
95 shill::kActivateOverNonCellularNetworkProperty,
96 &activate_over_non_cellular_networks);
97 const DictionaryValue* payment_dict;
98 std::string payment_url, post_method, post_data;
99 if (properties.GetDictionaryWithoutPathExpansion(
100 flimflam::kPaymentPortalProperty, &payment_dict)) {
101 payment_dict->GetStringWithoutPathExpansion(
102 flimflam::kPaymentPortalURL, &payment_url);
103 payment_dict->GetStringWithoutPathExpansion(
104 flimflam::kPaymentPortalMethod, &post_method);
105 payment_dict->GetStringWithoutPathExpansion(
106 flimflam::kPaymentPortalPostData, &post_data);
107 }
108
109 value->SetBoolean("activate_over_non_cellular_network",
110 activate_over_non_cellular_networks);
111 value->SetString("carrier", name);
112 value->SetString("payment_url", payment_url);
113 if (LowerCaseEqualsASCII(post_method, "post") && !post_data.empty())
114 value->SetString("post_data", post_data);
115
116 // Use the cached DeviceState properties.
117 std::string device_path;
118 if (!properties.GetStringWithoutPathExpansion(
119 flimflam::kDeviceProperty, &device_path) ||
120 device_path.empty()) {
121 return;
122 }
123 const chromeos::DeviceState* device =
124 NetworkHandler::Get()->network_state_handler()->GetDeviceState(
125 device_path);
126 if (!device)
127 return;
128
129 value->SetString("MEID", device->meid());
130 value->SetString("IMEI", device->imei());
131 value->SetString("MDN", device->mdn());
132 }
133
77 } // namespace 134 } // namespace
78 135
79 // Observes IPC messages from the rederer and notifies JS if frame loading error 136 // Observes IPC messages from the rederer and notifies JS if frame loading error
80 // appears. 137 // appears.
81 class PortalFrameLoadObserver : public content::RenderViewHostObserver { 138 class PortalFrameLoadObserver : public content::RenderViewHostObserver {
82 public: 139 public:
83 PortalFrameLoadObserver(const base::WeakPtr<MobileSetupUI>& parent, 140 PortalFrameLoadObserver(const base::WeakPtr<MobileSetupUI>& parent,
84 RenderViewHost* host) 141 RenderViewHost* host)
85 : content::RenderViewHostObserver(host), parent_(parent) { 142 : content::RenderViewHostObserver(host), parent_(parent) {
86 Send(new ChromeViewMsg_StartFrameSniffer(routing_id(), 143 Send(new ChromeViewMsg_StartFrameSniffer(routing_id(),
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 virtual std::string GetMimeType(const std::string&) const OVERRIDE { 192 virtual std::string GetMimeType(const std::string&) const OVERRIDE {
136 return "text/html"; 193 return "text/html";
137 } 194 }
138 virtual bool ShouldAddContentSecurityPolicy() const OVERRIDE { 195 virtual bool ShouldAddContentSecurityPolicy() const OVERRIDE {
139 return false; 196 return false;
140 } 197 }
141 198
142 private: 199 private:
143 virtual ~MobileSetupUIHTMLSource() {} 200 virtual ~MobileSetupUIHTMLSource() {}
144 201
202 void GetPropertiesSuccess(
203 const content::URLDataSource::GotDataCallback& callback,
204 const std::string& service_path,
205 const base::DictionaryValue& properties);
206 void GetPropertiesFailure(
207 const content::URLDataSource::GotDataCallback& callback,
208 const std::string& service_path,
209 const std::string& error_name,
210 scoped_ptr<base::DictionaryValue> error_data);
211
212 base::WeakPtrFactory<MobileSetupUIHTMLSource> weak_ptr_factory_;
213
145 DISALLOW_COPY_AND_ASSIGN(MobileSetupUIHTMLSource); 214 DISALLOW_COPY_AND_ASSIGN(MobileSetupUIHTMLSource);
146 }; 215 };
147 216
148 // The handler for Javascript messages related to the "register" view. 217 // The handler for Javascript messages related to the "register" view.
149 class MobileSetupHandler 218 class MobileSetupHandler
150 : public WebUIMessageHandler, 219 : public WebUIMessageHandler,
151 public MobileActivator::Observer, 220 public MobileActivator::Observer,
152 public chromeos::NetworkStateHandlerObserver, 221 public chromeos::NetworkStateHandlerObserver,
153 public base::SupportsWeakPtr<MobileSetupHandler> { 222 public base::SupportsWeakPtr<MobileSetupHandler> {
154 public: 223 public:
(...skipping 15 matching lines...) Expand all
170 // reached. 239 // reached.
171 TYPE_PORTAL_LTE 240 TYPE_PORTAL_LTE
172 }; 241 };
173 242
174 // MobileActivator::Observer. 243 // MobileActivator::Observer.
175 virtual void OnActivationStateChanged( 244 virtual void OnActivationStateChanged(
176 const NetworkState* network, 245 const NetworkState* network,
177 MobileActivator::PlanActivationState new_state, 246 MobileActivator::PlanActivationState new_state,
178 const std::string& error_description) OVERRIDE; 247 const std::string& error_description) OVERRIDE;
179 248
249 // Callbacks for NetworkConfigurationHandler::GetProperties.
250 void GetPropertiesAndCallStatusChanged(
251 MobileActivator::PlanActivationState state,
252 const std::string& error_description,
253 const std::string& service_path,
254 const base::DictionaryValue& properties);
255 void GetPropertiesAndCallGetDeviceInfo(
256 const std::string& service_path,
257 const base::DictionaryValue& properties);
258 void GetPropertiesFailure(
259 const std::string& service_path,
260 const std::string& callback_name,
261 const std::string& error_name,
262 scoped_ptr<base::DictionaryValue> error_data);
263
180 // Handlers for JS WebUI messages. 264 // Handlers for JS WebUI messages.
181 void HandleSetTransactionStatus(const ListValue* args); 265 void HandleSetTransactionStatus(const ListValue* args);
182 void HandleStartActivation(const ListValue* args); 266 void HandleStartActivation(const ListValue* args);
183 void HandlePaymentPortalLoad(const ListValue* args); 267 void HandlePaymentPortalLoad(const ListValue* args);
184 void HandleGetDeviceInfo(const ListValue* args); 268 void HandleGetDeviceInfo(const ListValue* args);
185 269
186 // NetworkStateHandlerObserver implementation. 270 // NetworkStateHandlerObserver implementation.
187 virtual void NetworkManagerChanged() OVERRIDE; 271 virtual void NetworkManagerChanged() OVERRIDE;
188 virtual void DefaultNetworkChanged( 272 virtual void DefaultNetworkChanged(
189 const NetworkState* default_network) OVERRIDE; 273 const NetworkState* default_network) OVERRIDE;
190 274
191 // Updates |lte_portal_reachable_| for lte network |network| and notifies 275 // Updates |lte_portal_reachable_| for lte network |network| and notifies
192 // webui of the new state if the reachability changed or |force_notification| 276 // webui of the new state if the reachability changed or |force_notification|
193 // is set. 277 // is set.
194 void UpdatePortalReachability(const NetworkState* network, 278 void UpdatePortalReachability(const NetworkState* network,
195 bool force_notification); 279 bool force_notification);
196 280
197 // Sends message to host registration page with system/user info data. 281 // Sends message to host registration page with system/user info data.
198 void SendDeviceInfo(); 282 void SendDeviceInfo();
199 283
200 // Converts the currently active CellularNetwork device into a JS object.
201 static void GetDeviceInfo(const NetworkState* network,
202 DictionaryValue* value);
203
204 // Type of the mobilesetup webui deduced from received messages. 284 // Type of the mobilesetup webui deduced from received messages.
205 Type type_; 285 Type type_;
206 // Whether portal page for lte networks can be reached in current network 286 // Whether portal page for lte networks can be reached in current network
207 // connection state. This value is reflected in portal webui for lte networks. 287 // connection state. This value is reflected in portal webui for lte networks.
208 // Initial value is true. 288 // Initial value is true.
209 bool lte_portal_reachable_; 289 bool lte_portal_reachable_;
290 base::WeakPtrFactory<MobileSetupHandler> weak_ptr_factory_;
210 291
211 DISALLOW_COPY_AND_ASSIGN(MobileSetupHandler); 292 DISALLOW_COPY_AND_ASSIGN(MobileSetupHandler);
212 }; 293 };
213 294
214 //////////////////////////////////////////////////////////////////////////////// 295 ////////////////////////////////////////////////////////////////////////////////
215 // 296 //
216 // MobileSetupUIHTMLSource 297 // MobileSetupUIHTMLSource
217 // 298 //
218 //////////////////////////////////////////////////////////////////////////////// 299 ////////////////////////////////////////////////////////////////////////////////
219 300
220 MobileSetupUIHTMLSource::MobileSetupUIHTMLSource() { 301 MobileSetupUIHTMLSource::MobileSetupUIHTMLSource()
302 : weak_ptr_factory_(this) {
221 } 303 }
222 304
223 std::string MobileSetupUIHTMLSource::GetSource() const { 305 std::string MobileSetupUIHTMLSource::GetSource() const {
224 return chrome::kChromeUIMobileSetupHost; 306 return chrome::kChromeUIMobileSetupHost;
225 } 307 }
226 308
227 void MobileSetupUIHTMLSource::StartDataRequest( 309 void MobileSetupUIHTMLSource::StartDataRequest(
228 const std::string& path, 310 const std::string& path,
229 int render_process_id, 311 int render_process_id,
230 int render_view_id, 312 int render_view_id,
231 const content::URLDataSource::GotDataCallback& callback) { 313 const content::URLDataSource::GotDataCallback& callback) {
232 const NetworkState* network = NULL; 314 NetworkHandler::Get()->network_configuration_handler()->GetProperties(
233 if (!path.empty()) { 315 path,
234 network = NetworkHandler::Get()->network_state_handler()->GetNetworkState( 316 base::Bind(&MobileSetupUIHTMLSource::GetPropertiesSuccess,
235 path); 317 weak_ptr_factory_.GetWeakPtr(),
236 } 318 callback),
319 base::Bind(&MobileSetupUIHTMLSource::GetPropertiesFailure,
320 weak_ptr_factory_.GetWeakPtr(),
321 callback, path));
322 }
237 323
238 if (!network || 324 void MobileSetupUIHTMLSource::GetPropertiesSuccess(
239 (network->payment_url().empty() && network->usage_url().empty() && 325 const content::URLDataSource::GotDataCallback& callback,
240 network->activation_state() != flimflam::kActivationStateActivated)) { 326 const std::string& service_path,
241 LOG(WARNING) << "Can't find device to activate for service path " << path; 327 const base::DictionaryValue& properties) {
242 scoped_refptr<base::RefCountedBytes> html_bytes(new base::RefCountedBytes); 328 const DictionaryValue* payment_dict;
243 callback.Run(html_bytes.get()); 329 std::string name, usage_url, activation_state, payment_url;
330 if (!properties.GetStringWithoutPathExpansion(
331 flimflam::kNameProperty, &name) ||
332 !properties.GetStringWithoutPathExpansion(
333 flimflam::kUsageURLProperty, &usage_url) ||
334 !properties.GetStringWithoutPathExpansion(
335 flimflam::kActivationStateProperty, &activation_state) ||
336 !properties.GetDictionaryWithoutPathExpansion(
337 flimflam::kPaymentPortalProperty, &payment_dict) ||
338 !payment_dict->GetStringWithoutPathExpansion(
339 flimflam::kPaymentPortalURL, &payment_url)) {
340 DataRequestFailed(service_path, callback);
244 return; 341 return;
245 } 342 }
246 343
247 LOG(WARNING) << "Starting mobile setup for " << path; 344 if (payment_url.empty() && usage_url.empty() &&
345 activation_state != flimflam::kActivationStateActivated) {
346 DataRequestFailed(service_path, callback);
347 return;
348 }
349
350 NET_LOG_EVENT("Starting mobile setup", service_path);
248 DictionaryValue strings; 351 DictionaryValue strings;
249 352
250 strings.SetString("connecting_header", 353 strings.SetString("connecting_header",
251 l10n_util::GetStringFUTF16(IDS_MOBILE_CONNECTING_HEADER, 354 l10n_util::GetStringFUTF16(IDS_MOBILE_CONNECTING_HEADER,
252 network ? UTF8ToUTF16(network->name()) : string16())); 355 UTF8ToUTF16(name)));
253 strings.SetString("error_header", 356 strings.SetString("error_header",
254 l10n_util::GetStringUTF16(IDS_MOBILE_ERROR_HEADER)); 357 l10n_util::GetStringUTF16(IDS_MOBILE_ERROR_HEADER));
255 strings.SetString("activating_header", 358 strings.SetString("activating_header",
256 l10n_util::GetStringUTF16(IDS_MOBILE_ACTIVATING_HEADER)); 359 l10n_util::GetStringUTF16(IDS_MOBILE_ACTIVATING_HEADER));
257 strings.SetString("completed_header", 360 strings.SetString("completed_header",
258 l10n_util::GetStringUTF16(IDS_MOBILE_COMPLETED_HEADER)); 361 l10n_util::GetStringUTF16(IDS_MOBILE_COMPLETED_HEADER));
259 strings.SetString("please_wait", 362 strings.SetString("please_wait",
260 l10n_util::GetStringUTF16(IDS_MOBILE_PLEASE_WAIT)); 363 l10n_util::GetStringUTF16(IDS_MOBILE_PLEASE_WAIT));
261 strings.SetString("completed_text", 364 strings.SetString("completed_text",
262 l10n_util::GetStringUTF16(IDS_MOBILE_COMPLETED_TEXT)); 365 l10n_util::GetStringUTF16(IDS_MOBILE_COMPLETED_TEXT));
263 strings.SetString("portal_unreachable_header", 366 strings.SetString("portal_unreachable_header",
264 l10n_util::GetStringUTF16(IDS_MOBILE_NO_CONNECTION_HEADER)); 367 l10n_util::GetStringUTF16(IDS_MOBILE_NO_CONNECTION_HEADER));
265 strings.SetString("invalid_device_info_header", 368 strings.SetString("invalid_device_info_header",
266 l10n_util::GetStringUTF16(IDS_MOBILE_INVALID_DEVICE_INFO_HEADER)); 369 l10n_util::GetStringUTF16(IDS_MOBILE_INVALID_DEVICE_INFO_HEADER));
267 strings.SetString("title", l10n_util::GetStringUTF16(IDS_MOBILE_SETUP_TITLE)); 370 strings.SetString("title", l10n_util::GetStringUTF16(IDS_MOBILE_SETUP_TITLE));
268 strings.SetString("close_button", 371 strings.SetString("close_button",
269 l10n_util::GetStringUTF16(IDS_CLOSE)); 372 l10n_util::GetStringUTF16(IDS_CLOSE));
270 strings.SetString("cancel_button", 373 strings.SetString("cancel_button",
271 l10n_util::GetStringUTF16(IDS_CANCEL)); 374 l10n_util::GetStringUTF16(IDS_CANCEL));
272 strings.SetString("ok_button", 375 strings.SetString("ok_button",
273 l10n_util::GetStringUTF16(IDS_OK)); 376 l10n_util::GetStringUTF16(IDS_OK));
274 webui::SetFontAndTextDirection(&strings); 377 webui::SetFontAndTextDirection(&strings);
275 378
276 // The webui differs based on whether the network is activated or not. If the 379 // The webui differs based on whether the network is activated or not. If the
277 // network is activated, the webui goes straight to portal. Otherwise the 380 // network is activated, the webui goes straight to portal. Otherwise the
278 // webui is used for activation flow. 381 // webui is used for activation flow.
279 std::string full_html; 382 std::string full_html;
280 if (network->activation_state() == flimflam::kActivationStateActivated) { 383 if (activation_state == flimflam::kActivationStateActivated) {
281 static const base::StringPiece html_for_activated( 384 static const base::StringPiece html_for_activated(
282 ResourceBundle::GetSharedInstance().GetRawDataResource( 385 ResourceBundle::GetSharedInstance().GetRawDataResource(
283 IDR_MOBILE_SETUP_PORTAL_PAGE_HTML)); 386 IDR_MOBILE_SETUP_PORTAL_PAGE_HTML));
284 full_html = webui::GetI18nTemplateHtml(html_for_activated, &strings); 387 full_html = webui::GetI18nTemplateHtml(html_for_activated, &strings);
285 } else { 388 } else {
286 static const base::StringPiece html_for_non_activated( 389 static const base::StringPiece html_for_non_activated(
287 ResourceBundle::GetSharedInstance().GetRawDataResource( 390 ResourceBundle::GetSharedInstance().GetRawDataResource(
288 IDR_MOBILE_SETUP_PAGE_HTML)); 391 IDR_MOBILE_SETUP_PAGE_HTML));
289 full_html = webui::GetI18nTemplateHtml(html_for_non_activated, &strings); 392 full_html = webui::GetI18nTemplateHtml(html_for_non_activated, &strings);
290 } 393 }
291 394
292 callback.Run(base::RefCountedString::TakeString(&full_html)); 395 callback.Run(base::RefCountedString::TakeString(&full_html));
293 } 396 }
294 397
398 void MobileSetupUIHTMLSource::GetPropertiesFailure(
399 const content::URLDataSource::GotDataCallback& callback,
400 const std::string& service_path,
401 const std::string& error_name,
402 scoped_ptr<base::DictionaryValue> error_data) {
403 DataRequestFailed(service_path, callback);
404 }
405
295 //////////////////////////////////////////////////////////////////////////////// 406 ////////////////////////////////////////////////////////////////////////////////
296 // 407 //
297 // MobileSetupHandler 408 // MobileSetupHandler
298 // 409 //
299 //////////////////////////////////////////////////////////////////////////////// 410 ////////////////////////////////////////////////////////////////////////////////
300 MobileSetupHandler::MobileSetupHandler() 411 MobileSetupHandler::MobileSetupHandler()
301 : type_(TYPE_UNDETERMINED), 412 : type_(TYPE_UNDETERMINED),
302 lte_portal_reachable_(true) { 413 lte_portal_reachable_(true),
414 weak_ptr_factory_(this) {
303 } 415 }
304 416
305 MobileSetupHandler::~MobileSetupHandler() { 417 MobileSetupHandler::~MobileSetupHandler() {
306 if (type_ == TYPE_ACTIVATION) { 418 if (type_ == TYPE_ACTIVATION) {
307 MobileActivator::GetInstance()->RemoveObserver(this); 419 MobileActivator::GetInstance()->RemoveObserver(this);
308 MobileActivator::GetInstance()->TerminateActivation(); 420 MobileActivator::GetInstance()->TerminateActivation();
309 } else if (type_ == TYPE_PORTAL_LTE) { 421 } else if (type_ == TYPE_PORTAL_LTE) {
310 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this, 422 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this,
311 FROM_HERE); 423 FROM_HERE);
312 } 424 }
313 } 425 }
314 426
315 void MobileSetupHandler::OnActivationStateChanged( 427 void MobileSetupHandler::OnActivationStateChanged(
316 const NetworkState* network, 428 const NetworkState* network,
317 MobileActivator::PlanActivationState state, 429 MobileActivator::PlanActivationState state,
318 const std::string& error_description) { 430 const std::string& error_description) {
319 DCHECK_EQ(TYPE_ACTIVATION, type_); 431 DCHECK_EQ(TYPE_ACTIVATION, type_);
320 if (!web_ui()) 432 if (!web_ui())
321 return; 433 return;
434 NetworkHandler::Get()->network_configuration_handler()->GetProperties(
435 network->path(),
436 base::Bind(&MobileSetupHandler::GetPropertiesAndCallStatusChanged,
437 weak_ptr_factory_.GetWeakPtr(),
438 state,
439 error_description),
440 base::Bind(&MobileSetupHandler::GetPropertiesFailure,
441 weak_ptr_factory_.GetWeakPtr(),
442 network->path(),
443 kJsDeviceStatusChangedCallback));
444 }
322 445
446 void MobileSetupHandler::GetPropertiesAndCallStatusChanged(
447 MobileActivator::PlanActivationState state,
448 const std::string& error_description,
449 const std::string& service_path,
450 const base::DictionaryValue& properties) {
323 DictionaryValue device_dict; 451 DictionaryValue device_dict;
324 if (network) 452 GetDeviceInfo(properties, &device_dict);
325 GetDeviceInfo(network, &device_dict);
326 device_dict.SetInteger("state", state); 453 device_dict.SetInteger("state", state);
327 if (error_description.length()) 454 if (error_description.length())
328 device_dict.SetString("error", error_description); 455 device_dict.SetString("error", error_description);
329 web_ui()->CallJavascriptFunction( 456 web_ui()->CallJavascriptFunction(
330 kJsDeviceStatusChangedCallback, device_dict); 457 kJsDeviceStatusChangedCallback, device_dict);
331 } 458 }
332 459
333 void MobileSetupHandler::RegisterMessages() { 460 void MobileSetupHandler::RegisterMessages() {
334 web_ui()->RegisterMessageCallback(kJsApiStartActivation, 461 web_ui()->RegisterMessageCallback(kJsApiStartActivation,
335 base::Bind(&MobileSetupHandler::HandleStartActivation, 462 base::Bind(&MobileSetupHandler::HandleStartActivation,
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 true /* force notification */); 557 true /* force notification */);
431 } else { 558 } else {
432 type_ = TYPE_PORTAL; 559 type_ = TYPE_PORTAL;
433 // For non-LTE networks network state is ignored, so report the portal is 560 // For non-LTE networks network state is ignored, so report the portal is
434 // reachable, so it gets shown. 561 // reachable, so it gets shown.
435 web_ui()->CallJavascriptFunction(kJsConnectivityChangedCallback, 562 web_ui()->CallJavascriptFunction(kJsConnectivityChangedCallback,
436 base::FundamentalValue(true)); 563 base::FundamentalValue(true));
437 } 564 }
438 } 565 }
439 566
567 NetworkHandler::Get()->network_configuration_handler()->GetProperties(
568 network->path(),
569 base::Bind(&MobileSetupHandler::GetPropertiesAndCallGetDeviceInfo,
570 weak_ptr_factory_.GetWeakPtr()),
571 base::Bind(&MobileSetupHandler::GetPropertiesFailure,
572 weak_ptr_factory_.GetWeakPtr(),
573 network->path(),
574 kJsGetDeviceInfoCallback));
575 }
576
577 void MobileSetupHandler::GetPropertiesAndCallGetDeviceInfo(
578 const std::string& service_path,
579 const base::DictionaryValue& properties) {
440 DictionaryValue device_info; 580 DictionaryValue device_info;
441 GetDeviceInfo(network, &device_info); 581 GetDeviceInfo(properties, &device_info);
442 web_ui()->CallJavascriptFunction(kJsGetDeviceInfoCallback, device_info); 582 web_ui()->CallJavascriptFunction(kJsGetDeviceInfoCallback, device_info);
443 } 583 }
444 584
585 void MobileSetupHandler::GetPropertiesFailure(
586 const std::string& service_path,
587 const std::string& callback_name,
588 const std::string& error_name,
589 scoped_ptr<base::DictionaryValue> error_data) {
590 NET_LOG_ERROR("MobileActivator GetProperties Failed: " + error_name,
591 service_path);
592 // Invoke |callback_name| with an empty dictionary.
593 DictionaryValue device_dict;
594 web_ui()->CallJavascriptFunction(callback_name, device_dict);
595 }
596
445 void MobileSetupHandler::NetworkManagerChanged() { 597 void MobileSetupHandler::NetworkManagerChanged() {
446 if (!web_ui()) 598 if (!web_ui())
447 return; 599 return;
448 600
449 std::string path = web_ui()->GetWebContents()->GetURL().path(); 601 std::string path = web_ui()->GetWebContents()->GetURL().path();
450 if (path.empty()) 602 if (path.empty())
451 return; 603 return;
452 604
453 const NetworkState* network = 605 const NetworkState* network =
454 NetworkHandler::Get()->network_state_handler()->GetNetworkState( 606 NetworkHandler::Get()->network_state_handler()->GetNetworkState(
(...skipping 28 matching lines...) Expand all
483 nsh->DefaultNetwork()->connection_state() == flimflam::kStateOnline)); 635 nsh->DefaultNetwork()->connection_state() == flimflam::kStateOnline));
484 636
485 if (force_notification || portal_reachable != lte_portal_reachable_) { 637 if (force_notification || portal_reachable != lte_portal_reachable_) {
486 web_ui()->CallJavascriptFunction(kJsConnectivityChangedCallback, 638 web_ui()->CallJavascriptFunction(kJsConnectivityChangedCallback,
487 base::FundamentalValue(portal_reachable)); 639 base::FundamentalValue(portal_reachable));
488 } 640 }
489 641
490 lte_portal_reachable_ = portal_reachable; 642 lte_portal_reachable_ = portal_reachable;
491 } 643 }
492 644
493 void MobileSetupHandler::GetDeviceInfo(const NetworkState* network,
494 DictionaryValue* value) {
495 DCHECK(network);
496 value->SetBoolean("activate_over_non_cellular_network",
497 network->activate_over_non_cellular_networks());
498 value->SetString("carrier", network->name());
499 value->SetString("payment_url", network->payment_url());
500 if (LowerCaseEqualsASCII(network->post_method(), "post") &&
501 !network->post_data().empty())
502 value->SetString("post_data", network->post_data());
503
504 const chromeos::DeviceState* device =
505 NetworkHandler::Get()->network_state_handler()->GetDeviceState(
506 network->device_path());
507 if (device) {
508 value->SetString("MEID", device->meid());
509 value->SetString("IMEI", device->imei());
510 value->SetString("MDN", device->mdn());
511 }
512 }
513
514 //////////////////////////////////////////////////////////////////////////////// 645 ////////////////////////////////////////////////////////////////////////////////
515 // 646 //
516 // MobileSetupUI 647 // MobileSetupUI
517 // 648 //
518 //////////////////////////////////////////////////////////////////////////////// 649 ////////////////////////////////////////////////////////////////////////////////
519 650
520 MobileSetupUI::MobileSetupUI(content::WebUI* web_ui) 651 MobileSetupUI::MobileSetupUI(content::WebUI* web_ui)
521 : WebUIController(web_ui) { 652 : WebUIController(web_ui) {
522 web_ui->AddMessageHandler(new MobileSetupHandler()); 653 web_ui->AddMessageHandler(new MobileSetupHandler());
523 MobileSetupUIHTMLSource* html_source = new MobileSetupUIHTMLSource(); 654 MobileSetupUIHTMLSource* html_source = new MobileSetupUIHTMLSource();
524 655
525 // Set up the chrome://mobilesetup/ source. 656 // Set up the chrome://mobilesetup/ source.
526 Profile* profile = Profile::FromWebUI(web_ui); 657 Profile* profile = Profile::FromWebUI(web_ui);
527 content::URLDataSource::Add(profile, html_source); 658 content::URLDataSource::Add(profile, html_source);
528 } 659 }
529 660
530 void MobileSetupUI::RenderViewCreated(RenderViewHost* host) { 661 void MobileSetupUI::RenderViewCreated(RenderViewHost* host) {
531 // Destroyed by the corresponding RenderViewHost 662 // Destroyed by the corresponding RenderViewHost
532 new PortalFrameLoadObserver(AsWeakPtr(), host); 663 new PortalFrameLoadObserver(AsWeakPtr(), host);
533 } 664 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698