Update {virtual,override,final} to follow C++11 style chrome/browser/ui/webui/chromeos.
[chromium-blink-merge.git] / chrome / browser / ui / webui / chromeos / mobile_setup_ui.cc
blob31b9e821f05046609f6d16c65dfbc6f5ee193e50
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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/webui/chromeos/mobile_setup_ui.h"
7 #include <algorithm>
8 #include <map>
9 #include <string>
11 #include "base/bind.h"
12 #include "base/bind_helpers.h"
13 #include "base/json/json_writer.h"
14 #include "base/logging.h"
15 #include "base/memory/ref_counted_memory.h"
16 #include "base/memory/weak_ptr.h"
17 #include "base/message_loop/message_loop.h"
18 #include "base/metrics/histogram.h"
19 #include "base/strings/string_piece.h"
20 #include "base/strings/string_util.h"
21 #include "base/strings/utf_string_conversions.h"
22 #include "base/values.h"
23 #include "chrome/browser/chromeos/mobile/mobile_activator.h"
24 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/ui/browser_list.h"
26 #include "chrome/common/render_messages.h"
27 #include "chrome/common/url_constants.h"
28 #include "chrome/grit/generated_resources.h"
29 #include "chrome/grit/locale_settings.h"
30 #include "chromeos/network/device_state.h"
31 #include "chromeos/network/network_configuration_handler.h"
32 #include "chromeos/network/network_event_log.h"
33 #include "chromeos/network/network_state.h"
34 #include "chromeos/network/network_state_handler.h"
35 #include "chromeos/network/network_state_handler_observer.h"
36 #include "content/public/browser/browser_thread.h"
37 #include "content/public/browser/render_frame_host.h"
38 #include "content/public/browser/url_data_source.h"
39 #include "content/public/browser/web_contents.h"
40 #include "content/public/browser/web_ui.h"
41 #include "content/public/browser/web_ui_message_handler.h"
42 #include "grit/browser_resources.h"
43 #include "third_party/cros_system_api/dbus/service_constants.h"
44 #include "ui/base/l10n/l10n_util.h"
45 #include "ui/base/resource/resource_bundle.h"
46 #include "ui/base/webui/jstemplate_builder.h"
47 #include "ui/base/webui/web_ui_util.h"
48 #include "url/gurl.h"
50 using chromeos::MobileActivator;
51 using chromeos::NetworkHandler;
52 using chromeos::NetworkState;
53 using content::BrowserThread;
54 using content::RenderViewHost;
55 using content::WebContents;
56 using content::WebUIMessageHandler;
58 namespace {
60 // Host page JS API function names.
61 const char kJsApiStartActivation[] = "startActivation";
62 const char kJsApiSetTransactionStatus[] = "setTransactionStatus";
63 const char kJsApiPaymentPortalLoad[] = "paymentPortalLoad";
64 const char kJsGetDeviceInfo[] = "getDeviceInfo";
65 const char kJsApiResultOK[] = "ok";
67 const char kJsDeviceStatusChangedCallback[] =
68 "mobile.MobileSetup.deviceStateChanged";
69 const char kJsPortalFrameLoadFailedCallback[] =
70 "mobile.MobileSetup.portalFrameLoadError";
71 const char kJsPortalFrameLoadCompletedCallback[] =
72 "mobile.MobileSetup.portalFrameLoadCompleted";
73 const char kJsGetDeviceInfoCallback[] =
74 "mobile.MobileSetupPortal.onGotDeviceInfo";
75 const char kJsConnectivityChangedCallback[] =
76 "mobile.MobileSetupPortal.onConnectivityChanged";
78 void DataRequestFailed(
79 const std::string& service_path,
80 const content::URLDataSource::GotDataCallback& callback) {
81 NET_LOG_ERROR("Data Request Failed for Mobile Setup", service_path);
82 scoped_refptr<base::RefCountedBytes> html_bytes(new base::RefCountedBytes);
83 callback.Run(html_bytes.get());
86 // Converts the network properties into a JS object.
87 void GetDeviceInfo(const base::DictionaryValue& properties,
88 base::DictionaryValue* value) {
89 std::string name;
90 properties.GetStringWithoutPathExpansion(shill::kNameProperty, &name);
91 std::string activation_type;
92 properties.GetStringWithoutPathExpansion(
93 shill::kActivationTypeProperty,
94 &activation_type);
95 const base::DictionaryValue* payment_dict;
96 std::string payment_url, post_method, post_data;
97 if (properties.GetDictionaryWithoutPathExpansion(
98 shill::kPaymentPortalProperty, &payment_dict)) {
99 payment_dict->GetStringWithoutPathExpansion(
100 shill::kPaymentPortalURL, &payment_url);
101 payment_dict->GetStringWithoutPathExpansion(
102 shill::kPaymentPortalMethod, &post_method);
103 payment_dict->GetStringWithoutPathExpansion(
104 shill::kPaymentPortalPostData, &post_data);
107 value->SetString("activation_type", activation_type);
108 value->SetString("carrier", name);
109 value->SetString("payment_url", payment_url);
110 if (LowerCaseEqualsASCII(post_method, "post") && !post_data.empty())
111 value->SetString("post_data", post_data);
113 // Use the cached DeviceState properties.
114 std::string device_path;
115 if (!properties.GetStringWithoutPathExpansion(
116 shill::kDeviceProperty, &device_path) ||
117 device_path.empty()) {
118 return;
120 const chromeos::DeviceState* device =
121 NetworkHandler::Get()->network_state_handler()->GetDeviceState(
122 device_path);
123 if (!device)
124 return;
126 value->SetString("MEID", device->meid());
127 value->SetString("IMEI", device->imei());
128 value->SetString("MDN", device->mdn());
131 void SetActivationStateAndError(MobileActivator::PlanActivationState state,
132 const std::string& error_description,
133 base::DictionaryValue* value) {
134 value->SetInteger("state", state);
135 if (!error_description.empty())
136 value->SetString("error", error_description);
139 } // namespace
141 class MobileSetupUIHTMLSource : public content::URLDataSource {
142 public:
143 MobileSetupUIHTMLSource();
145 // content::URLDataSource implementation.
146 std::string GetSource() const override;
147 void StartDataRequest(
148 const std::string& path,
149 int render_process_id,
150 int render_frame_id,
151 const content::URLDataSource::GotDataCallback& callback) override;
152 std::string GetMimeType(const std::string&) const override {
153 return "text/html";
155 bool ShouldAddContentSecurityPolicy() const override { return false; }
157 private:
158 ~MobileSetupUIHTMLSource() override {}
160 void GetPropertiesAndStartDataRequest(
161 const content::URLDataSource::GotDataCallback& callback,
162 const std::string& service_path,
163 const base::DictionaryValue& properties);
164 void GetPropertiesFailure(
165 const content::URLDataSource::GotDataCallback& callback,
166 const std::string& service_path,
167 const std::string& error_name,
168 scoped_ptr<base::DictionaryValue> error_data);
170 base::WeakPtrFactory<MobileSetupUIHTMLSource> weak_ptr_factory_;
172 DISALLOW_COPY_AND_ASSIGN(MobileSetupUIHTMLSource);
175 // The handler for Javascript messages related to the "register" view.
176 class MobileSetupHandler
177 : public WebUIMessageHandler,
178 public MobileActivator::Observer,
179 public chromeos::NetworkStateHandlerObserver,
180 public base::SupportsWeakPtr<MobileSetupHandler> {
181 public:
182 MobileSetupHandler();
183 ~MobileSetupHandler() override;
185 // WebUIMessageHandler implementation.
186 void RegisterMessages() override;
188 private:
189 enum Type {
190 TYPE_UNDETERMINED,
191 // The network is not yet activated, and the webui is in activation flow.
192 TYPE_ACTIVATION,
193 // The network is activated, the webui displays network portal.
194 TYPE_PORTAL,
195 // Same as TYPE_PORTAL, but the network technology is LTE. The webui is
196 // additionally aware of network manager state and whether the portal can be
197 // reached.
198 TYPE_PORTAL_LTE
201 // MobileActivator::Observer.
202 void OnActivationStateChanged(const NetworkState* network,
203 MobileActivator::PlanActivationState new_state,
204 const std::string& error_description) override;
206 // Callbacks for NetworkConfigurationHandler::GetProperties.
207 void GetPropertiesAndCallStatusChanged(
208 MobileActivator::PlanActivationState state,
209 const std::string& error_description,
210 const std::string& service_path,
211 const base::DictionaryValue& properties);
212 void GetPropertiesAndCallGetDeviceInfo(
213 const std::string& service_path,
214 const base::DictionaryValue& properties);
215 void GetPropertiesFailure(
216 const std::string& service_path,
217 const std::string& callback_name,
218 const std::string& error_name,
219 scoped_ptr<base::DictionaryValue> error_data);
221 // Handlers for JS WebUI messages.
222 void HandleSetTransactionStatus(const base::ListValue* args);
223 void HandleStartActivation(const base::ListValue* args);
224 void HandlePaymentPortalLoad(const base::ListValue* args);
225 void HandleGetDeviceInfo(const base::ListValue* args);
227 // NetworkStateHandlerObserver implementation.
228 void NetworkConnectionStateChanged(const NetworkState* network) override;
229 void DefaultNetworkChanged(const NetworkState* default_network) override;
231 // Updates |lte_portal_reachable_| for lte network |network| and notifies
232 // webui of the new state if the reachability changed or |force_notification|
233 // is set.
234 void UpdatePortalReachability(const NetworkState* network,
235 bool force_notification);
237 // Sends message to host registration page with system/user info data.
238 void SendDeviceInfo();
240 // Type of the mobilesetup webui deduced from received messages.
241 Type type_;
242 // Whether portal page for lte networks can be reached in current network
243 // connection state. This value is reflected in portal webui for lte networks.
244 // Initial value is true.
245 bool lte_portal_reachable_;
246 base::WeakPtrFactory<MobileSetupHandler> weak_ptr_factory_;
248 DISALLOW_COPY_AND_ASSIGN(MobileSetupHandler);
251 ////////////////////////////////////////////////////////////////////////////////
253 // MobileSetupUIHTMLSource
255 ////////////////////////////////////////////////////////////////////////////////
257 MobileSetupUIHTMLSource::MobileSetupUIHTMLSource()
258 : weak_ptr_factory_(this) {
261 std::string MobileSetupUIHTMLSource::GetSource() const {
262 return chrome::kChromeUIMobileSetupHost;
265 void MobileSetupUIHTMLSource::StartDataRequest(
266 const std::string& path,
267 int render_process_id,
268 int render_frame_id,
269 const content::URLDataSource::GotDataCallback& callback) {
270 NetworkHandler::Get()->network_configuration_handler()->GetProperties(
271 path,
272 base::Bind(&MobileSetupUIHTMLSource::GetPropertiesAndStartDataRequest,
273 weak_ptr_factory_.GetWeakPtr(),
274 callback),
275 base::Bind(&MobileSetupUIHTMLSource::GetPropertiesFailure,
276 weak_ptr_factory_.GetWeakPtr(),
277 callback, path));
280 void MobileSetupUIHTMLSource::GetPropertiesAndStartDataRequest(
281 const content::URLDataSource::GotDataCallback& callback,
282 const std::string& service_path,
283 const base::DictionaryValue& properties) {
284 const base::DictionaryValue* payment_dict;
285 std::string name, usage_url, activation_state, payment_url;
286 if (!properties.GetStringWithoutPathExpansion(
287 shill::kNameProperty, &name) ||
288 !properties.GetStringWithoutPathExpansion(
289 shill::kUsageURLProperty, &usage_url) ||
290 !properties.GetStringWithoutPathExpansion(
291 shill::kActivationStateProperty, &activation_state) ||
292 !properties.GetDictionaryWithoutPathExpansion(
293 shill::kPaymentPortalProperty, &payment_dict) ||
294 !payment_dict->GetStringWithoutPathExpansion(
295 shill::kPaymentPortalURL, &payment_url)) {
296 DataRequestFailed(service_path, callback);
297 return;
300 if (payment_url.empty() && usage_url.empty() &&
301 activation_state != shill::kActivationStateActivated) {
302 DataRequestFailed(service_path, callback);
303 return;
306 NET_LOG_EVENT("Starting mobile setup", service_path);
307 base::DictionaryValue strings;
309 strings.SetString("connecting_header",
310 l10n_util::GetStringFUTF16(IDS_MOBILE_CONNECTING_HEADER,
311 base::UTF8ToUTF16(name)));
312 strings.SetString("error_header",
313 l10n_util::GetStringUTF16(IDS_MOBILE_ERROR_HEADER));
314 strings.SetString("activating_header",
315 l10n_util::GetStringUTF16(IDS_MOBILE_ACTIVATING_HEADER));
316 strings.SetString("completed_header",
317 l10n_util::GetStringUTF16(IDS_MOBILE_COMPLETED_HEADER));
318 strings.SetString("please_wait",
319 l10n_util::GetStringUTF16(IDS_MOBILE_PLEASE_WAIT));
320 strings.SetString("completed_text",
321 l10n_util::GetStringUTF16(IDS_MOBILE_COMPLETED_TEXT));
322 strings.SetString("portal_unreachable_header",
323 l10n_util::GetStringUTF16(IDS_MOBILE_NO_CONNECTION_HEADER));
324 strings.SetString("invalid_device_info_header",
325 l10n_util::GetStringUTF16(IDS_MOBILE_INVALID_DEVICE_INFO_HEADER));
326 strings.SetString("title", l10n_util::GetStringUTF16(IDS_MOBILE_SETUP_TITLE));
327 strings.SetString("close_button",
328 l10n_util::GetStringUTF16(IDS_CLOSE));
329 strings.SetString("cancel_button",
330 l10n_util::GetStringUTF16(IDS_CANCEL));
331 strings.SetString("ok_button",
332 l10n_util::GetStringUTF16(IDS_OK));
333 webui::SetFontAndTextDirection(&strings);
335 // The webui differs based on whether the network is activated or not. If the
336 // network is activated, the webui goes straight to portal. Otherwise the
337 // webui is used for activation flow.
338 std::string full_html;
339 if (activation_state == shill::kActivationStateActivated) {
340 static const base::StringPiece html_for_activated(
341 ResourceBundle::GetSharedInstance().GetRawDataResource(
342 IDR_MOBILE_SETUP_PORTAL_PAGE_HTML));
343 full_html = webui::GetI18nTemplateHtml(html_for_activated, &strings);
344 } else {
345 static const base::StringPiece html_for_non_activated(
346 ResourceBundle::GetSharedInstance().GetRawDataResource(
347 IDR_MOBILE_SETUP_PAGE_HTML));
348 full_html = webui::GetI18nTemplateHtml(html_for_non_activated, &strings);
351 callback.Run(base::RefCountedString::TakeString(&full_html));
354 void MobileSetupUIHTMLSource::GetPropertiesFailure(
355 const content::URLDataSource::GotDataCallback& callback,
356 const std::string& service_path,
357 const std::string& error_name,
358 scoped_ptr<base::DictionaryValue> error_data) {
359 DataRequestFailed(service_path, callback);
362 ////////////////////////////////////////////////////////////////////////////////
364 // MobileSetupHandler
366 ////////////////////////////////////////////////////////////////////////////////
367 MobileSetupHandler::MobileSetupHandler()
368 : type_(TYPE_UNDETERMINED),
369 lte_portal_reachable_(true),
370 weak_ptr_factory_(this) {
373 MobileSetupHandler::~MobileSetupHandler() {
374 if (type_ == TYPE_ACTIVATION) {
375 MobileActivator::GetInstance()->RemoveObserver(this);
376 MobileActivator::GetInstance()->TerminateActivation();
377 } else if (type_ == TYPE_PORTAL_LTE) {
378 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this,
379 FROM_HERE);
383 void MobileSetupHandler::OnActivationStateChanged(
384 const NetworkState* network,
385 MobileActivator::PlanActivationState state,
386 const std::string& error_description) {
387 DCHECK_EQ(TYPE_ACTIVATION, type_);
388 if (!web_ui())
389 return;
391 if (!network) {
392 base::DictionaryValue device_dict;
393 SetActivationStateAndError(state, error_description, &device_dict);
394 web_ui()->CallJavascriptFunction(kJsDeviceStatusChangedCallback,
395 device_dict);
396 return;
399 NetworkHandler::Get()->network_configuration_handler()->GetProperties(
400 network->path(),
401 base::Bind(&MobileSetupHandler::GetPropertiesAndCallStatusChanged,
402 weak_ptr_factory_.GetWeakPtr(),
403 state,
404 error_description),
405 base::Bind(&MobileSetupHandler::GetPropertiesFailure,
406 weak_ptr_factory_.GetWeakPtr(),
407 network->path(),
408 kJsDeviceStatusChangedCallback));
411 void MobileSetupHandler::GetPropertiesAndCallStatusChanged(
412 MobileActivator::PlanActivationState state,
413 const std::string& error_description,
414 const std::string& service_path,
415 const base::DictionaryValue& properties) {
416 base::DictionaryValue device_dict;
417 GetDeviceInfo(properties, &device_dict);
418 SetActivationStateAndError(state, error_description, &device_dict);
419 web_ui()->CallJavascriptFunction(kJsDeviceStatusChangedCallback, device_dict);
422 void MobileSetupHandler::RegisterMessages() {
423 web_ui()->RegisterMessageCallback(kJsApiStartActivation,
424 base::Bind(&MobileSetupHandler::HandleStartActivation,
425 base::Unretained(this)));
426 web_ui()->RegisterMessageCallback(kJsApiSetTransactionStatus,
427 base::Bind(&MobileSetupHandler::HandleSetTransactionStatus,
428 base::Unretained(this)));
429 web_ui()->RegisterMessageCallback(kJsApiPaymentPortalLoad,
430 base::Bind(&MobileSetupHandler::HandlePaymentPortalLoad,
431 base::Unretained(this)));
432 web_ui()->RegisterMessageCallback(kJsGetDeviceInfo,
433 base::Bind(&MobileSetupHandler::HandleGetDeviceInfo,
434 base::Unretained(this)));
437 void MobileSetupHandler::HandleStartActivation(const base::ListValue* args) {
438 DCHECK_EQ(TYPE_UNDETERMINED, type_);
440 if (!web_ui())
441 return;
443 std::string path = web_ui()->GetWebContents()->GetURL().path();
444 if (!path.size())
445 return;
447 LOG(WARNING) << "Starting activation for service " << path;
449 type_ = TYPE_ACTIVATION;
450 MobileActivator::GetInstance()->AddObserver(this);
451 MobileActivator::GetInstance()->InitiateActivation(path.substr(1));
454 void MobileSetupHandler::HandleSetTransactionStatus(
455 const base::ListValue* args) {
456 DCHECK_EQ(TYPE_ACTIVATION, type_);
457 if (!web_ui())
458 return;
460 const size_t kSetTransactionStatusParamCount = 1;
461 if (args->GetSize() != kSetTransactionStatusParamCount)
462 return;
463 // Get change callback function name.
464 std::string status;
465 if (!args->GetString(0, &status))
466 return;
468 MobileActivator::GetInstance()->OnSetTransactionStatus(
469 LowerCaseEqualsASCII(status, kJsApiResultOK));
472 void MobileSetupHandler::HandlePaymentPortalLoad(const base::ListValue* args) {
473 // Only activation flow webui is interested in these events.
474 if (type_ != TYPE_ACTIVATION || !web_ui())
475 return;
477 const size_t kPaymentPortalLoadParamCount = 1;
478 if (args->GetSize() != kPaymentPortalLoadParamCount)
479 return;
480 // Get change callback function name.
481 std::string result;
482 if (!args->GetString(0, &result))
483 return;
485 MobileActivator::GetInstance()->OnPortalLoaded(
486 LowerCaseEqualsASCII(result, kJsApiResultOK));
489 void MobileSetupHandler::HandleGetDeviceInfo(const base::ListValue* args) {
490 DCHECK_NE(TYPE_ACTIVATION, type_);
491 if (!web_ui())
492 return;
494 std::string path = web_ui()->GetWebContents()->GetURL().path();
495 if (path.empty())
496 return;
498 chromeos::NetworkStateHandler* nsh =
499 NetworkHandler::Get()->network_state_handler();
500 // TODO: Figure out why the path has an extra '/' in the front. (e.g. It is
501 // '//service/5' instead of '/service/5'.
502 const NetworkState* network = nsh->GetNetworkState(path.substr(1));
503 if (!network) {
504 web_ui()->GetWebContents()->Close();
505 return;
508 // If this is the initial call, update the network status and start observing
509 // network changes, but only for LTE networks. The other networks should
510 // ignore network status.
511 if (type_ == TYPE_UNDETERMINED) {
512 if (network->network_technology() == shill::kNetworkTechnologyLte ||
513 network->network_technology() == shill::kNetworkTechnologyLteAdvanced) {
514 type_ = TYPE_PORTAL_LTE;
515 nsh->AddObserver(this, FROM_HERE);
516 // Update the network status and notify the webui. This is the initial
517 // network state so the webui should be notified no matter what.
518 UpdatePortalReachability(network,
519 true /* force notification */);
520 } else {
521 type_ = TYPE_PORTAL;
522 // For non-LTE networks network state is ignored, so report the portal is
523 // reachable, so it gets shown.
524 web_ui()->CallJavascriptFunction(kJsConnectivityChangedCallback,
525 base::FundamentalValue(true));
529 NetworkHandler::Get()->network_configuration_handler()->GetProperties(
530 network->path(),
531 base::Bind(&MobileSetupHandler::GetPropertiesAndCallGetDeviceInfo,
532 weak_ptr_factory_.GetWeakPtr()),
533 base::Bind(&MobileSetupHandler::GetPropertiesFailure,
534 weak_ptr_factory_.GetWeakPtr(),
535 network->path(),
536 kJsGetDeviceInfoCallback));
539 void MobileSetupHandler::GetPropertiesAndCallGetDeviceInfo(
540 const std::string& service_path,
541 const base::DictionaryValue& properties) {
542 base::DictionaryValue device_info;
543 GetDeviceInfo(properties, &device_info);
544 web_ui()->CallJavascriptFunction(kJsGetDeviceInfoCallback, device_info);
547 void MobileSetupHandler::GetPropertiesFailure(
548 const std::string& service_path,
549 const std::string& callback_name,
550 const std::string& error_name,
551 scoped_ptr<base::DictionaryValue> error_data) {
552 NET_LOG_ERROR("MobileActivator GetProperties Failed: " + error_name,
553 service_path);
554 // Invoke |callback_name| with an empty dictionary.
555 base::DictionaryValue device_dict;
556 web_ui()->CallJavascriptFunction(callback_name, device_dict);
559 void MobileSetupHandler::DefaultNetworkChanged(
560 const NetworkState* default_network) {
561 if (!web_ui())
562 return;
564 std::string path = web_ui()->GetWebContents()->GetURL().path().substr(1);
565 if (path.empty())
566 return;
568 const NetworkState* network =
569 NetworkHandler::Get()->network_state_handler()->GetNetworkState(path);
570 if (!network) {
571 LOG(ERROR) << "Service path lost";
572 web_ui()->GetWebContents()->Close();
573 return;
576 UpdatePortalReachability(network, false /* do not force notification */);
579 void MobileSetupHandler::NetworkConnectionStateChanged(
580 const NetworkState* network) {
581 if (!web_ui())
582 return;
584 std::string path = web_ui()->GetWebContents()->GetURL().path().substr(1);
585 if (path.empty() || path != network->path())
586 return;
588 UpdatePortalReachability(network, false /* do not force notification */);
591 void MobileSetupHandler::UpdatePortalReachability(
592 const NetworkState* network,
593 bool force_notification) {
594 DCHECK(web_ui());
596 DCHECK_EQ(type_, TYPE_PORTAL_LTE);
598 chromeos::NetworkStateHandler* nsh =
599 NetworkHandler::Get()->network_state_handler();
600 bool portal_reachable =
601 (network->IsConnectedState() ||
602 (nsh->DefaultNetwork() &&
603 nsh->DefaultNetwork()->connection_state() == shill::kStateOnline));
605 if (force_notification || portal_reachable != lte_portal_reachable_) {
606 web_ui()->CallJavascriptFunction(kJsConnectivityChangedCallback,
607 base::FundamentalValue(portal_reachable));
610 lte_portal_reachable_ = portal_reachable;
613 ////////////////////////////////////////////////////////////////////////////////
615 // MobileSetupUI
617 ////////////////////////////////////////////////////////////////////////////////
619 MobileSetupUI::MobileSetupUI(content::WebUI* web_ui)
620 : WebUIController(web_ui) {
621 web_ui->AddMessageHandler(new MobileSetupHandler());
622 MobileSetupUIHTMLSource* html_source = new MobileSetupUIHTMLSource();
624 // Set up the chrome://mobilesetup/ source.
625 Profile* profile = Profile::FromWebUI(web_ui);
626 content::URLDataSource::Add(profile, html_source);
628 content::WebContentsObserver::Observe(web_ui->GetWebContents());
631 void MobileSetupUI::DidCommitProvisionalLoadForFrame(
632 content::RenderFrameHost* render_frame_host,
633 const GURL& url,
634 ui::PageTransition transition_type) {
635 if (render_frame_host->GetFrameName() != "paymentForm")
636 return;
638 web_ui()->CallJavascriptFunction(
639 kJsPortalFrameLoadCompletedCallback);
642 void MobileSetupUI::DidFailProvisionalLoad(
643 content::RenderFrameHost* render_frame_host,
644 const GURL& validated_url,
645 int error_code,
646 const base::string16& error_description) {
647 if (render_frame_host->GetFrameName() != "paymentForm")
648 return;
650 base::FundamentalValue result_value(-error_code);
651 web_ui()->CallJavascriptFunction(kJsPortalFrameLoadFailedCallback,
652 result_value);