summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorsaintlou@chromium.org <saintlou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-29 23:12:15 +0000
committersaintlou@chromium.org <saintlou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-29 23:12:15 +0000
commit11f16d10114d6e266b590785fcf50bca63734d62 (patch)
tree8d68941d3e691746293b41dd890e7bcef0821d7d /chrome
parent6a01960c32c340d4333257bf9d0244f5199d8dd8 (diff)
downloadchromium_src-11f16d10114d6e266b590785fcf50bca63734d62.zip
chromium_src-11f16d10114d6e266b590785fcf50bca63734d62.tar.gz
chromium_src-11f16d10114d6e266b590785fcf50bca63734d62.tar.bz2
Force avatar and wallpaper decoding to use robust JPEG.
The next step in an upcoming CL will bind this separate path to a different JPEG library (at a minimum on CrOS). BUG=144296 Review URL: https://chromiumcodereview.appspot.com/10892023 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@154001 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/chromeos/extensions/wallpaper_private_api.cc3
-rw-r--r--chrome/browser/chromeos/login/user_image_loader.cc2
-rw-r--r--chrome/browser/image_decoder.cc11
-rw-r--r--chrome/browser/image_decoder.h9
-rw-r--r--chrome/browser/profiles/profile_downloader.cc2
-rw-r--r--chrome/browser/ui/webui/chromeos/login/user_image_screen_handler.cc3
-rw-r--r--chrome/browser/ui/webui/options/chromeos/change_picture_options_handler.cc3
-rw-r--r--chrome/common/chrome_utility_messages.h5
-rw-r--r--chrome/utility/chrome_content_utility_client.cc14
-rw-r--r--chrome/utility/chrome_content_utility_client.h2
10 files changed, 46 insertions, 8 deletions
diff --git a/chrome/browser/chromeos/extensions/wallpaper_private_api.cc b/chrome/browser/chromeos/extensions/wallpaper_private_api.cc
index 7550d3a..8432ed2 100644
--- a/chrome/browser/chromeos/extensions/wallpaper_private_api.cc
+++ b/chrome/browser/chromeos/extensions/wallpaper_private_api.cc
@@ -62,7 +62,8 @@ class WallpaperSetWallpaperFunction::WallpaperDecoder
}
void Start(const std::string& image_data) {
- image_decoder_ = new ImageDecoder(this, image_data);
+ image_decoder_ = new ImageDecoder(this, image_data,
+ ImageDecoder::ROBUST_JPEG_CODEC);
image_decoder_->Start();
}
diff --git a/chrome/browser/chromeos/login/user_image_loader.cc b/chrome/browser/chromeos/login/user_image_loader.cc
index da34f7d..dfcd436 100644
--- a/chrome/browser/chromeos/login/user_image_loader.cc
+++ b/chrome/browser/chromeos/login/user_image_loader.cc
@@ -56,7 +56,7 @@ void UserImageLoader::LoadImage(const std::string& filepath,
file_util::ReadFileToString(FilePath(filepath), &image_data);
scoped_refptr<ImageDecoder> image_decoder =
- new ImageDecoder(this, image_data);
+ new ImageDecoder(this, image_data, ImageDecoder::ROBUST_JPEG_CODEC);
image_info_map_.insert(std::make_pair(image_decoder.get(), image_info));
image_decoder->Start();
}
diff --git a/chrome/browser/image_decoder.cc b/chrome/browser/image_decoder.cc
index a345c77..1f456ee 100644
--- a/chrome/browser/image_decoder.cc
+++ b/chrome/browser/image_decoder.cc
@@ -14,9 +14,11 @@ using content::BrowserThread;
using content::UtilityProcessHost;
ImageDecoder::ImageDecoder(Delegate* delegate,
- const std::string& image_data)
+ const std::string& image_data,
+ ImageCodec image_codec)
: delegate_(delegate),
image_data_(image_data.begin(), image_data.end()),
+ image_codec_(image_codec),
target_thread_id_(BrowserThread::UI) {
}
@@ -62,5 +64,10 @@ void ImageDecoder::DecodeImageInSandbox(
UtilityProcessHost* utility_process_host = UtilityProcessHost::Create(
this, target_thread_id_);
utility_process_host->EnableZygote();
- utility_process_host->Send(new ChromeUtilityMsg_DecodeImage(image_data));
+ if (image_codec_ == ROBUST_JPEG_CODEC) {
+ utility_process_host->Send(
+ new ChromeUtilityMsg_RobustJPEGDecodeImage(image_data));
+ } else {
+ utility_process_host->Send(new ChromeUtilityMsg_DecodeImage(image_data));
+ }
}
diff --git a/chrome/browser/image_decoder.h b/chrome/browser/image_decoder.h
index 69caa43..24f4d89 100644
--- a/chrome/browser/image_decoder.h
+++ b/chrome/browser/image_decoder.h
@@ -33,8 +33,14 @@ class ImageDecoder : public content::UtilityProcessHostClient {
virtual ~Delegate() {}
};
+ enum ImageCodec {
+ DEFAULT_CODEC = 0, // Uses WebKit image decoding (via WebImage).
+ ROBUST_JPEG_CODEC, // Restrict decoding to robust jpeg codec.
+ };
+
ImageDecoder(Delegate* delegate,
- const std::string& image_data);
+ const std::string& image_data,
+ ImageCodec image_codec);
// Starts image decoding.
void Start();
@@ -61,6 +67,7 @@ class ImageDecoder : public content::UtilityProcessHostClient {
Delegate* delegate_;
std::vector<unsigned char> image_data_;
+ const ImageCodec image_codec_;
content::BrowserThread::ID target_thread_id_;
DISALLOW_COPY_AND_ASSIGN(ImageDecoder);
diff --git a/chrome/browser/profiles/profile_downloader.cc b/chrome/browser/profiles/profile_downloader.cc
index 878c565..50a0958 100644
--- a/chrome/browser/profiles/profile_downloader.cc
+++ b/chrome/browser/profiles/profile_downloader.cc
@@ -331,7 +331,7 @@ void ProfileDownloader::OnURLFetchComplete(const net::URLFetcher* source) {
} else if (source == profile_image_fetcher_.get()) {
VLOG(1) << "Decoding the image...";
scoped_refptr<ImageDecoder> image_decoder = new ImageDecoder(
- this, data);
+ this, data, ImageDecoder::DEFAULT_CODEC);
image_decoder->Start();
}
}
diff --git a/chrome/browser/ui/webui/chromeos/login/user_image_screen_handler.cc b/chrome/browser/ui/webui/chromeos/login/user_image_screen_handler.cc
index 50ca318..0c0b6b1 100644
--- a/chrome/browser/ui/webui/chromeos/login/user_image_screen_handler.cc
+++ b/chrome/browser/ui/webui/chromeos/login/user_image_screen_handler.cc
@@ -232,7 +232,8 @@ void UserImageScreenHandler::HandlePhotoTaken(const base::ListValue* args) {
if (image_decoder_.get())
image_decoder_->set_delegate(NULL);
- image_decoder_ = new ImageDecoder(this, raw_data);
+ image_decoder_ = new ImageDecoder(this, raw_data,
+ ImageDecoder::ROBUST_JPEG_CODEC);
image_decoder_->Start();
}
diff --git a/chrome/browser/ui/webui/options/chromeos/change_picture_options_handler.cc b/chrome/browser/ui/webui/options/chromeos/change_picture_options_handler.cc
index f6058e4..a27e801 100644
--- a/chrome/browser/ui/webui/options/chromeos/change_picture_options_handler.cc
+++ b/chrome/browser/ui/webui/options/chromeos/change_picture_options_handler.cc
@@ -200,7 +200,8 @@ void ChangePictureOptionsHandler::HandlePhotoTaken(
if (image_decoder_.get())
image_decoder_->set_delegate(NULL);
- image_decoder_ = new ImageDecoder(this, raw_data);
+ image_decoder_ = new ImageDecoder(this, raw_data,
+ ImageDecoder::ROBUST_JPEG_CODEC);
image_decoder_->Start();
}
diff --git a/chrome/common/chrome_utility_messages.h b/chrome/common/chrome_utility_messages.h
index 67508264..e67cec3 100644
--- a/chrome/common/chrome_utility_messages.h
+++ b/chrome/common/chrome_utility_messages.h
@@ -85,6 +85,11 @@ IPC_MESSAGE_CONTROL4(ChromeUtilityMsg_RenderPDFPagesToMetafile,
printing::PdfRenderSettings, // PDF render settitngs
std::vector<printing::PageRange>)
+// Tell the utility process to decode the given JPEG image data with a robust
+// libjpeg codec.
+IPC_MESSAGE_CONTROL1(ChromeUtilityMsg_RobustJPEGDecodeImage,
+ std::vector<unsigned char>) // encoded image contents
+
// Tell the utility process to parse a JSON string into a Value object.
IPC_MESSAGE_CONTROL1(ChromeUtilityMsg_ParseJSON,
std::string /* JSON to parse */)
diff --git a/chrome/utility/chrome_content_utility_client.cc b/chrome/utility/chrome_content_utility_client.cc
index 51fa4d5..f28771c 100644
--- a/chrome/utility/chrome_content_utility_client.cc
+++ b/chrome/utility/chrome_content_utility_client.cc
@@ -28,6 +28,7 @@
#include "printing/page_range.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/ui_base_switches.h"
+#include "ui/gfx/codec/jpeg_codec.h"
#include "ui/gfx/rect.h"
#include "webkit/glue/image_decoder.h"
@@ -83,6 +84,8 @@ bool ChromeContentUtilityClient::OnMessageReceived(
IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImageBase64, OnDecodeImageBase64)
IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToMetafile,
OnRenderPDFPagesToMetafile)
+ IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RobustJPEGDecodeImage,
+ OnRobustJPEGDecodeImage)
IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseJSON, OnParseJSON)
IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetPrinterCapsAndDefaults,
OnGetPrinterCapsAndDefaults)
@@ -357,6 +360,17 @@ bool ChromeContentUtilityClient::RenderPDFToWinMetafile(
}
#endif // defined(OS_WIN)
+void ChromeContentUtilityClient::OnRobustJPEGDecodeImage(
+ const std::vector<unsigned char>& encoded_data) {
+ scoped_ptr<SkBitmap> decoded_image(gfx::JPEGCodec::Decode(
+ &encoded_data[0], encoded_data.size()));
+ if (decoded_image->empty()) {
+ Send(new ChromeUtilityHostMsg_DecodeImage_Failed());
+ } else {
+ Send(new ChromeUtilityHostMsg_DecodeImage_Succeeded(*decoded_image));
+ }
+ content::UtilityThread::Get()->ReleaseProcessIfNeeded();
+}
void ChromeContentUtilityClient::OnParseJSON(const std::string& json) {
int error_code;
diff --git a/chrome/utility/chrome_content_utility_client.h b/chrome/utility/chrome_content_utility_client.h
index fb82afa..e988ef1 100644
--- a/chrome/utility/chrome_content_utility_client.h
+++ b/chrome/utility/chrome_content_utility_client.h
@@ -60,6 +60,8 @@ class ChromeContentUtilityClient : public content::ContentUtilityClient {
const FilePath& metafile_path,
const printing::PdfRenderSettings& pdf_render_settings,
const std::vector<printing::PageRange>& page_ranges);
+ void OnRobustJPEGDecodeImage(
+ const std::vector<unsigned char>& encoded_data);
void OnParseJSON(const std::string& json);
#if defined(OS_WIN)