| 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 "chrome/browser/extensions/api/networking_private/networking_private_cr
edentials_getter.h" | 5 #include "chrome/browser/extensions/api/networking_private/networking_private_cr
edentials_getter.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
| 13 #include "base/strings/stringprintf.h" |
| 13 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
| 14 #include "base/threading/sequenced_worker_pool.h" | 15 #include "base/threading/sequenced_worker_pool.h" |
| 15 #include "chrome/common/extensions/api/networking_private/networking_private_cry
pto.h" | 16 #include "chrome/common/extensions/api/networking_private/networking_private_cry
pto.h" |
| 16 #include "chrome/common/extensions/chrome_utility_extensions_messages.h" | 17 #include "chrome/common/extensions/chrome_utility_extensions_messages.h" |
| 17 #include "chrome/grit/generated_resources.h" | 18 #include "chrome/grit/generated_resources.h" |
| 18 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/utility_process_host.h" | 20 #include "content/public/browser/utility_process_host.h" |
| 20 #include "content/public/browser/utility_process_host_client.h" | 21 #include "content/public/browser/utility_process_host_client.h" |
| 21 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
| 22 | 23 |
| 23 using content::BrowserThread; | 24 using content::BrowserThread; |
| 24 using content::UtilityProcessHost; | 25 using content::UtilityProcessHost; |
| 25 using content::UtilityProcessHostClient; | 26 using content::UtilityProcessHostClient; |
| 26 using extensions::NetworkingPrivateCredentialsGetter; | 27 using extensions::NetworkingPrivateCredentialsGetter; |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 30 class CredentialsGetterHostClient : public UtilityProcessHostClient { | 31 class CredentialsGetterHostClient : public UtilityProcessHostClient { |
| 31 public: | 32 public: |
| 32 explicit CredentialsGetterHostClient(const std::string& public_key); | 33 explicit CredentialsGetterHostClient(const std::string& public_key); |
| 33 | 34 |
| 34 // UtilityProcessHostClient | 35 // UtilityProcessHostClient |
| 35 bool OnMessageReceived(const IPC::Message& message) override; | 36 bool OnMessageReceived(const IPC::Message& message) override; |
| 36 void OnProcessCrashed(int exit_code) override; | 37 void OnProcessCrashed(int exit_code) override; |
| 37 void OnProcessLaunchFailed() override; | 38 void OnProcessLaunchFailed(int error_code) override; |
| 38 | 39 |
| 39 // IPC message handlers. | 40 // IPC message handlers. |
| 40 void OnGotCredentials(const std::string& key_data, bool success); | 41 void OnGotCredentials(const std::string& key_data, bool success); |
| 41 | 42 |
| 42 // Starts the utility process that gets wifi passphrase from system. | 43 // Starts the utility process that gets wifi passphrase from system. |
| 43 void StartProcessOnIOThread( | 44 void StartProcessOnIOThread( |
| 44 const std::string& network_guid, | 45 const std::string& network_guid, |
| 45 const NetworkingPrivateCredentialsGetter::CredentialsCallback& callback); | 46 const NetworkingPrivateCredentialsGetter::CredentialsCallback& callback); |
| 46 | 47 |
| 47 private: | 48 private: |
| (...skipping 17 matching lines...) Expand all Loading... |
| 65 const IPC::Message& message) { | 66 const IPC::Message& message) { |
| 66 bool handled = true; | 67 bool handled = true; |
| 67 IPC_BEGIN_MESSAGE_MAP(CredentialsGetterHostClient, message) | 68 IPC_BEGIN_MESSAGE_MAP(CredentialsGetterHostClient, message) |
| 68 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GotWiFiCredentials, OnGotCredentials) | 69 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GotWiFiCredentials, OnGotCredentials) |
| 69 IPC_MESSAGE_UNHANDLED(handled = false) | 70 IPC_MESSAGE_UNHANDLED(handled = false) |
| 70 IPC_END_MESSAGE_MAP() | 71 IPC_END_MESSAGE_MAP() |
| 71 return handled; | 72 return handled; |
| 72 } | 73 } |
| 73 | 74 |
| 74 void CredentialsGetterHostClient::OnProcessCrashed(int exit_code) { | 75 void CredentialsGetterHostClient::OnProcessCrashed(int exit_code) { |
| 75 callback_.Run("", "Process Crashed"); | 76 callback_.Run( |
| 77 "", base::StringPrintf("Process Crashed with code %08x.", exit_code)); |
| 76 } | 78 } |
| 77 | 79 |
| 78 void CredentialsGetterHostClient::OnProcessLaunchFailed() { | 80 void CredentialsGetterHostClient::OnProcessLaunchFailed(int error_code) { |
| 79 callback_.Run("", "Process Launch Failed"); | 81 callback_.Run("", base::StringPrintf("Process Launch Failed with code %08x.", |
| 82 error_code)); |
| 80 } | 83 } |
| 81 | 84 |
| 82 void CredentialsGetterHostClient::OnGotCredentials(const std::string& key_data, | 85 void CredentialsGetterHostClient::OnGotCredentials(const std::string& key_data, |
| 83 bool success) { | 86 bool success) { |
| 84 if (success) { | 87 if (success) { |
| 85 std::vector<uint8_t> ciphertext; | 88 std::vector<uint8_t> ciphertext; |
| 86 if (!networking_private_crypto::EncryptByteString( | 89 if (!networking_private_crypto::EncryptByteString( |
| 87 public_key_, key_data, &ciphertext)) { | 90 public_key_, key_data, &ciphertext)) { |
| 88 callback_.Run("", "Encrypt Credentials Failed"); | 91 callback_.Run("", "Encrypt Credentials Failed"); |
| 89 return; | 92 return; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 | 156 |
| 154 NetworkingPrivateCredentialsGetterWin:: | 157 NetworkingPrivateCredentialsGetterWin:: |
| 155 ~NetworkingPrivateCredentialsGetterWin() {} | 158 ~NetworkingPrivateCredentialsGetterWin() {} |
| 156 | 159 |
| 157 NetworkingPrivateCredentialsGetter* | 160 NetworkingPrivateCredentialsGetter* |
| 158 NetworkingPrivateCredentialsGetter::Create() { | 161 NetworkingPrivateCredentialsGetter::Create() { |
| 159 return new NetworkingPrivateCredentialsGetterWin(); | 162 return new NetworkingPrivateCredentialsGetterWin(); |
| 160 } | 163 } |
| 161 | 164 |
| 162 } // namespace extensions | 165 } // namespace extensions |
| OLD | NEW |