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 "components/wifi/wifi_service.h" | 5 #include "components/wifi/wifi_service.h" |
6 | 6 |
7 #import <netinet/in.h> | 7 #import <netinet/in.h> |
8 #import <CoreWLAN/CoreWLAN.h> | 8 #import <CoreWLAN/CoreWLAN.h> |
9 #import <SystemConfiguration/SystemConfiguration.h> | 9 #import <SystemConfiguration/SystemConfiguration.h> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/mac/foundation_util.h" |
12 #include "base/mac/scoped_cftyperef.h" | 13 #include "base/mac/scoped_cftyperef.h" |
13 #include "base/mac/scoped_nsobject.h" | 14 #include "base/mac/scoped_nsobject.h" |
14 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
15 #include "base/strings/sys_string_conversions.h" | 16 #include "base/strings/sys_string_conversions.h" |
16 #include "components/onc/onc_constants.h" | 17 #include "components/onc/onc_constants.h" |
17 | 18 |
18 #if !defined(MAC_OS_X_VERSION_10_7) || \ | 19 #if !defined(MAC_OS_X_VERSION_10_7) || \ |
19 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 | 20 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 |
20 | 21 |
21 // Local definitions of API added in Mac OS X 10.7 | 22 // Local definitions of API added in Mac OS X 10.7 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 base::ListValue* network_list) OVERRIDE; | 91 base::ListValue* network_list) OVERRIDE; |
91 | 92 |
92 virtual void RequestNetworkScan() OVERRIDE; | 93 virtual void RequestNetworkScan() OVERRIDE; |
93 | 94 |
94 virtual void StartConnect(const std::string& network_guid, | 95 virtual void StartConnect(const std::string& network_guid, |
95 std::string* error) OVERRIDE; | 96 std::string* error) OVERRIDE; |
96 | 97 |
97 virtual void StartDisconnect(const std::string& network_guid, | 98 virtual void StartDisconnect(const std::string& network_guid, |
98 std::string* error) OVERRIDE; | 99 std::string* error) OVERRIDE; |
99 | 100 |
| 101 virtual void GetKeyFromSystem(const std::string& network_guid, |
| 102 std::string* key_data, |
| 103 std::string* error) OVERRIDE; |
| 104 |
100 virtual void SetEventObservers( | 105 virtual void SetEventObservers( |
101 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, | 106 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
102 const NetworkGuidListCallback& networks_changed_observer, | 107 const NetworkGuidListCallback& networks_changed_observer, |
103 const NetworkGuidListCallback& network_list_changed_observer) OVERRIDE; | 108 const NetworkGuidListCallback& network_list_changed_observer) OVERRIDE; |
104 | 109 |
105 virtual void RequestConnectedNetworkUpdate() OVERRIDE; | 110 virtual void RequestConnectedNetworkUpdate() OVERRIDE; |
106 | 111 |
107 private: | 112 private: |
108 // Checks |ns_error| and if is not |nil|, then stores |error_name| | 113 // Checks |ns_error| and if is not |nil|, then stores |error_name| |
109 // into |error|. | 114 // into |error|. |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 NSError* ns_error = nil; | 365 NSError* ns_error = nil; |
361 [interface_ setPower:NO error:&ns_error]; | 366 [interface_ setPower:NO error:&ns_error]; |
362 CheckError(ns_error, kErrorAssociateToNetwork, error); | 367 CheckError(ns_error, kErrorAssociateToNetwork, error); |
363 [interface_ setPower:YES error:&ns_error]; | 368 [interface_ setPower:YES error:&ns_error]; |
364 CheckError(ns_error, kErrorAssociateToNetwork, error); | 369 CheckError(ns_error, kErrorAssociateToNetwork, error); |
365 } else { | 370 } else { |
366 *error = kErrorNotConnected; | 371 *error = kErrorNotConnected; |
367 } | 372 } |
368 } | 373 } |
369 | 374 |
| 375 void WiFiServiceMac::GetKeyFromSystem(const std::string& network_guid, |
| 376 std::string* key_data, |
| 377 std::string* error) { |
| 378 static const char kAirPortServiceName[] = "AirPort"; |
| 379 |
| 380 UInt32 password_length = 0; |
| 381 void *password_data = NULL; |
| 382 OSStatus status = SecKeychainFindGenericPassword(NULL, |
| 383 strlen(kAirPortServiceName), |
| 384 kAirPortServiceName, |
| 385 network_guid.length(), |
| 386 network_guid.c_str(), |
| 387 &password_length, |
| 388 &password_data, |
| 389 NULL); |
| 390 if (status != errSecSuccess) { |
| 391 *error = kErrorNotFound; |
| 392 return; |
| 393 } |
| 394 |
| 395 if (password_data) { |
| 396 *key_data = std::string(reinterpret_cast<char*>(password_data), |
| 397 password_length); |
| 398 SecKeychainItemFreeContent(NULL, password_data); |
| 399 } |
| 400 } |
| 401 |
370 void WiFiServiceMac::SetEventObservers( | 402 void WiFiServiceMac::SetEventObservers( |
371 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, | 403 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
372 const NetworkGuidListCallback& networks_changed_observer, | 404 const NetworkGuidListCallback& networks_changed_observer, |
373 const NetworkGuidListCallback& network_list_changed_observer) { | 405 const NetworkGuidListCallback& network_list_changed_observer) { |
374 message_loop_proxy_.swap(message_loop_proxy); | 406 message_loop_proxy_.swap(message_loop_proxy); |
375 networks_changed_observer_ = networks_changed_observer; | 407 networks_changed_observer_ = networks_changed_observer; |
376 network_list_changed_observer_ = network_list_changed_observer; | 408 network_list_changed_observer_ = network_list_changed_observer; |
377 | 409 |
378 // Remove previous OS notifications observer. | 410 // Remove previous OS notifications observer. |
379 if (wlan_observer_) { | 411 if (wlan_observer_) { |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 NetworkGuidList changed_networks(1, network_guid); | 626 NetworkGuidList changed_networks(1, network_guid); |
595 message_loop_proxy_->PostTask( | 627 message_loop_proxy_->PostTask( |
596 FROM_HERE, | 628 FROM_HERE, |
597 base::Bind(networks_changed_observer_, changed_networks)); | 629 base::Bind(networks_changed_observer_, changed_networks)); |
598 } | 630 } |
599 | 631 |
600 // static | 632 // static |
601 WiFiService* WiFiService::Create() { return new WiFiServiceMac(); } | 633 WiFiService* WiFiService::Create() { return new WiFiServiceMac(); } |
602 | 634 |
603 } // namespace wifi | 635 } // namespace wifi |
OLD | NEW |