Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: chrome/utility/chrome_content_utility_client.cc

Issue 1159363002: [Download Notification] Show preview if downloaded file is image (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adressed comment #10 Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/utility/chrome_content_utility_client.h" 5 #include "chrome/utility/chrome_content_utility_client.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 } 175 }
176 176
177 bool ChromeContentUtilityClient::OnMessageReceived( 177 bool ChromeContentUtilityClient::OnMessageReceived(
178 const IPC::Message& message) { 178 const IPC::Message& message) {
179 if (filter_messages_ && !ContainsKey(message_id_whitelist_, message.type())) 179 if (filter_messages_ && !ContainsKey(message_id_whitelist_, message.type()))
180 return false; 180 return false;
181 181
182 bool handled = true; 182 bool handled = true;
183 IPC_BEGIN_MESSAGE_MAP(ChromeContentUtilityClient, message) 183 IPC_BEGIN_MESSAGE_MAP(ChromeContentUtilityClient, message)
184 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImage, OnDecodeImage) 184 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImage, OnDecodeImage)
185 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImageByHandle,
186 OnDecodeImageByHandle)
185 #if defined(OS_CHROMEOS) 187 #if defined(OS_CHROMEOS)
186 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RobustJPEGDecodeImage, 188 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RobustJPEGDecodeImage,
187 OnRobustJPEGDecodeImage) 189 OnRobustJPEGDecodeImage)
188 #endif // defined(OS_CHROMEOS) 190 #endif // defined(OS_CHROMEOS)
189 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseJSON, OnParseJSON) 191 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseJSON, OnParseJSON)
190 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_PatchFileBsdiff, 192 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_PatchFileBsdiff,
191 OnPatchFileBsdiff) 193 OnPatchFileBsdiff)
192 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_PatchFileCourgette, 194 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_PatchFileCourgette,
193 OnPatchFileCourgette) 195 OnPatchFileCourgette)
194 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_StartupPing, OnStartupPing) 196 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_StartupPing, OnStartupPing)
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 289
288 if (decoded_image.empty()) { 290 if (decoded_image.empty()) {
289 Send(new ChromeUtilityHostMsg_DecodeImage_Failed(request_id)); 291 Send(new ChromeUtilityHostMsg_DecodeImage_Failed(request_id));
290 } else { 292 } else {
291 Send(new ChromeUtilityHostMsg_DecodeImage_Succeeded(decoded_image, 293 Send(new ChromeUtilityHostMsg_DecodeImage_Succeeded(decoded_image,
292 request_id)); 294 request_id));
293 } 295 }
294 ReleaseProcessIfNeeded(); 296 ReleaseProcessIfNeeded();
295 } 297 }
296 298
299 void ChromeContentUtilityClient::OnDecodeImageByHandle(
300 const IPC::PlatformFileForTransit& image_file,
301 bool shrink_to_fit,
302 int request_id) {
303 base::File file = IPC::PlatformFileForTransitToFile(image_file);
304
305 std::vector<unsigned char> image_data(file.GetLength());
306 file.Read(0, reinterpret_cast<char*>(image_data.data()), file.GetLength());
asanka 2015/06/11 03:30:52 Fail early if reading failed.
yoshiki 2015/06/11 08:22:09 Done.
307 DecodeImageAndSend(image_data, shrink_to_fit, request_id);
308 }
309
297 void ChromeContentUtilityClient::OnDecodeImage( 310 void ChromeContentUtilityClient::OnDecodeImage(
298 const std::vector<unsigned char>& encoded_data, 311 const std::vector<unsigned char>& encoded_data,
299 bool shrink_to_fit, 312 bool shrink_to_fit,
300 int request_id) { 313 int request_id) {
301 DecodeImageAndSend(encoded_data, shrink_to_fit, request_id); 314 DecodeImageAndSend(encoded_data, shrink_to_fit, request_id);
302 } 315 }
303 316
304 #if defined(OS_CHROMEOS) 317 #if defined(OS_CHROMEOS)
305 void ChromeContentUtilityClient::OnCreateZipFile( 318 void ChromeContentUtilityClient::OnCreateZipFile(
306 const base::FilePath& src_dir, 319 const base::FilePath& src_dir,
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 const std::string& mime_type, int64 total_size, bool get_attached_images) { 454 const std::string& mime_type, int64 total_size, bool get_attached_images) {
442 // Only one IPCDataSource may be created and added to the list of handlers. 455 // Only one IPCDataSource may be created and added to the list of handlers.
443 metadata::IPCDataSource* source = new metadata::IPCDataSource(total_size); 456 metadata::IPCDataSource* source = new metadata::IPCDataSource(total_size);
444 handlers_.push_back(source); 457 handlers_.push_back(source);
445 458
446 metadata::MediaMetadataParser* parser = new metadata::MediaMetadataParser( 459 metadata::MediaMetadataParser* parser = new metadata::MediaMetadataParser(
447 source, mime_type, get_attached_images); 460 source, mime_type, get_attached_images);
448 parser->Start(base::Bind(&FinishParseMediaMetadata, base::Owned(parser))); 461 parser->Start(base::Bind(&FinishParseMediaMetadata, base::Owned(parser)));
449 } 462 }
450 #endif 463 #endif
OLDNEW
« chrome/browser/image_decoder.cc ('K') | « chrome/utility/chrome_content_utility_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698