diff options
author | rockot <rockot@chromium.org> | 2014-09-24 13:31:53 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-24 20:32:06 +0000 |
commit | eb6d47fab5dc127b474363d488aa1b6ccbfa7b48 (patch) | |
tree | 76d490eece9de85345c3c1cf31e5a6f8fb9e24dc /extensions | |
parent | 1b241325584a8612ff035c809ecfdeefa08063c5 (diff) | |
download | chromium_src-eb6d47fab5dc127b474363d488aa1b6ccbfa7b48.zip chromium_src-eb6d47fab5dc127b474363d488aa1b6ccbfa7b48.tar.gz chromium_src-eb6d47fab5dc127b474363d488aa1b6ccbfa7b48.tar.bz2 |
Move SafeManifestParser to //extensions
This moves SafeManifestParser to extensions_browser.
Also creates a new ExtensionUtility IPC message class in which
to define extensions utility process messages. The relevant
manifest parsing messages have been moved into this class.
BUG=398671
Review URL: https://codereview.chromium.org/464613002
Cr-Commit-Position: refs/heads/master@{#296508}
Diffstat (limited to 'extensions')
-rw-r--r-- | extensions/browser/BUILD.gn | 4 | ||||
-rw-r--r-- | extensions/browser/updater/safe_manifest_parser.cc | 79 | ||||
-rw-r--r-- | extensions/browser/updater/safe_manifest_parser.h | 58 | ||||
-rw-r--r-- | extensions/common/extension_message_generator.h | 1 | ||||
-rw-r--r-- | extensions/common/extension_utility_messages.h | 47 | ||||
-rw-r--r-- | extensions/extensions.gyp | 3 |
6 files changed, 191 insertions, 1 deletions
diff --git a/extensions/browser/BUILD.gn b/extensions/browser/BUILD.gn index e3f01ed..e71d5f5 100644 --- a/extensions/browser/BUILD.gn +++ b/extensions/browser/BUILD.gn @@ -346,7 +346,7 @@ source_set("browser") { "guest_view/app_view/app_view_guest_delegate.cc", "guest_view/app_view/app_view_guest_delegate.h", "guest_view/extension_options/extension_options_constants.cc", - "guest_view/extension_options/extension_options_constants.h", + "guest_view/extension_options/extension_options_constants.h", "guest_view/extension_options/extension_options_guest.cc", "guest_view/extension_options/extension_options_guest.h", "guest_view/extension_options/extension_options_guest_delegate.cc", @@ -418,6 +418,8 @@ source_set("browser") { "update_observer.h", "updater/manifest_fetch_data.cc", "updater/manifest_fetch_data.h", + "updater/safe_manifest_parser.cc", + "updater/safe_manifest_parser.h", "url_request_util.cc", "url_request_util.h", "value_store/leveldb_value_store.cc", diff --git a/extensions/browser/updater/safe_manifest_parser.cc b/extensions/browser/updater/safe_manifest_parser.cc new file mode 100644 index 0000000..2ab9a05 --- /dev/null +++ b/extensions/browser/updater/safe_manifest_parser.cc @@ -0,0 +1,79 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "extensions/browser/updater/safe_manifest_parser.h" + +#include "base/bind.h" +#include "base/command_line.h" +#include "base/location.h" +#include "base/logging.h" +#include "content/public/browser/browser_thread.h" +#include "content/public/browser/utility_process_host.h" +#include "content/public/common/content_switches.h" +#include "extensions/common/extension_utility_messages.h" +#include "ipc/ipc_message_macros.h" + +using content::BrowserThread; + +namespace extensions { + +SafeManifestParser::SafeManifestParser(const std::string& xml, + ManifestFetchData* fetch_data, + const UpdateCallback& update_callback) + : xml_(xml), fetch_data_(fetch_data), update_callback_(update_callback) { + DCHECK_CURRENTLY_ON(BrowserThread::UI); +} + +void SafeManifestParser::Start() { + DCHECK_CURRENTLY_ON(BrowserThread::UI); + if (!BrowserThread::PostTask( + BrowserThread::IO, + FROM_HERE, + base::Bind(&SafeManifestParser::ParseInSandbox, this))) { + NOTREACHED(); + } +} + +SafeManifestParser::~SafeManifestParser() { + // If we're using UtilityProcessHost, we may not be destroyed on + // the UI or IO thread. +} + +void SafeManifestParser::ParseInSandbox() { + DCHECK_CURRENTLY_ON(BrowserThread::IO); + + content::UtilityProcessHost* host = content::UtilityProcessHost::Create( + this, + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI).get()); + host->Send(new ExtensionUtilityMsg_ParseUpdateManifest(xml_)); +} + +bool SafeManifestParser::OnMessageReceived(const IPC::Message& message) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(SafeManifestParser, message) + IPC_MESSAGE_HANDLER(ExtensionUtilityHostMsg_ParseUpdateManifest_Succeeded, + OnParseUpdateManifestSucceeded) + IPC_MESSAGE_HANDLER(ExtensionUtilityHostMsg_ParseUpdateManifest_Failed, + OnParseUpdateManifestFailed) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + +void SafeManifestParser::OnParseUpdateManifestSucceeded( + const UpdateManifest::Results& results) { + VLOG(2) << "parsing manifest succeeded (" << fetch_data_->full_url() << ")"; + DCHECK_CURRENTLY_ON(BrowserThread::UI); + update_callback_.Run(*fetch_data_, &results); +} + +void SafeManifestParser::OnParseUpdateManifestFailed( + const std::string& error_message) { + VLOG(2) << "parsing manifest failed (" << fetch_data_->full_url() << ")"; + DCHECK_CURRENTLY_ON(BrowserThread::UI); + LOG(WARNING) << "Error parsing update manifest:\n" << error_message; + update_callback_.Run(*fetch_data_, NULL); +} + +} // namespace extensions diff --git a/extensions/browser/updater/safe_manifest_parser.h b/extensions/browser/updater/safe_manifest_parser.h new file mode 100644 index 0000000..278cd97 --- /dev/null +++ b/extensions/browser/updater/safe_manifest_parser.h @@ -0,0 +1,58 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef EXTENSIONS_BROWSER_UPDATER_SAFE_MANIFEST_PARSER_H_ +#define EXTENSIONS_BROWSER_UPDATER_SAFE_MANIFEST_PARSER_H_ + +#include <string> + +#include "base/basictypes.h" +#include "base/callback.h" +#include "base/memory/scoped_ptr.h" +#include "content/public/browser/utility_process_host_client.h" +#include "extensions/browser/updater/manifest_fetch_data.h" +#include "extensions/common/update_manifest.h" + +namespace extensions { + +// Utility class to handle doing xml parsing in a sandboxed utility process. +class SafeManifestParser : public content::UtilityProcessHostClient { + public: + // Callback that is invoked when the manifest results are ready. + typedef base::Callback<void(const ManifestFetchData&, + const UpdateManifest::Results*)> UpdateCallback; + + // Takes ownership of |fetch_data|. + SafeManifestParser(const std::string& xml, + ManifestFetchData* fetch_data, + const UpdateCallback& update_callback); + + // Posts a task over to the IO loop to start the parsing of xml_ in a + // utility process. + void Start(); + + private: + virtual ~SafeManifestParser(); + + // Creates the sandboxed utility process and tells it to start parsing. + void ParseInSandbox(); + + // content::UtilityProcessHostClient implementation. + virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; + + void OnParseUpdateManifestSucceeded(const UpdateManifest::Results& results); + void OnParseUpdateManifestFailed(const std::string& error_message); + + const std::string xml_; + + // Should be accessed only on UI thread. + scoped_ptr<ManifestFetchData> fetch_data_; + UpdateCallback update_callback_; + + DISALLOW_COPY_AND_ASSIGN(SafeManifestParser); +}; + +} // namespace extensions + +#endif // EXTENSIONS_BROWSER_UPDATER_SAFE_MANIFEST_PARSER_H_ diff --git a/extensions/common/extension_message_generator.h b/extensions/common/extension_message_generator.h index 0735924..fac22c8 100644 --- a/extensions/common/extension_message_generator.h +++ b/extensions/common/extension_message_generator.h @@ -5,3 +5,4 @@ // Multiply-included file, hence no include guard. #include "extensions/common/extension_messages.h" +#include "extensions/common/extension_utility_messages.h" diff --git a/extensions/common/extension_utility_messages.h b/extensions/common/extension_utility_messages.h new file mode 100644 index 0000000..77dfe13 --- /dev/null +++ b/extensions/common/extension_utility_messages.h @@ -0,0 +1,47 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Multiply-included message file, so no include guard. + +#include <string> + +#include "extensions/common/update_manifest.h" +#include "ipc/ipc_message_macros.h" + +#define IPC_MESSAGE_START ExtensionUtilityMsgStart + +IPC_STRUCT_TRAITS_BEGIN(UpdateManifest::Result) + IPC_STRUCT_TRAITS_MEMBER(extension_id) + IPC_STRUCT_TRAITS_MEMBER(version) + IPC_STRUCT_TRAITS_MEMBER(browser_min_version) + IPC_STRUCT_TRAITS_MEMBER(package_hash) + IPC_STRUCT_TRAITS_MEMBER(crx_url) +IPC_STRUCT_TRAITS_END() + +IPC_STRUCT_TRAITS_BEGIN(UpdateManifest::Results) + IPC_STRUCT_TRAITS_MEMBER(list) + IPC_STRUCT_TRAITS_MEMBER(daystart_elapsed_seconds) +IPC_STRUCT_TRAITS_END() + +//------------------------------------------------------------------------------ +// Utility process messages: +// These are messages from the browser to the utility process. + +// Tell the utility process to parse the given xml document. +IPC_MESSAGE_CONTROL1(ExtensionUtilityMsg_ParseUpdateManifest, + std::string /* xml document contents */) + +//------------------------------------------------------------------------------ +// Utility process host messages: +// These are messages from the utility process to the browser. + +// Reply when the utility process has succeeded in parsing an update manifest +// xml document. +IPC_MESSAGE_CONTROL1(ExtensionUtilityHostMsg_ParseUpdateManifest_Succeeded, + UpdateManifest::Results /* updates */) + +// Reply when an error occurred parsing the update manifest. |error_message| +// is a description of what went wrong suitable for logging. +IPC_MESSAGE_CONTROL1(ExtensionUtilityHostMsg_ParseUpdateManifest_Failed, + std::string /* error_message, if any */) diff --git a/extensions/extensions.gyp b/extensions/extensions.gyp index 6178f61..6b77c61 100644 --- a/extensions/extensions.gyp +++ b/extensions/extensions.gyp @@ -87,6 +87,7 @@ 'common/extension_set.h', 'common/extension_urls.cc', 'common/extension_urls.h', + 'common/extension_utility_messages.h', 'common/extensions_client.cc', 'common/extensions_client.h', 'common/feature_switch.cc', @@ -690,6 +691,8 @@ 'browser/update_observer.h', 'browser/updater/manifest_fetch_data.cc', 'browser/updater/manifest_fetch_data.h', + 'browser/updater/safe_manifest_parser.cc', + 'browser/updater/safe_manifest_parser.h', 'browser/url_request_util.cc', 'browser/url_request_util.h', 'browser/value_store/leveldb_value_store.cc', |