| 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 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 base::Bind(&MobileSetupHandler::HandleGetDeviceInfo, | 432 base::Bind(&MobileSetupHandler::HandleGetDeviceInfo, |
| 433 base::Unretained(this))); | 433 base::Unretained(this))); |
| 434 } | 434 } |
| 435 | 435 |
| 436 void MobileSetupHandler::HandleStartActivation(const base::ListValue* args) { | 436 void MobileSetupHandler::HandleStartActivation(const base::ListValue* args) { |
| 437 DCHECK_EQ(TYPE_UNDETERMINED, type_); | 437 DCHECK_EQ(TYPE_UNDETERMINED, type_); |
| 438 | 438 |
| 439 if (!web_ui()) | 439 if (!web_ui()) |
| 440 return; | 440 return; |
| 441 | 441 |
| 442 std::string path = web_ui()->GetWebContents()->GetURL().path(); | 442 base::StringPiece path = web_ui()->GetWebContents()->GetURL().path(); |
| 443 if (path.empty()) | 443 if (path.empty()) |
| 444 return; | 444 return; |
| 445 | 445 |
| 446 LOG(WARNING) << "Starting activation for service " << path; | 446 LOG(WARNING) << "Starting activation for service " << path; |
| 447 | 447 |
| 448 type_ = TYPE_ACTIVATION; | 448 type_ = TYPE_ACTIVATION; |
| 449 MobileActivator::GetInstance()->AddObserver(this); | 449 MobileActivator::GetInstance()->AddObserver(this); |
| 450 MobileActivator::GetInstance()->InitiateActivation(path.substr(1)); | 450 MobileActivator::GetInstance()->InitiateActivation( |
| 451 path.substr(1).as_string()); |
| 451 } | 452 } |
| 452 | 453 |
| 453 void MobileSetupHandler::HandleSetTransactionStatus( | 454 void MobileSetupHandler::HandleSetTransactionStatus( |
| 454 const base::ListValue* args) { | 455 const base::ListValue* args) { |
| 455 DCHECK_EQ(TYPE_ACTIVATION, type_); | 456 DCHECK_EQ(TYPE_ACTIVATION, type_); |
| 456 if (!web_ui()) | 457 if (!web_ui()) |
| 457 return; | 458 return; |
| 458 | 459 |
| 459 const size_t kSetTransactionStatusParamCount = 1; | 460 const size_t kSetTransactionStatusParamCount = 1; |
| 460 if (args->GetSize() != kSetTransactionStatusParamCount) | 461 if (args->GetSize() != kSetTransactionStatusParamCount) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 483 | 484 |
| 484 MobileActivator::GetInstance()->OnPortalLoaded( | 485 MobileActivator::GetInstance()->OnPortalLoaded( |
| 485 base::LowerCaseEqualsASCII(result, kJsApiResultOK)); | 486 base::LowerCaseEqualsASCII(result, kJsApiResultOK)); |
| 486 } | 487 } |
| 487 | 488 |
| 488 void MobileSetupHandler::HandleGetDeviceInfo(const base::ListValue* args) { | 489 void MobileSetupHandler::HandleGetDeviceInfo(const base::ListValue* args) { |
| 489 DCHECK_NE(TYPE_ACTIVATION, type_); | 490 DCHECK_NE(TYPE_ACTIVATION, type_); |
| 490 if (!web_ui()) | 491 if (!web_ui()) |
| 491 return; | 492 return; |
| 492 | 493 |
| 493 std::string path = web_ui()->GetWebContents()->GetURL().path(); | 494 base::StringPiece path = web_ui()->GetWebContents()->GetURL().path(); |
| 494 if (path.empty()) | 495 if (path.empty()) |
| 495 return; | 496 return; |
| 496 | 497 |
| 497 chromeos::NetworkStateHandler* nsh = | 498 chromeos::NetworkStateHandler* nsh = |
| 498 NetworkHandler::Get()->network_state_handler(); | 499 NetworkHandler::Get()->network_state_handler(); |
| 499 // TODO: Figure out why the path has an extra '/' in the front. (e.g. It is | 500 // TODO: Figure out why the path has an extra '/' in the front. (e.g. It is |
| 500 // '//service/5' instead of '/service/5'. | 501 // '//service/5' instead of '/service/5'. |
| 501 const NetworkState* network = nsh->GetNetworkState(path.substr(1)); | 502 const NetworkState* network = |
| 503 nsh->GetNetworkState(path.substr(1).as_string()); |
| 502 if (!network) { | 504 if (!network) { |
| 503 web_ui()->GetWebContents()->Close(); | 505 web_ui()->GetWebContents()->Close(); |
| 504 return; | 506 return; |
| 505 } | 507 } |
| 506 | 508 |
| 507 // If this is the initial call, update the network status and start observing | 509 // If this is the initial call, update the network status and start observing |
| 508 // network changes, but only for LTE networks. The other networks should | 510 // network changes, but only for LTE networks. The other networks should |
| 509 // ignore network status. | 511 // ignore network status. |
| 510 if (type_ == TYPE_UNDETERMINED) { | 512 if (type_ == TYPE_UNDETERMINED) { |
| 511 if (network->network_technology() == shill::kNetworkTechnologyLte || | 513 if (network->network_technology() == shill::kNetworkTechnologyLte || |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 // Invoke |callback_name| with an empty dictionary. | 554 // Invoke |callback_name| with an empty dictionary. |
| 553 base::DictionaryValue device_dict; | 555 base::DictionaryValue device_dict; |
| 554 web_ui()->CallJavascriptFunctionUnsafe(callback_name, device_dict); | 556 web_ui()->CallJavascriptFunctionUnsafe(callback_name, device_dict); |
| 555 } | 557 } |
| 556 | 558 |
| 557 void MobileSetupHandler::DefaultNetworkChanged( | 559 void MobileSetupHandler::DefaultNetworkChanged( |
| 558 const NetworkState* default_network) { | 560 const NetworkState* default_network) { |
| 559 if (!web_ui()) | 561 if (!web_ui()) |
| 560 return; | 562 return; |
| 561 | 563 |
| 562 std::string path = web_ui()->GetWebContents()->GetURL().path().substr(1); | 564 std::string path = |
| 565 web_ui()->GetWebContents()->GetURL().path().substr(1).as_string(); |
| 563 if (path.empty()) | 566 if (path.empty()) |
| 564 return; | 567 return; |
| 565 | 568 |
| 566 const NetworkState* network = | 569 const NetworkState* network = |
| 567 NetworkHandler::Get()->network_state_handler()->GetNetworkState(path); | 570 NetworkHandler::Get()->network_state_handler()->GetNetworkState(path); |
| 568 if (!network) { | 571 if (!network) { |
| 569 LOG(ERROR) << "Service path lost"; | 572 LOG(ERROR) << "Service path lost"; |
| 570 web_ui()->GetWebContents()->Close(); | 573 web_ui()->GetWebContents()->Close(); |
| 571 return; | 574 return; |
| 572 } | 575 } |
| 573 | 576 |
| 574 UpdatePortalReachability(network, false /* do not force notification */); | 577 UpdatePortalReachability(network, false /* do not force notification */); |
| 575 } | 578 } |
| 576 | 579 |
| 577 void MobileSetupHandler::NetworkConnectionStateChanged( | 580 void MobileSetupHandler::NetworkConnectionStateChanged( |
| 578 const NetworkState* network) { | 581 const NetworkState* network) { |
| 579 if (!web_ui()) | 582 if (!web_ui()) |
| 580 return; | 583 return; |
| 581 | 584 |
| 582 std::string path = web_ui()->GetWebContents()->GetURL().path().substr(1); | 585 std::string path = |
| 586 web_ui()->GetWebContents()->GetURL().path().substr(1).as_string(); |
| 583 if (path.empty() || path != network->path()) | 587 if (path.empty() || path != network->path()) |
| 584 return; | 588 return; |
| 585 | 589 |
| 586 UpdatePortalReachability(network, false /* do not force notification */); | 590 UpdatePortalReachability(network, false /* do not force notification */); |
| 587 } | 591 } |
| 588 | 592 |
| 589 void MobileSetupHandler::UpdatePortalReachability( | 593 void MobileSetupHandler::UpdatePortalReachability( |
| 590 const NetworkState* network, | 594 const NetworkState* network, |
| 591 bool force_notification) { | 595 bool force_notification) { |
| 592 DCHECK(web_ui()); | 596 DCHECK(web_ui()); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 int error_code, | 647 int error_code, |
| 644 const base::string16& error_description, | 648 const base::string16& error_description, |
| 645 bool was_ignored_by_handler) { | 649 bool was_ignored_by_handler) { |
| 646 if (render_frame_host->GetFrameName() != "paymentForm") | 650 if (render_frame_host->GetFrameName() != "paymentForm") |
| 647 return; | 651 return; |
| 648 | 652 |
| 649 base::FundamentalValue result_value(-error_code); | 653 base::FundamentalValue result_value(-error_code); |
| 650 web_ui()->CallJavascriptFunctionUnsafe(kJsPortalFrameLoadFailedCallback, | 654 web_ui()->CallJavascriptFunctionUnsafe(kJsPortalFrameLoadFailedCallback, |
| 651 result_value); | 655 result_value); |
| 652 } | 656 } |
| OLD | NEW |