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