Index: extensions/browser/api/networking_config/networking_config_api.cc |
diff --git a/extensions/browser/api/networking_config/networking_config_api.cc b/extensions/browser/api/networking_config/networking_config_api.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4afdddbeed1e7aac20cf2e83dc67441a1e0ae808 |
--- /dev/null |
+++ b/extensions/browser/api/networking_config/networking_config_api.cc |
@@ -0,0 +1,129 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include <string> |
+ |
+#include "base/strings/string_number_conversions.h" |
+#include "base/strings/utf_string_conversions.h" |
+#include "extensions/browser/api/networking_config/networking_config_api.h" |
+#include "extensions/browser/api/networking_config/networking_config_service.h" |
+#include "extensions/browser/api/networking_config/networking_config_service_factory.h" |
+#include "ui/base/l10n/l10n_util.h" |
+ |
+namespace extensions { |
+ |
+namespace { |
+ |
+const char kAuthenticationResultFailed[] = |
+ "Failed to set AuthenticationResult."; |
+const char kMalformedFilterDescription[] = "Malformed filter description."; |
+const char kMalformedFilterDescriptionWithSSID[] = |
+ "Malformed filter description. Failed to register network with SSID " |
+ "(hex): "; |
not at google - send to devlin
2015/01/29 16:48:38
Idiomatic: make this "(hex): *" and below use Erro
cschuet (SLOW)
2015/01/30 12:33:34
Done.
|
+ |
+} // namespace |
+ |
+NetworkingConfigSetNetworkFilterFunction:: |
+ NetworkingConfigSetNetworkFilterFunction() { |
+} |
+ |
+ExtensionFunction::ResponseAction |
+NetworkingConfigSetNetworkFilterFunction::Run() { |
+ parameters_ = |
+ core_api::networking_config::SetNetworkFilter::Params::Create(*args_); |
+ EXTENSION_FUNCTION_VALIDATE(parameters_.get()); |
+ |
+ NetworkingConfigService* networkingConfigService = |
+ NetworkingConfigServiceFactory::GetForBrowserContext(browser_context()); |
+ DCHECK(networkingConfigService); |
+ |
+ std::string id = extension_id(); |
not at google - send to devlin
2015/01/29 16:48:38
This creates an unnecessary copy. extension_id() r
cschuet (SLOW)
2015/01/30 12:33:34
Done.
|
+ |
+ // Remove previously registered networks. |
+ networkingConfigService->UnregisterExtension(id); |
+ |
+ for (linked_ptr<core_api::networking_config::NetworkInfo>& ni : |
+ parameters_->networks) { |
+ // |Type| field must be set to |WiFi| |
+ if (ni->type != core_api::networking_config::NETWORK_TYPE_WIFI) |
+ return RespondNow(Error(kMalformedFilterDescription)); |
stevenjb
2015/01/29 17:51:35
nit: Maybe include an "Unsupported network type" e
cschuet (SLOW)
2015/01/30 12:33:34
Done.
|
+ |
+ // Either |ssid| or |hex_ssid| must be set. |
+ if (!ni->ssid.get() && !ni->hex_ssid.get()) |
+ return RespondNow(Error(kMalformedFilterDescription)); |
+ |
+ std::string hex_ssid; |
+ if (ni->ssid.get()) { |
+ auto ssid_field = ni->ssid.get(); |
+ hex_ssid = base::HexEncode(ssid_field->c_str(), ssid_field->size()); |
+ } |
+ if (ni->hex_ssid.get()) |
+ hex_ssid = *ni->hex_ssid.get(); |
+ |
+ if (!networkingConfigService->RegisterHexSsid(hex_ssid, id)) |
+ return RespondNow(Error(kMalformedFilterDescriptionWithSSID + hex_ssid)); |
+} |
+ |
+ return RespondNow(NoArguments()); |
+} |
+ |
+NetworkingConfigSetNetworkFilterFunction:: |
+ ~NetworkingConfigSetNetworkFilterFunction() { |
+} |
+ |
+NetworkingConfigFinishAuthenticationFunction:: |
+ NetworkingConfigFinishAuthenticationFunction() { |
+} |
+ |
+ExtensionFunction::ResponseAction |
+NetworkingConfigFinishAuthenticationFunction::Run() { |
+ parameters_ = |
+ core_api::networking_config::FinishAuthentication::Params::Create(*args_); |
+ EXTENSION_FUNCTION_VALIDATE(parameters_.get()); |
+ |
+ NetworkingConfigService* networkingConfigService = |
+ NetworkingConfigServiceFactory::GetForBrowserContext(browser_context()); |
+ DCHECK(networkingConfigService); |
+ |
+ const NetworkingConfigService::AuthenticationResult& last_result = |
+ networkingConfigService->GetAuthenticationResult(); |
+ if (last_result.authentication_state != NetworkingConfigService::NOTRY || |
+ last_result.guid != parameters_->guid) { |
+ RespondNow(Error(kAuthenticationResultFailed)); |
+ } |
+ |
+ // Populate NetworkingCaptivePortalAPI::AuthenticationResult. |
+ NetworkingConfigService::AuthenticationResult authentication_result; |
+ authentication_result.extension_id = extension_id(); |
+ authentication_result.guid = parameters_->guid; |
+ switch (parameters_->result) { |
+ case core_api::networking_config::AUTHENTICATION_RESULT_NONE: |
+ NOTREACHED(); |
not at google - send to devlin
2015/01/29 16:48:38
It'd still be good to populate authentication_resu
cschuet (SLOW)
2015/01/30 12:33:34
Done.
|
+ break; |
+ case core_api::networking_config::AUTHENTICATION_RESULT_UNHANDLED: |
+ authentication_result.authentication_state = |
+ NetworkingConfigService::FAILED; |
+ break; |
+ case core_api::networking_config::AUTHENTICATION_RESULT_REJECTED: |
+ authentication_result.authentication_state = |
+ NetworkingConfigService::REJECTED; |
+ break; |
+ case core_api::networking_config::AUTHENTICATION_RESULT_FAILED: |
+ authentication_result.authentication_state = |
+ NetworkingConfigService::FAILED; |
+ break; |
+ case core_api::networking_config::AUTHENTICATION_RESULT_SUCCEEDED: |
+ authentication_result.authentication_state = |
+ NetworkingConfigService::SUCCESS; |
+ break; |
+ } |
+ networkingConfigService->SetAuthenticationResult(authentication_result); |
not at google - send to devlin
2015/01/29 16:48:38
|networking_config_service|? or just |service|, wh
cschuet (SLOW)
2015/01/30 12:33:34
Done.
|
+ return RespondNow(NoArguments()); |
+} |
+ |
+NetworkingConfigFinishAuthenticationFunction:: |
+ ~NetworkingConfigFinishAuthenticationFunction() { |
+} |
+ |
+} // namespace extensions |