OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/nfc_debug_ui.h" | 5 #include "chrome/browser/ui/webui/chromeos/nfc_debug_ui.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 base::Unretained(this))); | 384 base::Unretained(this))); |
385 web_ui()->RegisterMessageCallback( | 385 web_ui()->RegisterMessageCallback( |
386 kSubmitRecordFormCallback, | 386 kSubmitRecordFormCallback, |
387 base::Bind(&NfcDebugMessageHandler::SubmitRecordForm, | 387 base::Bind(&NfcDebugMessageHandler::SubmitRecordForm, |
388 base::Unretained(this))); | 388 base::Unretained(this))); |
389 } | 389 } |
390 | 390 |
391 void NfcDebugMessageHandler::Initialize(const base::ListValue* args) { | 391 void NfcDebugMessageHandler::Initialize(const base::ListValue* args) { |
392 bool nfc_available = NfcAdapterFactory::IsNfcAvailable(); | 392 bool nfc_available = NfcAdapterFactory::IsNfcAvailable(); |
393 base::FundamentalValue available(nfc_available); | 393 base::FundamentalValue available(nfc_available); |
394 web_ui()->CallJavascriptFunction(kOnNfcAvailabilityDeterminedFunction, | 394 web_ui()->CallJavascriptFunctionUnsafe(kOnNfcAvailabilityDeterminedFunction, |
395 available); | 395 available); |
396 if (!nfc_available) { | 396 if (!nfc_available) { |
397 LOG(WARNING) << "NFC is not available on current platform."; | 397 LOG(WARNING) << "NFC is not available on current platform."; |
398 return; | 398 return; |
399 } | 399 } |
400 NfcAdapterFactory::GetAdapter( | 400 NfcAdapterFactory::GetAdapter( |
401 base::Bind(&NfcDebugMessageHandler::OnGetAdapter, | 401 base::Bind(&NfcDebugMessageHandler::OnGetAdapter, |
402 base::Unretained(this))); | 402 base::Unretained(this))); |
403 } | 403 } |
404 | 404 |
405 void NfcDebugMessageHandler::SetAdapterPower(const base::ListValue* args) { | 405 void NfcDebugMessageHandler::SetAdapterPower(const base::ListValue* args) { |
406 DCHECK(1 == args->GetSize()); | 406 DCHECK(1 == args->GetSize()); |
407 DCHECK(nfc_adapter_.get()); | 407 DCHECK(nfc_adapter_.get()); |
408 bool powered; | 408 bool powered; |
409 args->GetBoolean(0, &powered); | 409 args->GetBoolean(0, &powered); |
410 VLOG(1) << "Setting adapter power: " << powered; | 410 VLOG(1) << "Setting adapter power: " << powered; |
411 nfc_adapter_->SetPowered( | 411 nfc_adapter_->SetPowered( |
412 powered, base::Bind(&base::DoNothing), | 412 powered, base::Bind(&base::DoNothing), |
413 base::Bind(&NfcDebugMessageHandler::OnSetAdapterPowerError, | 413 base::Bind(&NfcDebugMessageHandler::OnSetAdapterPowerError, |
414 base::Unretained(this))); | 414 base::Unretained(this))); |
415 } | 415 } |
416 | 416 |
417 void NfcDebugMessageHandler::OnSetAdapterPowerError() { | 417 void NfcDebugMessageHandler::OnSetAdapterPowerError() { |
418 LOG(ERROR) << "Failed to set NFC adapter power."; | 418 LOG(ERROR) << "Failed to set NFC adapter power."; |
419 web_ui()->CallJavascriptFunction(kOnSetAdapterPowerFailedFunction); | 419 web_ui()->CallJavascriptFunctionUnsafe(kOnSetAdapterPowerFailedFunction); |
420 } | 420 } |
421 | 421 |
422 void NfcDebugMessageHandler::SetAdapterPolling(const base::ListValue* args) { | 422 void NfcDebugMessageHandler::SetAdapterPolling(const base::ListValue* args) { |
423 DCHECK(1 == args->GetSize()); | 423 DCHECK(1 == args->GetSize()); |
424 DCHECK(nfc_adapter_.get()); | 424 DCHECK(nfc_adapter_.get()); |
425 bool start = false; | 425 bool start = false; |
426 bool result = args->GetBoolean(0, &start); | 426 bool result = args->GetBoolean(0, &start); |
427 DCHECK(result); | 427 DCHECK(result); |
428 if (start) { | 428 if (start) { |
429 VLOG(1) << "Starting NFC poll loop."; | 429 VLOG(1) << "Starting NFC poll loop."; |
430 nfc_adapter_->StartPolling( | 430 nfc_adapter_->StartPolling( |
431 base::Bind(&base::DoNothing), | 431 base::Bind(&base::DoNothing), |
432 base::Bind(&NfcDebugMessageHandler::OnSetAdapterPollingError, | 432 base::Bind(&NfcDebugMessageHandler::OnSetAdapterPollingError, |
433 base::Unretained(this))); | 433 base::Unretained(this))); |
434 } else { | 434 } else { |
435 VLOG(1) << "Stopping NFC poll loop."; | 435 VLOG(1) << "Stopping NFC poll loop."; |
436 nfc_adapter_->StopPolling( | 436 nfc_adapter_->StopPolling( |
437 base::Bind(&base::DoNothing), | 437 base::Bind(&base::DoNothing), |
438 base::Bind(&NfcDebugMessageHandler::OnSetAdapterPollingError, | 438 base::Bind(&NfcDebugMessageHandler::OnSetAdapterPollingError, |
439 base::Unretained(this))); | 439 base::Unretained(this))); |
440 } | 440 } |
441 } | 441 } |
442 | 442 |
443 void NfcDebugMessageHandler::OnSetAdapterPollingError() { | 443 void NfcDebugMessageHandler::OnSetAdapterPollingError() { |
444 LOG(ERROR) << "Failed to start/stop polling."; | 444 LOG(ERROR) << "Failed to start/stop polling."; |
445 web_ui()->CallJavascriptFunction(kOnSetAdapterPollingFailedFunction); | 445 web_ui()->CallJavascriptFunctionUnsafe(kOnSetAdapterPollingFailedFunction); |
446 } | 446 } |
447 | 447 |
448 void NfcDebugMessageHandler::SubmitRecordForm(const base::ListValue* args) { | 448 void NfcDebugMessageHandler::SubmitRecordForm(const base::ListValue* args) { |
449 DCHECK(1 == args->GetSize()); | 449 DCHECK(1 == args->GetSize()); |
450 DCHECK(nfc_adapter_.get()); | 450 DCHECK(nfc_adapter_.get()); |
451 const base::DictionaryValue* record_data_const = NULL; | 451 const base::DictionaryValue* record_data_const = NULL; |
452 if (!args->GetDictionary(0, &record_data_const)) { | 452 if (!args->GetDictionary(0, &record_data_const)) { |
453 NOTREACHED(); | 453 NOTREACHED(); |
454 return; | 454 return; |
455 } | 455 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 message, | 511 message, |
512 base::Bind(&base::DoNothing), | 512 base::Bind(&base::DoNothing), |
513 base::Bind(&NfcDebugMessageHandler::OnSubmitRecordFormFailed, | 513 base::Bind(&NfcDebugMessageHandler::OnSubmitRecordFormFailed, |
514 base::Unretained(this), | 514 base::Unretained(this), |
515 "Failed to write NDEF record.")); | 515 "Failed to write NDEF record.")); |
516 } | 516 } |
517 | 517 |
518 void NfcDebugMessageHandler::OnSubmitRecordFormFailed( | 518 void NfcDebugMessageHandler::OnSubmitRecordFormFailed( |
519 const std::string& error_message) { | 519 const std::string& error_message) { |
520 LOG(ERROR) << "SubmitRecordForm failed: " << error_message; | 520 LOG(ERROR) << "SubmitRecordForm failed: " << error_message; |
521 web_ui()->CallJavascriptFunction(kOnSubmitRecordFormFailedFunction, | 521 web_ui()->CallJavascriptFunctionUnsafe(kOnSubmitRecordFormFailedFunction, |
522 base::StringValue(error_message)); | 522 base::StringValue(error_message)); |
523 } | 523 } |
524 | 524 |
525 void NfcDebugMessageHandler::OnGetAdapter( | 525 void NfcDebugMessageHandler::OnGetAdapter( |
526 scoped_refptr<NfcAdapter> adapter) { | 526 scoped_refptr<NfcAdapter> adapter) { |
527 if (nfc_adapter_.get()) | 527 if (nfc_adapter_.get()) |
528 return; | 528 return; |
529 nfc_adapter_ = adapter; | 529 nfc_adapter_ = adapter; |
530 nfc_adapter_->AddObserver(this); | 530 nfc_adapter_->AddObserver(this); |
531 UpdateAdapterInfo(); | 531 UpdateAdapterInfo(); |
532 | 532 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 base::DictionaryValue* record_data = record->data().DeepCopy(); | 638 base::DictionaryValue* record_data = record->data().DeepCopy(); |
639 record_data->SetString(kRecordTypeProperty, | 639 record_data->SetString(kRecordTypeProperty, |
640 RecordTypeToString(record->type())); | 640 RecordTypeToString(record->type())); |
641 out->Append(record_data); | 641 out->Append(record_data); |
642 } | 642 } |
643 } | 643 } |
644 | 644 |
645 void NfcDebugMessageHandler::UpdateAdapterInfo() { | 645 void NfcDebugMessageHandler::UpdateAdapterInfo() { |
646 base::DictionaryValue data; | 646 base::DictionaryValue data; |
647 GetAdapterProperties(&data); | 647 GetAdapterProperties(&data); |
648 web_ui()->CallJavascriptFunction(kOnNfcAdapterInfoChangedFunction, data); | 648 web_ui()->CallJavascriptFunctionUnsafe(kOnNfcAdapterInfoChangedFunction, |
| 649 data); |
649 } | 650 } |
650 | 651 |
651 void NfcDebugMessageHandler::UpdatePeerInfo() { | 652 void NfcDebugMessageHandler::UpdatePeerInfo() { |
652 base::DictionaryValue data; | 653 base::DictionaryValue data; |
653 GetPeerProperties(&data); | 654 GetPeerProperties(&data); |
654 web_ui()->CallJavascriptFunction(kOnNfcPeerDeviceInfoChangedFunction, data); | 655 web_ui()->CallJavascriptFunctionUnsafe(kOnNfcPeerDeviceInfoChangedFunction, |
| 656 data); |
655 } | 657 } |
656 | 658 |
657 void NfcDebugMessageHandler::UpdateTagInfo() { | 659 void NfcDebugMessageHandler::UpdateTagInfo() { |
658 base::DictionaryValue data; | 660 base::DictionaryValue data; |
659 GetTagProperties(&data); | 661 GetTagProperties(&data); |
660 web_ui()->CallJavascriptFunction(kOnNfcTagInfoChangedFunction, data); | 662 web_ui()->CallJavascriptFunctionUnsafe(kOnNfcTagInfoChangedFunction, data); |
661 } | 663 } |
662 | 664 |
663 } // namespace | 665 } // namespace |
664 | 666 |
665 NfcDebugUI::NfcDebugUI(content::WebUI* web_ui) | 667 NfcDebugUI::NfcDebugUI(content::WebUI* web_ui) |
666 : content::WebUIController(web_ui) { | 668 : content::WebUIController(web_ui) { |
667 web_ui->AddMessageHandler(new NfcDebugMessageHandler()); | 669 web_ui->AddMessageHandler(new NfcDebugMessageHandler()); |
668 | 670 |
669 content::WebUIDataSource* html_source = | 671 content::WebUIDataSource* html_source = |
670 content::WebUIDataSource::Create(chrome::kChromeUINfcDebugHost); | 672 content::WebUIDataSource::Create(chrome::kChromeUINfcDebugHost); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 html_source->SetDefaultResource(IDR_NFC_DEBUG_HTML); | 735 html_source->SetDefaultResource(IDR_NFC_DEBUG_HTML); |
734 | 736 |
735 Profile* profile = Profile::FromWebUI(web_ui); | 737 Profile* profile = Profile::FromWebUI(web_ui); |
736 content::WebUIDataSource::Add(profile, html_source); | 738 content::WebUIDataSource::Add(profile, html_source); |
737 } | 739 } |
738 | 740 |
739 NfcDebugUI::~NfcDebugUI() { | 741 NfcDebugUI::~NfcDebugUI() { |
740 } | 742 } |
741 | 743 |
742 } // namespace chromeos | 744 } // namespace chromeos |
OLD | NEW |