| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chrome_content_utility_client.h" | 5 #include "chrome/utility/chrome_content_utility_client.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" |
| 10 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
| 11 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/time/time.h" |
| 13 #include "chrome/common/chrome_utility_messages.h" | 15 #include "chrome/common/chrome_utility_messages.h" |
| 14 #include "chrome/common/extensions/chrome_manifest_handlers.h" | 16 #include "chrome/common/extensions/chrome_manifest_handlers.h" |
| 15 #include "chrome/common/extensions/extension.h" | 17 #include "chrome/common/extensions/extension.h" |
| 16 #include "chrome/common/extensions/extension_l10n_util.h" | 18 #include "chrome/common/extensions/extension_l10n_util.h" |
| 17 #include "chrome/common/extensions/manifest.h" | 19 #include "chrome/common/extensions/manifest.h" |
| 18 #include "chrome/common/extensions/permissions/chrome_api_permissions.h" | 20 #include "chrome/common/extensions/permissions/chrome_api_permissions.h" |
| 19 #include "chrome/common/extensions/update_manifest.h" | 21 #include "chrome/common/extensions/update_manifest.h" |
| 20 #include "chrome/common/safe_browsing/zip_analyzer.h" | 22 #include "chrome/common/safe_browsing/zip_analyzer.h" |
| 21 #include "chrome/utility/extensions/unpacker.h" | 23 #include "chrome/utility/extensions/unpacker.h" |
| 22 #include "chrome/utility/profile_import_handler.h" | 24 #include "chrome/utility/profile_import_handler.h" |
| 23 #include "chrome/utility/web_resource_unpacker.h" | 25 #include "chrome/utility/web_resource_unpacker.h" |
| 24 #include "content/public/child/image_decoder_utils.h" | 26 #include "content/public/child/image_decoder_utils.h" |
| 25 #include "content/public/utility/utility_thread.h" | 27 #include "content/public/utility/utility_thread.h" |
| 28 #include "media/base/media.h" |
| 29 #include "media/base/media_file_checker.h" |
| 26 #include "printing/page_range.h" | 30 #include "printing/page_range.h" |
| 27 #include "third_party/skia/include/core/SkBitmap.h" | 31 #include "third_party/skia/include/core/SkBitmap.h" |
| 28 #include "third_party/zlib/google/zip.h" | 32 #include "third_party/zlib/google/zip.h" |
| 29 #include "ui/base/ui_base_switches.h" | 33 #include "ui/base/ui_base_switches.h" |
| 30 #include "ui/gfx/codec/jpeg_codec.h" | 34 #include "ui/gfx/codec/jpeg_codec.h" |
| 31 #include "ui/gfx/rect.h" | 35 #include "ui/gfx/rect.h" |
| 32 #include "ui/gfx/size.h" | 36 #include "ui/gfx/size.h" |
| 33 | 37 |
| 34 #if defined(OS_WIN) | 38 #if defined(OS_WIN) |
| 35 #include "base/file_util.h" | 39 #include "base/file_util.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToMetafile, | 120 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToMetafile, |
| 117 OnRenderPDFPagesToMetafile) | 121 OnRenderPDFPagesToMetafile) |
| 118 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RobustJPEGDecodeImage, | 122 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RobustJPEGDecodeImage, |
| 119 OnRobustJPEGDecodeImage) | 123 OnRobustJPEGDecodeImage) |
| 120 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseJSON, OnParseJSON) | 124 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseJSON, OnParseJSON) |
| 121 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetPrinterCapsAndDefaults, | 125 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetPrinterCapsAndDefaults, |
| 122 OnGetPrinterCapsAndDefaults) | 126 OnGetPrinterCapsAndDefaults) |
| 123 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_StartupPing, OnStartupPing) | 127 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_StartupPing, OnStartupPing) |
| 124 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_AnalyzeZipFileForDownloadProtection, | 128 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_AnalyzeZipFileForDownloadProtection, |
| 125 OnAnalyzeZipFileForDownloadProtection) | 129 OnAnalyzeZipFileForDownloadProtection) |
| 130 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_CheckMediaFile, OnCheckMediaFile) |
| 126 | 131 |
| 127 #if defined(OS_CHROMEOS) | 132 #if defined(OS_CHROMEOS) |
| 128 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_CreateZipFile, OnCreateZipFile) | 133 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_CreateZipFile, OnCreateZipFile) |
| 129 #endif // defined(OS_CHROMEOS) | 134 #endif // defined(OS_CHROMEOS) |
| 130 | 135 |
| 131 #if defined(OS_WIN) | 136 #if defined(OS_WIN) |
| 132 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseITunesPrefXml, | 137 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseITunesPrefXml, |
| 133 OnParseITunesPrefXml) | 138 OnParseITunesPrefXml) |
| 134 #endif // defined(OS_WIN) | 139 #endif // defined(OS_WIN) |
| 135 | 140 |
| 136 #if defined(OS_WIN) || defined(OS_MACOSX) | 141 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 137 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseITunesLibraryXmlFile, | 142 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseITunesLibraryXmlFile, |
| 138 OnParseITunesLibraryXmlFile) | 143 OnParseITunesLibraryXmlFile) |
| 139 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParsePicasaPMPDatabase, | 144 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParsePicasaPMPDatabase, |
| 140 OnParsePicasaPMPDatabase) | 145 OnParsePicasaPMPDatabase) |
| 141 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 146 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
| 142 | 147 |
| 143 IPC_MESSAGE_UNHANDLED(handled = false) | 148 IPC_MESSAGE_UNHANDLED(handled = false) |
| 144 IPC_END_MESSAGE_MAP() | 149 IPC_END_MESSAGE_MAP() |
| 145 | 150 |
| 146 for (Handlers::iterator it = handlers_.begin(); | 151 for (Handlers::iterator it = handlers_.begin(); |
| 147 !handled && it != handlers_.end(); ++it) { | 152 !handled && it != handlers_.end(); ++it) { |
| 148 handled = (*it)->OnMessageReceived(message); | 153 handled = (*it)->OnMessageReceived(message); |
| 149 } | 154 } |
| 150 | 155 |
| 151 return handled; | 156 return handled; |
| 152 } | 157 } |
| 153 | 158 |
| 154 void ChromeContentUtilityClient::PreSandboxStartup() { | 159 // static |
| 160 void ChromeContentUtilityClient::PreSandboxStartup( |
| 161 const base::FilePath& media_path) { |
| 155 #if defined(ENABLE_MDNS) | 162 #if defined(ENABLE_MDNS) |
| 156 local_discovery::ServiceDiscoveryMessageHandler::PreSandboxStartup(); | 163 local_discovery::ServiceDiscoveryMessageHandler::PreSandboxStartup(); |
| 157 #endif // ENABLE_MDNS | 164 #endif // ENABLE_MDNS |
| 165 |
| 166 // Load media libraries for media file validation. |
| 167 if (!media_path.empty()) |
| 168 media::InitializeMediaLibrary(media_path); |
| 158 } | 169 } |
| 159 | 170 |
| 160 void ChromeContentUtilityClient::OnUnpackExtension( | 171 void ChromeContentUtilityClient::OnUnpackExtension( |
| 161 const base::FilePath& extension_path, | 172 const base::FilePath& extension_path, |
| 162 const std::string& extension_id, | 173 const std::string& extension_id, |
| 163 int location, | 174 int location, |
| 164 int creation_flags) { | 175 int creation_flags) { |
| 165 CHECK_GT(location, extensions::Manifest::INVALID_LOCATION); | 176 CHECK_GT(location, extensions::Manifest::INVALID_LOCATION); |
| 166 CHECK_LT(location, extensions::Manifest::NUM_LOCATIONS); | 177 CHECK_LT(location, extensions::Manifest::NUM_LOCATIONS); |
| 167 extensions::PermissionsInfo::GetInstance()->InitializeWithDelegate( | 178 extensions::PermissionsInfo::GetInstance()->InitializeWithDelegate( |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 void ChromeContentUtilityClient::OnAnalyzeZipFileForDownloadProtection( | 518 void ChromeContentUtilityClient::OnAnalyzeZipFileForDownloadProtection( |
| 508 IPC::PlatformFileForTransit zip_file) { | 519 IPC::PlatformFileForTransit zip_file) { |
| 509 safe_browsing::zip_analyzer::Results results; | 520 safe_browsing::zip_analyzer::Results results; |
| 510 safe_browsing::zip_analyzer::AnalyzeZipFile( | 521 safe_browsing::zip_analyzer::AnalyzeZipFile( |
| 511 IPC::PlatformFileForTransitToPlatformFile(zip_file), &results); | 522 IPC::PlatformFileForTransitToPlatformFile(zip_file), &results); |
| 512 Send(new ChromeUtilityHostMsg_AnalyzeZipFileForDownloadProtection_Finished( | 523 Send(new ChromeUtilityHostMsg_AnalyzeZipFileForDownloadProtection_Finished( |
| 513 results)); | 524 results)); |
| 514 ReleaseProcessIfNeeded(); | 525 ReleaseProcessIfNeeded(); |
| 515 } | 526 } |
| 516 | 527 |
| 528 void ChromeContentUtilityClient::OnCheckMediaFile( |
| 529 int64 milliseconds_of_decoding, |
| 530 IPC::PlatformFileForTransit media_file) { |
| 531 bool check_success = false; |
| 532 #if !defined(OS_ANDROID) |
| 533 media::MediaFileChecker |
| 534 checker(IPC::PlatformFileForTransitToPlatformFile(media_file)); |
| 535 check_success = checker.Start( |
| 536 base::TimeDelta::FromMilliseconds(milliseconds_of_decoding)); |
| 537 #endif // !defined(OS_ANDROID) |
| 538 Send(new ChromeUtilityHostMsg_CheckMediaFile_Finished(check_success)); |
| 539 ReleaseProcessIfNeeded(); |
| 540 } |
| 541 |
| 517 #if defined(OS_WIN) | 542 #if defined(OS_WIN) |
| 518 void ChromeContentUtilityClient::OnParseITunesPrefXml( | 543 void ChromeContentUtilityClient::OnParseITunesPrefXml( |
| 519 const std::string& itunes_xml_data) { | 544 const std::string& itunes_xml_data) { |
| 520 base::FilePath library_path( | 545 base::FilePath library_path( |
| 521 itunes::FindLibraryLocationInPrefXml(itunes_xml_data)); | 546 itunes::FindLibraryLocationInPrefXml(itunes_xml_data)); |
| 522 Send(new ChromeUtilityHostMsg_GotITunesDirectory(library_path)); | 547 Send(new ChromeUtilityHostMsg_GotITunesDirectory(library_path)); |
| 523 ReleaseProcessIfNeeded(); | 548 ReleaseProcessIfNeeded(); |
| 524 } | 549 } |
| 525 #endif // defined(OS_WIN) | 550 #endif // defined(OS_WIN) |
| 526 | 551 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 indexer.ParseFolderINI(it->folder_path, it->ini_contents); | 598 indexer.ParseFolderINI(it->folder_path, it->ini_contents); |
| 574 } | 599 } |
| 575 | 600 |
| 576 Send(new ChromeUtilityHostMsg_IndexPicasaAlbumsContents_Finished( | 601 Send(new ChromeUtilityHostMsg_IndexPicasaAlbumsContents_Finished( |
| 577 indexer.albums_images())); | 602 indexer.albums_images())); |
| 578 ReleaseProcessIfNeeded(); | 603 ReleaseProcessIfNeeded(); |
| 579 } | 604 } |
| 580 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 605 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
| 581 | 606 |
| 582 } // namespace chrome | 607 } // namespace chrome |
| OLD | NEW |