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 "build/build_config.h" |
6 | 6 |
7 #include "webkit/glue/plugins/pepper_private.h" | 7 #include "webkit/glue/plugins/pepper_private.h" |
8 | 8 |
| 9 #include "app/resource_bundle.h" |
9 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "grit/webkit_resources.h" |
10 #include "grit/webkit_strings.h" | 12 #include "grit/webkit_strings.h" |
| 13 #include "skia/ext/platform_canvas.h" |
| 14 #include "third_party/skia/include/core/SkBitmap.h" |
11 #include "webkit/glue/webkit_glue.h" | 15 #include "webkit/glue/webkit_glue.h" |
| 16 #include "webkit/glue/plugins/pepper_image_data.h" |
12 #include "webkit/glue/plugins/pepper_plugin_module.h" | 17 #include "webkit/glue/plugins/pepper_plugin_module.h" |
13 #include "webkit/glue/plugins/pepper_var.h" | 18 #include "webkit/glue/plugins/pepper_var.h" |
14 #include "webkit/glue/plugins/ppb_private.h" | 19 #include "webkit/glue/plugins/ppb_private.h" |
15 | 20 |
16 namespace pepper { | 21 namespace pepper { |
17 | 22 |
18 #if defined(OS_LINUX) | 23 #if defined(OS_LINUX) |
19 class PrivateFontFile : public Resource { | 24 class PrivateFontFile : public Resource { |
20 public: | 25 public: |
21 PrivateFontFile(PluginModule* module, int fd) : Resource(module), fd_(fd) {} | 26 PrivateFontFile(PluginModule* module, int fd) : Resource(module), fd_(fd) {} |
22 virtual ~PrivateFontFile() {} | 27 virtual ~PrivateFontFile() {} |
23 | 28 |
24 // Resource overrides. | 29 // Resource overrides. |
25 PrivateFontFile* AsPrivateFontFile() { return this; } | 30 PrivateFontFile* AsPrivateFontFile() { return this; } |
26 | 31 |
27 bool GetFontTable(uint32_t table, | 32 bool GetFontTable(uint32_t table, |
28 void* output, | 33 void* output, |
29 uint32_t* output_length); | 34 uint32_t* output_length); |
30 | 35 |
31 private: | 36 private: |
32 int fd_; | 37 int fd_; |
33 }; | 38 }; |
34 #endif | 39 #endif |
35 | 40 |
36 namespace { | 41 namespace { |
37 | 42 |
| 43 struct ResourceImageInfo { |
| 44 PP_ResourceImage pp_id; |
| 45 int res_id; |
| 46 }; |
| 47 |
| 48 static const ResourceImageInfo kResourceImageMap[] = { |
| 49 { PP_RESOURCEIMAGE_PDF_BUTTON_FTH, IDR_PDF_BUTTON_FTH }, |
| 50 { PP_RESOURCEIMAGE_PDF_BUTTON_FTH_HOVER, IDR_PDF_BUTTON_FTH_HOVER }, |
| 51 { PP_RESOURCEIMAGE_PDF_BUTTON_FTH_PRESSED, IDR_PDF_BUTTON_FTH_PRESSED }, |
| 52 { PP_RESOURCEIMAGE_PDF_BUTTON_FTW, IDR_PDF_BUTTON_FTW }, |
| 53 { PP_RESOURCEIMAGE_PDF_BUTTON_FTW_HOVER, IDR_PDF_BUTTON_FTW_HOVER }, |
| 54 { PP_RESOURCEIMAGE_PDF_BUTTON_FTW_PRESSED, IDR_PDF_BUTTON_FTW_PRESSED }, |
| 55 { PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN, IDR_PDF_BUTTON_ZOOMIN }, |
| 56 { PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN_HOVER, IDR_PDF_BUTTON_ZOOMIN_HOVER }, |
| 57 { PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN_PRESSED, IDR_PDF_BUTTON_ZOOMIN_PRESSED }, |
| 58 { PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMOUT, IDR_PDF_BUTTON_ZOOMOUT }, |
| 59 { PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMOUT_HOVER, IDR_PDF_BUTTON_ZOOMOUT_HOVER }, |
| 60 { PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMOUT_PRESSED, |
| 61 IDR_PDF_BUTTON_ZOOMOUT_PRESSED }, |
| 62 { PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_0, IDR_PDF_THUMBNAIL_0 }, |
| 63 { PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_1, IDR_PDF_THUMBNAIL_1 }, |
| 64 { PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_2, IDR_PDF_THUMBNAIL_2 }, |
| 65 { PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_3, IDR_PDF_THUMBNAIL_3 }, |
| 66 { PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_4, IDR_PDF_THUMBNAIL_4 }, |
| 67 { PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_5, IDR_PDF_THUMBNAIL_5 }, |
| 68 { PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_6, IDR_PDF_THUMBNAIL_6 }, |
| 69 { PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_7, IDR_PDF_THUMBNAIL_7 }, |
| 70 { PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_8, IDR_PDF_THUMBNAIL_8 }, |
| 71 { PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_9, IDR_PDF_THUMBNAIL_9 }, |
| 72 { PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_NUM_BACKGROUND, |
| 73 IDR_PDF_THUMBNAIL_NUM_BACKGROUND }, |
| 74 }; |
| 75 |
38 PP_Var GetLocalizedString(PP_ResourceString string_id) { | 76 PP_Var GetLocalizedString(PP_ResourceString string_id) { |
39 std::string rv; | 77 std::string rv; |
40 if (string_id == PP_RESOURCESTRING_PDFGETPASSWORD) | 78 if (string_id == PP_RESOURCESTRING_PDFGETPASSWORD) |
41 rv = UTF16ToUTF8(webkit_glue::GetLocalizedString(IDS_PDF_NEED_PASSWORD)); | 79 rv = UTF16ToUTF8(webkit_glue::GetLocalizedString(IDS_PDF_NEED_PASSWORD)); |
42 | 80 |
43 return StringToPPVar(rv); | 81 return StringToPPVar(rv); |
44 } | 82 } |
45 | 83 |
| 84 PP_Resource GetResourceImage(PP_Module module_id, PP_ResourceImage image_id) { |
| 85 int res_id = 0; |
| 86 for (size_t i = 0; i < arraysize(kResourceImageMap); ++i) { |
| 87 if (kResourceImageMap[i].pp_id == image_id) { |
| 88 res_id = kResourceImageMap[i].res_id; |
| 89 break; |
| 90 } |
| 91 } |
| 92 if (res_id == 0) |
| 93 return NULL; |
| 94 |
| 95 SkBitmap* res_bitmap = |
| 96 ResourceBundle::GetSharedInstance().GetBitmapNamed(res_id); |
| 97 |
| 98 PluginModule* module = PluginModule::FromPPModule(module_id); |
| 99 if (!module) |
| 100 return NULL; |
| 101 scoped_refptr<pepper::ImageData> image_data(new pepper::ImageData(module)); |
| 102 if (!image_data->Init(PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
| 103 res_bitmap->width(), res_bitmap->height(), false)) { |
| 104 return NULL; |
| 105 } |
| 106 |
| 107 ImageDataAutoMapper mapper(image_data); |
| 108 if (!mapper.is_valid()) |
| 109 return NULL; |
| 110 |
| 111 skia::PlatformCanvas* canvas = image_data->mapped_canvas(); |
| 112 SkBitmap& ret_bitmap = |
| 113 const_cast<SkBitmap&>(canvas->getTopPlatformDevice().accessBitmap(true)); |
| 114 if (!res_bitmap->copyTo(&ret_bitmap, SkBitmap::kARGB_8888_Config, NULL)) { |
| 115 return NULL; |
| 116 } |
| 117 |
| 118 return image_data->GetReference(); |
| 119 } |
| 120 |
46 PP_Resource GetFontFileWithFallback( | 121 PP_Resource GetFontFileWithFallback( |
47 PP_Module module_id, | 122 PP_Module module_id, |
48 const PP_PrivateFontFileDescription* description) { | 123 const PP_PrivateFontFileDescription* description) { |
49 #if defined(OS_LINUX) | 124 #if defined(OS_LINUX) |
50 PluginModule* module = PluginModule::FromPPModule(module_id); | 125 PluginModule* module = PluginModule::FromPPModule(module_id); |
51 if (!module) | 126 if (!module) |
52 return NULL; | 127 return NULL; |
53 | 128 |
54 int fd = webkit_glue::MatchFontWithFallback(description->face, | 129 int fd = webkit_glue::MatchFontWithFallback(description->face, |
55 description->weight >= 700, | 130 description->weight >= 700, |
(...skipping 22 matching lines...) Expand all Loading... |
78 if (!font.get()) | 153 if (!font.get()) |
79 return false; | 154 return false; |
80 return font->GetFontTable(table, output, output_length); | 155 return font->GetFontTable(table, output, output_length); |
81 #else | 156 #else |
82 return false; | 157 return false; |
83 #endif | 158 #endif |
84 } | 159 } |
85 | 160 |
86 const PPB_Private ppb_private = { | 161 const PPB_Private ppb_private = { |
87 &GetLocalizedString, | 162 &GetLocalizedString, |
| 163 &GetResourceImage, |
88 &GetFontFileWithFallback, | 164 &GetFontFileWithFallback, |
89 &GetFontTableForPrivateFontFile, | 165 &GetFontTableForPrivateFontFile, |
90 }; | 166 }; |
91 | 167 |
92 } // namespace | 168 } // namespace |
93 | 169 |
94 // static | 170 // static |
95 const PPB_Private* Private::GetInterface() { | 171 const PPB_Private* Private::GetInterface() { |
96 return &ppb_private; | 172 return &ppb_private; |
97 } | 173 } |
98 | 174 |
99 #if defined(OS_LINUX) | 175 #if defined(OS_LINUX) |
100 bool PrivateFontFile::GetFontTable(uint32_t table, | 176 bool PrivateFontFile::GetFontTable(uint32_t table, |
101 void* output, | 177 void* output, |
102 uint32_t* output_length) { | 178 uint32_t* output_length) { |
103 size_t temp_size = static_cast<size_t>(*output_length); | 179 size_t temp_size = static_cast<size_t>(*output_length); |
104 bool rv = webkit_glue::GetFontTable( | 180 bool rv = webkit_glue::GetFontTable( |
105 fd_, table, static_cast<uint8_t*>(output), &temp_size); | 181 fd_, table, static_cast<uint8_t*>(output), &temp_size); |
106 *output_length = static_cast<uint32_t>(temp_size); | 182 *output_length = static_cast<uint32_t>(temp_size); |
107 return rv; | 183 return rv; |
108 } | 184 } |
109 #endif | 185 #endif |
110 | 186 |
111 } // namespace pepper | 187 } // namespace pepper |
OLD | NEW |