| 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/utility/extensions/extensions_handler.h" | 5 #include "chrome/utility/extensions/extensions_handler.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "media/base/media.h" | 25 #include "media/base/media.h" |
| 26 #include "mojo/public/cpp/bindings/strong_binding.h" | 26 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 27 #include "services/service_manager/public/cpp/interface_registry.h" | 27 #include "services/service_manager/public/cpp/interface_registry.h" |
| 28 #include "ui/base/ui_base_switches.h" | 28 #include "ui/base/ui_base_switches.h" |
| 29 | 29 |
| 30 #if !defined(MEDIA_DISABLE_FFMPEG) | 30 #if !defined(MEDIA_DISABLE_FFMPEG) |
| 31 #include "media/base/media_file_checker.h" | 31 #include "media/base/media_file_checker.h" |
| 32 #endif | 32 #endif |
| 33 | 33 |
| 34 #if defined(OS_WIN) | 34 #if defined(OS_WIN) |
| 35 #include "chrome/common/extensions/wifi_credentials_getter.mojom.h" |
| 35 #include "chrome/utility/media_galleries/itunes_pref_parser_win.h" | 36 #include "chrome/utility/media_galleries/itunes_pref_parser_win.h" |
| 36 #include "components/wifi/wifi_service.h" | 37 #include "components/wifi/wifi_service.h" |
| 37 #endif // defined(OS_WIN) | 38 #endif // defined(OS_WIN) |
| 38 | 39 |
| 39 #if defined(OS_WIN) || defined(OS_MACOSX) | 40 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 40 #include "chrome/utility/media_galleries/iapps_xml_utils.h" | 41 #include "chrome/utility/media_galleries/iapps_xml_utils.h" |
| 41 #include "chrome/utility/media_galleries/itunes_library_parser.h" | 42 #include "chrome/utility/media_galleries/itunes_library_parser.h" |
| 42 #include "chrome/utility/media_galleries/picasa_album_table_reader.h" | 43 #include "chrome/utility/media_galleries/picasa_album_table_reader.h" |
| 43 #include "chrome/utility/media_galleries/picasa_albums_indexer.h" | 44 #include "chrome/utility/media_galleries/picasa_albums_indexer.h" |
| 44 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 45 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 const std::vector<metadata::AttachedImage>& attached_images) { | 89 const std::vector<metadata::AttachedImage>& attached_images) { |
| 89 callback.Run(true, metadata.ToValue(), attached_images); | 90 callback.Run(true, metadata.ToValue(), attached_images); |
| 90 ReleaseProcessIfNeeded(); | 91 ReleaseProcessIfNeeded(); |
| 91 } | 92 } |
| 92 | 93 |
| 93 ChromeContentUtilityClient* const utility_client_; | 94 ChromeContentUtilityClient* const utility_client_; |
| 94 | 95 |
| 95 DISALLOW_COPY_AND_ASSIGN(MediaParserImpl); | 96 DISALLOW_COPY_AND_ASSIGN(MediaParserImpl); |
| 96 }; | 97 }; |
| 97 | 98 |
| 99 #if defined(OS_WIN) |
| 100 class WiFiCredentialsGetterImpl |
| 101 : public extensions::mojom::WiFiCredentialsGetter { |
| 102 public: |
| 103 WiFiCredentialsGetterImpl() = default; |
| 104 ~WiFiCredentialsGetterImpl() override = default; |
| 105 |
| 106 static void Create(extensions::mojom::WiFiCredentialsGetterRequest request) { |
| 107 mojo::MakeStrongBinding(base::MakeUnique<WiFiCredentialsGetterImpl>(), |
| 108 std::move(request)); |
| 109 } |
| 110 |
| 111 private: |
| 112 // extensions::mojom::WiFiCredentialsGetter: |
| 113 void GetWiFiCredentials(const std::string& ssid, |
| 114 const GetWiFiCredentialsCallback& callback) override { |
| 115 if (ssid == kWiFiTestNetwork) { |
| 116 callback.Run(true, ssid); // test-mode: return the ssid in key_data. |
| 117 return; |
| 118 } |
| 119 |
| 120 std::unique_ptr<wifi::WiFiService> wifi_service( |
| 121 wifi::WiFiService::Create()); |
| 122 wifi_service->Initialize(nullptr); |
| 123 |
| 124 std::string key_data; |
| 125 std::string error; |
| 126 wifi_service->GetKeyFromSystem(ssid, &key_data, &error); |
| 127 |
| 128 const bool success = error.empty(); |
| 129 if (!success) |
| 130 key_data.clear(); |
| 131 |
| 132 callback.Run(success, key_data); |
| 133 } |
| 134 |
| 135 DISALLOW_COPY_AND_ASSIGN(WiFiCredentialsGetterImpl); |
| 136 }; |
| 137 #endif // defined(OS_WIN) |
| 138 |
| 98 } // namespace | 139 } // namespace |
| 99 | 140 |
| 100 namespace extensions { | 141 namespace extensions { |
| 101 | 142 |
| 102 ExtensionsHandler::ExtensionsHandler() { | 143 ExtensionsHandler::ExtensionsHandler() { |
| 103 ExtensionsClient::Set(ChromeExtensionsClient::GetInstance()); | 144 ExtensionsClient::Set(ChromeExtensionsClient::GetInstance()); |
| 104 } | 145 } |
| 105 | 146 |
| 106 ExtensionsHandler::~ExtensionsHandler() { | 147 ExtensionsHandler::~ExtensionsHandler() { |
| 107 } | 148 } |
| 108 | 149 |
| 109 // static | 150 // static |
| 110 void ExtensionsHandler::PreSandboxStartup() { | 151 void ExtensionsHandler::PreSandboxStartup() { |
| 111 // Initialize media libraries for media file validation. | 152 // Initialize media libraries for media file validation. |
| 112 media::InitializeMediaLibrary(); | 153 media::InitializeMediaLibrary(); |
| 113 } | 154 } |
| 114 | 155 |
| 115 // static | 156 // static |
| 116 void ExtensionsHandler::ExposeInterfacesToBrowser( | 157 void ExtensionsHandler::ExposeInterfacesToBrowser( |
| 117 service_manager::InterfaceRegistry* registry, | 158 service_manager::InterfaceRegistry* registry, |
| 118 ChromeContentUtilityClient* utility_client, | 159 ChromeContentUtilityClient* utility_client, |
| 119 bool running_elevated) { | 160 bool running_elevated) { |
| 120 // If our process runs with elevated privileges, only add elevated | 161 // If our process runs with elevated privileges, only add elevated Mojo |
| 121 // Mojo services to the interface registry. | 162 // services to the interface registry. |
| 122 if (running_elevated) | 163 if (running_elevated) { |
| 164 #if defined(OS_WIN) |
| 165 registry->AddInterface(base::Bind(&WiFiCredentialsGetterImpl::Create)); |
| 166 #endif |
| 123 return; | 167 return; |
| 168 } |
| 124 | 169 |
| 125 registry->AddInterface(base::Bind(&MediaParserImpl::Create, utility_client)); | 170 registry->AddInterface(base::Bind(&MediaParserImpl::Create, utility_client)); |
| 126 } | 171 } |
| 127 | 172 |
| 128 bool ExtensionsHandler::OnMessageReceived(const IPC::Message& message) { | 173 bool ExtensionsHandler::OnMessageReceived(const IPC::Message& message) { |
| 129 bool handled = true; | 174 bool handled = true; |
| 130 IPC_BEGIN_MESSAGE_MAP(ExtensionsHandler, message) | 175 IPC_BEGIN_MESSAGE_MAP(ExtensionsHandler, message) |
| 131 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_CheckMediaFile, OnCheckMediaFile) | 176 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_CheckMediaFile, OnCheckMediaFile) |
| 132 | 177 |
| 133 #if defined(OS_WIN) | 178 #if defined(OS_WIN) |
| 134 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseITunesPrefXml, | 179 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseITunesPrefXml, |
| 135 OnParseITunesPrefXml) | 180 OnParseITunesPrefXml) |
| 136 #endif // defined(OS_WIN) | 181 #endif // defined(OS_WIN) |
| 137 | 182 |
| 138 #if defined(OS_WIN) || defined(OS_MACOSX) | 183 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 139 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseITunesLibraryXmlFile, | 184 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseITunesLibraryXmlFile, |
| 140 OnParseITunesLibraryXmlFile) | 185 OnParseITunesLibraryXmlFile) |
| 141 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParsePicasaPMPDatabase, | 186 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParsePicasaPMPDatabase, |
| 142 OnParsePicasaPMPDatabase) | 187 OnParsePicasaPMPDatabase) |
| 143 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_IndexPicasaAlbumsContents, | 188 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_IndexPicasaAlbumsContents, |
| 144 OnIndexPicasaAlbumsContents) | 189 OnIndexPicasaAlbumsContents) |
| 145 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 190 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
| 146 | 191 |
| 147 #if defined(OS_WIN) | |
| 148 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GetWiFiCredentials, | |
| 149 OnGetWiFiCredentials) | |
| 150 #endif // defined(OS_WIN) | |
| 151 | |
| 152 IPC_MESSAGE_UNHANDLED(handled = false) | 192 IPC_MESSAGE_UNHANDLED(handled = false) |
| 153 IPC_END_MESSAGE_MAP() | 193 IPC_END_MESSAGE_MAP() |
| 154 | 194 |
| 155 return handled || utility_handler_.OnMessageReceived(message); | 195 return handled || utility_handler_.OnMessageReceived(message); |
| 156 } | 196 } |
| 157 | 197 |
| 158 void ExtensionsHandler::OnCheckMediaFile( | 198 void ExtensionsHandler::OnCheckMediaFile( |
| 159 int64_t milliseconds_of_decoding, | 199 int64_t milliseconds_of_decoding, |
| 160 const IPC::PlatformFileForTransit& media_file) { | 200 const IPC::PlatformFileForTransit& media_file) { |
| 161 #if !defined(MEDIA_DISABLE_FFMPEG) | 201 #if !defined(MEDIA_DISABLE_FFMPEG) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 const std::vector<picasa::FolderINIContents>& folders_inis) { | 260 const std::vector<picasa::FolderINIContents>& folders_inis) { |
| 221 picasa::PicasaAlbumsIndexer indexer(album_uids); | 261 picasa::PicasaAlbumsIndexer indexer(album_uids); |
| 222 indexer.ParseFolderINI(folders_inis); | 262 indexer.ParseFolderINI(folders_inis); |
| 223 | 263 |
| 224 Send(new ChromeUtilityHostMsg_IndexPicasaAlbumsContents_Finished( | 264 Send(new ChromeUtilityHostMsg_IndexPicasaAlbumsContents_Finished( |
| 225 indexer.albums_images())); | 265 indexer.albums_images())); |
| 226 ReleaseProcessIfNeeded(); | 266 ReleaseProcessIfNeeded(); |
| 227 } | 267 } |
| 228 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 268 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
| 229 | 269 |
| 230 #if defined(OS_WIN) | |
| 231 void ExtensionsHandler::OnGetWiFiCredentials(const std::string& network_guid) { | |
| 232 std::unique_ptr<wifi::WiFiService> wifi_service(wifi::WiFiService::Create()); | |
| 233 wifi_service->Initialize(NULL); | |
| 234 | |
| 235 std::string key_data; | |
| 236 std::string error; | |
| 237 wifi_service->GetKeyFromSystem(network_guid, &key_data, &error); | |
| 238 | |
| 239 Send(new ChromeUtilityHostMsg_GotWiFiCredentials(key_data, error.empty())); | |
| 240 } | |
| 241 #endif // defined(OS_WIN) | |
| 242 | |
| 243 } // namespace extensions | 270 } // namespace extensions |
| OLD | NEW |