Chromium Code Reviews| 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/media_galleries/image_metadata_extractor.h" | 14 #include "chrome/utility/media_galleries/image_metadata_extractor.h" |
| 15 #include "content/public/common/content_paths.h" | 15 #include "content/public/common/content_paths.h" |
| 16 #include "content/public/utility/utility_thread.h" | 16 #include "content/public/utility/utility_thread.h" |
| 17 #include "extensions/common/extension.h" | 17 #include "extensions/common/extension.h" |
| 18 #include "extensions/common/extension_l10n_util.h" | 18 #include "extensions/common/extension_l10n_util.h" |
| 19 #include "extensions/common/extension_utility_messages.h" | 19 #include "extensions/common/extension_utility_messages.h" |
| 20 #include "extensions/common/manifest.h" | |
| 21 #include "extensions/utility/unpacker.h" | 20 #include "extensions/utility/unpacker.h" |
| 22 #include "media/base/media.h" | 21 #include "media/base/media.h" |
| 23 #include "media/base/media_file_checker.h" | 22 #include "media/base/media_file_checker.h" |
| 24 #include "third_party/zlib/google/zip.h" | 23 #include "third_party/zlib/google/zip.h" |
| 25 #include "ui/base/ui_base_switches.h" | 24 #include "ui/base/ui_base_switches.h" |
| 26 | 25 |
| 27 #if defined(OS_WIN) | 26 #if defined(OS_WIN) |
| 28 #include "chrome/common/extensions/api/networking_private/networking_private_cry pto.h" | 27 #include "chrome/common/extensions/api/networking_private/networking_private_cry pto.h" |
| 29 #include "chrome/utility/media_galleries/itunes_pref_parser_win.h" | 28 #include "chrome/utility/media_galleries/itunes_pref_parser_win.h" |
| 30 #include "components/wifi/wifi_service.h" | 29 #include "components/wifi/wifi_service.h" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 52 void ReleaseProcessIfNeeded() { | 51 void ReleaseProcessIfNeeded() { |
| 53 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); | 52 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); |
| 54 } | 53 } |
| 55 | 54 |
| 56 const char kExtensionHandlerUnzipError[] = | 55 const char kExtensionHandlerUnzipError[] = |
| 57 "Could not unzip extension for install."; | 56 "Could not unzip extension for install."; |
| 58 | 57 |
| 59 } // namespace | 58 } // namespace |
| 60 | 59 |
| 61 ExtensionsHandler::ExtensionsHandler() { | 60 ExtensionsHandler::ExtensionsHandler() { |
| 61 ExtensionsClient::Set(ChromeExtensionsClient::GetInstance()); | |
|
asargent_no_longer_on_chrome
2015/01/21 21:41:55
Note that we used to only do this inside OnUnpackE
| |
| 62 } | 62 } |
| 63 | 63 |
| 64 ExtensionsHandler::~ExtensionsHandler() { | 64 ExtensionsHandler::~ExtensionsHandler() { |
| 65 } | 65 } |
| 66 | 66 |
| 67 // static | 67 // static |
| 68 void ExtensionsHandler::PreSandboxStartup() { | 68 void ExtensionsHandler::PreSandboxStartup() { |
| 69 // Initialize libexif for image metadata parsing. | 69 // Initialize libexif for image metadata parsing. |
| 70 metadata::ImageMetadataExtractor::InitializeLibrary(); | 70 metadata::ImageMetadataExtractor::InitializeLibrary(); |
| 71 | 71 |
| 72 // Load media libraries for media file validation. | 72 // Load media libraries for media file validation. |
| 73 base::FilePath media_path; | 73 base::FilePath media_path; |
| 74 PathService::Get(content::DIR_MEDIA_LIBS, &media_path); | 74 PathService::Get(content::DIR_MEDIA_LIBS, &media_path); |
| 75 if (!media_path.empty()) | 75 if (!media_path.empty()) |
| 76 media::InitializeMediaLibrary(media_path); | 76 media::InitializeMediaLibrary(media_path); |
| 77 } | 77 } |
| 78 | 78 |
| 79 // static | |
| 80 void ExtensionsHandler::UtilityThreadStarted() { | |
| 81 UtilityHandler::UtilityThreadStarted(); | |
| 82 } | |
| 83 | |
| 84 bool ExtensionsHandler::OnMessageReceived(const IPC::Message& message) { | 79 bool ExtensionsHandler::OnMessageReceived(const IPC::Message& message) { |
| 85 bool handled = true; | 80 bool handled = true; |
| 86 IPC_BEGIN_MESSAGE_MAP(ExtensionsHandler, message) | 81 IPC_BEGIN_MESSAGE_MAP(ExtensionsHandler, message) |
| 87 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_UnpackExtension, OnUnpackExtension) | |
| 88 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_UnzipToDir, OnUnzipToDir) | 82 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_UnzipToDir, OnUnzipToDir) |
| 89 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImageBase64, OnDecodeImageBase64) | 83 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImageBase64, OnDecodeImageBase64) |
| 90 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_CheckMediaFile, OnCheckMediaFile) | 84 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_CheckMediaFile, OnCheckMediaFile) |
| 91 #if defined(OS_WIN) | 85 #if defined(OS_WIN) |
| 92 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseITunesPrefXml, | 86 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseITunesPrefXml, |
| 93 OnParseITunesPrefXml) | 87 OnParseITunesPrefXml) |
| 94 #endif // defined(OS_WIN) | 88 #endif // defined(OS_WIN) |
| 95 | 89 |
| 96 #if defined(OS_MACOSX) | 90 #if defined(OS_MACOSX) |
| 97 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseIPhotoLibraryXmlFile, | 91 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseIPhotoLibraryXmlFile, |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 110 #if defined(OS_WIN) | 104 #if defined(OS_WIN) |
| 111 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GetWiFiCredentials, | 105 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GetWiFiCredentials, |
| 112 OnGetWiFiCredentials) | 106 OnGetWiFiCredentials) |
| 113 #endif // defined(OS_WIN) | 107 #endif // defined(OS_WIN) |
| 114 | 108 |
| 115 IPC_MESSAGE_UNHANDLED(handled = false) | 109 IPC_MESSAGE_UNHANDLED(handled = false) |
| 116 IPC_END_MESSAGE_MAP() | 110 IPC_END_MESSAGE_MAP() |
| 117 return handled || utility_handler_.OnMessageReceived(message); | 111 return handled || utility_handler_.OnMessageReceived(message); |
| 118 } | 112 } |
| 119 | 113 |
| 120 void ExtensionsHandler::OnUnpackExtension( | |
| 121 const base::FilePath& extension_path, | |
| 122 const std::string& extension_id, | |
| 123 int location, | |
| 124 int creation_flags) { | |
| 125 CHECK_GT(location, Manifest::INVALID_LOCATION); | |
| 126 CHECK_LT(location, Manifest::NUM_LOCATIONS); | |
| 127 ExtensionsClient::Set(ChromeExtensionsClient::GetInstance()); | |
| 128 Unpacker unpacker(extension_path, | |
| 129 extension_id, | |
| 130 static_cast<Manifest::Location>(location), | |
| 131 creation_flags); | |
| 132 if (unpacker.Run() && unpacker.DumpImagesToFile() && | |
| 133 unpacker.DumpMessageCatalogsToFile()) { | |
| 134 Send(new ChromeUtilityHostMsg_UnpackExtension_Succeeded( | |
| 135 *unpacker.parsed_manifest())); | |
| 136 } else { | |
| 137 Send(new ChromeUtilityHostMsg_UnpackExtension_Failed( | |
| 138 unpacker.error_message())); | |
| 139 } | |
| 140 | |
| 141 ReleaseProcessIfNeeded(); | |
| 142 } | |
| 143 | |
| 144 void ExtensionsHandler::OnUnzipToDir(const base::FilePath& zip_path, | 114 void ExtensionsHandler::OnUnzipToDir(const base::FilePath& zip_path, |
| 145 const base::FilePath& dir) { | 115 const base::FilePath& dir) { |
| 146 if (!zip::Unzip(zip_path, dir)) { | 116 if (!zip::Unzip(zip_path, dir)) { |
| 147 Send(new ChromeUtilityHostMsg_UnzipToDir_Failed( | 117 Send(new ChromeUtilityHostMsg_UnzipToDir_Failed( |
| 148 std::string(kExtensionHandlerUnzipError))); | 118 std::string(kExtensionHandlerUnzipError))); |
| 149 } else { | 119 } else { |
| 150 Send(new ChromeUtilityHostMsg_UnzipToDir_Succeeded(dir)); | 120 Send(new ChromeUtilityHostMsg_UnzipToDir_Succeeded(dir)); |
| 151 } | 121 } |
| 152 | 122 |
| 153 ReleaseProcessIfNeeded(); | 123 ReleaseProcessIfNeeded(); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 256 | 226 |
| 257 std::string key_data; | 227 std::string key_data; |
| 258 std::string error; | 228 std::string error; |
| 259 wifi_service->GetKeyFromSystem(network_guid, &key_data, &error); | 229 wifi_service->GetKeyFromSystem(network_guid, &key_data, &error); |
| 260 | 230 |
| 261 Send(new ChromeUtilityHostMsg_GotWiFiCredentials(key_data, error.empty())); | 231 Send(new ChromeUtilityHostMsg_GotWiFiCredentials(key_data, error.empty())); |
| 262 } | 232 } |
| 263 #endif // defined(OS_WIN) | 233 #endif // defined(OS_WIN) |
| 264 | 234 |
| 265 } // namespace extensions | 235 } // namespace extensions |
| OLD | NEW |