diff options
author | asargent <asargent@chromium.org> | 2015-01-14 17:07:02 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-15 01:08:11 +0000 |
commit | 9156f029885bb4c54eeb5599a22b7aba0f7dbd3e (patch) | |
tree | bc232e28c29e03d0b3bd7fd145050c247128c732 | |
parent | f8346eaaa8271f81474f1daf9cc5fcb436d358ac (diff) | |
download | chromium_src-9156f029885bb4c54eeb5599a22b7aba0f7dbd3e.zip chromium_src-9156f029885bb4c54eeb5599a22b7aba0f7dbd3e.tar.gz chromium_src-9156f029885bb4c54eeb5599a22b7aba0f7dbd3e.tar.bz2 |
Refactoring: move extension unpacker from chrome/ to extensions/
This is mostly a series of mechanical changes to move
unpacker.{h,cc} from chrome/utility to extensions/utility.
The unpacker_unittests.cc and associated data files will be moved
in a follow-up CL to keep this one easy to review, because there
are a lot of test data files to move.
BUG=447014
Review URL: https://codereview.chromium.org/818943004
Cr-Commit-Position: refs/heads/master@{#311598}
-rw-r--r-- | chrome/app/generated_resources.grd | 12 | ||||
-rw-r--r-- | chrome/browser/extensions/sandboxed_unpacker.cc | 1 | ||||
-rw-r--r-- | chrome/chrome_utility.gypi | 2 | ||||
-rw-r--r-- | chrome/common/chrome_utility_messages.h | 7 | ||||
-rw-r--r-- | chrome/utility/extensions/extensions_handler.cc | 2 | ||||
-rw-r--r-- | chrome/utility/extensions/unpacker_unittest.cc | 2 | ||||
-rw-r--r-- | extensions/common/extension_utility_messages.h | 9 | ||||
-rw-r--r-- | extensions/extensions.gyp | 4 | ||||
-rw-r--r-- | extensions/extensions_strings.grd | 13 | ||||
-rw-r--r-- | extensions/utility/BUILD.gn | 3 | ||||
-rw-r--r-- | extensions/utility/DEPS | 3 | ||||
-rw-r--r-- | extensions/utility/unpacker.cc (renamed from chrome/utility/extensions/unpacker.cc) | 84 | ||||
-rw-r--r-- | extensions/utility/unpacker.h (renamed from chrome/utility/extensions/unpacker.h) | 10 |
13 files changed, 74 insertions, 78 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index efebc50..29ce598 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -4755,18 +4755,6 @@ Even if you have downloaded files from this website before, the website might ha <message name="IDS_EXTENSION_INSTALL_PROCESS_CRASHED" desc="Error message in case package fails to install because a utility process crashed."> Could not install package because a utility process crashed. Try restarting Chrome and trying again. </message> - <message name="IDS_EXTENSION_PACKAGE_DIRECTORY_ERROR" desc="Message for when an error occurs while trying to create the temporary directory needed to unzip a packaged extension or app."> - Could not create directory for unzipping: '<ph name="DIRECTORY_PATH">$1<ex>profile/Extensions/CRX_INSTALL</ex></ph>' - </message> - <message name="IDS_EXTENSION_PACKAGE_UNZIP_ERROR" desc="Message for when an error occurs while unzipping a packaged extension or app."> - Could not unzip extension - </message> - <message name="IDS_EXTENSION_PACKAGE_IMAGE_PATH_ERROR" desc="Error message for when a packaged extension or app contains a reference to an image that could be outside the package."> - Illegal path (absolute or relative with '..'): '<ph name="IMAGE_PATH">$1<ex>../image.png</ex></ph>' - </message> - <message name="IDS_EXTENSION_PACKAGE_IMAGE_ERROR" desc="Message for when an error occurs while trying to decode an image found within a packaged extension or app."> - Could not decode image: '<ph name="IMAGE_NAME">$1<ex>image.png</ex></ph>' - </message> <!-- Extension installed bubble --> <message name="IDS_EXTENSION_BUNDLE_INSTALLED_HEADING_EXTENSIONS" desc="First line in the content area of the extension bundle installed bubble. Instructs which extensions were installed."> diff --git a/chrome/browser/extensions/sandboxed_unpacker.cc b/chrome/browser/extensions/sandboxed_unpacker.cc index b2c6a3b..f01e584 100644 --- a/chrome/browser/extensions/sandboxed_unpacker.cc +++ b/chrome/browser/extensions/sandboxed_unpacker.cc @@ -36,6 +36,7 @@ #include "extensions/common/constants.h" #include "extensions/common/extension.h" #include "extensions/common/extension_l10n_util.h" +#include "extensions/common/extension_utility_messages.h" #include "extensions/common/extensions_client.h" #include "extensions/common/file_util.h" #include "extensions/common/manifest_constants.h" diff --git a/chrome/chrome_utility.gypi b/chrome/chrome_utility.gypi index 4501b8d..55c691e 100644 --- a/chrome/chrome_utility.gypi +++ b/chrome/chrome_utility.gypi @@ -26,8 +26,6 @@ 'chrome_utility_extensions_sources': [ 'utility/extensions/extensions_handler.cc', 'utility/extensions/extensions_handler.h', - 'utility/extensions/unpacker.cc', - 'utility/extensions/unpacker.h', 'utility/image_writer/disk_unmounter_mac.cc', 'utility/image_writer/disk_unmounter_mac.h', 'utility/image_writer/error_messages.cc', diff --git a/chrome/common/chrome_utility_messages.h b/chrome/common/chrome_utility_messages.h index a30163c..7744841 100644 --- a/chrome/common/chrome_utility_messages.h +++ b/chrome/common/chrome_utility_messages.h @@ -23,13 +23,6 @@ #define IPC_MESSAGE_START ChromeUtilityMsgStart -#ifndef CHROME_COMMON_CHROME_UTILITY_MESSAGES_H_ -#define CHROME_COMMON_CHROME_UTILITY_MESSAGES_H_ - -typedef std::vector<Tuple<SkBitmap, base::FilePath>> DecodedImages; - -#endif // CHROME_COMMON_CHROME_UTILITY_MESSAGES_H_ - #if defined(FULL_SAFE_BROWSING) IPC_STRUCT_TRAITS_BEGIN(safe_browsing::zip_analyzer::Results) IPC_STRUCT_TRAITS_MEMBER(success) diff --git a/chrome/utility/extensions/extensions_handler.cc b/chrome/utility/extensions/extensions_handler.cc index 254e9c5..06d83c0 100644 --- a/chrome/utility/extensions/extensions_handler.cc +++ b/chrome/utility/extensions/extensions_handler.cc @@ -11,7 +11,6 @@ #include "chrome/common/extensions/chrome_utility_extensions_messages.h" #include "chrome/common/media_galleries/metadata_types.h" #include "chrome/utility/chrome_content_utility_client.h" -#include "chrome/utility/extensions/unpacker.h" #include "chrome/utility/media_galleries/image_metadata_extractor.h" #include "content/public/common/content_paths.h" #include "content/public/utility/utility_thread.h" @@ -19,6 +18,7 @@ #include "extensions/common/extension_l10n_util.h" #include "extensions/common/extension_utility_messages.h" #include "extensions/common/manifest.h" +#include "extensions/utility/unpacker.h" #include "media/base/media.h" #include "media/base/media_file_checker.h" #include "third_party/zlib/google/zip.h" diff --git a/chrome/utility/extensions/unpacker_unittest.cc b/chrome/utility/extensions/unpacker_unittest.cc index 21e1bb6..bc5e590 100644 --- a/chrome/utility/extensions/unpacker_unittest.cc +++ b/chrome/utility/extensions/unpacker_unittest.cc @@ -9,10 +9,10 @@ #include "base/strings/utf_string_conversions.h" #include "base/values.h" #include "chrome/common/chrome_paths.h" -#include "chrome/utility/extensions/unpacker.h" #include "extensions/common/constants.h" #include "extensions/common/extension.h" #include "extensions/common/manifest_constants.h" +#include "extensions/utility/unpacker.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkBitmap.h" diff --git a/extensions/common/extension_utility_messages.h b/extensions/common/extension_utility_messages.h index 77dfe13..123fc98 100644 --- a/extensions/common/extension_utility_messages.h +++ b/extensions/common/extension_utility_messages.h @@ -8,9 +8,18 @@ #include "extensions/common/update_manifest.h" #include "ipc/ipc_message_macros.h" +#include "third_party/skia/include/core/SkBitmap.h" +#include "ui/gfx/ipc/gfx_param_traits.h" #define IPC_MESSAGE_START ExtensionUtilityMsgStart +#ifndef EXTENSIONS_COMMON_EXTENSION_UTILITY_MESSAGES_H_ +#define EXTENSIONS_COMMON_EXTENSION_UTILITY_MESSAGES_H_ + +typedef std::vector<Tuple<SkBitmap, base::FilePath>> DecodedImages; + +#endif // EXTENSIONS_COMMON_EXTENSION_UTILITY_MESSAGES_H_ + IPC_STRUCT_TRAITS_BEGIN(UpdateManifest::Result) IPC_STRUCT_TRAITS_MEMBER(extension_id) IPC_STRUCT_TRAITS_MEMBER(version) diff --git a/extensions/extensions.gyp b/extensions/extensions.gyp index 47a19b4..4306d35 100644 --- a/extensions/extensions.gyp +++ b/extensions/extensions.gyp @@ -1031,12 +1031,15 @@ 'type': 'static_library', 'dependencies': [ '../content/content.gyp:content_utility', + '../third_party/zlib/google/zip.gyp:zip', 'extensions_common', ], 'include_dirs': [ '..', ], 'sources': [ + 'utility/unpacker.cc', + 'utility/unpacker.h', 'utility/utility_handler.cc', 'utility/utility_handler.h', ], @@ -1185,6 +1188,7 @@ 'extensions_shell_and_test_pak', 'extensions_strings.gyp:extensions_strings', 'extensions_test_support', + 'extensions_utility', ], # Needed for third_party libraries like leveldb. 'include_dirs': [ diff --git a/extensions/extensions_strings.grd b/extensions/extensions_strings.grd index 7ef88d3..e4ab2c4 100644 --- a/extensions/extensions_strings.grd +++ b/extensions/extensions_strings.grd @@ -210,6 +210,19 @@ <message name="IDS_EXTENSION_MANIFEST_INVALID" desc=""> Manifest file is invalid. </message> + <message name="IDS_EXTENSION_PACKAGE_DIRECTORY_ERROR" desc="Message for when an error occurs while trying to create the temporary directory needed to unzip a packaged extension or app."> + Could not create directory for unzipping: '<ph name="DIRECTORY_PATH">$1<ex>profile/Extensions/CRX_INSTALL</ex></ph>' + </message> + <message name="IDS_EXTENSION_PACKAGE_IMAGE_PATH_ERROR" desc="Error message for when a packaged extension or app contains a reference to an image that could be outside the package."> + Illegal path (absolute or relative with '..'): '<ph name="IMAGE_PATH">$1<ex>../image.png</ex></ph>' + </message> + <message name="IDS_EXTENSION_PACKAGE_IMAGE_ERROR" desc="Message for when an error occurs while trying to decode an image found within a packaged extension or app."> + Could not decode image: '<ph name="IMAGE_NAME">$1<ex>image.png</ex></ph>' + </message> + <message name="IDS_EXTENSION_PACKAGE_UNZIP_ERROR" desc="Message for when an error occurs while unzipping a packaged extension or app."> + Could not unzip extension + </message> + <message name="IDS_EXTENSION_PROMPT_WARNING_CLIPBOARD" desc="Permission string for access to clipboard."> Read data you copy and paste </message> diff --git a/extensions/utility/BUILD.gn b/extensions/utility/BUILD.gn index a88421c..c954746 100644 --- a/extensions/utility/BUILD.gn +++ b/extensions/utility/BUILD.gn @@ -9,6 +9,8 @@ assert(enable_extensions) # GYP version: extensions/extensions.gyp:extensions_utility source_set("utility") { sources = [ + "unpacker.cc", + "unpacker.h", "utility_handler.cc", "utility_handler.h", ] @@ -16,6 +18,7 @@ source_set("utility") { deps = [ "//content/public/utility", "//extensions/common", + "//skia", ] if (is_win) { diff --git a/extensions/utility/DEPS b/extensions/utility/DEPS index 8ad521e..48d2f8d 100644 --- a/extensions/utility/DEPS +++ b/extensions/utility/DEPS @@ -1,3 +1,6 @@ include_rules = [ "+content/public/utility", + "+content/public/child", + "+net", + "+third_party/zlib/google", ] diff --git a/chrome/utility/extensions/unpacker.cc b/extensions/utility/unpacker.cc index ba82e59..d244ba5 100644 --- a/chrome/utility/extensions/unpacker.cc +++ b/extensions/utility/unpacker.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/utility/extensions/unpacker.h" +#include "extensions/utility/unpacker.h" #include <set> @@ -16,18 +16,18 @@ #include "base/strings/utf_string_conversions.h" #include "base/threading/thread.h" #include "base/values.h" -#include "chrome/common/chrome_utility_messages.h" -#include "chrome/grit/generated_resources.h" #include "content/public/child/image_decoder_utils.h" #include "content/public/common/common_param_traits.h" #include "extensions/common/constants.h" #include "extensions/common/extension.h" #include "extensions/common/extension_l10n_util.h" +#include "extensions/common/extension_utility_messages.h" #include "extensions/common/extensions_client.h" #include "extensions/common/file_util.h" #include "extensions/common/manifest.h" #include "extensions/common/manifest_constants.h" #include "extensions/common/manifest_handlers/default_locale_handler.h" +#include "extensions/strings/grit/extensions_strings.h" #include "ipc/ipc_message_utils.h" #include "net/base/file_stream.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -56,9 +56,8 @@ SkBitmap DecodeImage(const base::FilePath& path) { // Decode the image using WebKit's image decoder. const unsigned char* data = reinterpret_cast<const unsigned char*>(file_contents.data()); - SkBitmap bitmap = content::DecodeImage(data, - gfx::Size(), - file_contents.length()); + SkBitmap bitmap = + content::DecodeImage(data, gfx::Size(), file_contents.length()); if (bitmap.computeSize64() > kMaxImageCanvas) return SkBitmap(); return bitmap; @@ -71,11 +70,11 @@ bool PathContainsParentDirectory(const base::FilePath& path) { const size_t npos = base::FilePath::StringType::npos; const base::FilePath::StringType& value = path.value(); - for (size_t i = 0; i < value.length(); ) { + for (size_t i = 0; i < value.length();) { i = value.find(kParentDirectory, i); if (i != npos) { - if ((i == 0 || kSeparators.find(value[i-1]) == npos) && - (i+1 < value.length() || kSeparators.find(value[i+1]) == npos)) { + if ((i == 0 || kSeparators.find(value[i - 1]) == npos) && + (i + 1 < value.length() || kSeparators.find(value[i + 1]) == npos)) { return true; } ++i; @@ -113,8 +112,7 @@ Unpacker::~Unpacker() { } base::DictionaryValue* Unpacker::ReadManifest() { - base::FilePath manifest_path = - temp_install_dir_.Append(kManifestFilename); + base::FilePath manifest_path = temp_install_dir_.Append(kManifestFilename); if (!base::PathExists(manifest_path)) { SetError(errors::kInvalidManifest); return NULL; @@ -137,12 +135,10 @@ base::DictionaryValue* Unpacker::ReadManifest() { } bool Unpacker::ReadAllMessageCatalogs(const std::string& default_locale) { - base::FilePath locales_path = - temp_install_dir_.Append(kLocaleFolder); + base::FilePath locales_path = temp_install_dir_.Append(kLocaleFolder); // Not all folders under _locales have to be valid locales. - base::FileEnumerator locales(locales_path, - false, + base::FileEnumerator locales(locales_path, false, base::FileEnumerator::DIRECTORIES); std::set<std::string> all_locales; @@ -166,15 +162,13 @@ bool Unpacker::Run() { DVLOG(1) << "Installing extension " << extension_path_.value(); // <profile>/Extensions/CRX_INSTALL - temp_install_dir_ = - extension_path_.DirName().AppendASCII(kTempExtensionName); + temp_install_dir_ = extension_path_.DirName().AppendASCII(kTempExtensionName); if (!base::CreateDirectory(temp_install_dir_)) { - SetUTF16Error( - l10n_util::GetStringFUTF16( - IDS_EXTENSION_PACKAGE_DIRECTORY_ERROR, - base::i18n::GetDisplayStringInLTRDirectionality( - temp_install_dir_.LossyDisplayName()))); + SetUTF16Error(l10n_util::GetStringFUTF16( + IDS_EXTENSION_PACKAGE_DIRECTORY_ERROR, + base::i18n::GetDisplayStringInLTRDirectionality( + temp_install_dir_.LossyDisplayName()))); return false; } @@ -189,13 +183,9 @@ bool Unpacker::Run() { return false; // Error was already reported. std::string error; - scoped_refptr<Extension> extension(Extension::Create( - temp_install_dir_, - location_, - *parsed_manifest_, - creation_flags_, - extension_id_, - &error)); + scoped_refptr<Extension> extension( + Extension::Create(temp_install_dir_, location_, *parsed_manifest_, + creation_flags_, extension_id_, &error)); if (!extension.get()) { SetError(error); return false; @@ -212,8 +202,7 @@ bool Unpacker::Run() { std::set<base::FilePath> image_paths = ExtensionsClient::Get()->GetBrowserImagePaths(extension.get()); for (std::set<base::FilePath>::iterator it = image_paths.begin(); - it != image_paths.end(); - ++it) { + it != image_paths.end(); ++it) { if (!AddDecodedImage(*it)) return false; // Error was already reported. } @@ -232,8 +221,8 @@ bool Unpacker::DumpImagesToFile() { IPC::Message pickle; // We use a Message so we can use WriteParam. IPC::WriteParam(&pickle, internal_data_->decoded_images); - base::FilePath path = extension_path_.DirName().AppendASCII( - kDecodedImagesFilename); + base::FilePath path = + extension_path_.DirName().AppendASCII(kDecodedImagesFilename); if (!WritePickle(pickle, path)) { SetError("Could not write image data to disk."); return false; @@ -246,8 +235,8 @@ bool Unpacker::DumpMessageCatalogsToFile() { IPC::Message pickle; IPC::WriteParam(&pickle, *parsed_catalogs_.get()); - base::FilePath path = extension_path_.DirName().AppendASCII( - kDecodedMessageCatalogsFilename); + base::FilePath path = + extension_path_.DirName().AppendASCII(kDecodedMessageCatalogsFilename); if (!WritePickle(pickle, path)) { SetError("Could not write message catalogs to disk."); return false; @@ -259,21 +248,19 @@ bool Unpacker::DumpMessageCatalogsToFile() { bool Unpacker::AddDecodedImage(const base::FilePath& path) { // Make sure it's not referencing a file outside the extension's subdir. if (path.IsAbsolute() || PathContainsParentDirectory(path)) { - SetUTF16Error( - l10n_util::GetStringFUTF16( - IDS_EXTENSION_PACKAGE_IMAGE_PATH_ERROR, - base::i18n::GetDisplayStringInLTRDirectionality( - path.LossyDisplayName()))); + SetUTF16Error(l10n_util::GetStringFUTF16( + IDS_EXTENSION_PACKAGE_IMAGE_PATH_ERROR, + base::i18n::GetDisplayStringInLTRDirectionality( + path.LossyDisplayName()))); return false; } SkBitmap image_bitmap = DecodeImage(temp_install_dir_.Append(path)); if (image_bitmap.isNull()) { - SetUTF16Error( - l10n_util::GetStringFUTF16( - IDS_EXTENSION_PACKAGE_IMAGE_ERROR, - base::i18n::GetDisplayStringInLTRDirectionality( - path.BaseName().LossyDisplayName()))); + SetUTF16Error(l10n_util::GetStringFUTF16( + IDS_EXTENSION_PACKAGE_IMAGE_ERROR, + base::i18n::GetDisplayStringInLTRDirectionality( + path.BaseName().LossyDisplayName()))); return false; } @@ -293,9 +280,8 @@ bool Unpacker::ReadMessageCatalog(const base::FilePath& message_path) { SetError(base::StringPrintf("%s %s", errors::kLocalesMessagesFileMissing, base::UTF16ToUTF8(messages_file).c_str())); } else { - SetError(base::StringPrintf("%s: %s", - base::UTF16ToUTF8(messages_file).c_str(), - error.c_str())); + SetError(base::StringPrintf( + "%s: %s", base::UTF16ToUTF8(messages_file).c_str(), error.c_str())); } return false; } @@ -317,7 +303,7 @@ bool Unpacker::ReadMessageCatalog(const base::FilePath& message_path) { return true; } -void Unpacker::SetError(const std::string &error) { +void Unpacker::SetError(const std::string& error) { SetUTF16Error(base::UTF8ToUTF16(error)); } diff --git a/chrome/utility/extensions/unpacker.h b/extensions/utility/unpacker.h index 8d44b1b..240172e 100644 --- a/chrome/utility/extensions/unpacker.h +++ b/extensions/utility/unpacker.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_UTILITY_EXTENSIONS_UNPACKER_H_ -#define CHROME_UTILITY_EXTENSIONS_UNPACKER_H_ +#ifndef EXTENSIONS_UTILITY_UNPACKER_H_ +#define EXTENSIONS_UTILITY_UNPACKER_H_ #include <string> #include <vector> @@ -47,9 +47,7 @@ class Unpacker { bool DumpMessageCatalogsToFile(); const base::string16& error_message() { return error_message_; } - base::DictionaryValue* parsed_manifest() { - return parsed_manifest_.get(); - } + base::DictionaryValue* parsed_manifest() { return parsed_manifest_.get(); } base::DictionaryValue* parsed_catalogs() { return parsed_catalogs_.get(); } private: @@ -107,4 +105,4 @@ class Unpacker { } // namespace extensions -#endif // CHROME_UTILITY_EXTENSIONS_UNPACKER_H_ +#endif // EXTENSIONS_UTILITY_UNPACKER_H_ |