Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / webui / chromeos / mobile_setup_ui.cc
blob40e9d6da6a94e6cfa4ed37a05dfa3abef309dafa
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/browser_process.h"
24 #include "chrome/browser/chromeos/mobile/mobile_activator.h"
25 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/browser/ui/browser_list.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 (base::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()->GetShillProperties(
271 path,
272 base::Bind(&MobileSetupUIHTMLSource::GetPropertiesAndStartDataRequest,
273 weak_ptr_factory_.GetWeakPtr(), callback),
274 base::Bind(&MobileSetupUIHTMLSource::GetPropertiesFailure,
275 weak_ptr_factory_.GetWeakPtr(), callback, path));
278 void MobileSetupUIHTMLSource::GetPropertiesAndStartDataRequest(
279 const content::URLDataSource::GotDataCallback& callback,
280 const std::string& service_path,
281 const base::DictionaryValue& properties) {
282 const base::DictionaryValue* payment_dict;
283 std::string name, usage_url, activation_state, payment_url;
284 if (!properties.GetStringWithoutPathExpansion(
285 shill::kNameProperty, &name) ||
286 !properties.GetStringWithoutPathExpansion(
287 shill::kUsageURLProperty, &usage_url) ||
288 !properties.GetStringWithoutPathExpansion(
289 shill::kActivationStateProperty, &activation_state) ||
290 !properties.GetDictionaryWithoutPathExpansion(
291 shill::kPaymentPortalProperty, &payment_dict) ||
292 !payment_dict->GetStringWithoutPathExpansion(
293 shill::kPaymentPortalURL, &payment_url)) {
294 DataRequestFailed(service_path, callback);
295 return;
298 if (payment_url.empty() && usage_url.empty() &&
299 activation_state != shill::kActivationStateActivated) {
300 DataRequestFailed(service_path, callback);
301 return;
304 NET_LOG_EVENT("Starting mobile setup", service_path);
305 base::DictionaryValue strings;
307 strings.SetString("connecting_header",
308 l10n_util::GetStringFUTF16(IDS_MOBILE_CONNECTING_HEADER,
309 base::UTF8ToUTF16(name)));
310 strings.SetString("error_header",
311 l10n_util::GetStringUTF16(IDS_MOBILE_ERROR_HEADER));
312 strings.SetString("activating_header",
313 l10n_util::GetStringUTF16(IDS_MOBILE_ACTIVATING_HEADER));
314 strings.SetString("completed_header",
315 l10n_util::GetStringUTF16(IDS_MOBILE_COMPLETED_HEADER));
316 strings.SetString("please_wait",
317 l10n_util::GetStringUTF16(IDS_MOBILE_PLEASE_WAIT));
318 strings.SetString("completed_text",
319 l10n_util::GetStringUTF16(IDS_MOBILE_COMPLETED_TEXT));
320 strings.SetString("portal_unreachable_header",
321 l10n_util::GetStringUTF16(IDS_MOBILE_NO_CONNECTION_HEADER));
322 strings.SetString("invalid_device_info_header",
323 l10n_util::GetStringUTF16(IDS_MOBILE_INVALID_DEVICE_INFO_HEADER));
324 strings.SetString("title", l10n_util::GetStringUTF16(IDS_MOBILE_SETUP_TITLE));
325 strings.SetString("close_button",
326 l10n_util::GetStringUTF16(IDS_CLOSE));
327 strings.SetString("cancel_button",
328 l10n_util::GetStringUTF16(IDS_CANCEL));
329 strings.SetString("ok_button",
330 l10n_util::GetStringUTF16(IDS_OK));
332 const std::string& app_locale = g_browser_process->GetApplicationLocale();
333 webui::SetLoadTimeDataDefaults(app_locale, &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()->GetShillProperties(
400 network->path(),
401 base::Bind(&MobileSetupHandler::GetPropertiesAndCallStatusChanged,
402 weak_ptr_factory_.GetWeakPtr(), state, error_description),
403 base::Bind(&MobileSetupHandler::GetPropertiesFailure,
404 weak_ptr_factory_.GetWeakPtr(), network->path(),
405 kJsDeviceStatusChangedCallback));
408 void MobileSetupHandler::GetPropertiesAndCallStatusChanged(
409 MobileActivator::PlanActivationState state,
410 const std::string& error_description,
411 const std::string& service_path,
412 const base::DictionaryValue& properties) {
413 base::DictionaryValue device_dict;
414 GetDeviceInfo(properties, &device_dict);
415 SetActivationStateAndError(state, error_description, &device_dict);
416 web_ui()->CallJavascriptFunction(kJsDeviceStatusChangedCallback, device_dict);
419 void MobileSetupHandler::RegisterMessages() {
420 web_ui()->RegisterMessageCallback(kJsApiStartActivation,
421 base::Bind(&MobileSetupHandler::HandleStartActivation,
422 base::Unretained(this)));
423 web_ui()->RegisterMessageCallback(kJsApiSetTransactionStatus,
424 base::Bind(&MobileSetupHandler::HandleSetTransactionStatus,
425 base::Unretained(this)));
426 web_ui()->RegisterMessageCallback(kJsApiPaymentPortalLoad,
427 base::Bind(&MobileSetupHandler::HandlePaymentPortalLoad,
428 base::Unretained(this)));
429 web_ui()->RegisterMessageCallback(kJsGetDeviceInfo,
430 base::Bind(&MobileSetupHandler::HandleGetDeviceInfo,
431 base::Unretained(this)));
434 void MobileSetupHandler::HandleStartActivation(const base::ListValue* args) {
435 DCHECK_EQ(TYPE_UNDETERMINED, type_);
437 if (!web_ui())
438 return;
440 std::string path = web_ui()->GetWebContents()->GetURL().path();
441 if (!path.size())
442 return;
444 LOG(WARNING) << "Starting activation for service " << path;
446 type_ = TYPE_ACTIVATION;
447 MobileActivator::GetInstance()->AddObserver(this);
448 MobileActivator::GetInstance()->InitiateActivation(path.substr(1));
451 void MobileSetupHandler::HandleSetTransactionStatus(
452 const base::ListValue* args) {
453 DCHECK_EQ(TYPE_ACTIVATION, type_);
454 if (!web_ui())
455 return;
457 const size_t kSetTransactionStatusParamCount = 1;
458 if (args->GetSize() != kSetTransactionStatusParamCount)
459 return;
460 // Get change callback function name.
461 std::string status;
462 if (!args->GetString(0, &status))
463 return;
465 MobileActivator::GetInstance()->OnSetTransactionStatus(
466 base::LowerCaseEqualsASCII(status, kJsApiResultOK));
469 void MobileSetupHandler::HandlePaymentPortalLoad(const base::ListValue* args) {
470 // Only activation flow webui is interested in these events.
471 if (type_ != TYPE_ACTIVATION || !web_ui())
472 return;
474 const size_t kPaymentPortalLoadParamCount = 1;
475 if (args->GetSize() != kPaymentPortalLoadParamCount)
476 return;
477 // Get change callback function name.
478 std::string result;
479 if (!args->GetString(0, &result))
480 return;
482 MobileActivator::GetInstance()->OnPortalLoaded(
483 base::LowerCaseEqualsASCII(result, kJsApiResultOK));
486 void MobileSetupHandler::HandleGetDeviceInfo(const base::ListValue* args) {
487 DCHECK_NE(TYPE_ACTIVATION, type_);
488 if (!web_ui())
489 return;
491 std::string path = web_ui()->GetWebContents()->GetURL().path();
492 if (path.empty())
493 return;
495 chromeos::NetworkStateHandler* nsh =
496 NetworkHandler::Get()->network_state_handler();
497 // TODO: Figure out why the path has an extra '/' in the front. (e.g. It is
498 // '//service/5' instead of '/service/5'.
499 const NetworkState* network = nsh->GetNetworkState(path.substr(1));
500 if (!network) {
501 web_ui()->GetWebContents()->Close();
502 return;
505 // If this is the initial call, update the network status and start observing
506 // network changes, but only for LTE networks. The other networks should
507 // ignore network status.
508 if (type_ == TYPE_UNDETERMINED) {
509 if (network->network_technology() == shill::kNetworkTechnologyLte ||
510 network->network_technology() == shill::kNetworkTechnologyLteAdvanced) {
511 type_ = TYPE_PORTAL_LTE;
512 nsh->AddObserver(this, FROM_HERE);
513 // Update the network status and notify the webui. This is the initial
514 // network state so the webui should be notified no matter what.
515 UpdatePortalReachability(network,
516 true /* force notification */);
517 } else {
518 type_ = TYPE_PORTAL;
519 // For non-LTE networks network state is ignored, so report the portal is
520 // reachable, so it gets shown.
521 web_ui()->CallJavascriptFunction(kJsConnectivityChangedCallback,
522 base::FundamentalValue(true));
526 NetworkHandler::Get()->network_configuration_handler()->GetShillProperties(
527 network->path(),
528 base::Bind(&MobileSetupHandler::GetPropertiesAndCallGetDeviceInfo,
529 weak_ptr_factory_.GetWeakPtr()),
530 base::Bind(&MobileSetupHandler::GetPropertiesFailure,
531 weak_ptr_factory_.GetWeakPtr(), network->path(),
532 kJsGetDeviceInfoCallback));
535 void MobileSetupHandler::GetPropertiesAndCallGetDeviceInfo(
536 const std::string& service_path,
537 const base::DictionaryValue& properties) {
538 base::DictionaryValue device_info;
539 GetDeviceInfo(properties, &device_info);
540 web_ui()->CallJavascriptFunction(kJsGetDeviceInfoCallback, device_info);
543 void MobileSetupHandler::GetPropertiesFailure(
544 const std::string& service_path,
545 const std::string& callback_name,
546 const std::string& error_name,
547 scoped_ptr<base::DictionaryValue> error_data) {
548 NET_LOG_ERROR("MobileActivator GetProperties Failed: " + error_name,
549 service_path);
550 // Invoke |callback_name| with an empty dictionary.
551 base::DictionaryValue device_dict;
552 web_ui()->CallJavascriptFunction(callback_name, device_dict);
555 void MobileSetupHandler::DefaultNetworkChanged(
556 const NetworkState* default_network) {
557 if (!web_ui())
558 return;
560 std::string path = web_ui()->GetWebContents()->GetURL().path().substr(1);
561 if (path.empty())
562 return;
564 const NetworkState* network =
565 NetworkHandler::Get()->network_state_handler()->GetNetworkState(path);
566 if (!network) {
567 LOG(ERROR) << "Service path lost";
568 web_ui()->GetWebContents()->Close();
569 return;
572 UpdatePortalReachability(network, false /* do not force notification */);
575 void MobileSetupHandler::NetworkConnectionStateChanged(
576 const NetworkState* network) {
577 if (!web_ui())
578 return;
580 std::string path = web_ui()->GetWebContents()->GetURL().path().substr(1);
581 if (path.empty() || path != network->path())
582 return;
584 UpdatePortalReachability(network, false /* do not force notification */);
587 void MobileSetupHandler::UpdatePortalReachability(
588 const NetworkState* network,
589 bool force_notification) {
590 DCHECK(web_ui());
592 DCHECK_EQ(type_, TYPE_PORTAL_LTE);
594 chromeos::NetworkStateHandler* nsh =
595 NetworkHandler::Get()->network_state_handler();
596 bool portal_reachable =
597 (network->IsConnectedState() ||
598 (nsh->DefaultNetwork() &&
599 nsh->DefaultNetwork()->connection_state() == shill::kStateOnline));
601 if (force_notification || portal_reachable != lte_portal_reachable_) {
602 web_ui()->CallJavascriptFunction(kJsConnectivityChangedCallback,
603 base::FundamentalValue(portal_reachable));
606 lte_portal_reachable_ = portal_reachable;
609 ////////////////////////////////////////////////////////////////////////////////
611 // MobileSetupUI
613 ////////////////////////////////////////////////////////////////////////////////
615 MobileSetupUI::MobileSetupUI(content::WebUI* web_ui)
616 : WebUIController(web_ui) {
617 web_ui->AddMessageHandler(new MobileSetupHandler());
618 MobileSetupUIHTMLSource* html_source = new MobileSetupUIHTMLSource();
620 // Set up the chrome://mobilesetup/ source.
621 Profile* profile = Profile::FromWebUI(web_ui);
622 content::URLDataSource::Add(profile, html_source);
624 content::WebContentsObserver::Observe(web_ui->GetWebContents());
627 void MobileSetupUI::DidCommitProvisionalLoadForFrame(
628 content::RenderFrameHost* render_frame_host,
629 const GURL& url,
630 ui::PageTransition transition_type) {
631 if (render_frame_host->GetFrameName() != "paymentForm")
632 return;
634 web_ui()->CallJavascriptFunction(
635 kJsPortalFrameLoadCompletedCallback);
638 void MobileSetupUI::DidFailProvisionalLoad(
639 content::RenderFrameHost* render_frame_host,
640 const GURL& validated_url,
641 int error_code,
642 const base::string16& error_description,
643 bool was_ignored_by_handler) {
644 if (render_frame_host->GetFrameName() != "paymentForm")
645 return;
647 base::FundamentalValue result_value(-error_code);
648 web_ui()->CallJavascriptFunction(kJsPortalFrameLoadFailedCallback,
649 result_value);