OLD | NEW |
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/renderer/pepper/ppb_pdf_impl.h" | 5 #include "chrome/renderer/pepper/ppb_pdf_impl.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
12 #include "chrome/common/render_messages.h" | 12 #include "chrome/common/render_messages.h" |
13 #include "chrome/renderer/print_web_view_helper.h" | 13 #include "chrome/renderer/print_web_view_helper.h" |
14 #include "content/public/common/child_process_sandbox_support_linux.h" | 14 #include "content/public/common/child_process_sandbox_support_linux.h" |
15 #include "content/public/common/content_client.h" | 15 #include "content/public/common/content_client.h" |
16 #include "content/public/renderer/render_thread.h" | 16 #include "content/public/renderer/render_thread.h" |
17 #include "content/public/renderer/render_view.h" | 17 #include "content/public/renderer/render_view.h" |
18 #include "grit/webkit_resources.h" | 18 #include "grit/webkit_resources.h" |
19 #include "grit/webkit_strings.h" | 19 #include "grit/webkit_strings.h" |
20 #include "ppapi/c/pp_resource.h" | |
21 #include "ppapi/c/private/ppb_pdf.h" | 20 #include "ppapi/c/private/ppb_pdf.h" |
22 #include "ppapi/shared_impl/resource.h" | 21 #include "ppapi/shared_impl/resource.h" |
23 #include "ppapi/shared_impl/resource_tracker.h" | 22 #include "ppapi/shared_impl/resource_tracker.h" |
24 #include "ppapi/shared_impl/var.h" | 23 #include "ppapi/shared_impl/var.h" |
25 #include "skia/ext/platform_canvas.h" | 24 #include "skia/ext/platform_canvas.h" |
26 #include "third_party/skia/include/core/SkBitmap.h" | 25 #include "third_party/skia/include/core/SkBitmap.h" |
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 rv = UTF16ToUTF8(l10n_util::GetStringUTF16(IDS_PDF_PAGE_LOAD_FAILED)); | 148 rv = UTF16ToUTF8(l10n_util::GetStringUTF16(IDS_PDF_PAGE_LOAD_FAILED)); |
150 } else if (string_id == PP_RESOURCESTRING_PDFPROGRESSLOADING) { | 149 } else if (string_id == PP_RESOURCESTRING_PDFPROGRESSLOADING) { |
151 rv = UTF16ToUTF8(l10n_util::GetStringUTF16(IDS_PDF_PROGRESS_LOADING)); | 150 rv = UTF16ToUTF8(l10n_util::GetStringUTF16(IDS_PDF_PROGRESS_LOADING)); |
152 } else { | 151 } else { |
153 NOTREACHED(); | 152 NOTREACHED(); |
154 } | 153 } |
155 | 154 |
156 return ppapi::StringVar::StringToPPVar(rv); | 155 return ppapi::StringVar::StringToPPVar(rv); |
157 } | 156 } |
158 | 157 |
159 PP_Resource GetFontFileWithFallback( | |
160 PP_Instance instance_id, | |
161 const PP_FontDescription_Dev* description, | |
162 PP_PrivateFontCharset charset) { | |
163 #if defined(OS_LINUX) || defined(OS_OPENBSD) | |
164 // Validate the instance before using it below. | |
165 if (!content::GetHostGlobals()->GetInstance(instance_id)) | |
166 return 0; | |
167 | |
168 scoped_refptr<ppapi::StringVar> face_name(ppapi::StringVar::FromPPVar( | |
169 description->face)); | |
170 if (!face_name) | |
171 return 0; | |
172 | |
173 int fd = content::MatchFontWithFallback( | |
174 face_name->value().c_str(), | |
175 description->weight >= PP_FONTWEIGHT_BOLD, | |
176 description->italic, | |
177 charset); | |
178 if (fd == -1) | |
179 return 0; | |
180 | |
181 scoped_refptr<PrivateFontFile> font(new PrivateFontFile(instance_id, fd)); | |
182 | |
183 return font->GetReference(); | |
184 #else | |
185 // For trusted PPAPI plugins, this is only needed in Linux since font loading | |
186 // on Windows and Mac works through the renderer sandbox. | |
187 return 0; | |
188 #endif | |
189 } | |
190 | |
191 bool GetFontTableForPrivateFontFile(PP_Resource font_file, | |
192 uint32_t table, | |
193 void* output, | |
194 uint32_t* output_length) { | |
195 #if defined(OS_LINUX) || defined(OS_OPENBSD) | |
196 ppapi::Resource* resource = | |
197 PpapiGlobals::Get()->GetResourceTracker()->GetResource(font_file); | |
198 if (!resource) | |
199 return false; | |
200 | |
201 PrivateFontFile* font = static_cast<PrivateFontFile*>(resource); | |
202 return font->GetFontTable(table, output, output_length); | |
203 #else | |
204 return false; | |
205 #endif | |
206 } | |
207 | |
208 void SearchString(PP_Instance instance, | 158 void SearchString(PP_Instance instance, |
209 const unsigned short* input_string, | 159 const unsigned short* input_string, |
210 const unsigned short* input_term, | 160 const unsigned short* input_term, |
211 bool case_sensitive, | 161 bool case_sensitive, |
212 PP_PrivateFindResult** results, | 162 PP_PrivateFindResult** results, |
213 int* count) { | 163 int* count) { |
214 const char16* string = reinterpret_cast<const char16*>(input_string); | 164 const char16* string = reinterpret_cast<const char16*>(input_string); |
215 const char16* term = reinterpret_cast<const char16*>(input_term); | 165 const char16* term = reinterpret_cast<const char16*>(input_term); |
216 | 166 |
217 UErrorCode status = U_ZERO_ERROR; | 167 UErrorCode status = U_ZERO_ERROR; |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 } | 330 } |
381 | 331 |
382 PP_Resource GetResourceImage(PP_Instance instance_id, | 332 PP_Resource GetResourceImage(PP_Instance instance_id, |
383 PP_ResourceImage image_id) { | 333 PP_ResourceImage image_id) { |
384 return GetResourceImageForScale(instance_id, image_id, 1.0f); | 334 return GetResourceImageForScale(instance_id, image_id, 1.0f); |
385 } | 335 } |
386 | 336 |
387 const PPB_PDF ppb_pdf = { | 337 const PPB_PDF ppb_pdf = { |
388 &GetLocalizedString, | 338 &GetLocalizedString, |
389 &GetResourceImage, | 339 &GetResourceImage, |
390 &GetFontFileWithFallback, | 340 &PPB_PDF_Impl::GetFontFileWithFallback, |
391 &GetFontTableForPrivateFontFile, | 341 &PPB_PDF_Impl::GetFontTableForPrivateFontFile, |
392 &SearchString, | 342 &SearchString, |
393 &DidStartLoading, | 343 &DidStartLoading, |
394 &DidStopLoading, | 344 &DidStopLoading, |
395 &SetContentRestriction, | 345 &SetContentRestriction, |
396 &HistogramPDFPageCount, | 346 &HistogramPDFPageCount, |
397 &UserMetricsRecordAction, | 347 &UserMetricsRecordAction, |
398 &HasUnsupportedFeature, | 348 &HasUnsupportedFeature, |
399 &SaveAs, | 349 &SaveAs, |
400 &PPB_PDF_Impl::InvokePrintingForInstance, | 350 &PPB_PDF_Impl::InvokePrintingForInstance, |
401 &IsFeatureEnabled, | 351 &IsFeatureEnabled, |
402 &GetResourceImageForScale | 352 &GetResourceImageForScale |
403 }; | 353 }; |
404 | 354 |
405 } // namespace | 355 } // namespace |
406 | 356 |
407 // static | 357 // static |
408 const PPB_PDF* PPB_PDF_Impl::GetInterface() { | 358 const PPB_PDF* PPB_PDF_Impl::GetInterface() { |
409 return &ppb_pdf; | 359 return &ppb_pdf; |
410 } | 360 } |
411 | 361 |
412 // static | 362 // static |
| 363 PP_Resource PPB_PDF_Impl::GetFontFileWithFallback( |
| 364 PP_Instance instance_id, |
| 365 const PP_FontDescription_Dev* description, |
| 366 PP_PrivateFontCharset charset) { |
| 367 #if defined(OS_LINUX) || defined(OS_OPENBSD) |
| 368 // Validate the instance before using it below. |
| 369 if (!content::GetHostGlobals()->GetInstance(instance_id)) |
| 370 return 0; |
| 371 |
| 372 scoped_refptr<ppapi::StringVar> face_name(ppapi::StringVar::FromPPVar( |
| 373 description->face)); |
| 374 if (!face_name) |
| 375 return 0; |
| 376 |
| 377 int fd = content::MatchFontWithFallback( |
| 378 face_name->value().c_str(), |
| 379 description->weight >= PP_FONTWEIGHT_BOLD, |
| 380 description->italic, |
| 381 charset); |
| 382 if (fd == -1) |
| 383 return 0; |
| 384 |
| 385 scoped_refptr<PrivateFontFile> font(new PrivateFontFile(instance_id, fd)); |
| 386 |
| 387 return font->GetReference(); |
| 388 #else |
| 389 // For trusted PPAPI plugins, this is only needed in Linux since font loading |
| 390 // on Windows and Mac works through the renderer sandbox. |
| 391 return 0; |
| 392 #endif |
| 393 } |
| 394 |
| 395 // static |
| 396 bool PPB_PDF_Impl::GetFontTableForPrivateFontFile(PP_Resource font_file, |
| 397 uint32_t table, |
| 398 void* output, |
| 399 uint32_t* output_length) { |
| 400 #if defined(OS_LINUX) || defined(OS_OPENBSD) |
| 401 ppapi::Resource* resource = |
| 402 PpapiGlobals::Get()->GetResourceTracker()->GetResource(font_file); |
| 403 if (!resource) |
| 404 return false; |
| 405 |
| 406 PrivateFontFile* font = static_cast<PrivateFontFile*>(resource); |
| 407 return font->GetFontTable(table, output, output_length); |
| 408 #else |
| 409 return false; |
| 410 #endif |
| 411 } |
| 412 |
| 413 // static |
413 void PPB_PDF_Impl::InvokePrintingForInstance(PP_Instance instance_id) { | 414 void PPB_PDF_Impl::InvokePrintingForInstance(PP_Instance instance_id) { |
414 #if defined(ENABLE_PRINTING) | 415 #if defined(ENABLE_PRINTING) |
415 PluginInstance* instance = HostGlobals::Get()->GetInstance(instance_id); | 416 PluginInstance* instance = HostGlobals::Get()->GetInstance(instance_id); |
416 if (!instance) | 417 if (!instance) |
417 return; | 418 return; |
418 | 419 |
419 WebKit::WebElement element = instance->container()->element(); | 420 WebKit::WebElement element = instance->container()->element(); |
420 WebKit::WebView* view = element.document().frame()->view(); | 421 WebKit::WebView* view = element.document().frame()->view(); |
421 content::RenderView* render_view = content::RenderView::FromWebView(view); | 422 content::RenderView* render_view = content::RenderView::FromWebView(view); |
422 | 423 |
423 PrintWebViewHelper* print_view_helper = PrintWebViewHelper::Get(render_view); | 424 PrintWebViewHelper* print_view_helper = PrintWebViewHelper::Get(render_view); |
424 if (print_view_helper) | 425 if (print_view_helper) |
425 print_view_helper->PrintNode(element); | 426 print_view_helper->PrintNode(element); |
426 #endif | 427 #endif |
427 } | 428 } |
OLD | NEW |