Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Side by Side Diff: components/pdf/renderer/ppb_pdf_impl.cc

Issue 916003002: Fix a crash for ppb_pdf_impl.cc under single process model (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 base::LazyInstance<base::ThreadLocalPointer<PPB_PDF_Impl::PrintClient> >::Leaky
41 g_print_client_tls = LAZY_INSTANCE_INITIALIZER;
dmichael (off chromium) 2015/02/11 17:35:00 Please add a comment briefly explaining why we're
39 42
40 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) 43 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
41 class PrivateFontFile : public ppapi::Resource { 44 class PrivateFontFile : public ppapi::Resource {
42 public: 45 public:
43 PrivateFontFile(PP_Instance instance, int fd) 46 PrivateFontFile(PP_Instance instance, int fd)
44 : Resource(ppapi::OBJECT_IS_IMPL, instance), fd_(fd) {} 47 : Resource(ppapi::OBJECT_IS_IMPL, instance), fd_(fd) {}
45 48
46 bool GetFontTable(uint32_t table, void* output, uint32_t* output_length) { 49 bool GetFontTable(uint32_t table, void* output, uint32_t* output_length) {
47 size_t temp_size = static_cast<size_t>(*output_length); 50 size_t temp_size = static_cast<size_t>(*output_length);
48 bool rv = content::GetFontTable(fd_.get(), 51 bool rv = content::GetFontTable(fd_.get(),
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 253
251 void Print(PP_Instance instance) { 254 void Print(PP_Instance instance) {
252 PPB_PDF_Impl::InvokePrintingForInstance(instance); 255 PPB_PDF_Impl::InvokePrintingForInstance(instance);
253 } 256 }
254 257
255 PP_Bool IsFeatureEnabled(PP_Instance instance, PP_PDFFeature feature) { 258 PP_Bool IsFeatureEnabled(PP_Instance instance, PP_PDFFeature feature) {
256 switch (feature) { 259 switch (feature) {
257 case PP_PDFFEATURE_HIDPI: 260 case PP_PDFFEATURE_HIDPI:
258 return PP_TRUE; 261 return PP_TRUE;
259 case PP_PDFFEATURE_PRINTING: 262 case PP_PDFFEATURE_PRINTING:
260 return (g_print_client && g_print_client->IsPrintingEnabled(instance)) 263 return (g_print_client_tls.Pointer()->Get() &&
264 g_print_client_tls.Pointer()->Get()->IsPrintingEnabled(instance))
261 ? PP_TRUE 265 ? PP_TRUE
262 : PP_FALSE; 266 : PP_FALSE;
263 } 267 }
264 return PP_FALSE; 268 return PP_FALSE;
265 } 269 }
266 270
267 PP_Resource GetResourceImageForScale(PP_Instance instance_id, 271 PP_Resource GetResourceImageForScale(PP_Instance instance_id,
268 PP_ResourceImage image_id, 272 PP_ResourceImage image_id,
269 float scale) { 273 float scale) {
270 // Validate the instance. 274 // Validate the instance.
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 368
365 } // namespace 369 } // namespace
366 370
367 // static 371 // static
368 const PPB_PDF* PPB_PDF_Impl::GetInterface() { 372 const PPB_PDF* PPB_PDF_Impl::GetInterface() {
369 return &ppb_pdf; 373 return &ppb_pdf;
370 } 374 }
371 375
372 // static 376 // static
373 bool PPB_PDF_Impl::InvokePrintingForInstance(PP_Instance instance_id) { 377 bool PPB_PDF_Impl::InvokePrintingForInstance(PP_Instance instance_id) {
374 return g_print_client ? g_print_client->Print(instance_id) : false; 378 return g_print_client_tls.Pointer()->Get()
379 ? g_print_client_tls.Pointer()->Get()->Print(instance_id)
380 : false;
375 } 381 }
376 382
377 void PPB_PDF_Impl::SetPrintClient(PPB_PDF_Impl::PrintClient* client) { 383 void PPB_PDF_Impl::SetPrintClient(PPB_PDF_Impl::PrintClient* client) {
378 CHECK(!g_print_client) << "There should only be a single PrintClient."; 384 CHECK(!g_print_client_tls.Pointer()->Get())
379 g_print_client = client; 385 << "There should only be a single PrintClient for one RenderThread.";
386 g_print_client_tls.Pointer()->Set(client);
380 } 387 }
381 388
382 } // namespace pdf 389 } // namespace pdf
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698