Skip to content

Commit

Permalink
Move sandboxed_unpacker.{h,cc} from chrome/ to extensions/
Browse files Browse the repository at this point in the history
This is a mostly mechanical change to move these files over, and
make corresponding changes to strings, build files, and include paths.

BUG=447014

Review URL: https://codereview.chromium.org/864093002

Cr-Commit-Position: refs/heads/master@{#313404}
  • Loading branch information
asargent authored and Commit bot committed Jan 27, 2015
1 parent 151e70d commit 275faaa
Show file tree
Hide file tree
Showing 30 changed files with 325 additions and 305 deletions.
22 changes: 0 additions & 22 deletions chrome/app/generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -4742,28 +4742,6 @@ Even if you have downloaded files from this website before, the website might ha
<message name="IDS_EXTENSION_LOAD_ICON_FOR_BROWSER_ACTION_FAILED" desc="">
Could not load icon '<ph name="ICON">$1<ex>icon.png</ex></ph>' for browser action.
</message>
<if expr="is_win">
<message name="IDS_EXTENSION_UNPACK_FAILED" desc="On windows, it is possible to mount a disk without the root of that disk having a drive letter. The sandbox does not support this. See crbug/49530 .">
Can not unpack extension. To safely unpack an extension, there must be a path to your profile directory that starts with a drive letter and does not contain a junction, mount point, or symlink. No such path exists for your profile.
</message>
</if>
<if expr="not is_win">
<message name="IDS_EXTENSION_UNPACK_FAILED" desc="">
Can not unpack extension. To safely unpack an extension, there must be a path to your profile directory that does not contain a symlink. No such path exists for your profile.
</message>
</if>
<message name="IDS_EXTENSION_PACKAGE_ERROR_MESSAGE" desc="The cases where we get an error message string back from some other component. The message might be in English, but these are typically developer errors, and the extension SDK is English.">
Package is invalid. Details: '<ph name="ERROR_MESSAGE">$1<ex>error</ex></ph>'.
</message>
<message name="IDS_EXTENSION_PACKAGE_ERROR_CODE" desc="Error message in cases where we fail to install the extension because the crx file is invalid. For example, because the crx header or signature is invalid.">
Package is invalid: '<ph name="ERROR_CODE">$1<ex>error</ex></ph>'.
</message>
<message name="IDS_EXTENSION_PACKAGE_INSTALL_ERROR" desc="Error message in case package fails to install because of some problem with the filesystem.">
Could not install package: '<ph name="ERROR_CODE">$1<ex>error</ex></ph>'
</message>
<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>

<!-- 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.">
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/chromeos/app_mode/kiosk_app_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
#include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/sandboxed_unpacker.h"
#include "chrome/browser/extensions/webstore_data_fetcher.h"
#include "chrome/browser/extensions/webstore_install_helper.h"
#include "chrome/browser/image_decoder.h"
#include "chrome/browser/profiles/profile.h"
#include "content/public/browser/browser_thread.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/image_loader.h"
#include "extensions/browser/sandboxed_unpacker.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension_urls.h"
#include "extensions/common/manifest.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "base/files/file_path.h"
#include "base/memory/weak_ptr.h"
#include "base/sequenced_task_runner.h"
#include "chrome/browser/extensions/sandboxed_unpacker.h"
#include "extensions/browser/sandboxed_unpacker.h"

namespace extensions {
class Extension;
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/chromeos/app_mode/kiosk_external_updater.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
#include "base/version.h"
#include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
#include "chrome/browser/chromeos/ui/kiosk_external_update_notification.h"
#include "chrome/browser/extensions/sandboxed_unpacker.h"
#include "chrome/common/chrome_version_info.h"
#include "content/public/browser/browser_thread.h"
#include "extensions/browser/sandboxed_unpacker.h"
#include "extensions/common/extension.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
Expand Down
3 changes: 1 addition & 2 deletions chrome/browser/extensions/crx_installer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/version.h"
#include "chrome/browser/extensions/blacklist.h"
#include "chrome/browser/extensions/extension_install_checker.h"
#include "chrome/browser/extensions/extension_install_prompt.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/sandboxed_unpacker.h"
#include "chrome/browser/extensions/webstore_installer.h"
#include "chrome/common/extensions/extension_constants.h"
#include "extensions/browser/install_flag.h"
#include "extensions/browser/sandboxed_unpacker.h"
#include "extensions/common/extension.h"
#include "extensions/common/manifest.h"
#include "sync/api/string_ordinal.h"
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/extensions/startup_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/sandboxed_unpacker.h"
#include "chrome/browser/extensions/webstore_startup_installer.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/chrome_extensions_client.h"
#include "components/crx_file/id_util.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/sandboxed_unpacker.h"
#include "extensions/common/extension.h"
#include "ipc/ipc_message.h"

Expand Down Expand Up @@ -298,7 +298,7 @@ void AppInstallHelper::OnAppInstallComplete(bool success,
const std::string& error,
webstore_install::Result result) {
success_ = success;
error_= error;
error_ = error;
done_callback_.Run();
}

Expand Down
2 changes: 0 additions & 2 deletions chrome/chrome_browser_extensions.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -755,8 +755,6 @@
'browser/extensions/proxy_overridden_bubble_controller.h',
'browser/extensions/requirements_checker.cc',
'browser/extensions/requirements_checker.h',
'browser/extensions/sandboxed_unpacker.cc',
'browser/extensions/sandboxed_unpacker.h',
'browser/extensions/settings_api_bubble_controller.cc',
'browser/extensions/settings_api_bubble_controller.h',
'browser/extensions/settings_api_helpers.cc',
Expand Down
1 change: 0 additions & 1 deletion chrome/chrome_tests_unit.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,6 @@
'browser/extensions/permission_messages_unittest.cc',
'browser/extensions/permissions_based_management_policy_provider_unittest.cc',
'browser/extensions/permissions_updater_unittest.cc',
'browser/extensions/sandboxed_unpacker_unittest.cc',
'browser/extensions/shared_module_service_unittest.cc',
'browser/extensions/standard_management_policy_provider_unittest.cc',
'browser/extensions/token_cache/token_cache_service_unittest.cc',
Expand Down
23 changes: 0 additions & 23 deletions chrome/common/extensions/chrome_utility_extensions_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,6 @@ IPC_STRUCT_TRAITS_END()
// Utility process messages:
// These are messages from the browser to the utility process.

// Tells the utility process to unpack the given extension file in its
// directory and verify that it is valid.
IPC_MESSAGE_CONTROL4(ChromeUtilityMsg_UnpackExtension,
base::FilePath /* extension_filename */,
std::string /* extension_id */,
int /* Manifest::Location */,
int /* InitFromValue flags */)

IPC_MESSAGE_CONTROL2(ChromeUtilityMsg_UnzipToDir,
base::FilePath /* zip_file */,
base::FilePath /* dir */)
Expand Down Expand Up @@ -162,21 +154,6 @@ IPC_MESSAGE_CONTROL0(ChromeUtilityMsg_ImageWriter_Cancel)
// Utility process host messages:
// These are messages from the utility process to the browser.

// Reply when the utility process is done unpacking an extension. |manifest|
// is the parsed manifest.json file.
// The unpacker should also have written out files containing the decoded
// images and message catalogs from the extension. The data is written into a
// DecodedImages struct into a file named kDecodedImagesFilename in the
// directory that was passed in. This is done because the data is too large to
// pass over IPC.
IPC_MESSAGE_CONTROL1(ChromeUtilityHostMsg_UnpackExtension_Succeeded,
base::DictionaryValue /* manifest */)

// Reply when the utility process has failed while unpacking an extension.
// |error_message| is a user-displayable explanation of what went wrong.
IPC_MESSAGE_CONTROL1(ChromeUtilityHostMsg_UnpackExtension_Failed,
base::string16 /* error_message, if any */)

// Reply when the utility process is done unzipping a file. |unpacked_path|
// is the directory which contains the unzipped contents.
IPC_MESSAGE_CONTROL1(ChromeUtilityHostMsg_UnzipToDir_Succeeded,
Expand Down
2 changes: 1 addition & 1 deletion chrome/utility/chrome_content_utility_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ ChromeContentUtilityClient::~ChromeContentUtilityClient() {

void ChromeContentUtilityClient::UtilityThreadStarted() {
#if defined(ENABLE_EXTENSIONS)
extensions::ExtensionsHandler::UtilityThreadStarted();
extensions::UtilityHandler::UtilityThreadStarted();
#endif

if (kMessageWhitelistSize > 0) {
Expand Down
32 changes: 1 addition & 31 deletions chrome/utility/extensions/extensions_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "extensions/common/extension.h"
#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"
Expand Down Expand Up @@ -59,6 +58,7 @@ const char kExtensionHandlerUnzipError[] =
} // namespace

ExtensionsHandler::ExtensionsHandler() {
ExtensionsClient::Set(ChromeExtensionsClient::GetInstance());
}

ExtensionsHandler::~ExtensionsHandler() {
Expand All @@ -76,15 +76,9 @@ void ExtensionsHandler::PreSandboxStartup() {
media::InitializeMediaLibrary(media_path);
}

// static
void ExtensionsHandler::UtilityThreadStarted() {
UtilityHandler::UtilityThreadStarted();
}

bool ExtensionsHandler::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(ExtensionsHandler, message)
IPC_MESSAGE_HANDLER(ChromeUtilityMsg_UnpackExtension, OnUnpackExtension)
IPC_MESSAGE_HANDLER(ChromeUtilityMsg_UnzipToDir, OnUnzipToDir)
IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImageBase64, OnDecodeImageBase64)
IPC_MESSAGE_HANDLER(ChromeUtilityMsg_CheckMediaFile, OnCheckMediaFile)
Expand Down Expand Up @@ -117,30 +111,6 @@ bool ExtensionsHandler::OnMessageReceived(const IPC::Message& message) {
return handled || utility_handler_.OnMessageReceived(message);
}

void ExtensionsHandler::OnUnpackExtension(
const base::FilePath& extension_path,
const std::string& extension_id,
int location,
int creation_flags) {
CHECK_GT(location, Manifest::INVALID_LOCATION);
CHECK_LT(location, Manifest::NUM_LOCATIONS);
ExtensionsClient::Set(ChromeExtensionsClient::GetInstance());
Unpacker unpacker(extension_path,
extension_id,
static_cast<Manifest::Location>(location),
creation_flags);
if (unpacker.Run() && unpacker.DumpImagesToFile() &&
unpacker.DumpMessageCatalogsToFile()) {
Send(new ChromeUtilityHostMsg_UnpackExtension_Succeeded(
*unpacker.parsed_manifest()));
} else {
Send(new ChromeUtilityHostMsg_UnpackExtension_Failed(
unpacker.error_message()));
}

ReleaseProcessIfNeeded();
}

void ExtensionsHandler::OnUnzipToDir(const base::FilePath& zip_path,
const base::FilePath& dir) {
if (!zip::Unzip(zip_path, dir)) {
Expand Down
4 changes: 0 additions & 4 deletions chrome/utility/extensions/extensions_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,12 @@ class ExtensionsHandler : public UtilityMessageHandler {
~ExtensionsHandler() override;

static void PreSandboxStartup();
static void UtilityThreadStarted();

// UtilityMessageHandler:
bool OnMessageReceived(const IPC::Message& message) override;

private:
// IPC message handlers.
void OnUnpackExtension(const base::FilePath& extension_path,
const std::string& extension_id,
int location, int creation_flags);
void OnUnzipToDir(const base::FilePath& zip_path, const base::FilePath& dir);
void OnDecodeImageBase64(const std::string& encoded_data);
void OnCheckMediaFile(int64 milliseconds_of_decoding,
Expand Down
3 changes: 3 additions & 0 deletions extensions/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ source_set("test_support") {
"test/extension_test_message_listener.h",
"test/result_catcher.cc",
"test/result_catcher.h",
"test/test_content_utility_client.cc",
"test/test_content_utility_client.h",
"test/test_extensions_client.cc",
"test/test_extensions_client.h",
"test/test_permission_message_provider.cc",
Expand Down Expand Up @@ -212,6 +214,7 @@ if (false) {
"browser/process_map_unittest.cc",
"browser/quota_service_unittest.cc",
"browser/runtime_data_unittest.cc",
"browser/sandboxed_unpacker_unittest.cc",
"browser/value_store/leveldb_value_store_unittest.cc",
"browser/value_store/testing_value_store_unittest.cc",
"browser/value_store/value_store_change_unittest.cc",
Expand Down
2 changes: 1 addition & 1 deletion extensions/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ include_rules = [
"+extensions/test",
"+grit/extensions_renderer_resources.h",
"+grit/extensions_resources.h",
"+testing",
"+third_party/mojo/src/mojo/public",
"+third_party/skia/include",
"+testing",

# Minimal UI dependencies. There are two good rules for UI dependencies here:
#
Expand Down
2 changes: 2 additions & 0 deletions extensions/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,8 @@ source_set("browser") {
"renderer_startup_helper.h",
"runtime_data.cc",
"runtime_data.h",
"sandboxed_unpacker.cc",
"sandboxed_unpacker.h",
"script_execution_observer.h",
"script_executor.cc",
"script_executor.h",
Expand Down
4 changes: 4 additions & 0 deletions extensions/browser/extensions_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "content/public/common/content_client.h"
#include "content/public/test/test_browser_context.h"
#include "extensions/browser/test_extensions_browser_client.h"
#include "extensions/test/test_content_utility_client.h"

namespace extensions {

Expand All @@ -22,18 +23,21 @@ namespace extensions {
// };
ExtensionsTest::ExtensionsTest()
: content_client_(new content::ContentClient),
content_utility_client_(new TestContentUtilityClient),
content_browser_client_(new content::ContentBrowserClient),
browser_context_(new content::TestBrowserContext),
extensions_browser_client_(
new TestExtensionsBrowserClient(browser_context_.get())) {
content::SetContentClient(content_client_.get());
content::SetUtilityClientForTesting(content_utility_client_.get());
content::SetBrowserClientForTesting(content_browser_client_.get());
ExtensionsBrowserClient::Set(extensions_browser_client_.get());
}

ExtensionsTest::~ExtensionsTest() {
ExtensionsBrowserClient::Set(NULL);
content::SetBrowserClientForTesting(NULL);
content::SetUtilityClientForTesting(NULL);
content::SetContentClient(NULL);
}

Expand Down
4 changes: 3 additions & 1 deletion extensions/browser/extensions_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@

namespace content {
class BrowserContext;
class ContentClient;
class ContentBrowserClient;
class ContentClient;
class ContentUtilityClient;
}

namespace extensions {
Expand Down Expand Up @@ -49,6 +50,7 @@ class ExtensionsTest : public testing::Test {
private:
// TODO(yoz): Add a NotificationService here; it's used widely enough.
scoped_ptr<content::ContentClient> content_client_;
scoped_ptr<content::ContentUtilityClient> content_utility_client_;
scoped_ptr<content::ContentBrowserClient> content_browser_client_;
scoped_ptr<content::BrowserContext> browser_context_;
scoped_ptr<TestExtensionsBrowserClient> extensions_browser_client_;
Expand Down
Loading

0 comments on commit 275faaa

Please sign in to comment.