ProfilePolicyConnectorFactory: Refactoring from Profile to BrowserContext.
[chromium-blink-merge.git] / chrome / browser / ui / webui / chromeos / mobile_setup_ui.cc
blobdffbc158879ef9f36f3d9505f95b6956a6176ff8
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()->GetProperties(
272 path,
273 base::Bind(&MobileSetupUIHTMLSource::GetPropertiesAndStartDataRequest,
274 weak_ptr_factory_.GetWeakPtr(),
275 callback),
276 base::Bind(&MobileSetupUIHTMLSource::GetPropertiesFailure,
277 weak_ptr_factory_.GetWeakPtr(),
278 callback, path));
281 void MobileSetupUIHTMLSource::GetPropertiesAndStartDataRequest(
282 const content::URLDataSource::GotDataCallback& callback,
283 const std::string& service_path,
284 const base::DictionaryValue& properties) {
285 const base::DictionaryValue* payment_dict;
286 std::string name, usage_url, activation_state, payment_url;
287 if (!properties.GetStringWithoutPathExpansion(
288 shill::kNameProperty, &name) ||
289 !properties.GetStringWithoutPathExpansion(
290 shill::kUsageURLProperty, &usage_url) ||
291 !properties.GetStringWithoutPathExpansion(
292 shill::kActivationStateProperty, &activation_state) ||
293 !properties.GetDictionaryWithoutPathExpansion(
294 shill::kPaymentPortalProperty, &payment_dict) ||
295 !payment_dict->GetStringWithoutPathExpansion(
296 shill::kPaymentPortalURL, &payment_url)) {
297 DataRequestFailed(service_path, callback);
298 return;
301 if (payment_url.empty() && usage_url.empty() &&
302 activation_state != shill::kActivationStateActivated) {
303 DataRequestFailed(service_path, callback);
304 return;
307 NET_LOG_EVENT("Starting mobile setup", service_path);
308 base::DictionaryValue strings;
310 strings.SetString("connecting_header",
311 l10n_util::GetStringFUTF16(IDS_MOBILE_CONNECTING_HEADER,
312 base::UTF8ToUTF16(name)));
313 strings.SetString("error_header",
314 l10n_util::GetStringUTF16(IDS_MOBILE_ERROR_HEADER));
315 strings.SetString("activating_header",
316 l10n_util::GetStringUTF16(IDS_MOBILE_ACTIVATING_HEADER));
317 strings.SetString("completed_header",
318 l10n_util::GetStringUTF16(IDS_MOBILE_COMPLETED_HEADER));
319 strings.SetString("please_wait",
320 l10n_util::GetStringUTF16(IDS_MOBILE_PLEASE_WAIT));
321 strings.SetString("completed_text",
322 l10n_util::GetStringUTF16(IDS_MOBILE_COMPLETED_TEXT));
323 strings.SetString("portal_unreachable_header",
324 l10n_util::GetStringUTF16(IDS_MOBILE_NO_CONNECTION_HEADER));
325 strings.SetString("invalid_device_info_header",
326 l10n_util::GetStringUTF16(IDS_MOBILE_INVALID_DEVICE_INFO_HEADER));
327 strings.SetString("title", l10n_util::GetStringUTF16(IDS_MOBILE_SETUP_TITLE));
328 strings.SetString("close_button",
329 l10n_util::GetStringUTF16(IDS_CLOSE));
330 strings.SetString("cancel_button",
331 l10n_util::GetStringUTF16(IDS_CANCEL));
332 strings.SetString("ok_button",
333 l10n_util::GetStringUTF16(IDS_OK));
335 const std::string& app_locale = g_browser_process->GetApplicationLocale();
336 webui::SetLoadTimeDataDefaults(app_locale, &strings);
338 // The webui differs based on whether the network is activated or not. If the
339 // network is activated, the webui goes straight to portal. Otherwise the
340 // webui is used for activation flow.
341 std::string full_html;
342 if (activation_state == shill::kActivationStateActivated) {
343 static const base::StringPiece html_for_activated(
344 ResourceBundle::GetSharedInstance().GetRawDataResource(
345 IDR_MOBILE_SETUP_PORTAL_PAGE_HTML));
346 full_html = webui::GetI18nTemplateHtml(html_for_activated, &strings);
347 } else {
348 static const base::StringPiece html_for_non_activated(
349 ResourceBundle::GetSharedInstance().GetRawDataResource(
350 IDR_MOBILE_SETUP_PAGE_HTML));
351 full_html = webui::GetI18nTemplateHtml(html_for_non_activated, &strings);
354 callback.Run(base::RefCountedString::TakeString(&full_html));
357 void MobileSetupUIHTMLSource::GetPropertiesFailure(
358 const content::URLDataSource::GotDataCallback& callback,
359 const std::string& service_path,
360 const std::string& error_name,
361 scoped_ptr<base::DictionaryValue> error_data) {
362 DataRequestFailed(service_path, callback);
365 ////////////////////////////////////////////////////////////////////////////////
367 // MobileSetupHandler
369 ////////////////////////////////////////////////////////////////////////////////
370 MobileSetupHandler::MobileSetupHandler()
371 : type_(TYPE_UNDETERMINED),
372 lte_portal_reachable_(true),
373 weak_ptr_factory_(this) {
376 MobileSetupHandler::~MobileSetupHandler() {
377 if (type_ == TYPE_ACTIVATION) {
378 MobileActivator::GetInstance()->RemoveObserver(this);
379 MobileActivator::GetInstance()->TerminateActivation();
380 } else if (type_ == TYPE_PORTAL_LTE) {
381 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this,
382 FROM_HERE);
386 void MobileSetupHandler::OnActivationStateChanged(
387 const NetworkState* network,
388 MobileActivator::PlanActivationState state,
389 const std::string& error_description) {
390 DCHECK_EQ(TYPE_ACTIVATION, type_);
391 if (!web_ui())
392 return;
394 if (!network) {
395 base::DictionaryValue device_dict;
396 SetActivationStateAndError(state, error_description, &device_dict);
397 web_ui()->CallJavascriptFunction(kJsDeviceStatusChangedCallback,
398 device_dict);
399 return;
402 NetworkHandler::Get()->network_configuration_handler()->GetProperties(
403 network->path(),
404 base::Bind(&MobileSetupHandler::GetPropertiesAndCallStatusChanged,
405 weak_ptr_factory_.GetWeakPtr(),
406 state,
407 error_description),
408 base::Bind(&MobileSetupHandler::GetPropertiesFailure,
409 weak_ptr_factory_.GetWeakPtr(),
410 network->path(),
411 kJsDeviceStatusChangedCallback));
414 void MobileSetupHandler::GetPropertiesAndCallStatusChanged(
415 MobileActivator::PlanActivationState state,
416 const std::string& error_description,
417 const std::string& service_path,
418 const base::DictionaryValue& properties) {
419 base::DictionaryValue device_dict;
420 GetDeviceInfo(properties, &device_dict);
421 SetActivationStateAndError(state, error_description, &device_dict);
422 web_ui()->CallJavascriptFunction(kJsDeviceStatusChangedCallback, device_dict);
425 void MobileSetupHandler::RegisterMessages() {
426 web_ui()->RegisterMessageCallback(kJsApiStartActivation,
427 base::Bind(&MobileSetupHandler::HandleStartActivation,
428 base::Unretained(this)));
429 web_ui()->RegisterMessageCallback(kJsApiSetTransactionStatus,
430 base::Bind(&MobileSetupHandler::HandleSetTransactionStatus,
431 base::Unretained(this)));
432 web_ui()->RegisterMessageCallback(kJsApiPaymentPortalLoad,
433 base::Bind(&MobileSetupHandler::HandlePaymentPortalLoad,
434 base::Unretained(this)));
435 web_ui()->RegisterMessageCallback(kJsGetDeviceInfo,
436 base::Bind(&MobileSetupHandler::HandleGetDeviceInfo,
437 base::Unretained(this)));
440 void MobileSetupHandler::HandleStartActivation(const base::ListValue* args) {
441 DCHECK_EQ(TYPE_UNDETERMINED, type_);
443 if (!web_ui())
444 return;
446 std::string path = web_ui()->GetWebContents()->GetURL().path();
447 if (!path.size())
448 return;
450 LOG(WARNING) << "Starting activation for service " << path;
452 type_ = TYPE_ACTIVATION;
453 MobileActivator::GetInstance()->AddObserver(this);
454 MobileActivator::GetInstance()->InitiateActivation(path.substr(1));
457 void MobileSetupHandler::HandleSetTransactionStatus(
458 const base::ListValue* args) {
459 DCHECK_EQ(TYPE_ACTIVATION, type_);
460 if (!web_ui())
461 return;
463 const size_t kSetTransactionStatusParamCount = 1;
464 if (args->GetSize() != kSetTransactionStatusParamCount)
465 return;
466 // Get change callback function name.
467 std::string status;
468 if (!args->GetString(0, &status))
469 return;
471 MobileActivator::GetInstance()->OnSetTransactionStatus(
472 LowerCaseEqualsASCII(status, kJsApiResultOK));
475 void MobileSetupHandler::HandlePaymentPortalLoad(const base::ListValue* args) {
476 // Only activation flow webui is interested in these events.
477 if (type_ != TYPE_ACTIVATION || !web_ui())
478 return;
480 const size_t kPaymentPortalLoadParamCount = 1;
481 if (args->GetSize() != kPaymentPortalLoadParamCount)
482 return;
483 // Get change callback function name.
484 std::string result;
485 if (!args->GetString(0, &result))
486 return;
488 MobileActivator::GetInstance()->OnPortalLoaded(
489 LowerCaseEqualsASCII(result, kJsApiResultOK));
492 void MobileSetupHandler::HandleGetDeviceInfo(const base::ListValue* args) {
493 DCHECK_NE(TYPE_ACTIVATION, type_);
494 if (!web_ui())
495 return;
497 std::string path = web_ui()->GetWebContents()->GetURL().path();
498 if (path.empty())
499 return;
501 chromeos::NetworkStateHandler* nsh =
502 NetworkHandler::Get()->network_state_handler();
503 // TODO: Figure out why the path has an extra '/' in the front. (e.g. It is
504 // '//service/5' instead of '/service/5'.
505 const NetworkState* network = nsh->GetNetworkState(path.substr(1));
506 if (!network) {
507 web_ui()->GetWebContents()->Close();
508 return;
511 // If this is the initial call, update the network status and start observing
512 // network changes, but only for LTE networks. The other networks should
513 // ignore network status.
514 if (type_ == TYPE_UNDETERMINED) {
515 if (network->network_technology() == shill::kNetworkTechnologyLte ||
516 network->network_technology() == shill::kNetworkTechnologyLteAdvanced) {
517 type_ = TYPE_PORTAL_LTE;
518 nsh->AddObserver(this, FROM_HERE);
519 // Update the network status and notify the webui. This is the initial
520 // network state so the webui should be notified no matter what.
521 UpdatePortalReachability(network,
522 true /* force notification */);
523 } else {
524 type_ = TYPE_PORTAL;
525 // For non-LTE networks network state is ignored, so report the portal is
526 // reachable, so it gets shown.
527 web_ui()->CallJavascriptFunction(kJsConnectivityChangedCallback,
528 base::FundamentalValue(true));
532 NetworkHandler::Get()->network_configuration_handler()->GetProperties(
533 network->path(),
534 base::Bind(&MobileSetupHandler::GetPropertiesAndCallGetDeviceInfo,
535 weak_ptr_factory_.GetWeakPtr()),
536 base::Bind(&MobileSetupHandler::GetPropertiesFailure,
537 weak_ptr_factory_.GetWeakPtr(),
538 network->path(),
539 kJsGetDeviceInfoCallback));
542 void MobileSetupHandler::GetPropertiesAndCallGetDeviceInfo(
543 const std::string& service_path,
544 const base::DictionaryValue& properties) {
545 base::DictionaryValue device_info;
546 GetDeviceInfo(properties, &device_info);
547 web_ui()->CallJavascriptFunction(kJsGetDeviceInfoCallback, device_info);
550 void MobileSetupHandler::GetPropertiesFailure(
551 const std::string& service_path,
552 const std::string& callback_name,
553 const std::string& error_name,
554 scoped_ptr<base::DictionaryValue> error_data) {
555 NET_LOG_ERROR("MobileActivator GetProperties Failed: " + error_name,
556 service_path);
557 // Invoke |callback_name| with an empty dictionary.
558 base::DictionaryValue device_dict;
559 web_ui()->CallJavascriptFunction(callback_name, device_dict);
562 void MobileSetupHandler::DefaultNetworkChanged(
563 const NetworkState* default_network) {
564 if (!web_ui())
565 return;
567 std::string path = web_ui()->GetWebContents()->GetURL().path().substr(1);
568 if (path.empty())
569 return;
571 const NetworkState* network =
572 NetworkHandler::Get()->network_state_handler()->GetNetworkState(path);
573 if (!network) {
574 LOG(ERROR) << "Service path lost";
575 web_ui()->GetWebContents()->Close();
576 return;
579 UpdatePortalReachability(network, false /* do not force notification */);
582 void MobileSetupHandler::NetworkConnectionStateChanged(
583 const NetworkState* network) {
584 if (!web_ui())
585 return;
587 std::string path = web_ui()->GetWebContents()->GetURL().path().substr(1);
588 if (path.empty() || path != network->path())
589 return;
591 UpdatePortalReachability(network, false /* do not force notification */);
594 void MobileSetupHandler::UpdatePortalReachability(
595 const NetworkState* network,
596 bool force_notification) {
597 DCHECK(web_ui());
599 DCHECK_EQ(type_, TYPE_PORTAL_LTE);
601 chromeos::NetworkStateHandler* nsh =
602 NetworkHandler::Get()->network_state_handler();
603 bool portal_reachable =
604 (network->IsConnectedState() ||
605 (nsh->DefaultNetwork() &&
606 nsh->DefaultNetwork()->connection_state() == shill::kStateOnline));
608 if (force_notification || portal_reachable != lte_portal_reachable_) {
609 web_ui()->CallJavascriptFunction(kJsConnectivityChangedCallback,
610 base::FundamentalValue(portal_reachable));
613 lte_portal_reachable_ = portal_reachable;
616 ////////////////////////////////////////////////////////////////////////////////
618 // MobileSetupUI
620 ////////////////////////////////////////////////////////////////////////////////
622 MobileSetupUI::MobileSetupUI(content::WebUI* web_ui)
623 : WebUIController(web_ui) {
624 web_ui->AddMessageHandler(new MobileSetupHandler());
625 MobileSetupUIHTMLSource* html_source = new MobileSetupUIHTMLSource();
627 // Set up the chrome://mobilesetup/ source.
628 Profile* profile = Profile::FromWebUI(web_ui);
629 content::URLDataSource::Add(profile, html_source);
631 content::WebContentsObserver::Observe(web_ui->GetWebContents());
634 void MobileSetupUI::DidCommitProvisionalLoadForFrame(
635 content::RenderFrameHost* render_frame_host,
636 const GURL& url,
637 ui::PageTransition transition_type) {
638 if (render_frame_host->GetFrameName() != "paymentForm")
639 return;
641 web_ui()->CallJavascriptFunction(
642 kJsPortalFrameLoadCompletedCallback);
645 void MobileSetupUI::DidFailProvisionalLoad(
646 content::RenderFrameHost* render_frame_host,
647 const GURL& validated_url,
648 int error_code,
649 const base::string16& error_description) {
650 if (render_frame_host->GetFrameName() != "paymentForm")
651 return;
653 base::FundamentalValue result_value(-error_code);
654 web_ui()->CallJavascriptFunction(kJsPortalFrameLoadFailedCallback,
655 result_value);