| 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 "components/pdf/renderer/ppb_pdf_impl.h" | 5 #include "components/pdf/renderer/ppb_pdf_impl.h" |
| 6 | 6 |
| 7 #include "base/files/scoped_file.h" | 7 #include "base/files/scoped_file.h" |
| 8 #include "base/lazy_instance.h" |
| 8 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 9 #include "base/numerics/safe_conversions.h" | 10 #include "base/numerics/safe_conversions.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/threading/thread_local.h" |
| 11 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 12 #include "components/pdf/common/pdf_messages.h" | 14 #include "components/pdf/common/pdf_messages.h" |
| 13 #include "components/pdf/renderer/pdf_resource_util.h" | 15 #include "components/pdf/renderer/pdf_resource_util.h" |
| 14 #include "content/public/common/child_process_sandbox_support_linux.h" | 16 #include "content/public/common/child_process_sandbox_support_linux.h" |
| 15 #include "content/public/common/referrer.h" | 17 #include "content/public/common/referrer.h" |
| 16 #include "content/public/renderer/pepper_plugin_instance.h" | 18 #include "content/public/renderer/pepper_plugin_instance.h" |
| 17 #include "content/public/renderer/render_thread.h" | 19 #include "content/public/renderer/render_thread.h" |
| 18 #include "content/public/renderer/render_view.h" | 20 #include "content/public/renderer/render_view.h" |
| 19 #include "gin/public/isolate_holder.h" | 21 #include "gin/public/isolate_holder.h" |
| 20 #include "ppapi/c/pp_resource.h" | 22 #include "ppapi/c/pp_resource.h" |
| 21 #include "ppapi/c/private/ppb_pdf.h" | 23 #include "ppapi/c/private/ppb_pdf.h" |
| 22 #include "ppapi/c/trusted/ppb_browser_font_trusted.h" | 24 #include "ppapi/c/trusted/ppb_browser_font_trusted.h" |
| 23 #include "ppapi/shared_impl/ppapi_globals.h" | 25 #include "ppapi/shared_impl/ppapi_globals.h" |
| 24 #include "ppapi/shared_impl/resource.h" | 26 #include "ppapi/shared_impl/resource.h" |
| 25 #include "ppapi/shared_impl/resource_tracker.h" | 27 #include "ppapi/shared_impl/resource_tracker.h" |
| 26 #include "ppapi/shared_impl/var.h" | 28 #include "ppapi/shared_impl/var.h" |
| 27 #include "third_party/WebKit/public/web/WebDocument.h" | 29 #include "third_party/WebKit/public/web/WebDocument.h" |
| 28 #include "third_party/WebKit/public/web/WebElement.h" | 30 #include "third_party/WebKit/public/web/WebElement.h" |
| 29 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 31 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 30 #include "third_party/WebKit/public/web/WebPluginContainer.h" | 32 #include "third_party/WebKit/public/web/WebPluginContainer.h" |
| 31 #include "third_party/WebKit/public/web/WebView.h" | 33 #include "third_party/WebKit/public/web/WebView.h" |
| 32 #include "third_party/icu/source/i18n/unicode/usearch.h" | 34 #include "third_party/icu/source/i18n/unicode/usearch.h" |
| 33 #include "third_party/skia/include/core/SkBitmap.h" | 35 #include "third_party/skia/include/core/SkBitmap.h" |
| 34 | 36 |
| 35 namespace pdf { | 37 namespace pdf { |
| 36 namespace { | 38 namespace { |
| 37 | 39 |
| 38 PPB_PDF_Impl::PrintClient* g_print_client = NULL; | 40 // --single-process model may fail in CHECK(!g_print_client) if there exist |
| 41 // more than two RenderThreads, so here we use TLS for g_print_client. |
| 42 // See http://crbug.com/457580. |
| 43 base::LazyInstance<base::ThreadLocalPointer<PPB_PDF_Impl::PrintClient> >::Leaky |
| 44 g_print_client_tls = LAZY_INSTANCE_INITIALIZER; |
| 39 | 45 |
| 40 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 46 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| 41 class PrivateFontFile : public ppapi::Resource { | 47 class PrivateFontFile : public ppapi::Resource { |
| 42 public: | 48 public: |
| 43 PrivateFontFile(PP_Instance instance, int fd) | 49 PrivateFontFile(PP_Instance instance, int fd) |
| 44 : Resource(ppapi::OBJECT_IS_IMPL, instance), fd_(fd) {} | 50 : Resource(ppapi::OBJECT_IS_IMPL, instance), fd_(fd) {} |
| 45 | 51 |
| 46 bool GetFontTable(uint32_t table, void* output, uint32_t* output_length) { | 52 bool GetFontTable(uint32_t table, void* output, uint32_t* output_length) { |
| 47 size_t temp_size = static_cast<size_t>(*output_length); | 53 size_t temp_size = static_cast<size_t>(*output_length); |
| 48 bool rv = content::GetFontTable(fd_.get(), | 54 bool rv = content::GetFontTable(fd_.get(), |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 | 256 |
| 251 void Print(PP_Instance instance) { | 257 void Print(PP_Instance instance) { |
| 252 PPB_PDF_Impl::InvokePrintingForInstance(instance); | 258 PPB_PDF_Impl::InvokePrintingForInstance(instance); |
| 253 } | 259 } |
| 254 | 260 |
| 255 PP_Bool IsFeatureEnabled(PP_Instance instance, PP_PDFFeature feature) { | 261 PP_Bool IsFeatureEnabled(PP_Instance instance, PP_PDFFeature feature) { |
| 256 switch (feature) { | 262 switch (feature) { |
| 257 case PP_PDFFEATURE_HIDPI: | 263 case PP_PDFFEATURE_HIDPI: |
| 258 return PP_TRUE; | 264 return PP_TRUE; |
| 259 case PP_PDFFEATURE_PRINTING: | 265 case PP_PDFFEATURE_PRINTING: |
| 260 return (g_print_client && g_print_client->IsPrintingEnabled(instance)) | 266 return (g_print_client_tls.Pointer()->Get() && |
| 267 g_print_client_tls.Pointer()->Get()->IsPrintingEnabled(instance)) |
| 261 ? PP_TRUE | 268 ? PP_TRUE |
| 262 : PP_FALSE; | 269 : PP_FALSE; |
| 263 } | 270 } |
| 264 return PP_FALSE; | 271 return PP_FALSE; |
| 265 } | 272 } |
| 266 | 273 |
| 267 PP_Resource GetResourceImageForScale(PP_Instance instance_id, | 274 PP_Resource GetResourceImageForScale(PP_Instance instance_id, |
| 268 PP_ResourceImage image_id, | 275 PP_ResourceImage image_id, |
| 269 float scale) { | 276 float scale) { |
| 270 // Validate the instance. | 277 // Validate the instance. |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 | 371 |
| 365 } // namespace | 372 } // namespace |
| 366 | 373 |
| 367 // static | 374 // static |
| 368 const PPB_PDF* PPB_PDF_Impl::GetInterface() { | 375 const PPB_PDF* PPB_PDF_Impl::GetInterface() { |
| 369 return &ppb_pdf; | 376 return &ppb_pdf; |
| 370 } | 377 } |
| 371 | 378 |
| 372 // static | 379 // static |
| 373 bool PPB_PDF_Impl::InvokePrintingForInstance(PP_Instance instance_id) { | 380 bool PPB_PDF_Impl::InvokePrintingForInstance(PP_Instance instance_id) { |
| 374 return g_print_client ? g_print_client->Print(instance_id) : false; | 381 return g_print_client_tls.Pointer()->Get() |
| 382 ? g_print_client_tls.Pointer()->Get()->Print(instance_id) |
| 383 : false; |
| 375 } | 384 } |
| 376 | 385 |
| 377 void PPB_PDF_Impl::SetPrintClient(PPB_PDF_Impl::PrintClient* client) { | 386 void PPB_PDF_Impl::SetPrintClient(PPB_PDF_Impl::PrintClient* client) { |
| 378 CHECK(!g_print_client) << "There should only be a single PrintClient."; | 387 CHECK(!g_print_client_tls.Pointer()->Get()) |
| 379 g_print_client = client; | 388 << "There should only be a single PrintClient for one RenderThread."; |
| 389 g_print_client_tls.Pointer()->Set(client); |
| 380 } | 390 } |
| 381 | 391 |
| 382 } // namespace pdf | 392 } // namespace pdf |
| OLD | NEW |