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/extension_utility_messages.h" |
20 #include "extensions/common/manifest.h" | 21 #include "extensions/common/manifest.h" |
21 #include "extensions/common/update_manifest.h" | 22 #include "extensions/common/update_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" |
24 #include "third_party/zlib/google/zip.h" | 25 #include "third_party/zlib/google/zip.h" |
25 #include "ui/base/ui_base_switches.h" | 26 #include "ui/base/ui_base_switches.h" |
26 | 27 |
27 #if defined(OS_WIN) | 28 #if defined(OS_WIN) |
28 #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" |
29 #include "chrome/utility/media_galleries/itunes_pref_parser_win.h" | 30 #include "chrome/utility/media_galleries/itunes_pref_parser_win.h" |
(...skipping 21 matching lines...) Expand all Loading... |
51 | 52 |
52 void ReleaseProcessIfNeeded() { | 53 void ReleaseProcessIfNeeded() { |
53 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); | 54 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); |
54 } | 55 } |
55 | 56 |
56 const char kExtensionHandlerUnzipError[] = | 57 const char kExtensionHandlerUnzipError[] = |
57 "Could not unzip extension for install."; | 58 "Could not unzip extension for install."; |
58 | 59 |
59 } // namespace | 60 } // namespace |
60 | 61 |
61 ExtensionsHandler::ExtensionsHandler() {} | 62 ExtensionsHandler::ExtensionsHandler() { |
| 63 } |
62 | 64 |
63 ExtensionsHandler::~ExtensionsHandler() {} | 65 ExtensionsHandler::~ExtensionsHandler() { |
| 66 } |
64 | 67 |
65 // static | 68 // static |
66 void ExtensionsHandler::PreSandboxStartup() { | 69 void ExtensionsHandler::PreSandboxStartup() { |
67 // Initialize libexif for image metadata parsing. | 70 // Initialize libexif for image metadata parsing. |
68 metadata::ImageMetadataExtractor::InitializeLibrary(); | 71 metadata::ImageMetadataExtractor::InitializeLibrary(); |
69 | 72 |
70 // Load media libraries for media file validation. | 73 // Load media libraries for media file validation. |
71 base::FilePath media_path; | 74 base::FilePath media_path; |
72 PathService::Get(content::DIR_MEDIA_LIBS, &media_path); | 75 PathService::Get(content::DIR_MEDIA_LIBS, &media_path); |
73 if (!media_path.empty()) | 76 if (!media_path.empty()) |
74 media::InitializeMediaLibrary(media_path); | 77 media::InitializeMediaLibrary(media_path); |
75 } | 78 } |
76 | 79 |
77 void ExtensionsHandler::UtilityThreadStarted() { | 80 void ExtensionsHandler::UtilityThreadStarted() { |
78 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 81 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
79 std::string lang = command_line->GetSwitchValueASCII(switches::kLang); | 82 std::string lang = command_line->GetSwitchValueASCII(switches::kLang); |
80 if (!lang.empty()) | 83 if (!lang.empty()) |
81 extension_l10n_util::SetProcessLocale(lang); | 84 extension_l10n_util::SetProcessLocale(lang); |
82 } | 85 } |
83 | 86 |
84 bool ExtensionsHandler::OnMessageReceived(const IPC::Message& message) { | 87 bool ExtensionsHandler::OnMessageReceived(const IPC::Message& message) { |
85 bool handled = true; | 88 bool handled = true; |
86 IPC_BEGIN_MESSAGE_MAP(ExtensionsHandler, message) | 89 IPC_BEGIN_MESSAGE_MAP(ExtensionsHandler, message) |
87 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_UnpackExtension, OnUnpackExtension) | 90 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_UnpackExtension, OnUnpackExtension) |
88 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_UnzipToDir, OnUnzipToDir) | 91 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_UnzipToDir, OnUnzipToDir) |
89 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseUpdateManifest, | |
90 OnParseUpdateManifest) | |
91 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImageBase64, OnDecodeImageBase64) | 92 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImageBase64, OnDecodeImageBase64) |
92 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseJSON, OnParseJSON) | 93 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseJSON, OnParseJSON) |
93 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_CheckMediaFile, OnCheckMediaFile) | 94 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_CheckMediaFile, OnCheckMediaFile) |
94 #if defined(OS_WIN) | 95 #if defined(OS_WIN) |
95 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseITunesPrefXml, | 96 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseITunesPrefXml, |
96 OnParseITunesPrefXml) | 97 OnParseITunesPrefXml) |
97 #endif // defined(OS_WIN) | 98 #endif // defined(OS_WIN) |
98 | 99 |
99 #if defined(OS_MACOSX) | 100 #if defined(OS_MACOSX) |
100 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseIPhotoLibraryXmlFile, | 101 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseIPhotoLibraryXmlFile, |
101 OnParseIPhotoLibraryXmlFile) | 102 OnParseIPhotoLibraryXmlFile) |
102 #endif // defined(OS_MACOSX) | 103 #endif // defined(OS_MACOSX) |
103 | 104 |
104 #if defined(OS_WIN) || defined(OS_MACOSX) | 105 #if defined(OS_WIN) || defined(OS_MACOSX) |
105 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseITunesLibraryXmlFile, | 106 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseITunesLibraryXmlFile, |
106 OnParseITunesLibraryXmlFile) | 107 OnParseITunesLibraryXmlFile) |
107 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParsePicasaPMPDatabase, | 108 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParsePicasaPMPDatabase, |
108 OnParsePicasaPMPDatabase) | 109 OnParsePicasaPMPDatabase) |
109 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_IndexPicasaAlbumsContents, | 110 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_IndexPicasaAlbumsContents, |
110 OnIndexPicasaAlbumsContents) | 111 OnIndexPicasaAlbumsContents) |
111 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 112 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
112 | 113 |
113 #if defined(OS_WIN) | 114 #if defined(OS_WIN) |
114 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GetWiFiCredentials, | 115 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GetWiFiCredentials, |
115 OnGetWiFiCredentials) | 116 OnGetWiFiCredentials) |
116 #endif // defined(OS_WIN) | 117 #endif // defined(OS_WIN) |
117 | 118 |
| 119 IPC_MESSAGE_HANDLER(ExtensionUtilityMsg_ParseUpdateManifest, |
| 120 OnParseUpdateManifest) |
| 121 |
118 IPC_MESSAGE_UNHANDLED(handled = false) | 122 IPC_MESSAGE_UNHANDLED(handled = false) |
119 IPC_END_MESSAGE_MAP() | 123 IPC_END_MESSAGE_MAP() |
120 return handled; | 124 return handled; |
121 } | 125 } |
122 | 126 |
123 void ExtensionsHandler::OnUnpackExtension( | 127 void ExtensionsHandler::OnUnpackExtension( |
124 const base::FilePath& extension_path, | 128 const base::FilePath& extension_path, |
125 const std::string& extension_id, | 129 const std::string& extension_id, |
126 int location, | 130 int location, |
127 int creation_flags) { | 131 int creation_flags) { |
(...skipping 24 matching lines...) Expand all Loading... |
152 } else { | 156 } else { |
153 Send(new ChromeUtilityHostMsg_UnzipToDir_Succeeded(dir)); | 157 Send(new ChromeUtilityHostMsg_UnzipToDir_Succeeded(dir)); |
154 } | 158 } |
155 | 159 |
156 ReleaseProcessIfNeeded(); | 160 ReleaseProcessIfNeeded(); |
157 } | 161 } |
158 | 162 |
159 void ExtensionsHandler::OnParseUpdateManifest(const std::string& xml) { | 163 void ExtensionsHandler::OnParseUpdateManifest(const std::string& xml) { |
160 UpdateManifest manifest; | 164 UpdateManifest manifest; |
161 if (!manifest.Parse(xml)) { | 165 if (!manifest.Parse(xml)) { |
162 Send(new ChromeUtilityHostMsg_ParseUpdateManifest_Failed( | 166 Send(new ExtensionUtilityHostMsg_ParseUpdateManifest_Failed( |
163 manifest.errors())); | 167 manifest.errors())); |
164 } else { | 168 } else { |
165 Send(new ChromeUtilityHostMsg_ParseUpdateManifest_Succeeded( | 169 Send(new ExtensionUtilityHostMsg_ParseUpdateManifest_Succeeded( |
166 manifest.results())); | 170 manifest.results())); |
167 } | 171 } |
168 ReleaseProcessIfNeeded(); | 172 ReleaseProcessIfNeeded(); |
169 } | 173 } |
170 | 174 |
171 void ExtensionsHandler::OnDecodeImageBase64( | 175 void ExtensionsHandler::OnDecodeImageBase64( |
172 const std::string& encoded_string) { | 176 const std::string& encoded_string) { |
173 std::string decoded_string; | 177 std::string decoded_string; |
174 | 178 |
175 if (!base::Base64Decode(encoded_string, &decoded_string)) { | 179 if (!base::Base64Decode(encoded_string, &decoded_string)) { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 files.name_file = | 260 files.name_file = |
257 IPC::PlatformFileForTransitToFile(album_table_files.name_file); | 261 IPC::PlatformFileForTransitToFile(album_table_files.name_file); |
258 files.token_file = | 262 files.token_file = |
259 IPC::PlatformFileForTransitToFile(album_table_files.token_file); | 263 IPC::PlatformFileForTransitToFile(album_table_files.token_file); |
260 files.uid_file = | 264 files.uid_file = |
261 IPC::PlatformFileForTransitToFile(album_table_files.uid_file); | 265 IPC::PlatformFileForTransitToFile(album_table_files.uid_file); |
262 | 266 |
263 picasa::PicasaAlbumTableReader reader(files.Pass()); | 267 picasa::PicasaAlbumTableReader reader(files.Pass()); |
264 bool parse_success = reader.Init(); | 268 bool parse_success = reader.Init(); |
265 Send(new ChromeUtilityHostMsg_ParsePicasaPMPDatabase_Finished( | 269 Send(new ChromeUtilityHostMsg_ParsePicasaPMPDatabase_Finished( |
266 parse_success, | 270 parse_success, reader.albums(), reader.folders())); |
267 reader.albums(), | |
268 reader.folders())); | |
269 ReleaseProcessIfNeeded(); | 271 ReleaseProcessIfNeeded(); |
270 } | 272 } |
271 | 273 |
272 void ExtensionsHandler::OnIndexPicasaAlbumsContents( | 274 void ExtensionsHandler::OnIndexPicasaAlbumsContents( |
273 const picasa::AlbumUIDSet& album_uids, | 275 const picasa::AlbumUIDSet& album_uids, |
274 const std::vector<picasa::FolderINIContents>& folders_inis) { | 276 const std::vector<picasa::FolderINIContents>& folders_inis) { |
275 picasa::PicasaAlbumsIndexer indexer(album_uids); | 277 picasa::PicasaAlbumsIndexer indexer(album_uids); |
276 indexer.ParseFolderINI(folders_inis); | 278 indexer.ParseFolderINI(folders_inis); |
277 | 279 |
278 Send(new ChromeUtilityHostMsg_IndexPicasaAlbumsContents_Finished( | 280 Send(new ChromeUtilityHostMsg_IndexPicasaAlbumsContents_Finished( |
279 indexer.albums_images())); | 281 indexer.albums_images())); |
280 ReleaseProcessIfNeeded(); | 282 ReleaseProcessIfNeeded(); |
281 } | 283 } |
282 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 284 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
283 | 285 |
284 #if defined(OS_WIN) | 286 #if defined(OS_WIN) |
285 void ExtensionsHandler::OnGetWiFiCredentials(const std::string& network_guid) { | 287 void ExtensionsHandler::OnGetWiFiCredentials(const std::string& network_guid) { |
286 scoped_ptr<wifi::WiFiService> wifi_service(wifi::WiFiService::Create()); | 288 scoped_ptr<wifi::WiFiService> wifi_service(wifi::WiFiService::Create()); |
287 wifi_service->Initialize(NULL); | 289 wifi_service->Initialize(NULL); |
288 | 290 |
289 std::string key_data; | 291 std::string key_data; |
290 std::string error; | 292 std::string error; |
291 wifi_service->GetKeyFromSystem(network_guid, &key_data, &error); | 293 wifi_service->GetKeyFromSystem(network_guid, &key_data, &error); |
292 | 294 |
293 Send(new ChromeUtilityHostMsg_GotWiFiCredentials(key_data, error.empty())); | 295 Send(new ChromeUtilityHostMsg_GotWiFiCredentials(key_data, error.empty())); |
294 } | 296 } |
295 #endif // defined(OS_WIN) | 297 #endif // defined(OS_WIN) |
296 | 298 |
297 } // namespace extensions | 299 } // namespace extensions |
OLD | NEW |