| 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/extensions/api/gcd_private/gcd_private_api.h" | 5 #include "chrome/browser/extensions/api/gcd_private/gcd_private_api.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 const std::string& api, | 278 const std::string& api, |
| 279 const base::DictionaryValue& input, | 279 const base::DictionaryValue& input, |
| 280 MessageResponseCallback callback) { | 280 MessageResponseCallback callback) { |
| 281 const base::DictionaryValue* input_actual = &input; | 281 const base::DictionaryValue* input_actual = &input; |
| 282 #if defined(ENABLE_WIFI_BOOTSTRAPPING) | 282 #if defined(ENABLE_WIFI_BOOTSTRAPPING) |
| 283 scoped_ptr<base::DictionaryValue> input_cloned; | 283 scoped_ptr<base::DictionaryValue> input_cloned; |
| 284 | 284 |
| 285 if (api == kPrivatAPISetup) { | 285 if (api == kPrivatAPISetup) { |
| 286 const base::DictionaryValue* wifi = NULL; | 286 const base::DictionaryValue* wifi = NULL; |
| 287 | 287 |
| 288 if (input.GetDictionary(kPrivetKeyWifi, &wifi) && | 288 if (input.GetDictionary(kPrivetKeyWifi, &wifi)) { |
| 289 !wifi->HasKey(kPrivetKeyPassphrase)) { | |
| 290 // If the message is a setup message, has a wifi section, try sending the | |
| 291 // passphrase. | |
| 292 std::string ssid; | 289 std::string ssid; |
| 293 | 290 |
| 294 if (!wifi->GetString(kPrivetKeySSID, &ssid)) { | 291 if (!wifi->GetString(kPrivetKeySSID, &ssid)) { |
| 295 callback.Run(gcd_private::STATUS_SETUPPARSEERROR, | 292 callback.Run(gcd_private::STATUS_SETUPPARSEERROR, |
| 296 base::DictionaryValue()); | 293 base::DictionaryValue()); |
| 297 return; | 294 return; |
| 298 } | 295 } |
| 299 | 296 |
| 300 PasswordMap::iterator found = wifi_passwords_.find(ssid); | 297 if (!wifi->HasKey(kPrivetKeyPassphrase)) { |
| 301 if (found == wifi_passwords_.end()) { | 298 // If the message is a setup message, has a wifi section, try sending |
| 302 callback.Run(gcd_private::STATUS_WIFIPASSWORDERROR, | 299 // the passphrase. |
| 303 base::DictionaryValue()); | 300 |
| 304 return; | 301 PasswordMap::iterator found = wifi_passwords_.find(ssid); |
| 302 if (found == wifi_passwords_.end()) { |
| 303 callback.Run(gcd_private::STATUS_WIFIPASSWORDERROR, |
| 304 base::DictionaryValue()); |
| 305 return; |
| 306 } |
| 307 |
| 308 input_cloned.reset(input.DeepCopy()); |
| 309 input_cloned->SetString(kPrivetKeyPassphraseDotted, found->second); |
| 310 input_actual = input_cloned.get(); |
| 305 } | 311 } |
| 306 | |
| 307 input_cloned.reset(input.DeepCopy()); | |
| 308 input_cloned->SetString(kPrivetKeyPassphraseDotted, found->second); | |
| 309 input_actual = input_cloned.get(); | |
| 310 } | 312 } |
| 311 } | 313 } |
| 312 #endif | 314 #endif |
| 313 | 315 |
| 314 GCDSessionMap::iterator found = sessions_.find(session_id); | 316 GCDSessionMap::iterator found = sessions_.find(session_id); |
| 315 | 317 |
| 316 if (found == sessions_.end()) { | 318 if (found == sessions_.end()) { |
| 317 callback.Run(gcd_private::STATUS_UNKNOWNSESSIONERROR, | 319 callback.Run(gcd_private::STATUS_UNKNOWNSESSIONERROR, |
| 318 base::DictionaryValue()); | 320 base::DictionaryValue()); |
| 319 return; | 321 return; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 wifi_manager_->Start(); | 355 wifi_manager_->Start(); |
| 354 } | 356 } |
| 355 } | 357 } |
| 356 | 358 |
| 357 #endif | 359 #endif |
| 358 | 360 |
| 359 void GcdPrivateAPI::RemoveSession(int session_id) { | 361 void GcdPrivateAPI::RemoveSession(int session_id) { |
| 360 sessions_.erase(session_id); | 362 sessions_.erase(session_id); |
| 361 } | 363 } |
| 362 | 364 |
| 365 scoped_ptr<base::ListValue> GcdPrivateAPI::GetPrefetchedSSIDList() { |
| 366 scoped_ptr<base::ListValue> retval(new base::ListValue); |
| 367 |
| 368 #if defined(ENABLE_WIFI_BOOTSTRAPPING) |
| 369 for (PasswordMap::iterator i = wifi_passwords_.begin(); |
| 370 i != wifi_passwords_.end(); |
| 371 i++) { |
| 372 retval->AppendString(i->first); |
| 373 } |
| 374 #endif |
| 375 |
| 376 return retval.Pass(); |
| 377 } |
| 378 |
| 363 // static | 379 // static |
| 364 void GcdPrivateAPI::SetGCDApiFlowFactoryForTests( | 380 void GcdPrivateAPI::SetGCDApiFlowFactoryForTests( |
| 365 GCDApiFlowFactoryForTests* factory) { | 381 GCDApiFlowFactoryForTests* factory) { |
| 366 g_gcd_api_flow_factory = factory; | 382 g_gcd_api_flow_factory = factory; |
| 367 } | 383 } |
| 368 | 384 |
| 369 GcdPrivateRequest::GcdPrivateRequest( | 385 GcdPrivateRequest::GcdPrivateRequest( |
| 370 const std::string& api, | 386 const std::string& api, |
| 371 const base::DictionaryValue& input, | 387 const base::DictionaryValue& input, |
| 372 const GcdPrivateAPI::MessageResponseCallback& callback, | 388 const GcdPrivateAPI::MessageResponseCallback& callback, |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 } | 576 } |
| 561 | 577 |
| 562 GcdPrivateQueryForNewLocalDevicesFunction:: | 578 GcdPrivateQueryForNewLocalDevicesFunction:: |
| 563 ~GcdPrivateQueryForNewLocalDevicesFunction() { | 579 ~GcdPrivateQueryForNewLocalDevicesFunction() { |
| 564 } | 580 } |
| 565 | 581 |
| 566 bool GcdPrivateQueryForNewLocalDevicesFunction::RunSync() { | 582 bool GcdPrivateQueryForNewLocalDevicesFunction::RunSync() { |
| 567 GcdPrivateAPI* gcd_api = | 583 GcdPrivateAPI* gcd_api = |
| 568 BrowserContextKeyedAPIFactory<GcdPrivateAPI>::Get(GetProfile()); | 584 BrowserContextKeyedAPIFactory<GcdPrivateAPI>::Get(GetProfile()); |
| 569 | 585 |
| 570 if (!gcd_api) | |
| 571 return false; | |
| 572 | 586 |
| 573 if (!gcd_api->QueryForDevices()) { | 587 if (!gcd_api->QueryForDevices()) { |
| 574 error_ = | 588 error_ = |
| 575 "You must first subscribe to onDeviceStateChanged or onDeviceRemoved " | 589 "You must first subscribe to onDeviceStateChanged or onDeviceRemoved " |
| 576 "notifications"; | 590 "notifications"; |
| 577 return false; | 591 return false; |
| 578 } | 592 } |
| 579 | 593 |
| 580 return true; | 594 return true; |
| 581 } | 595 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 bool GcdPrivateEstablishSessionFunction::RunAsync() { | 638 bool GcdPrivateEstablishSessionFunction::RunAsync() { |
| 625 scoped_ptr<gcd_private::EstablishSession::Params> params = | 639 scoped_ptr<gcd_private::EstablishSession::Params> params = |
| 626 gcd_private::EstablishSession::Params::Create(*args_); | 640 gcd_private::EstablishSession::Params::Create(*args_); |
| 627 | 641 |
| 628 if (!params) | 642 if (!params) |
| 629 return false; | 643 return false; |
| 630 | 644 |
| 631 GcdPrivateAPI* gcd_api = | 645 GcdPrivateAPI* gcd_api = |
| 632 BrowserContextKeyedAPIFactory<GcdPrivateAPI>::Get(GetProfile()); | 646 BrowserContextKeyedAPIFactory<GcdPrivateAPI>::Get(GetProfile()); |
| 633 | 647 |
| 634 if (!gcd_api) | |
| 635 return false; | |
| 636 | 648 |
| 637 gcd_api->EstablishSession( | 649 gcd_api->EstablishSession( |
| 638 params->ip_address, | 650 params->ip_address, |
| 639 params->port, | 651 params->port, |
| 640 base::Bind(&GcdPrivateEstablishSessionFunction::OnConfirmCodeCallback, | 652 base::Bind(&GcdPrivateEstablishSessionFunction::OnConfirmCodeCallback, |
| 641 this)); | 653 this)); |
| 642 | 654 |
| 643 return true; | 655 return true; |
| 644 } | 656 } |
| 645 | 657 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 662 bool GcdPrivateConfirmCodeFunction::RunAsync() { | 674 bool GcdPrivateConfirmCodeFunction::RunAsync() { |
| 663 scoped_ptr<gcd_private::ConfirmCode::Params> params = | 675 scoped_ptr<gcd_private::ConfirmCode::Params> params = |
| 664 gcd_private::ConfirmCode::Params::Create(*args_); | 676 gcd_private::ConfirmCode::Params::Create(*args_); |
| 665 | 677 |
| 666 if (!params) | 678 if (!params) |
| 667 return false; | 679 return false; |
| 668 | 680 |
| 669 GcdPrivateAPI* gcd_api = | 681 GcdPrivateAPI* gcd_api = |
| 670 BrowserContextKeyedAPIFactory<GcdPrivateAPI>::Get(GetProfile()); | 682 BrowserContextKeyedAPIFactory<GcdPrivateAPI>::Get(GetProfile()); |
| 671 | 683 |
| 672 if (!gcd_api) | |
| 673 return false; | |
| 674 | 684 |
| 675 gcd_api->ConfirmCode( | 685 gcd_api->ConfirmCode( |
| 676 params->session_id, | 686 params->session_id, |
| 677 base::Bind(&GcdPrivateConfirmCodeFunction::OnSessionEstablishedCallback, | 687 base::Bind(&GcdPrivateConfirmCodeFunction::OnSessionEstablishedCallback, |
| 678 this)); | 688 this)); |
| 679 | 689 |
| 680 return true; | 690 return true; |
| 681 } | 691 } |
| 682 | 692 |
| 683 void GcdPrivateConfirmCodeFunction::OnSessionEstablishedCallback( | 693 void GcdPrivateConfirmCodeFunction::OnSessionEstablishedCallback( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 695 bool GcdPrivateSendMessageFunction::RunAsync() { | 705 bool GcdPrivateSendMessageFunction::RunAsync() { |
| 696 scoped_ptr<gcd_private::PassMessage::Params> params = | 706 scoped_ptr<gcd_private::PassMessage::Params> params = |
| 697 gcd_private::PassMessage::Params::Create(*args_); | 707 gcd_private::PassMessage::Params::Create(*args_); |
| 698 | 708 |
| 699 if (!params) | 709 if (!params) |
| 700 return false; | 710 return false; |
| 701 | 711 |
| 702 GcdPrivateAPI* gcd_api = | 712 GcdPrivateAPI* gcd_api = |
| 703 BrowserContextKeyedAPIFactory<GcdPrivateAPI>::Get(GetProfile()); | 713 BrowserContextKeyedAPIFactory<GcdPrivateAPI>::Get(GetProfile()); |
| 704 | 714 |
| 705 if (!gcd_api) | |
| 706 return false; | |
| 707 | 715 |
| 708 gcd_api->SendMessage( | 716 gcd_api->SendMessage( |
| 709 params->session_id, | 717 params->session_id, |
| 710 params->api, | 718 params->api, |
| 711 params->input.additional_properties, | 719 params->input.additional_properties, |
| 712 base::Bind(&GcdPrivateSendMessageFunction::OnMessageSentCallback, this)); | 720 base::Bind(&GcdPrivateSendMessageFunction::OnMessageSentCallback, this)); |
| 713 | 721 |
| 714 return true; | 722 return true; |
| 715 } | 723 } |
| 716 | 724 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 733 bool GcdPrivateTerminateSessionFunction::RunAsync() { | 741 bool GcdPrivateTerminateSessionFunction::RunAsync() { |
| 734 scoped_ptr<gcd_private::TerminateSession::Params> params = | 742 scoped_ptr<gcd_private::TerminateSession::Params> params = |
| 735 gcd_private::TerminateSession::Params::Create(*args_); | 743 gcd_private::TerminateSession::Params::Create(*args_); |
| 736 | 744 |
| 737 if (!params) | 745 if (!params) |
| 738 return false; | 746 return false; |
| 739 | 747 |
| 740 GcdPrivateAPI* gcd_api = | 748 GcdPrivateAPI* gcd_api = |
| 741 BrowserContextKeyedAPIFactory<GcdPrivateAPI>::Get(GetProfile()); | 749 BrowserContextKeyedAPIFactory<GcdPrivateAPI>::Get(GetProfile()); |
| 742 | 750 |
| 743 if (!gcd_api) | |
| 744 return false; | |
| 745 | 751 |
| 746 gcd_api->RemoveSession(params->session_id); | 752 gcd_api->RemoveSession(params->session_id); |
| 747 | 753 |
| 748 SendResponse(true); | 754 SendResponse(true); |
| 749 return true; | 755 return true; |
| 750 } | 756 } |
| 751 | 757 |
| 752 GcdPrivateGetCommandDefinitionsFunction:: | 758 GcdPrivateGetCommandDefinitionsFunction:: |
| 753 GcdPrivateGetCommandDefinitionsFunction() { | 759 GcdPrivateGetCommandDefinitionsFunction() { |
| 754 } | 760 } |
| 755 | 761 |
| 756 GcdPrivateGetCommandDefinitionsFunction:: | 762 GcdPrivateGetCommandDefinitionsFunction:: |
| 757 ~GcdPrivateGetCommandDefinitionsFunction() { | 763 ~GcdPrivateGetCommandDefinitionsFunction() { |
| 758 } | 764 } |
| 759 | 765 |
| 766 GcdPrivateGetPrefetchedWifiNameListFunction:: |
| 767 GcdPrivateGetPrefetchedWifiNameListFunction() { |
| 768 } |
| 769 |
| 770 GcdPrivateGetPrefetchedWifiNameListFunction:: |
| 771 ~GcdPrivateGetPrefetchedWifiNameListFunction() { |
| 772 } |
| 773 |
| 774 bool GcdPrivateGetPrefetchedWifiNameListFunction::RunSync() { |
| 775 GcdPrivateAPI* gcd_api = |
| 776 BrowserContextKeyedAPIFactory<GcdPrivateAPI>::Get(GetProfile()); |
| 777 |
| 778 DCHECK(gcd_api); |
| 779 scoped_ptr<base::ListValue> ssid_list = gcd_api->GetPrefetchedSSIDList(); |
| 780 |
| 781 SetResult(ssid_list.release()); |
| 782 |
| 783 return true; |
| 784 } |
| 785 |
| 760 bool GcdPrivateGetCommandDefinitionsFunction::RunAsync() { | 786 bool GcdPrivateGetCommandDefinitionsFunction::RunAsync() { |
| 761 return false; | 787 return false; |
| 762 } | 788 } |
| 763 | 789 |
| 764 GcdPrivateInsertCommandFunction::GcdPrivateInsertCommandFunction() { | 790 GcdPrivateInsertCommandFunction::GcdPrivateInsertCommandFunction() { |
| 765 } | 791 } |
| 766 | 792 |
| 767 GcdPrivateInsertCommandFunction::~GcdPrivateInsertCommandFunction() { | 793 GcdPrivateInsertCommandFunction::~GcdPrivateInsertCommandFunction() { |
| 768 } | 794 } |
| 769 | 795 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 795 } | 821 } |
| 796 | 822 |
| 797 GcdPrivateGetCommandsListFunction::~GcdPrivateGetCommandsListFunction() { | 823 GcdPrivateGetCommandsListFunction::~GcdPrivateGetCommandsListFunction() { |
| 798 } | 824 } |
| 799 | 825 |
| 800 bool GcdPrivateGetCommandsListFunction::RunAsync() { | 826 bool GcdPrivateGetCommandsListFunction::RunAsync() { |
| 801 return false; | 827 return false; |
| 802 } | 828 } |
| 803 | 829 |
| 804 } // namespace extensions | 830 } // namespace extensions |
| OLD | NEW |