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

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

Issue 3043037: Adds IDBKeyPath parser / extractor, and provides a mechanism to call it sandboxed. (Closed)
Patch Set: Makes MSVC happy. Created 10 years, 4 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
« no previous file with comments | « chrome/utility/utility_thread.h ('k') | webkit/glue/idb_bindings.h » ('j') | 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/utility_thread.h" 5 #include "chrome/utility/utility_thread.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #if defined(OS_WIN) 10 #if defined(OS_WIN)
11 #include "base/iat_patch.h" 11 #include "base/iat_patch.h"
12 #endif 12 #endif
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "chrome/common/child_process.h" 14 #include "chrome/common/child_process.h"
15 #include "chrome/common/chrome_paths.h" 15 #include "chrome/common/chrome_paths.h"
16 #include "chrome/common/extensions/extension_unpacker.h" 16 #include "chrome/common/extensions/extension_unpacker.h"
17 #include "chrome/common/extensions/update_manifest.h" 17 #include "chrome/common/extensions/update_manifest.h"
18 #include "chrome/common/indexed_db_key.h"
18 #include "chrome/common/utility_messages.h" 19 #include "chrome/common/utility_messages.h"
19 #include "chrome/common/web_resource/web_resource_unpacker.h" 20 #include "chrome/common/web_resource/web_resource_unpacker.h"
20 #include "gfx/rect.h" 21 #include "gfx/rect.h"
21 #include "printing/native_metafile.h" 22 #include "printing/native_metafile.h"
22 #include "printing/page_range.h" 23 #include "printing/page_range.h"
23 #include "printing/units.h" 24 #include "printing/units.h"
24 #include "third_party/skia/include/core/SkBitmap.h" 25 #include "third_party/skia/include/core/SkBitmap.h"
26 #include "webkit/glue/idb_bindings.h"
25 #include "webkit/glue/image_decoder.h" 27 #include "webkit/glue/image_decoder.h"
26 28
27 29
28 UtilityThread::UtilityThread() { 30 namespace {
31
32 template<typename SRC, typename DEST>
33 void ConvertVector(const SRC& src, DEST* dest) {
34 dest->reserve(src.size());
35 for (typename SRC::const_iterator i = src.begin(); i != src.end(); ++i)
36 dest->push_back(typename DEST::value_type(*i));
37 }
38
39 } // namespace
40
41
42 UtilityThread::UtilityThread()
43 : batch_mode_(false) {
29 ChildProcess::current()->AddRefProcess(); 44 ChildProcess::current()->AddRefProcess();
30 } 45 }
31 46
32 UtilityThread::~UtilityThread() { 47 UtilityThread::~UtilityThread() {
33 } 48 }
34 49
35 void UtilityThread::OnControlMessageReceived(const IPC::Message& msg) { 50 void UtilityThread::OnControlMessageReceived(const IPC::Message& msg) {
36 IPC_BEGIN_MESSAGE_MAP(UtilityThread, msg) 51 IPC_BEGIN_MESSAGE_MAP(UtilityThread, msg)
37 IPC_MESSAGE_HANDLER(UtilityMsg_UnpackExtension, OnUnpackExtension) 52 IPC_MESSAGE_HANDLER(UtilityMsg_UnpackExtension, OnUnpackExtension)
38 IPC_MESSAGE_HANDLER(UtilityMsg_UnpackWebResource, OnUnpackWebResource) 53 IPC_MESSAGE_HANDLER(UtilityMsg_UnpackWebResource, OnUnpackWebResource)
39 IPC_MESSAGE_HANDLER(UtilityMsg_ParseUpdateManifest, OnParseUpdateManifest) 54 IPC_MESSAGE_HANDLER(UtilityMsg_ParseUpdateManifest, OnParseUpdateManifest)
40 IPC_MESSAGE_HANDLER(UtilityMsg_DecodeImage, OnDecodeImage) 55 IPC_MESSAGE_HANDLER(UtilityMsg_DecodeImage, OnDecodeImage)
41 IPC_MESSAGE_HANDLER(UtilityMsg_RenderPDFPagesToMetafile, 56 IPC_MESSAGE_HANDLER(UtilityMsg_RenderPDFPagesToMetafile,
42 OnRenderPDFPagesToMetafile) 57 OnRenderPDFPagesToMetafile)
58 IPC_MESSAGE_HANDLER(UtilityMsg_IDBKeysFromValuesAndKeyPath,
59 OnIDBKeysFromValuesAndKeyPath)
60 IPC_MESSAGE_HANDLER(UtilityMsg_BatchMode_Started, OnBatchModeStarted)
61 IPC_MESSAGE_HANDLER(UtilityMsg_BatchMode_Finished, OnBatchModeFinished)
43 IPC_END_MESSAGE_MAP() 62 IPC_END_MESSAGE_MAP()
44 } 63 }
45 64
46 void UtilityThread::OnUnpackExtension(const FilePath& extension_path) { 65 void UtilityThread::OnUnpackExtension(const FilePath& extension_path) {
47 ExtensionUnpacker unpacker(extension_path); 66 ExtensionUnpacker unpacker(extension_path);
48 if (unpacker.Run() && unpacker.DumpImagesToFile() && 67 if (unpacker.Run() && unpacker.DumpImagesToFile() &&
49 unpacker.DumpMessageCatalogsToFile()) { 68 unpacker.DumpMessageCatalogsToFile()) {
50 Send(new UtilityHostMsg_UnpackExtension_Succeeded( 69 Send(new UtilityHostMsg_UnpackExtension_Succeeded(
51 *unpacker.parsed_manifest())); 70 *unpacker.parsed_manifest()));
52 } else { 71 } else {
53 Send(new UtilityHostMsg_UnpackExtension_Failed(unpacker.error_message())); 72 Send(new UtilityHostMsg_UnpackExtension_Failed(unpacker.error_message()));
54 } 73 }
55 74
56 ChildProcess::current()->ReleaseProcess(); 75 ReleaseProcessIfNeeded();
57 } 76 }
58 77
59 void UtilityThread::OnUnpackWebResource(const std::string& resource_data) { 78 void UtilityThread::OnUnpackWebResource(const std::string& resource_data) {
60 // Parse json data. 79 // Parse json data.
61 // TODO(mrc): Add the possibility of a template that controls parsing, and 80 // TODO(mrc): Add the possibility of a template that controls parsing, and
62 // the ability to download and verify images. 81 // the ability to download and verify images.
63 WebResourceUnpacker unpacker(resource_data); 82 WebResourceUnpacker unpacker(resource_data);
64 if (unpacker.Run()) { 83 if (unpacker.Run()) {
65 Send(new UtilityHostMsg_UnpackWebResource_Succeeded( 84 Send(new UtilityHostMsg_UnpackWebResource_Succeeded(
66 *unpacker.parsed_json())); 85 *unpacker.parsed_json()));
67 } else { 86 } else {
68 Send(new UtilityHostMsg_UnpackWebResource_Failed( 87 Send(new UtilityHostMsg_UnpackWebResource_Failed(
69 unpacker.error_message())); 88 unpacker.error_message()));
70 } 89 }
71 90
72 ChildProcess::current()->ReleaseProcess(); 91 ReleaseProcessIfNeeded();
73 } 92 }
74 93
75 void UtilityThread::OnParseUpdateManifest(const std::string& xml) { 94 void UtilityThread::OnParseUpdateManifest(const std::string& xml) {
76 UpdateManifest manifest; 95 UpdateManifest manifest;
77 if (!manifest.Parse(xml)) { 96 if (!manifest.Parse(xml)) {
78 Send(new UtilityHostMsg_ParseUpdateManifest_Failed(manifest.errors())); 97 Send(new UtilityHostMsg_ParseUpdateManifest_Failed(manifest.errors()));
79 } else { 98 } else {
80 Send(new UtilityHostMsg_ParseUpdateManifest_Succeeded(manifest.results())); 99 Send(new UtilityHostMsg_ParseUpdateManifest_Succeeded(manifest.results()));
81 } 100 }
82 ChildProcess::current()->ReleaseProcess(); 101 ReleaseProcessIfNeeded();
83 } 102 }
84 103
85 void UtilityThread::OnDecodeImage( 104 void UtilityThread::OnDecodeImage(
86 const std::vector<unsigned char>& encoded_data) { 105 const std::vector<unsigned char>& encoded_data) {
87 webkit_glue::ImageDecoder decoder; 106 webkit_glue::ImageDecoder decoder;
88 const SkBitmap& decoded_image = decoder.Decode(&encoded_data[0], 107 const SkBitmap& decoded_image = decoder.Decode(&encoded_data[0],
89 encoded_data.size()); 108 encoded_data.size());
90 if (decoded_image.empty()) { 109 if (decoded_image.empty()) {
91 Send(new UtilityHostMsg_DecodeImage_Failed()); 110 Send(new UtilityHostMsg_DecodeImage_Failed());
92 } else { 111 } else {
93 Send(new UtilityHostMsg_DecodeImage_Succeeded(decoded_image)); 112 Send(new UtilityHostMsg_DecodeImage_Succeeded(decoded_image));
94 } 113 }
95 ChildProcess::current()->ReleaseProcess(); 114 ReleaseProcessIfNeeded();
96 } 115 }
97 116
98 117
99 void UtilityThread::OnRenderPDFPagesToMetafile( 118 void UtilityThread::OnRenderPDFPagesToMetafile(
100 base::PlatformFile pdf_file, 119 base::PlatformFile pdf_file,
101 const gfx::Rect& render_area, 120 const gfx::Rect& render_area,
102 int render_dpi, 121 int render_dpi,
103 const std::vector<printing::PageRange>& page_ranges) { 122 const std::vector<printing::PageRange>& page_ranges) {
104 bool succeeded = false; 123 bool succeeded = false;
105 #if defined(OS_WIN) 124 #if defined(OS_WIN)
106 printing::NativeMetafile metafile; 125 printing::NativeMetafile metafile;
107 int highest_rendered_page_number = 0; 126 int highest_rendered_page_number = 0;
108 succeeded = RenderPDFToWinMetafile(pdf_file, render_area, render_dpi, 127 succeeded = RenderPDFToWinMetafile(pdf_file, render_area, render_dpi,
109 page_ranges, &metafile, 128 page_ranges, &metafile,
110 &highest_rendered_page_number); 129 &highest_rendered_page_number);
111 if (succeeded) { 130 if (succeeded) {
112 Send(new UtilityHostMsg_RenderPDFPagesToMetafile_Succeeded(metafile, 131 Send(new UtilityHostMsg_RenderPDFPagesToMetafile_Succeeded(metafile,
113 highest_rendered_page_number)); 132 highest_rendered_page_number));
114 } 133 }
115 #endif // defined(OS_WIN) 134 #endif // defined(OS_WIN)
116 if (!succeeded) { 135 if (!succeeded) {
117 Send(new UtilityHostMsg_RenderPDFPagesToMetafile_Failed()); 136 Send(new UtilityHostMsg_RenderPDFPagesToMetafile_Failed());
118 } 137 }
119 ChildProcess::current()->ReleaseProcess(); 138 ReleaseProcessIfNeeded();
120 } 139 }
121 140
122 #if defined(OS_WIN) 141 #if defined(OS_WIN)
123 // Exported by pdf.dll 142 // Exported by pdf.dll
124 typedef bool (*RenderPDFPageToDCProc)( 143 typedef bool (*RenderPDFPageToDCProc)(
125 const unsigned char* pdf_buffer, int buffer_size, int page_number, HDC dc, 144 const unsigned char* pdf_buffer, int buffer_size, int page_number, HDC dc,
126 int dpi_x, int dpi_y, int bounds_origin_x, int bounds_origin_y, 145 int dpi_x, int dpi_y, int bounds_origin_x, int bounds_origin_y,
127 int bounds_width, int bounds_height, bool fit_to_bounds, 146 int bounds_width, int bounds_height, bool fit_to_bounds,
128 bool stretch_to_bounds, bool keep_aspect_ratio, bool center_in_bounds); 147 bool stretch_to_bounds, bool keep_aspect_ratio, bool center_in_bounds);
129 148
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 if (*highest_rendered_page_number < page_number) 265 if (*highest_rendered_page_number < page_number)
247 *highest_rendered_page_number = page_number; 266 *highest_rendered_page_number = page_number;
248 ret = true; 267 ret = true;
249 metafile->EndPage(); 268 metafile->EndPage();
250 } 269 }
251 } 270 }
252 metafile->CloseDc(); 271 metafile->CloseDc();
253 return ret; 272 return ret;
254 } 273 }
255 #endif // defined(OS_WIN) 274 #endif // defined(OS_WIN)
275
276 void UtilityThread::OnIDBKeysFromValuesAndKeyPath(
277 int id,
278 const std::vector<SerializedScriptValue>& serialized_script_values,
279 const string16& idb_key_path) {
280 std::vector<WebKit::WebSerializedScriptValue> web_values;
281 ConvertVector(serialized_script_values, &web_values);
282 std::vector<WebKit::WebIDBKey> web_keys;
283 bool error = webkit_glue::IDBKeysFromValuesAndKeyPath(
284 web_values, idb_key_path, &web_keys);
285 if (error) {
286 Send(new UtilityHostMsg_IDBKeysFromValuesAndKeyPath_Failed(id));
287 return;
288 }
289 std::vector<IndexedDBKey> keys;
290 ConvertVector(web_keys, &keys);
291 Send(new UtilityHostMsg_IDBKeysFromValuesAndKeyPath_Succeeded(id, keys));
292 ReleaseProcessIfNeeded();
293 }
294
295 void UtilityThread::OnBatchModeStarted() {
296 batch_mode_ = true;
297 }
298
299 void UtilityThread::OnBatchModeFinished() {
300 ChildProcess::current()->ReleaseProcess();
301 }
302
303 void UtilityThread::ReleaseProcessIfNeeded() {
304 if (!batch_mode_)
305 ChildProcess::current()->ReleaseProcess();
306 }
OLDNEW
« no previous file with comments | « chrome/utility/utility_thread.h ('k') | webkit/glue/idb_bindings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698