| 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 "extensions/browser/api/networking_private/networking_private_api.h" | 5 #include "extensions/browser/api/networking_private/networking_private_api.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "components/onc/onc_constants.h" | 12 #include "components/onc/onc_constants.h" |
| 13 #include "extensions/browser/api/networking_private/networking_private_delegate.
h" | 13 #include "extensions/browser/api/networking_private/networking_private_delegate.
h" |
| 14 #include "extensions/browser/api/networking_private/networking_private_delegate_
factory.h" | 14 #include "extensions/browser/api/networking_private/networking_private_delegate_
factory.h" |
| 15 #include "extensions/browser/extension_function_registry.h" | 15 #include "extensions/browser/extension_function_registry.h" |
| 16 #include "extensions/common/api/networking_private.h" | 16 #include "extensions/common/api/networking_private.h" |
| 17 #include "extensions/common/extension_api.h" |
| 18 #include "extensions/common/features/feature_provider.h" |
| 19 |
| 20 namespace extensions { |
| 17 | 21 |
| 18 namespace { | 22 namespace { |
| 19 | 23 |
| 20 const int kDefaultNetworkListLimit = 1000; | 24 const int kDefaultNetworkListLimit = 1000; |
| 21 | 25 |
| 22 extensions::NetworkingPrivateDelegate* GetDelegate( | 26 const char kPrivateOnlyError[] = "Requires networkingPrivate API access."; |
| 27 |
| 28 NetworkingPrivateDelegate* GetDelegate( |
| 23 content::BrowserContext* browser_context) { | 29 content::BrowserContext* browser_context) { |
| 24 return extensions::NetworkingPrivateDelegateFactory::GetForBrowserContext( | 30 return NetworkingPrivateDelegateFactory::GetForBrowserContext( |
| 25 browser_context); | 31 browser_context); |
| 26 } | 32 } |
| 27 | 33 |
| 34 bool HasPrivateNetworkingAccess(const Extension* extension, |
| 35 Feature::Context context, |
| 36 const GURL& source_url) { |
| 37 return ExtensionAPI::GetSharedInstance() |
| 38 ->IsAvailable("networkingPrivate", extension, context, source_url, |
| 39 CheckAliasStatus::NOT_ALLOWED) |
| 40 .is_available(); |
| 41 } |
| 42 |
| 28 } // namespace | 43 } // namespace |
| 29 | 44 |
| 30 namespace extensions { | |
| 31 | |
| 32 namespace private_api = api::networking_private; | 45 namespace private_api = api::networking_private; |
| 33 | 46 |
| 34 namespace networking_private { | 47 namespace networking_private { |
| 35 | 48 |
| 36 // static | 49 // static |
| 37 const char kErrorInvalidNetworkGuid[] = "Error.InvalidNetworkGuid"; | 50 const char kErrorInvalidNetworkGuid[] = "Error.InvalidNetworkGuid"; |
| 38 const char kErrorInvalidNetworkOperation[] = "Error.InvalidNetworkOperation"; | 51 const char kErrorInvalidNetworkOperation[] = "Error.InvalidNetworkOperation"; |
| 39 const char kErrorNetworkUnavailable[] = "Error.NetworkUnavailable"; | 52 const char kErrorNetworkUnavailable[] = "Error.NetworkUnavailable"; |
| 40 const char kErrorEncryptionError[] = "Error.EncryptionError"; | 53 const char kErrorEncryptionError[] = "Error.EncryptionError"; |
| 41 const char kErrorNotReady[] = "Error.NotReady"; | 54 const char kErrorNotReady[] = "Error.NotReady"; |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 | 288 |
| 276 NetworkingPrivateGetVisibleNetworksFunction:: | 289 NetworkingPrivateGetVisibleNetworksFunction:: |
| 277 ~NetworkingPrivateGetVisibleNetworksFunction() { | 290 ~NetworkingPrivateGetVisibleNetworksFunction() { |
| 278 } | 291 } |
| 279 | 292 |
| 280 bool NetworkingPrivateGetVisibleNetworksFunction::RunAsync() { | 293 bool NetworkingPrivateGetVisibleNetworksFunction::RunAsync() { |
| 281 std::unique_ptr<private_api::GetVisibleNetworks::Params> params = | 294 std::unique_ptr<private_api::GetVisibleNetworks::Params> params = |
| 282 private_api::GetVisibleNetworks::Params::Create(*args_); | 295 private_api::GetVisibleNetworks::Params::Create(*args_); |
| 283 EXTENSION_FUNCTION_VALIDATE(params); | 296 EXTENSION_FUNCTION_VALIDATE(params); |
| 284 | 297 |
| 298 // getVisibleNetworks is deprecated - allow it only for apps with |
| 299 // networkingPrivate permissions, i.e. apps that might have started using it |
| 300 // before its deprecation. |
| 301 if (!HasPrivateNetworkingAccess(extension(), source_context_type(), |
| 302 source_url())) { |
| 303 error_ = kPrivateOnlyError; |
| 304 return false; |
| 305 } |
| 306 |
| 285 std::string network_type = private_api::ToString(params->network_type); | 307 std::string network_type = private_api::ToString(params->network_type); |
| 286 const bool configured_only = false; | 308 const bool configured_only = false; |
| 287 const bool visible_only = true; | 309 const bool visible_only = true; |
| 288 | 310 |
| 289 GetDelegate(browser_context()) | 311 GetDelegate(browser_context()) |
| 290 ->GetNetworks( | 312 ->GetNetworks( |
| 291 network_type, configured_only, visible_only, kDefaultNetworkListLimit, | 313 network_type, configured_only, visible_only, kDefaultNetworkListLimit, |
| 292 base::Bind(&NetworkingPrivateGetVisibleNetworksFunction::Success, | 314 base::Bind(&NetworkingPrivateGetVisibleNetworksFunction::Success, |
| 293 this), | 315 this), |
| 294 base::Bind(&NetworkingPrivateGetVisibleNetworksFunction::Failure, | 316 base::Bind(&NetworkingPrivateGetVisibleNetworksFunction::Failure, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 310 | 332 |
| 311 //////////////////////////////////////////////////////////////////////////////// | 333 //////////////////////////////////////////////////////////////////////////////// |
| 312 // NetworkingPrivateGetEnabledNetworkTypesFunction | 334 // NetworkingPrivateGetEnabledNetworkTypesFunction |
| 313 | 335 |
| 314 NetworkingPrivateGetEnabledNetworkTypesFunction:: | 336 NetworkingPrivateGetEnabledNetworkTypesFunction:: |
| 315 ~NetworkingPrivateGetEnabledNetworkTypesFunction() { | 337 ~NetworkingPrivateGetEnabledNetworkTypesFunction() { |
| 316 } | 338 } |
| 317 | 339 |
| 318 ExtensionFunction::ResponseAction | 340 ExtensionFunction::ResponseAction |
| 319 NetworkingPrivateGetEnabledNetworkTypesFunction::Run() { | 341 NetworkingPrivateGetEnabledNetworkTypesFunction::Run() { |
| 342 // getEnabledNetworkTypes is deprecated - allow it only for apps with |
| 343 // networkingPrivate permissions, i.e. apps that might have started using it |
| 344 // before its deprecation. |
| 345 if (!HasPrivateNetworkingAccess(extension(), source_context_type(), |
| 346 source_url())) { |
| 347 return RespondNow(Error(kPrivateOnlyError)); |
| 348 } |
| 349 |
| 320 std::unique_ptr<base::ListValue> enabled_networks_onc_types( | 350 std::unique_ptr<base::ListValue> enabled_networks_onc_types( |
| 321 GetDelegate(browser_context())->GetEnabledNetworkTypes()); | 351 GetDelegate(browser_context())->GetEnabledNetworkTypes()); |
| 322 if (!enabled_networks_onc_types) | 352 if (!enabled_networks_onc_types) |
| 323 return RespondNow(Error(networking_private::kErrorNotSupported)); | 353 return RespondNow(Error(networking_private::kErrorNotSupported)); |
| 324 std::unique_ptr<base::ListValue> enabled_networks_list(new base::ListValue); | 354 std::unique_ptr<base::ListValue> enabled_networks_list(new base::ListValue); |
| 325 for (base::ListValue::iterator iter = enabled_networks_onc_types->begin(); | 355 for (base::ListValue::iterator iter = enabled_networks_onc_types->begin(); |
| 326 iter != enabled_networks_onc_types->end(); ++iter) { | 356 iter != enabled_networks_onc_types->end(); ++iter) { |
| 327 std::string type; | 357 std::string type; |
| 328 if (!(*iter)->GetAsString(&type)) | 358 if (!(*iter)->GetAsString(&type)) |
| 329 NOTREACHED(); | 359 NOTREACHED(); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 } | 538 } |
| 509 | 539 |
| 510 //////////////////////////////////////////////////////////////////////////////// | 540 //////////////////////////////////////////////////////////////////////////////// |
| 511 // NetworkingPrivateVerifyDestinationFunction | 541 // NetworkingPrivateVerifyDestinationFunction |
| 512 | 542 |
| 513 NetworkingPrivateVerifyDestinationFunction:: | 543 NetworkingPrivateVerifyDestinationFunction:: |
| 514 ~NetworkingPrivateVerifyDestinationFunction() { | 544 ~NetworkingPrivateVerifyDestinationFunction() { |
| 515 } | 545 } |
| 516 | 546 |
| 517 bool NetworkingPrivateVerifyDestinationFunction::RunAsync() { | 547 bool NetworkingPrivateVerifyDestinationFunction::RunAsync() { |
| 548 // This method is private - as such, it should not be exposed through public |
| 549 // networking.onc API. |
| 550 // TODO(tbarzic): Consider exposing this via separate API. |
| 551 // http://crbug.com/678737 |
| 552 if (!HasPrivateNetworkingAccess(extension(), source_context_type(), |
| 553 source_url())) { |
| 554 error_ = kPrivateOnlyError; |
| 555 return false; |
| 556 } |
| 557 |
| 518 std::unique_ptr<private_api::VerifyDestination::Params> params = | 558 std::unique_ptr<private_api::VerifyDestination::Params> params = |
| 519 private_api::VerifyDestination::Params::Create(*args_); | 559 private_api::VerifyDestination::Params::Create(*args_); |
| 520 EXTENSION_FUNCTION_VALIDATE(params); | 560 EXTENSION_FUNCTION_VALIDATE(params); |
| 521 | 561 |
| 522 GetDelegate(browser_context()) | 562 GetDelegate(browser_context()) |
| 523 ->VerifyDestination( | 563 ->VerifyDestination( |
| 524 params->properties, | 564 params->properties, |
| 525 base::Bind(&NetworkingPrivateVerifyDestinationFunction::Success, | 565 base::Bind(&NetworkingPrivateVerifyDestinationFunction::Success, |
| 526 this), | 566 this), |
| 527 base::Bind(&NetworkingPrivateVerifyDestinationFunction::Failure, | 567 base::Bind(&NetworkingPrivateVerifyDestinationFunction::Failure, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 541 } | 581 } |
| 542 | 582 |
| 543 //////////////////////////////////////////////////////////////////////////////// | 583 //////////////////////////////////////////////////////////////////////////////// |
| 544 // NetworkingPrivateVerifyAndEncryptCredentialsFunction | 584 // NetworkingPrivateVerifyAndEncryptCredentialsFunction |
| 545 | 585 |
| 546 NetworkingPrivateVerifyAndEncryptCredentialsFunction:: | 586 NetworkingPrivateVerifyAndEncryptCredentialsFunction:: |
| 547 ~NetworkingPrivateVerifyAndEncryptCredentialsFunction() { | 587 ~NetworkingPrivateVerifyAndEncryptCredentialsFunction() { |
| 548 } | 588 } |
| 549 | 589 |
| 550 bool NetworkingPrivateVerifyAndEncryptCredentialsFunction::RunAsync() { | 590 bool NetworkingPrivateVerifyAndEncryptCredentialsFunction::RunAsync() { |
| 591 // This method is private - as such, it should not be exposed through public |
| 592 // networking.onc API. |
| 593 // TODO(tbarzic): Consider exposing this via separate API. |
| 594 // http://crbug.com/678737 |
| 595 if (!HasPrivateNetworkingAccess(extension(), source_context_type(), |
| 596 source_url())) { |
| 597 error_ = kPrivateOnlyError; |
| 598 return false; |
| 599 } |
| 551 std::unique_ptr<private_api::VerifyAndEncryptCredentials::Params> params = | 600 std::unique_ptr<private_api::VerifyAndEncryptCredentials::Params> params = |
| 552 private_api::VerifyAndEncryptCredentials::Params::Create(*args_); | 601 private_api::VerifyAndEncryptCredentials::Params::Create(*args_); |
| 553 EXTENSION_FUNCTION_VALIDATE(params); | 602 EXTENSION_FUNCTION_VALIDATE(params); |
| 554 | 603 |
| 555 GetDelegate(browser_context()) | 604 GetDelegate(browser_context()) |
| 556 ->VerifyAndEncryptCredentials( | 605 ->VerifyAndEncryptCredentials( |
| 557 params->network_guid, params->properties, | 606 params->network_guid, params->properties, |
| 558 base::Bind( | 607 base::Bind( |
| 559 &NetworkingPrivateVerifyAndEncryptCredentialsFunction::Success, | 608 &NetworkingPrivateVerifyAndEncryptCredentialsFunction::Success, |
| 560 this), | 609 this), |
| (...skipping 16 matching lines...) Expand all Loading... |
| 577 } | 626 } |
| 578 | 627 |
| 579 //////////////////////////////////////////////////////////////////////////////// | 628 //////////////////////////////////////////////////////////////////////////////// |
| 580 // NetworkingPrivateVerifyAndEncryptDataFunction | 629 // NetworkingPrivateVerifyAndEncryptDataFunction |
| 581 | 630 |
| 582 NetworkingPrivateVerifyAndEncryptDataFunction:: | 631 NetworkingPrivateVerifyAndEncryptDataFunction:: |
| 583 ~NetworkingPrivateVerifyAndEncryptDataFunction() { | 632 ~NetworkingPrivateVerifyAndEncryptDataFunction() { |
| 584 } | 633 } |
| 585 | 634 |
| 586 bool NetworkingPrivateVerifyAndEncryptDataFunction::RunAsync() { | 635 bool NetworkingPrivateVerifyAndEncryptDataFunction::RunAsync() { |
| 636 // This method is private - as such, it should not be exposed through public |
| 637 // networking.onc API. |
| 638 // TODO(tbarzic): Consider exposing this via separate API. |
| 639 // http://crbug.com/678737 |
| 640 if (!HasPrivateNetworkingAccess(extension(), source_context_type(), |
| 641 source_url())) { |
| 642 error_ = kPrivateOnlyError; |
| 643 return false; |
| 644 } |
| 587 std::unique_ptr<private_api::VerifyAndEncryptData::Params> params = | 645 std::unique_ptr<private_api::VerifyAndEncryptData::Params> params = |
| 588 private_api::VerifyAndEncryptData::Params::Create(*args_); | 646 private_api::VerifyAndEncryptData::Params::Create(*args_); |
| 589 EXTENSION_FUNCTION_VALIDATE(params); | 647 EXTENSION_FUNCTION_VALIDATE(params); |
| 590 | 648 |
| 591 GetDelegate(browser_context()) | 649 GetDelegate(browser_context()) |
| 592 ->VerifyAndEncryptData( | 650 ->VerifyAndEncryptData( |
| 593 params->properties, params->data, | 651 params->properties, params->data, |
| 594 base::Bind(&NetworkingPrivateVerifyAndEncryptDataFunction::Success, | 652 base::Bind(&NetworkingPrivateVerifyAndEncryptDataFunction::Success, |
| 595 this), | 653 this), |
| 596 base::Bind(&NetworkingPrivateVerifyAndEncryptDataFunction::Failure, | 654 base::Bind(&NetworkingPrivateVerifyAndEncryptDataFunction::Failure, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 611 } | 669 } |
| 612 | 670 |
| 613 //////////////////////////////////////////////////////////////////////////////// | 671 //////////////////////////////////////////////////////////////////////////////// |
| 614 // NetworkingPrivateSetWifiTDLSEnabledStateFunction | 672 // NetworkingPrivateSetWifiTDLSEnabledStateFunction |
| 615 | 673 |
| 616 NetworkingPrivateSetWifiTDLSEnabledStateFunction:: | 674 NetworkingPrivateSetWifiTDLSEnabledStateFunction:: |
| 617 ~NetworkingPrivateSetWifiTDLSEnabledStateFunction() { | 675 ~NetworkingPrivateSetWifiTDLSEnabledStateFunction() { |
| 618 } | 676 } |
| 619 | 677 |
| 620 bool NetworkingPrivateSetWifiTDLSEnabledStateFunction::RunAsync() { | 678 bool NetworkingPrivateSetWifiTDLSEnabledStateFunction::RunAsync() { |
| 679 // This method is private - as such, it should not be exposed through public |
| 680 // networking.onc API. |
| 681 // TODO(tbarzic): Consider exposing this via separate API. |
| 682 // http://crbug.com/678737 |
| 683 if (!HasPrivateNetworkingAccess(extension(), source_context_type(), |
| 684 source_url())) { |
| 685 error_ = kPrivateOnlyError; |
| 686 return false; |
| 687 } |
| 621 std::unique_ptr<private_api::SetWifiTDLSEnabledState::Params> params = | 688 std::unique_ptr<private_api::SetWifiTDLSEnabledState::Params> params = |
| 622 private_api::SetWifiTDLSEnabledState::Params::Create(*args_); | 689 private_api::SetWifiTDLSEnabledState::Params::Create(*args_); |
| 623 EXTENSION_FUNCTION_VALIDATE(params); | 690 EXTENSION_FUNCTION_VALIDATE(params); |
| 624 | 691 |
| 625 GetDelegate(browser_context()) | 692 GetDelegate(browser_context()) |
| 626 ->SetWifiTDLSEnabledState( | 693 ->SetWifiTDLSEnabledState( |
| 627 params->ip_or_mac_address, params->enabled, | 694 params->ip_or_mac_address, params->enabled, |
| 628 base::Bind(&NetworkingPrivateSetWifiTDLSEnabledStateFunction::Success, | 695 base::Bind(&NetworkingPrivateSetWifiTDLSEnabledStateFunction::Success, |
| 629 this), | 696 this), |
| 630 base::Bind(&NetworkingPrivateSetWifiTDLSEnabledStateFunction::Failure, | 697 base::Bind(&NetworkingPrivateSetWifiTDLSEnabledStateFunction::Failure, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 646 } | 713 } |
| 647 | 714 |
| 648 //////////////////////////////////////////////////////////////////////////////// | 715 //////////////////////////////////////////////////////////////////////////////// |
| 649 // NetworkingPrivateGetWifiTDLSStatusFunction | 716 // NetworkingPrivateGetWifiTDLSStatusFunction |
| 650 | 717 |
| 651 NetworkingPrivateGetWifiTDLSStatusFunction:: | 718 NetworkingPrivateGetWifiTDLSStatusFunction:: |
| 652 ~NetworkingPrivateGetWifiTDLSStatusFunction() { | 719 ~NetworkingPrivateGetWifiTDLSStatusFunction() { |
| 653 } | 720 } |
| 654 | 721 |
| 655 bool NetworkingPrivateGetWifiTDLSStatusFunction::RunAsync() { | 722 bool NetworkingPrivateGetWifiTDLSStatusFunction::RunAsync() { |
| 723 // This method is private - as such, it should not be exposed through public |
| 724 // networking.onc API. |
| 725 // TODO(tbarzic): Consider exposing this via separate API. |
| 726 // http://crbug.com/678737 |
| 727 if (!HasPrivateNetworkingAccess(extension(), source_context_type(), |
| 728 source_url())) { |
| 729 error_ = kPrivateOnlyError; |
| 730 return false; |
| 731 } |
| 656 std::unique_ptr<private_api::GetWifiTDLSStatus::Params> params = | 732 std::unique_ptr<private_api::GetWifiTDLSStatus::Params> params = |
| 657 private_api::GetWifiTDLSStatus::Params::Create(*args_); | 733 private_api::GetWifiTDLSStatus::Params::Create(*args_); |
| 658 EXTENSION_FUNCTION_VALIDATE(params); | 734 EXTENSION_FUNCTION_VALIDATE(params); |
| 659 | 735 |
| 660 GetDelegate(browser_context()) | 736 GetDelegate(browser_context()) |
| 661 ->GetWifiTDLSStatus( | 737 ->GetWifiTDLSStatus( |
| 662 params->ip_or_mac_address, | 738 params->ip_or_mac_address, |
| 663 base::Bind(&NetworkingPrivateGetWifiTDLSStatusFunction::Success, | 739 base::Bind(&NetworkingPrivateGetWifiTDLSStatusFunction::Success, |
| 664 this), | 740 this), |
| 665 base::Bind(&NetworkingPrivateGetWifiTDLSStatusFunction::Failure, | 741 base::Bind(&NetworkingPrivateGetWifiTDLSStatusFunction::Failure, |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 793 // private_api::GlobalPolicy is a subset of the global policy dictionary | 869 // private_api::GlobalPolicy is a subset of the global policy dictionary |
| 794 // (by definition), so use the api setter/getter to generate the subset. | 870 // (by definition), so use the api setter/getter to generate the subset. |
| 795 std::unique_ptr<private_api::GlobalPolicy> policy( | 871 std::unique_ptr<private_api::GlobalPolicy> policy( |
| 796 private_api::GlobalPolicy::FromValue(*policy_dict)); | 872 private_api::GlobalPolicy::FromValue(*policy_dict)); |
| 797 DCHECK(policy); | 873 DCHECK(policy); |
| 798 return RespondNow( | 874 return RespondNow( |
| 799 ArgumentList(private_api::GetGlobalPolicy::Results::Create(*policy))); | 875 ArgumentList(private_api::GetGlobalPolicy::Results::Create(*policy))); |
| 800 } | 876 } |
| 801 | 877 |
| 802 } // namespace extensions | 878 } // namespace extensions |
| OLD | NEW |