OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include <string> | |
6 | |
7 #include "base/strings/string_number_conversions.h" | |
8 #include "base/strings/utf_string_conversions.h" | |
9 #include "extensions/browser/api/networking_config/networking_config_api.h" | |
10 #include "extensions/browser/api/networking_config/networking_config_service.h" | |
11 #include "extensions/browser/api/networking_config/networking_config_service_fac tory.h" | |
12 #include "ui/base/l10n/l10n_util.h" | |
13 | |
14 namespace extensions { | |
15 | |
16 namespace { | |
17 | |
18 const char kAuthenticationResultFailed[] = | |
19 "Failed to set AuthenticationResult."; | |
20 const char kMalformedFilterDescription[] = "Malformed filter description."; | |
21 const char kMalformedFilterDescriptionWithSSID[] = | |
22 "Malformed filter description. Failed to register network with SSID " | |
23 "(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.
| |
24 | |
25 } // namespace | |
26 | |
27 NetworkingConfigSetNetworkFilterFunction:: | |
28 NetworkingConfigSetNetworkFilterFunction() { | |
29 } | |
30 | |
31 ExtensionFunction::ResponseAction | |
32 NetworkingConfigSetNetworkFilterFunction::Run() { | |
33 parameters_ = | |
34 core_api::networking_config::SetNetworkFilter::Params::Create(*args_); | |
35 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); | |
36 | |
37 NetworkingConfigService* networkingConfigService = | |
38 NetworkingConfigServiceFactory::GetForBrowserContext(browser_context()); | |
39 DCHECK(networkingConfigService); | |
40 | |
41 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.
| |
42 | |
43 // Remove previously registered networks. | |
44 networkingConfigService->UnregisterExtension(id); | |
45 | |
46 for (linked_ptr<core_api::networking_config::NetworkInfo>& ni : | |
47 parameters_->networks) { | |
48 // |Type| field must be set to |WiFi| | |
49 if (ni->type != core_api::networking_config::NETWORK_TYPE_WIFI) | |
50 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.
| |
51 | |
52 // Either |ssid| or |hex_ssid| must be set. | |
53 if (!ni->ssid.get() && !ni->hex_ssid.get()) | |
54 return RespondNow(Error(kMalformedFilterDescription)); | |
55 | |
56 std::string hex_ssid; | |
57 if (ni->ssid.get()) { | |
58 auto ssid_field = ni->ssid.get(); | |
59 hex_ssid = base::HexEncode(ssid_field->c_str(), ssid_field->size()); | |
60 } | |
61 if (ni->hex_ssid.get()) | |
62 hex_ssid = *ni->hex_ssid.get(); | |
63 | |
64 if (!networkingConfigService->RegisterHexSsid(hex_ssid, id)) | |
65 return RespondNow(Error(kMalformedFilterDescriptionWithSSID + hex_ssid)); | |
66 } | |
67 | |
68 return RespondNow(NoArguments()); | |
69 } | |
70 | |
71 NetworkingConfigSetNetworkFilterFunction:: | |
72 ~NetworkingConfigSetNetworkFilterFunction() { | |
73 } | |
74 | |
75 NetworkingConfigFinishAuthenticationFunction:: | |
76 NetworkingConfigFinishAuthenticationFunction() { | |
77 } | |
78 | |
79 ExtensionFunction::ResponseAction | |
80 NetworkingConfigFinishAuthenticationFunction::Run() { | |
81 parameters_ = | |
82 core_api::networking_config::FinishAuthentication::Params::Create(*args_); | |
83 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); | |
84 | |
85 NetworkingConfigService* networkingConfigService = | |
86 NetworkingConfigServiceFactory::GetForBrowserContext(browser_context()); | |
87 DCHECK(networkingConfigService); | |
88 | |
89 const NetworkingConfigService::AuthenticationResult& last_result = | |
90 networkingConfigService->GetAuthenticationResult(); | |
91 if (last_result.authentication_state != NetworkingConfigService::NOTRY || | |
92 last_result.guid != parameters_->guid) { | |
93 RespondNow(Error(kAuthenticationResultFailed)); | |
94 } | |
95 | |
96 // Populate NetworkingCaptivePortalAPI::AuthenticationResult. | |
97 NetworkingConfigService::AuthenticationResult authentication_result; | |
98 authentication_result.extension_id = extension_id(); | |
99 authentication_result.guid = parameters_->guid; | |
100 switch (parameters_->result) { | |
101 case core_api::networking_config::AUTHENTICATION_RESULT_NONE: | |
102 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.
| |
103 break; | |
104 case core_api::networking_config::AUTHENTICATION_RESULT_UNHANDLED: | |
105 authentication_result.authentication_state = | |
106 NetworkingConfigService::FAILED; | |
107 break; | |
108 case core_api::networking_config::AUTHENTICATION_RESULT_REJECTED: | |
109 authentication_result.authentication_state = | |
110 NetworkingConfigService::REJECTED; | |
111 break; | |
112 case core_api::networking_config::AUTHENTICATION_RESULT_FAILED: | |
113 authentication_result.authentication_state = | |
114 NetworkingConfigService::FAILED; | |
115 break; | |
116 case core_api::networking_config::AUTHENTICATION_RESULT_SUCCEEDED: | |
117 authentication_result.authentication_state = | |
118 NetworkingConfigService::SUCCESS; | |
119 break; | |
120 } | |
121 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.
| |
122 return RespondNow(NoArguments()); | |
123 } | |
124 | |
125 NetworkingConfigFinishAuthenticationFunction:: | |
126 ~NetworkingConfigFinishAuthenticationFunction() { | |
127 } | |
128 | |
129 } // namespace extensions | |
OLD | NEW |