Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / chrome / browser / ui / webui / chromeos / mobile_setup_ui.cc
blobcf35c04b229708ddff6cac30de572ccf801ebb2b
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/render_messages.h"
28 #include "chrome/common/url_constants.h"
29 #include "chrome/grit/generated_resources.h"
30 #include "chrome/grit/locale_settings.h"
31 #include "chromeos/network/device_state.h"
32 #include "chromeos/network/network_configuration_handler.h"
33 #include "chromeos/network/network_event_log.h"
34 #include "chromeos/network/network_state.h"
35 #include "chromeos/network/network_state_handler.h"
36 #include "chromeos/network/network_state_handler_observer.h"
37 #include "content/public/browser/browser_thread.h"
38 #include "content/public/browser/render_frame_host.h"
39 #include "content/public/browser/url_data_source.h"
40 #include "content/public/browser/web_contents.h"
41 #include "content/public/browser/web_ui.h"
42 #include "content/public/browser/web_ui_message_handler.h"
43 #include "grit/browser_resources.h"
44 #include "third_party/cros_system_api/dbus/service_constants.h"
45 #include "ui/base/l10n/l10n_util.h"
46 #include "ui/base/resource/resource_bundle.h"
47 #include "ui/base/webui/jstemplate_builder.h"
48 #include "ui/base/webui/web_ui_util.h"
49 #include "url/gurl.h"
51 using chromeos::MobileActivator;
52 using chromeos::NetworkHandler;
53 using chromeos::NetworkState;
54 using content::BrowserThread;
55 using content::RenderViewHost;
56 using content::WebContents;
57 using content::WebUIMessageHandler;
59 namespace {
61 // Host page JS API function names.
62 const char kJsApiStartActivation[] = "startActivation";
63 const char kJsApiSetTransactionStatus[] = "setTransactionStatus";
64 const char kJsApiPaymentPortalLoad[] = "paymentPortalLoad";
65 const char kJsGetDeviceInfo[] = "getDeviceInfo";
66 const char kJsApiResultOK[] = "ok";
68 const char kJsDeviceStatusChangedCallback[] =
69 "mobile.MobileSetup.deviceStateChanged";
70 const char kJsPortalFrameLoadFailedCallback[] =
71 "mobile.MobileSetup.portalFrameLoadError";
72 const char kJsPortalFrameLoadCompletedCallback[] =
73 "mobile.MobileSetup.portalFrameLoadCompleted";
74 const char kJsGetDeviceInfoCallback[] =
75 "mobile.MobileSetupPortal.onGotDeviceInfo";
76 const char kJsConnectivityChangedCallback[] =
77 "mobile.MobileSetupPortal.onConnectivityChanged";
79 void DataRequestFailed(
80 const std::string& service_path,
81 const content::URLDataSource::GotDataCallback& callback) {
82 NET_LOG_ERROR("Data Request Failed for Mobile Setup", service_path);
83 scoped_refptr<base::RefCountedBytes> html_bytes(new base::RefCountedBytes);
84 callback.Run(html_bytes.get());
87 // Converts the network properties into a JS object.
88 void GetDeviceInfo(const base::DictionaryValue& properties,
89 base::DictionaryValue* value) {
90 std::string name;
91 properties.GetStringWithoutPathExpansion(shill::kNameProperty, &name);
92 std::string activation_type;
93 properties.GetStringWithoutPathExpansion(
94 shill::kActivationTypeProperty,
95 &activation_type);
96 const base::DictionaryValue* payment_dict;
97 std::string payment_url, post_method, post_data;
98 if (properties.GetDictionaryWithoutPathExpansion(
99 shill::kPaymentPortalProperty, &payment_dict)) {
100 payment_dict->GetStringWithoutPathExpansion(
101 shill::kPaymentPortalURL, &payment_url);
102 payment_dict->GetStringWithoutPathExpansion(
103 shill::kPaymentPortalMethod, &post_method);
104 payment_dict->GetStringWithoutPathExpansion(
105 shill::kPaymentPortalPostData, &post_data);
108 value->SetString("activation_type", activation_type);
109 value->SetString("carrier", name);
110 value->SetString("payment_url", payment_url);
111 if (LowerCaseEqualsASCII(post_method, "post") && !post_data.empty())
112 value->SetString("post_data", post_data);
114 // Use the cached DeviceState properties.
115 std::string device_path;
116 if (!properties.GetStringWithoutPathExpansion(
117 shill::kDeviceProperty, &device_path) ||
118 device_path.empty()) {
119 return;
121 const chromeos::DeviceState* device =
122 NetworkHandler::Get()->network_state_handler()->GetDeviceState(
123 device_path);
124 if (!device)
125 return;
127 value->SetString("MEID", device->meid());
128 value->SetString("IMEI", device->imei());
129 value->SetString("MDN", device->mdn());
132 void SetActivationStateAndError(MobileActivator::PlanActivationState state,
133 const std::string& error_description,
134 base::DictionaryValue* value) {
135 value->SetInteger("state", state);
136 if (!error_description.empty())
137 value->SetString("error", error_description);
140 } // namespace
142 class MobileSetupUIHTMLSource : public content::URLDataSource {
143 public:
144 MobileSetupUIHTMLSource();
146 // content::URLDataSource implementation.
147 std::string GetSource() const override;
148 void StartDataRequest(
149 const std::string& path,
150 int render_process_id,
151 int render_frame_id,
152 const content::URLDataSource::GotDataCallback& callback) override;
153 std::string GetMimeType(const std::string&) const override {
154 return "text/html";
156 bool ShouldAddContentSecurityPolicy() const override { return false; }
158 private:
159 ~MobileSetupUIHTMLSource() override {}
161 void GetPropertiesAndStartDataRequest(
162 const content::URLDataSource::GotDataCallback& callback,
163 const std::string& service_path,
164 const base::DictionaryValue& properties);
165 void GetPropertiesFailure(
166 const content::URLDataSource::GotDataCallback& callback,
167 const std::string& service_path,
168 const std::string& error_name,
169 scoped_ptr<base::DictionaryValue> error_data);
171 base::WeakPtrFactory<MobileSetupUIHTMLSource> weak_ptr_factory_;
173 DISALLOW_COPY_AND_ASSIGN(MobileSetupUIHTMLSource);
176 // The handler for Javascript messages related to the "register" view.
177 class MobileSetupHandler
178 : public WebUIMessageHandler,
179 public MobileActivator::Observer,
180 public chromeos::NetworkStateHandlerObserver,
181 public base::SupportsWeakPtr<MobileSetupHandler> {
182 public:
183 MobileSetupHandler();
184 ~MobileSetupHandler() override;
186 // WebUIMessageHandler implementation.
187 void RegisterMessages() override;
189 private:
190 enum Type {
191 TYPE_UNDETERMINED,
192 // The network is not yet activated, and the webui is in activation flow.
193 TYPE_ACTIVATION,
194 // The network is activated, the webui displays network portal.
195 TYPE_PORTAL,
196 // Same as TYPE_PORTAL, but the network technology is LTE. The webui is
197 // additionally aware of network manager state and whether the portal can be
198 // reached.
199 TYPE_PORTAL_LTE
202 // MobileActivator::Observer.
203 void OnActivationStateChanged(const NetworkState* network,
204 MobileActivator::PlanActivationState new_state,
205 const std::string& error_description) override;
207 // Callbacks for NetworkConfigurationHandler::GetProperties.
208 void GetPropertiesAndCallStatusChanged(
209 MobileActivator::PlanActivationState state,
210 const std::string& error_description,
211 const std::string& service_path,
212 const base::DictionaryValue& properties);
213 void GetPropertiesAndCallGetDeviceInfo(
214 const std::string& service_path,
215 const base::DictionaryValue& properties);
216 void GetPropertiesFailure(
217 const std::string& service_path,
218 const std::string& callback_name,
219 const std::string& error_name,
220 scoped_ptr<base::DictionaryValue> error_data);
222 // Handlers for JS WebUI messages.
223 void HandleSetTransactionStatus(const base::ListValue* args);
224 void HandleStartActivation(const base::ListValue* args);
225 void HandlePaymentPortalLoad(const base::ListValue* args);
226 void HandleGetDeviceInfo(const base::ListValue* args);
228 // NetworkStateHandlerObserver implementation.
229 void NetworkConnectionStateChanged(const NetworkState* network) override;
230 void DefaultNetworkChanged(const NetworkState* default_network) override;
232 // Updates |lte_portal_reachable_| for lte network |network| and notifies
233 // webui of the new state if the reachability changed or |force_notification|
234 // is set.
235 void UpdatePortalReachability(const NetworkState* network,
236 bool force_notification);
238 // Sends message to host registration page with system/user info data.
239 void SendDeviceInfo();
241 // Type of the mobilesetup webui deduced from received messages.
242 Type type_;
243 // Whether portal page for lte networks can be reached in current network
244 // connection state. This value is reflected in portal webui for lte networks.
245 // Initial value is true.
246 bool lte_portal_reachable_;
247 base::WeakPtrFactory<MobileSetupHandler> weak_ptr_factory_;
249 DISALLOW_COPY_AND_ASSIGN(MobileSetupHandler);
252 ////////////////////////////////////////////////////////////////////////////////
254 // MobileSetupUIHTMLSource
256 ////////////////////////////////////////////////////////////////////////////////
258 MobileSetupUIHTMLSource::MobileSetupUIHTMLSource()
259 : weak_ptr_factory_(this) {
262 std::string MobileSetupUIHTMLSource::GetSource() const {
263 return chrome::kChromeUIMobileSetupHost;
266 void MobileSetupUIHTMLSource::StartDataRequest(
267 const std::string& path,
268 int render_process_id,
269 int render_frame_id,
270 const content::URLDataSource::GotDataCallback& callback) {
271 NetworkHandler::Get()->network_configuration_handler()->GetShillProperties(
272 path,
273 base::Bind(&MobileSetupUIHTMLSource::GetPropertiesAndStartDataRequest,
274 weak_ptr_factory_.GetWeakPtr(), callback),
275 base::Bind(&MobileSetupUIHTMLSource::GetPropertiesFailure,
276 weak_ptr_factory_.GetWeakPtr(), callback, path));
279 void MobileSetupUIHTMLSource::GetPropertiesAndStartDataRequest(
280 const content::URLDataSource::GotDataCallback& callback,
281 const std::string& service_path,
282 const base::DictionaryValue& properties) {
283 const base::DictionaryValue* payment_dict;
284 std::string name, usage_url, activation_state, payment_url;
285 if (!properties.GetStringWithoutPathExpansion(
286 shill::kNameProperty, &name) ||
287 !properties.GetStringWithoutPathExpansion(
288 shill::kUsageURLProperty, &usage_url) ||
289 !properties.GetStringWithoutPathExpansion(
290 shill::kActivationStateProperty, &activation_state) ||
291 !properties.GetDictionaryWithoutPathExpansion(
292 shill::kPaymentPortalProperty, &payment_dict) ||
293 !payment_dict->GetStringWithoutPathExpansion(
294 shill::kPaymentPortalURL, &payment_url)) {
295 DataRequestFailed(service_path, callback);
296 return;
299 if (payment_url.empty() && usage_url.empty() &&
300 activation_state != shill::kActivationStateActivated) {
301 DataRequestFailed(service_path, callback);
302 return;
305 NET_LOG_EVENT("Starting mobile setup", service_path);
306 base::DictionaryValue strings;
308 strings.SetString("connecting_header",
309 l10n_util::GetStringFUTF16(IDS_MOBILE_CONNECTING_HEADER,
310 base::UTF8ToUTF16(name)));
311 strings.SetString("error_header",
312 l10n_util::GetStringUTF16(IDS_MOBILE_ERROR_HEADER));
313 strings.SetString("activating_header",
314 l10n_util::GetStringUTF16(IDS_MOBILE_ACTIVATING_HEADER));
315 strings.SetString("completed_header",
316 l10n_util::GetStringUTF16(IDS_MOBILE_COMPLETED_HEADER));
317 strings.SetString("please_wait",
318 l10n_util::GetStringUTF16(IDS_MOBILE_PLEASE_WAIT));
319 strings.SetString("completed_text",
320 l10n_util::GetStringUTF16(IDS_MOBILE_COMPLETED_TEXT));
321 strings.SetString("portal_unreachable_header",
322 l10n_util::GetStringUTF16(IDS_MOBILE_NO_CONNECTION_HEADER));
323 strings.SetString("invalid_device_info_header",
324 l10n_util::GetStringUTF16(IDS_MOBILE_INVALID_DEVICE_INFO_HEADER));
325 strings.SetString("title", l10n_util::GetStringUTF16(IDS_MOBILE_SETUP_TITLE));
326 strings.SetString("close_button",
327 l10n_util::GetStringUTF16(IDS_CLOSE));
328 strings.SetString("cancel_button",
329 l10n_util::GetStringUTF16(IDS_CANCEL));
330 strings.SetString("ok_button",
331 l10n_util::GetStringUTF16(IDS_OK));
333 const std::string& app_locale = g_browser_process->GetApplicationLocale();
334 webui::SetLoadTimeDataDefaults(app_locale, &strings);
336 // The webui differs based on whether the network is activated or not. If the
337 // network is activated, the webui goes straight to portal. Otherwise the
338 // webui is used for activation flow.
339 std::string full_html;
340 if (activation_state == shill::kActivationStateActivated) {
341 static const base::StringPiece html_for_activated(
342 ResourceBundle::GetSharedInstance().GetRawDataResource(
343 IDR_MOBILE_SETUP_PORTAL_PAGE_HTML));
344 full_html = webui::GetI18nTemplateHtml(html_for_activated, &strings);
345 } else {
346 static const base::StringPiece html_for_non_activated(
347 ResourceBundle::GetSharedInstance().GetRawDataResource(
348 IDR_MOBILE_SETUP_PAGE_HTML));
349 full_html = webui::GetI18nTemplateHtml(html_for_non_activated, &strings);
352 callback.Run(base::RefCountedString::TakeString(&full_html));
355 void MobileSetupUIHTMLSource::GetPropertiesFailure(
356 const content::URLDataSource::GotDataCallback& callback,
357 const std::string& service_path,
358 const std::string& error_name,
359 scoped_ptr<base::DictionaryValue> error_data) {
360 DataRequestFailed(service_path, callback);
363 ////////////////////////////////////////////////////////////////////////////////
365 // MobileSetupHandler
367 ////////////////////////////////////////////////////////////////////////////////
368 MobileSetupHandler::MobileSetupHandler()
369 : type_(TYPE_UNDETERMINED),
370 lte_portal_reachable_(true),
371 weak_ptr_factory_(this) {
374 MobileSetupHandler::~MobileSetupHandler() {
375 if (type_ == TYPE_ACTIVATION) {
376 MobileActivator::GetInstance()->RemoveObserver(this);
377 MobileActivator::GetInstance()->TerminateActivation();
378 } else if (type_ == TYPE_PORTAL_LTE) {
379 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this,
380 FROM_HERE);
384 void MobileSetupHandler::OnActivationStateChanged(
385 const NetworkState* network,
386 MobileActivator::PlanActivationState state,
387 const std::string& error_description) {
388 DCHECK_EQ(TYPE_ACTIVATION, type_);
389 if (!web_ui())
390 return;
392 if (!network) {
393 base::DictionaryValue device_dict;
394 SetActivationStateAndError(state, error_description, &device_dict);
395 web_ui()->CallJavascriptFunction(kJsDeviceStatusChangedCallback,
396 device_dict);
397 return;
400 NetworkHandler::Get()->network_configuration_handler()->GetShillProperties(
401 network->path(),
402 base::Bind(&MobileSetupHandler::GetPropertiesAndCallStatusChanged,
403 weak_ptr_factory_.GetWeakPtr(), state, error_description),
404 base::Bind(&MobileSetupHandler::GetPropertiesFailure,
405 weak_ptr_factory_.GetWeakPtr(), network->path(),
406 kJsDeviceStatusChangedCallback));
409 void MobileSetupHandler::GetPropertiesAndCallStatusChanged(
410 MobileActivator::PlanActivationState state,
411 const std::string& error_description,
412 const std::string& service_path,
413 const base::DictionaryValue& properties) {
414 base::DictionaryValue device_dict;
415 GetDeviceInfo(properties, &device_dict);
416 SetActivationStateAndError(state, error_description, &device_dict);
417 web_ui()->CallJavascriptFunction(kJsDeviceStatusChangedCallback, device_dict);
420 void MobileSetupHandler::RegisterMessages() {
421 web_ui()->RegisterMessageCallback(kJsApiStartActivation,
422 base::Bind(&MobileSetupHandler::HandleStartActivation,
423 base::Unretained(this)));
424 web_ui()->RegisterMessageCallback(kJsApiSetTransactionStatus,
425 base::Bind(&MobileSetupHandler::HandleSetTransactionStatus,
426 base::Unretained(this)));
427 web_ui()->RegisterMessageCallback(kJsApiPaymentPortalLoad,
428 base::Bind(&MobileSetupHandler::HandlePaymentPortalLoad,
429 base::Unretained(this)));
430 web_ui()->RegisterMessageCallback(kJsGetDeviceInfo,
431 base::Bind(&MobileSetupHandler::HandleGetDeviceInfo,
432 base::Unretained(this)));
435 void MobileSetupHandler::HandleStartActivation(const base::ListValue* args) {
436 DCHECK_EQ(TYPE_UNDETERMINED, type_);
438 if (!web_ui())
439 return;
441 std::string path = web_ui()->GetWebContents()->GetURL().path();
442 if (!path.size())
443 return;
445 LOG(WARNING) << "Starting activation for service " << path;
447 type_ = TYPE_ACTIVATION;
448 MobileActivator::GetInstance()->AddObserver(this);
449 MobileActivator::GetInstance()->InitiateActivation(path.substr(1));
452 void MobileSetupHandler::HandleSetTransactionStatus(
453 const base::ListValue* args) {
454 DCHECK_EQ(TYPE_ACTIVATION, type_);
455 if (!web_ui())
456 return;
458 const size_t kSetTransactionStatusParamCount = 1;
459 if (args->GetSize() != kSetTransactionStatusParamCount)
460 return;
461 // Get change callback function name.
462 std::string status;
463 if (!args->GetString(0, &status))
464 return;
466 MobileActivator::GetInstance()->OnSetTransactionStatus(
467 LowerCaseEqualsASCII(status, kJsApiResultOK));
470 void MobileSetupHandler::HandlePaymentPortalLoad(const base::ListValue* args) {
471 // Only activation flow webui is interested in these events.
472 if (type_ != TYPE_ACTIVATION || !web_ui())
473 return;
475 const size_t kPaymentPortalLoadParamCount = 1;
476 if (args->GetSize() != kPaymentPortalLoadParamCount)
477 return;
478 // Get change callback function name.
479 std::string result;
480 if (!args->GetString(0, &result))
481 return;
483 MobileActivator::GetInstance()->OnPortalLoaded(
484 LowerCaseEqualsASCII(result, kJsApiResultOK));
487 void MobileSetupHandler::HandleGetDeviceInfo(const base::ListValue* args) {
488 DCHECK_NE(TYPE_ACTIVATION, type_);
489 if (!web_ui())
490 return;
492 std::string path = web_ui()->GetWebContents()->GetURL().path();
493 if (path.empty())
494 return;
496 chromeos::NetworkStateHandler* nsh =
497 NetworkHandler::Get()->network_state_handler();
498 // TODO: Figure out why the path has an extra '/' in the front. (e.g. It is
499 // '//service/5' instead of '/service/5'.
500 const NetworkState* network = nsh->GetNetworkState(path.substr(1));
501 if (!network) {
502 web_ui()->GetWebContents()->Close();
503 return;
506 // If this is the initial call, update the network status and start observing
507 // network changes, but only for LTE networks. The other networks should
508 // ignore network status.
509 if (type_ == TYPE_UNDETERMINED) {
510 if (network->network_technology() == shill::kNetworkTechnologyLte ||
511 network->network_technology() == shill::kNetworkTechnologyLteAdvanced) {
512 type_ = TYPE_PORTAL_LTE;
513 nsh->AddObserver(this, FROM_HERE);
514 // Update the network status and notify the webui. This is the initial
515 // network state so the webui should be notified no matter what.
516 UpdatePortalReachability(network,
517 true /* force notification */);
518 } else {
519 type_ = TYPE_PORTAL;
520 // For non-LTE networks network state is ignored, so report the portal is
521 // reachable, so it gets shown.
522 web_ui()->CallJavascriptFunction(kJsConnectivityChangedCallback,
523 base::FundamentalValue(true));
527 NetworkHandler::Get()->network_configuration_handler()->GetShillProperties(
528 network->path(),
529 base::Bind(&MobileSetupHandler::GetPropertiesAndCallGetDeviceInfo,
530 weak_ptr_factory_.GetWeakPtr()),
531 base::Bind(&MobileSetupHandler::GetPropertiesFailure,
532 weak_ptr_factory_.GetWeakPtr(), network->path(),
533 kJsGetDeviceInfoCallback));
536 void MobileSetupHandler::GetPropertiesAndCallGetDeviceInfo(
537 const std::string& service_path,
538 const base::DictionaryValue& properties) {
539 base::DictionaryValue device_info;
540 GetDeviceInfo(properties, &device_info);
541 web_ui()->CallJavascriptFunction(kJsGetDeviceInfoCallback, device_info);
544 void MobileSetupHandler::GetPropertiesFailure(
545 const std::string& service_path,
546 const std::string& callback_name,
547 const std::string& error_name,
548 scoped_ptr<base::DictionaryValue> error_data) {
549 NET_LOG_ERROR("MobileActivator GetProperties Failed: " + error_name,
550 service_path);
551 // Invoke |callback_name| with an empty dictionary.
552 base::DictionaryValue device_dict;
553 web_ui()->CallJavascriptFunction(callback_name, device_dict);
556 void MobileSetupHandler::DefaultNetworkChanged(
557 const NetworkState* default_network) {
558 if (!web_ui())
559 return;
561 std::string path = web_ui()->GetWebContents()->GetURL().path().substr(1);
562 if (path.empty())
563 return;
565 const NetworkState* network =
566 NetworkHandler::Get()->network_state_handler()->GetNetworkState(path);
567 if (!network) {
568 LOG(ERROR) << "Service path lost";
569 web_ui()->GetWebContents()->Close();
570 return;
573 UpdatePortalReachability(network, false /* do not force notification */);
576 void MobileSetupHandler::NetworkConnectionStateChanged(
577 const NetworkState* network) {
578 if (!web_ui())
579 return;
581 std::string path = web_ui()->GetWebContents()->GetURL().path().substr(1);
582 if (path.empty() || path != network->path())
583 return;
585 UpdatePortalReachability(network, false /* do not force notification */);
588 void MobileSetupHandler::UpdatePortalReachability(
589 const NetworkState* network,
590 bool force_notification) {
591 DCHECK(web_ui());
593 DCHECK_EQ(type_, TYPE_PORTAL_LTE);
595 chromeos::NetworkStateHandler* nsh =
596 NetworkHandler::Get()->network_state_handler();
597 bool portal_reachable =
598 (network->IsConnectedState() ||
599 (nsh->DefaultNetwork() &&
600 nsh->DefaultNetwork()->connection_state() == shill::kStateOnline));
602 if (force_notification || portal_reachable != lte_portal_reachable_) {
603 web_ui()->CallJavascriptFunction(kJsConnectivityChangedCallback,
604 base::FundamentalValue(portal_reachable));
607 lte_portal_reachable_ = portal_reachable;
610 ////////////////////////////////////////////////////////////////////////////////
612 // MobileSetupUI
614 ////////////////////////////////////////////////////////////////////////////////
616 MobileSetupUI::MobileSetupUI(content::WebUI* web_ui)
617 : WebUIController(web_ui) {
618 web_ui->AddMessageHandler(new MobileSetupHandler());
619 MobileSetupUIHTMLSource* html_source = new MobileSetupUIHTMLSource();
621 // Set up the chrome://mobilesetup/ source.
622 Profile* profile = Profile::FromWebUI(web_ui);
623 content::URLDataSource::Add(profile, html_source);
625 content::WebContentsObserver::Observe(web_ui->GetWebContents());
628 void MobileSetupUI::DidCommitProvisionalLoadForFrame(
629 content::RenderFrameHost* render_frame_host,
630 const GURL& url,
631 ui::PageTransition transition_type) {
632 if (render_frame_host->GetFrameName() != "paymentForm")
633 return;
635 web_ui()->CallJavascriptFunction(
636 kJsPortalFrameLoadCompletedCallback);
639 void MobileSetupUI::DidFailProvisionalLoad(
640 content::RenderFrameHost* render_frame_host,
641 const GURL& validated_url,
642 int error_code,
643 const base::string16& error_description) {
644 if (render_frame_host->GetFrameName() != "paymentForm")
645 return;
647 base::FundamentalValue result_value(-error_code);
648 web_ui()->CallJavascriptFunction(kJsPortalFrameLoadFailedCallback,
649 result_value);