| 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 "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_util.h" |
| 8 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 9 #include "chrome/common/chrome_utility_messages.h" | 10 #include "chrome/common/chrome_utility_messages.h" |
| 10 #include "chrome/common/extensions/chrome_extensions_client.h" | 11 #include "chrome/common/extensions/chrome_extensions_client.h" |
| 11 #include "chrome/common/extensions/chrome_utility_extensions_messages.h" | 12 #include "chrome/common/extensions/chrome_utility_extensions_messages.h" |
| 12 #include "chrome/common/extensions/update_manifest.h" | 13 #include "chrome/common/extensions/update_manifest.h" |
| 13 #include "chrome/common/media_galleries/metadata_types.h" | 14 #include "chrome/common/media_galleries/metadata_types.h" |
| 14 #include "chrome/utility/chrome_content_utility_client.h" | 15 #include "chrome/utility/chrome_content_utility_client.h" |
| 15 #include "chrome/utility/extensions/unpacker.h" | 16 #include "chrome/utility/extensions/unpacker.h" |
| 16 #include "chrome/utility/media_galleries/image_metadata_extractor.h" | 17 #include "chrome/utility/media_galleries/image_metadata_extractor.h" |
| 17 #include "content/public/common/content_paths.h" | 18 #include "content/public/common/content_paths.h" |
| 18 #include "content/public/utility/utility_thread.h" | 19 #include "content/public/utility/utility_thread.h" |
| 19 #include "extensions/common/extension.h" | 20 #include "extensions/common/extension.h" |
| 20 #include "extensions/common/extension_l10n_util.h" | 21 #include "extensions/common/extension_l10n_util.h" |
| 21 #include "extensions/common/manifest.h" | 22 #include "extensions/common/manifest.h" |
| 22 #include "media/base/media.h" | 23 #include "media/base/media.h" |
| 23 #include "media/base/media_file_checker.h" | 24 #include "media/base/media_file_checker.h" |
| 25 #include "third_party/zlib/google/zip.h" |
| 24 #include "ui/base/ui_base_switches.h" | 26 #include "ui/base/ui_base_switches.h" |
| 25 | 27 |
| 26 #if defined(OS_WIN) | 28 #if defined(OS_WIN) |
| 27 #include "chrome/common/extensions/api/networking_private/networking_private_cry
pto.h" | 29 #include "chrome/common/extensions/api/networking_private/networking_private_cry
pto.h" |
| 28 #include "chrome/utility/media_galleries/itunes_pref_parser_win.h" | 30 #include "chrome/utility/media_galleries/itunes_pref_parser_win.h" |
| 29 #include "components/wifi/wifi_service.h" | 31 #include "components/wifi/wifi_service.h" |
| 30 #endif // defined(OS_WIN) | 32 #endif // defined(OS_WIN) |
| 31 | 33 |
| 32 #if defined(OS_MACOSX) | 34 #if defined(OS_MACOSX) |
| 33 #include "chrome/utility/media_galleries/iphoto_library_parser.h" | 35 #include "chrome/utility/media_galleries/iphoto_library_parser.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 45 namespace { | 47 namespace { |
| 46 | 48 |
| 47 bool Send(IPC::Message* message) { | 49 bool Send(IPC::Message* message) { |
| 48 return content::UtilityThread::Get()->Send(message); | 50 return content::UtilityThread::Get()->Send(message); |
| 49 } | 51 } |
| 50 | 52 |
| 51 void ReleaseProcessIfNeeded() { | 53 void ReleaseProcessIfNeeded() { |
| 52 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); | 54 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); |
| 53 } | 55 } |
| 54 | 56 |
| 57 const char kExtensionHandlerTempDirError[] = |
| 58 "Could not create temporary directory for zipped extension."; |
| 59 const char kExtensionHandlerUnzipError[] = |
| 60 "Could not unzip extension for install."; |
| 61 |
| 55 } // namespace | 62 } // namespace |
| 56 | 63 |
| 57 ExtensionsHandler::ExtensionsHandler() {} | 64 ExtensionsHandler::ExtensionsHandler() {} |
| 58 | 65 |
| 59 ExtensionsHandler::~ExtensionsHandler() {} | 66 ExtensionsHandler::~ExtensionsHandler() {} |
| 60 | 67 |
| 61 // static | 68 // static |
| 62 void ExtensionsHandler::PreSandboxStartup() { | 69 void ExtensionsHandler::PreSandboxStartup() { |
| 63 // Initialize libexif for image metadata parsing. | 70 // Initialize libexif for image metadata parsing. |
| 64 metadata::ImageMetadataExtractor::InitializeLibrary(); | 71 metadata::ImageMetadataExtractor::InitializeLibrary(); |
| 65 | 72 |
| 66 // Load media libraries for media file validation. | 73 // Load media libraries for media file validation. |
| 67 base::FilePath media_path; | 74 base::FilePath media_path; |
| 68 PathService::Get(content::DIR_MEDIA_LIBS, &media_path); | 75 PathService::Get(content::DIR_MEDIA_LIBS, &media_path); |
| 69 if (!media_path.empty()) | 76 if (!media_path.empty()) |
| 70 media::InitializeMediaLibrary(media_path); | 77 media::InitializeMediaLibrary(media_path); |
| 71 } | 78 } |
| 72 | 79 |
| 73 void ExtensionsHandler::UtilityThreadStarted() { | 80 void ExtensionsHandler::UtilityThreadStarted() { |
| 74 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 81 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 75 std::string lang = command_line->GetSwitchValueASCII(switches::kLang); | 82 std::string lang = command_line->GetSwitchValueASCII(switches::kLang); |
| 76 if (!lang.empty()) | 83 if (!lang.empty()) |
| 77 extension_l10n_util::SetProcessLocale(lang); | 84 extension_l10n_util::SetProcessLocale(lang); |
| 78 } | 85 } |
| 79 | 86 |
| 80 bool ExtensionsHandler::OnMessageReceived(const IPC::Message& message) { | 87 bool ExtensionsHandler::OnMessageReceived(const IPC::Message& message) { |
| 81 bool handled = true; | 88 bool handled = true; |
| 82 IPC_BEGIN_MESSAGE_MAP(ExtensionsHandler, message) | 89 IPC_BEGIN_MESSAGE_MAP(ExtensionsHandler, message) |
| 83 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_UnpackExtension, OnUnpackExtension) | 90 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_UnpackExtension, OnUnpackExtension) |
| 91 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_UnzipToDir, OnUnzipToDir) |
| 84 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseUpdateManifest, | 92 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseUpdateManifest, |
| 85 OnParseUpdateManifest) | 93 OnParseUpdateManifest) |
| 86 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImageBase64, OnDecodeImageBase64) | 94 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImageBase64, OnDecodeImageBase64) |
| 87 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseJSON, OnParseJSON) | 95 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseJSON, OnParseJSON) |
| 88 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_CheckMediaFile, OnCheckMediaFile) | 96 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_CheckMediaFile, OnCheckMediaFile) |
| 89 #if defined(OS_WIN) | 97 #if defined(OS_WIN) |
| 90 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseITunesPrefXml, | 98 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseITunesPrefXml, |
| 91 OnParseITunesPrefXml) | 99 OnParseITunesPrefXml) |
| 92 #endif // defined(OS_WIN) | 100 #endif // defined(OS_WIN) |
| 93 | 101 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 Send(new ChromeUtilityHostMsg_UnpackExtension_Succeeded( | 140 Send(new ChromeUtilityHostMsg_UnpackExtension_Succeeded( |
| 133 *unpacker.parsed_manifest())); | 141 *unpacker.parsed_manifest())); |
| 134 } else { | 142 } else { |
| 135 Send(new ChromeUtilityHostMsg_UnpackExtension_Failed( | 143 Send(new ChromeUtilityHostMsg_UnpackExtension_Failed( |
| 136 unpacker.error_message())); | 144 unpacker.error_message())); |
| 137 } | 145 } |
| 138 | 146 |
| 139 ReleaseProcessIfNeeded(); | 147 ReleaseProcessIfNeeded(); |
| 140 } | 148 } |
| 141 | 149 |
| 150 void ExtensionsHandler::OnUnzipToDir(const base::FilePath& zip_path, |
| 151 const base::FilePath& dir) { |
| 152 base::FilePath temp_path; |
| 153 if (!base::CreateTemporaryDirInDir( |
| 154 dir, |
| 155 zip_path.RemoveExtension().BaseName().value() + |
| 156 FILE_PATH_LITERAL("_"), |
| 157 &temp_path)) { |
| 158 Send(new ChromeUtilityHostMsg_UnzipToDir_Failed( |
| 159 std::string(kExtensionHandlerTempDirError))); |
| 160 return; |
| 161 } |
| 162 if (!zip::Unzip(zip_path, temp_path)) { |
| 163 Send(new ChromeUtilityHostMsg_UnzipToDir_Failed( |
| 164 std::string(kExtensionHandlerUnzipError))); |
| 165 return; |
| 166 } |
| 167 Send(new ChromeUtilityHostMsg_UnzipToDir_Succeeded(temp_path)); |
| 168 } |
| 169 |
| 142 void ExtensionsHandler::OnParseUpdateManifest(const std::string& xml) { | 170 void ExtensionsHandler::OnParseUpdateManifest(const std::string& xml) { |
| 143 UpdateManifest manifest; | 171 UpdateManifest manifest; |
| 144 if (!manifest.Parse(xml)) { | 172 if (!manifest.Parse(xml)) { |
| 145 Send(new ChromeUtilityHostMsg_ParseUpdateManifest_Failed( | 173 Send(new ChromeUtilityHostMsg_ParseUpdateManifest_Failed( |
| 146 manifest.errors())); | 174 manifest.errors())); |
| 147 } else { | 175 } else { |
| 148 Send(new ChromeUtilityHostMsg_ParseUpdateManifest_Succeeded( | 176 Send(new ChromeUtilityHostMsg_ParseUpdateManifest_Succeeded( |
| 149 manifest.results())); | 177 manifest.results())); |
| 150 } | 178 } |
| 151 ReleaseProcessIfNeeded(); | 179 ReleaseProcessIfNeeded(); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 NetworkingPrivateCrypto crypto; | 309 NetworkingPrivateCrypto crypto; |
| 282 success = crypto.EncryptByteString(public_key, key_data, &ciphertext); | 310 success = crypto.EncryptByteString(public_key, key_data, &ciphertext); |
| 283 } | 311 } |
| 284 | 312 |
| 285 Send(new ChromeUtilityHostMsg_GotEncryptedWiFiCredentials(ciphertext, | 313 Send(new ChromeUtilityHostMsg_GotEncryptedWiFiCredentials(ciphertext, |
| 286 success)); | 314 success)); |
| 287 } | 315 } |
| 288 #endif // defined(OS_WIN) | 316 #endif // defined(OS_WIN) |
| 289 | 317 |
| 290 } // namespace extensions | 318 } // namespace extensions |
| OLD | NEW |