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

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

Issue 11309014: File manager: support for zipping selected files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sanitize source relative paths to reject absolute and trick paths. Created 8 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « chrome/utility/chrome_content_utility_client.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/base64.h" 7 #include "base/base64.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_util.h"
10 #include "base/json/json_reader.h" 11 #include "base/json/json_reader.h"
11 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
12 #include "base/message_loop_proxy.h" 13 #include "base/message_loop_proxy.h"
13 #include "base/threading/thread.h" 14 #include "base/threading/thread.h"
14 #include "chrome/browser/importer/importer.h" 15 #include "chrome/browser/importer/importer.h"
15 #include "chrome/browser/importer/profile_import_process_messages.h" 16 #include "chrome/browser/importer/profile_import_process_messages.h"
16 #include "chrome/common/child_process_logging.h" 17 #include "chrome/common/child_process_logging.h"
17 #include "chrome/common/chrome_paths.h" 18 #include "chrome/common/chrome_paths.h"
18 #include "chrome/common/chrome_utility_messages.h" 19 #include "chrome/common/chrome_utility_messages.h"
19 #include "chrome/common/extensions/extension.h" 20 #include "chrome/common/extensions/extension.h"
20 #include "chrome/common/extensions/extension_l10n_util.h" 21 #include "chrome/common/extensions/extension_l10n_util.h"
21 #include "chrome/common/extensions/unpacker.h" 22 #include "chrome/common/extensions/unpacker.h"
22 #include "chrome/common/extensions/update_manifest.h" 23 #include "chrome/common/extensions/update_manifest.h"
23 #include "chrome/common/web_resource/web_resource_unpacker.h" 24 #include "chrome/common/web_resource/web_resource_unpacker.h"
25 #include "chrome/common/zip.h"
24 #include "chrome/utility/profile_import_handler.h" 26 #include "chrome/utility/profile_import_handler.h"
25 #include "content/public/utility/utility_thread.h" 27 #include "content/public/utility/utility_thread.h"
26 #include "printing/backend/print_backend.h" 28 #include "printing/backend/print_backend.h"
27 #include "printing/page_range.h" 29 #include "printing/page_range.h"
28 #include "third_party/skia/include/core/SkBitmap.h" 30 #include "third_party/skia/include/core/SkBitmap.h"
29 #include "ui/base/ui_base_switches.h" 31 #include "ui/base/ui_base_switches.h"
30 #include "ui/gfx/codec/jpeg_codec.h" 32 #include "ui/gfx/codec/jpeg_codec.h"
31 #include "ui/gfx/rect.h" 33 #include "ui/gfx/rect.h"
32 #include "webkit/glue/image_decoder.h" 34 #include "webkit/glue/image_decoder.h"
33 35
34 #if defined(OS_WIN) 36 #if defined(OS_WIN)
35 #include "base/file_util.h"
36 #include "base/path_service.h" 37 #include "base/path_service.h"
37 #include "base/win/iat_patch_function.h" 38 #include "base/win/iat_patch_function.h"
38 #include "base/win/scoped_handle.h" 39 #include "base/win/scoped_handle.h"
39 #include "content/public/common/content_switches.h" 40 #include "content/public/common/content_switches.h"
40 #include "printing/emf_win.h" 41 #include "printing/emf_win.h"
41 #include "ui/gfx/gdi_util.h" 42 #include "ui/gfx/gdi_util.h"
42 #endif // defined(OS_WIN) 43 #endif // defined(OS_WIN)
43 44
44 namespace chrome { 45 namespace chrome {
45 46
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 OnParseUpdateManifest) 82 OnParseUpdateManifest)
82 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImage, OnDecodeImage) 83 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImage, OnDecodeImage)
83 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImageBase64, OnDecodeImageBase64) 84 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImageBase64, OnDecodeImageBase64)
84 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToMetafile, 85 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToMetafile,
85 OnRenderPDFPagesToMetafile) 86 OnRenderPDFPagesToMetafile)
86 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RobustJPEGDecodeImage, 87 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RobustJPEGDecodeImage,
87 OnRobustJPEGDecodeImage) 88 OnRobustJPEGDecodeImage)
88 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseJSON, OnParseJSON) 89 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseJSON, OnParseJSON)
89 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetPrinterCapsAndDefaults, 90 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetPrinterCapsAndDefaults,
90 OnGetPrinterCapsAndDefaults) 91 OnGetPrinterCapsAndDefaults)
92
93 #if defined(OS_CHROMEOS)
94 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_CreateZipFile, OnCreateZipFile)
95 #endif // defined(OS_CHROMEOS)
96
91 IPC_MESSAGE_UNHANDLED(handled = false) 97 IPC_MESSAGE_UNHANDLED(handled = false)
92 IPC_END_MESSAGE_MAP() 98 IPC_END_MESSAGE_MAP()
93 99
94 #if !defined(OS_ANDROID) 100 #if !defined(OS_ANDROID)
95 if (!handled) 101 if (!handled)
96 handled = import_handler_->OnMessageReceived(message); 102 handled = import_handler_->OnMessageReceived(message);
97 #endif 103 #endif
98 104
99 return handled; 105 return handled;
100 } 106 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 } 185 }
180 186
181 std::vector<unsigned char> decoded_vector(decoded_string.size()); 187 std::vector<unsigned char> decoded_vector(decoded_string.size());
182 for (size_t i = 0; i < decoded_string.size(); ++i) { 188 for (size_t i = 0; i < decoded_string.size(); ++i) {
183 decoded_vector[i] = static_cast<unsigned char>(decoded_string[i]); 189 decoded_vector[i] = static_cast<unsigned char>(decoded_string[i]);
184 } 190 }
185 191
186 OnDecodeImage(decoded_vector); 192 OnDecodeImage(decoded_vector);
187 } 193 }
188 194
195 #if defined(OS_CHROMEOS)
196 void ChromeContentUtilityClient::OnCreateZipFile(
197 const FilePath& src_dir,
198 const std::vector<FilePath>& src_relative_paths,
199 const base::FileDescriptor& dest_fd) {
200 bool succeeded = true;
201
202 // Check sanity for source relative paths. Reject if path is absolute or
Jorge Lucangeli Obes 2012/11/22 00:28:20 "Check sanity of" or "Sanity check for".
hshi1 2012/11/22 00:35:45 Done.
203 // contains any attempt to reference a parent directory ("../" tricks).
204 for (std::vector<FilePath>::const_iterator iter = src_relative_paths.begin();
205 iter != src_relative_paths.end(); ++iter) {
206 if (iter->IsAbsolute() || iter->ReferencesParent()) {
207 succeeded = false;
208 break;
209 }
210 }
211
212 if (succeeded)
213 succeeded = zip::ZipFiles(src_dir, src_relative_paths, dest_fd.fd);
214
215 if (succeeded)
216 Send(new ChromeUtilityHostMsg_CreateZipFile_Succeeded());
217 else
218 Send(new ChromeUtilityHostMsg_CreateZipFile_Failed());
219 content::UtilityThread::Get()->ReleaseProcessIfNeeded();
220 }
221 #endif // defined(OS_CHROMEOS)
222
189 void ChromeContentUtilityClient::OnRenderPDFPagesToMetafile( 223 void ChromeContentUtilityClient::OnRenderPDFPagesToMetafile(
190 base::PlatformFile pdf_file, 224 base::PlatformFile pdf_file,
191 const FilePath& metafile_path, 225 const FilePath& metafile_path,
192 const printing::PdfRenderSettings& pdf_render_settings, 226 const printing::PdfRenderSettings& pdf_render_settings,
193 const std::vector<printing::PageRange>& page_ranges) { 227 const std::vector<printing::PageRange>& page_ranges) {
194 bool succeeded = false; 228 bool succeeded = false;
195 #if defined(OS_WIN) 229 #if defined(OS_WIN)
196 int highest_rendered_page_number = 0; 230 int highest_rendered_page_number = 0;
197 double scale_factor = 1.0; 231 double scale_factor = 1.0;
198 succeeded = RenderPDFToWinMetafile(pdf_file, 232 succeeded = RenderPDFToWinMetafile(pdf_file,
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 } else 441 } else
408 #endif 442 #endif
409 { 443 {
410 Send(new ChromeUtilityHostMsg_GetPrinterCapsAndDefaults_Failed( 444 Send(new ChromeUtilityHostMsg_GetPrinterCapsAndDefaults_Failed(
411 printer_name)); 445 printer_name));
412 } 446 }
413 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); 447 content::UtilityThread::Get()->ReleaseProcessIfNeeded();
414 } 448 }
415 449
416 } // namespace chrome 450 } // namespace chrome
OLDNEW
« no previous file with comments | « 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