| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/webui/chromeos/mobile_setup_ui.h" | 5 #include "chrome/browser/ui/webui/chromeos/mobile_setup_ui.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 const NetworkState* network, | 387 const NetworkState* network, |
| 388 MobileActivator::PlanActivationState state, | 388 MobileActivator::PlanActivationState state, |
| 389 const std::string& error_description) { | 389 const std::string& error_description) { |
| 390 DCHECK_EQ(TYPE_ACTIVATION, type_); | 390 DCHECK_EQ(TYPE_ACTIVATION, type_); |
| 391 if (!web_ui()) | 391 if (!web_ui()) |
| 392 return; | 392 return; |
| 393 | 393 |
| 394 if (!network) { | 394 if (!network) { |
| 395 base::DictionaryValue device_dict; | 395 base::DictionaryValue device_dict; |
| 396 SetActivationStateAndError(state, error_description, &device_dict); | 396 SetActivationStateAndError(state, error_description, &device_dict); |
| 397 web_ui()->CallJavascriptFunction(kJsDeviceStatusChangedCallback, | 397 web_ui()->CallJavascriptFunctionUnsafe(kJsDeviceStatusChangedCallback, |
| 398 device_dict); | 398 device_dict); |
| 399 return; | 399 return; |
| 400 } | 400 } |
| 401 | 401 |
| 402 NetworkHandler::Get()->network_configuration_handler()->GetShillProperties( | 402 NetworkHandler::Get()->network_configuration_handler()->GetShillProperties( |
| 403 network->path(), | 403 network->path(), |
| 404 base::Bind(&MobileSetupHandler::GetPropertiesAndCallStatusChanged, | 404 base::Bind(&MobileSetupHandler::GetPropertiesAndCallStatusChanged, |
| 405 weak_ptr_factory_.GetWeakPtr(), state, error_description), | 405 weak_ptr_factory_.GetWeakPtr(), state, error_description), |
| 406 base::Bind(&MobileSetupHandler::GetPropertiesFailure, | 406 base::Bind(&MobileSetupHandler::GetPropertiesFailure, |
| 407 weak_ptr_factory_.GetWeakPtr(), network->path(), | 407 weak_ptr_factory_.GetWeakPtr(), network->path(), |
| 408 kJsDeviceStatusChangedCallback)); | 408 kJsDeviceStatusChangedCallback)); |
| 409 } | 409 } |
| 410 | 410 |
| 411 void MobileSetupHandler::GetPropertiesAndCallStatusChanged( | 411 void MobileSetupHandler::GetPropertiesAndCallStatusChanged( |
| 412 MobileActivator::PlanActivationState state, | 412 MobileActivator::PlanActivationState state, |
| 413 const std::string& error_description, | 413 const std::string& error_description, |
| 414 const std::string& service_path, | 414 const std::string& service_path, |
| 415 const base::DictionaryValue& properties) { | 415 const base::DictionaryValue& properties) { |
| 416 base::DictionaryValue device_dict; | 416 base::DictionaryValue device_dict; |
| 417 GetDeviceInfo(properties, &device_dict); | 417 GetDeviceInfo(properties, &device_dict); |
| 418 SetActivationStateAndError(state, error_description, &device_dict); | 418 SetActivationStateAndError(state, error_description, &device_dict); |
| 419 web_ui()->CallJavascriptFunction(kJsDeviceStatusChangedCallback, device_dict); | 419 web_ui()->CallJavascriptFunctionUnsafe(kJsDeviceStatusChangedCallback, |
| 420 device_dict); |
| 420 } | 421 } |
| 421 | 422 |
| 422 void MobileSetupHandler::RegisterMessages() { | 423 void MobileSetupHandler::RegisterMessages() { |
| 423 web_ui()->RegisterMessageCallback(kJsApiStartActivation, | 424 web_ui()->RegisterMessageCallback(kJsApiStartActivation, |
| 424 base::Bind(&MobileSetupHandler::HandleStartActivation, | 425 base::Bind(&MobileSetupHandler::HandleStartActivation, |
| 425 base::Unretained(this))); | 426 base::Unretained(this))); |
| 426 web_ui()->RegisterMessageCallback(kJsApiSetTransactionStatus, | 427 web_ui()->RegisterMessageCallback(kJsApiSetTransactionStatus, |
| 427 base::Bind(&MobileSetupHandler::HandleSetTransactionStatus, | 428 base::Bind(&MobileSetupHandler::HandleSetTransactionStatus, |
| 428 base::Unretained(this))); | 429 base::Unretained(this))); |
| 429 web_ui()->RegisterMessageCallback(kJsApiPaymentPortalLoad, | 430 web_ui()->RegisterMessageCallback(kJsApiPaymentPortalLoad, |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 type_ = TYPE_PORTAL_LTE; | 515 type_ = TYPE_PORTAL_LTE; |
| 515 nsh->AddObserver(this, FROM_HERE); | 516 nsh->AddObserver(this, FROM_HERE); |
| 516 // Update the network status and notify the webui. This is the initial | 517 // 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 // network state so the webui should be notified no matter what. |
| 518 UpdatePortalReachability(network, | 519 UpdatePortalReachability(network, |
| 519 true /* force notification */); | 520 true /* force notification */); |
| 520 } else { | 521 } else { |
| 521 type_ = TYPE_PORTAL; | 522 type_ = TYPE_PORTAL; |
| 522 // For non-LTE networks network state is ignored, so report the portal is | 523 // For non-LTE networks network state is ignored, so report the portal is |
| 523 // reachable, so it gets shown. | 524 // reachable, so it gets shown. |
| 524 web_ui()->CallJavascriptFunction(kJsConnectivityChangedCallback, | 525 web_ui()->CallJavascriptFunctionUnsafe(kJsConnectivityChangedCallback, |
| 525 base::FundamentalValue(true)); | 526 base::FundamentalValue(true)); |
| 526 } | 527 } |
| 527 } | 528 } |
| 528 | 529 |
| 529 NetworkHandler::Get()->network_configuration_handler()->GetShillProperties( | 530 NetworkHandler::Get()->network_configuration_handler()->GetShillProperties( |
| 530 network->path(), | 531 network->path(), |
| 531 base::Bind(&MobileSetupHandler::GetPropertiesAndCallGetDeviceInfo, | 532 base::Bind(&MobileSetupHandler::GetPropertiesAndCallGetDeviceInfo, |
| 532 weak_ptr_factory_.GetWeakPtr()), | 533 weak_ptr_factory_.GetWeakPtr()), |
| 533 base::Bind(&MobileSetupHandler::GetPropertiesFailure, | 534 base::Bind(&MobileSetupHandler::GetPropertiesFailure, |
| 534 weak_ptr_factory_.GetWeakPtr(), network->path(), | 535 weak_ptr_factory_.GetWeakPtr(), network->path(), |
| 535 kJsGetDeviceInfoCallback)); | 536 kJsGetDeviceInfoCallback)); |
| 536 } | 537 } |
| 537 | 538 |
| 538 void MobileSetupHandler::GetPropertiesAndCallGetDeviceInfo( | 539 void MobileSetupHandler::GetPropertiesAndCallGetDeviceInfo( |
| 539 const std::string& service_path, | 540 const std::string& service_path, |
| 540 const base::DictionaryValue& properties) { | 541 const base::DictionaryValue& properties) { |
| 541 base::DictionaryValue device_info; | 542 base::DictionaryValue device_info; |
| 542 GetDeviceInfo(properties, &device_info); | 543 GetDeviceInfo(properties, &device_info); |
| 543 web_ui()->CallJavascriptFunction(kJsGetDeviceInfoCallback, device_info); | 544 web_ui()->CallJavascriptFunctionUnsafe(kJsGetDeviceInfoCallback, device_info); |
| 544 } | 545 } |
| 545 | 546 |
| 546 void MobileSetupHandler::GetPropertiesFailure( | 547 void MobileSetupHandler::GetPropertiesFailure( |
| 547 const std::string& service_path, | 548 const std::string& service_path, |
| 548 const std::string& callback_name, | 549 const std::string& callback_name, |
| 549 const std::string& error_name, | 550 const std::string& error_name, |
| 550 std::unique_ptr<base::DictionaryValue> error_data) { | 551 std::unique_ptr<base::DictionaryValue> error_data) { |
| 551 NET_LOG_ERROR("MobileActivator GetProperties Failed: " + error_name, | 552 NET_LOG_ERROR("MobileActivator GetProperties Failed: " + error_name, |
| 552 service_path); | 553 service_path); |
| 553 // Invoke |callback_name| with an empty dictionary. | 554 // Invoke |callback_name| with an empty dictionary. |
| 554 base::DictionaryValue device_dict; | 555 base::DictionaryValue device_dict; |
| 555 web_ui()->CallJavascriptFunction(callback_name, device_dict); | 556 web_ui()->CallJavascriptFunctionUnsafe(callback_name, device_dict); |
| 556 } | 557 } |
| 557 | 558 |
| 558 void MobileSetupHandler::DefaultNetworkChanged( | 559 void MobileSetupHandler::DefaultNetworkChanged( |
| 559 const NetworkState* default_network) { | 560 const NetworkState* default_network) { |
| 560 if (!web_ui()) | 561 if (!web_ui()) |
| 561 return; | 562 return; |
| 562 | 563 |
| 563 std::string path = web_ui()->GetWebContents()->GetURL().path().substr(1); | 564 std::string path = web_ui()->GetWebContents()->GetURL().path().substr(1); |
| 564 if (path.empty()) | 565 if (path.empty()) |
| 565 return; | 566 return; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 595 DCHECK_EQ(type_, TYPE_PORTAL_LTE); | 596 DCHECK_EQ(type_, TYPE_PORTAL_LTE); |
| 596 | 597 |
| 597 chromeos::NetworkStateHandler* nsh = | 598 chromeos::NetworkStateHandler* nsh = |
| 598 NetworkHandler::Get()->network_state_handler(); | 599 NetworkHandler::Get()->network_state_handler(); |
| 599 bool portal_reachable = | 600 bool portal_reachable = |
| 600 (network->IsConnectedState() || | 601 (network->IsConnectedState() || |
| 601 (nsh->DefaultNetwork() && | 602 (nsh->DefaultNetwork() && |
| 602 nsh->DefaultNetwork()->connection_state() == shill::kStateOnline)); | 603 nsh->DefaultNetwork()->connection_state() == shill::kStateOnline)); |
| 603 | 604 |
| 604 if (force_notification || portal_reachable != lte_portal_reachable_) { | 605 if (force_notification || portal_reachable != lte_portal_reachable_) { |
| 605 web_ui()->CallJavascriptFunction(kJsConnectivityChangedCallback, | 606 web_ui()->CallJavascriptFunctionUnsafe( |
| 606 base::FundamentalValue(portal_reachable)); | 607 kJsConnectivityChangedCallback, |
| 608 base::FundamentalValue(portal_reachable)); |
| 607 } | 609 } |
| 608 | 610 |
| 609 lte_portal_reachable_ = portal_reachable; | 611 lte_portal_reachable_ = portal_reachable; |
| 610 } | 612 } |
| 611 | 613 |
| 612 //////////////////////////////////////////////////////////////////////////////// | 614 //////////////////////////////////////////////////////////////////////////////// |
| 613 // | 615 // |
| 614 // MobileSetupUI | 616 // MobileSetupUI |
| 615 // | 617 // |
| 616 //////////////////////////////////////////////////////////////////////////////// | 618 //////////////////////////////////////////////////////////////////////////////// |
| (...skipping 10 matching lines...) Expand all Loading... |
| 627 content::WebContentsObserver::Observe(web_ui->GetWebContents()); | 629 content::WebContentsObserver::Observe(web_ui->GetWebContents()); |
| 628 } | 630 } |
| 629 | 631 |
| 630 void MobileSetupUI::DidCommitProvisionalLoadForFrame( | 632 void MobileSetupUI::DidCommitProvisionalLoadForFrame( |
| 631 content::RenderFrameHost* render_frame_host, | 633 content::RenderFrameHost* render_frame_host, |
| 632 const GURL& url, | 634 const GURL& url, |
| 633 ui::PageTransition transition_type) { | 635 ui::PageTransition transition_type) { |
| 634 if (render_frame_host->GetFrameName() != "paymentForm") | 636 if (render_frame_host->GetFrameName() != "paymentForm") |
| 635 return; | 637 return; |
| 636 | 638 |
| 637 web_ui()->CallJavascriptFunction( | 639 web_ui()->CallJavascriptFunctionUnsafe(kJsPortalFrameLoadCompletedCallback); |
| 638 kJsPortalFrameLoadCompletedCallback); | |
| 639 } | 640 } |
| 640 | 641 |
| 641 void MobileSetupUI::DidFailProvisionalLoad( | 642 void MobileSetupUI::DidFailProvisionalLoad( |
| 642 content::RenderFrameHost* render_frame_host, | 643 content::RenderFrameHost* render_frame_host, |
| 643 const GURL& validated_url, | 644 const GURL& validated_url, |
| 644 int error_code, | 645 int error_code, |
| 645 const base::string16& error_description, | 646 const base::string16& error_description, |
| 646 bool was_ignored_by_handler) { | 647 bool was_ignored_by_handler) { |
| 647 if (render_frame_host->GetFrameName() != "paymentForm") | 648 if (render_frame_host->GetFrameName() != "paymentForm") |
| 648 return; | 649 return; |
| 649 | 650 |
| 650 base::FundamentalValue result_value(-error_code); | 651 base::FundamentalValue result_value(-error_code); |
| 651 web_ui()->CallJavascriptFunction(kJsPortalFrameLoadFailedCallback, | 652 web_ui()->CallJavascriptFunctionUnsafe(kJsPortalFrameLoadFailedCallback, |
| 652 result_value); | 653 result_value); |
| 653 } | 654 } |
| OLD | NEW |