OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "build/build_config.h" | 5 #include "webkit/plugins/ppapi/ppb_pdf_impl.h" |
6 | |
7 #include "webkit/glue/plugins/pepper_private.h" | |
8 | |
9 #include "unicode/usearch.h" | |
10 | 6 |
11 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
12 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
13 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "build/build_config.h" |
14 #include "grit/webkit_resources.h" | 11 #include "grit/webkit_resources.h" |
15 #include "grit/webkit_strings.h" | 12 #include "grit/webkit_strings.h" |
16 #include "skia/ext/platform_canvas.h" | 13 #include "skia/ext/platform_canvas.h" |
17 #include "ppapi/c/pp_resource.h" | 14 #include "ppapi/c/pp_resource.h" |
18 #include "third_party/skia/include/core/SkBitmap.h" | 15 #include "third_party/skia/include/core/SkBitmap.h" |
| 16 #include "third_party/icu/public/i18n/unicode/usearch.h" |
19 #include "webkit/glue/webkit_glue.h" | 17 #include "webkit/glue/webkit_glue.h" |
20 #include "webkit/glue/plugins/pepper_image_data.h" | 18 #include "webkit/plugins/ppapi/plugin_delegate.h" |
21 #include "webkit/glue/plugins/pepper_plugin_delegate.h" | 19 #include "webkit/plugins/ppapi/plugin_instance.h" |
22 #include "webkit/glue/plugins/pepper_plugin_instance.h" | 20 #include "webkit/plugins/ppapi/plugin_module.h" |
23 #include "webkit/glue/plugins/pepper_plugin_module.h" | 21 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" |
24 #include "webkit/glue/plugins/pepper_var.h" | 22 #include "webkit/plugins/ppapi/ppb_pdf.h" |
25 #include "webkit/glue/plugins/ppb_private.h" | 23 #include "webkit/plugins/ppapi/var.h" |
26 #include "webkit/glue/plugins/pepper_var.h" | |
27 | 24 |
28 namespace pepper { | 25 namespace webkit { |
| 26 namespace plugins { |
| 27 namespace ppapi { |
29 | 28 |
30 #if defined(OS_LINUX) | 29 #if defined(OS_LINUX) |
31 class PrivateFontFile : public Resource { | 30 class PrivateFontFile : public Resource { |
32 public: | 31 public: |
33 PrivateFontFile(PluginModule* module, int fd) | 32 PrivateFontFile(PluginModule* module, int fd) |
34 : Resource(module), | 33 : Resource(module), |
35 fd_(fd) { | 34 fd_(fd) { |
36 } | 35 } |
37 virtual ~PrivateFontFile() { | 36 virtual ~PrivateFontFile() { |
38 } | 37 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 } | 112 } |
114 if (res_id == 0) | 113 if (res_id == 0) |
115 return 0; | 114 return 0; |
116 | 115 |
117 SkBitmap* res_bitmap = | 116 SkBitmap* res_bitmap = |
118 ResourceBundle::GetSharedInstance().GetBitmapNamed(res_id); | 117 ResourceBundle::GetSharedInstance().GetBitmapNamed(res_id); |
119 | 118 |
120 PluginModule* module = ResourceTracker::Get()->GetModule(module_id); | 119 PluginModule* module = ResourceTracker::Get()->GetModule(module_id); |
121 if (!module) | 120 if (!module) |
122 return 0; | 121 return 0; |
123 scoped_refptr<pepper::ImageData> image_data(new pepper::ImageData(module)); | 122 scoped_refptr<PPB_ImageData_Impl> image_data(new PPB_ImageData_Impl(module)); |
124 if (!image_data->Init(ImageData::GetNativeImageDataFormat(), | 123 if (!image_data->Init(PPB_ImageData_Impl::GetNativeImageDataFormat(), |
125 res_bitmap->width(), res_bitmap->height(), false)) { | 124 res_bitmap->width(), res_bitmap->height(), false)) { |
126 return 0; | 125 return 0; |
127 } | 126 } |
128 | 127 |
129 ImageDataAutoMapper mapper(image_data); | 128 ImageDataAutoMapper mapper(image_data); |
130 if (!mapper.is_valid()) | 129 if (!mapper.is_valid()) |
131 return 0; | 130 return 0; |
132 | 131 |
133 skia::PlatformCanvas* canvas = image_data->mapped_canvas(); | 132 skia::PlatformCanvas* canvas = image_data->mapped_canvas(); |
134 SkBitmap& ret_bitmap = | 133 SkBitmap& ret_bitmap = |
(...skipping 23 matching lines...) Expand all Loading... |
158 description->weight >= PP_FONTWEIGHT_BOLD, | 157 description->weight >= PP_FONTWEIGHT_BOLD, |
159 description->italic, | 158 description->italic, |
160 charset); | 159 charset); |
161 if (fd == -1) | 160 if (fd == -1) |
162 return 0; | 161 return 0; |
163 | 162 |
164 scoped_refptr<PrivateFontFile> font(new PrivateFontFile(module, fd)); | 163 scoped_refptr<PrivateFontFile> font(new PrivateFontFile(module, fd)); |
165 | 164 |
166 return font->GetReference(); | 165 return font->GetReference(); |
167 #else | 166 #else |
168 // For trusted pepper plugins, this is only needed in Linux since font loading | 167 // For trusted PPAPI plugins, this is only needed in Linux since font loading |
169 // on Windows and Mac works through the renderer sandbox. | 168 // on Windows and Mac works through the renderer sandbox. |
170 return 0; | 169 return 0; |
171 #endif | 170 #endif |
172 } | 171 } |
173 | 172 |
174 bool GetFontTableForPrivateFontFile(PP_Resource font_file, | 173 bool GetFontTableForPrivateFontFile(PP_Resource font_file, |
175 uint32_t table, | 174 uint32_t table, |
176 void* output, | 175 void* output, |
177 uint32_t* output_length) { | 176 uint32_t* output_length) { |
178 #if defined(OS_LINUX) | 177 #if defined(OS_LINUX) |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 void HistogramPDFPageCount(int count) { | 259 void HistogramPDFPageCount(int count) { |
261 UMA_HISTOGRAM_COUNTS_10000("PDF.PageCount", count); | 260 UMA_HISTOGRAM_COUNTS_10000("PDF.PageCount", count); |
262 } | 261 } |
263 | 262 |
264 void UserMetricsRecordAction(PP_Var action) { | 263 void UserMetricsRecordAction(PP_Var action) { |
265 scoped_refptr<StringVar> action_str(StringVar::FromPPVar(action)); | 264 scoped_refptr<StringVar> action_str(StringVar::FromPPVar(action)); |
266 if (action_str) | 265 if (action_str) |
267 webkit_glue::UserMetricsRecordAction(action_str->value()); | 266 webkit_glue::UserMetricsRecordAction(action_str->value()); |
268 } | 267 } |
269 | 268 |
270 const PPB_Private ppb_private = { | 269 const PPB_Pdf ppb_pdf = { |
271 &GetLocalizedString, | 270 &GetLocalizedString, |
272 &GetResourceImage, | 271 &GetResourceImage, |
273 &GetFontFileWithFallback, | 272 &GetFontFileWithFallback, |
274 &GetFontTableForPrivateFontFile, | 273 &GetFontTableForPrivateFontFile, |
275 &SearchString, | 274 &SearchString, |
276 &DidStartLoading, | 275 &DidStartLoading, |
277 &DidStopLoading, | 276 &DidStopLoading, |
278 &SetContentRestriction, | 277 &SetContentRestriction, |
279 &HistogramPDFPageCount, | 278 &HistogramPDFPageCount, |
280 &UserMetricsRecordAction | 279 &UserMetricsRecordAction |
281 }; | 280 }; |
282 | 281 |
283 } // namespace | 282 } // namespace |
284 | 283 |
285 // static | 284 // static |
286 const PPB_Private* Private::GetInterface() { | 285 const PPB_Pdf* PPB_Pdf_Impl::GetInterface() { |
287 return &ppb_private; | 286 return &ppb_pdf; |
288 } | 287 } |
289 | 288 |
290 #if defined(OS_LINUX) | 289 #if defined(OS_LINUX) |
291 bool PrivateFontFile::GetFontTable(uint32_t table, | 290 bool PrivateFontFile::GetFontTable(uint32_t table, |
292 void* output, | 291 void* output, |
293 uint32_t* output_length) { | 292 uint32_t* output_length) { |
294 size_t temp_size = static_cast<size_t>(*output_length); | 293 size_t temp_size = static_cast<size_t>(*output_length); |
295 bool rv = webkit_glue::GetFontTable( | 294 bool rv = webkit_glue::GetFontTable( |
296 fd_, table, static_cast<uint8_t*>(output), &temp_size); | 295 fd_, table, static_cast<uint8_t*>(output), &temp_size); |
297 *output_length = static_cast<uint32_t>(temp_size); | 296 *output_length = static_cast<uint32_t>(temp_size); |
298 return rv; | 297 return rv; |
299 } | 298 } |
300 #endif | 299 #endif |
301 | 300 |
302 } // namespace pepper | 301 } // namespace ppapi |
| 302 } // namespace plugins |
| 303 } // namespace webkit |
| 304 |
OLD | NEW |