diff options
author | bulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-18 13:54:59 +0000 |
---|---|---|
committer | bulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-18 13:54:59 +0000 |
commit | 67a7851692243892bb2d7253d2f1974833e57432 (patch) | |
tree | 98bdc05f9af985cbcc8b9cc6ea0ccf472a85b588 /chrome/utility | |
parent | e40cc399bd7e438579d6fcfa208103c12caf9052 (diff) | |
download | chromium_src-67a7851692243892bb2d7253d2f1974833e57432.zip chromium_src-67a7851692243892bb2d7253d2f1974833e57432.tar.gz chromium_src-67a7851692243892bb2d7253d2f1974833e57432.tar.bz2 |
Adds IDBKeyPath parser / extractor, and provides a mechanism to call it sandboxed.
TEST=idbkeypathextractor_browsertests.cc
Review URL: http://codereview.chromium.org/3043037
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56524 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/utility')
-rw-r--r-- | chrome/utility/utility_thread.cc | 63 | ||||
-rw-r--r-- | chrome/utility/utility_thread.h | 20 |
2 files changed, 77 insertions, 6 deletions
diff --git a/chrome/utility/utility_thread.cc b/chrome/utility/utility_thread.cc index 420df28..c759c0d 100644 --- a/chrome/utility/utility_thread.cc +++ b/chrome/utility/utility_thread.cc @@ -15,6 +15,7 @@ #include "chrome/common/chrome_paths.h" #include "chrome/common/extensions/extension_unpacker.h" #include "chrome/common/extensions/update_manifest.h" +#include "chrome/common/indexed_db_key.h" #include "chrome/common/utility_messages.h" #include "chrome/common/web_resource/web_resource_unpacker.h" #include "gfx/rect.h" @@ -22,10 +23,24 @@ #include "printing/page_range.h" #include "printing/units.h" #include "third_party/skia/include/core/SkBitmap.h" +#include "webkit/glue/idb_bindings.h" #include "webkit/glue/image_decoder.h" -UtilityThread::UtilityThread() { +namespace { + +template<typename SRC, typename DEST> +void ConvertVector(const SRC& src, DEST* dest) { + dest->reserve(src.size()); + for (typename SRC::const_iterator i = src.begin(); i != src.end(); ++i) + dest->push_back(typename DEST::value_type(*i)); +} + +} // namespace + + +UtilityThread::UtilityThread() + : batch_mode_(false) { ChildProcess::current()->AddRefProcess(); } @@ -40,6 +55,10 @@ void UtilityThread::OnControlMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(UtilityMsg_DecodeImage, OnDecodeImage) IPC_MESSAGE_HANDLER(UtilityMsg_RenderPDFPagesToMetafile, OnRenderPDFPagesToMetafile) + IPC_MESSAGE_HANDLER(UtilityMsg_IDBKeysFromValuesAndKeyPath, + OnIDBKeysFromValuesAndKeyPath) + IPC_MESSAGE_HANDLER(UtilityMsg_BatchMode_Started, OnBatchModeStarted) + IPC_MESSAGE_HANDLER(UtilityMsg_BatchMode_Finished, OnBatchModeFinished) IPC_END_MESSAGE_MAP() } @@ -53,7 +72,7 @@ void UtilityThread::OnUnpackExtension(const FilePath& extension_path) { Send(new UtilityHostMsg_UnpackExtension_Failed(unpacker.error_message())); } - ChildProcess::current()->ReleaseProcess(); + ReleaseProcessIfNeeded(); } void UtilityThread::OnUnpackWebResource(const std::string& resource_data) { @@ -69,7 +88,7 @@ void UtilityThread::OnUnpackWebResource(const std::string& resource_data) { unpacker.error_message())); } - ChildProcess::current()->ReleaseProcess(); + ReleaseProcessIfNeeded(); } void UtilityThread::OnParseUpdateManifest(const std::string& xml) { @@ -79,7 +98,7 @@ void UtilityThread::OnParseUpdateManifest(const std::string& xml) { } else { Send(new UtilityHostMsg_ParseUpdateManifest_Succeeded(manifest.results())); } - ChildProcess::current()->ReleaseProcess(); + ReleaseProcessIfNeeded(); } void UtilityThread::OnDecodeImage( @@ -92,7 +111,7 @@ void UtilityThread::OnDecodeImage( } else { Send(new UtilityHostMsg_DecodeImage_Succeeded(decoded_image)); } - ChildProcess::current()->ReleaseProcess(); + ReleaseProcessIfNeeded(); } @@ -116,7 +135,7 @@ void UtilityThread::OnRenderPDFPagesToMetafile( if (!succeeded) { Send(new UtilityHostMsg_RenderPDFPagesToMetafile_Failed()); } - ChildProcess::current()->ReleaseProcess(); + ReleaseProcessIfNeeded(); } #if defined(OS_WIN) @@ -253,3 +272,35 @@ bool UtilityThread::RenderPDFToWinMetafile( return ret; } #endif // defined(OS_WIN) + +void UtilityThread::OnIDBKeysFromValuesAndKeyPath( + int id, + const std::vector<SerializedScriptValue>& serialized_script_values, + const string16& idb_key_path) { + std::vector<WebKit::WebSerializedScriptValue> web_values; + ConvertVector(serialized_script_values, &web_values); + std::vector<WebKit::WebIDBKey> web_keys; + bool error = webkit_glue::IDBKeysFromValuesAndKeyPath( + web_values, idb_key_path, &web_keys); + if (error) { + Send(new UtilityHostMsg_IDBKeysFromValuesAndKeyPath_Failed(id)); + return; + } + std::vector<IndexedDBKey> keys; + ConvertVector(web_keys, &keys); + Send(new UtilityHostMsg_IDBKeysFromValuesAndKeyPath_Succeeded(id, keys)); + ReleaseProcessIfNeeded(); +} + +void UtilityThread::OnBatchModeStarted() { + batch_mode_ = true; +} + +void UtilityThread::OnBatchModeFinished() { + ChildProcess::current()->ReleaseProcess(); +} + +void UtilityThread::ReleaseProcessIfNeeded() { + if (!batch_mode_) + ChildProcess::current()->ReleaseProcess(); +} diff --git a/chrome/utility/utility_thread.h b/chrome/utility/utility_thread.h index 1f86cdc..a92c08b 100644 --- a/chrome/utility/utility_thread.h +++ b/chrome/utility/utility_thread.h @@ -14,6 +14,7 @@ #include "printing/native_metafile.h" class GURL; +class SerializedScriptValue; class SkBitmap; namespace gfx { @@ -68,6 +69,25 @@ class UtilityThread : public ChildThread { int* highest_rendered_page_number); #endif // defined(OS_WIN) + // IPC for extracting IDBKeys from SerializedScriptValues, used by IndexedDB. + void OnIDBKeysFromValuesAndKeyPath( + int id, + const std::vector<SerializedScriptValue>& serialized_script_values, + const string16& idb_key_path); + + // IPC to notify we'll be running in batch mode instead of quitting after + // any of the IPCs above, we'll only quit during OnBatchModeFinished(). + void OnBatchModeStarted(); + + // IPC to notify batch mode has finished and we should now quit. + void OnBatchModeFinished(); + + // Releases the process if we are not (or no longer) in batch mode. + void ReleaseProcessIfNeeded(); + + // True when we're running in batch mode. + bool batch_mode_; + DISALLOW_COPY_AND_ASSIGN(UtilityThread); }; |