diff options
-rw-r--r-- | chrome/browser/utility_process_host.cc | 13 | ||||
-rw-r--r-- | chrome/browser/utility_process_host.h | 13 | ||||
-rw-r--r-- | chrome/common/utility_messages_internal.h | 14 | ||||
-rw-r--r-- | chrome/utility/DEPS | 1 | ||||
-rw-r--r-- | chrome/utility/utility_thread.cc | 18 | ||||
-rw-r--r-- | chrome/utility/utility_thread.h | 5 |
6 files changed, 64 insertions, 0 deletions
diff --git a/chrome/browser/utility_process_host.cc b/chrome/browser/utility_process_host.cc index 1766b7e..2f7ce5d 100644 --- a/chrome/browser/utility_process_host.cc +++ b/chrome/browser/utility_process_host.cc @@ -51,6 +51,15 @@ bool UtilityProcessHost::StartUpdateManifestParse(const std::string& xml) { return true; } +bool UtilityProcessHost::StartImageDecoding( + const std::vector<unsigned char>& encoded_data) { + if (!StartProcess(FilePath())) + return false; + + Send(new UtilityMsg_DecodeImage(encoded_data)); + return true; +} + FilePath UtilityProcessHost::GetUtilityProcessCmd() { return GetChildPath(true); } @@ -146,5 +155,9 @@ void UtilityProcessHost::Client::OnMessageReceived( Client::OnParseUpdateManifestSucceeded) IPC_MESSAGE_HANDLER(UtilityHostMsg_ParseUpdateManifest_Failed, Client::OnParseUpdateManifestFailed) + IPC_MESSAGE_HANDLER(UtilityHostMsg_DecodeImage_Succeeded, + Client::OnDecodeImageSucceeded) + IPC_MESSAGE_HANDLER(UtilityHostMsg_DecodeImage_Failed, + Client::OnDecodeImageFailed) IPC_END_MESSAGE_MAP_EX() } diff --git a/chrome/browser/utility_process_host.h b/chrome/browser/utility_process_host.h index ab326e8..faeec97 100644 --- a/chrome/browser/utility_process_host.h +++ b/chrome/browser/utility_process_host.h @@ -6,6 +6,7 @@ #define CHROME_BROWSER_UTILITY_PROCESS_HOST_H_ #include <string> +#include <vector> #include "base/basictypes.h" #include "base/ref_counted.h" @@ -14,6 +15,7 @@ #include "chrome/browser/chrome_thread.h" #include "chrome/common/extensions/update_manifest.h" #include "ipc/ipc_channel.h" +#include "third_party/skia/include/core/SkBitmap.h" class CommandLine; class DictionaryValue; @@ -63,6 +65,14 @@ class UtilityProcessHost : public ChildProcessHost { virtual void OnParseUpdateManifestFailed( const std::string& error_message) {} + // Called when image data was successfully decoded. |decoded_image| + // stores the result. + virtual void OnDecodeImageSucceeded( + const SkBitmap& decoded_image) {} + + // Called when image data decoding failed. + virtual void OnDecodeImageFailed() {} + protected: friend class base::RefCountedThreadSafe<Client>; @@ -97,6 +107,9 @@ class UtilityProcessHost : public ChildProcessHost { // Start parsing an extensions auto-update manifest xml file. bool StartUpdateManifestParse(const std::string& xml); + // Start image decoding. + bool StartImageDecoding(const std::vector<unsigned char>& encoded_data); + protected: // Allow these methods to be overridden for tests. virtual FilePath GetUtilityProcessCmd(); diff --git a/chrome/common/utility_messages_internal.h b/chrome/common/utility_messages_internal.h index 46da384..5c3f971 100644 --- a/chrome/common/utility_messages_internal.h +++ b/chrome/common/utility_messages_internal.h @@ -2,6 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <string> +#include <vector> + // This header is meant to be included in multiple passes, hence no traditional // header guard. It is included by utility_messages_internal.h // See ipc_message_macros.h for explanation of the macros and passes. @@ -10,6 +13,8 @@ // from it via utility_messages.h. #include "ipc/ipc_message_macros.h" +#include "third_party/skia/include/core/SkBitmap.h" + //------------------------------------------------------------------------------ // Utility process messages: // These are messages from the browser to the utility process. @@ -29,6 +34,9 @@ IPC_BEGIN_MESSAGES(Utility) IPC_MESSAGE_CONTROL1(UtilityMsg_ParseUpdateManifest, std::string /* xml document contents */) + // Tell the utility process to decode the given image data. + IPC_MESSAGE_CONTROL1(UtilityMsg_DecodeImage, + std::vector<unsigned char>) // encoded image contents IPC_END_MESSAGES(Utility) //------------------------------------------------------------------------------ @@ -70,4 +78,10 @@ IPC_BEGIN_MESSAGES(UtilityHost) IPC_MESSAGE_CONTROL1(UtilityHostMsg_ParseUpdateManifest_Failed, std::string /* error_message, if any */) + // Reply when the utility process has succeeded in decoding the image. + IPC_MESSAGE_CONTROL1(UtilityHostMsg_DecodeImage_Succeeded, + SkBitmap) // decoded image + + // Reply when an error occured decoding the image. + IPC_MESSAGE_CONTROL0(UtilityHostMsg_DecodeImage_Failed) IPC_END_MESSAGES(UtilityHost) diff --git a/chrome/utility/DEPS b/chrome/utility/DEPS index 07cb004..96944f28 100644 --- a/chrome/utility/DEPS +++ b/chrome/utility/DEPS @@ -1,3 +1,4 @@ include_rules = [ "+sandbox/src", + "+webkit/glue", ] diff --git a/chrome/utility/utility_thread.cc b/chrome/utility/utility_thread.cc index 0615efb..259b185 100644 --- a/chrome/utility/utility_thread.cc +++ b/chrome/utility/utility_thread.cc @@ -4,6 +4,8 @@ #include "chrome/utility/utility_thread.h" +#include <vector> + #include "base/file_util.h" #include "base/values.h" #include "chrome/common/child_process.h" @@ -12,6 +14,7 @@ #include "chrome/common/utility_messages.h" #include "chrome/common/web_resource/web_resource_unpacker.h" #include "third_party/skia/include/core/SkBitmap.h" +#include "webkit/glue/image_decoder.h" UtilityThread::UtilityThread() { ChildProcess::current()->AddRefProcess(); @@ -25,6 +28,7 @@ void UtilityThread::OnControlMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(UtilityMsg_UnpackExtension, OnUnpackExtension) IPC_MESSAGE_HANDLER(UtilityMsg_UnpackWebResource, OnUnpackWebResource) IPC_MESSAGE_HANDLER(UtilityMsg_ParseUpdateManifest, OnParseUpdateManifest) + IPC_MESSAGE_HANDLER(UtilityMsg_DecodeImage, OnDecodeImage) IPC_END_MESSAGE_MAP() } @@ -66,3 +70,17 @@ void UtilityThread::OnParseUpdateManifest(const std::string& xml) { } ChildProcess::current()->ReleaseProcess(); } + +void UtilityThread::OnDecodeImage( + const std::vector<unsigned char>& encoded_data) { + webkit_glue::ImageDecoder decoder; + const SkBitmap& decoded_image = decoder.Decode(&encoded_data[0], + encoded_data.size()); + if (decoded_image.empty()) { + Send(new UtilityHostMsg_DecodeImage_Failed()); + } else { + Send(new UtilityHostMsg_DecodeImage_Succeeded(decoded_image)); + } + ChildProcess::current()->ReleaseProcess(); +} + diff --git a/chrome/utility/utility_thread.h b/chrome/utility/utility_thread.h index 180f53d..9b88bc2 100644 --- a/chrome/utility/utility_thread.h +++ b/chrome/utility/utility_thread.h @@ -6,10 +6,12 @@ #define CHROME_UTILITY_UTILITY_THREAD_H_ #include <string> +#include <vector> #include "chrome/common/child_thread.h" class GURL; +class SkBitmap; // This class represents the background thread where the utility task runs. class UtilityThread : public ChildThread { @@ -33,6 +35,9 @@ class UtilityThread : public ChildThread { // IPC for parsing an extensions auto-update manifest xml file. void OnParseUpdateManifest(const std::string& xml); + // IPC for decoding an image. + void OnDecodeImage(const std::vector<unsigned char>& encoded_data); + DISALLOW_COPY_AND_ASSIGN(UtilityThread); }; |