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

Side by Side Diff: pdf/pdfium/pdfium_engine.cc

Issue 1419793008: Setup and tear down V8 if the PDF module is not managed via pepper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updates Created 5 years, 1 month 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 | « pdf/pdf.cc ('k') | 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 "pdf/pdfium/pdfium_engine.h" 5 #include "pdf/pdfium/pdfium_engine.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include "base/i18n/icu_encoding_detection.h" 9 #include "base/i18n/icu_encoding_detection.h"
10 #include "base/i18n/icu_string_conversions.h" 10 #include "base/i18n/icu_string_conversions.h"
11 #include "base/json/json_writer.h" 11 #include "base/json/json_writer.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/numerics/safe_conversions.h" 14 #include "base/numerics/safe_conversions.h"
15 #include "base/stl_util.h" 15 #include "base/stl_util.h"
16 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/string_piece.h" 17 #include "base/strings/string_piece.h"
18 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
19 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
20 #include "base/values.h" 20 #include "base/values.h"
21 #include "gin/array_buffer.h"
21 #include "gin/public/gin_embedders.h" 22 #include "gin/public/gin_embedders.h"
23 #include "gin/public/isolate_holder.h"
22 #include "pdf/draw_utils.h" 24 #include "pdf/draw_utils.h"
23 #include "pdf/pdfium/pdfium_api_string_buffer_adapter.h" 25 #include "pdf/pdfium/pdfium_api_string_buffer_adapter.h"
24 #include "pdf/pdfium/pdfium_mem_buffer_file_read.h" 26 #include "pdf/pdfium/pdfium_mem_buffer_file_read.h"
25 #include "pdf/pdfium/pdfium_mem_buffer_file_write.h" 27 #include "pdf/pdfium/pdfium_mem_buffer_file_write.h"
26 #include "ppapi/c/pp_errors.h" 28 #include "ppapi/c/pp_errors.h"
27 #include "ppapi/c/pp_input_event.h" 29 #include "ppapi/c/pp_input_event.h"
28 #include "ppapi/c/ppb_core.h" 30 #include "ppapi/c/ppb_core.h"
29 #include "ppapi/c/private/ppb_pdf.h" 31 #include "ppapi/c/private/ppb_pdf.h"
30 #include "ppapi/cpp/dev/memory_dev.h" 32 #include "ppapi/cpp/dev/memory_dev.h"
31 #include "ppapi/cpp/input_event.h" 33 #include "ppapi/cpp/input_event.h"
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 return std::string(); 444 return std::string();
443 445
444 base::string16 value; 446 base::string16 value;
445 PDFiumAPIStringBufferSizeInBytesAdapter<base::string16> string_adapter( 447 PDFiumAPIStringBufferSizeInBytesAdapter<base::string16> string_adapter(
446 &value, size, false); 448 &value, size, false);
447 string_adapter.Close( 449 string_adapter.Close(
448 FPDF_GetMetaText(doc, key.c_str(), string_adapter.GetData(), size)); 450 FPDF_GetMetaText(doc, key.c_str(), string_adapter.GetData(), size));
449 return base::UTF16ToUTF8(value); 451 return base::UTF16ToUTF8(value);
450 } 452 }
451 453
454 gin::IsolateHolder* g_isolate_holder = nullptr;
455
456 void SetUpV8() {
457 gin::IsolateHolder::Initialize(gin::IsolateHolder::kNonStrictMode,
458 gin::ArrayBufferAllocator::SharedInstance());
459 g_isolate_holder =
460 new gin::IsolateHolder(gin::IsolateHolder::kSingleThread);
461 g_isolate_holder->isolate()->Enter();
462 }
463
464 void TearDownV8() {
465 g_isolate_holder->isolate()->Exit();
466 delete g_isolate_holder;
467 g_isolate_holder = nullptr;
468 }
469
452 } // namespace 470 } // namespace
453 471
454 bool InitializeSDK() { 472 bool InitializeSDK() {
473 SetUpV8();
474
455 FPDF_LIBRARY_CONFIG config; 475 FPDF_LIBRARY_CONFIG config;
456 config.version = 2; 476 config.version = 2;
457 config.m_pUserFontPaths = nullptr; 477 config.m_pUserFontPaths = nullptr;
458 config.m_pIsolate = v8::Isolate::GetCurrent(); 478 config.m_pIsolate = v8::Isolate::GetCurrent();
459 config.m_v8EmbedderSlot = gin::kEmbedderPDFium; 479 config.m_v8EmbedderSlot = gin::kEmbedderPDFium;
460 FPDF_InitLibraryWithConfig(&config); 480 FPDF_InitLibraryWithConfig(&config);
461 481
462 #if defined(OS_LINUX) 482 #if defined(OS_LINUX)
463 // Font loading doesn't work in the renderer sandbox in Linux. 483 // Font loading doesn't work in the renderer sandbox in Linux.
464 FPDF_SetSystemFontInfo(&g_font_info); 484 FPDF_SetSystemFontInfo(&g_font_info);
465 #endif 485 #endif
466 486
467 FSDK_SetUnSpObjProcessHandler(&g_unsupported_info); 487 FSDK_SetUnSpObjProcessHandler(&g_unsupported_info);
468 488
469 return true; 489 return true;
Lei Zhang 2015/11/06 05:04:11 And we don't even return false. I'll fix this by c
470 } 490 }
471 491
472 void ShutdownSDK() { 492 void ShutdownSDK() {
493 TearDownV8();
473 FPDF_DestroyLibrary(); 494 FPDF_DestroyLibrary();
474 } 495 }
475 496
476 PDFEngine* PDFEngine::Create(PDFEngine::Client* client) { 497 PDFEngine* PDFEngine::Create(PDFEngine::Client* client) {
477 return new PDFiumEngine(client); 498 return new PDFiumEngine(client);
478 } 499 }
479 500
480 PDFiumEngine::PDFiumEngine(PDFEngine::Client* client) 501 PDFiumEngine::PDFiumEngine(PDFEngine::Client* client)
481 : client_(client), 502 : client_(client),
482 current_zoom_(1.0), 503 current_zoom_(1.0),
(...skipping 3486 matching lines...) Expand 10 before | Expand all | Expand 10 after
3969 double* height) { 3990 double* height) {
3970 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); 3991 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL);
3971 if (!doc) 3992 if (!doc)
3972 return false; 3993 return false;
3973 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 3994 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
3974 FPDF_CloseDocument(doc); 3995 FPDF_CloseDocument(doc);
3975 return success; 3996 return success;
3976 } 3997 }
3977 3998
3978 } // namespace chrome_pdf 3999 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « pdf/pdf.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698