OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/pdf.h" | 5 #include "pdf/pdf.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #endif | 9 #endif |
10 | 10 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "gin/array_buffer.h" | |
14 #include "gin/public/isolate_holder.h" | |
15 #include "pdf/out_of_process_instance.h" | 13 #include "pdf/out_of_process_instance.h" |
16 #include "ppapi/c/ppp.h" | 14 #include "ppapi/c/ppp.h" |
17 #include "ppapi/cpp/private/internal_module.h" | 15 #include "ppapi/cpp/private/internal_module.h" |
18 #include "ppapi/cpp/private/pdf.h" | 16 #include "ppapi/cpp/private/pdf.h" |
19 #include "v8/include/v8.h" | 17 #include "v8/include/v8.h" |
20 | 18 |
21 namespace chrome_pdf { | 19 namespace chrome_pdf { |
22 | 20 |
23 namespace { | 21 namespace { |
24 | 22 |
25 bool g_sdk_initialized_via_pepper = false; | 23 bool g_sdk_initialized_via_pepper = false; |
26 | 24 |
27 gin::IsolateHolder* g_isolate_holder = nullptr; | |
28 | |
29 void TearDownV8() { | |
30 g_isolate_holder->isolate()->Exit(); | |
31 delete g_isolate_holder; | |
32 g_isolate_holder = nullptr; | |
33 } | |
34 | |
35 } // namespace | 25 } // namespace |
36 | 26 |
37 PDFModule::PDFModule() { | 27 PDFModule::PDFModule() { |
38 } | 28 } |
39 | 29 |
40 PDFModule::~PDFModule() { | 30 PDFModule::~PDFModule() { |
41 if (g_sdk_initialized_via_pepper) { | 31 if (g_sdk_initialized_via_pepper) { |
42 TearDownV8(); | |
43 chrome_pdf::ShutdownSDK(); | 32 chrome_pdf::ShutdownSDK(); |
44 g_sdk_initialized_via_pepper = false; | 33 g_sdk_initialized_via_pepper = false; |
45 } | 34 } |
46 } | 35 } |
47 | 36 |
48 bool PDFModule::Init() { | 37 bool PDFModule::Init() { |
49 return true; | 38 return true; |
50 } | 39 } |
51 | 40 |
52 pp::Instance* PDFModule::CreateInstance(PP_Instance instance) { | 41 pp::Instance* PDFModule::CreateInstance(PP_Instance instance) { |
53 if (!g_sdk_initialized_via_pepper) { | 42 if (!g_sdk_initialized_via_pepper) { |
54 v8::StartupData natives; | 43 v8::StartupData natives; |
55 v8::StartupData snapshot; | 44 v8::StartupData snapshot; |
56 pp::PDF::GetV8ExternalSnapshotData(pp::InstanceHandle(instance), | 45 pp::PDF::GetV8ExternalSnapshotData(pp::InstanceHandle(instance), |
57 &natives.data, &natives.raw_size, | 46 &natives.data, &natives.raw_size, |
58 &snapshot.data, &snapshot.raw_size); | 47 &snapshot.data, &snapshot.raw_size); |
59 if (natives.data) { | 48 if (natives.data) { |
60 v8::V8::SetNativesDataBlob(&natives); | 49 v8::V8::SetNativesDataBlob(&natives); |
61 v8::V8::SetSnapshotDataBlob(&snapshot); | 50 v8::V8::SetSnapshotDataBlob(&snapshot); |
62 } | 51 } |
63 gin::IsolateHolder::Initialize(gin::IsolateHolder::kNonStrictMode, | 52 if (!chrome_pdf::InitializeSDK()) |
64 gin::ArrayBufferAllocator::SharedInstance()); | |
65 g_isolate_holder = | |
66 new gin::IsolateHolder(gin::IsolateHolder::kSingleThread); | |
67 g_isolate_holder->isolate()->Enter(); | |
68 if (!chrome_pdf::InitializeSDK()) { | |
69 TearDownV8(); | |
70 return NULL; | 53 return NULL; |
71 } | |
72 g_sdk_initialized_via_pepper = true; | 54 g_sdk_initialized_via_pepper = true; |
73 } | 55 } |
74 | 56 |
75 return new OutOfProcessInstance(instance); | 57 return new OutOfProcessInstance(instance); |
76 } | 58 } |
77 | 59 |
78 | 60 |
79 // Implementation of Global PPP functions --------------------------------- | 61 // Implementation of Global PPP functions --------------------------------- |
80 int32_t PPP_InitializeModule(PP_Module module_id, | 62 int32_t PPP_InitializeModule(PP_Module module_id, |
81 PPB_GetInterface get_browser_interface) { | 63 PPB_GetInterface get_browser_interface) { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 autorotate); | 171 autorotate); |
190 bool ret = engine_exports->RenderPDFPageToBitmap( | 172 bool ret = engine_exports->RenderPDFPageToBitmap( |
191 pdf_buffer, pdf_buffer_size, page_number, settings, bitmap_buffer); | 173 pdf_buffer, pdf_buffer_size, page_number, settings, bitmap_buffer); |
192 if (!g_sdk_initialized_via_pepper) { | 174 if (!g_sdk_initialized_via_pepper) { |
193 chrome_pdf::ShutdownSDK(); | 175 chrome_pdf::ShutdownSDK(); |
194 } | 176 } |
195 return ret; | 177 return ret; |
196 } | 178 } |
197 | 179 |
198 } // namespace chrome_pdf | 180 } // namespace chrome_pdf |
OLD | NEW |