Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: extensions/browser/api/networking_private/networking_private_api.cc

Issue 2628673002: Enable networking.onc for autolaunched kiosk sessions (on dev) (Closed)
Patch Set: . Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
17 19
18 namespace { 20 namespace {
19 21
20 const int kDefaultNetworkListLimit = 1000; 22 const int kDefaultNetworkListLimit = 1000;
21 23
24 const char kPrivateOnlyError[] = "Requires networkingPrivate API access.";
25
22 extensions::NetworkingPrivateDelegate* GetDelegate( 26 extensions::NetworkingPrivateDelegate* GetDelegate(
23 content::BrowserContext* browser_context) { 27 content::BrowserContext* browser_context) {
24 return extensions::NetworkingPrivateDelegateFactory::GetForBrowserContext( 28 return extensions::NetworkingPrivateDelegateFactory::GetForBrowserContext(
25 browser_context); 29 browser_context);
26 } 30 }
27 31
32 bool HasPrivateNetworkingAccess(const extensions::Extension* extension,
33 extensions::Feature::Context context,
34 const GURL& source_url) {
35 return extensions::ExtensionAPI::GetSharedInstance()
Devlin 2017/01/12 21:41:05 nitty nit: maybe just move the namespace extension
tbarzic 2017/01/12 21:59:55 Done.
36 ->IsAvailable("networkingPrivate", extension, context, source_url,
37 extensions::CheckAliasStatus::NOT_ALLOWED)
38 .is_available();
39 }
40
28 } // namespace 41 } // namespace
29 42
30 namespace extensions { 43 namespace extensions {
31 44
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";
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
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.
300 if (!HasPrivateNetworkingAccess(extension(), source_context_type(),
301 source_url())) {
302 error_ = kPrivateOnlyError;
303 return false;
304 }
305
285 std::string network_type = private_api::ToString(params->network_type); 306 std::string network_type = private_api::ToString(params->network_type);
286 const bool configured_only = false; 307 const bool configured_only = false;
287 const bool visible_only = true; 308 const bool visible_only = true;
288 309
289 GetDelegate(browser_context()) 310 GetDelegate(browser_context())
290 ->GetNetworks( 311 ->GetNetworks(
291 network_type, configured_only, visible_only, kDefaultNetworkListLimit, 312 network_type, configured_only, visible_only, kDefaultNetworkListLimit,
292 base::Bind(&NetworkingPrivateGetVisibleNetworksFunction::Success, 313 base::Bind(&NetworkingPrivateGetVisibleNetworksFunction::Success,
293 this), 314 this),
294 base::Bind(&NetworkingPrivateGetVisibleNetworksFunction::Failure, 315 base::Bind(&NetworkingPrivateGetVisibleNetworksFunction::Failure,
(...skipping 15 matching lines...) Expand all
310 331
311 //////////////////////////////////////////////////////////////////////////////// 332 ////////////////////////////////////////////////////////////////////////////////
312 // NetworkingPrivateGetEnabledNetworkTypesFunction 333 // NetworkingPrivateGetEnabledNetworkTypesFunction
313 334
314 NetworkingPrivateGetEnabledNetworkTypesFunction:: 335 NetworkingPrivateGetEnabledNetworkTypesFunction::
315 ~NetworkingPrivateGetEnabledNetworkTypesFunction() { 336 ~NetworkingPrivateGetEnabledNetworkTypesFunction() {
316 } 337 }
317 338
318 ExtensionFunction::ResponseAction 339 ExtensionFunction::ResponseAction
319 NetworkingPrivateGetEnabledNetworkTypesFunction::Run() { 340 NetworkingPrivateGetEnabledNetworkTypesFunction::Run() {
341 // getEnabledNetworkTypes is deprecated - allow it only for apps with
342 // networkingPrivate permissions.
343 if (!HasPrivateNetworkingAccess(extension(), source_context_type(),
344 source_url())) {
345 return RespondNow(Error(kPrivateOnlyError));
346 }
347
320 std::unique_ptr<base::ListValue> enabled_networks_onc_types( 348 std::unique_ptr<base::ListValue> enabled_networks_onc_types(
321 GetDelegate(browser_context())->GetEnabledNetworkTypes()); 349 GetDelegate(browser_context())->GetEnabledNetworkTypes());
322 if (!enabled_networks_onc_types) 350 if (!enabled_networks_onc_types)
323 return RespondNow(Error(networking_private::kErrorNotSupported)); 351 return RespondNow(Error(networking_private::kErrorNotSupported));
324 std::unique_ptr<base::ListValue> enabled_networks_list(new base::ListValue); 352 std::unique_ptr<base::ListValue> enabled_networks_list(new base::ListValue);
325 for (base::ListValue::iterator iter = enabled_networks_onc_types->begin(); 353 for (base::ListValue::iterator iter = enabled_networks_onc_types->begin();
326 iter != enabled_networks_onc_types->end(); ++iter) { 354 iter != enabled_networks_onc_types->end(); ++iter) {
327 std::string type; 355 std::string type;
328 if (!(*iter)->GetAsString(&type)) 356 if (!(*iter)->GetAsString(&type))
329 NOTREACHED(); 357 NOTREACHED();
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 } 536 }
509 537
510 //////////////////////////////////////////////////////////////////////////////// 538 ////////////////////////////////////////////////////////////////////////////////
511 // NetworkingPrivateVerifyDestinationFunction 539 // NetworkingPrivateVerifyDestinationFunction
512 540
513 NetworkingPrivateVerifyDestinationFunction:: 541 NetworkingPrivateVerifyDestinationFunction::
514 ~NetworkingPrivateVerifyDestinationFunction() { 542 ~NetworkingPrivateVerifyDestinationFunction() {
515 } 543 }
516 544
517 bool NetworkingPrivateVerifyDestinationFunction::RunAsync() { 545 bool NetworkingPrivateVerifyDestinationFunction::RunAsync() {
546 // TODO(tbarzic): Consider exposing this via separate API.
547 // http://crbug.com/678737
548 if (!HasPrivateNetworkingAccess(extension(), source_context_type(),
549 source_url())) {
550 error_ = kPrivateOnlyError;
551 return false;
552 }
553
518 std::unique_ptr<private_api::VerifyDestination::Params> params = 554 std::unique_ptr<private_api::VerifyDestination::Params> params =
519 private_api::VerifyDestination::Params::Create(*args_); 555 private_api::VerifyDestination::Params::Create(*args_);
520 EXTENSION_FUNCTION_VALIDATE(params); 556 EXTENSION_FUNCTION_VALIDATE(params);
521 557
522 GetDelegate(browser_context()) 558 GetDelegate(browser_context())
523 ->VerifyDestination( 559 ->VerifyDestination(
524 params->properties, 560 params->properties,
525 base::Bind(&NetworkingPrivateVerifyDestinationFunction::Success, 561 base::Bind(&NetworkingPrivateVerifyDestinationFunction::Success,
526 this), 562 this),
527 base::Bind(&NetworkingPrivateVerifyDestinationFunction::Failure, 563 base::Bind(&NetworkingPrivateVerifyDestinationFunction::Failure,
(...skipping 13 matching lines...) Expand all
541 } 577 }
542 578
543 //////////////////////////////////////////////////////////////////////////////// 579 ////////////////////////////////////////////////////////////////////////////////
544 // NetworkingPrivateVerifyAndEncryptCredentialsFunction 580 // NetworkingPrivateVerifyAndEncryptCredentialsFunction
545 581
546 NetworkingPrivateVerifyAndEncryptCredentialsFunction:: 582 NetworkingPrivateVerifyAndEncryptCredentialsFunction::
547 ~NetworkingPrivateVerifyAndEncryptCredentialsFunction() { 583 ~NetworkingPrivateVerifyAndEncryptCredentialsFunction() {
548 } 584 }
549 585
550 bool NetworkingPrivateVerifyAndEncryptCredentialsFunction::RunAsync() { 586 bool NetworkingPrivateVerifyAndEncryptCredentialsFunction::RunAsync() {
587 // TODO(tbarzic): Consider exposing this via separate API.
588 // http://crbug.com/678737
589 if (!HasPrivateNetworkingAccess(extension(), source_context_type(),
590 source_url())) {
591 error_ = kPrivateOnlyError;
592 return false;
593 }
551 std::unique_ptr<private_api::VerifyAndEncryptCredentials::Params> params = 594 std::unique_ptr<private_api::VerifyAndEncryptCredentials::Params> params =
552 private_api::VerifyAndEncryptCredentials::Params::Create(*args_); 595 private_api::VerifyAndEncryptCredentials::Params::Create(*args_);
553 EXTENSION_FUNCTION_VALIDATE(params); 596 EXTENSION_FUNCTION_VALIDATE(params);
554 597
555 GetDelegate(browser_context()) 598 GetDelegate(browser_context())
556 ->VerifyAndEncryptCredentials( 599 ->VerifyAndEncryptCredentials(
557 params->network_guid, params->properties, 600 params->network_guid, params->properties,
558 base::Bind( 601 base::Bind(
559 &NetworkingPrivateVerifyAndEncryptCredentialsFunction::Success, 602 &NetworkingPrivateVerifyAndEncryptCredentialsFunction::Success,
560 this), 603 this),
(...skipping 16 matching lines...) Expand all
577 } 620 }
578 621
579 //////////////////////////////////////////////////////////////////////////////// 622 ////////////////////////////////////////////////////////////////////////////////
580 // NetworkingPrivateVerifyAndEncryptDataFunction 623 // NetworkingPrivateVerifyAndEncryptDataFunction
581 624
582 NetworkingPrivateVerifyAndEncryptDataFunction:: 625 NetworkingPrivateVerifyAndEncryptDataFunction::
583 ~NetworkingPrivateVerifyAndEncryptDataFunction() { 626 ~NetworkingPrivateVerifyAndEncryptDataFunction() {
584 } 627 }
585 628
586 bool NetworkingPrivateVerifyAndEncryptDataFunction::RunAsync() { 629 bool NetworkingPrivateVerifyAndEncryptDataFunction::RunAsync() {
630 // TODO(tbarzic): Consider exposing this via separate API.
631 // http://crbug.com/678737
632 if (!HasPrivateNetworkingAccess(extension(), source_context_type(),
633 source_url())) {
634 error_ = kPrivateOnlyError;
635 return false;
636 }
587 std::unique_ptr<private_api::VerifyAndEncryptData::Params> params = 637 std::unique_ptr<private_api::VerifyAndEncryptData::Params> params =
588 private_api::VerifyAndEncryptData::Params::Create(*args_); 638 private_api::VerifyAndEncryptData::Params::Create(*args_);
589 EXTENSION_FUNCTION_VALIDATE(params); 639 EXTENSION_FUNCTION_VALIDATE(params);
590 640
591 GetDelegate(browser_context()) 641 GetDelegate(browser_context())
592 ->VerifyAndEncryptData( 642 ->VerifyAndEncryptData(
593 params->properties, params->data, 643 params->properties, params->data,
594 base::Bind(&NetworkingPrivateVerifyAndEncryptDataFunction::Success, 644 base::Bind(&NetworkingPrivateVerifyAndEncryptDataFunction::Success,
595 this), 645 this),
596 base::Bind(&NetworkingPrivateVerifyAndEncryptDataFunction::Failure, 646 base::Bind(&NetworkingPrivateVerifyAndEncryptDataFunction::Failure,
(...skipping 14 matching lines...) Expand all
611 } 661 }
612 662
613 //////////////////////////////////////////////////////////////////////////////// 663 ////////////////////////////////////////////////////////////////////////////////
614 // NetworkingPrivateSetWifiTDLSEnabledStateFunction 664 // NetworkingPrivateSetWifiTDLSEnabledStateFunction
615 665
616 NetworkingPrivateSetWifiTDLSEnabledStateFunction:: 666 NetworkingPrivateSetWifiTDLSEnabledStateFunction::
617 ~NetworkingPrivateSetWifiTDLSEnabledStateFunction() { 667 ~NetworkingPrivateSetWifiTDLSEnabledStateFunction() {
618 } 668 }
619 669
620 bool NetworkingPrivateSetWifiTDLSEnabledStateFunction::RunAsync() { 670 bool NetworkingPrivateSetWifiTDLSEnabledStateFunction::RunAsync() {
671 // TODO(tbarzic): Consider exposing this via separate API.
672 // http://crbug.com/678737
673 if (!HasPrivateNetworkingAccess(extension(), source_context_type(),
674 source_url())) {
675 error_ = kPrivateOnlyError;
676 return false;
677 }
621 std::unique_ptr<private_api::SetWifiTDLSEnabledState::Params> params = 678 std::unique_ptr<private_api::SetWifiTDLSEnabledState::Params> params =
622 private_api::SetWifiTDLSEnabledState::Params::Create(*args_); 679 private_api::SetWifiTDLSEnabledState::Params::Create(*args_);
623 EXTENSION_FUNCTION_VALIDATE(params); 680 EXTENSION_FUNCTION_VALIDATE(params);
624 681
625 GetDelegate(browser_context()) 682 GetDelegate(browser_context())
626 ->SetWifiTDLSEnabledState( 683 ->SetWifiTDLSEnabledState(
627 params->ip_or_mac_address, params->enabled, 684 params->ip_or_mac_address, params->enabled,
628 base::Bind(&NetworkingPrivateSetWifiTDLSEnabledStateFunction::Success, 685 base::Bind(&NetworkingPrivateSetWifiTDLSEnabledStateFunction::Success,
629 this), 686 this),
630 base::Bind(&NetworkingPrivateSetWifiTDLSEnabledStateFunction::Failure, 687 base::Bind(&NetworkingPrivateSetWifiTDLSEnabledStateFunction::Failure,
(...skipping 15 matching lines...) Expand all
646 } 703 }
647 704
648 //////////////////////////////////////////////////////////////////////////////// 705 ////////////////////////////////////////////////////////////////////////////////
649 // NetworkingPrivateGetWifiTDLSStatusFunction 706 // NetworkingPrivateGetWifiTDLSStatusFunction
650 707
651 NetworkingPrivateGetWifiTDLSStatusFunction:: 708 NetworkingPrivateGetWifiTDLSStatusFunction::
652 ~NetworkingPrivateGetWifiTDLSStatusFunction() { 709 ~NetworkingPrivateGetWifiTDLSStatusFunction() {
653 } 710 }
654 711
655 bool NetworkingPrivateGetWifiTDLSStatusFunction::RunAsync() { 712 bool NetworkingPrivateGetWifiTDLSStatusFunction::RunAsync() {
713 // TODO(tbarzic): Consider exposing this via separate API.
714 // http://crbug.com/678737
715 if (!HasPrivateNetworkingAccess(extension(), source_context_type(),
716 source_url())) {
717 error_ = kPrivateOnlyError;
718 return false;
719 }
656 std::unique_ptr<private_api::GetWifiTDLSStatus::Params> params = 720 std::unique_ptr<private_api::GetWifiTDLSStatus::Params> params =
657 private_api::GetWifiTDLSStatus::Params::Create(*args_); 721 private_api::GetWifiTDLSStatus::Params::Create(*args_);
658 EXTENSION_FUNCTION_VALIDATE(params); 722 EXTENSION_FUNCTION_VALIDATE(params);
659 723
660 GetDelegate(browser_context()) 724 GetDelegate(browser_context())
661 ->GetWifiTDLSStatus( 725 ->GetWifiTDLSStatus(
662 params->ip_or_mac_address, 726 params->ip_or_mac_address,
663 base::Bind(&NetworkingPrivateGetWifiTDLSStatusFunction::Success, 727 base::Bind(&NetworkingPrivateGetWifiTDLSStatusFunction::Success,
664 this), 728 this),
665 base::Bind(&NetworkingPrivateGetWifiTDLSStatusFunction::Failure, 729 base::Bind(&NetworkingPrivateGetWifiTDLSStatusFunction::Failure,
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 // private_api::GlobalPolicy is a subset of the global policy dictionary 857 // private_api::GlobalPolicy is a subset of the global policy dictionary
794 // (by definition), so use the api setter/getter to generate the subset. 858 // (by definition), so use the api setter/getter to generate the subset.
795 std::unique_ptr<private_api::GlobalPolicy> policy( 859 std::unique_ptr<private_api::GlobalPolicy> policy(
796 private_api::GlobalPolicy::FromValue(*policy_dict)); 860 private_api::GlobalPolicy::FromValue(*policy_dict));
797 DCHECK(policy); 861 DCHECK(policy);
798 return RespondNow( 862 return RespondNow(
799 ArgumentList(private_api::GetGlobalPolicy::Results::Create(*policy))); 863 ArgumentList(private_api::GetGlobalPolicy::Results::Create(*policy)));
800 } 864 }
801 865
802 } // namespace extensions 866 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698