OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/renderer/chrome_ppb_pdf_impl.h" | 5 #include "chrome/renderer/chrome_ppb_pdf_impl.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 #include "content/common/view_messages.h" | 10 #include "content/common/view_messages.h" |
11 #include "content/renderer/render_thread.h" | 11 #include "content/renderer/render_thread.h" |
12 #include "grit/webkit_resources.h" | 12 #include "grit/webkit_resources.h" |
13 #include "grit/webkit_strings.h" | 13 #include "grit/webkit_strings.h" |
14 #include "ppapi/c/pp_resource.h" | 14 #include "ppapi/c/pp_resource.h" |
15 #include "ppapi/c/private/ppb_pdf.h" | 15 #include "ppapi/c/private/ppb_pdf.h" |
16 #include "ppapi/shared_impl/resource.h" | 16 #include "ppapi/shared_impl/resource.h" |
17 #include "ppapi/shared_impl/resource_tracker.h" | 17 #include "ppapi/shared_impl/resource_tracker.h" |
18 #include "ppapi/shared_impl/tracker_base.h" | 18 #include "ppapi/shared_impl/tracker_base.h" |
19 #include "ppapi/shared_impl/var.h" | 19 #include "ppapi/shared_impl/var.h" |
20 #include "skia/ext/platform_canvas.h" | 20 #include "skia/ext/platform_canvas.h" |
21 #include "third_party/skia/include/core/SkBitmap.h" | 21 #include "third_party/skia/include/core/SkBitmap.h" |
22 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
23 #include "ui/base/resource/resource_bundle.h" | 23 #include "ui/base/resource/resource_bundle.h" |
24 #include "unicode/usearch.h" | 24 #include "unicode/usearch.h" |
25 #include "webkit/glue/webkit_glue.h" | 25 #include "webkit/glue/webkit_glue.h" |
26 #include "webkit/plugins/ppapi/plugin_delegate.h" | 26 #include "webkit/plugins/ppapi/plugin_delegate.h" |
27 #include "webkit/plugins/ppapi/plugin_module.h" | 27 #include "webkit/plugins/ppapi/plugin_module.h" |
28 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 28 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
29 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" | 29 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" |
30 #include "webkit/plugins/ppapi/resource_tracker.h" | |
30 | 31 |
31 namespace chrome { | 32 namespace chrome { |
32 | 33 |
33 #if defined(OS_LINUX) | 34 #if defined(OS_LINUX) |
34 class PrivateFontFile : public webkit::ppapi::Resource { | 35 class PrivateFontFile : public ppapi::Resource { |
35 public: | 36 public: |
36 PrivateFontFile(webkit::ppapi::PluginInstance* instance, int fd) | 37 PrivateFontFile(PP_Instance instance, int fd) : Resource(instance), fd_(fd) { |
37 : webkit::ppapi::Resource(instance), | |
38 fd_(fd) { | |
39 } | 38 } |
40 virtual ~PrivateFontFile() { | 39 virtual ~PrivateFontFile() { |
41 } | 40 } |
42 | 41 |
43 bool GetFontTable(uint32_t table, | 42 bool GetFontTable(uint32_t table, |
44 void* output, | 43 void* output, |
45 uint32_t* output_length) { | 44 uint32_t* output_length) { |
46 size_t temp_size = static_cast<size_t>(*output_length); | 45 size_t temp_size = static_cast<size_t>(*output_length); |
47 bool rv = webkit_glue::GetFontTable( | 46 bool rv = webkit_glue::GetFontTable( |
48 fd_, table, static_cast<uint8_t*>(output), &temp_size); | 47 fd_, table, static_cast<uint8_t*>(output), &temp_size); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 rv = UTF16ToUTF8(l10n_util::GetStringUTF16(IDS_PDF_PAGE_LOAD_FAILED)); | 126 rv = UTF16ToUTF8(l10n_util::GetStringUTF16(IDS_PDF_PAGE_LOAD_FAILED)); |
128 } else if (string_id == PP_RESOURCESTRING_PDFPROGRESSLOADING) { | 127 } else if (string_id == PP_RESOURCESTRING_PDFPROGRESSLOADING) { |
129 rv = UTF16ToUTF8(l10n_util::GetStringUTF16(IDS_PDF_PROGRESS_LOADING)); | 128 rv = UTF16ToUTF8(l10n_util::GetStringUTF16(IDS_PDF_PROGRESS_LOADING)); |
130 } else { | 129 } else { |
131 NOTREACHED(); | 130 NOTREACHED(); |
132 } | 131 } |
133 | 132 |
134 return ppapi::StringVar::StringToPPVar(instance->module()->pp_module(), rv); | 133 return ppapi::StringVar::StringToPPVar(instance->module()->pp_module(), rv); |
135 } | 134 } |
136 | 135 |
137 PP_Resource GetResourceImage(PP_Instance instance_id, | 136 PP_Resource GetResourceImage(PP_Instance instance, |
138 PP_ResourceImage image_id) { | 137 PP_ResourceImage image_id) { |
139 int res_id = 0; | 138 int res_id = 0; |
140 for (size_t i = 0; i < arraysize(kResourceImageMap); ++i) { | 139 for (size_t i = 0; i < arraysize(kResourceImageMap); ++i) { |
141 if (kResourceImageMap[i].pp_id == image_id) { | 140 if (kResourceImageMap[i].pp_id == image_id) { |
142 res_id = kResourceImageMap[i].res_id; | 141 res_id = kResourceImageMap[i].res_id; |
143 break; | 142 break; |
144 } | 143 } |
145 } | 144 } |
146 if (res_id == 0) | 145 if (res_id == 0) |
147 return 0; | 146 return 0; |
148 | 147 |
149 SkBitmap* res_bitmap = | 148 SkBitmap* res_bitmap = |
150 ResourceBundle::GetSharedInstance().GetBitmapNamed(res_id); | 149 ResourceBundle::GetSharedInstance().GetBitmapNamed(res_id); |
151 | 150 |
152 webkit::ppapi::PluginInstance* instance = | 151 // Validate the instance. |
153 webkit::ppapi::ResourceTracker::Get()->GetInstance(instance_id); | 152 if (!webkit::ppapi::ResourceTracker::Get()->GetInstance(instance)) |
viettrungluu
2011/08/22 23:19:46
I really wish we had a consistent convention for i
brettw
2011/08/23 17:16:28
This patch generally removes uses of PluginInstanc
| |
154 if (!instance) | |
155 return 0; | 153 return 0; |
156 scoped_refptr<webkit::ppapi::PPB_ImageData_Impl> image_data( | 154 scoped_refptr<webkit::ppapi::PPB_ImageData_Impl> image_data( |
157 new webkit::ppapi::PPB_ImageData_Impl(instance)); | 155 new webkit::ppapi::PPB_ImageData_Impl(instance)); |
158 if (!image_data->Init( | 156 if (!image_data->Init( |
159 webkit::ppapi::PPB_ImageData_Impl::GetNativeImageDataFormat(), | 157 webkit::ppapi::PPB_ImageData_Impl::GetNativeImageDataFormat(), |
160 res_bitmap->width(), res_bitmap->height(), false)) { | 158 res_bitmap->width(), res_bitmap->height(), false)) { |
161 return 0; | 159 return 0; |
162 } | 160 } |
163 | 161 |
164 webkit::ppapi::ImageDataAutoMapper mapper(image_data); | 162 webkit::ppapi::ImageDataAutoMapper mapper(image_data); |
165 if (!mapper.is_valid()) | 163 if (!mapper.is_valid()) |
166 return 0; | 164 return 0; |
167 | 165 |
168 skia::PlatformCanvas* canvas = image_data->mapped_canvas(); | 166 skia::PlatformCanvas* canvas = image_data->mapped_canvas(); |
169 // Note: Do not skBitmap::copyTo the canvas bitmap directly because it will | 167 // Note: Do not skBitmap::copyTo the canvas bitmap directly because it will |
170 // ignore the allocated pixels in shared memory and re-allocate a new buffer. | 168 // ignore the allocated pixels in shared memory and re-allocate a new buffer. |
171 skia::GetTopDevice(*canvas)->writePixels(*res_bitmap, 0, 0); | 169 skia::GetTopDevice(*canvas)->writePixels(*res_bitmap, 0, 0); |
172 | 170 |
173 return image_data->GetReference(); | 171 return image_data->GetReference(); |
174 } | 172 } |
175 | 173 |
176 PP_Resource GetFontFileWithFallback( | 174 PP_Resource GetFontFileWithFallback( |
177 PP_Instance instance_id, | 175 PP_Instance instance, |
178 const PP_FontDescription_Dev* description, | 176 const PP_FontDescription_Dev* description, |
179 PP_PrivateFontCharset charset) { | 177 PP_PrivateFontCharset charset) { |
180 #if defined(OS_LINUX) | 178 #if defined(OS_LINUX) |
181 webkit::ppapi::PluginInstance* instance = | 179 // Validate the instance before using it below. |
182 webkit::ppapi::ResourceTracker::Get()->GetInstance(instance_id); | 180 if (!webkit::ppapi::ResourceTracker::Get()->GetInstance(instance)) |
183 if (!instance) | |
184 return 0; | 181 return 0; |
185 | 182 |
186 scoped_refptr<ppapi::StringVar> face_name(ppapi::StringVar::FromPPVar( | 183 scoped_refptr<ppapi::StringVar> face_name(ppapi::StringVar::FromPPVar( |
187 description->face)); | 184 description->face)); |
188 if (!face_name) | 185 if (!face_name) |
189 return 0; | 186 return 0; |
190 | 187 |
191 int fd = webkit_glue::MatchFontWithFallback( | 188 int fd = webkit_glue::MatchFontWithFallback( |
192 face_name->value().c_str(), | 189 face_name->value().c_str(), |
193 description->weight >= PP_FONTWEIGHT_BOLD, | 190 description->weight >= PP_FONTWEIGHT_BOLD, |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
346 &SaveAs | 343 &SaveAs |
347 }; | 344 }; |
348 | 345 |
349 // static | 346 // static |
350 const PPB_PDF* PPB_PDF_Impl::GetInterface() { | 347 const PPB_PDF* PPB_PDF_Impl::GetInterface() { |
351 return &ppb_pdf; | 348 return &ppb_pdf; |
352 } | 349 } |
353 | 350 |
354 } // namespace chrome | 351 } // namespace chrome |
355 | 352 |
OLD | NEW |