Chromium Code Reviews| Index: chrome/utility/extensions/extensions_handler.cc |
| diff --git a/chrome/utility/extensions/extensions_handler.cc b/chrome/utility/extensions/extensions_handler.cc |
| index 9992d42ec90fe10e797ef4849fae210e8b7ba3ff..3b4483260cf1209229325bb750a08c8220eddd65 100644 |
| --- a/chrome/utility/extensions/extensions_handler.cc |
| +++ b/chrome/utility/extensions/extensions_handler.cc |
| @@ -32,6 +32,7 @@ |
| #endif |
| #if defined(OS_WIN) |
| +#include "chrome/common/extensions/wifi_credentials.mojom.h" |
| #include "chrome/utility/media_galleries/itunes_pref_parser_win.h" |
| #include "components/wifi/wifi_service.h" |
| #endif // defined(OS_WIN) |
| @@ -95,6 +96,45 @@ class MediaParserImpl : public extensions::mojom::MediaParser { |
| DISALLOW_COPY_AND_ASSIGN(MediaParserImpl); |
| }; |
| +#if defined(OS_WIN) |
| +class WiFiCredentialsImpl : public extensions::mojom::WiFiCredentials { |
| + public: |
| + static void Create(extensions::mojom::WiFiCredentialsRequest request) { |
|
Sam McNally
2017/01/16 04:16:20
Constructors and destructors before methods.
Noel Gordon
2017/01/16 11:09:58
Done.
|
| + mojo::MakeStrongBinding(base::MakeUnique<WiFiCredentialsImpl>(), |
| + std::move(request)); |
| + } |
| + |
| + WiFiCredentialsImpl() = default; |
| + ~WiFiCredentialsImpl() override = default; |
| + |
| + private: |
| + // extensions::mojom::WiFiCredentials: |
| + void GetWiFiCredentials(const std::string& ssid, |
| + const GetWiFiCredentialsCallback& callback) override { |
| + if (ssid == "chrome://test-wifi-get-key-from-system") { |
| + callback.Run(true, ssid); // test-mode: echo the ssid back in key_data. |
| + return; |
| + } |
| + |
| + std::unique_ptr<wifi::WiFiService> wifi_service( |
| + wifi::WiFiService::Create()); |
| + wifi_service->Initialize(nullptr); |
| + |
| + std::string key_data; |
| + std::string error; |
| + wifi_service->GetKeyFromSystem(ssid, &key_data, &error); |
| + |
| + const bool success = error.empty(); |
| + if (!success) |
| + key_data.clear(); |
|
Sam McNally
2017/01/16 04:16:20
This wasn't here before.
Noel Gordon
2017/01/16 11:09:58
But is now because security. If this API fails, t
|
| + |
| + callback.Run(success, key_data); |
| + } |
| + |
| + DISALLOW_COPY_AND_ASSIGN(WiFiCredentialsImpl); |
| +}; |
| +#endif // defined(OS_WIN) |
| + |
| } // namespace |
| namespace extensions { |
| @@ -119,8 +159,12 @@ void ExtensionsHandler::ExposeInterfacesToBrowser( |
| bool running_elevated) { |
| // If our process runs with elevated privileges, only add elevated |
| // Mojo services to the interface registry. |
| - if (running_elevated) |
| + if (running_elevated) { |
| +#if defined(OS_WIN) |
| + registry->AddInterface(base::Bind(&WiFiCredentialsImpl::Create)); |
| +#endif |
| return; |
| + } |
| registry->AddInterface(base::Bind(&MediaParserImpl::Create, utility_client)); |
| } |
| @@ -144,11 +188,6 @@ bool ExtensionsHandler::OnMessageReceived(const IPC::Message& message) { |
| OnIndexPicasaAlbumsContents) |
| #endif // defined(OS_WIN) || defined(OS_MACOSX) |
| -#if defined(OS_WIN) |
| - IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GetWiFiCredentials, |
| - OnGetWiFiCredentials) |
| -#endif // defined(OS_WIN) |
| - |
| IPC_MESSAGE_UNHANDLED(handled = false) |
| IPC_END_MESSAGE_MAP() |
| @@ -227,17 +266,4 @@ void ExtensionsHandler::OnIndexPicasaAlbumsContents( |
| } |
| #endif // defined(OS_WIN) || defined(OS_MACOSX) |
| -#if defined(OS_WIN) |
| -void ExtensionsHandler::OnGetWiFiCredentials(const std::string& network_guid) { |
| - std::unique_ptr<wifi::WiFiService> wifi_service(wifi::WiFiService::Create()); |
| - wifi_service->Initialize(NULL); |
| - |
| - std::string key_data; |
| - std::string error; |
| - wifi_service->GetKeyFromSystem(network_guid, &key_data, &error); |
| - |
| - Send(new ChromeUtilityHostMsg_GotWiFiCredentials(key_data, error.empty())); |
| -} |
| -#endif // defined(OS_WIN) |
| - |
| } // namespace extensions |